Skip to content

Commit 8119f4b

Browse files
committed
Merge tag 'scmi-updates-5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/sudeep.holla/linux into arm/drivers
ARM SCMI updates for v5.10 Couple of main additions: SCMI system protocol support and ability to build SCMI driver as a single module which is needed by some transports like virtio as they may not be ready early during the boot. This also includes constification of scmi ops and related function pointers. * tag 'scmi-updates-5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/sudeep.holla/linux: firmware: arm_scmi: Enable building as a single module firmware: arm_scmi: Move scmi protocols registration into the driver firmware: arm_scmi: Move scmi bus init and exit calls into the driver firmware: smccc: Export both smccc functions firmware: arm_scmi: Fix NULL pointer dereference in mailbox_chan_free firmware: arm_scmi: Add SCMI device for system power protocol firmware: arm_scmi: Add system power protocol support firmware: arm_scmi: Constify static scmi-ops firmware: arm_scmi: Constify ops pointers in scmi_handle cpufreq: arm_scmi: Constify scmi_perf_ops pointers Link: https://lore.kernel.org/r/20200914075018.2rvytvghxyutcbk4@bogus Signed-off-by: Olof Johansson <olof@lixom.net>
2 parents bd2fad8 + 66d90f6 commit 8119f4b

18 files changed

Lines changed: 238 additions & 59 deletions

File tree

