drm/ttm: nuke caching placement flags
[linux-2.6-microblaze.git] / include / drm / ttm / ttm_tt.h
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 #include <drm/ttm/ttm_caching.h>
32
33 struct ttm_tt;
34 struct ttm_resource;
35 struct ttm_buffer_object;
36 struct ttm_operation_ctx;
37
38 #define TTM_PAGE_FLAG_SWAPPED         (1 << 4)
39 #define TTM_PAGE_FLAG_ZERO_ALLOC      (1 << 6)
40 #define TTM_PAGE_FLAG_DMA32           (1 << 7)
41 #define TTM_PAGE_FLAG_SG              (1 << 8)
42 #define TTM_PAGE_FLAG_NO_RETRY        (1 << 9)
43
44 #define TTM_PAGE_FLAG_PRIV_POPULATED  (1 << 31)
45
46 /**
47  * struct ttm_tt
48  *
49  * @pages: Array of pages backing the data.
50  * @num_pages: Number of pages in the page array.
51  * @bdev: Pointer to the current struct ttm_bo_device.
52  * @be: Pointer to the ttm backend.
53  * @swap_storage: Pointer to shmem struct file for swap storage.
54  * @caching_state: The current caching state of the pages.
55  * @state: The current binding state of the pages.
56  *
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.
60  */
61 struct ttm_tt {
62         struct page **pages;
63         uint32_t page_flags;
64         unsigned long num_pages;
65         struct sg_table *sg; /* for SG objects via dma-buf */
66         struct file *swap_storage;
67         enum ttm_caching caching;
68 };
69
70 static inline bool ttm_tt_is_populated(struct ttm_tt *tt)
71 {
72         return tt->page_flags & TTM_PAGE_FLAG_PRIV_POPULATED;
73 }
74
75 static inline void ttm_tt_set_unpopulated(struct ttm_tt *tt)
76 {
77         tt->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED;
78 }
79
80 static inline void ttm_tt_set_populated(struct ttm_tt *tt)
81 {
82         tt->page_flags |= TTM_PAGE_FLAG_PRIV_POPULATED;
83 }
84
85 /**
86  * struct ttm_dma_tt
87  *
88  * @ttm: Base ttm_tt struct.
89  * @dma_address: The DMA (bus) addresses of the pages
90  * @pages_list: used by some page allocation backend
91  *
92  * This is a structure holding the pages, caching- and aperture binding
93  * status for a buffer object that isn't backed by fixed (VRAM / AGP)
94  * memory.
95  */
96 struct ttm_dma_tt {
97         struct ttm_tt ttm;
98         dma_addr_t *dma_address;
99         struct list_head pages_list;
100 };
101
102 /**
103  * ttm_tt_create
104  *
105  * @bo: pointer to a struct ttm_buffer_object
106  * @zero_alloc: true if allocated pages needs to be zeroed
107  *
108  * Make sure we have a TTM structure allocated for the given BO.
109  * No pages are actually allocated.
110  */
111 int ttm_tt_create(struct ttm_buffer_object *bo, bool zero_alloc);
112
113 /**
114  * ttm_tt_init
115  *
116  * @ttm: The struct ttm_tt.
117  * @bo: The buffer object we create the ttm for.
118  * @page_flags: Page flags as identified by TTM_PAGE_FLAG_XX flags.
119  * @caching: the desired caching state of the pages
120  *
121  * Create a struct ttm_tt to back data with system memory pages.
122  * No pages are actually allocated.
123  * Returns:
124  * NULL: Out of memory.
125  */
126 int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo,
127                 uint32_t page_flags, enum ttm_caching caching);
128 int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object *bo,
129                     uint32_t page_flags, enum ttm_caching caching);
130 int ttm_sg_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object *bo,
131                    uint32_t page_flags, enum ttm_caching caching);
132
133 /**
134  * ttm_tt_fini
135  *
136  * @ttm: the ttm_tt structure.
137  *
138  * Free memory of ttm_tt structure
139  */
140 void ttm_tt_fini(struct ttm_tt *ttm);
141 void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma);
142
143 /**
144  * ttm_ttm_destroy:
145  *
146  * @ttm: The struct ttm_tt.
147  *
148  * Unbind, unpopulate and destroy common struct ttm_tt.
149  */
150 void ttm_tt_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
151
152 /**
153  * ttm_tt_destroy_common:
154  *
155  * Called from driver to destroy common path.
156  */
157 void ttm_tt_destroy_common(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
158
159 /**
160  * ttm_tt_swapin:
161  *
162  * @ttm: The struct ttm_tt.
163  *
164  * Swap in a previously swap out ttm_tt.
165  */
166 int ttm_tt_swapin(struct ttm_tt *ttm);
167 int ttm_tt_swapout(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
168
169 /**
170  * ttm_tt_populate - allocate pages for a ttm
171  *
172  * @ttm: Pointer to the ttm_tt structure
173  *
174  * Calls the driver method to allocate pages for a ttm
175  */
176 int ttm_tt_populate(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
177
178 /**
179  * ttm_tt_unpopulate - free pages from a ttm
180  *
181  * @ttm: Pointer to the ttm_tt structure
182  *
183  * Calls the driver method to free all pages from a ttm
184  */
185 void ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
186
187 #if IS_ENABLED(CONFIG_AGP)
188 #include <linux/agp_backend.h>
189
190 /**
191  * ttm_agp_tt_create
192  *
193  * @bo: Buffer object we allocate the ttm for.
194  * @bridge: The agp bridge this device is sitting on.
195  * @page_flags: Page flags as identified by TTM_PAGE_FLAG_XX flags.
196  *
197  *
198  * Create a TTM backend that uses the indicated AGP bridge as an aperture
199  * for TT memory. This function uses the linux agpgart interface to
200  * bind and unbind memory backing a ttm_tt.
201  */
202 struct ttm_tt *ttm_agp_tt_create(struct ttm_buffer_object *bo,
203                                  struct agp_bridge_data *bridge,
204                                  uint32_t page_flags);
205 int ttm_agp_bind(struct ttm_tt *ttm, struct ttm_resource *bo_mem);
206 void ttm_agp_unbind(struct ttm_tt *ttm);
207 void ttm_agp_destroy(struct ttm_tt *ttm);
208 bool ttm_agp_is_bound(struct ttm_tt *ttm);
209 #endif
210
211 #endif