1 // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
2 /*
3 *
4 * (C) COPYRIGHT 2014-2016, 2018, 2020-2022 ARM Limited. All rights reserved.
5 *
6 * This program is free software and is provided to you under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation, and any use by you of this program is subject to the terms
9 * of such GNU license.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you can access it online at
18 * http://www.gnu.org/licenses/gpl-2.0.html.
19 *
20 */
21
22 #include "backend/gpu/mali_kbase_cache_policy_backend.h"
23 #include <device/mali_kbase_device.h>
24
25 /**
26 * kbasep_amba_register_present() - Check AMBA_<> register is present
27 * in the GPU.
28 * @kbdev: Device pointer
29 *
30 * Note: Only for arch version 12.x.1 onwards.
31 *
32 * Return: true if AMBA_FEATURES/ENABLE registers are present.
33 */
kbasep_amba_register_present(struct kbase_device * kbdev)34 static bool kbasep_amba_register_present(struct kbase_device *kbdev)
35 {
36 return (ARCH_MAJOR_REV_REG(kbdev->gpu_props.props.raw_props.gpu_id) >=
37 GPU_ID2_ARCH_MAJOR_REV_MAKE(12, 1));
38 }
39
kbase_cache_set_coherency_mode(struct kbase_device * kbdev,u32 mode)40 void kbase_cache_set_coherency_mode(struct kbase_device *kbdev,
41 u32 mode)
42 {
43 kbdev->current_gpu_coherency_mode = mode;
44
45 if (kbasep_amba_register_present(kbdev)) {
46 u32 val = kbase_reg_read(kbdev, AMBA_ENABLE);
47
48 val = AMBA_ENABLE_COHERENCY_PROTOCOL_SET(val, mode);
49 kbase_reg_write(kbdev, AMBA_ENABLE, val);
50 } else
51 kbase_reg_write(kbdev, COHERENCY_ENABLE, mode);
52 }
53
kbase_cache_get_coherency_features(struct kbase_device * kbdev)54 u32 kbase_cache_get_coherency_features(struct kbase_device *kbdev)
55 {
56 u32 coherency_features;
57
58 if (kbasep_amba_register_present(kbdev))
59 coherency_features =
60 kbase_reg_read(kbdev, GPU_CONTROL_REG(AMBA_FEATURES));
61 else
62 coherency_features = kbase_reg_read(
63 kbdev, GPU_CONTROL_REG(COHERENCY_FEATURES));
64
65 return coherency_features;
66 }
67
kbase_amba_set_memory_cache_support(struct kbase_device * kbdev,bool enable)68 void kbase_amba_set_memory_cache_support(struct kbase_device *kbdev,
69 bool enable)
70 {
71 if (kbasep_amba_register_present(kbdev)) {
72 u32 val = kbase_reg_read(kbdev, AMBA_ENABLE);
73
74 val = AMBA_ENABLE_MEMORY_CACHE_SUPPORT_SET(val, enable);
75 kbase_reg_write(kbdev, AMBA_ENABLE, val);
76
77 } else {
78 WARN(1, "memory_cache_support not supported");
79 }
80 }
81
kbase_amba_set_invalidate_hint(struct kbase_device * kbdev,bool enable)82 void kbase_amba_set_invalidate_hint(struct kbase_device *kbdev, bool enable)
83 {
84 if (kbasep_amba_register_present(kbdev)) {
85 u32 val = kbase_reg_read(kbdev, AMBA_ENABLE);
86
87 val = AMBA_ENABLE_INVALIDATE_HINT_SET(val, enable);
88 kbase_reg_write(kbdev, AMBA_ENABLE, val);
89 } else {
90 WARN(1, "invalidate_hint not supported");
91 }
92 }
93