tkernel_2/include/tk/devmgr.h | bare source | permlink (0.03 seconds) |
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 TRON Forum(http://www.tron.org/) at 2015/06/01. 11: * 12: *---------------------------------------------------------------------- 13: */ 14: 15: /* 16: * @(#)devmgr.h (T-Kernel) 17: * 18: * T-Kernel Device Management 19: */ 20: 21: #ifndef __TK_DEVMGR_H__ 22: #define __TK_DEVMGR_H__ 23: 24: #include <basic.h> 25: #include <tk/typedef.h> 26: #include <tk/syscall.h> 27: 28: #ifdef __cplusplus 29: extern "C" { 30: #endif 31: 32: #define L_DEVNM 8 /* Device name length */ 33: 34: /* 35: * Device attribute (ATR) 36: * 37: * IIII IIII IIII IIII PRxx xxxx KKKK KKKK 38: * 39: * The first 16-bit is the device-dependent attribute and 40: * defined by each device. 41: * The last 16-bit is the standard attribute and defined 42: * like as followings. 43: */ 44: #define TD_PROTECT 0x8000U /* P: Write protected */ 45: #define TD_REMOVABLE 0x4000U /* R: Media remove enabled */ 46: 47: #define TD_DEVKIND 0x00ffU /* K: Device/media type */ 48: #define TD_DEVTYPE 0x00f0U /* Device type */ 49: 50: /* Device type */ 51: #define TDK_UNDEF 0x0000U /* Undefined/Unknown */ 52: #define TDK_DISK 0x0010U /* Disk device */ 53: 54: /* Disk type */ 55: #define TDK_DISK_UNDEF 0x0010U /* Other disks */ 56: #define TDK_DISK_RAM 0x0011U /* RAM disk (Use main memory) */ 57: #define TDK_DISK_ROM 0x0012U /* ROM disk (Use main memory) */ 58: #define TDK_DISK_FLA 0x0013U /* Flash ROM, other silicon disks */ 59: #define TDK_DISK_FD 0x0014U /* Floppy disk */ 60: #define TDK_DISK_HD 0x0015U /* Hard disk */ 61: #define TDK_DISK_CDROM 0x0016U /* CD-ROM */ 62: 63: /* 64: * Device open mode 65: */ 66: #define TD_READ 0x0001U /* Read only */ 67: #define TD_WRITE 0x0002U /* Write only */ 68: #define TD_UPDATE 0x0003U /* Read and write */ 69: #define TD_EXCL 0x0100U /* Exclusive */ 70: #define TD_WEXCL 0x0200U /* Exclusive write */ 71: #define TD_REXCL 0x0400U /* Exclusive read */ 72: #define TD_NOLOCK 0x1000U /* Lock (resident) non-required */ 73: 74: /* 75: * Device close option 76: */ 77: #define TD_EJECT 0x0001U /* Media eject */ 78: 79: /* 80: * Suspend mode 81: */ 82: #define TD_SUSPEND 0x0001U /* Suspend */ 83: #define TD_DISSUS 0x0002U /* Disable suspend */ 84: #define TD_ENASUS 0x0003U /* Enable suspend */ 85: #define TD_CHECK 0x0004U /* Get suspend disable request count */ 86: #define TD_FORCE 0x8000U /* Specify forced suspend */ 87: 88: /* 89: * Device information 90: */ 91: typedef struct t_rdev { 92: ATR devatr; /* Device attribute */ 93: INT blksz; /* Specific data block size (-1: Unknown) */ 94: INT nsub; /* Number of subunits */ 95: INT subno; /* 0: Physical device, 96: 1 - nsub: Subunit number +1 */ 97: } T_RDEV; 98: 99: /* 100: * Registration device information 101: */ 102: typedef struct t_ldev { 103: ATR devatr; /* Device attribute */ 104: INT blksz; /* Specific data block size (-1: Unknown) */ 105: INT nsub; /* Number of subunits */ 106: UB devnm[L_DEVNM]; /* Physical device name */ 107: } T_LDEV; 108: 109: /* 110: * Common attribute data number 111: * RW: Readable (tk_rea_dev)/writable (tk_wri_dev) 112: * R-: Readable (tk_rea_dev) only 113: */ 114: #define TDN_EVENT (-1) /* RW:Message buffer ID 115: for event notification */ 116: #define TDN_DISKINFO (-2) /* R-:Disk information */ 117: #define TDN_DISPSPEC (-3) /* R-:Display device specification */ 118: #define TDN_PCMCIAINFO (-4) /* R-:PC card information */ 119: #define TDN_DISKINFO_D (-5) /* R-: Disk information (64 bits device) */ 120: 121: /* 122: * Device event type 123: */ 124: typedef enum tdevttyp { 125: TDE_unknown = 0, /* Undefined */ 126: TDE_MOUNT = 0x01, /* Media insert */ 127: TDE_EJECT = 0x02, /* Media eject */ 128: TDE_ILLMOUNT = 0x03, /* Media incorrect insert */ 129: TDE_ILLEJECT = 0x04, /* Media incorrect eject */ 130: TDE_REMOUNT = 0x05, /* Media re-insert */ 131: TDE_CARDBATLOW = 0x06, /* Card battery low */ 132: TDE_CARDBATFAIL = 0x07, /* Card battery abnormal */ 133: TDE_REQEJECT = 0x08, /* Media eject request */ 134: TDE_PDBUT = 0x11, /* PD button state change */ 135: TDE_PDMOVE = 0x12, /* PD position move */ 136: TDE_PDSTATE = 0x13, /* PD state change */ 137: TDE_PDEXT = 0x14, /* PD extended event */ 138: TDE_KEYDOWN = 0x21, /* Key down */ 139: TDE_KEYUP = 0x22, /* Key up */ 140: TDE_KEYMETA = 0x23, /* Meta key state change */ 141: TDE_POWEROFF = 0x31, /* Power switch off */ 142: TDE_POWERLOW = 0x32, /* Power low */ 143: TDE_POWERFAIL = 0x33, /* Power abnormal */ 144: TDE_POWERSUS = 0x34, /* Automatic suspend */ 145: TDE_POWERUPTM = 0x35, /* Clock update */ 146: TDE_CKPWON = 0x41 /* Automatic power on notification */ 147: } TDEvtTyp; 148: 149: /* 150: * Device event message format 151: */ 152: typedef struct t_devevt { 153: TDEvtTyp evttyp; /* Event type */ 154: /* Information by each event type is added below */ 155: } T_DEVEVT; 156: 157: /* 158: * Device event message format with device ID 159: */ 160: typedef struct t_devevt_id { 161: TDEvtTyp evttyp; /* Event type */ 162: ID devid; /* Device ID */ 163: /* Information by each event type is added below */ 164: } T_DEVEVT_ID; 165: 166: /* ------------------------------------------------------------------------ */ 167: 168: /* 169: * Device registration information 170: */ 171: typedef struct t_ddev { 172: void *exinf; /* Extended information */ 173: ATR drvatr; /* Driver attribute */ 174: ATR devatr; /* Device attribute */ 175: INT nsub; /* Number of subunits */ 176: INT blksz; /* Specific data block size (-1: Unknown) */ 177: FP openfn; /* Open function */ 178: FP closefn; /* Close function */ 179: FP execfn; /* Execute function */ 180: FP waitfn; /* Completion wait function */ 181: FP abortfn; /* Abort function */ 182: FP eventfn; /* Event function */ 183: #if TA_GP 184: void *gp; /* Global pointer (gp) */ 185: #endif 186: } T_DDEV; 187: 188: /* 189: * Open function: 190: * ER openfn( ID devid, UINT omode, void *exinf ) 191: * Close function: 192: * ER closefn( ID devid, UINT option, void *exinf ) 193: * Execute function: 194: * ER execfn( T_DEVREQ *devreq, TMO tmout, void *exinf ) 195: * Completion wait function: 196: * INT waitfn( T_DEVREQ *devreq, INT nreq, TMO tmout, void *exinf ) 197: * Abort function: 198: * ER abortfn( ID tskid, T_DEVREQ *devreq, INT nreq, void *exinf) 199: * Event function: 200: * INT eventfn( INT evttyp, void *evtinf, void *exinf ) 201: */ 202: 203: /* 204: * Driver attribute 205: */ 206: #define TDA_OPENREQ 0x0001U /* Every time open/close */ 207: #define TDA_TMO_U 0x0002U /* Timeout in microseconds */ 208: #define TDA_DEV_D 0x0004U /* 64 bits device */ 209: 210: /* 211: * Device initial setting information 212: */ 213: typedef struct t_idev { 214: ID evtmbfid; /* Message buffer ID for event notification */ 215: } T_IDEV; 216: 217: /* 218: * Device request packet 219: * I: Input parameter 220: * O: Output parameter 221: */ 222: typedef struct t_devreq { 223: struct t_devreq *next; /* I:Link to request packet (NULL:End) */ 224: void *exinf; /* X:Extended information */ 225: ID devid; /* I:Target device ID */ 226: INT cmd:4; /* I:Request command */ 227: BOOL abort:1; /* I:When executing abort request, TRUE */ 228: BOOL nolock:1; /* I:When lock (resident) is not required, TRUE */ 229: INT rsv:26; /* I:Reserved (always 0) */ 230: T_TSKSPC tskspc; /* I:Task space of request task */ 231: W start; /* I:Start data number */ 232: W size; /* I:Request size */ 233: void *buf; /* I:Input/output buffer address */ 234: W asize; /* O:Result size */ 235: ER error; /* O:Result error */ 236: } T_DEVREQ; 237: typedef struct t_devreq_d { 238: struct t_devreq_d *next; /* I:Link to request packet (NULL:End) */ 239: void *exinf; /* X:Extended information */ 240: ID devid; /* I:Target device ID */ 241: INT cmd:4; /* I:Request command */ 242: BOOL abort:1; /* I:When executing abort request, TRUE */ 243: BOOL nolock:1; /* I:When lock (resident) is not required, TRUE */ 244: INT rsv:26; /* I:Reserved (always 0) */ 245: T_TSKSPC tskspc; /* I:Task space of request task */ 246: D start_d; /* I:Start data number */ 247: W size; /* I:Request size */ 248: void *buf; /* I:Input/output buffer address */ 249: W asize; /* O:Result size */ 250: ER error; /* O:Result error */ 251: } T_DEVREQ_D; 252: 253: /* 254: * Request command 255: */ 256: #define TDC_READ 1 /* Read request */ 257: #define TDC_WRITE 2 /* Write request */ 258: 259: /* 260: * Driver request event 261: */ 262: #define TDV_SUSPEND (-1) /* Suspend */ 263: #define TDV_RESUME (-2) /* Resume */ 264: #define TDV_CARDEVT 1 /* PC card event (Refer card manager) */ 265: #define TDV_USBEVT 2 /* USB event (Refer USB manager) */ 266: 267: /* ------------------------------------------------------------------------ */ 268: 269: /* 270: * Definition for interface library automatic generation (mkiflib) 271: */ 272: /*** DEFINE_IFLIB 273: [INCLUDE FILE] 274: <tk/devmgr.h> 275: 276: [PREFIX] 277: DEVICE 278: ***/ 279: 280: /* [BEGIN SYSCALLS] */ 281: /* Application interface */ 282: IMPORT ID tk_opn_dev( CONST UB *devnm, UINT omode ); 283: IMPORT ER tk_cls_dev( ID dd, UINT option ); 284: IMPORT ID tk_rea_dev( ID dd, W start, void *buf, W size, TMO tmout ); 285: IMPORT ER tk_srea_dev( ID dd, W start, void *buf, W size, W *asize ); 286: IMPORT ID tk_wri_dev( ID dd, W start, CONST void *buf, W size, TMO tmout ); 287: IMPORT ER tk_swri_dev( ID dd, W start, CONST void *buf, W size, W *asize ); 288: IMPORT ID tk_wai_dev( ID dd, ID reqid, W *asize, ER *ioer, TMO tmout ); 289: IMPORT INT tk_sus_dev( UINT mode ); 290: IMPORT ID tk_get_dev( ID devid, UB *devnm ); 291: IMPORT ID tk_ref_dev( CONST UB *devnm, T_RDEV *rdev ); 292: IMPORT ID tk_oref_dev( ID dd, T_RDEV *rdev ); 293: IMPORT INT tk_lst_dev( T_LDEV *ldev, INT start, INT ndev ); 294: IMPORT INT tk_evt_dev( ID devid, INT evttyp, void *evtinf ); 295: 296: /* T-Kernel 2.0 */ 297: IMPORT ID tk_rea_dev_du( ID dd, D start_d, void *buf, W size, TMO_U tmout_u ); 298: IMPORT ER tk_srea_dev_d( ID dd, D start_d, void *buf, W size, W *asize ); 299: IMPORT ID tk_wri_dev_du( ID dd, D start_d, CONST void *buf, W size, TMO_U tmout_u ); 300: IMPORT ER tk_swri_dev_d( ID dd, D start_d, CONST void *buf, W size, W *asize ); 301: IMPORT ID tk_wai_dev_u( ID dd, ID reqid, W *asize, ER *ioer, TMO_U tmout_u ); 302: 303: /* Device registration */ 304: /* ALIGN_NO 0x0100 */ 305: IMPORT ID tk_def_dev( CONST UB *devnm, CONST T_DDEV *ddev, T_IDEV *idev ); 306: IMPORT ER tk_ref_idv( T_IDEV *idev ); 307: /* [END SYSCALLS] */ 308: 309: #ifdef __cplusplus 310: } 311: #endif 312: #endif /* __TK_DEVMGR_H__ */