Linux Audio

Check our new training course

Loading...
v6.2
  1/**************************************************************************
  2 *
  3 * Copyright (c) 2006-2009 Vmware, Inc., Palo Alto, CA., USA
  4 * All Rights Reserved.
  5 *
  6 * Permission is hereby granted, free of charge, to any person obtaining a
  7 * copy of this software and associated documentation files (the
  8 * "Software"), to deal in the Software without restriction, including
  9 * without limitation the rights to use, copy, modify, merge, publish,
 10 * distribute, sub license, and/or sell copies of the Software, and to
 11 * permit persons to whom the Software is furnished to do so, subject to
 12 * the following conditions:
 13 *
 14 * The above copyright notice and this permission notice (including the
 15 * next paragraph) shall be included in all copies or substantial portions
 16 * of the Software.
 17 *
 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
 22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 25 *
 26 **************************************************************************/
 27#ifndef _TTM_TT_H_
 28#define _TTM_TT_H_
 29
 30#include <linux/pagemap.h>
 31#include <linux/types.h>
 32#include <drm/ttm/ttm_caching.h>
 33#include <drm/ttm/ttm_kmap_iter.h>
 34
 35struct ttm_device;
 36struct ttm_tt;
 37struct ttm_resource;
 38struct ttm_buffer_object;
 39struct ttm_operation_ctx;
 40
 41/**
 42 * struct ttm_tt - This is a structure holding the pages, caching- and aperture
 43 * binding status for a buffer object that isn't backed by fixed (VRAM / AGP)
 44 * memory.
 45 */
 46struct ttm_tt {
 47	/** @pages: Array of pages backing the data. */
 48	struct page **pages;
 
 
 
 
 
 
 
 49	/**
 50	 * @page_flags: The page flags.
 51	 *
 52	 * Supported values:
 53	 *
 54	 * TTM_TT_FLAG_SWAPPED: Set by TTM when the pages have been unpopulated
 55	 * and swapped out by TTM.  Calling ttm_tt_populate() will then swap the
 56	 * pages back in, and unset the flag. Drivers should in general never
 57	 * need to touch this.
 58	 *
 59	 * TTM_TT_FLAG_ZERO_ALLOC: Set if the pages will be zeroed on
 60	 * allocation.
 61	 *
 62	 * TTM_TT_FLAG_EXTERNAL: Set if the underlying pages were allocated
 63	 * externally, like with dma-buf or userptr. This effectively disables
 64	 * TTM swapping out such pages.  Also important is to prevent TTM from
 65	 * ever directly mapping these pages.
 66	 *
 67	 * Note that enum ttm_bo_type.ttm_bo_type_sg objects will always enable
 68	 * this flag.
 69	 *
 70	 * TTM_TT_FLAG_EXTERNAL_MAPPABLE: Same behaviour as
 71	 * TTM_TT_FLAG_EXTERNAL, but with the reduced restriction that it is
 72	 * still valid to use TTM to map the pages directly. This is useful when
 73	 * implementing a ttm_tt backend which still allocates driver owned
 74	 * pages underneath(say with shmem).
 75	 *
 76	 * Note that since this also implies TTM_TT_FLAG_EXTERNAL, the usage
 77	 * here should always be:
 
 
 
 
 
 78	 *
 79	 *   page_flags = TTM_TT_FLAG_EXTERNAL |
 80	 *		  TTM_TT_FLAG_EXTERNAL_MAPPABLE;
 81	 *
 82	 * TTM_TT_FLAG_PRIV_POPULATED: TTM internal only. DO NOT USE. This is
 83	 * set by TTM after ttm_tt_populate() has successfully returned, and is
 84	 * then unset when TTM calls ttm_tt_unpopulate().
 85	 */
 86#define TTM_TT_FLAG_SWAPPED		(1 << 0)
 87#define TTM_TT_FLAG_ZERO_ALLOC		(1 << 1)
 88#define TTM_TT_FLAG_EXTERNAL		(1 << 2)
 89#define TTM_TT_FLAG_EXTERNAL_MAPPABLE	(1 << 3)
 90
 91#define TTM_TT_FLAG_PRIV_POPULATED  (1U << 31)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 92	uint32_t page_flags;
 93	/** @num_pages: Number of pages in the page array. */
 94	uint32_t num_pages;
 95	/** @sg: for SG objects via dma-buf. */
 96	struct sg_table *sg;
 97	/** @dma_address: The DMA (bus) addresses of the pages. */
 98	dma_addr_t *dma_address;
 99	/** @swap_storage: Pointer to shmem struct file for swap storage. */
100	struct file *swap_storage;
101	/**
102	 * @caching: The current caching state of the pages, see enum
103	 * ttm_caching.
104	 */
105	enum ttm_caching caching;
 
106};
107
108/**
109 * struct ttm_kmap_iter_tt - Specialization of a mappig iterator for a tt.
110 * @base: Embedded struct ttm_kmap_iter providing the usage interface
111 * @tt: Cached struct ttm_tt.
112 * @prot: Cached page protection for mapping.
113 */
114struct ttm_kmap_iter_tt {
115	struct ttm_kmap_iter base;
116	struct ttm_tt *tt;
117	pgprot_t prot;
 
 
 
 
 
118};
119
120static inline bool ttm_tt_is_populated(struct ttm_tt *tt)
121{
122	return tt->page_flags & TTM_TT_FLAG_PRIV_POPULATED;
123}
124
125/**
126 * ttm_tt_create
127 *
128 * @bo: pointer to a struct ttm_buffer_object
129 * @zero_alloc: true if allocated pages needs to be zeroed
130 *
131 * Make sure we have a TTM structure allocated for the given BO.
132 * No pages are actually allocated.
133 */
134int ttm_tt_create(struct ttm_buffer_object *bo, bool zero_alloc);
135
136/**
137 * ttm_tt_init
138 *
139 * @ttm: The struct ttm_tt.
140 * @bo: The buffer object we create the ttm for.
141 * @page_flags: Page flags as identified by TTM_TT_FLAG_XX flags.
142 * @caching: the desired caching state of the pages
143 * @extra_pages: Extra pages needed for the driver.
144 *
145 * Create a struct ttm_tt to back data with system memory pages.
146 * No pages are actually allocated.
147 * Returns:
148 * NULL: Out of memory.
149 */
150int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo,
151		uint32_t page_flags, enum ttm_caching caching,
152		unsigned long extra_pages);
153int ttm_sg_tt_init(struct ttm_tt *ttm_dma, struct ttm_buffer_object *bo,
154		   uint32_t page_flags, enum ttm_caching caching);
 
