18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2015-2018 Etnaviv Project
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef __ETNAVIV_GPU_H__
78c2ecf20Sopenharmony_ci#define __ETNAVIV_GPU_H__
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include "etnaviv_cmdbuf.h"
108c2ecf20Sopenharmony_ci#include "etnaviv_gem.h"
118c2ecf20Sopenharmony_ci#include "etnaviv_mmu.h"
128c2ecf20Sopenharmony_ci#include "etnaviv_drv.h"
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cistruct etnaviv_gem_submit;
158c2ecf20Sopenharmony_cistruct etnaviv_vram_mapping;
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistruct etnaviv_chip_identity {
188c2ecf20Sopenharmony_ci	u32 model;
198c2ecf20Sopenharmony_ci	u32 revision;
208c2ecf20Sopenharmony_ci	u32 product_id;
218c2ecf20Sopenharmony_ci	u32 customer_id;
228c2ecf20Sopenharmony_ci	u32 eco_id;
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci	/* Supported feature fields. */
258c2ecf20Sopenharmony_ci	u32 features;
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci	/* Supported minor feature fields. */
288c2ecf20Sopenharmony_ci	u32 minor_features0;
298c2ecf20Sopenharmony_ci	u32 minor_features1;
308c2ecf20Sopenharmony_ci	u32 minor_features2;
318c2ecf20Sopenharmony_ci	u32 minor_features3;
328c2ecf20Sopenharmony_ci	u32 minor_features4;
338c2ecf20Sopenharmony_ci	u32 minor_features5;
348c2ecf20Sopenharmony_ci	u32 minor_features6;
358c2ecf20Sopenharmony_ci	u32 minor_features7;
368c2ecf20Sopenharmony_ci	u32 minor_features8;
378c2ecf20Sopenharmony_ci	u32 minor_features9;
388c2ecf20Sopenharmony_ci	u32 minor_features10;
398c2ecf20Sopenharmony_ci	u32 minor_features11;
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	/* Number of streams supported. */
428c2ecf20Sopenharmony_ci	u32 stream_count;
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	/* Total number of temporary registers per thread. */
458c2ecf20Sopenharmony_ci	u32 register_max;
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	/* Maximum number of threads. */
488c2ecf20Sopenharmony_ci	u32 thread_count;
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	/* Number of shader cores. */
518c2ecf20Sopenharmony_ci	u32 shader_core_count;
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci	/* Size of the vertex cache. */
548c2ecf20Sopenharmony_ci	u32 vertex_cache_size;
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	/* Number of entries in the vertex output buffer. */
578c2ecf20Sopenharmony_ci	u32 vertex_output_buffer_size;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	/* Number of pixel pipes. */
608c2ecf20Sopenharmony_ci	u32 pixel_pipes;
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	/* Number of instructions. */
638c2ecf20Sopenharmony_ci	u32 instruction_count;
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	/* Number of constants. */
668c2ecf20Sopenharmony_ci	u32 num_constants;
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	/* Buffer size */
698c2ecf20Sopenharmony_ci	u32 buffer_size;
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	/* Number of varyings */
728c2ecf20Sopenharmony_ci	u8 varyings_count;
738c2ecf20Sopenharmony_ci};
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cienum etnaviv_sec_mode {
768c2ecf20Sopenharmony_ci	ETNA_SEC_NONE = 0,
778c2ecf20Sopenharmony_ci	ETNA_SEC_KERNEL,
788c2ecf20Sopenharmony_ci	ETNA_SEC_TZ
798c2ecf20Sopenharmony_ci};
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_cistruct etnaviv_event {
828c2ecf20Sopenharmony_ci	struct dma_fence *fence;
838c2ecf20Sopenharmony_ci	struct etnaviv_gem_submit *submit;
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci	void (*sync_point)(struct etnaviv_gpu *gpu, struct etnaviv_event *event);
868c2ecf20Sopenharmony_ci};
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_cistruct etnaviv_cmdbuf_suballoc;
898c2ecf20Sopenharmony_cistruct regulator;
908c2ecf20Sopenharmony_cistruct clk;
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#define ETNA_NR_EVENTS 30
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cistruct etnaviv_gpu {
958c2ecf20Sopenharmony_ci	struct drm_device *drm;
968c2ecf20Sopenharmony_ci	struct thermal_cooling_device *cooling;
978c2ecf20Sopenharmony_ci	struct device *dev;
988c2ecf20Sopenharmony_ci	struct mutex lock;
998c2ecf20Sopenharmony_ci	struct etnaviv_chip_identity identity;
1008c2ecf20Sopenharmony_ci	enum etnaviv_sec_mode sec_mode;
1018c2ecf20Sopenharmony_ci	struct workqueue_struct *wq;
1028c2ecf20Sopenharmony_ci	struct drm_gpu_scheduler sched;
1038c2ecf20Sopenharmony_ci	bool initialized;
1048c2ecf20Sopenharmony_ci	bool fe_running;
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	/* 'ring'-buffer: */
1078c2ecf20Sopenharmony_ci	struct etnaviv_cmdbuf buffer;
1088c2ecf20Sopenharmony_ci	int exec_state;
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	/* event management: */
1118c2ecf20Sopenharmony_ci	DECLARE_BITMAP(event_bitmap, ETNA_NR_EVENTS);
1128c2ecf20Sopenharmony_ci	struct etnaviv_event event[ETNA_NR_EVENTS];
1138c2ecf20Sopenharmony_ci	struct completion event_free;
1148c2ecf20Sopenharmony_ci	spinlock_t event_spinlock;
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci	u32 idle_mask;
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	/* Fencing support */
1198c2ecf20Sopenharmony_ci	struct mutex fence_lock;
1208c2ecf20Sopenharmony_ci	struct idr fence_idr;
1218c2ecf20Sopenharmony_ci	u32 next_fence;
1228c2ecf20Sopenharmony_ci	u32 completed_fence;
1238c2ecf20Sopenharmony_ci	wait_queue_head_t fence_event;
1248c2ecf20Sopenharmony_ci	u64 fence_context;
1258c2ecf20Sopenharmony_ci	spinlock_t fence_spinlock;
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci	/* worker for handling 'sync' points: */
1288c2ecf20Sopenharmony_ci	struct work_struct sync_point_work;
1298c2ecf20Sopenharmony_ci	int sync_point_event;
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	/* hang detection */
1328c2ecf20Sopenharmony_ci	u32 hangcheck_dma_addr;
1338c2ecf20Sopenharmony_ci	u32 hangcheck_fence;
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci	void __iomem *mmio;
1368c2ecf20Sopenharmony_ci	int irq;
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	struct etnaviv_iommu_context *mmu_context;
1398c2ecf20Sopenharmony_ci	unsigned int flush_seq;
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	/* Power Control: */
1428c2ecf20Sopenharmony_ci	struct clk *clk_bus;
1438c2ecf20Sopenharmony_ci	struct clk *clk_reg;
1448c2ecf20Sopenharmony_ci	struct clk *clk_core;
1458c2ecf20Sopenharmony_ci	struct clk *clk_shader;
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	unsigned int freq_scale;
1488c2ecf20Sopenharmony_ci	unsigned long base_rate_core;
1498c2ecf20Sopenharmony_ci	unsigned long base_rate_shader;
1508c2ecf20Sopenharmony_ci};
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_cistatic inline void gpu_write(struct etnaviv_gpu *gpu, u32 reg, u32 data)
1538c2ecf20Sopenharmony_ci{
1548c2ecf20Sopenharmony_ci	writel(data, gpu->mmio + reg);
1558c2ecf20Sopenharmony_ci}
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_cistatic inline u32 gpu_read(struct etnaviv_gpu *gpu, u32 reg)
1588c2ecf20Sopenharmony_ci{
1598c2ecf20Sopenharmony_ci	return readl(gpu->mmio + reg);
1608c2ecf20Sopenharmony_ci}
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ciint etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value);
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ciint etnaviv_gpu_init(struct etnaviv_gpu *gpu);
1658c2ecf20Sopenharmony_cibool etnaviv_fill_identity_from_hwdb(struct etnaviv_gpu *gpu);
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS
1688c2ecf20Sopenharmony_ciint etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m);
1698c2ecf20Sopenharmony_ci#endif
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_civoid etnaviv_gpu_recover_hang(struct etnaviv_gpu *gpu);
1728c2ecf20Sopenharmony_civoid etnaviv_gpu_retire(struct etnaviv_gpu *gpu);
1738c2ecf20Sopenharmony_ciint etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu *gpu,
1748c2ecf20Sopenharmony_ci	u32 fence, struct drm_etnaviv_timespec *timeout);
1758c2ecf20Sopenharmony_ciint etnaviv_gpu_wait_obj_inactive(struct etnaviv_gpu *gpu,
1768c2ecf20Sopenharmony_ci	struct etnaviv_gem_object *etnaviv_obj,
1778c2ecf20Sopenharmony_ci	struct drm_etnaviv_timespec *timeout);
1788c2ecf20Sopenharmony_cistruct dma_fence *etnaviv_gpu_submit(struct etnaviv_gem_submit *submit);
1798c2ecf20Sopenharmony_ciint etnaviv_gpu_pm_get_sync(struct etnaviv_gpu *gpu);
1808c2ecf20Sopenharmony_civoid etnaviv_gpu_pm_put(struct etnaviv_gpu *gpu);
1818c2ecf20Sopenharmony_ciint etnaviv_gpu_wait_idle(struct etnaviv_gpu *gpu, unsigned int timeout_ms);
1828c2ecf20Sopenharmony_civoid etnaviv_gpu_start_fe(struct etnaviv_gpu *gpu, u32 address, u16 prefetch);
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ciextern struct platform_driver etnaviv_gpu_driver;
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci#endif /* __ETNAVIV_GPU_H__ */
187