Changeset 32fb6bce in mainline for uspace/lib/usbhost/include


Ignore:
Timestamp:
2017-12-18T22:50:21Z (8 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.

Location:
uspace/lib/usbhost/include/usb/host
Files:
5 edited

Legend:

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

    r1ea0bbf r32fb6bce  
    4343#define LIBUSBHOST_HOST_BUS_H
    4444
    45 #include <usb/usb.h>
    46 #include <usb/request.h>
    47 #include <usb/host/hcd.h>
    48 
    4945#include <assert.h>
    5046#include <fibril_synch.h>
    5147#include <stdbool.h>
     48#include <usb/host/hcd.h>
     49#include <usb/request.h>
     50#include <usb/usb.h>
     51#include <usbhc_iface.h>
    5252
    5353typedef struct hcd hcd_t;
     
    9494
    9595        /* Global operations on the bus */
     96        void (*interrupt)(bus_t *, uint32_t);
     97        int (*status)(bus_t *, uint32_t *);
    9698        int (*reserve_default_address)(bus_t *, usb_speed_t);
    9799        int (*release_default_address)(bus_t *);
     
    116118
    117119        /* Operations on batch */
    118         void (*batch_destroy)(usb_transfer_batch_t *);  /**< Optional */
     120        void (*batch_destroy)(usb_transfer_batch_t *);          /**< Optional */
     121        int (*batch_schedule)(usb_transfer_batch_t *);
    119122};
    120123
     
    129132        fibril_mutex_t guard;
    130133
    131         /* TODO: get rid of this one. */
    132         hcd_t *hcd;
    133 
     134        /* Size of the device_t extended structure */
    134135        size_t device_size;
    135136
     
    140141} bus_t;
    141142
    142 void bus_init(bus_t *, hcd_t *, size_t);
     143void bus_init(bus_t *, size_t);
    143144int bus_device_init(device_t *, bus_t *);
    144145
     
    150151int bus_device_online(device_t *);
    151152int bus_device_offline(device_t *);
     153
     154int bus_device_send_batch(device_t *, usb_target_t,
     155    usb_direction_t direction, char *, size_t, uint64_t,
     156    usbhc_iface_transfer_callback_t, void *, const char *);
     157
     158ssize_t bus_device_send_batch_sync(device_t *, usb_target_t,
     159    usb_direction_t direction, char *, size_t, uint64_t,
     160    const char *);
    152161
    153162int bus_endpoint_add(device_t *, const usb_endpoint_desc_t *, endpoint_t **);
  • uspace/lib/usbhost/include/usb/host/ddf_helpers.h

    r1ea0bbf r32fb6bce  
    3939#include <ddf/driver.h>
    4040#include <ddf/interrupt.h>
    41 #include <device/hw_res_parsed.h>
    4241#include <usb/usb.h>
    4342
    4443#include <usb/host/hcd.h>
    4544
    46 typedef int (*driver_init_t)(hcd_t *, const hw_res_list_parsed_t *, ddf_dev_t *);
    47 typedef int (*irq_code_gen_t)(irq_code_t *, hcd_t *, const hw_res_list_parsed_t *);
    48 typedef int (*claim_t)(hcd_t *, ddf_dev_t *);
    49 typedef int (*driver_start_t)(hcd_t *, bool irq);
    50 typedef int (*setup_root_hub_t)(hcd_t *, ddf_dev_t *);
     45int hcd_ddf_setup_hc(ddf_dev_t *, size_t);
     46void hcd_ddf_clean_hc(hc_device_t *);
    5147
    52 typedef void (*driver_stop_t)(hcd_t *);
    53 typedef void (*driver_fini_t)(hcd_t *);
     48int hcd_setup_virtual_root_hub(hc_device_t *);
    5449
    55 /**
    56  * All callbacks are optional.
    57  */
    58 typedef struct {
    59         hcd_ops_t ops;
    60         const char *name;
     50device_t *hcd_ddf_fun_create(hc_device_t *);
     51void hcd_ddf_fun_destroy(device_t *);
    6152
    62         interrupt_handler_t *irq_handler;  /**< Handler of IRQ. Do have generic implementation. */
     53int hcd_device_explore(device_t *);
    6354
    64         /* Initialization sequence: */
    65         driver_init_t init;                /**< Initialize internal structures, memory */
    66         claim_t claim;                     /**< Claim device from BIOS */
    67         irq_code_gen_t irq_code_gen;       /**< Generate IRQ handling code */
    68         driver_start_t start;              /**< Start the HC */
    69         setup_root_hub_t setup_root_hub;   /**< Setup the root hub */
     55int hcd_ddf_enable_interrupt(hc_device_t *hcd, int);
     56int hcd_ddf_get_registers(hc_device_t *hcd, hw_res_list_parsed_t *hw_res);
    7057
    71         /* Destruction sequence: */
    72         driver_stop_t stop;                /**< Stop the HC (counterpart of start) */
    73         driver_fini_t fini;                /**< Destroy internal structures (counterpart of init) */
    74 } ddf_hc_driver_t;
    75 
    76 int hcd_ddf_add_hc(ddf_dev_t *device, const ddf_hc_driver_t *driver);
    77 
    78 int hcd_ddf_setup_hc(ddf_dev_t *device);
    79 void hcd_ddf_clean_hc(ddf_dev_t *device);
    80 
    81 int hcd_setup_virtual_root_hub(hcd_t *, ddf_dev_t *);
    82 
    83 device_t *hcd_ddf_device_create(ddf_dev_t *, bus_t *);
    84 void hcd_ddf_device_destroy(device_t *);
    85 int hcd_ddf_device_explore(device_t *);
    86 int hcd_ddf_device_online(ddf_fun_t *);
    87 int hcd_ddf_device_offline(ddf_fun_t *);
    88 
    89 hcd_t *dev_to_hcd(ddf_dev_t *dev);
    90 
    91 int hcd_ddf_enable_interrupt(ddf_dev_t *device, int);
    92 int hcd_ddf_get_registers(ddf_dev_t *device, hw_res_list_parsed_t *hw_res);
    93 int hcd_ddf_setup_interrupts(ddf_dev_t *device,
    94     const hw_res_list_parsed_t *hw_res,
    95     interrupt_handler_t handler,
    96     irq_code_gen_t gen_irq_code);
    97 void ddf_hcd_gen_irq_handler(ipc_callid_t iid, ipc_call_t *call, ddf_dev_t *dev);
     58void hcd_ddf_gen_irq_handler(ipc_callid_t iid, ipc_call_t *call, ddf_dev_t *dev);
    9859
    9960#endif
  • uspace/lib/usbhost/include/usb/host/endpoint.h

    r1ea0bbf r32fb6bce  
    109109ssize_t endpoint_count_bw(endpoint_t *, size_t);
    110110
     111int endpoint_send_batch(endpoint_t *, usb_target_t, usb_direction_t,
     112    char *, size_t, uint64_t, usbhc_iface_transfer_callback_t, void *,
     113    const char *);
     114
    111115static inline bus_t *endpoint_get_bus(endpoint_t *ep)
    112116{
  • 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
  • uspace/lib/usbhost/include/usb/host/usb2_bus.h

    r1ea0bbf r32fb6bce  
    6666extern const bus_ops_t usb2_bus_ops;
    6767
    68 extern int usb2_bus_init(usb2_bus_t *, hcd_t *, size_t);
     68extern int usb2_bus_init(usb2_bus_t *, size_t);
    6969
    7070#endif
Note: See TracChangeset for help on using the changeset viewer.