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 23a8c21a54SThe etnaviv authors #include "etnaviv_drv.h" 24a8c21a54SThe etnaviv authors 25a8c21a54SThe etnaviv authors struct etnaviv_gem_submit; 26b6325f40SRussell King struct etnaviv_vram_mapping; 27a8c21a54SThe etnaviv authors 28a8c21a54SThe etnaviv authors struct etnaviv_chip_identity { 29a8c21a54SThe etnaviv authors /* Chip model. */ 30a8c21a54SThe etnaviv authors u32 model; 31a8c21a54SThe etnaviv authors 32a8c21a54SThe etnaviv authors /* Revision value.*/ 33a8c21a54SThe etnaviv authors u32 revision; 34a8c21a54SThe etnaviv authors 35a8c21a54SThe etnaviv authors /* Supported feature fields. */ 36a8c21a54SThe etnaviv authors u32 features; 37a8c21a54SThe etnaviv authors 38a8c21a54SThe etnaviv authors /* Supported minor feature fields. */ 39a8c21a54SThe etnaviv authors u32 minor_features0; 40a8c21a54SThe etnaviv authors 41a8c21a54SThe etnaviv authors /* Supported minor feature 1 fields. */ 42a8c21a54SThe etnaviv authors u32 minor_features1; 43a8c21a54SThe etnaviv authors 44a8c21a54SThe etnaviv authors /* Supported minor feature 2 fields. */ 45a8c21a54SThe etnaviv authors u32 minor_features2; 46a8c21a54SThe etnaviv authors 47a8c21a54SThe etnaviv authors /* Supported minor feature 3 fields. */ 48a8c21a54SThe etnaviv authors u32 minor_features3; 49a8c21a54SThe etnaviv authors 50602eb489SRussell King /* Supported minor feature 4 fields. */ 51602eb489SRussell King u32 minor_features4; 52602eb489SRussell King 53602eb489SRussell King /* Supported minor feature 5 fields. */ 54602eb489SRussell King u32 minor_features5; 55602eb489SRussell King 56a8c21a54SThe etnaviv authors /* Number of streams supported. */ 57a8c21a54SThe etnaviv authors u32 stream_count; 58a8c21a54SThe etnaviv authors 59a8c21a54SThe etnaviv authors /* Total number of temporary registers per thread. */ 60a8c21a54SThe etnaviv authors u32 register_max; 61a8c21a54SThe etnaviv authors 62a8c21a54SThe etnaviv authors /* Maximum number of threads. */ 63a8c21a54SThe etnaviv authors u32 thread_count; 64a8c21a54SThe etnaviv authors 65a8c21a54SThe etnaviv authors /* Number of shader cores. */ 66a8c21a54SThe etnaviv authors u32 shader_core_count; 67a8c21a54SThe etnaviv authors 68a8c21a54SThe etnaviv authors /* Size of the vertex cache. */ 69a8c21a54SThe etnaviv authors u32 vertex_cache_size; 70a8c21a54SThe etnaviv authors 71a8c21a54SThe etnaviv authors /* Number of entries in the vertex output buffer. */ 72a8c21a54SThe etnaviv authors u32 vertex_output_buffer_size; 73a8c21a54SThe etnaviv authors 74a8c21a54SThe etnaviv authors /* Number of pixel pipes. */ 75a8c21a54SThe etnaviv authors u32 pixel_pipes; 76a8c21a54SThe etnaviv authors 77a8c21a54SThe etnaviv authors /* Number of instructions. */ 78a8c21a54SThe etnaviv authors u32 instruction_count; 79a8c21a54SThe etnaviv authors 80a8c21a54SThe etnaviv authors /* Number of constants. */ 81a8c21a54SThe etnaviv authors u32 num_constants; 82a8c21a54SThe etnaviv authors 83a8c21a54SThe etnaviv authors /* Buffer size */ 84a8c21a54SThe etnaviv authors u32 buffer_size; 85602eb489SRussell King 86602eb489SRussell King /* Number of varyings */ 87602eb489SRussell King u8 varyings_count; 88a8c21a54SThe etnaviv authors }; 89a8c21a54SThe etnaviv authors 90a8c21a54SThe etnaviv authors struct etnaviv_event { 91a8c21a54SThe etnaviv authors bool used; 92f54d1867SChris Wilson struct dma_fence *fence; 93a8c21a54SThe etnaviv authors }; 94a8c21a54SThe etnaviv authors 95e66774ddSLucas Stach struct etnaviv_cmdbuf_suballoc; 96a8c21a54SThe etnaviv authors struct etnaviv_cmdbuf; 97a8c21a54SThe etnaviv authors 98a8c21a54SThe etnaviv authors struct etnaviv_gpu { 99a8c21a54SThe etnaviv authors struct drm_device *drm; 100bcdfb5e5SRussell King struct thermal_cooling_device *cooling; 101a8c21a54SThe etnaviv authors struct device *dev; 102a8c21a54SThe etnaviv authors struct mutex lock; 103a8c21a54SThe etnaviv authors struct etnaviv_chip_identity identity; 104a8c21a54SThe etnaviv authors struct etnaviv_file_private *lastctx; 105a8c21a54SThe etnaviv authors bool switch_context; 106a8c21a54SThe etnaviv authors 107a8c21a54SThe etnaviv authors /* 'ring'-buffer: */ 108a8c21a54SThe etnaviv authors struct etnaviv_cmdbuf *buffer; 109f6086311SRussell King int exec_state; 110a8c21a54SThe etnaviv authors 111a8c21a54SThe etnaviv authors /* bus base address of memory */ 112a8c21a54SThe etnaviv authors u32 memory_base; 113a8c21a54SThe etnaviv authors 114a8c21a54SThe etnaviv authors /* event management: */ 115a8c21a54SThe etnaviv authors struct etnaviv_event event[30]; 116a8c21a54SThe etnaviv authors struct completion event_free; 117a8c21a54SThe etnaviv authors spinlock_t event_spinlock; 118a8c21a54SThe etnaviv authors 119a8c21a54SThe etnaviv authors /* list of currently in-flight command buffers */ 120a8c21a54SThe etnaviv authors struct list_head active_cmd_list; 121a8c21a54SThe etnaviv authors 122a8c21a54SThe etnaviv authors u32 idle_mask; 123a8c21a54SThe etnaviv authors 124a8c21a54SThe etnaviv authors /* Fencing support */ 125a8c21a54SThe etnaviv authors u32 next_fence; 126a8c21a54SThe etnaviv authors u32 active_fence; 127a8c21a54SThe etnaviv authors u32 completed_fence; 128a8c21a54SThe etnaviv authors u32 retired_fence; 129a8c21a54SThe etnaviv authors wait_queue_head_t fence_event; 13076bf0db5SChristian König u64 fence_context; 131a8c21a54SThe etnaviv authors spinlock_t fence_spinlock; 132a8c21a54SThe etnaviv authors 133a8c21a54SThe etnaviv authors /* worker for handling active-list retiring: */ 134a8c21a54SThe etnaviv authors struct work_struct retire_work; 135a8c21a54SThe etnaviv authors 136a8c21a54SThe etnaviv authors void __iomem *mmio; 137a8c21a54SThe etnaviv authors int irq; 138a8c21a54SThe etnaviv authors 139a8c21a54SThe etnaviv authors struct etnaviv_iommu *mmu; 140e66774ddSLucas Stach struct etnaviv_cmdbuf_suballoc *cmdbuf_suballoc; 141a8c21a54SThe etnaviv authors 142a8c21a54SThe etnaviv authors /* Power Control: */ 143a8c21a54SThe etnaviv authors struct clk *clk_bus; 144a8c21a54SThe etnaviv authors struct clk *clk_core; 145a8c21a54SThe etnaviv authors struct clk *clk_shader; 146a8c21a54SThe etnaviv authors 147a8c21a54SThe etnaviv authors /* Hang Detction: */ 148a8c21a54SThe etnaviv authors #define DRM_ETNAVIV_HANGCHECK_PERIOD 500 /* in ms */ 149a8c21a54SThe etnaviv authors #define DRM_ETNAVIV_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_ETNAVIV_HANGCHECK_PERIOD) 150a8c21a54SThe etnaviv authors struct timer_list hangcheck_timer; 151a8c21a54SThe etnaviv authors u32 hangcheck_fence; 152a8c21a54SThe etnaviv authors u32 hangcheck_dma_addr; 153a8c21a54SThe etnaviv authors struct work_struct recover_work; 154bcdfb5e5SRussell King unsigned int freq_scale; 155a8c21a54SThe etnaviv authors }; 156a8c21a54SThe etnaviv authors 157a8c21a54SThe etnaviv authors static inline void gpu_write(struct etnaviv_gpu *gpu, u32 reg, u32 data) 158a8c21a54SThe etnaviv authors { 159a8c21a54SThe etnaviv authors etnaviv_writel(data, gpu->mmio + reg); 160a8c21a54SThe etnaviv authors } 161a8c21a54SThe etnaviv authors 162a8c21a54SThe etnaviv authors static inline u32 gpu_read(struct etnaviv_gpu *gpu, u32 reg) 163a8c21a54SThe etnaviv authors { 164a8c21a54SThe etnaviv authors return etnaviv_readl(gpu->mmio + reg); 165a8c21a54SThe etnaviv authors } 166a8c21a54SThe etnaviv authors 167a8c21a54SThe etnaviv authors static inline bool fence_completed(struct etnaviv_gpu *gpu, u32 fence) 168a8c21a54SThe etnaviv authors { 169a8c21a54SThe etnaviv authors return fence_after_eq(gpu->completed_fence, fence); 170a8c21a54SThe etnaviv authors } 171a8c21a54SThe etnaviv authors 172a8c21a54SThe etnaviv authors static inline bool fence_retired(struct etnaviv_gpu *gpu, u32 fence) 173a8c21a54SThe etnaviv authors { 174a8c21a54SThe etnaviv authors return fence_after_eq(gpu->retired_fence, fence); 175a8c21a54SThe etnaviv authors } 176a8c21a54SThe etnaviv authors 177a8c21a54SThe etnaviv authors int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value); 178a8c21a54SThe etnaviv authors 179a8c21a54SThe etnaviv authors int etnaviv_gpu_init(struct etnaviv_gpu *gpu); 180a8c21a54SThe etnaviv authors 181a8c21a54SThe etnaviv authors #ifdef CONFIG_DEBUG_FS 182a8c21a54SThe etnaviv authors int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m); 183a8c21a54SThe etnaviv authors #endif 184a8c21a54SThe etnaviv authors 185a8c21a54SThe etnaviv authors int etnaviv_gpu_fence_sync_obj(struct etnaviv_gem_object *etnaviv_obj, 1869ad59feaSPhilipp Zabel unsigned int context, bool exclusive, bool implicit); 187a8c21a54SThe etnaviv authors 188a8c21a54SThe etnaviv authors void etnaviv_gpu_retire(struct etnaviv_gpu *gpu); 189a8c21a54SThe etnaviv authors int etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu *gpu, 190a8c21a54SThe etnaviv authors u32 fence, struct timespec *timeout); 191a8c21a54SThe etnaviv authors int etnaviv_gpu_wait_obj_inactive(struct etnaviv_gpu *gpu, 192a8c21a54SThe etnaviv authors struct etnaviv_gem_object *etnaviv_obj, struct timespec *timeout); 193a8c21a54SThe etnaviv authors int etnaviv_gpu_submit(struct etnaviv_gpu *gpu, 194a8c21a54SThe etnaviv authors struct etnaviv_gem_submit *submit, struct etnaviv_cmdbuf *cmdbuf); 195a8c21a54SThe etnaviv authors int etnaviv_gpu_pm_get_sync(struct etnaviv_gpu *gpu); 196a8c21a54SThe etnaviv authors void etnaviv_gpu_pm_put(struct etnaviv_gpu *gpu); 197b88163e3SLucas Stach int etnaviv_gpu_wait_idle(struct etnaviv_gpu *gpu, unsigned int timeout_ms); 198229855b6SLucas Stach void etnaviv_gpu_start_fe(struct etnaviv_gpu *gpu, u32 address, u16 prefetch); 199a8c21a54SThe etnaviv authors 200a8c21a54SThe etnaviv authors extern struct platform_driver etnaviv_gpu_driver; 201a8c21a54SThe etnaviv authors 202a8c21a54SThe etnaviv authors #endif /* __ETNAVIV_GPU_H__ */ 203