Changeset b9d910f in mainline


Ignore:
Timestamp:
2011-02-19T23:02:49Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fb78ae72
Parents:
6edc69a
Message:

Use properly initialized interrupt code

Location:
uspace/drv/uhci-hcd
Files:
3 edited

Legend:

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

    r6edc69a rb9d910f  
    8080};
    8181/*----------------------------------------------------------------------------*/
    82 static irq_cmd_t uhci_cmds[] = {
    83         {
    84                 .cmd = CMD_PIO_READ_16,
    85                 .addr = (void*)0xc022,
    86                 .dstarg = 1
    87         },
    88         {
    89                 .cmd = CMD_PIO_WRITE_16,
    90                 .addr = (void*)0xc022,
    91                 .value = 0x1f
    92         },
    93         {
    94                 .cmd = CMD_ACCEPT
    95         }
    96 };
    97 /*----------------------------------------------------------------------------*/
    98 static irq_code_t uhci_code = {
    99         sizeof(uhci_cmds) / sizeof(irq_cmd_t),
    100         uhci_cmds
    101 };
    102 /*----------------------------------------------------------------------------*/
    10382static void irq_handler(device_t *device, ipc_callid_t iid, ipc_call_t *call)
    10483{
     
    11190}
    11291/*----------------------------------------------------------------------------*/
     92#define CHECK_RET_RETURN(ret, message...) \
     93if (ret != EOK) { \
     94        usb_log_error(message); \
     95        return ret; \
     96}
     97
    11398static int uhci_add_device(device_t *device)
    11499{
     
    125110            pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq);
    126111
    127         if (ret != EOK) {
    128                 usb_log_error(
    129                     "Failed(%d) to get I/O registers addresses for device:.\n",
    130                     ret, device->handle);
    131                 return ret;
    132         }
    133 
     112        CHECK_RET_RETURN(ret,
     113            "Failed(%d) to get I/O registers addresses for device:.\n",
     114            ret, device->handle);
    134115        usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
    135116            io_reg_base, io_reg_size, irq);
     
    158139        async_hangup(irc_phone);
    159140
    160         ret = register_interrupt_handler(device, irq, irq_handler, &uhci_code);
    161         usb_log_debug("Registered interrupt handler %d.\n", ret);
    162141
    163142        uhci_t *uhci_hc = malloc(sizeof(uhci_t));
    164         if (!uhci_hc) {
    165                 usb_log_error("Failed to allocate memory for uhci hcd driver.\n");
    166                 return ENOMEM;
    167         }
     143        ret = (uhci_hc != NULL) ? EOK : ENOMEM;
     144        CHECK_RET_RETURN(ret, "Failed to allocate memory for uhci hcd driver.\n");
    168145
    169146        ret = uhci_init(uhci_hc, (void*)io_reg_base, io_reg_size);
    170147        if (ret != EOK) {
    171148                usb_log_error("Failed to init uhci-hcd.\n");
     149                free(uhci_hc);
    172150                return ret;
    173151        }
     152
     153        ret = register_interrupt_handler(device, irq, irq_handler,
     154            &uhci_hc->interrupt_code);
     155        if (ret != EOK) {
     156                usb_log_error("Failed to register interrupt handler.\n");
     157                uhci_fini(uhci_hc);
     158                free(uhci_hc);
     159                return ret;
     160        }
     161
    174162        device_t *rh;
    175163        ret = setup_root_hub(&rh, device);
    176164        if (ret != EOK) {
    177165                usb_log_error("Failed to setup uhci root hub.\n");
    178                 /* TODO: destroy uhci here */
     166                uhci_fini(uhci_hc);
     167                free(uhci_hc);
    179168                return ret;
    180169        }
     
    183172        if (ret != EOK) {
    184173                usb_log_error("Failed to register root hub.\n");
    185                 /* TODO: destroy uhci here */
     174                uhci_fini(uhci_hc);
     175                free(uhci_hc);
     176                free(rh);
    186177                return ret;
    187178        }
    188179
    189180        device->driver_data = uhci_hc;
    190 
    191181        return EOK;
    192182}
  • uspace/drv/uhci-hcd/uhci.c

    r6edc69a rb9d910f  
    3939
    4040#include "uhci.h"
     41static irq_cmd_t uhci_cmds[] = {
     42        {
     43                .cmd = CMD_PIO_READ_16,
     44                .addr = (void*)0xc022,
     45                .dstarg = 1
     46        },
     47        {
     48                .cmd = CMD_PIO_WRITE_16,
     49                .addr = (void*)0xc022,
     50                .value = 0x1f
     51        },
     52        {
     53                .cmd = CMD_ACCEPT
     54        }
     55};
    4156
    4257static int uhci_init_transfer_lists(uhci_t *instance);
     
    101116{
    102117        assert(instance);
     118
     119        /* init interrupt code */
     120        irq_cmd_t *interrupt_commands = malloc(sizeof(uhci_cmds));
     121        if (interrupt_commands == NULL) {
     122                return ENOMEM;
     123        }
     124        memcpy(interrupt_commands, uhci_cmds, sizeof(uhci_cmds));
     125        interrupt_commands[0].addr = (void*)&instance->registers->usbsts;
     126        interrupt_commands[1].addr = (void*)&instance->registers->usbsts;
     127        instance->interrupt_code.cmds = interrupt_commands;
     128        instance->interrupt_code.cmdcount =
     129            sizeof(uhci_cmds) / sizeof(irq_cmd_t);
     130
    103131        /* init transfer lists */
    104132        int ret = uhci_init_transfer_lists(instance);
  • uspace/drv/uhci-hcd/uhci.h

    r6edc69a rb9d910f  
    9393        transfer_list_t *transfers[2][4];
    9494
     95        irq_code_t interrupt_code;
     96
    9597        fid_t cleaner;
    9698        fid_t debug_checker;
     
    100102int uhci_init(uhci_t *instance, void *regs, size_t reg_size);
    101103
    102 int uhci_fini(uhci_t *device);
     104static inline void uhci_fini(uhci_t *instance) {};
    103105
    104106int uhci_transfer(
     
    122124        { return (uhci_t*)dev->driver_data; }
    123125
     126
    124127#endif
    125128/**
Note: See TracChangeset for help on using the changeset viewer.