1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org> 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21bf215546Sopenharmony_ci * SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci * Authors: 24bf215546Sopenharmony_ci * Rob Clark <robclark@freedesktop.org> 25bf215546Sopenharmony_ci */ 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#ifndef FREEDRENO_SCREEN_H_ 28bf215546Sopenharmony_ci#define FREEDRENO_SCREEN_H_ 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include "common/freedreno_dev_info.h" 31bf215546Sopenharmony_ci#include "drm/freedreno_drmif.h" 32bf215546Sopenharmony_ci#include "drm/freedreno_ringbuffer.h" 33bf215546Sopenharmony_ci#include "perfcntrs/freedreno_perfcntr.h" 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ci#include "pipe/p_screen.h" 36bf215546Sopenharmony_ci#include "renderonly/renderonly.h" 37bf215546Sopenharmony_ci#include "util/debug.h" 38bf215546Sopenharmony_ci#include "util/simple_mtx.h" 39bf215546Sopenharmony_ci#include "util/slab.h" 40bf215546Sopenharmony_ci#include "util/u_idalloc.h" 41bf215546Sopenharmony_ci#include "util/u_memory.h" 42bf215546Sopenharmony_ci#include "util/u_queue.h" 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_ci#include "freedreno_batch_cache.h" 45bf215546Sopenharmony_ci#include "freedreno_gmem.h" 46bf215546Sopenharmony_ci#include "freedreno_util.h" 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_cistruct fd_bo; 49bf215546Sopenharmony_ci 50bf215546Sopenharmony_ci/* Potential reasons for needing to skip bypass path and use GMEM, the 51bf215546Sopenharmony_ci * generation backend can override this with screen->gmem_reason_mask 52bf215546Sopenharmony_ci */ 53bf215546Sopenharmony_cienum fd_gmem_reason { 54bf215546Sopenharmony_ci FD_GMEM_CLEARS_DEPTH_STENCIL = BIT(0), 55bf215546Sopenharmony_ci FD_GMEM_DEPTH_ENABLED = BIT(1), 56bf215546Sopenharmony_ci FD_GMEM_STENCIL_ENABLED = BIT(2), 57bf215546Sopenharmony_ci FD_GMEM_BLEND_ENABLED = BIT(3), 58bf215546Sopenharmony_ci FD_GMEM_LOGICOP_ENABLED = BIT(4), 59bf215546Sopenharmony_ci FD_GMEM_FB_READ = BIT(5), 60bf215546Sopenharmony_ci}; 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_cistruct fd_screen { 63bf215546Sopenharmony_ci struct pipe_screen base; 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_ci struct list_head context_list; 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci simple_mtx_t lock; 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_ci /* it would be tempting to use pipe_reference here, but that 70bf215546Sopenharmony_ci * really doesn't work well if it isn't the first member of 71bf215546Sopenharmony_ci * the struct, so not quite so awesome to be adding refcnting 72bf215546Sopenharmony_ci * further down the inheritance hierarchy: 73bf215546Sopenharmony_ci */ 74bf215546Sopenharmony_ci int refcnt; 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_ci /* place for winsys to stash it's own stuff: */ 77bf215546Sopenharmony_ci void *winsys_priv; 78bf215546Sopenharmony_ci 79bf215546Sopenharmony_ci struct slab_parent_pool transfer_pool; 80bf215546Sopenharmony_ci 81bf215546Sopenharmony_ci uint64_t gmem_base; 82bf215546Sopenharmony_ci uint32_t gmemsize_bytes; 83bf215546Sopenharmony_ci 84bf215546Sopenharmony_ci const struct fd_dev_id *dev_id; 85bf215546Sopenharmony_ci uint8_t gen; /* GPU (major) generation */ 86bf215546Sopenharmony_ci uint32_t gpu_id; /* 220, 305, etc */ 87bf215546Sopenharmony_ci uint64_t chip_id; /* coreid:8 majorrev:8 minorrev:8 patch:8 */ 88bf215546Sopenharmony_ci uint32_t max_freq; 89bf215546Sopenharmony_ci uint32_t ram_size; 90bf215546Sopenharmony_ci uint32_t max_rts; /* max # of render targets */ 91bf215546Sopenharmony_ci uint32_t priority_mask; 92bf215546Sopenharmony_ci bool has_timestamp; 93bf215546Sopenharmony_ci bool has_robustness; 94bf215546Sopenharmony_ci bool has_syncobj; 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ci const struct fd_dev_info *info; 97bf215546Sopenharmony_ci uint32_t ccu_offset_gmem; 98bf215546Sopenharmony_ci uint32_t ccu_offset_bypass; 99bf215546Sopenharmony_ci 100bf215546Sopenharmony_ci /* Bitmask of gmem_reasons that do not force GMEM path over bypass 101bf215546Sopenharmony_ci * for current generation. 102bf215546Sopenharmony_ci */ 103bf215546Sopenharmony_ci enum fd_gmem_reason gmem_reason_mask; 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_ci unsigned num_perfcntr_groups; 106bf215546Sopenharmony_ci const struct fd_perfcntr_group *perfcntr_groups; 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ci /* generated at startup from the perfcntr groups: */ 109bf215546Sopenharmony_ci unsigned num_perfcntr_queries; 110bf215546Sopenharmony_ci struct pipe_driver_query_info *perfcntr_queries; 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_ci void *compiler; /* currently unused for a2xx */ 113bf215546Sopenharmony_ci struct util_queue compile_queue; /* currently unused for a2xx */ 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_ci struct fd_device *dev; 116bf215546Sopenharmony_ci 117bf215546Sopenharmony_ci /* NOTE: we still need a pipe associated with the screen in a few 118bf215546Sopenharmony_ci * places, like screen->get_timestamp(). For anything context 119bf215546Sopenharmony_ci * related, use ctx->pipe instead. 120bf215546Sopenharmony_ci */ 121bf215546Sopenharmony_ci struct fd_pipe *pipe; 122bf215546Sopenharmony_ci 123bf215546Sopenharmony_ci uint32_t (*setup_slices)(struct fd_resource *rsc); 124bf215546Sopenharmony_ci unsigned (*tile_mode)(const struct pipe_resource *prsc); 125bf215546Sopenharmony_ci int (*layout_resource_for_modifier)(struct fd_resource *rsc, 126bf215546Sopenharmony_ci uint64_t modifier); 127bf215546Sopenharmony_ci 128bf215546Sopenharmony_ci /* indirect-branch emit: */ 129bf215546Sopenharmony_ci void (*emit_ib)(struct fd_ringbuffer *ring, struct fd_ringbuffer *target); 130bf215546Sopenharmony_ci 131bf215546Sopenharmony_ci /* simple gpu "memcpy": */ 132bf215546Sopenharmony_ci void (*mem_to_mem)(struct fd_ringbuffer *ring, struct pipe_resource *dst, 133bf215546Sopenharmony_ci unsigned dst_off, struct pipe_resource *src, 134bf215546Sopenharmony_ci unsigned src_off, unsigned sizedwords); 135bf215546Sopenharmony_ci 136bf215546Sopenharmony_ci int64_t cpu_gpu_time_delta; 137bf215546Sopenharmony_ci 138bf215546Sopenharmony_ci struct fd_batch_cache batch_cache; 139bf215546Sopenharmony_ci struct fd_gmem_cache gmem_cache; 140bf215546Sopenharmony_ci 141bf215546Sopenharmony_ci bool reorder; 142bf215546Sopenharmony_ci 143bf215546Sopenharmony_ci uint16_t rsc_seqno; 144bf215546Sopenharmony_ci uint16_t ctx_seqno; 145bf215546Sopenharmony_ci struct util_idalloc_mt buffer_ids; 146bf215546Sopenharmony_ci 147bf215546Sopenharmony_ci unsigned num_supported_modifiers; 148bf215546Sopenharmony_ci const uint64_t *supported_modifiers; 149bf215546Sopenharmony_ci 150bf215546Sopenharmony_ci struct renderonly *ro; 151bf215546Sopenharmony_ci 152bf215546Sopenharmony_ci /* the blob seems to always use 8K factor and 128K param sizes, copy them */ 153bf215546Sopenharmony_ci#define FD6_TESS_FACTOR_SIZE (8 * 1024) 154bf215546Sopenharmony_ci#define FD6_TESS_PARAM_SIZE (128 * 1024) 155bf215546Sopenharmony_ci#define FD6_TESS_BO_SIZE (FD6_TESS_FACTOR_SIZE + FD6_TESS_PARAM_SIZE) 156bf215546Sopenharmony_ci struct fd_bo *tess_bo; 157bf215546Sopenharmony_ci 158bf215546Sopenharmony_ci /* table with PIPE_PRIM_MAX+1 entries mapping PIPE_PRIM_x to 159bf215546Sopenharmony_ci * DI_PT_x value to use for draw initiator. There are some 160bf215546Sopenharmony_ci * slight differences between generation. 161bf215546Sopenharmony_ci * 162bf215546Sopenharmony_ci * Note that primtypes[PRIM_TYPE_MAX] is used to map to the 163bf215546Sopenharmony_ci * internal RECTLIST primtype, if available, used for blits/ 164bf215546Sopenharmony_ci * clears. 165bf215546Sopenharmony_ci */ 166bf215546Sopenharmony_ci const enum pc_di_primtype *primtypes; 167bf215546Sopenharmony_ci uint32_t primtypes_mask; 168bf215546Sopenharmony_ci}; 169bf215546Sopenharmony_ci 170bf215546Sopenharmony_cistatic inline struct fd_screen * 171bf215546Sopenharmony_cifd_screen(struct pipe_screen *pscreen) 172bf215546Sopenharmony_ci{ 173bf215546Sopenharmony_ci return (struct fd_screen *)pscreen; 174bf215546Sopenharmony_ci} 175bf215546Sopenharmony_ci 176bf215546Sopenharmony_cistatic inline void 177bf215546Sopenharmony_cifd_screen_lock(struct fd_screen *screen) 178bf215546Sopenharmony_ci{ 179bf215546Sopenharmony_ci simple_mtx_lock(&screen->lock); 180bf215546Sopenharmony_ci} 181bf215546Sopenharmony_ci 182bf215546Sopenharmony_cistatic inline void 183bf215546Sopenharmony_cifd_screen_unlock(struct fd_screen *screen) 184bf215546Sopenharmony_ci{ 185bf215546Sopenharmony_ci simple_mtx_unlock(&screen->lock); 186bf215546Sopenharmony_ci} 187bf215546Sopenharmony_ci 188bf215546Sopenharmony_cistatic inline void 189bf215546Sopenharmony_cifd_screen_assert_locked(struct fd_screen *screen) 190bf215546Sopenharmony_ci{ 191bf215546Sopenharmony_ci simple_mtx_assert_locked(&screen->lock); 192bf215546Sopenharmony_ci} 193bf215546Sopenharmony_ci 194bf215546Sopenharmony_cibool fd_screen_bo_get_handle(struct pipe_screen *pscreen, struct fd_bo *bo, 195bf215546Sopenharmony_ci struct renderonly_scanout *scanout, 196bf215546Sopenharmony_ci unsigned stride, struct winsys_handle *whandle); 197bf215546Sopenharmony_cistruct fd_bo *fd_screen_bo_from_handle(struct pipe_screen *pscreen, 198bf215546Sopenharmony_ci struct winsys_handle *whandle); 199bf215546Sopenharmony_ci 200bf215546Sopenharmony_cistruct pipe_screen *fd_screen_create(struct fd_device *dev, 201bf215546Sopenharmony_ci struct renderonly *ro, 202bf215546Sopenharmony_ci const struct pipe_screen_config *config); 203bf215546Sopenharmony_ci 204bf215546Sopenharmony_cistatic inline boolean 205bf215546Sopenharmony_ciis_a20x(struct fd_screen *screen) 206bf215546Sopenharmony_ci{ 207bf215546Sopenharmony_ci return (screen->gpu_id >= 200) && (screen->gpu_id < 210); 208bf215546Sopenharmony_ci} 209bf215546Sopenharmony_ci 210bf215546Sopenharmony_cistatic inline boolean 211bf215546Sopenharmony_ciis_a2xx(struct fd_screen *screen) 212bf215546Sopenharmony_ci{ 213bf215546Sopenharmony_ci return screen->gen == 2; 214bf215546Sopenharmony_ci} 215bf215546Sopenharmony_ci 216bf215546Sopenharmony_ci/* is a3xx patch revision 0? */ 217bf215546Sopenharmony_ci/* TODO a306.0 probably doesn't need this.. be more clever?? */ 218bf215546Sopenharmony_cistatic inline boolean 219bf215546Sopenharmony_ciis_a3xx_p0(struct fd_screen *screen) 220bf215546Sopenharmony_ci{ 221bf215546Sopenharmony_ci return (screen->chip_id & 0xff0000ff) == 0x03000000; 222bf215546Sopenharmony_ci} 223bf215546Sopenharmony_ci 224bf215546Sopenharmony_cistatic inline boolean 225bf215546Sopenharmony_ciis_a3xx(struct fd_screen *screen) 226bf215546Sopenharmony_ci{ 227bf215546Sopenharmony_ci return screen->gen == 3; 228bf215546Sopenharmony_ci} 229bf215546Sopenharmony_ci 230bf215546Sopenharmony_cistatic inline boolean 231bf215546Sopenharmony_ciis_a4xx(struct fd_screen *screen) 232bf215546Sopenharmony_ci{ 233bf215546Sopenharmony_ci return screen->gen == 4; 234bf215546Sopenharmony_ci} 235bf215546Sopenharmony_ci 236bf215546Sopenharmony_cistatic inline boolean 237bf215546Sopenharmony_ciis_a5xx(struct fd_screen *screen) 238bf215546Sopenharmony_ci{ 239bf215546Sopenharmony_ci return screen->gen == 5; 240bf215546Sopenharmony_ci} 241bf215546Sopenharmony_ci 242bf215546Sopenharmony_cistatic inline boolean 243bf215546Sopenharmony_ciis_a6xx(struct fd_screen *screen) 244bf215546Sopenharmony_ci{ 245bf215546Sopenharmony_ci return screen->gen == 6; 246bf215546Sopenharmony_ci} 247bf215546Sopenharmony_ci 248bf215546Sopenharmony_ci/* is it using the ir3 compiler (shader isa introduced with a3xx)? */ 249bf215546Sopenharmony_cistatic inline boolean 250bf215546Sopenharmony_ciis_ir3(struct fd_screen *screen) 251bf215546Sopenharmony_ci{ 252bf215546Sopenharmony_ci return is_a3xx(screen) || is_a4xx(screen) || is_a5xx(screen) || 253bf215546Sopenharmony_ci is_a6xx(screen); 254bf215546Sopenharmony_ci} 255bf215546Sopenharmony_ci 256bf215546Sopenharmony_cistatic inline bool 257bf215546Sopenharmony_cihas_compute(struct fd_screen *screen) 258bf215546Sopenharmony_ci{ 259bf215546Sopenharmony_ci return is_a4xx(screen) || is_a5xx(screen) || is_a6xx(screen); 260bf215546Sopenharmony_ci} 261bf215546Sopenharmony_ci 262bf215546Sopenharmony_ci#endif /* FREEDRENO_SCREEN_H_ */ 263