95543bb2086a4f829f45fffdec187de618edd34c
[mesa.git] / src / gallium / drivers / radeon / radeon_winsys.h
1 /*
2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 * Copyright 2010 Marek Olšák <maraeo@gmail.com>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
23
24 #ifndef RADEON_WINSYS_H
25 #define RADEON_WINSYS_H
26
27 /* The public winsys interface header for the radeon driver. */
28
29 #include "pipebuffer/pb_buffer.h"
30
31 #include "amd/common/ac_gpu_info.h"
32 #include "amd/common/ac_surface.h"
33
34 #define RADEON_FLUSH_ASYNC (1 << 0)
35 #define RADEON_FLUSH_END_OF_FRAME (1 << 1)
36
37 /* Tiling flags. */
38 enum radeon_bo_layout {
39 RADEON_LAYOUT_LINEAR = 0,
40 RADEON_LAYOUT_TILED,
41 RADEON_LAYOUT_SQUARETILED,
42
43 RADEON_LAYOUT_UNKNOWN
44 };
45
46 enum radeon_bo_domain { /* bitfield */
47 RADEON_DOMAIN_GTT = 2,
48 RADEON_DOMAIN_VRAM = 4,
49 RADEON_DOMAIN_VRAM_GTT = RADEON_DOMAIN_VRAM | RADEON_DOMAIN_GTT
50 };
51
52 enum radeon_bo_flag { /* bitfield */
53 RADEON_FLAG_GTT_WC = (1 << 0),
54 RADEON_FLAG_NO_CPU_ACCESS = (1 << 1),
55 RADEON_FLAG_NO_SUBALLOC = (1 << 2),
56 RADEON_FLAG_SPARSE = (1 << 3),
57 };
58
59 enum radeon_bo_usage { /* bitfield */
60 RADEON_USAGE_READ = 2,
61 RADEON_USAGE_WRITE = 4,
62 RADEON_USAGE_READWRITE = RADEON_USAGE_READ | RADEON_USAGE_WRITE,
63
64 /* The winsys ensures that the CS submission will be scheduled after
65 * previously flushed CSs referencing this BO in a conflicting way.
66 */
67 RADEON_USAGE_SYNCHRONIZED = 8
68 };
69
70 #define RADEON_SPARSE_PAGE_SIZE (64 * 1024)
71
72 enum ring_type {
73 RING_GFX = 0,
74 RING_COMPUTE,
75 RING_DMA,
76 RING_UVD,
77 RING_VCE,
78 RING_UVD_ENC,
79 RING_VCN_DEC,
80 RING_LAST,
81 };
82
83 enum radeon_value_id {
84 RADEON_REQUESTED_VRAM_MEMORY,
85 RADEON_REQUESTED_GTT_MEMORY,
86 RADEON_MAPPED_VRAM,
87 RADEON_MAPPED_GTT,
88 RADEON_BUFFER_WAIT_TIME_NS,
89 RADEON_NUM_MAPPED_BUFFERS,
90 RADEON_TIMESTAMP,
91 RADEON_NUM_GFX_IBS,
92 RADEON_NUM_SDMA_IBS,
93 RADEON_GFX_BO_LIST_COUNTER, /* number of BOs submitted in gfx IBs */
94 RADEON_NUM_BYTES_MOVED,
95 RADEON_NUM_EVICTIONS,
96 RADEON_NUM_VRAM_CPU_PAGE_FAULTS,
97 RADEON_VRAM_USAGE,
98 RADEON_VRAM_VIS_USAGE,
99 RADEON_GTT_USAGE,
100 RADEON_GPU_TEMPERATURE, /* DRM 2.42.0 */
101 RADEON_CURRENT_SCLK,
102 RADEON_CURRENT_MCLK,
103 RADEON_GPU_RESET_COUNTER, /* DRM 2.43.0 */
104 RADEON_CS_THREAD_TIME,
105 };
106
107 /* Each group of four has the same priority. */
108 enum radeon_bo_priority {
109 RADEON_PRIO_FENCE = 0,
110 RADEON_PRIO_TRACE,
111 RADEON_PRIO_SO_FILLED_SIZE,
112 RADEON_PRIO_QUERY,
113
114 RADEON_PRIO_IB1 = 4, /* main IB submitted to the kernel */
115 RADEON_PRIO_IB2, /* IB executed with INDIRECT_BUFFER */
116 RADEON_PRIO_DRAW_INDIRECT,
117 RADEON_PRIO_INDEX_BUFFER,
118
119 RADEON_PRIO_VCE = 8,
120 RADEON_PRIO_UVD,
121 RADEON_PRIO_SDMA_BUFFER,
122 RADEON_PRIO_SDMA_TEXTURE,
123
124 RADEON_PRIO_CP_DMA = 12,
125
126 RADEON_PRIO_CONST_BUFFER = 16,
127 RADEON_PRIO_DESCRIPTORS,
128 RADEON_PRIO_BORDER_COLORS,
129
130 RADEON_PRIO_SAMPLER_BUFFER = 20,
131 RADEON_PRIO_VERTEX_BUFFER,
132
133 RADEON_PRIO_SHADER_RW_BUFFER = 24,
134 RADEON_PRIO_COMPUTE_GLOBAL,
135
136 RADEON_PRIO_SAMPLER_TEXTURE = 28,
137 RADEON_PRIO_SHADER_RW_IMAGE,
138
139 RADEON_PRIO_SAMPLER_TEXTURE_MSAA = 32,
140
141 RADEON_PRIO_COLOR_BUFFER = 36,
142
143 RADEON_PRIO_DEPTH_BUFFER = 40,
144
145 RADEON_PRIO_COLOR_BUFFER_MSAA = 44,
146
147 RADEON_PRIO_DEPTH_BUFFER_MSAA = 48,
148
149 RADEON_PRIO_CMASK = 52,
150 RADEON_PRIO_DCC,
151 RADEON_PRIO_HTILE,
152 RADEON_PRIO_SHADER_BINARY, /* the hw can't hide instruction cache misses */
153
154 RADEON_PRIO_SHADER_RINGS = 56,
155
156 RADEON_PRIO_SCRATCH_BUFFER = 60,
157 /* 63 is the maximum value */
158 };
159
160 struct winsys_handle;
161 struct radeon_winsys_ctx;
162
163 struct radeon_winsys_cs_chunk {
164 unsigned cdw; /* Number of used dwords. */
165 unsigned max_dw; /* Maximum number of dwords. */
166 uint32_t *buf; /* The base pointer of the chunk. */
167 };
168
169 struct radeon_winsys_cs {
170 struct radeon_winsys_cs_chunk current;
171 struct radeon_winsys_cs_chunk *prev;
172 unsigned num_prev; /* Number of previous chunks. */
173 unsigned max_prev; /* Space in array pointed to by prev. */
174 unsigned prev_dw; /* Total number of dwords in previous chunks. */
175
176 /* Memory usage of the buffer list. These are always 0 for CE and preamble
177 * IBs. */
178 uint64_t used_vram;
179 uint64_t used_gart;
180 };
181
182 /* Tiling info for display code, DRI sharing, and other data. */
183 struct radeon_bo_metadata {
184 /* Tiling flags describing the texture layout for display code
185 * and DRI sharing.
186 */
187 union {
188 struct {
189 enum radeon_bo_layout microtile;
190 enum radeon_bo_layout macrotile;
191 unsigned pipe_config;
192 unsigned bankw;
193 unsigned bankh;
194 unsigned tile_split;
195 unsigned mtilea;
196 unsigned num_banks;
197 unsigned stride;
198 bool scanout;
199 } legacy;
200
201 struct {
202 /* surface flags */
203 unsigned swizzle_mode:5;
204 } gfx9;
205 } u;
206
207 /* Additional metadata associated with the buffer, in bytes.
208 * The maximum size is 64 * 4. This is opaque for the winsys & kernel.
209 * Supported by amdgpu only.
210 */
211 uint32_t size_metadata;
212 uint32_t metadata[64];
213 };
214
215 enum radeon_feature_id {
216 RADEON_FID_R300_HYPERZ_ACCESS, /* ZMask + HiZ */
217 RADEON_FID_R300_CMASK_ACCESS,
218 };
219
220 struct radeon_bo_list_item {
221 uint64_t bo_size;
222 uint64_t vm_address;
223 uint64_t priority_usage; /* mask of (1 << RADEON_PRIO_*) */
224 };
225
226 struct radeon_winsys {
227 /**
228 * The screen object this winsys was created for
229 */
230 struct pipe_screen *screen;
231
232 /**
233 * Decrement the winsys reference count.
234 *
235 * \param ws The winsys this function is called for.
236 * \return True if the winsys and screen should be destroyed.
237 */
238 bool (*unref)(struct radeon_winsys *ws);
239
240 /**
241 * Destroy this winsys.
242 *
243 * \param ws The winsys this function is called from.
244 */
245 void (*destroy)(struct radeon_winsys *ws);
246
247 /**
248 * Query an info structure from winsys.
249 *
250 * \param ws The winsys this function is called from.
251 * \param info Return structure
252 */
253 void (*query_info)(struct radeon_winsys *ws,
254 struct radeon_info *info);
255
256 /**************************************************************************
257 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
258 *
259 * Remember that gallium gets to choose the interface it needs, and the
260 * window systems must then implement that interface (rather than the
261 * other way around...).
262 *************************************************************************/
263
264 /**
265 * Create a buffer object.
266 *
267 * \param ws The winsys this function is called from.
268 * \param size The size to allocate.
269 * \param alignment An alignment of the buffer in memory.
270 * \param use_reusable_pool Whether the cache buffer manager should be used.
271 * \param domain A bitmask of the RADEON_DOMAIN_* flags.
272 * \return The created buffer object.
273 */
274 struct pb_buffer *(*buffer_create)(struct radeon_winsys *ws,
275 uint64_t size,
276 unsigned alignment,
277 enum radeon_bo_domain domain,
278 enum radeon_bo_flag flags);
279
280 /**
281 * Map the entire data store of a buffer object into the client's address
282 * space.
283 *
284 * \param buf A winsys buffer object to map.
285 * \param cs A command stream to flush if the buffer is referenced by it.
286 * \param usage A bitmask of the PIPE_TRANSFER_* flags.
287 * \return The pointer at the beginning of the buffer.
288 */
289 void *(*buffer_map)(struct pb_buffer *buf,
290 struct radeon_winsys_cs *cs,
291 enum pipe_transfer_usage usage);
292
293 /**
294 * Unmap a buffer object from the client's address space.
295 *
296 * \param buf A winsys buffer object to unmap.
297 */
298 void (*buffer_unmap)(struct pb_buffer *buf);
299
300 /**
301 * Wait for the buffer and return true if the buffer is not used
302 * by the device.
303 *
304 * The timeout of 0 will only return the status.
305 * The timeout of PIPE_TIMEOUT_INFINITE will always wait until the buffer
306 * is idle.
307 */
308 bool (*buffer_wait)(struct pb_buffer *buf, uint64_t timeout,
309 enum radeon_bo_usage usage);
310
311 /**
312 * Return buffer metadata.
313 * (tiling info for display code, DRI sharing, and other data)
314 *
315 * \param buf A winsys buffer object to get the flags from.
316 * \param md Metadata
317 */
318 void (*buffer_get_metadata)(struct pb_buffer *buf,
319 struct radeon_bo_metadata *md);
320
321 /**
322 * Set buffer metadata.
323 * (tiling info for display code, DRI sharing, and other data)
324 *
325 * \param buf A winsys buffer object to set the flags for.
326 * \param md Metadata
327 */
328 void (*buffer_set_metadata)(struct pb_buffer *buf,
329 struct radeon_bo_metadata *md);
330
331 /**
332 * Get a winsys buffer from a winsys handle. The internal structure
333 * of the handle is platform-specific and only a winsys should access it.
334 *
335 * \param ws The winsys this function is called from.
336 * \param whandle A winsys handle pointer as was received from a state
337 * tracker.
338 * \param stride The returned buffer stride in bytes.
339 */
340 struct pb_buffer *(*buffer_from_handle)(struct radeon_winsys *ws,
341 struct winsys_handle *whandle,
342 unsigned *stride, unsigned *offset);
343
344 /**
345 * Get a winsys buffer from a user pointer. The resulting buffer can't
346 * be exported. Both pointer and size must be page aligned.
347 *
348 * \param ws The winsys this function is called from.
349 * \param pointer User pointer to turn into a buffer object.
350 * \param Size Size in bytes for the new buffer.
351 */
352 struct pb_buffer *(*buffer_from_ptr)(struct radeon_winsys *ws,
353 void *pointer, uint64_t size);
354
355 /**
356 * Whether the buffer was created from a user pointer.
357 *
358 * \param buf A winsys buffer object
359 * \return whether \p buf was created via buffer_from_ptr
360 */
361 bool (*buffer_is_user_ptr)(struct pb_buffer *buf);
362
363 /**
364 * Get a winsys handle from a winsys buffer. The internal structure
365 * of the handle is platform-specific and only a winsys should access it.
366 *
367 * \param buf A winsys buffer object to get the handle from.
368 * \param whandle A winsys handle pointer.
369 * \param stride A stride of the buffer in bytes, for texturing.
370 * \return true on success.
371 */
372 bool (*buffer_get_handle)(struct pb_buffer *buf,
373 unsigned stride, unsigned offset,
374 unsigned slice_size,
375 struct winsys_handle *whandle);
376
377 /**
378 * Change the commitment of a (64KB-page aligned) region of the given
379 * sparse buffer.
380 *
381 * \warning There is no automatic synchronization with command submission.
382 *
383 * \note Only implemented by the amdgpu winsys.
384 *
385 * \return false on out of memory or other failure, true on success.
386 */
387 bool (*buffer_commit)(struct pb_buffer *buf,
388 uint64_t offset, uint64_t size,
389 bool commit);
390
391 /**
392 * Return the virtual address of a buffer.
393 *
394 * When virtual memory is not in use, this is the offset relative to the
395 * relocation base (non-zero for sub-allocated buffers).
396 *
397 * \param buf A winsys buffer object
398 * \return virtual address
399 */
400 uint64_t (*buffer_get_virtual_address)(struct pb_buffer *buf);
401
402 /**
403 * Return the offset of this buffer relative to the relocation base.
404 * This is only non-zero for sub-allocated buffers.
405 *
406 * This is only supported in the radeon winsys, since amdgpu uses virtual
407 * addresses in submissions even for the video engines.
408 *
409 * \param buf A winsys buffer object
410 * \return the offset for relocations
411 */
412 unsigned (*buffer_get_reloc_offset)(struct pb_buffer *buf);
413
414 /**
415 * Query the initial placement of the buffer from the kernel driver.
416 */
417 enum radeon_bo_domain (*buffer_get_initial_domain)(struct pb_buffer *buf);
418
419 /**************************************************************************
420 * Command submission.
421 *
422 * Each pipe context should create its own command stream and submit
423 * commands independently of other contexts.
424 *************************************************************************/
425
426 /**
427 * Create a command submission context.
428 * Various command streams can be submitted to the same context.
429 */
430 struct radeon_winsys_ctx *(*ctx_create)(struct radeon_winsys *ws);
431
432 /**
433 * Destroy a context.
434 */
435 void (*ctx_destroy)(struct radeon_winsys_ctx *ctx);
436
437 /**
438 * Query a GPU reset status.
439 */
440 enum pipe_reset_status (*ctx_query_reset_status)(struct radeon_winsys_ctx *ctx);
441
442 /**
443 * Create a command stream.
444 *
445 * \param ctx The submission context
446 * \param ring_type The ring type (GFX, DMA, UVD)
447 * \param flush Flush callback function associated with the command stream.
448 * \param user User pointer that will be passed to the flush callback.
449 */
450 struct radeon_winsys_cs *(*cs_create)(struct radeon_winsys_ctx *ctx,
451 enum ring_type ring_type,
452 void (*flush)(void *ctx, unsigned flags,
453 struct pipe_fence_handle **fence),
454 void *flush_ctx);
455
456 /**
457 * Add a constant engine IB to a graphics CS. This makes the graphics CS
458 * from "cs_create" a group of two IBs that share a buffer list and are
459 * flushed together.
460 *
461 * The returned constant CS is only a stream for writing packets to the new
462 * IB. Calling other winsys functions with it is not allowed, not even
463 * "cs_destroy".
464 *
465 * In order to add buffers and check memory usage, use the graphics CS.
466 * In order to flush it, use the graphics CS, which will flush both IBs.
467 * Destroying the graphics CS will destroy both of them.
468 *
469 * \param cs The graphics CS from "cs_create" that will hold the buffer
470 * list and will be used for flushing.
471 */
472 struct radeon_winsys_cs *(*cs_add_const_ib)(struct radeon_winsys_cs *cs);
473
474 /**
475 * Add a constant engine preamble IB to a graphics CS. This add an extra IB
476 * in similar manner to cs_add_const_ib. This should always be called after
477 * cs_add_const_ib.
478 *
479 * The returned IB is a constant engine IB that only gets flushed if the
480 * context changed.
481 *
482 * \param cs The graphics CS from "cs_create" that will hold the buffer
483 * list and will be used for flushing.
484 */
485 struct radeon_winsys_cs *(*cs_add_const_preamble_ib)(struct radeon_winsys_cs *cs);
486 /**
487 * Destroy a command stream.
488 *
489 * \param cs A command stream to destroy.
490 */
491 void (*cs_destroy)(struct radeon_winsys_cs *cs);
492
493 /**
494 * Add a buffer. Each buffer used by a CS must be added using this function.
495 *
496 * \param cs Command stream
497 * \param buf Buffer
498 * \param usage Whether the buffer is used for read and/or write.
499 * \param domain Bitmask of the RADEON_DOMAIN_* flags.
500 * \param priority A higher number means a greater chance of being
501 * placed in the requested domain. 15 is the maximum.
502 * \return Buffer index.
503 */
504 unsigned (*cs_add_buffer)(struct radeon_winsys_cs *cs,
505 struct pb_buffer *buf,
506 enum radeon_bo_usage usage,
507 enum radeon_bo_domain domain,
508 enum radeon_bo_priority priority);
509
510 /**
511 * Return the index of an already-added buffer.
512 *
513 * Not supported on amdgpu. Drivers with GPUVM should not care about
514 * buffer indices.
515 *
516 * \param cs Command stream
517 * \param buf Buffer
518 * \return The buffer index, or -1 if the buffer has not been added.
519 */
520 int (*cs_lookup_buffer)(struct radeon_winsys_cs *cs,
521 struct pb_buffer *buf);
522
523 /**
524 * Return true if there is enough memory in VRAM and GTT for the buffers
525 * added so far. If the validation fails, all buffers which have
526 * been added since the last call of cs_validate will be removed and
527 * the CS will be flushed (provided there are still any buffers).
528 *
529 * \param cs A command stream to validate.
530 */
531 bool (*cs_validate)(struct radeon_winsys_cs *cs);
532
533 /**
534 * Check whether the given number of dwords is available in the IB.
535 * Optionally chain a new chunk of the IB if necessary and supported.
536 *
537 * \param cs A command stream.
538 * \param dw Number of CS dwords requested by the caller.
539 */
540 bool (*cs_check_space)(struct radeon_winsys_cs *cs, unsigned dw);
541
542 /**
543 * Return the buffer list.
544 *
545 * This is the buffer list as passed to the kernel, i.e. it only contains
546 * the parent buffers of sub-allocated buffers.
547 *
548 * \param cs Command stream
549 * \param list Returned buffer list. Set to NULL to query the count only.
550 * \return The buffer count.
551 */
552 unsigned (*cs_get_buffer_list)(struct radeon_winsys_cs *cs,
553 struct radeon_bo_list_item *list);
554
555 /**
556 * Flush a command stream.
557 *
558 * \param cs A command stream to flush.
559 * \param flags, RADEON_FLUSH_ASYNC or 0.
560 * \param fence Pointer to a fence. If non-NULL, a fence is inserted
561 * after the CS and is returned through this parameter.
562 * \return Negative POSIX error code or 0 for success.
563 * Asynchronous submissions never return an error.
564 */
565 int (*cs_flush)(struct radeon_winsys_cs *cs,
566 unsigned flags,
567 struct pipe_fence_handle **fence);
568
569 /**
570 * Create a fence before the CS is flushed.
571 * The user must flush manually to complete the initializaton of the fence.
572 * The fence must not be used before the flush.
573 */
574 struct pipe_fence_handle *(*cs_get_next_fence)(struct radeon_winsys_cs *cs);
575
576 /**
577 * Return true if a buffer is referenced by a command stream.
578 *
579 * \param cs A command stream.
580 * \param buf A winsys buffer.
581 */
582 bool (*cs_is_buffer_referenced)(struct radeon_winsys_cs *cs,
583 struct pb_buffer *buf,
584 enum radeon_bo_usage usage);
585
586 /**
587 * Request access to a feature for a command stream.
588 *
589 * \param cs A command stream.
590 * \param fid Feature ID, one of RADEON_FID_*
591 * \param enable Whether to enable or disable the feature.
592 */
593 bool (*cs_request_feature)(struct radeon_winsys_cs *cs,
594 enum radeon_feature_id fid,
595 bool enable);
596 /**
597 * Make sure all asynchronous flush of the cs have completed
598 *
599 * \param cs A command stream.
600 */
601 void (*cs_sync_flush)(struct radeon_winsys_cs *cs);
602
603 /**
604 * Wait for the fence and return true if the fence has been signalled.
605 * The timeout of 0 will only return the status.
606 * The timeout of PIPE_TIMEOUT_INFINITE will always wait until the fence
607 * is signalled.
608 */
609 bool (*fence_wait)(struct radeon_winsys *ws,
610 struct pipe_fence_handle *fence,
611 uint64_t timeout);
612
613 /**
614 * Reference counting for fences.
615 */
616 void (*fence_reference)(struct pipe_fence_handle **dst,
617 struct pipe_fence_handle *src);
618
619 /**
620 * Initialize surface
621 *
622 * \param ws The winsys this function is called from.
623 * \param tex Input texture description
624 * \param flags Bitmask of RADEON_SURF_* flags
625 * \param bpe Bytes per pixel, it can be different for Z buffers.
626 * \param mode Preferred tile mode. (linear, 1D, or 2D)
627 * \param surf Output structure
628 */
629 int (*surface_init)(struct radeon_winsys *ws,
630 const struct pipe_resource *tex,
631 unsigned flags, unsigned bpe,
632 enum radeon_surf_mode mode,
633 struct radeon_surf *surf);
634
635 uint64_t (*query_value)(struct radeon_winsys *ws,
636 enum radeon_value_id value);
637
638 bool (*read_registers)(struct radeon_winsys *ws, unsigned reg_offset,
639 unsigned num_registers, uint32_t *out);
640
641 const char* (*get_chip_name)(struct radeon_winsys *ws);
642 };
643
644 static inline bool radeon_emitted(struct radeon_winsys_cs *cs, unsigned num_dw)
645 {
646 return cs && (cs->prev_dw + cs->current.cdw > num_dw);
647 }
648
649 static inline void radeon_emit(struct radeon_winsys_cs *cs, uint32_t value)
650 {
651 cs->current.buf[cs->current.cdw++] = value;
652 }
653
654 static inline void radeon_emit_array(struct radeon_winsys_cs *cs,
655 const uint32_t *values, unsigned count)
656 {
657 memcpy(cs->current.buf + cs->current.cdw, values, count * 4);
658 cs->current.cdw += count;
659 }
660
661 enum radeon_heap {
662 RADEON_HEAP_VRAM,
663 RADEON_HEAP_VRAM_GTT, /* combined heaps */
664 RADEON_HEAP_GTT_WC,
665 RADEON_HEAP_GTT,
666 RADEON_MAX_SLAB_HEAPS,
667 };
668
669 static inline enum radeon_bo_domain radeon_domain_from_heap(enum radeon_heap heap)
670 {
671 switch (heap) {
672 case RADEON_HEAP_VRAM:
673 return RADEON_DOMAIN_VRAM;
674 case RADEON_HEAP_VRAM_GTT:
675 return RADEON_DOMAIN_VRAM_GTT;
676 case RADEON_HEAP_GTT_WC:
677 case RADEON_HEAP_GTT:
678 return RADEON_DOMAIN_GTT;
679 default:
680 assert(0);
681 return 0;
682 }
683 }
684
685 static inline unsigned radeon_flags_from_heap(enum radeon_heap heap)
686 {
687 switch (heap) {
688 case RADEON_HEAP_VRAM:
689 case RADEON_HEAP_VRAM_GTT:
690 case RADEON_HEAP_GTT_WC:
691 return RADEON_FLAG_GTT_WC;
692 case RADEON_HEAP_GTT:
693 default:
694 return 0;
695 }
696 }
697
698 /* Return the heap index for winsys allocators, or -1 on failure. */
699 static inline int radeon_get_heap_index(enum radeon_bo_domain domain,
700 enum radeon_bo_flag flags)
701 {
702 /* VRAM implies WC (write combining) */
703 assert(!(domain & RADEON_DOMAIN_VRAM) || flags & RADEON_FLAG_GTT_WC);
704
705 /* Unsupported flags: NO_CPU_ACCESS, NO_SUBALLOC, SPARSE. */
706 if (flags & ~RADEON_FLAG_GTT_WC)
707 return -1;
708
709 switch (domain) {
710 case RADEON_DOMAIN_VRAM:
711 return RADEON_HEAP_VRAM;
712 case RADEON_DOMAIN_VRAM_GTT:
713 return RADEON_HEAP_VRAM_GTT;
714 case RADEON_DOMAIN_GTT:
715 if (flags & RADEON_FLAG_GTT_WC)
716 return RADEON_HEAP_GTT_WC;
717 else
718 return RADEON_HEAP_GTT;
719 }
720 return -1;
721 }
722
723 #endif