Changeset 243cb86 in mainline for uspace/drv


Ignore:
Timestamp:
2010-12-12T10:50:19Z (15 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8365533
Parents:
101ef25c (diff), ebb98c5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from development + several changes to hid driver.

Changes to hid driver:

  • copied some code to usbkbd_get_descriptors() function
  • base structure for hid descriptor and report parser (files uspace/lib/usb/include/usb/classes/hidparser.h

and uspace/lib/usb/src/hidparser.c)

Location:
uspace/drv
Files:
17 added
1 deleted
16 edited
3 moved

Legend:

Unmodified
Added
Removed
  • uspace/drv/isa/isa.c

    r101ef25c r243cb86  
    282282
    283283                printf(NAME ": added io range (addr=0x%x, size=0x%x) to "
    284                     "device %s\n", addr, len, dev->name);
     284                    "device %s\n", (unsigned int) addr, (unsigned int) len,
     285                    dev->name);
    285286        }
    286287}
     
    489490static int isa_add_device(device_t *dev)
    490491{
    491         printf(NAME ": isa_add_device, device handle = %d\n", dev->handle);
     492        printf(NAME ": isa_add_device, device handle = %d\n",
     493            (int) dev->handle);
    492494
    493495        /* Add child devices. */
  • uspace/drv/ns8250/ns8250.c

    r101ef25c r243cb86  
    274274       
    275275        /* Gain control over port's registers. */
    276         if (pio_enable((void *) data->io_addr, REG_COUNT,
     276        if (pio_enable((void *)(uintptr_t) data->io_addr, REG_COUNT,
    277277            (void **) &data->port)) {
    278278                printf(NAME ": error - cannot gain the port %#" PRIx32 " for device "
     
    727727{
    728728        printf(NAME ": ns8250_add_device %s (handle = %d)\n",
    729             dev->name, dev->handle);
     729            dev->name, (int) dev->handle);
    730730       
    731731        int res = ns8250_dev_initialize(dev);
  • uspace/drv/pciintel/pci.c

    r101ef25c r243cb86  
    324324                printf(NAME ": device %s : ", dev->name);
    325325                printf("address = %" PRIx64, range_addr);
    326                 printf(", size = %x\n", range_size);
     326                printf(", size = %x\n", (unsigned int) range_size);
    327327        }
    328328       
     
    489489            (uint32_t) hw_resources.resources[0].res.io_range.address;
    490490       
    491         if (pio_enable((void *)bus_data->conf_io_addr, 8,
     491        if (pio_enable((void *)(uintptr_t)bus_data->conf_io_addr, 8,
    492492            &bus_data->conf_addr_port)) {
    493493                printf(NAME ": failed to enable configuration ports.\n");
  • uspace/drv/root/root.c

    r101ef25c r243cb86  
    11/*
    22 * Copyright (c) 2010 Lenka Trochtova
     3 * Copyright (c) 2010 Vojtech Horky
    34 * All rights reserved.
    45 *
     
    5354#define NAME "root"
    5455
     56#define PLATFORM_DEVICE_NAME "hw"
     57#define PLATFORM_DEVICE_MATCH_ID STRING(UARCH)
     58#define PLATFORM_DEVICE_MATCH_SCORE 100
     59
     60#define VIRTUAL_DEVICE_NAME "virt"
     61#define VIRTUAL_DEVICE_MATCH_ID "rootvirt"
     62#define VIRTUAL_DEVICE_MATCH_SCORE 100
     63
    5564static int root_add_device(device_t *dev);
    5665
     
    6675};
    6776
     77/** Create the device which represents the root of virtual device tree.
     78 *
     79 * @param parent Parent of the newly created device.
     80 * @return Error code.
     81 */
     82static int add_virtual_root_child(device_t *parent)
     83{
     84        printf(NAME ": adding new child for virtual devices.\n");
     85        printf(NAME ":   device node is `%s' (%d %s)\n", VIRTUAL_DEVICE_NAME,
     86            VIRTUAL_DEVICE_MATCH_SCORE, VIRTUAL_DEVICE_MATCH_ID);
     87
     88        int res = child_device_register_wrapper(parent, VIRTUAL_DEVICE_NAME,
     89            VIRTUAL_DEVICE_MATCH_ID, VIRTUAL_DEVICE_MATCH_SCORE,
     90            NULL);
     91
     92        return res;
     93}
     94
    6895/** Create the device which represents the root of HW device tree.
    6996 *
     
    74101{
    75102        printf(NAME ": adding new child for platform device.\n");
     103        printf(NAME ":   device node is `%s' (%d %s)\n", PLATFORM_DEVICE_NAME,
     104            PLATFORM_DEVICE_MATCH_SCORE, PLATFORM_DEVICE_MATCH_ID);
    76105       
    77         int res = EOK;
    78         device_t *platform = NULL;
    79         match_id_t *match_id = NULL;
    80        
    81         /* Create new device. */
    82         platform = create_device();
    83         if (NULL == platform) {
    84                 res = ENOMEM;
    85                 goto failure;
    86         }       
    87        
    88         platform->name = "hw";
    89         printf(NAME ": the new device's name is %s.\n", platform->name);
    90        
    91         /* Initialize match id list. */
    92         match_id = create_match_id();
    93         if (NULL == match_id) {
    94                 res = ENOMEM;
    95                 goto failure;
    96         }
    97        
    98         /* TODO - replace this with some better solution (sysinfo ?) */
    99         match_id->id = STRING(UARCH);
    100         match_id->score = 100;
    101         add_match_id(&platform->match_ids, match_id);
    102        
    103         /* Register child device. */
    104         res = child_device_register(platform, parent);
    105         if (EOK != res)
    106                 goto failure;
    107        
     106        int res = child_device_register_wrapper(parent, PLATFORM_DEVICE_NAME,
     107            PLATFORM_DEVICE_MATCH_ID, PLATFORM_DEVICE_MATCH_SCORE,
     108            NULL);
     109
    108110        return res;
    109        
    110 failure:
    111         if (NULL != match_id)
    112                 match_id->id = NULL;
    113        
    114         if (NULL != platform) {
    115                 platform->name = NULL;
    116                 delete_device(platform);
    117         }
    118        
    119         return res;
    120 }
    121 
    122 /** Create virtual USB host controller device.
    123  * Note that the virtual HC is actually device and driver in one
    124  * task.
    125  *
    126  * @param parent Parent device.
    127  * @return Error code.
    128  */
    129 static int add_virtual_usb_host_controller(device_t *parent)
    130 {
    131         printf(NAME ": adding virtual host contoller.\n");
    132 
    133         int rc;
    134         device_t *vhc = NULL;
    135         match_id_t *match_id = NULL;
    136 
    137         vhc = create_device();
    138         if (vhc == NULL) {
    139                 rc = ENOMEM;
    140                 goto failure;
    141         }
    142 
    143         vhc->name = "vhc";
    144         printf(NAME ": the new device's name is %s.\n", vhc->name);
    145 
    146         /* Initialize match id list. */
    147         match_id = create_match_id();
    148         if (match_id == NULL) {
    149                 rc = ENOMEM;
    150                 goto failure;
    151         }
    152 
    153         match_id->id = "usb&hc=vhc";
    154         match_id->score = 100;
    155         add_match_id(&vhc->match_ids, match_id);
    156 
    157         /* Register child device. */
    158         rc = child_device_register(vhc, parent);
    159         if (rc != EOK)
    160                 goto failure;
    161 
    162         return EOK;
    163 
    164 failure:
    165         if (match_id != NULL)
    166                 match_id->id = NULL;
    167 
    168         if (vhc != NULL) {
    169                 vhc->name = NULL;
    170                 delete_device(vhc);
    171         }
    172 
    173         return rc;
    174111}
    175112
     
    184121            dev->handle);
    185122       
     123        /*
     124         * Register virtual devices root.
     125         * We ignore error occurrence because virtual devices shall not be
     126         * vital for the system.
     127         */
     128        add_virtual_root_child(dev);
     129
    186130        /* Register root device's children. */
    187131        int res = add_platform_child(dev);
     
    189133                printf(NAME ": failed to add child device for platform.\n");
    190134       
    191         /* Register virtual USB host controller. */
    192         int rc = add_virtual_usb_host_controller(dev);
    193         if (EOK != rc) {
    194                 printf(NAME ": failed to add child device - virtual USB HC.\n");
    195         }
    196 
    197135        return res;
    198136}
  • uspace/drv/rootpc/Makefile

    r101ef25c r243cb86  
    3030LIBS = $(LIBDRV_PREFIX)/libdrv.a
    3131EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include
    32 BINARY = rootia32
     32BINARY = rootpc
    3333
    3434SOURCES = \
    35         rootia32.c
     35        rootpc.c
    3636
    3737include $(USPACE_PREFIX)/Makefile.common
  • uspace/drv/rootpc/rootpc.c

    r101ef25c r243cb86  
    2828
    2929/**
    30  * @defgroup root_ia32 Root HW device driver for ia32 platform.
    31  * @brief HelenOS root HW device driver for ia32 platform.
     30 * @defgroup root_pc Root HW device driver for ia32 and amd64 platform.
     31 * @brief HelenOS root HW device driver for ia32 and amd64 platform.
    3232 * @{
    3333 */
     
    5353#include <device/hw_res.h>
    5454
    55 #define NAME "rootia32"
    56 
    57 typedef struct rootia32_child_dev_data {
     55#define NAME "rootpc"
     56
     57typedef struct rootpc_child_dev_data {
    5858        hw_resource_list_t hw_resources;
    59 } rootia32_child_dev_data_t;
    60 
    61 static int rootia32_add_device(device_t *dev);
    62 static void root_ia32_init(void);
     59} rootpc_child_dev_data_t;
     60
     61static int rootpc_add_device(device_t *dev);
     62static void root_pc_init(void);
    6363
    6464/** The root device driver's standard operations. */
    65 static driver_ops_t rootia32_ops = {
    66         .add_device = &rootia32_add_device
     65static driver_ops_t rootpc_ops = {
     66        .add_device = &rootpc_add_device
    6767};
    6868
    6969/** The root device driver structure. */
    70 static driver_t rootia32_driver = {
     70static driver_t rootpc_driver = {
    7171        .name = NAME,
    72         .driver_ops = &rootia32_ops
     72        .driver_ops = &rootpc_ops
    7373};
    7474
     
    8282};
    8383
    84 static rootia32_child_dev_data_t pci_data = {
     84static rootpc_child_dev_data_t pci_data = {
    8585        .hw_resources = {
    8686                1,
     
    8989};
    9090
    91 static hw_resource_list_t *rootia32_get_child_resources(device_t *dev)
    92 {
    93         rootia32_child_dev_data_t *data;
    94        
    95         data = (rootia32_child_dev_data_t *) dev->driver_data;
     91static hw_resource_list_t *rootpc_get_child_resources(device_t *dev)
     92{
     93        rootpc_child_dev_data_t *data;
     94       
     95        data = (rootpc_child_dev_data_t *) dev->driver_data;
    9696        if (NULL == data)
    9797                return NULL;
     
    100100}
    101101
    102 static bool rootia32_enable_child_interrupt(device_t *dev)
     102static bool rootpc_enable_child_interrupt(device_t *dev)
    103103{
    104104        /* TODO */
     
    108108
    109109static resource_iface_t child_res_iface = {
    110         &rootia32_get_child_resources,
    111         &rootia32_enable_child_interrupt
    112 };
    113 
    114 /* Initialized in root_ia32_init() function. */
    115 static device_ops_t rootia32_child_ops;
     110        &rootpc_get_child_resources,
     111        &rootpc_enable_child_interrupt
     112};
     113
     114/* Initialized in root_pc_init() function. */
     115static device_ops_t rootpc_child_ops;
    116116
    117117static bool
    118 rootia32_add_child(device_t *parent, const char *name, const char *str_match_id,
    119     rootia32_child_dev_data_t *drv_data)
     118rootpc_add_child(device_t *parent, const char *name, const char *str_match_id,
     119    rootpc_child_dev_data_t *drv_data)
    120120{
    121121        printf(NAME ": adding new child device '%s'.\n", name);
     
    142142       
    143143        /* Set provided operations to the device. */
    144         child->ops = &rootia32_child_ops;
     144        child->ops = &rootpc_child_ops;
    145145       
    146146        /* Register child device. */
     
    164164}
    165165
    166 static bool rootia32_add_children(device_t *dev)
    167 {
    168         return rootia32_add_child(dev, "pci0", "intel_pci", &pci_data);
     166static bool rootpc_add_children(device_t *dev)
     167{
     168        return rootpc_add_child(dev, "pci0", "intel_pci", &pci_data);
    169169}
    170170
     
    175175 * @return              Zero on success, negative error number otherwise.
    176176 */
    177 static int rootia32_add_device(device_t *dev)
    178 {
    179         printf(NAME ": rootia32_add_device, device handle = %d\n", dev->handle);
     177static int rootpc_add_device(device_t *dev)
     178{
     179        printf(NAME ": rootpc_add_device, device handle = %d\n",
     180            (int)dev->handle);
    180181       
    181182        /* Register child devices. */
    182         if (!rootia32_add_children(dev)) {
     183        if (!rootpc_add_children(dev)) {
    183184                printf(NAME ": failed to add child devices for platform "
    184185                    "ia32.\n");
     
    188189}
    189190
    190 static void root_ia32_init(void)
    191 {
    192         rootia32_child_ops.interfaces[HW_RES_DEV_IFACE] = &child_res_iface;
     191static void root_pc_init(void)
     192{
     193        rootpc_child_ops.interfaces[HW_RES_DEV_IFACE] = &child_res_iface;
    193194}
    194195
    195196int main(int argc, char *argv[])
    196197{
    197         printf(NAME ": HelenOS rootia32 device driver\n");
    198         root_ia32_init();
    199         return driver_main(&rootia32_driver);
     198        printf(NAME ": HelenOS rootpc device driver\n");
     199        root_pc_init();
     200        return driver_main(&rootpc_driver);
    200201}
    201202
  • uspace/drv/uhci/Makefile

    r101ef25c r243cb86  
    3333
    3434SOURCES = \
    35         main.c
     35        main.c \
     36        transfers.c
    3637
    3738include $(USPACE_PREFIX)/Makefile.common
  • uspace/drv/uhci/main.c

    r101ef25c r243cb86  
    2727 */
    2828#include <usb/hcdhubd.h>
     29#include <usb/debug.h>
    2930#include <errno.h>
     31#include "uhci.h"
    3032
    31 static int enqueue_transfer_out(usb_hc_device_t *hc,
    32     usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,
    33     void *buffer, size_t size,
    34     usb_hcd_transfer_callback_out_t callback, void *arg)
    35 {
    36         printf("UHCI: transfer OUT [%d.%d (%s); %u]\n",
    37             dev->address, endpoint->endpoint,
    38             usb_str_transfer_type(endpoint->transfer_type),
    39             size);
    40         return ENOTSUP;
    41 }
    42 
    43 static int enqueue_transfer_setup(usb_hc_device_t *hc,
    44     usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,
    45     void *buffer, size_t size,
    46     usb_hcd_transfer_callback_out_t callback, void *arg)
    47 {
    48         printf("UHCI: transfer SETUP [%d.%d (%s); %u]\n",
    49             dev->address, endpoint->endpoint,
    50             usb_str_transfer_type(endpoint->transfer_type),
    51             size);
    52         return ENOTSUP;
    53 }
    54 
    55 static int enqueue_transfer_in(usb_hc_device_t *hc,
    56     usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,
    57     void *buffer, size_t size,
    58     usb_hcd_transfer_callback_in_t callback, void *arg)
    59 {
    60         printf("UHCI: transfer IN [%d.%d (%s); %u]\n",
    61             dev->address, endpoint->endpoint,
    62             usb_str_transfer_type(endpoint->transfer_type),
    63             size);
    64         return ENOTSUP;
    65 }
    66 
    67 static usb_hcd_transfer_ops_t uhci_transfer_ops = {
    68         .transfer_out = enqueue_transfer_out,
    69         .transfer_in = enqueue_transfer_in,
    70         .transfer_setup = enqueue_transfer_setup
     33static device_ops_t uhci_ops = {
     34        .interfaces[USBHC_DEV_IFACE] = &uhci_iface,
    7135};
    7236
    73 static int uhci_add_hc(usb_hc_device_t *device)
     37static int uhci_add_device(device_t *device)
    7438{
    75         device->transfer_ops = &uhci_transfer_ops;
     39        usb_dprintf(NAME, 1, "uhci_add_device() called\n");
     40        device->ops = &uhci_ops;
    7641
    7742        /*
    7843         * We need to announce the presence of our root hub.
    7944         */
     45        usb_dprintf(NAME, 2, "adding root hub\n");
    8046        usb_hcd_add_root_hub(device);
    8147
     
    8349}
    8450
    85 usb_hc_driver_t uhci_driver = {
    86         .name = "uhci",
    87         .add_hc = uhci_add_hc
     51static driver_ops_t uhci_driver_ops = {
     52        .add_device = uhci_add_device,
     53};
     54
     55static driver_t uhci_driver = {
     56        .name = NAME,
     57        .driver_ops = &uhci_driver_ops
    8858};
    8959
     
    9363         * Do some global initializations.
    9464         */
     65        sleep(5);
     66        usb_dprintf_enable(NAME, 5);
    9567
    96         return usb_hcd_main(&uhci_driver);
     68        return driver_main(&uhci_driver);
    9769}
  • uspace/drv/uhci/uhci.ma

    r101ef25c r243cb86  
    1110 pci/ven=8086&dev=7020
    2 10 usb&hc=uhci
    3 10 usb&hc=uhci&hub
     2
  • uspace/drv/usbhub/utils.c

    r101ef25c r243cb86  
    3333 * @brief Hub driver.
    3434 */
    35 #include <usb/hcdhubd.h>
     35#include <driver.h>
    3636#include <usb/devreq.h>
    3737#include <usbhc_iface.h>
     38#include <usb/usbdrv.h>
    3839#include <usb/descriptor.h>
    3940#include <driver.h>
     
    4142#include <errno.h>
    4243#include <usb/classes/hub.h>
    43 #include "hcdhubd_private.h"
     44#include "usbhub.h"
    4445
    4546static void check_hub_changes(void);
     
    108109//*********************************************
    109110
    110 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address);
    111 
    112111usb_hcd_hub_info_t * usb_create_hub_info(device_t * device) {
    113112        usb_hcd_hub_info_t* result = (usb_hcd_hub_info_t*) malloc(sizeof (usb_hcd_hub_info_t));
    114         //get parent device
    115         /// @TODO this code is not correct
    116         device_t * my_hcd = device;
    117         while (my_hcd->parent)
    118                 my_hcd = my_hcd->parent;
    119         //dev->
    120         printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);
    121         //we add the hub into the first hc
    122         //link_t *link_hc = hc_list.next;
    123         //usb_hc_device_t *hc = list_get_instance(link_hc,
    124         //              usb_hc_device_t, link);
    125         //must get generic device info
    126 
    127113
    128114        return result;
     
    135121 */
    136122int usb_add_hub_device(device_t *dev) {
    137         usb_hc_device_t *hc = list_get_instance(hc_list.next, usb_hc_device_t, link);
    138         set_hub_address(hc, 5);
     123        printf(NAME ": add_hub_device(handle=%d)\n", (int) dev->handle);
    139124
    140125        check_hub_changes();
     
    145130         * connected devices.
    146131         */
    147         //insert hub into list
    148         //find owner hcd
    149         device_t * my_hcd = dev;
    150         while (my_hcd->parent)
    151                 my_hcd = my_hcd->parent;
    152         //dev->
    153         printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);
    154         my_hcd = dev;
    155         while (my_hcd->parent)
    156                 my_hcd = my_hcd->parent;
    157         //dev->
    158 
    159         printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);
    160132
    161133        //create the hub structure
    162134        usb_hcd_hub_info_t * hub_info = usb_create_hub_info(dev);
    163 
    164 
    165         //append into the list
    166         //we add the hub into the first hc
    167         list_append(&hub_info->link, &hc->hubs);
    168 
    169 
     135        (void)hub_info;
    170136
    171137        return EOK;
     
    173139}
    174140
    175 /** Sample usage of usb_hc_async functions.
    176  * This function sets hub address using standard SET_ADDRESS request.
    177  *
    178  * @warning This function shall be removed once you are familiar with
    179  * the usb_hc_ API.
    180  *
    181  * @param hc Host controller the hub belongs to.
    182  * @param address New hub address.
    183  */
    184 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address) {
    185         printf("%s: setting hub address to %d\n", hc->generic->name, address);
    186         usb_target_t target = {0, 0};
    187         usb_handle_t handle;
    188         int rc;
    189 
    190         usb_device_request_setup_packet_t setup_packet = {
    191                 .request_type = 0,
    192                 .request = USB_DEVREQ_SET_ADDRESS,
    193                 .index = 0,
    194                 .length = 0,
    195         };
    196         setup_packet.value = address;
    197 
    198         rc = usb_hc_async_control_write_setup(hc, target,
    199                         &setup_packet, sizeof (setup_packet), &handle);
    200         if (rc != EOK) {
    201                 return;
    202         }
    203 
    204         rc = usb_hc_async_wait_for(handle);
    205         if (rc != EOK) {
    206                 return;
    207         }
    208 
    209         rc = usb_hc_async_control_write_status(hc, target, &handle);
    210         if (rc != EOK) {
    211                 return;
    212         }
    213 
    214         rc = usb_hc_async_wait_for(handle);
    215         if (rc != EOK) {
    216                 return;
    217         }
    218 
    219         printf("%s: hub address changed\n", hc->generic->name);
    220 }
    221141
    222142/** Check changes on all known hubs.
     
    224144static void check_hub_changes(void) {
    225145        /*
    226          * Iterate through all HCs.
     146         * Iterate through all hubs.
    227147         */
    228         link_t *link_hc;
    229         for (link_hc = hc_list.next;
    230                         link_hc != &hc_list;
    231                         link_hc = link_hc->next) {
    232                 usb_hc_device_t *hc = list_get_instance(link_hc,
    233                                 usb_hc_device_t, link);
    234                 /*
    235                  * Iterate through all their hubs.
    236                  */
    237                 link_t *link_hub;
    238                 for (link_hub = hc->hubs.next;
    239                                 link_hub != &hc->hubs;
    240                                 link_hub = link_hub->next) {
    241                         usb_hcd_hub_info_t *hub = list_get_instance(link_hub,
    242                                         usb_hcd_hub_info_t, link);
    243 
    244                         /*
    245                          * Check status change pipe of this hub.
    246                          */
    247                         usb_target_t target = {
    248                                 .address = hub->device->address,
    249                                 .endpoint = 1
    250                         };
    251 
    252                         // FIXME: count properly
    253                         size_t byte_length = (hub->port_count / 8) + 1;
    254 
    255                         void *change_bitmap = malloc(byte_length);
    256                         size_t actual_size;
    257                         usb_handle_t handle;
    258 
    259                         /*
    260                          * Send the request.
    261                          * FIXME: check returned value for possible errors
    262                          */
    263                         usb_hc_async_interrupt_in(hc, target,
    264                                         change_bitmap, byte_length, &actual_size,
    265                                         &handle);
    266 
    267                         usb_hc_async_wait_for(handle);
    268 
    269                         /*
    270                          * TODO: handle the changes.
    271                          */
     148        for (; false; ) {
     149                /*
     150                 * Check status change pipe of this hub.
     151                 */
     152                usb_target_t target = {
     153                        .address = 5,
     154                        .endpoint = 1
     155                };
     156
     157                size_t port_count = 7;
     158
     159                /*
     160                 * Connect to respective HC.
     161                 */
     162                int hc = usb_drv_hc_connect(NULL, 0);
     163                if (hc < 0) {
     164                        continue;
    272165                }
     166
     167                // FIXME: count properly
     168                size_t byte_length = (port_count / 8) + 1;
     169
     170                void *change_bitmap = malloc(byte_length);
     171                size_t actual_size;
     172                usb_handle_t handle;
     173
     174                /*
     175                 * Send the request.
     176                 * FIXME: check returned value for possible errors
     177                 */
     178                usb_drv_async_interrupt_in(hc, target,
     179                                change_bitmap, byte_length, &actual_size,
     180                                &handle);
     181
     182                usb_drv_async_wait_for(handle);
     183
     184                /*
     185                 * TODO: handle the changes.
     186                 */
     187
     188                /*
     189                 * WARNING: sample code, will not work out of the box.
     190                 * And does not contain code for checking for errors.
     191                 */
     192#if 0
     193                /*
     194                 * Before opening the port, we must acquire the default
     195                 * address.
     196                 */
     197                usb_drv_reserve_default_address(hc);
     198
     199                usb_address_t new_device_address = usb_drv_request_address(hc);
     200
     201                // TODO: open the port
     202
     203                // TODO: send request for setting address to new_device_address
     204
     205                /*
     206                 * Once new address is set, we can release the default
     207                 * address.
     208                 */
     209                usb_drv_release_default_address(hc);
     210
     211                /*
     212                 * Obtain descriptors and create match ids for devman.
     213                 */
     214
     215                // TODO: get device descriptors
     216
     217                // TODO: create match ids
     218
     219                // TODO: add child device
     220
     221                // child_device_register sets the device handle
     222                // TODO: store it here
     223                devman_handle_t new_device_handle = 0;
     224
     225                /*
     226                 * Inform the HC that the new device has devman handle
     227                 * assigned.
     228                 */
     229                usb_drv_bind_address(hc, new_device_address, new_device_handle);
     230
     231                /*
     232                 * That's all.
     233                 */
     234#endif
     235
     236
     237                /*
     238                 * Hang-up the HC-connected phone.
     239                 */
     240                ipc_hangup(hc);
    273241        }
    274242}
  • uspace/drv/usbkbd/main.c

    r101ef25c r243cb86  
    3232#include <fibril.h>
    3333#include <usb/classes/hid.h>
     34#include <usb/classes/hidparser.h>
     35#include <usb/devreq.h>
    3436
    3537#define BUFFER_SIZE 32
     
    3739
    3840static const usb_endpoint_t CONTROL_EP = 0;
     41
     42/*
     43 * Callbacks for parser
     44 */
     45static void usbkbd_process_keycodes(const uint16_t *key_codes, size_t count,
     46                                    void *arg)
     47{
     48
     49}
     50
     51/*
     52 * Kbd functions
     53 */
     54static int usbkbd_get_descriptors()
     55{
     56        // copy-pasted:
     57       
     58        /* Prepare the setup packet. */
     59        usb_device_request_setup_packet_t setup_packet = {
     60                .request_type = 128,
     61                .request = USB_DEVREQ_GET_DESCRIPTOR,
     62                .index = 0,
     63                .length = sizeof(usb_standard_device_descriptor_t)
     64        };
     65       
     66        setup_packet.value_high = USB_DESCTYPE_DEVICE;
     67        setup_packet.value_low = 0;
     68
     69        /* Prepare local descriptor. */
     70        size_t actually_transferred = 0;
     71        usb_standard_device_descriptor_t descriptor_tmp;
     72
     73        /* Perform the control read transaction. */
     74        int rc = usb_drv_psync_control_read(phone, target,
     75            &setup_packet, sizeof(setup_packet),
     76            &descriptor_tmp, sizeof(descriptor_tmp), &actually_transferred);
     77
     78        if (rc != EOK) {
     79                return rc;
     80        }
     81       
     82        // end of copy-paste
     83}
    3984
    4085static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
     
    68113
    69114        // TODO: get descriptors
    70 
     115        usbkbd_get_descriptors();
    71116        // TODO: parse descriptors and save endpoints
    72117
     
    75120
    76121static void usbkbd_process_interrupt_in(usb_hid_dev_kbd_t *kbd_dev,
    77                                         char *buffer, size_t actual_size)
     122                                        uint8_t *buffer, size_t actual_size)
    78123{
    79124        /*
     
    81126         * now only take last 6 bytes and process, i.e. send to kbd
    82127         */
     128
     129        usb_hid_report_in_callbacks_t *callbacks =
     130            (usb_hid_report_in_callbacks_t *)malloc(
     131                sizeof(usb_hid_report_in_callbacks_t));
     132        callbacks->keyboard = usbkbd_process_keycodes;
     133
     134        usb_hid_parse_report(kbd_dev->parser, buffer, callbacks, NULL);
    83135}
    84136
     
    87139        int rc;
    88140        usb_handle_t handle;
    89         char buffer[BUFFER_SIZE];
     141        uint8_t buffer[BUFFER_SIZE];
    90142        size_t actual_size;
    91143        //usb_endpoint_t poll_endpoint = 1;
  • uspace/drv/vhc/conn.h

    r101ef25c r243cb86  
    3838#include <usb/usb.h>
    3939#include <usb/hcdhubd.h>
     40#include <usbhc_iface.h>
    4041#include "vhcd.h"
    4142#include "devices.h"
     
    4445
    4546usb_hcd_transfer_ops_t vhc_transfer_ops;
     47usbhc_iface_t vhc_iface;
     48
     49void address_init(void);
     50
    4651
    4752void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *);
  • uspace/drv/vhc/connhost.c

    r101ef25c r243cb86  
    3636#include <errno.h>
    3737#include <usb/usb.h>
     38#include <usb/hcd.h>
    3839
    3940#include "vhcd.h"
     
    4344typedef struct {
    4445        usb_direction_t direction;
    45         usb_hcd_transfer_callback_out_t out_callback;
    46         usb_hcd_transfer_callback_in_t in_callback;
    47         usb_hc_device_t *hc;
     46        usbhc_iface_transfer_out_callback_t out_callback;
     47        usbhc_iface_transfer_in_callback_t in_callback;
     48        device_t *dev;
    4849        void *arg;
    4950} transfer_info_t;
     
    5657        switch (transfer->direction) {
    5758                case USB_DIRECTION_IN:
    58                         transfer->in_callback(transfer->hc,
    59                             size, outcome,
     59                        transfer->in_callback(transfer->dev,
     60                            outcome, size,
    6061                            transfer->arg);
    6162                        break;
    6263                case USB_DIRECTION_OUT:
    63                         transfer->out_callback(transfer->hc,
     64                        transfer->out_callback(transfer->dev,
    6465                            outcome,
    6566                            transfer->arg);
     
    7374}
    7475
    75 static transfer_info_t *create_transfer_info(usb_hc_device_t *hc,
     76static transfer_info_t *create_transfer_info(device_t *dev,
    7677    usb_direction_t direction, void *arg)
    7778{
     
    8283        transfer->out_callback = NULL;
    8384        transfer->arg = arg;
    84         transfer->hc = hc;
     85        transfer->dev = dev;
    8586
    8687        return transfer;
    8788}
    8889
    89 static int enqueue_transfer_out(usb_hc_device_t *hc,
    90     usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,
     90static int enqueue_transfer_out(device_t *dev,
     91    usb_target_t target, usb_transfer_type_t transfer_type,
    9192    void *buffer, size_t size,
    92     usb_hcd_transfer_callback_out_t callback, void *arg)
    93 {
    94         printf(NAME ": transfer OUT [%d.%d (%s); %u]\n",
    95             dev->address, endpoint->endpoint,
    96             usb_str_transfer_type(endpoint->transfer_type),
     93    usbhc_iface_transfer_out_callback_t callback, void *arg)
     94{
     95        printf(NAME ": transfer OUT [%d.%d (%s); %zu]\n",
     96            target.address, target.endpoint,
     97            usb_str_transfer_type(transfer_type),
    9798            size);
    9899
    99100        transfer_info_t *transfer
    100             = create_transfer_info(hc, USB_DIRECTION_OUT, arg);
     101            = create_transfer_info(dev, USB_DIRECTION_OUT, arg);
    101102        transfer->out_callback = callback;
    102 
    103         usb_target_t target = {
    104                 .address = dev->address,
    105                 .endpoint = endpoint->endpoint
    106         };
    107103
    108104        hc_add_transaction_to_device(false, target, buffer, size,
     
    112108}
    113109
    114 static int enqueue_transfer_setup(usb_hc_device_t *hc,
    115     usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,
     110static int enqueue_transfer_setup(device_t *dev,
     111    usb_target_t target, usb_transfer_type_t transfer_type,
    116112    void *buffer, size_t size,
    117     usb_hcd_transfer_callback_out_t callback, void *arg)
    118 {
    119         printf(NAME ": transfer SETUP [%d.%d (%s); %u]\n",
    120             dev->address, endpoint->endpoint,
    121             usb_str_transfer_type(endpoint->transfer_type),
     113    usbhc_iface_transfer_out_callback_t callback, void *arg)
     114{
     115        printf(NAME ": transfer SETUP [%d.%d (%s); %zu]\n",
     116            target.address, target.endpoint,
     117            usb_str_transfer_type(transfer_type),
    122118            size);
    123119
    124120        transfer_info_t *transfer
    125             = create_transfer_info(hc, USB_DIRECTION_OUT, arg);
     121            = create_transfer_info(dev, USB_DIRECTION_OUT, arg);
    126122        transfer->out_callback = callback;
    127 
    128         usb_target_t target = {
    129                 .address = dev->address,
    130                 .endpoint = endpoint->endpoint
    131         };
    132123
    133124        hc_add_transaction_to_device(true, target, buffer, size,
     
    137128}
    138129
    139 static int enqueue_transfer_in(usb_hc_device_t *hc,
    140     usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,
     130static int enqueue_transfer_in(device_t *dev,
     131    usb_target_t target, usb_transfer_type_t transfer_type,
    141132    void *buffer, size_t size,
    142     usb_hcd_transfer_callback_in_t callback, void *arg)
    143 {
    144         printf(NAME ": transfer IN [%d.%d (%s); %u]\n",
    145             dev->address, endpoint->endpoint,
    146             usb_str_transfer_type(endpoint->transfer_type),
     133    usbhc_iface_transfer_in_callback_t callback, void *arg)
     134{
     135        printf(NAME ": transfer IN [%d.%d (%s); %zu]\n",
     136            target.address, target.endpoint,
     137            usb_str_transfer_type(transfer_type),
    147138            size);
    148139
    149140        transfer_info_t *transfer
    150             = create_transfer_info(hc, USB_DIRECTION_IN, arg);
     141            = create_transfer_info(dev, USB_DIRECTION_IN, arg);
    151142        transfer->in_callback = callback;
    152 
    153         usb_target_t target = {
    154                 .address = dev->address,
    155                 .endpoint = endpoint->endpoint
    156         };
    157143
    158144        hc_add_transaction_from_device(target, buffer, size,
     
    163149
    164150
    165 usb_hcd_transfer_ops_t vhc_transfer_ops = {
    166         .transfer_out = enqueue_transfer_out,
    167         .transfer_in = enqueue_transfer_in,
    168         .transfer_setup = enqueue_transfer_setup
     151static int interrupt_out(device_t *dev, usb_target_t target,
     152    void *data, size_t size,
     153    usbhc_iface_transfer_out_callback_t callback, void *arg)
     154{
     155        return enqueue_transfer_out(dev, target, USB_TRANSFER_INTERRUPT,
     156            data, size,
     157            callback, arg);
     158}
     159
     160static int interrupt_in(device_t *dev, usb_target_t target,
     161    void *data, size_t size,
     162    usbhc_iface_transfer_in_callback_t callback, void *arg)
     163{
     164        return enqueue_transfer_in(dev, target, USB_TRANSFER_INTERRUPT,
     165            data, size,
     166            callback, arg);
     167}
     168
     169static int control_write_setup(device_t *dev, usb_target_t target,
     170    void *data, size_t size,
     171    usbhc_iface_transfer_out_callback_t callback, void *arg)
     172{
     173        return enqueue_transfer_setup(dev, target, USB_TRANSFER_CONTROL,
     174            data, size,
     175            callback, arg);
     176}
     177
     178static int control_write_data(device_t *dev, usb_target_t target,
     179    void *data, size_t size,
     180    usbhc_iface_transfer_out_callback_t callback, void *arg)
     181{
     182        return enqueue_transfer_out(dev, target, USB_TRANSFER_CONTROL,
     183            data, size,
     184            callback, arg);
     185}
     186
     187static int control_write_status(device_t *dev, usb_target_t target,
     188    usbhc_iface_transfer_in_callback_t callback, void *arg)
     189{
     190        return enqueue_transfer_in(dev, target, USB_TRANSFER_CONTROL,
     191            NULL, 0,
     192            callback, arg);
     193}
     194
     195static int control_read_setup(device_t *dev, usb_target_t target,
     196    void *data, size_t size,
     197    usbhc_iface_transfer_out_callback_t callback, void *arg)
     198{
     199        return enqueue_transfer_setup(dev, target, USB_TRANSFER_CONTROL,
     200            data, size,
     201            callback, arg);
     202}
     203
     204static int control_read_data(device_t *dev, usb_target_t target,
     205    void *data, size_t size,
     206    usbhc_iface_transfer_in_callback_t callback, void *arg)
     207{
     208        return enqueue_transfer_in(dev, target, USB_TRANSFER_CONTROL,
     209            data, size,
     210            callback, arg);
     211}
     212
     213static int control_read_status(device_t *dev, usb_target_t target,
     214    usbhc_iface_transfer_out_callback_t callback, void *arg)
     215{
     216        return enqueue_transfer_out(dev, target, USB_TRANSFER_CONTROL,
     217            NULL, 0,
     218            callback, arg);
     219}
     220
     221static usb_address_keeping_t addresses;
     222
     223
     224static int reserve_default_address(device_t *dev)
     225{
     226        usb_address_keeping_reserve_default(&addresses);
     227        return EOK;
     228}
     229
     230static int release_default_address(device_t *dev)
     231{
     232        usb_address_keeping_release_default(&addresses);
     233        return EOK;
     234}
     235
     236static int request_address(device_t *dev, usb_address_t *address)
     237{
     238        usb_address_t addr = usb_address_keeping_request(&addresses);
     239        if (addr < 0) {
     240                return (int)addr;
     241        }
     242
     243        *address = addr;
     244        return EOK;
     245}
     246
     247static int release_address(device_t *dev, usb_address_t address)
     248{
     249        return usb_address_keeping_release(&addresses, address);
     250}
     251
     252static int bind_address(device_t *dev, usb_address_t address,
     253    devman_handle_t handle)
     254{
     255        usb_address_keeping_devman_bind(&addresses, address, handle);
     256        return EOK;
     257}
     258
     259static int tell_address(device_t *dev, devman_handle_t handle,
     260    usb_address_t *address)
     261{
     262        usb_address_t addr = usb_address_keeping_find(&addresses, handle);
     263        if (addr < 0) {
     264                return addr;
     265        }
     266
     267        *address = addr;
     268        return EOK;
     269}
     270
     271void address_init(void)
     272{
     273        usb_address_keeping_init(&addresses, 50);
     274}
     275
     276usbhc_iface_t vhc_iface = {
     277        .tell_address = tell_address,
     278
     279        .reserve_default_address = reserve_default_address,
     280        .release_default_address = release_default_address,
     281        .request_address = request_address,
     282        .bind_address = bind_address,
     283        .release_address = release_address,
     284
     285        .interrupt_out = interrupt_out,
     286        .interrupt_in = interrupt_in,
     287
     288        .control_write_setup = control_write_setup,
     289        .control_write_data = control_write_data,
     290        .control_write_status = control_write_status,
     291
     292        .control_read_setup = control_read_setup,
     293        .control_read_data = control_read_data,
     294        .control_read_status = control_read_status
    169295};
    170296
  • uspace/drv/vhc/debug.c

    r101ef25c r243cb86  
    3535#include <stdio.h>
    3636#include <ipc/ipc.h>
     37#include <usb/debug.h>
    3738
    3839#include "vhcd.h"
    3940
    40 /** Current debug level. */
    41 int debug_level = 0;
    42 
    43 /** Debugging printf.
    44  * This function is intended for single-line messages as it
    45  * automatically prints debugging prefix at the beginning of the
    46  * line.
    47  *
    48  * @see printf
    49  * @param level Debugging level.
    50  */
    51 void dprintf(int level, const char *format, ...)
    52 {
    53         if (level > debug_level) {
    54                 return;
    55         }
    56        
    57         printf("%s(%d): ", NAME, level);
    58         va_list args;
    59         va_start(args, format);
    60         vprintf(format, args);
    61         va_end(args);
    62         printf("\n");
    63 }
    6441
    6542/** Debug print informing of invalid call.
  • uspace/drv/vhc/hcd.c

    r101ef25c r243cb86  
    5252#include "conn.h"
    5353
     54static device_ops_t vhc_ops = {
     55        .interfaces[USBHC_DEV_IFACE] = &vhc_iface,
     56        .default_handler = default_connection_handler
     57};
    5458
    5559static int vhc_count = 0;
    56 static int vhc_add_device(usb_hc_device_t *dev)
     60static int vhc_add_device(device_t *dev)
    5761{
    5862        /*
     
    6569        vhc_count++;
    6670
    67         dev->transfer_ops = &vhc_transfer_ops;
    68         dev->generic->ops->default_handler = default_connection_handler;
     71        dev->ops = &vhc_ops;
     72
     73        /*
     74         * Initialize address management.
     75         */
     76        address_init();
    6977
    7078        /*
    7179         * Initialize our hub and announce its presence.
    7280         */
    73         hub_init();
    74         usb_hcd_add_root_hub(dev);
     81        hub_init(dev);
    7582
    7683        printf("%s: virtual USB host controller ready.\n", NAME);
     
    7986}
    8087
    81 static usb_hc_driver_t vhc_driver = {
     88static driver_ops_t vhc_driver_ops = {
     89        .add_device = vhc_add_device,
     90};
     91
     92static driver_t vhc_driver = {
    8293        .name = NAME,
    83         .add_hc = &vhc_add_device
     94        .driver_ops = &vhc_driver_ops
    8495};
    8596
     
    99110        printf("%s: virtual USB host controller driver.\n", NAME);
    100111
    101         debug_level = 10;
     112        usb_dprintf_enable(NAME, 10);
    102113
    103114        fid_t fid = fibril_create(hc_manager_fibril, NULL);
     
    114125        sleep(4);
    115126
    116         return usb_hcd_main(&vhc_driver);
     127        return driver_main(&vhc_driver);
    117128}
    118129
  • uspace/drv/vhc/hub.c

    r101ef25c r243cb86  
    3737#include <usbvirt/device.h>
    3838#include <errno.h>
     39#include <str_error.h>
    3940#include <stdlib.h>
     41#include <driver.h>
    4042
    4143#include "vhcd.h"
    4244#include "hub.h"
    4345#include "hubintern.h"
     46#include "conn.h"
    4447
    4548
     
    148151hub_device_t hub_dev;
    149152
     153static usb_address_t hub_set_address(usbvirt_device_t *hub)
     154{
     155        usb_address_t new_address;
     156        int rc = vhc_iface.request_address(NULL, &new_address);
     157        if (rc != EOK) {
     158                return rc;
     159        }
     160       
     161        usb_device_request_setup_packet_t setup_packet = {
     162                .request_type = 0,
     163                .request = USB_DEVREQ_SET_ADDRESS,
     164                .index = 0,
     165                .length = 0,
     166        };
     167        setup_packet.value = new_address;
     168
     169        hub->transaction_setup(hub, 0, &setup_packet, sizeof(setup_packet));
     170        hub->transaction_in(hub, 0, NULL, 0, NULL);
     171       
     172        return new_address;
     173}
     174
    150175/** Initialize virtual hub. */
    151 void hub_init(void)
     176void hub_init(device_t *hc_dev)
    152177{
    153178        size_t i;
     
    163188       
    164189        dprintf(1, "virtual hub (%d ports) created", HUB_PORT_COUNT);
     190
     191        usb_address_t hub_address = hub_set_address(&virthub_dev);
     192        if (hub_address < 0) {
     193                dprintf(1, "problem changing hub address (%s)",
     194                    str_error(hub_address));
     195        }
     196
     197        dprintf(2, "virtual hub address changed to %d", hub_address);
     198
     199        char *id;
     200        int rc = asprintf(&id, "usb&hub");
     201        if (rc <= 0) {
     202                return;
     203        }
     204        devman_handle_t hub_handle;
     205        rc = child_device_register_wrapper(hc_dev, "hub", id, 10, &hub_handle);
     206        if (rc != EOK) {
     207                free(id);
     208        }
     209
     210        vhc_iface.bind_address(NULL, hub_address, hub_handle); 
     211
     212        dprintf(2, "virtual hub has devman handle %d", (int) hub_handle);
    165213}
    166214
  • uspace/drv/vhc/hub.h

    r101ef25c r243cb86  
    3737
    3838#include <usbvirt/device.h>
     39#include <driver.h>
    3940
    4041#include "devices.h"
     
    4748extern usbvirt_device_t virthub_dev;
    4849
    49 void hub_init(void);
     50void hub_init(device_t *);
    5051size_t hub_add_device(virtdev_connection_t *);
    5152void hub_remove_device(virtdev_connection_t *);
  • uspace/drv/vhc/vhc.ma

    r101ef25c r243cb86  
    1110 usb&hc=vhc
    2 10 usb&hc=vhc&hub
     2
  • uspace/drv/vhc/vhcd.h

    r101ef25c r243cb86  
    3636#define VHCD_VHCD_H_
    3737
     38#include <usb/debug.h>
     39
    3840#define NAME "vhc"
    3941#define NAME_DEV "hcd-virt-dev"
     
    4345#define DEVMAP_PATH_DEV NAMESPACE "/" NAME_DEV
    4446
    45 extern int debug_level;
    46 void dprintf(int, const char *, ...);
     47#define dprintf(level, format, ...) \
     48        usb_dprintf(NAME, (level), format "\n", ##__VA_ARGS__)
    4749void dprintf_inval_call(int, ipc_call_t, ipcarg_t);
    4850
Note: See TracChangeset for help on using the changeset viewer.