Changeset 9a2923d in mainline


Ignore:
Timestamp:
2011-03-25T17:29:10Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d70765d, ea696998
Parents:
b8d453ec (diff), 889e8e3 (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:

USB MID fixes, devman in kconsole (#145, #150)

Ported USB MID driver to new USB framework.

Devman can be configured to run in kconsole for better log viewing.

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • HelenOS.config

    rb8d453ec r9a2923d  
    554554% Polling UHCI & OHCI (no interrupts)
    555555! [PLATFORM=ia32|PLATFORM=amd64] CONFIG_USBHC_NO_INTERRUPTS (y/n)
     556
     557% Run devman in kconsole (not recommended)
     558! CONFIG_DEVMAN_EARLY_LAUNCH (n/y)
     559
  • uspace/app/init/init.c

    rb8d453ec r9a2923d  
    288288       
    289289        spawn("/srv/clip");
     290
     291#ifdef CONFIG_DEVMAN_EARLY_LAUNCH
     292        spawn("/srv/devman");
     293#endif
    290294       
    291295        /*
     
    313317        getterm("term/vc5", "/app/bdsh", false);
    314318        getterm("term/vc6", "/app/klog", false);
     319
     320#ifndef CONFIG_DEVMAN_EARLY_LAUNCH
    315321        getterm("term/vc7", "/srv/devman", false);
    316        
     322#endif
     323
    317324        return 0;
    318325}
  • uspace/app/klog/klog.c

    rb8d453ec r9a2923d  
    4444#include <io/klog.h>
    4545#include <sysinfo.h>
     46#include <fibril_synch.h>
    4647
    4748#define NAME       "klog"
     
    5455static FILE *log;
    5556
     57/* Serialize the output a bit. This will not avoid messed-up log completely
     58   but chances for are pretty high (experimentally confirmed). */
     59static FIBRIL_MUTEX_INITIALIZE(log_mutex);
     60
    5661static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
    5762{
     63        fibril_mutex_lock(&log_mutex);
     64       
    5865        size_t klog_start = (size_t) IPC_GET_ARG1(*call);
    5966        size_t klog_len = (size_t) IPC_GET_ARG2(*call);
     
    7481                fsync(fileno(log));
    7582        }
     83       
     84        fibril_mutex_unlock(&log_mutex);
    7685}
    7786
  • uspace/drv/usbmid/explore.c

    rb8d453ec r9a2923d  
    4040#include <usb/request.h>
    4141#include <usb/dp.h>
     42#include <usb/ddfiface.h>
    4243#include "usbmid.h"
     44
     45/** Operations of the device itself. */
     46static ddf_dev_ops_t mid_device_ops = {
     47        .interfaces[USB_DEV_IFACE] = &usb_iface_hub_impl
     48};
    4349
    4450/** Find starting indexes of all interface descriptors in a configuration.
     
    105111 * @return Whether to accept this device from devman.
    106112 */
    107 bool usbmid_explore_device(usbmid_device_t *dev)
     113bool usbmid_explore_device(usb_device_t *dev)
    108114{
    109         usb_standard_device_descriptor_t device_descriptor;
    110         int rc = usb_request_get_device_descriptor(&dev->ctrl_pipe,
    111             &device_descriptor);
    112         if (rc != EOK) {
    113                 usb_log_error("Getting device descriptor failed: %s.\n",
    114                     str_error(rc));
    115                 return false;
    116         }
    117 
    118         if (device_descriptor.device_class != USB_CLASS_USE_INTERFACE) {
     115        int rc;
     116
     117        int dev_class = dev->descriptors.device.device_class;
     118        if (dev_class != USB_CLASS_USE_INTERFACE) {
    119119                usb_log_warning(
    120120                    "Device class: %d (%s), but expected class 0.\n",
    121                     device_descriptor.device_class,
    122                     usb_str_class(device_descriptor.device_class));
     121                    dev_class, usb_str_class(dev_class));
    123122                usb_log_error("Not multi interface device, refusing.\n");
    124123                return false;
    125124        }
    126125
    127         size_t config_descriptor_size;
    128         uint8_t *config_descriptor_raw = NULL;
    129         rc = usb_request_get_full_configuration_descriptor_alloc(
    130             &dev->ctrl_pipe, 0,
    131             (void **) &config_descriptor_raw, &config_descriptor_size);
    132         if (rc != EOK) {
    133                 usb_log_error("Failed getting full config descriptor: %s.\n",
    134                     str_error(rc));
    135                 return false;
    136         }
    137 
    138         usb_standard_configuration_descriptor_t *config_descriptor
    139             = (usb_standard_configuration_descriptor_t *) config_descriptor_raw;
     126        /* Short cuts to save on typing ;-). */
     127        uint8_t *config_descriptor_raw = dev->descriptors.configuration;
     128        size_t config_descriptor_size = dev->descriptors.configuration_size;
     129        usb_standard_configuration_descriptor_t *config_descriptor =
     130            (usb_standard_configuration_descriptor_t *) config_descriptor_raw;
    140131
    141132        size_t *interface_descriptors
     
    154145        if (interface_descriptors_count == (size_t) -1) {
    155146                usb_log_error("Problem parsing configuration descriptor.\n");
    156                 free(config_descriptor_raw);
    157147                free(interface_descriptors);
    158148                return false;
     
    165155                usb_log_error("Failed to set device configuration: %s.\n",
    166156                    str_error(rc));
    167                 free(config_descriptor_raw);
    168157                free(interface_descriptors);
    169158                return false;
     
    172161
    173162        /* Create control function */
    174         ddf_fun_t *ctl_fun = ddf_fun_create(dev->dev, fun_exposed, "ctl");
     163        ddf_fun_t *ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl");
    175164        if (ctl_fun == NULL) {
    176165                usb_log_error("Failed to create control function.\n");
    177                 free(config_descriptor_raw);
    178                 free(interface_descriptors);
    179                 return false;
    180         }
     166                free(interface_descriptors);
     167                return false;
     168        }
     169
     170        ctl_fun->ops = &mid_device_ops;
     171
    181172        rc = ddf_fun_bind(ctl_fun);
    182173        if (rc != EOK) {
    183174                usb_log_error("Failed to bind control function: %s.\n",
    184175                    str_error(rc));
    185                 free(config_descriptor_raw);
    186176                free(interface_descriptors);
    187177                return false;
     
    199189                    (int) interface->interface_number,
    200190                    usb_str_class(interface->interface_class));
    201                 rc = usbmid_spawn_interface_child(dev, &device_descriptor,
     191                rc = usbmid_spawn_interface_child(dev, &dev->descriptors.device,
    202192                    interface);
    203193                if (rc != EOK) {
     
    207197        }
    208198
    209         free(config_descriptor_raw);
    210 
    211199        return true;
    212200}
  • uspace/drv/usbmid/main.c

    rb8d453ec r9a2923d  
    4949 * @return Error code.
    5050 */
    51 static int usbmid_add_device(ddf_dev_t *gen_dev)
     51static int usbmid_add_device(usb_device_t *dev)
    5252{
    53         usbmid_device_t *dev = usbmid_device_create(gen_dev);
    54         if (dev == NULL) {
    55                 return ENOMEM;
    56         }
    57 
    58         usb_log_info("Taking care of new MID: addr %d (HC %zu)\n",
    59             dev->wire.address, dev->wire.hc_handle);
     53        usb_log_info("Taking care of new MID `%s'.\n", dev->ddf_dev->name);
    6054
    6155        int rc;
     
    6559                usb_log_error("Failed to start session on control pipe: %s.\n",
    6660                    str_error(rc));
    67                 goto error_leave;
     61                return rc;
    6862        }
    6963
     
    7771
    7872        if (!accept) {
    79                 rc = ENOTSUP;
    80                 goto error_leave;
     73                return ENOTSUP;
    8174        }
    8275
    83         gen_dev->driver_data = dev;
    84 
    8576        return EOK;
    86 
    87 
    88 error_leave:
    89         free(dev);
    90         return rc;
    9177}
    9278
    9379/** USB MID driver ops. */
    94 static driver_ops_t mid_driver_ops = {
     80static usb_driver_ops_t mid_driver_ops = {
    9581        .add_device = usbmid_add_device,
    9682};
    9783
    9884/** USB MID driver. */
    99 static driver_t mid_driver = {
     85static usb_driver_t mid_driver = {
    10086        .name = NAME,
    101         .driver_ops = &mid_driver_ops
     87        .ops = &mid_driver_ops,
     88        .endpoints = NULL
    10289};
    10390
     
    10794
    10895        usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
    109         return ddf_driver_main(&mid_driver);
     96
     97        return usb_driver_main(&mid_driver);
    11098}
    11199
  • uspace/drv/usbmid/usbmid.c

    rb8d453ec r9a2923d  
    7979};
    8080
    81 /** Operations of the device itself. */
    82 static ddf_dev_ops_t mid_device_ops = {
    83         .interfaces[USB_DEV_IFACE] = &usb_iface_hub_impl
    84 };
    85 
    86 /** Create new USB multi interface device.
    87  *
    88  * @param dev Backing generic DDF device.
    89  * @return New USB MID device.
    90  * @retval NULL Error occured.
    91  */
    92 usbmid_device_t *usbmid_device_create(ddf_dev_t *dev)
    93 {
    94         usbmid_device_t *mid = malloc(sizeof(usbmid_device_t));
    95         if (mid == NULL) {
    96                 usb_log_error("Out of memory (wanted %zu bytes).\n",
    97                     sizeof(usbmid_device_t));
    98                 return NULL;
    99         }
    100 
    101         int rc;
    102         rc = usb_device_connection_initialize_from_device(&mid->wire, dev);
    103         if (rc != EOK) {
    104                 usb_log_error("Failed to initialize `USB wire': %s.\n",
    105                     str_error(rc));
    106                 free(mid);
    107                 return NULL;
    108         }
    109 
    110         rc = usb_pipe_initialize_default_control(&mid->ctrl_pipe,
    111             &mid->wire);
    112         if (rc != EOK) {
    113                 usb_log_error("Failed to initialize control pipe: %s.\n",
    114                     str_error(rc));
    115                 free(mid);
    116                 return NULL;
    117         }
    118         rc = usb_pipe_probe_default_control(&mid->ctrl_pipe);
    119         if (rc != EOK) {
    120                 usb_log_error("Probing default control pipe failed: %s.\n",
    121                     str_error(rc));
    122                 free(mid);
    123                 return NULL;
    124         }
    125 
    126         mid->dev = dev;
    127         (void) &mid_device_ops;
    128 
    129         return mid;
    130 }
    131 
    13281/** Create new interface for USB MID device.
    13382 *
     
    160109 * @return Error code.
    161110 */
    162 int usbmid_spawn_interface_child(usbmid_device_t *parent,
     111int usbmid_spawn_interface_child(usb_device_t *parent,
    163112    const usb_standard_device_descriptor_t *device_descriptor,
    164113    const usb_standard_interface_descriptor_t *interface_descriptor)
     
    182131
    183132        /* Create the device. */
    184         child = ddf_fun_create(parent->dev, fun_inner, child_name);
     133        child = ddf_fun_create(parent->ddf_dev, fun_inner, child_name);
    185134        if (child == NULL) {
    186135                rc = ENOMEM;
  • uspace/drv/usbmid/usbmid.h

    rb8d453ec r9a2923d  
    4141#include <usb/pipes.h>
    4242#include <usb/debug.h>
     43#include <usb/devdrv.h>
    4344
    4445#define NAME "usbmid"
    45 
    46 /** USB MID device container. */
    47 typedef struct {
    48         /** Device container. */
    49         ddf_dev_t *dev;
    50 
    51         /** Representation of USB wire. */
    52         usb_device_connection_t wire;
    53         /** Default control pipe. */
    54         usb_pipe_t ctrl_pipe;
    55 } usbmid_device_t;
    56 
    5746
    5847/** Container for single interface in a MID device. */
     
    6554} usbmid_interface_t;
    6655
    67 usbmid_device_t *usbmid_device_create(ddf_dev_t *);
    6856usbmid_interface_t *usbmid_interface_create(ddf_fun_t *, int);
    69 bool usbmid_explore_device(usbmid_device_t *);
    70 int usbmid_spawn_interface_child(usbmid_device_t *,
     57bool usbmid_explore_device(usb_device_t *);
     58int usbmid_spawn_interface_child(usb_device_t *,
    7159    const usb_standard_device_descriptor_t *,
    7260    const usb_standard_interface_descriptor_t *);
Note: See TracChangeset for help on using the changeset viewer.