1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */ 2 /* Copyright 2018-2019 Qiang Yu <yuq825@gmail.com> */ 3 4 #ifndef __LIMA_DEVICE_H__ 5 #define __LIMA_DEVICE_H__ 6 7 #include <drm/drm_device.h> 8 #include <linux/delay.h> 9 #include <linux/list.h> 10 #include <linux/mutex.h> 11 12 #include "lima_sched.h" 13 #include "lima_dump.h" 14 #include "lima_devfreq.h" 15 16 enum lima_gpu_id { 17 lima_gpu_mali400 = 0, 18 lima_gpu_mali450, 19 lima_gpu_num, 20 }; 21 22 enum lima_ip_id { 23 lima_ip_pmu, 24 lima_ip_gpmmu, 25 lima_ip_ppmmu0, 26 lima_ip_ppmmu1, 27 lima_ip_ppmmu2, 28 lima_ip_ppmmu3, 29 lima_ip_ppmmu4, 30 lima_ip_ppmmu5, 31 lima_ip_ppmmu6, 32 lima_ip_ppmmu7, 33 lima_ip_gp, 34 lima_ip_pp0, 35 lima_ip_pp1, 36 lima_ip_pp2, 37 lima_ip_pp3, 38 lima_ip_pp4, 39 lima_ip_pp5, 40 lima_ip_pp6, 41 lima_ip_pp7, 42 lima_ip_l2_cache0, 43 lima_ip_l2_cache1, 44 lima_ip_l2_cache2, 45 lima_ip_dlbu, 46 lima_ip_bcast, 47 lima_ip_pp_bcast, 48 lima_ip_ppmmu_bcast, 49 lima_ip_num, 50 }; 51 52 struct lima_device; 53 54 struct lima_ip { 55 struct lima_device *dev; 56 enum lima_ip_id id; 57 bool present; 58 59 void __iomem *iomem; 60 int irq; 61 62 union { 63 /* gp/pp */ 64 bool async_reset; 65 /* l2 cache */ 66 spinlock_t lock; 67 } data; 68 }; 69 70 enum lima_pipe_id { 71 lima_pipe_gp, 72 lima_pipe_pp, 73 lima_pipe_num, 74 }; 75 76 struct lima_device { 77 struct device *dev; 78 struct drm_device *ddev; 79 struct platform_device *pdev; 80 81 enum lima_gpu_id id; 82 u32 gp_version; 83 u32 pp_version; 84 int num_pp; 85 86 void __iomem *iomem; 87 struct clk *clk_bus; 88 struct clk *clk_gpu; 89 struct reset_control *reset; 90 struct regulator *regulator; 91 92 struct lima_ip ip[lima_ip_num]; 93 struct lima_sched_pipe pipe[lima_pipe_num]; 94 95 struct lima_vm *empty_vm; 96 uint64_t va_start; 97 uint64_t va_end; 98 99 u32 *dlbu_cpu; 100 dma_addr_t dlbu_dma; 101 102 struct lima_devfreq devfreq; 103 104 /* debug info */ 105 struct lima_dump_head dump; 106 struct list_head error_task_list; 107 struct mutex error_task_list_lock; 108 }; 109 110 static inline struct lima_device * 111 to_lima_dev(struct drm_device *dev) 112 { 113 return dev->dev_private; 114 } 115 116 int lima_device_init(struct lima_device *ldev); 117 void lima_device_fini(struct lima_device *ldev); 118 119 const char *lima_ip_name(struct lima_ip *ip); 120 121 typedef int (*lima_poll_func_t)(struct lima_ip *); 122 123 static inline int lima_poll_timeout(struct lima_ip *ip, lima_poll_func_t func, 124 int sleep_us, int timeout_us) 125 { 126 ktime_t timeout = ktime_add_us(ktime_get(), timeout_us); 127 128 might_sleep_if(sleep_us); 129 while (1) { 130 if (func(ip)) 131 return 0; 132 133 if (timeout_us && ktime_compare(ktime_get(), timeout) > 0) 134 return -ETIMEDOUT; 135 136 if (sleep_us) 137 usleep_range((sleep_us >> 2) + 1, sleep_us); 138 } 139 return 0; 140 } 141 142 #endif 143