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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
/*
* Copyright (c) 2019 Park Bumgyu, Samsung Electronics Co., Ltd <bumgyu.park@samsung.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* UCC(User Cstate Control) driver implementation
*/
#include <linux/cpumask.h>
#include <linux/of.h>
#include <linux/slab.h>
#include <linux/exynos-ucc.h>
static int ucc_initialized = false;
bool ib_ucc_initialized;
EXPORT_SYMBOL(ib_ucc_initialized);
/*
* struct ucc_config
*
* - index : index of cstate config
* - cstate : mask indicating whether each cpu supports cstate
* - mask bit set : cstate enable
* - mask bit unset : cstate disable
*/
struct ucc_config {
int index;
struct cpumask cstate;
};
static struct ucc_config *ucc_configs;
static int ucc_config_count;
/*
* cur_cstate has cpu cstate config corresponding to maximum index among ucc
* request. Whenever maximum requested index is changed, cur_state is updated.
*/
static struct cpumask cur_cstate;
int filter_cstate(int cpu, int index)
{
if (!ucc_initialized)
return index;
if (!cpumask_test_cpu(cpu, &cur_cstate)) {
/* index 0 is default idle state */
return 0;
}
return index;
}
static struct plist_head ucc_req_list = PLIST_HEAD_INIT(ucc_req_list);
static DEFINE_SPINLOCK(ucc_lock);
static int ucc_get_value(void)
{
if (plist_head_empty(&ucc_req_list))
return -1;
return plist_last(&ucc_req_list)->prio;
}
static void update_cur_cstate(void)
{
int value = ucc_get_value();
if (value < 0) {
cpumask_copy(&cur_cstate, cpu_possible_mask);
return;
}
cpumask_copy(&cur_cstate, &ucc_configs[value].cstate);
}
enum {
UCC_REMOVE_REQ,
UCC_UPDATE_REQ,
UCC_ADD_REQ,
};
static void ucc_update(struct ucc_req *req, int value, int action)
{
int prev_value = ucc_get_value();
switch (action) {
case UCC_REMOVE_REQ:
plist_del(&req->node, &ucc_req_list);
req->active = 0;
break;
case UCC_UPDATE_REQ:
plist_del(&req->node, &ucc_req_list);
case UCC_ADD_REQ:
plist_node_init(&req->node, value);
plist_add(&req->node, &ucc_req_list);
req->active = 1;
break;
}
if (prev_value != ucc_get_value())
update_cur_cstate();
}
void ucc_add_request(struct ucc_req *req, int value)
{
unsigned long flags;
spin_lock_irqsave(&ucc_lock, flags);
if (req->active) {
spin_unlock_irqrestore(&ucc_lock, flags);
return;
}
ucc_update(req, value, UCC_ADD_REQ);
spin_unlock_irqrestore(&ucc_lock, flags);
}
void ucc_update_request(struct ucc_req *req, int value)
{
unsigned long flags;
spin_lock_irqsave(&ucc_lock, flags);
if (!req->active) {
spin_unlock_irqrestore(&ucc_lock, flags);
return;
}
ucc_update(req, value, UCC_UPDATE_REQ);
spin_unlock_irqrestore(&ucc_lock, flags);
}
void ucc_remove_request(struct ucc_req *req)
{
unsigned long flags;
spin_lock_irqsave(&ucc_lock, flags);
if (!req->active) {
spin_unlock_irqrestore(&ucc_lock, flags);
return;
}
ucc_update(req, 0, UCC_REMOVE_REQ);
spin_unlock_irqrestore(&ucc_lock, flags);
}
static ssize_t show_ucc_requests(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
struct ucc_req *req;
int ret = 0;
plist_for_each_entry(req, &ucc_req_list, node)
ret += snprintf(buf + ret, PAGE_SIZE - ret,
" request : %d (%s)\n", req->node.prio, req->name);
return ret;
}
static struct kobj_attribute ucc_requests =
__ATTR(ucc_requests, 0444, show_ucc_requests, NULL);
void __init init_exynos_ucc(void)
{
struct device_node *dn, *child;
int i = 0;
dn = of_find_node_by_name(NULL, "cpuidle-ucc");
ucc_config_count = of_get_child_count(dn);
ucc_configs = kcalloc(ucc_config_count,
sizeof(struct ucc_config), GFP_KERNEL);
if (!ucc_configs)
return;
for_each_child_of_node(dn, child) {
const char *mask;
of_property_read_u32(child, "index", &ucc_configs[i].index);
if (of_property_read_string(child, "cstate", &mask))
cpumask_clear(&ucc_configs[i].cstate);
else
cpulist_parse(mask, &ucc_configs[i].cstate);
i++;
}
if (sysfs_create_file(power_kobj, &ucc_requests.attr))
pr_err("failed to create cstate_control node\n");
cpumask_setall(&cur_cstate);
ucc_initialized = true;
ib_ucc_initialized = true;
}
|