Subversion Repositories Kolibri OS

Rev

Rev 1630 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1408 serge 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
/*
28
 * Authors: Thomas Hellstrom 
29
 */
30
 
31
#ifndef _TTM_BO_API_H_
32
#define _TTM_BO_API_H_
33
 
34
#include "drm_hashtab.h"
35
#include 
36
#include 
37
 
38
#include 
39
 
40
//#include 
41
//#include 
42
//#include 
43
//#include 
44
#include 
45
 
46
struct ttm_bo_device;
47
 
48
struct drm_mm_node;
49
 
50
 
51
/**
52
 * struct ttm_placement
53
 *
54
 * @fpfn:		first valid page frame number to put the object
55
 * @lpfn:		last valid page frame number to put the object
56
 * @num_placement:	number of prefered placements
57
 * @placement:		prefered placements
58
 * @num_busy_placement:	number of prefered placements when need to evict buffer
59
 * @busy_placement:	prefered placements when need to evict buffer
60
 *
61
 * Structure indicating the placement you request for an object.
62
 */
63
struct ttm_placement {
64
	unsigned	fpfn;
65
	unsigned	lpfn;
66
	unsigned	num_placement;
67
	const uint32_t	*placement;
68
	unsigned	num_busy_placement;
69
	const uint32_t	*busy_placement;
70
};
71
 
72
 
73
/**
74
 * struct ttm_mem_reg
75
 *
76
 * @mm_node: Memory manager node.
77
 * @size: Requested size of memory region.
78
 * @num_pages: Actual size of memory region in pages.
79
 * @page_alignment: Page alignment.
80
 * @placement: Placement flags.
81
 *
82
 * Structure indicating the placement and space resources used by a
83
 * buffer object.
84
 */
85
 
86
struct ttm_mem_reg {
87
	struct drm_mm_node *mm_node;
88
	unsigned long size;
89
	unsigned long num_pages;
90
	uint32_t page_alignment;
91
	uint32_t mem_type;
92
	uint32_t placement;
93
};
94
 
95
/**
96
 * enum ttm_bo_type
97
 *
98
 * @ttm_bo_type_device:	These are 'normal' buffers that can
99
 * be mmapped by user space. Each of these bos occupy a slot in the
100
 * device address space, that can be used for normal vm operations.
101
 *
102
 * @ttm_bo_type_user: These are user-space memory areas that are made
103
 * available to the GPU by mapping the buffer pages into the GPU aperture
104
 * space. These buffers cannot be mmaped from the device address space.
105
 *
106
 * @ttm_bo_type_kernel: These buffers are like ttm_bo_type_device buffers,
107
 * but they cannot be accessed from user-space. For kernel-only use.
108
 */
109
 
110
enum ttm_bo_type {
111
	ttm_bo_type_device,
112
	ttm_bo_type_user,
113
	ttm_bo_type_kernel
114
};
115
 
116
struct ttm_tt;
117
 
