1/*
2 * Copyright (c) 2014 ETH Zurich.
3 * All rights reserved.
4 *
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Universitaetsstrasse 6, CH-8092 Zurich. Attn: Systems Group.
8 */
9
10#ifndef LIB_DMA_MEM_UTILS_H
11#define LIB_DMA_MEM_UTILS_H
12
13#include <barrelfish/types.h>
14#include <barrelfish/capabilities.h>
15
16struct dma_mem
17{
18    lvaddr_t vaddr;         ///< virtual address of the mapped region
19    lpaddr_t paddr;         ///< physical address of the underlying frame
20    uint64_t bytes;         ///< size of the region in bytes
21    uint64_t requested;     ///< requested size of the region in bytes (<= bytes)
22    struct capref frame;    ///< frame capability backing this region
23};
24
25/**
26 * \brief allocates and maps a memory region to be used for DMA purposes
27 *
28 * \param bytes minimum size of the memory region in bytes
29 * \param mem   returns the mapping information
30 *
31  * \returns SYS_ERR_OK on success
32 *          errval on error
33 */
34errval_t dma_mem_alloc(size_t bytes, struct dma_mem *mem);
35
36/**
37 * \brief Initializes a dma_mem struct for a given capref
38 *
39 * \param frame The frame with a reference to memory
40 *
41 * \returns SYS_ERR_OK on success
42 *          errval on error
43 */
44errval_t dma_mem_from_capref(struct capref frame, struct dma_mem *mem);
45
46/**
47 * \brief tries to free the allocated memory region
48 *
49 * \returns SYS_ERR_OK on success
50 *          errval on error
51 */
52errval_t dma_mem_free(struct dma_mem *mem);
53
54
55
56#endif /* LIB_DMA_MEM_UTILS_H */
57