Move dummy_read_page from drm_ttm_set_user to drm_ttm_create.
[profile/ivi/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_type;
151         uint32_t type;
152         uint32_t signaled;
153         uint32_t sequence;
154         uint32_t flush_mask;
155         uint32_t submitted_flush;
156         uint32_t error;
157 };
158
159 #define _DRM_FENCE_CLASSES 8
160 #define _DRM_FENCE_TYPE_EXE 0x00
161
162 struct drm_fence_class_manager {
163         struct list_head ring;
164         uint32_t pending_flush;
165         wait_queue_head_t fence_queue;
166         int pending_exe_flush;
167         uint32_t last_exe_flush;
168         uint32_t exe_flush_sequence;
169 };
170
171 struct drm_fence_manager {
172         int initialized;
173         rwlock_t lock;
174         struct drm_fence_class_manager fence_class[_DRM_FENCE_CLASSES];
175         uint32_t num_classes;
176         atomic_t count;
177 };
178
179 struct drm_fence_driver {
180         uint32_t num_classes;
181         uint32_t wrap_diff;
182         uint32_t flush_diff;
183         uint32_t sequence_mask;
184         int lazy_capable;
185         int (*has_irq) (struct drm_device *dev, uint32_t fence_class,
186                         uint32_t flags);
187         int (*emit) (struct drm_device *dev, uint32_t fence_class,
188                      uint32_t flags, uint32_t *breadcrumb,
189                      uint32_t *native_type);
190         void (*poke_flush) (struct drm_device *dev, uint32_t fence_class);
191 };
192
193 extern void drm_fence_handler(struct drm_device *dev, uint32_t fence_class,
194                               uint32_t sequence, uint32_t type,
195                               uint32_t error);
196 extern void drm_fence_manager_init(struct drm_device *dev);
197 extern void drm_fence_manager_takedown(struct drm_device *dev);
198 extern void drm_fence_flush_old(struct drm_device *dev, uint32_t fence_class,
199                                 uint32_t sequence);
200 extern int drm_fence_object_flush(struct drm_fence_object *fence,
201                                   uint32_t type);
202 extern int drm_fence_object_signaled(struct drm_fence_object *fence,
203                                      uint32_t type, int flush);
204 extern void drm_fence_usage_deref_locked(struct drm_fence_object **fence);
205 extern void drm_fence_usage_deref_unlocked(struct drm_fence_object **fence);
206 extern struct drm_fence_object *drm_fence_reference_locked(struct drm_fence_object *src);
207 extern void drm_fence_reference_unlocked(struct drm_fence_object **dst,
208                                          struct drm_fence_object *src);
209 extern int drm_fence_object_wait(struct drm_fence_object *fence,
210                                  int lazy, int ignore_signals, uint32_t mask);
211 extern int drm_fence_object_create(struct drm_device *dev, uint32_t type,
212                                    uint32_t fence_flags, uint32_t fence_class,
213                                    struct drm_fence_object **c_fence);
214 extern int drm_fence_object_emit(struct drm_fence_object *fence,
215                                  uint32_t fence_flags, uint32_t class,
216                                  uint32_t type);
217 extern void drm_fence_fill_arg(struct drm_fence_object *fence,
218                                struct drm_fence_arg *arg);
219
220 extern int drm_fence_add_user_object(struct drm_file *priv,
221                                      struct drm_fence_object *fence,
222                                      int shareable);
223
224 extern int drm_fence_create_ioctl(struct drm_device *dev, void *data,
225                                   struct drm_file *file_priv);
226 extern int drm_fence_destroy_ioctl(struct drm_device *dev, void *data,
227                                    struct drm_file *file_priv);
228 extern int drm_fence_reference_ioctl(struct drm_device *dev, void *data,
229                                      struct drm_file *file_priv);
230 extern int drm_fence_unreference_ioctl(struct drm_device *dev, void *data,
231                                        struct drm_file *file_priv);
232 extern int drm_fence_signaled_ioctl(struct drm_device *dev, void *data,
233                                     struct drm_file *file_priv);
234 extern int drm_fence_flush_ioctl(struct drm_device *dev, void *data,
235                                  struct drm_file *file_priv);
236 extern int drm_fence_wait_ioctl(struct drm_device *dev, void *data,
237                                 struct drm_file *file_priv);
238 extern int drm_fence_emit_ioctl(struct drm_device *dev, void *data,
239                                 struct drm_file *file_priv);
240 extern int drm_fence_buffers_ioctl(struct drm_device *dev, void *data,
241                                    struct drm_file *file_priv);
242 /**************************************************
243  *TTMs
244  */
245
246 /*
247  * The ttm backend GTT interface. (In our case AGP).
248  * Any similar type of device (PCIE?)
249  * needs only to implement these functions to be usable with the TTM interface.
250  * The AGP backend implementation lives in drm_agpsupport.c
251  * basically maps these calls to available functions in agpgart.
252  * Each drm device driver gets an
253  * additional function pointer that creates these types,
254  * so that the device can choose the correct aperture.
255  * (Multiple AGP apertures, etc.)
256  * Most device drivers will let this point to the standard AGP implementation.
257  */
258
259 #define DRM_BE_FLAG_NEEDS_FREE     0x00000001
260 #define DRM_BE_FLAG_BOUND_CACHED   0x00000002
261
262 struct drm_ttm_backend;
263 struct drm_ttm_backend_func {
264         int (*needs_ub_cache_adjust) (struct drm_ttm_backend *backend);
265         int (*populate) (struct drm_ttm_backend *backend,
266                          unsigned long num_pages, struct page **pages);
267         void (*clear) (struct drm_ttm_backend *backend);
268         int (*bind) (struct drm_ttm_backend *backend,
269                      struct drm_bo_mem_reg *bo_mem);
270         int (*unbind) (struct drm_ttm_backend *backend);
271         void (*destroy) (struct drm_ttm_backend *backend);
272 };
273
274
275 struct drm_ttm_backend {
276         struct drm_device *dev;
277         uint32_t flags;
278         struct drm_ttm_backend_func *func;
279 };
280
281 struct drm_ttm {
282         struct page *dummy_read_page;
283         struct page **pages;
284         uint32_t page_flags;
285         unsigned long num_pages;
286         atomic_t vma_count;
287         struct drm_device *dev;
288         int destroy;
289         uint32_t mapping_offset;
290         struct drm_ttm_backend *be;
291         enum {
292                 ttm_bound,
293                 ttm_evicted,
294                 ttm_unbound,
295                 ttm_unpopulated,
296         } state;
297
298 };
299
300 extern struct drm_ttm *drm_ttm_create(struct drm_device *dev, unsigned long size,
301                                       uint32_t page_flags,
302                                       struct page *dummy_read_page);
303 extern int drm_ttm_bind(struct drm_ttm *ttm, struct drm_bo_mem_reg *bo_mem);
304 extern void drm_ttm_unbind(struct drm_ttm *ttm);
305 extern void drm_ttm_evict(struct drm_ttm *ttm);
306 extern void drm_ttm_fixup_caching(struct drm_ttm *ttm);
307 extern struct page *drm_ttm_get_page(struct drm_ttm *ttm, int index);
308 extern void drm_ttm_cache_flush(void);
309 extern int drm_ttm_populate(struct drm_ttm *ttm);
310 extern int drm_ttm_set_user(struct drm_ttm *ttm,
311                             struct task_struct *tsk,
312                             unsigned long start,
313                             unsigned long num_pages);
314
315 /*
316  * Destroy a ttm. The user normally calls drmRmMap or a similar IOCTL to do
317  * this which calls this function iff there are no vmas referencing it anymore.
318  * Otherwise it is called when the last vma exits.
319  */
320
321 extern int drm_ttm_destroy(struct drm_ttm *ttm);
322
323 #define DRM_FLAG_MASKED(_old, _new, _mask) {\
324 (_old) ^= (((_old) ^ (_new)) & (_mask)); \
325 }
326
327 #define DRM_TTM_MASK_FLAGS ((1 << PAGE_SHIFT) - 1)
328 #define DRM_TTM_MASK_PFN (0xFFFFFFFFU - DRM_TTM_MASK_FLAGS)
329
330 /*
331  * Page flags.
332  */
333
334 /*
335  * This ttm should not be cached by the CPU
336  */
337 #define DRM_TTM_PAGE_UNCACHED   (1 << 0)
338 /*
339  * This flat is not used at this time; I don't know what the
340  * intent was
341  */
342 #define DRM_TTM_PAGE_USED       (1 << 1)
343 /*
344  * This flat is not used at this time; I don't know what the
345  * intent was
346  */
347 #define DRM_TTM_PAGE_BOUND      (1 << 2)
348 /*
349  * This flat is not used at this time; I don't know what the
350  * intent was
351  */
352 #define DRM_TTM_PAGE_PRESENT    (1 << 3)
353 /*
354  * The array of page pointers was allocated with vmalloc
355  * instead of drm_calloc.
356  */
357 #define DRM_TTM_PAGE_VMALLOC    (1 << 4)
358 /*
359  * This ttm is mapped from user space
360  */
361 #define DRM_TTM_PAGE_USER       (1 << 5)
362 /*
363  * This ttm will be written to by the GPU
364  */
365 #define DRM_TTM_PAGE_WRITE      (1 << 6)
366 /*
367  * This ttm was mapped to the GPU, and so the contents may have
368  * been modified
369  */
370 #define DRM_TTM_PAGE_USER_DIRTY (1 << 7)
371 /*
372  * This flag is not used at this time; I don't know what the
373  * intent was.
374  */
375 #define DRM_TTM_PAGE_USER_DMA   (1 << 8)
376
377 /***************************************************
378  * Buffer objects. (drm_bo.c, drm_bo_move.c)
379  */
380
381 struct drm_bo_mem_reg {
382         struct drm_mm_node *mm_node;
383         unsigned long size;
384         unsigned long num_pages;
385         uint32_t page_alignment;
386         uint32_t mem_type;
387         uint64_t flags;
388         uint64_t mask;
389         uint32_t desired_tile_stride;
390         uint32_t hw_tile_stride;
391 };
392
393 enum drm_bo_type {
394         drm_bo_type_dc,
395         drm_bo_type_user,
396         drm_bo_type_kernel, /* for initial kernel allocations */
397 };
398
399 struct drm_buffer_object {
400         struct drm_device *dev;
401         struct drm_user_object base;
402
403         /*
404          * If there is a possibility that the usage variable is zero,
405          * then dev->struct_mutext should be locked before incrementing it.
406          */
407
408         atomic_t usage;
409         unsigned long buffer_start;
410         enum drm_bo_type type;
411         unsigned long offset;
412         atomic_t mapped;
413         struct drm_bo_mem_reg mem;
414
415         struct list_head lru;
416         struct list_head ddestroy;
417
418         uint32_t fence_type;
419         uint32_t fence_class;
420         uint32_t new_fence_type;
421         uint32_t new_fence_class;
422         struct drm_fence_object *fence;
423         uint32_t priv_flags;
424         wait_queue_head_t event_queue;
425         struct mutex mutex;
426         unsigned long num_pages;
427
428         /* For pinned buffers */
429         struct drm_mm_node *pinned_node;
430         uint32_t pinned_mem_type;
431         struct list_head pinned_lru;
432
433         /* For vm */
434         struct drm_ttm *ttm;
435         struct drm_map_list map_list;
436         uint32_t memory_type;
437         unsigned long bus_offset;
438         uint32_t vm_flags;
439         void *iomap;
440
441 #ifdef DRM_ODD_MM_COMPAT
442         /* dev->struct_mutex only protected. */
443         struct list_head vma_list;
444         struct list_head p_mm_list;
445 #endif
446
447 };
448
449 #define _DRM_BO_FLAG_UNFENCED 0x00000001
450 #define _DRM_BO_FLAG_EVICTED  0x00000002
451
452 struct drm_mem_type_manager {
453         int has_type;
454         int use_type;
455         struct drm_mm manager;
456         struct list_head lru;
457         struct list_head pinned;
458         uint32_t flags;
459         uint32_t drm_bus_maptype;
460         unsigned long gpu_offset;
461         unsigned long io_offset;
462         unsigned long io_size;
463         void *io_addr;
464 };
465
466 struct drm_bo_lock {
467         struct drm_user_object base;
468         wait_queue_head_t queue;
469         atomic_t write_lock_pending;
470         atomic_t readers;
471 };
472
473 #define _DRM_FLAG_MEMTYPE_FIXED     0x00000001  /* Fixed (on-card) PCI memory */
474 #define _DRM_FLAG_MEMTYPE_MAPPABLE  0x00000002  /* Memory mappable */
475 #define _DRM_FLAG_MEMTYPE_CACHED    0x00000004  /* Cached binding */
476 #define _DRM_FLAG_NEEDS_IOREMAP     0x00000008  /* Fixed memory needs ioremap
477                                                    before kernel access. */
478 #define _DRM_FLAG_MEMTYPE_CMA       0x00000010  /* Can't map aperture */
479 #define _DRM_FLAG_MEMTYPE_CSELECT   0x00000020  /* Select caching */
480
481 struct drm_buffer_manager {
482         struct drm_bo_lock bm_lock;
483         struct mutex evict_mutex;
484         int nice_mode;
485         int initialized;
486         struct drm_file *last_to_validate;
487         struct drm_mem_type_manager man[DRM_BO_MEM_TYPES];
488         struct list_head unfenced;
489         struct list_head ddestroy;
490 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
491         struct work_struct wq;
492 #else
493         struct delayed_work wq;
494 #endif
495         uint32_t fence_type;
496         unsigned long cur_pages;
497         atomic_t count;
498         struct page *dummy_read_page;
499 };
500
501 struct drm_bo_driver {
502         const uint32_t *mem_type_prio;
503         const uint32_t *mem_busy_prio;
504         uint32_t num_mem_type_prio;
505         uint32_t num_mem_busy_prio;
506         struct drm_ttm_backend *(*create_ttm_backend_entry)
507          (struct drm_device *dev);
508         int (*fence_type) (struct drm_buffer_object *bo, uint32_t *fclass,
509                            uint32_t *type);
510         int (*invalidate_caches) (struct drm_device *dev, uint64_t flags);
511         int (*init_mem_type) (struct drm_device *dev, uint32_t type,
512                               struct drm_mem_type_manager *man);
513          uint32_t(*evict_mask) (struct drm_buffer_object *bo);
514         int (*move) (struct drm_buffer_object *bo,
515                      int evict, int no_wait, struct drm_bo_mem_reg *new_mem);
516         void (*ttm_cache_flush)(struct drm_ttm *ttm);
517 };
518
519 /*
520  * buffer objects (drm_bo.c)
521  */
522
523 extern int drm_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
524 extern int drm_bo_destroy_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
525 extern int drm_bo_map_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
526 extern int drm_bo_unmap_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
527 extern int drm_bo_reference_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
528 extern int drm_bo_unreference_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
529 extern int drm_bo_wait_idle_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
530 extern int drm_bo_info_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
531 extern int drm_bo_setstatus_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
532 extern int drm_mm_init_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
533 extern int drm_mm_takedown_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
534 extern int drm_mm_lock_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
535 extern int drm_mm_unlock_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
536 extern int drm_bo_version_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
537 extern int drm_bo_driver_finish(struct drm_device *dev);
538 extern int drm_bo_driver_init(struct drm_device *dev);
539 extern int drm_bo_pci_offset(struct drm_device *dev,
540                              struct drm_bo_mem_reg *mem,
541                              unsigned long *bus_base,
542                              unsigned long *bus_offset,
543                              unsigned long *bus_size);
544 extern int drm_mem_reg_is_pci(struct drm_device *dev, struct drm_bo_mem_reg *mem);
545
546 extern void drm_bo_usage_deref_locked(struct drm_buffer_object **bo);
547 extern void drm_bo_usage_deref_unlocked(struct drm_buffer_object **bo);
548 extern void drm_putback_buffer_objects(struct drm_device *dev);
549 extern int drm_fence_buffer_objects(struct drm_device *dev,
550                                     struct list_head *list,
551                                     uint32_t fence_flags,
552                                     struct drm_fence_object *fence,
553                                     struct drm_fence_object **used_fence);
554 extern void drm_bo_add_to_lru(struct drm_buffer_object *bo);
555 extern int drm_buffer_object_create(struct drm_device *dev, unsigned long size,
556                                     enum drm_bo_type type, uint64_t mask,
557                                     uint32_t hint, uint32_t page_alignment,
558                                     unsigned long buffer_start,
559                                     struct drm_buffer_object **bo);
560 extern int drm_bo_wait(struct drm_buffer_object *bo, int lazy, int ignore_signals,
561                        int no_wait);
562 extern int drm_bo_mem_space(struct drm_buffer_object *bo,
563                             struct drm_bo_mem_reg *mem, int no_wait);
564 extern int drm_bo_move_buffer(struct drm_buffer_object *bo,
565                               uint64_t new_mem_flags,
566                               int no_wait, int move_unfenced);
567 extern int drm_bo_clean_mm(struct drm_device *dev, unsigned mem_type);
568 extern int drm_bo_init_mm(struct drm_device *dev, unsigned type,
569                           unsigned long p_offset, unsigned long p_size);
570 extern int drm_bo_handle_validate(struct drm_file *file_priv, uint32_t handle,
571                                   uint64_t flags, uint64_t mask, uint32_t hint,
572                                   uint32_t fence_class, int use_old_fence_class,
573                                   struct drm_bo_info_rep *rep,
574                                   struct drm_buffer_object **bo_rep);
575 extern struct drm_buffer_object *drm_lookup_buffer_object(struct drm_file *file_priv,
576                                                           uint32_t handle,
577                                                           int check_owner);
578 extern int drm_bo_do_validate(struct drm_buffer_object *bo,
579                               uint64_t flags, uint64_t mask, uint32_t hint,
580                               uint32_t fence_class,
581                               struct drm_bo_info_rep *rep);
582
583 /*
584  * Buffer object memory move- and map helpers.
585  * drm_bo_move.c
586  */
587
588 extern int drm_bo_move_ttm(struct drm_buffer_object *bo,
589                            int evict, int no_wait,
590                            struct drm_bo_mem_reg *new_mem);
591 extern int drm_bo_move_memcpy(struct drm_buffer_object *bo,
592                               int evict,
593                               int no_wait, struct drm_bo_mem_reg *new_mem);
594 extern int drm_bo_move_accel_cleanup(struct drm_buffer_object *bo,
595                                      int evict, int no_wait,
596                                      uint32_t fence_class, uint32_t fence_type,
597                                      uint32_t fence_flags,
598                                      struct drm_bo_mem_reg *new_mem);
599 extern int drm_bo_same_page(unsigned long offset, unsigned long offset2);
600 extern unsigned long drm_bo_offset_end(unsigned long offset,
601                                        unsigned long end);
602
603 struct drm_bo_kmap_obj {
604         void *virtual;
605         struct page *page;
606         enum {
607                 bo_map_iomap,
608                 bo_map_vmap,
609                 bo_map_kmap,
610                 bo_map_premapped,
611         } bo_kmap_type;
612 };
613
614 static inline void *drm_bmo_virtual(struct drm_bo_kmap_obj *map, int *is_iomem)
615 {
616         *is_iomem = (map->bo_kmap_type == bo_map_iomap ||
617                      map->bo_kmap_type == bo_map_premapped);
618         return map->virtual;
619 }
620 extern void drm_bo_kunmap(struct drm_bo_kmap_obj *map);
621 extern int drm_bo_kmap(struct drm_buffer_object *bo, unsigned long start_page,
622                        unsigned long num_pages, struct drm_bo_kmap_obj *map);
623
624
625 /*
626  * drm_regman.c
627  */
628
629 struct drm_reg {
630         struct list_head head;
631         struct drm_fence_object *fence;
632         uint32_t fence_type;
633         uint32_t new_fence_type;
634 };
635
636 struct drm_reg_manager {
637         struct list_head free;
638         struct list_head lru;
639         struct list_head unfenced;
640
641         int (*reg_reusable)(const struct drm_reg *reg, const void *data);
642         void (*reg_destroy)(struct drm_reg *reg);
643 };
644
645 extern int drm_regs_alloc(struct drm_reg_manager *manager,
646                           const void *data,
647                           uint32_t fence_class,
648                           uint32_t fence_type,
649                           int interruptible,
650                           int no_wait,
651                           struct drm_reg **reg);
652
653 extern void drm_regs_fence(struct drm_reg_manager *regs,
654                            struct drm_fence_object *fence);
655
656 extern void drm_regs_free(struct drm_reg_manager *manager);
657 extern void drm_regs_add(struct drm_reg_manager *manager, struct drm_reg *reg);
658 extern void drm_regs_init(struct drm_reg_manager *manager,
659                           int (*reg_reusable)(const struct drm_reg *,
660                                               const void *),
661                           void (*reg_destroy)(struct drm_reg *));
662
663 /*
664  * drm_bo_lock.c
665  * Simple replacement for the hardware lock on buffer manager init and clean.
666  */
667
668
669 extern void drm_bo_init_lock(struct drm_bo_lock *lock);
670 extern void drm_bo_read_unlock(struct drm_bo_lock *lock);
671 extern int drm_bo_read_lock(struct drm_bo_lock *lock);
672 extern int drm_bo_write_lock(struct drm_bo_lock *lock,
673                              struct drm_file *file_priv);
674
675 extern int drm_bo_write_unlock(struct drm_bo_lock *lock,
676                                struct drm_file *file_priv);
677
678 #ifdef CONFIG_DEBUG_MUTEXES
679 #define DRM_ASSERT_LOCKED(_mutex)                                       \
680         BUG_ON(!mutex_is_locked(_mutex) ||                              \
681                ((_mutex)->owner != current_thread_info()))
682 #else
683 #define DRM_ASSERT_LOCKED(_mutex)
684 #endif
685 #endif