1848b8605Smrg/* 2848b8605Smrg * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org> 3848b8605Smrg * 4848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5848b8605Smrg * copy of this software and associated documentation files (the "Software"), 6848b8605Smrg * to deal in the Software without restriction, including without limitation 7848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the 9848b8605Smrg * Software is furnished to do so, subject to the following conditions: 10848b8605Smrg * 11848b8605Smrg * The above copyright notice and this permission notice (including the next 12848b8605Smrg * paragraph) shall be included in all copies or substantial portions of the 13848b8605Smrg * Software. 14848b8605Smrg * 15848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16848b8605Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19848b8605Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20848b8605Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21848b8605Smrg * SOFTWARE. 22848b8605Smrg * 23848b8605Smrg * Authors: 24848b8605Smrg * Rob Clark <robclark@freedesktop.org> 25848b8605Smrg */ 26848b8605Smrg 27848b8605Smrg#ifndef FREEDRENO_SCREEN_H_ 28848b8605Smrg#define FREEDRENO_SCREEN_H_ 29848b8605Smrg 30b8e80941Smrg#include "drm/freedreno_drmif.h" 31b8e80941Smrg#include "drm/freedreno_ringbuffer.h" 32848b8605Smrg 33848b8605Smrg#include "pipe/p_screen.h" 34848b8605Smrg#include "util/u_memory.h" 35b8e80941Smrg#include "util/slab.h" 36b8e80941Smrg#include "os/os_thread.h" 37b8e80941Smrg#include "renderonly/renderonly.h" 38848b8605Smrg 39b8e80941Smrg#include "freedreno_batch_cache.h" 40b8e80941Smrg#include "freedreno_perfcntr.h" 41b8e80941Smrg#include "freedreno_util.h" 42848b8605Smrg 43848b8605Smrgstruct fd_bo; 44848b8605Smrg 45848b8605Smrgstruct fd_screen { 46848b8605Smrg struct pipe_screen base; 47848b8605Smrg 48b8e80941Smrg mtx_t lock; 49b8e80941Smrg 50b8e80941Smrg /* it would be tempting to use pipe_reference here, but that 51b8e80941Smrg * really doesn't work well if it isn't the first member of 52b8e80941Smrg * the struct, so not quite so awesome to be adding refcnting 53b8e80941Smrg * further down the inheritance hierarchy: 54b8e80941Smrg */ 55b8e80941Smrg int refcnt; 56b8e80941Smrg 57b8e80941Smrg /* place for winsys to stash it's own stuff: */ 58b8e80941Smrg void *winsys_priv; 59b8e80941Smrg 60b8e80941Smrg struct slab_parent_pool transfer_pool; 61b8e80941Smrg 62b8e80941Smrg uint64_t gmem_base; 63848b8605Smrg uint32_t gmemsize_bytes; 64848b8605Smrg uint32_t device_id; 65848b8605Smrg uint32_t gpu_id; /* 220, 305, etc */ 66848b8605Smrg uint32_t chip_id; /* coreid:8 majorrev:8 minorrev:8 patch:8 */ 67b8e80941Smrg uint32_t max_freq; 68b8e80941Smrg uint32_t ram_size; 69b8e80941Smrg uint32_t max_rts; /* max # of render targets */ 70b8e80941Smrg uint32_t gmem_alignw, gmem_alignh; 71b8e80941Smrg uint32_t num_vsc_pipes; 72b8e80941Smrg uint32_t priority_mask; 73b8e80941Smrg bool has_timestamp; 74b8e80941Smrg bool has_robustness; 75b8e80941Smrg 76b8e80941Smrg unsigned num_perfcntr_groups; 77b8e80941Smrg const struct fd_perfcntr_group *perfcntr_groups; 78b8e80941Smrg 79b8e80941Smrg /* generated at startup from the perfcntr groups: */ 80b8e80941Smrg unsigned num_perfcntr_queries; 81b8e80941Smrg struct pipe_driver_query_info *perfcntr_queries; 82b8e80941Smrg 83b8e80941Smrg void *compiler; /* currently unused for a2xx */ 84848b8605Smrg 85848b8605Smrg struct fd_device *dev; 86b8e80941Smrg 87b8e80941Smrg /* NOTE: we still need a pipe associated with the screen in a few 88b8e80941Smrg * places, like screen->get_timestamp(). For anything context 89b8e80941Smrg * related, use ctx->pipe instead. 90b8e80941Smrg */ 91848b8605Smrg struct fd_pipe *pipe; 92848b8605Smrg 93b8e80941Smrg uint32_t (*fill_ubwc_buffer_sizes)(struct fd_resource *rsc); 94b8e80941Smrg uint32_t (*setup_slices)(struct fd_resource *rsc); 95b8e80941Smrg unsigned (*tile_mode)(const struct pipe_resource *prsc); 96b8e80941Smrg 97848b8605Smrg int64_t cpu_gpu_time_delta; 98b8e80941Smrg 99b8e80941Smrg struct fd_batch_cache batch_cache; 100b8e80941Smrg 101b8e80941Smrg bool reorder; 102b8e80941Smrg 103b8e80941Smrg uint16_t rsc_seqno; 104b8e80941Smrg 105b8e80941Smrg unsigned num_supported_modifiers; 106b8e80941Smrg const uint64_t *supported_modifiers; 107b8e80941Smrg 108b8e80941Smrg struct renderonly *ro; 109848b8605Smrg}; 110848b8605Smrg 111b8e80941Smrgstatic inline struct fd_screen * 112848b8605Smrgfd_screen(struct pipe_screen *pscreen) 113848b8605Smrg{ 114848b8605Smrg return (struct fd_screen *)pscreen; 115848b8605Smrg} 116848b8605Smrg 117848b8605Smrgboolean fd_screen_bo_get_handle(struct pipe_screen *pscreen, 118848b8605Smrg struct fd_bo *bo, 119b8e80941Smrg struct renderonly_scanout *scanout, 120848b8605Smrg unsigned stride, 121848b8605Smrg struct winsys_handle *whandle); 122848b8605Smrgstruct fd_bo * fd_screen_bo_from_handle(struct pipe_screen *pscreen, 123b8e80941Smrg struct winsys_handle *whandle); 124b8e80941Smrg 125b8e80941Smrgstruct pipe_screen * 126b8e80941Smrgfd_screen_create(struct fd_device *dev, struct renderonly *ro); 127b8e80941Smrg 128b8e80941Smrgstatic inline boolean 129b8e80941Smrgis_a20x(struct fd_screen *screen) 130b8e80941Smrg{ 131b8e80941Smrg return (screen->gpu_id >= 200) && (screen->gpu_id < 210); 132b8e80941Smrg} 133848b8605Smrg 134b8e80941Smrgstatic inline boolean 135b8e80941Smrgis_a2xx(struct fd_screen *screen) 136b8e80941Smrg{ 137b8e80941Smrg return (screen->gpu_id >= 200) && (screen->gpu_id < 300); 138b8e80941Smrg} 139848b8605Smrg 140848b8605Smrg/* is a3xx patch revision 0? */ 141b8e80941Smrg/* TODO a306.0 probably doesn't need this.. be more clever?? */ 142848b8605Smrgstatic inline boolean 143848b8605Smrgis_a3xx_p0(struct fd_screen *screen) 144848b8605Smrg{ 145b8e80941Smrg return (screen->chip_id & 0xff0000ff) == 0x03000000; 146b8e80941Smrg} 147b8e80941Smrg 148b8e80941Smrgstatic inline boolean 149b8e80941Smrgis_a3xx(struct fd_screen *screen) 150b8e80941Smrg{ 151b8e80941Smrg return (screen->gpu_id >= 300) && (screen->gpu_id < 400); 152b8e80941Smrg} 153b8e80941Smrg 154b8e80941Smrgstatic inline boolean 155b8e80941Smrgis_a4xx(struct fd_screen *screen) 156b8e80941Smrg{ 157b8e80941Smrg return (screen->gpu_id >= 400) && (screen->gpu_id < 500); 158b8e80941Smrg} 159b8e80941Smrg 160b8e80941Smrgstatic inline boolean 161b8e80941Smrgis_a5xx(struct fd_screen *screen) 162b8e80941Smrg{ 163b8e80941Smrg return (screen->gpu_id >= 500) && (screen->gpu_id < 600); 164b8e80941Smrg} 165b8e80941Smrg 166b8e80941Smrgstatic inline boolean 167b8e80941Smrgis_a6xx(struct fd_screen *screen) 168b8e80941Smrg{ 169b8e80941Smrg return (screen->gpu_id >= 600) && (screen->gpu_id < 700); 170b8e80941Smrg} 171b8e80941Smrg 172b8e80941Smrg/* is it using the ir3 compiler (shader isa introduced with a3xx)? */ 173b8e80941Smrgstatic inline boolean 174b8e80941Smrgis_ir3(struct fd_screen *screen) 175b8e80941Smrg{ 176b8e80941Smrg return is_a3xx(screen) || is_a4xx(screen) || is_a5xx(screen) || is_a6xx(screen); 177b8e80941Smrg} 178b8e80941Smrg 179b8e80941Smrgstatic inline bool 180b8e80941Smrghas_compute(struct fd_screen *screen) 181b8e80941Smrg{ 182b8e80941Smrg return is_a5xx(screen) || is_a6xx(screen); 183848b8605Smrg} 184848b8605Smrg 185848b8605Smrg#endif /* FREEDRENO_SCREEN_H_ */ 186