3 * (C) COPYRIGHT 2011-2016 ARM Limited. All rights reserved.
5 * This program is free software and is provided to you under the terms of the
6 * GNU General Public License version 2 as published by the Free Software
7 * Foundation, and any use by you of this program is subject to the terms
10 * A copy of the licence is included with the program, and can also be obtained
11 * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12 * Boston, MA 02110-1301, USA.
18 #include <linux/ioport.h>
19 #include <linux/thermal.h>
20 #include <mali_kbase.h>
21 #include <mali_kbase_defs.h>
22 #include <mali_kbase_config.h>
23 #include <mali_kbase_smc.h>
25 /* Versatile Express (VE) Juno Development Platform */
27 #define HARD_RESET_AT_POWER_OFF 0
30 static struct kbase_io_resources io_resources = {
36 .end = 0x2D000000 + (4096 * 4) - 1}
40 static int pm_callback_power_on(struct kbase_device *kbdev)
42 /* Nothing is needed on VExpress, but we may have destroyed GPU state (if the below HARD_RESET code is active) */
46 static void pm_callback_power_off(struct kbase_device *kbdev)
48 #if HARD_RESET_AT_POWER_OFF
49 /* Cause a GPU hard reset to test whether we have actually idled the GPU
50 * and that we properly reconfigure the GPU on power up.
51 * Usually this would be dangerous, but if the GPU is working correctly it should
52 * be completely safe as the GPU should not be active at this point.
53 * However this is disabled normally because it will most likely interfere with
56 KBASE_TRACE_ADD(kbdev, CORE_GPU_HARD_RESET, NULL, NULL, 0u, 0);
57 kbase_os_reg_write(kbdev, GPU_CONTROL_REG(GPU_COMMAND), GPU_COMMAND_HARD_RESET);
61 struct kbase_pm_callback_conf pm_callbacks = {
62 .power_on_callback = pm_callback_power_on,
63 .power_off_callback = pm_callback_power_off,
64 .power_suspend_callback = NULL,
65 .power_resume_callback = NULL
69 * Juno Protected Mode integration
72 /* SMC Function Numbers */
73 #define JUNO_SMC_PROTECTED_ENTER_FUNC 0xff06
74 #define JUNO_SMC_PROTECTED_RESET_FUNC 0xff07
76 static int juno_protected_mode_enter(struct kbase_device *kbdev)
78 /* T62X in SoC detected */
79 u64 ret = kbase_invoke_smc(SMC_OEN_SIP,
80 JUNO_SMC_PROTECTED_ENTER_FUNC, false,
85 /* TODO: Remove these externs, reset should should be done by the firmware */
86 extern void kbase_reg_write(struct kbase_device *kbdev, u16 offset, u32 value,
87 struct kbase_context *kctx);
89 extern u32 kbase_reg_read(struct kbase_device *kbdev, u16 offset,
90 struct kbase_context *kctx);
92 static int juno_protected_mode_reset(struct kbase_device *kbdev)
95 /* T62X in SoC detected */
96 u64 ret = kbase_invoke_smc(SMC_OEN_SIP,
97 JUNO_SMC_PROTECTED_RESET_FUNC, false,
100 /* TODO: Remove this reset, it should be done by the firmware */
101 kbase_reg_write(kbdev, GPU_CONTROL_REG(GPU_COMMAND),
102 GPU_COMMAND_HARD_RESET, NULL);
104 while ((kbase_reg_read(kbdev, GPU_CONTROL_REG(GPU_IRQ_RAWSTAT), NULL)
105 & RESET_COMPLETED) != RESET_COMPLETED)
111 static bool juno_protected_mode_supported(struct kbase_device *kbdev)
113 u32 gpu_id = kbdev->gpu_props.props.raw_props.gpu_id;
116 * Protected mode is only supported for the built in GPU
117 * _and_ only if the right firmware is running.
119 * Given that at init time the GPU is not powered up the
120 * juno_protected_mode_reset function can't be used as
121 * is needs to access GPU registers.
122 * However, although we don't want the GPU to boot into
123 * protected mode we know a GPU reset will be done after
124 * this function is called so although we set the GPU to
125 * protected mode it will exit protected mode before the
126 * driver is ready to run work.
128 if (gpu_id == GPU_ID_MAKE(GPU_ID_PI_T62X, 0, 1, 0) &&
129 (kbdev->reg_start == 0x2d000000))
130 return juno_protected_mode_enter(kbdev) == 0;
135 struct kbase_protected_ops juno_protected_ops = {
136 .protected_mode_enter = juno_protected_mode_enter,
137 .protected_mode_reset = juno_protected_mode_reset,
138 .protected_mode_supported = juno_protected_mode_supported,
141 static struct kbase_platform_config versatile_platform_config = {
143 .io_resources = &io_resources
147 struct kbase_platform_config *kbase_get_platform_config(void)
149 return &versatile_platform_config;
152 int kbase_platform_early_init(void)
154 /* Nothing needed at this stage */