OSDN Git Service

i915: Evict if relocatee buffer is CACHED_MAPPED before
[android-x86/external-libdrm.git] / linux-core / drm_objects.h
1 /**************************************************************************
2  *
3  * Copyright (c) 2006-2007 Tungsten Graphics, Inc., Cedar Park, TX., 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 Hellström <thomas-at-tungstengraphics-dot-com>
29  */
30
31 #ifndef _DRM_OBJECTS_H
32 #define _DRM_OBJECTS_H
33
34 struct drm_device;
35 struct drm_bo_mem_reg;
36
37 /***************************************************
38  * User space objects. (drm_object.c)
39  */
40
41 #define drm_user_object_entry(_ptr, _type, _member) container_of(_ptr, _type, _member)
42
43 enum drm_object_type {
44         drm_fence_type,
45         drm_buffer_type,
46         drm_lock_type,
47             /*
48              * Add other user space object types here.
49              */
50         drm_driver_type0 = 256,
51         drm_driver_type1,
52         drm_driver_type2,
53         drm_driver_type3,
54         drm_driver_type4
55 };
56
57 /*
58  * A user object is a structure that helps the drm give out user handles
59  * to kernel internal objects and to keep track of these objects so that
60  * they can be destroyed, for example when the user space process exits.
61  * Designed to be accessible using a user space 32-bit handle.
62  */
63
64 struct drm_user_object {
65         struct drm_hash_item hash;
66         struct list_head list;
67         enum drm_object_type type;
68         atomic_t refcount;
69         int shareable;
70         struct drm_file *owner;
71         void (*ref_struct_locked) (struct drm_file *priv,
72                                    struct drm_user_object *obj,
73                                    enum drm_ref_type ref_action);
74         void (*unref) (struct drm_file *priv, struct drm_user_object *obj,
75                        enum drm_ref_type unref_action);
76         void (*remove) (struct drm_file *priv, struct drm_user_object *obj);
77 };
78
79 /*
80  * A ref object is a structure which is used to
81  * keep track of references to user objects and to keep track of these
82  * references so that they can be destroyed for example when the user space
83  * process exits. Designed to be accessible using a pointer to the _user_ object.
84  */
85
86 struct drm_ref_object {
87         struct drm_hash_item hash;
88         struct list_head list;
89         atomic_t refcount;
90         enum drm_ref_type unref_action;
91 };
92
93 /**
94  * Must be called with the struct_mutex held.
95  */
96
97 extern int drm_add_user_object(struct drm_file *priv, struct drm_user_object *item,
98                                int shareable);
99 /**
100  * Must be called with the struct_mutex held.
101  */
102
103 extern struct drm_user_object *drm_lookup_user_object(struct drm_file *priv,
104                                                  uint32_t key);
105
106 /*
107  * Must be called with the struct_mutex held. May temporarily release it.
108  */
109
110 extern int drm_add_ref_object(struct drm_file *priv,
111                               struct drm_user_object *referenced_object,
112                               enum drm_ref_type ref_action);
113
114 /*
115  * Must be called with the struct_mutex held.
116  */
117
118 struct drm_ref_object *drm_lookup_ref_object(struct drm_file *priv,
119                                         struct drm_user_object *referenced_object,
120                                         enum drm_ref_type ref_action);
121 /*
122  * Must be called with the struct_mutex held.
123  * If "item" has been obtained by a call to drm_lookup_ref_object. You may not
124  * release the struct_mutex before calling drm_remove_ref_object.
125  * This function may temporarily release the struct_mutex.
126  */
127
128 extern void drm_remove_ref_object(struct drm_file *priv, struct drm_ref_object *item);
129 extern int drm_user_object_ref(struct drm_file *priv, uint32_t user_token,
130                                enum drm_object_type type,
131                                struct drm_user_object **object);
132 extern int drm_user_object_unref(struct drm_file *priv, uint32_t user_token,
133                                  enum drm_object_type type);
134
135 /***************************************************
136  * Fence objects. (drm_fence.c)
137  */
138
139 struct drm_fence_object {
140         struct drm_user_object base;
141         struct drm_device *dev;
142         atomic_t usage;
143
144         /*
145          * The below three fields are protected by the fence manager spinlock.
146          */
147
148         struct list_head ring;
149         int fence_class;
150         uint32_t native_types;
151         uint32_t type;
152         uint32_t signaled_types;
153         uint32_t sequence;
154         uint32_t waiting_types;
155         uint32_t error;
156 };
157
158 #define _DRM_FENCE_CLASSES 8
159 #define _DRM_FENCE_TYPE_EXE 0x00
160
161 struct drm_fence_class_manager {
162         struct list_head ring;
163         uint32_t pending_flush;
164         uint32_t waiting_types;
165         wait_queue_head_t fence_queue;
166         uint32_t highest_waiting_sequence;
167         uint32_t latest_queued_sequence;
168 };
169
170 struct drm_fence_manager {
171         int initialized;
172         rwlock_t lock;
173         struct drm_fence_class_manager fence_class[_DRM_FENCE_CLASSES];
174         uint32_t num_classes;
175         atomic_t count;
176 };
177
178 struct drm_fence_driver {
179         unsigned long *waiting_jiffies;
180         uint32_t num_classes;
181         uint32_t wrap_diff;
182         uint32_t flush_diff;
183         uint32_t sequence_mask;
184
185         /*
186          * Driver implemented functions:
187          * has_irq() : 1 if the hardware can update the indicated type_flags using an
188          * irq handler. 0 if polling is required.
189          *
190          * emit() : Emit a sequence number to the command stream.
191          * Return the sequence number.
192          *
193          * flush() : Make sure the flags indicated in fc->pending_flush will eventually
194          * signal for fc->highest_received_sequence and all preceding sequences.
195          * Acknowledge by clearing the flags fc->pending_flush.
196          *
197          * poll() : Call drm_fence_handler with any new information.
198          *
199          * needed_flush() : Given the current state of the fence->type flags and previusly 
200          * executed or queued flushes, return the type_flags that need flushing.
201          *
202          * wait(): Wait for the "mask" flags to signal on a given fence, performing
203          * whatever's necessary to make this happen.
204          */
205
206         int (*has_irq) (struct drm_device *dev, uint32_t fence_class,
207                         uint32_t flags);
208         int (*emit) (struct drm_device *dev, uint32_t fence_class,
209                      uint32_t flags, uint32_t *breadcrumb,
210                      uint32_t *native_type);
211         void (*flush) (struct drm_device *dev, uint32_t fence_class);
212         void (*poll) (struct drm_device *dev, uint32_t fence_class,
213                 uint32_t types);
214         uint32_t (*needed_flush) (struct drm_fence_object *fence);
215         int (*wait) (struct drm_fence_object *fence, int lazy,
216                      int interruptible, uint32_t mask);
217 };
218
219 extern int drm_fence_wait_polling(struct drm_fence_object *fence, int lazy,
220                                   int interruptible, uint32_t mask,
221                                   unsigned long end_jiffies);
222 extern void drm_fence_handler(struct drm_device *dev, uint32_t fence_class,
223                               uint32_t sequence, uint32_t type,
224                               uint32_t error);
225 extern void drm_fence_manager_init(struct drm_device *dev);
226 extern void drm_fence_manager_takedown(struct drm_device *dev);
227 extern void drm_fence_flush_old(struct drm_device *dev, uint32_t fence_class,
228                                 uint32_t sequence);
229 extern int drm_fence_object_flush(struct drm_fence_object *fence,
230                                   uint32_t type);
231 extern int drm_fence_object_signaled(struct drm_fence_object *fence,
232                                      uint32_t type);
233 extern void drm_fence_usage_deref_locked(struct drm_fence_object **fence);
234 extern void drm_fence_usage_deref_unlocked(struct drm_fence_object **fence);
235 extern struct drm_fence_object *drm_fence_reference_locked(struct drm_fence_object *src);
236 extern void drm_fence_reference_unlocked(struct drm_fence_object **dst,
237                                          struct drm_fence_object *src);
238 extern int drm_fence_object_wait(struct drm_fence_object *fence,
239                                  int lazy, int ignore_signals, uint32_t mask);
240 extern int drm_fence_object_create(struct drm_device *dev, uint32_t type,
241                                    uint32_t fence_flags, uint32_t fence_class,
242                                    struct drm_fence_object **c_fence);
243 extern int drm_fence_object_emit(struct drm_fence_object *fence,
244                                  uint32_t fence_flags, uint32_t class,
245                                  uint32_t type);
246 extern void drm_fence_fill_arg(struct drm_fence_object *fence,
247                                struct drm_fence_arg *arg);
248
249 extern int drm_fence_add_user_object(struct drm_file *priv,
250                                      struct drm_fence_object *fence,
251                                      int shareable);
252
253 extern int drm_fence_create_ioctl(struct drm_device *dev, void *data,
254                                   struct drm_file *file_priv);
255 extern int drm_fence_destroy_ioctl(struct drm_device *dev, void *data,
256                                    struct drm_file *file_priv);
257 extern int drm_fence_reference_ioctl(struct drm_device *dev, void *data,
258                                      struct drm_file *file_priv);
259 extern int drm_fence_unreference_ioctl(struct drm_device *dev, void *data,
260                                        struct drm_file *file_priv);
261 extern int drm_fence_signaled_ioctl(struct drm_device *dev, void *data,
262                                     struct drm_file *file_priv);
263 extern int drm_fence_flush_ioctl(struct drm_device *dev, void *data,
264                                  struct drm_file *file_priv);
265 extern int drm_fence_wait_ioctl(struct drm_device *dev, void *data,
266                                 struct drm_file *file_priv);
267 extern int drm_fence_emit_ioctl(struct drm_device *dev, void *data,
268                                 struct drm_file *file_priv);
269 extern int drm_fence_buffers_ioctl(struct drm_device *dev, void *data,
270                                    struct drm_file *file_priv);
271 /**************************************************
272  *TTMs
273  */
274
275 /*
276  * The ttm backend GTT interface. (In our case AGP).
277  * Any similar type of device (PCIE?)
278  * needs only to implement these functions to be usable with the TTM interface.
279  * The AGP backend implementation lives in drm_agpsupport.c
280  * basically maps these calls to available functions in agpgart.
281  * Each drm device driver gets an
282  * additional function pointer that creates these types,
283  * so that the device can choose the correct aperture.
284  * (Multiple AGP apertures, etc.)
285  * Most device drivers will let this point to the standard AGP implementation.
286  */
287
288 #define DRM_BE_FLAG_NEEDS_FREE     0x00000001
289 #define DRM_BE_FLAG_BOUND_CACHED   0x00000002
290
291 struct drm_ttm_backend;
292 struct drm_ttm_backend_func {
293         int (*needs_ub_cache_adjust) (struct drm_ttm_backend *backend);
294         int (*populate) (struct drm_ttm_backend *backend,
295                          unsigned long num_pages, struct page **pages,
296                          struct page *dummy_read_page);
297         void (*clear) (struct drm_ttm_backend *backend);
298         int (*bind) (struct drm_ttm_backend *backend,
299                      struct drm_bo_mem_reg *bo_mem);
300         int (*unbind) (struct drm_ttm_backend *backend);
301         void (*destroy) (struct drm_ttm_backend *backend);
302 };
303
304
305 struct drm_ttm_backend {
306         struct drm_device *dev;
307         uint32_t flags;
308         struct drm_ttm_backend_func *func;
309 };
310
311 struct drm_ttm {
312         struct page *dummy_read_page;
313         struct page **pages;
314         uint32_t page_flags;
315         unsigned long num_pages;
316         atomic_t vma_count;
317         struct drm_device *dev;
318         int destroy;
319         uint32_t mapping_offset;
320         struct drm_ttm_backend *be;
321         enum {
322                 ttm_bound,
323                 ttm_evicted,
324                 ttm_unbound,
325                 ttm_unpopulated,
326         } state;
327
328 };
329
330 extern struct drm_ttm *drm_ttm_create(struct drm_device *dev, unsigned long size,
331                                       uint32_t page_flags,
332                                       struct page *dummy_read_page);
333 extern int drm_ttm_bind(struct drm_ttm *ttm, struct drm_bo_mem_reg *bo_mem);
334 extern void drm_ttm_unbind(struct drm_ttm *ttm);
335 extern void drm_ttm_evict(struct drm_ttm *ttm);
336 extern void drm_ttm_fixup_caching(struct drm_ttm *ttm);
337 extern struct page *drm_ttm_get_page(struct drm_ttm *ttm, int index);
338 extern void drm_ttm_cache_flush(void);
339 extern int drm_ttm_populate(struct drm_ttm *ttm);
340 extern int drm_ttm_set_user(struct drm_ttm *ttm,
341                             struct task_struct *tsk,
342                             unsigned long start,
343                             unsigned long num_pages);
344
345 /*
346  * Destroy a ttm. The user normally calls drmRmMap or a similar IOCTL to do
347  * this which calls this function iff there are no vmas referencing it anymore.
348  * Otherwise it is called when the last vma exits.
349  */
350
351 extern int drm_ttm_destroy(struct drm_ttm *ttm);
352
353 #define DRM_FLAG_MASKED(_old, _new, _mask) {\
354 (_old) ^= (((_old) ^ (_new)) & (_mask)); \
355 }
356
357 #define DRM_TTM_MASK_FLAGS ((1 << PAGE_SHIFT) - 1)
358 #define DRM_TTM_MASK_PFN (0xFFFFFFFFU - DRM_TTM_MASK_FLAGS)
359
360 /*
361  * Page flags.
362  */
363
364 /*
365  * This ttm should not be cached by the CPU
366  */
367 #define DRM_TTM_PAGE_UNCACHED   (1 << 0)
368 /*
369  * This flat is not used at this time; I don't know what the
370  * intent was
371  */
372 #define DRM_TTM_PAGE_USED       (1 << 1)
373 /*
374  * This flat is not used at this time; I don't know what the
375  * intent was
376  */
377 #define DRM_TTM_PAGE_BOUND      (1 << 2)
378 /*
379  * This flat is not used at this time; I don't know what the
380  * intent was
381  */
382 #define DRM_TTM_PAGE_PRESENT    (1 << 3)
383 /*
384  * The array of page pointers was allocated with vmalloc
385  * instead of drm_calloc.
386  */
387 #define DRM_TTM_PAGEDIR_VMALLOC (1 << 4)
388 /*
389  * This ttm is mapped from user space
390  */
391 #define DRM_TTM_PAGE_USER       (1 << 5)
392 /*
393  * This ttm will be written to by the GPU
394  */
395 #define DRM_TTM_PAGE_WRITE      (1 << 6)
396 /*
397  * This ttm was mapped to the GPU, and so the contents may have
398  * been modified
399  */
400 #define DRM_TTM_PAGE_USER_DIRTY (1 << 7)
401 /*
402  * This flag is not used at this time; I don't know what the
403  * intent was.
404  */
405 #define DRM_TTM_PAGE_USER_DMA   (1 << 8)
406
407 /***************************************************
408  * Buffer objects. (drm_bo.c, drm_bo_move.c)
409  */
410
411 struct drm_bo_mem_reg {
412         struct drm_mm_node *mm_node;
413         unsigned long size;
414         unsigned long num_pages;
415         uint32_t page_alignment;
416         uint32_t mem_type;
417         /*
418          * Current buffer status flags, indicating
419          * where the buffer is located and which
420          * access modes are in effect
421          */
422         uint64_t flags;
423         /**
424          * These are the flags proposed for
425          * a validate operation. If the
426          * validate succeeds, they'll get moved
427          * into the flags field
428          */
429         uint64_t proposed_flags;
430         
431         uint32_t desired_tile_stride;
432         uint32_t hw_tile_stride;
433 };
434
435 enum drm_bo_type {
436         /*
437          * drm_bo_type_device are 'normal' drm allocations,
438          * pages are allocated from within the kernel automatically
439          * and the objects can be mmap'd from the drm device. Each
440          * drm_bo_type_device object has a unique name which can be
441          * used by other processes to share access to the underlying
442          * buffer.
443          */
444         drm_bo_type_device,
445         /*
446          * drm_bo_type_user are buffers of pages that already exist
447          * in the process address space. They are more limited than
448          * drm_bo_type_device buffers in that they must always
449          * remain cached (as we assume the user pages are mapped cached),
450          * and they are not sharable to other processes through DRM
451          * (although, regular shared memory should still work fine).
452          */
453         drm_bo_type_user,
454         /*
455          * drm_bo_type_kernel are buffers that exist solely for use
456          * within the kernel. The pages cannot be mapped into the
457          * process. One obvious use would be for the ring
458          * buffer where user access would not (ideally) be required.
459          */
460         drm_bo_type_kernel,
461 };
462
463 struct drm_buffer_object {
464         struct drm_device *dev;
465         struct drm_user_object base;
466
467         /*
468          * If there is a possibility that the usage variable is zero,
469          * then dev->struct_mutext should be locked before incrementing it.
470          */
471
472         atomic_t usage;
473         unsigned long buffer_start;
474         enum drm_bo_type type;
475         unsigned long offset;
476         atomic_t mapped;
477         struct drm_bo_mem_reg mem;
478
479         struct list_head lru;
480         struct list_head ddestroy;
481
482         uint32_t fence_type;
483         uint32_t fence_class;
484         uint32_t new_fence_type;
485         uint32_t new_fence_class;
486         struct drm_fence_object *fence;
487         uint32_t priv_flags;
488         wait_queue_head_t event_queue;
489         struct mutex mutex;
490         unsigned long num_pages;
491
492         /* For pinned buffers */
493         struct drm_mm_node *pinned_node;
494         uint32_t pinned_mem_type;
495         struct list_head pinned_lru;
496
497         /* For vm */
498         struct drm_ttm *ttm;
499         struct drm_map_list map_list;
500         uint32_t memory_type;
501         unsigned long bus_offset;
502         uint32_t vm_flags;
503         void *iomap;
504
505 #ifdef DRM_ODD_MM_COMPAT
506         /* dev->struct_mutex only protected. */
507         struct list_head vma_list;
508         struct list_head p_mm_list;
509 #endif
510
511 };
512
513 #define _DRM_BO_FLAG_UNFENCED 0x00000001
514 #define _DRM_BO_FLAG_EVICTED  0x00000002
515
516 struct drm_mem_type_manager {
517         int has_type;
518         int use_type;
519         struct drm_mm manager;
520         struct list_head lru;
521         struct list_head pinned;
522         uint32_t flags;
523         uint32_t drm_bus_maptype;
524         unsigned long gpu_offset;
525         unsigned long io_offset;
526         unsigned long io_size;
527         void *io_addr;
528 };
529
530 struct drm_bo_lock {
531         struct drm_user_object base;
532         wait_queue_head_t queue;
533         atomic_t write_lock_pending;
534         atomic_t readers;
535 };
536
537 #define _DRM_FLAG_MEMTYPE_FIXED     0x00000001  /* Fixed (on-card) PCI memory */
538 #define _DRM_FLAG_MEMTYPE_MAPPABLE  0x00000002  /* Memory mappable */
539 #define _DRM_FLAG_MEMTYPE_CACHED    0x00000004  /* Cached binding */
540 #define _DRM_FLAG_NEEDS_IOREMAP     0x00000008  /* Fixed memory needs ioremap
541                                                    before kernel access. */
542 #define _DRM_FLAG_MEMTYPE_CMA       0x00000010  /* Can't map aperture */
543 #define _DRM_FLAG_MEMTYPE_CSELECT   0x00000020  /* Select caching */
544
545 struct drm_buffer_manager {
546         struct drm_bo_lock bm_lock;
547         struct mutex evict_mutex;
548         int nice_mode;
549         int initialized;
550         struct drm_file *last_to_validate;
551         struct drm_mem_type_manager man[DRM_BO_MEM_TYPES];
552         struct list_head unfenced;
553         struct list_head ddestroy;
554 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
555         struct work_struct wq;
556 #else
557         struct delayed_work wq;
558 #endif
559         uint32_t fence_type;
560         unsigned long cur_pages;
561         atomic_t count;
562         struct page *dummy_read_page;
563 };
564
565 struct drm_bo_driver {
566         const uint32_t *mem_type_prio;
567         const uint32_t *mem_busy_prio;
568         uint32_t num_mem_type_prio;
569         uint32_t num_mem_busy_prio;
570         struct drm_ttm_backend *(*create_ttm_backend_entry)
571          (struct drm_device *dev);
572         int (*fence_type) (struct drm_buffer_object *bo, uint32_t *fclass,
573                            uint32_t *type);
574         int (*invalidate_caches) (struct drm_device *dev, uint64_t flags);
575         int (*init_mem_type) (struct drm_device *dev, uint32_t type,
576                               struct drm_mem_type_manager *man);
577         /*
578          * evict_flags:
579          *
580          * @bo: the buffer object to be evicted
581          *
582          * Return the bo flags for a buffer which is not mapped to the hardware.
583          * These will be placed in proposed_flags so that when the move is
584          * finished, they'll end up in bo->mem.flags
585          */
586         uint64_t(*evict_flags) (struct drm_buffer_object *bo);
587         /*
588          * move:
589          *
590          * @bo: the buffer to move
591          *
592          * @evict: whether this motion is evicting the buffer from
593          * the graphics address space
594          *
595          * @no_wait: whether this should give up and return -EBUSY
596          * if this move would require sleeping
597          *
598          * @new_mem: the new memory region receiving the buffer
599          *
600          * Move a buffer between two memory regions.
601          */
602         int (*move) (struct drm_buffer_object *bo,
603                      int evict, int no_wait, struct drm_bo_mem_reg *new_mem);
604         /*
605          * ttm_cache_flush
606          */
607         void (*ttm_cache_flush)(struct drm_ttm *ttm);
608
609         /*
610          * command_stream_barrier
611          *
612          * @dev: The drm device.
613          *
614          * @bo: The buffer object to validate.
615          *
616          * @new_fence_class: The new fence class for the buffer object.
617          *
618          * @new_fence_type: The new fence type for the buffer object.
619          *
620          * @no_wait: whether this should give up and return -EBUSY
621          * if this operation would require sleeping
622          *
623          * Insert a command stream barrier that makes sure that the
624          * buffer is idle once the commands associated with the
625          * current validation are starting to execute. If an error
626          * condition is returned, or the function pointer is NULL,
627          * the drm core will force buffer idle
628          * during validation.
629          */
630
631         int (*command_stream_barrier) (struct drm_buffer_object *bo,
632                                        uint32_t new_fence_class,
633                                        uint32_t new_fence_type,
634                                        int no_wait);                                   
635 };
636
637 /*
638  * buffer objects (drm_bo.c)
639  */
640
641 extern int drm_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
642 extern int drm_bo_destroy_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
643 extern int drm_bo_map_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
644 extern int drm_bo_unmap_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
645 extern int drm_bo_reference_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
646 extern int drm_bo_unreference_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
647 extern int drm_bo_wait_idle_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
648 extern int drm_bo_info_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
649 extern int drm_bo_setstatus_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
650 extern int drm_mm_init_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
651 extern int drm_mm_takedown_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
652 extern int drm_mm_lock_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
653 extern int drm_mm_unlock_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
654 extern int drm_bo_version_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
655 extern int drm_bo_driver_finish(struct drm_device *dev);
656 extern int drm_bo_driver_init(struct drm_device *dev);
657 extern int drm_bo_pci_offset(struct drm_device *dev,
658                              struct drm_bo_mem_reg *mem,
659                              unsigned long *bus_base,
660                              unsigned long *bus_offset,
661                              unsigned long *bus_size);
662 extern int drm_mem_reg_is_pci(struct drm_device *dev, struct drm_bo_mem_reg *mem);
663
664 extern void drm_bo_usage_deref_locked(struct drm_buffer_object **bo);
665 extern void drm_bo_usage_deref_unlocked(struct drm_buffer_object **bo);
666 extern void drm_putback_buffer_objects(struct drm_device *dev);
667 extern int drm_fence_buffer_objects(struct drm_device *dev,
668                                     struct list_head *list,
669                                     uint32_t fence_flags,
670                                     struct drm_fence_object *fence,
671                                     struct drm_fence_object **used_fence);
672 extern void drm_bo_add_to_lru(struct drm_buffer_object *bo);
673 extern int drm_buffer_object_create(struct drm_device *dev, unsigned long size,
674                                     enum drm_bo_type type, uint64_t flags,
675                                     uint32_t hint, uint32_t page_alignment,
676                                     unsigned long buffer_start,
677                                     struct drm_buffer_object **bo);
678 extern int drm_bo_wait(struct drm_buffer_object *bo, int lazy, int ignore_signals,
679                        int no_wait);
680 extern int drm_bo_mem_space(struct drm_buffer_object *bo,
681                             struct drm_bo_mem_reg *mem, int no_wait);
682 extern int drm_bo_move_buffer(struct drm_buffer_object *bo,
683                               uint64_t new_mem_flags,
684                               int no_wait, int move_unfenced);
685 extern int drm_bo_clean_mm(struct drm_device *dev, unsigned mem_type);
686 extern int drm_bo_init_mm(struct drm_device *dev, unsigned type,
687                           unsigned long p_offset, unsigned long p_size);
688 extern int drm_bo_handle_validate(struct drm_file *file_priv, uint32_t handle,
689                                   uint64_t flags, uint64_t mask, uint32_t hint,
690                                   uint32_t fence_class, int use_old_fence_class,
691                                   struct drm_bo_info_rep *rep,
692                                   struct drm_buffer_object **bo_rep);
693 extern struct drm_buffer_object *drm_lookup_buffer_object(struct drm_file *file_priv,
694                                                           uint32_t handle,
695                                                           int check_owner);
696 extern int drm_bo_do_validate(struct drm_buffer_object *bo,
697                               uint64_t flags, uint64_t mask, uint32_t hint,
698                               uint32_t fence_class,
699                               struct drm_bo_info_rep *rep);
700 extern int drm_bo_evict_cached(struct drm_buffer_object *bo);
701 /*
702  * Buffer object memory move- and map helpers.
703  * drm_bo_move.c
704  */
705
706 extern int drm_bo_move_ttm(struct drm_buffer_object *bo,
707                            int evict, int no_wait,
708                            struct drm_bo_mem_reg *new_mem);
709 extern int drm_bo_move_memcpy(struct drm_buffer_object *bo,
710                               int evict,
711                               int no_wait, struct drm_bo_mem_reg *new_mem);
712 extern int drm_bo_move_accel_cleanup(struct drm_buffer_object *bo,
713                                      int evict, int no_wait,
714                                      uint32_t fence_class, uint32_t fence_type,
715                                      uint32_t fence_flags,
716                                      struct drm_bo_mem_reg *new_mem);
717 extern int drm_bo_same_page(unsigned long offset, unsigned long offset2);
718 extern unsigned long drm_bo_offset_end(unsigned long offset,
719                                        unsigned long end);
720
721 struct drm_bo_kmap_obj {
722         void *virtual;
723         struct page *page;
724         enum {
725                 bo_map_iomap,
726                 bo_map_vmap,
727                 bo_map_kmap,
728                 bo_map_premapped,
729         } bo_kmap_type;
730 };
731
732 static inline void *drm_bmo_virtual(struct drm_bo_kmap_obj *map, int *is_iomem)
733 {
734         *is_iomem = (map->bo_kmap_type == bo_map_iomap ||
735                      map->bo_kmap_type == bo_map_premapped);
736         return map->virtual;
737 }
738 extern void drm_bo_kunmap(struct drm_bo_kmap_obj *map);
739 extern int drm_bo_kmap(struct drm_buffer_object *bo, unsigned long start_page,
740                        unsigned long num_pages, struct drm_bo_kmap_obj *map);
741 extern int drm_bo_pfn_prot(struct drm_buffer_object *bo,
742                            unsigned long dst_offset,
743                            unsigned long *pfn,
744                            pgprot_t *prot);
745
746
747 /*
748  * drm_regman.c
749  */
750
751 struct drm_reg {
752         struct list_head head;
753         struct drm_fence_object *fence;
754         uint32_t fence_type;
755         uint32_t new_fence_type;
756 };
757
758 struct drm_reg_manager {
759         struct list_head free;
760         struct list_head lru;
761         struct list_head unfenced;
762
763         int (*reg_reusable)(const struct drm_reg *reg, const void *data);
764         void (*reg_destroy)(struct drm_reg *reg);
765 };
766
767 extern int drm_regs_alloc(struct drm_reg_manager *manager,
768                           const void *data,
769                           uint32_t fence_class,
770                           uint32_t fence_type,
771                           int interruptible,
772                           int no_wait,
773                           struct drm_reg **reg);
774
775 extern void drm_regs_fence(struct drm_reg_manager *regs,
776                            struct drm_fence_object *fence);
777
778 extern void drm_regs_free(struct drm_reg_manager *manager);
779 extern void drm_regs_add(struct drm_reg_manager *manager, struct drm_reg *reg);
780 extern void drm_regs_init(struct drm_reg_manager *manager,
781                           int (*reg_reusable)(const struct drm_reg *,
782                                               const void *),
783                           void (*reg_destroy)(struct drm_reg *));
784
785 /*
786  * drm_bo_lock.c
787  * Simple replacement for the hardware lock on buffer manager init and clean.
788  */
789
790
791 extern void drm_bo_init_lock(struct drm_bo_lock *lock);
792 extern void drm_bo_read_unlock(struct drm_bo_lock *lock);
793 extern int drm_bo_read_lock(struct drm_bo_lock *lock);
794 extern int drm_bo_write_lock(struct drm_bo_lock *lock,
795                              struct drm_file *file_priv);
796
797 extern int drm_bo_write_unlock(struct drm_bo_lock *lock,
798                                struct drm_file *file_priv);
799
800 #ifdef CONFIG_DEBUG_MUTEXES
801 #define DRM_ASSERT_LOCKED(_mutex)                                       \
802         BUG_ON(!mutex_is_locked(_mutex) ||                              \
803                ((_mutex)->owner != current_thread_info()))
804 #else
805 #define DRM_ASSERT_LOCKED(_mutex)
806 #endif
807 #endif