1af69d88dSmrg/* 2af69d88dSmrg * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org> 3af69d88dSmrg * 4af69d88dSmrg * Permission is hereby granted, free of charge, to any person obtaining a 5af69d88dSmrg * copy of this software and associated documentation files (the "Software"), 6af69d88dSmrg * to deal in the Software without restriction, including without limitation 7af69d88dSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8af69d88dSmrg * and/or sell copies of the Software, and to permit persons to whom the 9af69d88dSmrg * Software is furnished to do so, subject to the following conditions: 10af69d88dSmrg * 11af69d88dSmrg * The above copyright notice and this permission notice (including the next 12af69d88dSmrg * paragraph) shall be included in all copies or substantial portions of the 13af69d88dSmrg * Software. 14af69d88dSmrg * 15af69d88dSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16af69d88dSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17af69d88dSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19af69d88dSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20af69d88dSmrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21af69d88dSmrg * SOFTWARE. 22af69d88dSmrg * 23af69d88dSmrg * Authors: 24af69d88dSmrg * Rob Clark <robclark@freedesktop.org> 25af69d88dSmrg */ 26af69d88dSmrg 27af69d88dSmrg#ifndef FREEDRENO_SCREEN_H_ 28af69d88dSmrg#define FREEDRENO_SCREEN_H_ 29af69d88dSmrg 307ec681f3Smrg#include "common/freedreno_dev_info.h" 3101e04c3fSmrg#include "drm/freedreno_drmif.h" 3201e04c3fSmrg#include "drm/freedreno_ringbuffer.h" 337ec681f3Smrg#include "perfcntrs/freedreno_perfcntr.h" 34af69d88dSmrg 35af69d88dSmrg#include "pipe/p_screen.h" 369f464c52Smaya#include "renderonly/renderonly.h" 377ec681f3Smrg#include "util/debug.h" 387ec681f3Smrg#include "util/simple_mtx.h" 397ec681f3Smrg#include "util/slab.h" 407ec681f3Smrg#include "util/u_idalloc.h" 417ec681f3Smrg#include "util/u_memory.h" 427ec681f3Smrg#include "util/u_queue.h" 43af69d88dSmrg 4401e04c3fSmrg#include "freedreno_batch_cache.h" 457ec681f3Smrg#include "freedreno_gmem.h" 4601e04c3fSmrg#include "freedreno_util.h" 47af69d88dSmrg 48af69d88dSmrgstruct fd_bo; 49af69d88dSmrg 507ec681f3Smrg/* Potential reasons for needing to skip bypass path and use GMEM, the 517ec681f3Smrg * generation backend can override this with screen->gmem_reason_mask 527ec681f3Smrg */ 537ec681f3Smrgenum fd_gmem_reason { 547ec681f3Smrg FD_GMEM_CLEARS_DEPTH_STENCIL = BIT(0), 557ec681f3Smrg FD_GMEM_DEPTH_ENABLED = BIT(1), 567ec681f3Smrg FD_GMEM_STENCIL_ENABLED = BIT(2), 577ec681f3Smrg FD_GMEM_BLEND_ENABLED = BIT(3), 587ec681f3Smrg FD_GMEM_LOGICOP_ENABLED = BIT(4), 597ec681f3Smrg FD_GMEM_FB_READ = BIT(5), 607ec681f3Smrg}; 617ec681f3Smrg 62af69d88dSmrgstruct fd_screen { 637ec681f3Smrg struct pipe_screen base; 647ec681f3Smrg 657ec681f3Smrg struct list_head context_list; 667ec681f3Smrg 677ec681f3Smrg simple_mtx_t lock; 687ec681f3Smrg 697ec681f3Smrg /* it would be tempting to use pipe_reference here, but that 707ec681f3Smrg * really doesn't work well if it isn't the first member of 717ec681f3Smrg * the struct, so not quite so awesome to be adding refcnting 727ec681f3Smrg * further down the inheritance hierarchy: 737ec681f3Smrg */ 747ec681f3Smrg int refcnt; 757ec681f3Smrg 767ec681f3Smrg /* place for winsys to stash it's own stuff: */ 777ec681f3Smrg void *winsys_priv; 787ec681f3Smrg 797ec681f3Smrg struct slab_parent_pool transfer_pool; 80af69d88dSmrg 817ec681f3Smrg uint64_t gmem_base; 827ec681f3Smrg uint32_t gmemsize_bytes; 8301e04c3fSmrg 847ec681f3Smrg const struct fd_dev_id *dev_id; 857ec681f3Smrg uint8_t gen; /* GPU (major) generation */ 867ec681f3Smrg uint32_t gpu_id; /* 220, 305, etc */ 877ec681f3Smrg uint64_t chip_id; /* coreid:8 majorrev:8 minorrev:8 patch:8 */ 887ec681f3Smrg uint32_t max_freq; 897ec681f3Smrg uint32_t ram_size; 907ec681f3Smrg uint32_t max_rts; /* max # of render targets */ 917ec681f3Smrg uint32_t priority_mask; 927ec681f3Smrg bool has_timestamp; 937ec681f3Smrg bool has_robustness; 947ec681f3Smrg bool has_syncobj; 9501e04c3fSmrg 967ec681f3Smrg const struct fd_dev_info *info; 977ec681f3Smrg uint32_t ccu_offset_gmem; 987ec681f3Smrg uint32_t ccu_offset_bypass; 9901e04c3fSmrg 1007ec681f3Smrg /* Bitmask of gmem_reasons that do not force GMEM path over bypass 1017ec681f3Smrg * for current generation. 1027ec681f3Smrg */ 1037ec681f3Smrg enum fd_gmem_reason gmem_reason_mask; 10401e04c3fSmrg 1057ec681f3Smrg unsigned num_perfcntr_groups; 1067ec681f3Smrg const struct fd_perfcntr_group *perfcntr_groups; 10701e04c3fSmrg 1087ec681f3Smrg /* generated at startup from the perfcntr groups: */ 1097ec681f3Smrg unsigned num_perfcntr_queries; 1107ec681f3Smrg struct pipe_driver_query_info *perfcntr_queries; 11101e04c3fSmrg 1127ec681f3Smrg void *compiler; /* currently unused for a2xx */ 1137ec681f3Smrg struct util_queue compile_queue; /* currently unused for a2xx */ 11401e04c3fSmrg 1157ec681f3Smrg struct fd_device *dev; 116af69d88dSmrg 1177ec681f3Smrg /* NOTE: we still need a pipe associated with the screen in a few 1187ec681f3Smrg * places, like screen->get_timestamp(). For anything context 1197ec681f3Smrg * related, use ctx->pipe instead. 1207ec681f3Smrg */ 1217ec681f3Smrg struct fd_pipe *pipe; 12201e04c3fSmrg 1237ec681f3Smrg uint32_t (*setup_slices)(struct fd_resource *rsc); 1247ec681f3Smrg unsigned (*tile_mode)(const struct pipe_resource *prsc); 1257ec681f3Smrg int (*layout_resource_for_modifier)(struct fd_resource *rsc, 1267ec681f3Smrg uint64_t modifier); 127af69d88dSmrg 1287ec681f3Smrg /* indirect-branch emit: */ 1297ec681f3Smrg void (*emit_ib)(struct fd_ringbuffer *ring, struct fd_ringbuffer *target); 13001e04c3fSmrg 1317ec681f3Smrg /* simple gpu "memcpy": */ 1327ec681f3Smrg void (*mem_to_mem)(struct fd_ringbuffer *ring, struct pipe_resource *dst, 1337ec681f3Smrg unsigned dst_off, struct pipe_resource *src, 1347ec681f3Smrg unsigned src_off, unsigned sizedwords); 13501e04c3fSmrg 1367ec681f3Smrg int64_t cpu_gpu_time_delta; 13701e04c3fSmrg 1387ec681f3Smrg struct fd_batch_cache batch_cache; 1397ec681f3Smrg struct fd_gmem_cache gmem_cache; 14001e04c3fSmrg 1417ec681f3Smrg bool reorder; 1429f464c52Smaya 1437ec681f3Smrg uint16_t rsc_seqno; 1447ec681f3Smrg uint16_t ctx_seqno; 1457ec681f3Smrg struct util_idalloc_mt buffer_ids; 1469f464c52Smaya 1477ec681f3Smrg unsigned num_supported_modifiers; 1487ec681f3Smrg const uint64_t *supported_modifiers; 1497ec681f3Smrg 1507ec681f3Smrg struct renderonly *ro; 1517ec681f3Smrg 1527ec681f3Smrg /* table with PIPE_PRIM_MAX+1 entries mapping PIPE_PRIM_x to 1537ec681f3Smrg * DI_PT_x value to use for draw initiator. There are some 1547ec681f3Smrg * slight differences between generation. 1557ec681f3Smrg * 1567ec681f3Smrg * Note that primtypes[PRIM_TYPE_MAX] is used to map to the 1577ec681f3Smrg * internal RECTLIST primtype, if available, used for blits/ 1587ec681f3Smrg * clears. 1597ec681f3Smrg */ 1607ec681f3Smrg const uint8_t *primtypes; 1617ec681f3Smrg uint32_t primtypes_mask; 162af69d88dSmrg}; 163af69d88dSmrg 16401e04c3fSmrgstatic inline struct fd_screen * 165af69d88dSmrgfd_screen(struct pipe_screen *pscreen) 166af69d88dSmrg{ 1677ec681f3Smrg return (struct fd_screen *)pscreen; 1687ec681f3Smrg} 1697ec681f3Smrg 1707ec681f3Smrgstatic inline void 1717ec681f3Smrgfd_screen_lock(struct fd_screen *screen) 1727ec681f3Smrg{ 1737ec681f3Smrg simple_mtx_lock(&screen->lock); 1747ec681f3Smrg} 1757ec681f3Smrg 1767ec681f3Smrgstatic inline void 1777ec681f3Smrgfd_screen_unlock(struct fd_screen *screen) 1787ec681f3Smrg{ 1797ec681f3Smrg simple_mtx_unlock(&screen->lock); 1807ec681f3Smrg} 1817ec681f3Smrg 1827ec681f3Smrgstatic inline void 1837ec681f3Smrgfd_screen_assert_locked(struct fd_screen *screen) 1847ec681f3Smrg{ 1857ec681f3Smrg simple_mtx_assert_locked(&screen->lock); 186af69d88dSmrg} 187af69d88dSmrg 1887ec681f3Smrgbool fd_screen_bo_get_handle(struct pipe_screen *pscreen, struct fd_bo *bo, 1897ec681f3Smrg struct renderonly_scanout *scanout, 1907ec681f3Smrg unsigned stride, struct winsys_handle *whandle); 1917ec681f3Smrgstruct fd_bo *fd_screen_bo_from_handle(struct pipe_screen *pscreen, 1927ec681f3Smrg struct winsys_handle *whandle); 193af69d88dSmrg 1947ec681f3Smrgstruct pipe_screen *fd_screen_create(struct fd_device *dev, 1957ec681f3Smrg struct renderonly *ro, 1967ec681f3Smrg const struct pipe_screen_config *config); 197af69d88dSmrg 19801e04c3fSmrgstatic inline boolean 19901e04c3fSmrgis_a20x(struct fd_screen *screen) 20001e04c3fSmrg{ 2017ec681f3Smrg return (screen->gpu_id >= 200) && (screen->gpu_id < 210); 20201e04c3fSmrg} 20301e04c3fSmrg 2049f464c52Smayastatic inline boolean 2059f464c52Smayais_a2xx(struct fd_screen *screen) 2069f464c52Smaya{ 2077ec681f3Smrg return screen->gen == 2; 2089f464c52Smaya} 2099f464c52Smaya 210af69d88dSmrg/* is a3xx patch revision 0? */ 21101e04c3fSmrg/* TODO a306.0 probably doesn't need this.. be more clever?? */ 212af69d88dSmrgstatic inline boolean 213af69d88dSmrgis_a3xx_p0(struct fd_screen *screen) 214af69d88dSmrg{ 2157ec681f3Smrg return (screen->chip_id & 0xff0000ff) == 0x03000000; 21601e04c3fSmrg} 21701e04c3fSmrg 21801e04c3fSmrgstatic inline boolean 21901e04c3fSmrgis_a3xx(struct fd_screen *screen) 22001e04c3fSmrg{ 2217ec681f3Smrg return screen->gen == 3; 22201e04c3fSmrg} 22301e04c3fSmrg 22401e04c3fSmrgstatic inline boolean 22501e04c3fSmrgis_a4xx(struct fd_screen *screen) 22601e04c3fSmrg{ 2277ec681f3Smrg return screen->gen == 4; 22801e04c3fSmrg} 22901e04c3fSmrg 23001e04c3fSmrgstatic inline boolean 23101e04c3fSmrgis_a5xx(struct fd_screen *screen) 23201e04c3fSmrg{ 2337ec681f3Smrg return screen->gen == 5; 23401e04c3fSmrg} 23501e04c3fSmrg 23601e04c3fSmrgstatic inline boolean 23701e04c3fSmrgis_a6xx(struct fd_screen *screen) 23801e04c3fSmrg{ 2397ec681f3Smrg return screen->gen == 6; 24001e04c3fSmrg} 24101e04c3fSmrg 24201e04c3fSmrg/* is it using the ir3 compiler (shader isa introduced with a3xx)? */ 24301e04c3fSmrgstatic inline boolean 24401e04c3fSmrgis_ir3(struct fd_screen *screen) 24501e04c3fSmrg{ 2467ec681f3Smrg return is_a3xx(screen) || is_a4xx(screen) || is_a5xx(screen) || 2477ec681f3Smrg is_a6xx(screen); 24801e04c3fSmrg} 24901e04c3fSmrg 25001e04c3fSmrgstatic inline bool 25101e04c3fSmrghas_compute(struct fd_screen *screen) 25201e04c3fSmrg{ 2537ec681f3Smrg return is_a5xx(screen) || is_a6xx(screen); 254af69d88dSmrg} 255af69d88dSmrg 256af69d88dSmrg#endif /* FREEDRENO_SCREEN_H_ */ 257