Changeset 98893ede in mainline


Ignore:
Timestamp:
2018-01-31T17:00:39Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
50206e9
Parents:
3b60ea0
Message:

libusb: dma_buffers optimization

Location:
uspace/lib/usb
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/include/usb/dma_buffer.h

    r3b60ea0 r98893ede  
    5555} dma_buffer_t;
    5656
    57 extern dma_policy_t dma_policy_default;
    58 
    5957extern int dma_buffer_alloc(dma_buffer_t *db, size_t size);
    60 extern int dma_buffer_alloc_policy(dma_buffer_t *, size_t, dma_policy_t);
     58extern int dma_buffer_alloc_policy(dma_buffer_t *, size_t, const dma_policy_t *);
    6159extern void dma_buffer_free(dma_buffer_t *);
    6260extern uintptr_t dma_buffer_phys(const dma_buffer_t *, void *);
  • uspace/lib/usb/src/dma_buffer.c

    r3b60ea0 r98893ede  
    3939#include "usb/dma_buffer.h"
    4040
    41 dma_policy_t dma_policy_default = {
     41const dma_policy_t dma_policy_default = {
    4242        .use64 = false,
    4343        .alignment = PAGE_SIZE,
     
    4545
    4646/**
    47  * Allocate a DMA buffer.
    48  *
    49  * @param[in] db dma_buffer_t structure to fill
    50  * @param[in] policy dma_policy_t structure to guide
    51  * @param[in] size Size of the required memory space
    52  * @return Error code.
     47 * The routine of allocating a DMA buffer. Inlined to force optimization for the
     48 * default policy.
    5349 */
    54 int dma_buffer_alloc_policy(dma_buffer_t *db, size_t size, dma_policy_t policy)
     50static inline int dma_buffer_alloc_internal(dma_buffer_t *db,
     51    size_t size, const dma_policy_t *policy)
    5552{
    5653        assert(db);
    5754
    58         if (policy.alignment > PAGE_SIZE)
     55        if (policy->alignment > PAGE_SIZE)
    5956                return EINVAL;
    6057
    61         const size_t aligned_size = ALIGN_UP(size, policy.alignment);
     58        const size_t aligned_size = ALIGN_UP(size, policy->alignment);
    6259        const size_t real_size = ALIGN_UP(aligned_size, PAGE_SIZE);
    63         const uintptr_t flags = policy.use64 ? 0 : DMAMEM_4GiB;
     60        const uintptr_t flags = policy->use64 ? 0 : DMAMEM_4GiB;
    6461
    6562        uintptr_t phys;
     
    7168
    7269        if (ret == EOK) {
    73                 /* Poison, accessing it should be enough to make sure
    74                  * the location is mapped, but poison works better */
    75                 memset(address, 0x5, real_size);
    7670                db->virt = address;
    7771                db->phys = phys;
    7872        }
    7973        return ret;
     74}
     75
     76/**
     77 * Allocate a DMA buffer.
     78 *
     79 * @param[in] db dma_buffer_t structure to fill
     80 * @param[in] size Size of the required memory space
     81 * @param[in] policy dma_policy_t structure to guide
     82 * @return Error code.
     83 */
     84int dma_buffer_alloc_policy(dma_buffer_t *db, size_t size,
     85    const dma_policy_t *policy)
     86{
     87        return dma_buffer_alloc_internal(db, size, policy);
    8088}
    8189
     
    8997int dma_buffer_alloc(dma_buffer_t *db, size_t size)
    9098{
    91         return dma_buffer_alloc_policy(db, size, dma_policy_default);
     99        return dma_buffer_alloc_internal(db, size, &dma_policy_default);
    92100}
    93101
Note: See TracChangeset for help on using the changeset viewer.