Lines Matching +full:in +full:- +full:memory

1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Pointer to dma-buf-mapped memory, plus helpers.
15 * Calling dma-buf's vmap operation returns a pointer to the buffer's memory.
17 * I/O operations or memory load/store operations. For example, copying to
18 * system memory could be done with memcpy(), copying to I/O memory would be
21 * .. code-block:: c
23 * void *vaddr = ...; // pointer to system memory
26 * void *vaddr_iomem = ...; // pointer to I/O memory
29 * When using dma-buf's vmap operation, the returned pointer is encoded as
31 * :c:type:`struct dma_buf_map <dma_buf_map>` stores the buffer's address in
32 * system or I/O memory and a flag that signals the required method of
34 * to access the buffer's memory in the correct way.
37 * actually independent from the dma-buf infrastructure. When sharing buffers
38 * among devices, drivers have to know the location of the memory to access
39 * the buffers in a safe way. :c:type:`struct dma_buf_map <dma_buf_map>`
40 * solves this problem for dma-buf and its users. If other drivers or
41 * sub-systems require similar functionality, the type could be generalized
44 * Open-coding access to :c:type:`struct dma_buf_map <dma_buf_map>` is
49 * dma_buf_map_set_vaddr(). These helpers will set an address in system memory.
51 * .. code-block:: c
57 * To set an address in I/O memory, use dma_buf_map_set_vaddr_iomem().
59 * .. code-block:: c
65 * always refer to system memory.
67 * .. code-block:: c
74 * .. code-block:: c
81 * memory spaces, system or I/O, are never equal. That's even true if both
82 * spaces are located in the same address space, both mappings contain the
85 * .. code-block:: c
87 * struct dma_buf_map sys_map; // refers to system memory
88 * struct dma_buf_map io_map; // refers to I/O memory
94 * the buffer memory. Depending on the location of the memory, the provided
95 * helpers will pick the correct operations. Data can be copied into the memory
99 * .. code-block:: c
109 * struct dma_buf_map - Pointer to vmap'ed dma-buf memory.
110 * @vaddr_iomem: The buffer's address if in I/O memory
111 * @vaddr: The buffer's address if in system memory
112 * @is_iomem: True if the dma-buf memory is located in I/O
113 * memory, or false otherwise.
124 * DMA_BUF_MAP_INIT_VADDR - Initializes struct dma_buf_map to an address in system memory
125 * @vaddr_: A system-memory address
134 * dma_buf_map_set_vaddr - Sets a dma-buf mapping structure to an address in system memory
135 * @map: The dma-buf mapping structure
136 * @vaddr: A system-memory address
138 * Sets the address and clears the I/O-memory flag.
142 map->vaddr = vaddr; in dma_buf_map_set_vaddr()
143 map->is_iomem = false; in dma_buf_map_set_vaddr()
147 * dma_buf_map_set_vaddr_iomem - Sets a dma-buf mapping structure to an address in I/O memory
148 * @map: The dma-buf mapping structure
149 * @vaddr_iomem: An I/O-memory address
151 * Sets the address and the I/O-memory flag.
156 map->vaddr_iomem = vaddr_iomem; in dma_buf_map_set_vaddr_iomem()
157 map->is_iomem = true; in dma_buf_map_set_vaddr_iomem()
161 * dma_buf_map_is_equal - Compares two dma-buf mapping structures for equality
162 * @lhs: The dma-buf mapping structure
163 * @rhs: A dma-buf mapping structure to compare with
165 * Two dma-buf mapping structures are equal if they both refer to the same type of memory
166 * and to the same address within that memory.
174 if (lhs->is_iomem != rhs->is_iomem) in dma_buf_map_is_equal()
176 else if (lhs->is_iomem) in dma_buf_map_is_equal()
177 return lhs->vaddr_iomem == rhs->vaddr_iomem; in dma_buf_map_is_equal()
179 return lhs->vaddr == rhs->vaddr; in dma_buf_map_is_equal()
183 * dma_buf_map_is_null - Tests for a dma-buf mapping to be NULL
184 * @map: The dma-buf mapping structure
194 if (map->is_iomem) in dma_buf_map_is_null()
195 return !map->vaddr_iomem; in dma_buf_map_is_null()
196 return !map->vaddr; in dma_buf_map_is_null()
200 * dma_buf_map_is_set - Tests is the dma-buf mapping has been set
201 * @map: The dma-buf mapping structure
215 * dma_buf_map_clear - Clears a dma-buf mapping structure
216 * @map: The dma-buf mapping structure
219 * mapping structures that were set to point to I/O memory are reset for
220 * system memory. Pointers are cleared to NULL. This is the default.
224 if (map->is_iomem) { in dma_buf_map_clear()
225 map->vaddr_iomem = NULL; in dma_buf_map_clear()
226 map->is_iomem = false; in dma_buf_map_clear()
228 map->vaddr = NULL; in dma_buf_map_clear()
233 * dma_buf_map_memcpy_to - Memcpy into dma-buf mapping
234 * @dst: The dma-buf mapping structure
236 * @len: The number of byte in src
238 * Copies data into a dma-buf mapping. The source buffer is in system
239 * memory. Depending on the buffer's location, the helper picks the correct
240 * method of accessing the memory.
244 if (dst->is_iomem) in dma_buf_map_memcpy_to()
245 memcpy_toio(dst->vaddr_iomem, src, len); in dma_buf_map_memcpy_to()
247 memcpy(dst->vaddr, src, len); in dma_buf_map_memcpy_to()
251 * dma_buf_map_incr - Increments the address stored in a dma-buf mapping
252 * @map: The dma-buf mapping structure
255 * Increments the address stored in a dma-buf mapping. Depending on the
260 if (map->is_iomem) in dma_buf_map_incr()
261 map->vaddr_iomem += incr; in dma_buf_map_incr()
263 map->vaddr += incr; in dma_buf_map_incr()