1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2017 The Linux Foundation. All rights reserved. */
7 #include <linux/iopoll.h>
8 #include <linux/interrupt.h>
13 struct drm_gem_object *obj;
20 * These define the different GMU wake up options - these define how both the
21 * CPU and the GMU bring up the hardware
24 /* THe GMU has already been booted and the rentention registers are active */
25 #define GMU_WARM_BOOT 0
27 /* the GMU is coming up for the first time or back from a power collapse */
28 #define GMU_COLD_BOOT 1
31 * These define the level of control that the GMU has - the higher the number
32 * the more things that the GMU hardware controls on its own.
35 /* The GMU does not do any idle state management */
36 #define GMU_IDLE_STATE_ACTIVE 0
38 /* The GMU manages SPTP power collapse */
39 #define GMU_IDLE_STATE_SPTP 2
41 /* The GMU does automatic IFPC (intra-frame power collapse) */
42 #define GMU_IDLE_STATE_IFPC 3
47 struct msm_gem_address_space *aspace;
59 struct a6xx_gmu_bo hfi;
60 struct a6xx_gmu_bo debug;
61 struct a6xx_gmu_bo icache;
62 struct a6xx_gmu_bo dcache;
63 struct a6xx_gmu_bo dummy;
64 struct a6xx_gmu_bo log;
67 struct clk_bulk_data *clocks;
71 /* current performance index set externally */
72 int current_perf_index;
75 unsigned long gpu_freqs[16];
79 unsigned long gmu_freqs[4];
84 struct a6xx_hfi_queue queues[2];
88 bool legacy; /* a618 or a630 */
91 static inline u32 gmu_read(struct a6xx_gmu *gmu, u32 offset)
93 return msm_readl(gmu->mmio + (offset << 2));
96 static inline void gmu_write(struct a6xx_gmu *gmu, u32 offset, u32 value)
98 return msm_writel(value, gmu->mmio + (offset << 2));
102 gmu_write_bulk(struct a6xx_gmu *gmu, u32 offset, const u32 *data, u32 size)
104 memcpy_toio(gmu->mmio + (offset << 2), data, size);
108 static inline void gmu_rmw(struct a6xx_gmu *gmu, u32 reg, u32 mask, u32 or)
110 u32 val = gmu_read(gmu, reg);
114 gmu_write(gmu, reg, val | or);
117 static inline u64 gmu_read64(struct a6xx_gmu *gmu, u32 lo, u32 hi)
121 val = (u64) msm_readl(gmu->mmio + (lo << 2));
122 val |= ((u64) msm_readl(gmu->mmio + (hi << 2)) << 32);
127 #define gmu_poll_timeout(gmu, addr, val, cond, interval, timeout) \
128 readl_poll_timeout((gmu)->mmio + ((addr) << 2), val, cond, \
131 static inline u32 gmu_read_rscc(struct a6xx_gmu *gmu, u32 offset)
133 return msm_readl(gmu->rscc + (offset << 2));
136 static inline void gmu_write_rscc(struct a6xx_gmu *gmu, u32 offset, u32 value)
138 return msm_writel(value, gmu->rscc + (offset << 2));
141 #define gmu_poll_timeout_rscc(gmu, addr, val, cond, interval, timeout) \
142 readl_poll_timeout((gmu)->rscc + ((addr) << 2), val, cond, \
146 * These are the available OOB (out of band requests) to the GMU where "out of
147 * band" means that the CPU talks to the GMU directly and not through HFI.
148 * Normally this works by writing a ITCM/DTCM register and then triggering a
149 * interrupt (the "request" bit) and waiting for an acknowledgment (the "ack"
150 * bit). The state is cleared by writing the "clear' bit to the GMU interrupt.
152 * These are used to force the GMU/GPU to stay on during a critical sequence or
153 * for hardware workarounds.
156 enum a6xx_gmu_oob_state {
158 * Let the GMU know that a boot or slumber operation has started. The value in
159 * REG_A6XX_GMU_BOOT_SLUMBER_OPTION lets the GMU know which operation we are
162 GMU_OOB_BOOT_SLUMBER = 0,
164 * Let the GMU know to not turn off any GPU registers while the CPU is in a
169 * Set a new power level for the GPU when the CPU is doing frequency scaling
173 * Used to keep the GPU on for CPU-side reads of performance counters.
175 GMU_OOB_PERFCOUNTER_SET,
178 void a6xx_hfi_init(struct a6xx_gmu *gmu);
179 int a6xx_hfi_start(struct a6xx_gmu *gmu, int boot_state);
180 void a6xx_hfi_stop(struct a6xx_gmu *gmu);
181 int a6xx_hfi_send_prep_slumber(struct a6xx_gmu *gmu);
182 int a6xx_hfi_set_freq(struct a6xx_gmu *gmu, int index);
184 bool a6xx_gmu_gx_is_on(struct a6xx_gmu *gmu);
185 bool a6xx_gmu_sptprac_is_on(struct a6xx_gmu *gmu);