Changeset 32fb6bce in mainline for uspace/drv/bus/usb/uhci/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/uhci/hc.c

    r1ea0bbf r32fb6bce  
    9595
    9696static void hc_init_hw(const hc_t *instance);
    97 static int hc_init_mem_structures(hc_t *instance, hcd_t *);
     97static int hc_init_mem_structures(hc_t *instance, hc_device_t *);
    9898static int hc_init_transfer_lists(hc_t *instance);
    9999
     
    107107 * @return Error code.
    108108 */
    109 int uhci_hc_gen_irq_code(irq_code_t *code, hcd_t *hcd, const hw_res_list_parsed_t *hw_res)
     109int hc_gen_irq_code(irq_code_t *code, hc_device_t *hcd, const hw_res_list_parsed_t *hw_res)
    110110{
    111111        assert(code);
     
    156156 * - resume from suspend state (not implemented)
    157157 */
    158 void uhci_hc_interrupt(hcd_t *hcd, uint32_t status)
    159 {
    160         assert(hcd);
    161         hc_t *instance = hcd_get_driver_data(hcd);
    162         assert(instance);
     158static void hc_interrupt(bus_t *bus, uint32_t status)
     159{
     160        hc_t *instance = bus_to_hc(bus);
     161
    163162        /* Lower 2 bits are transaction error and transaction complete */
    164163        if (status & (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)) {
     
    199198                } else {
    200199                        usb_log_fatal("Too many UHCI hardware failures!.\n");
    201                         hc_fini(instance);
     200                        hc_gone(&instance->base);
    202201                }
    203202        }
     
    215214 * interrupt fibrils.
    216215 */
    217 int hc_init(hc_t *instance, hcd_t *hcd, const hw_res_list_parsed_t *hw_res)
    218 {
    219         assert(instance);
     216int hc_add(hc_device_t *hcd, const hw_res_list_parsed_t *hw_res)
     217{
     218        hc_t *instance = hcd_to_hc(hcd);
    220219        assert(hw_res);
    221220        if (hw_res->io_ranges.count != 1 ||
     
    249248}
    250249
    251 void hc_start(hc_t *instance)
    252 {
     250int hc_start(hc_device_t *hcd)
     251{
     252        hc_t *instance = hcd_to_hc(hcd);
    253253        hc_init_hw(instance);
    254254        (void)hc_debug_checker;
    255255
    256         uhci_rh_init(&instance->rh, instance->registers->ports, "uhci");
     256        return uhci_rh_init(&instance->rh, instance->registers->ports, "uhci");
    257257}
    258258
     
    261261 * @param[in] instance Host controller structure to use.
    262262 */
    263 void hc_fini(hc_t *instance)
     263int hc_gone(hc_device_t *instance)
    264264{
    265265        assert(instance);
    266266        //TODO Implement
     267        return ENOTSUP;
    267268}
    268269
     
    294295        pio_write_32(&registers->flbaseadd, pa);
    295296
    296         if (instance->hw_interrupts) {
     297        if (instance->base.irq_cap >= 0) {
    297298                /* Enable all interrupts, but resume interrupt */
    298299                pio_write_16(&instance->registers->usbintr,
     
    320321}
    321322
     323static int hc_status(bus_t *, uint32_t *);
     324static int hc_schedule(usb_transfer_batch_t *);
     325
    322326static const bus_ops_t uhci_bus_ops = {
    323327        .parent = &usb2_bus_ops,
    324328
     329        .interrupt = hc_interrupt,
     330        .status = hc_status,
     331
    325332        .endpoint_count_bw = bandwidth_count_usb11,
    326333        .batch_create = create_transfer_batch,
     334        .batch_schedule = hc_schedule,
    327335        .batch_destroy = destroy_transfer_batch,
    328336};
     
    338346 *  - frame list page (needs to be one UHCI hw accessible 4K page)
    339347 */
    340 int hc_init_mem_structures(hc_t *instance, hcd_t *hcd)
     348int hc_init_mem_structures(hc_t *instance, hc_device_t *hcd)
    341349{
    342350        int err;
    343351        assert(instance);
    344352
    345         if ((err = usb2_bus_init(&instance->bus, hcd, BANDWIDTH_AVAILABLE_USB11)))
     353        if ((err = usb2_bus_init(&instance->bus, BANDWIDTH_AVAILABLE_USB11)))
    346354                return err;
    347355
    348356        bus_t *bus = (bus_t *) &instance->bus;
    349357        bus->ops = &uhci_bus_ops;
     358
     359        hc_device_setup(&instance->base, bus);
    350360
    351361        /* Init USB frame list page */
     
    438448}
    439449
    440 int uhci_hc_status(hcd_t *hcd, uint32_t *status)
    441 {
    442         assert(hcd);
     450static int hc_status(bus_t *bus, uint32_t *status)
     451{
     452        hc_t *instance = bus_to_hc(bus);
    443453        assert(status);
    444         hc_t *instance = hcd_get_driver_data(hcd);
    445         assert(instance);
    446454
    447455        *status = 0;
     
    462470 * Checks for bandwidth availability and appends the batch to the proper queue.
    463471 */
    464 int uhci_hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
    465 {
    466         assert(hcd);
    467         hc_t *instance = hcd_get_driver_data(hcd);
    468         assert(instance);
     472static int hc_schedule(usb_transfer_batch_t *batch)
     473{
     474        hc_t *instance = bus_to_hc(endpoint_get_bus(batch->ep));
    469475        assert(batch);
    470476
Note: See TracChangeset for help on using the changeset viewer.