Index: sys/compat/linuxkpi/common/include/linux/usb.h =================================================================== --- sys/compat/linuxkpi/common/include/linux/usb.h +++ sys/compat/linuxkpi/common/include/linux/usb.h @@ -55,6 +55,14 @@ .match_flags = USB_DEVICE_ID_MATCH_DEVICE, .idVendor = (vend), \ .idProduct = (prod) +#define USB_DEVICE_AND_INTERFACE_INFO(vend, prod, class, subclass, proto) \ + .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \ + .idVendor = (vend), \ + .idProduct = (prod), \ + .bInterfaceClass = (class), \ + .bInterfaceSubClass = (subclass), \ + .bInterfaceProtocol = (proto) + /* The "usb_driver" structure holds the Linux USB device driver * callbacks, and a pointer to device ID's which this entry should * match against. Usually this entry is exposed to the USB emulation @@ -107,9 +115,44 @@ * Definition of direction mask for * "bEndpointAddress" and "bmRequestType": */ -#define USB_DIR_MASK 0x80 -#define USB_DIR_OUT 0x00 /* write to USB device */ -#define USB_DIR_IN 0x80 /* read from USB device */ +#define USB_DIR_MASK UE_DIR_IN +#define USB_DIR_OUT UE_DIR_OUT /* write to USB device */ +#define USB_DIR_IN UE_DIR_IN /* read from USB device */ + +static inline bool +usb_endpoint_dir_in(const struct usb_endpoint_descriptor *ed) +{ + + return (UE_GET_DIR(ed->bEndpointAddress) == USB_DIR_IN); +} + +static inline bool +usb_endpoint_dir_out(const struct usb_endpoint_descriptor *ed) +{ + + return (UE_GET_DIR(ed->bEndpointAddress) == USB_DIR_OUT); +} + +static inline int +usb_endpoint_num(const struct usb_endpoint_descriptor *ed) +{ + + return (ed->bEndpointAddress & UE_ADDR); +} + +static inline bool +usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *ed) +{ + + return (UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK); +} + +static inline bool +usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *ed) +{ + + return (UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT); +} /* * Definition of type mask for @@ -275,6 +318,39 @@ struct usb_iso_packet_descriptor iso_frame_desc[]; /* (in) ISO ONLY */ }; +static inline void +usb_fill_control_urb(struct urb *urb, struct usb_device * udev, + /* unsigned int pipe */ struct usb_host_endpoint *ep, + uint8_t *setuppkt, uint8_t *transbuf, usb_size_t transbuflen, + usb_complete_t complete_cb_fn, void *ctx) +{ + + urb->dev = udev; +/* + * This seems to be unsigned int pipe in Linux based on calling code. + * Our macros using usb_find_host_endpoint() already return an *ep. + * So we change some code. + */ +/* urb->pipe = pipe; */ + urb->endpoint = ep; + urb->setup_packet = setuppkt; + urb->transfer_buffer = transbuf; + urb->transfer_buffer_length = transbuflen; + urb->complete = complete_cb_fn; + urb->context = ctx; +} + +#define USB_STATE_NOTATTACHED USB_STATE_DETACHED /* enum usb_dev_state */ + +/* libusb::struct usb_ctrl_setup */ +struct usb_ctrlrequest { + uint8_t bRequestType; + uint8_t bRequest; + uint16_t wValue; + uint16_t wIndex; + uint16_t wLength; +}; + /* various prototypes */ int usb_submit_urb(struct urb *urb, uint16_t mem_flags); @@ -315,4 +391,49 @@ #define interface_to_usbdev(intf) (intf)->linux_udev #define interface_to_bsddev(intf) (intf)->linux_udev +#define module_usb_driver(_driver) \ + \ +static inline void \ +_usb_init(void) \ +{ \ + \ + usb_linux_register(&_driver); \ +} \ + \ +static inline void \ +_usb_exit(void) \ +{ \ + \ + usb_linux_deregister(&_driver); \ +} \ + \ +module_init(_usb_init); \ +module_exit(_usb_exit) + + +static inline void * +usb_get_intfdata(struct usb_interface *intf) +{ + return (NULL); +} + +static inline struct usb_device * +usb_get_dev(struct usb_device *dev) +{ + + return (dev); +} + +static inline void +usb_put_dev(struct usb_device *dev) +{ + return; +} + +static inline int +usb_reset_device(struct usb_device *dev) +{ + return (-ENXIO); +} + #endif /* _USB_COMPAT_LINUX_H */