155
156/**
157 * ttm_tt_fini
158 *
159 * @ttm: the ttm_tt structure.
160 *
161 * Free memory of ttm_tt structure
162 */
163void ttm_tt_fini(struct ttm_tt *ttm);
 
 
 
 
 
 
 
 
 
 
 
 
164
165/**
166 * ttm_tt_destroy:
167 *
168 * @bdev: the ttm_device this object belongs to
169 * @ttm: The struct ttm_tt.
170 *
171 * Unbind, unpopulate and destroy common struct ttm_tt.
172 */
173void ttm_tt_destroy(struct ttm_device *bdev, struct ttm_tt *ttm);
 
 
 
 
 
 
 
 
 
174
175/**
176 * ttm_tt_swapin:
177 *
178 * @ttm: The struct ttm_tt.
179 *
180 * Swap in a previously swap out ttm_tt.
181 */
182int ttm_tt_swapin(struct ttm_tt *ttm);
183int ttm_tt_swapout(struct ttm_device *bdev, struct ttm_tt *ttm,
184		   gfp_t gfp_flags);
185
186/**
187 * ttm_tt_populate - allocate pages for a ttm
188 *
189 * @bdev: the ttm_device this object belongs to
190 * @ttm: Pointer to the ttm_tt structure
191 * @ctx: operation context for populating the tt object.
192 *
193 * Calls the driver method to allocate pages for a ttm
 
 
 
 
 
194 */
195int ttm_tt_populate(struct ttm_device *bdev, struct ttm_tt *ttm,
196		    struct ttm_operation_ctx *ctx);
197
198/**
199 * ttm_tt_unpopulate - free pages from a ttm
200 *
201 * @bdev: the ttm_device this object belongs to
202 * @ttm: Pointer to the ttm_tt structure
203 *
204 * Calls the driver method to free all pages from a ttm
205 */
206void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm);
207
208/**
209 * ttm_tt_mark_for_clear - Mark pages for clearing on populate.
210 *
211 * @ttm: Pointer to the ttm_tt structure
212 *
213 * Marks pages for clearing so that the next time the page vector is
214 * populated, the pages will be cleared.
215 */
216static inline void ttm_tt_mark_for_clear(struct ttm_tt *ttm)
217{
218	ttm->page_flags |= TTM_TT_FLAG_ZERO_ALLOC;
219}
220
221void ttm_tt_mgr_init(unsigned long num_pages, unsigned long num_dma32_pages);
222
223struct ttm_kmap_iter *ttm_kmap_iter_tt_init(struct ttm_kmap_iter_tt *iter_tt,
224					    struct ttm_tt *tt);
225
226#if IS_ENABLED(CONFIG_AGP)
227#include <linux/agp_backend.h>
228
229/**
230 * ttm_agp_tt_create
231 *
232 * @bo: Buffer object we allocate the ttm for.
233 * @bridge: The agp bridge this device is sitting on.
234 * @page_flags: Page flags as identified by TTM_TT_FLAG_XX flags.
235 *
236 *
237 * Create a TTM backend that uses the indicated AGP bridge as an aperture
238 * for TT memory. This function uses the linux agpgart interface to
239 * bind and unbind memory backing a ttm_tt.
240 */
241struct ttm_tt *ttm_agp_tt_create(struct ttm_buffer_object *bo,
242				 struct agp_bridge_data *bridge,
243				 uint32_t page_flags);
244int ttm_agp_bind(struct ttm_tt *ttm, struct ttm_resource *bo_mem);
245void ttm_agp_unbind(struct ttm_tt *ttm);
246void ttm_agp_destroy(struct ttm_tt *ttm);
247bool ttm_agp_is_bound(struct ttm_tt *ttm);
248#endif
249
250#endif
v4.17
  1/**************************************************************************
  2 *
  3 * Copyright (c) 2006-2009 Vmware, Inc., Palo Alto, CA., USA
  4 * All Rights Reserved.
  5 *
  6 * Permission is hereby granted, free of charge, to any person obtaining a
  7 * copy of this software and associated documentation files (the
  8 * "Software"), to deal in the Software without restriction, including
  9 * without limitation the rights to use, copy, modify, merge, publish,
 10 * distribute, sub license, and/or sell copies of the Software, and to
 11 * permit persons to whom the Software is furnished to do so, subject to
 12 * the following conditions:
 13 *
 14 * The above copyright notice and this permission notice (including the
 15 * next paragraph) shall be included in all copies or substantial portions
 16 * of the Software.
 17 *
 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
 22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 25 *
 26 **************************************************************************/
 27#ifndef _TTM_TT_H_
 28#define _TTM_TT_H_
 29
 
 30#include <linux/types.h>
 
 
 31
 
 32struct ttm_tt;
 33struct ttm_mem_reg;
 34struct ttm_buffer_object;
 35struct ttm_operation_ctx;
 36
 37#define TTM_PAGE_FLAG_WRITE           (1 << 3)
 38#define TTM_PAGE_FLAG_SWAPPED         (1 << 4)
 39#define TTM_PAGE_FLAG_PERSISTENT_SWAP (1 << 5)
 40#define TTM_PAGE_FLAG_ZERO_ALLOC      (1 << 6)
 41#define TTM_PAGE_FLAG_DMA32           (1 << 7)
 42#define TTM_PAGE_FLAG_SG              (1 << 8)
 43#define TTM_PAGE_FLAG_NO_RETRY	      (1 << 9)
 44
 45enum ttm_caching_state {
 46	tt_uncached,
 47	tt_wc,
 48	tt_cached
 49};
 50
 51struct ttm_backend_func {
 52	/**
 53	 * struct ttm_backend_func member bind
 54	 *
 55	 * @ttm: Pointer to a struct ttm_tt.
 56	 * @bo_mem: Pointer to a struct ttm_mem_reg describing the
 57	 * memory type and location for binding.
 58	 *
 59	 * Bind the backend pages into the aperture in the location
 60	 * indicated by @bo_mem. This function should be able to handle
 61	 * differences between aperture and system page sizes.
 62	 */
 63	int (*bind) (struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem);
 64
 65	/**
 66	 * struct ttm_backend_func member unbind
 
 
 
 
 
 67	 *
 68	 * @ttm: Pointer to a struct ttm_tt.
 
 
 
 
 69	 *
 70	 * Unbind previously bound backend pages. This function should be
 71	 * able to handle differences between aperture and system page sizes.
 72	 */
 73	int (*unbind) (struct ttm_tt *ttm);
 74
 75	/**
 76	 * struct ttm_backend_func member destroy
 77	 *
 78	 * @ttm: Pointer to a struct ttm_tt.
 
 79	 *
 80	 * Destroy the backend. This will be call back from ttm_tt_destroy so
 81	 * don't call ttm_tt_destroy from the callback or infinite loop.
 
 82	 */
 83	void (*destroy) (struct ttm_tt *ttm);
 84};
 
 
 85
 86/**
 87 * struct ttm_tt
 88 *
 89 * @bdev: Pointer to a struct ttm_bo_device.
 90 * @func: Pointer to a struct ttm_backend_func that describes
 91 * the backend methods.
 92 * pointer.
 93 * @pages: Array of pages backing the data.
 94 * @num_pages: Number of pages in the page array.
 95 * @bdev: Pointer to the current struct ttm_bo_device.
 96 * @be: Pointer to the ttm backend.
 97 * @swap_storage: Pointer to shmem struct file for swap storage.
 98 * @caching_state: The current caching state of the pages.
 99 * @state: The current binding state of the pages.
100 *
101 * This is a structure holding the pages, caching- and aperture binding
102 * status for a buffer object that isn't backed by fixed (VRAM / AGP)
103 * memory.
104 */
105struct ttm_tt {
106	struct ttm_bo_device *bdev;
107	struct ttm_backend_func *func;
108	struct page **pages;
109	uint32_t page_flags;
110	unsigned long num_pages;
111	struct sg_table *sg; /* for SG objects via dma-buf */
 
 
 
 
 
112	struct file *swap_storage;
113	enum ttm_caching_state caching_state;
114	enum {
115		tt_bound,
116		tt_unbound,
117		tt_unpopulated,
118	} state;
119};
120
121/**
122 * struct ttm_dma_tt
123 *
124 * @ttm: Base ttm_tt struct.
125 * @dma_address: The DMA (bus) addresses of the pages
126 * @pages_list: used by some page allocation backend
127 *
128 * This is a structure holding the pages, caching- and aperture binding
129 * status for a buffer object that isn't backed by fixed (VRAM / AGP)
130 * memory.
131 */
132struct ttm_dma_tt {
133	struct ttm_tt ttm;
134	dma_addr_t *dma_address;
135	struct list_head pages_list;
136};
137
 
 
 
 
 
