usb.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. int data01; /* 0=DATA0, 1=DATA1 */
  41. uchar eof;
  42. ulong csp;
  43. uchar mode; /* OREAD, OWRITE, ORDWR */
  44. uchar nbuf; /* number of buffers allowed */
  45. uchar iso;
  46. uchar debug;
  47. uchar active; /* listed for examination by interrupts */
  48. int setin;
  49. /* ISO related: */
  50. int hz;
  51. int remain; /* for packet size calculations */
  52. int samplesz;
  53. int sched; /* schedule index; -1 if undefined or aperiodic */
  54. int pollms; /* polling interval in msec */
  55. int psize; /* (remaining) size of this packet */
  56. int off; /* offset into packet */
  57. /* Real-time iso stuff */
  58. ulong foffset; /* file offset (to detect seeks) */
  59. ulong poffset; /* offset of next packet to be queued */
  60. ulong toffset; /* offset associated with time */
  61. vlong time; /* timeassociated with offset */
  62. int buffered; /* bytes captured but unread, or written but unsent */
  63. /* end ISO stuff */
  64. Udev* dev; /* owning device */
  65. ulong nbytes;
  66. ulong nblocks;
  67. void *private;
  68. // all the rest could (should?) move to the driver private structure; except perhaps err
  69. QLock rlock;
  70. Rendez rr;
  71. Queue* rq;
  72. QLock wlock;
  73. Rendez wr;
  74. Queue* wq;
  75. int ntd;
  76. char* err; // needs to be global for unstall; fix?
  77. Endpt* activef; /* active endpoint list */
  78. };
  79. /* device parameters */
  80. enum
  81. {
  82. /* Udev.state */
  83. Disabled = 0,
  84. Attached,
  85. Enabled,
  86. Assigned,
  87. Configured,
  88. /* Udev.class */
  89. Noclass = 0,
  90. Hubclass = 9,
  91. };
  92. /*
  93. * active USB device
  94. */
  95. struct Udev
  96. {
  97. Ref;
  98. Lock;
  99. Usbhost *uh;
  100. int x; /* index in usbdev[] */
  101. int busy;
  102. int state;
  103. int id;
  104. uchar port; /* port number on connecting hub */
  105. ulong csp;
  106. int ls;
  107. int npt;
  108. Endpt* ep[16]; /* active end points */
  109. Udev* ports; /* active ports, if hub */
  110. Udev* next; /* next device on this hub */
  111. };
  112. /*
  113. * One of these per active Host Controller Interface (HCI)
  114. */
  115. struct Usbhost
  116. {
  117. ISAConf; /* hardware info */
  118. int tbdf; /* type+busno+devno+funcno */
  119. QLock; /* protects namespace state */
  120. int idgen; /* version number to distinguish new connections */
  121. Udev* dev[MaxUsbDev]; /* device endpoints managed by this HCI */
  122. void (*init)(Usbhost*);
  123. void (*interrupt)(Ureg*, void*);
  124. void (*portinfo)(Usbhost*, char*, char*);
  125. void (*portreset)(Usbhost*, int);
  126. void (*portenable)(Usbhost*, int, int);
  127. void (*epalloc)(Usbhost*, Endpt*);
  128. void (*epfree)(Usbhost*, Endpt*);
  129. void (*epopen)(Usbhost*, Endpt*);
  130. void (*epclose)(Usbhost*, Endpt*);
  131. void (*epmode)(Usbhost*, Endpt*);
  132. long (*read)(Usbhost*, Endpt*, void*, long, vlong);
  133. long (*write)(Usbhost*, Endpt*, void*, long, vlong, int);
  134. void *ctlr;
  135. };
  136. extern void addusbtype(char*, int(*)(Usbhost*));