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
|
/* Copyright (c) 2016-2017, 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/bitops.h>
#include <linux/spinlock.h>
#include <linux/cpu.h>
#include <linux/export.h>
#include <asm/app_api.h>
static spinlock_t spinlock;
static spinlock_t spinlock_32bit_app;
static DEFINE_PER_CPU(int, app_config_applied);
static unsigned long app_config_set[NR_CPUS];
static unsigned long app_config_clear[NR_CPUS];
void set_app_setting_bit(uint32_t bit)
{
unsigned long flags;
uint64_t reg;
int cpu;
spin_lock_irqsave(&spinlock, flags);
asm volatile("mrs %0, S3_1_C15_C15_0" : "=r" (reg));
reg = reg | BIT(bit);
isb();
asm volatile("msr S3_1_C15_C15_0, %0" : : "r" (reg));
isb();
if (bit == APP_SETTING_BIT) {
cpu = raw_smp_processor_id();
app_config_set[cpu]++;
this_cpu_write(app_config_applied, 1);
}
spin_unlock_irqrestore(&spinlock, flags);
}
EXPORT_SYMBOL(set_app_setting_bit);
void clear_app_setting_bit(uint32_t bit)
{
unsigned long flags;
uint64_t reg;
int cpu;
spin_lock_irqsave(&spinlock, flags);
asm volatile("mrs %0, S3_1_C15_C15_0" : "=r" (reg));
reg = reg & ~BIT(bit);
isb();
asm volatile("msr S3_1_C15_C15_0, %0" : : "r" (reg));
isb();
if (bit == APP_SETTING_BIT) {
cpu = raw_smp_processor_id();
app_config_clear[cpu]++;
this_cpu_write(app_config_applied, 0);
}
spin_unlock_irqrestore(&spinlock, flags);
}
EXPORT_SYMBOL(clear_app_setting_bit);
void set_app_setting_bit_for_32bit_apps(void)
{
unsigned long flags;
uint64_t reg;
spin_lock_irqsave(&spinlock_32bit_app, flags);
if (use_32bit_app_setting) {
asm volatile("mrs %0, S3_0_c15_c15_0 " : "=r" (reg));
reg = reg | BIT(24);
isb();
asm volatile("msr S3_0_c15_c15_0, %0" : : "r" (reg));
isb();
asm volatile("mrs %0, S3_0_c15_c15_1 " : "=r" (reg));
reg = reg | BIT(18) | BIT(2) | BIT(0);
isb();
asm volatile("msr S3_0_c15_c15_1, %0" : : "r" (reg));
isb();
} else if (use_32bit_app_setting_pro) {
asm volatile("mrs %0, S3_0_c15_c15_1 " : "=r" (reg));
reg = reg | BIT(18);
isb();
asm volatile("msr S3_0_c15_c15_1, %0" : : "r" (reg));
isb();
}
spin_unlock_irqrestore(&spinlock_32bit_app, flags);
}
EXPORT_SYMBOL(set_app_setting_bit_for_32bit_apps);
void clear_app_setting_bit_for_32bit_apps(void)
{
unsigned long flags;
uint64_t reg;
spin_lock_irqsave(&spinlock_32bit_app, flags);
if (use_32bit_app_setting) {
asm volatile("mrs %0, S3_0_c15_c15_0 " : "=r" (reg));
reg = reg & ~BIT(24);
isb();
asm volatile("msr S3_0_c15_c15_0, %0" : : "r" (reg));
isb();
asm volatile("mrs %0, S3_0_c15_c15_1 " : "=r" (reg));
reg = reg & ~BIT(18);
reg = reg & ~BIT(2);
reg = reg & ~BIT(0);
isb();
asm volatile("msr S3_0_c15_c15_1, %0" : : "r" (reg));
isb();
} else if (use_32bit_app_setting_pro) {
asm volatile("mrs %0, S3_0_c15_c15_1 " : "=r" (reg));
reg = reg & ~BIT(18);
isb();
asm volatile("msr S3_0_c15_c15_1, %0" : : "r" (reg));
isb();
}
spin_unlock_irqrestore(&spinlock_32bit_app, flags);
}
EXPORT_SYMBOL(clear_app_setting_bit_for_32bit_apps);
static int __init init_app_api(void)
{
spin_lock_init(&spinlock);
spin_lock_init(&spinlock_32bit_app);
return 0;
}
early_initcall(init_app_api);
|