138/**
139 * ttm_tt_create
140 *
141 * @bo: pointer to a struct ttm_buffer_object
142 * @zero_alloc: true if allocated pages needs to be zeroed
143 *
144 * Make sure we have a TTM structure allocated for the given BO.
145 * No pages are actually allocated.
146 */
147int ttm_tt_create(struct ttm_buffer_object *bo, bool zero_alloc);
148
149/**
150 * ttm_tt_init
151 *
152 * @ttm: The struct ttm_tt.
153 * @bo: The buffer object we create the ttm for.
154 * @page_flags: Page flags as identified by TTM_PAGE_FLAG_XX flags.
 
 
155 *
156 * Create a struct ttm_tt to back data with system memory pages.
157 * No pages are actually allocated.
158 * Returns:
159 * NULL: Out of memory.
160 */
161int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo,
162		uint32_t page_flags);
163int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object *bo,
164		    uint32_t page_flags);
165int ttm_sg_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object *bo,
166		   uint32_t page_flags);
167
168/**
169 * ttm_tt_fini
170 *
171 * @ttm: the ttm_tt structure.
172 *
173 * Free memory of ttm_tt structure
174 */
175void ttm_tt_fini(struct ttm_tt *ttm);
176void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma);
177
178/**
179 * ttm_ttm_bind:
180 *
181 * @ttm: The struct ttm_tt containing backing pages.
182 * @bo_mem: The struct ttm_mem_reg identifying the binding location.
183 *
184 * Bind the pages of @ttm to an aperture location identified by @bo_mem
185 */
186int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem,
187		struct ttm_operation_ctx *ctx);
188
189/**
190 * ttm_ttm_destroy:
191 *
 
192 * @ttm: The struct ttm_tt.
193 *
194 * Unbind, unpopulate and destroy common struct ttm_tt.
195 */
196void ttm_tt_destroy(struct ttm_tt *ttm);
197
198/**
199 * ttm_ttm_unbind:
200 *
201 * @ttm: The struct ttm_tt.
202 *
203 * Unbind a struct ttm_tt.
204 */
205void ttm_tt_unbind(struct ttm_tt *ttm);
206
207/**
208 * ttm_tt_swapin:
209 *
210 * @ttm: The struct ttm_tt.
211 *
212 * Swap in a previously swap out ttm_tt.
213 */
214int ttm_tt_swapin(struct ttm_tt *ttm);
 
 
215
216/**
217 * ttm_tt_set_placement_caching:
218 *
219 * @ttm A struct ttm_tt the backing pages of which will change caching policy.
220 * @placement: Flag indicating the desired caching policy.
 
221 *
222 * This function will change caching policy of any default kernel mappings of
223 * the pages backing @ttm. If changing from cached to uncached or
224 * write-combined,
225 * all CPU caches will first be flushed to make sure the data of the pages
226 * hit RAM. This function may be very costly as it involves global TLB
227 * and cache flushes and potential page splitting / combining.
228 */
229int ttm_tt_set_placement_caching(struct ttm_tt *ttm, uint32_t placement);
230int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage);
231
232/**
233 * ttm_tt_populate - allocate pages for a ttm
234 *
 
235 * @ttm: Pointer to the ttm_tt structure
236 *
237 * Calls the driver method to allocate pages for a ttm
238 */
239int ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
240
241/**
242 * ttm_tt_unpopulate - free pages from a ttm
243 *
244 * @ttm: Pointer to the ttm_tt structure
245 *
246 * Calls the driver method to free all pages from a ttm
 
247 */
248void ttm_tt_unpopulate(struct ttm_tt *ttm);
 
 
 
 
 
 
 
 
249
250#if IS_ENABLED(CONFIG_AGP)
251#include <linux/agp_backend.h>
252
253/**
254 * ttm_agp_tt_create
255 *
256 * @bo: Buffer object we allocate the ttm for.
257 * @bridge: The agp bridge this device is sitting on.
258 * @page_flags: Page flags as identified by TTM_PAGE_FLAG_XX flags.
259 *
260 *
261 * Create a TTM backend that uses the indicated AGP bridge as an aperture
262 * for TT memory. This function uses the linux agpgart interface to
263 * bind and unbind memory backing a ttm_tt.
264 */
265struct ttm_tt *ttm_agp_tt_create(struct ttm_buffer_object *bo,
266				 struct agp_bridge_data *bridge,
267				 uint32_t page_flags);
268int ttm_agp_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
269void ttm_agp_tt_unpopulate(struct ttm_tt *ttm);
 
 
270#endif
271
272#endif