Ignore:
File:
1 edited

Legend:

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

    rae3a941 rb7fd2a0  
    11/*
    22 * Copyright (c) 2011 Jan Vesely
    3  * Copyright (c) 2018 Ondrej Hlavaty
    43 * All rights reserved.
    54 *
     
    3837#define LIBUSBHOST_HOST_HCD_H
    3938
    40 #include <ddf/driver.h>
    41 #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>
    4243
    43 typedef struct hw_resource_list_parsed hw_res_list_parsed_t;
    44 typedef struct bus bus_t;
    45 typedef struct device device_t;
     44#include <assert.h>
     45#include <usbhc_iface.h>
     46#include <stddef.h>
     47#include <stdint.h>
    4648
    47 /* Treat this header as read-only in driver code.
    48  * It could be opaque, but why to complicate matters.
    49  */
    50 typedef struct hc_device {
    51         /* Bus instance */
    52         bus_t *bus;
     49typedef struct hcd hcd_t;
    5350
    54         /* Managed DDF device */
    55         ddf_dev_t *ddf_dev;
     51typedef errno_t (*schedule_hook_t)(hcd_t *, usb_transfer_batch_t *);
     52typedef errno_t (*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 errno_t (*status_hook_t)(hcd_t *, uint32_t *);
    5656
    57         /* Control function */
    58         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;
    5969
    60         /* Result of enabling HW IRQs */
    61         int irq_cap;
     70/** Generic host controller driver structure. */
     71struct hcd {
     72        /** Endpoint manager. */
     73        usb_bus_t bus;
    6274
    6375        /** Interrupt replacement fibril */
    6476        fid_t polling_fibril;
    6577
    66         /* This structure is meant to be extended by driver code. */
    67 } hc_device_t;
     78        /** Driver implementation */
     79        hcd_ops_t ops;
     80        /** Device specific driver data. */
     81        void * driver_data;
     82};
    6883
    69 typedef struct hc_driver {
    70         const char *name;
     84extern void hcd_init(hcd_t *, usb_speed_t, size_t, bw_count_func_t);
    7185
    72         /** Size of the device data to be allocated, and passed as the
    73          * hc_device_t. */
    74         size_t hc_device_size;
    75 
    76         /** Initialize device structures. */
    77         int (*hc_add)(hc_device_t *, const hw_res_list_parsed_t *);
    78 
    79         /** Generate IRQ code to handle interrupts. */
    80         int (*irq_code_gen)(irq_code_t *, hc_device_t *,
    81             const hw_res_list_parsed_t *, int *);
    82 
    83         /** Claim device from BIOS. */
    84         int (*claim)(hc_device_t *);
    85 
    86         /** Start the host controller. */
    87         int (*start)(hc_device_t *);
    88 
    89         /** Setup the virtual roothub. */
    90         int (*setup_root_hub)(hc_device_t *);
    91 
    92         /** Stop the host controller (after start has been called) */
    93         int (*stop)(hc_device_t *);
    94 
    95         /** HC was asked to be removed (after hc_add has been called) */
    96         int (*hc_remove)(hc_device_t *);
    97 
    98         /** HC is gone. */
    99         int (*hc_gone)(hc_device_t *);
    100 } hc_driver_t;
    101 
    102 /* Drivers should call this before leaving hc_add */
    103 static inline void hc_device_setup(hc_device_t *hcd, bus_t *bus)
     86static inline void hcd_set_implementation(hcd_t *hcd, void *data,
     87    const hcd_ops_t *ops)
    10488{
    105         hcd->bus = bus;
     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        }
    10696}
    10797
    108 static inline hc_device_t *dev_to_hcd(ddf_dev_t *dev)
     98static inline void * hcd_get_driver_data(hcd_t *hcd)
    10999{
    110         return ddf_dev_data_get(dev);
     100        assert(hcd);
     101        return hcd->driver_data;
    111102}
    112103
    113 extern errno_t hc_driver_main(const hc_driver_t *);
     104extern errno_t hcd_request_address(hcd_t *, usb_speed_t, usb_address_t *);
     105
     106extern errno_t hcd_release_address(hcd_t *, usb_address_t);
     107
     108extern errno_t hcd_reserve_default_address(hcd_t *, usb_speed_t);
     109
     110static inline errno_t hcd_release_default_address(hcd_t *hcd)
     111{
     112        return hcd_release_address(hcd, USB_ADDRESS_DEFAULT);
     113}
     114
     115extern errno_t 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 errno_t hcd_remove_ep(hcd_t *, usb_target_t, usb_direction_t);
     120
     121extern errno_t 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 errno_t hcd_send_batch_sync(hcd_t *, usb_target_t, usb_direction_t,
     126    void *, size_t, uint64_t, const char *, size_t *);
    114127
    115128#endif
Note: See TracChangeset for help on using the changeset viewer.