Changeset cc63815 in mainline for uspace/lib/usb/include


Ignore:
Timestamp:
2018-02-05T00:54:08Z (7 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fdc2253b
Parents:
5c69377
git-author:
Ondřej Hlavatý <aearsis@…> (2018-02-02 14:35:14)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-02-05 00:54:08)
Message:

usb dma_buffer: policy is now just a flag field, implement (un)locking

File:
1 edited

Legend:

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

    r5c69377 rcc63815  
    3232 * @brief USB host controller library: DMA buffer helpers
    3333 *
    34  * Simplifies usage of bounce buffers
     34 * Simplifies handling of buffers accessible to hardware. Defines properties of
     35 * such buffer, which can be communicated through IPC to allow higher layers to
     36 * allocate a buffer that is ready to be passed to HW right away (after being
     37 * shared through IPC).
    3538 *
    36  * Currently the minimum size allocated is a page, which is wasteful. Could be
    37  * extended to support memory pools, which will enable smaller units of
    38  * allocation.
     39 * Note that although allocated memory is always page-aligned, the buffer itself
     40 * may be only a part of it, justifying the existence of page-alignment and
     41 * page-crossing flags.
     42 *
     43 * Also, currently the buffers that are allocated are always contiguous and
     44 * page-aligned, regardless of whether the policy requires it. We blindly
     45 * believe this fact in dma_buffer_phys, which will yield wrong results if the
     46 * buffer is not contiguous.
    3947 */
    4048#ifndef LIB_USB_DMA_BUFFER
     
    4351#include <stdint.h>
    4452#include <stdlib.h>
     53#include <usbhc_iface.h>
    4554#include <errno.h>
    4655
    47 typedef const struct dma_policy {
    48         unsigned flags;
     56#define DMA_POLICY_4GiB         (1<<0)  /**< Must use only 32-bit addresses */
     57#define DMA_POLICY_PAGE_ALIGNED (1<<1)  /**< The first pointer must be page-aligned */
     58#define DMA_POLICY_CONTIGUOUS   (1<<2)  /**< Pages must follow each other physically */
     59#define DMA_POLICY_NOT_CROSSING (1<<3)  /**< Buffer must not cross page boundary. (Implies buffer is no larger than page).  */
    4960
    50 #define DMA_POLICY_F_4GiB       (1<<0)  /**< Must use only 32-bit addresses */
    51 #define DMA_POLICY_F_CONTIGUOUS (1<<1)  /**< Pages must follow each other physically */
    52 } dma_policy_t;
     61#define DMA_POLICY_STRICT       (-1U)
     62#define DMA_POLICY_DEFAULT      DMA_POLICY_STRICT
    5363
    5464typedef struct dma_buffer {
     
    5767} dma_buffer_t;
    5868
    59 extern 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 *);
     69extern errno_t dma_buffer_alloc(dma_buffer_t *db, size_t size);
     70extern errno_t dma_buffer_alloc_policy(dma_buffer_t *, size_t, dma_policy_t);
    6171extern void dma_buffer_free(dma_buffer_t *);
    6272extern uintptr_t dma_buffer_phys(const dma_buffer_t *, void *);
    6373
    64 extern bool dma_buffer_check_policy(const void *, size_t, dma_policy_t *);
     74extern bool dma_buffer_check_policy(const void *, size_t, const dma_policy_t);
     75
     76extern errno_t dma_buffer_lock(dma_buffer_t *, void *, size_t);
     77extern void dma_buffer_unlock(dma_buffer_t *, size_t);
    6578
    6679static inline int dma_buffer_is_set(dma_buffer_t *db)
Note: See TracChangeset for help on using the changeset viewer.