Ignore:
File:
1 edited

Legend:

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

    r944f8fdd r68e5406  
    3737#define LIBUSBHOST_HOST_HCD_H
    3838
    39 #include <ddf/driver.h>
    40 #include <usb/request.h>
     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>
    4143
    42 typedef struct hw_resource_list_parsed hw_res_list_parsed_t;
    43 typedef struct bus bus_t;
    44 typedef struct device device_t;
     44#include <assert.h>
     45#include <usbhc_iface.h>
     46#include <stddef.h>
     47#include <stdint.h>
    4548
    46 /* Treat this header as read-only in driver code.
    47  * It could be opaque, but why to complicate matters.
    48  */
    49 typedef struct hc_device {
    50         /* Bus instance */
    51         bus_t *bus;
     49typedef struct hcd hcd_t;
    5250
    53         /* Managed DDF device */
    54         ddf_dev_t *ddf_dev;
     51typedef int (*schedule_hook_t)(hcd_t *, usb_transfer_batch_t *);
     52typedef int (*ep_add_hook_t)(hcd_t *, endpoint_t *);
     53typedef void (*ep_remove_hook_t)(hcd_t *, endpoint_t *);
     54typedef void (*interrupt_hook_t)(hcd_t *, uint32_t);
     55typedef int (*status_hook_t)(hcd_t *, uint32_t *);
    5556
    56         /* Control function */
    57         ddf_fun_t *ctl_fun;
     57typedef 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;
    5869
    59         /* Result of enabling HW IRQs */
    60         int irq_cap;
     70/** Generic host controller driver structure. */
     71struct hcd {
     72        /** Endpoint manager. */
     73        usb_bus_t bus;
    6174
    6275        /** Interrupt replacement fibril */
    6376        fid_t polling_fibril;
    6477
    65         /* This structure is meant to be extended by driver code. */
    66 } hc_device_t;
     78        /** Driver implementation */
     79        hcd_ops_t ops;
     80        /** Device specific driver data. */
     81        void * driver_data;
     82};
    6783
    68 typedef struct hc_driver {
    69         const char *name;
     84extern void hcd_init(hcd_t *, usb_speed_t, size_t, bw_count_func_t);
    7085
    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 */
    101 static inline void hc_device_setup(hc_device_t *hcd, bus_t *bus) {
    102         hcd->bus = bus;
     86static 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        }
    10396}
    10497
    105 static inline hc_device_t *dev_to_hcd(ddf_dev_t *dev)
     98static inline void * hcd_get_driver_data(hcd_t *hcd)
    10699{
    107         return ddf_dev_data_get(dev);
     100        assert(hcd);
     101        return hcd->driver_data;
    108102}
    109103
    110 int hc_driver_main(const hc_driver_t *);
     104extern int hcd_request_address(hcd_t *, usb_speed_t, usb_address_t *);
     105
     106extern int hcd_release_address(hcd_t *, usb_address_t);
     107
     108extern int hcd_reserve_default_address(hcd_t *, usb_speed_t);
     109
     110static inline int hcd_release_default_address(hcd_t *hcd)
     111{
     112        return hcd_release_address(hcd, USB_ADDRESS_DEFAULT);
     113}
     114
     115extern 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
     119extern int hcd_remove_ep(hcd_t *, usb_target_t, usb_direction_t);
     120
     121extern 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
     125extern int hcd_send_batch_sync(hcd_t *, usb_target_t, usb_direction_t,
     126    void *, size_t, uint64_t, const char *, size_t *);
    111127
    112128#endif
Note: See TracChangeset for help on using the changeset viewer.