From 51041cf86f86436b6150a3093b9ed5b511925588 Mon Sep 17 00:00:00 2001 From: yutaka Date: Thu, 6 Dec 2007 05:08:47 +0000 Subject: [PATCH] =?UTF-8?q?=E3=83=BBPXI=E3=82=92TwlSDK=E7=89=88=E3=81=A8?= =?UTF-8?q?=E5=85=B1=E5=AD=98=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@321 b08762b0-b915-fc4b-9d8c-17b2551a87ff --- build/libraries/aes/ARM7/aes_init.c | 3 +- build/libraries/os/common/os_init_firm.c | 6 +- build/libraries/pxi/ARM7/Makefile | 3 +- build/libraries/pxi/ARM9/Makefile | 3 +- build/libraries/pxi/common/pxi_firm.c | 216 ++++++++++++++ build/libraries/pxi/common/pxi_misc.c | 352 ----------------------- include/firm/aes/ARM9/aes_init.h | 3 +- include/firm/hw/common/mmap_firm.h | 11 + include/firm/os/common/boot.h | 4 +- include/firm/pxi.h | 3 +- 10 files changed, 242 insertions(+), 362 deletions(-) create mode 100644 build/libraries/pxi/common/pxi_firm.c delete mode 100644 build/libraries/pxi/common/pxi_misc.c diff --git a/build/libraries/aes/ARM7/aes_init.c b/build/libraries/aes/ARM7/aes_init.c index 8d5c996a..de77a545 100644 --- a/build/libraries/aes/ARM7/aes_init.c +++ b/build/libraries/aes/ARM7/aes_init.c @@ -84,7 +84,8 @@ void AESi_InitKeysForApp( u8 game_code[4] ) void AESi_RecvSeed( void ) { AESKey seed; - PXI_RecvDataByFifo( PXI_FIFO_TAG_DATA, &seed, AES_BLOCK_SIZE ); +// PXI_RecvDataByFifo( PXI_FIFO_TAG_DATA, &seed, AES_BLOCK_SIZE ); + PXI_RecvStream( &seed, AES_BLOCK_SIZE ); AESi_WaitKey(); AESi_SetKeySeedA((AESKeySeed*)&seed); // APP //AESi_WaitKey(); diff --git a/build/libraries/os/common/os_init_firm.c b/build/libraries/os/common/os_init_firm.c index 7359313e..532682e5 100644 --- a/build/libraries/os/common/os_init_firm.c +++ b/build/libraries/os/common/os_init_firm.c @@ -44,7 +44,8 @@ void OS_InitFIRM(void) // Sync with ARM7 to enable OS_GetConsoleType() // PXI_Init() must be called before OS_InitArenaEx() //PXI_Init(); - PXI_InitFifoFIRM(); + //PXI_InitFifoFIRM(); + PXI_InitFIRM(); //---- Init Arena (arenas except SUBPRIV-WRAM) OS_InitArena(); @@ -106,7 +107,8 @@ void OS_InitFIRM(void) //---- Init interProcessor I/F //PXI_Init(); - PXI_InitFifoFIRM(); + //PXI_InitFifoFIRM(); + PXI_InitFIRM(); //---- Init Arena (SUBPRIV-WRAM arena) OS_InitArena(); diff --git a/build/libraries/pxi/ARM7/Makefile b/build/libraries/pxi/ARM7/Makefile index ce2d85a8..09a3c37a 100644 --- a/build/libraries/pxi/ARM7/Makefile +++ b/build/libraries/pxi/ARM7/Makefile @@ -29,7 +29,8 @@ TWL_PROC = ARM7 SRCDIR = ../common . SRCS = \ - pxi_misc.c \ + pxi_firm.c +# pxi_misc.c \ TARGET_LIB = libpxi_sp$(FIRM_LIBSUFFIX).a diff --git a/build/libraries/pxi/ARM9/Makefile b/build/libraries/pxi/ARM9/Makefile index 3e8d0580..d7d5361f 100644 --- a/build/libraries/pxi/ARM9/Makefile +++ b/build/libraries/pxi/ARM9/Makefile @@ -28,7 +28,8 @@ TWL_CODEGEN_ALL ?= TRUE SRCDIR = ../common . SRCS = \ - pxi_misc.c \ + pxi_firm.c +# pxi_misc.c \ TARGET_LIB = libpxi$(FIRM_LIBSUFFIX).a diff --git a/build/libraries/pxi/common/pxi_firm.c b/build/libraries/pxi/common/pxi_firm.c new file mode 100644 index 00000000..8d75e9ef --- /dev/null +++ b/build/libraries/pxi/common/pxi_firm.c @@ -0,0 +1,216 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - library - pxi + File: pxi_firm.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: $ + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#include +#include +#include + +#define PXI_FIRM_ID_MAX 32 +#define PXI_FIRM_STREAM_MAX 32 + +typedef struct +{ + u32 wp; + u32 rp; + u8 id[PXI_FIRM_ID_MAX]; + + u32 length; + u32 current; + u8 data[PXI_FIRM_STREAM_MAX]; +} +PxiWork; +static PxiWork work; + +static void PxiFirmStreamCallback( PXIFifoTag tag, u32 data, BOOL err ) +{ + (void)tag; + (void)err; + if ( !work.length ) // stream is starting + { + if ( work.length >= PXI_FIRM_STREAM_MAX ) + { + OS_TPrintf("Receiving stream has too large size (%d >= %d).\n", work.length, PXI_FIRM_STREAM_MAX); + } + work.length = data; + work.current = 0; + } + else if ( work.current < work.length ) // stream is cotinuous + { + int i; + for ( i = 0; i < 3 && work.current < work.length; i++ ) + { + work.data[ work.current++ ] = (u8)( (data >> 16) & 0xFF ); + } + } + else + { + OS_TPrintf("Stream buffer was overflow because of multiple usage.\n"); + } +} + +static void PxiFirmIDCallback( PXIFifoTag tag, u32 data, BOOL err ) +{ + u32 next_wp = ( work.wp + 1 ) % PXI_FIRM_ID_MAX; + (void)tag; + (void)err; + if ( next_wp != work.rp ) + { + work.wp = next_wp; + work.id[work.wp] = (u8)data; + } + else + { + OS_TPrintf("ID buffer was overflow (%d is ignored).\n", (u8)data); + } +} + +/*---------------------------------------------------------------------------* + Name: PXI_InitFIRM + + Description: initialize PXI for firm + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void PXI_InitFIRM(void) +{ + PXI_Init(); +#ifdef SDK_ARM9 + while (!PXI_IsCallbackReady(PXI_FIFO_TAG_USER_0, PXI_PROC_ARM7)) + { + } +#endif + work.rp = work.wp = work.length = 0; + PXI_SetFifoRecvCallback( PXI_FIFO_TAG_USER_0, PxiFirmStreamCallback ); + PXI_SetFifoRecvCallback( PXI_FIFO_TAG_USER_1, PxiFirmIDCallback ); +#ifdef SDK_ARM7 + while (!PXI_IsCallbackReady(PXI_FIFO_TAG_USER_1, PXI_PROC_ARM9)) + { + } +#endif +} + +/*---------------------------------------------------------------------------* + Name: PXI_SendStream + + Description: Send data stream + + Arguments: buf pointer to data buffer + size transfer size + + Returns: None. + *---------------------------------------------------------------------------*/ +void PXI_SendStream( const void* buf, int size ) +{ + u8* ptr = (u8*)buf; + while ( 0 > PXI_SendWordByFifo( PXI_FIFO_TAG_USER_0, (u32)size, 0 ) ) + { + } + while ( size > 0 ) + { + u32 data = (u32)(ptr[0] << 16 | ptr[1] << 8 | ptr[2] << 0); + while ( 0 > PXI_SendWordByFifo( PXI_FIFO_TAG_USER_0, data, 0 ) ) + { + } + size -= 3; + ptr += 3; + } +} + +/*---------------------------------------------------------------------------* + Name: PXI_RecvStream + + Description: Receive data stream + + Arguments: buf pointer to data buffer + size transfer size + + Returns: None. + *---------------------------------------------------------------------------*/ +void PXI_RecvStream( void* buf, int size ) +{ + while ( 1 ) + { + OSIntrMode enabled = OS_DisableInterrupts(); + if ( work.length && work.current >= work.length ) + { + if ( size != work.length ) + { + OS_TPrintf("Stream data size was not expected."); + } + else + { + MI_CpuCopy8( work.data, buf, (u32)size ); + work.length = work.current = 0; + } + OS_RestoreInterrupts( enabled ); + return; + } + OS_RestoreInterrupts( enabled ); + } +} + +/*---------------------------------------------------------------------------* + Name: PXI_NotifyID + + Description: Send ID + + Arguments: id id to send + + Returns: None. + *---------------------------------------------------------------------------*/ +void PXI_NotifyID( FIRMPxiID id ) +{ + while ( 0 > PXI_SendWordByFifo( PXI_FIFO_TAG_USER_1, id, 0 ) ) + { + } +#ifdef SDK_ARM9 + OS_TPrintf("[ARM9] Notify: %d\n", (u8)id); +#else + OS_TPrintf("[ARM7] Notify: %d\n", (u8)id); +#endif +} + +/*---------------------------------------------------------------------------* + Name: PXI_RecvID + + Description: Receive ID + + Arguments: None + + Returns: Received ID + *---------------------------------------------------------------------------*/ +FIRMPxiID PXI_RecvID( void ) +{ + while ( 1 ) + { + OSIntrMode enabled = OS_DisableInterrupts(); + if ( work.rp != work.wp ) + { + FIRMPxiID id; + work.rp = ( work.rp + 1 ) % PXI_FIRM_ID_MAX; + id = (FIRMPxiID)work.id[work.rp]; + OS_RestoreInterrupts( enabled ); +#ifdef SDK_ARM9 + OS_TPrintf("[ARM9] Received: %d\n", id); +#else + OS_TPrintf("[ARM7] Received: %d\n", id); +#endif + return id; + } + OS_RestoreInterrupts( enabled ); + } +} diff --git a/build/libraries/pxi/common/pxi_misc.c b/build/libraries/pxi/common/pxi_misc.c deleted file mode 100644 index 7804e4b5..00000000 --- a/build/libraries/pxi/common/pxi_misc.c +++ /dev/null @@ -1,352 +0,0 @@ -/*---------------------------------------------------------------------------* - Project: TwlFirm - library - pxi - File: pxi_misc.c - - Copyright 2007 Nintendo. All rights reserved. - - These coded instructions, statements, and computer programs contain - proprietary information of Nintendo of America Inc. and/or Nintendo - Company Ltd., and are protected by Federal copyright law. They may - not be disclosed to third parties or copied or duplicated in any form, - in whole or in part, without the prior written consent of Nintendo. - - $Log: $ - $NoKeywords: $ - *---------------------------------------------------------------------------*/ -#include -#include -#include - -static u16 FifoCtrlInit = 0; - -/*********** function prototypes ******************/ -static inline PXIFifoStatus PXIi_GetFromFifo(u32 *data_buf); -static inline PXIFifoStatus PXIi_SetToFifo(u32 data); - - -/*---------------------------------------------------------------------------* - Name: PXI_InitFifoFIRM - - Description: initialize FIFO system for firm - - Arguments: None. - - Returns: None. - *---------------------------------------------------------------------------*/ -void PXI_InitFifoFIRM(void) -{ - OSIntrMode enabled; - - enabled = OS_DisableInterrupts(); - - if (!FifoCtrlInit) - { - FifoCtrlInit = TRUE; - - reg_PXI_FIFO_CNT = - (REG_PXI_FIFO_CNT_SEND_CL_MASK | - REG_PXI_FIFO_CNT_E_MASK | REG_PXI_FIFO_CNT_ERR_MASK); - -#ifdef SDK_ARM9 - PXI_SendIDByIntf( FIRM_PXI_ID_INIT_ARM9 ); - PXI_WaitIDByIntf( FIRM_PXI_ID_INIT_ARM7 ); -#else // SDK_ARM7 - PXI_SendIDByIntf( FIRM_PXI_ID_INIT_ARM7 ); - PXI_WaitIDByIntf( FIRM_PXI_ID_INIT_ARM9 ); -#endif // SDK_ARM7 - } - (void)OS_RestoreInterrupts(enabled); -} - - -/*---------------------------------------------------------------------------* - Name: PXI_NotifyID - - Description: Send 4bit id to other processor - - Arguments: id notifying id - - Returns: None - *---------------------------------------------------------------------------*/ -void PXI_NotifyID( u32 id ) -{ - PXI_SendIDByFifo( PXI_FIFO_TAG_SYSTEM, id ); -} - -/*---------------------------------------------------------------------------* - Name: PXI_WaitID - - Description: Wait 4bit id from the other processor - - Arguments: id waiting id - - Returns: None - *---------------------------------------------------------------------------*/ -void PXI_WaitID( u32 id ) -{ - PXI_WaitIDByFifo( PXI_FIFO_TAG_SYSTEM, id ); -} - -/*---------------------------------------------------------------------------* - Name: PXI_RecvID - - Description: Receive 4bit id from the other processor - - Arguments: None - - Returns: id - *---------------------------------------------------------------------------*/ -u8 PXI_RecvID( void ) -{ - u8 id; - - while (PXI_RecvIDByFifo(PXI_FIFO_TAG_SYSTEM, &id) != PXI_FIFO_SUCCESS) - { - } - - return id; -} - -/*---------------------------------------------------------------------------* - Name: PXI_SendIDByIntf - - Description: Send 4bit id to the other processor - - Arguments: id sending id - - Returns: None - *---------------------------------------------------------------------------*/ -void PXI_SendIDByIntf( u32 id ) -{ - reg_PXI_INTF = (u16)(id << REG_PXI_INTF_SEND_SHIFT); -} - -/*---------------------------------------------------------------------------* - Name: PXI_RecvIDByIntf - - Description: Receive 4bit id from the other processor - - Arguments: None - - Returns: received id - *---------------------------------------------------------------------------*/ -u32 PXI_RecvIDByIntf( void ) -{ - return (u32)((reg_PXI_INTF & REG_PXI_INTF_RECV_MASK) >> REG_PXI_INTF_RECV_SHIFT); -} - -/*---------------------------------------------------------------------------* - Name: PXI_WaitIDByIntf - - Description: Wait 4bit id from the other processor - - Arguments: id waiting id - - Returns: None - *---------------------------------------------------------------------------*/ -void PXI_WaitIDByIntf( u32 id ) -{ - while (PXI_RecvIDByIntf() != id) - { - } -} - -/*---------------------------------------------------------------------------* - Name: PXI_SendIDByFifo - - Description: Send 32bit-word to another CPU via FIFO - - Arguments: - - Returns: None - *---------------------------------------------------------------------------*/ -void PXI_SendIDByFifo(PXIFifoTag tag, u32 id) -{ - static PXIFifoMessage fifomsg; - - fifomsg.e.tag = tag; - fifomsg.e.data = id; - - while ( PXIi_SetToFifo(fifomsg.raw) != PXI_FIFO_SUCCESS ) - { - } -} - -/*---------------------------------------------------------------------------* - Name: PXI_RecvIDByFifo - - Description: Recv 32bit-word from another CPU via FIFO - - Arguments: - - Returns: if error occured, returns minus value - *---------------------------------------------------------------------------*/ -PXIFifoStatus PXI_RecvIDByFifo(PXIFifoTag tag, void* buf) -{ - static PXIFifoMessage fifomsg; - u8* p = buf; - - while ( PXIi_GetFromFifo(&fifomsg.raw) != PXI_FIFO_SUCCESS ) - { - } - - if (fifomsg.e.tag != tag) - { - return PXI_FIFO_FAIL_RECV_ERR; - } - - *p = (u8)fifomsg.e.data; - - return PXI_FIFO_SUCCESS; -} - -/*---------------------------------------------------------------------------* - Name: PXI_WaitIDByFifo - - Description: Wait 32bit-word from another CPU via FIFO - - Arguments: id waiting id - - Returns: None - *---------------------------------------------------------------------------*/ -void PXI_WaitIDByFifo(PXIFifoTag tag, u32 id) -{ - u8 buf = (u8)id; - - do - { - while (PXI_RecvIDByFifo(tag, &buf) != PXI_FIFO_SUCCESS) - { - } - } - while ( buf != id ); -} - -/*---------------------------------------------------------------------------* - Name: PXI_SendDataByFifo - - Description: Send data to another CPU via FIFO - - Arguments: - - Returns: None - *---------------------------------------------------------------------------*/ -void PXI_SendDataByFifo(PXIFifoTag tag, void* buf, int size) -{ - static PXIFifoMessage fifomsg; - u32* p = buf; - int len = size/4; - int i; - - fifomsg.e.tag = tag; - fifomsg.e.data = len; - - while ( PXIi_SetToFifo(fifomsg.raw) != PXI_FIFO_SUCCESS ) - { - } - - for ( i=0; i max_size/4) - { - return PXI_FIFO_FAIL_SEND_ERR; - } - - for ( i=0; i +#include + #ifdef __cplusplus extern "C" { #endif @@ -28,6 +31,14 @@ extern "C" { #define HW_FIRM_LOAD_BUFFER_SIZE (HW_FIRM_LOAD_BUFFER_UNIT_SIZE * HW_FIRM_LOAD_BUFFER_UNIT_NUMS) #define HW_FIRM_LOAD_BUFFER_END (HW_FIRM_LOAD_BUFFER_BASE + HW_FIRM_LOAD_BUFFER_SIZE) +//------------------------------------- FS/FATFS +#define HW_FIRM_FATFS_COMMAND_BUFFER (HW_FIRM_FATFS_COMMAND_BUFFER_END - HW_FIRM_FATFS_COMMAND_BUFFER_SIZE) +#define HW_FIRM_FATFS_COMMAND_BUFFER_SIZE FATFS_COMMAND_BUFFER_MAX // 0x800 +#define HW_FIRM_FATFS_COMMAND_BUFFER_END HW_FIRM_FS_TWMP_BUFFER // 0x02ff8000 + +#define HW_FIRM_FS_TWMP_BUFFER (HW_FIRM_FS_TWMP_BUFFER_END - HW_FIRM_FS_TWMP_BUFFER_SIZE) +#define HW_FIRM_FS_TWMP_BUFFER_SIZE FS_TEMPORARY_BUFFER_MAX // 0x4000 +#define HW_FIRM_FS_TWMP_BUFFER_END HW_TWL_MAIN_MEM_SHARED // 0x02ffc000 #ifdef __cplusplus } /* extern "C" */ diff --git a/include/firm/os/common/boot.h b/include/firm/os/common/boot.h index e09503f5..d4ec0318 100644 --- a/include/firm/os/common/boot.h +++ b/include/firm/os/common/boot.h @@ -71,7 +71,7 @@ BOOL OSi_FromBromToMenu( void ); Returns: address *---------------------------------------------------------------------------*/ -static inline OSFromBromBuf* OSi_GetFromBromAddr( void ) +static inline OSFromBromBuf* const OSi_GetFromBromAddr( void ) { return (OSFromBromBuf*)HW_FIRM_FROM_BROM_BUF; } @@ -85,7 +85,7 @@ static inline OSFromBromBuf* OSi_GetFromBromAddr( void ) Returns: address *---------------------------------------------------------------------------*/ -static inline OSFromFirmBuf* OSi_GetFromFirmAddr( void ) +static inline OSFromFirmBuf* const OSi_GetFromFirmAddr( void ) { return (OSFromFirmBuf*)HW_FIRM_FROM_FIRM_BUF; } diff --git a/include/firm/pxi.h b/include/firm/pxi.h index b257e654..7290d329 100644 --- a/include/firm/pxi.h +++ b/include/firm/pxi.h @@ -21,8 +21,7 @@ #include #include -#include - +#include /* FIRM_PXI_H_ */ #endif