Changeset 15d3b54 in mainline


Ignore:
Timestamp:
2011-03-14T21:24:02Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fcf07e6
Parents:
c69209d (diff), 9370884 (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 comments, enable hw interrupts if possible

Location:
uspace
Files:
28 edited

Legend:

Unmodified
Added
Removed
  • uspace/doc/doxygroups.h

    rc69209d r15d3b54  
    253253         * @defgroup drvusbuhci UHCI driver
    254254         * @ingroup usb
    255          * @brief Driver for USB host controller UHCI.
     255         * @brief Drivers for USB UHCI host controller and root hub.
     256         */
     257
     258        /**
     259         * @defgroup drvusbuhcirh UHCI root hub driver
     260         * @ingroup drvusbuhci
     261         * @brief Driver for UHCI complaint root hub.
     262         */
     263
     264        /**
     265         * @defgroup drvusbuhcirh UHCI host controller driver
     266         * @ingroup drvusbuhci
     267         * @brief Driver for UHCI complaint USB host controller.
    256268         */
    257269
  • uspace/drv/ehci-hcd/main.c

    rc69209d r15d3b54  
    2727 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828 */
    29 /** @addtogroup usbdrvehci
     29/** @addtogroup drvusbehci
    3030 * @{
    3131 */
  • uspace/drv/uhci-hcd/batch.c

    rc69209d r15d3b54  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb
     28/** @addtogroup drvusbuhcihc
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI driver
     32 * @brief UHCI driver USB transaction structure
    3333 */
    3434#include <errno.h>
     
    4444
    4545#define DEFAULT_ERROR_COUNT 3
    46 
    47 static int batch_schedule(batch_t *instance);
    4846
    4947static void batch_control(batch_t *instance,
     
    5452static void batch_call_in_and_dispose(batch_t *instance);
    5553static void batch_call_out_and_dispose(batch_t *instance);
    56 static void batch_dispose(batch_t *instance);
    57 
    58 
    59 /** Allocates memory and initializes internal data structures.
     54
     55
     56/** Allocate memory and initialize internal data structure.
    6057 *
    6158 * @param[in] fun DDF function to pass to callback.
     
    7269 * @param[in] arg additional parameter to func_in or func_out
    7370 * @param[in] manager Pointer to toggle management structure.
    74  * @return False, if there is an active TD, true otherwise.
     71 * @return Valid pointer if all substructures were successfully created,
     72 * NULL otherwise.
     73 *
     74 * Determines the number of needed packets (TDs). Prepares a transport buffer
     75 * (that is accessible by the hardware). Initializes parameters needed for the
     76 * transaction and callback.
    7577 */
    7678batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
     
    151153}
    152154/*----------------------------------------------------------------------------*/
    153 /** Checks batch TDs for activity.
     155/** Check batch TDs for activity.
    154156 *
    155157 * @param[in] instance Batch structure to use.
    156158 * @return False, if there is an active TD, true otherwise.
     159 *
     160 * Walk all TDs. Stop with false if there is an active one (it is to be
     161 * processed). Stop with true if an error is found. Return true if the last TS
     162 * is reached.
    157163 */
    158164bool batch_is_complete(batch_t *instance)
     
    193199 *
    194200 * @param[in] instance Batch structure to use.
     201 *
     202 * Uses genercir control function with pids OUT and IN.
    195203 */
    196204void batch_control_write(batch_t *instance)
    197205{
    198206        assert(instance);
    199         /* we are data out, we are supposed to provide data */
     207        /* We are data out, we are supposed to provide data */
    200208        memcpy(instance->transport_buffer, instance->buffer,
    201209            instance->buffer_size);
     
    203211        instance->next_step = batch_call_out_and_dispose;
    204212        usb_log_debug("Batch(%p) CONTROL WRITE initialized.\n", instance);
    205         batch_schedule(instance);
    206213}
    207214/*----------------------------------------------------------------------------*/
     
    209216 *
    210217 * @param[in] instance Batch structure to use.
     218 *
     219 * Uses generic control with pids IN and OUT.
    211220 */
    212221void batch_control_read(batch_t *instance)
     
    216225        instance->next_step = batch_call_in_and_dispose;
    217226        usb_log_debug("Batch(%p) CONTROL READ initialized.\n", instance);
    218         batch_schedule(instance);
    219 }
    220 /*----------------------------------------------------------------------------*/
    221 /** Prepares interrupt in transaction.
    222  *
    223  * @param[in] instance Batch structure to use.
     227}
     228/*----------------------------------------------------------------------------*/
     229/** Prepare interrupt in transaction.
     230 *
     231 * @param[in] instance Batch structure to use.
     232 *
     233 * Data transaction with PID_IN.
    224234 */
    225235void batch_interrupt_in(batch_t *instance)
     
    229239        instance->next_step = batch_call_in_and_dispose;
    230240        usb_log_debug("Batch(%p) INTERRUPT IN initialized.\n", instance);
    231         batch_schedule(instance);
    232 }
    233 /*----------------------------------------------------------------------------*/
    234 /** Prepares interrupt out transaction.
    235  *
    236  * @param[in] instance Batch structure to use.
     241}
     242/*----------------------------------------------------------------------------*/
     243/** Prepare interrupt out transaction.
     244 *
     245 * @param[in] instance Batch structure to use.
     246 *
     247 * Data transaction with PID_OUT.
    237248 */
    238249void batch_interrupt_out(batch_t *instance)
    239250{
    240251        assert(instance);
    241         /* we are data out, we are supposed to provide data */
     252        /* We are data out, we are supposed to provide data */
    242253        memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size);
    243254        batch_data(instance, USB_PID_OUT);
    244255        instance->next_step = batch_call_out_and_dispose;
    245256        usb_log_debug("Batch(%p) INTERRUPT OUT initialized.\n", instance);
    246         batch_schedule(instance);
    247 }
    248 /*----------------------------------------------------------------------------*/
    249 /** Prepares bulk in transaction.
    250  *
    251  * @param[in] instance Batch structure to use.
     257}
     258/*----------------------------------------------------------------------------*/
     259/** Prepare bulk in transaction.
     260 *
     261 * @param[in] instance Batch structure to use.
     262 *
     263 * Data transaction with PID_IN.
    252264 */
    253265void batch_bulk_in(batch_t *instance)
     
    257269        instance->next_step = batch_call_in_and_dispose;
    258270        usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
    259         batch_schedule(instance);
    260 }
    261 /*----------------------------------------------------------------------------*/
    262 /** Prepares bulk out transaction.
    263  *
    264  * @param[in] instance Batch structure to use.
     271}
     272/*----------------------------------------------------------------------------*/
     273/** Prepare bulk out transaction.
     274 *
     275 * @param[in] instance Batch structure to use.
     276 *
     277 * Data transaction with PID_OUT.
    265278 */
    266279void batch_bulk_out(batch_t *instance)
    267280{
    268281        assert(instance);
     282        /* We are data out, we are supposed to provide data */
    269283        memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size);
    270284        batch_data(instance, USB_PID_OUT);
    271285        instance->next_step = batch_call_out_and_dispose;
    272286        usb_log_debug("Batch(%p) BULK OUT initialized.\n", instance);
    273         batch_schedule(instance);
    274 }
    275 /*----------------------------------------------------------------------------*/
    276 /** Prepares generic data transaction
     287}
     288/*----------------------------------------------------------------------------*/
     289/** Prepare generic data transaction
    277290 *
    278291 * @param[in] instance Batch structure to use.
    279292 * @param[in] pid to use for data packets.
     293 *
     294 * Packets with alternating toggle bit and supplied pid value.
     295 * The last packet is marked with IOC flag.
    280296 */
    281297void batch_data(batch_t *instance, usb_packet_id pid)
     
    318334}
    319335/*----------------------------------------------------------------------------*/
    320 /** Prepares generic control transaction
     336/** Prepare generic control transaction
    321337 *
    322338 * @param[in] instance Batch structure to use.
    323339 * @param[in] data_stage to use for data packets.
    324340 * @param[in] status_stage to use for data packets.
     341 *
     342 * Setup stage with toggle 0 and USB_PID_SETUP.
     343 * Data stage with alternating toggle and pid supplied by parameter.
     344 * Status stage with toggle 1 and pid supplied by parameter.
     345 * The last packet is marked with IOC.
    325346 */
    326347void batch_control(batch_t *instance,
     
    371392}
    372393/*----------------------------------------------------------------------------*/
    373 /** Prepares data, gets error status and calls callback in.
    374  *
    375  * @param[in] instance Batch structure to use.
     394/** Prepare data, get error status and call callback in.
     395 *
     396 * @param[in] instance Batch structure to use.
     397 * Copies data from transport buffer, and calls callback with appropriate
     398 * parameters.
    376399 */
    377400void batch_call_in(batch_t *instance)
     
    380403        assert(instance->callback_in);
    381404
    382         /* we are data in, we need data */
     405        /* We are data in, we need data */
    383406        memcpy(instance->buffer, instance->transport_buffer,
    384407            instance->buffer_size);
     
    393416}
    394417/*----------------------------------------------------------------------------*/
    395 /** Gets error status and calls callback out.
     418/** Get error status and call callback out.
    396419 *
    397420 * @param[in] instance Batch structure to use.
     
    409432}
    410433/*----------------------------------------------------------------------------*/
    411 /** Prepares data, gets error status, calls callback in and dispose.
     434/** Helper function calls callback and correctly disposes of batch structure.
    412435 *
    413436 * @param[in] instance Batch structure to use.
     
    420443}
    421444/*----------------------------------------------------------------------------*/
    422 /** Gets error status, calls callback out and dispose.
     445/** Helper function calls callback and correctly disposes of batch structure.
    423446 *
    424447 * @param[in] instance Batch structure to use.
     
    431454}
    432455/*----------------------------------------------------------------------------*/
    433 /** Correctly disposes all used data structures.
     456/** Correctly dispose all used data structures.
    434457 *
    435458 * @param[in] instance Batch structure to use.
     
    446469        free(instance);
    447470}
    448 /*----------------------------------------------------------------------------*/
    449 int batch_schedule(batch_t *instance)
    450 {
    451         assert(instance);
    452         uhci_hc_t *hc = fun_to_uhci_hc(instance->fun);
    453         assert(hc);
    454         return uhci_hc_schedule(hc, instance);
    455 }
    456471/**
    457472 * @}
  • uspace/drv/uhci-hcd/batch.h

    rc69209d r15d3b54  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb
     28/** @addtogroup drvusbuhcihc
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI driver
     32 * @brief UHCI driver USB transaction structure
    3333 */
    3434#ifndef DRV_UHCI_BATCH_H
     
    7878                );
    7979
     80void batch_dispose(batch_t *instance);
     81
    8082bool batch_is_complete(batch_t *instance);
    8183
  • uspace/drv/uhci-hcd/iface.c

    rc69209d r15d3b54  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb
     28/** @addtogroup drvusbuhcihc
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI driver
     32 * @brief UHCI driver hc interface implementation
    3333 */
    3434#include <ddf/driver.h>
     
    161161                return ENOMEM;
    162162        batch_interrupt_out(batch);
     163        const int ret = uhci_hc_schedule(hc, batch);
     164        if (ret != EOK) {
     165                batch_dispose(batch);
     166                return ret;
     167        }
    163168        return EOK;
    164169}
     
    192197                return ENOMEM;
    193198        batch_interrupt_in(batch);
     199        const int ret = uhci_hc_schedule(hc, batch);
     200        if (ret != EOK) {
     201                batch_dispose(batch);
     202                return ret;
     203        }
    194204        return EOK;
    195205}
     
    224234                return ENOMEM;
    225235        batch_bulk_out(batch);
     236        const int ret = uhci_hc_schedule(hc, batch);
     237        if (ret != EOK) {
     238                batch_dispose(batch);
     239                return ret;
     240        }
    226241        return EOK;
    227242}
     
    255270                return ENOMEM;
    256271        batch_bulk_in(batch);
     272        const int ret = uhci_hc_schedule(hc, batch);
     273        if (ret != EOK) {
     274                batch_dispose(batch);
     275                return ret;
     276        }
    257277        return EOK;
    258278}
     
    293313        device_keeper_reset_if_need(&hc->device_manager, target, setup_data);
    294314        batch_control_write(batch);
     315        const int ret = uhci_hc_schedule(hc, batch);
     316        if (ret != EOK) {
     317                batch_dispose(batch);
     318                return ret;
     319        }
    295320        return EOK;
    296321}
     
    327352                return ENOMEM;
    328353        batch_control_read(batch);
     354        const int ret = uhci_hc_schedule(hc, batch);
     355        if (ret != EOK) {
     356                batch_dispose(batch);
     357                return ret;
     358        }
    329359        return EOK;
    330360}
  • uspace/drv/uhci-hcd/iface.h

    rc69209d r15d3b54  
    2727 */
    2828
    29 /** @addtogroup usb
     29/** @addtogroup drvusbuhcihc
    3030 * @{
    3131 */
    3232/** @file
    33  * @brief UHCI driver
     33 * @brief UHCI driver iface
    3434 */
    3535#ifndef DRV_UHCI_IFACE_H
  • uspace/drv/uhci-hcd/main.c

    rc69209d r15d3b54  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb
     28/** @addtogroup drvusbuhcihc
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI driver
     32 * @brief UHCI driver initialization
    3333 */
    3434#include <ddf/driver.h>
     
    5555};
    5656/*----------------------------------------------------------------------------*/
    57 /** Initializes a new ddf driver instance for uhci hc and hub.
     57/** Initialize a new ddf driver instance for uhci hc and hub.
    5858 *
    5959 * @param[in] device DDF instance of the device to initialize.
    6060 * @return Error code.
    61  *
    62  * Gets and initialies hardware resources, disables any legacy support,
    63  * and reports root hub device.
    6461 */
    6562int uhci_add_device(ddf_dev_t *device)
     
    8279}
    8380/*----------------------------------------------------------------------------*/
    84 /** Initializes global driver structures (NONE).
     81/** Initialize global driver structures (NONE).
    8582 *
    8683 * @param[in] argc Nmber of arguments in argv vector (ignored).
     
    9289int main(int argc, char *argv[])
    9390{
    94         sleep(3);
     91        sleep(3); /* TODO: remove in final version */
    9592        usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
    9693
  • uspace/drv/uhci-hcd/pci.c

    rc69209d r15d3b54  
    2727 */
    2828/**
    29  * @addtogroup drvusbuhci
     29 * @addtogroup drvusbuhcihc
    3030 * @{
    3131 */
     
    117117}
    118118/*----------------------------------------------------------------------------*/
    119 /** Calls the PCI driver with a request to enable interrupts
     119/** Call the PCI driver with a request to enable interrupts
    120120 *
    121121 * @param[in] device Device asking for interrupts
     
    131131}
    132132/*----------------------------------------------------------------------------*/
    133 /** Calls the PCI driver with a request to clear legacy support register
     133/** Call the PCI driver with a request to clear legacy support register
    134134 *
    135135 * @param[in] device Device asking to disable interrupts
  • uspace/drv/uhci-hcd/pci.h

    rc69209d r15d3b54  
    2727 */
    2828
    29 /** @addtogroup drvusbuhci
     29/** @addtogroup drvusbuhcihc
    3030 * @{
    3131 */
    3232/** @file
    33  * @brief UHCI driver
     33 * @brief UHCI driver PCI helper functions
    3434 */
    3535#ifndef DRV_UHCI_PCI_H
  • uspace/drv/uhci-hcd/transfer_list.c

    rc69209d r15d3b54  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb
     28/** @addtogroup drvusbuhcihc
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI driver
     32 * @brief UHCI driver transfer list implementation
    3333 */
    3434#include <errno.h>
    35 
    3635#include <usb/debug.h>
    3736
     
    4140    transfer_list_t *instance, batch_t *batch);
    4241/*----------------------------------------------------------------------------*/
    43 /** Initializes transfer list structures.
     42/** Initialize transfer list structures.
    4443 *
    4544 * @param[in] instance Memory place to use.
    46  * @param[in] name Name of te new list.
     45 * @param[in] name Name of the new list.
    4746 * @return Error code
    4847 *
     
    6665}
    6766/*----------------------------------------------------------------------------*/
    68 /** Set the next list in chain.
     67/** Set the next list in transfer list chain.
    6968 *
    7069 * @param[in] instance List to lead.
     
    7271 * @return Error code
    7372 *
    74  * Does not check whether there was a next list already.
     73 * Does not check whether this replaces an existing list .
    7574 */
    7675void transfer_list_set_next(transfer_list_t *instance, transfer_list_t *next)
     
    8079        if (!instance->queue_head)
    8180                return;
    82         /* set both next and element to point to the same QH */
     81        /* Set both next and element to point to the same QH */
    8382        qh_set_next_qh(instance->queue_head, next->queue_head_pa);
    8483        qh_set_element_qh(instance->queue_head, next->queue_head_pa);
    8584}
    8685/*----------------------------------------------------------------------------*/
    87 /** Submits a new transfer batch to list and queue.
     86/** Submit transfer batch to the list and queue.
    8887 *
    8988 * @param[in] instance List to use.
    9089 * @param[in] batch Transfer batch to submit.
    9190 * @return Error code
     91 *
     92 * The batch is added to the end of the list and queue.
    9293 */
    9394void transfer_list_add_batch(transfer_list_t *instance, batch_t *batch)
     
    106107        fibril_mutex_lock(&instance->guard);
    107108
     109        /* Add to the hardware queue. */
    108110        if (list_empty(&instance->batch_list)) {
    109111                /* There is nothing scheduled */
     
    117119                qh_set_next_qh(last->qh, pa);
    118120        }
     121        /* Add to the driver list */
    119122        list_append(&batch->link, &instance->batch_list);
    120123
     
    126129}
    127130/*----------------------------------------------------------------------------*/
    128 /** Removes a transfer batch from the list and queue.
     131/** Remove a transfer batch from the list and queue.
    129132 *
    130133 * @param[in] instance List to use.
     
    144147
    145148        const char * pos = NULL;
     149        /* Remove from the hardware queue */
    146150        if (batch->link.prev == &instance->batch_list) {
    147151                /* I'm the first one here */
     
    154158                pos = "NOT FIRST";
    155159        }
     160        /* Remove from the driver list */
    156161        list_remove(&batch->link);
    157162        usb_log_debug("Batch(%p) removed (%s) from %s, next element %x.\n",
     
    159164}
    160165/*----------------------------------------------------------------------------*/
    161 /** Checks list for finished batches.
     166/** Check list for finished batches.
    162167 *
    163168 * @param[in] instance List to use.
    164169 * @return Error code
     170 *
     171 * Creates a local list of finished batches and calls next_step on each and
     172 * every one. This is safer because next_step may theoretically access
     173 * this transfer list leading to the deadlock if its done inline.
    165174 */
    166175void transfer_list_remove_finished(transfer_list_t *instance)
     
    177186
    178187                if (batch_is_complete(batch)) {
     188                        /* Save for post-processing */
    179189                        transfer_list_remove_batch(instance, batch);
    180190                        list_append(current, &done);
  • uspace/drv/uhci-hcd/transfer_list.h

    rc69209d r15d3b54  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb
     28/** @addtogroup drvusbuhcihc
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI driver
     32 * @brief UHCI driver transfer list structure
    3333 */
    3434#ifndef DRV_UHCI_TRANSFER_LIST_H
     
    5050} transfer_list_t;
    5151
    52 int transfer_list_init(transfer_list_t *instance, const char *name);
    53 
    54 void transfer_list_set_next(transfer_list_t *instance, transfer_list_t *next);
    55 
     52/** Dispose transfer list structures.
     53 *
     54 * @param[in] instance Memory place to use.
     55 *
     56 * Frees memory for internal qh_t structure.
     57 */
    5658static inline void transfer_list_fini(transfer_list_t *instance)
    5759{
     
    5961        free32(instance->queue_head);
    6062}
     63
     64int transfer_list_init(transfer_list_t *instance, const char *name);
     65
     66void transfer_list_set_next(transfer_list_t *instance, transfer_list_t *next);
     67
    6168void transfer_list_remove_finished(transfer_list_t *instance);
    6269
  • uspace/drv/uhci-hcd/uhci.c

    rc69209d r15d3b54  
    6060}
    6161/*----------------------------------------------------------------------------*/
     62/** Get address of the device identified by handle.
     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 int usb_iface_get_address(
    6369    ddf_fun_t *fun, devman_handle_t handle, usb_address_t *address)
     
    106112};
    107113/*----------------------------------------------------------------------------*/
    108 /** Gets root hub hw resources.
     114/** Get root hub hw resources (I/O registers).
    109115 *
    110116 * @param[in] fun Root hub function.
     
    127133};
    128134/*----------------------------------------------------------------------------*/
     135/** Initialize hc and rh ddf structures and their respective drivers.
     136 *
     137 * @param[in] instance UHCI structure to use.
     138 * @param[in] device DDF instance of the device to use.
     139 *
     140 * This function does all the preparatory work for hc and rh drivers:
     141 *  - gets device hw resources
     142 *  - disables UHCI legacy support
     143 *  - asks for interrupt
     144 *  - registers interrupt handler
     145 */
    129146int uhci_init(uhci_t *instance, ddf_dev_t *device)
    130147{
     
    157174            "Failed(%d) to disable legacy USB: %s.\n", ret, str_error(ret));
    158175
    159 #if 0
     176        bool interrupts = false;
    160177        ret = pci_enable_interrupts(device);
    161178        if (ret != EOK) {
     
    163180                    "Failed(%d) to enable interrupts, fall back to polling.\n",
    164181                    ret);
     182        } else {
     183                usb_log_debug("Hw interrupts enabled.\n");
     184                interrupts = true;
    165185        }
    166 #endif
    167186
    168187        instance->hc_fun = ddf_fun_create(device, fun_exposed, "uhci-hc");
    169188        ret = (instance->hc_fun == NULL) ? ENOMEM : EOK;
    170         CHECK_RET_DEST_FUN_RETURN(ret, "Failed(%d) to create HC function.\n", ret);
    171 
    172         ret = uhci_hc_init(
    173             &instance->hc, instance->hc_fun, (void*)io_reg_base, io_reg_size);
     189        CHECK_RET_DEST_FUN_RETURN(ret,
     190            "Failed(%d) to create HC function.\n", ret);
     191
     192        ret = uhci_hc_init(&instance->hc, instance->hc_fun,
     193            (void*)io_reg_base, io_reg_size, interrupts);
    174194        CHECK_RET_DEST_FUN_RETURN(ret, "Failed(%d) to init uhci-hcd.\n", ret);
    175195        instance->hc_fun->ops = &uhci_hc_ops;
     
    217237#undef CHECK_RET_FINI_RETURN
    218238}
    219 
    220239/**
    221240 * @}
  • uspace/drv/uhci-hcd/uhci.h

    rc69209d r15d3b54  
    3131 */
    3232/** @file
    33  * @brief UHCI driver
     33 * @brief UHCI driver main structure for both host controller and root-hub.
    3434 */
    3535#ifndef DRV_UHCI_UHCI_H
  • uspace/drv/uhci-hcd/uhci_hc.c

    rc69209d r15d3b54  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb
     28/** @addtogroup drvusbuhcihc
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI driver
     32 * @brief UHCI Host controller driver routines
    3333 */
    3434#include <errno.h>
     
    5959        }
    6060};
    61 
    62 /** Gets USB address of the calling device.
    63  *
    64  * @param[in] fun UHCI hc function.
    65  * @param[in] handle Handle of the device seeking address.
    66  * @param[out] address Place to store found address.
    67  * @return Error code.
    68  */
    6961/*----------------------------------------------------------------------------*/
    7062static int uhci_hc_init_transfer_lists(uhci_hc_t *instance);
     
    7870    bool low_speed, usb_transfer_type_t transfer, size_t size);
    7971/*----------------------------------------------------------------------------*/
    80 /** Initializes UHCI hcd driver structure
     72/** Initialize UHCI hcd driver structure
    8173 *
    8274 * @param[in] instance Memory place to initialize.
     
    8678 * @return Error code.
    8779 * @note Should be called only once on any structure.
    88  */
    89 int uhci_hc_init(uhci_hc_t *instance, ddf_fun_t *fun, void *regs, size_t reg_size)
     80 *
     81 * Initializes memory structures, starts up hw, and launches debugger and
     82 * interrupt fibrils.
     83 */
     84int uhci_hc_init(uhci_hc_t *instance, ddf_fun_t *fun,
     85    void *regs, size_t reg_size, bool interrupts)
    9086{
    9187        assert(reg_size >= sizeof(regs_t));
     
    10096        } else (void) 0
    10197
     98        instance->hw_interrupts = interrupts;
    10299        /* Setup UHCI function. */
    103100        instance->ddf_instance = fun;
     
    118115
    119116        uhci_hc_init_hw(instance);
    120         instance->cleaner =
    121             fibril_create(uhci_hc_interrupt_emulator, instance);
    122         fibril_add_ready(instance->cleaner);
     117        if (!interrupts) {
     118                instance->cleaner =
     119                    fibril_create(uhci_hc_interrupt_emulator, instance);
     120                fibril_add_ready(instance->cleaner);
     121        }
    123122
    124123        instance->debug_checker = fibril_create(uhci_hc_debug_checker, instance);
     
    130129}
    131130/*----------------------------------------------------------------------------*/
    132 /** Initializes UHCI hcd hw resources.
     131/** Initialize UHCI hc hw resources.
    133132 *
    134133 * @param[in] instance UHCI structure to use.
     134 * For magic values see UHCI Design Guide
    135135 */
    136136void uhci_hc_init_hw(uhci_hc_t *instance)
     
    153153        pio_write_32(&registers->flbaseadd, pa);
    154154
    155         /* Enable all interrupts, but resume interrupt */
    156 //      pio_write_16(&instance->registers->usbintr,
    157 //          UHCI_INTR_CRC | UHCI_INTR_COMPLETE | UHCI_INTR_SHORT_PACKET);
     155        if (instance->hw_interrupts) {
     156                /* Enable all interrupts, but resume interrupt */
     157                pio_write_16(&instance->registers->usbintr,
     158                    UHCI_INTR_CRC | UHCI_INTR_COMPLETE | UHCI_INTR_SHORT_PACKET);
     159        }
    158160
    159161        uint16_t status = pio_read_16(&registers->usbcmd);
     
    166168}
    167169/*----------------------------------------------------------------------------*/
    168 /** Initializes UHCI hcd memory structures.
     170/** Initialize UHCI hc memory structures.
    169171 *
    170172 * @param[in] instance UHCI structure to use.
    171173 * @return Error code
    172174 * @note Should be called only once on any structure.
     175 *
     176 * Structures:
     177 *  - interrupt code (I/O addressses are customized per instance)
     178 *  - transfer lists (queue heads need to be accessible by the hw)
     179 *  - frame list page (needs to be one UHCI hw accessible 4K page)
    173180 */
    174181int uhci_hc_init_mem_structures(uhci_hc_t *instance)
     
    229236}
    230237/*----------------------------------------------------------------------------*/
    231 /** Initializes UHCI hcd transfer lists.
     238/** Initialize UHCI hc transfer lists.
    232239 *
    233240 * @param[in] instance UHCI structure to use.
    234241 * @return Error code
    235242 * @note Should be called only once on any structure.
     243 *
     244 * Initializes transfer lists and sets them in one chain to support proper
     245 * USB scheduling. Sets pointer table for quick access.
    236246 */
    237247int uhci_hc_init_transfer_lists(uhci_hc_t *instance)
     
    293303}
    294304/*----------------------------------------------------------------------------*/
    295 /** Schedules batch for execution.
     305/** Schedule batch for execution.
    296306 *
    297307 * @param[in] instance UHCI structure to use.
    298308 * @param[in] batch Transfer batch to schedule.
    299309 * @return Error code
     310 *
     311 * Checks for bandwidth availability and appends the batch to the proper queue.
    300312 */
    301313int uhci_hc_schedule(uhci_hc_t *instance, batch_t *batch)
     
    312324                return ENOTSUP;
    313325        }
    314         /* TODO: check available bandwith here */
     326        /* TODO: check available bandwidth here */
    315327
    316328        transfer_list_t *list =
     
    322334}
    323335/*----------------------------------------------------------------------------*/
    324 /** Takes action based on the interrupt cause.
     336/** Take action based on the interrupt cause.
    325337 *
    326338 * @param[in] instance UHCI structure to use.
    327  * @param[in] status Value of the stsatus regiser at the time of interrupt.
     339 * @param[in] status Value of the status register at the time of interrupt.
     340 *
     341 * Interrupt might indicate:
     342 * - transaction completed, either by triggering IOC, SPD, or an error
     343 * - some kind of device error
     344 * - resume from suspend state (not implemented)
    328345 */
    329346void uhci_hc_interrupt(uhci_hc_t *instance, uint16_t status)
     
    342359/** Polling function, emulates interrupts.
    343360 *
    344  * @param[in] arg UHCI structure to use.
    345  * @return EOK
     361 * @param[in] arg UHCI hc structure to use.
     362 * @return EOK (should never return)
    346363 */
    347364int uhci_hc_interrupt_emulator(void* arg)
     
    366383 *
    367384 * @param[in] arg UHCI structure to use.
    368  * @return EOK
     385 * @return EOK (should never return)
    369386 */
    370387int uhci_hc_debug_checker(void *arg)
     
    430447}
    431448/*----------------------------------------------------------------------------*/
    432 /** Checks transfer packets, for USB validity
     449/** Check transfer packets, for USB validity
    433450 *
    434451 * @param[in] low_speed Transfer speed.
    435452 * @param[in] transfer Transer type
    436453 * @param[in] size Maximum size of used packets
    437  * @return EOK
     454 * @return True if transaction is allowed by USB specs, false otherwise
    438455 */
    439456bool allowed_usb_packet(
  • uspace/drv/uhci-hcd/uhci_hc.h

    rc69209d r15d3b54  
    2727 */
    2828
    29 /** @addtogroup drvusbuhci
     29/** @addtogroup drvusbuhcihc
    3030 * @{
    3131 */
    3232/** @file
    33  * @brief UHCI driver
     33 * @brief UHCI host controller driver structure
    3434 */
    3535#ifndef DRV_UHCI_UHCI_HC_H
     
    9999        fid_t cleaner;
    100100        fid_t debug_checker;
     101        bool hw_interrupts;
    101102
    102103        ddf_fun_t *ddf_instance;
    103104} uhci_hc_t;
    104105
    105 /* init uhci specifics in device.driver_data */
    106 int uhci_hc_init(uhci_hc_t *instance, ddf_fun_t *fun, void *regs, size_t reg_size);
    107 
    108 static inline void uhci_hc_fini(uhci_hc_t *instance) { /* TODO: implement*/ };
     106int uhci_hc_init(uhci_hc_t *instance, ddf_fun_t *fun,
     107    void *regs, size_t reg_size, bool interupts);
    109108
    110109int uhci_hc_schedule(uhci_hc_t *instance, batch_t *batch);
     
    112111void uhci_hc_interrupt(uhci_hc_t *instance, uint16_t status);
    113112
     113/** Safely dispose host controller internal structures
     114 *
     115 * @param[in] instance Host controller structure to use.
     116 */
     117static inline void uhci_hc_fini(uhci_hc_t *instance) { /* TODO: implement*/ };
     118
     119/** Get and cast pointer to the driver data
     120 *
     121 * @param[in] fun DDF function pointer
     122 * @return cast pointer to driver_data
     123 */
    114124static inline uhci_hc_t * fun_to_uhci_hc(ddf_fun_t *fun)
    115125        { return (uhci_hc_t*)fun->driver_data; }
  • uspace/drv/uhci-hcd/uhci_rh.c

    rc69209d r15d3b54  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb
     28/** @addtogroup drvusbuhci
    2929 * @{
    3030 */
     
    4242#include "uhci_hc.h"
    4343
    44 /*----------------------------------------------------------------------------*/
     44/** Root hub initialization
     45 * @param[in] instance RH structure to initialize
     46 * @param[in] fun DDF function representing UHCI root hub
     47 * @param[in] reg_addr Address of root hub status and control registers.
     48 * @param[in] reg_size Size of accessible address space.
     49 * @return Error code.
     50 */
    4551int uhci_rh_init(
    4652    uhci_rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size)
     
    6874        instance->io_regs.type = IO_RANGE;
    6975        instance->io_regs.res.io_range.address = reg_addr;
    70 //          ((uintptr_t)hc->registers) + 0x10; // see UHCI design guide
    7176        instance->io_regs.res.io_range.size = reg_size;
    7277        instance->io_regs.res.io_range.endianness = LITTLE_ENDIAN;
  • uspace/drv/uhci-hcd/uhci_struct/link_pointer.h

    rc69209d r15d3b54  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb
     28/** @addtogroup drvusbuhcihc
    2929 * @{
    3030 */
  • uspace/drv/uhci-hcd/uhci_struct/queue_head.h

    rc69209d r15d3b54  
    1 
    21/*
    32 * Copyright (c) 2010 Jan Vesely
     
    2726 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2827 */
    29 /** @addtogroup usb
     28/** @addtogroup drv usbuhcihc
    3029 * @{
    3130 */
     
    4746} __attribute__((packed)) qh_t;
    4847/*----------------------------------------------------------------------------*/
     48/** Initialize queue head structure
     49 *
     50 * @param[in] instance qh_t structure to initialize.
     51 *
     52 * Sets both pointer to terminal NULL.
     53 */
    4954static inline void qh_init(qh_t *instance)
    5055{
     
    5560}
    5661/*----------------------------------------------------------------------------*/
     62/** Set queue head next pointer
     63 *
     64 * @param[in] instance qh_t structure to use.
     65 * @param[in] pa Physical address of the next queue head.
     66 *
     67 * Adds proper flag. If the pointer is NULL or terminal, sets next to terminal
     68 * NULL.
     69 */
    5770static inline void qh_set_next_qh(qh_t *instance, uint32_t pa)
    5871{
    59         /* address is valid and not terminal */
     72        /* Address is valid and not terminal */
    6073        if (pa && ((pa & LINK_POINTER_TERMINATE_FLAG) == 0)) {
    6174                instance->next = (pa & LINK_POINTER_ADDRESS_MASK)
     
    6679}
    6780/*----------------------------------------------------------------------------*/
     81/** Set queue head element pointer
     82 *
     83 * @param[in] instance qh_t structure to initialize.
     84 * @param[in] pa Physical address of the next queue head.
     85 *
     86 * Adds proper flag. If the pointer is NULL or terminal, sets element
     87 * to terminal NULL.
     88 */
    6889static inline void qh_set_element_qh(qh_t *instance, uint32_t pa)
    6990{
    70         /* address is valid and not terminal */
     91        /* Address is valid and not terminal */
    7192        if (pa && ((pa & LINK_POINTER_TERMINATE_FLAG) == 0)) {
    7293                instance->element = (pa & LINK_POINTER_ADDRESS_MASK)
     
    7798}
    7899/*----------------------------------------------------------------------------*/
     100/** Set queue head element pointer
     101 *
     102 * @param[in] instance qh_t structure to initialize.
     103 * @param[in] pa Physical address of the TD structure.
     104 *
     105 * Adds proper flag. If the pointer is NULL or terminal, sets element
     106 * to terminal NULL.
     107 */
    79108static inline void qh_set_element_td(qh_t *instance, uint32_t pa)
    80109{
  • uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.c

    rc69209d r15d3b54  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb
     28/** @addtogroup drvusbuhcihc
    2929 * @{
    3030 */
     
    3838#include "utils/malloc32.h"
    3939
    40 /** Initializes Transfer Descriptor
     40/** Initialize Transfer Descriptor
    4141 *
    4242 * @param[in] instance Memory place to initialize.
     
    106106}
    107107/*----------------------------------------------------------------------------*/
    108 /** Converts TD status into standard error code
     108/** Convert TD status into standard error code
    109109 *
    110110 * @param[in] instance TD structure to use.
  • uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.h

    rc69209d r15d3b54  
    11/*
    2  * Copyright (c) 2010 Jan Vesely
     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 /** @addtogroup usb
     28/** @addtogroup drvusbuhcihc
    2929 * @{
    3030 */
     
    108108}
    109109/*----------------------------------------------------------------------------*/
    110 /** Checks whether less than max data were recieved and packet is marked as SPD.
     110/** Check whether less than max data were recieved and packet is marked as SPD.
    111111 *
    112112 * @param[in] instance TD structure to use.
  • uspace/drv/uhci-hcd/utils/device_keeper.c

    rc69209d r15d3b54  
    2727 */
    2828
    29 /** @addtogroup drvusbuhci
     29/** @addtogroup drvusbuhcihc
    3030 * @{
    3131 */
     
    4040
    4141/*----------------------------------------------------------------------------*/
    42 /** Initializes device keeper structure.
     42/** Initialize device keeper structure.
    4343 *
    4444 * @param[in] instance Memory place to initialize.
     45 *
     46 * Set all values to false/0.
    4547 */
    4648void device_keeper_init(device_keeper_t *instance)
     
    5860}
    5961/*----------------------------------------------------------------------------*/
    60 /** Attempts to obtain address 0, blocks.
     62/** Attempt to obtain address 0, blocks.
    6163 *
    6264 * @param[in] instance Device keeper structure to use.
     
    7678}
    7779/*----------------------------------------------------------------------------*/
    78 /** Attempts to obtain address 0, blocks.
     80/** Attempt to obtain address 0, blocks.
    7981 *
    8082 * @param[in] instance Device keeper structure to use.
     
    9092}
    9193/*----------------------------------------------------------------------------*/
    92 /** Checks setup data for signs of toggle reset.
     94/** Check setup packet data for signs of toggle reset.
    9395 *
    9496 * @param[in] instance Device keeper structure to use.
    9597 * @param[in] target Device to receive setup packet.
    9698 * @param[in] data Setup packet data.
     99 *
     100 * Really ugly one.
    97101 */
    98102void device_keeper_reset_if_need(
     
    105109            || !instance->devices[target.address].occupied) {
    106110                fibril_mutex_unlock(&instance->guard);
     111                usb_log_error("Invalid data when checking for toggle reset.\n");
    107112                return;
    108113        }
     
    130135}
    131136/*----------------------------------------------------------------------------*/
    132 /** Gets current value of endpoint toggle.
     137/** Get current value of endpoint toggle.
    133138 *
    134139 * @param[in] instance Device keeper structure to use.
     
    144149            || target.address >= USB_ADDRESS_COUNT || target.address < 0
    145150            || !instance->devices[target.address].occupied) {
     151                usb_log_error("Invalid data when asking for toggle value.\n");
    146152                ret = EINVAL;
    147153        } else {
    148                 ret =
    149                     (instance->devices[target.address].toggle_status
     154                ret = (instance->devices[target.address].toggle_status
    150155                        >> target.endpoint) & 1;
    151156        }
     
    154159}
    155160/*----------------------------------------------------------------------------*/
    156 /** Sets current value of endpoint toggle.
     161/** Set current value of endpoint toggle.
    157162 *
    158163 * @param[in] instance Device keeper structure to use.
    159164 * @param[in] target Device and endpoint used.
    160  * @param[in] toggle Current toggle value.
     165 * @param[in] toggle Toggle value.
    161166 * @return Error code.
    162167 */
     
    170175            || target.address >= USB_ADDRESS_COUNT || target.address < 0
    171176            || !instance->devices[target.address].occupied) {
     177                usb_log_error("Invalid data when setting toggle value.\n");
    172178                ret = EINVAL;
    173179        } else {
     
    183189}
    184190/*----------------------------------------------------------------------------*/
    185 /** Gets a free USB address
     191/** Get a free USB address
    186192 *
    187193 * @param[in] instance Device keeper structure to use.
     
    216222}
    217223/*----------------------------------------------------------------------------*/
    218 /** Binds USB address to devman handle.
     224/** Bind USB address to devman handle.
    219225 *
    220226 * @param[in] instance Device keeper structure to use.
     
    234240}
    235241/*----------------------------------------------------------------------------*/
    236 /** Releases used USB address.
     242/** Release used USB address.
    237243 *
    238244 * @param[in] instance Device keeper structure to use.
     
    251257}
    252258/*----------------------------------------------------------------------------*/
    253 /** Finds USB address associated with the device
     259/** Find USB address associated with the device
    254260 *
    255261 * @param[in] instance Device keeper structure to use.
     
    274280}
    275281/*----------------------------------------------------------------------------*/
    276 /** Gets speed associated with the address
     282/** Get speed associated with the address
    277283 *
    278284 * @param[in] instance Device keeper structure to use.
  • uspace/drv/uhci-hcd/utils/device_keeper.h

    rc69209d r15d3b54  
    2727 */
    2828
    29 /** @addtogroup drvusbuhci
     29/** @addtogroup drvusbuhcihc
    3030 * @{
    3131 */
  • uspace/drv/uhci-hcd/utils/malloc32.h

    rc69209d r15d3b54  
    4343#define UHCI_REQUIRED_PAGE_SIZE 4096
    4444
     45/** Get physical address translation
     46 *
     47 * @param[in] addr Virtual address to translate
     48 * @return Physical address if exists, NULL otherwise.
     49 */
    4550static inline uintptr_t addr_to_phys(void *addr)
    4651{
     
    4853        int ret = as_get_physical_mapping(addr, &result);
    4954
    50         assert(ret == 0);
     55        if (ret != EOK)
     56                return 0;
    5157        return (result | ((uintptr_t)addr & 0xfff));
    5258}
    53 
     59/*----------------------------------------------------------------------------*/
     60/** Physical mallocator simulator
     61 *
     62 * @param[in] size Size of the required memory space
     63 * @return Address of the alligned and big enough memory place, NULL on failure.
     64 */
    5465static inline void * malloc32(size_t size)
    5566        { return memalign(UHCI_STRCUTURES_ALIGNMENT, size); }
    56 
    57 static inline void * get_page()
     67/*----------------------------------------------------------------------------*/
     68/** Physical mallocator simulator
     69 *
     70 * @param[in] addr Address of the place allocated by malloc32
     71 */
     72static inline void free32(void *addr)
     73        { if (addr) free(addr); }
     74/*----------------------------------------------------------------------------*/
     75/** Create 4KB page mapping
     76 *
     77 * @return Address of the mapped page, NULL on failure.
     78 */
     79static inline void * get_page(void)
    5880{
    5981        void * free_address = as_get_mappable_page(UHCI_REQUIRED_PAGE_SIZE);
    6082        assert(free_address);
    6183        if (free_address == 0)
    62                 return 0;
     84                return NULL;
    6385        void* ret =
    6486          as_area_create(free_address, UHCI_REQUIRED_PAGE_SIZE,
    6587                  AS_AREA_READ | AS_AREA_WRITE);
    6688        if (ret != free_address)
    67                 return 0;
     89                return NULL;
    6890        return ret;
    6991}
    70 
    71 static inline void free32(void *addr)
    72         { if (addr) free(addr); }
    7392
    7493#endif
  • uspace/drv/uhci-rhd/main.c

    rc69209d r15d3b54  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb
     28/** @addtogroup drvusbuhcirh
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI driver
     32 * @brief UHCI root hub initialization routines
    3333 */
    3434#include <ddf/driver.h>
     
    4040#include <usb/debug.h>
    4141
    42 
    43 
    4442#include "root_hub.h"
    4543
     
    4745static int hc_get_my_registers(ddf_dev_t *dev,
    4846    uintptr_t *io_reg_address, size_t *io_reg_size);
     47#if 0
    4948/*----------------------------------------------------------------------------*/
    5049static int usb_iface_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
     
    6766        .interfaces[USB_DEV_IFACE] = &uhci_rh_usb_iface,
    6867};
     68#endif
    6969/*----------------------------------------------------------------------------*/
    70 /** Initializes a new ddf driver instance of UHCI root hub.
     70/** Initialize a new ddf driver instance of UHCI root hub.
    7171 *
    7272 * @param[in] device DDF instance of the device to initialize.
     
    8181
    8282        //device->ops = &uhci_rh_ops;
    83         (void) uhci_rh_ops;
    84 
    85         uhci_root_hub_t *rh = malloc(sizeof(uhci_root_hub_t));
    86         if (!rh) {
    87                 usb_log_error("Failed to allocate memory for driver instance.\n");
    88                 return ENOMEM;
    89         }
    90 
    9183        uintptr_t io_regs = 0;
    9284        size_t io_size = 0;
    9385
    9486        int ret = hc_get_my_registers(device, &io_regs, &io_size);
    95         assert(ret == EOK);
     87        if (ret != EOK) {
     88                usb_log_error("Failed(%d) to get registers from parent hc.",
     89                    ret);
     90        }
     91        usb_log_info("I/O regs at %#X (size %zu).\n", io_regs, io_size);
    9692
    97         /* TODO: verify values from hc */
    98         usb_log_info("I/O regs at 0x%X (size %zu).\n", io_regs, io_size);
     93        uhci_root_hub_t *rh = malloc(sizeof(uhci_root_hub_t));
     94        if (!rh) {
     95                usb_log_error("Failed to allocate driver instance.\n");
     96                return ENOMEM;
     97        }
     98
    9999        ret = uhci_root_hub_init(rh, (void*)io_regs, io_size, device);
    100100        if (ret != EOK) {
     
    119119};
    120120/*----------------------------------------------------------------------------*/
    121 /** Initializes global driver structures (NONE).
     121/** Initialize global driver structures (NONE).
    122122 *
    123123 * @param[in] argc Nmber of arguments in argv vector (ignored).
  • uspace/drv/uhci-rhd/port.c

    rc69209d r15d3b54  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb
     28/** @addtogroup drvusbuhcirh
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI driver
    33  */
     32 * @brief UHCI root hub port routines
     33 */
     34#include <libarch/ddi.h> /* pio_read and pio_write */
    3435#include <errno.h>
    3536#include <str_error.h>
     
    3738
    3839#include <usb/usb.h>    /* usb_address_t */
    39 #include <usb/usbdevice.h>
    4040#include <usb/hub.h>
    41 #include <usb/request.h>
    4241#include <usb/debug.h>
    43 #include <usb/recognise.h>
    4442
    4543#include "port.h"
     
    5048static int uhci_port_check(void *port);
    5149static int uhci_port_reset_enable(int portno, void *arg);
    52 /*----------------------------------------------------------------------------*/
    53 /** Initializes UHCI root hub port instance.
     50static void uhci_port_print_status(
     51    uhci_port_t *port, const port_status_t value);
     52
     53/** Register reading helper function.
     54 *
     55 * @param[in] port Structure to use.
     56 * @return Error code. (Always EOK)
     57 */
     58static inline port_status_t uhci_port_read_status(uhci_port_t *port)
     59{
     60        assert(port);
     61        return pio_read_16(port->address);
     62}
     63/*----------------------------------------------------------------------------*/
     64/** Register writing helper function.
     65 *
     66 * @param[in] port Structure to use.
     67 * @param[in] value New register value.
     68 * @return Error code. (Always EOK)
     69 */
     70static inline void uhci_port_write_status(
     71    uhci_port_t *port, port_status_t value)
     72{
     73        assert(port);
     74        pio_write_16(port->address, value);
     75}
     76
     77/*----------------------------------------------------------------------------*/
     78/** Initialize UHCI root hub port instance.
    5479 *
    5580 * @param[in] port Memory structure to use.
     
    6085 * @return Error code.
    6186 *
    62  * Starts the polling fibril.
     87 * Creates and starts the polling fibril.
    6388 */
    6489int uhci_port_init(uhci_port_t *port,
     
    86111        port->checker = fibril_create(uhci_port_check, port);
    87112        if (port->checker == 0) {
    88                 usb_log_error("Port(%p - %d): failed to launch root hub fibril.",
    89                     port->address, port->number);
     113                usb_log_error("%s: failed to create polling fibril.",
     114                    port->id_string);
    90115                return ENOMEM;
    91116        }
    92117
    93118        fibril_add_ready(port->checker);
    94         usb_log_debug("Port(%p - %d): Added fibril. %x\n",
    95             port->address, port->number, port->checker);
    96         return EOK;
    97 }
    98 /*----------------------------------------------------------------------------*/
    99 /** Finishes UHCI root hub port instance.
     119        usb_log_debug("%s: Started polling fibril(%x).\n",
     120            port->id_string, port->checker);
     121        return EOK;
     122}
     123/*----------------------------------------------------------------------------*/
     124/** Cleanup UHCI root hub port instance.
    100125 *
    101126 * @param[in] port Memory structure to use.
     
    105130void uhci_port_fini(uhci_port_t *port)
    106131{
     132        assert(port);
     133        free(port->id_string);
    107134        /* TODO: Kill fibril here */
    108135        return;
     
    111138/** Periodically checks port status and reports new devices.
    112139 *
    113  * @param[in] port Memory structure to use.
     140 * @param[in] port Port structure to use.
    114141 * @return Error code.
    115142 */
     
    122149                async_usleep(instance->wait_period_usec);
    123150
    124                 /* read register value */
     151                /* Read register value */
    125152                port_status_t port_status = uhci_port_read_status(instance);
    126153
    127                 /* print the value if it's interesting */
     154                /* Print the value if it's interesting */
    128155                if (port_status & ~STATUS_ALWAYS_ONE)
    129156                        uhci_port_print_status(instance, port_status);
     
    177204 * @param arg Pointer to uhci_port_t of port with the new device.
    178205 * @return Error code.
     206 *
     207 * Resets and enables the ub port.
    179208 */
    180209int uhci_port_reset_enable(int portno, void *arg)
     
    214243}
    215244/*----------------------------------------------------------------------------*/
    216 /** Initializes and reports connected device.
    217  *
    218  * @param[in] port Memory structure to use.
     245/** Initialize and report connected device.
     246 *
     247 * @param[in] port Port structure to use.
    219248 * @param[in] speed Detected speed.
    220249 * @return Error code.
     
    247276}
    248277/*----------------------------------------------------------------------------*/
    249 /** Removes device.
     278/** Remove device.
    250279 *
    251280 * @param[in] port Memory structure to use.
    252281 * @return Error code.
    253282 *
    254  * Does not work DDF does not support device removal.
     283 * Does not work, DDF does not support device removal.
     284 * Does not even free used USB address (it would be dangerous if tis driver
     285 * is still running).
    255286 */
    256287int uhci_port_remove_device(uhci_port_t *port)
     
    261292}
    262293/*----------------------------------------------------------------------------*/
    263 /** Enables and disables port.
    264  *
    265  * @param[in] port Memory structure to use.
     294/** Enable or disable root hub port.
     295 *
     296 * @param[in] port Port structure to use.
     297 * @param[in] enabled Port status to set.
    266298 * @return Error code. (Always EOK)
    267299 */
     
    288320}
    289321/*----------------------------------------------------------------------------*/
     322/** Print the port status value in a human friendly way
     323 *
     324 * @param[in] port Port structure to use.
     325 * @param[in] value Port register value to print.
     326 * @return Error code. (Always EOK)
     327 */
     328void uhci_port_print_status(uhci_port_t *port, const port_status_t value)
     329{
     330        assert(port);
     331        usb_log_debug2("%s Port status(%#x):%s%s%s%s%s%s%s%s%s%s%s.\n",
     332            port->id_string, value,
     333            (value & STATUS_SUSPEND) ? " SUSPENDED," : "",
     334            (value & STATUS_RESUME) ? " IN RESUME," : "",
     335            (value & STATUS_IN_RESET) ? " IN RESET," : "",
     336            (value & STATUS_LINE_D_MINUS) ? " VD-," : "",
     337            (value & STATUS_LINE_D_PLUS) ? " VD+," : "",
     338            (value & STATUS_LOW_SPEED) ? " LOWSPEED," : "",
     339            (value & STATUS_ENABLED_CHANGED) ? " ENABLED-CHANGE," : "",
     340            (value & STATUS_ENABLED) ? " ENABLED," : "",
     341            (value & STATUS_CONNECTED_CHANGED) ? " CONNECTED-CHANGE," : "",
     342            (value & STATUS_CONNECTED) ? " CONNECTED," : "",
     343            (value & STATUS_ALWAYS_ONE) ? " ALWAYS ONE" : " ERROR: NO ALWAYS ONE"
     344        );
     345}
    290346/**
    291347 * @}
  • uspace/drv/uhci-rhd/port.h

    rc69209d r15d3b54  
    11/*
    2  * Copyright (c) 2010 Jan Vesely
     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 /** @addtogroup usb
     28/** @addtogroup drvusbuhcirh
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI port driver
     32 * @brief UHCI root hub port routines
    3333 */
    3434#ifndef DRV_UHCI_PORT_H
    3535#define DRV_UHCI_PORT_H
    3636
    37 #include <assert.h>
    3837#include <stdint.h>
     38#include <fibril.h>
    3939#include <ddf/driver.h>
    40 #include <libarch/ddi.h> /* pio_read and pio_write */
    41 #include <usb/usbdevice.h>
     40#include <usb/usbdevice.h> /* usb_hc_connection_t */
    4241
    4342typedef uint16_t port_status_t;
    44 
    4543#define STATUS_CONNECTED         (1 << 0)
    4644#define STATUS_CONNECTED_CHANGED (1 << 1)
     
    7472void uhci_port_fini(uhci_port_t *port);
    7573
    76 static inline port_status_t uhci_port_read_status(uhci_port_t *port)
    77 {
    78         assert(port);
    79         return pio_read_16(port->address);
    80 }
    81 
    82 static inline void uhci_port_write_status(
    83     uhci_port_t *port, port_status_t value)
    84 {
    85         assert(port);
    86         pio_write_16(port->address, value);
    87 }
    88 
    89 static inline void uhci_port_print_status(
    90     uhci_port_t *port, const port_status_t value)
    91 {
    92         assert(port);
    93         usb_log_debug2("%s Port status(%#x):%s%s%s%s%s%s%s%s%s%s%s.\n",
    94             port->id_string, value,
    95             (value & STATUS_SUSPEND) ? " SUSPENDED," : "",
    96             (value & STATUS_RESUME) ? " IN RESUME," : "",
    97             (value & STATUS_IN_RESET) ? " IN RESET," : "",
    98             (value & STATUS_LINE_D_MINUS) ? " VD-," : "",
    99             (value & STATUS_LINE_D_PLUS) ? " VD+," : "",
    100             (value & STATUS_LOW_SPEED) ? " LOWSPEED," : "",
    101             (value & STATUS_ENABLED_CHANGED) ? " ENABLED-CHANGE," : "",
    102             (value & STATUS_ENABLED) ? " ENABLED," : "",
    103             (value & STATUS_CONNECTED_CHANGED) ? " CONNECTED-CHANGE," : "",
    104             (value & STATUS_CONNECTED) ? " CONNECTED," : "",
    105             (value & STATUS_ALWAYS_ONE) ? " ALWAYS ONE" : " ERROR: NO ALWAYS ONE"
    106         );
    107 }
    10874#endif
    10975/**
  • uspace/drv/uhci-rhd/root_hub.c

    rc69209d r15d3b54  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb
     28/** @addtogroup drvusbuhcirh
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI driver
     32 * @brief UHCI root hub driver
    3333 */
    3434#include <errno.h>
    35 #include <stdint.h>
    3635#include <ddi.h>
    37 #include <devman.h>
    3836#include <usb/debug.h>
    3937
    4038#include "root_hub.h"
    4139
    42 /** Initializes UHCI root hub instance.
     40/** Initialize UHCI root hub instance.
    4341 *
    4442 * @param[in] instance Driver memory structure to use.
    4543 * @param[in] addr Address of I/O registers.
    4644 * @param[in] size Size of available I/O space.
    47  * @param[in] rh Pointer to ddf instance fo the root hub driver.
     45 * @param[in] rh Pointer to ddf instance of the root hub driver.
    4846 * @return Error code.
    4947 */
     
    6159        if (ret < 0) {
    6260                usb_log_error(
    63                     "Failed to gain access to port registers at %p\n", regs);
     61                    "Failed(%d) to gain access to port registers at %p\n",
     62                    ret, regs);
    6463                return ret;
    6564        }
    6665
    67         /* add fibrils for periodic port checks */
     66        /* Initialize root hub ports */
    6867        unsigned i = 0;
    6968        for (; i < UHCI_ROOT_HUB_PORT_COUNT; ++i) {
     
    8281}
    8382/*----------------------------------------------------------------------------*/
    84 /** Finishes UHCI root hub instance.
     83/** Cleanup UHCI root hub instance.
    8584 *
    86  * @param[in] instance Driver memory structure to use.
     85 * @param[in] instance Root hub structure to use.
    8786 * @return Error code.
    8887 */
  • uspace/drv/uhci-rhd/root_hub.h

    rc69209d r15d3b54  
    11/*
    2  * Copyright (c) 2010 Jan Vesely
     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 /** @addtogroup usb
     28/** @addtogroup drvusbuhcirh
    2929 * @{
    3030 */
     
    3535#define DRV_UHCI_ROOT_HUB_H
    3636
    37 #include <fibril.h>
    3837#include <ddf/driver.h>
    3938
Note: See TracChangeset for help on using the changeset viewer.