1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16:
17: 18: 19: 20: 21:
22: #include "sdisk.h"
23: #include "tm/tmonitor.h"
24: #include "device/devconf.h"
25:
26:
27: IMPORT W GetDevConf( UB *name, W *val );
28:
29: #define SYSDISK_PRI 45
30:
31: EXPORT DrvTab *TopDrvT[4 + 1] =
32: {NULL, NULL, NULL, NULL, (DrvTab*)(-1)};
33:
34: 35: 36:
37:
38: LOCAL SDInfo mmc_drv[] = {
39: {1, MMC_CARD, "pcb", (UW)CH4toW('m','m','c','d'),
40: PC_DRV + 1, 0, 0 }
41: };
42:
43:
44: LOCAL SDInfo rd_drv[] = {
45: {3, ROM_DISK, "rda", (UW)CH4toW('m','d','s','k'),
46: MEM_DRV + 0, 0, 0 },
47: };
48:
49: LOCAL SDInfo md_drv[] = {
50: {4, RAM_DISK, "mda", (UW)CH4toW('m','a','d','k'),
51: MEM_DRV + 1, 0, 0 },
52: };
53:
54: 55: 56:
57: LOCAL ID CreTask(FP entry, INT par, UW name4)
58: {
59: T_CTSK ctsk;
60: ID tskid;
61: ER er;
62:
63:
64: ctsk.exinf = (void*)name4;
65: ctsk.task = entry;
66: ctsk.itskpri = SYSDISK_PRI;
67: ctsk.stksz = DRVTSK_STKSZ;
68: ctsk.tskatr = TA_HLNG | TA_RNG0;
69:
70: tskid = er = tk_cre_tsk(&ctsk);
71: if (er >= E_OK) {
72:
73: er = tk_sta_tsk(tskid, par);
74: if (er < E_OK) tk_del_tsk(tskid);
75: }
76: return (er >= E_OK) ? tskid : E_SYS;
77: }
78:
79: 80: 81:
82: LOCAL void ExecTask(SDInfo *inf)
83: {
84: ER er;
85: DrvTab *drv, *ndrv;
86: T_IDEV idev;
87: GDefDev ddev = {
88: NULL,
89: "",
90: 1,
91: 0,
92: 0,
93: 0,
94: -1,
95: sdOpenFn,
96: sdCloseFn,
97: sdAbortFn,
98: sdEventFn,
99: };
100:
101:
102: for (ndrv = NULL; ; inf++, ndrv = drv) {
103:
104:
105: if (!(drv = (DrvTab*)Kcalloc(1, sizeof(DrvTab)))) {
106: goto E_EXIT;
107: }
108: drv->Next = ndrv;
109:
110:
111: drv->Spec = inf->spec;
112: STRNCPY(drv->DevName, inf->devnm, L_DEVNM);
113: drv->DrvNo = inf->drvno;
114: drv->DrvBit = 0x01 << (inf->drvno & 0x1F);
115: drv->IOB = inf->iob;
116: drv->MiscPar = inf->misc;
117:
118:
119: er = CreateLock(&drv->ProcLock, (B*)&inf->name4);
120: if (er < E_OK) goto E_EXIT;
121:
122:
123: Lock(&drv->ProcLock);
124:
125:
126: ddev.exinf = drv;
127: STRNCPY(ddev.devnm, inf->devnm, L_DEVNM);
128: er = GDefDevice(&ddev, &idev, &drv->Gdi);
129: if (er < E_OK) goto E_EXIT;
130:
131:
132: sdSetUpAccFn(drv);
133:
134:
135: drv->MbfId = idev.evtmbfid;
136: drv->DevId = GDI_devid(drv->Gdi);
137: drv->ReqTmout = TMO_FEVR;
138: drv->SecSize = drv->Spec.blocksz << 9;
139:
140:
141: if (drv->Spec.pccard) {
142:
143: er = sdInitCard(drv);
144:
145: } else if (drv->IOB != 0) {
146:
147: er = sdDefIntHdr(drv, TRUE);
148: if (er >= E_OK) {
149:
150: er = (*(drv->Identify))(drv, FALSE);
151: if (er >= E_OK) {
152: drv->DriveOK = TRUE;
153: sdRegistDevice(drv);
154: } else {
155:
156: sdDefIntHdr(drv, FALSE);
157: }
158: }
159: } else {
160: er = E_OK;
161: }
162: if (er < E_OK) {
163: Kfree((void*)drv);
164: drv = ndrv;
165: }
166: if (inf->num != 0) break;
167: }
168: if (drv == NULL) {er = E_NOEXS; goto E_EXIT;}
169:
170:
171: for (ndrv = drv; ndrv != NULL; ndrv = ndrv->Next) ndrv->Top = drv;
172: TopDrvT[inf->num - 1] = drv;
173:
174:
175: (*(drv->Misc))(drv, DC_TSKINIT);
176:
177:
178: for (ndrv = drv; ndrv != NULL; ndrv = ndrv->Next) {
179: Unlock(&ndrv->ProcLock);
180: }
181:
182:
183: sdAcceptRequest(drv);
184:
185:
186: E_EXIT:
187: while ((ndrv = drv) != NULL) {
188: DeleteLock(&ndrv->ProcLock);
189: GDelDevice(ndrv->Gdi);
190: drv = ndrv->Next;
191: Kfree((void*)ndrv);
192: }
193: tk_exd_tsk();
194: }
195:
196: 197: 198:
199: EXPORT ER SysDiskDrv(INT ac, UB *av[])
200: {
201: W v[L_DEVCONF_VAL];
202: UW *mp;
203:
204: if (ac < 0) {
205:
206: return E_OK;
207: }
208:
209:
210: CreTask((FP)ExecTask, (INT)&mmc_drv[0], mmc_drv[0].name4);
211:
212:
213: if (tm_extsvc(0x01, (INT)&mp, 0, 0) >= E_OK) {
214: 215: 216: 217: 218:
219: if (mp[0] == 1 && mp[1] == 512) {
220: rd_drv[0].iob = (UW)mp[2];
221: rd_drv[0].misc = mp[3] - mp[2];
222: CreTask((FP)ExecTask, (INT)&rd_drv[0],rd_drv[0].name4);
223: }
224: }
225:
226:
227: if (GetDevConf("RAMDISK", v) > 0) {
228: mp = (v[0] <= 0) ? NULL : (UW*)Kcalloc(1, v[0]);
229: md_drv[0].iob = (UW)mp;
230: md_drv[0].misc = (mp == NULL) ? 0 : v[0];
231: CreTask((FP)ExecTask, (INT)&md_drv[0], md_drv[0].name4);
232: }
233:
234: return E_OK;
235: }