1a8c21a54SThe etnaviv authors /* 2a8c21a54SThe etnaviv authors * Copyright (C) 2015 Etnaviv Project 3a8c21a54SThe etnaviv authors * 4a8c21a54SThe etnaviv authors * This program is free software; you can redistribute it and/or modify it 5a8c21a54SThe etnaviv authors * under the terms of the GNU General Public License version 2 as published by 6a8c21a54SThe etnaviv authors * the Free Software Foundation. 7a8c21a54SThe etnaviv authors * 8a8c21a54SThe etnaviv authors * This program is distributed in the hope that it will be useful, but WITHOUT 9a8c21a54SThe etnaviv authors * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10a8c21a54SThe etnaviv authors * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11a8c21a54SThe etnaviv authors * more details. 12a8c21a54SThe etnaviv authors * 13a8c21a54SThe etnaviv authors * You should have received a copy of the GNU General Public License along with 14a8c21a54SThe etnaviv authors * this program. If not, see <http://www.gnu.org/licenses/>. 15a8c21a54SThe etnaviv authors */ 16a8c21a54SThe etnaviv authors 17a8c21a54SThe etnaviv authors #ifndef __ETNAVIV_GPU_H__ 18a8c21a54SThe etnaviv authors #define __ETNAVIV_GPU_H__ 19a8c21a54SThe etnaviv authors 20a8c21a54SThe etnaviv authors #include <linux/clk.h> 21a8c21a54SThe etnaviv authors #include <linux/regulator/consumer.h> 22a8c21a54SThe etnaviv authors 232f9225dbSLucas Stach #include "etnaviv_cmdbuf.h" 24a8c21a54SThe etnaviv authors #include "etnaviv_drv.h" 25a8c21a54SThe etnaviv authors 26a8c21a54SThe etnaviv authors struct etnaviv_gem_submit; 27b6325f40SRussell King struct etnaviv_vram_mapping; 28a8c21a54SThe etnaviv authors 29a8c21a54SThe etnaviv authors struct etnaviv_chip_identity { 30a8c21a54SThe etnaviv authors /* Chip model. */ 31a8c21a54SThe etnaviv authors u32 model; 32a8c21a54SThe etnaviv authors 33a8c21a54SThe etnaviv authors /* Revision value.*/ 34a8c21a54SThe etnaviv authors u32 revision; 35a8c21a54SThe etnaviv authors 36a8c21a54SThe etnaviv authors /* Supported feature fields. */ 37a8c21a54SThe etnaviv authors u32 features; 38a8c21a54SThe etnaviv authors 39a8c21a54SThe etnaviv authors /* Supported minor feature fields. */ 40a8c21a54SThe etnaviv authors u32 minor_features0; 41a8c21a54SThe etnaviv authors 42a8c21a54SThe etnaviv authors /* Supported minor feature 1 fields. */ 43a8c21a54SThe etnaviv authors u32 minor_features1; 44a8c21a54SThe etnaviv authors 45a8c21a54SThe etnaviv authors /* Supported minor feature 2 fields. */ 46a8c21a54SThe etnaviv authors u32 minor_features2; 47a8c21a54SThe etnaviv authors 48a8c21a54SThe etnaviv authors /* Supported minor feature 3 fields. */ 49a8c21a54SThe etnaviv authors u32 minor_features3; 50a8c21a54SThe etnaviv authors 51602eb489SRussell King /* Supported minor feature 4 fields. */ 52602eb489SRussell King u32 minor_features4; 53602eb489SRussell King 54602eb489SRussell King /* Supported minor feature 5 fields. */ 55602eb489SRussell King u32 minor_features5; 56602eb489SRussell King 57a8c21a54SThe etnaviv authors /* Number of streams supported. */ 58a8c21a54SThe etnaviv authors u32 stream_count; 59a8c21a54SThe etnaviv authors 60a8c21a54SThe etnaviv authors /* Total number of temporary registers per thread. */ 61a8c21a54SThe etnaviv authors u32 register_max; 62a8c21a54SThe etnaviv authors 63a8c21a54SThe etnaviv authors /* Maximum number of threads. */ 64a8c21a54SThe etnaviv authors u32 thread_count; 65a8c21a54SThe etnaviv authors 66a8c21a54SThe etnaviv authors /* Number of shader cores. */ 67a8c21a54SThe etnaviv authors u32 shader_core_count; 68a8c21a54SThe etnaviv authors 69a8c21a54SThe etnaviv authors /* Size of the vertex cache. */ 70a8c21a54SThe etnaviv authors u32 vertex_cache_size; 71a8c21a54SThe etnaviv authors 72a8c21a54SThe etnaviv authors /* Number of entries in the vertex output buffer. */ 73a8c21a54SThe etnaviv authors u32 vertex_output_buffer_size; 74a8c21a54SThe etnaviv authors 75a8c21a54SThe etnaviv authors /* Number of pixel pipes. */ 76a8c21a54SThe etnaviv authors u32 pixel_pipes; 77a8c21a54SThe etnaviv authors 78a8c21a54SThe etnaviv authors /* Number of instructions. */ 79a8c21a54SThe etnaviv authors u32 instruction_count; 80a8c21a54SThe etnaviv authors 81a8c21a54SThe etnaviv authors /* Number of constants. */ 82a8c21a54SThe etnaviv authors u32 num_constants; 83a8c21a54SThe etnaviv authors 84a8c21a54SThe etnaviv authors /* Buffer size */ 85a8c21a54SThe etnaviv authors u32 buffer_size; 86602eb489SRussell King 87602eb489SRussell King /* Number of varyings */ 88602eb489SRussell King u8 varyings_count; 89a8c21a54SThe etnaviv authors }; 90a8c21a54SThe etnaviv authors 91a8c21a54SThe etnaviv authors struct etnaviv_event { 92f54d1867SChris Wilson struct dma_fence *fence; 93ef146c00SLucas Stach struct etnaviv_gem_submit *submit; 94357713ceSChristian Gmeiner 95357713ceSChristian Gmeiner void (*sync_point)(struct etnaviv_gpu *gpu, struct etnaviv_event *event); 96a8c21a54SThe etnaviv authors }; 97a8c21a54SThe etnaviv authors 98e66774ddSLucas Stach struct etnaviv_cmdbuf_suballoc; 99a8c21a54SThe etnaviv authors struct etnaviv_cmdbuf; 100a8c21a54SThe etnaviv authors 101355502e0SChristian Gmeiner #define ETNA_NR_EVENTS 30 102355502e0SChristian Gmeiner 103a8c21a54SThe etnaviv authors struct etnaviv_gpu { 104a8c21a54SThe etnaviv authors struct drm_device *drm; 105bcdfb5e5SRussell King struct thermal_cooling_device *cooling; 106a8c21a54SThe etnaviv authors struct device *dev; 107a8c21a54SThe etnaviv authors struct mutex lock; 108a8c21a54SThe etnaviv authors struct etnaviv_chip_identity identity; 109a8c21a54SThe etnaviv authors struct etnaviv_file_private *lastctx; 110a7790d78SLucas Stach struct workqueue_struct *wq; 111a8c21a54SThe etnaviv authors 112a8c21a54SThe etnaviv authors /* 'ring'-buffer: */ 1132f9225dbSLucas Stach struct etnaviv_cmdbuf buffer; 114f6086311SRussell King int exec_state; 115a8c21a54SThe etnaviv authors 116a8c21a54SThe etnaviv authors /* bus base address of memory */ 117a8c21a54SThe etnaviv authors u32 memory_base; 118a8c21a54SThe etnaviv authors 119a8c21a54SThe etnaviv authors /* event management: */ 120355502e0SChristian Gmeiner DECLARE_BITMAP(event_bitmap, ETNA_NR_EVENTS); 121355502e0SChristian Gmeiner struct etnaviv_event event[ETNA_NR_EVENTS]; 122a8c21a54SThe etnaviv authors struct completion event_free; 123a8c21a54SThe etnaviv authors spinlock_t event_spinlock; 124a8c21a54SThe etnaviv authors 125a8c21a54SThe etnaviv authors /* list of currently in-flight command buffers */ 1262f9225dbSLucas Stach struct list_head active_submit_list; 127a8c21a54SThe etnaviv authors 128a8c21a54SThe etnaviv authors u32 idle_mask; 129a8c21a54SThe etnaviv authors 130a8c21a54SThe etnaviv authors /* Fencing support */ 1318bc4d885SLucas Stach struct idr fence_idr; 132a8c21a54SThe etnaviv authors u32 next_fence; 133a8c21a54SThe etnaviv authors u32 active_fence; 134a8c21a54SThe etnaviv authors u32 completed_fence; 135a8c21a54SThe etnaviv authors u32 retired_fence; 136a8c21a54SThe etnaviv authors wait_queue_head_t fence_event; 13776bf0db5SChristian König u64 fence_context; 138a8c21a54SThe etnaviv authors spinlock_t fence_spinlock; 139a8c21a54SThe etnaviv authors 140a8c21a54SThe etnaviv authors /* worker for handling active-list retiring: */ 141a8c21a54SThe etnaviv authors struct work_struct retire_work; 142a8c21a54SThe etnaviv authors 143357713ceSChristian Gmeiner /* worker for handling 'sync' points: */ 144357713ceSChristian Gmeiner struct work_struct sync_point_work; 145357713ceSChristian Gmeiner int sync_point_event; 146357713ceSChristian Gmeiner 147a8c21a54SThe etnaviv authors void __iomem *mmio; 148a8c21a54SThe etnaviv authors int irq; 149a8c21a54SThe etnaviv authors 150a8c21a54SThe etnaviv authors struct etnaviv_iommu *mmu; 151e66774ddSLucas Stach struct etnaviv_cmdbuf_suballoc *cmdbuf_suballoc; 152a8c21a54SThe etnaviv authors 153a8c21a54SThe etnaviv authors /* Power Control: */ 154a8c21a54SThe etnaviv authors struct clk *clk_bus; 155a8c21a54SThe etnaviv authors struct clk *clk_core; 156a8c21a54SThe etnaviv authors struct clk *clk_shader; 157a8c21a54SThe etnaviv authors 158a8c21a54SThe etnaviv authors /* Hang Detction: */ 159a8c21a54SThe etnaviv authors #define DRM_ETNAVIV_HANGCHECK_PERIOD 500 /* in ms */ 160a8c21a54SThe etnaviv authors #define DRM_ETNAVIV_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_ETNAVIV_HANGCHECK_PERIOD) 161a8c21a54SThe etnaviv authors struct timer_list hangcheck_timer; 162a8c21a54SThe etnaviv authors u32 hangcheck_fence; 163a8c21a54SThe etnaviv authors u32 hangcheck_dma_addr; 164a8c21a54SThe etnaviv authors struct work_struct recover_work; 165bcdfb5e5SRussell King unsigned int freq_scale; 166d79fd1ccSLucas Stach unsigned long base_rate_core; 167d79fd1ccSLucas Stach unsigned long base_rate_shader; 168a8c21a54SThe etnaviv authors }; 169a8c21a54SThe etnaviv authors 170a8c21a54SThe etnaviv authors static inline void gpu_write(struct etnaviv_gpu *gpu, u32 reg, u32 data) 171a8c21a54SThe etnaviv authors { 172a8c21a54SThe etnaviv authors etnaviv_writel(data, gpu->mmio + reg); 173a8c21a54SThe etnaviv authors } 174a8c21a54SThe etnaviv authors 175a8c21a54SThe etnaviv authors static inline u32 gpu_read(struct etnaviv_gpu *gpu, u32 reg) 176a8c21a54SThe etnaviv authors { 177a8c21a54SThe etnaviv authors return etnaviv_readl(gpu->mmio + reg); 178a8c21a54SThe etnaviv authors } 179a8c21a54SThe etnaviv authors 180a8c21a54SThe etnaviv authors static inline bool fence_completed(struct etnaviv_gpu *gpu, u32 fence) 181a8c21a54SThe etnaviv authors { 182a8c21a54SThe etnaviv authors return fence_after_eq(gpu->completed_fence, fence); 183a8c21a54SThe etnaviv authors } 184a8c21a54SThe etnaviv authors 185a8c21a54SThe etnaviv authors static inline bool fence_retired(struct etnaviv_gpu *gpu, u32 fence) 186a8c21a54SThe etnaviv authors { 187a8c21a54SThe etnaviv authors return fence_after_eq(gpu->retired_fence, fence); 188a8c21a54SThe etnaviv authors } 189a8c21a54SThe etnaviv authors 190a8c21a54SThe etnaviv authors int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value); 191a8c21a54SThe etnaviv authors 192a8c21a54SThe etnaviv authors int etnaviv_gpu_init(struct etnaviv_gpu *gpu); 193a8c21a54SThe etnaviv authors 194a8c21a54SThe etnaviv authors #ifdef CONFIG_DEBUG_FS 195a8c21a54SThe etnaviv authors int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m); 196a8c21a54SThe etnaviv authors #endif 197a8c21a54SThe etnaviv authors 198a8c21a54SThe etnaviv authors int etnaviv_gpu_fence_sync_obj(struct etnaviv_gem_object *etnaviv_obj, 1999ad59feaSPhilipp Zabel unsigned int context, bool exclusive, bool implicit); 200a8c21a54SThe etnaviv authors 201a8c21a54SThe etnaviv authors void etnaviv_gpu_retire(struct etnaviv_gpu *gpu); 202a8c21a54SThe etnaviv authors int etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu *gpu, 203a8c21a54SThe etnaviv authors u32 fence, struct timespec *timeout); 204a8c21a54SThe etnaviv authors int etnaviv_gpu_wait_obj_inactive(struct etnaviv_gpu *gpu, 205a8c21a54SThe etnaviv authors struct etnaviv_gem_object *etnaviv_obj, struct timespec *timeout); 206a8c21a54SThe etnaviv authors int etnaviv_gpu_submit(struct etnaviv_gpu *gpu, 2072f9225dbSLucas Stach struct etnaviv_gem_submit *submit); 208a8c21a54SThe etnaviv authors int etnaviv_gpu_pm_get_sync(struct etnaviv_gpu *gpu); 209a8c21a54SThe etnaviv authors void etnaviv_gpu_pm_put(struct etnaviv_gpu *gpu); 210b88163e3SLucas Stach int etnaviv_gpu_wait_idle(struct etnaviv_gpu *gpu, unsigned int timeout_ms); 211229855b6SLucas Stach void etnaviv_gpu_start_fe(struct etnaviv_gpu *gpu, u32 address, u16 prefetch); 212a8c21a54SThe etnaviv authors 213a8c21a54SThe etnaviv authors extern struct platform_driver etnaviv_gpu_driver; 214a8c21a54SThe etnaviv authors 215a8c21a54SThe etnaviv authors #endif /* __ETNAVIV_GPU_H__ */ 216