Ignore:
File:
1 edited

Legend:

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

    rfb78ae72 r357a302  
    3434#include <driver.h>
    3535#include <usb_iface.h>
    36 #include <device/hw_res.h>
    3736
    3837#include <errno.h>
     
    4746#define NAME "uhci-hcd"
    4847
    49 static int uhci_add_device(device_t *device);
    50 static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle);
    51 /*----------------------------------------------------------------------------*/
    5248static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
    5349{
     
    5854        return EOK;
    5955}
    60 /*----------------------------------------------------------------------------*/
     56
     57static int usb_iface_get_address(device_t *dev, devman_handle_t handle,
     58    usb_address_t *address)
     59{
     60        assert(dev);
     61        uhci_t *hc = dev_to_uhci(dev);
     62        assert(hc);
     63
     64        usb_address_t addr = usb_address_keeping_find(&hc->address_manager,
     65            handle);
     66        if (addr < 0) {
     67                return addr;
     68        }
     69
     70        if (address != NULL) {
     71                *address = addr;
     72        }
     73
     74        return EOK;
     75}
     76
    6177static usb_iface_t hc_usb_iface = {
    62         .get_hc_handle = usb_iface_get_hc_handle
     78        .get_hc_handle = usb_iface_get_hc_handle,
     79        .get_address = usb_iface_get_address
    6380};
    64 /*----------------------------------------------------------------------------*/
     81
    6582static device_ops_t uhci_ops = {
    6683        .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
    6784        .interfaces[USBHC_DEV_IFACE] = &uhci_iface
    6885};
    69 /*----------------------------------------------------------------------------*/
    70 static driver_ops_t uhci_driver_ops = {
    71         .add_device = uhci_add_device,
    72 };
    73 /*----------------------------------------------------------------------------*/
    74 static driver_t uhci_driver = {
    75         .name = NAME,
    76         .driver_ops = &uhci_driver_ops
    77 };
    78 /*----------------------------------------------------------------------------*/
    79 static void irq_handler(device_t *device, ipc_callid_t iid, ipc_call_t *call)
    80 {
    81         assert(device);
    82         uhci_t *hc = dev_to_uhci(device);
    83         uint16_t status = IPC_GET_ARG1(*call);
    84         assert(hc);
    85         uhci_interrupt(hc, status);
    86 }
    87 /*----------------------------------------------------------------------------*/
    88 #define CHECK_RET_RETURN(ret, message...) \
    89 if (ret != EOK) { \
    90         usb_log_error(message); \
    91         return ret; \
    92 }
    9386
    9487static int uhci_add_device(device_t *device)
     
    10396        int irq;
    10497
    105         int ret =
    106             pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq);
     98        int rc = pci_get_my_registers(device,
     99            &io_reg_base, &io_reg_size, &irq);
    107100
    108         CHECK_RET_RETURN(ret,
    109             "Failed(%d) to get I/O addresses:.\n", ret, device->handle);
     101        if (rc != EOK) {
     102                usb_log_error("Failed(%d) to get I/O registers addresses for device:.\n",
     103                    rc, device->handle);
     104                return rc;
     105        }
     106
    110107        usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
    111108            io_reg_base, io_reg_size, irq);
    112109
    113         ret = pci_enable_interrupts(device);
    114         CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret);
     110        uhci_t *uhci_hc = malloc(sizeof(uhci_t));
     111        if (!uhci_hc) {
     112                usb_log_error("Failed to allocaete memory for uhci hcd driver.\n");
     113                return ENOMEM;
     114        }
    115115
    116         uhci_t *uhci_hc = malloc(sizeof(uhci_t));
    117         ret = (uhci_hc != NULL) ? EOK : ENOMEM;
    118         CHECK_RET_RETURN(ret, "Failed to allocate memory for uhci hcd driver.\n");
    119 
    120         ret = uhci_init(uhci_hc, (void*)io_reg_base, io_reg_size);
     116        int ret = uhci_init(uhci_hc, (void*)io_reg_base, io_reg_size);
    121117        if (ret != EOK) {
    122118                usb_log_error("Failed to init uhci-hcd.\n");
    123                 free(uhci_hc);
    124119                return ret;
    125120        }
    126 
    127         ret = register_interrupt_handler(device, irq, irq_handler,
    128             &uhci_hc->interrupt_code);
    129         if (ret != EOK) {
    130                 usb_log_error("Failed to register interrupt handler.\n");
    131                 uhci_fini(uhci_hc);
    132                 free(uhci_hc);
    133                 return ret;
    134         }
    135 
    136121        device_t *rh;
    137122        ret = setup_root_hub(&rh, device);
     123
    138124        if (ret != EOK) {
    139125                usb_log_error("Failed to setup uhci root hub.\n");
    140                 uhci_fini(uhci_hc);
    141                 free(uhci_hc);
     126                /* TODO: destroy uhci here */
    142127                return ret;
    143128        }
     
    146131        if (ret != EOK) {
    147132                usb_log_error("Failed to register root hub.\n");
    148                 uhci_fini(uhci_hc);
    149                 free(uhci_hc);
    150                 free(rh);
     133                /* TODO: destroy uhci here */
    151134                return ret;
    152135        }
    153136
    154137        device->driver_data = uhci_hc;
     138
    155139        return EOK;
    156140}
    157 /*----------------------------------------------------------------------------*/
     141
     142static driver_ops_t uhci_driver_ops = {
     143        .add_device = uhci_add_device,
     144};
     145
     146static driver_t uhci_driver = {
     147        .name = NAME,
     148        .driver_ops = &uhci_driver_ops
     149};
     150
    158151int main(int argc, char *argv[])
    159152{
    160         sleep(3);
    161         usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
     153        /*
     154         * Do some global initializations.
     155         */
     156        sleep(5);
     157        usb_log_enable(USB_LOG_LEVEL_INFO, NAME);
    162158
    163159        return driver_main(&uhci_driver);
Note: See TracChangeset for help on using the changeset viewer.