Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/root_hub.c

    r1a93bb0 r687efaa  
    3535#include <errno.h>
    3636#include <stdio.h>
    37 #include <ops/hw_res.h>
    38 
    3937#include <usb_iface.h>
    4038#include <usb/debug.h>
    4139
    4240#include "root_hub.h"
    43 #include "uhci.h"
    4441
     42extern device_ops_t child_ops;
    4543/*----------------------------------------------------------------------------*/
    46 static int usb_iface_get_hc_handle_rh_impl(ddf_fun_t *root_hub_fun,
    47     devman_handle_t *handle)
     44int setup_root_hub(device_t **device, device_t *hc)
    4845{
    49         ddf_fun_t *hc_fun = root_hub_fun->driver_data;
    50         assert(hc_fun != NULL);
    51 
    52         *handle = hc_fun->handle;
    53 
    54         return EOK;
    55 }
    56 /*----------------------------------------------------------------------------*/
    57 static int usb_iface_get_address_rh_impl(ddf_fun_t *fun, devman_handle_t handle,
    58     usb_address_t *address)
    59 {
    60         assert(fun);
    61         ddf_fun_t *hc_fun = fun->driver_data;
    62         assert(hc_fun);
    63         uhci_t *hc = fun_to_uhci(hc_fun);
    64         assert(hc);
    65 
    66         usb_address_t addr = device_keeper_find(&hc->device_manager,
    67             handle);
    68         if (addr < 0) {
    69                 return addr;
    70         }
    71 
    72         if (address != NULL) {
    73                 *address = addr;
    74         }
    75 
    76         return EOK;
    77 }
    78 /*----------------------------------------------------------------------------*/
    79 usb_iface_t usb_iface_root_hub_fun_impl = {
    80         .get_hc_handle = usb_iface_get_hc_handle_rh_impl,
    81         .get_address = usb_iface_get_address_rh_impl
    82 };
    83 /*----------------------------------------------------------------------------*/
    84 static hw_resource_list_t *get_resource_list(ddf_fun_t *dev)
    85 {
    86         assert(dev);
    87         ddf_fun_t *hc_ddf_instance = dev->driver_data;
    88         assert(hc_ddf_instance);
    89         uhci_t *hc = hc_ddf_instance->driver_data;
    90         assert(hc);
    91 
    92         //TODO: fix memory leak
    93         hw_resource_list_t *resource_list = malloc(sizeof(hw_resource_list_t));
    94         assert(resource_list);
    95         resource_list->count = 1;
    96         resource_list->resources = malloc(sizeof(hw_resource_t));
    97         assert(resource_list->resources);
    98         resource_list->resources[0].type = IO_RANGE;
    99         resource_list->resources[0].res.io_range.address =
    100             ((uintptr_t)hc->registers) + 0x10; // see UHCI design guide
    101         resource_list->resources[0].res.io_range.size = 4;
    102         resource_list->resources[0].res.io_range.endianness = LITTLE_ENDIAN;
    103 
    104         return resource_list;
    105 }
    106 /*----------------------------------------------------------------------------*/
    107 static hw_res_ops_t hw_res_iface = {
    108         .get_resource_list = get_resource_list,
    109         .enable_interrupt = NULL
    110 };
    111 /*----------------------------------------------------------------------------*/
    112 static ddf_dev_ops_t root_hub_ops = {
    113         .interfaces[USB_DEV_IFACE] = &usb_iface_root_hub_fun_impl,
    114         .interfaces[HW_RES_DEV_IFACE] = &hw_res_iface
    115 };
    116 /*----------------------------------------------------------------------------*/
    117 int setup_root_hub(ddf_fun_t **fun, ddf_dev_t *hc)
    118 {
    119         assert(fun);
    120         int ret;
    121 
    122         ddf_fun_t *hub = ddf_fun_create(hc, fun_inner, "root-hub");
     46        assert(device);
     47        device_t *hub = create_device();
    12348        if (!hub) {
    12449                usb_log_error("Failed to create root hub device structure.\n");
     50                return ENOMEM;
     51        }
     52        char *name;
     53        int ret = asprintf(&name, "UHCI Root Hub");
     54        if (ret < 0) {
     55                usb_log_error("Failed to create root hub name.\n");
     56                free(hub);
    12557                return ENOMEM;
    12658        }
     
    13062        if (ret < 0) {
    13163                usb_log_error("Failed to create root hub match string.\n");
    132                 ddf_fun_destroy(hub);
     64                free(hub);
     65                free(name);
    13366                return ENOMEM;
    13467        }
    13568
    136         ret = ddf_fun_add_match_id(hub, match_str, 100);
    137         if (ret != EOK) {
    138                 usb_log_error("Failed to add root hub match id.\n");
    139                 ddf_fun_destroy(hub);
     69        match_id_t *match_id = create_match_id();
     70        if (!match_id) {
     71                usb_log_error("Failed to create root hub match id.\n");
     72                free(hub);
     73                free(match_str);
    14074                return ENOMEM;
    14175        }
     76        match_id->id = match_str;
     77        match_id->score = 90;
    14278
    143         hub->ops = &root_hub_ops;
     79        add_match_id(&hub->match_ids, match_id);
     80        hub->name = name;
     81        hub->parent = hc;
     82        hub->ops = &child_ops;
    14483
    145         *fun = hub;
     84        *device = hub;
    14685        return EOK;
    14786}
Note: See TracChangeset for help on using the changeset viewer.