1 /**************************************************************************
3 * Copyright (c) 2006-2007 Tungsten Graphics, Inc., Cedar Park, TX., USA
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
31 #ifndef _DRM_OBJECTS_H
32 #define _DRM_OBJECTS_H
35 struct drm_bo_mem_reg;
37 #define DRM_FENCE_FLAG_EMIT 0x00000001
38 #define DRM_FENCE_FLAG_SHAREABLE 0x00000002
40 * On hardware with no interrupt events for operation completion,
41 * indicates that the kernel should sleep while waiting for any blocking
42 * operation to complete rather than spinning.
44 * Has no effect otherwise.
46 #define DRM_FENCE_FLAG_WAIT_LAZY 0x00000004
47 #define DRM_FENCE_FLAG_NO_USER 0x00000010
49 /* Reserved for driver use */
50 #define DRM_FENCE_MASK_DRIVER 0xFF000000
52 #define DRM_FENCE_TYPE_EXE 0x00000001
54 struct drm_fence_arg {
56 unsigned int fence_class;
59 unsigned int signaled;
61 unsigned int sequence;
63 uint64_t expand_pad[2]; /*Future expansion */
66 /* Buffer permissions, referring to how the GPU uses the buffers.
67 * these translate to fence types used for the buffers.
68 * Typically a texture buffer is read, A destination buffer is write and
69 * a command (batch-) buffer is exe. Can be or-ed together.
72 #define DRM_BO_FLAG_READ (1ULL << 0)
73 #define DRM_BO_FLAG_WRITE (1ULL << 1)
74 #define DRM_BO_FLAG_EXE (1ULL << 2)
77 * All of the bits related to access mode
79 #define DRM_BO_MASK_ACCESS (DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_EXE)
81 * Status flags. Can be read to determine the actual state of a buffer.
82 * Can also be set in the buffer mask before validation.
86 * Mask: Never evict this buffer. Not even with force. This type of buffer is only
87 * available to root and must be manually removed before buffer manager shutdown
91 #define DRM_BO_FLAG_NO_EVICT (1ULL << 4)
94 * Mask: Require that the buffer is placed in mappable memory when validated.
95 * If not set the buffer may or may not be in mappable memory when validated.
96 * Flags: If set, the buffer is in mappable memory.
98 #define DRM_BO_FLAG_MAPPABLE (1ULL << 5)
100 /* Mask: The buffer should be shareable with other processes.
101 * Flags: The buffer is shareable with other processes.
103 #define DRM_BO_FLAG_SHAREABLE (1ULL << 6)
105 /* Mask: If set, place the buffer in cache-coherent memory if available.
106 * If clear, never place the buffer in cache coherent memory if validated.
107 * Flags: The buffer is currently in cache-coherent memory.
109 #define DRM_BO_FLAG_CACHED (1ULL << 7)
111 /* Mask: Make sure that every time this buffer is validated,
112 * it ends up on the same location provided that the memory mask is the same.
113 * The buffer will also not be evicted when claiming space for
114 * other buffers. Basically a pinned buffer but it may be thrown out as
115 * part of buffer manager shutdown or locking.
116 * Flags: Acknowledge.
118 #define DRM_BO_FLAG_NO_MOVE (1ULL << 8)
120 /* Mask: Make sure the buffer is in cached memory when mapped. In conjunction
121 * with DRM_BO_FLAG_CACHED it also allows the buffer to be bound into the GART
122 * with unsnooped PTEs instead of snooped, by using chipset-specific cache
123 * flushing at bind time. A better name might be DRM_BO_FLAG_TT_UNSNOOPED,
124 * as the eviction to local memory (TTM unbind) on map is just a side effect
125 * to prevent aggressive cache prefetch from the GPU disturbing the cache
126 * management that the DRM is doing.
128 * Flags: Acknowledge.
129 * Buffers allocated with this flag should not be used for suballocators
130 * This type may have issues on CPUs with over-aggressive caching
131 * http://marc.info/?l=linux-kernel&m=102376926732464&w=2
133 #define DRM_BO_FLAG_CACHED_MAPPED (1ULL << 19)
136 /* Mask: Force DRM_BO_FLAG_CACHED flag strictly also if it is set.
137 * Flags: Acknowledge.
139 #define DRM_BO_FLAG_FORCE_CACHING (1ULL << 13)
142 * Mask: Force DRM_BO_FLAG_MAPPABLE flag strictly also if it is clear.
143 * Flags: Acknowledge.
145 #define DRM_BO_FLAG_FORCE_MAPPABLE (1ULL << 14)
146 #define DRM_BO_FLAG_TILE (1ULL << 15)
149 * Memory type flags that can be or'ed together in the mask, but only
150 * one appears in flags.
154 #define DRM_BO_FLAG_MEM_LOCAL (1ULL << 24)
155 /* Translation table memory */
156 #define DRM_BO_FLAG_MEM_TT (1ULL << 25)
158 #define DRM_BO_FLAG_MEM_VRAM (1ULL << 26)
159 /* Up to the driver to define. */
160 #define DRM_BO_FLAG_MEM_PRIV0 (1ULL << 27)
161 #define DRM_BO_FLAG_MEM_PRIV1 (1ULL << 28)
162 #define DRM_BO_FLAG_MEM_PRIV2 (1ULL << 29)
163 #define DRM_BO_FLAG_MEM_PRIV3 (1ULL << 30)
164 #define DRM_BO_FLAG_MEM_PRIV4 (1ULL << 31)
165 /* We can add more of these now with a 64-bit flag type */
168 * This is a mask covering all of the memory type flags; easier to just
169 * use a single constant than a bunch of | values. It covers
170 * DRM_BO_FLAG_MEM_LOCAL through DRM_BO_FLAG_MEM_PRIV4
172 #define DRM_BO_MASK_MEM 0x00000000FF000000ULL
174 * This adds all of the CPU-mapping options in with the memory
175 * type to label all bits which change how the page gets mapped
177 #define DRM_BO_MASK_MEMTYPE (DRM_BO_MASK_MEM | \
178 DRM_BO_FLAG_CACHED_MAPPED | \
179 DRM_BO_FLAG_CACHED | \
180 DRM_BO_FLAG_MAPPABLE)
182 /* Driver-private flags */
183 #define DRM_BO_MASK_DRIVER 0xFFFF000000000000ULL
186 * Don't block on validate and map. Instead, return EBUSY.
188 #define DRM_BO_HINT_DONT_BLOCK 0x00000002
190 * Don't place this buffer on the unfenced list. This means
191 * that the buffer will not end up having a fence associated
192 * with it as a result of this operation
194 #define DRM_BO_HINT_DONT_FENCE 0x00000004
196 * On hardware with no interrupt events for operation completion,
197 * indicates that the kernel should sleep while waiting for any blocking
198 * operation to complete rather than spinning.
200 * Has no effect otherwise.
202 #define DRM_BO_HINT_WAIT_LAZY 0x00000008
204 * The client has compute relocations refering to this buffer using the
205 * offset in the presumed_offset field. If that offset ends up matching
206 * where this buffer lands, the kernel is free to skip executing those
209 #define DRM_BO_HINT_PRESUMED_OFFSET 0x00000010
212 #define DRM_BO_MEM_LOCAL 0
213 #define DRM_BO_MEM_TT 1
214 #define DRM_BO_MEM_VRAM 2
215 #define DRM_BO_MEM_PRIV0 3
216 #define DRM_BO_MEM_PRIV1 4
217 #define DRM_BO_MEM_PRIV2 5
218 #define DRM_BO_MEM_PRIV3 6
219 #define DRM_BO_MEM_PRIV4 7
221 #define DRM_BO_MEM_TYPES 8 /* For now. */
223 #define DRM_BO_LOCK_UNLOCK_BM (1 << 0)
224 #define DRM_BO_LOCK_IGNORE_NO_EVICT (1 << 1)
227 /***************************************************
228 * Fence objects. (drm_fence.c)
231 struct drm_fence_object {
232 struct drm_device *dev;
236 * The below three fields are protected by the fence manager spinlock.
239 struct list_head ring;
241 uint32_t native_types;
243 uint32_t signaled_types;
245 uint32_t waiting_types;
249 #define _DRM_FENCE_CLASSES 8
251 struct drm_fence_class_manager {
252 struct list_head ring;
253 uint32_t pending_flush;
254 uint32_t waiting_types;
255 wait_queue_head_t fence_queue;
256 uint32_t highest_waiting_sequence;
257 uint32_t latest_queued_sequence;
260 struct drm_fence_manager {
263 struct drm_fence_class_manager fence_class[_DRM_FENCE_CLASSES];
264 uint32_t num_classes;
268 struct drm_fence_driver {
269 unsigned long *waiting_jiffies;
270 uint32_t num_classes;
273 uint32_t sequence_mask;
276 * Driver implemented functions:
277 * has_irq() : 1 if the hardware can update the indicated type_flags using an
278 * irq handler. 0 if polling is required.
280 * emit() : Emit a sequence number to the command stream.
281 * Return the sequence number.
283 * flush() : Make sure the flags indicated in fc->pending_flush will eventually
284 * signal for fc->highest_received_sequence and all preceding sequences.
285 * Acknowledge by clearing the flags fc->pending_flush.
287 * poll() : Call drm_fence_handler with any new information.
289 * needed_flush() : Given the current state of the fence->type flags and previusly
290 * executed or queued flushes, return the type_flags that need flushing.
292 * wait(): Wait for the "mask" flags to signal on a given fence, performing
293 * whatever's necessary to make this happen.
296 int (*has_irq) (struct drm_device *dev, uint32_t fence_class,
298 int (*emit) (struct drm_device *dev, uint32_t fence_class,
299 uint32_t flags, uint32_t *breadcrumb,
300 uint32_t *native_type);
301 void (*flush) (struct drm_device *dev, uint32_t fence_class);
302 void (*poll) (struct drm_device *dev, uint32_t fence_class,
304 uint32_t (*needed_flush) (struct drm_fence_object *fence);
305 int (*wait) (struct drm_fence_object *fence, int lazy,
306 int interruptible, uint32_t mask);
309 extern int drm_fence_wait_polling(struct drm_fence_object *fence, int lazy,
310 int interruptible, uint32_t mask,
311 unsigned long end_jiffies);
312 extern void drm_fence_handler(struct drm_device *dev, uint32_t fence_class,
313 uint32_t sequence, uint32_t type,
315 extern void drm_fence_manager_init(struct drm_device *dev);
316 extern void drm_fence_manager_takedown(struct drm_device *dev);
317 extern void drm_fence_flush_old(struct drm_device *dev, uint32_t fence_class,
319 extern int drm_fence_object_flush(struct drm_fence_object *fence,
321 extern int drm_fence_object_signaled(struct drm_fence_object *fence,
323 extern void drm_fence_usage_deref_locked(struct drm_fence_object **fence);
324 extern void drm_fence_usage_deref_unlocked(struct drm_fence_object **fence);
325 extern struct drm_fence_object *drm_fence_reference_locked(struct drm_fence_object *src);
326 extern void drm_fence_reference_unlocked(struct drm_fence_object **dst,
327 struct drm_fence_object *src);
328 extern int drm_fence_object_wait(struct drm_fence_object *fence,
329 int lazy, int ignore_signals, uint32_t mask);
330 extern int drm_fence_object_create(struct drm_device *dev, uint32_t type,
331 uint32_t fence_flags, uint32_t fence_class,
332 struct drm_fence_object **c_fence);
333 extern int drm_fence_object_emit(struct drm_fence_object *fence,
334 uint32_t fence_flags, uint32_t class,
336 extern void drm_fence_fill_arg(struct drm_fence_object *fence,
337 struct drm_fence_arg *arg);
339 extern int drm_fence_add_user_object(struct drm_file *priv,
340 struct drm_fence_object *fence,
343 extern int drm_fence_create_ioctl(struct drm_device *dev, void *data,
344 struct drm_file *file_priv);
345 extern int drm_fence_destroy_ioctl(struct drm_device *dev, void *data,
346 struct drm_file *file_priv);
347 extern int drm_fence_reference_ioctl(struct drm_device *dev, void *data,
348 struct drm_file *file_priv);
349 extern int drm_fence_unreference_ioctl(struct drm_device *dev, void *data,
350 struct drm_file *file_priv);
351 extern int drm_fence_signaled_ioctl(struct drm_device *dev, void *data,
352 struct drm_file *file_priv);
353 extern int drm_fence_flush_ioctl(struct drm_device *dev, void *data,
354 struct drm_file *file_priv);
355 extern int drm_fence_wait_ioctl(struct drm_device *dev, void *data,
356 struct drm_file *file_priv);
357 extern int drm_fence_emit_ioctl(struct drm_device *dev, void *data,
358 struct drm_file *file_priv);
359 extern int drm_fence_buffers_ioctl(struct drm_device *dev, void *data,
360 struct drm_file *file_priv);
361 /**************************************************
366 * The ttm backend GTT interface. (In our case AGP).
367 * Any similar type of device (PCIE?)
368 * needs only to implement these functions to be usable with the TTM interface.
369 * The AGP backend implementation lives in drm_agpsupport.c
370 * basically maps these calls to available functions in agpgart.
371 * Each drm device driver gets an
372 * additional function pointer that creates these types,
373 * so that the device can choose the correct aperture.
374 * (Multiple AGP apertures, etc.)
375 * Most device drivers will let this point to the standard AGP implementation.
378 #define DRM_BE_FLAG_NEEDS_FREE 0x00000001
379 #define DRM_BE_FLAG_BOUND_CACHED 0x00000002
381 struct drm_ttm_backend;
382 struct drm_ttm_backend_func {
383 int (*needs_ub_cache_adjust) (struct drm_ttm_backend *backend);
384 int (*populate) (struct drm_ttm_backend *backend,
385 unsigned long num_pages, struct page **pages,
386 struct page *dummy_read_page);
387 void (*clear) (struct drm_ttm_backend *backend);
388 int (*bind) (struct drm_ttm_backend *backend,
389 struct drm_bo_mem_reg *bo_mem);
390 int (*unbind) (struct drm_ttm_backend *backend);
391 void (*destroy) (struct drm_ttm_backend *backend);
395 * This structure associates a set of flags and methods with a drm_ttm
396 * object, and will also be subclassed by the particular backend.
398 * \sa #drm_agp_ttm_backend
400 struct drm_ttm_backend {
401 struct drm_device *dev;
403 struct drm_ttm_backend_func *func;
407 struct page *dummy_read_page;
409 long first_himem_page;
410 long last_lomem_page;
412 unsigned long num_pages;
414 struct drm_device *dev;
416 uint32_t mapping_offset;
417 struct drm_ttm_backend *be;
418 unsigned long highest_lomem_entry;
419 unsigned long lowest_himem_entry;
429 extern struct drm_ttm *drm_ttm_create(struct drm_device *dev, unsigned long size,
431 struct page *dummy_read_page);
432 extern int drm_ttm_bind(struct drm_ttm *ttm, struct drm_bo_mem_reg *bo_mem);
433 extern void drm_ttm_unbind(struct drm_ttm *ttm);
434 extern void drm_ttm_evict(struct drm_ttm *ttm);
435 extern void drm_ttm_fixup_caching(struct drm_ttm *ttm);
436 extern struct page *drm_ttm_get_page(struct drm_ttm *ttm, int index);
437 extern void drm_ttm_cache_flush(struct page *pages[], unsigned long num_pages);
438 extern int drm_ttm_populate(struct drm_ttm *ttm);
439 extern int drm_ttm_set_user(struct drm_ttm *ttm,
440 struct task_struct *tsk,
442 unsigned long num_pages);
445 * Destroy a ttm. The user normally calls drmRmMap or a similar IOCTL to do
446 * this which calls this function iff there are no vmas referencing it anymore.
447 * Otherwise it is called when the last vma exits.
450 extern int drm_ttm_destroy(struct drm_ttm *ttm);
452 #define DRM_FLAG_MASKED(_old, _new, _mask) {\
453 (_old) ^= (((_old) ^ (_new)) & (_mask)); \
456 #define DRM_TTM_MASK_FLAGS ((1 << PAGE_SHIFT) - 1)
457 #define DRM_TTM_MASK_PFN (0xFFFFFFFFU - DRM_TTM_MASK_FLAGS)
464 * This ttm should not be cached by the CPU
466 #define DRM_TTM_PAGE_UNCACHED (1 << 0)
468 * This flat is not used at this time; I don't know what the
471 #define DRM_TTM_PAGE_USED (1 << 1)
473 * This flat is not used at this time; I don't know what the
476 #define DRM_TTM_PAGE_BOUND (1 << 2)
478 * This flat is not used at this time; I don't know what the
481 #define DRM_TTM_PAGE_PRESENT (1 << 3)
483 * The array of page pointers was allocated with vmalloc
484 * instead of drm_calloc.
486 #define DRM_TTM_PAGEDIR_VMALLOC (1 << 4)
488 * This ttm is mapped from user space
490 #define DRM_TTM_PAGE_USER (1 << 5)
492 * This ttm will be written to by the GPU
494 #define DRM_TTM_PAGE_WRITE (1 << 6)
496 * This ttm was mapped to the GPU, and so the contents may have
499 #define DRM_TTM_PAGE_USER_DIRTY (1 << 7)
501 * This flag is not used at this time; I don't know what the
504 #define DRM_TTM_PAGE_USER_DMA (1 << 8)
506 /***************************************************
507 * Buffer objects. (drm_bo.c, drm_bo_move.c)
510 struct drm_bo_mem_reg {
511 struct drm_mm_node *mm_node;
513 unsigned long num_pages;
514 uint32_t page_alignment;
517 * Current buffer status flags, indicating
518 * where the buffer is located and which
519 * access modes are in effect
523 * These are the flags proposed for
524 * a validate operation. If the
525 * validate succeeds, they'll get moved
526 * into the flags field
528 uint64_t proposed_flags;
530 uint32_t desired_tile_stride;
531 uint32_t hw_tile_stride;
536 * drm_bo_type_device are 'normal' drm allocations,
537 * pages are allocated from within the kernel automatically
538 * and the objects can be mmap'd from the drm device. Each
539 * drm_bo_type_device object has a unique name which can be
540 * used by other processes to share access to the underlying
545 * drm_bo_type_user are buffers of pages that already exist
546 * in the process address space. They are more limited than
547 * drm_bo_type_device buffers in that they must always
548 * remain cached (as we assume the user pages are mapped cached),
549 * and they are not sharable to other processes through DRM
550 * (although, regular shared memory should still work fine).
554 * drm_bo_type_kernel are buffers that exist solely for use
555 * within the kernel. The pages cannot be mapped into the
556 * process. One obvious use would be for the ring
557 * buffer where user access would not (ideally) be required.
562 struct drm_buffer_object {
563 struct drm_device *dev;
566 * If there is a possibility that the usage variable is zero,
567 * then dev->struct_mutext should be locked before incrementing it.
571 unsigned long buffer_start;
572 enum drm_bo_type type;
573 unsigned long offset;
575 struct drm_bo_mem_reg mem;
577 struct list_head lru;
578 struct list_head ddestroy;
581 uint32_t fence_class;
582 uint32_t new_fence_type;
583 uint32_t new_fence_class;
584 struct drm_fence_object *fence;
586 wait_queue_head_t event_queue;
588 unsigned long num_pages;
590 /* For pinned buffers */
591 struct drm_mm_node *pinned_node;
592 uint32_t pinned_mem_type;
593 struct list_head pinned_lru;
597 struct drm_map_list map_list;
598 uint32_t memory_type;
599 unsigned long bus_offset;
603 #ifdef DRM_ODD_MM_COMPAT
604 /* dev->struct_mutex only protected. */
605 struct list_head vma_list;
606 struct list_head p_mm_list;
611 #define _DRM_BO_FLAG_UNFENCED 0x00000001
612 #define _DRM_BO_FLAG_EVICTED 0x00000002
615 * This flag indicates that a flag called with bo->mutex held has
616 * temporarily released the buffer object mutex, (usually to wait for something).
617 * and thus any post-lock validation needs to be rerun.
620 #define _DRM_BO_FLAG_UNLOCKED 0x00000004
622 struct drm_mem_type_manager {
626 struct drm_mm manager;
627 struct list_head lru;
628 struct list_head pinned;
630 uint32_t drm_bus_maptype;
631 unsigned long gpu_offset;
632 unsigned long io_offset;
633 unsigned long io_size;
635 uint64_t size; /* size of managed area for reporting to userspace */
639 // struct drm_user_object base;
640 wait_queue_head_t queue;
641 atomic_t write_lock_pending;
645 #define _DRM_FLAG_MEMTYPE_FIXED 0x00000001 /* Fixed (on-card) PCI memory */
646 #define _DRM_FLAG_MEMTYPE_MAPPABLE 0x00000002 /* Memory mappable */
647 #define _DRM_FLAG_MEMTYPE_CACHED 0x00000004 /* Cached binding */
648 #define _DRM_FLAG_NEEDS_IOREMAP 0x00000008 /* Fixed memory needs ioremap
649 before kernel access. */
650 #define _DRM_FLAG_MEMTYPE_CMA 0x00000010 /* Can't map aperture */
651 #define _DRM_FLAG_MEMTYPE_CSELECT 0x00000020 /* Select caching */
653 struct drm_buffer_manager {
654 struct drm_bo_lock bm_lock;
655 struct mutex evict_mutex;
658 struct drm_file *last_to_validate;
659 struct drm_mem_type_manager man[DRM_BO_MEM_TYPES];
660 struct list_head unfenced;
661 struct list_head ddestroy;
662 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
663 struct work_struct wq;
665 struct delayed_work wq;
668 unsigned long cur_pages;
670 struct page *dummy_read_page;
673 struct drm_bo_driver {
674 const uint32_t *mem_type_prio;
675 const uint32_t *mem_busy_prio;
676 uint32_t num_mem_type_prio;
677 uint32_t num_mem_busy_prio;
678 struct drm_ttm_backend *(*create_ttm_backend_entry)
679 (struct drm_device *dev);
680 int (*fence_type) (struct drm_buffer_object *bo, uint32_t *fclass,
682 int (*invalidate_caches) (struct drm_device *dev, uint64_t flags);
683 int (*init_mem_type) (struct drm_device *dev, uint32_t type,
684 struct drm_mem_type_manager *man);
688 * @bo: the buffer object to be evicted
690 * Return the bo flags for a buffer which is not mapped to the hardware.
691 * These will be placed in proposed_flags so that when the move is
692 * finished, they'll end up in bo->mem.flags
694 uint64_t(*evict_flags) (struct drm_buffer_object *bo);
698 * @bo: the buffer to move
700 * @evict: whether this motion is evicting the buffer from
701 * the graphics address space
703 * @no_wait: whether this should give up and return -EBUSY
704 * if this move would require sleeping
706 * @new_mem: the new memory region receiving the buffer
708 * Move a buffer between two memory regions.
710 int (*move) (struct drm_buffer_object *bo,
711 int evict, int no_wait, struct drm_bo_mem_reg *new_mem);
715 void (*ttm_cache_flush)(struct drm_ttm *ttm);
718 * command_stream_barrier
720 * @dev: The drm device.
722 * @bo: The buffer object to validate.
724 * @new_fence_class: The new fence class for the buffer object.
726 * @new_fence_type: The new fence type for the buffer object.
728 * @no_wait: whether this should give up and return -EBUSY
729 * if this operation would require sleeping
731 * Insert a command stream barrier that makes sure that the
732 * buffer is idle once the commands associated with the
733 * current validation are starting to execute. If an error
734 * condition is returned, or the function pointer is NULL,
735 * the drm core will force buffer idle
739 int (*command_stream_barrier) (struct drm_buffer_object *bo,
740 uint32_t new_fence_class,
741 uint32_t new_fence_type,
746 * buffer objects (drm_bo.c)
748 int drm_bo_do_validate(struct drm_buffer_object *bo,
749 uint64_t flags, uint64_t mask, uint32_t hint,
750 uint32_t fence_class);
751 extern int drm_bo_set_pin(struct drm_device *dev, struct drm_buffer_object *bo, int pin);
752 extern int drm_bo_driver_finish(struct drm_device *dev);
753 extern int drm_bo_driver_init(struct drm_device *dev);
754 extern int drm_bo_pci_offset(struct drm_device *dev,
755 struct drm_bo_mem_reg *mem,
756 unsigned long *bus_base,
757 unsigned long *bus_offset,
758 unsigned long *bus_size);
759 extern int drm_mem_reg_is_pci(struct drm_device *dev, struct drm_bo_mem_reg *mem);
761 extern int drm_bo_add_user_object(struct drm_file *file_priv,
762 struct drm_buffer_object *bo, int shareable);
763 extern void drm_bo_usage_deref_locked(struct drm_buffer_object **bo);
764 extern void drm_bo_usage_deref_unlocked(struct drm_buffer_object **bo);
765 extern void drm_putback_buffer_objects(struct drm_device *dev);
766 extern int drm_fence_buffer_objects(struct drm_device *dev,
767 struct list_head *list,
768 uint32_t fence_flags,
769 struct drm_fence_object *fence,
770 struct drm_fence_object **used_fence);
771 extern void drm_bo_add_to_lru(struct drm_buffer_object *bo);
772 extern int drm_buffer_object_create(struct drm_device *dev, unsigned long size,
773 enum drm_bo_type type, uint64_t flags,
774 uint32_t hint, uint32_t page_alignment,
775 unsigned long buffer_start,
776 struct drm_buffer_object **bo);
777 extern int drm_bo_wait(struct drm_buffer_object *bo, int lazy, int interruptible,
778 int no_wait, int check_unfenced);
779 extern int drm_bo_mem_space(struct drm_buffer_object *bo,
780 struct drm_bo_mem_reg *mem, int no_wait);
781 extern int drm_bo_move_buffer(struct drm_buffer_object *bo,
782 uint64_t new_mem_flags,
783 int no_wait, int move_unfenced);
784 extern int drm_bo_clean_mm(struct drm_device *dev, unsigned mem_type, int kern_clean);
785 extern int drm_bo_init_mm(struct drm_device *dev, unsigned type,
786 unsigned long p_offset, unsigned long p_size,
788 extern struct drm_buffer_object *drm_lookup_buffer_object(struct drm_file *file_priv,
791 extern int drm_bo_evict_cached(struct drm_buffer_object *bo);
793 extern void drm_bo_takedown_vm_locked(struct drm_buffer_object *bo);
795 * Buffer object memory move- and map helpers.
799 extern int drm_bo_move_ttm(struct drm_buffer_object *bo,
800 int evict, int no_wait,
801 struct drm_bo_mem_reg *new_mem);
802 extern int drm_bo_move_memcpy(struct drm_buffer_object *bo,
804 int no_wait, struct drm_bo_mem_reg *new_mem);
805 extern int drm_bo_move_accel_cleanup(struct drm_buffer_object *bo,
806 int evict, int no_wait,
807 uint32_t fence_class, uint32_t fence_type,
808 uint32_t fence_flags,
809 struct drm_bo_mem_reg *new_mem);
810 extern int drm_bo_same_page(unsigned long offset, unsigned long offset2);
811 extern unsigned long drm_bo_offset_end(unsigned long offset,
814 struct drm_bo_kmap_obj {
825 static inline void *drm_bmo_virtual(struct drm_bo_kmap_obj *map, int *is_iomem)
827 *is_iomem = (map->bo_kmap_type == bo_map_iomap ||
828 map->bo_kmap_type == bo_map_premapped);
831 extern void drm_bo_kunmap(struct drm_bo_kmap_obj *map);
832 extern int drm_bo_kmap(struct drm_buffer_object *bo, unsigned long start_page,
833 unsigned long num_pages, struct drm_bo_kmap_obj *map);
834 extern int drm_bo_pfn_prot(struct drm_buffer_object *bo,
835 unsigned long dst_offset,
845 struct list_head head;
846 struct drm_fence_object *fence;
848 uint32_t new_fence_type;
851 struct drm_reg_manager {
852 struct list_head free;
853 struct list_head lru;
854 struct list_head unfenced;
856 int (*reg_reusable)(const struct drm_reg *reg, const void *data);
857 void (*reg_destroy)(struct drm_reg *reg);
860 extern int drm_regs_alloc(struct drm_reg_manager *manager,
862 uint32_t fence_class,
866 struct drm_reg **reg);
868 extern void drm_regs_fence(struct drm_reg_manager *regs,
869 struct drm_fence_object *fence);
871 extern void drm_regs_free(struct drm_reg_manager *manager);
872 extern void drm_regs_add(struct drm_reg_manager *manager, struct drm_reg *reg);
873 extern void drm_regs_init(struct drm_reg_manager *manager,
874 int (*reg_reusable)(const struct drm_reg *,
876 void (*reg_destroy)(struct drm_reg *));
878 extern int drm_mem_reg_ioremap(struct drm_device *dev, struct drm_bo_mem_reg * mem,
880 extern void drm_mem_reg_iounmap(struct drm_device *dev, struct drm_bo_mem_reg * mem,
882 #ifdef CONFIG_DEBUG_MUTEXES
883 #define DRM_ASSERT_LOCKED(_mutex) \
884 BUG_ON(!mutex_is_locked(_mutex) || \
885 ((_mutex)->owner != current_thread_info()))
887 #define DRM_ASSERT_LOCKED(_mutex)