Lines Matching +full:dma +full:- +full:safe +full:- +full:map
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.
21 * .. code-block:: c
29 * When using dma-buf's vmap operation, the returned pointer is encoded as
37 * actually independent from the dma-buf infrastructure. When sharing buffers
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
51 * .. code-block:: c
53 * struct dma_buf_map map = DMA_BUF_MAP_INIT_VADDR(0xdeadbeaf);
55 * dma_buf_map_set_vaddr(&map. 0xdeadbeaf);
59 * .. code-block:: c
61 * dma_buf_map_set_vaddr_iomem(&map. 0xdeadbeaf);
67 * .. code-block:: c
69 * dma_buf_map_clear(&map);
74 * .. code-block:: c
76 * if (dma_buf_map_is_set(&map) != dma_buf_map_is_null(&map))
85 * .. code-block:: c
99 * .. code-block:: c
104 * dma_buf_map_memcpy_to(&map, src, len);
105 * dma_buf_map_incr(&map, len); // go to first byte after the memcpy
109 * struct dma_buf_map - Pointer to vmap'ed dma-buf memory.
112 * @is_iomem: True if the dma-buf memory is located in I/O
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.
140 static inline void dma_buf_map_set_vaddr(struct dma_buf_map *map, void *vaddr) in dma_buf_map_set_vaddr() argument
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.
153 static inline void dma_buf_map_set_vaddr_iomem(struct dma_buf_map *map, in dma_buf_map_set_vaddr_iomem() argument
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
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
192 static inline bool dma_buf_map_is_null(const struct dma_buf_map *map) in dma_buf_map_is_null() argument
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
209 static inline bool dma_buf_map_is_set(const struct dma_buf_map *map) in dma_buf_map_is_set() argument
211 return !dma_buf_map_is_null(map); in dma_buf_map_is_set()
215 * dma_buf_map_clear - Clears a dma-buf mapping structure
216 * @map: The dma-buf mapping structure
222 static inline void dma_buf_map_clear(struct dma_buf_map *map) in dma_buf_map_clear() argument
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
238 * Copies data into a dma-buf mapping. The source buffer is in system
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
258 static inline void dma_buf_map_incr(struct dma_buf_map *map, size_t incr) in dma_buf_map_incr() argument
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()