fix issue with HBC stub + 64B L2 cache (tueidj)
[libogc.git] / libogc / gcsd.c
blob4f87b82d3157f8dc01dcacd29a0f079aca55f96f
1 /*
3 gcsd.h
5 Hardware routines for reading and writing to SD geckos connected
6 to the memory card ports.
8 These functions are just wrappers around libsdcard's functions.
10 Copyright (c) 2008 Sven "svpe" Peter <svpe@gmx.net>
12 Redistribution and use in source and binary forms, with or without modification,
13 are permitted provided that the following conditions are met:
15 1. Redistributions of source code must retain the above copyright notice,
16 this list of conditions and the following disclaimer.
17 2. Redistributions in binary form must reproduce the above copyright notice,
18 this list of conditions and the following disclaimer in the documentation and/or
19 other materials provided with the distribution.
20 3. The name of the author may not be used to endorse or promote products derived
21 from this software without specific prior written permission.
23 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
26 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sdcard/gcsd.h>
35 #include <sdcard/card_cmn.h>
36 #include <sdcard/card_io.h>
37 #include <sdcard/card_buf.h>
39 static int __gcsd_init = 0;
41 static bool __gcsd_isInserted(int n)
43 if(sdgecko_readStatus(n) == CARDIO_ERROR_NOCARD)
44 return false;
45 return true;
48 static bool __gcsd_startup(int n)
50 if(__gcsd_init == 1)
51 return __gcsd_isInserted(n);
52 sdgecko_initBufferPool();
53 sdgecko_initIODefault();
54 __gcsd_init = 1;
55 return __gcsd_isInserted(n);
59 static bool __gcsd_readSectors(int n, u32 sector, u32 numSectors, void *buffer)
61 s32 ret;
63 ret = sdgecko_readSectors(n,sector,numSectors,buffer);
64 if(ret == CARDIO_ERROR_READY)
65 return true;
67 return false;
70 static bool __gcsd_writeSectors(int n, u32 sector, u32 numSectors, const void *buffer)
72 s32 ret;
74 ret = sdgecko_writeSectors(n,sector,numSectors,buffer);
75 if(ret == CARDIO_ERROR_READY)
76 return true;
78 return false;
81 static bool __gcsd_clearStatus(int n)
83 return true; // FIXME
86 static bool __gcsd_shutdown(int n)
88 sdgecko_doUnmount(n);
89 return true;
93 static bool __gcsda_startup(void)
95 return __gcsd_startup(0);
98 static bool __gcsda_isInserted(void)
100 return __gcsd_isInserted(0);
103 static bool __gcsda_readSectors(u32 sector, u32 numSectors, void *buffer)
105 return __gcsd_readSectors(0, sector, numSectors, buffer);
108 static bool __gcsda_writeSectors(u32 sector, u32 numSectors, void *buffer)
110 return __gcsd_writeSectors(0, sector, numSectors, buffer);
113 static bool __gcsda_clearStatus(void)
115 return __gcsd_clearStatus(0);
118 static bool __gcsda_shutdown(void)
120 return __gcsd_shutdown(0);
125 static bool __gcsdb_startup(void)
127 return __gcsd_startup(1);
130 static bool __gcsdb_isInserted(void)
132 return __gcsd_isInserted(1);
135 static bool __gcsdb_readSectors(u32 sector, u32 numSectors, void *buffer)
137 return __gcsd_readSectors(1, sector, numSectors, buffer);
140 static bool __gcsdb_writeSectors(u32 sector, u32 numSectors, void *buffer)
142 return __gcsd_writeSectors(1, sector, numSectors, buffer);
145 static bool __gcsdb_clearStatus(void)
147 return __gcsd_clearStatus(1);
150 static bool __gcsdb_shutdown(void)
152 return __gcsd_shutdown(1);
155 const DISC_INTERFACE __io_gcsda = {
156 DEVICE_TYPE_GC_SD,
157 FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_GAMECUBE_SLOTA,
158 (FN_MEDIUM_STARTUP)&__gcsda_startup,
159 (FN_MEDIUM_ISINSERTED)&__gcsda_isInserted,
160 (FN_MEDIUM_READSECTORS)&__gcsda_readSectors,
161 (FN_MEDIUM_WRITESECTORS)&__gcsda_writeSectors,
162 (FN_MEDIUM_CLEARSTATUS)&__gcsda_clearStatus,
163 (FN_MEDIUM_SHUTDOWN)&__gcsda_shutdown
165 const DISC_INTERFACE __io_gcsdb = {
166 DEVICE_TYPE_GC_SD,
167 FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_GAMECUBE_SLOTB,
168 (FN_MEDIUM_STARTUP)&__gcsdb_startup,
169 (FN_MEDIUM_ISINSERTED)&__gcsdb_isInserted,
170 (FN_MEDIUM_READSECTORS)&__gcsdb_readSectors,
171 (FN_MEDIUM_WRITESECTORS)&__gcsdb_writeSectors,
172 (FN_MEDIUM_CLEARSTATUS)&__gcsdb_clearStatus,
173 (FN_MEDIUM_SHUTDOWN)&__gcsdb_shutdown