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
|
// SPDX-License-Identifier: GPL-2.0
/*
* Samsung Exynos SoC series dsp driver
*
* Copyright (c) 2019 Samsung Electronics Co., Ltd.
* http://www.samsung.com/
*/
#include <soc/samsung/bts.h>
#include "dsp-log.h"
#include "hardware/dsp-system.h"
#include "hardware/dsp-bus.h"
int dsp_bus_mo_get(struct dsp_bus *bus, unsigned char *scenario_name)
{
int ret;
int idx;
struct dsp_bus_scenario *scen = NULL;
dsp_enter();
for (idx = 0; idx < DSP_MO_SCENARIO_COUNT; ++idx) {
if (!strncmp(bus->scen[idx].name, scenario_name,
DSP_BUS_SCENARIO_NAME_LEN)) {
scen = &bus->scen[idx];
break;
}
}
if (!scen) {
ret = -EINVAL;
dsp_err("scenario_name(%s) is invalid\n", scenario_name);
goto p_err;
}
if (!scen->bts_scen_idx) {
ret = -EINVAL;
dsp_err("scenario_name(%s) was not initilized\n", scen->name);
goto p_err;
}
dsp_dbg("scenario[%s] idx : %u\n", scen->name, scen->bts_scen_idx);
mutex_lock(&scen->lock);
if (!scen->enabled) {
bts_add_scenario(scen->bts_scen_idx);
scen->enabled = true;
dsp_info("bus scenario[%s] is enabled\n", scen->name);
} else {
dsp_dbg("bus scenario[%s] is already enabled\n", scen->name);
}
mutex_unlock(&scen->lock);
dsp_leave();
return 0;
p_err:
return ret;
}
int dsp_bus_mo_put(struct dsp_bus *bus, unsigned char *scenario_name)
{
int ret;
int idx;
struct dsp_bus_scenario *scen = NULL;
dsp_enter();
for (idx = 0; idx < DSP_MO_SCENARIO_COUNT; ++idx) {
if (!strncmp(bus->scen[idx].name, scenario_name,
DSP_BUS_SCENARIO_NAME_LEN)) {
scen = &bus->scen[idx];
break;
}
}
if (!scen) {
ret = -EINVAL;
dsp_err("scenario_name(%s) is invalid\n", scenario_name);
goto p_err;
}
if (!scen->bts_scen_idx) {
ret = -EINVAL;
dsp_err("scenario_name(%s) was not initilized\n", scen->name);
goto p_err;
}
dsp_dbg("scenario[%s] idx : %u\n", scen->name, scen->bts_scen_idx);
mutex_lock(&scen->lock);
if (scen->enabled) {
bts_del_scenario(scen->bts_scen_idx);
scen->enabled = false;
dsp_info("bus scenario[%s] is disabled\n", scen->name);
} else {
dsp_warn("bus scenario[%s] is not enabled\n", scen->name);
}
mutex_unlock(&scen->lock);
dsp_leave();
return 0;
p_err:
return ret;
}
int dsp_bus_open(struct dsp_bus *bus)
{
int idx;
struct dsp_bus_scenario *scen;
dsp_enter();
for (idx = 0; idx < DSP_MO_SCENARIO_COUNT; ++idx) {
scen = &bus->scen[idx];
dsp_dbg("scenario[%d/%d] info : [%s/%u]\n",
idx, DSP_MO_SCENARIO_COUNT,
scen->name, scen->bts_scen_idx);
}
dsp_leave();
return 0;
}
int dsp_bus_close(struct dsp_bus *bus)
{
int idx;
struct dsp_bus_scenario *scen;
dsp_enter();
for (idx = 0; idx < DSP_MO_SCENARIO_COUNT; ++idx) {
scen = &bus->scen[idx];
mutex_lock(&scen->lock);
if (scen->enabled) {
bts_del_scenario(scen->bts_scen_idx);
scen->enabled = false;
dsp_warn("bus scenario[%s] is forcibly disabled\n",
scen->name);
}
mutex_unlock(&scen->lock);
}
dsp_leave();
return 0;
}
int dsp_bus_probe(struct dsp_system *sys)
{
int ret;
struct dsp_bus *bus;
struct dsp_bus_scenario *scen;
dsp_enter();
bus = &sys->bus;
bus->sys = sys;
bus->scen = kzalloc(sizeof(*scen) * DSP_MO_SCENARIO_COUNT, GFP_KERNEL);
if (!bus->scen) {
ret = -ENOMEM;
dsp_err("Failed to alloc dsp_bus_scenario\n");
goto p_err;
}
scen = &bus->scen[DSP_MO_MAX];
snprintf(scen->name, DSP_BUS_SCENARIO_NAME_LEN, "max");
scen->bts_scen_idx = bts_get_scenindex("npu_performance");
mutex_init(&scen->lock);
scen->enabled = false;
dsp_leave();
return 0;
p_err:
return ret;
}
void dsp_bus_remove(struct dsp_bus *bus)
{
int idx;
dsp_enter();
for (idx = 0; idx < DSP_MO_SCENARIO_COUNT; ++idx)
mutex_destroy(&bus->scen[idx].lock);
kfree(bus->scen);
dsp_leave();
}
|