118
/**
119
 * struct ttm_buffer_object
120
 *
121
 * @bdev: Pointer to the buffer object device structure.
122
 * @buffer_start: The virtual user-space start address of ttm_bo_type_user
123
 * buffers.
124
 * @type: The bo type.
125
 * @destroy: Destruction function. If NULL, kfree is used.
126
 * @num_pages: Actual number of pages.
127
 * @addr_space_offset: Address space offset.
128
 * @acc_size: Accounted size for this object.
129
 * @kref: Reference count of this buffer object. When this refcount reaches
130
 * zero, the object is put on the delayed delete list.
131
 * @list_kref: List reference count of this buffer object. This member is
132
 * used to avoid destruction while the buffer object is still on a list.
133
 * Lru lists may keep one refcount, the delayed delete list, and kref != 0
134
 * keeps one refcount. When this refcount reaches zero,
135
 * the object is destroyed.
136
 * @event_queue: Queue for processes waiting on buffer object status change.
137
 * @lock: spinlock protecting mostly synchronization members.
138
 * @mem: structure describing current placement.
139
 * @persistant_swap_storage: Usually the swap storage is deleted for buffers
140
 * pinned in physical memory. If this behaviour is not desired, this member
141
 * holds a pointer to a persistant shmem object.
142
 * @ttm: TTM structure holding system pages.
143
 * @evicted: Whether the object was evicted without user-space knowing.
144
 * @cpu_writes: For synchronization. Number of cpu writers.
145
 * @lru: List head for the lru list.
146
 * @ddestroy: List head for the delayed destroy list.
147
 * @swap: List head for swap LRU list.
148
 * @val_seq: Sequence of the validation holding the @reserved lock.
149
 * Used to avoid starvation when many processes compete to validate the
150
 * buffer. This member is protected by the bo_device::lru_lock.
151
 * @seq_valid: The value of @val_seq is valid. This value is protected by
152
 * the bo_device::lru_lock.
153
 * @reserved: Deadlock-free lock used for synchronization state transitions.
154
 * @sync_obj_arg: Opaque argument to synchronization object function.
155
 * @sync_obj: Pointer to a synchronization object.
156
 * @priv_flags: Flags describing buffer object internal state.
157
 * @vm_rb: Rb node for the vm rb tree.
158
 * @vm_node: Address space manager node.
159
 * @offset: The current GPU offset, which can have different meanings
160
 * depending on the memory type. For SYSTEM type memory, it should be 0.
161
 * @cur_placement: Hint of current placement.
162
 *
163
 * Base class for TTM buffer object, that deals with data placement and CPU
164
 * mappings. GPU mappings are really up to the driver, but for simpler GPUs
165
 * the driver can usually use the placement offset @offset directly as the
166
 * GPU virtual address. For drivers implementing multiple
167
 * GPU memory manager contexts, the driver should manage the address space
168
 * in these contexts separately and use these objects to get the correct
169
 * placement and caching for these GPU maps. This makes it possible to use
170
 * these objects for even quite elaborate memory management schemes.
171
 * The destroy member, the API visibility of this object makes it possible
172
 * to derive driver specific types.
173
 */
174
 
175
struct ttm_buffer_object {
176
	/**
177
	 * Members constant at init.
178
	 */
179
 
180
	struct ttm_bo_global *glob;
181
	struct ttm_bo_device *bdev;
182
	unsigned long buffer_start;
183
	enum ttm_bo_type type;
184
	void (*destroy) (struct ttm_buffer_object *);
185
	unsigned long num_pages;
186
	uint64_t addr_space_offset;
187
	size_t acc_size;
188
 
189
	/**
190
	* Members not needing protection.
191
	*/
192
 
193
   struct kref kref;
194
   struct kref list_kref;
195
//   wait_queue_head_t event_queue;
196
   spinlock_t lock;
197
 
198
	/**
199
	 * Members protected by the bo::reserved lock.
200
	 */
201
 
202
	struct ttm_mem_reg mem;
203
//   struct file *persistant_swap_storage;
204
	struct ttm_tt *ttm;
205
	bool evicted;
206
 
207
	/**
208
	 * Members protected by the bo::reserved lock only when written to.
209
	 */
210
 
211
   atomic_t cpu_writers;
212
 
213
	/**
214
	 * Members protected by the bdev::lru_lock.
215
	 */
216
 
217
	struct list_head lru;
218
	struct list_head ddestroy;
219
	struct list_head swap;
220
	uint32_t val_seq;
221
	bool seq_valid;
222
 
223
	/**
224
	 * Members protected by the bdev::lru_lock
225
	 * only when written to.
226
	 */
227
 
228
   atomic_t reserved;
229
 
230
 
231
	/**
232
	 * Members protected by the bo::lock
233
	 */
234
 
235
	void *sync_obj_arg;
236
	void *sync_obj;
237
	unsigned long priv_flags;
238
 
239
	/**
240
	 * Members protected by the bdev::vm_lock
241
	 */
242
 
243
//   struct rb_node vm_rb;
244
	struct drm_mm_node *vm_node;
245
 
246
 
247
	/**
248
	 * Special members that are protected by the reserve lock
249
	 * and the bo::lock when written to. Can be read with
250
	 * either of these locks held.
251
	 */
252
 
253
	unsigned long offset;
254
	uint32_t cur_placement;
255
};
256
 
257
/**
258
 * struct ttm_bo_kmap_obj
259
 *
260
 * @virtual: The current kernel virtual address.
261
 * @page: The page when kmap'ing a single page.
262
 * @bo_kmap_type: Type of bo_kmap.
263
 *
264
 * Object describing a kernel mapping. Since a TTM bo may be located
265
 * in various memory types with various caching policies, the
266
 * mapping can either be an ioremap, a vmap, a kmap or part of a
267
 * premapped region.