1 /**************************************************************************
3 * Copyright (c) 2006-2009 Vmware, Inc., Palo Alto, CA., USA
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
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 **************************************************************************/
30 #include <linux/types.h>
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 {
54 * @pages: Array of pages backing the data.
55 * @num_pages: Number of pages in the page array.
56 * @bdev: Pointer to the current struct ttm_bo_device.
57 * @be: Pointer to the ttm backend.
58 * @swap_storage: Pointer to shmem struct file for swap storage.
59 * @caching_state: The current caching state of the pages.
60 * @state: The current binding state of the pages.
62 * This is a structure holding the pages, caching- and aperture binding
63 * status for a buffer object that isn't backed by fixed (VRAM / AGP)
69 unsigned long num_pages;
70 struct sg_table *sg; /* for SG objects via dma-buf */
71 struct file *swap_storage;
72 enum ttm_caching_state caching_state;
83 * @ttm: Base ttm_tt struct.
84 * @dma_address: The DMA (bus) addresses of the pages
85 * @pages_list: used by some page allocation backend
87 * This is a structure holding the pages, caching- and aperture binding
88 * status for a buffer object that isn't backed by fixed (VRAM / AGP)
93 dma_addr_t *dma_address;
94 struct list_head pages_list;
100 * @bo: pointer to a struct ttm_buffer_object
101 * @zero_alloc: true if allocated pages needs to be zeroed
103 * Make sure we have a TTM structure allocated for the given BO.
104 * No pages are actually allocated.
106 int ttm_tt_create(struct ttm_buffer_object *bo, bool zero_alloc);
111 * @ttm: The struct ttm_tt.
112 * @bo: The buffer object we create the ttm for.
113 * @page_flags: Page flags as identified by TTM_PAGE_FLAG_XX flags.
115 * Create a struct ttm_tt to back data with system memory pages.
116 * No pages are actually allocated.
118 * NULL: Out of memory.
120 int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo,
121 uint32_t page_flags);
122 int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object *bo,
123 uint32_t page_flags);
124 int ttm_sg_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object *bo,
125 uint32_t page_flags);
130 * @ttm: the ttm_tt structure.
132 * Free memory of ttm_tt structure
134 void ttm_tt_fini(struct ttm_tt *ttm);
135 void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma);
140 * @ttm: The struct ttm_tt containing backing pages.
141 * @bo_mem: The struct ttm_resource identifying the binding location.
143 * Bind the pages of @ttm to an aperture location identified by @bo_mem
145 int ttm_tt_bind(struct ttm_bo_device *bdev,
146 struct ttm_tt *ttm, struct ttm_resource *bo_mem,
147 struct ttm_operation_ctx *ctx);
152 * @ttm: The struct ttm_tt.
154 * Unbind, unpopulate and destroy common struct ttm_tt.
156 void ttm_tt_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
161 * @ttm: The struct ttm_tt.
163 * Unbind a struct ttm_tt.
165 void ttm_tt_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
170 * @ttm: The struct ttm_tt.
172 * Swap in a previously swap out ttm_tt.
174 int ttm_tt_swapin(struct ttm_tt *ttm);
177 * ttm_tt_set_placement_caching:
179 * @ttm A struct ttm_tt the backing pages of which will change caching policy.
180 * @placement: Flag indicating the desired caching policy.
182 * This function will change caching policy of any default kernel mappings of
183 * the pages backing @ttm. If changing from cached to uncached or
185 * all CPU caches will first be flushed to make sure the data of the pages
186 * hit RAM. This function may be very costly as it involves global TLB
187 * and cache flushes and potential page splitting / combining.
189 int ttm_tt_set_placement_caching(struct ttm_tt *ttm, uint32_t placement);
190 int ttm_tt_swapout(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct file *persistent_swap_storage);
193 * ttm_tt_populate - allocate pages for a ttm
195 * @ttm: Pointer to the ttm_tt structure
197 * Calls the driver method to allocate pages for a ttm
199 int ttm_tt_populate(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
202 * ttm_tt_unpopulate - free pages from a ttm
204 * @ttm: Pointer to the ttm_tt structure
206 * Calls the driver method to free all pages from a ttm
208 void ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
210 #if IS_ENABLED(CONFIG_AGP)
211 #include <linux/agp_backend.h>
216 * @bo: Buffer object we allocate the ttm for.
217 * @bridge: The agp bridge this device is sitting on.
218 * @page_flags: Page flags as identified by TTM_PAGE_FLAG_XX flags.
221 * Create a TTM backend that uses the indicated AGP bridge as an aperture
222 * for TT memory. This function uses the linux agpgart interface to
223 * bind and unbind memory backing a ttm_tt.
225 struct ttm_tt *ttm_agp_tt_create(struct ttm_buffer_object *bo,
226 struct agp_bridge_data *bridge,
227 uint32_t page_flags);
228 int ttm_agp_bind(struct ttm_tt *ttm, struct ttm_resource *bo_mem);
229 void ttm_agp_unbind(struct ttm_tt *ttm);
230 void ttm_agp_destroy(struct ttm_tt *ttm);