Changeset 14e7959 in mainline


Ignore:
Timestamp:
2011-05-25T18:28:10Z (13 years ago)
Author:
Matej Klonfar <maklf@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1eee99f2
Parents:
5499a8b (diff), 1889786 (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:

development changes merged

Files:
1 added
6 deleted
30 edited
2 moved

Legend:

Unmodified
Added
Removed
  • .bzrignore

    r5499a8b r14e7959  
    77*.map
    88*.disasm
     9*.lo
     10*.la
     11*.so.*
     12*.so0
    913_link.ld
    1014./*.iso
  • uspace/Makefile.common

    r5499a8b r14e7959  
    131131        endif
    132132endif
     133# Build static whenever we use libusb because that library uses
     134# thread local variables
     135ifneq ($(findstring usb, $(LIBS)),)
     136        STATIC_BUILD = y
     137endif
    133138
    134139ifeq ($(STATIC_BUILD), y)
  • uspace/app/lsusb/main.c

    r5499a8b r14e7959  
    4545#include <devmap.h>
    4646#include <usb/dev/hub.h>
    47 #include <usb/host.h>
     47#include <usb/hc.h>
    4848
    4949#define NAME "lsusb"
  • uspace/app/mkbd/main.c

    r5499a8b r14e7959  
    4545#include <devmap.h>
    4646#include <usb/dev/hub.h>
    47 #include <usb/host.h>
    48 #include <usb/driver.h>
     47#include <usb/hc.h>
    4948#include <usb/dev/pipes.h>
    5049
     
    173172                /* Try to get its address. */
    174173                if (!addr_found) {
    175                         addr = usb_device_get_assigned_address(dev_handle);
     174                        addr = usb_hc_get_address_by_handle(dev_handle);
    176175                        if (addr >= 0) {
    177176                                addr_found = true;
  • uspace/app/usbinfo/main.c

    r5499a8b r14e7959  
    4343#include <devman.h>
    4444#include <devmap.h>
    45 #include <usb/dev/hc.h>
     45#include <usb/hc.h>
    4646#include <usb/dev/pipes.h>
    47 #include <usb/host.h>
    48 #include <usb/driver.h>
    4947#include "usbinfo.h"
    50 
    51 static bool try_parse_class_and_address(const char *path,
    52     devman_handle_t *out_hc_handle, usb_address_t *out_device_address)
    53 {
    54         size_t class_index;
    55         size_t address;
    56         int rc;
    57         char *ptr;
    58 
    59         rc = str_size_t(path, &ptr, 10, false, &class_index);
    60         if (rc != EOK) {
    61                 return false;
    62         }
    63         if ((*ptr == ':') || (*ptr == '.')) {
    64                 ptr++;
    65         } else {
    66                 return false;
    67         }
    68         rc = str_size_t(ptr, NULL, 10, true, &address);
    69         if (rc != EOK) {
    70                 return false;
    71         }
    72         rc = usb_ddf_get_hc_handle_by_class(class_index, out_hc_handle);
    73         if (rc != EOK) {
    74                 return false;
    75         }
    76         if (out_device_address != NULL) {
    77                 *out_device_address = (usb_address_t) address;
    78         }
    79         return true;
    80 }
    81 
    82 static bool resolve_hc_handle_and_dev_addr(const char *devpath,
    83     devman_handle_t *out_hc_handle, usb_address_t *out_device_address)
    84 {
    85         int rc;
    86 
    87         /* Hack for QEMU to save-up on typing ;-). */
    88         if (str_cmp(devpath, "qemu") == 0) {
    89                 devpath = "/hw/pci0/00:01.2/uhci-rh/usb00_a1";
    90         }
    91 
    92         /* Hack for virtual keyboard. */
    93         if (str_cmp(devpath, "virt") == 0) {
    94                 devpath = "/virt/usbhc/usb00_a1/usb00_a2";
    95         }
    96 
    97         if (try_parse_class_and_address(devpath,
    98             out_hc_handle, out_device_address)) {
    99                 return true;
    100         }
    101 
    102         char *path = str_dup(devpath);
    103         if (path == NULL) {
    104                 return ENOMEM;
    105         }
    106 
    107         devman_handle_t hc = 0;
    108         bool hc_found = false;
    109         usb_address_t addr = 0;
    110         bool addr_found = false;
    111 
    112         /* Remove suffixes and hope that we will encounter device node. */
    113         while (str_length(path) > 0) {
    114                 /* Get device handle first. */
    115                 devman_handle_t dev_handle;
    116                 rc = devman_device_get_handle(path, &dev_handle, 0);
    117                 if (rc != EOK) {
    118                         free(path);
    119                         return false;
    120                 }
    121 
    122                 /* Try to find its host controller. */
    123                 if (!hc_found) {
    124                         rc = usb_hc_find(dev_handle, &hc);
    125                         if (rc == EOK) {
    126                                 hc_found = true;
    127                         }
    128                 }
    129                 /* Try to get its address. */
    130                 if (!addr_found) {
    131                         addr = usb_device_get_assigned_address(dev_handle);
    132                         if (addr >= 0) {
    133                                 addr_found = true;
    134                         }
    135                 }
    136 
    137                 /* Speed-up. */
    138                 if (hc_found && addr_found) {
    139                         break;
    140                 }
    141 
    142                 /* Remove the last suffix. */
    143                 char *slash_pos = str_rchr(path, '/');
    144                 if (slash_pos != NULL) {
    145                         *slash_pos = 0;
    146                 }
    147         }
    148 
    149         free(path);
    150 
    151         if (hc_found && addr_found) {
    152                 if (out_hc_handle != NULL) {
    153                         *out_hc_handle = hc;
    154                 }
    155                 if (out_device_address != NULL) {
    156                         *out_device_address = addr;
    157                 }
    158                 return true;
    159         } else {
    160                 return false;
    161         }
    162 }
    16348
    16449static void print_usage(char *app_name)
     
    300185                devman_handle_t hc_handle = 0;
    301186                usb_address_t dev_addr = 0;
    302                 bool found = resolve_hc_handle_and_dev_addr(devpath,
    303                     &hc_handle, &dev_addr);
    304                 if (!found) {
     187                int rc = usb_resolve_device_handle(devpath,
     188                    &hc_handle, &dev_addr, NULL);
     189                if (rc != EOK) {
    305190                        fprintf(stderr, NAME ": device `%s' not found "
    306191                            "or not of USB kind, skipping.\n",
  • uspace/drv/ohci/hc.c

    r5499a8b r14e7959  
    565565        bzero(&instance->rh, sizeof(instance->rh));
    566566        /* Init queues */
    567         hc_init_transfer_lists(instance);
     567        const int ret = hc_init_transfer_lists(instance);
     568        if (ret != EOK) {
     569                return ret;
     570        }
    568571
    569572        /*Init HCCA */
  • uspace/drv/uhci-hcd/Makefile

    r5499a8b r14e7959  
    4848        root_hub.c \
    4949        hw_struct/transfer_descriptor.c \
    50         utils/slab.c \
    5150        pci.c \
    5251        batch.c
  • uspace/drv/uhci-hcd/batch.h

    r5499a8b r14e7959  
    3535#define DRV_UHCI_BATCH_H
    3636
    37 #include <usbhc_iface.h>
    38 #include <usb/usb.h>
    39 #include <usb/host/device_keeper.h>
    40 #include <usb/host/endpoint.h>
    4137#include <usb/host/batch.h>
    4238
  • uspace/drv/uhci-hcd/hc.c

    r5499a8b r14e7959  
    3939#include <usb/debug.h>
    4040#include <usb/usb.h>
    41 #include <usb/ddfiface.h>
    42 #include <usb_iface.h>
    4341
    4442#include "hc.h"
     
    8583        /* allow access to hc control registers */
    8684        regs_t *io;
    87         ret = pio_enable(regs, reg_size, (void**)&io);
     85        ret = pio_enable(regs, reg_size, (void **)&io);
    8886        CHECK_RET_RETURN(ret,
    8987            "Failed(%d) to gain access to registers at %p: %s.\n",
     
    143141        }
    144142
    145         uint16_t status = pio_read_16(&registers->usbcmd);
     143        const uint16_t status = pio_read_16(&registers->usbcmd);
    146144        if (status != 0)
    147145                usb_log_warning("Previous command value: %x.\n", status);
     
    212210        /* Init USB frame list page*/
    213211        instance->frame_list = get_page();
    214         ret = instance ? EOK : ENOMEM;
     212        ret = instance->frame_list ? EOK : ENOMEM;
    215213        CHECK_RET_RETURN(ret, "Failed to get frame list page.\n");
    216214        usb_log_debug("Initialized frame list at %p.\n", instance->frame_list);
     
    277275                &instance->transfers_control_slow);
    278276
    279         /*FSBR*/
     277        /*FSBR, This feature is not needed (adds no benefit) and is supposedly
     278         * buggy on certain hw, enable at your own risk. */
    280279#ifdef FSBR
    281280        transfer_list_set_next(&instance->transfers_bulk_full,
     
    428427                }
    429428
    430                 uintptr_t frame_list =
     429                const uintptr_t frame_list =
    431430                    pio_read_32(&instance->registers->flbaseadd) & ~0xfff;
    432431                if (frame_list != addr_to_phys(instance->frame_list)) {
  • uspace/drv/uhci-hcd/hc.h

    r5499a8b r14e7959  
    3737
    3838#include <fibril.h>
    39 #include <fibril_synch.h>
    40 #include <adt/list.h>
    4139#include <ddi.h>
    4240
    43 #include <usbhc_iface.h>
    4441#include <usb/host/device_keeper.h>
    4542#include <usb/host/usb_endpoint_manager.h>
     43#include <usb/host/batch.h>
    4644
    47 #include "batch.h"
    4845#include "transfer_list.h"
    4946
     
    154151 */
    155152static inline hc_t * fun_to_hc(ddf_fun_t *fun)
    156         { return (hc_t*)fun->driver_data; }
     153{
     154        assert(fun);
     155        return fun->driver_data;
     156}
    157157#endif
    158158/**
  • uspace/drv/uhci-hcd/iface.c

    r5499a8b r14e7959  
    3939
    4040#include "iface.h"
     41#include "batch.h"
    4142#include "hc.h"
    4243
     
    122123        return EOK;
    123124}
    124 
     125/*----------------------------------------------------------------------------*/
    125126/** Find device handle by address interface function.
    126127 *
     
    136137        hc_t *hc = fun_to_hc(fun);
    137138        assert(hc);
    138         bool found =
     139        const bool found =
    139140            usb_device_keeper_find_by_address(&hc->manager, address, handle);
    140141        return found ? EOK : ENOENT;
    141142}
    142 
    143143/*----------------------------------------------------------------------------*/
    144144/** Release address interface function
     
    164164    size_t max_packet_size, unsigned int interval)
    165165{
     166        assert(fun);
    166167        hc_t *hc = fun_to_hc(fun);
    167168        assert(hc);
     
    183184    usb_endpoint_t endpoint, usb_direction_t direction)
    184185{
     186        assert(fun);
    185187        hc_t *hc = fun_to_hc(fun);
    186188        assert(hc);
     
    211213        if (ret != EOK)
    212214                return ret;
     215        assert(batch);
     216        assert(hc);
    213217        batch_interrupt_out(batch);
    214218        ret = hc_schedule(hc, batch);
     
    239243        if (ret != EOK)
    240244                return ret;
     245        assert(batch);
     246        assert(hc);
    241247        batch_interrupt_in(batch);
    242248        ret = hc_schedule(hc, batch);
     
    267273        if (ret != EOK)
    268274                return ret;
     275        assert(batch);
     276        assert(hc);
    269277        batch_bulk_out(batch);
    270278        ret = hc_schedule(hc, batch);
     
    295303        if (ret != EOK)
    296304                return ret;
     305        assert(batch);
     306        assert(hc);
    297307        batch_bulk_in(batch);
    298308        ret = hc_schedule(hc, batch);
     
    327337        if (ret != EOK)
    328338                return ret;
     339        assert(batch);
     340        assert(hc);
    329341        usb_endpoint_manager_reset_if_need(&hc->ep_manager, target, setup_data);
    330342        batch_control_write(batch);
     
    360372        if (ret != EOK)
    361373                return ret;
     374        assert(batch);
     375        assert(hc);
    362376        batch_control_read(batch);
    363377        ret = hc_schedule(hc, batch);
  • uspace/drv/uhci-hcd/pci.c

    r5499a8b r14e7959  
    5252 * @return Error code.
    5353 */
    54 int pci_get_my_registers(ddf_dev_t *dev,
     54int pci_get_my_registers(const ddf_dev_t *dev,
    5555    uintptr_t *io_reg_address, size_t *io_reg_size, int *irq_no)
    5656{
    57         assert(dev != NULL);
     57        assert(dev);
     58        assert(io_reg_address);
     59        assert(io_reg_size);
     60        assert(irq_no);
    5861
    5962        int parent_phone =
     
    6669        int rc = hw_res_get_resource_list(parent_phone, &hw_resources);
    6770        if (rc != EOK) {
    68                 goto leave;
     71                async_hangup(parent_phone);
     72                return rc;
    6973        }
    7074
     
    7882        size_t i;
    7983        for (i = 0; i < hw_resources.count; i++) {
    80                 hw_resource_t *res = &hw_resources.resources[i];
     84                const hw_resource_t *res = &hw_resources.resources[i];
    8185                switch (res->type)
    8286                {
     
    99103                }
    100104        }
     105        async_hangup(parent_phone);
    101106
    102         if (!io_found || !irq_found) {
    103                 rc = ENOENT;
    104                 goto leave;
    105         }
     107        if (!io_found || !irq_found)
     108                return ENOENT;
    106109
    107110        *io_reg_address = io_address;
     
    109112        *irq_no = irq;
    110113
    111         rc = EOK;
    112 leave:
    113         async_hangup(parent_phone);
    114         return rc;
     114        return EOK;
    115115}
    116116/*----------------------------------------------------------------------------*/
     
    120120 * @return Error code.
    121121 */
    122 int pci_enable_interrupts(ddf_dev_t *device)
     122int pci_enable_interrupts(const ddf_dev_t *device)
    123123{
    124         int parent_phone = devman_parent_device_connect(device->handle,
    125             IPC_FLAG_BLOCKING);
    126         bool enabled = hw_res_enable_interrupt(parent_phone);
     124        const int parent_phone =
     125            devman_parent_device_connect(device->handle, IPC_FLAG_BLOCKING);
     126        if (parent_phone < 0) {
     127                return parent_phone;
     128        }
     129        const bool enabled = hw_res_enable_interrupt(parent_phone);
    127130        async_hangup(parent_phone);
    128131        return enabled ? EOK : EIO;
     
    134137 * @return Error code.
    135138 */
    136 int pci_disable_legacy(ddf_dev_t *device)
     139int pci_disable_legacy(const ddf_dev_t *device)
    137140{
    138141        assert(device);
    139         int parent_phone =
     142        const int parent_phone =
    140143            devman_parent_device_connect(device->handle, IPC_FLAG_BLOCKING);
    141144        if (parent_phone < 0) {
     
    145148        /* See UHCI design guide for these values p.45,
    146149         * write all WC bits in USB legacy register */
    147         sysarg_t address = 0xc0;
    148         sysarg_t value = 0xaf00;
     150        const sysarg_t address = 0xc0;
     151        const sysarg_t value = 0xaf00;
    149152
    150         int rc = async_req_3_0(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE),
     153        const int rc = async_req_3_0(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE),
    151154            IPC_M_CONFIG_SPACE_WRITE_16, address, value);
    152155        async_hangup(parent_phone);
  • uspace/drv/uhci-hcd/pci.h

    r5499a8b r14e7959  
    3838#include <ddf/driver.h>
    3939
    40 int pci_get_my_registers(ddf_dev_t *, uintptr_t *, size_t *, int *);
    41 int pci_enable_interrupts(ddf_dev_t *);
    42 int pci_disable_legacy(ddf_dev_t *);
     40int pci_get_my_registers(const ddf_dev_t *, uintptr_t *, size_t *, int *);
     41int pci_enable_interrupts(const ddf_dev_t *);
     42int pci_disable_legacy(const ddf_dev_t *);
    4343
    4444#endif
  • uspace/drv/uhci-hcd/root_hub.c

    r5499a8b r14e7959  
    6060                return ret;
    6161        }
     62        assert(match_str);
    6263
    6364        ret = ddf_fun_add_match_id(fun, match_str, 100);
  • uspace/drv/uhci-hcd/root_hub.h

    r5499a8b r14e7959  
    4343        /** List of resources available to the root hub. */
    4444        hw_resource_list_t resource_list;
    45         /** The only resource in the above list */
     45        /** The only resource in the RH resource list */
    4646        hw_resource_t io_regs;
    4747} rh_t;
  • uspace/drv/uhci-hcd/transfer_list.c

    r5499a8b r14e7959  
    3636#include <arch/barrier.h>
    3737
     38
    3839#include "transfer_list.h"
     40#include "batch.h"
    3941
    4042static void transfer_list_remove_batch(
     
    5860                return ENOMEM;
    5961        }
    60         uint32_t queue_head_pa = addr_to_phys(instance->queue_head);
     62        const uint32_t queue_head_pa = addr_to_phys(instance->queue_head);
    6163        usb_log_debug2("Transfer list %s setup with QH: %p (%#" PRIx32" ).\n",
    6264            name, instance->queue_head, queue_head_pa);
     
    9092{
    9193        assert(instance);
     94        assert(instance->queue_head);
    9295        assert(next);
    93         if (!instance->queue_head)
    94                 return;
    9596        /* Set queue_head.next to point to the follower */
    9697        qh_set_next_qh(instance->queue_head, next->queue_head);
     
    137138        write_barrier();
    138139
    139         /* Add to the driver list */
     140        /* Add to the driver's list */
    140141        list_append(&batch->link, &instance->batch_list);
    141142
     
    160161        link_t *current = instance->batch_list.next;
    161162        while (current != &instance->batch_list) {
    162                 link_t *next = current->next;
     163                link_t * const next = current->next;
    163164                usb_transfer_batch_t *batch =
    164165                    usb_transfer_batch_from_link(current);
     
    182183        fibril_mutex_lock(&instance->guard);
    183184        while (!list_empty(&instance->batch_list)) {
    184                 link_t *current = instance->batch_list.next;
     185                link_t * const current = instance->batch_list.next;
    185186                usb_transfer_batch_t *batch =
    186187                    usb_transfer_batch_from_link(current);
  • uspace/drv/uhci-hcd/transfer_list.h

    r5499a8b r14e7959  
    3636
    3737#include <fibril_synch.h>
     38#include <usb/host/batch.h>
    3839
    39 #include "batch.h"
    4040#include "hw_struct/queue_head.h"
    4141
  • uspace/drv/uhci-hcd/uhci.c

    r5499a8b r14e7959  
    7777{
    7878        assert(dev);
    79         hc_t *hc = &((uhci_t*)dev->driver_data)->hc;
     79        uhci_t *uhci = dev->driver_data;
     80        assert(uhci);
     81        hc_t *hc = &uhci->hc;
    8082        uint16_t status = IPC_GET_ARG1(*call);
    8183        assert(hc);
     
    144146{
    145147        assert(fun);
    146         return &((rh_t*)fun->driver_data)->resource_list;
     148        rh_t *rh = fun->driver_data;
     149        assert(rh);
     150        return &rh->resource_list;
    147151}
    148152/*----------------------------------------------------------------------------*/
  • uspace/drv/uhci-hcd/uhci.h

    r5499a8b r14e7959  
    3535#ifndef DRV_UHCI_UHCI_H
    3636#define DRV_UHCI_UHCI_H
    37 #include <ddi.h>
    3837#include <ddf/driver.h>
    3938
  • uspace/drv/uhci-hcd/utils/malloc32.h

    r5499a8b r14e7959  
    4141#include <as.h>
    4242
    43 #include "slab.h"
    44 
    4543#define UHCI_STRCUTURES_ALIGNMENT 16
    4644#define UHCI_REQUIRED_PAGE_SIZE 4096
     
    5957        uintptr_t result;
    6058        const int ret = as_get_physical_mapping(addr, &result);
    61         assert(ret == EOK);
    62 
    6359        if (ret != EOK)
    6460                return 0;
     
    7268 */
    7369static inline void * malloc32(size_t size) {
    74         if (size <= SLAB_ELEMENT_SIZE)
    75                 return slab_malloc_g();
    76         usb_log_warning("Requested %zu bytes, current allocator can't handle "
    77             "that amount, pray that the standard malloc will suffice.", size);
    78         return memalign(UHCI_STRCUTURES_ALIGNMENT, size);
     70        /* This works only when the host has less than 4GB of memory as
     71         * physical address needs to fit into 32 bits */
     72
     73        /* If we need more than one page there is no guarantee that the
     74         * memory will be continuous */
     75        if (size > PAGE_SIZE)
     76                return NULL;
     77        /* Calculate alignment to make sure the block won't cross page
     78         * boundary */
     79        size_t alignment = UHCI_STRCUTURES_ALIGNMENT;
     80        while (alignment < size)
     81                alignment *= 2;
     82        return memalign(alignment, size);
    7983}
    8084/*----------------------------------------------------------------------------*/
     
    8690        if (!addr)
    8791                return;
    88         if (slab_in_range_g(addr))
    89                 return slab_free_g(addr);
    9092        free(addr);
    9193}
     
    98100{
    99101        void *free_address = as_get_mappable_page(UHCI_REQUIRED_PAGE_SIZE);
    100         assert(free_address); /* TODO: remove this assert */
    101102        if (free_address == 0)
    102103                return NULL;
  • uspace/drv/uhci-rhd/main.c

    r5499a8b r14e7959  
    3737#include <errno.h>
    3838#include <str_error.h>
     39
    3940#include <usb_iface.h>
    4041#include <usb/ddfiface.h>
     
    4546#define NAME "uhci-rhd"
    4647
    47 static int hc_get_my_registers(ddf_dev_t *dev,
     48static int hc_get_my_registers(const ddf_dev_t *dev,
    4849    uintptr_t *io_reg_address, size_t *io_reg_size);
    4950/*----------------------------------------------------------------------------*/
     
    130131 */
    131132int hc_get_my_registers(
    132     ddf_dev_t *dev, uintptr_t *io_reg_address, size_t *io_reg_size)
     133    const ddf_dev_t *dev, uintptr_t *io_reg_address, size_t *io_reg_size)
    133134{
    134         assert(dev != NULL);
     135        assert(dev);
    135136
    136         int parent_phone = devman_parent_device_connect(dev->handle,
     137        const int parent_phone = devman_parent_device_connect(dev->handle,
    137138            IPC_FLAG_BLOCKING);
    138139        if (parent_phone < 0) {
     
    141142
    142143        hw_resource_list_t hw_resources;
    143         int ret = hw_res_get_resource_list(parent_phone, &hw_resources);
     144        const int ret = hw_res_get_resource_list(parent_phone, &hw_resources);
    144145        if (ret != EOK) {
    145146                async_hangup(parent_phone);
  • uspace/drv/uhci-rhd/port.c

    r5499a8b r14e7959  
    3636#include <errno.h>
    3737#include <str_error.h>
    38 #include <time.h>
    3938#include <async.h>
    4039
     
    8281 * @param[in] number Port number.
    8382 * @param[in] usec Polling interval.
    84  * @param[in] rh Pointer to ddf instance fo the root hub driver.
     83 * @param[in] rh Pointer to ddf instance of the root hub driver.
    8584 * @return Error code.
    8685 *
     
    9190{
    9291        assert(port);
    93         asprintf(&port->id_string, "Port (%p - %u)", port, number);
    94         if (port->id_string == NULL) {
     92        char *id_string;
     93        asprintf(&id_string, "Port (%p - %u)", port, number);
     94        if (id_string == NULL) {
    9595                return ENOMEM;
    9696        }
    9797
     98        port->id_string = id_string;
    9899        port->address = address;
    99100        port->number = number;
     
    105106            usb_hc_connection_initialize_from_device(&port->hc_connection, rh);
    106107        if (ret != EOK) {
    107                 usb_log_error("Failed to initialize connection to HC.");
     108                usb_log_error("%s: failed to initialize connection to HC.",
     109                    port->id_string);
     110                free(id_string);
    108111                return ret;
    109112        }
     
    113116                usb_log_error("%s: failed to create polling fibril.",
    114117                    port->id_string);
     118                free(id_string);
    115119                return ENOMEM;
    116120        }
     
    132136        assert(port);
    133137        free(port->id_string);
    134         /* TODO: Kill fibril here */
     138        // TODO: Kill fibril here
    135139        return;
    136140}
     
    150154
    151155                /* Read register value */
    152                 port_status_t port_status = uhci_port_read_status(instance);
     156                const port_status_t port_status =
     157                    uhci_port_read_status(instance);
    153158
    154159                /* Print the value if it's interesting */
     
    161166                usb_log_debug("%s: Connected change detected: %x.\n",
    162167                    instance->id_string, port_status);
    163 
    164                 int rc =
    165                     usb_hc_connection_open(&instance->hc_connection);
    166                 if (rc != EOK) {
    167                         usb_log_error("%s: Failed to connect to HC.",
    168                             instance->id_string);
    169                         continue;
    170                 }
    171168
    172169                /* Remove any old device */
     
    175172                            instance->id_string);
    176173                        uhci_port_remove_device(instance);
     174                }
     175
     176                int ret =
     177                    usb_hc_connection_open(&instance->hc_connection);
     178                if (ret != EOK) {
     179                        usb_log_error("%s: Failed to connect to HC.",
     180                            instance->id_string);
     181                        continue;
    177182                }
    178183
     
    190195                }
    191196
    192                 rc = usb_hc_connection_close(&instance->hc_connection);
    193                 if (rc != EOK) {
     197                ret = usb_hc_connection_close(&instance->hc_connection);
     198                if (ret != EOK) {
    194199                        usb_log_error("%s: Failed to disconnect.",
    195200                            instance->id_string);
     
    209214int uhci_port_reset_enable(int portno, void *arg)
    210215{
    211         uhci_port_t *port = (uhci_port_t *) arg;
     216        uhci_port_t *port = arg;
     217        assert(port);
    212218
    213219        usb_log_debug2("%s: new_device_enable_port.\n", port->id_string);
     
    283289        usb_log_error("%s: Don't know how to remove device %" PRIun ".\n",
    284290            port->id_string, port->attached_device);
     291        port->attached_device = 0;
    285292        return ENOTSUP;
    286293}
  • uspace/drv/uhci-rhd/port.h

    r5499a8b r14e7959  
    3838#include <fibril.h>
    3939#include <ddf/driver.h>
    40 #include <usb/dev/hc.h> /* usb_hc_connection_t */
     40#include <usb/hc.h> /* usb_hc_connection_t */
    4141
    4242typedef uint16_t port_status_t;
     
    5757typedef struct uhci_port
    5858{
    59         char *id_string;
     59        const char *id_string;
    6060        port_status_t *address;
    6161        unsigned number;
  • uspace/lib/usb/Makefile

    r5499a8b r14e7959  
    3737        src/ddfiface.c \
    3838        src/debug.c \
    39         src/driver.c \
    4039        src/dump.c \
    41         src/host.c \
     40        src/hc.c \
     41        src/resolve.c \
    4242        src/usb.c
    4343
  • uspace/lib/usb/include/usb/hc.h

    r5499a8b r14e7959  
    2727 */
    2828
    29 /** @addtogroup libusbdev
     29/** @addtogroup libusb
    3030 * @{
    3131 */
    3232/** @file
    33  * General communication between device drivers and host controller driver.
     33 * General communication with host controller driver.
    3434 */
    35 #ifndef LIBUSBDEV_HC_H_
    36 #define LIBUSBDEV_HC_H_
     35#ifndef LIBUSB_HC_H_
     36#define LIBUSB_HC_H_
    3737
    3838#include <sys/types.h>
     
    5757bool usb_hc_connection_is_opened(const usb_hc_connection_t *);
    5858int usb_hc_connection_close(usb_hc_connection_t *);
     59int usb_hc_get_handle_by_address(usb_hc_connection_t *, usb_address_t,
     60    devman_handle_t *);
    5961
     62int usb_hc_get_address_by_handle(devman_handle_t);
     63
     64int usb_hc_find(devman_handle_t, devman_handle_t *);
     65
     66int usb_resolve_device_handle(const char *, devman_handle_t *, usb_address_t *,
     67    devman_handle_t *);
     68
     69int usb_ddf_get_hc_handle_by_class(size_t, devman_handle_t *);
    6070
    6171
  • uspace/lib/usb/src/ddfiface.c

    r5499a8b r14e7959  
    3737#include <async.h>
    3838#include <usb/ddfiface.h>
    39 #include <usb/driver.h>
     39#include <usb/hc.h>
    4040#include <usb/debug.h>
    4141#include <errno.h>
  • uspace/lib/usb/src/hc.c

    r5499a8b r14e7959  
    2727 */
    2828
    29 /** @addtogroup libusbdev
     29/** @addtogroup libusb
    3030 * @{
    3131 */
    3232/** @file
    33  * General communication between device drivers and host controller driver.
     33 * General communication with host controller driver (implementation).
    3434 */
    3535#include <devman.h>
    3636#include <async.h>
     37#include <dev_iface.h>
    3738#include <usb_iface.h>
    38 #include <usb/dev/hc.h>
    39 #include <usb/driver.h>
     39#include <usbhc_iface.h>
     40#include <usb/hc.h>
    4041#include <usb/debug.h>
    4142#include <errno.h>
     
    143144}
    144145
     146/** Get handle of USB device with given address.
     147 *
     148 * @param[in] connection Opened connection to host controller.
     149 * @param[in] address Address of device in question.
     150 * @param[out] handle Where to write the device handle.
     151 * @return Error code.
     152 */
     153int usb_hc_get_handle_by_address(usb_hc_connection_t *connection,
     154    usb_address_t address, devman_handle_t *handle)
     155{
     156        if (!usb_hc_connection_is_opened(connection)) {
     157                return ENOENT;
     158        }
     159
     160        sysarg_t tmp;
     161        int rc = async_req_2_1(connection->hc_phone,
     162            DEV_IFACE_ID(USBHC_DEV_IFACE),
     163            IPC_M_USBHC_GET_HANDLE_BY_ADDRESS,
     164            address, &tmp);
     165        if ((rc == EOK) && (handle != NULL)) {
     166                *handle = tmp;
     167        }
     168
     169        return rc;
     170}
     171
     172/** Tell USB address assigned to device with given handle.
     173 *
     174 * @param dev_handle Devman handle of the USB device in question.
     175 * @return USB address or negative error code.
     176 */
     177usb_address_t usb_hc_get_address_by_handle(devman_handle_t dev_handle)
     178{
     179        int parent_phone = devman_parent_device_connect(dev_handle,
     180            IPC_FLAG_BLOCKING);
     181        if (parent_phone < 0) {
     182                return parent_phone;
     183        }
     184
     185        sysarg_t address;
     186
     187        int rc = async_req_2_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
     188            IPC_M_USB_GET_ADDRESS,
     189            dev_handle, &address);
     190
     191        if (rc != EOK) {
     192                return rc;
     193        }
     194
     195        async_hangup(parent_phone);
     196
     197        return (usb_address_t) address;
     198}
     199
     200
     201/** Get host controller handle by its class index.
     202 *
     203 * @param class_index Class index for the host controller.
     204 * @param hc_handle Where to store the HC handle
     205 *      (can be NULL for existence test only).
     206 * @return Error code.
     207 */
     208int usb_ddf_get_hc_handle_by_class(size_t class_index,
     209    devman_handle_t *hc_handle)
     210{
     211        char *class_index_str;
     212        devman_handle_t hc_handle_tmp;
     213        int rc;
     214
     215        rc = asprintf(&class_index_str, "%zu", class_index);
     216        if (rc < 0) {
     217                return ENOMEM;
     218        }
     219        rc = devman_device_get_handle_by_class("usbhc", class_index_str,
     220            &hc_handle_tmp, 0);
     221        free(class_index_str);
     222        if (rc != EOK) {
     223                return rc;
     224        }
     225
     226        if (hc_handle != NULL) {
     227                *hc_handle = hc_handle_tmp;
     228        }
     229
     230        return EOK;
     231}
     232
     233/** Find host controller handle that is ancestor of given device.
     234 *
     235 * @param[in] device_handle Device devman handle.
     236 * @param[out] hc_handle Where to store handle of host controller
     237 *      controlling device with @p device_handle handle.
     238 * @return Error code.
     239 */
     240int usb_hc_find(devman_handle_t device_handle, devman_handle_t *hc_handle)
     241{
     242        int parent_phone = devman_parent_device_connect(device_handle,
     243            IPC_FLAG_BLOCKING);
     244        if (parent_phone < 0) {
     245                return parent_phone;
     246        }
     247
     248        devman_handle_t h;
     249        int rc = async_req_1_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
     250            IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &h);
     251
     252        async_hangup(parent_phone);
     253
     254        if (rc != EOK) {
     255                return rc;
     256        }
     257
     258        if (hc_handle != NULL) {
     259                *hc_handle = h;
     260        }
     261
     262        return EOK;
     263}
     264
    145265/**
    146266 * @}
  • uspace/lib/usbdev/Makefile

    r5499a8b r14e7959  
    4646        src/pipesio.c \
    4747        src/recognise.c \
    48         src/request.c \
    49         src/usbdevice.c
     48        src/request.c
    5049
    5150include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/usbdev/include/usb/dev/hub.h

    r5499a8b r14e7959  
    3939
    4040#include <sys/types.h>
    41 #include <usb/dev/hc.h>
     41#include <usb/hc.h>
    4242
    4343int usb_hc_new_device_wrapper(ddf_dev_t *, usb_hc_connection_t *, usb_speed_t,
     
    6363    const usb_hc_attached_device_t *);
    6464int usb_hc_unregister_device(usb_hc_connection_t *, usb_address_t);
    65 int usb_hc_get_handle_by_address(usb_hc_connection_t *, usb_address_t,
    66     devman_handle_t *);
    6765
    6866#endif
  • uspace/lib/usbdev/include/usb/dev/pipes.h

    r5499a8b r14e7959  
    3838#include <sys/types.h>
    3939#include <usb/usb.h>
    40 #include <usb/dev/hc.h>
     40#include <usb/hc.h>
    4141#include <usb/descriptor.h>
    4242#include <ipc/devman.h>
     
    163163
    164164int usb_device_get_assigned_interface(ddf_dev_t *);
    165 usb_address_t usb_device_get_assigned_address(devman_handle_t);
    166165
    167166int usb_pipe_initialize(usb_pipe_t *, usb_device_connection_t *,
  • uspace/lib/usbdev/src/hub.c

    r5499a8b r14e7959  
    120120}
    121121
    122 /** Get handle of USB device with given address.
    123  *
    124  * @param[in] connection Opened connection to host controller.
    125  * @param[in] address Address of device in question.
    126  * @param[out] handle Where to write the device handle.
    127  * @return Error code.
    128  */
    129 int usb_hc_get_handle_by_address(usb_hc_connection_t *connection,
    130     usb_address_t address, devman_handle_t *handle)
    131 {
    132         CHECK_CONNECTION(connection);
    133 
    134         sysarg_t tmp;
    135         int rc = async_req_2_1(connection->hc_phone,
    136             DEV_IFACE_ID(USBHC_DEV_IFACE),
    137             IPC_M_USBHC_GET_HANDLE_BY_ADDRESS,
    138             address, &tmp);
    139         if ((rc == EOK) && (handle != NULL)) {
    140                 *handle = tmp;
    141         }
    142 
    143         return rc;
    144 }
    145122
    146123static void unregister_control_endpoint_on_default_address(
  • uspace/lib/usbdev/src/pipes.c

    r5499a8b r14e7959  
    3636#include <usb/dev/pipes.h>
    3737#include <usb/debug.h>
    38 #include <usb/driver.h>
     38#include <usb/hc.h>
    3939#include <usbhc_iface.h>
    4040#include <usb_iface.h>
     
    9797
    9898        return (int) iface_no;
    99 }
    100 
    101 /** Tell USB address assigned to given device.
    102  *
    103  * @param dev_handle Devman handle of the USB device in question.
    104  * @return USB address or negative error code.
    105  */
    106 usb_address_t usb_device_get_assigned_address(devman_handle_t dev_handle)
    107 {
    108         int parent_phone = devman_parent_device_connect(dev_handle,
    109             IPC_FLAG_BLOCKING);
    110         if (parent_phone < 0) {
    111                 return parent_phone;
    112         }
    113 
    114         sysarg_t address;
    115 
    116         int rc = async_req_2_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
    117             IPC_M_USB_GET_ADDRESS,
    118             dev_handle, &address);
    119 
    120         if (rc != EOK) {
    121                 return rc;
    122         }
    123 
    124         async_hangup(parent_phone);
    125 
    126         return (usb_address_t) address;
    12799}
    128100
Note: See TracChangeset for help on using the changeset viewer.