Subversion Repositories Kolibri OS

Rev

Rev 1029 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. typedef struct list_head  list_t;
  3.  
  4.  
  5. typedef struct {
  6.   int     available;          /**< Count of available items in this slab. */
  7.   void   *start;              /**< Start address of first item. */
  8.   addr_t  nextavail;          /**< The index of next available item. */
  9.   addr_t  dma;
  10. } slab_t;
  11.  
  12.  
  13. #define USB_CLASS_AUDIO                    1
  14. #define USB_CLASS_COMM                     2
  15. #define USB_CLASS_HID                      3
  16. #define USB_CLASS_PHYSICAL                 5
  17. #define USB_CLASS_STILL_IMAGE              6
  18. #define USB_CLASS_PRINTER                  7
  19. #define USB_CLASS_MASS_STORAGE             8
  20. #define USB_CLASS_HUB                      9
  21. #define USB_CLASS_CDC_DATA              0x0a
  22. #define USB_CLASS_CSCID                 0x0b    /* chip+ smart card */
  23. #define USB_CLASS_CONTENT_SEC           0x0d    /* content security */
  24. #define USB_CLASS_VIDEO                 0x0e
  25. #define USB_CLASS_WIRELESS_CONTROLLER   0xe0
  26. #define USB_CLASS_MISC                  0xef
  27. #define USB_CLASS_APP_SPEC              0xfe
  28. #define USB_CLASS_VENDOR_SPEC           0xff
  29.  
  30.  
  31. typedef struct
  32. {
  33.     addr_t  qlink;
  34.     addr_t  qelem;
  35.  
  36.     addr_t  dma;
  37.     u32_t   r1;
  38.  
  39. }qh_t __attribute__((aligned(16)));
  40.  
  41. typedef struct
  42. {
  43.     list_t  list;
  44.  
  45.     addr_t  iobase;
  46.  
  47.     u32_t   *frame_base;
  48.     count_t frame_number;
  49.     addr_t  frame_dma;
  50.  
  51.     qh_t   *qh1;
  52.  
  53.     u32_t  *data;
  54.     addr_t  data_dma;
  55.  
  56.     u32_t   port_map;
  57.  
  58.     int     numports;
  59.  
  60.     u32_t   pciId;
  61.     PCITAG  PciTag;
  62.     addr_t  ioBase[6];
  63.     addr_t  memBase[6];
  64.     size_t  memSize[6];
  65.     u32_t   memType[6];
  66. }hc_t;
  67.  
  68. typedef struct tag_td
  69. {
  70.         /* Hardware fields */
  71.     addr_t   link;
  72.     u32_t    status;
  73.     u32_t    token;
  74.     addr_t   buffer;
  75.  
  76.         /* Software fields */
  77.     addr_t   dma;
  78.  
  79.     struct   tag_td *bk;
  80.  
  81.   //  struct list_head list;
  82.  
  83.   //  int frame;          /* for iso: what frame? */
  84.   //  struct list_head fl_list;
  85.  
  86.     u32_t    reserved[2];
  87. } td_t __attribute__((aligned(16)));
  88.  
  89. #define TD_CTRL_SPD         (1 << 29)   /* Short Packet Detect */
  90. #define TD_CTRL_C_ERR_MASK      (3 << 27)       /* Error Counter bits */
  91. #define TD_CTRL_C_ERR_SHIFT     27
  92. #define TD_CTRL_LS          (1 << 26)   /* Low Speed Device */
  93. #define TD_CTRL_IOS         (1 << 25)   /* Isochronous Select */
  94. #define TD_CTRL_IOC         (1 << 24)   /* Interrupt on Complete */
  95. #define TD_CTRL_ACTIVE          (1 << 23)       /* TD Active */
  96. #define TD_CTRL_STALLED         (1 << 22)       /* TD Stalled */
  97. #define TD_CTRL_DBUFERR         (1 << 21)       /* Data Buffer Error */
  98. #define TD_CTRL_BABBLE          (1 << 20)       /* Babble Detected */
  99. #define TD_CTRL_NAK         (1 << 19)   /* NAK Received */
  100. #define TD_CTRL_CRCTIMEO        (1 << 18)       /* CRC/Time Out Error */
  101. #define TD_CTRL_BITSTUFF    (1 << 17)   /* Bit Stuff Error */
  102.  
  103. #define TD_ANY_ERROR   (TD_CTRL_STALLED | TD_CTRL_DBUFERR  | \
  104.                         TD_CTRL_BABBLE  | TD_CTRL_CRCTIMEO | \
  105.                         TD_CTRL_BITSTUFF)
  106.  
  107. typedef struct __attribute__ ((packed))
  108. {
  109.     u8_t    bLength;
  110.     u8_t    bDescriptorType;
  111.     u16_t   bcdUSB;
  112.  
  113.     u8_t    bDeviceClass;
  114.     u8_t    bDeviceSubClass;
  115.     u8_t    bDeviceProtocol;
  116.     u8_t    bMaxPacketSize0;
  117.  
  118.     u16_t   idVendor;
  119.     u16_t   idProduct;
  120.     u16_t   bcdDevice;
  121.  
  122.     u8_t    iManufacturer;
  123.     u8_t    iProduct;
  124.     u8_t    iSerialNumber;
  125.     u8_t    bNumConfigurations;
  126. }dev_descr_t;
  127.  
  128. typedef struct  __attribute__ ((packed))
  129. {
  130.     u8_t    bLength;
  131.     u8_t    bDescriptorType;
  132.     u16_t   wTotalLength;
  133.     u8_t    bNumInterfaces;
  134.     u8_t    bConfigurationValue;
  135.     u8_t    iConfiguration;
  136.     u8_t    bmAttributes;
  137.     u8_t    bMaxPower;
  138. }conf_descr_t;
  139.  
  140. typedef struct __attribute__ ((packed))
  141. {
  142.     u8_t    bLength;
  143.     u8_t    bDescriptorType;
  144.     u8_t    bInterfaceNumber;
  145.     u8_t    bAlternateSetting;
  146.     u8_t    bNumEndpoints;
  147.     u8_t    bInterfaceClass;
  148.     u8_t    bInterfaceSubClass;
  149.     u8_t    bInterfaceProtocol;
  150.     u8_t    iInterface;
  151. }interface_descr_t ;
  152.  
  153. typedef struct __attribute__ ((packed))
  154. {
  155.     u8_t    bLength;
  156.     u8_t    bDescriptorType;
  157.  
  158.     u8_t    bEndpointAddress;
  159.     u8_t    bmAttributes;
  160.     u16_t   wMaxPacketSize;
  161.     u8_t    bInterval;
  162.  
  163.         /* NOTE:  these two are _only_ in audio endpoints. */
  164.         /* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */
  165.     u8_t    bRefresh;
  166.     u8_t    bSynchAddress;
  167. }endpoint_descr_t;
  168.  
  169. typedef struct
  170. {
  171.     addr_t  address;
  172.     addr_t  size;
  173.     u32_t   toggle;
  174.  
  175. }endp_t;
  176.  
  177. typedef struct __attribute__ ((packed))
  178. {
  179.     u8_t    bRequestType;
  180.     u8_t    bRequest;
  181.     u16_t   wValue;
  182.     u16_t   wIndex;
  183.     u16_t   wLength;
  184. }ctrl_request_t;
  185.  
  186.  
  187. typedef struct
  188. {
  189.     list_t  list;
  190.     u32_t   id;
  191.  
  192.     hc_t   *host;
  193.  
  194.     u32_t   speed;
  195.     addr_t  addr;
  196.  
  197.     addr_t  ep0_size;
  198.  
  199.     endp_t  enp;
  200.  
  201.     u32_t   status;
  202.     int     port;
  203.  
  204.     dev_descr_t   dev_descr;
  205.     conf_descr_t  *conf;
  206. }udev_t;
  207.  
  208. typedef struct   tag_request
  209. {
  210.     list_t        list;
  211.     td_t         *td_head;
  212.     td_t         *td_tail;
  213.     addr_t        data;
  214.     size_t        size;
  215.     udev_t       *dev;
  216.     u32_t         type;
  217.     bool        (*handler)(udev_t *dev, struct   tag_request *rq);
  218. }request_t;
  219.  
  220.  
  221. #define  DMA(val) GetPgAddr(val)|(((addr_t)(val))&0xFFF)
  222.  
  223. #define  TOKEN( size, toggle, ep, addr, pid) \
  224.          ( (((size)-1)<<21)|(toggle)|(((ep)&0xF)<<15)|((addr)<<8)|(pid))
  225.  
  226. bool FindUSBControllers();
  227.  
  228. bool ctrl_request(udev_t *dev, void *req, u32_t dir,
  229.                   void *data, size_t req_size);
  230.  
  231. bool set_address(udev_t *dev);
  232.  
  233. bool init_device(udev_t *dev);
  234.  
  235. bool init_hid(udev_t *dev);
  236.  
  237. struct boot_packet
  238. {
  239.     u8_t  buttons;
  240.     char  x;
  241.     char  y;
  242.     char  z;
  243. }__attribute__ ((packed));
  244.  
  245. #define DOUT   0xE1
  246. #define DIN    0x69
  247.  
  248. #define DATA0  (0<<19)
  249. #define DATA1  (1<<19)
  250.  
  251.