drivers/cpufreq/scmi-cpufreq.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static const struct scmi_handle *handle;
2929
static unsigned int scmi_cpufreq_get_rate(unsigned int cpu)
3030
{
3131
struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
32-
struct scmi_perf_ops *perf_ops = handle->perf_ops;
32+
const struct scmi_perf_ops *perf_ops = handle->perf_ops;
3333
struct scmi_data *priv = policy->driver_data;
3434
unsigned long rate;
3535
int ret;
@@ -50,7 +50,7 @@ scmi_cpufreq_set_target(struct cpufreq_policy *policy, unsigned int index)
5050
{
5151
int ret;
5252
struct scmi_data *priv = policy->driver_data;
53-
struct scmi_perf_ops *perf_ops = handle->perf_ops;
53+
const struct scmi_perf_ops *perf_ops = handle->perf_ops;
5454
u64 freq = policy->freq_table[index].frequency;
5555

5656
ret = perf_ops->freq_set(handle, priv->domain_id, freq * 1000, false);
@@ -64,7 +64,7 @@ static unsigned int scmi_cpufreq_fast_switch(struct cpufreq_policy *policy,
6464
unsigned int target_freq)
6565
{
6666
struct scmi_data *priv = policy->driver_data;
67-
struct scmi_perf_ops *perf_ops = handle->perf_ops;
67+
const struct scmi_perf_ops *perf_ops = handle->perf_ops;
6868

6969
if (!perf_ops->freq_set(handle, priv->domain_id,
7070
target_freq * 1000, true)) {

drivers/firmware/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
menu "Firmware Drivers"
88

99
config ARM_SCMI_PROTOCOL
10-
bool "ARM System Control and Management Interface (SCMI) Message Protocol"
10+
tristate "ARM System Control and Management Interface (SCMI) Message Protocol"
1111
depends on ARM || ARM64 || COMPILE_TEST
1212
depends on MAILBOX
1313
help

drivers/firmware/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ obj-$(CONFIG_TI_SCI_PROTOCOL) += ti_sci.o
2222
obj-$(CONFIG_TRUSTED_FOUNDATIONS) += trusted_foundations.o
2323
obj-$(CONFIG_TURRIS_MOX_RWTM) += turris-mox-rwtm.o
2424

25-
obj-$(CONFIG_ARM_SCMI_PROTOCOL) += arm_scmi/
25+
obj-y += arm_scmi/
2626
obj-y += broadcom/
2727
obj-y += meson/
2828
obj-$(CONFIG_GOOGLE_FIRMWARE) += google/

drivers/firmware/arm_scmi/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# SPDX-License-Identifier: GPL-2.0-only
2-
obj-y = scmi-bus.o scmi-driver.o scmi-protocols.o scmi-transport.o
32
scmi-bus-y = bus.o
43
scmi-driver-y = driver.o notify.o
54
scmi-transport-y = shmem.o
65
scmi-transport-$(CONFIG_MAILBOX) += mailbox.o
76
scmi-transport-$(CONFIG_HAVE_ARM_SMCCC_DISCOVERY) += smc.o
8-
scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o
7+
scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o system.o
8+
scmi-module-objs := $(scmi-bus-y) $(scmi-driver-y) $(scmi-protocols-y) \
9+
$(scmi-transport-y)
10+
obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-module.o
911
obj-$(CONFIG_ARM_SCMI_POWER_DOMAIN) += scmi_pm_domain.o

drivers/firmware/arm_scmi/bus.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static void scmi_devices_unregister(void)
230230
bus_for_each_dev(&scmi_bus_type, NULL, NULL, __scmi_devices_unregister);
231231
}
232232

233-
static int __init scmi_bus_init(void)
233+
int __init scmi_bus_init(void)
234234
{
235235
int retval;
236236

@@ -240,12 +240,10 @@ static int __init scmi_bus_init(void)
240240

241241
return retval;
242242
}
243-
subsys_initcall(scmi_bus_init);
244243

245-
static void __exit scmi_bus_exit(void)
244+
void __exit scmi_bus_exit(void)
246245
{
247246
scmi_devices_unregister();
248247
bus_unregister(&scmi_bus_type);
249248
ida_destroy(&scmi_bus_id);
250249
}
251-
module_exit(scmi_bus_exit);

drivers/firmware/arm_scmi/clock.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ scmi_clock_info_get(const struct scmi_handle *handle, u32 clk_id)
318318
return clk;
319319
}
320320

321-
static struct scmi_clk_ops clk_ops = {
321+
static const struct scmi_clk_ops clk_ops = {
322322
.count_get = scmi_clock_count_get,
323323
.info_get = scmi_clock_info_get,
324324
.rate_get = scmi_clock_rate_get,
@@ -364,9 +364,4 @@ static int scmi_clock_protocol_init(struct scmi_handle *handle)
364364
return 0;
365365
}
366366

367-
static int __init scmi_clock_init(void)
368-
{
369-
return scmi_protocol_register(SCMI_PROTOCOL_CLOCK,
370-
&scmi_clock_protocol_init);
371-
}
372-
subsys_initcall(scmi_clock_init);
367+
DEFINE_SCMI_PROTOCOL_REGISTER_UNREGISTER(SCMI_PROTOCOL_CLOCK, clock)

drivers/firmware/arm_scmi/common.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,30 @@ void scmi_setup_protocol_implemented(const struct scmi_handle *handle,
156156

157157
int scmi_base_protocol_init(struct scmi_handle *h);
158158

159+
int __init scmi_bus_init(void);
160+
void __exit scmi_bus_exit(void);
161+
162+
#define DECLARE_SCMI_REGISTER_UNREGISTER(func) \
163+
int __init scmi_##func##_register(void); \
164+
void __exit scmi_##func##_unregister(void)
165+
DECLARE_SCMI_REGISTER_UNREGISTER(clock);
166+
DECLARE_SCMI_REGISTER_UNREGISTER(perf);
167+
DECLARE_SCMI_REGISTER_UNREGISTER(power);
168+
DECLARE_SCMI_REGISTER_UNREGISTER(reset);
169+
DECLARE_SCMI_REGISTER_UNREGISTER(sensors);
170+
DECLARE_SCMI_REGISTER_UNREGISTER(system);
171+
172+
#define DEFINE_SCMI_PROTOCOL_REGISTER_UNREGISTER(id, name) \
173+
int __init scmi_##name##_register(void) \
174+
{ \
175+
return scmi_protocol_register((id), &scmi_##name##_protocol_init); \
176+
} \
177+
\
178+
void __exit scmi_##name##_unregister(void) \
179+
{ \
180+
scmi_protocol_unregister((id)); \
181+
}
182+
159183
/* SCMI Transport */
160184
/**
161185
* struct scmi_chan_info - Structure representing a SCMI channel information
@@ -210,7 +234,7 @@ struct scmi_transport_ops {
210234
* @max_msg_size: Maximum size of data per message that can be handled.
211235
*/
212236
struct scmi_desc {
213-
struct scmi_transport_ops *ops;
237+
const struct scmi_transport_ops *ops;
214238
int max_rx_timeout_ms;
215239
int max_msg;
216240
int max_msg_size;

drivers/firmware/arm_scmi/driver.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ struct scmi_prot_devnames {
730730

731731
static struct scmi_prot_devnames devnames[] = {
732732
{ SCMI_PROTOCOL_POWER, { "genpd" },},
733+
{ SCMI_PROTOCOL_SYSTEM, { "syspower" },},
733734
{ SCMI_PROTOCOL_PERF, { "cpufreq" },},
734735
{ SCMI_PROTOCOL_CLOCK, { "clocks" },},
735736
{ SCMI_PROTOCOL_SENSOR, { "hwmon" },},
@@ -928,7 +929,35 @@ static struct platform_driver scmi_driver = {
928929
.remove = scmi_remove,
929930
};
930931

931-
module_platform_driver(scmi_driver);
932+
static int __init scmi_driver_init(void)
933+
{
934+
scmi_bus_init();
935+
936+
scmi_clock_register();
937+
scmi_perf_register();
938+
scmi_power_register();
939+
scmi_reset_register();
940+
scmi_sensors_register();
941+
scmi_system_register();
942+
943+
return platform_driver_register(&scmi_driver);
944+
}
945+
subsys_initcall(scmi_driver_init);
946+
947+
static void __exit scmi_driver_exit(void)
948+
{
949+
scmi_bus_exit();
950+
951+
scmi_clock_unregister();
952+
scmi_perf_unregister();
953+
scmi_power_unregister();
954+
scmi_reset_unregister();
955+
scmi_sensors_unregister();
956+
scmi_system_unregister();
957+
958+
platform_driver_unregister(&scmi_driver);
959+
}
960+
module_exit(scmi_driver_exit);
932961

933962
MODULE_ALIAS("platform: arm-scmi");
934963
MODULE_AUTHOR("Sudeep Holla <sudeep.holla@arm.com>");

drivers/firmware/arm_scmi/mailbox.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static int mailbox_chan_free(int id, void *p, void *data)
110110
struct scmi_chan_info *cinfo = p;
111111
struct scmi_mailbox *smbox = cinfo->transport_info;
112112

113-
if (!IS_ERR(smbox->chan)) {
113+
if (smbox && !IS_ERR(smbox->chan)) {
114114
mbox_free_channel(smbox->chan);
115115
cinfo->transport_info = NULL;
116116
smbox->chan = NULL;
@@ -181,7 +181,7 @@ mailbox_poll_done(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer)
181181
return shmem_poll_done(smbox->shmem, xfer);
182182
}
183183

184-
static struct scmi_transport_ops scmi_mailbox_ops = {
184+
static const struct scmi_transport_ops scmi_mailbox_ops = {
185185
.chan_available = mailbox_chan_available,
186186
.chan_setup = mailbox_chan_setup,
187187
.chan_free = mailbox_chan_free,

drivers/firmware/arm_scmi/notify.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ static void scmi_protocols_late_init(struct work_struct *work)
14211421
* notify_ops are attached to the handle so that can be accessed
14221422
* directly from an scmi_driver to register its own notifiers.
14231423
*/
1424-
static struct scmi_notify_ops notify_ops = {
1424+
static const struct scmi_notify_ops notify_ops = {
14251425
.register_event_notifier = scmi_register_notifier,
14261426
.unregister_event_notifier = scmi_unregister_notifier,
14271427
};

0 commit comments

Comments
 (0)