Subversion Repositories Kolibri OS

Rev

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

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