1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/smp.h>
#include <linux/debugfs.h>
#include <linux/cpu.h>
#include <soc/qcom/scm.h>
#define SCM_KRYO_ERRATA_ID 0x12
#define ERRATA_WA_DISABLE 0
#define ERRATA_WA_ENABLE 1
#define ERRATA_74_75_ID_BIT 0x000
#define ERRATA_76_ID_BIT 0x100
static struct dentry *debugfs_base;
static bool kryo_e74_e75_wa = true;
static bool kryo_e76_wa;
static void kryo_e74_e75_scm(void *enable)
{
int ret;
struct scm_desc desc = {0};
if (!is_scm_armv8())
return;
desc.arginfo = SCM_ARGS(1);
desc.args[0] = enable ? ERRATA_WA_ENABLE : ERRATA_WA_DISABLE;
desc.args[0] |= ERRATA_74_75_ID_BIT;
ret = scm_call2_atomic(SCM_SIP_FNID(SCM_SVC_BOOT, SCM_KRYO_ERRATA_ID),
&desc);
if (ret)
pr_err("Failed to %s ERRATA_74_75 workaround\n",
enable ? "enable" : "disable");
}
static int kryo_e74_e75_set(void *data, u64 val)
{
if ((val && kryo_e74_e75_wa) || (!val && !kryo_e74_e75_wa))
return 0;
kryo_e74_e75_wa = !!val;
get_cpu();
on_each_cpu(kryo_e74_e75_scm, (void *)kryo_e74_e75_wa, 1);
put_cpu();
return 0;
}
static int kryo_e74_e75_get(void *data, u64 *val)
{
*val = kryo_e74_e75_wa;
return 0;
}
static void kryo_e76_scm(void *enable)
{
int ret;
struct scm_desc desc = {0};
if (!is_scm_armv8())
return;
desc.arginfo = SCM_ARGS(1);
desc.args[0] = enable ? ERRATA_WA_ENABLE : ERRATA_WA_DISABLE;
desc.args[0] |= ERRATA_76_ID_BIT;
ret = scm_call2_atomic(SCM_SIP_FNID(SCM_SVC_BOOT, SCM_KRYO_ERRATA_ID),
&desc);
if (ret)
pr_err("Failed to %s ERRATA_76 workaround\n",
enable ? "enable" : "disable");
}
static int kryo_e76_set(void *data, u64 val)
{
if ((val && kryo_e76_wa) || (!val && !kryo_e76_wa))
return 0;
kryo_e76_wa = !!val;
get_cpu();
on_each_cpu(kryo_e76_scm, (void *)kryo_e76_wa, 1);
put_cpu();
return 0;
}
static int kryo_e76_get(void *data, u64 *val)
{
*val = kryo_e76_wa;
return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(kryo_e74_e75_fops, kryo_e74_e75_get,
kryo_e74_e75_set, "%llu\n");
DEFINE_SIMPLE_ATTRIBUTE(kryo_e76_fops, kryo_e76_get,
kryo_e76_set, "%llu\n");
static int scm_errata_notifier_callback(struct notifier_block *nfb,
unsigned long action, void *hcpu)
{
switch (action & ~CPU_TASKS_FROZEN) {
case CPU_STARTING:
kryo_e74_e75_scm((void *)kryo_e74_e75_wa);
kryo_e76_scm((void *)kryo_e76_wa);
break;
}
return 0;
}
static struct notifier_block scm_errata_notifier = {
.notifier_call = scm_errata_notifier_callback,
};
static int __init scm_errata_init(void)
{
int ret;
debugfs_base = debugfs_create_dir("scm_errata", NULL);
if (!debugfs_base)
return -ENOMEM;
if (!debugfs_create_file("kryo_e74_e75", S_IRUGO | S_IWUSR,
debugfs_base, NULL, &kryo_e74_e75_fops))
goto err;
if (!debugfs_create_file("kryo_e76", S_IRUGO | S_IWUSR,
debugfs_base, NULL, &kryo_e76_fops))
goto err;
ret = register_hotcpu_notifier(&scm_errata_notifier);
if (ret)
goto err;
return 0;
err:
debugfs_remove_recursive(debugfs_base);
return ret;
}
device_initcall(scm_errata_init);
|