usb.h 3.6 KB

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