blob: 49b43c23636af87011d5010d19be01f02594e8c7 [file] [log] [blame]
Thomas Hellstromba4e7d92009-06-10 15:20:19 +02001/**************************************************************************
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 <thellstrom-at-vmware-dot-com>
29 */
30
31#ifndef _TTM_BO_API_H_
32#define _TTM_BO_API_H_
33
34#include "drm_hashtab.h"
35#include <linux/kref.h>
36#include <linux/list.h>
37#include <linux/wait.h>
38#include <linux/mutex.h>
39#include <linux/mm.h>
40#include <linux/rbtree.h>
41#include <linux/bitmap.h>
42
43struct ttm_bo_device;
44
45struct drm_mm_node;
46
Jerome Glisseca262a9992009-12-08 15:33:32 +010047
48/**
49 * struct ttm_placement
50 *
51 * @fpfn: first valid page frame number to put the object
52 * @lpfn: last valid page frame number to put the object
53 * @num_placement: number of prefered placements
54 * @placement: prefered placements
55 * @num_busy_placement: number of prefered placements when need to evict buffer
56 * @busy_placement: prefered placements when need to evict buffer
57 *
58 * Structure indicating the placement you request for an object.
59 */
60struct ttm_placement {
61 unsigned fpfn;
62 unsigned lpfn;
63 unsigned num_placement;
64 const uint32_t *placement;
65 unsigned num_busy_placement;
66 const uint32_t *busy_placement;
67};
68
Jerome Glisse82c5da62010-04-09 14:39:23 +020069/**
70 * struct ttm_bus_placement
71 *
72 * @addr: mapped virtual address
73 * @base: bus base address
74 * @is_iomem: is this io memory ?
75 * @size: size in byte
76 * @offset: offset from the base address
77 *
78 * Structure indicating the bus placement of an object.
79 */
80struct ttm_bus_placement {
81 void *addr;
82 unsigned long base;
83 unsigned long size;
84 unsigned long offset;
85 bool is_iomem;
86 bool io_reserved;
87};
88
Jerome Glisseca262a9992009-12-08 15:33:32 +010089
Thomas Hellstromba4e7d92009-06-10 15:20:19 +020090/**
91 * struct ttm_mem_reg
92 *
93 * @mm_node: Memory manager node.
94 * @size: Requested size of memory region.
95 * @num_pages: Actual size of memory region in pages.
96 * @page_alignment: Page alignment.
97 * @placement: Placement flags.
Jerome Glisse82c5da62010-04-09 14:39:23 +020098 * @bus: Placement on io bus accessible to the CPU
Thomas Hellstromba4e7d92009-06-10 15:20:19 +020099 *
100 * Structure indicating the placement and space resources used by a
101 * buffer object.
102 */
103
104struct ttm_mem_reg {
Ben Skeggsd961db72010-08-05 10:48:18 +1000105 void *mm_node;
106 unsigned long start;
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200107 unsigned long size;
108 unsigned long num_pages;
109 uint32_t page_alignment;
110 uint32_t mem_type;
111 uint32_t placement;
Jerome Glisse82c5da62010-04-09 14:39:23 +0200112 struct ttm_bus_placement bus;
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200113};
114
115/**
116 * enum ttm_bo_type
117 *
118 * @ttm_bo_type_device: These are 'normal' buffers that can
119 * be mmapped by user space. Each of these bos occupy a slot in the
120 * device address space, that can be used for normal vm operations.
121 *
122 * @ttm_bo_type_user: These are user-space memory areas that are made
123 * available to the GPU by mapping the buffer pages into the GPU aperture
124 * space. These buffers cannot be mmaped from the device address space.
125 *
126 * @ttm_bo_type_kernel: These buffers are like ttm_bo_type_device buffers,
127 * but they cannot be accessed from user-space. For kernel-only use.
128 */
129
130enum ttm_bo_type {
131 ttm_bo_type_device,
132 ttm_bo_type_user,
133 ttm_bo_type_kernel
134};
135
136struct ttm_tt;
137
138/**
139 * struct ttm_buffer_object
140 *
141 * @bdev: Pointer to the buffer object device structure.
142 * @buffer_start: The virtual user-space start address of ttm_bo_type_user
143 * buffers.
144 * @type: The bo type.
145 * @destroy: Destruction function. If NULL, kfree is used.
146 * @num_pages: Actual number of pages.
147 * @addr_space_offset: Address space offset.
148 * @acc_size: Accounted size for this object.
149 * @kref: Reference count of this buffer object. When this refcount reaches
150 * zero, the object is put on the delayed delete list.
151 * @list_kref: List reference count of this buffer object. This member is
152 * used to avoid destruction while the buffer object is still on a list.
153 * Lru lists may keep one refcount, the delayed delete list, and kref != 0
154 * keeps one refcount. When this refcount reaches zero,
155 * the object is destroyed.
156 * @event_queue: Queue for processes waiting on buffer object status change.
157 * @lock: spinlock protecting mostly synchronization members.
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200158 * @mem: structure describing current placement.
159 * @persistant_swap_storage: Usually the swap storage is deleted for buffers
160 * pinned in physical memory. If this behaviour is not desired, this member
161 * holds a pointer to a persistant shmem object.
162 * @ttm: TTM structure holding system pages.
163 * @evicted: Whether the object was evicted without user-space knowing.
164 * @cpu_writes: For synchronization. Number of cpu writers.
165 * @lru: List head for the lru list.
166 * @ddestroy: List head for the delayed destroy list.
167 * @swap: List head for swap LRU list.
168 * @val_seq: Sequence of the validation holding the @reserved lock.
169 * Used to avoid starvation when many processes compete to validate the
170 * buffer. This member is protected by the bo_device::lru_lock.
171 * @seq_valid: The value of @val_seq is valid. This value is protected by
172 * the bo_device::lru_lock.
173 * @reserved: Deadlock-free lock used for synchronization state transitions.
174 * @sync_obj_arg: Opaque argument to synchronization object function.
175 * @sync_obj: Pointer to a synchronization object.
176 * @priv_flags: Flags describing buffer object internal state.
177 * @vm_rb: Rb node for the vm rb tree.
178 * @vm_node: Address space manager node.
179 * @offset: The current GPU offset, which can have different meanings
180 * depending on the memory type. For SYSTEM type memory, it should be 0.
181 * @cur_placement: Hint of current placement.
182 *
183 * Base class for TTM buffer object, that deals with data placement and CPU
184 * mappings. GPU mappings are really up to the driver, but for simpler GPUs
185 * the driver can usually use the placement offset @offset directly as the
186 * GPU virtual address. For drivers implementing multiple
187 * GPU memory manager contexts, the driver should manage the address space
188 * in these contexts separately and use these objects to get the correct
189 * placement and caching for these GPU maps. This makes it possible to use
190 * these objects for even quite elaborate memory management schemes.
191 * The destroy member, the API visibility of this object makes it possible
192 * to derive driver specific types.
193 */
194
195struct ttm_buffer_object {
196 /**
197 * Members constant at init.
198 */
199
Thomas Hellstroma987fca2009-08-18 16:51:56 +0200200 struct ttm_bo_global *glob;
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200201 struct ttm_bo_device *bdev;
202 unsigned long buffer_start;
203 enum ttm_bo_type type;
204 void (*destroy) (struct ttm_buffer_object *);
205 unsigned long num_pages;
206 uint64_t addr_space_offset;
207 size_t acc_size;
208
209 /**
210 * Members not needing protection.
211 */
212
213 struct kref kref;
214 struct kref list_kref;
215 wait_queue_head_t event_queue;
216 spinlock_t lock;
217
218 /**
219 * Members protected by the bo::reserved lock.
220 */
221
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200222 struct ttm_mem_reg mem;
223 struct file *persistant_swap_storage;
224 struct ttm_tt *ttm;
225 bool evicted;
226
227 /**
228 * Members protected by the bo::reserved lock only when written to.
229 */
230
231 atomic_t cpu_writers;
232
233 /**
234 * Members protected by the bdev::lru_lock.
235 */
236
237 struct list_head lru;
238 struct list_head ddestroy;
239 struct list_head swap;
240 uint32_t val_seq;
241 bool seq_valid;
242
243 /**
244 * Members protected by the bdev::lru_lock
245 * only when written to.
246 */
247
248 atomic_t reserved;
249
250
251 /**
252 * Members protected by the bo::lock
253 */
254
255 void *sync_obj_arg;
256 void *sync_obj;
257 unsigned long priv_flags;
258
259 /**
260 * Members protected by the bdev::vm_lock
261 */
262
263 struct rb_node vm_rb;
264 struct drm_mm_node *vm_node;
265
266
267 /**
268 * Special members that are protected by the reserve lock
269 * and the bo::lock when written to. Can be read with
270 * either of these locks held.
271 */
272
273 unsigned long offset;
274 uint32_t cur_placement;
275};
276
277/**
278 * struct ttm_bo_kmap_obj
279 *
280 * @virtual: The current kernel virtual address.
281 * @page: The page when kmap'ing a single page.
282 * @bo_kmap_type: Type of bo_kmap.
283 *
284 * Object describing a kernel mapping. Since a TTM bo may be located
285 * in various memory types with various caching policies, the
286 * mapping can either be an ioremap, a vmap, a kmap or part of a
287 * premapped region.
288 */
289
Pekka Paalanena0724fc2009-08-17 01:18:38 +0300290#define TTM_BO_MAP_IOMEM_MASK 0x80
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200291struct ttm_bo_kmap_obj {
292 void *virtual;
293 struct page *page;
294 enum {
Pekka Paalanena0724fc2009-08-17 01:18:38 +0300295 ttm_bo_map_iomap = 1 | TTM_BO_MAP_IOMEM_MASK,
296 ttm_bo_map_vmap = 2,
297 ttm_bo_map_kmap = 3,
298 ttm_bo_map_premapped = 4 | TTM_BO_MAP_IOMEM_MASK,
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200299 } bo_kmap_type;
Jerome Glisse82c5da62010-04-09 14:39:23 +0200300 struct ttm_buffer_object *bo;
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200301};
302
303/**
304 * ttm_bo_reference - reference a struct ttm_buffer_object
305 *
306 * @bo: The buffer object.
307 *
308 * Returns a refcounted pointer to a buffer object.
309 */
310
311static inline struct ttm_buffer_object *
312ttm_bo_reference(struct ttm_buffer_object *bo)
313{
314 kref_get(&bo->kref);
315 return bo;
316}
317
318/**
319 * ttm_bo_wait - wait for buffer idle.
320 *
321 * @bo: The buffer object.
322 * @interruptible: Use interruptible wait.
323 * @no_wait: Return immediately if buffer is busy.
324 *
325 * This function must be called with the bo::mutex held, and makes
326 * sure any previous rendering to the buffer is completed.
327 * Note: It might be necessary to block validations before the
328 * wait by reserving the buffer.
329 * Returns -EBUSY if no_wait is true and the buffer is busy.
Thomas Hellstrom98ffc4152009-12-07 18:36:18 +0100330 * Returns -ERESTARTSYS if interrupted by a signal.
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200331 */
332extern int ttm_bo_wait(struct ttm_buffer_object *bo, bool lazy,
333 bool interruptible, bool no_wait);
334/**
Jerome Glisse09855ac2009-12-10 17:16:27 +0100335 * ttm_bo_validate
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200336 *
337 * @bo: The buffer object.
Jerome Glisseca262a9992009-12-08 15:33:32 +0100338 * @placement: Proposed placement for the buffer object.
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200339 * @interruptible: Sleep interruptible if sleeping.
Jerome Glisse9d87fa22010-04-07 10:21:19 +0000340 * @no_wait_reserve: Return immediately if other buffers are busy.
341 * @no_wait_gpu: Return immediately if the GPU is busy.
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200342 *
343 * Changes placement and caching policy of the buffer object
Jerome Glisseca262a9992009-12-08 15:33:32 +0100344 * according proposed placement.
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200345 * Returns
Jerome Glisseca262a9992009-12-08 15:33:32 +0100346 * -EINVAL on invalid proposed placement.
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200347 * -ENOMEM on out-of-memory condition.
348 * -EBUSY if no_wait is true and buffer busy.
Thomas Hellstrom98ffc4152009-12-07 18:36:18 +0100349 * -ERESTARTSYS if interrupted by a signal.
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200350 */
Jerome Glisse09855ac2009-12-10 17:16:27 +0100351extern int ttm_bo_validate(struct ttm_buffer_object *bo,
352 struct ttm_placement *placement,
Jerome Glisse9d87fa22010-04-07 10:21:19 +0000353 bool interruptible, bool no_wait_reserve,
354 bool no_wait_gpu);
Jerome Glisseca262a9992009-12-08 15:33:32 +0100355
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200356/**
357 * ttm_bo_unref
358 *
359 * @bo: The buffer object.
360 *
361 * Unreference and clear a pointer to a buffer object.
362 */
363extern void ttm_bo_unref(struct ttm_buffer_object **bo);
364
365/**
Matthew Garrett7c5ee532010-04-26 16:00:09 -0400366 * ttm_bo_lock_delayed_workqueue
367 *
368 * Prevent the delayed workqueue from running.
369 * Returns
370 * True if the workqueue was queued at the time
371 */
372extern int ttm_bo_lock_delayed_workqueue(struct ttm_bo_device *bdev);
373
374/**
375 * ttm_bo_unlock_delayed_workqueue
376 *
377 * Allows the delayed workqueue to run.
378 */
379extern void ttm_bo_unlock_delayed_workqueue(struct ttm_bo_device *bdev,
380 int resched);
381
382/**
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200383 * ttm_bo_synccpu_write_grab
384 *
385 * @bo: The buffer object:
386 * @no_wait: Return immediately if buffer is busy.
387 *
388 * Synchronizes a buffer object for CPU RW access. This means
389 * blocking command submission that affects the buffer and
390 * waiting for buffer idle. This lock is recursive.
391 * Returns
392 * -EBUSY if the buffer is busy and no_wait is true.
Thomas Hellstrom98ffc4152009-12-07 18:36:18 +0100393 * -ERESTARTSYS if interrupted by a signal.
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200394 */
395
396extern int
397ttm_bo_synccpu_write_grab(struct ttm_buffer_object *bo, bool no_wait);
398/**
399 * ttm_bo_synccpu_write_release:
400 *
401 * @bo : The buffer object.
402 *
403 * Releases a synccpu lock.
404 */
405extern void ttm_bo_synccpu_write_release(struct ttm_buffer_object *bo);
406
407/**
Jerome Glisse09855ac2009-12-10 17:16:27 +0100408 * ttm_bo_init
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200409 *
410 * @bdev: Pointer to a ttm_bo_device struct.
411 * @bo: Pointer to a ttm_buffer_object to be initialized.
412 * @size: Requested size of buffer object.
413 * @type: Requested type of buffer object.
414 * @flags: Initial placement flags.
415 * @page_alignment: Data alignment in pages.
416 * @buffer_start: Virtual address of user space data backing a
417 * user buffer object.
418 * @interruptible: If needing to sleep to wait for GPU resources,
419 * sleep interruptible.
420 * @persistant_swap_storage: Usually the swap storage is deleted for buffers
421 * pinned in physical memory. If this behaviour is not desired, this member
422 * holds a pointer to a persistant shmem object. Typically, this would
423 * point to the shmem object backing a GEM object if TTM is used to back a
424 * GEM user interface.
425 * @acc_size: Accounted size for this object.
426 * @destroy: Destroy function. Use NULL for kfree().
427 *
428 * This function initializes a pre-allocated struct ttm_buffer_object.
429 * As this object may be part of a larger structure, this function,
430 * together with the @destroy function,
431 * enables driver-specific objects derived from a ttm_buffer_object.
432 * On successful return, the object kref and list_kref are set to 1.
433 * Returns
434 * -ENOMEM: Out of memory.
435 * -EINVAL: Invalid placement flags.
Thomas Hellstrom98ffc4152009-12-07 18:36:18 +0100436 * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200437 */
438
Jerome Glisse09855ac2009-12-10 17:16:27 +0100439extern int ttm_bo_init(struct ttm_bo_device *bdev,
440 struct ttm_buffer_object *bo,
441 unsigned long size,
442 enum ttm_bo_type type,
443 struct ttm_placement *placement,
444 uint32_t page_alignment,
445 unsigned long buffer_start,
446 bool interrubtible,
447 struct file *persistant_swap_storage,
448 size_t acc_size,
449 void (*destroy) (struct ttm_buffer_object *));
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200450/**
451 * ttm_bo_synccpu_object_init
452 *
453 * @bdev: Pointer to a ttm_bo_device struct.
454 * @bo: Pointer to a ttm_buffer_object to be initialized.
455 * @size: Requested size of buffer object.
456 * @type: Requested type of buffer object.
457 * @flags: Initial placement flags.
458 * @page_alignment: Data alignment in pages.
459 * @buffer_start: Virtual address of user space data backing a
460 * user buffer object.
461 * @interruptible: If needing to sleep while waiting for GPU resources,
462 * sleep interruptible.
463 * @persistant_swap_storage: Usually the swap storage is deleted for buffers
464 * pinned in physical memory. If this behaviour is not desired, this member
465 * holds a pointer to a persistant shmem object. Typically, this would
466 * point to the shmem object backing a GEM object if TTM is used to back a
467 * GEM user interface.
468 * @p_bo: On successful completion *p_bo points to the created object.
469 *
Jerome Glisse09855ac2009-12-10 17:16:27 +0100470 * This function allocates a ttm_buffer_object, and then calls ttm_bo_init
471 * on that object. The destroy function is set to kfree().
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200472 * Returns
473 * -ENOMEM: Out of memory.
474 * -EINVAL: Invalid placement flags.
Thomas Hellstrom98ffc4152009-12-07 18:36:18 +0100475 * -ERESTARTSYS: Interrupted by signal while waiting for resources.
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200476 */
477
Jerome Glisse09855ac2009-12-10 17:16:27 +0100478extern int ttm_bo_create(struct ttm_bo_device *bdev,
479 unsigned long size,
480 enum ttm_bo_type type,
481 struct ttm_placement *placement,
482 uint32_t page_alignment,
483 unsigned long buffer_start,
484 bool interruptible,
485 struct file *persistant_swap_storage,
486 struct ttm_buffer_object **p_bo);
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200487
488/**
489 * ttm_bo_check_placement
490 *
Jerome Glisse09855ac2009-12-10 17:16:27 +0100491 * @bo: the buffer object.
492 * @placement: placements
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200493 *
494 * Performs minimal validity checking on an intended change of
495 * placement flags.
496 * Returns
497 * -EINVAL: Intended change is invalid or not allowed.
498 */
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200499extern int ttm_bo_check_placement(struct ttm_buffer_object *bo,
Jerome Glisse09855ac2009-12-10 17:16:27 +0100500 struct ttm_placement *placement);
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200501
502/**
503 * ttm_bo_init_mm
504 *
505 * @bdev: Pointer to a ttm_bo_device struct.
506 * @mem_type: The memory type.
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200507 * @p_size: size managed area in pages.
508 *
509 * Initialize a manager for a given memory type.
510 * Note: if part of driver firstopen, it must be protected from a
511 * potentially racing lastclose.
512 * Returns:
513 * -EINVAL: invalid size or memory type.
514 * -ENOMEM: Not enough memory.
515 * May also return driver-specified errors.
516 */
517
518extern int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
Jerome Glisseca262a9992009-12-08 15:33:32 +0100519 unsigned long p_size);
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200520/**
521 * ttm_bo_clean_mm
522 *
523 * @bdev: Pointer to a ttm_bo_device struct.
524 * @mem_type: The memory type.
525 *
526 * Take down a manager for a given memory type after first walking
527 * the LRU list to evict any buffers left alive.
528 *
529 * Normally, this function is part of lastclose() or unload(), and at that
530 * point there shouldn't be any buffers left created by user-space, since
531 * there should've been removed by the file descriptor release() method.
532 * However, before this function is run, make sure to signal all sync objects,
533 * and verify that the delayed delete queue is empty. The driver must also
534 * make sure that there are no NO_EVICT buffers present in this memory type
535 * when the call is made.
536 *
537 * If this function is part of a VT switch, the caller must make sure that
538 * there are no appications currently validating buffers before this
539 * function is called. The caller can do that by first taking the
540 * struct ttm_bo_device::ttm_lock in write mode.
541 *
542 * Returns:
543 * -EINVAL: invalid or uninitialized memory type.
544 * -EBUSY: There are still buffers left in this memory type.
545 */
546
547extern int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type);
548
549/**
550 * ttm_bo_evict_mm
551 *
552 * @bdev: Pointer to a ttm_bo_device struct.
553 * @mem_type: The memory type.
554 *
555 * Evicts all buffers on the lru list of the memory type.
556 * This is normally part of a VT switch or an
557 * out-of-memory-space-due-to-fragmentation handler.
558 * The caller must make sure that there are no other processes
559 * currently validating buffers, and can do that by taking the
560 * struct ttm_bo_device::ttm_lock in write mode.
561 *
562 * Returns:
563 * -EINVAL: Invalid or uninitialized memory type.
Thomas Hellstrom98ffc4152009-12-07 18:36:18 +0100564 * -ERESTARTSYS: The call was interrupted by a signal while waiting to
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200565 * evict a buffer.
566 */
567
568extern int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type);
569
570/**
571 * ttm_kmap_obj_virtual
572 *
573 * @map: A struct ttm_bo_kmap_obj returned from ttm_bo_kmap.
574 * @is_iomem: Pointer to an integer that on return indicates 1 if the
575 * virtual map is io memory, 0 if normal memory.
576 *
577 * Returns the virtual address of a buffer object area mapped by ttm_bo_kmap.
578 * If *is_iomem is 1 on return, the virtual address points to an io memory area,
579 * that should strictly be accessed by the iowriteXX() and similar functions.
580 */
581
582static inline void *ttm_kmap_obj_virtual(struct ttm_bo_kmap_obj *map,
583 bool *is_iomem)
584{
Pekka Paalanena0724fc2009-08-17 01:18:38 +0300585 *is_iomem = !!(map->bo_kmap_type & TTM_BO_MAP_IOMEM_MASK);
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200586 return map->virtual;
587}
588
589/**
590 * ttm_bo_kmap
591 *
592 * @bo: The buffer object.
593 * @start_page: The first page to map.
594 * @num_pages: Number of pages to map.
595 * @map: pointer to a struct ttm_bo_kmap_obj representing the map.
596 *
597 * Sets up a kernel virtual mapping, using ioremap, vmap or kmap to the
598 * data in the buffer object. The ttm_kmap_obj_virtual function can then be
599 * used to obtain a virtual address to the data.
600 *
601 * Returns
602 * -ENOMEM: Out of memory.
603 * -EINVAL: Invalid range.
604 */
605
606extern int ttm_bo_kmap(struct ttm_buffer_object *bo, unsigned long start_page,
607 unsigned long num_pages, struct ttm_bo_kmap_obj *map);
608
609/**
610 * ttm_bo_kunmap
611 *
612 * @map: Object describing the map to unmap.
613 *
614 * Unmaps a kernel map set up by ttm_bo_kmap.
615 */
616
617extern void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map);
618
619#if 0
620#endif
621
622/**
623 * ttm_fbdev_mmap - mmap fbdev memory backed by a ttm buffer object.
624 *
625 * @vma: vma as input from the fbdev mmap method.
626 * @bo: The bo backing the address space. The address space will
627 * have the same size as the bo, and start at offset 0.
628 *
629 * This function is intended to be called by the fbdev mmap method
630 * if the fbdev address space is to be backed by a bo.
631 */
632
633extern int ttm_fbdev_mmap(struct vm_area_struct *vma,
634 struct ttm_buffer_object *bo);
635
636/**
637 * ttm_bo_mmap - mmap out of the ttm device address space.
638 *
639 * @filp: filp as input from the mmap method.
640 * @vma: vma as input from the mmap method.
641 * @bdev: Pointer to the ttm_bo_device with the address space manager.
642 *
643 * This function is intended to be called by the device mmap method.
644 * if the device address space is to be backed by the bo manager.
645 */
646
647extern int ttm_bo_mmap(struct file *filp, struct vm_area_struct *vma,
648 struct ttm_bo_device *bdev);
649
650/**
651 * ttm_bo_io
652 *
653 * @bdev: Pointer to the struct ttm_bo_device.
654 * @filp: Pointer to the struct file attempting to read / write.
655 * @wbuf: User-space pointer to address of buffer to write. NULL on read.
656 * @rbuf: User-space pointer to address of buffer to read into.
657 * Null on write.
658 * @count: Number of bytes to read / write.
659 * @f_pos: Pointer to current file position.
660 * @write: 1 for read, 0 for write.
661 *
662 * This function implements read / write into ttm buffer objects, and is
663 * intended to
664 * be called from the fops::read and fops::write method.
665 * Returns:
666 * See man (2) write, man(2) read. In particular,
Thomas Hellstrom98ffc4152009-12-07 18:36:18 +0100667 * the function may return -ERESTARTSYS if
Thomas Hellstromba4e7d92009-06-10 15:20:19 +0200668 * interrupted by a signal.
669 */
670
671extern ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
672 const char __user *wbuf, char __user *rbuf,
673 size_t count, loff_t *f_pos, bool write);
674
675extern void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
676
677#endif