split dev_queue
[cor.git] / include / drm / ttm / ttm_tt.h
blobc0e928abf59207b118fc0afe887c73c5f1351cbf
1 /**************************************************************************
3 * Copyright (c) 2006-2009 Vmware, Inc., Palo Alto, CA., USA
4 * All Rights Reserved.
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:
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.
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.
26 **************************************************************************/
27 #ifndef _TTM_TT_H_
28 #define _TTM_TT_H_
30 #include <linux/types.h>
32 struct ttm_tt;
33 struct ttm_mem_reg;
34 struct ttm_buffer_object;
35 struct ttm_operation_ctx;
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)
45 enum ttm_caching_state {
46 tt_uncached,
47 tt_wc,
48 tt_cached
51 struct ttm_backend_func {
52 /**
53 * struct ttm_backend_func member bind
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.
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.
63 int (*bind) (struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem);
65 /**
66 * struct ttm_backend_func member unbind
68 * @ttm: Pointer to a struct ttm_tt.
70 * Unbind previously bound backend pages. This function should be
71 * able to handle differences between aperture and system page sizes.
73 int (*unbind) (struct ttm_tt *ttm);
75 /**
76 * struct ttm_backend_func member destroy
78 * @ttm: Pointer to a struct ttm_tt.
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.
83 void (*destroy) (struct ttm_tt *ttm);
86 /**
87 * struct ttm_tt
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.
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.
105 struct 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;
122 * struct ttm_dma_tt
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
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.
132 struct ttm_dma_tt {
133 struct ttm_tt ttm;
134 dma_addr_t *dma_address;
135 struct list_head pages_list;
139 * ttm_tt_create
141 * @bo: pointer to a struct ttm_buffer_object
142 * @zero_alloc: true if allocated pages needs to be zeroed
144 * Make sure we have a TTM structure allocated for the given BO.
145 * No pages are actually allocated.
147 int ttm_tt_create(struct ttm_buffer_object *bo, bool zero_alloc);
150 * ttm_tt_init
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.
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.
161 int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo,
162 uint32_t page_flags);
163 int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object *bo,
164 uint32_t page_flags);
165 int ttm_sg_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object *bo,
166 uint32_t page_flags);
169 * ttm_tt_fini
171 * @ttm: the ttm_tt structure.
173 * Free memory of ttm_tt structure
175 void ttm_tt_fini(struct ttm_tt *ttm);
176 void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma);
179 * ttm_ttm_bind:
181 * @ttm: The struct ttm_tt containing backing pages.
182 * @bo_mem: The struct ttm_mem_reg identifying the binding location.
184 * Bind the pages of @ttm to an aperture location identified by @bo_mem
186 int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem,
187 struct ttm_operation_ctx *ctx);
190 * ttm_ttm_destroy:
192 * @ttm: The struct ttm_tt.
194 * Unbind, unpopulate and destroy common struct ttm_tt.
196 void ttm_tt_destroy(struct ttm_tt *ttm);
199 * ttm_ttm_unbind:
201 * @ttm: The struct ttm_tt.
203 * Unbind a struct ttm_tt.
205 void ttm_tt_unbind(struct ttm_tt *ttm);
208 * ttm_tt_swapin:
210 * @ttm: The struct ttm_tt.
212 * Swap in a previously swap out ttm_tt.
214 int ttm_tt_swapin(struct ttm_tt *ttm);
217 * ttm_tt_set_placement_caching:
219 * @ttm A struct ttm_tt the backing pages of which will change caching policy.
220 * @placement: Flag indicating the desired caching policy.
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.
229 int ttm_tt_set_placement_caching(struct ttm_tt *ttm, uint32_t placement);
230 int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage);
233 * ttm_tt_populate - allocate pages for a ttm
235 * @ttm: Pointer to the ttm_tt structure
237 * Calls the driver method to allocate pages for a ttm
239 int ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
242 * ttm_tt_unpopulate - free pages from a ttm
244 * @ttm: Pointer to the ttm_tt structure
246 * Calls the driver method to free all pages from a ttm
248 void ttm_tt_unpopulate(struct ttm_tt *ttm);
250 #if IS_ENABLED(CONFIG_AGP)
251 #include <linux/agp_backend.h>
254 * ttm_agp_tt_create
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.
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.
265 struct ttm_tt *ttm_agp_tt_create(struct ttm_buffer_object *bo,
266 struct agp_bridge_data *bridge,
267 uint32_t page_flags);
268 int ttm_agp_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
269 void ttm_agp_tt_unpopulate(struct ttm_tt *ttm);
270 #endif
272 #endif