Ignore:
Timestamp:
2017-12-18T22:50:21Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7f70d1c
Parents:
1ea0bbf
git-author:
Ondřej Hlavatý <aearsis@…> (2017-12-18 22:04:50)
git-committer:
Ondřej Hlavatý <aearsis@…> (2017-12-18 22:50:21)
Message:

usbhost: refactoring

This commit moves interrupt, status and schedule to bus
operations. Then the purpose of hcd_t is better defined, and split into
hc_driver_t and hc_device_t. hc_driver_t is used to wrap driver
implementation by the library (similar to how usb_driver_t is used to
wrap usb device drivers). hc_device_t is used as a parent for hc_t
inside drivers, and is allocated inside the DDF device node.

To support these changes, some local identifiers were renamed, some
functions were moved and/or renamed and their arguments changed. The
most notable one being hcd_send_batch → bus_device_send_batch.

File:
1 edited

Legend:

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

    r1ea0bbf r32fb6bce  
    3737#define LIBUSBHOST_HOST_HCD_H
    3838
    39 #include <assert.h>
    40 #include <mem.h>
    41 #include <stddef.h>
    42 #include <stdint.h>
    43 #include <usb/usb.h>
    44 #include <usbhc_iface.h>
     39#include <ddf/driver.h>
     40#include <usb/request.h>
    4541
    46 typedef struct hcd hcd_t;
     42typedef struct hw_resource_list_parsed hw_res_list_parsed_t;
    4743typedef struct bus bus_t;
    4844typedef struct device device_t;
    49 typedef struct usb_transfer_batch usb_transfer_batch_t;
    5045
    51 typedef int (*schedule_hook_t)(hcd_t *, usb_transfer_batch_t *);
    52 typedef void (*interrupt_hook_t)(hcd_t *, uint32_t);
    53 typedef int (*status_hook_t)(hcd_t *, uint32_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;
    5452
    55 typedef struct {
    56         /** Transfer scheduling, implement in device driver. */
    57         schedule_hook_t schedule;
    58         /** Hook to be called on device interrupt, passes ARG1 */
    59         interrupt_hook_t irq_hook;
    60         /** Periodic polling hook */
    61         status_hook_t status_hook;
    62 } hcd_ops_t;
     53        /* Managed DDF device */
     54        ddf_dev_t *ddf_dev;
    6355
    64 /** Generic host controller driver structure. */
    65 struct hcd {
    66         /** Endpoint manager. */
    67         bus_t *bus;
     56        /* Control function */
     57        ddf_fun_t *ctl_fun;
     58
     59        /* Result of enabling HW IRQs */
     60        int irq_cap;
    6861
    6962        /** Interrupt replacement fibril */
    7063        fid_t polling_fibril;
    7164
    72         /** Driver implementation */
    73         hcd_ops_t ops;
     65        /* This structure is meant to be extended by driver code. */
     66} hc_device_t;
    7467
    75         /** Device specific driver data. */
    76         void * driver_data;
    77 };
     68typedef struct hc_driver {
     69        const char *name;
    7870
    79 extern void hcd_init(hcd_t *);
     71        /** Size of the device data to be allocated, and passed as the
     72         * hc_device_t. */
     73        size_t hc_device_size;
    8074
    81 static inline void hcd_set_implementation(hcd_t *hcd, void *data,
    82     const hcd_ops_t *ops, bus_t *bus)
    83 {
    84         assert(hcd);
    85         if (ops) {
    86                 hcd->driver_data = data;
    87                 hcd->ops = *ops;
    88                 hcd->bus = bus;
    89         } else {
    90                 memset(&hcd->ops, 0, sizeof(hcd->ops));
    91         }
     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;
    92103}
    93104
    94 static inline void * hcd_get_driver_data(hcd_t *hcd)
     105static inline hc_device_t *dev_to_hcd(ddf_dev_t *dev)
    95106{
    96         assert(hcd);
    97         return hcd->driver_data;
     107        return ddf_dev_data_get(dev);
    98108}
    99109
    100 extern int hcd_get_ep0_max_packet_size(uint16_t *, hcd_t *, device_t *);
     110int hc_driver_main(const hc_driver_t *);
     111
     112/* TODO: These are a kind of utility functions, they should probably go
     113 * somewhere else.
     114 */
     115extern int hcd_get_ep0_max_packet_size(uint16_t *, bus_t *, device_t *);
    101116extern void hcd_setup_device_tt(device_t *);
    102 
    103 extern int hcd_send_batch(hcd_t *, device_t *, usb_target_t,
    104     usb_direction_t direction, char *, size_t, uint64_t,
    105     usbhc_iface_transfer_callback_t, void *, const char *);
    106 
    107 extern ssize_t hcd_send_batch_sync(hcd_t *, device_t *, usb_target_t,
    108     usb_direction_t direction, char *, size_t, uint64_t,
    109     const char *);
    110117
    111118/** How many toggles need to be reset */
     
    116123} toggle_reset_mode_t;
    117124
     125extern toggle_reset_mode_t hcd_get_request_toggle_reset_mode(
     126    const usb_device_request_setup_packet_t *request);
     127
    118128#endif
    119129
Note: See TracChangeset for help on using the changeset viewer.