Changeset 32fb6bce in mainline for uspace/drv/bus/usb/ohci/hc.c


Ignore:
Timestamp:
2017-12-18T22:50:21Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7f70d1c
Parents:
1ea0bbf
git-author:
Ondřej Hlavatý <aearsis@…> (2017-12-18 22:04:50)
git-committer:
Ondřej Hlavatý <aearsis@…> (2017-12-18 22:50:21)
Message:

usbhost: refactoring

This commit moves interrupt, status and schedule to bus
operations. Then the purpose of hcd_t is better defined, and split into
hc_driver_t and hc_device_t. hc_driver_t is used to wrap driver
implementation by the library (similar to how usb_driver_t is used to
wrap usb device drivers). hc_device_t is used as a parent for hc_t
inside drivers, and is allocated inside the DDF device node.

To support these changes, some local identifiers were renamed, some
functions were moved and/or renamed and their arguments changed. The
most notable one being hcd_send_batch → bus_device_send_batch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ohci/hc.c

    r1ea0bbf r32fb6bce  
    101101 * @return Error code.
    102102 */
    103 int ohci_hc_gen_irq_code(irq_code_t *code, hcd_t *hcd, const hw_res_list_parsed_t *hw_res)
     103int hc_gen_irq_code(irq_code_t *code, hc_device_t *hcd, const hw_res_list_parsed_t *hw_res)
    104104{
    105105        assert(code);
     
    149149 * @return Error code
    150150 */
    151 int hc_init(hc_t *instance, const hw_res_list_parsed_t *hw_res)
    152 {
    153         assert(instance);
     151int hc_add(hc_device_t *hcd, const hw_res_list_parsed_t *hw_res)
     152{
     153        hc_t *instance = hcd_to_hc(hcd);
    154154        assert(hw_res);
    155155        if (hw_res->mem_ranges.count != 1 ||
     
    186186 * @param[in] instance Host controller structure to use.
    187187 */
    188 void hc_fini(hc_t *instance)
     188int hc_gone(hc_device_t *instance)
    189189{
    190190        assert(instance);
    191191        /* TODO: implement*/
    192 };
     192        return ENOTSUP;
     193}
    193194
    194195void hc_enqueue_endpoint(hc_t *instance, const endpoint_t *ep)
     
    260261}
    261262
    262 int ohci_hc_status(hcd_t *hcd, uint32_t *status)
    263 {
    264         assert(hcd);
     263int ohci_hc_status(bus_t *bus_base, uint32_t *status)
     264{
     265        assert(bus_base);
    265266        assert(status);
    266         hc_t *instance = hcd_get_driver_data(hcd);
    267         assert(instance);
    268 
    269         if (instance->registers){
    270                 *status = OHCI_RD(instance->registers->interrupt_status);
    271                 OHCI_WR(instance->registers->interrupt_status, *status);
     267
     268        ohci_bus_t *bus = (ohci_bus_t *) bus_base;
     269        hc_t *hc = bus->hc;
     270        assert(hc);
     271
     272        if (hc->registers){
     273                *status = OHCI_RD(hc->registers->interrupt_status);
     274                OHCI_WR(hc->registers->interrupt_status, *status);
    272275        }
    273276        return EOK;
     
    280283 * @return Error code.
    281284 */
    282 int ohci_hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
    283 {
    284         assert(hcd);
    285         hc_t *instance = hcd_get_driver_data(hcd);
    286         assert(instance);
     285int ohci_hc_schedule(usb_transfer_batch_t *batch)
     286{
     287        assert(batch);
     288
     289        ohci_bus_t *bus = (ohci_bus_t *) endpoint_get_bus(batch->ep);
     290        hc_t *hc = bus->hc;
     291        assert(hc);
    287292
    288293        /* Check for root hub communication */
    289         if (batch->target.address == ohci_rh_get_address(&instance->rh)) {
     294        if (batch->target.address == ohci_rh_get_address(&hc->rh)) {
    290295                usb_log_debug("OHCI root hub request.\n");
    291                 return ohci_rh_schedule(&instance->rh, batch);
     296                return ohci_rh_schedule(&hc->rh, batch);
    292297        }
    293298        ohci_transfer_batch_t *ohci_batch = ohci_transfer_batch_get(batch);
     
    299304                return err;
    300305
    301         fibril_mutex_lock(&instance->guard);
    302         list_append(&ohci_batch->link, &instance->pending_batches);
     306        fibril_mutex_lock(&hc->guard);
     307        list_append(&ohci_batch->link, &hc->pending_batches);
    303308        ohci_transfer_batch_commit(ohci_batch);
    304309
     
    307312        {
    308313        case USB_TRANSFER_CONTROL:
    309                 OHCI_SET(instance->registers->command_status, CS_CLF);
     314                OHCI_SET(hc->registers->command_status, CS_CLF);
    310315                break;
    311316        case USB_TRANSFER_BULK:
    312                 OHCI_SET(instance->registers->command_status, CS_BLF);
     317                OHCI_SET(hc->registers->command_status, CS_BLF);
    313318                break;
    314319        default:
    315320                break;
    316321        }
    317         fibril_mutex_unlock(&instance->guard);
     322        fibril_mutex_unlock(&hc->guard);
    318323        return EOK;
    319324}
     
    324329 * @param[in] status Value of the status register at the time of interrupt.
    325330 */
    326 void ohci_hc_interrupt(hcd_t *hcd, uint32_t status)
    327 {
    328         assert(hcd);
    329         hc_t *instance = hcd_get_driver_data(hcd);
     331void ohci_hc_interrupt(bus_t *bus_base, uint32_t status)
     332{
     333        assert(bus_base);
     334
     335        ohci_bus_t *bus = (ohci_bus_t *) bus_base;
     336        hc_t *hc = bus->hc;
     337        assert(hc);
     338
    330339        status = OHCI_RD(status);
    331         assert(instance);
     340        assert(hc);
    332341        if ((status & ~I_SF) == 0) /* ignore sof status */
    333342                return;
    334         usb_log_debug2("OHCI(%p) interrupt: %x.\n", instance, status);
     343        usb_log_debug2("OHCI(%p) interrupt: %x.\n", hc, status);
    335344        if (status & I_RHSC)
    336                 ohci_rh_interrupt(&instance->rh);
     345                ohci_rh_interrupt(&hc->rh);
    337346
    338347        if (status & I_WDH) {
    339                 fibril_mutex_lock(&instance->guard);
    340                 usb_log_debug2("HCCA: %p-%#" PRIx32 " (%p).\n", instance->hcca,
    341                     OHCI_RD(instance->registers->hcca),
    342                     (void *) addr_to_phys(instance->hcca));
     348                fibril_mutex_lock(&hc->guard);
     349                usb_log_debug2("HCCA: %p-%#" PRIx32 " (%p).\n", hc->hcca,
     350                    OHCI_RD(hc->registers->hcca),
     351                    (void *) addr_to_phys(hc->hcca));
    343352                usb_log_debug2("Periodic current: %#" PRIx32 ".\n",
    344                     OHCI_RD(instance->registers->periodic_current));
    345 
    346                 link_t *current = list_first(&instance->pending_batches);
    347                 while (current && current != &instance->pending_batches.head) {
     353                    OHCI_RD(hc->registers->periodic_current));
     354
     355                link_t *current = list_first(&hc->pending_batches);
     356                while (current && current != &hc->pending_batches.head) {
    348357                        link_t *next = current->next;
    349358                        ohci_transfer_batch_t *batch =
     
    357366                        current = next;
    358367                }
    359                 fibril_mutex_unlock(&instance->guard);
     368                fibril_mutex_unlock(&hc->guard);
    360369        }
    361370
    362371        if (status & I_UE) {
    363372                usb_log_fatal("Error like no other!\n");
    364                 hc_start(instance);
     373                hc_start(&hc->base);
    365374        }
    366375
     
    374383 * @param[in] instance OHCI hc driver structure.
    375384 */
    376 void hc_gain_control(hc_t *instance)
    377 {
    378         assert(instance);
     385int hc_gain_control(hc_device_t *hcd)
     386{
     387        hc_t *instance = hcd_to_hc(hcd);
    379388
    380389        usb_log_debug("Requesting OHCI control.\n");
     
    409418                C_HCFS_SET(instance->registers->control, C_HCFS_RESET);
    410419                async_usleep(50000);
    411                 return;
     420                return EOK;
    412421        }
    413422
     
    418427                if (hc_status == C_HCFS_OPERATIONAL) {
    419428                        usb_log_info("BIOS driver: HC operational.\n");
    420                         return;
     429                        return EOK;
    421430                }
    422431                /* HC is suspended assert resume for 20ms */
     
    424433                async_usleep(20000);
    425434                usb_log_info("BIOS driver: HC resumed.\n");
    426                 return;
     435                return EOK;
    427436        }
    428437
     
    431440        usb_log_debug("Host controller found in reset state.\n");
    432441        async_usleep(50000);
     442        return EOK;
    433443}
    434444
     
    437447 * @param[in] instance OHCI hc driver structure.
    438448 */
    439 void hc_start(hc_t *instance)
    440 {
     449int hc_start(hc_device_t *hcd)
     450{
     451        hc_t *instance = hcd_to_hc(hcd);
    441452        ohci_rh_init(&instance->rh, instance->registers, "ohci rh");
    442453
     
    489500
    490501        /* Enable interrupts */
    491         if (instance->hw_interrupts) {
     502        if (instance->base.irq_cap >= 0) {
    492503                OHCI_WR(instance->registers->interrupt_enable,
    493504                    OHCI_USED_INTERRUPTS);
     
    508519        usb_log_debug("OHCI HC up and running (ctl_reg=0x%x).\n",
    509520            OHCI_RD(instance->registers->control));
     521
     522        return EOK;
    510523}
    511524
     
    555568        memset(&instance->rh, 0, sizeof(instance->rh));
    556569        /* Init queues */
    557         const int ret = hc_init_transfer_lists(instance);
     570        int ret = hc_init_transfer_lists(instance);
    558571        if (ret != EOK) {
    559572                return ret;
     
    574587            instance->lists[USB_TRANSFER_INTERRUPT].list_head_pa);
    575588
     589        if ((ret = ohci_bus_init(&instance->bus, instance))) {
     590                usb_log_error("HC(%p): Failed to setup bus : %s",
     591                    instance, str_error(ret));
     592                return ret;
     593        }
     594
     595        hc_device_setup(&instance->base, (bus_t *) &instance->bus);
     596
    576597        return EOK;
    577598}
Note: See TracChangeset for help on using the changeset viewer.