Changeset 062b25f in mainline for uspace/drv/bus/usb/ohci/root_hub.c


Ignore:
Timestamp:
2011-07-11T11:27:57Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
01bbbb2
Parents:
c85804f
Message:

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

Still one more to go.
Add some asserts.

File:
1 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 =
Note: See TracChangeset for help on using the changeset viewer.