Changeset e67c50a in mainline for uspace/drv/bus/usb/ohci/ohci_bus.c


Ignore:
Timestamp:
2018-02-01T21:13:23Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
64ce0c1
Parents:
3e6ff9a
git-author:
Ondřej Hlavatý <aearsis@…> (2018-02-01 21:13:22)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-02-01 21:13:23)
Message:

ohci: use dma memory responsibly

Instead of leaving arbitrary TD behind to be used by next transfer,
prepare two of them in endpoint and use them in a cyclic manner. This
reduces the number of pages allocated per transfer to one.

File:
1 edited

Legend:

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

    r3e6ff9a re67c50a  
    7575        assert(dev);
    7676
    77         ohci_endpoint_t *ohci_ep = malloc(sizeof(ohci_endpoint_t));
     77        ohci_endpoint_t *ohci_ep = calloc(1, sizeof(ohci_endpoint_t));
    7878        if (ohci_ep == NULL)
    7979                return NULL;
     
    8181        endpoint_init(&ohci_ep->base, dev, desc);
    8282
    83         ohci_ep->ed = malloc32(sizeof(ed_t));
    84         if (ohci_ep->ed == NULL) {
     83        const errno_t err = dma_buffer_alloc(&ohci_ep->dma_buffer, sizeof(ed_t) + 2 * sizeof(td_t));
     84        if (err) {
    8585                free(ohci_ep);
    8686                return NULL;
    8787        }
    8888
    89         ohci_ep->td = malloc32(sizeof(td_t));
    90         if (ohci_ep->td == NULL) {
    91                 free32(ohci_ep->ed);
    92                 free(ohci_ep);
    93                 return NULL;
    94         }
     89        ohci_ep->ed = ohci_ep->dma_buffer.virt;
     90
     91        ohci_ep->tds[0] = (td_t *) ohci_ep->ed + 1;
     92        ohci_ep->tds[1] = ohci_ep->tds[0] + 1;
    9593
    9694        link_initialize(&ohci_ep->eplist_link);
     
    109107        ohci_endpoint_t *instance = ohci_endpoint_get(ep);
    110108
    111         free32(instance->ed);
    112         free32(instance->td);
     109        dma_buffer_free(&instance->dma_buffer);
    113110        free(instance);
    114111}
     
    125122                return err;
    126123
    127         ed_init(ohci_ep->ed, ep, ohci_ep->td);
     124        ed_init(ohci_ep->ed, ep, ohci_ep->tds[0]);
    128125        hc_enqueue_endpoint(bus->hc, ep);
    129126        endpoint_set_online(ep, &bus->hc->guard);
Note: See TracChangeset for help on using the changeset viewer.