Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/uhci/uhci.c

    r8b54fe6 r795448f  
    4141
    4242#include "uhci.h"
    43 #include "pci.h"
    44 
     43
     44#include "res.h"
    4545#include "hc.h"
    4646#include "root_hub.h"
     
    4949 * and USB root hub */
    5050typedef struct uhci {
    51         /** Pointer to DDF represenation of UHCI host controller */
     51        /** Pointer to DDF representation of UHCI host controller */
    5252        ddf_fun_t *hc_fun;
    53         /** Pointer to DDF represenation of UHCI root hub */
     53        /** Pointer to DDF representation of UHCI root hub */
    5454        ddf_fun_t *rh_fun;
    5555
    56         /** Internal driver's represenation of UHCI host controller */
     56        /** Internal driver's representation of UHCI host controller */
    5757        hc_t hc;
    58         /** Internal driver's represenation of UHCI root hub */
     58        /** Internal driver's representation of UHCI root hub */
    5959        rh_t rh;
    6060} uhci_t;
     
    8989};
    9090/*----------------------------------------------------------------------------*/
    91 /** Get address of the device identified by handle.
    92  *
    93  * @param[in] fun DDF instance of the function to use.
    94  * @param[in] handle DDF handle of the driver seeking its USB address.
    95  * @param[out] address Found address.
    96  */
    97 static int usb_iface_get_address(
    98     ddf_fun_t *fun, devman_handle_t handle, usb_address_t *address)
    99 {
    100         assert(fun);
    101         usb_device_manager_t *manager =
    102             &dev_to_uhci(fun->dev)->hc.generic.dev_manager;
    103         const usb_address_t addr = usb_device_manager_find(manager, handle);
    104 
    105         if (addr < 0) {
    106                 return addr;
    107         }
    108 
    109         if (address != NULL) {
    110                 *address = addr;
    111         }
    112 
    113         return EOK;
    114 }
    115 /*----------------------------------------------------------------------------*/
    11691/** Gets handle of the respective hc.
    11792 *
     
    134109static usb_iface_t usb_iface = {
    135110        .get_hc_handle = usb_iface_get_hc_handle,
    136         .get_address = usb_iface_get_address
    137111};
    138112/*----------------------------------------------------------------------------*/
     
    174148int device_setup_uhci(ddf_dev_t *device)
    175149{
    176         assert(device);
    177         uhci_t *instance = malloc(sizeof(uhci_t));
     150        if (!device)
     151                return EBADMEM;
     152
     153        uhci_t *instance = ddf_dev_data_alloc(device, sizeof(uhci_t));
    178154        if (instance == NULL) {
    179155                usb_log_error("Failed to allocate OHCI driver.\n");
     
    184160if (ret != EOK) { \
    185161        if (instance->hc_fun) \
    186                 instance->hc_fun->ops = NULL; \
    187162                instance->hc_fun->driver_data = NULL; \
    188163                ddf_fun_destroy(instance->hc_fun); \
    189164        if (instance->rh_fun) {\
    190                 instance->rh_fun->ops = NULL; \
    191165                instance->rh_fun->driver_data = NULL; \
    192166                ddf_fun_destroy(instance->rh_fun); \
    193167        } \
    194         device->driver_data = NULL; \
    195168        usb_log_error(message); \
    196169        return ret; \
     
    214187        int irq = 0;
    215188
    216         ret = pci_get_my_registers(device, &reg_base, &reg_size, &irq);
     189        ret = get_my_registers(device, &reg_base, &reg_size, &irq);
    217190        CHECK_RET_DEST_FREE_RETURN(ret,
    218191            "Failed to get I/O addresses for %" PRIun ": %s.\n",
     
    221194            (void *) reg_base, reg_size, irq);
    222195
    223         ret = pci_disable_legacy(device);
     196        ret = disable_legacy(device);
    224197        CHECK_RET_DEST_FREE_RETURN(ret,
    225198            "Failed to disable legacy USB: %s.\n", str_error(ret));
    226199
    227         const size_t cmd_count = hc_irq_cmd_count();
    228         irq_cmd_t irq_cmds[cmd_count];
    229         ret =
    230             hc_get_irq_commands(irq_cmds, sizeof(irq_cmds), reg_base, reg_size);
     200        const size_t ranges_count = hc_irq_pio_range_count();
     201        const size_t cmds_count = hc_irq_cmd_count();
     202        irq_pio_range_t irq_ranges[ranges_count];
     203        irq_cmd_t irq_cmds[cmds_count];
     204        ret = hc_get_irq_code(irq_ranges, sizeof(irq_ranges), irq_cmds,
     205            sizeof(irq_cmds), reg_base, reg_size);
    231206        CHECK_RET_DEST_FREE_RETURN(ret,
    232207            "Failed to generate IRQ commands: %s.\n", str_error(ret));
    233208
    234         irq_code_t irq_code = { .cmdcount = cmd_count, .cmds = irq_cmds };
     209        irq_code_t irq_code = {
     210                .rangecount = ranges_count,
     211                .ranges = irq_ranges,
     212                .cmdcount = cmds_count,
     213                .cmds = irq_cmds
     214        };
    235215
    236216        /* Register handler to avoid interrupt lockup */
     
    240220
    241221        bool interrupts = false;
    242         ret = pci_enable_interrupts(device);
     222        ret = enable_interrupts(device);
    243223        if (ret != EOK) {
    244224                usb_log_warning("Failed to enable interrupts: %s."
     
    253233            "Failed to init uhci_hcd: %s.\n", str_error(ret));
    254234
    255         device->driver_data = instance;
    256 
    257235#define CHECK_RET_FINI_RETURN(ret, message...) \
    258236if (ret != EOK) { \
Note: See TracChangeset for help on using the changeset viewer.