1/* 2 * Copyright © 2011 Marek Olšák <maraeo@gmail.com> 3 * All Rights Reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining 6 * a copy of this software and associated documentation files (the 7 * "Software"), to deal in the Software without restriction, including 8 * without limitation the rights to use, copy, modify, merge, publish, 9 * distribute, sub license, and/or sell copies of the Software, and to 10 * permit persons to whom the Software is furnished to do so, subject to 11 * the following conditions: 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 14 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 15 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 16 * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS 17 * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 * USE OR OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * The above copyright notice and this permission notice (including the 23 * next paragraph) shall be included in all copies or substantial portions 24 * of the Software. 25 */ 26 27#ifndef RADEON_DRM_CS_H 28#define RADEON_DRM_CS_H 29 30#include "radeon_drm_bo.h" 31 32struct radeon_ctx { 33 struct radeon_drm_winsys *ws; 34 uint32_t gpu_reset_counter; 35}; 36 37struct radeon_bo_item { 38 struct radeon_bo *bo; 39 union { 40 struct { 41 uint32_t priority_usage; 42 } real; 43 struct { 44 unsigned real_idx; 45 } slab; 46 } u; 47}; 48 49struct radeon_cs_context { 50 uint32_t buf[16 * 1024]; 51 52 int fd; 53 struct drm_radeon_cs cs; 54 struct drm_radeon_cs_chunk chunks[3]; 55 uint64_t chunk_array[3]; 56 uint32_t flags[2]; 57 58 /* Buffers. */ 59 unsigned max_relocs; 60 unsigned num_relocs; 61 unsigned num_validated_relocs; 62 struct radeon_bo_item *relocs_bo; 63 struct drm_radeon_cs_reloc *relocs; 64 65 unsigned num_slab_buffers; 66 unsigned max_slab_buffers; 67 struct radeon_bo_item *slab_buffers; 68 69 int reloc_indices_hashlist[4096]; 70}; 71 72struct radeon_drm_cs { 73 enum ring_type ring_type; 74 75 /* We flip between these two CS. While one is being consumed 76 * by the kernel in another thread, the other one is being filled 77 * by the pipe driver. */ 78 struct radeon_cs_context csc1; 79 struct radeon_cs_context csc2; 80 /* The currently-used CS. */ 81 struct radeon_cs_context *csc; 82 /* The CS being currently-owned by the other thread. */ 83 struct radeon_cs_context *cst; 84 85 /* The winsys. */ 86 struct radeon_drm_winsys *ws; 87 88 /* Flush CS. */ 89 void (*flush_cs)(void *ctx, unsigned flags, struct pipe_fence_handle **fence); 90 void *flush_data; 91 92 struct util_queue_fence flush_completed; 93 struct pipe_fence_handle *next_fence; 94}; 95 96int radeon_lookup_buffer(struct radeon_cs_context *csc, struct radeon_bo *bo); 97 98static inline struct radeon_drm_cs * 99radeon_drm_cs(struct radeon_cmdbuf *rcs) 100{ 101 return (struct radeon_drm_cs*)rcs->priv; 102} 103 104static inline bool 105radeon_bo_is_referenced_by_cs(struct radeon_drm_cs *cs, 106 struct radeon_bo *bo) 107{ 108 int num_refs = bo->num_cs_references; 109 return num_refs == bo->rws->num_cs || 110 (num_refs && radeon_lookup_buffer(cs->csc, bo) != -1); 111} 112 113static inline bool 114radeon_bo_is_referenced_by_cs_for_write(struct radeon_drm_cs *cs, 115 struct radeon_bo *bo) 116{ 117 int index; 118 119 if (!bo->num_cs_references) 120 return false; 121 122 index = radeon_lookup_buffer(cs->csc, bo); 123 if (index == -1) 124 return false; 125 126 if (!bo->handle) 127 index = cs->csc->slab_buffers[index].u.slab.real_idx; 128 129 return cs->csc->relocs[index].write_domain != 0; 130} 131 132static inline bool 133radeon_bo_is_referenced_by_any_cs(struct radeon_bo *bo) 134{ 135 return bo->num_cs_references != 0; 136} 137 138void radeon_drm_cs_sync_flush(struct radeon_cmdbuf *rcs); 139void radeon_drm_cs_init_functions(struct radeon_drm_winsys *ws); 140void radeon_drm_cs_emit_ioctl_oneshot(void *job, void *gdata, int thread_index); 141 142#endif 143