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 * Buffer has been mapped or touched since creation
150 * for VRAM we don't need to migrate, just fill with 0s for non-dirty
152 #define DRM_BO_FLAG_CLEAN (1ULL << 16)
155 * Memory type flags that can be or'ed together in the mask, but only
156 * one appears in flags.
160 #define DRM_BO_FLAG_MEM_LOCAL (1ULL << 24)
161 /* Translation table memory */
162 #define DRM_BO_FLAG_MEM_TT (1ULL << 25)
164 #define DRM_BO_FLAG_MEM_VRAM (1ULL << 26)
165 /* Up to the driver to define. */
166 #define DRM_BO_FLAG_MEM_PRIV0 (1ULL << 27)
167 #define DRM_BO_FLAG_MEM_PRIV1 (1ULL << 28)
168 #define DRM_BO_FLAG_MEM_PRIV2 (1ULL << 29)
169 #define DRM_BO_FLAG_MEM_PRIV3 (1ULL << 30)
170 #define DRM_BO_FLAG_MEM_PRIV4 (1ULL << 31)
171 /* We can add more of these now with a 64-bit flag type */
174 * This is a mask covering all of the memory type flags; easier to just
175 * use a single constant than a bunch of | values. It covers
176 * DRM_BO_FLAG_MEM_LOCAL through DRM_BO_FLAG_MEM_PRIV4
178 #define DRM_BO_MASK_MEM 0x00000000FF000000ULL
180 * This adds all of the CPU-mapping options in with the memory
181 * type to label all bits which change how the page gets mapped
183 #define DRM_BO_MASK_MEMTYPE (DRM_BO_MASK_MEM | \
184 DRM_BO_FLAG_CACHED_MAPPED | \
185 DRM_BO_FLAG_CACHED | \
186 DRM_BO_FLAG_MAPPABLE)
188 /* Driver-private flags */
189 #define DRM_BO_MASK_DRIVER 0xFFFF000000000000ULL
192 * Don't block on validate and map. Instead, return EBUSY.
194 #define DRM_BO_HINT_DONT_BLOCK 0x00000002
196 * Don't place this buffer on the unfenced list. This means
197 * that the buffer will not end up having a fence associated
198 * with it as a result of this operation
200 #define DRM_BO_HINT_DONT_FENCE 0x00000004
202 * On hardware with no interrupt events for operation completion,
203 * indicates that the kernel should sleep while waiting for any blocking
204 * operation to complete rather than spinning.
206 * Has no effect otherwise.
208 #define DRM_BO_HINT_WAIT_LAZY 0x00000008
210 * The client has compute relocations refering to this buffer using the
211 * offset in the presumed_offset field. If that offset ends up matching
212 * where this buffer lands, the kernel is free to skip executing those
215 #define DRM_BO_HINT_PRESUMED_OFFSET 0x00000010
217 #define DRM_BO_MEM_LOCAL 0
218 #define DRM_BO_MEM_TT 1
219 #define DRM_BO_MEM_VRAM 2
220 #define DRM_BO_MEM_PRIV0 3
221 #define DRM_BO_MEM_PRIV1 4
222 #define DRM_BO_MEM_PRIV2 5
223 #define DRM_BO_MEM_PRIV3 6
224 #define DRM_BO_MEM_PRIV4 7
226 #define DRM_BO_MEM_TYPES 8 /* For now. */
228 #define DRM_BO_LOCK_UNLOCK_BM (1 << 0)
229 #define DRM_BO_LOCK_IGNORE_NO_EVICT (1 << 1)
232 /***************************************************
233 * Fence objects. (drm_fence.c)
236 struct drm_fence_object {
237 struct drm_device *dev;
241 * The below three fields are protected by the fence manager spinlock.
244 struct list_head ring;
246 uint32_t native_types;
248 uint32_t signaled_types;
250 uint32_t waiting_types;
254 #define _DRM_FENCE_CLASSES 8
256 struct drm_fence_class_manager {
257 struct list_head ring;
258 uint32_t pending_flush;
259 uint32_t waiting_types;
260 wait_queue_head_t fence_queue;
261 uint32_t highest_waiting_sequence;
262 uint32_t latest_queued_sequence;
265 struct drm_fence_manager {
268 struct drm_fence_class_manager fence_class[_DRM_FENCE_CLASSES];
269 uint32_t num_classes;
273 struct drm_fence_driver {
274 unsigned long *waiting_jiffies;
275 uint32_t num_classes;
278 uint32_t sequence_mask;
281 * Driver implemented functions:
282 * has_irq() : 1 if the hardware can update the indicated type_flags using an
283 * irq handler. 0 if polling is required.
285 * emit() : Emit a sequence number to the command stream.
286 * Return the sequence number.
288 * flush() : Make sure the flags indicated in fc->pending_flush will eventually
289 * signal for fc->highest_received_sequence and all preceding sequences.
290 * Acknowledge by clearing the flags fc->pending_flush.
292 * poll() : Call drm_fence_handler with any new information.
294 * needed_flush() : Given the current state of the fence->type flags and previusly
295 * executed or queued flushes, return the type_flags that need flushing.
297 * wait(): Wait for the "mask" flags to signal on a given fence, performing
298 * whatever's necessary to make this happen.
301 int (*has_irq) (struct drm_device *dev, uint32_t fence_class,
303 int (*emit) (struct drm_device *dev, uint32_t fence_class,
304 uint32_t flags, uint32_t *breadcrumb,
305 uint32_t *native_type);
306 void (*flush) (struct drm_device *dev, uint32_t fence_class);
307 void (*poll) (struct drm_device *dev, uint32_t fence_class,
309 uint32_t (*needed_flush) (struct drm_fence_object *fence);
310 int (*wait) (struct drm_fence_object *fence, int lazy,
311 int interruptible, uint32_t mask);
314 extern int drm_fence_wait_polling(struct drm_fence_object *fence, int lazy,
315 int interruptible, uint32_t mask,
316 unsigned long end_jiffies);
317 extern void drm_fence_handler(struct drm_device *dev, uint32_t fence_class,
318 uint32_t sequence, uint32_t type,
320 extern void drm_fence_manager_init(struct drm_device *dev);
321 extern void drm_fence_manager_takedown(struct drm_device *dev);
322 extern void drm_fence_flush_old(struct drm_device *dev, uint32_t fence_class,
324 extern int drm_fence_object_flush(struct drm_fence_object *fence,
326 extern int drm_fence_object_signaled(struct drm_fence_object *fence,
328 extern void drm_fence_usage_deref_locked(struct drm_fence_object **fence);
329 extern void drm_fence_usage_deref_unlocked(struct drm_fence_object **fence);
330 extern struct drm_fence_object *drm_fence_reference_locked(struct drm_fence_object *src);
331 extern void drm_fence_reference_unlocked(struct drm_fence_object **dst,
332 struct drm_fence_object *src);
333 extern int drm_fence_object_wait(struct drm_fence_object *fence,
334 int lazy, int ignore_signals, uint32_t mask);
335 extern int drm_fence_object_create(struct drm_device *dev, uint32_t type,
336 uint32_t fence_flags, uint32_t fence_class,
337 struct drm_fence_object **c_fence);
338 extern int drm_fence_object_emit(struct drm_fence_object *fence,
339 uint32_t fence_flags, uint32_t class,
341 extern void drm_fence_fill_arg(struct drm_fence_object *fence,
342 struct drm_fence_arg *arg);
344 extern int drm_fence_add_user_object(struct drm_file *priv,
345 struct drm_fence_object *fence,
348 extern int drm_fence_create_ioctl(struct drm_device *dev, void *data,
349 struct drm_file *file_priv);
350 extern int drm_fence_destroy_ioctl(struct drm_device *dev, void *data,
351 struct drm_file *file_priv);
352 extern int drm_fence_reference_ioctl(struct drm_device *dev, void *data,
353 struct drm_file *file_priv);
354 extern int drm_fence_unreference_ioctl(struct drm_device *dev, void *data,
355 struct drm_file *file_priv);
356 extern int drm_fence_signaled_ioctl(struct drm_device *dev, void *data,
357 struct drm_file *file_priv);
358 extern int drm_fence_flush_ioctl(struct drm_device *dev, void *data,
359 struct drm_file *file_priv);
360 extern int drm_fence_wait_ioctl(struct drm_device *dev, void *data,
361 struct drm_file *file_priv);
362 extern int drm_fence_emit_ioctl(struct drm_device *dev, void *data,
363 struct drm_file *file_priv);
364 extern int drm_fence_buffers_ioctl(struct drm_device *dev, void *data,
365 struct drm_file *file_priv);
366 /**************************************************
371 * The ttm backend GTT interface. (In our case AGP).
372 * Any similar type of device (PCIE?)
373 * needs only to implement these functions to be usable with the TTM interface.
374 * The AGP backend implementation lives in drm_agpsupport.c
375 * basically maps these calls to available functions in agpgart.
376 * Each drm device driver gets an
377 * additional function pointer that creates these types,
378 * so that the device can choose the correct aperture.
379 * (Multiple AGP apertures, etc.)
380 * Most device drivers will let this point to the standard AGP implementation.
383 #define DRM_BE_FLAG_NEEDS_FREE 0x00000001
384 #define DRM_BE_FLAG_BOUND_CACHED 0x00000002
386 struct drm_ttm_backend;
387 struct drm_ttm_backend_func {
388 int (*needs_ub_cache_adjust) (struct drm_ttm_backend *backend);
389 int (*populate) (struct drm_ttm_backend *backend,
390 unsigned long num_pages, struct page **pages,
391 struct page *dummy_read_page);
392 void (*clear) (struct drm_ttm_backend *backend);
393 int (*bind) (struct drm_ttm_backend *backend,
394 struct drm_bo_mem_reg *bo_mem);
395 int (*unbind) (struct drm_ttm_backend *backend);
396 void (*destroy) (struct drm_ttm_backend *backend);
400 * This structure associates a set of flags and methods with a drm_ttm
401 * object, and will also be subclassed by the particular backend.
403 * \sa #drm_agp_ttm_backend
405 struct drm_ttm_backend {
406 struct drm_device *dev;
408 struct drm_ttm_backend_func *func;
412 struct page *dummy_read_page;
414 long first_himem_page;
415 long last_lomem_page;
417 unsigned long num_pages;
419 struct drm_device *dev;
421 uint32_t mapping_offset;
422 struct drm_ttm_backend *be;
423 unsigned long highest_lomem_entry;
424 unsigned long lowest_himem_entry;
434 extern struct drm_ttm *drm_ttm_create(struct drm_device *dev, unsigned long size,
436 struct page *dummy_read_page);
437 extern int drm_ttm_bind(struct drm_ttm *ttm, struct drm_bo_mem_reg *bo_mem);
438 extern void drm_ttm_unbind(struct drm_ttm *ttm);
439 extern void drm_ttm_evict(struct drm_ttm *ttm);
440 extern void drm_ttm_fixup_caching(struct drm_ttm *ttm);
441 extern struct page *drm_ttm_get_page(struct drm_ttm *ttm, int index);
442 extern void drm_ttm_cache_flush(struct page *pages[], unsigned long num_pages);
443 extern int drm_ttm_populate(struct drm_ttm *ttm);
444 extern int drm_ttm_set_user(struct drm_ttm *ttm,
445 struct task_struct *tsk,
447 unsigned long num_pages);
450 * Destroy a ttm. The user normally calls drmRmMap or a similar IOCTL to do
451 * this which calls this function iff there are no vmas referencing it anymore.
452 * Otherwise it is called when the last vma exits.
455 extern int drm_ttm_destroy(struct drm_ttm *ttm);
457 #define DRM_FLAG_MASKED(_old, _new, _mask) {\
458 (_old) ^= (((_old) ^ (_new)) & (_mask)); \
461 #define DRM_TTM_MASK_FLAGS ((1 << PAGE_SHIFT) - 1)
462 #define DRM_TTM_MASK_PFN (0xFFFFFFFFU - DRM_TTM_MASK_FLAGS)
469 * This ttm should not be cached by the CPU
471 #define DRM_TTM_PAGE_UNCACHED (1 << 0)
473 * This flat is not used at this time; I don't know what the
476 #define DRM_TTM_PAGE_USED (1 << 1)
478 * This flat is not used at this time; I don't know what the
481 #define DRM_TTM_PAGE_BOUND (1 << 2)
483 * This flat is not used at this time; I don't know what the
486 #define DRM_TTM_PAGE_PRESENT (1 << 3)
488 * The array of page pointers was allocated with vmalloc
489 * instead of drm_calloc.
491 #define DRM_TTM_PAGEDIR_VMALLOC (1 << 4)
493 * This ttm is mapped from user space
495 #define DRM_TTM_PAGE_USER (1 << 5)
497 * This ttm will be written to by the GPU
499 #define DRM_TTM_PAGE_WRITE (1 << 6)
501 * This ttm was mapped to the GPU, and so the contents may have
504 #define DRM_TTM_PAGE_USER_DIRTY (1 << 7)
506 * This flag is not used at this time; I don't know what the
509 #define DRM_TTM_PAGE_USER_DMA (1 << 8)
511 /***************************************************
512 * Buffer objects. (drm_bo.c, drm_bo_move.c)
515 struct drm_bo_mem_reg {
516 struct drm_mm_node *mm_node;
518 unsigned long num_pages;
519 uint32_t page_alignment;
522 * Current buffer status flags, indicating
523 * where the buffer is located and which
524 * access modes are in effect
528 * These are the flags proposed for
529 * a validate operation. If the
530 * validate succeeds, they'll get moved
531 * into the flags field
533 uint64_t proposed_flags;
535 uint32_t desired_tile_stride;
536 uint32_t hw_tile_stride;
541 * drm_bo_type_device are 'normal' drm allocations,
542 * pages are allocated from within the kernel automatically
543 * and the objects can be mmap'd from the drm device. Each
544 * drm_bo_type_device object has a unique name which can be
545 * used by other processes to share access to the underlying
550 * drm_bo_type_user are buffers of pages that already exist
551 * in the process address space. They are more limited than
552 * drm_bo_type_device buffers in that they must always
553 * remain cached (as we assume the user pages are mapped cached),
554 * and they are not sharable to other processes through DRM
555 * (although, regular shared memory should still work fine).
559 * drm_bo_type_kernel are buffers that exist solely for use
560 * within the kernel. The pages cannot be mapped into the
561 * process. One obvious use would be for the ring
562 * buffer where user access would not (ideally) be required.
567 struct drm_buffer_object {
568 struct drm_device *dev;
571 * If there is a possibility that the usage variable is zero,
572 * then dev->struct_mutext should be locked before incrementing it.
576 unsigned long buffer_start;
577 enum drm_bo_type type;
578 unsigned long offset;
580 struct drm_bo_mem_reg mem;
582 struct list_head lru;
583 struct list_head ddestroy;
586 uint32_t fence_class;
587 uint32_t new_fence_type;
588 uint32_t new_fence_class;
589 struct drm_fence_object *fence;
591 wait_queue_head_t event_queue;
593 unsigned long num_pages;
595 /* For pinned buffers */
596 struct drm_mm_node *pinned_node;
597 uint32_t pinned_mem_type;
598 struct list_head pinned_lru;
602 struct drm_map_list map_list;
603 uint32_t memory_type;
604 unsigned long bus_offset;
608 #ifdef DRM_ODD_MM_COMPAT
609 /* dev->struct_mutex only protected. */
610 struct list_head vma_list;
611 struct list_head p_mm_list;
616 #define _DRM_BO_FLAG_UNFENCED 0x00000001
617 #define _DRM_BO_FLAG_EVICTED 0x00000002
620 * This flag indicates that a flag called with bo->mutex held has
621 * temporarily released the buffer object mutex, (usually to wait for something).
622 * and thus any post-lock validation needs to be rerun.
625 #define _DRM_BO_FLAG_UNLOCKED 0x00000004
627 struct drm_mem_type_manager {
631 struct drm_mm manager;
632 struct list_head lru;
633 struct list_head pinned;
635 uint32_t drm_bus_maptype;
636 unsigned long gpu_offset;
637 unsigned long io_offset;
638 unsigned long io_size;
640 uint64_t size; /* size of managed area for reporting to userspace */
644 // struct drm_user_object base;
645 wait_queue_head_t queue;
646 atomic_t write_lock_pending;
650 #define _DRM_FLAG_MEMTYPE_FIXED 0x00000001 /* Fixed (on-card) PCI memory */
651 #define _DRM_FLAG_MEMTYPE_MAPPABLE 0x00000002 /* Memory mappable */
652 #define _DRM_FLAG_MEMTYPE_CACHED 0x00000004 /* Cached binding */
653 #define _DRM_FLAG_NEEDS_IOREMAP 0x00000008 /* Fixed memory needs ioremap
654 before kernel access. */
655 #define _DRM_FLAG_MEMTYPE_CMA 0x00000010 /* Can't map aperture */
656 #define _DRM_FLAG_MEMTYPE_CSELECT 0x00000020 /* Select caching */
658 struct drm_buffer_manager {
659 struct drm_bo_lock bm_lock;
660 struct mutex evict_mutex;
663 struct drm_file *last_to_validate;
664 struct drm_mem_type_manager man[DRM_BO_MEM_TYPES];
665 struct list_head unfenced;
666 struct list_head ddestroy;
667 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
668 struct work_struct wq;
670 struct delayed_work wq;
673 unsigned long cur_pages;
675 struct page *dummy_read_page;
678 struct drm_bo_driver {
679 const uint32_t *mem_type_prio;
680 const uint32_t *mem_busy_prio;
681 uint32_t num_mem_type_prio;
682 uint32_t num_mem_busy_prio;
683 struct drm_ttm_backend *(*create_ttm_backend_entry)
684 (struct drm_device *dev);
685 int (*fence_type) (struct drm_buffer_object *bo, uint32_t *fclass,
687 int (*invalidate_caches) (struct drm_device *dev, uint64_t flags);
688 int (*init_mem_type) (struct drm_device *dev, uint32_t type,
689 struct drm_mem_type_manager *man);
693 * @bo: the buffer object to be evicted
695 * Return the bo flags for a buffer which is not mapped to the hardware.
696 * These will be placed in proposed_flags so that when the move is
697 * finished, they'll end up in bo->mem.flags
699 uint64_t(*evict_flags) (struct drm_buffer_object *bo);
703 * @bo: the buffer to move
705 * @evict: whether this motion is evicting the buffer from
706 * the graphics address space
708 * @no_wait: whether this should give up and return -EBUSY
709 * if this move would require sleeping
711 * @new_mem: the new memory region receiving the buffer
713 * Move a buffer between two memory regions.
715 int (*move) (struct drm_buffer_object *bo,
716 int evict, int no_wait, struct drm_bo_mem_reg *new_mem);
720 void (*ttm_cache_flush)(struct drm_ttm *ttm);
723 * command_stream_barrier
725 * @dev: The drm device.
727 * @bo: The buffer object to validate.
729 * @new_fence_class: The new fence class for the buffer object.
731 * @new_fence_type: The new fence type for the buffer object.
733 * @no_wait: whether this should give up and return -EBUSY
734 * if this operation would require sleeping
736 * Insert a command stream barrier that makes sure that the
737 * buffer is idle once the commands associated with the
738 * current validation are starting to execute. If an error
739 * condition is returned, or the function pointer is NULL,
740 * the drm core will force buffer idle
744 int (*command_stream_barrier) (struct drm_buffer_object *bo,
745 uint32_t new_fence_class,
746 uint32_t new_fence_type,
751 * buffer objects (drm_bo.c)
753 int drm_bo_do_validate(struct drm_buffer_object *bo,
754 uint64_t flags, uint64_t mask, uint32_t hint,
755 uint32_t fence_class);
756 extern int drm_bo_set_pin(struct drm_device *dev, struct drm_buffer_object *bo, int pin);
757 extern int drm_bo_driver_finish(struct drm_device *dev);
758 extern int drm_bo_driver_init(struct drm_device *dev);
759 extern int drm_bo_pci_offset(struct drm_device *dev,
760 struct drm_bo_mem_reg *mem,
761 unsigned long *bus_base,
762 unsigned long *bus_offset,
763 unsigned long *bus_size);
764 extern int drm_mem_reg_is_pci(struct drm_device *dev, struct drm_bo_mem_reg *mem);
766 extern int drm_bo_add_user_object(struct drm_file *file_priv,
767 struct drm_buffer_object *bo, int shareable);
768 extern void drm_bo_usage_deref_locked(struct drm_buffer_object **bo);
769 extern void drm_bo_usage_deref_unlocked(struct drm_buffer_object **bo);
770 extern void drm_putback_buffer_objects(struct drm_device *dev);
771 extern int drm_fence_buffer_objects(struct drm_device *dev,
772 struct list_head *list,
773 uint32_t fence_flags,
774 struct drm_fence_object *fence,
775 struct drm_fence_object **used_fence);
776 extern void drm_bo_add_to_lru(struct drm_buffer_object *bo);
777 extern int drm_buffer_object_create(struct drm_device *dev, unsigned long size,
778 enum drm_bo_type type, uint64_t flags,
779 uint32_t hint, uint32_t page_alignment,
780 unsigned long buffer_start,
781 struct drm_buffer_object **bo);
782 extern int drm_bo_wait(struct drm_buffer_object *bo, int lazy, int interruptible,
783 int no_wait, int check_unfenced);
784 extern int drm_bo_mem_space(struct drm_buffer_object *bo,
785 struct drm_bo_mem_reg *mem, int no_wait);
786 extern int drm_bo_move_buffer(struct drm_buffer_object *bo,
787 uint64_t new_mem_flags,
788 int no_wait, int move_unfenced);
789 extern int drm_bo_clean_mm(struct drm_device *dev, unsigned mem_type, int kern_clean);
790 extern int drm_bo_init_mm(struct drm_device *dev, unsigned type,
791 unsigned long p_offset, unsigned long p_size,
793 extern struct drm_buffer_object *drm_lookup_buffer_object(struct drm_file *file_priv,
796 extern int drm_bo_evict_cached(struct drm_buffer_object *bo);
798 extern void drm_bo_takedown_vm_locked(struct drm_buffer_object *bo);
799 extern void drm_bo_evict_mm(struct drm_device *dev, int mem_type, int no_wait);
801 * Buffer object memory move- and map helpers.
805 extern int drm_bo_add_ttm(struct drm_buffer_object *bo);
806 extern int drm_bo_move_ttm(struct drm_buffer_object *bo,
807 int evict, int no_wait,
808 struct drm_bo_mem_reg *new_mem);
809 extern int drm_bo_move_memcpy(struct drm_buffer_object *bo,
811 int no_wait, struct drm_bo_mem_reg *new_mem);
812 extern int drm_bo_move_zero(struct drm_buffer_object *bo,
813 int evict, int no_wait, struct drm_bo_mem_reg *new_mem);
814 extern int drm_bo_move_accel_cleanup(struct drm_buffer_object *bo,
815 int evict, int no_wait,
816 uint32_t fence_class, uint32_t fence_type,
817 uint32_t fence_flags,
818 struct drm_bo_mem_reg *new_mem);
819 extern int drm_bo_same_page(unsigned long offset, unsigned long offset2);
820 extern unsigned long drm_bo_offset_end(unsigned long offset,
823 struct drm_bo_kmap_obj {
834 static inline void *drm_bmo_virtual(struct drm_bo_kmap_obj *map, int *is_iomem)
836 *is_iomem = (map->bo_kmap_type == bo_map_iomap ||
837 map->bo_kmap_type == bo_map_premapped);
840 extern void drm_bo_kunmap(struct drm_bo_kmap_obj *map);
841 extern int drm_bo_kmap(struct drm_buffer_object *bo, unsigned long start_page,
842 unsigned long num_pages, struct drm_bo_kmap_obj *map);
843 extern int drm_bo_pfn_prot(struct drm_buffer_object *bo,
844 unsigned long dst_offset,
854 struct list_head head;
855 struct drm_fence_object *fence;
857 uint32_t new_fence_type;
860 struct drm_reg_manager {
861 struct list_head free;
862 struct list_head lru;
863 struct list_head unfenced;
865 int (*reg_reusable)(const struct drm_reg *reg, const void *data);
866 void (*reg_destroy)(struct drm_reg *reg);
869 extern int drm_regs_alloc(struct drm_reg_manager *manager,
871 uint32_t fence_class,
875 struct drm_reg **reg);
877 extern void drm_regs_fence(struct drm_reg_manager *regs,
878 struct drm_fence_object *fence);
880 extern void drm_regs_free(struct drm_reg_manager *manager);
881 extern void drm_regs_add(struct drm_reg_manager *manager, struct drm_reg *reg);
882 extern void drm_regs_init(struct drm_reg_manager *manager,
883 int (*reg_reusable)(const struct drm_reg *,
885 void (*reg_destroy)(struct drm_reg *));
887 extern int drm_mem_reg_ioremap(struct drm_device *dev, struct drm_bo_mem_reg * mem,
889 extern void drm_mem_reg_iounmap(struct drm_device *dev, struct drm_bo_mem_reg * mem,
891 #ifdef CONFIG_DEBUG_MUTEXES
892 #define DRM_ASSERT_LOCKED(_mutex) \
893 BUG_ON(!mutex_is_locked(_mutex) || \
894 ((_mutex)->owner != current_thread_info()))
896 #define DRM_ASSERT_LOCKED(_mutex)