Changeset 53332b5b in mainline


Ignore:
Timestamp:
2012-12-21T11:01:09Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0ef03d7
Parents:
a720ff6
Message:

libusbhost: Move ddf specific functions to separate header.

Switch ehci to using libusbhost proided routines.
Make hcd_iface private.

Location:
uspace
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ehci/main.c

    ra720ff6 r53332b5b  
    4040
    4141#include <usb_iface.h>
    42 #include <usb/ddfiface.h>
    4342#include <usb/debug.h>
    44 #include <usb/host/hcd.h>
     43#include <usb/host/ddf_helpers.h>
    4544
    4645#include "res.h"
     
    5756        .name = NAME,
    5857        .driver_ops = &ehci_driver_ops
    59 };
    60 static ddf_dev_ops_t hc_ops = {
    61         .interfaces[USBHC_DEV_IFACE] = &hcd_iface,
    6258};
    6359
     
    9288            "Failed to disable legacy USB: %s.\n", str_error(ret));
    9389
    94         ddf_fun_t *hc_fun = ddf_fun_create(device, fun_exposed, "ehci_hc");
    95         if (hc_fun == NULL) {
    96                 usb_log_error("Failed to create EHCI function.\n");
    97                 return ENOMEM;
    98         }
    99         hcd_t *ehci_hc = ddf_fun_data_alloc(hc_fun, sizeof(hcd_t));
    100         if (ehci_hc == NULL) {
    101                 usb_log_error("Failed to alloc generic HC driver.\n");
    102                 return ENOMEM;
    103         }
    104         /* High Speed, no bandwidth */
    105         hcd_init(ehci_hc, USB_SPEED_HIGH, 0, NULL);
    106         ddf_fun_set_ops(hc_fun,  &hc_ops);
    107 
    108         ret = ddf_fun_bind(hc_fun);
     90        /* TODO High Speed, no bandwidth */
     91        ret = hcd_ddf_setup_device(device, NULL);       
    10992        CHECK_RET_RETURN(ret,
    110             "Failed to bind EHCI function: %s.\n",
    111             str_error(ret));
    112         ret = ddf_fun_add_to_category(hc_fun, USB_HC_CATEGORY);
    113         CHECK_RET_RETURN(ret,
    114             "Failed to add EHCI to HC class: %s.\n",
    115             str_error(ret));
     93            "Failed to init generci hcd driver: %s\n", str_error(ret));
    11694
    11795        usb_log_info("Controlling new EHCI device `%s' (handle %" PRIun ").\n",
  • uspace/drv/bus/usb/ohci/ohci.c

    ra720ff6 r53332b5b  
    3737#include <str_error.h>
    3838#include <ddf/interrupt.h>
    39 #include <usb_iface.h>
    4039#include <usb/usb.h>
    4140#include <usb/ddfiface.h>
    4241#include <usb/debug.h>
     42
     43#include <usb/host/ddf_helpers.h>
    4344
    4445#include "ohci.h"
     
    131132
    132133        /* Initialize generic HCD driver */
    133         ret = hcd_setup_device(device, NULL);
     134        ret = hcd_ddf_setup_device(device, NULL);
    134135        if (ret != EOK) {
    135136                unregister_interrupt_handler(device, irq);
    136137                return ret;
    137138        }
    138 
    139139
    140140// TODO: Undo hcd_setup_device
     
    158158
    159159        /* HC should be running OK. We can add root hub */
    160         ret = hcd_setup_hub(dev_to_hcd(device), &hc_impl->rh.address, device);
     160        ret = hcd_ddf_setup_hub(dev_to_hcd(device), &hc_impl->rh.address, device);
    161161        CHECK_RET_CLEAN_RETURN(ret,
    162162            "Failed to register OHCI root hub: %s.\n", str_error(ret));
  • uspace/drv/bus/usb/uhci/uhci.c

    ra720ff6 r53332b5b  
    4040#include <str_error.h>
    4141#include <ddf/interrupt.h>
    42 #include <usb_iface.h>
    4342#include <usb/ddfiface.h>
    4443#include <usb/debug.h>
    4544#include <usb/host/hcd.h>
     45#include <usb/host/ddf_helpers.h>
    4646
    4747#include "uhci.h"
     
    137137
    138138        ddf_fun_t *hc_fun = NULL;
    139         ret = hcd_setup_device(device, &hc_fun);
     139        ret = hcd_ddf_setup_device(device, &hc_fun);
    140140        CHECK_RET_RETURN(ret, "Failed to setup UHCI HCD.\n");
    141141       
  • uspace/lib/usbhost/Makefile

    ra720ff6 r53332b5b  
    3232        -I$(LIBUSB_PREFIX)/include \
    3333        -I$(LIBDRV_PREFIX)/include \
     34        -Iinclude/usb/host \
    3435        -Iinclude
    3536
    3637SOURCES = \
     38        src/ddf_helpers.c \
    3739        src/endpoint.c \
    3840        src/hcd.c \
  • uspace/lib/usbhost/include/usb/host/hcd.h

    ra720ff6 r53332b5b  
    103103    usbhc_iface_transfer_out_callback_t out, void *arg, const char* name);
    104104
    105 int hcd_add_device(hcd_t *instance, ddf_dev_t *parent,
    106     usb_address_t address, usb_speed_t speed, const char *name,
    107     const match_id_list_t *mids);
    108 
    109 int hcd_setup_device(ddf_dev_t *device, ddf_fun_t **fun);
    110 int hcd_setup_hub(hcd_t *instance, usb_address_t *address, ddf_dev_t *dev);
    111 
    112 hcd_t *dev_to_hcd(ddf_dev_t *dev);
    113105
    114106/** Data retrieve wrapper.
     
    122114
    123115
    124 extern usbhc_iface_t hcd_iface;
    125 
    126116#endif
    127117
  • uspace/lib/usbhost/src/hcd.c

    ra720ff6 r53332b5b  
    4141#include <usb/host/hcd.h>
    4242
    43 typedef struct hc_dev {
    44         ddf_fun_t *hc_fun;
    45 } hc_dev_t;
    46 
    47 static hc_dev_t *dev_to_hc_dev(ddf_dev_t *dev)
    48 {
    49         return ddf_dev_data_get(dev);
    50 }
    51 
    52 hcd_t *dev_to_hcd(ddf_dev_t *dev)
    53 {
    54         hc_dev_t *hc_dev = dev_to_hc_dev(dev);
    55         if (!hc_dev || !hc_dev->hc_fun) {
    56                 usb_log_error("Invalid OHCI device.\n");
    57                 return NULL;
    58         }
    59         return ddf_fun_data_get(hc_dev->hc_fun);
    60 }
    61 
    62 typedef struct usb_dev {
    63         link_t link;
    64         ddf_fun_t *fun;
    65         usb_address_t address;
    66         usb_speed_t speed;
    67         devman_handle_t handle;
    68 } usb_dev_t;
    69 
    70 /** Get USB address assigned to root hub.
    71  *
    72  * @param[in] fun Root hub function.
    73  * @param[out] address Store the address here.
    74  * @return Error code.
    75  */
    76 static int rh_get_my_address(ddf_fun_t *fun, usb_address_t *address)
    77 {
    78         assert(fun);
    79         if (address != NULL) {
    80                 usb_dev_t *usb_dev = ddf_fun_data_get(fun);
    81                 *address = usb_dev->address;
    82         }
    83         return EOK;
    84 }
    85 
    86 /** Gets handle of the respective hc (this device, hc function).
    87  *
    88  * @param[in] root_hub_fun Root hub function seeking hc handle.
    89  * @param[out] handle Place to write the handle.
    90  * @return Error code.
    91  */
    92 static int rh_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
    93 {
    94         assert(fun);
    95 
    96         if (handle != NULL) {
    97                 usb_dev_t *usb_dev = ddf_fun_data_get(fun);
    98                 *handle = usb_dev->handle;
    99         }
    100         return EOK;
    101 }
    102 
    103 /** Root hub USB interface */
    104 static usb_iface_t usb_iface = {
    105         .get_hc_handle = rh_get_hc_handle,
    106         .get_my_address = rh_get_my_address,
    107 };
    108 /** Standard USB RH options (RH interface) */
    109 static ddf_dev_ops_t usb_ops = {
    110         .interfaces[USB_DEV_IFACE] = &usb_iface,
    111 };
    112 
    113 /** Standard USB HC options (HC interface) */
    114 static ddf_dev_ops_t hc_ops = {
    115         .interfaces[USBHC_DEV_IFACE] = &hcd_iface,
    116 };
    117 
    11843/** Initialize hcd_t structure.
    11944 * Initializes device and endpoint managers. Sets data and hook pointer to NULL.
     
    13661        hcd->ep_add_hook = NULL;
    13762        hcd->ep_remove_hook = NULL;
    138 }
    139 
    140 int hcd_add_device(hcd_t *instance, ddf_dev_t *parent,
    141     usb_address_t address, usb_speed_t speed, const char *name,
    142     const match_id_list_t *mids)
    143 {
    144         assert(instance);
    145         assert(parent);
    146         hc_dev_t *hc_dev = ddf_dev_data_get(parent);
    147         devman_handle_t hc_handle = ddf_fun_get_handle(hc_dev->hc_fun);
    148 
    149         //TODO more checks
    150         ddf_fun_t *fun = ddf_fun_create(parent, fun_inner, name);
    151         if (!fun)
    152                 return ENOMEM;
    153         usb_dev_t *info = ddf_fun_data_alloc(fun, sizeof(usb_dev_t));
    154         if (!info) {
    155                 ddf_fun_destroy(fun);
    156                 return ENOMEM;
    157         }
    158         info->address = address;
    159         info->speed = speed;
    160         info->handle = hc_handle;
    161         info->fun = fun;
    162         link_initialize(&info->link);
    163 
    164         ddf_fun_set_ops(fun, &usb_ops);
    165         list_foreach(mids->ids, iter) {
    166                 match_id_t *mid = list_get_instance(iter, match_id_t, link);
    167                 ddf_fun_add_match_id(fun, mid->id, mid->score);
    168         }
    169 
    170         int ret = ddf_fun_bind(fun);
    171         if (ret != EOK) {
    172                 ddf_fun_destroy(fun);
    173                 return ret;
    174         }
    175 
    176         ret = usb_device_manager_bind_address(&instance->dev_manager,
    177             address, ddf_fun_get_handle(fun));
    178         if (ret != EOK)
    179                 usb_log_warning("Failed to bind root hub address: %s.\n",
    180                     str_error(ret));
    181 
    182         list_append(&info->link, &instance->devices);
    183         return EOK;
    18463}
    18564
     
    243122}
    244123
    245 
    246 /** Announce root hub to the DDF
    247  *
    248  * @param[in] instance OHCI driver instance
    249  * @param[in] hub_fun DDF function representing OHCI root hub
    250  * @return Error code
    251  */
    252 int hcd_setup_hub(hcd_t *instance, usb_address_t *address, ddf_dev_t *device)
    253 {
    254         assert(instance);
    255         assert(address);
    256         assert(device);
    257 
    258         int ret = usb_device_manager_request_address(&instance->dev_manager,
    259             address, false, USB_SPEED_FULL);
    260         if (ret != EOK) {
    261                 usb_log_error("Failed to get root hub address: %s\n",
    262                     str_error(ret));
    263                 return ret;
    264         }
    265 
    266 #define CHECK_RET_UNREG_RETURN(ret, message...) \
    267 if (ret != EOK) { \
    268         usb_log_error(message); \
    269         usb_endpoint_manager_remove_ep( \
    270             &instance->ep_manager, *address, 0, \
    271             USB_DIRECTION_BOTH, NULL, NULL); \
    272         usb_device_manager_release_address( \
    273             &instance->dev_manager, *address); \
    274         return ret; \
    275 } else (void)0
    276 
    277         ret = usb_endpoint_manager_add_ep(
    278             &instance->ep_manager, *address, 0,
    279             USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL, USB_SPEED_FULL, 64,
    280             0, NULL, NULL);
    281         CHECK_RET_UNREG_RETURN(ret,
    282             "Failed to add root hub control endpoint: %s.\n", str_error(ret));
    283 
    284         match_id_t mid = { .id = "usb&class=hub", .score = 100 };
    285         link_initialize(&mid.link);
    286         match_id_list_t mid_list;
    287         init_match_ids(&mid_list);
    288         add_match_id(&mid_list, &mid);
    289 
    290         ret = hcd_add_device(
    291             instance, device, *address, USB_SPEED_FULL, "rh", &mid_list);
    292         CHECK_RET_UNREG_RETURN(ret,
    293             "Failed to add hcd device: %s.\n", str_error(ret));
    294 
    295         return EOK;
    296 #undef CHECK_RET_UNREG_RETURN
    297 }
    298 
    299 /** Initialize hc structures.
    300  *
    301  * @param[in] device DDF instance of the device to use.
    302  *
    303  * This function does all the preparatory work for hc driver implementation.
    304  *  - gets device hw resources
    305  *  - disables OHCI legacy support
    306  *  - asks for interrupt
    307  *  - registers interrupt handler
    308  */
    309 int hcd_setup_device(ddf_dev_t *device, ddf_fun_t **hc_fun)
    310 {
    311         if (device == NULL)
    312                 return EBADMEM;
    313 
    314         hc_dev_t *instance = ddf_dev_data_alloc(device, sizeof(hc_dev_t));
    315         if (instance == NULL) {
    316                 usb_log_error("Failed to allocate OHCI driver.\n");
    317                 return ENOMEM;
    318         }
    319 
    320 #define CHECK_RET_DEST_FREE_RETURN(ret, message...) \
    321 if (ret != EOK) { \
    322         if (instance->hc_fun) { \
    323                 ddf_fun_destroy(instance->hc_fun); \
    324         } \
    325         usb_log_error(message); \
    326         return ret; \
    327 } else (void)0
    328 
    329         instance->hc_fun = ddf_fun_create(device, fun_exposed, "hc");
    330         int ret = instance->hc_fun ? EOK : ENOMEM;
    331         CHECK_RET_DEST_FREE_RETURN(ret,
    332             "Failed to create OHCI HC function: %s.\n", str_error(ret));
    333         ddf_fun_set_ops(instance->hc_fun, &hc_ops);
    334         hcd_t *hcd = ddf_fun_data_alloc(instance->hc_fun, sizeof(hcd_t));
    335         ret = hcd ? EOK : ENOMEM;
    336         CHECK_RET_DEST_FREE_RETURN(ret,
    337             "Failed to allocate HCD structure: %s.\n", str_error(ret));
    338 
    339         hcd_init(hcd, USB_SPEED_FULL, BANDWIDTH_AVAILABLE_USB11,
    340             bandwidth_count_usb11);
    341 
    342         ret = ddf_fun_bind(instance->hc_fun);
    343         CHECK_RET_DEST_FREE_RETURN(ret,
    344             "Failed to bind OHCI device function: %s.\n", str_error(ret));
    345 
    346 #define CHECK_RET_UNBIND_FREE_RETURN(ret, message...) \
    347 if (ret != EOK) { \
    348         ddf_fun_unbind(instance->hc_fun); \
    349         CHECK_RET_DEST_FREE_RETURN(ret, \
    350             "Failed to add OHCI to HC class: %s.\n", str_error(ret)); \
    351 } else (void)0
    352         ret = ddf_fun_add_to_category(instance->hc_fun, USB_HC_CATEGORY);
    353         CHECK_RET_UNBIND_FREE_RETURN(ret,
    354             "Failed to add hc to category: %s\n", str_error(ret));
    355 
    356         /* HC should be ok at this point (except it can't do anything) */
    357         if (hc_fun)
    358                 *hc_fun = instance->hc_fun;
    359 
    360         return EOK;
    361 }
    362 
    363124/**
    364125 * @}
Note: See TracChangeset for help on using the changeset viewer.