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

Changeset ece7f78 in mainline


Ignore:
Timestamp:
2011-07-11T09:52:15Z (10 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
c85804f
Parents:
aa81adc
Message:

OHCI: Root hub: remove allocation and fix rare bug.

Limit port-count to 15 (specs say so on page 124).
Use array of max possible size (2 bytes), instead of heap allocation.
Fix issue with changes happening on port 8 on 8-port hub.

Location:
uspace/drv/bus/usb/ohci
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ohci/root_hub.c

    raa81adc rece7f78  
    224224 * @return Error code.
    225225 */
    226 int rh_init(rh_t *instance, ohci_regs_t *regs) {
    227         assert(instance);
     226int rh_init(rh_t *instance, ohci_regs_t *regs)
     227{
     228        assert(instance);
     229
    228230        instance->registers = regs;
    229231        instance->port_count =
    230232            (instance->registers->rh_desc_a >> RHDA_NDS_SHIFT) & RHDA_NDS_MASK;
    231         int opResult = rh_init_descriptors(instance);
    232         if (opResult != EOK) {
    233                 return opResult;
    234         }
    235         // set port power mode to no-power-switching
     233        if (port_count > 15) {
     234                usb_log_error("OHCI specification does not allow more than 15"
     235                    " ports. Max 15 ports will be used");
     236                instance->port_count = 15;
     237        }
     238
     239        int ret = rh_init_descriptors(instance);
     240        if (ret != EOK) {
     241                return ret;
     242        }
     243        /* Set port power mode to no-power-switching. */
    236244        instance->registers->rh_desc_a |= RHDA_NPS_FLAG;
    237245        instance->unfinished_interrupt_transfer = NULL;
    238         instance->interrupt_mask_size = (instance->port_count + 8) / 8;
    239         instance->interrupt_buffer = malloc(instance->interrupt_mask_size);
    240         if (!instance->interrupt_buffer)
    241                 return ENOMEM;
     246        /* Don't forget the hub status bit and round up */
     247        instance->interrupt_mask_size = (instance->port_count + 1 + 8) / 8;
     248        instance->interrupt_buffer[0] = 0;
     249        instance->interrupt_buffer[1] = 0;
    242250
    243251        usb_log_info("Root hub (%zu ports) initialized.\n",
  • uspace/drv/bus/usb/ohci/root_hub.h

    raa81adc rece7f78  
    5757        /** pre-allocated interrupt mask
    5858         *
    59          * This is allocated when initializing instance, so that memory
    60          * allocation is not needed when processing request. Buffer is used for
    61          * interrupt bitmask.
     59         * OHCI support max 15 ports (specs page 124) + one global bit, it
     60         * gives max 2 bytes.
    6261         */
    63         uint8_t * interrupt_buffer;
     62        uint8_t interrupt_buffer[2];
    6463        /** size of interrupt buffer */
    6564        size_t interrupt_mask_size;
Note: See TracChangeset for help on using the changeset viewer.