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 80 enum lima_gpu_id id; 81 u32 gp_version; 82 u32 pp_version; 83 int num_pp; 84 85 void __iomem *iomem; 86 struct clk *clk_bus; 87 struct clk *clk_gpu; 88 struct reset_control *reset; 89 struct regulator *regulator; 90 91 struct lima_ip ip[lima_ip_num]; 92 struct lima_sched_pipe pipe[lima_pipe_num]; 93 94 struct lima_vm *empty_vm; 95 uint64_t va_start; 96 uint64_t va_end; 97 98 u32 *dlbu_cpu; 99 dma_addr_t dlbu_dma; 100 101 struct lima_devfreq devfreq; 102 103 /* debug info */ 104 struct lima_dump_head dump; 105 struct list_head error_task_list; 106 struct mutex error_task_list_lock; 107 }; 108 109 static inline struct lima_device * 110 to_lima_dev(struct drm_device *dev) 111 { 112 return dev->dev_private; 113 } 114 115 int lima_device_init(struct lima_device *ldev); 116 void lima_device_fini(struct lima_device *ldev); 117 118 const char *lima_ip_name(struct lima_ip *ip); 119 120 typedef int (*lima_poll_func_t)(struct lima_ip *); 121 122 static inline int lima_poll_timeout(struct lima_ip *ip, lima_poll_func_t func, 123 int sleep_us, int timeout_us) 124 { 125 ktime_t timeout = ktime_add_us(ktime_get(), timeout_us); 126 127 might_sleep_if(sleep_us); 128 while (1) { 129 if (func(ip)) 130 return 0; 131 132 if (timeout_us && ktime_compare(ktime_get(), timeout) > 0) 133 return -ETIMEDOUT; 134 135 if (sleep_us) 136 usleep_range((sleep_us >> 2) + 1, sleep_us); 137 } 138 return 0; 139 } 140 141 #endif 142