Changeset f8e8738 in mainline for uspace/drv


Ignore:
Timestamp:
2011-04-07T20:22:40Z (15 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fee6381
Parents:
61257f4 (diff), a82889e (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:

Changes from development

Location:
uspace/drv
Files:
4 added
36 edited
3 moved

Legend:

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

    r61257f4 rf8e8738  
    5353
    5454#include <ddf/driver.h>
     55#include <ddf/log.h>
    5556#include <ops/hw_res.h>
    5657
     
    134135        fd = open(conf_path, O_RDONLY);
    135136        if (fd < 0) {
    136                 printf(NAME ": unable to open %s\n", conf_path);
     137                ddf_msg(LVL_ERROR, "Unable to open %s", conf_path);
    137138                goto cleanup;
    138139        }
     
    141142
    142143        len = lseek(fd, 0, SEEK_END);
    143         lseek(fd, 0, SEEK_SET); 
     144        lseek(fd, 0, SEEK_SET);
    144145        if (len == 0) {
    145                 printf(NAME ": fun_conf_read error: configuration file '%s' "
    146                     "is empty.\n", conf_path);
     146                ddf_msg(LVL_ERROR, "Configuration file '%s' is empty.",
     147                    conf_path);
    147148                goto cleanup;
    148149        }
     
    150151        buf = malloc(len + 1);
    151152        if (buf == NULL) {
    152                 printf(NAME ": fun_conf_read error: memory allocation failed.\n");
     153                ddf_msg(LVL_ERROR, "Memory allocation failed.");
    153154                goto cleanup;
    154155        }
    155156
    156157        if (0 >= read(fd, buf, len)) {
    157                 printf(NAME ": fun_conf_read error: unable to read file '%s'.\n",
    158                     conf_path);
     158                ddf_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path);
    159159                goto cleanup;
    160160        }
     
    252252                fun->hw_resources.count++;
    253253
    254                 printf(NAME ": added irq 0x%x to function %s\n", irq,
     254                ddf_msg(LVL_NOTE, "Added irq 0x%x to function %s", irq,
    255255                    fun->fnode->name);
    256256        }
     
    270270                fun->hw_resources.count++;
    271271
    272                 printf(NAME ": added io range (addr=0x%x, size=0x%x) to "
    273                     "function %s\n", (unsigned int) addr, (unsigned int) len,
     272                ddf_msg(LVL_NOTE, "Added io range (addr=0x%x, size=0x%x) to "
     273                    "function %s", (unsigned int) addr, (unsigned int) len,
    274274                    fun->fnode->name);
    275275        }
     
    331331        score = (int)strtol(val, &end, 10);
    332332        if (val == end) {
    333                 printf(NAME " : error - could not read match score for "
    334                     "function %s.\n", fun->fnode->name);
     333                ddf_msg(LVL_ERROR, "Cannot read match score for function "
     334                    "%s.", fun->fnode->name);
    335335                return;
    336336        }
     
    339339        get_match_id(&id, val);
    340340        if (id == NULL) {
    341                 printf(NAME " : error - could not read match id for "
    342                     "function %s.\n", fun->fnode->name);
     341                ddf_msg(LVL_ERROR, "Cannot read match ID for function %s.",
     342                    fun->fnode->name);
    343343                return;
    344344        }
    345345
    346         printf(NAME ": adding match id '%s' with score %d to function %s\n", id,
    347             score, fun->fnode->name);
     346        ddf_msg(LVL_DEBUG, "Adding match id '%s' with score %d to "
     347            "function %s", id, score, fun->fnode->name);
    348348
    349349        rc = ddf_fun_add_match_id(fun->fnode, id, score);
    350         if (rc != EOK)
    351                 printf(NAME ": error adding match ID: %s\n", str_error(rc));
     350        if (rc != EOK) {
     351                ddf_msg(LVL_ERROR, "Failed adding match ID: %s",
     352                    str_error(rc));
     353        }
    352354}
    353355
     
    375377        if (!prop_parse(fun, line, "io_range", &fun_parse_io_range) &&
    376378            !prop_parse(fun, line, "irq", &fun_parse_irq) &&
    377             !prop_parse(fun, line, "match", &fun_parse_match_id))
    378         {
    379             printf(NAME " error undefined device property at line '%s'\n",
    380                 line);
     379            !prop_parse(fun, line, "match", &fun_parse_match_id)) {
     380
     381                ddf_msg(LVL_ERROR, "Undefined device property at line '%s'",
     382                    line);
    381383        }
    382384}
     
    439441        fun->fnode->ops = &isa_fun_ops;
    440442
    441         printf(NAME ": Binding function %s.\n", fun->fnode->name);
     443        ddf_msg(LVL_DEBUG, "Binding function %s.", fun->fnode->name);
    442444
    443445        /* XXX Handle error */
     
    467469static int isa_add_device(ddf_dev_t *dev)
    468470{
    469         printf(NAME ": isa_add_device, device handle = %d\n",
     471        ddf_msg(LVL_DEBUG, "isa_add_device, device handle = %d",
    470472            (int) dev->handle);
    471473
    472474        /* Make the bus device more visible. Does not do anything. */
    473         printf(NAME ": adding a 'ctl' function\n");
     475        ddf_msg(LVL_DEBUG, "Adding a 'ctl' function");
    474476
    475477        ddf_fun_t *ctl = ddf_fun_create(dev, fun_exposed, "ctl");
    476478        if (ctl == NULL) {
    477                 printf(NAME ": Error creating control function.\n");
     479                ddf_msg(LVL_ERROR, "Failed creating control function.");
    478480                return EXDEV;
    479481        }
    480482
    481483        if (ddf_fun_bind(ctl) != EOK) {
    482                 printf(NAME ": Error binding control function.\n");
     484                ddf_msg(LVL_ERROR, "Failed binding control function.");
    483485                return EXDEV;
    484486        }
     
    486488        /* Add functions as specified in the configuration file. */
    487489        isa_functions_add(dev);
    488         printf(NAME ": finished the enumeration of legacy functions\n");
     490        ddf_msg(LVL_NOTE, "Finished enumerating legacy functions");
    489491
    490492        return EOK;
     
    493495static void isa_init()
    494496{
     497        ddf_log_init(NAME, LVL_ERROR);
    495498        isa_fun_ops.interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops;
    496499}
  • uspace/drv/ns8250/ns8250.c

    r61257f4 rf8e8738  
    5555#include <ddf/driver.h>
    5656#include <ddf/interrupt.h>
     57#include <ddf/log.h>
    5758#include <ops/char_dev.h>
    5859
     
    275276static bool ns8250_pio_enable(ns8250_t *ns)
    276277{
    277         printf(NAME ": ns8250_pio_enable %s\n", ns->dev->name);
     278        ddf_msg(LVL_DEBUG, "ns8250_pio_enable %s", ns->dev->name);
    278279       
    279280        /* Gain control over port's registers. */
    280281        if (pio_enable((void *)(uintptr_t) ns->io_addr, REG_COUNT,
    281282            (void **) &ns->port)) {
    282                 printf(NAME ": error - cannot gain the port %#" PRIx32 " for device "
    283                     "%s.\n", ns->io_addr, ns->dev->name);
     283                ddf_msg(LVL_ERROR, "Cannot map the port %#" PRIx32
     284                    " for device %s.", ns->io_addr, ns->dev->name);
    284285                return false;
    285286        }
     
    295296static bool ns8250_dev_probe(ns8250_t *ns)
    296297{
    297         printf(NAME ": ns8250_dev_probe %s\n", ns->dev->name);
     298        ddf_msg(LVL_DEBUG, "ns8250_dev_probe %s", ns->dev->name);
    298299       
    299300        ioport8_t *port_addr = ns->port;
     
    313314        pio_write_8(port_addr + 4, olddata);
    314315       
    315         if (!res)
    316                 printf(NAME ": device %s is not present.\n", ns->dev->name);
     316        if (!res) {
     317                ddf_msg(LVL_DEBUG, "Device %s is not present.",
     318                    ns->dev->name);
     319        }
    317320       
    318321        return res;
     
    326329static int ns8250_dev_initialize(ns8250_t *ns)
    327330{
    328         printf(NAME ": ns8250_dev_initialize %s\n", ns->dev->name);
     331        ddf_msg(LVL_DEBUG, "ns8250_dev_initialize %s", ns->dev->name);
    329332       
    330333        int ret = EOK;
     
    337340            IPC_FLAG_BLOCKING);
    338341        if (ns->dev->parent_phone < 0) {
    339                 printf(NAME ": failed to connect to the parent driver of the "
    340                     "device %s.\n", ns->dev->name);
     342                ddf_msg(LVL_ERROR, "Failed to connect to parent driver of "
     343                    "device %s.", ns->dev->name);
    341344                ret = ns->dev->parent_phone;
    342345                goto failed;
     
    346349        ret = hw_res_get_resource_list(ns->dev->parent_phone, &hw_resources);
    347350        if (ret != EOK) {
    348                 printf(NAME ": failed to get hw resources for the device "
    349                     "%s.\n", ns->dev->name);
     351                ddf_msg(LVL_ERROR, "Failed to get HW resources for device "
     352                    "%s.", ns->dev->name);
    350353                goto failed;
    351354        }
     
    362365                        ns->irq = res->res.interrupt.irq;
    363366                        irq = true;
    364                         printf(NAME ": the %s device was asigned irq = 0x%x.\n",
     367                        ddf_msg(LVL_NOTE, "Device %s was asigned irq = 0x%x.",
    365368                            ns->dev->name, ns->irq);
    366369                        break;
     
    369372                        ns->io_addr = res->res.io_range.address;
    370373                        if (res->res.io_range.size < REG_COUNT) {
    371                                 printf(NAME ": i/o range assigned to the device "
    372                                     "%s is too small.\n", ns->dev->name);
     374                                ddf_msg(LVL_ERROR, "I/O range assigned to "
     375                                    "device %s is too small.", ns->dev->name);
    373376                                ret = ELIMIT;
    374377                                goto failed;
    375378                        }
    376379                        ioport = true;
    377                         printf(NAME ": the %s device was asigned i/o address = "
    378                             "0x%x.\n", ns->dev->name, ns->io_addr);
    379                         break;
     380                        ddf_msg(LVL_NOTE, "Device %s was asigned I/O address = "
     381                            "0x%x.", ns->dev->name, ns->io_addr);
     382                        break;
    380383                       
    381384                default:
     
    385388       
    386389        if (!irq || !ioport) {
    387                 printf(NAME ": missing hw resource(s) for the device %s.\n",
     390                ddf_msg(LVL_ERROR, "Missing HW resource(s) for device %s.",
    388391                    ns->dev->name);
    389392                ret = ENOENT;
     
    470473       
    471474        if (baud_rate < 50 || MAX_BAUD_RATE % baud_rate != 0) {
    472                 printf(NAME ": error - somebody tried to set invalid baud rate "
    473                     "%d\n", baud_rate);
     475                ddf_msg(LVL_ERROR, "Invalid baud rate %d requested.",
     476                    baud_rate);
    474477                return EINVAL;
    475478        }
     
    654657                        if (ns->client_connected) {
    655658                                if (!buf_push_back(&ns->input_buffer, val)) {
    656                                         printf(NAME ": buffer overflow on "
    657                                             "%s.\n", ns->dev->name);
     659                                        ddf_msg(LVL_WARN, "Buffer overflow on "
     660                                            "%s.", ns->dev->name);
    658661                                } else {
    659                                         printf(NAME ": the character %c saved "
    660                                             "to the buffer of %s.\n",
     662                                        ddf_msg(LVL_DEBUG2, "Character %c saved "
     663                                            "to the buffer of %s.",
    661664                                            val, ns->dev->name);
    662665                                }
     
    714717        int rc;
    715718       
    716         printf(NAME ": ns8250_add_device %s (handle = %d)\n",
     719        ddf_msg(LVL_DEBUG, "ns8250_add_device %s (handle = %d)",
    717720            dev->name, (int) dev->handle);
    718721       
     
    749752        /* Register interrupt handler. */
    750753        if (ns8250_register_interrupt_handler(ns) != EOK) {
    751                 printf(NAME ": failed to register interrupt handler.\n");
     754                ddf_msg(LVL_ERROR, "Failed to register interrupt handler.");
    752755                rc = EADDRNOTAVAIL;
    753756                goto fail;
     
    757760        rc = ns8250_interrupt_enable(ns);
    758761        if (rc != EOK) {
    759                 printf(NAME ": failed to enable the interrupt. Error code = "
    760                     "%d.\n", rc);
     762                ddf_msg(LVL_ERROR, "Failed to enable the interrupt. Error code = "
     763                    "%d.", rc);
    761764                goto fail;
    762765        }
     
    764767        fun = ddf_fun_create(dev, fun_exposed, "a");
    765768        if (fun == NULL) {
    766                 printf(NAME ": error creating function.\n");
     769                ddf_msg(LVL_ERROR, "Failed creating function.");
    767770                goto fail;
    768771        }
     
    772775        rc = ddf_fun_bind(fun);
    773776        if (rc != EOK) {
    774                 printf(NAME ": error binding function.\n");
     777                ddf_msg(LVL_ERROR, "Failed binding function.");
    775778                goto fail;
    776779        }
     
    780783        ddf_fun_add_to_class(fun, "serial");
    781784       
    782         printf(NAME ": the %s device has been successfully initialized.\n",
     785        ddf_msg(LVL_NOTE, "Device %s successfully initialized.",
    783786            dev->name);
    784787       
     
    862865        fibril_mutex_unlock(&data->mutex);
    863866       
    864         printf(NAME ": ns8250_get_props: baud rate %d, parity 0x%x, word "
    865             "length %d, stop bits %d\n", *baud_rate, *parity, *word_length,
     867        ddf_msg(LVL_DEBUG, "ns8250_get_props: baud rate %d, parity 0x%x, word "
     868            "length %d, stop bits %d", *baud_rate, *parity, *word_length,
    866869            *stop_bits);
    867870}
     
    879882    unsigned int parity, unsigned int word_length, unsigned int stop_bits)
    880883{
    881         printf(NAME ": ns8250_set_props: baud rate %d, parity 0x%x, word "
    882             "length %d, stop bits %d\n", baud_rate, parity, word_length,
     884        ddf_msg(LVL_DEBUG, "ns8250_set_props: baud rate %d, parity 0x%x, word "
     885            "length %d, stop bits %d", baud_rate, parity, word_length,
    883886            stop_bits);
    884887       
     
    940943static void ns8250_init(void)
    941944{
     945        ddf_log_init(NAME, LVL_ERROR);
     946       
    942947        ns8250_dev_ops.open = &ns8250_open;
    943948        ns8250_dev_ops.close = &ns8250_close;
  • uspace/drv/ohci/batch.c

    r61257f4 rf8e8738  
    7373        CHECK_NULL_DISPOSE_RETURN(instance,
    7474            "Failed to allocate batch instance.\n");
    75         usb_transfer_batch_init(instance, target, transfer_type, speed, max_packet_size,
    76             buffer, NULL, buffer_size, NULL, setup_size, func_in,
    77             func_out, arg, fun, NULL);
     75        usb_transfer_batch_init(instance, target, transfer_type, speed,
     76            max_packet_size, buffer, NULL, buffer_size, NULL, setup_size,
     77            func_in, func_out, arg, fun, NULL, NULL);
    7878
    7979        if (buffer_size > 0) {
  • uspace/drv/ohci/hc.c

    r61257f4 rf8e8738  
    4545
    4646static int interrupt_emulator(hc_t *instance);
     47static void hc_gain_control(hc_t *instance);
     48static void hc_init_hw(hc_t *instance);
    4749/*----------------------------------------------------------------------------*/
    4850int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun)
     
    5860
    5961        char *match_str = NULL;
    60         int ret = asprintf(&match_str, "usb&mid");
     62        int ret = asprintf(&match_str, "usb&class=hub");
    6163        ret = (match_str == NULL) ? ret : EOK;
    6264        if (ret < 0) {
     
    7779        assert(instance);
    7880        int ret = EOK;
     81#define CHECK_RET_RETURN(ret, message...) \
     82if (ret != EOK) { \
     83        usb_log_error(message); \
     84        return ret; \
     85} else (void)0
    7986
    8087        ret = pio_enable((void*)regs, reg_size, (void**)&instance->registers);
    81         if (ret != EOK) {
    82                 usb_log_error("Failed to gain access to device registers.\n");
    83                 return ret;
    84         }
     88        CHECK_RET_RETURN(ret,
     89            "Failed(%d) to gain access to device registers: %s.\n",
     90            ret, str_error(ret));
     91
    8592        instance->ddf_instance = fun;
    8693        usb_device_keeper_init(&instance->manager);
     94        ret = usb_endpoint_manager_init(&instance->ep_manager,
     95            BANDWIDTH_AVAILABLE_USB11);
     96        CHECK_RET_RETURN(ret, "Failed to initialize endpoint manager: %s.\n",
     97            ret, str_error(ret));
    8798
    8899        if (!interrupts) {
     
    92103        }
    93104
     105        hc_gain_control(instance);
     106
    94107        rh_init(&instance->rh, dev, instance->registers);
     108
     109        hc_init_hw(instance);
    95110
    96111        /* TODO: implement */
     
    117132                rh_interrupt(&instance->rh);
    118133
     134        usb_log_info("OHCI interrupt: %x.\n", status);
     135
    119136        /* TODO: Check for further interrupt causes */
    120137        /* TODO: implement */
     
    126143        usb_log_info("Started interrupt emulator.\n");
    127144        while (1) {
    128                 uint32_t status = instance->registers->interrupt_status;
     145                const uint32_t status = instance->registers->interrupt_status;
    129146                instance->registers->interrupt_status = status;
    130147                hc_interrupt(instance, status);
     
    133150        return EOK;
    134151}
     152/*----------------------------------------------------------------------------*/
     153void hc_gain_control(hc_t *instance)
     154{
     155        assert(instance);
     156        /* Interrupt routing enabled => smm driver is active */
     157        if (instance->registers->control & C_IR) {
     158                usb_log_info("Found SMM driver requesting ownership change.\n");
     159                instance->registers->command_status |= CS_OCR;
     160                while (instance->registers->control & C_IR) {
     161                        async_usleep(1000);
     162                }
     163                usb_log_info("Ownership taken from SMM driver.\n");
     164                return;
     165        }
     166
     167        const unsigned hc_status =
     168            (instance->registers->control >> C_HCFS_SHIFT) & C_HCFS_MASK;
     169        /* Interrupt routing disabled && status != USB_RESET => BIOS active */
     170        if (hc_status != C_HCFS_RESET) {
     171                usb_log_info("Found BIOS driver.\n");
     172                if (hc_status == C_HCFS_OPERATIONAL) {
     173                        usb_log_info("HC operational(BIOS).\n");
     174                        return;
     175                }
     176                /* HC is suspended assert resume for 20ms */
     177                instance->registers->control &= (C_HCFS_RESUME << C_HCFS_SHIFT);
     178                async_usleep(20000);
     179                return;
     180        }
     181
     182        /* HC is in reset (hw startup) => no other driver
     183         * maintain reset for at least the time specified in USB spec (50 ms)*/
     184        async_usleep(50000);
     185
     186        /* turn off legacy emulation */
     187        volatile uint32_t *ohci_emulation_reg =
     188            (uint32_t*)((char*)instance->registers + 0x100);
     189        usb_log_info("OHCI legacy register status %p: %x.\n",
     190                ohci_emulation_reg, *ohci_emulation_reg);
     191        *ohci_emulation_reg = 0;
     192
     193}
     194/*----------------------------------------------------------------------------*/
     195void hc_init_hw(hc_t *instance)
     196{
     197        assert(instance);
     198        const uint32_t fm_interval = instance->registers->fm_interval;
     199        instance->registers->command_status = CS_HCR;
     200        async_usleep(10);
     201        instance->registers->fm_interval = fm_interval;
     202        assert((instance->registers->command_status & CS_HCR) == 0);
     203        /* hc is now in suspend state */
     204        /* TODO: init HCCA block */
     205        /* TODO: init queues */
     206        /* TODO: enable queues */
     207        /* TODO: enable interrupts */
     208        /* TODO: set periodic start to 90% */
     209
     210        instance->registers->control &= (C_HCFS_OPERATIONAL << C_HCFS_SHIFT);
     211        usb_log_info("OHCI HC up and running.\n");
     212}
    135213/**
    136214 * @}
  • uspace/drv/ohci/hc.h

    r61257f4 rf8e8738  
    4242#include <usb/usb.h>
    4343#include <usb/host/device_keeper.h>
     44#include <usb/host/usb_endpoint_manager.h>
    4445#include <usbhc_iface.h>
    4546
     
    4748#include "ohci_regs.h"
    4849#include "root_hub.h"
     50#include "hw_struct/hcca.h"
    4951
    5052typedef struct hc {
     
    5456        ddf_fun_t *ddf_instance;
    5557        usb_device_keeper_t manager;
     58        usb_endpoint_manager_t ep_manager;
    5659        fid_t interrupt_emulator;
    5760} hc_t;
  • uspace/drv/ohci/hw_struct/completion_codes.h

    r61257f4 rf8e8738  
    11/*
    2  * Copyright (c) 2005 Sergey Bondari
     2 * Copyright (c) 2011 Jan Vesely
    33 * All rights reserved.
    44 *
     
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 
    29 /** @addtogroup arm32
     28/** @addtogroup drvusbohci
    3029 * @{
    3130 */
    3231/** @file
    33  *  @brief Memory manipulating functions declarations.
     32 * @brief OHCI driver
    3433 */
     34#ifndef DRV_OHCI_HW_STRUCT_COMPLETION_CODES_H
     35#define DRV_OHCI_HW_STRUCT_COMPLETION_CODES_H
    3536
    36 #ifndef KERN_arm32_MEMSTR_H_
    37 #define KERN_arm32_MEMSTR_H_
    38 
    39 #define memcpy(dst, src, cnt)  __builtin_memcpy((dst), (src), (cnt))
    40 
    41 extern void memsetw(void *, size_t, uint16_t);
    42 extern void memsetb(void *, size_t, uint8_t);
     37#define CC_NOERROR (0x0)
     38#define CC_CRC (0x1)
     39#define CC_BITSTUFF (0x2)
     40#define CC_TOGGLE (0x3)
     41#define CC_STALL (0x4)
     42#define CC_NORESPONSE (0x5)
     43#define CC_PIDFAIL (0x6)
     44#define CC_PIDUNEXPECTED (0x7)
     45#define CC_DATAOVERRRUN (0x8)
     46#define CC_DATAUNDERRRUN (0x9)
     47#define CC_BUFFEROVERRRUN (0xc)
     48#define CC_BUFFERUNDERRUN (0xd)
     49#define CC_NOACCESS1 (0xe)
     50#define CC_NOACCESS2 (0xf)
    4351
    4452#endif
    45 
    46 /** @}
     53/**
     54 * @}
    4755 */
  • uspace/drv/ohci/hw_struct/hcca.h

    r61257f4 rf8e8738  
    11/*
    2  * Copyright (c) 2010 Martin Decky
     2 * Copyright (c) 2011 Jan Vesely
    33 * All rights reserved.
    44 *
     
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 
    29 /** @addtogroup abs32le
     28/** @addtogroup drvusbohci
    3029 * @{
    3130 */
    3231/** @file
     32 * @brief OHCI driver
     33 */
     34#ifndef DRV_OHCI_HW_STRUCT_HCCA_H
     35#define DRV_OHCI_HW_STRUCT_HCCA_H
     36
     37#include <stdint.h>
     38
     39typedef struct hcca {
     40        uint32_t int_ep[32];
     41        uint16_t frame_number;
     42        uint16_t pad1;
     43        uint32_t done_head;
     44        uint32_t reserved[29];
     45} __attribute__((packed)) hcca_t;
     46
     47#endif
     48/**
     49 * @}
    3350 */
    3451
    35 #ifndef KERN_abs32le_MEMSTR_H_
    36 #define KERN_abs32le_MEMSTR_H_
    37 
    38 #define memcpy(dst, src, cnt)   _memcpy((dst), (src), (cnt))
    39 #define memsetb(dst, cnt, val)  _memsetb((dst), (cnt), (val))
    40 #define memsetw(dst, cnt, val)  _memsetw((dst), (cnt), (val))
    41 
    42 #endif
    43 
    44 /** @}
    45  */
  • uspace/drv/ohci/iface.c

    r61257f4 rf8e8738  
    151151    size_t max_packet_size, unsigned int interval)
    152152{
    153         UNSUPPORTED("register_endpoint");
    154 
    155         return ENOTSUP;
     153        assert(fun);
     154        hc_t *hc = fun_to_hc(fun);
     155        assert(hc);
     156        if (address == hc->rh.address)
     157                return EOK;
     158        const usb_speed_t speed =
     159                usb_device_keeper_get_speed(&hc->manager, address);
     160        const size_t size = max_packet_size;
     161        usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n",
     162            address, endpoint, usb_str_transfer_type(transfer_type),
     163            usb_str_speed(speed), direction, size, max_packet_size, interval);
     164        // TODO use real endpoint here!
     165        return usb_endpoint_manager_register_ep(&hc->ep_manager,NULL, 0);
    156166}
    157167/*----------------------------------------------------------------------------*/
     
    168178    usb_endpoint_t endpoint, usb_direction_t direction)
    169179{
    170         UNSUPPORTED("unregister_endpoint");
    171 
    172         return ENOTSUP;
     180        assert(fun);
     181        hc_t *hc = fun_to_hc(fun);
     182        assert(hc);
     183        usb_log_debug("Unregister endpoint %d:%d %d.\n",
     184            address, endpoint, direction);
     185        return usb_endpoint_manager_unregister_ep(&hc->ep_manager, address,
     186            endpoint, direction);
    173187}
    174188/*----------------------------------------------------------------------------*/
  • uspace/drv/ohci/ohci.c

    r61257f4 rf8e8738  
    3131 */
    3232/** @file
    33  * @brief UHCI driver
     33 * @brief OHCI driver
    3434 */
    3535#include <errno.h>
     
    117117/** Initialize hc and rh ddf structures and their respective drivers.
    118118 *
    119  * @param[in] instance UHCI structure to use.
     119 * @param[in] instance OHCI structure to use.
    120120 * @param[in] device DDF instance of the device to use.
    121121 *
    122122 * This function does all the preparatory work for hc and rh drivers:
    123123 *  - gets device hw resources
    124  *  - disables UHCI legacy support
     124 *  - disables OHCI legacy support
    125125 *  - asks for interrupt
    126126 *  - registers interrupt handler
     
    185185        ret = ddf_fun_bind(instance->hc_fun);
    186186        CHECK_RET_DEST_FUN_RETURN(ret,
    187             "Failed(%d) to bind UHCI device function: %s.\n",
     187            "Failed(%d) to bind OHCI device function: %s.\n",
    188188            ret, str_error(ret));
    189189#undef CHECK_RET_HC_RETURN
     
    216216        ret = ddf_fun_bind(instance->rh_fun);
    217217        CHECK_RET_FINI_RETURN(ret,
    218             "Failed(%d) to register UHCI root hub.\n", ret);
     218            "Failed(%d) to register OHCI root hub.\n", ret);
    219219
    220220        return EOK;
  • uspace/drv/ohci/ohci_regs.h

    r61257f4 rf8e8738  
    3939typedef struct ohci_regs
    4040{
    41         volatile uint32_t revision;
     41        const volatile uint32_t revision;
    4242        volatile uint32_t control;
     43#define C_CSBR_MASK (0x3)
     44#define C_CSBR_SHIFT (0)
     45#define C_PLE (1 << 2)
     46#define C_IE (1 << 3)
     47#define C_CLE (1 << 4)
     48#define C_BLE (1 << 5)
     49
     50#define C_HCFS_MASK (0x3)
     51#define C_HCFS_SHIFT (6)
     52#define C_HCFS_RESET (0x0)
     53#define C_HCFS_OPERATIONAL (0x1)
     54#define C_HCFS_RESUME (0x2)
     55#define C_HCFS_SUSPEND (0x3)
     56
     57#define C_IR (1 << 8)
     58#define C_RWC (1 << 9)
     59#define C_RWE (1 << 10)
     60
    4361        volatile uint32_t command_status;
     62#define CS_HCR (1 << 0)
     63#define CS_CLF (1 << 1)
     64#define CS_BLF (1 << 2)
     65#define CS_OCR (1 << 3)
     66#define CS_SOC_MASK (0x3)
     67#define CS_SOC_SHIFT (16)
     68
    4469        volatile uint32_t interrupt_status;
    4570#define IS_SO (1 << 0)
     
    5176#define IS_RHSC (1 << 6)
    5277#define IS_OC (1 << 30)
     78
    5379        volatile uint32_t interupt_enable;
    5480#define IE_SO   (1 << 0)
  • uspace/drv/ohci/root_hub.c

    r61257f4 rf8e8738  
    4040#include "root_hub.h"
    4141#include "usb/classes/classes.h"
     42#include "usb/devdrv.h"
    4243#include <usb/request.h>
    4344#include <usb/classes/hub.h>
     
    6162                /// \TODO these values migt be different
    6263                .str_serial_number = 0,
    63                 .usb_spec_version = 0,
     64                .usb_spec_version = 0x110,
    6465};
    6566
     
    110111};
    111112
    112 /** Root hub initialization
    113  * @return Error code.
    114  */
    115 int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs)
    116 {
    117         assert(instance);
    118         instance->address = -1;
    119         instance->registers = regs;
    120         instance->device = dev;
    121 
    122 
    123         usb_log_info("OHCI root hub with %d ports.\n", regs->rh_desc_a & 0xff);
    124 
    125         //start generic usb hub driver
     113static const uint32_t hub_clear_feature_valid_mask =
     114        (1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER) +
     115        (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
     116
     117static const uint32_t hub_clear_feature_by_writing_one_mask =
     118        1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER;
     119
     120static const uint32_t hub_set_feature_valid_mask =
     121        (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
     122
    126123       
    127         /* TODO: implement */
    128         return EOK;
    129 }
    130 /*----------------------------------------------------------------------------*/
    131 
    132 /**
    133  * create answer to port status_request
    134  *
    135  * Copy content of corresponding port status register to answer buffer.
    136  *
    137  * @param instance root hub instance
    138  * @param port port number, counted from 1
    139  * @param request structure containing both request and response information
    140  * @return error code
    141  */
    142 static int process_get_port_status_request(rh_t *instance, uint16_t port,
    143                 usb_transfer_batch_t * request){
    144         if(port<1 || port>instance->port_count)
    145                 return EINVAL;
    146         uint32_t * uint32_buffer = (uint32_t*)request->buffer;
    147         request->transfered_size = 4;
    148         uint32_buffer[0] = instance->registers->rh_port_status[port -1];
    149         return EOK;
    150 }
    151 
    152 /**
    153  * create answer to port status_request
    154  *
    155  * Copy content of hub status register to answer buffer.
    156  *
    157  * @param instance root hub instance
    158  * @param request structure containing both request and response information
    159  * @return error code
    160  */
    161 static int process_get_hub_status_request(rh_t *instance,
    162                 usb_transfer_batch_t * request){
    163         uint32_t * uint32_buffer = (uint32_t*)request->buffer;
    164         //bits, 0,1,16,17
    165         request->transfered_size = 4;
    166         uint32_t mask = 1 & (1<<1) & (1<<16) & (1<<17);
    167         uint32_buffer[0] = mask & instance->registers->rh_status;
    168         return EOK;
    169 
    170 }
     124static const uint32_t hub_set_feature_direct_mask =
     125        (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
     126
     127static const uint32_t port_set_feature_valid_mask =
     128        (1 << USB_HUB_FEATURE_PORT_ENABLE) +
     129        (1 << USB_HUB_FEATURE_PORT_SUSPEND) +
     130        (1 << USB_HUB_FEATURE_PORT_RESET) +
     131        (1 << USB_HUB_FEATURE_PORT_POWER);
     132
     133static const uint32_t port_clear_feature_valid_mask =
     134        (1 << USB_HUB_FEATURE_PORT_CONNECTION) +
     135        (1 << USB_HUB_FEATURE_PORT_SUSPEND) +
     136        (1 << USB_HUB_FEATURE_PORT_OVER_CURRENT) +
     137        (1 << USB_HUB_FEATURE_PORT_POWER) +
     138        (1 << USB_HUB_FEATURE_C_PORT_CONNECTION) +
     139        (1 << USB_HUB_FEATURE_C_PORT_ENABLE) +
     140        (1 << USB_HUB_FEATURE_C_PORT_SUSPEND) +
     141        (1 << USB_HUB_FEATURE_C_PORT_OVER_CURRENT) +
     142        (1 << USB_HUB_FEATURE_C_PORT_RESET);
     143//note that USB_HUB_FEATURE_PORT_POWER bit is translated into USB_HUB_FEATURE_PORT_LOW_SPEED
     144
     145
     146
    171147
    172148/**
    173149 * Create hub descriptor used in hub-driver <-> hub communication
    174  * 
     150 *
    175151 * This means creating byt array from data in root hub registers. For more
    176152 * info see usb hub specification.
     
    197173        result[2] = instance->port_count;
    198174        uint32_t hub_desc_reg = instance->registers->rh_desc_a;
    199         result[3] = 
     175        result[3] =
    200176                        ((hub_desc_reg >> 8) %2) +
    201177                        (((hub_desc_reg >> 9) %2) << 1) +
     
    219195        (*out_size) = size;
    220196}
     197
     198
     199/** initialize hub descriptors
     200 *
     201 * Initialized are device and full configuration descriptor. These need to
     202 * be initialized only once per hub.
     203 * @instance root hub instance
     204 */
     205static void rh_init_descriptors(rh_t *instance){
     206        memcpy(&instance->descriptors.device, &ohci_rh_device_descriptor,
     207                sizeof(ohci_rh_device_descriptor)
     208        );
     209        usb_standard_configuration_descriptor_t descriptor;
     210        memcpy(&descriptor,&ohci_rh_conf_descriptor,
     211                        sizeof(ohci_rh_conf_descriptor));
     212        uint8_t * hub_descriptor;
     213        size_t hub_desc_size;
     214        usb_create_serialized_hub_descriptor(instance, &hub_descriptor,
     215                        &hub_desc_size);
     216
     217        descriptor.total_length =
     218                        sizeof(usb_standard_configuration_descriptor_t)+
     219                        sizeof(usb_standard_endpoint_descriptor_t)+
     220                        sizeof(usb_standard_interface_descriptor_t)+
     221                        hub_desc_size;
     222       
     223        uint8_t * full_config_descriptor =
     224                        (uint8_t*) malloc(descriptor.total_length);
     225        memcpy(full_config_descriptor, &descriptor, sizeof(descriptor));
     226        memcpy(full_config_descriptor + sizeof(descriptor),
     227                        &ohci_rh_iface_descriptor, sizeof(ohci_rh_iface_descriptor));
     228        memcpy(full_config_descriptor + sizeof(descriptor) +
     229                                sizeof(ohci_rh_iface_descriptor),
     230                        &ohci_rh_ep_descriptor, sizeof(ohci_rh_ep_descriptor));
     231        memcpy(full_config_descriptor + sizeof(descriptor) +
     232                                sizeof(ohci_rh_iface_descriptor) +
     233                                sizeof(ohci_rh_ep_descriptor),
     234                        hub_descriptor, hub_desc_size);
     235       
     236        instance->descriptors.configuration = full_config_descriptor;
     237        instance->descriptors.configuration_size = descriptor.total_length;
     238}
     239
     240/** Root hub initialization
     241 * @return Error code.
     242 */
     243int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs)
     244{
     245        assert(instance);
     246        instance->address = -1;
     247        instance->registers = regs;
     248        instance->device = dev;
     249        instance->port_count = instance->registers->rh_desc_a & 0xff;
     250        rh_init_descriptors(instance);
     251        /// \TODO set port power mode
     252
     253
     254        usb_log_info("OHCI root hub with %d ports.\n", instance->port_count);
     255
     256        //start generic usb hub driver
     257       
     258        /* TODO: implement */
     259        return EOK;
     260}
     261/*----------------------------------------------------------------------------*/
     262
     263/**
     264 * create answer to port status_request
     265 *
     266 * Copy content of corresponding port status register to answer buffer.
     267 *
     268 * @param instance root hub instance
     269 * @param port port number, counted from 1
     270 * @param request structure containing both request and response information
     271 * @return error code
     272 */
     273static int process_get_port_status_request(rh_t *instance, uint16_t port,
     274                usb_transfer_batch_t * request){
     275        if(port<1 || port>instance->port_count)
     276                return EINVAL;
     277        uint32_t * uint32_buffer = (uint32_t*)request->transport_buffer;
     278        request->transfered_size = 4;
     279        uint32_buffer[0] = instance->registers->rh_port_status[port -1];
     280        return EOK;
     281}
     282
     283/**
     284 * create answer to port status_request
     285 *
     286 * Copy content of hub status register to answer buffer.
     287 *
     288 * @param instance root hub instance
     289 * @param request structure containing both request and response information
     290 * @return error code
     291 */
     292static int process_get_hub_status_request(rh_t *instance,
     293                usb_transfer_batch_t * request){
     294        uint32_t * uint32_buffer = (uint32_t*)request->transport_buffer;
     295        //bits, 0,1,16,17
     296        request->transfered_size = 4;
     297        uint32_t mask = 1 & (1<<1) & (1<<16) & (1<<17);
     298        uint32_buffer[0] = mask & instance->registers->rh_status;
     299        return EOK;
     300
     301}
     302
    221303
    222304
     
    284366        }
    285367}
    286 
    287 /**
    288  * create standart configuration descriptor for the root hub instance
    289  * @param instance root hub instance
    290  * @return newly allocated descriptor
    291  */
    292 static usb_standard_configuration_descriptor_t *
    293 usb_ohci_rh_create_standart_configuration_descriptor(rh_t *instance){
    294         usb_standard_configuration_descriptor_t * descriptor =
    295                         malloc(sizeof(usb_standard_configuration_descriptor_t));
    296         memcpy(descriptor, &ohci_rh_conf_descriptor,
    297                 sizeof(usb_standard_configuration_descriptor_t));
    298         /// \TODO should this include device descriptor?
    299         const size_t hub_descriptor_size = 7 +
    300                         2* (instance->port_count / 8 +
    301                         ((instance->port_count % 8 > 0) ? 1 : 0));
    302         descriptor->total_length =
    303                         sizeof(usb_standard_configuration_descriptor_t)+
    304                         sizeof(usb_standard_endpoint_descriptor_t)+
    305                         sizeof(usb_standard_interface_descriptor_t)+
    306                         hub_descriptor_size;
    307         return descriptor;
    308 }
    309 
     368 
    310369/**
    311370 * create answer to a descriptor request
     
    344403                case USB_DESCTYPE_CONFIGURATION: {
    345404                        usb_log_debug("USB_DESCTYPE_CONFIGURATION\n");
    346                         usb_standard_configuration_descriptor_t * descriptor =
    347                                         usb_ohci_rh_create_standart_configuration_descriptor(
    348                                                 instance);
    349                         result_descriptor = descriptor;
    350                         size = sizeof(usb_standard_configuration_descriptor_t);
    351                         del = true;
     405                        result_descriptor = instance->descriptors.configuration;
     406                        size = instance->descriptors.configuration_size;
    352407                        break;
    353408                }
     
    380435        }
    381436        request->transfered_size = size;
    382         memcpy(request->buffer,result_descriptor,size);
     437        memcpy(request->transport_buffer,result_descriptor,size);
     438        usb_log_debug("sent desctiptor: %s\n",
     439                        usb_debug_str_buffer((uint8_t*)request->transport_buffer,size,size));
    383440        if (del)
    384441                free(result_descriptor);
     
    400457        if(request->buffer_size != 1)
    401458                return EINVAL;
    402         request->buffer[0] = 1;
     459        request->transport_buffer[0] = 1;
    403460        request->transfered_size = 1;
    404461        return EOK;
     
    406463
    407464/**
    408  * process feature-enabling/disabling request on hub
     465 * process feature-enabling request on hub
    409466 *
    410467 * @param instance root hub instance
    411468 * @param feature feature selector
    412  * @param enable enable or disable specified feature
    413469 * @return error code
    414470 */
    415471static int process_hub_feature_set_request(rh_t *instance,
    416                 uint16_t feature, bool enable){
    417         if(feature > USB_HUB_FEATURE_C_HUB_OVER_CURRENT)
     472                uint16_t feature){
     473        if(! ((1<<feature) & hub_set_feature_valid_mask))
    418474                return EINVAL;
    419475        instance->registers->rh_status =
    420                         enable ?
    421476                        (instance->registers->rh_status | (1<<feature))
    422                         :
    423                         (instance->registers->rh_status & (~(1<<feature)));
    424         /// \TODO any error?
    425         return EOK;
    426 }
    427 
    428 /**
    429  * process feature-enabling/disabling request on hub
     477                        & (~ hub_clear_feature_by_writing_one_mask);
     478        return EOK;
     479}
     480
     481/**
     482 * process feature-disabling request on hub
     483 *
     484 * @param instance root hub instance
     485 * @param feature feature selector
     486 * @return error code
     487 */
     488static int process_hub_feature_clear_request(rh_t *instance,
     489                uint16_t feature){
     490        if(! ((1<<feature) & hub_clear_feature_valid_mask))
     491                return EINVAL;
     492        //is the feature cleared directly?
     493        if ((1<<feature) & hub_set_feature_direct_mask){
     494                instance->registers->rh_status =
     495                        (instance->registers->rh_status & (~(1<<feature)))
     496                        & (~ hub_clear_feature_by_writing_one_mask);
     497        }else{//the feature is cleared by writing '1'
     498                instance->registers->rh_status =
     499                                (instance->registers->rh_status
     500                                & (~ hub_clear_feature_by_writing_one_mask))
     501                                | (1<<feature);
     502        }
     503        return EOK;
     504}
     505
     506
     507
     508/**
     509 * process feature-enabling request on hub
    430510 *
    431511 * @param instance root hub instance
     
    436516 */
    437517static int process_port_feature_set_request(rh_t *instance,
    438                 uint16_t feature, uint16_t port, bool enable){
    439         if(feature > USB_HUB_FEATURE_C_PORT_RESET)
     518                uint16_t feature, uint16_t port){
     519        if(!((1<<feature) & port_set_feature_valid_mask))
    440520                return EINVAL;
    441521        if(port<1 || port>instance->port_count)
    442522                return EINVAL;
    443523        instance->registers->rh_port_status[port - 1] =
    444                         enable ?
    445524                        (instance->registers->rh_port_status[port - 1] | (1<<feature))
    446                         :
    447                         (instance->registers->rh_port_status[port - 1] & (~(1<<feature)));
     525                        & (~port_clear_feature_valid_mask);
    448526        /// \TODO any error?
    449527        return EOK;
    450528}
     529
     530/**
     531 * process feature-disabling request on hub
     532 *
     533 * @param instance root hub instance
     534 * @param feature feature selector
     535 * @param port port number, counted from 1
     536 * @param enable enable or disable the specified feature
     537 * @return error code
     538 */
     539static int process_port_feature_clear_request(rh_t *instance,
     540                uint16_t feature, uint16_t port){
     541        if(!((1<<feature) & port_clear_feature_valid_mask))
     542                return EINVAL;
     543        if(port<1 || port>instance->port_count)
     544                return EINVAL;
     545        if(feature == USB_HUB_FEATURE_PORT_POWER)
     546                feature = USB_HUB_FEATURE_PORT_LOW_SPEED;
     547        if(feature == USB_HUB_FEATURE_PORT_SUSPEND)
     548                feature = USB_HUB_FEATURE_PORT_OVER_CURRENT;
     549        instance->registers->rh_port_status[port - 1] =
     550                        (instance->registers->rh_port_status[port - 1]
     551                        & (~port_clear_feature_valid_mask))
     552                        | (1<<feature);
     553        /// \TODO any error?
     554        return EOK;
     555}
     556
    451557
    452558/**
     
    530636                        (usb_device_request_setup_packet_t*)request->setup_buffer;
    531637        request->transfered_size = 0;
    532         if(setup_request->request == USB_DEVREQ_CLEAR_FEATURE
    533                                 || setup_request->request == USB_DEVREQ_SET_FEATURE){
     638        if(setup_request->request == USB_DEVREQ_CLEAR_FEATURE){
    534639                if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE){
    535640                        usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n");
    536                         return process_hub_feature_set_request(instance, setup_request->value,
    537                                         setup_request->request == USB_DEVREQ_SET_FEATURE);
     641                        return process_hub_feature_clear_request(instance,
     642                                        setup_request->value);
    538643                }
    539644                if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE){
    540645                        usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
    541                         return process_port_feature_set_request(instance, setup_request->value,
    542                                         setup_request->index,
    543                                         setup_request->request == USB_DEVREQ_SET_FEATURE);
     646                        return process_port_feature_clear_request(instance,
     647                                        setup_request->value,
     648                                        setup_request->index);
     649                }
     650                usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",
     651                                setup_request->request_type);
     652                return EINVAL;
     653        }
     654        if(setup_request->request == USB_DEVREQ_SET_FEATURE){
     655                if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE){
     656                        usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n");
     657                        return process_hub_feature_set_request(instance,
     658                                        setup_request->value);
     659                }
     660                if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE){
     661                        usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
     662                        return process_port_feature_set_request(instance,
     663                                        setup_request->value,
     664                                        setup_request->index);
    544665                }
    545666                usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",setup_request->request_type);
  • uspace/drv/ohci/root_hub.h

    r61257f4 rf8e8738  
    3737
    3838#include <usb/usb.h>
     39#include <usb/devdrv.h>
    3940
    4041#include "ohci_regs.h"
     
    5354        /** hub port count */
    5455        int port_count;
     56        /** hubs descriptors */
     57        usb_device_descriptors_t descriptors;
    5558} rh_t;
    5659
  • uspace/drv/pciintel/pci.c

    r61257f4 rf8e8738  
    4848
    4949#include <ddf/driver.h>
     50#include <ddf/log.h>
    5051#include <devman.h>
    5152#include <ipc/devman.h>
     
    106107        }
    107108
    108         size_t i;
    109         for (i = 0; i < dev_data->hw_resources.count; i++) {
    110                 if (dev_data->hw_resources.resources[i].type == INTERRUPT) {
    111                         int irq = dev_data->hw_resources.resources[i].res.interrupt.irq;
    112                         int rc = async_req_1_0(irc_phone, IRC_ENABLE_INTERRUPT, irq);
     109        size_t i = 0;
     110        hw_resource_list_t *res = &dev_data->hw_resources;
     111        for (; i < res->count; i++) {
     112                if (res->resources[i].type == INTERRUPT) {
     113                        const int irq = res->resources[i].res.interrupt.irq;
     114                        const int rc =
     115                            async_req_1_0(irc_phone, IRC_ENABLE_INTERRUPT, irq);
    113116                        if (rc != EOK) {
    114117                                async_hangup(irc_phone);
     
    325328
    326329        if (match_id_str == NULL) {
    327                 printf(NAME ": out of memory creating match ID.\n");
     330                ddf_msg(LVL_ERROR, "Out of memory creating match ID.");
    328331                return;
    329332        }
     
    331334        rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 90);
    332335        if (rc != EOK) {
    333                 printf(NAME ": error adding match ID: %s\n",
     336                ddf_msg(LVL_ERROR, "Failed adding match ID: %s",
    334337                    str_error(rc));
    335338        }
     
    428431       
    429432        if (range_addr != 0) {
    430                 printf(NAME ": function %s : ", fun->fnode->name);
    431                 printf("address = %" PRIx64, range_addr);
    432                 printf(", size = %x\n", (unsigned int) range_size);
     433                ddf_msg(LVL_DEBUG, "Function %s : address = %" PRIx64
     434                    ", size = %x", fun->fnode->name, range_addr,
     435                    (unsigned int) range_size);
    433436        }
    434437       
     
    455458        hw_res_list->count++;
    456459       
    457         printf(NAME ": function %s uses irq %x.\n", fun->fnode->name, irq);
     460        ddf_msg(LVL_NOTE, "Function %s uses irq %x.", fun->fnode->name, irq);
    458461}
    459462
     
    511514                        char *fun_name = pci_fun_create_name(fun);
    512515                        if (fun_name == NULL) {
    513                                 printf(NAME ": out of memory.\n");
     516                                ddf_msg(LVL_ERROR, "Out of memory.");
    514517                                return;
    515518                        }
     
    517520                        fnode = ddf_fun_create(bus->dnode, fun_inner, fun_name);
    518521                        if (fnode == NULL) {
    519                                 printf(NAME ": error creating function.\n");
     522                                ddf_msg(LVL_ERROR, "Failed creating function.");
    520523                                return;
    521524                        }
     
    531534                        fnode->driver_data = fun;
    532535                       
    533                         printf(NAME ": adding new function %s.\n",
     536                        ddf_msg(LVL_DEBUG, "Adding new function %s.",
    534537                            fnode->name);
    535538                       
     
    548551                                child_bus = pci_conf_read_8(fun,
    549552                                    PCI_BRIDGE_SEC_BUS_NUM);
    550                                 printf(NAME ": device is pci-to-pci bridge, "
    551                                     "secondary bus number = %d.\n", bus_num);
     553                                ddf_msg(LVL_DEBUG, "Device is pci-to-pci "
     554                                    "bridge, secondary bus number = %d.",
     555                                    bus_num);
    552556                                if (child_bus > bus_num)
    553557                                        pci_bus_scan(bus, child_bus);
     
    571575        int rc;
    572576       
    573         printf(NAME ": pci_add_device\n");
     577        ddf_msg(LVL_DEBUG, "pci_add_device");
    574578        dnode->parent_phone = -1;
    575579       
    576580        bus = pci_bus_new();
    577581        if (bus == NULL) {
    578                 printf(NAME ": pci_add_device allocation failed.\n");
     582                ddf_msg(LVL_ERROR, "pci_add_device allocation failed.");
    579583                rc = ENOMEM;
    580584                goto fail;
     
    586590            IPC_FLAG_BLOCKING);
    587591        if (dnode->parent_phone < 0) {
    588                 printf(NAME ": pci_add_device failed to connect to the "
    589                     "parent's driver.\n");
     592                ddf_msg(LVL_ERROR, "pci_add_device failed to connect to the "
     593                    "parent's driver.");
    590594                rc = dnode->parent_phone;
    591595                goto fail;
     
    596600        rc = hw_res_get_resource_list(dnode->parent_phone, &hw_resources);
    597601        if (rc != EOK) {
    598                 printf(NAME ": pci_add_device failed to get hw resources for "
    599                     "the device.\n");
     602                ddf_msg(LVL_ERROR, "pci_add_device failed to get hw resources "
     603                    "for the device.");
    600604                goto fail;
    601605        }
    602606        got_res = true;
    603607       
    604         printf(NAME ": conf_addr = %" PRIx64 ".\n",
     608        ddf_msg(LVL_DEBUG, "conf_addr = %" PRIx64 ".",
    605609            hw_resources.resources[0].res.io_range.address);
    606610       
     
    614618        if (pio_enable((void *)(uintptr_t)bus->conf_io_addr, 8,
    615619            &bus->conf_addr_port)) {
    616                 printf(NAME ": failed to enable configuration ports.\n");
     620                ddf_msg(LVL_ERROR, "Failed to enable configuration ports.");
    617621                rc = EADDRNOTAVAIL;
    618622                goto fail;
     
    621625       
    622626        /* Make the bus device more visible. It has no use yet. */
    623         printf(NAME ": adding a 'ctl' function\n");
     627        ddf_msg(LVL_DEBUG, "Adding a 'ctl' function");
    624628       
    625629        ctl = ddf_fun_create(bus->dnode, fun_exposed, "ctl");
    626630        if (ctl == NULL) {
    627                 printf(NAME ": error creating control function.\n");
     631                ddf_msg(LVL_ERROR, "Failed creating control function.");
    628632                rc = ENOMEM;
    629633                goto fail;
     
    632636        rc = ddf_fun_bind(ctl);
    633637        if (rc != EOK) {
    634                 printf(NAME ": error binding control function.\n");
     638                ddf_msg(LVL_ERROR, "Failed binding control function.");
    635639                goto fail;
    636640        }
    637641       
    638642        /* Enumerate functions. */
    639         printf(NAME ": scanning the bus\n");
     643        ddf_msg(LVL_DEBUG, "Scanning the bus");
    640644        pci_bus_scan(bus, 0);
    641645       
     
    659663static void pciintel_init(void)
    660664{
     665        ddf_log_init(NAME, LVL_ERROR);
    661666        pci_fun_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops;
    662667        pci_fun_ops.interfaces[PCI_DEV_IFACE] = &pci_dev_ops;
     
    738743int main(int argc, char *argv[])
    739744{
    740         printf(NAME ": HelenOS pci bus driver (intel method 1).\n");
     745        printf(NAME ": HelenOS PCI bus driver (Intel method 1).\n");
    741746        pciintel_init();
    742747        return ddf_driver_main(&pci_driver);
  • uspace/drv/root/root.c

    r61257f4 rf8e8738  
    5252
    5353#include <ddf/driver.h>
     54#include <ddf/log.h>
    5455#include <devman.h>
    5556#include <ipc/devman.h>
     
    8990        int rc;
    9091
    91         printf(NAME ": adding new function for virtual devices.\n");
    92         printf(NAME ":   function node is `%s' (%d %s)\n", name,
     92        ddf_msg(LVL_DEBUG, "Adding new function for virtual devices. "
     93            "Function node is `%s' (%d %s)", name,
    9394            VIRTUAL_FUN_MATCH_SCORE, VIRTUAL_FUN_MATCH_ID);
    9495
    9596        fun = ddf_fun_create(dev, fun_inner, name);
    9697        if (fun == NULL) {
    97                 printf(NAME ": error creating function %s\n", name);
     98                ddf_msg(LVL_ERROR, "Failed creating function %s", name);
    9899                return ENOMEM;
    99100        }
     
    102103            VIRTUAL_FUN_MATCH_SCORE);
    103104        if (rc != EOK) {
    104                 printf(NAME ": error adding match IDs to function %s\n", name);
     105                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
     106                    name);
    105107                ddf_fun_destroy(fun);
    106108                return rc;
     
    109111        rc = ddf_fun_bind(fun);
    110112        if (rc != EOK) {
    111                 printf(NAME ": error binding function %s: %s\n", name,
     113                ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,
    112114                    str_error(rc));
    113115                ddf_fun_destroy(fun);
     
    136138        platform = sysinfo_get_data("platform", &platform_size);
    137139        if (platform == NULL) {
    138                 printf(NAME ": Failed to obtain platform name.\n");
     140                ddf_msg(LVL_ERROR, "Failed to obtain platform name.");
    139141                return ENOENT;
    140142        }
     
    143145        platform = realloc(platform, platform_size + 1);
    144146        if (platform == NULL) {
    145                 printf(NAME ": Memory allocation failed.\n");
     147                ddf_msg(LVL_ERROR, "Memory allocation failed.");
    146148                return ENOMEM;
    147149        }
     
    151153        /* Construct match ID. */
    152154        if (asprintf(&match_id, PLATFORM_FUN_MATCH_ID_FMT, platform) == -1) {
    153                 printf(NAME ": Memory allocation failed.\n");
     155                ddf_msg(LVL_ERROR, "Memory allocation failed.");
    154156                return ENOMEM;
    155157        }
    156158
    157159        /* Add function. */
    158         printf(NAME ": adding platform function\n");
    159         printf(NAME ":   function node is `%s' (%d %s)\n", PLATFORM_FUN_NAME,
    160             PLATFORM_FUN_MATCH_SCORE, match_id);
     160        ddf_msg(LVL_DEBUG, "Adding platform function. Function node is `%s' "
     161            " (%d %s)", PLATFORM_FUN_NAME, PLATFORM_FUN_MATCH_SCORE,
     162            match_id);
    161163
    162164        fun = ddf_fun_create(dev, fun_inner, name);
    163165        if (fun == NULL) {
    164                 printf(NAME ": error creating function %s\n", name);
     166                ddf_msg(LVL_ERROR, "Error creating function %s", name);
    165167                return ENOMEM;
    166168        }
     
    168170        rc = ddf_fun_add_match_id(fun, match_id, PLATFORM_FUN_MATCH_SCORE);
    169171        if (rc != EOK) {
    170                 printf(NAME ": error adding match IDs to function %s\n", name);
     172                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
     173                    name);
    171174                ddf_fun_destroy(fun);
    172175                return rc;
     
    175178        rc = ddf_fun_bind(fun);
    176179        if (rc != EOK) {
    177                 printf(NAME ": error binding function %s: %s\n", name,
     180                ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,
    178181                    str_error(rc));
    179182                ddf_fun_destroy(fun);
     
    191194static int root_add_device(ddf_dev_t *dev)
    192195{
    193         printf(NAME ": root_add_device, device handle=%" PRIun "\n",
     196        ddf_msg(LVL_DEBUG, "root_add_device, device handle=%" PRIun,
    194197            dev->handle);
    195198
     
    204207        int res = add_platform_fun(dev);
    205208        if (EOK != res)
    206                 printf(NAME ": failed to add child device for platform.\n");
     209                ddf_msg(LVL_ERROR, "Failed adding child device for platform.");
    207210
    208211        return res;
     
    212215{
    213216        printf(NAME ": HelenOS root device driver\n");
     217
     218        ddf_log_init(NAME, LVL_ERROR);
    214219        return ddf_driver_main(&root_driver);
    215220}
  • uspace/drv/rootpc/rootpc.c

    r61257f4 rf8e8738  
    4747
    4848#include <ddf/driver.h>
     49#include <ddf/log.h>
    4950#include <devman.h>
    5051#include <ipc/devman.h>
     
    119120    rootpc_fun_t *fun)
    120121{
    121         printf(NAME ": adding new function '%s'.\n", name);
     122        ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
    122123       
    123124        ddf_fun_t *fnode = NULL;
     
    145146        /* Register function. */
    146147        if (ddf_fun_bind(fnode) != EOK) {
    147                 printf(NAME ": error binding function %s.\n", name);
     148                ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
    148149                goto failure;
    149150        }
     
    158159                ddf_fun_destroy(fnode);
    159160       
    160         printf(NAME ": failed to add function '%s'.\n", name);
     161        ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
    161162       
    162163        return false;
     
    176177static int rootpc_add_device(ddf_dev_t *dev)
    177178{
    178         printf(NAME ": rootpc_add_device, device handle = %d\n",
     179        ddf_msg(LVL_DEBUG, "rootpc_add_device, device handle = %d",
    179180            (int)dev->handle);
    180181       
    181182        /* Register functions. */
    182183        if (!rootpc_add_functions(dev)) {
    183                 printf(NAME ": failed to add functions for PC platform.\n");
     184                ddf_msg(LVL_ERROR, "Failed to add functions for PC platform.");
    184185        }
    185186       
     
    189190static void root_pc_init(void)
    190191{
     192        ddf_log_init(NAME, LVL_ERROR);
    191193        rootpc_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
    192194}
  • uspace/drv/rootvirt/rootvirt.c

    r61257f4 rf8e8738  
    4040#include <str_error.h>
    4141#include <ddf/driver.h>
     42#include <ddf/log.h>
    4243
    4344#define NAME "rootvirt"
     
    8384        int rc;
    8485
    85         printf(NAME ": registering function `%s' (match \"%s\")\n",
     86        ddf_msg(LVL_DEBUG, "Registering function `%s' (match \"%s\")",
    8687            vfun->name, vfun->match_id);
    8788
    8889        fun = ddf_fun_create(vdev, fun_inner, vfun->name);
    8990        if (fun == NULL) {
    90                 printf(NAME ": error creating function %s\n", vfun->name);
     91                ddf_msg(LVL_ERROR, "Failed creating function %s", vfun->name);
    9192                return ENOMEM;
    9293        }
     
    9495        rc = ddf_fun_add_match_id(fun, vfun->match_id, 10);
    9596        if (rc != EOK) {
    96                 printf(NAME ": error adding match IDs to function %s\n",
     97                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
    9798                    vfun->name);
    9899                ddf_fun_destroy(fun);
     
    102103        rc = ddf_fun_bind(fun);
    103104        if (rc != EOK) {
    104                 printf(NAME ": error binding function %s: %s\n", vfun->name,
    105                     str_error(rc));
     105                ddf_msg(LVL_ERROR, "Failed binding function %s: %s",
     106                    vfun->name, str_error(rc));
    106107                ddf_fun_destroy(fun);
    107108                return rc;
    108109        }
    109110
    110         printf(NAME ": registered child device `%s'\n", vfun->name);
     111        ddf_msg(LVL_NOTE, "Registered child device `%s'", vfun->name);
    111112        return EOK;
    112113}
     
    124125        }
    125126
    126         printf(NAME ": add_device(handle=%d)\n", (int)dev->handle);
     127        ddf_msg(LVL_DEBUG, "add_device(handle=%d)", (int)dev->handle);
    127128
    128129        /*
     
    142143{
    143144        printf(NAME ": HelenOS virtual devices root driver\n");
     145
     146        ddf_log_init(NAME, LVL_ERROR);
    144147        return ddf_driver_main(&rootvirt_driver);
    145148}
  • uspace/drv/test1/test1.c

    r61257f4 rf8e8738  
    3535#include <str_error.h>
    3636#include <ddf/driver.h>
     37#include <ddf/log.h>
    3738
    3839#include "test1.h"
     
    5859 */
    5960static int register_fun_verbose(ddf_dev_t *parent, const char *message,
    60     const char *name, const char *match_id, int match_score)
     61    const char *name, const char *match_id, int match_score,
     62    int expected_rc)
    6163{
    62         ddf_fun_t *fun;
     64        ddf_fun_t *fun = NULL;
    6365        int rc;
    6466
    65         printf(NAME ": registering function `%s': %s.\n", name, message);
     67        ddf_msg(LVL_DEBUG, "Registering function `%s': %s.", name, message);
    6668
    6769        fun = ddf_fun_create(parent, fun_inner, name);
    6870        if (fun == NULL) {
    69                 printf(NAME ": error creating function %s\n", name);
    70                 return ENOMEM;
     71                ddf_msg(LVL_ERROR, "Failed creating function %s", name);
     72                rc = ENOMEM;
     73                goto leave;
    7174        }
    7275
    73         rc = ddf_fun_add_match_id(fun, match_id, match_score);
     76        rc = ddf_fun_add_match_id(fun, str_dup(match_id), match_score);
    7477        if (rc != EOK) {
    75                 printf(NAME ": error adding match IDs to function %s\n", name);
    76                 ddf_fun_destroy(fun);
    77                 return rc;
     78                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
     79                    name);
     80                goto leave;
    7881        }
    7982
    8083        rc = ddf_fun_bind(fun);
    8184        if (rc != EOK) {
    82                 printf(NAME ": error binding function %s: %s\n", name,
     85                ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,
    8386                    str_error(rc));
    84                 ddf_fun_destroy(fun);
    85                 return rc;
     87                goto leave;
    8688        }
    8789
    88         printf(NAME ": registered child device `%s'\n", name);
    89         return EOK;
     90        ddf_msg(LVL_NOTE, "Registered child device `%s'", name);
     91        rc = EOK;
     92
     93leave:
     94        if (rc != expected_rc) {
     95                fprintf(stderr,
     96                    NAME ": Unexpected error registering function `%s'.\n"
     97                    NAME ":     Expected \"%s\" but got \"%s\".\n",
     98                    name, str_error(expected_rc), str_error(rc));
     99        }
     100
     101        if ((rc != EOK) && (fun != NULL)) {
     102                ddf_fun_destroy(fun);
     103        }
     104
     105        return rc;
    90106}
    91107
     
    112128        int rc;
    113129
    114         printf(NAME ": add_device(name=\"%s\", handle=%d)\n",
     130        ddf_msg(LVL_DEBUG, "add_device(name=\"%s\", handle=%d)",
    115131            dev->name, (int) dev->handle);
    116132
    117133        fun_a = ddf_fun_create(dev, fun_exposed, "a");
    118134        if (fun_a == NULL) {
    119                 printf(NAME ": error creating function 'a'.\n");
     135                ddf_msg(LVL_ERROR, "Failed creating function 'a'.");
    120136                return ENOMEM;
    121137        }
     
    123139        rc = ddf_fun_bind(fun_a);
    124140        if (rc != EOK) {
    125                 printf(NAME ": error binding function 'a'.\n");
     141                ddf_msg(LVL_ERROR, "Failed binding function 'a'.");
    126142                return rc;
    127143        }
     
    133149                ddf_fun_add_to_class(fun_a, "virt-null");
    134150        } else if (str_cmp(dev->name, "test1") == 0) {
    135                 (void) register_fun_verbose(dev, "cloning myself ;-)", "clone",
    136                     "virtual&test1", 10);
     151                (void) register_fun_verbose(dev,
     152                    "cloning myself ;-)", "clone",
     153                    "virtual&test1", 10, EOK);
     154                (void) register_fun_verbose(dev,
     155                    "cloning myself twice ;-)", "clone",
     156                    "virtual&test1", 10, EEXISTS);
    137157        } else if (str_cmp(dev->name, "clone") == 0) {
    138                 (void) register_fun_verbose(dev, "run by the same task", "child",
    139                     "virtual&test1&child", 10);
     158                (void) register_fun_verbose(dev,
     159                    "run by the same task", "child",
     160                    "virtual&test1&child", 10, EOK);
    140161        }
    141162
    142         printf(NAME ": device `%s' accepted.\n", dev->name);
     163        ddf_msg(LVL_DEBUG, "Device `%s' accepted.", dev->name);
    143164
    144165        return EOK;
     
    148169{
    149170        printf(NAME ": HelenOS test1 virtual device driver\n");
     171        ddf_log_init(NAME, LVL_ERROR);
    150172        return ddf_driver_main(&test1_driver);
    151173}
  • uspace/drv/test2/test2.c

    r61257f4 rf8e8738  
    3636#include <str_error.h>
    3737#include <ddf/driver.h>
     38#include <ddf/log.h>
    3839
    3940#define NAME "test2"
     
    6465        int rc;
    6566
    66         printf(NAME ": registering function `%s': %s.\n", name, message);
     67        ddf_msg(LVL_DEBUG, "Registering function `%s': %s.", name, message);
    6768
    6869        fun = ddf_fun_create(parent, fun_inner, name);
    6970        if (fun == NULL) {
    70                 printf(NAME ": error creating function %s\n", name);
     71                ddf_msg(LVL_ERROR, "Failed creating function %s", name);
    7172                return ENOMEM;
    7273        }
     
    7475        rc = ddf_fun_add_match_id(fun, match_id, match_score);
    7576        if (rc != EOK) {
    76                 printf(NAME ": error adding match IDs to function %s\n", name);
     77                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
     78                    name);
    7779                ddf_fun_destroy(fun);
    7880                return rc;
     
    8183        rc = ddf_fun_bind(fun);
    8284        if (rc != EOK) {
    83                 printf(NAME ": error binding function %s: %s\n", name,
     85                ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,
    8486                    str_error(rc));
    8587                ddf_fun_destroy(fun);
     
    8789        }
    8890
    89         printf(NAME ": registered child device `%s'\n", name);
     91        ddf_msg(LVL_NOTE, "Registered child device `%s'", name);
    9092        return EOK;
    9193}
     
    111113        fun_a = ddf_fun_create(dev, fun_exposed, "a");
    112114        if (fun_a == NULL) {
    113                 printf(NAME ": error creating function 'a'.\n");
     115                ddf_msg(LVL_ERROR, "Failed creating function 'a'.");
    114116                return ENOMEM;
    115117        }
     
    117119        rc = ddf_fun_bind(fun_a);
    118120        if (rc != EOK) {
    119                 printf(NAME ": error binding function 'a'.\n");
     121                ddf_msg(LVL_ERROR, "Failed binding function 'a'.");
    120122                return rc;
    121123        }
     
    128130static int test2_add_device(ddf_dev_t *dev)
    129131{
    130         printf(NAME ": test2_add_device(name=\"%s\", handle=%d)\n",
     132        ddf_msg(LVL_DEBUG, "test2_add_device(name=\"%s\", handle=%d)",
    131133            dev->name, (int) dev->handle);
    132134
     
    134136                fid_t postpone = fibril_create(postponed_birth, dev);
    135137                if (postpone == 0) {
    136                         printf(NAME ": fibril_create() error\n");
     138                        ddf_msg(LVL_ERROR, "fibril_create() failed.");
    137139                        return ENOMEM;
    138140                }
     
    149151{
    150152        printf(NAME ": HelenOS test2 virtual device driver\n");
     153        ddf_log_init(NAME, LVL_ERROR);
    151154        return ddf_driver_main(&test2_driver);
    152155}
  • uspace/drv/uhci-hcd/batch.c

    r61257f4 rf8e8738  
    4949        td_t *tds;
    5050        size_t transfers;
    51         usb_device_keeper_t *manager;
    5251} uhci_batch_t;
    5352
     
    7372 * @param[in] func_out function to call on outbound transaction completion
    7473 * @param[in] arg additional parameter to func_in or func_out
    75  * @param[in] manager Pointer to toggle management structure.
     74 * @param[in] ep Pointer to endpoint toggle management structure.
    7675 * @return Valid pointer if all substructures were successfully created,
    7776 * NULL otherwise.
     
    8685    char* setup_buffer, size_t setup_size,
    8786    usbhc_iface_transfer_in_callback_t func_in,
    88     usbhc_iface_transfer_out_callback_t func_out, void *arg,
    89     usb_device_keeper_t *manager
     87    usbhc_iface_transfer_out_callback_t func_out, void *arg, endpoint_t *ep
    9088    )
    9189{
     
    105103        CHECK_NULL_DISPOSE_RETURN(instance,
    106104            "Failed to allocate batch instance.\n");
    107         usb_transfer_batch_init(instance, target, transfer_type, speed, max_packet_size,
     105        usb_transfer_batch_init(instance, target,
     106            transfer_type, speed, max_packet_size,
    108107            buffer, NULL, buffer_size, NULL, setup_size, func_in,
    109             func_out, arg, fun, NULL);
     108            func_out, arg, fun, ep, NULL);
    110109
    111110
     
    114113            "Failed to allocate batch instance.\n");
    115114        bzero(data, sizeof(uhci_batch_t));
    116         data->manager = manager;
    117115        instance->private_data = data;
    118116
     
    180178                            instance, i, data->tds[i].status);
    181179                        td_print_status(&data->tds[i]);
    182 
    183                         usb_device_keeper_set_toggle(data->manager,
    184                             instance->target, instance->direction,
    185                             td_toggle(&data->tds[i]));
     180                        if (instance->ep != NULL)
     181                                endpoint_toggle_set(instance->ep,
     182                                    td_toggle(&data->tds[i]));
    186183                        if (i > 0)
    187184                                goto substract_ret;
     
    310307
    311308        const bool low_speed = instance->speed == USB_SPEED_LOW;
    312         int toggle = usb_device_keeper_get_toggle(
    313             data->manager, instance->target, instance->direction);
     309        int toggle = endpoint_toggle_get(instance->ep);
    314310        assert(toggle == 0 || toggle == 1);
    315311
     
    342338        }
    343339        td_set_ioc(&data->tds[transfer - 1]);
    344         usb_device_keeper_set_toggle(data->manager, instance->target,
    345             instance->direction, toggle);
     340        endpoint_toggle_set(instance->ep, toggle);
    346341}
    347342/*----------------------------------------------------------------------------*/
  • uspace/drv/uhci-hcd/batch.h

    r61257f4 rf8e8738  
    3535#define DRV_UHCI_BATCH_H
    3636
    37 #include <adt/list.h>
    38 
    3937#include <usbhc_iface.h>
    4038#include <usb/usb.h>
    4139#include <usb/host/device_keeper.h>
     40#include <usb/host/endpoint.h>
    4241#include <usb/host/batch.h>
    4342
     
    5756    usbhc_iface_transfer_out_callback_t func_out,
    5857                void *arg,
    59                 usb_device_keeper_t *manager
     58                endpoint_t *ep
    6059                );
    6160
  • uspace/drv/uhci-hcd/hc.c

    r61257f4 rf8e8738  
    6666static int hc_interrupt_emulator(void *arg);
    6767static int hc_debug_checker(void *arg);
    68 
     68#if 0
    6969static bool usb_is_allowed(
    7070    bool low_speed, usb_transfer_type_t transfer, size_t size);
     71#endif
    7172/*----------------------------------------------------------------------------*/
    7273/** Initialize UHCI hcd driver structure
     
    238239        usb_device_keeper_init(&instance->manager);
    239240        usb_log_debug("Initialized device manager.\n");
     241
     242        ret =
     243            usb_endpoint_manager_init(&instance->ep_manager,
     244                BANDWIDTH_AVAILABLE_USB11);
     245        assert(ret == EOK);
    240246
    241247        return EOK;
     
    322328        assert(instance);
    323329        assert(batch);
    324         const int low_speed = (batch->speed == USB_SPEED_LOW);
    325         if (!usb_is_allowed(
    326             low_speed, batch->transfer_type, batch->max_packet_size)) {
    327                 usb_log_warning(
    328                     "Invalid USB transfer specified %s SPEED %d %zu.\n",
    329                     low_speed ? "LOW" : "FULL" , batch->transfer_type,
    330                     batch->max_packet_size);
    331                 return ENOTSUP;
    332         }
    333         /* TODO: check available bandwidth here */
    334330
    335331        transfer_list_t *list =
     
    338334        if (batch->transfer_type == USB_TRANSFER_CONTROL) {
    339335                usb_device_keeper_use_control(
    340                     &instance->manager, batch->target.address);
     336                    &instance->manager, batch->target);
    341337        }
    342338        transfer_list_add_batch(list, batch);
     
    358354{
    359355        assert(instance);
     356//      status |= 1; //Uncomment to work around qemu hang
    360357        /* TODO: Resume interrupts are not supported */
    361358        /* Lower 2 bits are transaction error and transaction complete */
     
    376373                        usb_transfer_batch_t *batch =
    377374                            list_get_instance(item, usb_transfer_batch_t, link);
    378                         if (batch->transfer_type == USB_TRANSFER_CONTROL) {
     375                        switch (batch->transfer_type)
     376                        {
     377                        case USB_TRANSFER_CONTROL:
    379378                                usb_device_keeper_release_control(
    380                                     &instance->manager, batch->target.address);
     379                                    &instance->manager, batch->target);
     380                                break;
     381                        case USB_TRANSFER_INTERRUPT:
     382                        case USB_TRANSFER_ISOCHRONOUS: {
     383/*
     384                                int ret = bandwidth_free(&instance->bandwidth,
     385                                    batch->target.address,
     386                                    batch->target.endpoint,
     387                                    batch->direction);
     388                                if (ret != EOK)
     389                                        usb_log_warning("Failed(%d) to free "
     390                                            "reserved bw: %s.\n", ret,
     391                                            str_error(ret));
     392*/
     393                                }
     394                        default:
     395                                break;
    381396                        }
    382397                        batch->next_step(batch);
     
    499514 * @return True if transaction is allowed by USB specs, false otherwise
    500515 */
     516#if 0
    501517bool usb_is_allowed(
    502518    bool low_speed, usb_transfer_type_t transfer, size_t size)
     
    516532        return false;
    517533}
     534#endif
    518535/**
    519536 * @}
  • uspace/drv/uhci-hcd/hc.h

    r61257f4 rf8e8738  
    4343#include <usbhc_iface.h>
    4444#include <usb/host/device_keeper.h>
     45#include <usb/host/usb_endpoint_manager.h>
    4546
    4647#include "batch.h"
     
    8485typedef struct hc {
    8586        usb_device_keeper_t manager;
     87        usb_endpoint_manager_t ep_manager;
    8688
    8789        regs_t *registers;
  • uspace/drv/uhci-hcd/hw_struct/queue_head.h

    r61257f4 rf8e8738  
    3939
    4040#include "link_pointer.h"
    41 #include "utils/malloc32.h"
    4241
    4342typedef struct queue_head {
  • uspace/drv/uhci-hcd/iface.c

    r61257f4 rf8e8738  
    3636
    3737#include <usb/debug.h>
     38#include <usb/host/endpoint.h>
    3839
    3940#include "iface.h"
     
    5455        usb_device_keeper_reserve_default_address(&hc->manager, speed);
    5556        return EOK;
     57#if 0
     58        endpoint_t *ep = malloc(sizeof(endpoint_t));
     59        if (ep == NULL)
     60                return ENOMEM;
     61        const size_t max_packet_size = speed == USB_SPEED_LOW ? 8 : 64;
     62        endpoint_init(ep, USB_TRANSFER_CONTROL, speed, max_packet_size);
     63        int ret;
     64try_retgister:
     65        ret = usb_endpoint_manager_register_ep(&hc->ep_manager,
     66            USB_ADDRESS_DEFAULT, 0, USB_DIRECTION_BOTH, ep, endpoint_destroy, 0);
     67        if (ret == EEXISTS) {
     68                async_usleep(1000);
     69                goto try_retgister;
     70        }
     71        if (ret != EOK) {
     72                endpoint_destroy(ep);
     73        }
     74        return ret;
     75#endif
    5676}
    5777/*----------------------------------------------------------------------------*/
     
    6787        assert(hc);
    6888        usb_log_debug("Default address release.\n");
     89//      return usb_endpoint_manager_unregister_ep(&hc->ep_manager,
     90//          USB_ADDRESS_DEFAULT, 0, USB_DIRECTION_BOTH);
    6991        usb_device_keeper_release_default_address(&hc->manager);
    7092        return EOK;
     
    128150}
    129151/*----------------------------------------------------------------------------*/
     152static int register_endpoint(
     153    ddf_fun_t *fun, usb_address_t address, usb_endpoint_t endpoint,
     154    usb_transfer_type_t transfer_type, usb_direction_t direction,
     155    size_t max_packet_size, unsigned int interval)
     156{
     157        hc_t *hc = fun_to_hc(fun);
     158        assert(hc);
     159        const usb_speed_t speed =
     160            usb_device_keeper_get_speed(&hc->manager, address);
     161        const size_t size =
     162            (transfer_type == USB_TRANSFER_INTERRUPT
     163            || transfer_type == USB_TRANSFER_ISOCHRONOUS) ?
     164            max_packet_size : 0;
     165        int ret;
     166
     167        endpoint_t *ep = malloc(sizeof(endpoint_t));
     168        if (ep == NULL)
     169                return ENOMEM;
     170        ret = endpoint_init(ep, address, endpoint, direction,
     171            transfer_type, speed, max_packet_size);
     172        if (ret != EOK) {
     173                free(ep);
     174                return ret;
     175        }
     176
     177        usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n",
     178            address, endpoint, usb_str_transfer_type(transfer_type),
     179            usb_str_speed(speed), direction, size, max_packet_size, interval);
     180
     181        ret = usb_endpoint_manager_register_ep(&hc->ep_manager, ep, size);
     182        if (ret != EOK) {
     183                endpoint_destroy(ep);
     184        } else {
     185                usb_device_keeper_add_ep(&hc->manager, address, ep);
     186        }
     187        return ret;
     188}
     189/*----------------------------------------------------------------------------*/
     190static int unregister_endpoint(
     191    ddf_fun_t *fun, usb_address_t address,
     192    usb_endpoint_t endpoint, usb_direction_t direction)
     193{
     194        hc_t *hc = fun_to_hc(fun);
     195        assert(hc);
     196        usb_log_debug("Unregister endpoint %d:%d %d.\n",
     197            address, endpoint, direction);
     198        return usb_endpoint_manager_unregister_ep(&hc->ep_manager, address,
     199            endpoint, direction);
     200}
     201/*----------------------------------------------------------------------------*/
    130202/** Interrupt out transaction interface function
    131203 *
     
    146218        hc_t *hc = fun_to_hc(fun);
    147219        assert(hc);
    148         usb_speed_t speed =
    149             usb_device_keeper_get_speed(&hc->manager, target.address);
    150220
    151221        usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n",
    152222            target.address, target.endpoint, size, max_packet_size);
    153223
     224        size_t res_bw;
     225        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     226            target.address, target.endpoint, USB_DIRECTION_OUT, &res_bw);
     227        if (ep == NULL) {
     228                usb_log_error("Endpoint(%d:%d) not registered for INT OUT.\n",
     229                        target.address, target.endpoint);
     230                return ENOENT;
     231        }
     232        const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type,
     233            size, ep->max_packet_size);
     234        if (res_bw < bw)
     235        {
     236                usb_log_error("Endpoint(%d:%d) INT IN needs %zu bw "
     237                    "but only %zu is reserved.\n",
     238                    target.address, target.endpoint, bw, res_bw);
     239                return ENOENT;
     240        }
     241        assert(ep->speed ==
     242            usb_device_keeper_get_speed(&hc->manager, target.address));
     243        assert(ep->max_packet_size == max_packet_size);
     244        assert(ep->transfer_type == USB_TRANSFER_INTERRUPT);
     245
    154246        usb_transfer_batch_t *batch =
    155             batch_get(fun, target, USB_TRANSFER_INTERRUPT, max_packet_size,
    156                 speed, data, size, NULL, 0, NULL, callback, arg, &hc->manager);
     247            batch_get(fun, target, ep->transfer_type, ep->max_packet_size,
     248                ep->speed, data, size, NULL, 0, NULL, callback, arg, ep);
    157249        if (!batch)
    158250                return ENOMEM;
     
    183275        hc_t *hc = fun_to_hc(fun);
    184276        assert(hc);
    185         usb_speed_t speed =
    186             usb_device_keeper_get_speed(&hc->manager, target.address);
     277
    187278        usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n",
    188279            target.address, target.endpoint, size, max_packet_size);
    189280
     281        size_t res_bw;
     282        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     283            target.address, target.endpoint, USB_DIRECTION_IN, &res_bw);
     284        if (ep == NULL) {
     285                usb_log_error("Endpoint(%d:%d) not registered for INT IN.\n",
     286                    target.address, target.endpoint);
     287                return ENOENT;
     288        }
     289        const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type,
     290            size, ep->max_packet_size);
     291        if (res_bw < bw)
     292        {
     293                usb_log_error("Endpoint(%d:%d) INT IN needs %zu bw "
     294                    "but only %zu bw is reserved.\n",
     295                    target.address, target.endpoint, bw, res_bw);
     296                return ENOENT;
     297        }
     298
     299        assert(ep->speed ==
     300            usb_device_keeper_get_speed(&hc->manager, target.address));
     301        assert(ep->max_packet_size == max_packet_size);
     302        assert(ep->transfer_type == USB_TRANSFER_INTERRUPT);
     303
    190304        usb_transfer_batch_t *batch =
    191             batch_get(fun, target, USB_TRANSFER_INTERRUPT, max_packet_size,
    192                 speed, data, size, NULL, 0, callback, NULL, arg, &hc->manager);
     305            batch_get(fun, target, ep->transfer_type, ep->max_packet_size,
     306                ep->speed, data, size, NULL, 0, callback, NULL, arg, ep);
    193307        if (!batch)
    194308                return ENOMEM;
     
    219333        hc_t *hc = fun_to_hc(fun);
    220334        assert(hc);
    221         usb_speed_t speed =
    222             usb_device_keeper_get_speed(&hc->manager, target.address);
    223335
    224336        usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n",
    225337            target.address, target.endpoint, size, max_packet_size);
    226338
     339        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     340            target.address, target.endpoint, USB_DIRECTION_OUT, NULL);
     341        if (ep == NULL) {
     342                usb_log_error("Endpoint(%d:%d) not registered for BULK OUT.\n",
     343                        target.address, target.endpoint);
     344                return ENOENT;
     345        }
     346        assert(ep->speed ==
     347            usb_device_keeper_get_speed(&hc->manager, target.address));
     348        assert(ep->max_packet_size == max_packet_size);
     349        assert(ep->transfer_type == USB_TRANSFER_BULK);
     350
    227351        usb_transfer_batch_t *batch =
    228             batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed,
    229                 data, size, NULL, 0, NULL, callback, arg, &hc->manager);
     352            batch_get(fun, target, ep->transfer_type, ep->max_packet_size,
     353                ep->speed, data, size, NULL, 0, NULL, callback, arg, ep);
    230354        if (!batch)
    231355                return ENOMEM;
     
    256380        hc_t *hc = fun_to_hc(fun);
    257381        assert(hc);
    258         usb_speed_t speed =
    259             usb_device_keeper_get_speed(&hc->manager, target.address);
    260382        usb_log_debug("Bulk IN %d:%d %zu(%zu).\n",
    261383            target.address, target.endpoint, size, max_packet_size);
    262384
     385        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     386            target.address, target.endpoint, USB_DIRECTION_IN, NULL);
     387        if (ep == NULL) {
     388                usb_log_error("Endpoint(%d:%d) not registered for BULK IN.\n",
     389                        target.address, target.endpoint);
     390                return ENOENT;
     391        }
     392        assert(ep->speed ==
     393            usb_device_keeper_get_speed(&hc->manager, target.address));
     394        assert(ep->max_packet_size == max_packet_size);
     395        assert(ep->transfer_type == USB_TRANSFER_BULK);
     396
    263397        usb_transfer_batch_t *batch =
    264             batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed,
    265                 data, size, NULL, 0, callback, NULL, arg, &hc->manager);
     398            batch_get(fun, target, ep->transfer_type, ep->max_packet_size,
     399                ep->speed, data, size, NULL, 0, callback, NULL, arg, ep);
    266400        if (!batch)
    267401                return ENOMEM;
     
    299433        usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n",
    300434            speed, target.address, target.endpoint, size, max_packet_size);
     435        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     436            target.address, target.endpoint, USB_DIRECTION_BOTH, NULL);
     437        if (ep == NULL) {
     438                usb_log_warning("Endpoint(%d:%d) not registered for CONTROL.\n",
     439                        target.address, target.endpoint);
     440        }
    301441
    302442        if (setup_size != 8)
     
    305445        usb_transfer_batch_t *batch =
    306446            batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size, speed,
    307                 data, size, setup_data, setup_size, NULL, callback, arg,
    308                 &hc->manager);
     447                data, size, setup_data, setup_size, NULL, callback, arg, ep);
    309448        if (!batch)
    310449                return ENOMEM;
     
    344483        usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n",
    345484            speed, target.address, target.endpoint, size, max_packet_size);
     485        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     486            target.address, target.endpoint, USB_DIRECTION_BOTH, NULL);
     487        if (ep == NULL) {
     488                usb_log_warning("Endpoint(%d:%d) not registered for CONTROL.\n",
     489                        target.address, target.endpoint);
     490        }
    346491        usb_transfer_batch_t *batch =
    347492            batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size, speed,
    348                 data, size, setup_data, setup_size, callback, NULL, arg,
    349                 &hc->manager);
     493                data, size, setup_data, setup_size, callback, NULL, arg, ep);
    350494        if (!batch)
    351495                return ENOMEM;
     
    365509        .release_address = release_address,
    366510
     511        .register_endpoint = register_endpoint,
     512        .unregister_endpoint = unregister_endpoint,
     513
    367514        .interrupt_out = interrupt_out,
    368515        .interrupt_in = interrupt_in,
  • uspace/drv/uhci-hcd/transfer_list.h

    r61257f4 rf8e8738  
    3939#include "batch.h"
    4040#include "hw_struct/queue_head.h"
     41#include "utils/malloc32.h"
    4142
    4243typedef struct transfer_list
  • uspace/drv/uhci-hcd/utils/malloc32.h

    r61257f4 rf8e8738  
    3636
    3737#include <assert.h>
     38#include <errno.h>
    3839#include <malloc.h>
    3940#include <mem.h>
  • uspace/drv/uhci-rhd/main.c

    r61257f4 rf8e8738  
    4444
    4545#define NAME "uhci-rhd"
     46
    4647static int hc_get_my_registers(ddf_dev_t *dev,
    4748    uintptr_t *io_reg_address, size_t *io_reg_size);
    48 #if 0
    4949/*----------------------------------------------------------------------------*/
    50 static int usb_iface_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
    51 {
    52         assert(fun);
    53         assert(fun->driver_data);
    54         assert(handle);
    55 
    56         *handle = ((uhci_root_hub_t*)fun->driver_data)->hc_handle;
    57 
    58         return EOK;
    59 }
    60 /*----------------------------------------------------------------------------*/
    61 static usb_iface_t uhci_rh_usb_iface = {
    62         .get_hc_handle = usb_iface_get_hc_handle,
    63         .get_address = usb_iface_get_address_hub_impl
    64 };
    65 /*----------------------------------------------------------------------------*/
    66 static ddf_dev_ops_t uhci_rh_ops = {
    67         .interfaces[USB_DEV_IFACE] = &uhci_rh_usb_iface,
    68 };
    69 #endif
    70 /*----------------------------------------------------------------------------*/
    71 /** Initialize a new ddf driver instance of UHCI root hub.
    72  *
    73  * @param[in] device DDF instance of the device to initialize.
    74  * @return Error code.
    75  */
    76 static int uhci_rh_add_device(ddf_dev_t *device)
    77 {
    78         if (!device)
    79                 return ENOTSUP;
    80 
    81         usb_log_debug2("%s called device %d\n", __FUNCTION__, device->handle);
    82 
    83         //device->ops = &uhci_rh_ops;
    84         uintptr_t io_regs = 0;
    85         size_t io_size = 0;
    86 
    87         int ret = hc_get_my_registers(device, &io_regs, &io_size);
    88         if (ret != EOK) {
    89                 usb_log_error("Failed to get registers from parent HC: %s.\n",
    90                     str_error(ret));
    91         }
    92         usb_log_debug("I/O regs at %#X (size %zu).\n", io_regs, io_size);
    93 
    94         uhci_root_hub_t *rh = malloc(sizeof(uhci_root_hub_t));
    95         if (!rh) {
    96                 usb_log_error("Failed to allocate driver instance.\n");
    97                 return ENOMEM;
    98         }
    99 
    100         ret = uhci_root_hub_init(rh, (void*)io_regs, io_size, device);
    101         if (ret != EOK) {
    102                 usb_log_error("Failed to initialize driver instance: %s.\n",
    103                     str_error(ret));
    104                 free(rh);
    105                 return ret;
    106         }
    107 
    108         device->driver_data = rh;
    109         usb_log_info("Controlling root hub `%s' (%llu).\n",
    110             device->name, device->handle);
    111         return EOK;
    112 }
     50static int uhci_rh_add_device(ddf_dev_t *device);
    11351/*----------------------------------------------------------------------------*/
    11452static driver_ops_t uhci_rh_driver_ops = {
     
    13270{
    13371        printf(NAME ": HelenOS UHCI root hub driver.\n");
     72        usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
     73        return ddf_driver_main(&uhci_rh_driver);
     74}
     75/*----------------------------------------------------------------------------*/
     76/** Initialize a new ddf driver instance of UHCI root hub.
     77 *
     78 * @param[in] device DDF instance of the device to initialize.
     79 * @return Error code.
     80 */
     81static int uhci_rh_add_device(ddf_dev_t *device)
     82{
     83        if (!device)
     84                return EINVAL;
    13485
    135         usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
     86        usb_log_debug2("%s called device %d\n", __FUNCTION__, device->handle);
    13687
    137         return ddf_driver_main(&uhci_rh_driver);
     88        uintptr_t io_regs = 0;
     89        size_t io_size = 0;
     90        uhci_root_hub_t *rh = NULL;
     91        int ret = EOK;
     92
     93#define CHECK_RET_FREE_RH_RETURN(ret, message...) \
     94if (ret != EOK) { \
     95        usb_log_error(message); \
     96        if (rh) \
     97                free(rh); \
     98        return ret; \
     99} else (void)0
     100
     101        ret = hc_get_my_registers(device, &io_regs, &io_size);
     102        CHECK_RET_FREE_RH_RETURN(ret,
     103            "Failed(%d) to get registers from HC: %s.\n", ret, str_error(ret));
     104        usb_log_debug("I/O regs at %#x (size %zu).\n", io_regs, io_size);
     105
     106        rh = malloc(sizeof(uhci_root_hub_t));
     107        ret = (rh == NULL) ? ENOMEM : EOK;
     108        CHECK_RET_FREE_RH_RETURN(ret,
     109            "Failed to allocate rh driver instance.\n");
     110
     111        ret = uhci_root_hub_init(rh, (void*)io_regs, io_size, device);
     112        CHECK_RET_FREE_RH_RETURN(ret,
     113            "Failed(%d) to initialize rh driver instance: %s.\n",
     114            ret, str_error(ret));
     115
     116        device->driver_data = rh;
     117        usb_log_info("Controlling root hub '%s' (%llu).\n",
     118            device->name, device->handle);
     119        return EOK;
    138120}
    139121/*----------------------------------------------------------------------------*/
     
    156138        }
    157139
    158         int rc;
    159 
    160140        hw_resource_list_t hw_resources;
    161         rc = hw_res_get_resource_list(parent_phone, &hw_resources);
    162         if (rc != EOK) {
    163                 goto leave;
     141        int ret = hw_res_get_resource_list(parent_phone, &hw_resources);
     142        if (ret != EOK) {
     143                async_hangup(parent_phone);
     144                return ret;
    164145        }
    165146
     
    168149        bool io_found = false;
    169150
    170         size_t i;
    171         for (i = 0; i < hw_resources.count; i++) {
     151        size_t i = 0;
     152        for (; i < hw_resources.count; i++) {
    172153                hw_resource_t *res = &hw_resources.resources[i];
    173                 switch (res->type)
    174                 {
    175                 case IO_RANGE:
    176                         io_address = (uintptr_t) res->res.io_range.address;
     154                if (res->type == IO_RANGE) {
     155                        io_address = res->res.io_range.address;
    177156                        io_size = res->res.io_range.size;
    178157                        io_found = true;
    179 
    180                 default:
    181                         break;
    182158                }
    183159        }
     160        async_hangup(parent_phone);
    184161
    185162        if (!io_found) {
    186                 rc = ENOENT;
    187                 goto leave;
     163                return ENOENT;
    188164        }
    189 
    190165        if (io_reg_address != NULL) {
    191166                *io_reg_address = io_address;
     
    194169                *io_reg_size = io_size;
    195170        }
    196         rc = EOK;
    197 
    198 leave:
    199         async_hangup(parent_phone);
    200         return rc;
     171        return EOK;
    201172}
    202173/**
  • uspace/drv/uhci-rhd/port.c

    r61257f4 rf8e8738  
    4343#include "port.h"
    4444
     45static int uhci_port_check(void *port);
     46static int uhci_port_reset_enable(int portno, void *arg);
    4547static int uhci_port_new_device(uhci_port_t *port, usb_speed_t speed);
    4648static int uhci_port_remove_device(uhci_port_t *port);
    4749static int uhci_port_set_enabled(uhci_port_t *port, bool enabled);
    48 static int uhci_port_check(void *port);
    49 static int uhci_port_reset_enable(int portno, void *arg);
    5050static void uhci_port_print_status(
    5151    uhci_port_t *port, const port_status_t value);
     
    7474        pio_write_16(port->address, value);
    7575}
    76 
    7776/*----------------------------------------------------------------------------*/
    7877/** Initialize UHCI root hub port instance.
     
    259258
    260259        usb_address_t dev_addr;
    261         int rc = usb_hc_new_device_wrapper(port->rh, &port->hc_connection,
     260        int ret = usb_hc_new_device_wrapper(port->rh, &port->hc_connection,
    262261            speed, uhci_port_reset_enable, port->number, port,
    263262            &dev_addr, &port->attached_device, NULL, NULL, NULL);
    264263
    265         if (rc != EOK) {
     264        if (ret != EOK) {
    266265                usb_log_error("%s: Failed(%d) to add device: %s.\n",
    267                     port->id_string, rc, str_error(rc));
     266                    port->id_string, ret, str_error(ret));
    268267                uhci_port_set_enabled(port, false);
    269                 return rc;
     268                return ret;
    270269        }
    271270
     
    287286int uhci_port_remove_device(uhci_port_t *port)
    288287{
    289         usb_log_error("%s: Don't know how to remove device %d.\n",
    290             port->id_string, (unsigned int)port->attached_device);
    291         return EOK;
     288        usb_log_error("%s: Don't know how to remove device %llu.\n",
     289            port->id_string, port->attached_device);
     290        return ENOTSUP;
    292291}
    293292/*----------------------------------------------------------------------------*/
     
    341340            (value & STATUS_CONNECTED_CHANGED) ? " CONNECTED-CHANGE," : "",
    342341            (value & STATUS_CONNECTED) ? " CONNECTED," : "",
    343             (value & STATUS_ALWAYS_ONE) ? " ALWAYS ONE" : " ERROR: NO ALWAYS ONE"
     342            (value & STATUS_ALWAYS_ONE) ? " ALWAYS ONE" : " ERR: NO ALWAYS ONE"
    344343        );
    345344}
  • uspace/drv/uhci-rhd/root_hub.c

    r61257f4 rf8e8738  
    5151        assert(instance);
    5252        assert(rh);
    53         int ret;
    5453
    5554        /* Allow access to root hub port registers */
    5655        assert(sizeof(port_status_t) * UHCI_ROOT_HUB_PORT_COUNT <= size);
    5756        port_status_t *regs;
    58         ret = pio_enable(addr, size, (void**)&regs);
     57        int ret = pio_enable(addr, size, (void**)&regs);
    5958        if (ret < 0) {
    6059                usb_log_error(
     
    8483 *
    8584 * @param[in] instance Root hub structure to use.
    86  * @return Error code.
    8785 */
    88 int uhci_root_hub_fini(uhci_root_hub_t* instance)
     86void uhci_root_hub_fini(uhci_root_hub_t* instance)
    8987{
    9088        assert(instance);
     
    9391                uhci_port_fini(&instance->ports[i]);
    9492        }
    95         return EOK;
    9693}
    9794/*----------------------------------------------------------------------------*/
  • uspace/drv/uhci-rhd/root_hub.h

    r61257f4 rf8e8738  
    5050  uhci_root_hub_t *instance, void *addr, size_t size, ddf_dev_t *rh);
    5151
    52 int uhci_root_hub_fini(uhci_root_hub_t *instance);
     52void uhci_root_hub_fini(uhci_root_hub_t *instance);
    5353#endif
    5454/**
  • uspace/drv/usbhub/Makefile

    r61257f4 rf8e8738  
    3434SOURCES = \
    3535        main.c \
     36        ports.c \
    3637        utils.c \
    37         usbhub.c \
    38         usblist.c
     38        usbhub.c
    3939
    4040include $(USPACE_PREFIX)/Makefile.common
  • uspace/drv/usbhub/port_status.h

    r61257f4 rf8e8738  
    9595}
    9696
     97/**
     98 * set the device request to be a port feature clear request
     99 * @param request
     100 * @param port
     101 * @param feature_selector
     102 */
     103static inline void usb_hub_set_disable_port_feature_request(
     104usb_device_request_setup_packet_t * request, uint16_t port,
     105                uint16_t feature_selector
     106){
     107        request->index = port;
     108        request->request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE;
     109        request->request = USB_HUB_REQUEST_CLEAR_FEATURE;
     110        request->value = feature_selector;
     111        request->length = 0;
     112}
    97113
    98114/**
  • uspace/drv/usbhub/ports.h

    r61257f4 rf8e8738  
    11/*
    2  * Copyright (c) 2010 Matus Dekanek
     2 * Copyright (c) 2011 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28
    2829/** @addtogroup drvusbhub
    2930 * @{
    3031 */
    3132/** @file
    32  * @brief usblist implementation
     33 * Hub ports related functions.
    3334 */
    34 #include <sys/types.h>
     35#ifndef DRV_USBHUB_PORTS_H
     36#define DRV_USBHUB_PORTS_H
    3537
    36 #include "usbhub_private.h"
     38#include <ipc/devman.h>
     39#include <usb/usb.h>
     40#include <ddf/driver.h>
     41#include <fibril_synch.h>
     42
     43#include <usb/hub.h>
     44
     45#include <usb/pipes.h>
     46#include <usb/devdrv.h>
     47
     48/** Information about single port on a hub. */
     49typedef struct {
     50        /** Mutex needed by CV for checking port reset. */
     51        fibril_mutex_t reset_mutex;
     52        /** CV for waiting to port reset completion. */
     53        fibril_condvar_t reset_cv;
     54        /** Whether port reset is completed.
     55         * Guarded by @c reset_mutex.
     56         */
     57        bool reset_completed;
     58
     59        /** Information about attached device. */
     60        usb_hc_attached_device_t attached_device;
     61} usb_hub_port_t;
     62
     63/** Initialize hub port information.
     64 *
     65 * @param port Port to be initialized.
     66 */
     67static inline void usb_hub_port_init(usb_hub_port_t *port) {
     68        port->attached_device.address = -1;
     69        port->attached_device.handle = 0;
     70        fibril_mutex_initialize(&port->reset_mutex);
     71        fibril_condvar_initialize(&port->reset_cv);
     72}
     73
     74bool hub_port_changes_callback(usb_device_t *, uint8_t *, size_t, void *);
    3775
    3876
    39 usb_general_list_t * usb_lst_create(void) {
    40         usb_general_list_t* result = usb_new(usb_general_list_t);
    41         usb_lst_init(result);
    42         return result;
    43 }
    44 
    45 void usb_lst_init(usb_general_list_t * lst) {
    46         lst->prev = lst;
    47         lst->next = lst;
    48         lst->data = NULL;
    49 }
    50 
    51 void usb_lst_prepend(usb_general_list_t* item, void* data) {
    52         usb_general_list_t* appended = usb_new(usb_general_list_t);
    53         appended->data = data;
    54         appended->next = item;
    55         appended->prev = item->prev;
    56         item->prev->next = appended;
    57         item->prev = appended;
    58 }
    59 
    60 void usb_lst_append(usb_general_list_t* item, void* data) {
    61         usb_general_list_t* appended = usb_new(usb_general_list_t);
    62         appended->data = data;
    63         appended->next = item->next;
    64         appended->prev = item;
    65         item->next->prev = appended;
    66         item->next = appended;
    67 }
    68 
    69 void usb_lst_remove(usb_general_list_t* item) {
    70         item->next->prev = item->prev;
    71         item->prev->next = item->next;
    72 }
    73 
    74 
    75 
     77#endif
    7678/**
    7779 * @}
    7880 */
    79 
    80 
  • uspace/drv/usbhub/usbhub.c

    r61257f4 rf8e8738  
    5353#include "usb/classes/classes.h"
    5454
    55 
    56 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,
    57                 usb_speed_t speed);
    58 
    5955static int usb_hub_trigger_connecting_non_removable_devices(
    6056                usb_hub_info_t * hub, usb_hub_descriptor_t * descriptor);
    61 
    62 /**
    63  * control loop running in hub`s fibril
    64  *
    65  * Hub`s fibril periodically asks for changes on hub and if needded calls
    66  * change handling routine.
    67  * @warning currently hub driver asks for changes once a second
    68  * @param hub_info_param hub representation pointer
    69  * @return zero
    70  */
    71 int usb_hub_control_loop(void * hub_info_param){
    72         usb_hub_info_t * hub_info = (usb_hub_info_t*)hub_info_param;
    73         int errorCode = EOK;
    74 
    75         while(errorCode == EOK){
    76                 errorCode = usb_hub_check_hub_changes(hub_info);
    77                 async_usleep(1000 * 1000 );/// \TODO proper number once
    78         }
    79         usb_log_error("something in ctrl loop went wrong, errno %d\n",errorCode);
    80 
    81         return 0;
    82 }
    8357
    8458
     
    152126        usb_log_debug("setting port count to %d\n",descriptor->ports_count);
    153127        hub_info->port_count = descriptor->ports_count;
    154         hub_info->attached_devs = (usb_hc_attached_device_t*)
    155             malloc((hub_info->port_count+1) * sizeof(usb_hc_attached_device_t));
    156         int i;
    157         for(i=0;i<hub_info->port_count+1;++i){
    158                 hub_info->attached_devs[i].handle=0;
    159                 hub_info->attached_devs[i].address=0;
     128        hub_info->ports = malloc(sizeof(usb_hub_port_t) * (hub_info->port_count+1));
     129        size_t port;
     130        for (port = 0; port < hub_info->port_count + 1; port++) {
     131                usb_hub_port_init(&hub_info->ports[port]);
    160132        }
    161133        //handle non-removable devices
     
    259231        assert(rc == EOK);
    260232
    261         //create fibril for the hub control loop
    262         fid_t fid = fibril_create(usb_hub_control_loop, hub_info);
    263         if (fid == 0) {
    264                 usb_log_error("failed to start monitoring fibril for new hub.\n");
    265                 return ENOMEM;
    266         }
    267         fibril_add_ready(fid);
    268         usb_log_debug("Hub fibril created.\n");
     233        /*
     234         * The processing will require opened control pipe and connection
     235         * to the host controller.
     236         * It is waste of resources but let's hope there will be less
     237         * hubs than the phone limit.
     238         * FIXME: with some proper locking over pipes and session
     239         * auto destruction, this could work better.
     240         */
     241        rc = usb_pipe_start_session(&usb_dev->ctrl_pipe);
     242        if (rc != EOK) {
     243                usb_log_error("Failed to start session on control pipe: %s.\n",
     244                    str_error(rc));
     245                goto leave;
     246        }
     247        rc = usb_hc_connection_open(&hub_info->connection);
     248        if (rc != EOK) {
     249                usb_pipe_end_session(&usb_dev->ctrl_pipe);
     250                usb_log_error("Failed to open connection to HC: %s.\n",
     251                    str_error(rc));
     252                goto leave;
     253        }
     254
     255        rc = usb_device_auto_poll(hub_info->usb_device, 0,
     256            hub_port_changes_callback, ((hub_info->port_count+1) / 8) + 1,
     257            NULL, hub_info);
     258        if (rc != EOK) {
     259                usb_log_error("Failed to create polling fibril: %s.\n",
     260                    str_error(rc));
     261                free(hub_info);
     262                return rc;
     263        }
    269264
    270265        usb_log_info("Controlling hub `%s' (%d ports).\n",
    271266            hub_info->usb_device->ddf_dev->name, hub_info->port_count);
    272267        return EOK;
     268
     269leave:
     270        free(hub_info);
     271
     272        return rc;
    273273}
    274274
     
    317317                        //set the status change bit, so it will be noticed in driver loop
    318318                        if(usb_port_dev_connected(&status)){
    319                                 usb_hub_set_enable_port_feature_request(&request, port,
    320                                                 USB_HUB_FEATURE_C_PORT_CONNECTION);
     319                                usb_hub_set_disable_port_feature_request(&request, port,
     320                                                USB_HUB_FEATURE_PORT_CONNECTION);
    321321                                opResult = usb_pipe_control_read(
    322322                                                hub->control_pipe,
     
    326326                                if (opResult != EOK) {
    327327                                        usb_log_warning(
    328                                                         "could not set port change on port %d errno:%d\n",
     328                                                        "could not clear port connection on port %d errno:%d\n",
    329329                                                        port, opResult);
    330330                                }
     331                                usb_log_debug("cleared port connection\n");
     332                                usb_hub_set_enable_port_feature_request(&request, port,
     333                                                USB_HUB_FEATURE_PORT_ENABLE);
     334                                opResult = usb_pipe_control_read(
     335                                                hub->control_pipe,
     336                                                &request, sizeof(usb_device_request_setup_packet_t),
     337                                                &status, 4, &rcvd_size
     338                                                );
     339                                if (opResult != EOK) {
     340                                        usb_log_warning(
     341                                                        "could not set port enabled on port %d errno:%d\n",
     342                                                        port, opResult);
     343                                }
     344                                usb_log_debug("port set to enabled - should lead to connection change\n");
    331345                        }
     346                }
     347        }
     348        /// \TODO this is just a debug code
     349        for(port=1;port<=descriptor->ports_count;++port){
     350                bool is_non_removable =
     351                                ((non_removable_dev_bitmap[port/8]) >> (port%8)) %2;
     352                if(is_non_removable){
     353                        usb_log_debug("port %d is non-removable\n",port);
     354                        usb_port_status_t status;
     355                        size_t rcvd_size;
     356                        usb_device_request_setup_packet_t request;
     357                        //int opResult;
     358                        usb_hub_set_port_status_request(&request, port);
     359                        //endpoint 0
     360                        opResult = usb_pipe_control_read(
     361                                        hub->control_pipe,
     362                                        &request, sizeof(usb_device_request_setup_packet_t),
     363                                        &status, 4, &rcvd_size
     364                                        );
     365                        if (opResult != EOK) {
     366                                usb_log_error("could not get port status %d\n",opResult);
     367                        }
     368                        if (rcvd_size != sizeof (usb_port_status_t)) {
     369                                usb_log_error("received status has incorrect size\n");
     370                        }
     371                        //something connected/disconnected
     372                        if (usb_port_connect_change(&status)) {
     373                                usb_log_debug("some connection changed\n");
     374                        }
     375                        usb_log_debug("status: %s\n",usb_debug_str_buffer(
     376                                        (uint8_t *)&status,4,4));
    332377                }
    333378        }
     
    352397        hub->is_default_address_used = false;
    353398        return EOK;
    354 }
    355 
    356 /**
    357  * Reset the port with new device and reserve the default address.
    358  * @param hub hub representation
    359  * @param port port number, starting from 1
    360  * @param speed transfer speed of attached device, one of low, full or high
    361  */
    362 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,
    363                 usb_speed_t speed) {
    364         //if this hub already uses default address, it cannot request it once more
    365         if(hub->is_default_address_used) return;
    366         usb_log_debug("some connection changed\n");
    367         assert(hub->control_pipe->hc_phone);
    368         int opResult = usb_hub_clear_port_feature(hub->control_pipe,
    369                                 port, USB_HUB_FEATURE_C_PORT_CONNECTION);
    370         if(opResult != EOK){
    371                 usb_log_warning("could not clear port-change-connection flag\n");
    372         }
    373         usb_device_request_setup_packet_t request;
    374        
    375         //get default address
    376         opResult = usb_hc_reserve_default_address(&hub->connection, speed);
    377        
    378         if (opResult != EOK) {
    379                 usb_log_warning("cannot assign default address, it is probably used %d\n",
    380                                 opResult);
    381                 return;
    382         }
    383         hub->is_default_address_used = true;
    384         //reset port
    385         usb_hub_set_reset_port_request(&request, port);
    386         opResult = usb_pipe_control_write(
    387                         hub->control_pipe,
    388                         &request,sizeof(usb_device_request_setup_packet_t),
    389                         NULL, 0
    390                         );
    391         if (opResult != EOK) {
    392                 usb_log_error("something went wrong when reseting a port %d\n",opResult);
    393                 usb_hub_release_default_address(hub);
    394         }
    395         return;
    396 }
    397 
    398 /**
    399  * Finalize adding new device after port reset
    400  *
    401  * Set device`s address and start it`s driver.
    402  * @param hub hub representation
    403  * @param port port number, starting from 1
    404  * @param speed transfer speed of attached device, one of low, full or high
    405  */
    406 static void usb_hub_finalize_add_device( usb_hub_info_t * hub,
    407                 uint16_t port, usb_speed_t speed) {
    408 
    409         int opResult;
    410         usb_log_debug("finalizing add device\n");
    411         opResult = usb_hub_clear_port_feature(hub->control_pipe,
    412             port, USB_HUB_FEATURE_C_PORT_RESET);
    413 
    414         if (opResult != EOK) {
    415                 usb_log_error("failed to clear port reset feature\n");
    416                 usb_hub_release_default_address(hub);
    417                 return;
    418         }
    419         //create connection to device
    420         usb_pipe_t new_device_pipe;
    421         usb_device_connection_t new_device_connection;
    422         usb_device_connection_initialize_on_default_address(
    423                         &new_device_connection,
    424                         &hub->connection
    425                         );
    426         usb_pipe_initialize_default_control(
    427                         &new_device_pipe,
    428                         &new_device_connection);
    429         usb_pipe_probe_default_control(&new_device_pipe);
    430 
    431         /* Request address from host controller. */
    432         usb_address_t new_device_address = usb_hc_request_address(
    433                         &hub->connection,
    434                         speed
    435                         );
    436         if (new_device_address < 0) {
    437                 usb_log_error("failed to get free USB address\n");
    438                 opResult = new_device_address;
    439                 usb_hub_release_default_address(hub);
    440                 return;
    441         }
    442         usb_log_debug("setting new address %d\n",new_device_address);
    443         //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
    444         //    new_device_address);
    445         usb_pipe_start_session(&new_device_pipe);
    446         opResult = usb_request_set_address(&new_device_pipe,new_device_address);
    447         usb_pipe_end_session(&new_device_pipe);
    448         if (opResult != EOK) {
    449                 usb_log_error("could not set address for new device %d\n",opResult);
    450                 usb_hub_release_default_address(hub);
    451                 return;
    452         }
    453 
    454         //opResult = usb_hub_release_default_address(hc);
    455         opResult = usb_hub_release_default_address(hub);
    456         if(opResult!=EOK){
    457                 return;
    458         }
    459 
    460         devman_handle_t child_handle;
    461         //??
    462     opResult = usb_device_register_child_in_devman(new_device_address,
    463             hub->connection.hc_handle, hub->usb_device->ddf_dev, &child_handle,
    464             NULL, NULL, NULL);
    465 
    466         if (opResult != EOK) {
    467                 usb_log_error("could not start driver for new device %d\n",opResult);
    468                 return;
    469         }
    470         hub->attached_devs[port].handle = child_handle;
    471         hub->attached_devs[port].address = new_device_address;
    472 
    473         //opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
    474         opResult = usb_hc_register_device(
    475                         &hub->connection,
    476                         &hub->attached_devs[port]);
    477         if (opResult != EOK) {
    478                 usb_log_error("could not assign address of device in hcd %d\n",opResult);
    479                 return;
    480         }
    481         usb_log_info("Detected new device on `%s' (port %d), " \
    482             "address %d (handle %llu).\n",
    483             hub->usb_device->ddf_dev->name, (int) port,
    484             new_device_address, child_handle);
    485399}
    486400
     
    494408 * @param port port number, starting from 1
    495409 */
    496 static void usb_hub_removed_device(
     410void usb_hub_removed_device(
    497411    usb_hub_info_t * hub,uint16_t port) {
    498412
     
    507421       
    508422        //close address
    509         if(hub->attached_devs[port].address!=0){
     423        if(hub->ports[port].attached_device.address >= 0){
    510424                /*uncomment this code to use it when DDF allows device removal
    511425                opResult = usb_hc_unregister_device(
     
    534448 * @param port port number, starting from 1
    535449 */
    536 static void usb_hub_over_current( usb_hub_info_t * hub,
     450void usb_hub_over_current( usb_hub_info_t * hub,
    537451                uint16_t port){
    538452        int opResult;
     
    545459}
    546460
    547 /**
    548  * Process interrupts on given hub port
    549  *
    550  * Accepts connection, over current and port reset change.
    551  * @param hub hub representation
    552  * @param port port number, starting from 1
    553  */
    554 static void usb_hub_process_interrupt(usb_hub_info_t * hub,
    555         uint16_t port) {
    556         usb_log_debug("interrupt at port %d\n", port);
    557         //determine type of change
    558         usb_pipe_t *pipe = hub->control_pipe;
    559        
    560         int opResult;
    561 
    562         usb_port_status_t status;
    563         size_t rcvd_size;
    564         usb_device_request_setup_packet_t request;
    565         //int opResult;
    566         usb_hub_set_port_status_request(&request, port);
    567         //endpoint 0
    568 
    569         opResult = usb_pipe_control_read(
    570                         pipe,
    571                         &request, sizeof(usb_device_request_setup_packet_t),
    572                         &status, 4, &rcvd_size
    573                         );
    574         if (opResult != EOK) {
    575                 usb_log_error("could not get port status\n");
    576                 return;
    577         }
    578         if (rcvd_size != sizeof (usb_port_status_t)) {
    579                 usb_log_error("received status has incorrect size\n");
    580                 return;
    581         }
    582         //something connected/disconnected
    583         if (usb_port_connect_change(&status)) {
    584                 if (usb_port_dev_connected(&status)) {
    585                         usb_log_debug("some connection changed\n");
    586                         usb_hub_init_add_device(hub, port, usb_port_speed(&status));
    587                 } else {
    588                         usb_hub_removed_device(hub, port);
    589                 }
    590         }
    591         //over current
    592         if (usb_port_overcurrent_change(&status)) {
    593                 //check if it was not auto-resolved
    594                 if(usb_port_over_current(&status)){
    595                         usb_hub_over_current(hub,port);
    596                 }else{
    597                         usb_log_debug("over current condition was auto-resolved on port %d\n",
    598                                         port);
    599                 }
    600         }
    601         //port reset
    602         if (usb_port_reset_completed(&status)) {
    603                 usb_log_debug("port reset complete\n");
    604                 if (usb_port_enabled(&status)) {
    605                         usb_hub_finalize_add_device(hub, port, usb_port_speed(&status));
    606                 } else {
    607                         usb_log_warning("port reset, but port still not enabled\n");
    608                 }
    609         }
    610 
    611         usb_port_set_connect_change(&status, false);
    612         usb_port_set_reset(&status, false);
    613         usb_port_set_reset_completed(&status, false);
    614         usb_port_set_dev_connected(&status, false);
    615         if (status>>16) {
    616                 usb_log_info("there was some unsupported change on port %d: %X\n",
    617                                 port,status);
    618 
    619         }
    620 }
    621 
    622 /**
    623  * check changes on hub
    624  *
    625  * Handles changes on each port with a status change.
    626  * @param hub_info hub representation
    627  * @return error code
    628  */
    629 int usb_hub_check_hub_changes(usb_hub_info_t * hub_info){
    630         int opResult;
    631         opResult = usb_pipe_start_session(
    632                         hub_info->status_change_pipe);
    633         if(opResult != EOK){
    634                 usb_log_error("could not initialize communication for hub; %d\n",
    635                                 opResult);
    636                 return opResult;
    637         }
    638 
    639         size_t port_count = hub_info->port_count;
    640 
    641         /// FIXME: count properly
    642         size_t byte_length = ((port_count+1) / 8) + 1;
    643                 void *change_bitmap = malloc(byte_length);
    644         size_t actual_size;
    645 
    646         /*
    647          * Send the request.
    648          */
    649         opResult = usb_pipe_read(
    650                         hub_info->status_change_pipe,
    651                         change_bitmap, byte_length, &actual_size
    652                         );
    653 
    654         if (opResult != EOK) {
    655                 free(change_bitmap);
    656                 usb_log_warning("something went wrong while getting status of hub\n");
    657                 usb_pipe_end_session(hub_info->status_change_pipe);
    658                 return opResult;
    659         }
    660         unsigned int port;
    661         opResult = usb_pipe_start_session(hub_info->control_pipe);
    662         if(opResult!=EOK){
    663                 usb_log_error("could not start control pipe session %d\n", opResult);
    664                 usb_pipe_end_session(hub_info->status_change_pipe);
    665                 return opResult;
    666         }
    667         opResult = usb_hc_connection_open(&hub_info->connection);
    668         if(opResult!=EOK){
    669                 usb_log_error("could not start host controller session %d\n",
    670                                 opResult);
    671                 usb_pipe_end_session(hub_info->control_pipe);
    672                 usb_pipe_end_session(hub_info->status_change_pipe);
    673                 return opResult;
    674         }
    675 
    676         ///todo, opresult check, pre obe konekce
    677         for (port = 1; port < port_count+1; ++port) {
    678                 bool interrupt =
    679                                 (((uint8_t*) change_bitmap)[port / 8] >> (port % 8)) % 2;
    680                 if (interrupt) {
    681                         usb_hub_process_interrupt(
    682                                 hub_info, port);
    683                 }
    684         }
    685         usb_hc_connection_close(&hub_info->connection);
    686         usb_pipe_end_session(hub_info->control_pipe);
    687         usb_pipe_end_session(hub_info->status_change_pipe);
    688         free(change_bitmap);
    689         return EOK;
    690 }
    691 
    692 
    693461
    694462/**
  • uspace/drv/usbhub/usbhub.h

    r61257f4 rf8e8738  
    4747#include <usb/devdrv.h>
    4848
     49#include "ports.h"
     50
     51
    4952
    5053/** Information about attached hub. */
    5154typedef struct {
    5255        /** Number of ports. */
    53         int port_count;
     56        size_t port_count;
    5457
    55         /** attached device handles, for each port one */
    56         usb_hc_attached_device_t * attached_devs;
     58        /** Ports. */
     59        usb_hub_port_t *ports;
    5760       
    5861        /** connection to hcd */
     
    100103int usb_hub_check_hub_changes(usb_hub_info_t * hub_info_param);
    101104
     105void usb_hub_removed_device(usb_hub_info_t *, uint16_t);
     106void usb_hub_over_current(usb_hub_info_t *, uint16_t);
    102107
    103108int usb_hub_add_device(usb_device_t * usb_dev);
  • uspace/drv/usbhub/usbhub_private.h

    r61257f4 rf8e8738  
    3838
    3939#include "usbhub.h"
    40 #include "usblist.h"
    4140
    4241#include <adt/list.h>
  • uspace/drv/usbmid/explore.c

    r61257f4 rf8e8738  
    4848};
    4949
    50 /** Find starting indexes of all interface descriptors in a configuration.
    51  *
    52  * @param config_descriptor Full configuration descriptor.
    53  * @param config_descriptor_size Size of @p config_descriptor in bytes.
    54  * @param interface_positions Array where to store indexes of interfaces.
    55  * @param interface_count Size of @p interface_positions array.
    56  * @return Number of found interfaces.
    57  * @retval (size_t)-1 Error occured.
    58  */
    59 static size_t find_interface_descriptors(uint8_t *config_descriptor,
    60     size_t config_descriptor_size,
    61     size_t *interface_positions, size_t interface_count)
     50/** Tell whether given interface is already in the list.
     51 *
     52 * @param list List of usbmid_interface_t members to be searched.
     53 * @param interface_no Interface number caller is looking for.
     54 * @return Interface @p interface_no is already present in the list.
     55 */
     56static bool interface_in_list(link_t *list, int interface_no)
    6257{
    63         if (interface_count == 0) {
    64                 return (size_t) -1;
    65         }
    66 
     58        link_t *l;
     59        for (l = list->next; l != list; l = l->next) {
     60                usbmid_interface_t *iface
     61                    = list_get_instance(l, usbmid_interface_t, link);
     62                if (iface->interface_no == interface_no) {
     63                        return true;
     64                }
     65        }
     66
     67        return false;
     68}
     69
     70/** Create list of interfaces from configuration descriptor.
     71 *
     72 * @param config_descriptor Configuration descriptor.
     73 * @param config_descriptor_size Size of configuration descriptor in bytes.
     74 * @param list List where to add the interfaces.
     75 */
     76static void create_interfaces(uint8_t *config_descriptor,
     77    size_t config_descriptor_size, link_t *list)
     78{
    6779        usb_dp_parser_data_t data = {
    6880                .data = config_descriptor,
     
    7587        };
    7688
    77         uint8_t *interface = usb_dp_get_nested_descriptor(&parser, &data,
     89        uint8_t *interface_ptr = usb_dp_get_nested_descriptor(&parser, &data,
    7890            data.data);
    79         if (interface == NULL) {
    80                 return (size_t) -1;
    81         }
    82         if (interface[1] != USB_DESCTYPE_INTERFACE) {
    83                 return (size_t) -1;
    84         }
    85 
    86         size_t found_interfaces = 0;
    87         interface_positions[found_interfaces] = interface - config_descriptor;
    88         found_interfaces++;
    89 
    90         while (interface != NULL) {
    91                 interface = usb_dp_get_sibling_descriptor(&parser, &data,
    92                     data.data, interface);
    93                 if ((interface != NULL)
    94                     && (found_interfaces < interface_count)
    95                     && (interface[1] == USB_DESCTYPE_INTERFACE)) {
    96                         interface_positions[found_interfaces]
    97                             = interface - config_descriptor;
    98                         found_interfaces++;
    99                 }
    100         }
    101 
    102         return found_interfaces;
     91        if (interface_ptr == NULL) {
     92                return;
     93        }
     94
     95        do {
     96                if (interface_ptr[1] != USB_DESCTYPE_INTERFACE) {
     97                        goto next_descriptor;
     98                }
     99
     100                usb_standard_interface_descriptor_t *interface
     101                    = (usb_standard_interface_descriptor_t *) interface_ptr;
     102
     103                /* Skip alternate interfaces. */
     104                if (!interface_in_list(list, interface->interface_number)) {
     105                        usbmid_interface_t *iface
     106                            = malloc(sizeof(usbmid_interface_t));
     107                        if (iface == NULL) {
     108                                break;
     109                        }
     110                        link_initialize(&iface->link);
     111                        iface->fun = NULL;
     112                        iface->interface_no = interface->interface_number;
     113                        iface->interface = interface;
     114
     115                        list_append(&iface->link, list);
     116                }
     117
     118                /* TODO: add the alternatives and create match ids from them
     119                 * as well.
     120                 */
     121
     122next_descriptor:
     123                interface_ptr = usb_dp_get_sibling_descriptor(&parser, &data,
     124                    data.data, interface_ptr);
     125
     126        } while (interface_ptr != NULL);
     127
    103128}
    104129
     
    130155            (usb_standard_configuration_descriptor_t *) config_descriptor_raw;
    131156
    132         size_t *interface_descriptors
    133             = malloc(sizeof(size_t) * config_descriptor->interface_count);
    134         if (interface_descriptors == NULL) {
    135                 usb_log_error("Out of memory (wanted %zuB).\n",
    136                     sizeof(size_t) * config_descriptor->interface_count);
    137                 free(config_descriptor_raw);
    138                 return false;
    139         }
    140         size_t interface_descriptors_count
    141             = find_interface_descriptors(
    142             config_descriptor_raw, config_descriptor_size,
    143             interface_descriptors, config_descriptor->interface_count);
    144 
    145         if (interface_descriptors_count == (size_t) -1) {
    146                 usb_log_error("Problem parsing configuration descriptor.\n");
    147                 free(interface_descriptors);
    148                 return false;
    149         }
    150 
    151157        /* Select the first configuration */
    152158        rc = usb_request_set_configuration(&dev->ctrl_pipe,
     
    155161                usb_log_error("Failed to set device configuration: %s.\n",
    156162                    str_error(rc));
    157                 free(interface_descriptors);
    158                 return false;
    159         }
    160 
     163                return false;
     164        }
    161165
    162166        /* Create control function */
     
    164168        if (ctl_fun == NULL) {
    165169                usb_log_error("Failed to create control function.\n");
    166                 free(interface_descriptors);
    167170                return false;
    168171        }
     
    174177                usb_log_error("Failed to bind control function: %s.\n",
    175178                    str_error(rc));
    176                 free(interface_descriptors);
    177                 return false;
    178         }
    179 
    180         /* Spawn interface children */
    181         size_t i;
    182         for (i = 0; i < interface_descriptors_count; i++) {
    183                 usb_standard_interface_descriptor_t *interface
    184                     = (usb_standard_interface_descriptor_t *)
    185                     (config_descriptor_raw + interface_descriptors[i]);
    186                 usb_log_debug2("Interface descriptor at index %zu (type %d).\n",
    187                     interface_descriptors[i], (int) interface->descriptor_type);
     179                return false;
     180        }
     181
     182        /* Create interface children. */
     183        link_t interface_list;
     184        list_initialize(&interface_list);
     185        create_interfaces(config_descriptor_raw, config_descriptor_size,
     186            &interface_list);
     187
     188        link_t *link;
     189        for (link = interface_list.next; link != &interface_list;
     190            link = link->next) {
     191                usbmid_interface_t *iface = list_get_instance(link,
     192                    usbmid_interface_t, link);
     193
    188194                usb_log_info("Creating child for interface %d (%s).\n",
    189                     (int) interface->interface_number,
    190                     usb_str_class(interface->interface_class));
    191                 rc = usbmid_spawn_interface_child(dev, &dev->descriptors.device,
    192                     interface);
     195                    (int) iface->interface_no,
     196                    usb_str_class(iface->interface->interface_class));
     197
     198                rc = usbmid_spawn_interface_child(dev, iface,
     199                    &dev->descriptors.device, iface->interface);
    193200                if (rc != EOK) {
    194201                        usb_log_error("Failed to create interface child: %s.\n",
  • uspace/drv/usbmid/usbmid.c

    r61257f4 rf8e8738  
    7979};
    8080
    81 /** Create new interface for USB MID device.
    82  *
    83  * @param fun Backing generic DDF device function (representing interface).
    84  * @param iface_no Interface number.
    85  * @return New interface.
    86  * @retval NULL Error occured.
    87  */
    88 usbmid_interface_t *usbmid_interface_create(ddf_fun_t *fun, int iface_no)
    89 {
    90         usbmid_interface_t *iface = malloc(sizeof(usbmid_interface_t));
    91         if (iface == NULL) {
    92                 usb_log_error("Out of memory (wanted %zuB).\n",
    93                     sizeof(usbmid_interface_t));
    94                 return NULL;
    95         }
    96 
    97         iface->fun = fun;
    98         iface->interface_no = iface_no;
    99 
    100         return iface;
    101 }
    102 
    10381
    10482/** Spawn new child device from one interface.
    10583 *
    10684 * @param parent Parent MID device.
     85 * @param iface Interface information.
    10786 * @param device_descriptor Device descriptor.
    10887 * @param interface_descriptor Interface descriptor.
     
    11089 */
    11190int usbmid_spawn_interface_child(usb_device_t *parent,
     91    usbmid_interface_t *iface,
    11292    const usb_standard_device_descriptor_t *device_descriptor,
    11393    const usb_standard_interface_descriptor_t *interface_descriptor)
     
    11595        ddf_fun_t *child = NULL;
    11696        char *child_name = NULL;
    117         usbmid_interface_t *child_as_interface = NULL;
    11897        int rc;
    11998
     
    137116        }
    138117
     118        iface->fun = child;
    139119
    140 
    141         child_as_interface = usbmid_interface_create(child,
    142             (int) interface_descriptor->interface_number);
    143         if (child_as_interface == NULL) {
    144                 rc = ENOMEM;
    145                 goto error_leave;
    146         }
    147 
    148         child->driver_data = child_as_interface;
     120        child->driver_data = iface;
    149121        child->ops = &child_device_ops;
    150122
     
    172144                free(child_name);
    173145        }
    174         if (child_as_interface != NULL) {
    175                 free(child_as_interface);
    176         }
    177146
    178147        return rc;
  • uspace/drv/usbmid/usbmid.h

    r61257f4 rf8e8738  
    3737#define USBMID_H_
    3838
     39#include <adt/list.h>
    3940#include <ddf/driver.h>
    4041#include <usb/usb.h>
     
    4950        /** Function container. */
    5051        ddf_fun_t *fun;
    51 
     52        /** Interface descriptor. */
     53        usb_standard_interface_descriptor_t *interface;
    5254        /** Interface number. */
    5355        int interface_no;
     56        /** List link. */
     57        link_t link;
    5458} usbmid_interface_t;
    5559
    56 usbmid_interface_t *usbmid_interface_create(ddf_fun_t *, int);
    5760bool usbmid_explore_device(usb_device_t *);
    58 int usbmid_spawn_interface_child(usb_device_t *,
     61int usbmid_spawn_interface_child(usb_device_t *, usbmid_interface_t *,
    5962    const usb_standard_device_descriptor_t *,
    6063    const usb_standard_interface_descriptor_t *);
Note: See TracChangeset for help on using the changeset viewer.