1 /*---------------------------------------------------------------------------* 2 Project: TwlSDK - MB - include 3 File: mb_cache.h 4 5 Copyright 2007-2008 Nintendo. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Date:: 2008-09-18#$ 14 $Rev: 8573 $ 15 $Author: okubata_ryoma $ 16 *---------------------------------------------------------------------------*/ 17 18 #if !defined(NITRO_MB_CACHE_H_) 19 #define NITRO_MB_CACHE_H_ 20 21 22 #if defined(__cplusplus) 23 extern "C" 24 { 25 #endif 26 27 28 /* constant ---------------------------------------------------------------- */ 29 30 31 #define MB_CACHE_INFO_MAX 4 32 33 #define MB_CACHE_STATE_EMPTY 0 34 #define MB_CACHE_STATE_BUSY 1 35 #define MB_CACHE_STATE_READY 2 36 #define MB_CACHE_STATE_LOCKED 3 37 38 39 /* struct ------------------------------------------------------------------ */ 40 41 42 /* 43 * Structure for virtual memory that uses paging. 44 * Manage a cache for a large capacity address space (for CARD and so on) using an array of these structures. 45 */ 46 typedef struct 47 { 48 u32 src; /* Logical source address */ 49 u32 len; /* Cache length */ 50 u8 *ptr; /* Pointer to cache buffer */ 51 u32 state; /* If 1, ready to use */ 52 } 53 MBiCacheInfo; 54 55 typedef struct 56 { 57 u32 lifetime; /* If hit or timeout, set 0. */ 58 u32 recent; /* Unused */ 59 MBiCacheInfo *p_list; /* Unused */ 60 u32 size; /* Unused */ 61 char arc_name[FS_ARCHIVE_NAME_LEN_MAX + 1]; /* Target archive */ 62 u32 arc_name_len; /* Archive name length */ 63 FSArchive *arc_pointer; 64 u8 reserved[32 - FS_ARCHIVE_NAME_LEN_MAX - 1 - sizeof(u32) - sizeof(FSArchive*)]; 65 MBiCacheInfo list[MB_CACHE_INFO_MAX]; 66 } 67 MBiCacheList; 68 69 70 /* Function ---------------------------------------------------------------- */ 71 72 73 74 /*---------------------------------------------------------------------------* 75 Name: MBi_InitCache 76 77 Description: Initializes a cache list. 78 79 80 Arguments: pl: Cache list. 81 82 Returns: None. 83 *---------------------------------------------------------------------------*/ 84 void MBi_InitCache(MBiCacheList * pl); 85 86 /*---------------------------------------------------------------------------* 87 Name: MBi_AttachCacheBuffer 88 89 Description: Assigns a buffer to a cache list. 90 91 Arguments: pl: Cache list. 92 ptr: Buffer to assign. 93 src: Source address of ptr. 94 len: Byte size of ptr. 95 state: Initial state to specify. 96 (MB_CACHE_STATE_READY or MB_CACHE_STATE_LOCKED) 97 98 Returns: None. 99 *---------------------------------------------------------------------------*/ 100 void MBi_AttachCacheBuffer(MBiCacheList * pl, u32 src, u32 len, void *ptr, u32 state); 101 102 /*---------------------------------------------------------------------------* 103 Name: MBi_ReadFromCache 104 105 Description: Reads the content of the specified address from the cache. 106 107 Arguments: pl: Cache list. 108 src: Source address of the read. 109 len: Read size (BYTE). 110 dst: Destination address of the read. 111 112 Returns: TRUE if the cache hits and a read is performed; FALSE otherwise. 113 *---------------------------------------------------------------------------*/ 114 BOOL MBi_ReadFromCache(MBiCacheList * pl, u32 src, void *dst, u32 len); 115 116 /*---------------------------------------------------------------------------* 117 Name: MBi_TryLoadCache 118 119 Description: Loads the content of the specified address to the cache. 120 The READY page cache with the lowest address is discarded. 121 122 Arguments: pl: Cache list. 123 src: Reload source address. 124 len: Reload size (in bytes). 125 126 Returns: TRUE if the reload could be started and FALSE otherwise. 127 (When there is a single reload processing engine in the system, this function should return FALSE if processing was not finished previously.) 128 129 *---------------------------------------------------------------------------*/ 130 BOOL MBi_TryLoadCache(MBiCacheList * pl, u32 src, u32 len); 131 132 133 134 #if defined(__cplusplus) 135 } 136 #endif 137 138 139 #endif /* NITRO_MB_CACHE_H_ */ 140