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

Changeset 062b25f in mainline


Ignore:
Timestamp:
2011-07-11T11:27:57Z (10 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
01bbbb2
Parents:
c85804f
Message:

OHCI: Root hub: Get rid of allocation in hub descriptor creation.

Still one more to go.
Add some asserts.

Location:
uspace
Files:
3 edited

Legend:

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

    rc85804f r062b25f  
    162162static const uint32_t port_status_change_mask = RHPS_CHANGE_WC_MASK;
    163163
    164 static int create_serialized_hub_descriptor(rh_t *instance);
     164static void create_serialized_hub_descriptor(rh_t *instance);
    165165
    166166static int rh_init_descriptors(rh_t *instance);
     
    227227{
    228228        assert(instance);
     229        assert(regs);
    229230
    230231        instance->registers = regs;
     
    321322 * @return Error code
    322323 */
    323 int create_serialized_hub_descriptor(rh_t *instance)
     324void create_serialized_hub_descriptor(rh_t *instance)
    324325{
    325326        assert(instance);
     
    329330        /* 7 bytes + 2 port bit fields (port count + global bit) */
    330331        const size_t size = 7 + (bit_field_size * 2);
    331 
    332         uint8_t *result = malloc(size);
    333         if (!result)
    334             return ENOMEM;
     332        assert(size <= HUB_DESCRIPTOR_MAX_SIZE);
     333        instance->descriptor_size = size;
     334
     335        const uint32_t hub_desc = instance->registers->rh_desc_a;
     336        const uint32_t port_desc = instance->registers->rh_desc_b;
    335337
    336338        /* bDescLength */
    337         result[0] = size;
     339        instance->hub_descriptor[0] = size;
    338340        /* bDescriptorType */
    339         result[1] = USB_DESCTYPE_HUB;
     341        instance->hub_descriptor[1] = USB_DESCTYPE_HUB;
    340342        /* bNmbrPorts */
    341         result[2] = instance->port_count;
    342         const uint32_t hub_desc = instance->registers->rh_desc_a;
     343        instance->hub_descriptor[2] = instance->port_count;
    343344        /* wHubCharacteristics */
    344         result[3] = 0 |
     345        instance->hub_descriptor[3] = 0 |
    345346            /* The lowest 2 bits indicate power switching mode */
    346347            (((hub_desc & RHDA_PSM_FLAG)  ? 1 : 0) << 0) |
     
    353354
    354355        /* Reserved */
    355         result[4] = 0;
     356        instance->hub_descriptor[4] = 0;
    356357        /* bPwrOn2PwrGood */
    357         result[5] = (hub_desc >> RHDA_POTPGT_SHIFT) & RHDA_POTPGT_MASK;
     358        instance->hub_descriptor[5] =
     359            (hub_desc >> RHDA_POTPGT_SHIFT) & RHDA_POTPGT_MASK;
    358360        /* bHubContrCurrent, root hubs don't need no power. */
    359         result[6] = 0;
    360 
    361         const uint32_t port_desc = instance->registers->rh_desc_a;
     361        instance->hub_descriptor[6] = 0;
     362
    362363        /* Device Removable and some legacy 1.0 stuff*/
    363         result[7] = (port_desc >> RHDB_DR_SHIFT) & RHDB_DR_MASK & 0xff;
    364         result[8] = 0xff;
     364        instance->hub_descriptor[7] =
     365            (port_desc >> RHDB_DR_SHIFT) & RHDB_DR_MASK & 0xff;
     366        instance->hub_descriptor[8] = 0xff;
    365367        if (bit_field_size == 2) {
    366                 result[8]  = (port_desc >> RHDB_DR_SHIFT) & RHDB_DR_MASK >> 8;
    367                 result[9]  = 0xff;
    368                 result[10] = 0xff;
    369         }
    370         instance->hub_descriptor = result;
    371         instance->descriptor_size = size;
    372 
    373         return EOK;
     368                instance->hub_descriptor[8] =
     369                    (port_desc >> RHDB_DR_SHIFT) & RHDB_DR_MASK >> 8;
     370                instance->hub_descriptor[9]  = 0xff;
     371                instance->hub_descriptor[10] = 0xff;
     372        }
    374373}
    375374/*----------------------------------------------------------------------------*/
     
    392391            sizeof(ohci_rh_conf_descriptor));
    393392
    394         int opResult = create_serialized_hub_descriptor(instance);
    395         if (opResult != EOK)
    396                 return opResult;
     393        create_serialized_hub_descriptor(instance);
    397394
    398395        descriptor.total_length =
  • uspace/drv/bus/usb/ohci/root_hub.h

    rc85804f r062b25f  
    4141#include "batch.h"
    4242
     43#define HUB_DESCRIPTOR_MAX_SIZE 11
     44#define INTERRUPT_BUFFER_MAX_SIZE 2
     45
    4346/**
    4447 * ohci root hub representation
     
    5457        usb_device_descriptors_t descriptors;
    5558        /** interrupt transfer waiting for an actual interrupt to occur */
    56         usb_transfer_batch_t * unfinished_interrupt_transfer;
     59        usb_transfer_batch_t *unfinished_interrupt_transfer;
    5760        /** Interrupt mask of changes
    5861         *
     
    6063         * gives max 2 bytes.
    6164         */
    62         uint8_t interrupt_buffer[2];
     65        uint8_t interrupt_buffer[INTERRUPT_BUFFER_MAX_SIZE];
    6366        /** size of interrupt buffer */
    6467        size_t interrupt_mask_size;
    6568        /** instance`s descriptor*/
    66         uint8_t * hub_descriptor;
     69        uint8_t hub_descriptor[HUB_DESCRIPTOR_MAX_SIZE];
    6770        /** size of hub descriptor */
    6871        size_t descriptor_size;
    69 
    7072
    7173} rh_t;
  • uspace/lib/usbhost/src/batch.c

    rc85804f r062b25f  
    109109        assert(instance);
    110110        assert(instance->ep);
     111        assert(instance->next_step);
    111112        endpoint_release(instance->ep);
    112113        instance->next_step(instance);
Note: See TracChangeset for help on using the changeset viewer.