Ignore:
Timestamp:
2018-01-05T20:15:08Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.