Changeset a7e2f0d in mainline


Ignore:
Timestamp:
2011-03-07T18:57:00Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
18e9eeb
Parents:
0d3167e
Message:

Doxygen and other comments

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

Legend:

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

    r0d3167e ra7e2f0d  
    5757
    5858
     59/** Allocates memory and initializes internal data structures.
     60 *
     61 * @param[in] fun DDF function to pass to callback.
     62 * @param[in] target Device and endpoint target of the transaction.
     63 * @param[in] transfer_type Interrupt, Control or Bulk.
     64 * @param[in] max_packet_size maximum allowed size of data packets.
     65 * @param[in] speed Speed of the transaction.
     66 * @param[in] buffer Data source/destination.
     67 * @param[in] size Size of the buffer.
     68 * @param[in] setup_buffer Setup data source (if not NULL)
     69 * @param[in] setup_size Size of setup_buffer (should be always 8)
     70 * @param[in] func_in function to call on inbound transaction completion
     71 * @param[in] func_out function to call on outbound transaction completion
     72 * @param[in] arg additional parameter to func_in or func_out
     73 * @param[in] manager Pointer to toggle management structure.
     74 * @return False, if there is an active TD, true otherwise.
     75 */
    5976batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
    6077    usb_transfer_type_t transfer_type, size_t max_packet_size,
     
    139156}
    140157/*----------------------------------------------------------------------------*/
     158/** Checks batch TDs for activity.
     159 *
     160 * @param[in] instance Batch structure to use.
     161 * @return False, if there is an active TD, true otherwise.
     162 */
    141163bool batch_is_complete(batch_t *instance)
    142164{
     
    172194}
    173195/*----------------------------------------------------------------------------*/
     196/** Prepares control write transaction.
     197 *
     198 * @param[in] instance Batch structure to use.
     199 */
    174200void batch_control_write(batch_t *instance)
    175201{
    176202        assert(instance);
    177203        /* we are data out, we are supposed to provide data */
    178         memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size);
     204        memcpy(instance->transport_buffer, instance->buffer,
     205            instance->buffer_size);
    179206        batch_control(instance, USB_PID_OUT, USB_PID_IN);
    180207        instance->next_step = batch_call_out_and_dispose;
     
    183210}
    184211/*----------------------------------------------------------------------------*/
     212/** Prepares control read transaction.
     213 *
     214 * @param[in] instance Batch structure to use.
     215 */
    185216void batch_control_read(batch_t *instance)
    186217{
     
    192223}
    193224/*----------------------------------------------------------------------------*/
     225/** Prepares interrupt in transaction.
     226 *
     227 * @param[in] instance Batch structure to use.
     228 */
    194229void batch_interrupt_in(batch_t *instance)
    195230{
     
    201236}
    202237/*----------------------------------------------------------------------------*/
     238/** Prepares interrupt out transaction.
     239 *
     240 * @param[in] instance Batch structure to use.
     241 */
    203242void batch_interrupt_out(batch_t *instance)
    204243{
     
    212251}
    213252/*----------------------------------------------------------------------------*/
     253/** Prepares bulk in transaction.
     254 *
     255 * @param[in] instance Batch structure to use.
     256 */
    214257void batch_bulk_in(batch_t *instance)
    215258{
     
    221264}
    222265/*----------------------------------------------------------------------------*/
     266/** Prepares bulk out transaction.
     267 *
     268 * @param[in] instance Batch structure to use.
     269 */
    223270void batch_bulk_out(batch_t *instance)
    224271{
     
    231278}
    232279/*----------------------------------------------------------------------------*/
     280/** Prepares generic data transaction
     281 *
     282 * @param[in] instance Batch structure to use.
     283 * @param[in] pid to use for data packets.
     284 */
    233285void batch_data(batch_t *instance, usb_packet_id pid)
    234286{
     
    269321}
    270322/*----------------------------------------------------------------------------*/
     323/** Prepares generic control transaction
     324 *
     325 * @param[in] instance Batch structure to use.
     326 * @param[in] data_stage to use for data packets.
     327 * @param[in] status_stage to use for data packets.
     328 */
    271329void batch_control(batch_t *instance,
    272330   usb_packet_id data_stage, usb_packet_id status_stage)
     
    317375}
    318376/*----------------------------------------------------------------------------*/
     377/** Prepares data, gets error status and calls callback in.
     378 *
     379 * @param[in] instance Batch structure to use.
     380 */
    319381void batch_call_in(batch_t *instance)
    320382{
     
    323385
    324386        /* we are data in, we need data */
    325         memcpy(instance->buffer, instance->transport_buffer, instance->buffer_size);
     387        memcpy(instance->buffer, instance->transport_buffer,
     388            instance->buffer_size);
    326389
    327390        int err = instance->error;
     
    334397}
    335398/*----------------------------------------------------------------------------*/
     399/** Gets error status and calls callback out.
     400 *
     401 * @param[in] instance Batch structure to use.
     402 */
    336403void batch_call_out(batch_t *instance)
    337404{
     
    346413}
    347414/*----------------------------------------------------------------------------*/
     415/** Prepares data, gets error status, calls callback in and dispose.
     416 *
     417 * @param[in] instance Batch structure to use.
     418 */
    348419void batch_call_in_and_dispose(batch_t *instance)
    349420{
     
    353424}
    354425/*----------------------------------------------------------------------------*/
     426/** Gets error status, calls callback out and dispose.
     427 *
     428 * @param[in] instance Batch structure to use.
     429 */
    355430void batch_call_out_and_dispose(batch_t *instance)
    356431{
     
    360435}
    361436/*----------------------------------------------------------------------------*/
     437/** Correctly disposes all used data structures.
     438 *
     439 * @param[in] instance Batch structure to use.
     440 */
    362441void batch_dispose(batch_t *instance)
    363442{
  • uspace/drv/uhci-hcd/iface.c

    r0d3167e ra7e2f0d  
    4343#include "utils/device_keeper.h"
    4444
     45/** Reserve default address interface function
     46 *
     47 * @param[in] fun DDF function that was called.
     48 * @param[in] speed Speed to associate with the new default address.
     49 * @return Error code.
     50 */
    4551/*----------------------------------------------------------------------------*/
    4652static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
     
    5460}
    5561/*----------------------------------------------------------------------------*/
     62/** Release default address interface function
     63 *
     64 * @param[in] fun DDF function that was called.
     65 * @return Error code.
     66 */
    5667static int release_default_address(ddf_fun_t *fun)
    5768{
     
    6475}
    6576/*----------------------------------------------------------------------------*/
     77/** Request address interface function
     78 *
     79 * @param[in] fun DDF function that was called.
     80 * @param[in] speed Speed to associate with the new default address.
     81 * @param[out] address Place to write a new address.
     82 * @return Error code.
     83 */
    6684static int request_address(ddf_fun_t *fun, usb_speed_t speed,
    6785    usb_address_t *address)
     
    8098}
    8199/*----------------------------------------------------------------------------*/
     100/** Bind address interface function
     101 *
     102 * @param[in] fun DDF function that was called.
     103 * @param[in] address Address of the device
     104 * @param[in] handle Devman handle of the device driver.
     105 * @return Error code.
     106 */
    82107static int bind_address(
    83108  ddf_fun_t *fun, usb_address_t address, devman_handle_t handle)
     
    91116}
    92117/*----------------------------------------------------------------------------*/
     118/** Release address interface function
     119 *
     120 * @param[in] fun DDF function that was called.
     121 * @param[in] address USB address to be released.
     122 * @return Error code.
     123 */
    93124static int release_address(ddf_fun_t *fun, usb_address_t address)
    94125{
     
    101132}
    102133/*----------------------------------------------------------------------------*/
     134/** Interrupt out transaction interface function
     135 *
     136 * @param[in] fun DDF function that was called.
     137 * @param[in] target USB device to write to.
     138 * @param[in] max_packet_size maximum size of data packet the device accepts
     139 * @param[in] data Source of data.
     140 * @param[in] size Size of data source.
     141 * @param[in] callback Function to call on transaction completion
     142 * @param[in] arg Additional for callback function.
     143 * @return Error code.
     144 */
    103145static int interrupt_out(ddf_fun_t *fun, usb_target_t target,
    104146    size_t max_packet_size, void *data, size_t size,
     
    122164}
    123165/*----------------------------------------------------------------------------*/
     166/** Interrupt in transaction interface function
     167 *
     168 * @param[in] fun DDF function that was called.
     169 * @param[in] target USB device to write to.
     170 * @param[in] max_packet_size maximum size of data packet the device accepts
     171 * @param[out] data Data destination.
     172 * @param[in] size Size of data source.
     173 * @param[in] callback Function to call on transaction completion
     174 * @param[in] arg Additional for callback function.
     175 * @return Error code.
     176 */
    124177static int interrupt_in(ddf_fun_t *fun, usb_target_t target,
    125178    size_t max_packet_size, void *data, size_t size,
     
    142195}
    143196/*----------------------------------------------------------------------------*/
     197/** Bulk out transaction interface function
     198 *
     199 * @param[in] fun DDF function that was called.
     200 * @param[in] target USB device to write to.
     201 * @param[in] max_packet_size maximum size of data packet the device accepts
     202 * @param[in] data Source of data.
     203 * @param[in] size Size of data source.
     204 * @param[in] callback Function to call on transaction completion
     205 * @param[in] arg Additional for callback function.
     206 * @return Error code.
     207 */
    144208static int bulk_out(ddf_fun_t *fun, usb_target_t target,
    145209    size_t max_packet_size, void *data, size_t size,
     
    163227}
    164228/*----------------------------------------------------------------------------*/
     229/** Bulk in transaction interface function
     230 *
     231 * @param[in] fun DDF function that was called.
     232 * @param[in] target USB device to write to.
     233 * @param[in] max_packet_size maximum size of data packet the device accepts
     234 * @param[out] data Data destination.
     235 * @param[in] size Size of data source.
     236 * @param[in] callback Function to call on transaction completion
     237 * @param[in] arg Additional for callback function.
     238 * @return Error code.
     239 */
    165240static int bulk_in(ddf_fun_t *fun, usb_target_t target,
    166241    size_t max_packet_size, void *data, size_t size,
     
    183258}
    184259/*----------------------------------------------------------------------------*/
     260/** Control write transaction interface function
     261 *
     262 * @param[in] fun DDF function that was called.
     263 * @param[in] target USB device to write to.
     264 * @param[in] max_packet_size maximum size of data packet the device accepts.
     265 * @param[in] setup_data Data to send with SETUP packet.
     266 * @param[in] setup_size Size of data to send with SETUP packet (should be 8B).
     267 * @param[in] data Source of data.
     268 * @param[in] size Size of data source.
     269 * @param[in] callback Function to call on transaction completion.
     270 * @param[in] arg Additional for callback function.
     271 * @return Error code.
     272 */
    185273static int control_write(ddf_fun_t *fun, usb_target_t target,
    186274    size_t max_packet_size,
     
    208296}
    209297/*----------------------------------------------------------------------------*/
     298/** Control read transaction interface function
     299 *
     300 * @param[in] fun DDF function that was called.
     301 * @param[in] target USB device to write to.
     302 * @param[in] max_packet_size maximum size of data packet the device accepts.
     303 * @param[in] setup_data Data to send with SETUP packet.
     304 * @param[in] setup_size Size of data to send with SETUP packet (should be 8B).
     305 * @param[out] data Source of data.
     306 * @param[in] size Size of data source.
     307 * @param[in] callback Function to call on transaction completion.
     308 * @param[in] arg Additional for callback function.
     309 * @return Error code.
     310 */
    210311static int control_read(ddf_fun_t *fun, usb_target_t target,
    211312    size_t max_packet_size,
  • uspace/drv/uhci-hcd/main.c

    r0d3167e ra7e2f0d  
    6060};
    6161/*----------------------------------------------------------------------------*/
     62/** IRQ handling callback, identifies devic
     63 *
     64 * @param[in] dev DDF instance of the device to use.
     65 * @param[in] iid (Unused).
     66 * @param[in] call Pointer to the call that represents interrupt.
     67 */
    6268static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call)
    6369{
     
    6975}
    7076/*----------------------------------------------------------------------------*/
    71 static int uhci_add_device(ddf_dev_t *device)
     77/** Initializes a new ddf driver instance of UHCI hcd.
     78 *
     79 * @param[in] device DDF instance of the device to initialize.
     80 * @return Error code.
     81 *
     82 * Gets and initialies hardware resources, disables any legacy support,
     83 * and reports root hub device.
     84 */
     85int uhci_add_device(ddf_dev_t *device)
    7286{
    7387        assert(device);
     
    96110        ret = pci_disable_legacy(device);
    97111        CHECK_RET_FREE_HC_RETURN(ret,
    98             "Failed(%d) disable legacy USB: %s.\n", ret, str_error(ret));
     112            "Failed(%d) to disable legacy USB: %s.\n", ret, str_error(ret));
    99113
    100114#if 0
     
    113127
    114128        ret = uhci_init(hcd, device, (void*)io_reg_base, io_reg_size);
    115         CHECK_RET_FREE_HC_RETURN(ret, "Failed(%d) to init uhci-hcd.\n",
    116             ret);
     129        CHECK_RET_FREE_HC_RETURN(ret, "Failed(%d) to init uhci-hcd.\n", ret);
    117130#undef CHECK_RET_FREE_HC_RETURN
    118131
     
    155168}
    156169/*----------------------------------------------------------------------------*/
     170/** Initializes global driver structures (NONE).
     171 *
     172 * @param[in] argc Nmber of arguments in argv vector (ignored).
     173 * @param[in] argv Cmdline argument vector (ignored).
     174 * @return Error code.
     175 *
     176 * Driver debug level is set here.
     177 */
    157178int main(int argc, char *argv[])
    158179{
  • uspace/drv/uhci-hcd/pci.c

    r0d3167e ra7e2f0d  
    6565
    6666        int rc;
    67 
    6867        hw_resource_list_t hw_resources;
    6968        rc = hw_res_get_resource_list(parent_phone, &hw_resources);
     
    118117}
    119118/*----------------------------------------------------------------------------*/
     119/** Calls the PCI driver with a request to enable interrupts
     120 *
     121 * @param[in] device Device asking for interrupts
     122 * @return Error code.
     123 */
    120124int pci_enable_interrupts(ddf_dev_t *device)
    121125{
     
    127131}
    128132/*----------------------------------------------------------------------------*/
     133/** Calls the PCI driver with a request to clear legacy support register
     134 *
     135 * @param[in] device Device asking to disable interrupts
     136 * @return Error code.
     137 */
    129138int pci_disable_legacy(ddf_dev_t *device)
    130139{
  • uspace/drv/uhci-hcd/root_hub.c

    r0d3167e ra7e2f0d  
    4545
    4646/*----------------------------------------------------------------------------*/
    47 static int usb_iface_get_hc_handle_rh_impl(ddf_fun_t *root_hub_fun,
    48     devman_handle_t *handle)
     47/** Gets handle of the respective hc (parent device).
     48 *
     49 * @param[in] root_hub_fun Root hub function seeking hc handle.
     50 * @param[out] handle Place to write the handle.
     51 * @return Error code.
     52 */
     53static int usb_iface_get_hc_handle_rh_impl(
     54    ddf_fun_t *root_hub_fun, devman_handle_t *handle)
    4955{
     56        /* TODO: Can't this use parent pointer? */
    5057        ddf_fun_t *hc_fun = root_hub_fun->driver_data;
    5158        assert(hc_fun != NULL);
     
    5663}
    5764/*----------------------------------------------------------------------------*/
    58 static int usb_iface_get_address_rh_impl(ddf_fun_t *fun, devman_handle_t handle,
    59     usb_address_t *address)
     65/** Gets USB address of the calling device.
     66 *
     67 * @param[in] fun Root hub function.
     68 * @param[in] handle Handle of the device seeking address.
     69 * @param[out] address Place to store found address.
     70 * @return Error code.
     71 */
     72static int usb_iface_get_address_rh_impl(
     73    ddf_fun_t *fun, devman_handle_t handle, usb_address_t *address)
    6074{
     75        /* TODO: What does this do? Is it neccessary? Can't it use implemented
     76         * hc function?*/
    6177        assert(fun);
    6278        ddf_fun_t *hc_fun = fun->driver_data;
     
    6581        assert(hc);
    6682
    67         usb_address_t addr = device_keeper_find(&hc->device_manager,
    68             handle);
     83        usb_address_t addr = device_keeper_find(&hc->device_manager, handle);
    6984        if (addr < 0) {
    7085                return addr;
     
    8398};
    8499/*----------------------------------------------------------------------------*/
     100/** Gets root hub hw resources.
     101 *
     102 * @param[in] fun Root hub function.
     103 * @return Pointer to the resource list used by the root hub.
     104 */
    85105static hw_resource_list_t *get_resource_list(ddf_fun_t *dev)
    86106{
     
    91111        assert(hc);
    92112
    93         //TODO: fix memory leak
     113        /* TODO: fix memory leak */
    94114        hw_resource_list_t *resource_list = malloc(sizeof(hw_resource_list_t));
    95115        assert(resource_list);
  • uspace/drv/uhci-hcd/transfer_list.c

    r0d3167e ra7e2f0d  
    3838#include "transfer_list.h"
    3939
     40static void transfer_list_remove_batch(
     41    transfer_list_t *instance, batch_t *batch);
     42/*----------------------------------------------------------------------------*/
     43/** Initializes transfer list structures.
     44 *
     45 * @param[in] instance Memory place to use.
     46 * @param[in] name Name of te new list.
     47 * @return Error code
     48 *
     49 * Allocates memory for internat queue_head_t structure.
     50 */
    4051int transfer_list_init(transfer_list_t *instance, const char *name)
    4152{
     
    4859                return ENOMEM;
    4960        }
    50         queue_head_init(instance->queue_head);
    5161        instance->queue_head_pa = addr_to_phys(instance->queue_head);
    5262
     
    5767}
    5868/*----------------------------------------------------------------------------*/
     69/** Set the next list in chain.
     70 *
     71 * @param[in] instance List to lead.
     72 * @param[in] next List to append.
     73 * @return Error code
     74 */
    5975void transfer_list_set_next(transfer_list_t *instance, transfer_list_t *next)
    6076{
     
    6783}
    6884/*----------------------------------------------------------------------------*/
     85/** Submits a new transfer batch to list and queue.
     86 *
     87 * @param[in] instance List to use.
     88 * @param[in] batch Transfer batch to submit.
     89 * @return Error code
     90 */
    6991void transfer_list_add_batch(transfer_list_t *instance, batch_t *batch)
    7092{
    7193        assert(instance);
    7294        assert(batch);
    73         usb_log_debug2("Adding batch(%p) to queue %s.\n", batch, instance->name);
     95        usb_log_debug2(
     96            "Adding batch(%p) to queue %s.\n", batch, instance->name);
    7497
    7598        uint32_t pa = (uintptr_t)addr_to_phys(batch->qh);
     
    98121        queue_head_append_qh(last->qh, pa);
    99122        list_append(&batch->link, &instance->batch_list);
     123
    100124        usb_log_debug("Batch(%p) added to queue %s last, first is %p.\n",
    101                 batch, instance->name, first );
     125                batch, instance->name, first);
    102126        fibril_mutex_unlock(&instance->guard);
    103127}
    104128/*----------------------------------------------------------------------------*/
    105 static void transfer_list_remove_batch(
    106     transfer_list_t *instance, batch_t *batch)
     129/** Removes a transfer batch from list and queue.
     130 *
     131 * @param[in] instance List to use.
     132 * @param[in] batch Transfer batch to remove.
     133 * @return Error code
     134 */
     135void transfer_list_remove_batch(transfer_list_t *instance, batch_t *batch)
    107136{
    108137        assert(instance);
     
    110139        assert(instance->queue_head);
    111140        assert(batch->qh);
    112         usb_log_debug2("Removing batch(%p) from queue %s.\n", batch, instance->name);
     141        usb_log_debug2(
     142            "Removing batch(%p) from queue %s.\n", batch, instance->name);
    113143
    114         /* I'm the first one here */
    115144        if (batch->link.prev == &instance->batch_list) {
    116                 usb_log_debug("Batch(%p) removed (FIRST) from queue %s, next element %x.\n",
    117                         batch, instance->name, batch->qh->next_queue);
     145                /* I'm the first one here */
     146                usb_log_debug(
     147                    "Batch(%p) removed (FIRST) from %s, next element %x.\n",
     148                    batch, instance->name, batch->qh->next_queue);
    118149                instance->queue_head->element = batch->qh->next_queue;
    119150        } else {
    120                 usb_log_debug("Batch(%p) removed (NOT FIRST) from queue, next element %x.\n",
    121                         batch, instance->name, batch->qh->next_queue);
    122                 batch_t *prev = list_get_instance(batch->link.prev, batch_t, link);
     151                usb_log_debug(
     152                    "Batch(%p) removed (FIRST:NO) from %s, next element %x.\n",
     153                    batch, instance->name, batch->qh->next_queue);
     154                batch_t *prev =
     155                    list_get_instance(batch->link.prev, batch_t, link);
    123156                prev->qh->next_queue = batch->qh->next_queue;
    124157        }
     
    126159}
    127160/*----------------------------------------------------------------------------*/
     161/** Checks list for finished transfers.
     162 *
     163 * @param[in] instance List to use.
     164 * @return Error code
     165 */
    128166void transfer_list_remove_finished(transfer_list_t *instance)
    129167{
  • uspace/drv/uhci-hcd/uhci.c

    r0d3167e ra7e2f0d  
    6161};
    6262
    63 static int usb_iface_get_address(ddf_fun_t *fun, devman_handle_t handle,
    64     usb_address_t *address)
     63/** Gets USB address of the calling device.
     64 *
     65 * @param[in] fun UHCI hc function.
     66 * @param[in] handle Handle of the device seeking address.
     67 * @param[out] address Place to store found address.
     68 * @return Error code.
     69 */
     70static int usb_iface_get_address(
     71    ddf_fun_t *fun, devman_handle_t handle, usb_address_t *address)
    6572{
    6673        assert(fun);
     
    99106
    100107static bool allowed_usb_packet(
    101         bool low_speed, usb_transfer_type_t, size_t size);
    102 
    103 
     108    bool low_speed, usb_transfer_type_t transfer, size_t size);
     109/*----------------------------------------------------------------------------*/
     110/** Initializes UHCI hcd driver structure
     111 *
     112 * @param[in] instance Memory place to initialize.
     113 * @param[in] dev DDF device.
     114 * @param[in] regs Address of I/O control registers.
     115 * @param[in] size Size of I/O control registers.
     116 * @return Error code.
     117 * @note Should be called only once on any structure.
     118 */
    104119int uhci_init(uhci_t *instance, ddf_dev_t *dev, void *regs, size_t reg_size)
    105120{
     
    156171}
    157172/*----------------------------------------------------------------------------*/
     173/** Initializes UHCI hcd hw resources.
     174 *
     175 * @param[in] instance UHCI structure to use.
     176 */
    158177void uhci_init_hw(uhci_t *instance)
    159178{
    160179        assert(instance);
    161 
    162         /* reset everything, who knows what touched it before us */
    163         pio_write_16(&instance->registers->usbcmd, UHCI_CMD_GLOBAL_RESET);
     180        regs_t *registers = instance->registers;
     181
     182        /* Reset everything, who knows what touched it before us */
     183        pio_write_16(&registers->usbcmd, UHCI_CMD_GLOBAL_RESET);
    164184        async_usleep(10000); /* 10ms according to USB spec */
    165         pio_write_16(&instance->registers->usbcmd, 0);
    166 
    167         /* reset hc, all states and counters */
    168         pio_write_16(&instance->registers->usbcmd, UHCI_CMD_HCRESET);
     185        pio_write_16(&registers->usbcmd, 0);
     186
     187        /* Reset hc, all states and counters */
     188        pio_write_16(&registers->usbcmd, UHCI_CMD_HCRESET);
    169189        do { async_usleep(10); }
    170         while ((pio_read_16(&instance->registers->usbcmd) & UHCI_CMD_HCRESET) != 0);
    171 
    172         /* set framelist pointer */
     190        while ((pio_read_16(&registers->usbcmd) & UHCI_CMD_HCRESET) != 0);
     191
     192        /* Set framelist pointer */
    173193        const uint32_t pa = addr_to_phys(instance->frame_list);
    174         pio_write_32(&instance->registers->flbaseadd, pa);
    175 
    176         /* enable all interrupts, but resume interrupt */
     194        pio_write_32(&registers->flbaseadd, pa);
     195
     196        /* Enable all interrupts, but resume interrupt */
    177197//      pio_write_16(&instance->registers->usbintr,
    178198//          UHCI_INTR_CRC | UHCI_INTR_COMPLETE | UHCI_INTR_SHORT_PACKET);
    179199
    180         uint16_t status = pio_read_16(&instance->registers->usbcmd);
    181         usb_log_warning("Previous command value: %x.\n", status);
     200        uint16_t status = pio_read_16(&registers->usbcmd);
     201        if (status != 0)
     202                usb_log_warning("Previous command value: %x.\n", status);
     203
    182204        /* Start the hc with large(64B) packet FSBR */
    183         pio_write_16(&instance->registers->usbcmd,
     205        pio_write_16(&registers->usbcmd,
    184206            UHCI_CMD_RUN_STOP | UHCI_CMD_MAX_PACKET | UHCI_CMD_CONFIGURE);
    185207}
    186208/*----------------------------------------------------------------------------*/
     209/** Initializes UHCI hcd memory structures.
     210 *
     211 * @param[in] instance UHCI structure to use.
     212 * @return Error code
     213 * @note Should be called only once on any structure.
     214 */
    187215int uhci_init_mem_structures(uhci_t *instance)
    188216{
     
    196224        } else (void) 0
    197225
    198         /* init interrupt code */
     226        /* Init interrupt code */
    199227        instance->interrupt_code.cmds = malloc(sizeof(uhci_cmds));
    200228        int ret = (instance->interrupt_code.cmds == NULL) ? ENOMEM : EOK;
    201         CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to allocate interrupt cmds space.\n");
     229        CHECK_RET_DEST_CMDS_RETURN(ret,
     230            "Failed to allocate interrupt cmds space.\n");
    202231
    203232        {
    204233                irq_cmd_t *interrupt_commands = instance->interrupt_code.cmds;
    205234                memcpy(interrupt_commands, uhci_cmds, sizeof(uhci_cmds));
    206                 interrupt_commands[0].addr = (void*)&instance->registers->usbsts;
    207                 interrupt_commands[1].addr = (void*)&instance->registers->usbsts;
     235                interrupt_commands[0].addr =
     236                    (void*)&instance->registers->usbsts;
     237                interrupt_commands[1].addr =
     238                    (void*)&instance->registers->usbsts;
    208239                instance->interrupt_code.cmdcount =
    209240                    sizeof(uhci_cmds) / sizeof(irq_cmd_t);
    210241        }
    211242
    212         /* init transfer lists */
     243        /* Init transfer lists */
    213244        ret = uhci_init_transfer_lists(instance);
    214         CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to initialize transfer lists.\n");
     245        CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to init transfer lists.\n");
    215246        usb_log_debug("Initialized transfer lists.\n");
    216247
    217         /* frame list initialization */
     248        /* Init USB frame list page*/
    218249        instance->frame_list = get_page();
    219250        ret = instance ? EOK : ENOMEM;
     
    221252        usb_log_debug("Initialized frame list.\n");
    222253
    223         /* initialize all frames to point to the first queue head */
     254        /* Set all frames to point to the first queue head */
    224255        const uint32_t queue =
    225256          instance->transfers_interrupt.queue_head_pa
     
    231262        }
    232263
    233         /* init address keeper(libusb) */
     264        /* Init device keeper*/
    234265        device_keeper_init(&instance->device_manager);
    235266        usb_log_debug("Initialized device manager.\n");
     
    239270}
    240271/*----------------------------------------------------------------------------*/
     272/** Initializes UHCI hcd transfer lists.
     273 *
     274 * @param[in] instance UHCI structure to use.
     275 * @return Error code
     276 * @note Should be called only once on any structure.
     277 */
    241278int uhci_init_transfer_lists(uhci_t *instance)
    242279{
     
    257294        CHECK_RET_CLEAR_RETURN(ret, "Failed to init BULK list.");
    258295
    259         ret = transfer_list_init(&instance->transfers_control_full, "CONTROL_FULL");
     296        ret = transfer_list_init(
     297            &instance->transfers_control_full, "CONTROL_FULL");
    260298        CHECK_RET_CLEAR_RETURN(ret, "Failed to init CONTROL FULL list.");
    261299
    262         ret = transfer_list_init(&instance->transfers_control_slow, "CONTROL_SLOW");
     300        ret = transfer_list_init(
     301            &instance->transfers_control_slow, "CONTROL_SLOW");
    263302        CHECK_RET_CLEAR_RETURN(ret, "Failed to init CONTROL SLOW list.");
    264303
     
    279318#endif
    280319
    281         instance->transfers[0][USB_TRANSFER_INTERRUPT] =
     320        /* Assign pointers to be used during scheduling */
     321        instance->transfers[USB_SPEED_FULL][USB_TRANSFER_INTERRUPT] =
    282322          &instance->transfers_interrupt;
    283         instance->transfers[1][USB_TRANSFER_INTERRUPT] =
     323        instance->transfers[USB_SPEED_LOW][USB_TRANSFER_INTERRUPT] =
    284324          &instance->transfers_interrupt;
    285         instance->transfers[0][USB_TRANSFER_CONTROL] =
     325        instance->transfers[USB_SPEED_FULL][USB_TRANSFER_CONTROL] =
    286326          &instance->transfers_control_full;
    287         instance->transfers[1][USB_TRANSFER_CONTROL] =
     327        instance->transfers[USB_SPEED_LOW][USB_TRANSFER_CONTROL] =
    288328          &instance->transfers_control_slow;
    289         instance->transfers[0][USB_TRANSFER_BULK] =
     329        instance->transfers[USB_SPEED_FULL][USB_TRANSFER_BULK] =
    290330          &instance->transfers_bulk_full;
    291331
     
    294334}
    295335/*----------------------------------------------------------------------------*/
     336/** Schedules batch for execution.
     337 *
     338 * @param[in] instance UHCI structure to use.
     339 * @param[in] batch Transfer batch to schedule.
     340 * @return Error code
     341 */
    296342int uhci_schedule(uhci_t *instance, batch_t *batch)
    297343{
     
    301347        if (!allowed_usb_packet(
    302348            low_speed, batch->transfer_type, batch->max_packet_size)) {
    303                 usb_log_warning("Invalid USB packet specified %s SPEED %d %zu.\n",
     349                usb_log_warning(
     350                    "Invalid USB packet specified %s SPEED %d %zu.\n",
    304351                    low_speed ? "LOW" : "FULL" , batch->transfer_type,
    305352                    batch->max_packet_size);
     
    316363}
    317364/*----------------------------------------------------------------------------*/
     365/** Takes action based on the interrupt cause.
     366 *
     367 * @param[in] instance UHCI structure to use.
     368 * @param[in] status Value of the stsatus regiser at the time of interrupt.
     369 */
    318370void uhci_interrupt(uhci_t *instance, uint16_t status)
    319371{
    320372        assert(instance);
     373        /* TODO: Check interrupt cause here */
    321374        transfer_list_remove_finished(&instance->transfers_interrupt);
    322375        transfer_list_remove_finished(&instance->transfers_control_slow);
     
    325378}
    326379/*----------------------------------------------------------------------------*/
     380/** Polling function, emulates interrupts.
     381 *
     382 * @param[in] arg UHCI structure to use.
     383 * @return EOK
     384 */
    327385int uhci_interrupt_emulator(void* arg)
    328386{
     
    343401}
    344402/*---------------------------------------------------------------------------*/
     403/** Debug function, checks consistency of memory structures.
     404 *
     405 * @param[in] arg UHCI structure to use.
     406 * @return EOK
     407 */
    345408int uhci_debug_checker(void *arg)
    346409{
     
    401464                async_usleep(UHCI_DEBUGER_TIMEOUT);
    402465        }
    403         return 0;
     466        return EOK;
    404467#undef QH
    405468}
    406469/*----------------------------------------------------------------------------*/
     470/** Checks transfer packets, for USB validity
     471 *
     472 * @param[in] low_speed Transfer speed.
     473 * @param[in] transfer Transer type
     474 * @param[in] size Maximum size of used packets
     475 * @return EOK
     476 */
    407477bool allowed_usb_packet(
    408478    bool low_speed, usb_transfer_type_t transfer, size_t size)
  • uspace/drv/uhci-hcd/uhci.h

    r0d3167e ra7e2f0d  
    8484        device_keeper_t device_manager;
    8585
    86         volatile regs_t *registers;
     86        regs_t *registers;
    8787
    8888        link_pointer_t *frame_list;
  • uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.c

    r0d3167e ra7e2f0d  
    3838#include "utils/malloc32.h"
    3939
     40/** Initializes Transfer Descriptor
     41 *
     42 * @param[in] instance Memory place to initialize.
     43 * @param[in] err_count Number of retries hc should attempt.
     44 * @param[in] size Size of data source.
     45 * @param[in] toggle Value of toggle bit.
     46 * @param[in] iso True if TD is for Isochronous transfer.
     47 * @param[in] low_speed Target device's speed.
     48 * @param[in] target Address and endpoint receiving the transfer.
     49 * @param[in] pid Packet identification (SETUP, IN or OUT).
     50 * @param[in] buffer Source of data.
     51 * @param[in] next Net TD in transaction.
     52 * @return Error code.
     53 */
    4054void td_init(td_t *instance, int err_count, size_t size, bool toggle, bool iso,
    41     bool low_speed, usb_target_t target, usb_packet_id pid, void *buffer, td_t *next)
     55    bool low_speed, usb_target_t target, usb_packet_id pid, void *buffer,
     56    td_t *next)
    4257{
    4358        assert(instance);
    4459        assert(size < 1024);
    45         assert((pid == USB_PID_SETUP) || (pid == USB_PID_IN) || (pid == USB_PID_OUT));
     60        assert((pid == USB_PID_SETUP) || (pid == USB_PID_IN)
     61            || (pid == USB_PID_OUT));
    4662
    4763        instance->next = 0
     
    8197}
    8298/*----------------------------------------------------------------------------*/
     99/** Converts TD status into standard error code
     100 *
     101 * @param[in] instance TD structure to use.
     102 * @return Error code.
     103 */
    83104int td_status(td_t *instance)
    84105{
  • uspace/drv/uhci-hcd/utils/device_keeper.c

    r0d3167e ra7e2f0d  
    3939
    4040/*----------------------------------------------------------------------------*/
     41/** Initializes device keeper structure.
     42 *
     43 * @param[in] instance Memory place to initialize.
     44 */
    4145void device_keeper_init(device_keeper_t *instance)
    4246{
     
    5357}
    5458/*----------------------------------------------------------------------------*/
    55 void device_keeper_reserve_default(
    56     device_keeper_t *instance, usb_speed_t speed)
     59/** Attempts to obtain address 0, blocks.
     60 *
     61 * @param[in] instance Device keeper structure to use.
     62 * @param[in] speed Speed of the device requesting default address.
     63 */
     64void device_keeper_reserve_default(device_keeper_t *instance, usb_speed_t speed)
    5765{
    5866        assert(instance);
     
    6775}
    6876/*----------------------------------------------------------------------------*/
     77/** Attempts to obtain address 0, blocks.
     78 *
     79 * @param[in] instance Device keeper structure to use.
     80 * @param[in] speed Speed of the device requesting default address.
     81 */
    6982void device_keeper_release_default(device_keeper_t *instance)
    7083{
     
    7689}
    7790/*----------------------------------------------------------------------------*/
     91/** Checks setup data for signs of toggle reset.
     92 *
     93 * @param[in] instance Device keeper structure to use.
     94 * @param[in] target Device to receive setup packet.
     95 * @param[in] data Setup packet data.
     96 */
    7897void device_keeper_reset_if_need(
    7998    device_keeper_t *instance, usb_target_t target, const unsigned char *data)
     
    84103            || target.address >= USB_ADDRESS_COUNT || target.address < 0
    85104            || !instance->devices[target.address].occupied) {
    86                 goto the_end;
     105                fibril_mutex_unlock(&instance->guard);
     106                return;
    87107        }
    88108
     
    90110        {
    91111        case 0x01: /*clear feature*/
    92                 /* recipient is enpoint, value is zero (ENDPOINT_STALL) */
     112                /* recipient is endpoint, value is zero (ENDPOINT_STALL) */
    93113                if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) {
    94                         /* enpoint number is < 16, thus first byte is enough */
    95                         instance->devices[target.address].toggle_status &= ~(1 << data[4]);
     114                        /* endpoint number is < 16, thus first byte is enough */
     115                        instance->devices[target.address].toggle_status &=
     116                            ~(1 << data[4]);
    96117                }
    97118        break;
     
    102123        break;
    103124        }
    104 the_end:
    105         fibril_mutex_unlock(&instance->guard);
    106 }
    107 /*----------------------------------------------------------------------------*/
     125        fibril_mutex_unlock(&instance->guard);
     126}
     127/*----------------------------------------------------------------------------*/
     128/** Gets current value of endpoint toggle.
     129 *
     130 * @param[in] instance Device keeper structure to use.
     131 * @param[in] target Device and endpoint used.
     132 * @return Error code
     133 */
    108134int device_keeper_get_toggle(device_keeper_t *instance, usb_target_t target)
    109135{
     
    116142                ret = EINVAL;
    117143        } else {
    118                 ret = (instance->devices[target.address].toggle_status >> target.endpoint) & 1;
     144                ret =
     145                    (instance->devices[target.address].toggle_status
     146                        >> target.endpoint) & 1;
    119147        }
    120148        fibril_mutex_unlock(&instance->guard);
     
    122150}
    123151/*----------------------------------------------------------------------------*/
     152/** Sets current value of endpoint toggle.
     153 *
     154 * @param[in] instance Device keeper structure to use.
     155 * @param[in] target Device and endpoint used.
     156 * @param[in] toggle Current toggle value.
     157 * @return Error code.
     158 */
    124159int device_keeper_set_toggle(
    125160    device_keeper_t *instance, usb_target_t target, bool toggle)
     
    144179}
    145180/*----------------------------------------------------------------------------*/
     181/** Gets a free USB address
     182 *
     183 * @param[in] instance Device keeper structure to use.
     184 * @param[in] speed Speed of the device requiring address.
     185 * @return Free address, or error code.
     186 */
    146187usb_address_t device_keeper_request(
    147188    device_keeper_t *instance, usb_speed_t speed)
     
    171212}
    172213/*----------------------------------------------------------------------------*/
     214/** Binds USB address to devman handle.
     215 *
     216 * @param[in] instance Device keeper structure to use.
     217 * @param[in] address Device address
     218 * @param[in] handle Devman handle of the device.
     219 */
    173220void device_keeper_bind(
    174221    device_keeper_t *instance, usb_address_t address, devman_handle_t handle)
     
    183230}
    184231/*----------------------------------------------------------------------------*/
     232/** Releases used USB address.
     233 *
     234 * @param[in] instance Device keeper structure to use.
     235 * @param[in] address Device address
     236 */
    185237void device_keeper_release(device_keeper_t *instance, usb_address_t address)
    186238{
     
    195247}
    196248/*----------------------------------------------------------------------------*/
     249/** Finds USB address associated with the device
     250 *
     251 * @param[in] instance Device keeper structure to use.
     252 * @param[in] handle Devman handle of the device seeking its address.
     253 * @return USB Address, or error code.
     254 */
    197255usb_address_t device_keeper_find(
    198256    device_keeper_t *instance, devman_handle_t handle)
     
    212270}
    213271/*----------------------------------------------------------------------------*/
     272/** Gets speed associated with the address
     273 *
     274 * @param[in] instance Device keeper structure to use.
     275 * @param[in] address Address of the device.
     276 * @return USB speed.
     277 */
    214278usb_speed_t device_keeper_speed(
    215279    device_keeper_t *instance, usb_address_t address)
Note: See TracChangeset for help on using the changeset viewer.