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

Changeset 1368a6b in mainline


Ignore:
Timestamp:
2011-07-11T14:10:27Z (10 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
b7c2757
Parents:
5fd0dc23
Message:

OHCI: Root hub: Nice and clean initialization of descriptors.

Last malloc is out.

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

Legend:

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

    r5fd0dc23 r1368a6b  
    332332        const size_t size = 7 + (bit_field_size * 2);
    333333        assert(size <= HUB_DESCRIPTOR_MAX_SIZE);
    334         instance->descriptor_size = size;
     334        instance->hub_descriptor_size = size;
    335335
    336336        const uint32_t hub_desc = instance->registers->rh_desc_a;
     
    338338
    339339        /* bDescLength */
    340         instance->hub_descriptor[0] = size;
     340        instance->descriptors.hub[0] = size;
    341341        /* bDescriptorType */
    342         instance->hub_descriptor[1] = USB_DESCTYPE_HUB;
     342        instance->descriptors.hub[1] = USB_DESCTYPE_HUB;
    343343        /* bNmbrPorts */
    344         instance->hub_descriptor[2] = instance->port_count;
     344        instance->descriptors.hub[2] = instance->port_count;
    345345        /* wHubCharacteristics */
    346         instance->hub_descriptor[3] = 0 |
     346        instance->descriptors.hub[3] = 0 |
    347347            /* The lowest 2 bits indicate power switching mode */
    348348            (((hub_desc & RHDA_PSM_FLAG)  ? 1 : 0) << 0) |
     
    355355
    356356        /* Reserved */
    357         instance->hub_descriptor[4] = 0;
     357        instance->descriptors.hub[4] = 0;
    358358        /* bPwrOn2PwrGood */
    359         instance->hub_descriptor[5] =
     359        instance->descriptors.hub[5] =
    360360            (hub_desc >> RHDA_POTPGT_SHIFT) & RHDA_POTPGT_MASK;
    361361        /* bHubContrCurrent, root hubs don't need no power. */
    362         instance->hub_descriptor[6] = 0;
     362        instance->descriptors.hub[6] = 0;
    363363
    364364        /* Device Removable and some legacy 1.0 stuff*/
    365         instance->hub_descriptor[7] =
     365        instance->descriptors.hub[7] =
    366366            (port_desc >> RHDB_DR_SHIFT) & RHDB_DR_MASK & 0xff;
    367         instance->hub_descriptor[8] = 0xff;
     367        instance->descriptors.hub[8] = 0xff;
    368368        if (bit_field_size == 2) {
    369                 instance->hub_descriptor[8] =
     369                instance->descriptors.hub[8] =
    370370                    (port_desc >> RHDB_DR_SHIFT) & RHDB_DR_MASK >> 8;
    371                 instance->hub_descriptor[9]  = 0xff;
    372                 instance->hub_descriptor[10] = 0xff;
     371                instance->descriptors.hub[9]  = 0xff;
     372                instance->descriptors.hub[10] = 0xff;
    373373        }
    374374}
     
    385385        assert(instance);
    386386
    387         memcpy(&instance->descriptors.device, &ohci_rh_device_descriptor,
    388             sizeof(ohci_rh_device_descriptor));
    389 
    390         usb_standard_configuration_descriptor_t descriptor;
    391         memcpy(&descriptor, &ohci_rh_conf_descriptor,
    392             sizeof(ohci_rh_conf_descriptor));
    393 
     387        instance->descriptors.configuration = ohci_rh_conf_descriptor;
     388        instance->descriptors.interface = ohci_rh_iface_descriptor;
     389        instance->descriptors.endpoint = ohci_rh_ep_descriptor;
    394390        create_serialized_hub_descriptor(instance);
    395391
    396         descriptor.total_length =
     392        instance->descriptors.configuration.total_length =
    397393            sizeof(usb_standard_configuration_descriptor_t) +
    398394            sizeof(usb_standard_endpoint_descriptor_t) +
    399395            sizeof(usb_standard_interface_descriptor_t) +
    400             instance->descriptor_size;
    401 
    402         uint8_t *full_config_descriptor = malloc(descriptor.total_length);
    403         if (!full_config_descriptor)
    404                 return ENOMEM;
    405 
    406         uint8_t *place = full_config_descriptor;
    407         memcpy(place, &descriptor, sizeof(descriptor));
    408 
    409         place += sizeof(descriptor);
    410         memcpy(place, &ohci_rh_iface_descriptor,
    411             sizeof(ohci_rh_iface_descriptor));
    412 
    413         place += sizeof(ohci_rh_iface_descriptor);
    414         memcpy(place, &ohci_rh_ep_descriptor, sizeof(ohci_rh_ep_descriptor));
    415 
    416         place += sizeof(ohci_rh_iface_descriptor);
    417         memcpy(place, instance->hub_descriptor, instance->descriptor_size);
    418 
    419         instance->descriptors.configuration = full_config_descriptor;
    420         instance->descriptors.configuration_size = descriptor.total_length;
     396            instance->hub_descriptor_size;
    421397
    422398        return EOK;
     
    566542        case USB_DESCTYPE_HUB:
    567543                usb_log_debug2("USB_DESCTYPE_HUB\n");
    568                 result_descriptor = instance->hub_descriptor;
    569                 size = instance->descriptor_size;
     544                result_descriptor = instance->descriptors.hub;
     545                size = instance->hub_descriptor_size;
    570546                break;
    571547
     
    578554        case USB_DESCTYPE_CONFIGURATION:
    579555                usb_log_debug2("USB_DESCTYPE_CONFIGURATION\n");
    580                 result_descriptor = instance->descriptors.configuration;
    581                 size = instance->descriptors.configuration_size;
     556                result_descriptor = &instance->descriptors;
     557                size = instance->descriptors.configuration.total_length;
    582558                break;
    583559
  • uspace/drv/bus/usb/ohci/root_hub.h

    r5fd0dc23 r1368a6b  
    4141#include "batch.h"
    4242
    43 #define HUB_DESCRIPTOR_MAX_SIZE 11
     43#define HUB_DESCRIPTOR_MAX_SIZE (7 + 2 + 2)
    4444#define INTERRUPT_BUFFER_MAX_SIZE 2
    4545
     
    5454        /** hub port count */
    5555        size_t port_count;
    56         /** hubs descriptors */
    57         usb_device_descriptors_t descriptors;
    5856        /** interrupt transfer waiting for an actual interrupt to occur */
    5957        usb_transfer_batch_t *unfinished_interrupt_transfer;
     
    6664        /** size of interrupt buffer */
    6765        size_t interrupt_mask_size;
    68         /** instance`s descriptor*/
    69         uint8_t hub_descriptor[HUB_DESCRIPTOR_MAX_SIZE];
     66
     67        /** Descriptors */
     68        struct {
     69                usb_standard_configuration_descriptor_t configuration;
     70                usb_standard_interface_descriptor_t interface;
     71                usb_standard_endpoint_descriptor_t endpoint;
     72                uint8_t hub[HUB_DESCRIPTOR_MAX_SIZE];
     73        } __attribute__ ((packed)) descriptors;
    7074        /** size of hub descriptor */
    71         size_t descriptor_size;
     75        size_t hub_descriptor_size;
    7276
    7377} rh_t;
Note: See TracChangeset for help on using the changeset viewer.