Changes in / [9a2923d:ea696998] in mainline


Ignore:
Location:
uspace/drv
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/ohci/Makefile

    r9a2923d rea696998  
    3737        main.c \
    3838        hc.c \
     39        ohci.c \
    3940        root_hub.c \
    4041        pci.c
  • uspace/drv/ohci/hc.c

    r9a2923d rea696998  
    3939#include <usb/debug.h>
    4040#include <usb/usb.h>
    41 #include <usb/hub.h>
    4241#include <usb/ddfiface.h>
    4342#include <usb/usbdevice.h>
     
    4544#include "hc.h"
    4645
    47 static int dummy_reset(int foo, void *arg);
    4846static int interrupt_emulator(hc_t *instance);
     47/*----------------------------------------------------------------------------*/
     48int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun)
     49{
     50        assert(instance);
     51        assert(hub_fun);
     52
     53        usb_address_t hub_address =
     54            device_keeper_get_free_address(&instance->manager, USB_SPEED_FULL);
     55        instance->rh.address = hub_address;
     56        usb_device_keeper_bind(
     57            &instance->manager, hub_address, hub_fun->handle);
     58
     59        char *match_str = NULL;
     60        int ret = asprintf(&match_str, "usb&mid");
     61        ret = (match_str == NULL) ? ret : EOK;
     62        if (ret < 0) {
     63                usb_log_error("Failed to create root hub match-id string.\n");
     64                return ret;
     65        }
     66
     67        ret = ddf_fun_add_match_id(hub_fun, match_str, 100);
     68        if (ret != EOK) {
     69                usb_log_error("Failed add create root hub match-id.\n");
     70        }
     71        return ret;
     72}
    4973/*----------------------------------------------------------------------------*/
    5074int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev,
     
    6892        }
    6993
     94        rh_init(&instance->rh, dev, instance->registers);
    7095
    71         rh_init(&instance->rh, dev, instance->registers);
    7296        /* TODO: implement */
    73         return EOK;
    74 }
    75 /*----------------------------------------------------------------------------*/
    76 int hc_register_hub(hc_t *instance)
    77 {
    78         async_usleep(1000000);
    79 #define CHECK_RET_RETURN(ret, msg...) \
    80         if (ret != EOK) { \
    81                 usb_log_error(msg); \
    82                 return ret; \
    83         } else (void)0
    84         assert(instance);
    85         assert(instance->ddf_instance);
    86         assert(instance->ddf_instance->handle);
    87         ddf_dev_t *dev = instance->rh.device;
    88         int ret = EOK;
    89 
    90         usb_hc_connection_t conn;
    91         ret =
    92             usb_hc_connection_initialize(&conn, instance->ddf_instance->handle);
    93         CHECK_RET_RETURN(ret, "Failed to initialize hc connection.\n");
    94 
    95         ret = usb_hc_connection_open(&conn);
    96         CHECK_RET_RETURN(ret, "Failed to open hc connection.\n");
    97 
    98         usb_address_t address;
    99         devman_handle_t handle;
    100         ret = usb_hc_new_device_wrapper(dev, &conn, USB_SPEED_FULL, dummy_reset,
    101             0, instance, &address, &handle, NULL, NULL, NULL);
    102         if (ret != EOK) {
    103                 usb_log_error("Failed to add rh device.\n");
    104                 instance->rh.address = -1;
    105                 return ret;
    106         }
    107 
    108         ret = usb_hc_connection_close(&conn);
    109         CHECK_RET_RETURN(ret, "Failed to close hc connection.\n");
    11097        return EOK;
    11198}
     
    134121}
    135122/*----------------------------------------------------------------------------*/
    136 static int dummy_reset(int foo, void *arg)
    137 {
    138         hc_t *hc = (hc_t*)arg;
    139         assert(hc);
    140         hc->rh.address = 0;
    141         return EOK;
    142 }
    143 /*----------------------------------------------------------------------------*/
    144 static int interrupt_emulator(hc_t *instance)
     123int interrupt_emulator(hc_t *instance)
    145124{
    146125        assert(instance);
  • uspace/drv/ohci/hc.h

    r9a2923d rea696998  
    5757} hc_t;
    5858
     59int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun);
     60
    5961int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev,
    6062     uintptr_t regs, size_t reg_size, bool interrupts);
    61 
    62 int hc_register_hub(hc_t *instance);
    6363
    6464int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch);
  • uspace/drv/ohci/iface.h

    r9a2923d rea696998  
    3333 * Common OHCI definitions.
    3434 */
    35 #ifndef DRV_OHCI_OHCI_H
    36 #define DRV_OHCI_OHCI_H
     35#ifndef DRV_OHCI_IFACE_H
     36#define DRV_OHCI_IFACE_H
    3737
    3838#include <usbhc_iface.h>
    39 
    40 #define NAME "ohci"
    4139
    4240extern usbhc_iface_t hc_iface;
  • uspace/drv/ohci/main.c

    r9a2923d rea696998  
    3434 */
    3535#include <ddf/driver.h>
    36 #include <ddf/interrupt.h>
    37 #include <device/hw_res.h>
    3836#include <errno.h>
    3937#include <str_error.h>
    4038
    41 #include <usb_iface.h>
    42 #include <usb/ddfiface.h>
    4339#include <usb/debug.h>
    4440
    45 #include "pci.h"
    46 #include "iface.h"
    47 #include "hc.h"
     41#include "ohci.h"
     42
     43#define NAME "ohci"
    4844
    4945static int ohci_add_device(ddf_dev_t *device);
    50 static int get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
    51 {
    52         assert(handle);
    53   assert(fun != NULL);
    54 
    55   *handle = fun->handle;
    56   return EOK;
    57 }
    58 /*----------------------------------------------------------------------------*/
    59 static int get_address(
    60     ddf_fun_t *fun, devman_handle_t handle, usb_address_t *address)
    61 {
    62         assert(fun);
    63         usb_device_keeper_t *manager = &fun_to_hc(fun)->manager;
    64   usb_address_t addr = usb_device_keeper_find(manager, handle);
    65   if (addr < 0) {
    66     return addr;
    67   }
    68 
    69   if (address != NULL) {
    70     *address = addr;
    71   }
    72 
    73   return EOK;
    74 }
    75 /*----------------------------------------------------------------------------*/
    76 /** IRQ handling callback, identifies device
    77  *
    78  * @param[in] dev DDF instance of the device to use.
    79  * @param[in] iid (Unused).
    80  * @param[in] call Pointer to the call that represents interrupt.
    81  */
    82 static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call)
    83 {
    84         assert(dev);
    85         hc_t *hc = (hc_t*)dev->driver_data;
    86         assert(hc);
    87         hc_interrupt(hc, 0);
    88 }
    8946/*----------------------------------------------------------------------------*/
    9047static driver_ops_t ohci_driver_ops = {
     
    9754};
    9855/*----------------------------------------------------------------------------*/
    99 static usb_iface_t hc_usb_iface = {
    100         .get_address = get_address,
    101         .get_hc_handle = get_hc_handle,
    102 };
    103 /*----------------------------------------------------------------------------*/
    104 static ddf_dev_ops_t hc_ops = {
    105         .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
    106         .interfaces[USBHC_DEV_IFACE] = &hc_iface,
    107 };
    108 /*----------------------------------------------------------------------------*/
    10956/** Initializes a new ddf driver instance of OHCI hcd.
    11057 *
     
    11259 * @return Error code.
    11360 */
    114 static int ohci_add_device(ddf_dev_t *device)
     61int ohci_add_device(ddf_dev_t *device)
    11562{
     63        usb_log_debug("ohci_add_device() called\n");
    11664        assert(device);
    117 #define CHECK_RET_RETURN(ret, message...) \
    118 if (ret != EOK) { \
    119         usb_log_error(message); \
    120         return ret; \
    121 }
    122 
    123         uintptr_t mem_reg_base = 0;
    124         size_t mem_reg_size = 0;
    125         int irq = 0;
    126 
    127         int ret =
    128             pci_get_my_registers(device, &mem_reg_base, &mem_reg_size, &irq);
    129         CHECK_RET_RETURN(ret,
    130             "Failed(%d) to get memory addresses:.\n", ret, device->handle);
    131         usb_log_info("Memory mapped regs at 0x%X (size %zu), IRQ %d.\n",
    132             mem_reg_base, mem_reg_size, irq);
    133 
    134         ret = pci_disable_legacy(device);
    135         CHECK_RET_RETURN(ret,
    136             "Failed(%d) disable legacy USB: %s.\n", ret, str_error(ret));
    137 
    138         hc_t *hcd = malloc(sizeof(hc_t));
    139         if (hcd == NULL) {
     65        ohci_t *ohci = malloc(sizeof(ohci_t));
     66        if (ohci == NULL) {
    14067                usb_log_error("Failed to allocate OHCI driver.\n");
    14168                return ENOMEM;
    14269        }
    14370
    144         ddf_fun_t *hc_fun = ddf_fun_create(device, fun_exposed, "ohci-hc");
    145         if (hc_fun == NULL) {
    146                 usb_log_error("Failed to create OHCI function.\n");
    147                 free(hcd);
    148                 return ENOMEM;
    149         }
    150 
    151 
    152         bool interrupts = false;
    153 #ifdef CONFIG_USBHC_NO_INTERRUPTS
    154         usb_log_warning("Interrupts disabled in OS config, " \
    155             "falling back to polling.\n");
    156 #else
    157         ret = pci_enable_interrupts(device);
     71        int ret = ohci_init(ohci, device);
    15872        if (ret != EOK) {
    159                 usb_log_warning("Failed to enable interrupts: %s.\n",
     73                usb_log_error("Failed to initialize OHCI driver: %s.\n",
    16074                    str_error(ret));
    161                 usb_log_info("HW interrupts not available, " \
    162                     "falling back to polling.\n");
    163         } else {
    164                 usb_log_debug("Hw interrupts enabled.\n");
    165                 interrupts = true;
    166         }
    167 #endif
    168 
    169         ret = hc_init(hcd, hc_fun, device, mem_reg_base, mem_reg_size, interrupts);
    170         if (ret != EOK) {
    171                 usb_log_error("Failed to initialize OHCI driver.\n");
    172                 free(hcd);
    17375                return ret;
    17476        }
     77        device->driver_data = ohci;
    17578
    176         ret = register_interrupt_handler(device, irq, irq_handler, NULL);
    177 
    178         hc_fun->ops = &hc_ops;
    179         ret = ddf_fun_bind(hc_fun);
    180         if (ret != EOK) {
    181                 usb_log_error("Failed to bind OHCI function.\n");
    182                 ddf_fun_destroy(hc_fun);
    183                 free(hcd);
    184                 return ret;
    185         }
    186         hc_fun->driver_data = hcd;
    187 
    188         fid_t later = fibril_create((int(*)(void*))hc_register_hub, hcd);
    189         fibril_add_ready(later);
    190 
    191         usb_log_info("Controlling new OHCI device `%s' (handle %llu).\n",
    192             device->name, device->handle);
     79        usb_log_info("Controlling new OHCI device `%s'.\n", device->name);
    19380
    19481        return EOK;
    195 #undef CHECK_RET_RETURN
    19682}
    19783/*----------------------------------------------------------------------------*/
  • uspace/drv/ohci/root_hub.c

    r9a2923d rea696998  
    4343#include <usb/classes/hub.h>
    4444
     45static const usb_standard_device_descriptor_t ohci_rh_device_descriptor =
     46{
     47                .configuration_count = 1,
     48                .descriptor_type = USB_DESCTYPE_DEVICE,
     49                .device_class = USB_CLASS_HUB,
     50                .device_protocol = 0,
     51                .device_subclass = 0,
     52                .device_version = 0,
     53                .length = sizeof(usb_standard_device_descriptor_t),
     54                /// \TODO this value is guessed
     55                .max_packet_size = 8,
     56                .vendor_id = 0x16db,
     57                .product_id = 0x0001,
     58                /// \TODO these values migt be different
     59                .str_serial_number = 0,
     60                .usb_spec_version = 0,
     61};
     62
     63static const usb_standard_configuration_descriptor_t ohci_rh_conf_descriptor =
     64{
     65        /// \TODO some values are default or guessed
     66        .attributes = 1<<7,
     67        .configuration_number = 1,
     68        .descriptor_type = USB_DESCTYPE_CONFIGURATION,
     69        .interface_count = 1,
     70        .length = sizeof(usb_standard_configuration_descriptor_t),
     71        .max_power = 100,
     72        .str_configuration = 0,
     73};
     74
     75static const usb_standard_interface_descriptor_t ohci_rh_iface_descriptor =
     76{
     77        .alternate_setting = 0,
     78        .descriptor_type = USB_DESCTYPE_INTERFACE,
     79        .endpoint_count = 1,
     80        .interface_class = USB_CLASS_HUB,
     81        /// \TODO is this correct?
     82        .interface_number = 1,
     83        .interface_protocol = 0,
     84        .interface_subclass = 0,
     85        .length = sizeof(usb_standard_interface_descriptor_t),
     86        .str_interface = 0,
     87};
     88
     89static const usb_standard_endpoint_descriptor_t ohci_rh_ep_descriptor =
     90{
     91        .attributes = USB_TRANSFER_INTERRUPT,
     92        .descriptor_type = USB_DESCTYPE_ENDPOINT,
     93        .endpoint_address = 1 + (1<<7),
     94        .length = sizeof(usb_standard_endpoint_descriptor_t),
     95        .max_packet_size = 8,
     96        .poll_interval = 255,
     97};
    4598
    4699/** Root hub initialization
     
    178231                        (usb_device_request_setup_packet_t*)request->setup_buffer;
    179232        size_t size;
    180         void * result_descriptor;
    181         uint16_t setup_request_value = setup_request->value_high;
     233        const void * result_descriptor;
     234        const uint16_t setup_request_value = setup_request->value_high;
    182235                        //(setup_request->value_low << 8);
     236        bool del = false;
     237
     238        switch (setup_request_value)
     239        {
     240        case USB_DESCTYPE_HUB: {
     241                uint8_t * descriptor;
     242                usb_create_serialized_hub_descriptor(
     243                    instance, &descriptor, &size);
     244                result_descriptor = descriptor;
     245                break;
     246        }
     247        case USB_DESCTYPE_DEVICE: {
     248                usb_log_debug("USB_DESCTYPE_DEVICE\n");
     249                result_descriptor = &ohci_rh_device_descriptor;
     250                size = sizeof(ohci_rh_device_descriptor);
     251                break;
     252        }
     253        case USB_DESCTYPE_CONFIGURATION: {
     254                usb_log_debug("USB_DESCTYPE_CONFIGURATION\n");
     255                usb_standard_configuration_descriptor_t * descriptor =
     256                                malloc(sizeof(usb_standard_configuration_descriptor_t));
     257                memcpy(descriptor, &ohci_rh_conf_descriptor,
     258                    sizeof(usb_standard_configuration_descriptor_t));
     259                /// \TODO should this include device descriptor?
     260                const size_t hub_descriptor_size = 7 +
     261                                2* (instance->port_count / 8 +
     262                                ((instance->port_count % 8 > 0) ? 1 : 0));
     263                descriptor->total_length =
     264                                sizeof(usb_standard_configuration_descriptor_t)+
     265                                sizeof(usb_standard_endpoint_descriptor_t)+
     266                                sizeof(usb_standard_interface_descriptor_t)+
     267                                hub_descriptor_size;
     268                result_descriptor = descriptor;
     269                size = sizeof(usb_standard_configuration_descriptor_t);
     270                del = true;
     271                break;
     272        }
     273        case USB_DESCTYPE_INTERFACE: {
     274                usb_log_debug("USB_DESCTYPE_INTERFACE\n");
     275                result_descriptor = &ohci_rh_iface_descriptor;
     276                size = sizeof(ohci_rh_iface_descriptor);
     277                break;
     278        }
     279        case USB_DESCTYPE_ENDPOINT: {
     280                usb_log_debug("USB_DESCTYPE_ENDPOINT\n");
     281                result_descriptor = &ohci_rh_ep_descriptor;
     282                size = sizeof(ohci_rh_ep_descriptor);
     283                break;
     284        }
     285        default: {
     286                usb_log_debug("USB_DESCTYPE_EINVAL %d \n",setup_request->value);
     287                usb_log_debug("\ttype %d\n\trequest %d\n\tvalue %d\n\tindex %d\n\tlen %d\n ",
     288                                setup_request->request_type,
     289                                setup_request->request,
     290                                setup_request_value,
     291                                setup_request->index,
     292                                setup_request->length
     293                                );
     294                return EINVAL;
     295        }
     296        }
     297#if 0
    183298        if(setup_request_value == USB_DESCTYPE_HUB){
    184299                usb_log_debug("USB_DESCTYPE_HUB\n");
     
    277392                return EINVAL;
    278393        }
     394#endif
    279395        if(request->buffer_size < size){
    280396                size = request->buffer_size;
     
    282398        request->transfered_size = size;
    283399        memcpy(request->buffer,result_descriptor,size);
    284         free(result_descriptor);
     400        if (del)
     401                free(result_descriptor);
    285402        return EOK;
    286403}
  • uspace/drv/uhci-hcd/root_hub.c

    r9a2923d rea696998  
    4848 * @return Error code.
    4949 */
    50 int rh_init(
    51     rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size)
     50int rh_init(rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size)
    5251{
    5352        assert(fun);
  • uspace/drv/uhci-hcd/uhci.c

    r9a2923d rea696998  
    4444#include "pci.h"
    4545
    46 
    4746/** IRQ handling callback, identifies device
    4847 *
     
    108107/*----------------------------------------------------------------------------*/
    109108static ddf_dev_ops_t hc_ops = {
    110         .interfaces[USB_DEV_IFACE] = &usb_iface,
     109//      .interfaces[USB_DEV_IFACE] = &usb_iface,
    111110        .interfaces[USBHC_DEV_IFACE] = &hc_iface, /* see iface.h/c */
    112111};
Note: See TracChangeset for help on using the changeset viewer.