Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 77d10f0 in mainline


Ignore:
Timestamp:
2011-04-22T21:29:57Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
af81980
Parents:
6f122df
Message:

Do not use static irq_commnd structure, there is no enough shared data.

One less malloc

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

Legend:

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

    r6f122df r77d10f0  
    4444#include "hc.h"
    4545
    46 static irq_cmd_t uhci_cmds[] = {
    47         {
    48                 .cmd = CMD_PIO_READ_16,
    49                 .addr = NULL, /* patched for every instance */
    50                 .dstarg = 1
    51         },
    52         {
    53                 .cmd = CMD_PIO_WRITE_16,
    54                 .addr = NULL, /* pathed for every instance */
    55                 .value = 0x1f
    56         },
    57         {
    58                 .cmd = CMD_ACCEPT
    59         }
    60 };
    61 /*----------------------------------------------------------------------------*/
    6246static int hc_init_transfer_lists(hc_t *instance);
    6347static int hc_init_mem_structures(hc_t *instance);
     
    177161{
    178162        assert(instance);
    179 #define CHECK_RET_DEST_CMDS_RETURN(ret, message...) \
     163#define CHECK_RET_RETURN(ret, message...) \
    180164        if (ret != EOK) { \
    181165                usb_log_error(message); \
    182                 if (instance->interrupt_code.cmds != NULL) \
    183                         free(instance->interrupt_code.cmds); \
    184166                return ret; \
    185167        } else (void) 0
    186168
    187169        /* Init interrupt code */
    188         instance->interrupt_code.cmds = malloc(sizeof(uhci_cmds));
    189         int ret = (instance->interrupt_code.cmds == NULL) ? ENOMEM : EOK;
    190         CHECK_RET_DEST_CMDS_RETURN(ret,
    191             "Failed to allocate interrupt cmds space.\n");
    192 
     170        instance->interrupt_code.cmds = instance->interrupt_commands;
    193171        {
    194                 irq_cmd_t *interrupt_commands = instance->interrupt_code.cmds;
    195                 memcpy(interrupt_commands, uhci_cmds, sizeof(uhci_cmds));
    196                 interrupt_commands[0].addr =
    197                     (void*)&instance->registers->usbsts;
    198                 interrupt_commands[1].addr =
    199                     (void*)&instance->registers->usbsts;
    200                 instance->interrupt_code.cmdcount =
    201                     sizeof(uhci_cmds) / sizeof(irq_cmd_t);
     172                instance->interrupt_commands[0].cmd = CMD_PIO_READ_16;
     173                instance->interrupt_commands[0].dstarg = 1;
     174                instance->interrupt_commands[0].addr =
     175                    &instance->registers->usbsts;
     176
     177                instance->interrupt_commands[1].cmd = CMD_PIO_WRITE_16;
     178                instance->interrupt_commands[1].value = 0x1f;
     179                instance->interrupt_commands[1].addr =
     180                    &instance->registers->usbsts;
     181
     182                instance->interrupt_commands[2].cmd = CMD_ACCEPT;
     183                instance->interrupt_code.cmdcount = UHCI_NEEDED_IRQ_COMMANDS;
    202184        }
    203185
    204186        /* Init transfer lists */
    205         ret = hc_init_transfer_lists(instance);
    206         CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to init transfer lists.\n");
     187        int ret = hc_init_transfer_lists(instance);
     188        CHECK_RET_RETURN(ret, "Failed to init transfer lists.\n");
    207189        usb_log_debug("Initialized transfer lists.\n");
    208190
     
    210192        instance->frame_list = get_page();
    211193        ret = instance ? EOK : ENOMEM;
    212         CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to get frame list page.\n");
     194        CHECK_RET_RETURN(ret, "Failed to get frame list page.\n");
    213195        usb_log_debug("Initialized frame list at %p.\n", instance->frame_list);
    214196
     
    229211        ret = usb_endpoint_manager_init(&instance->ep_manager,
    230212            BANDWIDTH_AVAILABLE_USB11);
    231         assert(ret == EOK);
    232 
    233         return EOK;
    234 #undef CHECK_RET_DEST_CMDS_RETURN
     213        CHECK_RET_RETURN(ret, "Failed to initialize endpoint manager: %s.\n",
     214            str_error(ret));
     215
     216        return EOK;
     217#undef CHECK_RET_RETURN
    235218}
    236219/*----------------------------------------------------------------------------*/
  • uspace/drv/uhci-hcd/hc.h

    r6f122df r77d10f0  
    9191#define UHCI_DEBUGER_TIMEOUT 5000000
    9292#define UHCI_ALLOWED_HW_FAIL 5
     93#define UHCI_NEEDED_IRQ_COMMANDS 3
    9394
    9495/* Main HC driver structure */
     
    119120        /** Code to be executed in kernel interrupt handler */
    120121        irq_code_t interrupt_code;
     122
     123        /** Commands that form interrupt code */
     124        irq_cmd_t interrupt_commands[UHCI_NEEDED_IRQ_COMMANDS];
    121125
    122126        /** Fibril periodically checking status register*/
Note: See TracChangeset for help on using the changeset viewer.