usbehci.h 7.1 KB

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