1 /* 2 * Copyright (c) 2015 Google Inc. All rights reserved 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining 5 * a copy of this software and associated documentation files 6 * (the "Software"), to deal in the Software without restriction, 7 * including without limitation the rights to use, copy, modify, merge, 8 * publish, distribute, sublicense, and/or sell copies of the Software, 9 * and to permit persons to whom the Software is furnished to do so, 10 * subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 24 #ifndef __UAPI_MM_H 25 #define __UAPI_MM_H 26 27 #include <stdint.h> 28 29 /* 30 * Flags for mmap syscall 31 */ 32 33 /** 34 * MMAP_FLAG_IO_HANDLE - map IO region rather than handle 35 * When passed to mmap(), this flag causes the handle argument to be 36 * interpreted as a MMIO region ID defined in the manifest rather than a 37 * handle. 38 * 39 * An IO Mapping has fixed attributes (non-secure, strongly ordered, 40 * physically contiguous, read-writable and 4k aligned) for now. 41 * 42 * It is an error to use this flag without %MMAP_PROT_READ and 43 * %MMAP_PROT_WRITE specified, or with %MMAP_PROT_EXEC specified. 44 */ 45 #define MMAP_FLAG_IO_HANDLE (0x1 << 4) 46 47 /** 48 * MMAP_FLAG_ANONYMOUS - the mapping is not backed by any handle. 49 * When passed to mmap(), this flag causes the handle argument to be 50 * ignored. This is analogous to MAP_ANONYMOUS in Linux. 51 * 52 * When this flag is used, the uaddr argument must be 0. 53 */ 54 #define MMAP_FLAG_ANONYMOUS (0x1 << 5) 55 56 /** 57 * MMAP_FLAG_NO_PHYSICAL - the mapping is not backed by any physical memory. 58 * When passed to mmap(), this flag creates a mapping, but does not allocate 59 * any physical memory. 60 * 61 * When this flag is used, the uaddr argument must be 0. 62 */ 63 #define MMAP_FLAG_NO_PHYSICAL (0x1 << 6) 64 65 /** 66 * MMAP_FLAG_FIXED_NOREPLACE - interpret the address exactly. The address 67 * must be page-aligned and should lie within a region previously returned 68 * by an mmap call with `MMAP_FLAG_NO_PHYSICAL` set. If a mapping overlaps 69 * any other region, it will fail. 70 * 71 * When this flag is used, the uaddr argument must also be set. 72 */ 73 #define MMAP_FLAG_FIXED_NOREPLACE (0x1 << 7) 74 75 /** 76 * Memory Protection attributes - flags to control mmap attributes 77 * %MMAP_FLAG_PROT_NONE: specifies absence of any mmap prot flags set 78 * %MMAP_FLAG_PROT_READ: specifies that mapped region should be readable 79 * %MMAP_FLAG_PROT_WRITE: specifies that mapped region should be writable 80 * %MMAP_FLAG_PROT_EXEC: specifies that mapped region should be executable 81 * %MMAP_FLAG_PROT_MTE: specifies that mapped region should use MTE. Note 82 * that the value of this flag does not match linux. 83 * %MMAP_FLAG_PROT_MASK: a combination of all possible PROT attributes 84 */ 85 #define MMAP_FLAG_PROT_NONE 0x0 86 #define MMAP_FLAG_PROT_READ 0x1 87 #define MMAP_FLAG_PROT_WRITE 0x2 88 #define MMAP_FLAG_PROT_EXEC 0x4 89 #define MMAP_FLAG_PROT_MTE 0x8 90 91 #define MMAP_FLAG_PROT_MASK \ 92 (MMAP_FLAG_PROT_READ | MMAP_FLAG_PROT_WRITE | MMAP_FLAG_PROT_EXEC | \ 93 MMAP_FLAG_PROT_MTE) 94 95 /** 96 * struct dma_pmem - a contiguous physical memory block 97 * @paddr: start of physical address 98 * @size: size of this contiguous block 99 * 100 * Caller passes this struct to prepare_dma syscall, which fills in pinned 101 * contiguous physical memory blocks. Caller uses DMA_MULTI_PMEM to tell 102 * syscall whether it passes in a single struct or an array. 103 */ 104 struct dma_pmem { 105 uint64_t paddr; 106 uint32_t size; 107 uint32_t pad; 108 }; 109 110 /* 111 * Flags for prepare_dma and finish_dma syscalls 112 */ 113 114 /* 115 * DMA directions 116 */ 117 #define DMA_FLAG_TO_DEVICE (0x1 << 0) /* memory to device */ 118 #define DMA_FLAG_FROM_DEVICE (0x1 << 1) /* device to memory */ 119 #define DMA_FLAG_BIDIRECTION (DMA_FLAG_TO_DEVICE | DMA_FLAG_FROM_DEVICE) 120 121 /* 122 * If DMA_FLAG_MULTI_PMEM is set, caller of prepare_dma must pass an array 123 * of dma_pmem struct. The array must be big enough to store all contiguous 124 * physical memory blocks to match requested user space memory aperture. For 125 * example, when minimum size of contiguous physical memory block is PAGE_SIZE, 126 * the array must be big enough to store 127 * ((uaddr + size - 1) / PAGE_SIZE - uaddr / PAGE_SIZE + 1) entries. 128 * Note: using a smaller dma_pmem array would corrupt current process's memory. 129 * 130 * If DMA_FLAG_MULTI_PMEM is not set, caller must pass a single dma_pmem struct. 131 * prepare_dma will attempt to map user space aperture into one contiguous 132 * physical memory block. If user space aperture is bigger than max size of 133 * contiguous physical memory block, behavior controlled by DMA_ALLOW_PARTIAL. 134 */ 135 #define DMA_FLAG_MULTI_PMEM (0x1 << 2) 136 137 /* 138 * If DMA_FLAG_ALLOW_PARTIAL is set, prepare_dma allows partial mapping of user 139 * requested aperture, e.g. assuming max size of one contiguous physical block 140 * is PAGE_SIZE, when DMA_MULTI_PMEM is not set and [vaddr, vaddr + size) spans 141 * on multiple pages, if this bit is set, kernel maps [vaddr, end of first page] 142 * with a single dma_pmem struct. If not set, kernel returns ERR_BAD_LEN. 143 */ 144 #define DMA_FLAG_ALLOW_PARTIAL (0x1 << 3) 145 146 #endif /* __UAPI_MM_H */ 147