usb.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * common USB definitions
  3. */
  4. typedef struct Ctlr Ctlr;
  5. typedef struct Endpt Endpt;
  6. typedef struct Udev Udev;
  7. typedef struct Usbhost Usbhost;
  8. enum
  9. {
  10. MaxUsb = 10, /* max # of USB Host Controller Interfaces (Usbhost*) */
  11. MaxUsbDev = 32, /* max # of attached USB devs, including root hub (Udev*) */
  12. /* request type */
  13. RH2D = 0<<7,
  14. RD2H = 1<<7,
  15. Rstandard = 0<<5,
  16. Rclass = 1<<5,
  17. Rvendor = 2<<5,
  18. Rdevice = 0,
  19. Rinterface = 1,
  20. Rendpt = 2,
  21. Rother = 3,
  22. };
  23. #define Class(csp) ((csp)&0xff)
  24. #define Subclass(csp) (((csp)>>8)&0xff)
  25. #define Proto(csp) (((csp)>>16)&0xff)
  26. #define CSP(c, s, p) ((c) | ((s)<<8) | ((p)<<16))
  27. /* for OHCI */
  28. typedef struct ED ED;
  29. struct ED {
  30. ulong ctrl;
  31. ulong tail; /* transfer descriptor */
  32. ulong head;
  33. ulong next;
  34. };
  35. /*
  36. * device endpoint
  37. */
  38. struct Endpt
  39. {
  40. ED *ined; /* for OHCI */
  41. ED *outed; /* for OHCI */
  42. Ref;
  43. Lock;
  44. int x; /* index in Udev.ep */
  45. struct { /* OHCI */
  46. int epmode;
  47. int nbuf; /* number of buffers allowed */
  48. int ntd;
  49. int mps;
  50. } out;
  51. struct { /* OHCI */
  52. int epmode;
  53. int nbuf; /* number of buffers allowed */
  54. int sched; /* schedule index; -1 if undefined or aperiodic */
  55. int pollms; /* polling interval in msec */
  56. int ntd;
  57. int mps;
  58. } in;
  59. int id; /* hardware endpoint address */
  60. int maxpkt; /* maximum packet size (from endpoint descriptor) */
  61. uchar wdata01; /* 0=DATA0, 1=DATA1 for output direction */
  62. uchar rdata01; /* 0=DATA0, 1=DATA1 for input direction */
  63. uchar eof;
  64. ulong csp;
  65. uchar mode; /* OREAD, OWRITE, ORDWR */
  66. uchar nbuf; /* number of buffers allowed */
  67. uchar iso;
  68. uchar debug;
  69. uchar active; /* listed for examination by interrupts */
  70. int setin;
  71. /* ISO related: */
  72. int hz;
  73. int remain; /* for packet size calculations */
  74. int samplesz;
  75. int sched; /* schedule index; -1 if undefined or aperiodic */
  76. int pollms; /* polling interval in msec */
  77. int psize; /* (remaining) size of this packet */
  78. int off; /* offset into packet */
  79. /* Real-time iso stuff */
  80. ulong foffset; /* file offset (to detect seeks) */
  81. ulong poffset; /* offset of next packet to be queued */
  82. ulong toffset; /* offset associated with time */
  83. vlong time; /* time associated with offset */
  84. int buffered; /* bytes captured but unread, or written but unsent */
  85. /* end ISO stuff */
  86. ulong bw; /* bandwidth requirement (OHCI) */
  87. Udev* dev; /* owning device */
  88. ulong nbytes;
  89. ulong nblocks;
  90. void *private;
  91. /*
  92. * all the rest could (should?) move to the driver private structure;
  93. * except perhaps err.
  94. */
  95. QLock rlock;
  96. Rendez rr;
  97. Queue* rq;
  98. QLock wlock;
  99. Rendez wr;
  100. Queue* wq;
  101. int ntd;
  102. char* err; /* needs to be global for unstall; fix? */
  103. Endpt* activef; /* active endpoint list */
  104. };
  105. /* OHCI endpoint modes */
  106. enum {
  107. Nomode,
  108. Ctlmode,
  109. Bulkmode,
  110. Intrmode
  111. };
  112. /* device parameters */
  113. enum
  114. {
  115. /* Udev.state */
  116. Disabled = 0,
  117. Attached,
  118. Enabled,
  119. Assigned,
  120. Configured,
  121. /* Udev.class */
  122. Noclass = 0,
  123. Hubclass = 9,
  124. };
  125. /*
  126. * active USB device
  127. */
  128. struct Udev
  129. {
  130. Ref;
  131. Lock;
  132. Usbhost *uh;
  133. int x; /* index in usbdev[] */
  134. int busy;
  135. int state;
  136. int id;
  137. uchar port; /* port number on connecting hub */
  138. ulong csp;
  139. ushort vid; /* vendor id */
  140. ushort did; /* product id */
  141. int ls;
  142. int npt;
  143. Endpt* ep[16]; /* active end points */
  144. Udev* ports; /* active ports, if hub */
  145. Udev* next; /* next device on this hub */
  146. };
  147. /*
  148. * One of these per active Host Controller Interface (HCI)
  149. */
  150. struct Usbhost
  151. {
  152. ISAConf; /* hardware info */
  153. int tbdf; /* type+busno+devno+funcno */
  154. QLock; /* protects namespace state */
  155. int idgen; /* version # to distinguish new connections */
  156. Udev* dev[MaxUsbDev]; /* device endpoints managed by this HCI */
  157. void (*init)(Usbhost*);
  158. void (*interrupt)(Ureg*, void*);
  159. void (*portinfo)(Usbhost*, char*, char*);
  160. void (*portreset)(Usbhost*, int);
  161. void (*portenable)(Usbhost*, int, int);
  162. void (*epalloc)(Usbhost*, Endpt*);
  163. void (*epfree)(Usbhost*, Endpt*);
  164. void (*epopen)(Usbhost*, Endpt*);
  165. void (*epclose)(Usbhost*, Endpt*);
  166. void (*epmode)(Usbhost*, Endpt*);
  167. long (*read)(Usbhost*, Endpt*, void*, long, vlong);
  168. long (*write)(Usbhost*, Endpt*, void*, long, vlong, int);
  169. void *ctlr;
  170. int tokin;
  171. int tokout;
  172. int toksetup;
  173. };
  174. extern void addusbtype(char*, int(*)(Usbhost*));