Changeset b4b534ac in mainline for uspace/lib/usbhost/include


Ignore:
Timestamp:
2016-07-22T08:24:47Z (10 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f76d2c2
Parents:
5b18137 (diff), 8351f9a4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~jan.vesely/helenos/usb

Location:
uspace/lib/usbhost/include/usb/host
Files:
1 deleted
3 edited
3 moved

Legend:

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

    r5b18137 rb4b534ac  
    11/*
    2  * Copyright (c) 2011 Vojtech Horky
     2 * Copyright (c) 2012 Jan Vesely
    33 * All rights reserved.
    44 *
     
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbohci
     28
     29/** @addtogroup libusbhost
    2930 * @{
    3031 */
    3132/** @file
    32  * PCI related functions needed by OHCI driver.
     33 *
    3334 */
    34 #ifndef DRV_OHCI_RES_H
    35 #define DRV_OHCI_RES_H
     35
     36#ifndef LIBUSBHOST_HOST_DDF_HELPERS_H
     37#define LIBUSBHOST_HOST_DDF_HELPERS_H
     38
     39#include <usb/host/hcd.h>
     40#include <usb/host/usb_bus.h>
     41#include <usb/usb.h>
    3642
    3743#include <ddf/driver.h>
     44#include <ddf/interrupt.h>
    3845#include <device/hw_res_parsed.h>
    3946
    40 int get_my_registers(ddf_dev_t *, addr_range_t *, int *);
    41 int enable_interrupts(ddf_dev_t *);
     47typedef int (*driver_init_t)(hcd_t *, const hw_res_list_parsed_t *, bool);
     48typedef void (*driver_fini_t)(hcd_t *);
     49typedef int (*claim_t)(ddf_dev_t *);
     50typedef int (*irq_code_gen_t)(irq_code_t *, const hw_res_list_parsed_t *);
     51
     52typedef struct {
     53        hcd_ops_t ops;
     54        claim_t claim;
     55        usb_speed_t hc_speed;
     56        driver_init_t init;
     57        driver_fini_t fini;
     58        interrupt_handler_t *irq_handler;
     59        irq_code_gen_t irq_code_gen;
     60        const char *name;
     61} ddf_hc_driver_t;
     62
     63int hcd_ddf_add_hc(ddf_dev_t *device, const ddf_hc_driver_t *driver);
     64
     65int hcd_ddf_setup_hc(ddf_dev_t *device, usb_speed_t max_speed,
     66    size_t bw, bw_count_func_t bw_count);
     67void hcd_ddf_clean_hc(ddf_dev_t *device);
     68int hcd_ddf_setup_root_hub(ddf_dev_t *device);
     69
     70hcd_t *dev_to_hcd(ddf_dev_t *dev);
     71
     72int hcd_ddf_enable_interrupts(ddf_dev_t *device);
     73int hcd_ddf_get_registers(ddf_dev_t *device, hw_res_list_parsed_t *hw_res);
     74int hcd_ddf_setup_interrupts(ddf_dev_t *device,
     75    const hw_res_list_parsed_t *hw_res,
     76    interrupt_handler_t handler,
     77    int (*gen_irq_code)(irq_code_t *, const hw_res_list_parsed_t *));
     78void ddf_hcd_gen_irq_handler(ipc_callid_t iid, ipc_call_t *call, ddf_dev_t *dev);
    4279
    4380#endif
     81
    4482/**
    4583 * @}
    4684 */
    47 
  • uspace/lib/usbhost/include/usb/host/endpoint.h

    r5b18137 rb4b534ac  
    5757        /** Maximum size of data packets. */
    5858        size_t max_packet_size;
     59        /** Additional opportunities per uframe */
     60        unsigned packets;
    5961        /** Necessary bandwidth. */
    6062        size_t bandwidth;
     
    6769        /** Signals change of active status. */
    6870        fibril_condvar_t avail;
     71        /** High speed TT data */
     72        struct {
     73                usb_address_t address;
     74                unsigned port;
     75        } tt;
    6976        /** Optional device specific data. */
    7077        struct {
     
    8087endpoint_t * endpoint_create(usb_address_t address, usb_endpoint_t endpoint,
    8188    usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed,
    82     size_t max_packet_size, size_t bw);
     89    size_t max_packet_size, unsigned packets, size_t bw,
     90    usb_address_t tt_address, unsigned tt_port);
    8391void endpoint_destroy(endpoint_t *instance);
    8492
  • uspace/lib/usbhost/include/usb/host/hcd.h

    r5b18137 rb4b534ac  
    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>
     43
    3944#include <assert.h>
    4045#include <usbhc_iface.h>
    41 
    42 #include <usb/host/usb_device_manager.h>
    43 #include <usb/host/usb_endpoint_manager.h>
    44 #include <usb/host/usb_transfer_batch.h>
     46#include <sys/types.h>
    4547
    4648typedef struct hcd hcd_t;
    4749
     50typedef int (*schedule_hook_t)(hcd_t *, usb_transfer_batch_t *);
     51typedef int (*ep_add_hook_t)(hcd_t *, endpoint_t *);
     52typedef void (*ep_remove_hook_t)(hcd_t *, endpoint_t *);
     53typedef void (*interrupt_hook_t)(hcd_t *, uint32_t);
     54typedef int (*status_hook_t)(hcd_t *, uint32_t *);
     55
     56typedef struct {
     57        /** Transfer scheduling, implement in device driver. */
     58        schedule_hook_t schedule;
     59        /** Hook called upon registering new endpoint. */
     60        ep_add_hook_t ep_add_hook;
     61        /** Hook called upon removing of an endpoint. */
     62        ep_remove_hook_t ep_remove_hook;
     63        /** Hook to be called on device interrupt, passes ARG1 */
     64        interrupt_hook_t irq_hook;
     65        /** Periodic polling hook */
     66        status_hook_t status_hook;
     67} hcd_ops_t;
     68
    4869/** Generic host controller driver structure. */
    4970struct hcd {
    50         /** Device manager storing handles and addresses. */
    51         usb_device_manager_t dev_manager;
    5271        /** Endpoint manager. */
    53         usb_endpoint_manager_t ep_manager;
     72        usb_bus_t bus;
    5473
     74        /** Interrupt replacement fibril */
     75        fid_t polling_fibril;
     76
     77        /** Driver implementation */
     78        hcd_ops_t ops;
    5579        /** Device specific driver data. */
    56         void *private_data;
    57         /** Transfer scheduling, implement in device driver. */
    58         int (*schedule)(hcd_t *, usb_transfer_batch_t *);
    59         /** Hook called upon registering new endpoint. */
    60         int (*ep_add_hook)(hcd_t *, endpoint_t *);
    61         /** Hook called upon removing of an endpoint. */
    62         void (*ep_remove_hook)(hcd_t *, endpoint_t *);
     80        void * driver_data;
    6381};
    6482
    65 /** Initialize hcd_t structure.
    66  * Initializes device and endpoint managers. Sets data and hook pointer to NULL.
    67  * @param hcd hcd_t structure to initialize, non-null.
    68  * @param bandwidth Available bandwidth, passed to endpoint manager.
    69  * @param bw_count Bandwidth compute function, passed to endpoint manager.
    70  */
    71 static inline void hcd_init(hcd_t *hcd, usb_speed_t max_speed, size_t bandwidth,
    72     size_t (*bw_count)(usb_speed_t, usb_transfer_type_t, size_t, size_t))
     83void hcd_init(hcd_t *hcd, usb_speed_t max_speed, size_t bandwidth,
     84    bw_count_func_t bw_count);
     85
     86static inline void hcd_set_implementation(hcd_t *hcd, void *data,
     87    const hcd_ops_t *ops)
    7388{
    7489        assert(hcd);
    75         usb_device_manager_init(&hcd->dev_manager, max_speed);
    76         usb_endpoint_manager_init(&hcd->ep_manager, bandwidth, bw_count);
    77         hcd->private_data = NULL;
    78         hcd->schedule = NULL;
    79         hcd->ep_add_hook = NULL;
    80         hcd->ep_remove_hook = NULL;
     90        if (ops) {
     91                hcd->driver_data = data;
     92                hcd->ops = *ops;
     93        } else {
     94                memset(&hcd->ops, 0, sizeof(hcd->ops));
     95        }
    8196}
    8297
    83 /** Check registered endpoints and reset toggle bit if necessary.
    84  * @param hcd hcd_t structure, non-null.
    85  * @param target Control communication target.
    86  * @param setup_data Setup packet of the control communication.
    87  */
    88 static inline void reset_ep_if_need(hcd_t *hcd, usb_target_t target,
    89     const char setup_data[8])
     98static inline void * hcd_get_driver_data(hcd_t *hcd)
    9099{
    91100        assert(hcd);
    92         usb_endpoint_manager_reset_eps_if_need(
    93             &hcd->ep_manager, target, (const uint8_t *)setup_data);
     101        return hcd->driver_data;
    94102}
    95103
    96 /** Data retrieve wrapper.
    97  * @param fun ddf function, non-null.
    98  * @return pointer cast to hcd_t*.
    99  */
    100 static inline hcd_t *fun_to_hcd(ddf_fun_t *fun)
     104usb_address_t hcd_request_address(hcd_t *hcd, usb_speed_t speed);
     105
     106int hcd_release_address(hcd_t *hcd, usb_address_t address);
     107
     108int hcd_reserve_default_address(hcd_t *hcd, usb_speed_t speed);
     109
     110static inline int hcd_release_default_address(hcd_t *hcd)
    101111{
    102         return ddf_fun_data_get(fun);
     112        return hcd_release_address(hcd, USB_ADDRESS_DEFAULT);
    103113}
    104114
    105 extern usbhc_iface_t hcd_iface;
     115int hcd_add_ep(hcd_t *hcd, usb_target_t target, usb_direction_t dir,
     116    usb_transfer_type_t type, size_t max_packet_size, unsigned packets,
     117    size_t size, usb_address_t tt_address, unsigned tt_port);
     118
     119int hcd_remove_ep(hcd_t *hcd, usb_target_t target, usb_direction_t dir);
     120
     121int hcd_send_batch(hcd_t *hcd, usb_target_t target, usb_direction_t direction,
     122    void *data, size_t size, uint64_t setup_data,
     123    usbhc_iface_transfer_in_callback_t in,
     124    usbhc_iface_transfer_out_callback_t out, void *arg, const char* name);
     125
     126ssize_t hcd_send_batch_sync(hcd_t *hcd, usb_target_t target,
     127    usb_direction_t dir, void *data, size_t size, uint64_t setup_data,
     128    const char* name);
    106129
    107130#endif
    108 
    109131/**
    110132 * @}
  • uspace/lib/usbhost/include/usb/host/usb_bus.h

    r5b18137 rb4b534ac  
    4040#define LIBUSBHOST_HOST_USB_ENDPOINT_MANAGER_H
    4141
     42#include <usb/host/endpoint.h>
     43#include <usb/usb.h>
     44
    4245#include <adt/list.h>
    4346#include <fibril_synch.h>
    44 #include <usb/usb.h>
     47#include <stdbool.h>
    4548
    46 #include <usb/host/endpoint.h>
    4749
    4850/** Bytes per second in FULL SPEED */
     
    5052/** 90% of total bandwidth is available for periodic transfers */
    5153#define BANDWIDTH_AVAILABLE_USB11 ((BANDWIDTH_TOTAL_USB11 / 10) * 9)
    52 /** 16 addresses per list */
    53 #define ENDPOINT_LIST_COUNT 8
     54
     55//TODO: Implement
     56#define BANDWIDTH_AVAILABLE_USB20  1
     57
     58typedef size_t (*bw_count_func_t)(usb_speed_t, usb_transfer_type_t, size_t, size_t);
     59typedef void (*ep_remove_callback_t)(endpoint_t *, void *);
     60typedef int (*ep_add_callback_t)(endpoint_t *, void *);
    5461
    5562/** Endpoint management structure */
    56 typedef struct usb_endpoint_manager {
    57         /** Store endpoint_t instances */
    58         list_t endpoint_lists[ENDPOINT_LIST_COUNT];
     63typedef struct usb_bus {
     64        struct {
     65                usb_speed_t speed;      /**< Device speed */
     66                bool occupied;          /**< The address is in use. */
     67                list_t endpoint_list;   /**< Store endpoint_t instances */
     68        } devices[USB_ADDRESS_COUNT];
    5969        /** Prevents races accessing lists */
    6070        fibril_mutex_t guard;
     
    6272        size_t free_bw;
    6373        /** Use this function to count bw required by EP */
    64         size_t (*bw_count)(usb_speed_t, usb_transfer_type_t, size_t, size_t);
    65 } usb_endpoint_manager_t;
     74        bw_count_func_t bw_count;
     75        /** Maximum speed allowed. */
     76        usb_speed_t max_speed;
     77        /** The last reserved address */
     78        usb_address_t last_address;
     79} usb_bus_t;
     80
    6681
    6782size_t bandwidth_count_usb11(usb_speed_t speed, usb_transfer_type_t type,
    6883    size_t size, size_t max_packet_size);
     84size_t bandwidth_count_usb20(usb_speed_t speed, usb_transfer_type_t type,
     85    size_t size, size_t max_packet_size);
    6986
    70 int usb_endpoint_manager_init(usb_endpoint_manager_t *instance,
    71     size_t available_bandwidth,
    72     size_t (*bw_count)(usb_speed_t, usb_transfer_type_t, size_t, size_t));
     87int usb_bus_init(usb_bus_t *instance,
     88    size_t available_bandwidth, bw_count_func_t bw_count, usb_speed_t max_speed);
    7389
    74 void usb_endpoint_manager_reset_eps_if_need(usb_endpoint_manager_t *instance,
    75     usb_target_t target, const uint8_t data[8]);
     90int usb_bus_register_ep(usb_bus_t *instance, endpoint_t *ep, size_t data_size);
    7691
    77 int usb_endpoint_manager_register_ep(
    78     usb_endpoint_manager_t *instance, endpoint_t *ep, size_t data_size);
    79 int usb_endpoint_manager_unregister_ep(
    80     usb_endpoint_manager_t *instance, endpoint_t *ep);
    81 endpoint_t * usb_endpoint_manager_find_ep(usb_endpoint_manager_t *instance,
     92int usb_bus_unregister_ep(usb_bus_t *instance, endpoint_t *ep);
     93
     94endpoint_t * usb_bus_find_ep(usb_bus_t *instance,
    8295    usb_address_t address, usb_endpoint_t ep, usb_direction_t direction);
    8396
    84 int usb_endpoint_manager_add_ep(usb_endpoint_manager_t *instance,
     97int usb_bus_add_ep(usb_bus_t *instance,
    8598    usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
    86     usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size,
    87     size_t data_size, int (*callback)(endpoint_t *, void *), void *arg);
     99    usb_transfer_type_t type, size_t max_packet_size, unsigned packets,
     100    size_t data_size, ep_add_callback_t callback, void *arg,
     101    usb_address_t tt_address, unsigned tt_port);
    88102
    89 int usb_endpoint_manager_remove_ep(usb_endpoint_manager_t *instance,
     103int usb_bus_remove_ep(usb_bus_t *instance,
    90104    usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
    91     void (*callback)(endpoint_t *, void *), void *arg);
     105    ep_remove_callback_t callback, void *arg);
    92106
    93 void usb_endpoint_manager_remove_address(usb_endpoint_manager_t *instance,
    94     usb_address_t address, void (*callback)(endpoint_t *, void *), void *arg);
     107int usb_bus_reset_toggle(usb_bus_t *instance, usb_target_t target, bool all);
     108
     109int usb_bus_remove_address(usb_bus_t *instance,
     110    usb_address_t address, ep_remove_callback_t callback, void *arg);
     111
     112int usb_bus_request_address(usb_bus_t *instance,
     113    usb_address_t *address, bool strict, usb_speed_t speed);
     114
     115int usb_bus_get_speed(usb_bus_t *instance,
     116    usb_address_t address, usb_speed_t *speed);
    95117#endif
    96118/**
  • uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h

    r5b18137 rb4b534ac  
    3737#define LIBUSBHOST_HOST_USB_TRANSFER_BATCH_H
    3838
    39 #include <adt/list.h>
     39#include <usb/host/endpoint.h>
     40#include <usb/usb.h>
    4041
     42#include <assert.h>
     43#include <stdbool.h>
     44#include <sys/types.h>
    4145#include <usbhc_iface.h>
    42 #include <usb/usb.h>
    43 #include <usb/host/endpoint.h>
    4446
    4547#define USB_SETUP_PACKET_SIZE 8
     
    6769         */
    6870        size_t setup_size;
    69         /** Host controller function, passed to callback function */
    70         ddf_fun_t *fun;
    7171
    7272        /** Actually used portion of the buffer
     
    8080         */
    8181        int error;
    82 
    83         /** Driver specific data */
    84         void *private_data;
    85         /** Callback to properly remove driver data during destruction */
    86         void (*private_data_dtor)(void *p_data);
    8782} usb_transfer_batch_t;
    8883
     
    108103    usbhc_iface_transfer_in_callback_t func_in,
    109104    usbhc_iface_transfer_out_callback_t func_out,
    110     void *arg,
    111     ddf_fun_t *fun,
    112     void *private_data,
    113     void (*private_data_dtor)(void *p_data)
     105    void *arg
    114106);
    115107void usb_transfer_batch_destroy(const usb_transfer_batch_t *instance);
  • uspace/lib/usbhost/include/usb/host/utils/malloc32.h

    r5b18137 rb4b534ac  
    11/*
    2  * Copyright (c) 2010 Jan Vesely
     2 * Copyright (c) 2013 Jan Vesely
    33 * All rights reserved.
    44 *
     
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbohci
     28/** @addtogroup drvusbehci
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief OHCI driver
     32 * @brief EHCI driver
    3333 */
    34 #ifndef DRV_OHCI_UTILS_MALLOC32_H
    35 #define DRV_OHCI_UTILS_MALLOC32_H
     34#ifndef DRV_EHCI_UTILS_MALLOC32_H
     35#define DRV_EHCI_UTILS_MALLOC32_H
    3636
    37 #include <assert.h>
    38 #include <malloc.h>
    39 #include <unistd.h>
     37#include <align.h>
     38#include <as.h>
     39#include <ddi.h>
    4040#include <errno.h>
    41 #include <mem.h>
    42 #include <as.h>
     41#include <stdlib.h>
     42#include <sys/types.h>
    4343
    4444/* Generic TDs and EDs require 16byte alignment,
     
    4646 * buffers do not have to be aligned.
    4747 */
    48 #define OHCI_ALIGN 32
     48#define EHCI_ALIGN   32
     49
     50#define EHCI_REQUIRED_PAGE_SIZE   4096
    4951
    5052/** Get physical address translation
     
    7072 */
    7173static inline void * malloc32(size_t size)
    72         { return memalign(OHCI_ALIGN, size); }
     74{
     75        uintptr_t phys;
     76        void *address = AS_AREA_ANY;
     77        size_t real_size = ALIGN_UP(size, PAGE_SIZE);
     78
     79        const int ret = dmamem_map_anonymous(real_size,
     80            DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys,
     81            &address);
     82
     83        if (ret == EOK) {
     84                /* Poison, accessing it should be enough to make sure
     85                 * the location is mapped, but poison works better */
     86                memset(address, 0x5, real_size);
     87                return address;
     88        }
     89        return NULL;
     90}
    7391
    7492/** Physical mallocator simulator
     
    7795 */
    7896static inline void free32(void *addr)
    79         { free(addr); }
     97{
     98        dmamem_unmap_anonymous(addr);
     99}
     100
     101/** Create 4KB page mapping
     102 *
     103 * @return Address of the mapped page, NULL on failure.
     104 */
     105static inline void *get_page()
     106{
     107        return malloc32(PAGE_SIZE);
     108}
     109
     110static inline void return_page(void *page)
     111{
     112        free32(page);
     113}
     114
     115
    80116#endif
    81117/**
Note: See TracChangeset for help on using the changeset viewer.