gonzui


Format: Advanced Search

tkernel_2/driver/tef_em1d/sysdsk/src/main.cbare sourcepermlink (0.02 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T-Kernel 2.0 Software Package
    4:  *
    5:  *    Copyright 2011 by Ken Sakamura.
    6:  *    This software is distributed under the latest version of T-License 2.x.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by T-Engine Forum(http://www.t-engine.org/) at 2011/05/17.
   10:  *    Modified by T-Engine Forum at 2014/09/10.
   11:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/01.
   12:  *
   13:  *----------------------------------------------------------------------
   14:  */
   15: 
   16: 
   17: /*
   18:  *      main.c               System disk driver
   19:  *
   20:  *      driver main
   21:  */
   22: #include "sdisk.h"
   23: #include "tm/tmonitor.h"
   24: #include "device/devconf.h"
   25: 
   26: /* Get "DEVCONF" entry */
   27: IMPORT W GetDevConf( UB *name, W *val );
   28: 
   29: #define SYSDISK_PRI     45
   30: 
   31: EXPORT  DrvTab   *TopDrvT[4 + 1] =         /* Top-drive table     */
   32:         {NULL, NULL, NULL, NULL, (DrvTab*)(-1)};
   33: 
   34: /*
   35:  *      Object disk information
   36:  */
   37: /* MMC/SD card definition */
   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: /* ROM disk definition */
   44: LOCAL   SDInfo    rd_drv[] = {
   45:         {3,    ROM_DISK, "rda", (UW)CH4toW('m','d','s','k'),
   46:                         MEM_DRV + 0,         0,     0   },
   47: };
   48: /* RAM disk definition */
   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:  *      Create task
   56:  */
   57: LOCAL   ID        CreTask(FP entry, INT par, UW name4)
   58: {
   59:         T_CTSK ctsk;
   60:         ID     tskid;
   61:         ER     er;
   62: 
   63:         /* Task creation */
   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:                 /* Task start-up */
   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:  *      System disk driver : common task (accept the common request)
   81:  */
   82: LOCAL   void      ExecTask(SDInfo      *inf)
   83: {
   84:         ER     er;
   85:         DrvTab *drv, *ndrv;
   86:         T_IDEV idev;
   87:         GDefDev        ddev = {
   88:                 NULL,         /* exinf */
   89:                 "",           /* devnm */
   90:                 1,            /* maxreqq */
   91:                 0,            /* drvatr */
   92:                 0,            /* devatr */
   93:                 0,            /* nsub */
   94:                 -1,           /* blksz */
   95:                 sdOpenFn,     /* open */
   96:                 sdCloseFn,    /* close */
   97:                 sdAbortFn,    /* abort */
   98:                 sdEventFn,    /* event */
   99:         };
  100: 
  101:         /* Create the data for drive processing */
  102:         for (ndrv = NULL; ; inf++, ndrv = drv) {
  103: 
  104:                 /* Get & Clear the drive information area  */
  105:                 if (!(drv = (DrvTab*)Kcalloc(1, sizeof(DrvTab)))) {
  106:                         goto E_EXIT;
  107:                 }
  108:                 drv->Next = ndrv;
  109: 
  110:                 /* Set the configuration data */
  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:                 /* Create the lock for common processing */
  119:                 er = CreateLock(&drv->ProcLock, (B*)&inf->name4);
  120:                 if (er < E_OK) goto E_EXIT;
  121: 
  122:                 /* Execute a lock until the completion of initialization */
  123:                 Lock(&drv->ProcLock);
  124: 
  125:                 /* Get the physical device ID */
  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:                 /* Set the device-support processing function */
  132:                 sdSetUpAccFn(drv);
  133: 
  134:                 /* Other initializations */
  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:                 /* The processing in accordance with device specification */
  141:                 if (drv->Spec.pccard) {               /* PC card type */
  142:                         /* Initialize the card */
  143:                         er = sdInitCard(drv);
  144: 
  145:                 } else if (drv->IOB != 0) {   /* Fixation I/F */
  146:                         /* Register the interrupt handler */
  147:                         er = sdDefIntHdr(drv, TRUE);
  148:                         if (er >= E_OK) {
  149:                                 /* Check the existence of disk & Register the device */
  150:                                 er = (*(drv->Identify))(drv, FALSE);
  151:                                 if (er >= E_OK) {
  152:                                         drv->DriveOK = TRUE;
  153:                                         sdRegistDevice(drv);
  154:                                 } else {
  155:                                         /* Release the interrupt handler */
  156:                                         sdDefIntHdr(drv, FALSE);
  157:                                 }
  158:                         }
  159:                 } else {                      /* Others */
  160:                         er = E_OK;
  161:                 }
  162:                 if (er < E_OK) {              /* Release the drive information */
  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:         /* Set the top drive */
  171:         for (ndrv = drv; ndrv != NULL; ndrv = ndrv->Next) ndrv->Top = drv;
  172:         TopDrvT[inf->num - 1] = drv;
  173: 
  174:         /* Initialize the device-support task */
  175:         (*(drv->Misc))(drv, DC_TSKINIT);
  176: 
  177:         /* Release the lock */
  178:         for (ndrv = drv; ndrv != NULL; ndrv = ndrv->Next) {
  179:                 Unlock(&ndrv->ProcLock);
  180:         }
  181: 
  182:         /* Start the acceptance of device processing request */
  183:         sdAcceptRequest(drv);
  184: 
  185:         /* It does not come here because it does not exit */
  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:  *      System disk driver : entry
  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:                 /* End processing: execute especially nothing because it is end of system */
  206:                 return E_OK;
  207:         }
  208: 
  209:         /* Driver for MMC/SD card */
  210:         CreTask((FP)ExecTask, (INT)&mmc_drv[0], mmc_drv[0].name4);
  211: 
  212:         /* Driver for ROM disk (rda): fetch the information from T-Monitor */
  213:         if (tm_extsvc(0x01, (INT)&mp, 0, 0) >= E_OK) {
  214:                 /*    mp[0] : ROM disk types
  215:                  *    mp[1] : ROM disk block size
  216:                  *    mp[2] : ROM disk start address
  217:                  *    mp[3] : ROM disk end address
  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:         /* Driver for RAM disk (mda) : DEVCONF: RAMDISK  size */
  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: }