forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_firmware_cfg.c
....@@ -1,7 +1,7 @@
11 // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
22 /*
33 *
4
- * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved.
4
+ * (C) COPYRIGHT 2020-2022 ARM Limited. All rights reserved.
55 *
66 * This program is free software and is provided to you under the terms of the
77 * GNU General Public License version 2 as published by the Free Software
....@@ -20,18 +20,19 @@
2020 */
2121
2222 #include <mali_kbase.h>
23
-#include "mali_kbase_csf_firmware_cfg.h"
2423 #include <mali_kbase_reset_gpu.h>
24
+#include <linux/version.h>
25
+
26
+#include "mali_kbase_csf_firmware_cfg.h"
27
+#include "mali_kbase_csf_firmware_log.h"
2528
2629 #if CONFIG_SYSFS
2730 #define CSF_FIRMWARE_CFG_SYSFS_DIR_NAME "firmware_config"
2831
32
+#define CSF_FIRMWARE_CFG_LOG_VERBOSITY_ENTRY_NAME "Log verbosity"
33
+
2934 /**
3035 * struct firmware_config - Configuration item within the MCU firmware
31
- *
32
- * The firmware may expose configuration options. Each option has a name, the
33
- * address where the option is controlled and the minimum and maximum values
34
- * that the option can take.
3536 *
3637 * @node: List head linking all options to
3738 * kbase_device:csf.firmware_config
....@@ -47,6 +48,10 @@
4748 * @min: The lowest legal value of the configuration option
4849 * @max: The maximum legal value of the configuration option
4950 * @cur_val: The current value of the configuration option
51
+ *
52
+ * The firmware may expose configuration options. Each option has a name, the
53
+ * address where the option is controlled and the minimum and maximum values
54
+ * that the option can take.
5055 */
5156 struct firmware_config {
5257 struct list_head node;
....@@ -67,9 +72,9 @@
6772 .mode = VERIFY_OCTAL_PERMISSIONS(_mode), \
6873 }
6974
70
-static FW_CFG_ATTR(min, S_IRUGO);
71
-static FW_CFG_ATTR(max, S_IRUGO);
72
-static FW_CFG_ATTR(cur, S_IRUGO | S_IWUSR);
75
+static FW_CFG_ATTR(min, 0444);
76
+static FW_CFG_ATTR(max, 0444);
77
+static FW_CFG_ATTR(cur, 0644);
7378
7479 static void fw_cfg_kobj_release(struct kobject *kobj)
7580 {
....@@ -124,7 +129,7 @@
124129
125130 if (attr == &fw_cfg_attr_cur) {
126131 unsigned long flags;
127
- u32 val;
132
+ u32 val, cur_val;
128133 int ret = kstrtouint(buf, 0, &val);
129134
130135 if (ret) {
....@@ -139,7 +144,9 @@
139144 return -EINVAL;
140145
141146 spin_lock_irqsave(&kbdev->hwaccess_lock, flags);
142
- if (config->cur_val == val) {
147
+
148
+ cur_val = config->cur_val;
149
+ if (cur_val == val) {
143150 spin_unlock_irqrestore(&kbdev->hwaccess_lock, flags);
144151 return count;
145152 }
....@@ -176,6 +183,20 @@
176183
177184 spin_unlock_irqrestore(&kbdev->hwaccess_lock, flags);
178185
186
+ /* Enable FW logging only if Log verbosity is non-zero */
187
+ if (!strcmp(config->name, CSF_FIRMWARE_CFG_LOG_VERBOSITY_ENTRY_NAME) &&
188
+ (!cur_val || !val)) {
189
+ ret = kbase_csf_firmware_log_toggle_logging_calls(kbdev, val);
190
+ if (ret) {
191
+ /* Undo FW configuration changes */
192
+ spin_lock_irqsave(&kbdev->hwaccess_lock, flags);
193
+ config->cur_val = cur_val;
194
+ kbase_csf_update_firmware_memory(kbdev, config->address, cur_val);
195
+ spin_unlock_irqrestore(&kbdev->hwaccess_lock, flags);
196
+ return ret;
197
+ }
198
+ }
199
+
179200 /* If we can update the config without firmware reset then
180201 * we need to just trigger FIRMWARE_CONFIG_UPDATE.
181202 */
....@@ -209,11 +230,18 @@
209230 &fw_cfg_attr_cur,
210231 NULL,
211232 };
233
+#if (KERNEL_VERSION(5, 2, 0) <= LINUX_VERSION_CODE)
234
+ATTRIBUTE_GROUPS(fw_cfg);
235
+#endif
212236
213237 static struct kobj_type fw_cfg_kobj_type = {
214238 .release = &fw_cfg_kobj_release,
215239 .sysfs_ops = &fw_cfg_ops,
240
+#if (KERNEL_VERSION(5, 2, 0) <= LINUX_VERSION_CODE)
241
+ .default_groups = fw_cfg_groups,
242
+#else
216243 .default_attrs = fw_cfg_attrs,
244
+#endif
217245 };
218246
219247 int kbase_csf_firmware_cfg_init(struct kbase_device *kbdev)
....@@ -273,9 +301,8 @@
273301 }
274302
275303 int kbase_csf_firmware_cfg_option_entry_parse(struct kbase_device *kbdev,
276
- const struct firmware *fw,
277
- const u32 *entry,
278
- unsigned int size, bool updatable)
304
+ const struct kbase_csf_mcu_fw *const fw,
305
+ const u32 *entry, unsigned int size, bool updatable)
279306 {
280307 const char *name = (char *)&entry[3];
281308 struct firmware_config *config;
....@@ -319,8 +346,8 @@
319346 }
320347
321348 int kbase_csf_firmware_cfg_option_entry_parse(struct kbase_device *kbdev,
322
- const struct firmware *fw,
323
- const u32 *entry, unsigned int size)
349
+ const struct kbase_csf_mcu_fw *const fw,
350
+ const u32 *entry, unsigned int size)
324351 {
325352 return 0;
326353 }