1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2017 The Linux Foundation. All rights reserved. */
7 #include <linux/completion.h>
8 #include <linux/iopoll.h>
9 #include <linux/interrupt.h>
10 #include <linux/notifier.h>
15 struct drm_gem_object *obj;
22 * These define the different GMU wake up options - these define how both the
23 * CPU and the GMU bring up the hardware
26 /* THe GMU has already been booted and the rentention registers are active */
27 #define GMU_WARM_BOOT 0
29 /* the GMU is coming up for the first time or back from a power collapse */
30 #define GMU_COLD_BOOT 1
33 * These define the level of control that the GMU has - the higher the number
34 * the more things that the GMU hardware controls on its own.
37 /* The GMU does not do any idle state management */
38 #define GMU_IDLE_STATE_ACTIVE 0
40 /* The GMU manages SPTP power collapse */
41 #define GMU_IDLE_STATE_SPTP 2
43 /* The GMU does automatic IFPC (intra-frame power collapse) */
44 #define GMU_IDLE_STATE_IFPC 3
49 /* For serializing communication with the GMU: */
52 struct msm_gem_address_space *aspace;
65 struct a6xx_gmu_bo hfi;
66 struct a6xx_gmu_bo debug;
67 struct a6xx_gmu_bo icache;
68 struct a6xx_gmu_bo dcache;
69 struct a6xx_gmu_bo dummy;
70 struct a6xx_gmu_bo log;
73 struct clk_bulk_data *clocks;
77 /* current performance index set externally */
78 int current_perf_index;
81 unsigned long gpu_freqs[16];
85 unsigned long gmu_freqs[4];
90 struct a6xx_hfi_queue queues[2];
94 bool legacy; /* a618 or a630 */
96 /* For power domain callback */
97 struct notifier_block pd_nb;
98 struct completion pd_gate;
101 static inline u32 gmu_read(struct a6xx_gmu *gmu, u32 offset)
103 return msm_readl(gmu->mmio + (offset << 2));
106 static inline void gmu_write(struct a6xx_gmu *gmu, u32 offset, u32 value)
108 msm_writel(value, gmu->mmio + (offset << 2));
112 gmu_write_bulk(struct a6xx_gmu *gmu, u32 offset, const u32 *data, u32 size)
114 memcpy_toio(gmu->mmio + (offset << 2), data, size);
118 static inline void gmu_rmw(struct a6xx_gmu *gmu, u32 reg, u32 mask, u32 or)
120 u32 val = gmu_read(gmu, reg);
124 gmu_write(gmu, reg, val | or);
127 static inline u64 gmu_read64(struct a6xx_gmu *gmu, u32 lo, u32 hi)
131 val = (u64) msm_readl(gmu->mmio + (lo << 2));
132 val |= ((u64) msm_readl(gmu->mmio + (hi << 2)) << 32);
137 #define gmu_poll_timeout(gmu, addr, val, cond, interval, timeout) \
138 readl_poll_timeout((gmu)->mmio + ((addr) << 2), val, cond, \
141 static inline u32 gmu_read_rscc(struct a6xx_gmu *gmu, u32 offset)
143 return msm_readl(gmu->rscc + (offset << 2));
146 static inline void gmu_write_rscc(struct a6xx_gmu *gmu, u32 offset, u32 value)
148 msm_writel(value, gmu->rscc + (offset << 2));
151 #define gmu_poll_timeout_rscc(gmu, addr, val, cond, interval, timeout) \
152 readl_poll_timeout((gmu)->rscc + ((addr) << 2), val, cond, \
156 * These are the available OOB (out of band requests) to the GMU where "out of
157 * band" means that the CPU talks to the GMU directly and not through HFI.
158 * Normally this works by writing a ITCM/DTCM register and then triggering a
159 * interrupt (the "request" bit) and waiting for an acknowledgment (the "ack"
160 * bit). The state is cleared by writing the "clear' bit to the GMU interrupt.
162 * These are used to force the GMU/GPU to stay on during a critical sequence or
163 * for hardware workarounds.
166 enum a6xx_gmu_oob_state {
168 * Let the GMU know that a boot or slumber operation has started. The value in
169 * REG_A6XX_GMU_BOOT_SLUMBER_OPTION lets the GMU know which operation we are
172 GMU_OOB_BOOT_SLUMBER = 0,
174 * Let the GMU know to not turn off any GPU registers while the CPU is in a
179 * Set a new power level for the GPU when the CPU is doing frequency scaling
183 * Used to keep the GPU on for CPU-side reads of performance counters.
185 GMU_OOB_PERFCOUNTER_SET,
188 void a6xx_hfi_init(struct a6xx_gmu *gmu);
189 int a6xx_hfi_start(struct a6xx_gmu *gmu, int boot_state);
190 void a6xx_hfi_stop(struct a6xx_gmu *gmu);
191 int a6xx_hfi_send_prep_slumber(struct a6xx_gmu *gmu);
192 int a6xx_hfi_set_freq(struct a6xx_gmu *gmu, int index);
194 bool a6xx_gmu_gx_is_on(struct a6xx_gmu *gmu);
195 bool a6xx_gmu_sptprac_is_on(struct a6xx_gmu *gmu);