Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 98d7550 in mainline


Ignore:
Timestamp:
2011-05-18T20:18:38Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
7941bd6
Parents:
17fc40c (diff), 030937e (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:

Doxygen and code style fixes, improve error handling in root hub registration

Remove kernel debug output in interrupt handlers accessing memory mapped registers.

Files:
14 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ipc/irq.c

    r17fc40c r98d7550  
    370370        if (AS != irq->driver_as) \
    371371                as_switch(AS, irq->driver_as); \
    372         printf("Copying data from address: %p.\n", va); \
    373372        memcpy_from_uspace(&target, va, (sizeof(target))); \
    374373        if (dstarg) \
     
    381380        if (AS != irq->driver_as) \
    382381                as_switch(AS, irq->driver_as); \
    383         printf("Writing data to address: %p.\n", va); \
    384382        memcpy_to_uspace(va, &val, sizeof(val)); \
    385383} while (0)
     
    457455                        uint32_t val;
    458456                        CMD_MEM_READ(val);
    459                         printf("mem READ value: %x.\n", val);
    460457                        break;
    461458                        }
  • uspace/drv/ohci/batch.c

    r17fc40c r98d7550  
    100100 */
    101101usb_transfer_batch_t * batch_get(ddf_fun_t *fun, endpoint_t *ep,
    102     char *buffer, size_t buffer_size, char* setup_buffer, size_t setup_size,
     102    char *buffer, size_t buffer_size,
     103    const char *setup_buffer, size_t setup_size,
    103104    usbhc_iface_transfer_in_callback_t func_in,
    104105    usbhc_iface_transfer_out_callback_t func_out, void *arg)
     
    120121            ohci_transfer_batch_dispose);
    121122
    122         hcd_endpoint_t *hcd_ep = hcd_endpoint_get(ep);
     123        const hcd_endpoint_t *hcd_ep = hcd_endpoint_get(ep);
    123124        assert(hcd_ep);
    124125
     
    129130        data->td_count =
    130131            ((buffer_size + OHCI_TD_MAX_TRANSFER - 1) / OHCI_TD_MAX_TRANSFER);
     132        /* Control transfer need Setup and Status stage */
    131133        if (ep->transfer_type == USB_TRANSFER_CONTROL) {
    132134                data->td_count += 2;
     
    407409        char *buffer = instance->data_buffer;
    408410        while (remain_size > 0) {
    409                 size_t transfer_size = remain_size > OHCI_TD_MAX_TRANSFER ?
    410                     OHCI_TD_MAX_TRANSFER : remain_size;
     411                const size_t transfer_size = remain_size > OHCI_TD_MAX_TRANSFER
     412                    ? OHCI_TD_MAX_TRANSFER : remain_size;
    411413
    412414                td_init(data->tds[td_current], instance->ep->direction,
  • uspace/drv/ohci/batch.h

    r17fc40c r98d7550  
    4343usb_transfer_batch_t * batch_get(
    4444    ddf_fun_t *fun, endpoint_t *ep, char *buffer, size_t size,
    45     char *setup_buffer, size_t setup_size,
     45    const char *setup_buffer, size_t setup_size,
    4646    usbhc_iface_transfer_in_callback_t func_in,
    4747    usbhc_iface_transfer_out_callback_t func_out,
  • uspace/drv/ohci/endpoint_list.h

    r17fc40c r98d7550  
    4242
    4343/** Structure maintains both OHCI queue and software list of active endpoints.*/
    44 typedef struct endpoint_list
    45 {
     44typedef struct endpoint_list {
    4645        /** Guard against add/remove races */
    4746        fibril_mutex_t guard;
     
    6968
    7069int endpoint_list_init(endpoint_list_t *instance, const char *name);
    71 
    7270void endpoint_list_set_next(endpoint_list_t *instance, endpoint_list_t *next);
    73 
    7471void endpoint_list_add_ep(endpoint_list_t *instance, hcd_endpoint_t *hcd_ep);
    75 
    7672void endpoint_list_remove_ep(endpoint_list_t *instance, hcd_endpoint_t *hcd_ep);
    7773#endif
  • uspace/drv/ohci/hc.c

    r17fc40c r98d7550  
    5151static int hc_init_memory(hc_t *instance);
    5252/*----------------------------------------------------------------------------*/
     53/** Announce OHCI root hub to the DDF
     54 *
     55 * @param[in] instance OHCI driver intance
     56 * @param[in] hub_fun DDF fuction representing OHCI root hub
     57 * @return Error code
     58 */
    5359int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun)
    5460{
     
    5662        assert(hub_fun);
    5763
    58         int ret;
    59 
    60         usb_address_t hub_address =
     64        const usb_address_t hub_address =
    6165            device_keeper_get_free_address(&instance->manager, USB_SPEED_FULL);
    6266        if (hub_address <= 0) {
    63                 usb_log_error("Failed to get OHCI root hub address.\n");
     67                usb_log_error("Failed(%d) to get OHCI root hub address.\n",
     68                    hub_address);
    6469                return hub_address;
    6570        }
     
    6873            &instance->manager, hub_address, hub_fun->handle);
    6974
    70         ret = hc_add_endpoint(instance, hub_address, 0, USB_SPEED_FULL,
     75#define CHECK_RET_RELEASE(ret, message...) \
     76if (ret != EOK) { \
     77        usb_log_error(message); \
     78        hc_remove_endpoint(instance, hub_address, 0, USB_DIRECTION_BOTH); \
     79        usb_device_keeper_release(&instance->manager, hub_address); \
     80        return ret; \
     81} else (void)0
     82
     83        int ret = hc_add_endpoint(instance, hub_address, 0, USB_SPEED_FULL,
    7184            USB_TRANSFER_CONTROL, USB_DIRECTION_BOTH, 64, 0, 0);
    72         if (ret != EOK) {
    73                 usb_log_error("Failed to add OHCI rh endpoint 0.\n");
    74                 usb_device_keeper_release(&instance->manager, hub_address);
    75                 return ret;
    76         }
     85        CHECK_RET_RELEASE(ret, "Failed(%d) to add OHCI rh endpoint 0.\n", ret);
    7786
    7887        char *match_str = NULL;
    7988        /* DDF needs heap allocated string */
    8089        ret = asprintf(&match_str, "usb&class=hub");
    81         if (ret < 0) {
    82                 usb_log_error(
    83                     "Failed(%d) to create root hub match-id string.\n", ret);
    84                 usb_device_keeper_release(&instance->manager, hub_address);
    85                 return ret;
    86         }
     90        ret = ret > 0 ? 0 : ret;
     91        CHECK_RET_RELEASE(ret, "Failed(%d) to create match-id string.\n", ret);
    8792
    8893        ret = ddf_fun_add_match_id(hub_fun, match_str, 100);
    89         if (ret != EOK) {
    90                 usb_log_error("Failed add root hub match-id.\n");
    91         }
     94        CHECK_RET_RELEASE(ret, "Failed(%d) add root hub match-id.\n", ret);
     95
    9296        ret = ddf_fun_bind(hub_fun);
    93         return ret;
    94 }
    95 /*----------------------------------------------------------------------------*/
     97        CHECK_RET_RELEASE(ret, "Failed(%d) to bind root hub function.\n", ret);
     98
     99        return EOK;
     100#undef CHECK_RET_RELEASE
     101}
     102/*----------------------------------------------------------------------------*/
     103/** Initialize OHCI hc driver structure
     104 *
     105 * @param[in] instance Memory place for the structure.
     106 * @param[in] regs Address of the memory mapped I/O registers.
     107 * @param[in] reg_size Size of the memory mapped area.
     108 * @param[in] interrupts True if w interrupts should be used
     109 * @return Error code
     110 */
    96111int hc_init(hc_t *instance, uintptr_t regs, size_t reg_size, bool interrupts)
    97112{
     
    121136#undef CHECK_RET_RETURN
    122137
    123 
    124 //      hc_init_hw(instance);
     138        fibril_mutex_initialize(&instance->guard);
    125139        hc_gain_control(instance);
    126         fibril_mutex_initialize(&instance->guard);
    127140
    128141        rh_init(&instance->rh, instance->registers);
     
    137150}
    138151/*----------------------------------------------------------------------------*/
     152/** Create end register endpoint structures
     153 *
     154 * @param[in] instance OHCI driver structure.
     155 * @param[in] address USB address of the device.
     156 * @param[in] endpoint USB endpoint number.
     157 * @param[in] speed Communication speeed of the device.
     158 * @param[in] type Endpoint's transfer type.
     159 * @param[in] direction Endpoint's direction.
     160 * @param[in] mps Maximum packet size the endpoint accepts.
     161 * @param[in] size Maximum allowed buffer size.
     162 * @param[in] interval Time between transfers(interrupt transfers only).
     163 * @return Error code
     164 */
    139165int hc_add_endpoint(
    140166    hc_t *instance, usb_address_t address, usb_endpoint_t endpoint,
     
    194220}
    195221/*----------------------------------------------------------------------------*/
     222/** Dequeue and delete endpoint structures
     223 *
     224 * @param[in] instance OHCI hc driver structure.
     225 * @param[in] address USB address of the device.
     226 * @param[in] endpoint USB endpoint number.
     227 * @param[in] direction Direction of the endpoint.
     228 * @return Error code
     229 */
    196230int hc_remove_endpoint(hc_t *instance, usb_address_t address,
    197231    usb_endpoint_t endpoint, usb_direction_t direction)
     
    244278}
    245279/*----------------------------------------------------------------------------*/
     280/** Get access to endpoint structures
     281 *
     282 * @param[in] instance OHCI hc driver structure.
     283 * @param[in] address USB address of the device.
     284 * @param[in] endpoint USB endpoint number.
     285 * @param[in] direction Direction of the endpoint.
     286 * @param[out] bw Reserved bandwidth.
     287 * @return Error code
     288 */
    246289endpoint_t * hc_get_endpoint(hc_t *instance, usb_address_t address,
    247290    usb_endpoint_t endpoint, usb_direction_t direction, size_t *bw)
     
    255298}
    256299/*----------------------------------------------------------------------------*/
     300/** Add USB transfer to the schedule.
     301 *
     302 * @param[in] instance OHCI hc driver structure.
     303 * @param[in] batch Batch representing the transfer.
     304 * @return Error code.
     305 */
    257306int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch)
    258307{
     
    261310        assert(batch->ep);
    262311
    263         /* check for root hub communication */
     312        /* Check for root hub communication */
    264313        if (batch->ep->address == instance->rh.address) {
    265314                return rh_request(&instance->rh, batch);
     
    269318        list_append(&batch->link, &instance->pending_batches);
    270319        batch_commit(batch);
    271         switch (batch->ep->transfer_type) {
     320
     321        /* Control and bulk schedules need a kick to start working */
     322        switch (batch->ep->transfer_type)
     323        {
    272324        case USB_TRANSFER_CONTROL:
    273325                instance->registers->command_status |= CS_CLF;
     
    279331                break;
    280332        }
    281 
    282333        fibril_mutex_unlock(&instance->guard);
    283334        return EOK;
    284335}
    285336/*----------------------------------------------------------------------------*/
     337/** Interrupt handling routine
     338 *
     339 * @param[in] instance OHCI hc driver structure.
     340 * @param[in] status Value of the status register at the time of interrupt.
     341 */
    286342void hc_interrupt(hc_t *instance, uint32_t status)
    287343{
     
    322378}
    323379/*----------------------------------------------------------------------------*/
     380/** Check status register regularly
     381 *
     382 * @param[in] instance OHCI hc driver structure.
     383 * @return Error code
     384 */
    324385int interrupt_emulator(hc_t *instance)
    325386{
     
    330391                instance->registers->interrupt_status = status;
    331392                hc_interrupt(instance, status);
    332                 async_usleep(50000);
     393                async_usleep(10000);
    333394        }
    334395        return EOK;
    335396}
    336397/*----------------------------------------------------------------------------*/
     398/** Turn off any (BIOS)driver that might be in control of the device.
     399 *
     400 * @param[in] instance OHCI hc driver structure.
     401 */
    337402void hc_gain_control(hc_t *instance)
    338403{
     
    384449}
    385450/*----------------------------------------------------------------------------*/
     451/** OHCI hw initialization routine.
     452 *
     453 * @param[in] instance OHCI hc driver structure.
     454 */
    386455void hc_start_hw(hc_t *instance)
    387456{
     
    451520}
    452521/*----------------------------------------------------------------------------*/
     522/** Initialize schedule queues
     523 *
     524 * @param[in] instance OHCI hc driver structure
     525 * @return Error code
     526 */
    453527int hc_init_transfer_lists(hc_t *instance)
    454528{
     
    466540                endpoint_list_fini(&instance->lists[USB_TRANSFER_BULK]); \
    467541        } \
     542        return ret; \
    468543} while (0)
    469544
     
    479554}
    480555/*----------------------------------------------------------------------------*/
     556/** Initialize memory structures used by the OHCI hcd.
     557 *
     558 * @param[in] instance OHCI hc driver structure.
     559 * @return Error code.
     560 */
    481561int hc_init_memory(hc_t *instance)
    482562{
     
    505585        /* Init interrupt code */
    506586        instance->interrupt_code.cmds = instance->interrupt_commands;
     587        instance->interrupt_code.cmdcount = OHCI_NEEDED_IRQ_COMMANDS;
    507588        {
    508589                /* Read status register */
     
    524605                instance->interrupt_commands[2].srcarg = 2;
    525606
    526                 /* Write clean status register */
     607                /* Write-clean status register */
    527608                instance->interrupt_commands[3].cmd = CMD_MEM_WRITE_A_32;
    528609                instance->interrupt_commands[3].srcarg = 1;
     
    532613                /* Accept interrupt */
    533614                instance->interrupt_commands[4].cmd = CMD_ACCEPT;
    534 
    535                 instance->interrupt_code.cmdcount = OHCI_NEEDED_IRQ_COMMANDS;
    536615        }
    537616
  • uspace/drv/ohci/hc.h

    r17fc40c r98d7550  
    5353#define OHCI_NEEDED_IRQ_COMMANDS 5
    5454
     55/** Main OHCI drier structure */
    5556typedef struct hc {
     57        /** USB bus driver, devices and addresses */
     58        usb_device_keeper_t manager;
     59        /** USB bus driver, endpoints */
     60        usb_endpoint_manager_t ep_manager;
     61
     62        /** Memory mapped I/O registers area */
    5663        ohci_regs_t *registers;
     64        /** Host controller communication area structure */
    5765        hcca_t *hcca;
    5866
    59         usb_address_t rh_address;
    60         rh_t rh;
    61 
     67        /** Transfer schedules */
    6268        endpoint_list_t lists[4];
     69        /** List of active transfers */
    6370        link_t pending_batches;
    6471
    65         usb_device_keeper_t manager;
    66         usb_endpoint_manager_t ep_manager;
     72        /** Fibril for periodic checks if interrupts can't be used */
    6773        fid_t interrupt_emulator;
     74
     75        /** Guards schedule and endpoint manipulation */
    6876        fibril_mutex_t guard;
    6977
     
    7381        /** Commands that form interrupt code */
    7482        irq_cmd_t interrupt_commands[OHCI_NEEDED_IRQ_COMMANDS];
     83
     84        /** USB hub emulation structure */
     85        rh_t rh;
    7586} hc_t;
    7687
    7788int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun);
    78 
    7989int hc_init(hc_t *instance, uintptr_t regs, size_t reg_size, bool interrupts);
    80 
    8190void hc_start_hw(hc_t *instance);
    8291
     
    8594 * @param[in] instance Host controller structure to use.
    8695 */
    87 static inline void hc_fini(hc_t *instance) { /* TODO: implement*/ };
     96static inline void hc_fini(hc_t *instance)
     97        { /* TODO: implement*/ };
    8898
    8999int hc_add_endpoint(hc_t *instance, usb_address_t address, usb_endpoint_t ep,
    90100    usb_speed_t speed, usb_transfer_type_t type, usb_direction_t direction,
    91101    size_t max_packet_size, size_t size, unsigned interval);
    92 
    93102int hc_remove_endpoint(hc_t *instance, usb_address_t address,
    94103    usb_endpoint_t endpoint, usb_direction_t direction);
    95 
    96104endpoint_t * hc_get_endpoint(hc_t *instance, usb_address_t address,
    97105    usb_endpoint_t endpoint, usb_direction_t direction, size_t *bw);
    98106
    99107int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch);
    100 
    101108void hc_interrupt(hc_t *instance, uint32_t status);
    102109
     
    107114 */
    108115static inline hc_t * fun_to_hc(ddf_fun_t *fun)
    109         { return (hc_t*)fun->driver_data; }
     116        { return fun->driver_data; }
    110117#endif
    111118/**
  • uspace/drv/ohci/hcd_endpoint.c

    r17fc40c r98d7550  
    3535#include "hcd_endpoint.h"
    3636
     37/** Callback to set toggle on ED.
     38 *
     39 * @param[in] hcd_ep hcd endpoint structure
     40 * @param[in] toggle new value of toggle bit
     41 */
    3742static void hcd_ep_toggle_set(void *hcd_ep, int toggle)
    3843{
     
    4247        ed_toggle_set(instance->ed, toggle);
    4348}
     49/*----------------------------------------------------------------------------*/
     50/** Callback to get value of toggle bit.
     51 *
     52 * @param[in] hcd_ep hcd endpoint structure
     53 * @return Current value of toggle bit.
     54 */
    4455static int hcd_ep_toggle_get(void *hcd_ep)
    4556{
     
    4960        return ed_toggle_get(instance->ed);
    5061}
    51 
    52 
     62/*----------------------------------------------------------------------------*/
     63/** Creates new hcd endpoint representation.
     64 *
     65 * @param[in] ep USBD endpoint structure
     66 * @return pointer to a new hcd endpoint structure, NULL on failure.
     67 */
    5368hcd_endpoint_t * hcd_endpoint_assign(endpoint_t *ep)
    5469{
     
    7893}
    7994/*----------------------------------------------------------------------------*/
    80 hcd_endpoint_t * hcd_endpoint_get(endpoint_t *ep)
    81 {
    82         assert(ep);
    83         return ep->hc_data.data;
    84 }
    85 /*----------------------------------------------------------------------------*/
     95/** Disposes assigned hcd endpoint structure
     96 *
     97 * @param[in] ep USBD endpoint structure
     98 */
    8699void hcd_endpoint_clear(endpoint_t *ep)
    87100{
  • uspace/drv/ohci/hcd_endpoint.h

    r17fc40c r98d7550  
    4242#include "hw_struct/transfer_descriptor.h"
    4343
    44 typedef struct hcd_endpoint
    45 {
     44/** Connector structure linking ED to to prepared TD. */
     45typedef struct hcd_endpoint {
     46        /** OHCI endpoint descriptor */
    4647        ed_t *ed;
     48        /** Currently enqueued transfer descriptor */
    4749        td_t *td;
     50        /** Linked list used by driver software */
    4851        link_t link;
    4952} hcd_endpoint_t;
    5053
    5154hcd_endpoint_t * hcd_endpoint_assign(endpoint_t *ep);
     55void hcd_endpoint_clear(endpoint_t *ep);
    5256
    53 hcd_endpoint_t * hcd_endpoint_get(endpoint_t *ep);
     57/** Get and convert assigned hcd_endpoint_t structure
     58 * @param[in] ep USBD endpoint structure.
     59 * @return Pointer to assigned hcd endpoint structure
     60 */
     61static inline hcd_endpoint_t * hcd_endpoint_get(endpoint_t *ep)
     62{
     63        assert(ep);
     64        return ep->hc_data.data;
     65}
    5466
    55 void hcd_endpoint_clear(endpoint_t *ep);
    5667#endif
    5768/**
  • uspace/drv/ohci/ohci_regs.h

    r17fc40c r98d7550  
    3636#include <stdint.h>
    3737
    38 typedef struct ohci_regs
    39 {
     38/** OHCI memory mapped registers structure */
     39typedef struct ohci_regs {
    4040        const volatile uint32_t revision;
    4141        volatile uint32_t control;
  • uspace/drv/uhci-hcd/batch.c

    r17fc40c r98d7550  
    9595 */
    9696usb_transfer_batch_t * batch_get(ddf_fun_t *fun, endpoint_t *ep,
    97     char *buffer, size_t buffer_size, char* setup_buffer, size_t setup_size,
     97    char *buffer, size_t buffer_size,
     98    const char* setup_buffer, size_t setup_size,
    9899    usbhc_iface_transfer_in_callback_t func_in,
    99100    usbhc_iface_transfer_out_callback_t func_out, void *arg)
  • uspace/drv/uhci-hcd/batch.h

    r17fc40c r98d7550  
    4545usb_transfer_batch_t * batch_get(
    4646    ddf_fun_t *fun, endpoint_t *ep, char *buffer, size_t size,
    47     char *setup_buffer, size_t setup_size,
     47    const char *setup_buffer, size_t setup_size,
    4848    usbhc_iface_transfer_in_callback_t func_in,
    4949    usbhc_iface_transfer_out_callback_t func_out,
     
    5555
    5656void batch_control_write(usb_transfer_batch_t *instance);
    57 
    5857void batch_control_read(usb_transfer_batch_t *instance);
    5958
    6059void batch_interrupt_in(usb_transfer_batch_t *instance);
    61 
    6260void batch_interrupt_out(usb_transfer_batch_t *instance);
    6361
    6462void batch_bulk_in(usb_transfer_batch_t *instance);
    65 
    6663void batch_bulk_out(usb_transfer_batch_t *instance);
    6764
  • uspace/drv/uhci-hcd/hc.c

    r17fc40c r98d7550  
    5757static int hc_debug_checker(void *arg);
    5858/*----------------------------------------------------------------------------*/
    59 /** Initialize UHCI hcd driver structure
     59/** Initialize UHCI hc driver structure
    6060 *
    6161 * @param[in] instance Memory place to initialize.
  • uspace/drv/uhci-hcd/hc.h

    r17fc40c r98d7550  
    9595#define UHCI_NEEDED_IRQ_COMMANDS 5
    9696
    97 /* Main HC driver structure */
     97/** Main UHCI driver structure */
    9898typedef struct hc {
    9999        /** USB bus driver, devices and addresses */
  • uspace/drv/uhci-hcd/transfer_list.h

    r17fc40c r98d7550  
    4343 * of currently executed transfers
    4444 */
    45 typedef struct transfer_list
    46 {
     45typedef struct transfer_list {
    4746        /** Guard against multiple add/remove races */
    4847        fibril_mutex_t guard;
Note: See TracChangeset for help on using the changeset viewer.