uhci.h 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #ifndef _UHCI_H
  2. #define _UHCI_H
  3. /*
  4. * The link pointer is multi use. Some fields are valid only for some uses.
  5. * In other cases, they must be 0
  6. *
  7. */
  8. #define MAX_POLLDEV 10
  9. #define MAX_TRANSACTIONS 10
  10. #define MAX_QUEUEHEAD 255
  11. #define MAX_TD 1024
  12. typedef struct link_pointer {
  13. unsigned long terminate:1;
  14. unsigned long queue:1;
  15. unsigned long depth:1;
  16. unsigned long reserved:1;
  17. unsigned long link:28;
  18. } __attribute__((packed)) link_pointer_t;
  19. extern link_pointer_t *frame_list[];
  20. void init_framelist(uchar dev);
  21. #define SETUP_TOKEN 0x2d
  22. #define IN_TOKEN 0x69
  23. #define OUT_TOKEN 0xe1
  24. #define CTRL_RETRIES 3
  25. #define CONTROL_STS_RETRIES 0
  26. // some port features
  27. #define PORT_CONNECTION 0
  28. #define PORT_ENABLE 1
  29. #define PORT_SUSPEND 2
  30. #define PORT_OVER_CURRENT 3
  31. #define PORT_RESET 4
  32. #define PORT_POWER 8
  33. #define PORT_LOW_SPEED 9
  34. #define C_PORT_CONNECTION 16
  35. #define C_PORT_ENABLE 17
  36. #define C_PORT_SUSPEND 18
  37. #define C_PORT_OVER_CURRENT 19
  38. #define C_PORT_RESET 20
  39. // features
  40. #define FEATURE_HALT 0
  41. typedef struct td {
  42. link_pointer_t link;
  43. unsigned long actual:11; // actual length
  44. unsigned long reserved2:5;
  45. // status/error flags
  46. unsigned long res1:1;
  47. unsigned long bitstuff:1;
  48. unsigned long crc:1;
  49. unsigned long nak:1;
  50. unsigned long babble:1;
  51. unsigned long buffer_error:1;
  52. unsigned long stall:1;
  53. unsigned long active:1;
  54. unsigned long interrupt:1; // interrupt on complete
  55. unsigned long isochronous:1;
  56. unsigned long lowspeed:1;
  57. unsigned long retrys:2;
  58. unsigned long detect_short:1;
  59. unsigned long reserved3:2;
  60. unsigned long packet_type:8; // one of in (0x69), out (0xe1) or setup (0x2d)
  61. unsigned long device_addr:7;
  62. unsigned long endpoint:4;
  63. unsigned long data_toggle:1;
  64. unsigned long reserved:1;
  65. unsigned long max_transfer:11; // misnamed. Desired length might be better
  66. void *buffer;
  67. unsigned long data[4]; // free use by driver
  68. } __attribute__((packed)) td_t;
  69. typedef struct queue_head {
  70. link_pointer_t bredth; // depth must = 0
  71. link_pointer_t depth; // depth may vary randomly, ignore
  72. unsigned long int udata[2];
  73. } __attribute__((packed)) queue_head_t;
  74. typedef struct transaction {
  75. queue_head_t *qh;
  76. td_t *td_list;
  77. struct transaction *next;
  78. } transaction_t;
  79. //#####################################################
  80. int wait_head( queue_head_t *head, int count);
  81. extern queue_head_t *free_qh;
  82. extern queue_head_t *queue_heads;
  83. queue_head_t *new_queue_head(void);
  84. void free_queue_head( queue_head_t *qh);
  85. void init_qh(void);
  86. extern td_t *free_td_list;
  87. extern td_t *tds;
  88. void init_td(void);
  89. td_t *new_td(void);
  90. td_t *find_last_td(td_t *td);
  91. void free_td( td_t *td);
  92. link_pointer_t *queue_end( queue_head_t *queue);
  93. void add_td( queue_head_t *head, td_t *td);
  94. extern transaction_t transactions[MAX_TRANSACTIONS];
  95. extern transaction_t *free_transactions;
  96. void init_transactions(void);
  97. void free_transaction( transaction_t *trans );
  98. transaction_t *new_transaction(td_t *td);
  99. transaction_t *add_transaction( transaction_t *trans, td_t *td);
  100. #define USBCMD(x) hc_base[x]
  101. #define USBSTS(x) (hc_base[x] + 0x02)
  102. #define USBINTR(x) (hc_base[x] + 0x04)
  103. #define FRNUM(x) ( hc_base[x] + 0x06)
  104. #define FLBASE(x) ( hc_base[x] + 0x08)
  105. #define SOFMOD(x) ( hc_base[x] + 0x0c)
  106. #define PORTSC1(x) ( hc_base[x] + 0x10)
  107. #define PORTSC2(x) ( hc_base[x] + 0x12)
  108. #define USBCMDRUN 0x01
  109. #define USBCMD_DEBUG 0x20
  110. #define USBSTSHALTED 0x20
  111. void hc_reset(uchar dev);
  112. int hc_stop(void);
  113. int hc_start(uchar dev);
  114. extern queue_head_t *sched_queue[];
  115. void init_sched(uchar dev);
  116. int poll_queue_head( queue_head_t *qh);
  117. int wait_queue_complete( queue_head_t *qh);
  118. extern int num_polls;
  119. extern int (*devpoll[MAX_POLLDEV])(uchar);
  120. extern uchar parm[MAX_POLLDEV];
  121. transaction_t *_bulk_transfer( uchar devnum, uchar ep, unsigned int len, uchar *data);
  122. transaction_t *ctrl_msg(uchar devnum, uchar request_type, uchar request, unsigned short wValue, unsigned short wIndex, unsigned short wLength, uchar *data);
  123. int schedule_transaction( uchar dev, transaction_t *trans);
  124. int wait_transaction( transaction_t *trans);
  125. void unlink_transaction( uchar dev, transaction_t *trans);
  126. int uhci_bulk_transfer( uchar devnum, uchar ep, unsigned int len, uchar *data);
  127. int uhci_control_msg( uchar devnum, uchar request_type, uchar request, unsigned short wValue, unsigned short wIndex, unsigned short wLength, void *data);
  128. // defined in uhci.c
  129. int uhc_init(struct pci_device *dev);
  130. void uhci_init(void);
  131. void clear_uport_stat(unsigned short port);
  132. int poll_u_root_hub(unsigned short port, uchar controller);
  133. #endif