usbehci.h 6.5 KB

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