usbehci.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* override default macros from ../port/usb.h */
  2. #undef dprint
  3. #undef ddprint
  4. #undef deprint
  5. #undef ddeprint
  6. #define dprint if(ehcidebug)print
  7. #define ddprint if(ehcidebug>1)print
  8. #define deprint if(ehcidebug || ep->debug)print
  9. #define ddeprint if(ehcidebug>1 || ep->debug>1)print
  10. typedef struct Ctlr Ctlr;
  11. typedef struct Ecapio Ecapio;
  12. typedef struct Edbgio Edbgio;
  13. typedef struct Eopio Eopio;
  14. typedef struct Isoio Isoio;
  15. typedef struct Poll Poll;
  16. typedef struct Qh Qh;
  17. typedef struct Qtree Qtree;
  18. #pragma incomplete Ctlr;
  19. #pragma incomplete Ecapio;
  20. #pragma incomplete Edbgio;
  21. #pragma incomplete Eopio;
  22. #pragma incomplete Isoio;
  23. #pragma incomplete Poll;
  24. #pragma incomplete Qh;
  25. #pragma incomplete Qtree;
  26. /*
  27. * EHCI interface registers and bits
  28. */
  29. enum
  30. {
  31. /* Ecapio->parms reg. */
  32. Cnports = 0xF, /* nport bits */
  33. Cdbgportshift = 20, /* debug port */
  34. Cdbgportmask = 0xF,
  35. /* Ecapio->capparms bits */
  36. C64 = 1<<0, /* 64-bits */
  37. Cpfl = 1<<1, /* program'ble frame list: can be <1024 */
  38. Casp = 1<<2, /* asynch. sched. park */
  39. Ceecpshift = 8, /* extended capabilities ptr. */
  40. Ceecpmask = (1<<8) - 1,
  41. Clegacy = 1, /* legacy support cap. id */
  42. CLbiossem = 2, /* legacy cap. bios sem. */
  43. CLossem = 3, /* legacy cap. os sem */
  44. CLcontrol = 4, /* legacy support control & status */
  45. /* typed links */
  46. Lterm = 1,
  47. Litd = 0<<1,
  48. Lqh = 1<<1,
  49. Lsitd = 2<<1,
  50. Lfstn = 3<<1, /* we don't use these */
  51. /* Cmd reg. */
  52. Cstop = 0x00000, /* stop running */
  53. Crun = 0x00001, /* start operation */
  54. Chcreset = 0x00002, /* host controller reset */
  55. Cflsmask = 0x0000C, /* frame list size bits */
  56. Cfls1024 = 0x00000, /* frame list size 1024 */
  57. Cfls512 = 0x00004, /* frame list size 512 frames */
  58. Cfls256 = 0x00008, /* frame list size 256 frames */
  59. Cpse = 0x00010, /* periodic sched. enable */
  60. Case = 0x00020, /* async sched. enable */
  61. Ciasync = 0x00040, /* interrupt on async advance doorbell */
  62. Citc1 = 0x10000, /* interrupt threshold ctl. 1 µframe */
  63. Citc4 = 0x40000, /* same. 2 µframes */
  64. /* ... */
  65. Citc8 = 0x80000, /* same. 8 µframes (can go up to 64) */
  66. /* Sts reg. */
  67. Sasyncss = 0x08000, /* aync schedule status */
  68. Speriodss = 0x04000, /* periodic schedule status */
  69. Srecl = 0x02000, /* reclamnation (empty async sched.) */
  70. Shalted = 0x01000, /* h.c. is halted */
  71. Sasync = 0x00020, /* interrupt on async advance */
  72. Sherr = 0x00010, /* host system error */
  73. Sfrroll = 0x00008, /* frame list roll over */
  74. Sportchg = 0x00004, /* port change detect */
  75. Serrintr = 0x00002, /* error interrupt */
  76. Sintr = 0x00001, /* interrupt */
  77. Sintrs = 0x0003F, /* interrupts status */
  78. /* Intr reg. */
  79. Iusb = 0x01, /* intr. on usb */
  80. Ierr = 0x02, /* intr. on usb error */
  81. Iportchg = 0x04, /* intr. on port change */
  82. Ifrroll = 0x08, /* intr. on frlist roll over */
  83. Ihcerr = 0x10, /* intr. on host error */
  84. Iasync = 0x20, /* intr. on async advance enable */
  85. Iall = 0x3F, /* all interrupts */
  86. /* Config reg. */
  87. Callmine = 1, /* route all ports to us */
  88. /* Portsc reg. */
  89. Pspresent = 0x00000001, /* device present */
  90. Psstatuschg = 0x00000002, /* Pspresent changed */
  91. Psenable = 0x00000004, /* device enabled */
  92. Pschange = 0x00000008, /* Psenable changed */
  93. Psresume = 0x00000040, /* resume detected */
  94. Pssuspend = 0x00000080, /* port suspended */
  95. Psreset = 0x00000100, /* port reset */
  96. Pspower = 0x00001000, /* port power on */
  97. Psowner = 0x00002000, /* port owned by companion */
  98. Pslinemask = 0x00000C00, /* line status bits */
  99. Pslow = 0x00000400, /* low speed device */
  100. /* Debug port csw reg. */
  101. Cowner = 0x40000000, /* port owned by ehci */
  102. Cenable = 0x10000000, /* debug port enabled */
  103. Cdone = 0x00010000, /* request is done */
  104. Cbusy = 0x00000400, /* port in use by a driver */
  105. Cerrmask= 0x00000380, /* error code bits */
  106. Chwerr = 0x00000100, /* hardware error */
  107. Cterr = 0x00000080, /* transaction error */
  108. Cfailed = 0x00000040, /* transaction did fail */
  109. Cgo = 0x00000020, /* execute the transaction */
  110. Cwrite = 0x00000010, /* request is a write */
  111. Clen = 0x0000000F, /* data len */
  112. /* Debug port pid reg. */
  113. Prpidshift = 16, /* received pid */
  114. Prpidmask = 0xFF,
  115. Pspidshift = 8, /* sent pid */
  116. Pspidmask = 0xFF,
  117. Ptokshift = 0, /* token pid */
  118. Ptokmask = 0xFF,
  119. Ptoggle = 0x00008800, /* to update toggles */
  120. Ptogglemask = 0x0000FF00,
  121. /* Debug port addr reg. */
  122. Adevshift = 8, /* device address */
  123. Adevmask = 0x7F,
  124. Aepshift = 0, /* endpoint number */
  125. Aepmask = 0xF,
  126. };
  127. /*
  128. * Capability registers (hw)
  129. */
  130. struct Ecapio
  131. {
  132. ulong cap; /* 00 controller capability register */
  133. ulong parms; /* 04 structural parameters register */
  134. ulong capparms; /* 08 capability parameters */
  135. ulong portroute; /* 0c not on the CS5536 */
  136. };
  137. /*
  138. * Debug port registers (hw)
  139. */
  140. struct Edbgio
  141. {
  142. ulong csw; /* control and status */
  143. ulong pid; /* USB pid */
  144. uchar data[8]; /* data buffer */
  145. ulong addr; /* device and endpoint addresses */
  146. };
  147. struct Poll
  148. {
  149. Lock;
  150. Rendez;
  151. int must;
  152. int does;
  153. };
  154. struct Ctlr
  155. {
  156. Rendez; /* for waiting to async advance doorbell */
  157. Lock; /* for ilock. qh lists and basic ctlr I/O */
  158. QLock portlck; /* for port resets/enable... (and doorbell) */
  159. int active; /* in use or not */
  160. Pcidev* pcidev;
  161. Ecapio* capio; /* Capability i/o regs */
  162. Eopio* opio; /* Operational i/o regs */
  163. int nframes; /* 1024, 512, or 256 frames in the list */
  164. ulong* frames; /* periodic frame list (hw) */
  165. Qh* qhs; /* async Qh circular list for bulk/ctl */
  166. Qtree* tree; /* tree of Qhs for the periodic list */
  167. int ntree; /* number of dummy qhs in tree */
  168. Qh* intrqhs; /* list of (not dummy) qhs in tree */
  169. Isoio* iso; /* list of active Iso I/O */
  170. ulong load;
  171. ulong isoload;
  172. int nintr; /* number of interrupts attended */
  173. int ntdintr; /* number of intrs. with something to do */
  174. int nqhintr; /* number of async td intrs. */
  175. int nisointr; /* number of periodic td intrs. */
  176. int nreqs;
  177. Poll poll;
  178. };
  179. /*
  180. * PC-specific stuff
  181. */
  182. /*
  183. * Operational registers (hw)
  184. */
  185. struct Eopio
  186. {
  187. ulong cmd; /* 00 command */
  188. ulong sts; /* 04 status */
  189. ulong intr; /* 08 interrupt enable */
  190. ulong frno; /* 0c frame index */
  191. ulong seg; /* 10 bits 63:32 of EHCI datastructs (unused) */
  192. ulong frbase; /* 14 frame list base addr, 4096-byte boundary */
  193. ulong link; /* 18 link for async list */
  194. uchar d2c[0x40-0x1c]; /* 1c dummy */
  195. ulong config; /* 40 1: all ports default-routed to this HC */
  196. ulong portsc[1]; /* 44 Port status and control, one per port */
  197. };
  198. extern int ehcidebug;
  199. extern Ecapio *ehcidebugcapio;
  200. extern int ehcidebugport;
  201. void ehcilinkage(Hci *hp);
  202. void ehcimeminit(Ctlr *ctlr);
  203. void ehcirun(Ctlr *ctlr, int on);