・PXIをTwlSDK版と共存できるように修正

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@321 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
yutaka 2007-12-06 05:08:47 +00:00
parent 9d06eb337b
commit 51041cf86f
10 changed files with 242 additions and 362 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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

View File

@ -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

View File

@ -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 <firm/os.h>
#include <twl/memorymap.h>
#include <firm/pxi.h>
#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 );
}
}

View File

@ -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 <firm/os.h>
#include <twl/memorymap.h>
#include <firm/pxi.h>
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<len; i++ )
{
while ( PXIi_SetToFifo(p[i]) != PXI_FIFO_SUCCESS )
{
}
}
}
/*---------------------------------------------------------------------------*
Name: PXI_RecvDataByFifo
Description: Recv data to another CPU via FIFO
Arguments:
Returns: if error occured, returns minus value
*---------------------------------------------------------------------------*/
PXIFifoStatus PXI_RecvDataByFifo(PXIFifoTag tag, void* buf, int max_size )
{
static PXIFifoMessage fifomsg;
u32* p = buf;
u32 len;
int i;
while ( PXIi_GetFromFifo(&fifomsg.raw) != PXI_FIFO_SUCCESS )
{
}
if (fifomsg.e.tag != tag)
{
return PXI_FIFO_FAIL_SEND_ERR;
}
len = fifomsg.e.data;
if (len > max_size/4)
{
return PXI_FIFO_FAIL_SEND_ERR;
}
for ( i=0; i<len; i++ )
{
while ( PXIi_GetFromFifo(&p[i]) != PXI_FIFO_SUCCESS )
{
}
}
return PXI_FIFO_SUCCESS;
}
//======================================================================
// Write Send-FIFO reg.
//======================================================================
static inline PXIFifoStatus PXIi_SetToFifo(u32 data)
{
OSIntrMode enabled;
if (reg_PXI_FIFO_CNT & REG_PXI_FIFO_CNT_ERR_MASK)
{
reg_PXI_FIFO_CNT |= (REG_PXI_FIFO_CNT_E_MASK | REG_PXI_FIFO_CNT_ERR_MASK);
return PXI_FIFO_FAIL_SEND_ERR;
}
enabled = OS_DisableInterrupts();
if (reg_PXI_FIFO_CNT & REG_PXI_FIFO_CNT_SEND_FULL_MASK)
{
(void)OS_RestoreInterrupts(enabled);
return PXI_FIFO_FAIL_SEND_FULL;
}
reg_PXI_SEND_FIFO = data;
(void)OS_RestoreInterrupts(enabled);
return PXI_FIFO_SUCCESS;
}
//======================================================================
// Read Send-FIFO reg.
//======================================================================
static inline PXIFifoStatus PXIi_GetFromFifo(u32 *data_buf)
{
OSIntrMode enabled;
if (reg_PXI_FIFO_CNT & REG_PXI_FIFO_CNT_ERR_MASK)
{
reg_PXI_FIFO_CNT |= (REG_PXI_FIFO_CNT_E_MASK | REG_PXI_FIFO_CNT_ERR_MASK);
return PXI_FIFO_FAIL_RECV_ERR;
}
enabled = OS_DisableInterrupts();
if (reg_PXI_FIFO_CNT & REG_PXI_FIFO_CNT_RECV_EMP_MASK)
{
(void)OS_RestoreInterrupts(enabled);
return PXI_FIFO_FAIL_RECV_EMPTY;
}
*data_buf = reg_PXI_RECV_FIFO;
(void)OS_RestoreInterrupts(enabled);
return PXI_FIFO_SUCCESS;
}

View File

@ -39,7 +39,8 @@ extern "C" {
*---------------------------------------------------------------------------*/
static inline void AESi_SendSeed( AESKey *pSeed )
{
PXI_SendDataByFifo( PXI_FIFO_TAG_DATA, pSeed, AES_BLOCK_SIZE );
// PXI_SendDataByFifo( PXI_FIFO_TAG_DATA, pSeed, AES_BLOCK_SIZE );
PXI_SendStream( pSeed, AES_BLOCK_SIZE );
}
#ifdef __cplusplus

View File

@ -17,6 +17,9 @@
#ifndef FIRM_HW_COMMON_MMAP_FIRM_H_
#define FIRM_HW_COMMON_MMAP_FIRM_H_
#include <nitro/fs/api.h>
#include <twl/fatfs/common/api.h>
#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" */

View File

@ -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;
}

View File

@ -21,8 +21,7 @@
#include <nitro/pxi.h>
#include <firm/pxi/common/regname_ex.h>
#include <firm/pxi/common/misc.h>
#include <firm/pxi/common/pxi_firm.h>
/* FIRM_PXI_H_ */
#endif