Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/include/usb/host/hcd.h

    r68e5406 r944f8fdd  
    3737#define LIBUSBHOST_HOST_HCD_H
    3838
    39 #include <usb/host/endpoint.h>
    40 #include <usb/host/usb_bus.h>
    41 #include <usb/host/usb_transfer_batch.h>
    42 #include <usb/usb.h>
     39#include <ddf/driver.h>
     40#include <usb/request.h>
    4341
    44 #include <assert.h>
    45 #include <usbhc_iface.h>
    46 #include <stddef.h>
    47 #include <stdint.h>
     42typedef struct hw_resource_list_parsed hw_res_list_parsed_t;
     43typedef struct bus bus_t;
     44typedef struct device device_t;
    4845
    49 typedef struct hcd hcd_t;
     46/* Treat this header as read-only in driver code.
     47 * It could be opaque, but why to complicate matters.
     48 */
     49typedef struct hc_device {
     50        /* Bus instance */
     51        bus_t *bus;
    5052
    51 typedef int (*schedule_hook_t)(hcd_t *, usb_transfer_batch_t *);
    52 typedef int (*ep_add_hook_t)(hcd_t *, endpoint_t *);
    53 typedef void (*ep_remove_hook_t)(hcd_t *, endpoint_t *);
    54 typedef void (*interrupt_hook_t)(hcd_t *, uint32_t);
    55 typedef int (*status_hook_t)(hcd_t *, uint32_t *);
     53        /* Managed DDF device */
     54        ddf_dev_t *ddf_dev;
    5655
    57 typedef struct {
    58         /** Transfer scheduling, implement in device driver. */
    59         schedule_hook_t schedule;
    60         /** Hook called upon registering new endpoint. */
    61         ep_add_hook_t ep_add_hook;
    62         /** Hook called upon removing of an endpoint. */
    63         ep_remove_hook_t ep_remove_hook;
    64         /** Hook to be called on device interrupt, passes ARG1 */
    65         interrupt_hook_t irq_hook;
    66         /** Periodic polling hook */
    67         status_hook_t status_hook;
    68 } hcd_ops_t;
     56        /* Control function */
     57        ddf_fun_t *ctl_fun;
    6958
    70 /** Generic host controller driver structure. */
    71 struct hcd {
    72         /** Endpoint manager. */
    73         usb_bus_t bus;
     59        /* Result of enabling HW IRQs */
     60        int irq_cap;
    7461
    7562        /** Interrupt replacement fibril */
    7663        fid_t polling_fibril;
    7764
    78         /** Driver implementation */
    79         hcd_ops_t ops;
    80         /** Device specific driver data. */
    81         void * driver_data;
    82 };
     65        /* This structure is meant to be extended by driver code. */
     66} hc_device_t;
    8367
    84 extern void hcd_init(hcd_t *, usb_speed_t, size_t, bw_count_func_t);
     68typedef struct hc_driver {
     69        const char *name;
    8570
    86 static inline void hcd_set_implementation(hcd_t *hcd, void *data,
    87     const hcd_ops_t *ops)
    88 {
    89         assert(hcd);
    90         if (ops) {
    91                 hcd->driver_data = data;
    92                 hcd->ops = *ops;
    93         } else {
    94                 memset(&hcd->ops, 0, sizeof(hcd->ops));
    95         }
     71        /** Size of the device data to be allocated, and passed as the
     72         * hc_device_t. */
     73        size_t hc_device_size;
     74
     75        /** Initialize device structures. */
     76        int (*hc_add)(hc_device_t *, const hw_res_list_parsed_t *);
     77
     78        /** Generate IRQ code to handle interrupts. */
     79        int (*irq_code_gen)(irq_code_t *, hc_device_t *, const hw_res_list_parsed_t *);
     80
     81        /** Claim device from BIOS. */
     82        int (*claim)(hc_device_t *);
     83
     84        /** Start the host controller. */
     85        int (*start)(hc_device_t *);
     86
     87        /** Setup the virtual roothub. */
     88        int (*setup_root_hub)(hc_device_t *);
     89
     90        /** Stop the host controller (after start has been called) */
     91        int (*stop)(hc_device_t *);
     92
     93        /** HC was asked to be removed (after hc_add has been called) */
     94        int (*hc_remove)(hc_device_t *);
     95
     96        /** HC is gone. */
     97        int (*hc_gone)(hc_device_t *);
     98} hc_driver_t;
     99
     100/* Drivers should call this before leaving hc_add */
     101static inline void hc_device_setup(hc_device_t *hcd, bus_t *bus) {
     102        hcd->bus = bus;
    96103}
    97104
    98 static inline void * hcd_get_driver_data(hcd_t *hcd)
     105static inline hc_device_t *dev_to_hcd(ddf_dev_t *dev)
    99106{
    100         assert(hcd);
    101         return hcd->driver_data;
     107        return ddf_dev_data_get(dev);
    102108}
    103109
    104 extern int hcd_request_address(hcd_t *, usb_speed_t, usb_address_t *);
    105 
    106 extern int hcd_release_address(hcd_t *, usb_address_t);
    107 
    108 extern int hcd_reserve_default_address(hcd_t *, usb_speed_t);
    109 
    110 static inline int hcd_release_default_address(hcd_t *hcd)
    111 {
    112         return hcd_release_address(hcd, USB_ADDRESS_DEFAULT);
    113 }
    114 
    115 extern int hcd_add_ep(hcd_t *, usb_target_t, usb_direction_t,
    116     usb_transfer_type_t, size_t, unsigned int, size_t, usb_address_t,
    117     unsigned int);
    118 
    119 extern int hcd_remove_ep(hcd_t *, usb_target_t, usb_direction_t);
    120 
    121 extern int hcd_send_batch(hcd_t *, usb_target_t, usb_direction_t, void *,
    122     size_t, uint64_t, usbhc_iface_transfer_in_callback_t,
    123     usbhc_iface_transfer_out_callback_t, void *, const char *);
    124 
    125 extern int hcd_send_batch_sync(hcd_t *, usb_target_t, usb_direction_t,
    126     void *, size_t, uint64_t, const char *, size_t *);
     110int hc_driver_main(const hc_driver_t *);
    127111
    128112#endif
Note: See TracChangeset for help on using the changeset viewer.