Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 35c37fc in mainline


Ignore:
Timestamp:
2018-01-05T20:15:08Z (4 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master
Children:
9e5b162
Parents:
b60944b
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-05 16:11:04)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-05 20:15:08)
Message:

ehci: refactor to dma_buffers

One big hidden thing was refactored - now TDs are allocated in one
buffer together with setup and data buffers themselves. This reduces the
number of allocated pages per transfer to minimum.

Location:
uspace
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ehci/ehci_batch.c

    rb60944b r35c37fc  
    4242#include <usb/usb.h>
    4343#include <usb/debug.h>
    44 #include <usb/host/utils/malloc32.h>
    4544
    4645#include "ehci_batch.h"
     
    6261{
    6362        assert(ehci_batch);
    64         if (ehci_batch->tds) {
    65                 for (size_t i = 0; i < ehci_batch->td_count; ++i) {
    66                         free32(ehci_batch->tds[i]);
    67                 }
    68                 free(ehci_batch->tds);
    69         }
    70         free32(ehci_batch->device_buffer);
     63        dma_buffer_free(&ehci_batch->dma_buffer);
    7164        free(ehci_batch);
    7265        usb_log_debug2("Batch(%p): disposed", ehci_batch);
     
    112105        const size_t size = ehci_batch->base.buffer_size;
    113106
    114         /* Mix setup stage and data together, we have enough space */
    115         if (size + setup_size > 0) {
    116                 /* Use one buffer for setup and data stage */
    117                 ehci_batch->device_buffer = malloc32(size + setup_size);
    118                 if (!ehci_batch->device_buffer) {
     107        /* Add TD left over by the previous transfer */
     108        ehci_batch->qh = ehci_endpoint_get(ehci_batch->base.ep)->qh;
     109
     110        /* Determine number of TDs needed */
     111        ehci_batch->td_count = (size + EHCI_TD_MAX_TRANSFER - 1)
     112                / EHCI_TD_MAX_TRANSFER;
     113
     114        /* Control transfer need Setup and Status stage */
     115        if (ehci_batch->base.ep->transfer_type == USB_TRANSFER_CONTROL) {
     116                ehci_batch->td_count += 2;
     117        }
     118
     119        const size_t tds_size = ehci_batch->td_count * sizeof(td_t);
     120
     121        /* Mix setup stage, data and TDs together, we have enough space */
     122        if (size + setup_size + tds_size > 0) {
     123                if (dma_buffer_alloc(&ehci_batch->dma_buffer, tds_size + setup_size + size)) {
    119124                        usb_log_error("Batch %p: Failed to allocate device "
    120125                            "buffer", ehci_batch);
    121126                        return ENOMEM;
    122127                }
     128                /* Clean TDs */
     129                ehci_batch->tds = ehci_batch->dma_buffer.virt;
     130                memset(ehci_batch->tds, 0, tds_size);
    123131                /* Copy setup data */
    124                 memcpy(ehci_batch->device_buffer, ehci_batch->base.setup.buffer,
    125                     setup_size);
     132                ehci_batch->setup_buffer = ehci_batch->dma_buffer.virt + tds_size;
     133                memcpy(ehci_batch->setup_buffer, ehci_batch->base.setup.buffer, setup_size);
    126134                /* Copy generic data */
     135                ehci_batch->data_buffer = ehci_batch->setup_buffer + setup_size;
    127136                if (ehci_batch->base.dir != USB_DIRECTION_IN)
    128                         memcpy(ehci_batch->device_buffer + setup_size,
    129                             ehci_batch->base.buffer, ehci_batch->base.buffer_size);
    130         }
    131 
    132         /* Add TD left over by the previous transfer */
    133         ehci_batch->qh = ehci_endpoint_get(ehci_batch->base.ep)->qh;
    134 
    135         /* Determine number of TDs needed */
    136         ehci_batch->td_count = (size + EHCI_TD_MAX_TRANSFER - 1)
    137                 / EHCI_TD_MAX_TRANSFER;
    138 
    139         /* Control transfer need Setup and Status stage */
    140         if (ehci_batch->base.ep->transfer_type == USB_TRANSFER_CONTROL) {
    141                 ehci_batch->td_count += 2;
    142         }
    143 
    144         ehci_batch->tds = calloc(ehci_batch->td_count, sizeof(td_t*));
    145         if (!ehci_batch->tds) {
    146                 usb_log_error("Batch %p: Failed to allocate EHCI transfer "
    147                     "descriptors.", ehci_batch);
    148                 return ENOMEM;
    149         }
    150 
    151         for (unsigned i = 0; i < ehci_batch->td_count; ++i) {
    152                 ehci_batch->tds[i] = malloc32(sizeof(td_t));
    153                 if (!ehci_batch->tds[i]) {
    154                         usb_log_error("Batch %p: Failed to allocate TD %d.",
    155                             ehci_batch, i);
    156                         return ENOMEM;
    157                 }
    158                 memset(ehci_batch->tds[i], 0, sizeof(td_t));
     137                        memcpy(ehci_batch->data_buffer,
     138                            ehci_batch->base.buffer,
     139                            ehci_batch->base.buffer_size);
    159140        }
    160141
     
    203184        /* Check all TDs */
    204185        for (size_t i = 0; i < ehci_batch->td_count; ++i) {
    205                 assert(ehci_batch->tds[i] != NULL);
    206186                usb_log_debug("Batch %p: TD %zu: %08x:%08x:%08x.",
    207187                    ehci_batch, i,
    208                     ehci_batch->tds[i]->status, ehci_batch->tds[i]->next,
    209                     ehci_batch->tds[i]->alternate);
    210 
    211                 ehci_batch->base.error = td_error(ehci_batch->tds[i]);
     188                    ehci_batch->tds[i].status, ehci_batch->tds[i].next,
     189                    ehci_batch->tds[i].alternate);
     190
     191                ehci_batch->base.error = td_error(&ehci_batch->tds[i]);
    212192                if (ehci_batch->base.error == EOK) {
    213193                        /* If the TD got all its data through, it will report
     
    224204                         */
    225205                        ehci_batch->base.transfered_size
    226                             -= td_remain_size(ehci_batch->tds[i]);
     206                            -= td_remain_size(&ehci_batch->tds[i]);
    227207                } else {
    228208                        usb_log_debug("Batch %p found error TD(%zu):%08x (%d).",
    229209                            ehci_batch, i,
    230                             ehci_batch->tds[i]->status,
     210                            ehci_batch->tds[i].status,
    231211                            ehci_batch->base.error);
    232212                        /* Clear possible ED HALT */
     
    238218        assert(ehci_batch->base.transfered_size <= ehci_batch->base.buffer_size);
    239219
    240         const size_t setup_size = (ehci_batch->base.ep->transfer_type == USB_TRANSFER_CONTROL)
    241                 ? USB_SETUP_PACKET_SIZE
    242                 : 0;
    243 
    244220        if (ehci_batch->base.dir == USB_DIRECTION_IN)
    245221                memcpy(ehci_batch->base.buffer,
    246                     ehci_batch->device_buffer + setup_size,
     222                    ehci_batch->data_buffer,
    247223                    ehci_batch->base.transfered_size);
    248224
     
    263239{
    264240        assert(ehci_batch);
    265         qh_set_next_td(ehci_batch->qh, ehci_batch->tds[0]);
     241        qh_set_next_td(ehci_batch->qh, dma_buffer_phys(&ehci_batch->dma_buffer, &ehci_batch->tds[0]));
    266242}
    267243
     
    281257        assert(dir == USB_DIRECTION_IN || dir == USB_DIRECTION_OUT);
    282258
    283         usb_log_debug2("Batch %p: Control QH(%"PRIxn"): "
     259        usb_log_debug2("Batch %p: Control QH(%p): "
    284260            "%08x:%08x:%08x:%08x:%08x:%08x", ehci_batch,
    285             addr_to_phys(ehci_batch->qh),
     261            ehci_batch->qh,
    286262            ehci_batch->qh->ep_char, ehci_batch->qh->ep_cap,
    287263            ehci_batch->qh->status, ehci_batch->qh->current,
     
    293269
    294270        int toggle = 0;
    295         const char* buffer = ehci_batch->device_buffer;
    296271        const usb_direction_t data_dir = dir;
    297272        const usb_direction_t status_dir = reverse_dir[dir];
    298273
    299274        /* Setup stage */
    300         td_init(ehci_batch->tds[0], ehci_batch->tds[1], USB_DIRECTION_BOTH,
    301             buffer, USB_SETUP_PACKET_SIZE, toggle, false);
     275        td_init(&ehci_batch->tds[0],
     276            dma_buffer_phys(&ehci_batch->dma_buffer, &ehci_batch->tds[1]),
     277            dma_buffer_phys(&ehci_batch->dma_buffer, ehci_batch->setup_buffer),
     278            USB_DIRECTION_BOTH, USB_SETUP_PACKET_SIZE, toggle, false);
    302279        usb_log_debug2("Batch %p: Created CONTROL SETUP TD(%"PRIxn"): "
    303280            "%08x:%08x:%08x", ehci_batch,
    304             addr_to_phys(ehci_batch->tds[0]),
    305             ehci_batch->tds[0]->status, ehci_batch->tds[0]->next,
    306             ehci_batch->tds[0]->alternate);
    307         buffer += USB_SETUP_PACKET_SIZE;
     281            dma_buffer_phys(&ehci_batch->dma_buffer, &ehci_batch->tds[0]),
     282            ehci_batch->tds[0].status, ehci_batch->tds[0].next,
     283            ehci_batch->tds[0].alternate);
    308284
    309285        /* Data stage */
    310         size_t td_current = 1;
     286        unsigned td_current = 1;
    311287        size_t remain_size = ehci_batch->base.buffer_size;
     288        uintptr_t buffer = dma_buffer_phys(&ehci_batch->dma_buffer, ehci_batch->data_buffer);
    312289        while (remain_size > 0) {
    313                 const size_t transfer_size =
    314                     min(remain_size, EHCI_TD_MAX_TRANSFER);
     290                const size_t transfer_size = min(remain_size, EHCI_TD_MAX_TRANSFER);
    315291                toggle = 1 - toggle;
    316292
    317                 td_init(ehci_batch->tds[td_current],
    318                     ehci_batch->tds[td_current + 1], data_dir, buffer,
    319                     transfer_size, toggle, false);
     293                td_init(&ehci_batch->tds[td_current],
     294                    dma_buffer_phys(&ehci_batch->dma_buffer, &ehci_batch->tds[td_current + 1]),
     295                    buffer, data_dir, transfer_size, toggle, false);
    320296                usb_log_debug2("Batch %p: Created CONTROL DATA TD(%"PRIxn"): "
    321297                    "%08x:%08x:%08x", ehci_batch,
    322                     addr_to_phys(ehci_batch->tds[td_current]),
    323                     ehci_batch->tds[td_current]->status,
    324                     ehci_batch->tds[td_current]->next,
    325                     ehci_batch->tds[td_current]->alternate);
     298                    dma_buffer_phys(&ehci_batch->dma_buffer, &ehci_batch->tds[td_current]),
     299                    ehci_batch->tds[td_current].status,
     300                    ehci_batch->tds[td_current].next,
     301                    ehci_batch->tds[td_current].alternate);
    326302
    327303                buffer += transfer_size;
     
    333309        /* Status stage */
    334310        assert(td_current == ehci_batch->td_count - 1);
    335         td_init(ehci_batch->tds[td_current], NULL, status_dir, NULL, 0, 1, true);
    336         usb_log_debug2("Batch %p: Created CONTROL STATUS TD(%"PRIxn"): "
    337             "%08x:%08x:%08x", ehci_batch,
    338             addr_to_phys(ehci_batch->tds[td_current]),
    339             ehci_batch->tds[td_current]->status,
    340             ehci_batch->tds[td_current]->next,
    341             ehci_batch->tds[td_current]->alternate);
     311        td_init(&ehci_batch->tds[td_current], 0, 0, status_dir, 0, 1, true);
     312        usb_log_debug2("Batch %p: Created CONTROL STATUS TD %d(%"PRIxn"): "
     313            "%08x:%08x:%08x", ehci_batch, td_current,
     314            dma_buffer_phys(&ehci_batch->dma_buffer, &ehci_batch->tds[td_current]),
     315            ehci_batch->tds[td_current].status,
     316            ehci_batch->tds[td_current].next,
     317            ehci_batch->tds[td_current].alternate);
    342318}
    343319
     
    354330        assert(ehci_batch);
    355331
    356         usb_log_debug2("Batch %p: Data QH(%"PRIxn"): "
     332        usb_log_debug2("Batch %p: Data QH(%p): "
    357333            "%08x:%08x:%08x:%08x:%08x:%08x", ehci_batch,
    358             addr_to_phys(ehci_batch->qh),
     334            ehci_batch->qh,
    359335            ehci_batch->qh->ep_char, ehci_batch->qh->ep_cap,
    360336            ehci_batch->qh->status, ehci_batch->qh->current,
     
    363339        size_t td_current = 0;
    364340        size_t remain_size = ehci_batch->base.buffer_size;
    365         char *buffer = ehci_batch->device_buffer;
     341        uintptr_t buffer = dma_buffer_phys(&ehci_batch->dma_buffer, ehci_batch->data_buffer);
    366342        while (remain_size > 0) {
    367343                const size_t transfer_size = remain_size > EHCI_TD_MAX_TRANSFER
     
    369345
    370346                const bool last = (remain_size == transfer_size);
    371                 td_init(
    372                     ehci_batch->tds[td_current],
    373                     last ? NULL : ehci_batch->tds[td_current + 1],
    374                     ehci_batch->base.dir, buffer, transfer_size, -1, last);
     347                td_init(&ehci_batch->tds[td_current],
     348                    last ? 0 : dma_buffer_phys(&ehci_batch->dma_buffer, &ehci_batch->tds[td_current + 1]),
     349                    buffer, ehci_batch->base.dir, transfer_size, -1, last);
    375350
    376351                usb_log_debug2("Batch %p: DATA TD(%"PRIxn": %08x:%08x:%08x",
    377352                    ehci_batch,
    378                     addr_to_phys(ehci_batch->tds[td_current]),
    379                     ehci_batch->tds[td_current]->status,
    380                     ehci_batch->tds[td_current]->next,
    381                     ehci_batch->tds[td_current]->alternate);
     353                    dma_buffer_phys(&ehci_batch->dma_buffer, &ehci_batch->tds[td_current]),
     354                    ehci_batch->tds[td_current].status,
     355                    ehci_batch->tds[td_current].next,
     356                    ehci_batch->tds[td_current].alternate);
    382357
    383358                buffer += transfer_size;
  • uspace/drv/bus/usb/ehci/ehci_batch.h

    rb60944b r35c37fc  
    3939#include <stdbool.h>
    4040#include <usb/host/usb_transfer_batch.h>
     41#include <usb/host/dma_buffer.h>
    4142
    4243#include "hw_struct/queue_head.h"
     
    4647typedef struct ehci_transfer_batch {
    4748        usb_transfer_batch_t base;
     49        /** Number of TDs used by the transfer */
     50        size_t td_count;
    4851        /** Link */
    4952        link_t link;
    5053        /** Endpoint descriptor of the target endpoint. */
    5154        qh_t *qh;
    52         /** List of TDs needed for the transfer */
    53         td_t **tds;
    54         /** Number of TDs used by the transfer */
    55         size_t td_count;
    5655        /** Data buffer, must be accessible by the EHCI hw. */
    57         char *device_buffer;
     56        dma_buffer_t dma_buffer;
     57        /** List of TDs needed for the transfer - backed by dma_buffer */
     58        td_t *tds;
     59        /** Data buffers - backed by dma_buffer */
     60        void *setup_buffer;
     61        void *data_buffer;
    5862        /** Generic USB transfer structure */
    5963        usb_transfer_batch_t *usb_batch;
  • uspace/drv/bus/usb/ehci/ehci_bus.c

    rb60944b r35c37fc  
    3636#include <assert.h>
    3737#include <stdlib.h>
    38 #include <usb/host/utils/malloc32.h>
    3938#include <usb/host/bandwidth.h>
    4039#include <usb/debug.h>
     
    9089
    9190        // TODO: extract USB2 information from desc
     91       
     92        if (dma_buffer_alloc(&ehci_ep->dma_buffer, sizeof(qh_t)))
     93                return NULL;
    9294
    93         ehci_ep->qh = malloc32(sizeof(qh_t));
    94         if (ehci_ep->qh == NULL) {
    95                 free(ehci_ep);
    96                 return NULL;
    97         }
     95        ehci_ep->qh = ehci_ep->dma_buffer.virt;
    9896
    9997        link_initialize(&ehci_ep->link);
     
    111109        ehci_endpoint_t *instance = ehci_endpoint_get(ep);
    112110
    113         free32(instance->qh);
     111        dma_buffer_free(&instance->dma_buffer);
    114112        free(instance);
    115113}
  • uspace/drv/bus/usb/ehci/ehci_bus.h

    rb60944b r35c37fc  
    4040#include <usb/host/usb2_bus.h>
    4141#include <usb/host/endpoint.h>
     42#include <usb/host/dma_buffer.h>
    4243
    4344#include "hw_struct/queue_head.h"
     
    4849        endpoint_t base;
    4950
    50         /** EHCI endpoint descriptor */
     51        /** EHCI endpoint descriptor, backed by dma_buffer */
    5152        qh_t *qh;
     53       
     54        dma_buffer_t dma_buffer;
    5255        /** Linked list used by driver software */
    5356        link_t link;
  • uspace/drv/bus/usb/ehci/endpoint_list.c

    rb60944b r35c37fc  
    5454        assert(instance);
    5555        instance->name = name;
    56         instance->list_head = malloc32(sizeof(qh_t));
    57         if (!instance->list_head) {
     56        if (dma_buffer_alloc(&instance->dma_buffer, sizeof(qh_t))) {
    5857                usb_log_error("EPL(%p-%s): Failed to allocate list head.",
    5958                    instance, name);
    6059                return ENOMEM;
    6160        }
     61        instance->list_head = instance->dma_buffer.virt;
    6262        qh_init(instance->list_head, NULL);
    6363
  • uspace/drv/bus/usb/ehci/endpoint_list.h

    rb60944b r35c37fc  
    3838#include <assert.h>
    3939#include <fibril_synch.h>
    40 #include <usb/host/utils/malloc32.h>
    4140
    4241#include "ehci_bus.h"
     
    4948        /** EHCI hw structure at the beginning of the queue */
    5049        qh_t *list_head;
     50        dma_buffer_t dma_buffer;
    5151        /** Assigned name, provides nicer debug output */
    5252        const char *name;
     
    6464{
    6565        assert(instance);
    66         free32(instance->list_head);
     66        dma_buffer_free(&instance->dma_buffer);
    6767        instance->list_head = NULL;
    6868}
  • uspace/drv/bus/usb/ehci/hc.c

    rb60944b r35c37fc  
    4545#include <usb/debug.h>
    4646#include <usb/usb.h>
    47 #include <usb/host/utils/malloc32.h>
    4847
    4948#include "ehci_batch.h"
     
    198197 * @param[in] instance Host controller structure to use.
    199198 */
    200 int hc_gone(hc_device_t *instance)
    201 {
    202         assert(instance);
    203         return EOK;
    204         //TODO: stop the hw
    205 #if 0
    206         endpoint_list_fini(&instance->async_list);
    207         endpoint_list_fini(&instance->int_list);
    208         return_page(instance->periodic_list_base);
    209 #endif
     199int hc_gone(hc_device_t *hcd)
     200{
     201        hc_t *hc = hcd_to_hc(hcd);
     202        endpoint_list_fini(&hc->async_list);
     203        endpoint_list_fini(&hc->int_list);
     204        dma_buffer_free(&hc->dma_buffer);
     205        return EOK;
    210206};
    211207
     
    406402
    407403        /* Enable periodic list */
    408         assert(instance->periodic_list_base);
     404        assert(instance->periodic_list);
    409405        uintptr_t phys_base =
    410             addr_to_phys((void*)instance->periodic_list_base);
     406            addr_to_phys((void*)instance->periodic_list);
    411407        assert((phys_base & USB_PERIODIC_LIST_BASE_MASK) == phys_base);
    412408        EHCI_WR(instance->registers->periodiclistbase, phys_base);
     
    477473
    478474        /* Take 1024 periodic list heads, we ignore low mem options */
    479         instance->periodic_list_base = get_page();
    480         if (!instance->periodic_list_base) {
     475        if (dma_buffer_alloc(&instance->dma_buffer, PAGE_SIZE)) {
    481476                usb_log_error("HC(%p): Failed to get ISO schedule page.",
    482477                    instance);
     
    485480                return ENOMEM;
    486481        }
     482        instance->periodic_list = instance->dma_buffer.virt;
    487483
    488484        usb_log_debug2("HC(%p): Initializing Periodic list.", instance);
    489         for (unsigned i = 0;
    490             i < PAGE_SIZE/sizeof(instance->periodic_list_base[0]); ++i)
     485        for (unsigned i = 0; i < PAGE_SIZE/sizeof(link_pointer_t); ++i)
    491486        {
    492487                /* Disable everything for now */
    493                 instance->periodic_list_base[i] =
     488                instance->periodic_list[i] =
    494489                    LINK_POINTER_QH(addr_to_phys(instance->int_list.list_head));
    495490        }
  • uspace/drv/bus/usb/ehci/hc.h

    rb60944b r35c37fc  
    6363        ehci_regs_t *registers;
    6464
    65         /** Iso transfer list */
    66         link_pointer_t *periodic_list_base;
     65        /** Iso transfer list, backed by dma_buffer */
     66        link_pointer_t *periodic_list;
     67
     68        dma_buffer_t dma_buffer;
    6769
    6870        /** CONTROL and BULK schedules */
  • uspace/drv/bus/usb/ehci/hw_struct/queue_head.h

    rb60944b r35c37fc  
    193193}
    194194
    195 static inline void qh_set_next_td(qh_t *qh, td_t *td)
     195static inline void qh_set_next_td(qh_t *qh, uintptr_t td)
    196196{
    197197        assert(qh);
    198198        assert(td);
    199         EHCI_MEM32_WR(qh->next, LINK_POINTER_TD(addr_to_phys(td)));
     199        EHCI_MEM32_WR(qh->next, LINK_POINTER_TD(td));
    200200}
    201201
  • uspace/drv/bus/usb/ehci/hw_struct/transfer_descriptor.c

    rb60944b r35c37fc  
    3939
    4040#include <usb/usb.h>
    41 #include <usb/host/utils/malloc32.h>
    4241
    4342#include "mem_access.h"
     
    7069};
    7170
     71#include <usb/debug.h>
     72
    7273/**
    7374 * Initialize EHCI TD.
    7475 * @param instance TD structure to initialize.
    75  * @param next Next TD in ED list.
     76 * @param next_phys Next TD in ED list.
    7677 * @param direction Used to determine PID, BOTH means setup PID.
    7778 * @param buffer Pointer to the first byte of transferred data.
     
    8081 *        any other value means that ED toggle will be used.
    8182 */
    82 void td_init(td_t *instance, const td_t *next,
    83     usb_direction_t direction, const void *buffer, size_t size, int toggle,
    84     bool ioc)
     83void td_init(td_t *instance, uintptr_t next_phys, uintptr_t buffer,
     84    usb_direction_t direction, size_t size, int toggle, bool ioc)
    8585{
    8686        assert(instance);
     
    9898        }
    9999
    100         if (buffer != NULL) {
     100        if (buffer != 0) {
    101101                assert(size != 0);
    102102                for (unsigned i = 0; (i < ARRAY_SIZE(instance->buffer_pointer))
    103103                    && size; ++i) {
    104                         const uintptr_t page =
    105                             (addr_to_phys(buffer) & TD_BUFFER_POINTER_MASK);
    106                         const size_t offset =
    107                             ((uintptr_t)buffer & TD_BUFFER_POINTER_OFFSET_MASK);
     104                        const uintptr_t offset = buffer & TD_BUFFER_POINTER_OFFSET_MASK;
    108105                        assert(offset == 0 || i == 0);
    109                         size -= min((4096 - offset), size);
    110                         buffer += min((4096 - offset), size);
    111                         EHCI_MEM32_WR(instance->buffer_pointer[i],
    112                             page | offset);
     106                        const size_t this_size = min(size, 4096 - offset);
     107                        EHCI_MEM32_WR(instance->buffer_pointer[i], buffer);
     108                        size -= this_size;
     109                        buffer += this_size;
    113110                }
    114111        }
    115112
    116         EHCI_MEM32_WR(instance->next, next ?
    117             LINK_POINTER_TD(addr_to_phys(next)) : LINK_POINTER_TERM);
     113        EHCI_MEM32_WR(instance->next, next_phys ?
     114            LINK_POINTER_TD(next_phys) : LINK_POINTER_TERM);
    118115
    119116        EHCI_MEM32_WR(instance->alternate, LINK_POINTER_TERM);
  • uspace/drv/bus/usb/ehci/hw_struct/transfer_descriptor.h

    rb60944b r35c37fc  
    3737#include <stddef.h>
    3838#include <stdint.h>
     39#include <macros.h>
    3940#include "link_pointer.h"
    4041#include "mem_access.h"
     
    7576        /* 64 bit struct only */
    7677        volatile uint32_t extended_bp[5];
    77 } td_t;
     78
     79        /* TDs must be 32-byte aligned */
     80        PADD32 [3];
     81
     82} __attribute__((packed)) td_t;
     83
     84static_assert(sizeof(td_t) % 32 == 0);
    7885
    7986static inline bool td_active(const td_t *td)
     
    9299int td_error(const td_t *td);
    93100
    94 void td_init(td_t *td, const td_t *next, usb_direction_t dir, const void * buf,
     101void td_init(td_t *td, uintptr_t next_phys, uintptr_t buf, usb_direction_t dir,
    95102    size_t buf_size, int toggle, bool ioc);
    96103
  • uspace/lib/usbhost/include/usb/host/dma_buffer.h

    rb60944b r35c37fc  
    6060extern int dma_buffer_alloc_policy(dma_buffer_t *, size_t, dma_policy_t);
    6161extern void dma_buffer_free(dma_buffer_t *);
     62extern uintptr_t dma_buffer_phys(const dma_buffer_t *, void *);
    6263
    6364static inline int dma_buffer_is_set(dma_buffer_t *db)
  • uspace/lib/usbhost/src/dma_buffer.c

    rb60944b r35c37fc  
    105105}
    106106
     107/** Convert a pointer inside a buffer to physical address.
     108 *
     109 * @param[in] db Buffer at which virt is pointing
     110 * @param[in] virt Pointer somewhere inside db
     111 */
     112uintptr_t dma_buffer_phys(const dma_buffer_t *db, void *virt)
     113{
     114        return db->phys + (virt - db->virt);
     115}
     116
    107117/**
    108118 * @}
Note: See TracChangeset for help on using the changeset viewer.