Merge tag 'iommu-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux
[linux/fpc-iii.git] / include / drm / ttm / ttm_tt.h
blobda27e9d8fa64ee509c7a5a208e69a86dbaf51ad0
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>
31 #include <drm/ttm/ttm_caching.h>
33 struct ttm_tt;
34 struct ttm_resource;
35 struct ttm_buffer_object;
36 struct ttm_operation_ctx;
38 #define TTM_PAGE_FLAG_SWAPPED (1 << 4)
39 #define TTM_PAGE_FLAG_ZERO_ALLOC (1 << 6)
40 #define TTM_PAGE_FLAG_SG (1 << 8)
41 #define TTM_PAGE_FLAG_NO_RETRY (1 << 9)
43 #define TTM_PAGE_FLAG_PRIV_POPULATED (1 << 31)
45 /**
46 * struct ttm_tt
48 * @pages: Array of pages backing the data.
49 * @page_flags: see TTM_PAGE_FLAG_*
50 * @num_pages: Number of pages in the page array.
51 * @sg: for SG objects via dma-buf
52 * @dma_address: The DMA (bus) addresses of the pages
53 * @swap_storage: Pointer to shmem struct file for swap storage.
54 * @pages_list: used by some page allocation backend
55 * @caching: The current caching state of the pages.
57 * This is a structure holding the pages, caching- and aperture binding
58 * status for a buffer object that isn't backed by fixed (VRAM / AGP)
59 * memory.
61 struct ttm_tt {
62 struct page **pages;
63 uint32_t page_flags;
64 uint32_t num_pages;
65 struct sg_table *sg;
66 dma_addr_t *dma_address;
67 struct file *swap_storage;
68 enum ttm_caching caching;
71 static inline bool ttm_tt_is_populated(struct ttm_tt *tt)
73 return tt->page_flags & TTM_PAGE_FLAG_PRIV_POPULATED;
76 /**
77 * ttm_tt_create
79 * @bo: pointer to a struct ttm_buffer_object
80 * @zero_alloc: true if allocated pages needs to be zeroed
82 * Make sure we have a TTM structure allocated for the given BO.
83 * No pages are actually allocated.
85 int ttm_tt_create(struct ttm_buffer_object *bo, bool zero_alloc);
87 /**
88 * ttm_tt_init
90 * @ttm: The struct ttm_tt.
91 * @bo: The buffer object we create the ttm for.
92 * @page_flags: Page flags as identified by TTM_PAGE_FLAG_XX flags.
93 * @caching: the desired caching state of the pages
95 * Create a struct ttm_tt to back data with system memory pages.
96 * No pages are actually allocated.
97 * Returns:
98 * NULL: Out of memory.
100 int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo,
101 uint32_t page_flags, enum ttm_caching caching);
102 int ttm_dma_tt_init(struct ttm_tt *ttm_dma, struct ttm_buffer_object *bo,
103 uint32_t page_flags, enum ttm_caching caching);
104 int ttm_sg_tt_init(struct ttm_tt *ttm_dma, struct ttm_buffer_object *bo,
105 uint32_t page_flags, enum ttm_caching caching);
108 * ttm_tt_fini
110 * @ttm: the ttm_tt structure.
112 * Free memory of ttm_tt structure
114 void ttm_tt_fini(struct ttm_tt *ttm);
117 * ttm_ttm_destroy:
119 * @ttm: The struct ttm_tt.
121 * Unbind, unpopulate and destroy common struct ttm_tt.
123 void ttm_tt_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
126 * ttm_tt_destroy_common:
128 * Called from driver to destroy common path.
130 void ttm_tt_destroy_common(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
133 * ttm_tt_swapin:
135 * @ttm: The struct ttm_tt.
137 * Swap in a previously swap out ttm_tt.
139 int ttm_tt_swapin(struct ttm_tt *ttm);
140 int ttm_tt_swapout(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
143 * ttm_tt_populate - allocate pages for a ttm
145 * @ttm: Pointer to the ttm_tt structure
147 * Calls the driver method to allocate pages for a ttm
149 int ttm_tt_populate(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
152 * ttm_tt_unpopulate - free pages from a ttm
154 * @ttm: Pointer to the ttm_tt structure
156 * Calls the driver method to free all pages from a ttm
158 void ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
160 #if IS_ENABLED(CONFIG_AGP)
161 #include <linux/agp_backend.h>
164 * ttm_agp_tt_create
166 * @bo: Buffer object we allocate the ttm for.
167 * @bridge: The agp bridge this device is sitting on.
168 * @page_flags: Page flags as identified by TTM_PAGE_FLAG_XX flags.
171 * Create a TTM backend that uses the indicated AGP bridge as an aperture
172 * for TT memory. This function uses the linux agpgart interface to
173 * bind and unbind memory backing a ttm_tt.
175 struct ttm_tt *ttm_agp_tt_create(struct ttm_buffer_object *bo,
176 struct agp_bridge_data *bridge,
177 uint32_t page_flags);
178 int ttm_agp_bind(struct ttm_tt *ttm, struct ttm_resource *bo_mem);
179 void ttm_agp_unbind(struct ttm_tt *ttm);
180 void ttm_agp_destroy(struct ttm_tt *ttm);
181 bool ttm_agp_is_bound(struct ttm_tt *ttm);
182 #endif
184 #endif