Changeset 233e68d in mainline for uspace/drv/uhci-hcd


Ignore:
Timestamp:
2011-02-23T18:28:41Z (15 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e9e58ea3
Parents:
deece2f (diff), a9c674e0 (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:

Devel changes

Location:
uspace/drv/uhci-hcd
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/batch.c

    rdeece2f r233e68d  
    5151
    5252
    53 batch_t * batch_get(device_t *dev, usb_target_t target,
     53batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
    5454    usb_transfer_type_t transfer_type, size_t max_packet_size,
    5555    dev_speed_t speed, char *buffer, size_t size,
     
    128128        instance->buffer_size = size;
    129129        instance->setup_size = setup_size;
    130         instance->dev = dev;
     130        instance->fun = fun;
    131131        instance->arg = arg;
    132132        instance->speed = speed;
     
    291291            err, instance->transfered_size);
    292292
    293         instance->callback_in(instance->dev,
     293        instance->callback_in(instance->fun,
    294294            err, instance->transfered_size,
    295295            instance->arg);
     
    303303        int err = instance->error;
    304304        usb_log_info("Callback OUT(%d): %d.\n", instance->transfer_type, err);
    305         instance->callback_out(instance->dev,
     305        instance->callback_out(instance->fun,
    306306            err, instance->arg);
    307307}
     
    334334{
    335335        assert(instance);
    336         uhci_t *hc = dev_to_uhci(instance->dev);
     336        uhci_t *hc = fun_to_uhci(instance->fun);
    337337        assert(hc);
    338338        return uhci_schedule(hc, instance);
  • uspace/drv/uhci-hcd/batch.h

    rdeece2f r233e68d  
    6868        size_t transfered_size;
    6969        int error;
    70         device_t *dev;
     70        ddf_fun_t *fun;
    7171        queue_head_t *qh;
    7272        transfer_descriptor_t *tds;
     
    7474} batch_t;
    7575
    76 batch_t * batch_get(device_t *dev, usb_target_t target,
     76batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
    7777    usb_transfer_type_t transfer_type, size_t max_packet_size,
    7878    dev_speed_t speed, char *buffer, size_t size,
  • uspace/drv/uhci-hcd/iface.c

    rdeece2f r233e68d  
    3232 * @brief UHCI driver
    3333 */
    34 #include <driver.h>
     34#include <ddf/driver.h>
    3535#include <remote_usbhc.h>
    3636
     
    4343
    4444/*----------------------------------------------------------------------------*/
    45 static int reserve_default_address(device_t *dev, usb_speed_t speed)
     45static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
    4646{
    47         assert(dev);
    48         uhci_t *hc = dev_to_uhci(dev);
     47        assert(fun);
     48        uhci_t *hc = fun_to_uhci(fun);
    4949        assert(hc);
    5050        usb_address_keeping_reserve_default(&hc->address_manager);
     
    5252}
    5353/*----------------------------------------------------------------------------*/
    54 static int release_default_address(device_t *dev)
     54static int release_default_address(ddf_fun_t *fun)
    5555{
    56         assert(dev);
    57         uhci_t *hc = dev_to_uhci(dev);
     56        assert(fun);
     57        uhci_t *hc = fun_to_uhci(fun);
    5858        assert(hc);
    5959        usb_address_keeping_release_default(&hc->address_manager);
     
    6161}
    6262/*----------------------------------------------------------------------------*/
    63 static int request_address(device_t *dev, usb_speed_t speed,
     63static int request_address(ddf_fun_t *fun, usb_speed_t speed,
    6464    usb_address_t *address)
    6565{
    66         assert(dev);
    67         uhci_t *hc = dev_to_uhci(dev);
     66        assert(fun);
     67        uhci_t *hc = fun_to_uhci(fun);
    6868        assert(hc);
    6969        *address = usb_address_keeping_request(&hc->address_manager);
     
    7474/*----------------------------------------------------------------------------*/
    7575static int bind_address(
    76   device_t *dev, usb_address_t address, devman_handle_t handle)
     76  ddf_fun_t *fun, usb_address_t address, devman_handle_t handle)
    7777{
    78         assert(dev);
    79         uhci_t *hc = dev_to_uhci(dev);
     78        assert(fun);
     79        uhci_t *hc = fun_to_uhci(fun);
    8080        assert(hc);
    8181        usb_address_keeping_devman_bind(&hc->address_manager, address, handle);
     
    8383}
    8484/*----------------------------------------------------------------------------*/
    85 static int release_address(device_t *dev, usb_address_t address)
     85static int release_address(ddf_fun_t *fun, usb_address_t address)
    8686{
    87         assert(dev);
    88         uhci_t *hc = dev_to_uhci(dev);
     87        assert(fun);
     88        uhci_t *hc = fun_to_uhci(fun);
    8989        assert(hc);
    9090        usb_address_keeping_release_default(&hc->address_manager);
     
    9292}
    9393/*----------------------------------------------------------------------------*/
    94 static int interrupt_out(device_t *dev, usb_target_t target,
     94static int interrupt_out(ddf_fun_t *fun, usb_target_t target,
    9595    size_t max_packet_size,
    9696    void *data, size_t size,
     
    9999        dev_speed_t speed = FULL_SPEED;
    100100
    101         batch_t *batch = batch_get(dev, target, USB_TRANSFER_INTERRUPT,
     101        batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
    102102            max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg);
    103103        if (!batch)
     
    107107}
    108108/*----------------------------------------------------------------------------*/
    109 static int interrupt_in(device_t *dev, usb_target_t target,
     109static int interrupt_in(ddf_fun_t *fun, usb_target_t target,
    110110    size_t max_packet_size,
    111111    void *data, size_t size,
     
    114114        dev_speed_t speed = FULL_SPEED;
    115115
    116         batch_t *batch = batch_get(dev, target, USB_TRANSFER_INTERRUPT,
     116        batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
    117117            max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg);
    118118        if (!batch)
     
    122122}
    123123/*----------------------------------------------------------------------------*/
    124 static int control_write(device_t *dev, usb_target_t target,
     124static int control_write(ddf_fun_t *fun, usb_target_t target,
    125125    size_t max_packet_size,
    126126    void *setup_data, size_t setup_size, void *data, size_t size,
     
    129129        dev_speed_t speed = FULL_SPEED;
    130130
    131         batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
     131        batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    132132            max_packet_size, speed, data, size, setup_data, setup_size,
    133133            NULL, callback, arg);
     
    138138}
    139139/*----------------------------------------------------------------------------*/
    140 static int control_read(device_t *dev, usb_target_t target,
     140static int control_read(ddf_fun_t *fun, usb_target_t target,
    141141    size_t max_packet_size,
    142142    void *setup_data, size_t setup_size, void *data, size_t size,
     
    145145        dev_speed_t speed = FULL_SPEED;
    146146
    147         batch_t *batch = batch_get(dev, target, USB_TRANSFER_CONTROL,
     147        batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    148148            max_packet_size, speed, data, size, setup_data, setup_size, callback,
    149149            NULL, arg);
  • uspace/drv/uhci-hcd/iface.h

    rdeece2f r233e68d  
    3838#include <usbhc_iface.h>
    3939
    40 usbhc_iface_t uhci_iface;
     40extern usbhc_iface_t uhci_iface;
    4141
    4242#endif
  • uspace/drv/uhci-hcd/main.c

    rdeece2f r233e68d  
    3232 * @brief UHCI driver
    3333 */
    34 #include <driver.h>
     34#include <ddf/driver.h>
     35#include <ddf/interrupt.h>
    3536#include <usb_iface.h>
    3637#include <usb/ddfiface.h>
     
    4849#define NAME "uhci-hcd"
    4950
    50 static int uhci_add_device(device_t *device);
     51static int uhci_add_device(ddf_dev_t *device);
    5152
    52 static int usb_iface_get_address(device_t *dev, devman_handle_t handle,
    53     usb_address_t *address)
    54 {
    55         assert(dev);
    56         uhci_t *hc = dev_to_uhci(dev);
    57         assert(hc);
    58 
    59         usb_address_t addr = usb_address_keeping_find(&hc->address_manager,
    60             handle);
    61         if (addr < 0) {
    62                 return addr;
    63         }
    64 
    65         if (address != NULL) {
    66                 *address = addr;
    67         }
    68 
    69         return EOK;
    70 }
    71 
    72 
    73 static usb_iface_t hc_usb_iface = {
    74         .get_hc_handle = usb_iface_get_hc_handle_hc_impl,
    75         .get_address = usb_iface_get_address
    76 };
    77 /*----------------------------------------------------------------------------*/
    78 static device_ops_t uhci_ops = {
    79         .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
    80         .interfaces[USBHC_DEV_IFACE] = &uhci_iface
    81 };
    8253/*----------------------------------------------------------------------------*/
    8354static driver_ops_t uhci_driver_ops = {
     
    9061};
    9162/*----------------------------------------------------------------------------*/
    92 static void irq_handler(device_t *device, ipc_callid_t iid, ipc_call_t *call)
     63static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call)
    9364{
    94         assert(device);
    95         uhci_t *hc = dev_to_uhci(device);
     65        assert(dev);
     66        uhci_t *hc = dev_to_uhci(dev);
    9667        uint16_t status = IPC_GET_ARG1(*call);
    9768        assert(hc);
     
    10576}
    10677
    107 static int uhci_add_device(device_t *device)
     78static int uhci_add_device(ddf_dev_t *device)
    10879{
    10980        assert(device);
    11081
    11182        usb_log_info("uhci_add_device() called\n");
    112         device->ops = &uhci_ops;
     83
    11384
    11485        uintptr_t io_reg_base;
     
    131102        CHECK_RET_RETURN(ret, "Failed to allocate memory for uhci hcd driver.\n");
    132103
    133         ret = uhci_init(uhci_hc, (void*)io_reg_base, io_reg_size);
     104        ret = uhci_init(uhci_hc, device, (void*)io_reg_base, io_reg_size);
    134105        if (ret != EOK) {
    135106                usb_log_error("Failed to init uhci-hcd.\n");
     
    137108                return ret;
    138109        }
     110
     111        /*
     112         * We might free uhci_hc, but that does not matter since no one
     113         * else would access driver_data anyway.
     114         */
     115        device->driver_data = uhci_hc;
    139116
    140117        ret = register_interrupt_handler(device, irq, irq_handler,
     
    147124        }
    148125
    149         device_t *rh;
     126        ddf_fun_t *rh;
    150127        ret = setup_root_hub(&rh, device);
    151128        if (ret != EOK) {
     
    155132                return ret;
    156133        }
     134        rh->driver_data = uhci_hc->ddf_instance;
    157135
    158         ret = child_device_register(rh, device);
     136        ret = ddf_fun_bind(rh);
    159137        if (ret != EOK) {
    160138                usb_log_error("Failed to register root hub.\n");
     
    165143        }
    166144
    167         device->driver_data = uhci_hc;
    168145        return EOK;
    169146}
     
    172149{
    173150        sleep(3);
    174         usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
     151        usb_log_enable(USB_LOG_LEVEL_INFO, NAME);
    175152
    176         return driver_main(&uhci_driver);
     153        return ddf_driver_main(&uhci_driver);
    177154}
    178155/**
  • uspace/drv/uhci-hcd/pci.c

    rdeece2f r233e68d  
    4949 * @return Error code.
    5050 */
    51 int pci_get_my_registers(device_t *dev,
     51int pci_get_my_registers(ddf_dev_t *dev,
    5252    uintptr_t *io_reg_address, size_t *io_reg_size,
    5353    int *irq_no)
     
    122122}
    123123/*----------------------------------------------------------------------------*/
    124 int pci_enable_interrupts(device_t *device)
     124int pci_enable_interrupts(ddf_dev_t *device)
    125125{
    126126        int parent_phone = devman_parent_device_connect(device->handle,
  • uspace/drv/uhci-hcd/pci.h

    rdeece2f r233e68d  
    3636#define DRV_UHCI_PCI_H
    3737
    38 #include <driver.h>
     38#include <ddf/driver.h>
    3939
    40 int pci_get_my_registers(device_t *, uintptr_t *, size_t *, int *);
    41 int pci_enable_interrupts(device_t *device);
     40int pci_get_my_registers(ddf_dev_t *, uintptr_t *, size_t *, int *);
     41int pci_enable_interrupts(ddf_dev_t *);
    4242
    4343#endif
  • uspace/drv/uhci-hcd/root_hub.c

    rdeece2f r233e68d  
    3939
    4040#include "root_hub.h"
     41#include "uhci.h"
    4142
    42 extern device_ops_t child_ops;
     43static int usb_iface_get_hc_handle_rh_impl(ddf_fun_t *root_hub_fun,
     44    devman_handle_t *handle)
     45{
     46        ddf_fun_t *hc_fun = root_hub_fun->driver_data;
     47        assert(hc_fun != NULL);
     48
     49        *handle = hc_fun->handle;
     50
     51        return EOK;
     52}
     53
     54static int usb_iface_get_address_rh_impl(ddf_fun_t *fun, devman_handle_t handle,
     55    usb_address_t *address)
     56{
     57        assert(fun);
     58        ddf_fun_t *hc_fun = fun->driver_data;
     59        assert(hc_fun);
     60        uhci_t *hc = fun_to_uhci(hc_fun);
     61        assert(hc);
     62
     63        usb_address_t addr = usb_address_keeping_find(&hc->address_manager,
     64            handle);
     65        if (addr < 0) {
     66                return addr;
     67        }
     68
     69        if (address != NULL) {
     70                *address = addr;
     71        }
     72
     73        return EOK;
     74}
     75
     76usb_iface_t usb_iface_root_hub_fun_impl = {
     77        .get_hc_handle = usb_iface_get_hc_handle_rh_impl,
     78        .get_address = usb_iface_get_address_rh_impl
     79};
     80
     81static ddf_dev_ops_t root_hub_ops = {
     82        .interfaces[USB_DEV_IFACE] = &usb_iface_root_hub_fun_impl
     83};
     84
    4385/*----------------------------------------------------------------------------*/
    44 int setup_root_hub(device_t **device, device_t *hc)
     86int setup_root_hub(ddf_fun_t **fun, ddf_dev_t *hc)
    4587{
    46         assert(device);
    47         device_t *hub = create_device();
     88        assert(fun);
     89        int ret;
     90
     91        ddf_fun_t *hub = ddf_fun_create(hc, fun_inner, "root-hub");
    4892        if (!hub) {
    4993                usb_log_error("Failed to create root hub device structure.\n");
    50                 return ENOMEM;
    51         }
    52         char *name;
    53         int ret = asprintf(&name, "UHCI Root Hub");
    54         if (ret < 0) {
    55                 usb_log_error("Failed to create root hub name.\n");
    56                 free(hub);
    5794                return ENOMEM;
    5895        }
     
    6299        if (ret < 0) {
    63100                usb_log_error("Failed to create root hub match string.\n");
    64                 free(hub);
    65                 free(name);
     101                ddf_fun_destroy(hub);
    66102                return ENOMEM;
    67103        }
    68104
    69         match_id_t *match_id = create_match_id();
    70         if (!match_id) {
    71                 usb_log_error("Failed to create root hub match id.\n");
    72                 free(hub);
    73                 free(match_str);
     105        ret = ddf_fun_add_match_id(hub, match_str, 100);
     106        if (ret != EOK) {
     107                usb_log_error("Failed to add root hub match id.\n");
     108                ddf_fun_destroy(hub);
    74109                return ENOMEM;
    75110        }
    76         match_id->id = match_str;
    77         match_id->score = 90;
    78111
    79         add_match_id(&hub->match_ids, match_id);
    80         hub->name = name;
    81         hub->parent = hc;
    82         hub->ops = &child_ops;
     112        hub->ops = &root_hub_ops;
    83113
    84         *device = hub;
     114        *fun = hub;
    85115        return EOK;
    86116}
  • uspace/drv/uhci-hcd/root_hub.h

    rdeece2f r233e68d  
    3636#define DRV_UHCI_ROOT_HUB_H
    3737
    38 #include <driver.h>
     38#include <ddf/driver.h>
    3939
    40 int setup_root_hub(device_t **device, device_t *hc);
     40int setup_root_hub(ddf_fun_t **device, ddf_dev_t *hc);
    4141
    4242#endif
  • uspace/drv/uhci-hcd/uhci.c

    rdeece2f r233e68d  
    3333 */
    3434#include <errno.h>
     35#include <str_error.h>
    3536#include <adt/list.h>
     37#include <libarch/ddi.h>
    3638
    3739#include <usb/debug.h>
    3840#include <usb/usb.h>
     41#include <usb/ddfiface.h>
     42#include <usb_iface.h>
    3943
    4044#include "uhci.h"
     45#include "iface.h"
     46
    4147static irq_cmd_t uhci_cmds[] = {
    4248        {
     
    5561};
    5662
     63static int usb_iface_get_address(ddf_fun_t *fun, devman_handle_t handle,
     64    usb_address_t *address)
     65{
     66        assert(fun);
     67        uhci_t *hc = fun_to_uhci(fun);
     68        assert(hc);
     69
     70        usb_address_t addr = usb_address_keeping_find(&hc->address_manager,
     71            handle);
     72        if (addr < 0) {
     73                return addr;
     74        }
     75
     76        if (address != NULL) {
     77                *address = addr;
     78        }
     79
     80        return EOK;
     81}
     82
     83
     84static usb_iface_t hc_usb_iface = {
     85        .get_hc_handle = usb_iface_get_hc_handle_hc_impl,
     86        .get_address = usb_iface_get_address
     87};
     88/*----------------------------------------------------------------------------*/
     89static ddf_dev_ops_t uhci_ops = {
     90        .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
     91        .interfaces[USBHC_DEV_IFACE] = &uhci_iface
     92};
     93
    5794static int uhci_init_transfer_lists(uhci_t *instance);
    5895static int uhci_init_mem_structures(uhci_t *instance);
     
    71108        } else (void) 0
    72109
    73 int uhci_init(uhci_t *instance, void *regs, size_t reg_size)
     110int uhci_init(uhci_t *instance, ddf_dev_t *dev, void *regs, size_t reg_size)
    74111{
    75112        assert(reg_size >= sizeof(regs_t));
     113        int ret;
     114
     115        /*
     116         * Create UHCI function.
     117         */
     118        instance->ddf_instance = ddf_fun_create(dev, fun_exposed, "uhci");
     119        if (instance->ddf_instance == NULL) {
     120                usb_log_error("Failed to create UHCI device function.\n");
     121                return ENOMEM;
     122        }
     123        instance->ddf_instance->ops = &uhci_ops;
     124        instance->ddf_instance->driver_data = instance;
     125
     126        ret = ddf_fun_bind(instance->ddf_instance);
     127        CHECK_RET_RETURN(ret, "Failed to bind UHCI device function: %s.\n",
     128            str_error(ret));
    76129
    77130        /* allow access to hc control registers */
    78131        regs_t *io;
    79         int ret = pio_enable(regs, reg_size, (void**)&io);
     132        ret = pio_enable(regs, reg_size, (void**)&io);
    80133        CHECK_RET_RETURN(ret, "Failed to gain access to registers at %p.\n", io);
    81134        instance->registers = io;
  • uspace/drv/uhci-hcd/uhci.h

    rdeece2f r233e68d  
    3939#include <fibril_synch.h>
    4040#include <adt/list.h>
     41#include <ddi.h>
    4142
    4243#include <usb/addrkeep.h>
     
    9798        fid_t cleaner;
    9899        fid_t debug_checker;
     100
     101        ddf_fun_t *ddf_instance;
    99102} uhci_t;
    100103
    101104/* init uhci specifics in device.driver_data */
    102 int uhci_init(uhci_t *instance, void *regs, size_t reg_size);
     105int uhci_init(uhci_t *instance, ddf_dev_t *dev, void *regs, size_t reg_size);
    103106
    104107static inline void uhci_fini(uhci_t *instance) {};
     
    108111void uhci_interrupt(uhci_t *instance, uint16_t status);
    109112
    110 static inline uhci_t * dev_to_uhci(device_t *dev)
     113static inline uhci_t * dev_to_uhci(ddf_dev_t *dev)
    111114        { return (uhci_t*)dev->driver_data; }
     115
     116static inline uhci_t * fun_to_uhci(ddf_fun_t *fun)
     117        { return (uhci_t*)fun->driver_data; }
    112118
    113119
Note: See TracChangeset for help on using the changeset viewer.