Changes in / [15d3b54:c69209d] in mainline


Ignore:
Location:
uspace
Files:
28 edited

Legend:

Unmodified
Added
Removed
  • uspace/doc/doxygroups.h

    r15d3b54 rc69209d  
    253253         * @defgroup drvusbuhci UHCI driver
    254254         * @ingroup usb
    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.
     255         * @brief Driver for USB host controller UHCI.
    268256         */
    269257
  • uspace/drv/ehci-hcd/main.c

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

    r15d3b54 rc69209d  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbuhcihc
     28/** @addtogroup usb
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI driver USB transaction structure
     32 * @brief UHCI driver
    3333 */
    3434#include <errno.h>
     
    4444
    4545#define DEFAULT_ERROR_COUNT 3
     46
     47static int batch_schedule(batch_t *instance);
    4648
    4749static void batch_control(batch_t *instance,
     
    5254static void batch_call_in_and_dispose(batch_t *instance);
    5355static void batch_call_out_and_dispose(batch_t *instance);
    54 
    55 
    56 /** Allocate memory and initialize internal data structure.
     56static void batch_dispose(batch_t *instance);
     57
     58
     59/** Allocates memory and initializes internal data structures.
    5760 *
    5861 * @param[in] fun DDF function to pass to callback.
     
    6972 * @param[in] arg additional parameter to func_in or func_out
    7073 * @param[in] manager Pointer to toggle management structure.
    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.
     74 * @return False, if there is an active TD, true otherwise.
    7775 */
    7876batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
     
    153151}
    154152/*----------------------------------------------------------------------------*/
    155 /** Check batch TDs for activity.
     153/** Checks batch TDs for activity.
    156154 *
    157155 * @param[in] instance Batch structure to use.
    158156 * @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.
    163157 */
    164158bool batch_is_complete(batch_t *instance)
     
    199193 *
    200194 * @param[in] instance Batch structure to use.
    201  *
    202  * Uses genercir control function with pids OUT and IN.
    203195 */
    204196void batch_control_write(batch_t *instance)
    205197{
    206198        assert(instance);
    207         /* We are data out, we are supposed to provide data */
     199        /* we are data out, we are supposed to provide data */
    208200        memcpy(instance->transport_buffer, instance->buffer,
    209201            instance->buffer_size);
     
    211203        instance->next_step = batch_call_out_and_dispose;
    212204        usb_log_debug("Batch(%p) CONTROL WRITE initialized.\n", instance);
     205        batch_schedule(instance);
    213206}
    214207/*----------------------------------------------------------------------------*/
     
    216209 *
    217210 * @param[in] instance Batch structure to use.
    218  *
    219  * Uses generic control with pids IN and OUT.
    220211 */
    221212void batch_control_read(batch_t *instance)
     
    225216        instance->next_step = batch_call_in_and_dispose;
    226217        usb_log_debug("Batch(%p) CONTROL READ initialized.\n", instance);
    227 }
    228 /*----------------------------------------------------------------------------*/
    229 /** Prepare interrupt in transaction.
    230  *
    231  * @param[in] instance Batch structure to use.
    232  *
    233  * Data transaction with PID_IN.
     218        batch_schedule(instance);
     219}
     220/*----------------------------------------------------------------------------*/
     221/** Prepares interrupt in transaction.
     222 *
     223 * @param[in] instance Batch structure to use.
    234224 */
    235225void batch_interrupt_in(batch_t *instance)
     
    239229        instance->next_step = batch_call_in_and_dispose;
    240230        usb_log_debug("Batch(%p) INTERRUPT IN initialized.\n", instance);
    241 }
    242 /*----------------------------------------------------------------------------*/
    243 /** Prepare interrupt out transaction.
    244  *
    245  * @param[in] instance Batch structure to use.
    246  *
    247  * Data transaction with PID_OUT.
     231        batch_schedule(instance);
     232}
     233/*----------------------------------------------------------------------------*/
     234/** Prepares interrupt out transaction.
     235 *
     236 * @param[in] instance Batch structure to use.
    248237 */
    249238void batch_interrupt_out(batch_t *instance)
    250239{
    251240        assert(instance);
    252         /* We are data out, we are supposed to provide data */
     241        /* we are data out, we are supposed to provide data */
    253242        memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size);
    254243        batch_data(instance, USB_PID_OUT);
    255244        instance->next_step = batch_call_out_and_dispose;
    256245        usb_log_debug("Batch(%p) INTERRUPT OUT initialized.\n", instance);
    257 }
    258 /*----------------------------------------------------------------------------*/
    259 /** Prepare bulk in transaction.
    260  *
    261  * @param[in] instance Batch structure to use.
    262  *
    263  * Data transaction with PID_IN.
     246        batch_schedule(instance);
     247}
     248/*----------------------------------------------------------------------------*/
     249/** Prepares bulk in transaction.
     250 *
     251 * @param[in] instance Batch structure to use.
    264252 */
    265253void batch_bulk_in(batch_t *instance)
     
    269257        instance->next_step = batch_call_in_and_dispose;
    270258        usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
    271 }
    272 /*----------------------------------------------------------------------------*/
    273 /** Prepare bulk out transaction.
    274  *
    275  * @param[in] instance Batch structure to use.
    276  *
    277  * Data transaction with PID_OUT.
     259        batch_schedule(instance);
     260}
     261/*----------------------------------------------------------------------------*/
     262/** Prepares bulk out transaction.
     263 *
     264 * @param[in] instance Batch structure to use.
    278265 */
    279266void batch_bulk_out(batch_t *instance)
    280267{
    281268        assert(instance);
    282         /* We are data out, we are supposed to provide data */
    283269        memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size);
    284270        batch_data(instance, USB_PID_OUT);
    285271        instance->next_step = batch_call_out_and_dispose;
    286272        usb_log_debug("Batch(%p) BULK OUT initialized.\n", instance);
    287 }
    288 /*----------------------------------------------------------------------------*/
    289 /** Prepare generic data transaction
     273        batch_schedule(instance);
     274}
     275/*----------------------------------------------------------------------------*/
     276/** Prepares generic data transaction
    290277 *
    291278 * @param[in] instance Batch structure to use.
    292279 * @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.
    296280 */
    297281void batch_data(batch_t *instance, usb_packet_id pid)
     
    334318}
    335319/*----------------------------------------------------------------------------*/
    336 /** Prepare generic control transaction
     320/** Prepares generic control transaction
    337321 *
    338322 * @param[in] instance Batch structure to use.
    339323 * @param[in] data_stage to use for data packets.
    340324 * @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.
    346325 */
    347326void batch_control(batch_t *instance,
     
    392371}
    393372/*----------------------------------------------------------------------------*/
    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.
     373/** Prepares data, gets error status and calls callback in.
     374 *
     375 * @param[in] instance Batch structure to use.
    399376 */
    400377void batch_call_in(batch_t *instance)
     
    403380        assert(instance->callback_in);
    404381
    405         /* We are data in, we need data */
     382        /* we are data in, we need data */
    406383        memcpy(instance->buffer, instance->transport_buffer,
    407384            instance->buffer_size);
     
    416393}
    417394/*----------------------------------------------------------------------------*/
    418 /** Get error status and call callback out.
     395/** Gets error status and calls callback out.
    419396 *
    420397 * @param[in] instance Batch structure to use.
     
    432409}
    433410/*----------------------------------------------------------------------------*/
    434 /** Helper function calls callback and correctly disposes of batch structure.
     411/** Prepares data, gets error status, calls callback in and dispose.
    435412 *
    436413 * @param[in] instance Batch structure to use.
     
    443420}
    444421/*----------------------------------------------------------------------------*/
    445 /** Helper function calls callback and correctly disposes of batch structure.
     422/** Gets error status, calls callback out and dispose.
    446423 *
    447424 * @param[in] instance Batch structure to use.
     
    454431}
    455432/*----------------------------------------------------------------------------*/
    456 /** Correctly dispose all used data structures.
     433/** Correctly disposes all used data structures.
    457434 *
    458435 * @param[in] instance Batch structure to use.
     
    469446        free(instance);
    470447}
     448/*----------------------------------------------------------------------------*/
     449int 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}
    471456/**
    472457 * @}
  • uspace/drv/uhci-hcd/batch.h

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

    r15d3b54 rc69209d  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbuhcihc
     28/** @addtogroup usb
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI driver hc interface implementation
     32 * @brief UHCI driver
    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         }
    168163        return EOK;
    169164}
     
    197192                return ENOMEM;
    198193        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         }
    204194        return EOK;
    205195}
     
    234224                return ENOMEM;
    235225        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         }
    241226        return EOK;
    242227}
     
    270255                return ENOMEM;
    271256        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         }
    277257        return EOK;
    278258}
     
    313293        device_keeper_reset_if_need(&hc->device_manager, target, setup_data);
    314294        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         }
    320295        return EOK;
    321296}
     
    352327                return ENOMEM;
    353328        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         }
    359329        return EOK;
    360330}
  • uspace/drv/uhci-hcd/iface.h

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

    r15d3b54 rc69209d  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbuhcihc
     28/** @addtogroup usb
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI driver initialization
     32 * @brief UHCI driver
    3333 */
    3434#include <ddf/driver.h>
     
    5555};
    5656/*----------------------------------------------------------------------------*/
    57 /** Initialize a new ddf driver instance for uhci hc and hub.
     57/** Initializes 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.
    6164 */
    6265int uhci_add_device(ddf_dev_t *device)
     
    7982}
    8083/*----------------------------------------------------------------------------*/
    81 /** Initialize global driver structures (NONE).
     84/** Initializes global driver structures (NONE).
    8285 *
    8386 * @param[in] argc Nmber of arguments in argv vector (ignored).
     
    8992int main(int argc, char *argv[])
    9093{
    91         sleep(3); /* TODO: remove in final version */
     94        sleep(3);
    9295        usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
    9396
  • uspace/drv/uhci-hcd/pci.c

    r15d3b54 rc69209d  
    2727 */
    2828/**
    29  * @addtogroup drvusbuhcihc
     29 * @addtogroup drvusbuhci
    3030 * @{
    3131 */
     
    117117}
    118118/*----------------------------------------------------------------------------*/
    119 /** Call the PCI driver with a request to enable interrupts
     119/** Calls the PCI driver with a request to enable interrupts
    120120 *
    121121 * @param[in] device Device asking for interrupts
     
    131131}
    132132/*----------------------------------------------------------------------------*/
    133 /** Call the PCI driver with a request to clear legacy support register
     133/** Calls 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

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

    r15d3b54 rc69209d  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbuhcihc
     28/** @addtogroup usb
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI driver transfer list implementation
     32 * @brief UHCI driver
    3333 */
    3434#include <errno.h>
     35
    3536#include <usb/debug.h>
    3637
     
    4041    transfer_list_t *instance, batch_t *batch);
    4142/*----------------------------------------------------------------------------*/
    42 /** Initialize transfer list structures.
     43/** Initializes transfer list structures.
    4344 *
    4445 * @param[in] instance Memory place to use.
    45  * @param[in] name Name of the new list.
     46 * @param[in] name Name of te new list.
    4647 * @return Error code
    4748 *
     
    6566}
    6667/*----------------------------------------------------------------------------*/
    67 /** Set the next list in transfer list chain.
     68/** Set the next list in chain.
    6869 *
    6970 * @param[in] instance List to lead.
     
    7172 * @return Error code
    7273 *
    73  * Does not check whether this replaces an existing list .
     74 * Does not check whether there was a next list already.
    7475 */
    7576void transfer_list_set_next(transfer_list_t *instance, transfer_list_t *next)
     
    7980        if (!instance->queue_head)
    8081                return;
    81         /* Set both next and element to point to the same QH */
     82        /* set both next and element to point to the same QH */
    8283        qh_set_next_qh(instance->queue_head, next->queue_head_pa);
    8384        qh_set_element_qh(instance->queue_head, next->queue_head_pa);
    8485}
    8586/*----------------------------------------------------------------------------*/
    86 /** Submit transfer batch to the list and queue.
     87/** Submits a new transfer batch to list and queue.
    8788 *
    8889 * @param[in] instance List to use.
    8990 * @param[in] batch Transfer batch to submit.
    9091 * @return Error code
    91  *
    92  * The batch is added to the end of the list and queue.
    9392 */
    9493void transfer_list_add_batch(transfer_list_t *instance, batch_t *batch)
     
    107106        fibril_mutex_lock(&instance->guard);
    108107
    109         /* Add to the hardware queue. */
    110108        if (list_empty(&instance->batch_list)) {
    111109                /* There is nothing scheduled */
     
    119117                qh_set_next_qh(last->qh, pa);
    120118        }
    121         /* Add to the driver list */
    122119        list_append(&batch->link, &instance->batch_list);
    123120
     
    129126}
    130127/*----------------------------------------------------------------------------*/
    131 /** Remove a transfer batch from the list and queue.
     128/** Removes a transfer batch from the list and queue.
    132129 *
    133130 * @param[in] instance List to use.
     
    147144
    148145        const char * pos = NULL;
    149         /* Remove from the hardware queue */
    150146        if (batch->link.prev == &instance->batch_list) {
    151147                /* I'm the first one here */
     
    158154                pos = "NOT FIRST";
    159155        }
    160         /* Remove from the driver list */
    161156        list_remove(&batch->link);
    162157        usb_log_debug("Batch(%p) removed (%s) from %s, next element %x.\n",
     
    164159}
    165160/*----------------------------------------------------------------------------*/
    166 /** Check list for finished batches.
     161/** Checks list for finished batches.
    167162 *
    168163 * @param[in] instance List to use.
    169164 * @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.
    174165 */
    175166void transfer_list_remove_finished(transfer_list_t *instance)
     
    186177
    187178                if (batch_is_complete(batch)) {
    188                         /* Save for post-processing */
    189179                        transfer_list_remove_batch(instance, batch);
    190180                        list_append(current, &done);
  • uspace/drv/uhci-hcd/transfer_list.h

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

    r15d3b54 rc69209d  
    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  */
    6862static int usb_iface_get_address(
    6963    ddf_fun_t *fun, devman_handle_t handle, usb_address_t *address)
     
    112106};
    113107/*----------------------------------------------------------------------------*/
    114 /** Get root hub hw resources (I/O registers).
     108/** Gets root hub hw resources.
    115109 *
    116110 * @param[in] fun Root hub function.
     
    133127};
    134128/*----------------------------------------------------------------------------*/
    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  */
    146129int uhci_init(uhci_t *instance, ddf_dev_t *device)
    147130{
     
    174157            "Failed(%d) to disable legacy USB: %s.\n", ret, str_error(ret));
    175158
    176         bool interrupts = false;
     159#if 0
    177160        ret = pci_enable_interrupts(device);
    178161        if (ret != EOK) {
     
    180163                    "Failed(%d) to enable interrupts, fall back to polling.\n",
    181164                    ret);
    182         } else {
    183                 usb_log_debug("Hw interrupts enabled.\n");
    184                 interrupts = true;
    185165        }
     166#endif
    186167
    187168        instance->hc_fun = ddf_fun_create(device, fun_exposed, "uhci-hc");
    188169        ret = (instance->hc_fun == NULL) ? ENOMEM : EOK;
    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);
     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);
    194174        CHECK_RET_DEST_FUN_RETURN(ret, "Failed(%d) to init uhci-hcd.\n", ret);
    195175        instance->hc_fun->ops = &uhci_hc_ops;
     
    237217#undef CHECK_RET_FINI_RETURN
    238218}
     219
    239220/**
    240221 * @}
  • uspace/drv/uhci-hcd/uhci.h

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

    r15d3b54 rc69209d  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbuhcihc
     28/** @addtogroup usb
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI Host controller driver routines
     32 * @brief UHCI driver
    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 */
    6169/*----------------------------------------------------------------------------*/
    6270static int uhci_hc_init_transfer_lists(uhci_hc_t *instance);
     
    7078    bool low_speed, usb_transfer_type_t transfer, size_t size);
    7179/*----------------------------------------------------------------------------*/
    72 /** Initialize UHCI hcd driver structure
     80/** Initializes UHCI hcd driver structure
    7381 *
    7482 * @param[in] instance Memory place to initialize.
     
    7886 * @return Error code.
    7987 * @note Should be called only once on any structure.
    80  *
    81  * Initializes memory structures, starts up hw, and launches debugger and
    82  * interrupt fibrils.
    83  */
    84 int uhci_hc_init(uhci_hc_t *instance, ddf_fun_t *fun,
    85     void *regs, size_t reg_size, bool interrupts)
     88 */
     89int uhci_hc_init(uhci_hc_t *instance, ddf_fun_t *fun, void *regs, size_t reg_size)
    8690{
    8791        assert(reg_size >= sizeof(regs_t));
     
    96100        } else (void) 0
    97101
    98         instance->hw_interrupts = interrupts;
    99102        /* Setup UHCI function. */
    100103        instance->ddf_instance = fun;
     
    115118
    116119        uhci_hc_init_hw(instance);
    117         if (!interrupts) {
    118                 instance->cleaner =
    119                     fibril_create(uhci_hc_interrupt_emulator, instance);
    120                 fibril_add_ready(instance->cleaner);
    121         }
     120        instance->cleaner =
     121            fibril_create(uhci_hc_interrupt_emulator, instance);
     122        fibril_add_ready(instance->cleaner);
    122123
    123124        instance->debug_checker = fibril_create(uhci_hc_debug_checker, instance);
     
    129130}
    130131/*----------------------------------------------------------------------------*/
    131 /** Initialize UHCI hc hw resources.
     132/** Initializes UHCI hcd hw resources.
    132133 *
    133134 * @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         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         }
     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);
    160158
    161159        uint16_t status = pio_read_16(&registers->usbcmd);
     
    168166}
    169167/*----------------------------------------------------------------------------*/
    170 /** Initialize UHCI hc memory structures.
     168/** Initializes UHCI hcd memory structures.
    171169 *
    172170 * @param[in] instance UHCI structure to use.
    173171 * @return Error code
    174172 * @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)
    180173 */
    181174int uhci_hc_init_mem_structures(uhci_hc_t *instance)
     
    236229}
    237230/*----------------------------------------------------------------------------*/
    238 /** Initialize UHCI hc transfer lists.
     231/** Initializes UHCI hcd transfer lists.
    239232 *
    240233 * @param[in] instance UHCI structure to use.
    241234 * @return Error code
    242235 * @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.
    246236 */
    247237int uhci_hc_init_transfer_lists(uhci_hc_t *instance)
     
    303293}
    304294/*----------------------------------------------------------------------------*/
    305 /** Schedule batch for execution.
     295/** Schedules batch for execution.
    306296 *
    307297 * @param[in] instance UHCI structure to use.
    308298 * @param[in] batch Transfer batch to schedule.
    309299 * @return Error code
    310  *
    311  * Checks for bandwidth availability and appends the batch to the proper queue.
    312300 */
    313301int uhci_hc_schedule(uhci_hc_t *instance, batch_t *batch)
     
    324312                return ENOTSUP;
    325313        }
    326         /* TODO: check available bandwidth here */
     314        /* TODO: check available bandwith here */
    327315
    328316        transfer_list_t *list =
     
    334322}
    335323/*----------------------------------------------------------------------------*/
    336 /** Take action based on the interrupt cause.
     324/** Takes action based on the interrupt cause.
    337325 *
    338326 * @param[in] instance UHCI structure to use.
    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)
     327 * @param[in] status Value of the stsatus regiser at the time of interrupt.
    345328 */
    346329void uhci_hc_interrupt(uhci_hc_t *instance, uint16_t status)
     
    359342/** Polling function, emulates interrupts.
    360343 *
    361  * @param[in] arg UHCI hc structure to use.
    362  * @return EOK (should never return)
     344 * @param[in] arg UHCI structure to use.
     345 * @return EOK
    363346 */
    364347int uhci_hc_interrupt_emulator(void* arg)
     
    383366 *
    384367 * @param[in] arg UHCI structure to use.
    385  * @return EOK (should never return)
     368 * @return EOK
    386369 */
    387370int uhci_hc_debug_checker(void *arg)
     
    447430}
    448431/*----------------------------------------------------------------------------*/
    449 /** Check transfer packets, for USB validity
     432/** Checks transfer packets, for USB validity
    450433 *
    451434 * @param[in] low_speed Transfer speed.
    452435 * @param[in] transfer Transer type
    453436 * @param[in] size Maximum size of used packets
    454  * @return True if transaction is allowed by USB specs, false otherwise
     437 * @return EOK
    455438 */
    456439bool allowed_usb_packet(
  • uspace/drv/uhci-hcd/uhci_hc.h

    r15d3b54 rc69209d  
    2727 */
    2828
    29 /** @addtogroup drvusbuhcihc
     29/** @addtogroup drvusbuhci
    3030 * @{
    3131 */
    3232/** @file
    33  * @brief UHCI host controller driver structure
     33 * @brief UHCI driver
    3434 */
    3535#ifndef DRV_UHCI_UHCI_HC_H
     
    9999        fid_t cleaner;
    100100        fid_t debug_checker;
    101         bool hw_interrupts;
    102101
    103102        ddf_fun_t *ddf_instance;
    104103} uhci_hc_t;
    105104
    106 int uhci_hc_init(uhci_hc_t *instance, ddf_fun_t *fun,
    107     void *regs, size_t reg_size, bool interupts);
     105/* init uhci specifics in device.driver_data */
     106int uhci_hc_init(uhci_hc_t *instance, ddf_fun_t *fun, void *regs, size_t reg_size);
     107
     108static inline void uhci_hc_fini(uhci_hc_t *instance) { /* TODO: implement*/ };
    108109
    109110int uhci_hc_schedule(uhci_hc_t *instance, batch_t *batch);
     
    111112void uhci_hc_interrupt(uhci_hc_t *instance, uint16_t status);
    112113
    113 /** Safely dispose host controller internal structures
    114  *
    115  * @param[in] instance Host controller structure to use.
    116  */
    117 static 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  */
    124114static inline uhci_hc_t * fun_to_uhci_hc(ddf_fun_t *fun)
    125115        { return (uhci_hc_t*)fun->driver_data; }
  • uspace/drv/uhci-hcd/uhci_rh.c

    r15d3b54 rc69209d  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbuhci
     28/** @addtogroup usb
    2929 * @{
    3030 */
     
    4242#include "uhci_hc.h"
    4343
    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  */
     44/*----------------------------------------------------------------------------*/
    5145int uhci_rh_init(
    5246    uhci_rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size)
     
    7468        instance->io_regs.type = IO_RANGE;
    7569        instance->io_regs.res.io_range.address = reg_addr;
     70//          ((uintptr_t)hc->registers) + 0x10; // see UHCI design guide
    7671        instance->io_regs.res.io_range.size = reg_size;
    7772        instance->io_regs.res.io_range.endianness = LITTLE_ENDIAN;
  • uspace/drv/uhci-hcd/uhci_struct/link_pointer.h

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

    r15d3b54 rc69209d  
     1
    12/*
    23 * Copyright (c) 2010 Jan Vesely
     
    2627 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2728 */
    28 /** @addtogroup drv usbuhcihc
     29/** @addtogroup usb
    2930 * @{
    3031 */
     
    4647} __attribute__((packed)) qh_t;
    4748/*----------------------------------------------------------------------------*/
    48 /** Initialize queue head structure
    49  *
    50  * @param[in] instance qh_t structure to initialize.
    51  *
    52  * Sets both pointer to terminal NULL.
    53  */
    5449static inline void qh_init(qh_t *instance)
    5550{
     
    6055}
    6156/*----------------------------------------------------------------------------*/
    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  */
    7057static inline void qh_set_next_qh(qh_t *instance, uint32_t pa)
    7158{
    72         /* Address is valid and not terminal */
     59        /* address is valid and not terminal */
    7360        if (pa && ((pa & LINK_POINTER_TERMINATE_FLAG) == 0)) {
    7461                instance->next = (pa & LINK_POINTER_ADDRESS_MASK)
     
    7966}
    8067/*----------------------------------------------------------------------------*/
    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  */
    8968static inline void qh_set_element_qh(qh_t *instance, uint32_t pa)
    9069{
    91         /* Address is valid and not terminal */
     70        /* address is valid and not terminal */
    9271        if (pa && ((pa & LINK_POINTER_TERMINATE_FLAG) == 0)) {
    9372                instance->element = (pa & LINK_POINTER_ADDRESS_MASK)
     
    9877}
    9978/*----------------------------------------------------------------------------*/
    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  */
    10879static inline void qh_set_element_td(qh_t *instance, uint32_t pa)
    10980{
  • uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.c

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

    r15d3b54 rc69209d  
    11/*
    2  * Copyright (c) 2011 Jan Vesely
     2 * Copyright (c) 2010 Jan Vesely
    33 * All rights reserved.
    44 *
     
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbuhcihc
     28/** @addtogroup usb
    2929 * @{
    3030 */
     
    108108}
    109109/*----------------------------------------------------------------------------*/
    110 /** Check whether less than max data were recieved and packet is marked as SPD.
     110/** Checks 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

    r15d3b54 rc69209d  
    2727 */
    2828
    29 /** @addtogroup drvusbuhcihc
     29/** @addtogroup drvusbuhci
    3030 * @{
    3131 */
     
    4040
    4141/*----------------------------------------------------------------------------*/
    42 /** Initialize device keeper structure.
     42/** Initializes device keeper structure.
    4343 *
    4444 * @param[in] instance Memory place to initialize.
    45  *
    46  * Set all values to false/0.
    4745 */
    4846void device_keeper_init(device_keeper_t *instance)
     
    6058}
    6159/*----------------------------------------------------------------------------*/
    62 /** Attempt to obtain address 0, blocks.
     60/** Attempts to obtain address 0, blocks.
    6361 *
    6462 * @param[in] instance Device keeper structure to use.
     
    7876}
    7977/*----------------------------------------------------------------------------*/
    80 /** Attempt to obtain address 0, blocks.
     78/** Attempts to obtain address 0, blocks.
    8179 *
    8280 * @param[in] instance Device keeper structure to use.
     
    9290}
    9391/*----------------------------------------------------------------------------*/
    94 /** Check setup packet data for signs of toggle reset.
     92/** Checks setup data for signs of toggle reset.
    9593 *
    9694 * @param[in] instance Device keeper structure to use.
    9795 * @param[in] target Device to receive setup packet.
    9896 * @param[in] data Setup packet data.
    99  *
    100  * Really ugly one.
    10197 */
    10298void device_keeper_reset_if_need(
     
    109105            || !instance->devices[target.address].occupied) {
    110106                fibril_mutex_unlock(&instance->guard);
    111                 usb_log_error("Invalid data when checking for toggle reset.\n");
    112107                return;
    113108        }
     
    135130}
    136131/*----------------------------------------------------------------------------*/
    137 /** Get current value of endpoint toggle.
     132/** Gets current value of endpoint toggle.
    138133 *
    139134 * @param[in] instance Device keeper structure to use.
     
    149144            || target.address >= USB_ADDRESS_COUNT || target.address < 0
    150145            || !instance->devices[target.address].occupied) {
    151                 usb_log_error("Invalid data when asking for toggle value.\n");
    152146                ret = EINVAL;
    153147        } else {
    154                 ret = (instance->devices[target.address].toggle_status
     148                ret =
     149                    (instance->devices[target.address].toggle_status
    155150                        >> target.endpoint) & 1;
    156151        }
     
    159154}
    160155/*----------------------------------------------------------------------------*/
    161 /** Set current value of endpoint toggle.
     156/** Sets current value of endpoint toggle.
    162157 *
    163158 * @param[in] instance Device keeper structure to use.
    164159 * @param[in] target Device and endpoint used.
    165  * @param[in] toggle Toggle value.
     160 * @param[in] toggle Current toggle value.
    166161 * @return Error code.
    167162 */
     
    175170            || target.address >= USB_ADDRESS_COUNT || target.address < 0
    176171            || !instance->devices[target.address].occupied) {
    177                 usb_log_error("Invalid data when setting toggle value.\n");
    178172                ret = EINVAL;
    179173        } else {
     
    189183}
    190184/*----------------------------------------------------------------------------*/
    191 /** Get a free USB address
     185/** Gets a free USB address
    192186 *
    193187 * @param[in] instance Device keeper structure to use.
     
    222216}
    223217/*----------------------------------------------------------------------------*/
    224 /** Bind USB address to devman handle.
     218/** Binds USB address to devman handle.
    225219 *
    226220 * @param[in] instance Device keeper structure to use.
     
    240234}
    241235/*----------------------------------------------------------------------------*/
    242 /** Release used USB address.
     236/** Releases used USB address.
    243237 *
    244238 * @param[in] instance Device keeper structure to use.
     
    257251}
    258252/*----------------------------------------------------------------------------*/
    259 /** Find USB address associated with the device
     253/** Finds USB address associated with the device
    260254 *
    261255 * @param[in] instance Device keeper structure to use.
     
    280274}
    281275/*----------------------------------------------------------------------------*/
    282 /** Get speed associated with the address
     276/** Gets speed associated with the address
    283277 *
    284278 * @param[in] instance Device keeper structure to use.
  • uspace/drv/uhci-hcd/utils/device_keeper.h

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

    r15d3b54 rc69209d  
    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  */
    5045static inline uintptr_t addr_to_phys(void *addr)
    5146{
     
    5348        int ret = as_get_physical_mapping(addr, &result);
    5449
    55         if (ret != EOK)
    56                 return 0;
     50        assert(ret == 0);
    5751        return (result | ((uintptr_t)addr & 0xfff));
    5852}
    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  */
     53
    6554static inline void * malloc32(size_t size)
    6655        { return memalign(UHCI_STRCUTURES_ALIGNMENT, size); }
    67 /*----------------------------------------------------------------------------*/
    68 /** Physical mallocator simulator
    69  *
    70  * @param[in] addr Address of the place allocated by malloc32
    71  */
    72 static 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  */
    79 static inline void * get_page(void)
     56
     57static inline void * get_page()
    8058{
    8159        void * free_address = as_get_mappable_page(UHCI_REQUIRED_PAGE_SIZE);
    8260        assert(free_address);
    8361        if (free_address == 0)
    84                 return NULL;
     62                return 0;
    8563        void* ret =
    8664          as_area_create(free_address, UHCI_REQUIRED_PAGE_SIZE,
    8765                  AS_AREA_READ | AS_AREA_WRITE);
    8866        if (ret != free_address)
    89                 return NULL;
     67                return 0;
    9068        return ret;
    9169}
     70
     71static inline void free32(void *addr)
     72        { if (addr) free(addr); }
    9273
    9374#endif
  • uspace/drv/uhci-rhd/main.c

    r15d3b54 rc69209d  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbuhcirh
     28/** @addtogroup usb
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI root hub initialization routines
     32 * @brief UHCI driver
    3333 */
    3434#include <ddf/driver.h>
     
    4040#include <usb/debug.h>
    4141
     42
     43
    4244#include "root_hub.h"
    4345
     
    4547static int hc_get_my_registers(ddf_dev_t *dev,
    4648    uintptr_t *io_reg_address, size_t *io_reg_size);
    47 #if 0
    4849/*----------------------------------------------------------------------------*/
    4950static int usb_iface_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
     
    6667        .interfaces[USB_DEV_IFACE] = &uhci_rh_usb_iface,
    6768};
    68 #endif
    6969/*----------------------------------------------------------------------------*/
    70 /** Initialize a new ddf driver instance of UHCI root hub.
     70/** Initializes 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
    8391        uintptr_t io_regs = 0;
    8492        size_t io_size = 0;
    8593
    8694        int ret = hc_get_my_registers(device, &io_regs, &io_size);
    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);
     95        assert(ret == EOK);
    9296
    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 
     97        /* TODO: verify values from hc */
     98        usb_log_info("I/O regs at 0x%X (size %zu).\n", io_regs, io_size);
    9999        ret = uhci_root_hub_init(rh, (void*)io_regs, io_size, device);
    100100        if (ret != EOK) {
     
    119119};
    120120/*----------------------------------------------------------------------------*/
    121 /** Initialize global driver structures (NONE).
     121/** Initializes global driver structures (NONE).
    122122 *
    123123 * @param[in] argc Nmber of arguments in argv vector (ignored).
  • uspace/drv/uhci-rhd/port.c

    r15d3b54 rc69209d  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbuhcirh
     28/** @addtogroup usb
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI root hub port routines
    33  */
    34 #include <libarch/ddi.h> /* pio_read and pio_write */
     32 * @brief UHCI driver
     33 */
    3534#include <errno.h>
    3635#include <str_error.h>
     
    3837
    3938#include <usb/usb.h>    /* usb_address_t */
     39#include <usb/usbdevice.h>
    4040#include <usb/hub.h>
     41#include <usb/request.h>
    4142#include <usb/debug.h>
     43#include <usb/recognise.h>
    4244
    4345#include "port.h"
     
    4850static int uhci_port_check(void *port);
    4951static int uhci_port_reset_enable(int portno, void *arg);
    50 static 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  */
    58 static 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  */
    70 static 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.
     52/*----------------------------------------------------------------------------*/
     53/** Initializes UHCI root hub port instance.
    7954 *
    8055 * @param[in] port Memory structure to use.
     
    8560 * @return Error code.
    8661 *
    87  * Creates and starts the polling fibril.
     62 * Starts the polling fibril.
    8863 */
    8964int uhci_port_init(uhci_port_t *port,
     
    11186        port->checker = fibril_create(uhci_port_check, port);
    11287        if (port->checker == 0) {
    113                 usb_log_error("%s: failed to create polling fibril.",
    114                     port->id_string);
     88                usb_log_error("Port(%p - %d): failed to launch root hub fibril.",
     89                    port->address, port->number);
    11590                return ENOMEM;
    11691        }
    11792
    11893        fibril_add_ready(port->checker);
    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.
     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.
    125100 *
    126101 * @param[in] port Memory structure to use.
     
    130105void uhci_port_fini(uhci_port_t *port)
    131106{
    132         assert(port);
    133         free(port->id_string);
    134107        /* TODO: Kill fibril here */
    135108        return;
     
    138111/** Periodically checks port status and reports new devices.
    139112 *
    140  * @param[in] port Port structure to use.
     113 * @param[in] port Memory structure to use.
    141114 * @return Error code.
    142115 */
     
    149122                async_usleep(instance->wait_period_usec);
    150123
    151                 /* Read register value */
     124                /* read register value */
    152125                port_status_t port_status = uhci_port_read_status(instance);
    153126
    154                 /* Print the value if it's interesting */
     127                /* print the value if it's interesting */
    155128                if (port_status & ~STATUS_ALWAYS_ONE)
    156129                        uhci_port_print_status(instance, port_status);
     
    204177 * @param arg Pointer to uhci_port_t of port with the new device.
    205178 * @return Error code.
    206  *
    207  * Resets and enables the ub port.
    208179 */
    209180int uhci_port_reset_enable(int portno, void *arg)
     
    243214}
    244215/*----------------------------------------------------------------------------*/
    245 /** Initialize and report connected device.
    246  *
    247  * @param[in] port Port structure to use.
     216/** Initializes and reports connected device.
     217 *
     218 * @param[in] port Memory structure to use.
    248219 * @param[in] speed Detected speed.
    249220 * @return Error code.
     
    276247}
    277248/*----------------------------------------------------------------------------*/
    278 /** Remove device.
    279  *
    280  * @param[in] port Memory structure to use.
    281  * @return Error code.
    282  *
    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).
     249/** Removes device.
     250 *
     251 * @param[in] port Memory structure to use.
     252 * @return Error code.
     253 *
     254 * Does not work DDF does not support device removal.
    286255 */
    287256int uhci_port_remove_device(uhci_port_t *port)
     
    292261}
    293262/*----------------------------------------------------------------------------*/
    294 /** Enable or disable root hub port.
    295  *
    296  * @param[in] port Port structure to use.
    297  * @param[in] enabled Port status to set.
     263/** Enables and disables port.
     264 *
     265 * @param[in] port Memory structure to use.
    298266 * @return Error code. (Always EOK)
    299267 */
     
    320288}
    321289/*----------------------------------------------------------------------------*/
    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  */
    328 void 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 }
    346290/**
    347291 * @}
  • uspace/drv/uhci-rhd/port.h

    r15d3b54 rc69209d  
    11/*
    2  * Copyright (c) 2011 Jan Vesely
     2 * Copyright (c) 2010 Jan Vesely
    33 * All rights reserved.
    44 *
     
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbuhcirh
     28/** @addtogroup usb
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI root hub port routines
     32 * @brief UHCI port driver
    3333 */
    3434#ifndef DRV_UHCI_PORT_H
    3535#define DRV_UHCI_PORT_H
    3636
     37#include <assert.h>
    3738#include <stdint.h>
    38 #include <fibril.h>
    3939#include <ddf/driver.h>
    40 #include <usb/usbdevice.h> /* usb_hc_connection_t */
     40#include <libarch/ddi.h> /* pio_read and pio_write */
     41#include <usb/usbdevice.h>
    4142
    4243typedef uint16_t port_status_t;
     44
    4345#define STATUS_CONNECTED         (1 << 0)
    4446#define STATUS_CONNECTED_CHANGED (1 << 1)
     
    7274void uhci_port_fini(uhci_port_t *port);
    7375
     76static 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
     82static 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
     89static 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}
    74108#endif
    75109/**
  • uspace/drv/uhci-rhd/root_hub.c

    r15d3b54 rc69209d  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbuhcirh
     28/** @addtogroup usb
    2929 * @{
    3030 */
    3131/** @file
    32  * @brief UHCI root hub driver
     32 * @brief UHCI driver
    3333 */
    3434#include <errno.h>
     35#include <stdint.h>
    3536#include <ddi.h>
     37#include <devman.h>
    3638#include <usb/debug.h>
    3739
    3840#include "root_hub.h"
    3941
    40 /** Initialize UHCI root hub instance.
     42/** Initializes UHCI root hub instance.
    4143 *
    4244 * @param[in] instance Driver memory structure to use.
    4345 * @param[in] addr Address of I/O registers.
    4446 * @param[in] size Size of available I/O space.
    45  * @param[in] rh Pointer to ddf instance of the root hub driver.
     47 * @param[in] rh Pointer to ddf instance fo the root hub driver.
    4648 * @return Error code.
    4749 */
     
    5961        if (ret < 0) {
    6062                usb_log_error(
    61                     "Failed(%d) to gain access to port registers at %p\n",
    62                     ret, regs);
     63                    "Failed to gain access to port registers at %p\n", regs);
    6364                return ret;
    6465        }
    6566
    66         /* Initialize root hub ports */
     67        /* add fibrils for periodic port checks */
    6768        unsigned i = 0;
    6869        for (; i < UHCI_ROOT_HUB_PORT_COUNT; ++i) {
     
    8182}
    8283/*----------------------------------------------------------------------------*/
    83 /** Cleanup UHCI root hub instance.
     84/** Finishes UHCI root hub instance.
    8485 *
    85  * @param[in] instance Root hub structure to use.
     86 * @param[in] instance Driver memory structure to use.
    8687 * @return Error code.
    8788 */
  • uspace/drv/uhci-rhd/root_hub.h

    r15d3b54 rc69209d  
    11/*
    2  * Copyright (c) 2011 Jan Vesely
     2 * Copyright (c) 2010 Jan Vesely
    33 * All rights reserved.
    44 *
     
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbuhcirh
     28/** @addtogroup usb
    2929 * @{
    3030 */
     
    3535#define DRV_UHCI_ROOT_HUB_H
    3636
     37#include <fibril.h>
    3738#include <ddf/driver.h>
    3839
Note: See TracChangeset for help on using the changeset viewer.