firmware: arm_scmi: Use signed integer to report transfer status
Subsystems (3)
PATCH 1/1 firmware: arm_scmi: Use signed integer to report transfer status
Currently the trace event 'scmi_xfer_end' reports the status of the transfer using the unsigned status field read from the firmware. This may not be easy to interpret and also may miss to present any timeouts that happen in the driver.
Let us use signed integer so that error values are emitted out after they are mapped from firmware errors to standard linux error codes. While at this, let us also include any timeouts in the driver itself.
--- drivers/firmware/arm_scmi/driver.c | 3 +-- include/trace/events/scmi.h | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/firmware/arm_scmi/driver.c +1 -2
@@ -392,8 +392,7 @@ int scmi_do_xfer(const struct scmi_handle *handle, struct scmi_xfer *xfer) info->desc->ops->mark_txdone (cinfo, ret);trace_scmi_xfer_end (xfer->transfer_id, xfer->hdr.id, - xfer->hdr.protocol_id, xfer->hdr.seq, - xfer->hdr.status); + xfer->hdr.protocol_id, xfer->hdr.seq, ret);return ret; }
include/trace/events/scmi.h +3 -3
@@ -35,7 +35,7 @@ TRACE_EVENT(scmi_xfer_begin, TRACE_EVENT(scmi_xfer_end, TP_PROTO(int transfer_id, u8 msg_id, u8 protocol_id, u16 seq, - u32 status), + int status), TP_ARGS(transfer_id, msg_id, protocol_id, seq, status), TP_STRUCT__entry(
@@ -43,7 +43,7 @@ TRACE_EVENT(scmi_xfer_end, __field(u8, msg_id) __field(u8, protocol_id) __field(u16, seq) -__field (u32, status) +__field (int, status) ), TP_fast_assign(
@@ -54,7 +54,7 @@ TRACE_EVENT(scmi_xfer_end, __entry->status = status; ), -TP_printk ("transfer_id=%d msg_id=%u protocol_id=%u seq=%u status=%u" , +TP_printk ("transfer_id=%d msg_id=%u protocol_id=%u seq=%u status=%d" , __entry->transfer_id, __entry->msg_id, __entry->protocol_id, __entry->seq, __entry->status) );
Signature · 1 line
2.17.1
Quoted 55 lines · Sudeep Holla
Currently the trace event '
scmi_xfer_end' reports the status of the transfer using the unsigned status field read from the firmware. This may not be easy to interpret and also may miss to present any timeouts that happen in the driver.Let us use signed integer so that error values are emitted out after they are mapped from firmware errors to standard linux error codes. While at this, let us also include any timeouts in the driver itself.
Cc Jim Quinlan <[email protected]>Cc Lukasz Luba <[email protected]>Signed-off-by Sudeep Holla <[email protected]>--- drivers/firmware/arm_scmi/driver.c | 3 +-- include/trace/events/scmi.h | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-)drivers/firmware/arm_scmi/driver.c +1
-2@@ -392,8 +392,7 @@ int scmi_do_xfer(const struct scmi_handle *handle, struct scmi_xfer *xfer) info->desc->ops->mark_txdone (cinfo, ret);trace_scmi_xfer_end (xfer->transfer_id, xfer->hdr.id, - xfer->hdr.protocol_id, xfer->hdr.seq, - xfer->hdr.status); + xfer->hdr.protocol_id, xfer->hdr.seq, ret);return ret; }include/trace/events/scmi.h +2
-2@@ -35,7 +35,7 @@ TRACE_EVENT(scmi_xfer_begin, TRACE_EVENT(scmi_xfer_end, TP_PROTO(int transfer_id, u8 msg_id, u8 protocol_id, u16 seq, - u32 status), + int status), TP_ARGS(transfer_id, msg_id, protocol_id, seq, status), TP_STRUCT__entry(@@ -43,7 +43,7 @@ TRACE_EVENT(scmi_xfer_end, __field(u8, msg_id) __field(u8, protocol_id) __field(u16, seq) -__field (u32, status) +__field (int, status) ), TP_fast_assign(
include/trace/events/scmi.h TRACE_EVENT(scmi_xfer_end, · line 60
Quoted 8 lines
include/trace/events/scmi.h +1
-1@@ -54,7 +54,7 @@ TRACE_EVENT(scmi_xfer_end, __entry->status = status; ), -TP_printk ("transfer_id=%d msg_id=%u protocol_id=%u seq=%u status=%u" , +TP_printk ("transfer_id=%d msg_id=%u protocol_id=%u seq=%u status=%d" , __entry->transfer_id, __entry->msg_id, __entry->protocol_id, __entry->seq, __entry->status) );
Indeed looks better with the Linux like ret status
Regards,
Lukasz
PATCH 1/2 firmware: arm_scmi: Add fast_switch_possible() api
Add a new fast_switch_possible interface to the existing perf_ops api to export the information of whether or not fast_switch is possible in this driver.
This can be used by the CPUFreq driver and framework to choose proper mechanism for frequency change.
--- drivers/firmware/arm_scmi/perf.c | 12 ++++++++++++ include/linux/scmi_protocol.h | 2 ++ 2 files changed, 14 insertions(+)
drivers/firmware/arm_scmi/perf.c +12 -0
@@ -697,6 +697,17 @@ static int scmi_dvfs_est_power_get(const struct scmi_handle *handle, u32 domain,return ret; } +static bool scmi_fast_switch_possible (const struct scmi_handle *handle, +struct device *dev) +{ +struct perf_dom_info *dom; +struct scmi_perf_info *pi = handle->perf_priv; + + dom = pi->dom_info +scmi_dev_domain_id (dev); + +return (dom->fc_info && dom->fc_info->level_set_addr); +} +static struct scmi_perf_ops perf_ops = { .limits_set = scmi_perf_limits_set, .limits_get = scmi_perf_limits_get,
@@ -708,6 +719,7 @@ static struct scmi_perf_ops perf_ops = { .freq_set = scmi_dvfs_freq_set, .freq_get = scmi_dvfs_freq_get, .est_power_get = scmi_dvfs_est_power_get, + .fast_switch_possible = scmi_fast_switch_possible, };static int scmi_perf_protocol_init (struct scmi_handle *handle)
include/linux/scmi_protocol.h +2 -0
@@ -118,6 +118,8 @@ struct scmi_perf_ops { unsigned long *rate, bool poll);int (*est_power_get)(const struct scmi_handle *handle,u32 domain,unsigned long *rate,unsigned long *power); +bool (*fast_switch_possible)(const struct scmi_handle *handle, +struct device *dev); };/**
Signature · 1 line
2.27.0
PATCH 2/2 cpufreq: arm_scmi: Set fast_switch_possible conditionally
Currently the fast_switch_possible flag is set unconditionally to true. Based on this, schedutil does not create a thread for frequency switching and would always use the fast switch path.
However, if the platform does not support frequency fast switch, this may cause the governor to attempt an operation that is not supported by the platform.
Fix this by correctly retrieve the fast_switch capability from the driver which knows if the platform can support this feature.
--- drivers/cpufreq/scmi-cpufreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/cpufreq/scmi-cpufreq.c +2 -1
@@ -198,7 +198,8 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy) policy->cpuinfo.transition_latency = latency; - policy->fast_switch_possible = true; + policy->fast_switch_possible = + handle->perf_ops->fast_switch_possible (handle, cpu_dev);em_register_perf_domain (policy->cpus, nr_opp, &em_cb);
Signature · 1 line
2.27.0
Re: [PATCH 2/2] cpufreq: arm_scmi: Set fast_switch_possible conditionally
Quoted 8 lines · Nicola Mazzucato
Currently the
fast_switch_possibleflag is set unconditionally to true. Based on this, schedutil does not create a thread for frequency switching and would always use the fast switch path.
However, if the platform does not support frequency fast switch, this may cause the governor to attempt an operation that is not supported by the platform.
Quoted 4 lines
Fix this by correctly retrieve the
fast_switchcapability from the driver which knows if the platform can support this feature.
Hi Viresh,
This is first step towards avoiding polling based cpufreq set if firmware has fast access registers that bypass normal mailbox based messaging.
If you happy with this and provide ack, I will take this along with scmi changes via ARM SoC. Hope that is fine by you.
--
Regards,
Sudeep
Viresh Kumar
maintainerRe: [PATCH 2/2] cpufreq: arm_scmi: Set fast_switch_possible conditionally
Quoted 5 lines · Sudeep Holla
This is first step towards avoiding polling based cpufreq set if firmware has fast access registers that bypass normal mailbox based messaging.
If you happy with this and provide ack, I will take this along with scmi changes via ARM SoC. Hope that is fine by you.
Sudeep,
I am not sure how it concerns me frankly :)
AFAICT, this is enabling fast switch based on some mechanism (internal to scmi) and so either the cpufreq driver will have fast-switch enabled or not, and both are fine by the cpufreq core.
And so I am confused on why my Ack is important here :)
Signature · 1 line
viresh
Re: [PATCH 2/2] cpufreq: arm_scmi: Set fast_switch_possible conditionally
Quoted 11 lines · Viresh Kumar
Quoted 5 lines · Sudeep Holla
This is first step towards avoiding polling based cpufreq set if firmware has fast access registers that bypass normal mailbox based messaging.
If you happy with this and provide ack, I will take this along with scmi changes via ARM SoC. Hope that is fine by you.
Sudeep,
I am not sure how it concerns me frankly :)
Sorry I wasn't clear.
Quoted 4 lines
AFAICT, this is enabling fast switch based on some mechanism (internal to scmi) and so either the cpufreq driver will have fast-switch enabled or not, and both are fine by the cpufreq core.
Indeed.
Quoted 2 lines
And so I am confused on why my Ack is important here :)
Generally ARM SoC team expects a stamp from other subsystem maintainers if they are pulling it. I understand there is more firmware aspect than cpufreq aspect here, but still we may need your stamp to this 😉 for logistic reasons.
--
Regards,
Sudeep
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH 2/2] cpufreq: arm_scmi: Set fast_switch_possible conditionally
In reply to Nicola MazzucatoQuoted 23 lines · Nicola Mazzucato
Currently the
fast_switch_possibleflag is set unconditionally to true. Based on this, schedutil does not create a thread for frequency switching and would always use the fast switch path.
However, if the platform does not support frequency fast switch, this may cause the governor to attempt an operation that is not supported by the platform.Fix this by correctly retrieve the
fast_switchcapability from the driver which knows if the platform can support this feature.Suggested-by Lukasz Luba <[email protected]>Signed-off-by Nicola Mazzucato <[email protected]>--- drivers/cpufreq/scmi-cpufreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/cpufreq/scmi-cpufreq.c +0
-0
drivers/cpufreq/scmi-cpufreq.c static int scmi_cpufreq_init(struct cpufreq_policy *policy) · line 204
Quoted 8 lines
drivers/cpufreq/scmi-cpufreq.c +2
-1@@ -198,7 +198,8 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy) policy->cpuinfo.transition_latency = latency; - policy->fast_switch_possible = true; + policy->fast_switch_possible = + handle->perf_ops->fast_switch_possible (handle, cpu_dev);em_register_perf_domain (policy->cpus, nr_opp, &em_cb);
Signature · 1 line
viresh
Cristian Marussi
reviewerPATCH 1/1 firmware: arm_scmi: Fix SCMI Generic Power Domain probing
When, at probe time, an SCMI communication failure inhibits the capacity to query power domains states, such domains should be skipped.
Registering partially initialized SCMI Power Domains with GenPD causes a
Kernel panic.
[ 292.593774] arm-scmi firmware:scmi: timed out in resp(caller: scmi_power_state_get+0xa4/0xd0) [ 292.602369] scmi-power-domain scmi_dev.2: failed to get state for domain 9 [ 292.609366] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 [ 292.618190] Mem abort info: [ 292.620982] ESR = 0x96000006 [ 292.624065] EC = 0x25: DABT (current EL), IL = 32 bits [ 292.629403] SET = 0, FnV = 0 [ 292.632474] EA = 0, S1PTW = 0 [ 292.635641] Data abort info: [ 292.638542] ISV = 0, ISS = 0x00000006 [ 292.642396] CM = 0, WnR = 0 [ 292.645364] user pgtable: 4k pages, 48-bit VAs, pgdp=00000009f3691000 [ 292.651838] [0000000000000000] pgd=00000009f1ca0003, p4d=00000009f1ca0003, pud=00000009f35ea003, pmd=0000000000000000 [ 292.662504] Internal error: Oops: 96000006 [#1] PREEMPT SMP [ 292.672272] CPU: 2 PID: 381 Comm: bash Not tainted 5.8.0-rc1-00011-gebd118c2cca8 #2 [ 292.679938] Hardware name: ARM LTD ARM Juno Development Platform/ARM Juno Development Platform, BIOS EDK II Jan 3 2020 292.662504] Internal error: Oops: 96000006 [#1] PREEMPT SMP [ 292.702221] pstate: 80000005 (Nzcv daif -PAN -UAO BTYPE=--) [ 292.707803] pc : of_genpd_add_provider_onecell+0x98/0x1f8 [ 292.713207] lr : of_genpd_add_provider_onecell+0x48/0x1f8 [ 292.718609] sp : ffff80001325bb50 [ 292.721922] x29: ffff80001325bb50 x28: ffff000974b28ec0 [ 292.727240] x27: ffff000971c11380 x26: ffff80001235b200 [ 292.732558] x25: ffff00097eff82c0 x24: 0000000000000001 [ 292.737874] x23: 00000000ffffffea x22: ffff00097eff82a8 [ 292.743191] x21: ffff80001235b1e0 x20: 0000000000000000 [ 292.748507] x19: ffff000974b2c080 x18: 0000000000000010 [ 292.753823] x17: 0000000000000000 x16: 0000000000000000 [ 292.759140] x15: ffffffffffffffff x14: ffff800012139948 [ 292.764456] x13: ffff80009325b817 x12: ffff80001325b81f [ 292.769772] x11: ffff80001215a000 x10: 0000000000000a10 [ 292.775089] x9 : ffff800010970e08 x8 : ffff000974e84370 [ 292.780405] x7 : 00000000ffffffff x6 : ffff00097ef5c1f0 [ 292.785721] x5 : ffff00097ef5c1f0 x4 : 0000000000000000 [ 292.791038] x3 : ffff80001235b1e0 x2 : fffffffffffffc28 [ 292.796354] x1 : 000000000000000a x0 : ffff000971c11680 [ 292.801671] Call trace: [ 292.804117] of_genpd_add_provider_onecell+0x98/0x1f8 [ 292.809173] scmi_pm_domain_probe+0x174/0x1e8 [ 292.813533] scmi_dev_probe+0x90/0xe0 [ 292.817198] really_probe+0xe4/0x448 [ 292.820774] driver_probe_device+0xfc/0x168 [ 292.824961] device_driver_attach+0x7c/0x88 [ 292.829146] bind_store+0xe8/0x128 [ 292.832548] drv_attr_store+0x2c/0x40 [ 292.836214] sysfs_kf_write+0x4c/0x60 [ 292.839876] kernfs_fop_write+0x114/0x230 [ 292.843889] __vfs_write+0x24/0x50 [ 292.847291] vfs_write+0xbc/0x1e0 [ 292.850605] ksys_write+0x70/0xf8 [ 292.853919] __arm64_sys_write+0x24/0x30 [ 292.857844] el0_svc_common.constprop.3+0x94/0x160 [ 292.862638] do_el0_svc+0x2c/0x98 [ 292.865954] el0_sync_handler+0x148/0x1a8 [ 292.869964] el0_sync+0x158/0x180 [ 292.873281] Code: eb1a005f d10f6042 540000c1 1400004e (f941ec42) [ 292.879388] ---[ end trace 0077e182f3135393 ]--- [ 292.884007] Kernel panic - not syncing: Fatal exception [ 292.889239] SMP: stopping secondary CPUs [ 292.893347] Kernel Offset: 0x140000 from 0xffff800010000000 [ 292.898923] PHYS_OFFSET: 0x80000000 [ 292.902411] CPU features: 0x240022,25806087 [ 292.906594] Memory Limit: none [ 292.909655] ---[ end Kernel panic - not syncing: Fatal exception ]---
Do not register with GenPD any power domain that failed to be queried.
--- drivers/firmware/arm_scmi/scmi_pm_domain.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/firmware/arm_scmi/scmi_pm_domain.c +6 -6
@@ -85,7 +85,10 @@ static int scmi_pm_domain_probe(struct scmi_device *sdev)for (i =0 ; i < num_domains; i++, scmi_pd++) {u32 state; - domains[i] = &scmi_pd->genpd; +if (handle->power_ops->state_get (handle, i, &state)) { +dev_warn (dev,"failed to get state for domain %d\n" , i); +continue ; + } scmi_pd->domain = i; scmi_pd->handle = handle;
@@ -94,13 +97,10 @@ static int scmi_pm_domain_probe(struct scmi_device *sdev) scmi_pd->genpd.power_off = scmi_pd_power_off; scmi_pd->genpd.power_on = scmi_pd_power_on; -if (handle->power_ops->state_get (handle, i, &state)) { -dev_warn (dev,"failed to get state for domain %d\n" , i); -continue ; - } -pm_genpd_init (&scmi_pd->genpd,NULL , state ==SCMI_POWER_STATE_GENERIC_OFF ); + + domains[i] = &scmi_pd->genpd; } scmi_pd_data->domains = domains;
Signature · 1 line
2.17.1
Sudeep Holla
AppliedRe: [PATCH] firmware: arm_scmi: Fix SCMI Generic Power Domain probing
Quoted 71 lines · Cristian Marussi
When, at probe time, an SCMI communication failure inhibits the capacity to query power domains states, such domains should be skipped.
Registering partially initialized SCMI Power Domains with GenPD causes a
Kernel panic.[ 292.593774] arm-scmi firmware:scmi: timed out in resp(caller: scmi_power_state_get+0xa4/0xd0) [ 292.602369] scmi-power-domain scmi_dev.2: failed to get state for domain 9 [ 292.609366] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 [ 292.618190] Mem abort info: [ 292.620982] ESR = 0x96000006 [ 292.624065] EC = 0x25: DABT (current EL), IL = 32 bits [ 292.629403] SET = 0, FnV = 0 [ 292.632474] EA = 0, S1PTW = 0 [ 292.635641] Data abort info: [ 292.638542] ISV = 0, ISS = 0x00000006 [ 292.642396] CM = 0, WnR = 0 [ 292.645364] user pgtable: 4k pages, 48-bit VAs, pgdp=00000009f3691000 [ 292.651838] [0000000000000000] pgd=00000009f1ca0003, p4d=00000009f1ca0003, pud=00000009f35ea003, pmd=0000000000000000 [ 292.662504] Internal error: Oops: 96000006 [#1] PREEMPT SMP [ 292.672272] CPU: 2 PID: 381 Comm: bash Not tainted 5.8.0-rc1-00011-gebd118c2cca8 #2 [ 292.679938] Hardware name: ARM LTD ARM Juno Development Platform/ARM Juno Development Platform, BIOS EDK II Jan 3 2020 292.662504] Internal error: Oops: 96000006 [#1] PREEMPT SMP [ 292.702221] pstate: 80000005 (Nzcv daif -PAN -UAO BTYPE=--) [ 292.707803] pc : of_genpd_add_provider_onecell+0x98/0x1f8 [ 292.713207] lr : of_genpd_add_provider_onecell+0x48/0x1f8 [ 292.718609] sp : ffff80001325bb50 [ 292.721922] x29: ffff80001325bb50 x28: ffff000974b28ec0 [ 292.727240] x27: ffff000971c11380 x26: ffff80001235b200 [ 292.732558] x25: ffff00097eff82c0 x24: 0000000000000001 [ 292.737874] x23: 00000000ffffffea x22: ffff00097eff82a8 [ 292.743191] x21: ffff80001235b1e0 x20: 0000000000000000 [ 292.748507] x19: ffff000974b2c080 x18: 0000000000000010 [ 292.753823] x17: 0000000000000000 x16: 0000000000000000 [ 292.759140] x15: ffffffffffffffff x14: ffff800012139948 [ 292.764456] x13: ffff80009325b817 x12: ffff80001325b81f [ 292.769772] x11: ffff80001215a000 x10: 0000000000000a10 [ 292.775089] x9 : ffff800010970e08 x8 : ffff000974e84370 [ 292.780405] x7 : 00000000ffffffff x6 : ffff00097ef5c1f0 [ 292.785721] x5 : ffff00097ef5c1f0 x4 : 0000000000000000 [ 292.791038] x3 : ffff80001235b1e0 x2 : fffffffffffffc28 [ 292.796354] x1 : 000000000000000a x0 : ffff000971c11680 [ 292.801671] Call trace: [ 292.804117] of_genpd_add_provider_onecell+0x98/0x1f8 [ 292.809173] scmi_pm_domain_probe+0x174/0x1e8 [ 292.813533] scmi_dev_probe+0x90/0xe0 [ 292.817198] really_probe+0xe4/0x448 [ 292.820774] driver_probe_device+0xfc/0x168 [ 292.824961] device_driver_attach+0x7c/0x88 [ 292.829146] bind_store+0xe8/0x128 [ 292.832548] drv_attr_store+0x2c/0x40 [ 292.836214] sysfs_kf_write+0x4c/0x60 [ 292.839876] kernfs_fop_write+0x114/0x230 [ 292.843889] __vfs_write+0x24/0x50 [ 292.847291] vfs_write+0xbc/0x1e0 [ 292.850605] ksys_write+0x70/0xf8 [ 292.853919] __arm64_sys_write+0x24/0x30 [ 292.857844] el0_svc_common.constprop.3+0x94/0x160 [ 292.862638] do_el0_svc+0x2c/0x98 [ 292.865954] el0_sync_handler+0x148/0x1a8 [ 292.869964] el0_sync+0x158/0x180 [ 292.873281] Code: eb1a005f d10f6042 540000c1 1400004e (f941ec42) [ 292.879388] ---[ end trace 0077e182f3135393 ]--- [ 292.884007] Kernel panic - not syncing: Fatal exception [ 292.889239] SMP: stopping secondary CPUs [ 292.893347] Kernel Offset: 0x140000 from 0xffff800010000000 [ 292.898923] PHYS_OFFSET: 0x80000000 [ 292.902411] CPU features: 0x240022,25806087 [ 292.906594] Memory Limit: none [ 292.909655] ---[ end Kernel panic - not syncing: Fatal exception ]---
Quoted 1 line
[...]
Applied to sudeep.holla/linux (for-next/scmi), thanks!
[1/1] firmware: arm_scmi: Fix SCMI genpd domain probing
https://git.kernel.org/sudeep.holla/c/e0f1a30cf1
--
Regards,
Sudeep
Sudeep Holla
AppliedRe: [PATCH v11 0/9] SCMI Notifications Core Support
Quoted 8 lines · Cristian Marussi
this series wants to introduce SCMI Notification Support, built on top of the standard Kernel notification chain subsystem.
At initialization time each SCMI Protocol takes care to register with the new SCMI notification core the set of its own events which it intends to support.
[...]
Applied to sudeep.holla/linux (for-next/scmi), thanks!
[1/9] firmware: arm_scmi: Add notification protocol-registration
https://git.kernel.org/sudeep.holla/c/1fc2dd1864 [2/9] firmware: arm_scmi: Add notification callbacks-registration https://git.kernel.org/sudeep.holla/c/e7c215f358 [3/9] firmware: arm_scmi: Add notification dispatch and delivery https://git.kernel.org/sudeep.holla/c/bd31b24969 [4/9] firmware: arm_scmi: Enable notification core https://git.kernel.org/sudeep.holla/c/6b8a69131d [5/9] firmware: arm_scmi: Add power notifications support https://git.kernel.org/sudeep.holla/c/e27077bc04 [6/9] firmware: arm_scmi: Add perf notifications support https://git.kernel.org/sudeep.holla/c/fb5086dc47 [7/9] firmware: arm_scmi: Add sensor notifications support https://git.kernel.org/sudeep.holla/c/128e3e9311 [8/9] firmware: arm_scmi: Add reset notifications support https://git.kernel.org/sudeep.holla/c/469ca1822d [9/9] (korg_sudeep/for-next/scmi) firmware: arm_scmi: Add base notifications support https://git.kernel.org/sudeep.holla/c/585dfab3fb
--
Regards,
Sudeep
Sudeep Holla
AppliedRe: [PATCH 1/2] firmware: arm_scmi: Add fast_switch_possible() api
Quoted 6 lines · Nicola Mazzucato
Add a new
fast_switch_possibleinterface to the existingperf_opsapi to export the information of whether or notfast_switchis possible in this driver.This can be used by the CPUFreq driver and framework to choose proper mechanism for frequency change.
Applied to sudeep.holla/linux (for-next/scmi), thanks!
[1/2] firmware: arm_scmi: Add fast_switch_possible() interface
https://git.kernel.org/sudeep.holla/c/1909872ff2 [2/2] cpufreq: arm_scmi: Set fast_switch_possible conditionally https://git.kernel.org/sudeep.holla/c/fb3571276b
--
Regards,
Sudeep
Sudeep Holla
AppliedRe: [PATCH] firmware: arm_scmi: Use HAVE_ARM_SMCCC_DISCOVERY instead of ARM_PSCI_FW
Quoted 10 lines · Sudeep Holla
Commit
e5bfb21d98b6("firmware: smccc: AddHAVE_ARM_SMCCC_DISCOVERYto identify SMCCC v1.1 and above") introduced new config option to identify the availability of SMCCC discoverability of version and features transparently hiding the indirect dependency onARM_PSCI_FW.Commit
5a897e3ab429("firmware:arm_scmi: fix psci dependency") just worked around the build dependency making SCMI SMC/HVC transport depend onARM_PSCI_FWat the time. Since it really just relies on SMCCC directly and not onARM_PSCI_FW, let us move to useCONFIG_HAVE_ARM_SMCCC_DISCOVERYinstead ofCONFIG_ARM_PSCI_FW.
Applied to sudeep.holla/linux (for-next/scmi), thanks!
[1/1] firmware: arm_scmi: Use HAVE_ARM_SMCCC_DISCOVERY instead of ARM_PSCI_FW
https://git.kernel.org/sudeep.holla/c/d764282377
--
Regards,
Sudeep
Sudeep Holla
AppliedQuoted 8 lines · Sudeep Holla
Currently the trace event '
scmi_xfer_end' reports the status of the transfer using the unsigned status field read from the firmware. This may not be easy to interpret and also may miss to present any timeouts that happen in the driver.Let us use signed integer so that error values are emitted out after they are mapped from firmware errors to standard linux error codes. While at this, let us also include any timeouts in the driver itself.
Applied to sudeep.holla/linux (for-next/scmi), thanks!
[1/1] firmware: arm_scmi: Use signed integer to report transfer status
https://git.kernel.org/sudeep.holla/c/bad0d73b65
--
Regards,
Sudeep
PATCH 1/1 firmware: arm_scmi: Use HAVE_ARM_SMCCC_DISCOVERY instead of ARM_PSCI_FW
Commit e5bfb21d98b6 ("firmware: smccc: Add HAVE_ARM_SMCCC_DISCOVERY to identify SMCCC v1.1 and above") introduced new config option to identify the availability of SMCCC discoverability of version and features transparently hiding the indirect dependency on ARM_PSCI_FW.
Commit 5a897e3ab429 ("firmware: arm_scmi: fix psci dependency") just worked around the build dependency making SCMI SMC/HVC transport depend on ARM_PSCI_FW at the time. Since it really just relies on SMCCC directly and not on ARM_PSCI_FW, let us move to use CONFIG_HAVE_ARM_SMCCC_DISCOVERY instead of CONFIG_ARM_PSCI_FW.
--- drivers/firmware/arm_scmi/Makefile | 2 +- drivers/firmware/arm_scmi/driver.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/firmware/arm_scmi/Makefile +1 -1
@@ -4,6 +4,6 @@ scmi-bus-y = bus.o scmi-driver-y = driver.o scmi-transport-y = shmem.o scmi-transport-$(CONFIG_MAILBOX) += mailbox.o -scmi-transport-$(CONFIG_ARM_PSCI_FW) += smc.o +scmi-transport-$(CONFIG_HAVE_ARM_SMCCC_DISCOVERY) += smc.o scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o obj-$(CONFIG_ARM_SCMI_POWER_DOMAIN) += scmi_pm_domain.o
drivers/firmware/arm_scmi/driver.c +1 -1
@@ -901,7 +901,7 @@ ATTRIBUTE_GROUPS(versions);/* Each compatible listed below must have descriptor associated with it */ static const struct of_device_id scmi_of_match[] = { { .compatible ="arm,scmi" , .data = &scmi_mailbox_desc }, -#ifdef CONFIG_ARM_PSCI_FW +#ifdef CONFIG_HAVE_ARM_SMCCC_DISCOVERY { .compatible ="arm,scmi-smc" , .data = &scmi_smc_desc}, #endif {/* Sentinel */ },
Signature · 1 line
2.17.1
Cristian Marussi
reviewerv11 cover SCMI Notifications Core Support
Hi all,
this series wants to introduce SCMI Notification Support, built on top of the standard Kernel notification chain subsystem.
At initialization time each SCMI Protocol takes care to register with the new SCMI notification core the set of its own events which it intends to support.
Using the API exposed via scmi_handle.notify_ops a Kernel user can register its own notifier_t callback (via a notifier_block as usual) against any registered event as identified by the tuple:
(proto_id, event_id, src_id)
where src_id represents a generic source identifier which is protocol dependent like domain_id, performance_id, sensor_id and so forth. (users can anyway do NOT provide any src_id, and subscribe instead to ALL
the existing (if any) src_id sources for that proto_id/evt_id combination)
Each of the above tuple-specified events will be served on its own dedicated blocking notification chain, dynamically allocated on-demand when at least one user has shown interest on that event.
Upon a notification delivery all the users' registered notifier_t callbacks will be in turn invoked and fed with the event_id as @action param and a generated custom per-event struct _report as @data param.
(as in include/linux/scmi_protocol.h)
The final step of notification delivery via users' callback invocation is instead delegated to a pool of deferred workers (Kernel cmwq): each SCMI protocol has its own dedicated worker and dedicated queue to push events from the rx ISR to the worker.
Based on scmi-next/for-next/scmi 5.8-rc3 [1], on top of:
commit 29c9e984d8e3 ("firmware: arm_scmi: Fix SCMI genpd domain probing")
This series has been tested on JUNO with an experimental firmware only supporting Perf Notifications.
Thanks
Cristian
----
v10 --> v11:
- fixed macros for argument reuse checkpatch warning
- added missing mutex comments
- removed improper usage of IS_ERR_OR_NULL
- switch to int retvals for some core functions instead of bools
- removed all likely/unlikely
v9 --> v10:
- rebased on top of scmi-next 5.8-rc1
- fixed a couple of Warnings (-Wtype-limit)
v8 --> v9:
- rebased on top of scmi-next 5.8
- moved some pr_info() to dev_dbg()
- moved around some macros definitions (using FIELD_PREPARE properly)
- introduced some meaningful define
- shrunk hashtables' sizes
- shortened the naming of some massively long data struct
v7 --> v8:
- removed unneeded initialized/enabled atomics, added proper barriers
- added a few comments about queueing work item and kfifos
v6 --> v7:
- rebased on top of scmi-next 5.7, dropped the initial 4 patches since now already queued on base scmi-next [1]
- fixed some events' proto initialization
- removed some notify_enabled explicit methods exposed in some protocol_ops since not supposed to be used directly when using this notification framework (and of no other known use)
- exposing SCMI_EVENT_ enums in scmi_protocol.h
- added agent_id field in RESET_ISSUED payload as per reviewed SCMI spec
- removed POWER_STATE_CHANGE_REQUESTED pre-notification definition and handling as per reviewedSCMI spec
- fixed report.timestamp field type
v5 --> v6:
- added handle argument to fill_custom_report() helper
v4 --> v5:
- fixed kernel-doc
- added proper barriers around registered protocols and events initialization
- reviewed queues allocation using devm_add_action_or_reset
- reviewed REVT_NOTIFY_ENABLE macro
v3 --> v4:
- dropped RFC tag
- avoid one unneeded evt payload memcpy on the ISR RC code path by redesigning dispatcher to handle partial queue-reads (in_flight events, only header)
- fixed the initialization issue exposed by late SCMI modules loading by reviewing the init process to support possible late events registrations by protocols and early callbacks registrations by users (pending)
- cleanup/simplification of exit path: SCMI protocols are generally never de-initialized after the initial device creation, so do not deinit notification core either (we do halt the delivery, stop the wq and empty the queues though)
- reduced contention on regustered_events_handler to the minimum during delivery by splitting the common registered_events_handlers hashtable into a number of per-protocol tables
- converted registered_protocols and registered_events hastable to fixed size arrays: simpler and lockless in our usage scenario
v2 --> v3:
- added platform instance awareness to the notification core: a notification instance is created for each known handle
- reviewed notification core initialization and shutdown process
- removed generic non-handle-rooted registration API
- added WQ_SYSFS flag to workqueue instance
v1 --> v2:
- dropped anti-tampering patch
- rebased on top of scmi-for-next-5.6, which includes Viresh series that make SCMI core independent of transport (5c8a47a5a91d)
- add a few new SCMI transport methods on top of Viresh patch to address needs of SCMI Notifications
- reviewed/renamed scmi_handle_xfer_delayed_resp()
- split main SCMI Notification core patch (~1k lines) into three chunks:
protocol-registration / callbacks-registration / dispatch-and-delivery
- removed awkward usage of IDR maps in favour of pure hashtables
- added enable/disable refcounting in notification core (was broken in v1)
- removed per-protocol candidate API: a single generic API is now proposed instead of scmi_register_<proto>_event_notifier(evt_id, *src_id, *nb)
- added handle->notify_ops as an alternative notification API for scmi_driver
- moved ALL_SRCIDs enabled handling from protocol code to core code
- reviewed protocol registration/unregistration logic to use devres
- reviewed cleanup phase on shutdown
- fixed ERROR: reference preceded by free as reported by kbuild test robot
[1] git://git.kernel.org/pub/scm/linux/kernel/git/sudeep.holla/linux.git
Cristian Marussi (9):
firmware: arm_scmi: Add notification protocol-registration
firmware: arm_scmi: Add notification callbacks-registration
firmware: arm_scmi: Add notification dispatch and delivery
firmware: arm_scmi: Enable notification core
firmware: arm_scmi: Add power notifications support
firmware: arm_scmi: Add perf notifications support
firmware: arm_scmi: Add sensor notifications support
firmware: arm_scmi: Add reset notifications support
firmware: arm_scmi: Add base notifications support
drivers/firmware/arm_scmi/Makefile | 2 +- drivers/firmware/arm_scmi/base.c | 108 +- drivers/firmware/arm_scmi/common.h | 4 + drivers/firmware/arm_scmi/driver.c | 10 + drivers/firmware/arm_scmi/notify.c | 1525 +++++++++++++++++++++++++++ drivers/firmware/arm_scmi/notify.h | 66 ++ drivers/firmware/arm_scmi/perf.c | 139 ++- drivers/firmware/arm_scmi/power.c | 92 +- drivers/firmware/arm_scmi/reset.c | 96 +- drivers/firmware/arm_scmi/sensors.c | 69 +- include/linux/scmi_protocol.h | 108 +- 11 files changed, 2189 insertions(+), 30 deletions(-) create mode 100644 drivers/firmware/arm_scmi/notify.c create mode 100644 drivers/firmware/arm_scmi/notify.h
Signature · 1 line
2.17.1
Cristian Marussi
reviewerPATCH v11 1/9 firmware: arm_scmi: Add notification protocol-registration
Add the core SCMI notifications protocol-registration support: allow protocols to register their own set of supported events, during their initialization phase. Notification core can track multiple platform instances by their handles.
---
v10 --> v11
- removed likely/unlikely
- fix set_notify_enabled ops not to use bool retval V9 --> V10
- fixed warning as
V8 --> V9
- shortened massive protocol_ struct naming
- fixed tabs
- reviewed macros to use bitfield.h
- fixed WARN_ON() usage
- switched to dev_dbg/info with proper dev_fmt
- added common define for protocol queue_sz
V7 --> V8
- Fixed init/enable procedure, un-needed atomics removed
V4 --> V5
- fixed kernel-doc
- added barriers for registered protocols and events
- using kfifo_alloc and devm_add_action_or_reset
V3 --> V4
- removed scratch ISR buffer, move scratch BH buffer into protocol descriptor
- converted registered_protocols and registered_events from hashtables into bare fixed-sized arrays
- removed unregister protocols' routines (never called really) V2 --> V3
- added scmi_notify_instance to track target platform instance V1 --> V2
- splitted out of V1 patch 04
- moved from IDR maps to real HashTables to store events
- scmi_notifications_initialized is now an atomic_t
- reviewed protocol registration/unregistration to use devres
- fixed:
drivers/firmware/arm_scmi/notify.c:483:18-23: ERROR:
reference preceded by free on line 482
--- drivers/firmware/arm_scmi/Makefile | 2 +- drivers/firmware/arm_scmi/common.h | 4 + drivers/firmware/arm_scmi/notify.c | 440 +++++++++++++++++++++++++++++ drivers/firmware/arm_scmi/notify.h | 56 ++++ include/linux/scmi_protocol.h | 3 + 5 files changed, 504 insertions(+), 1 deletion(-) create mode 100644 drivers/firmware/arm_scmi/notify.c create mode 100644 drivers/firmware/arm_scmi/notify.h
drivers/firmware/arm_scmi/Makefile +1 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y = scmi-bus.o scmi-driver.o scmi-protocols.o scmi-transport.o scmi-bus-y = bus.o -scmi-driver-y = driver.o +scmi-driver-y = driver.o notify.o scmi-transport-y = shmem.o scmi-transport-$(CONFIG_MAILBOX) += mailbox.o scmi-transport-$(CONFIG_HAVE_ARM_SMCCC_DISCOVERY) += smc.o
drivers/firmware/arm_scmi/common.h +4 -0
@@ -6,6 +6,8 @@* * Copyright (C) 2018 ARM Ltd. */ +#ifndef _SCMI_COMMON_H +#define _SCMI_COMMON_H#include <linux/bitfield.h> #include <linux/completion.h>
@@ -235,3 +237,5 @@ void shmem_fetch_notification(struct scmi_shared_mem __iomem *shmem,void shmem_clear_channel (struct scmi_shared_mem __iomem *shmem);bool shmem_poll_done (struct scmi_shared_mem __iomem *shmem,struct scmi_xfer *xfer); + +#endif /* _SCMI_COMMON_H */
drivers/firmware/arm_scmi/notify.c new file +440 -0
440 lines not on this page · raw message
drivers/firmware/arm_scmi/notify.h new file +56 -0
56 lines not on this page · raw message
include/linux/scmi_protocol.h +3 -0
@@ -233,6 +233,8 @@ struct scmi_reset_ops {* protocol(for internal use only) * @reset_priv: pointer to private data structure specific to reset * protocol(for internal use only) +* @notify_priv: pointer to private data structure specific to notifications +* (for internal use only) */ struct scmi_handle {struct device *dev;
@@ -248,6 +250,7 @@ struct scmi_handle {void *power_priv;void *sensor_priv;void *reset_priv; +void *notify_priv; };enum scmi_std_protocol {
Signature · 1 line
2.17.1
Cristian Marussi
reviewerPATCH v11 2/9 firmware: arm_scmi: Add notification callbacks-registration
In reply to Cristian MarussiAdd the core SCMI notifications callbacks-registration support: allow users to register their own callbacks against the desired events.
Whenever a registration request is issued against a still non existent event, mark such request as pending for later processing, in order to account for possible late initializations of SCMI Protocols associated to loadable drivers.
---
V10 --> V11
- removed likely/unlikely
- fix IS_ERR_OR_NULL
- change bool retvalues funcs to int
- fix set_notify_enable retval to int
V9 --> V10
- fixed warning as
V8 --> V9
- moved out needed defines to previous patch
- fixed unneeded NULL inits in macro
- shrinked hastables' sizes and introduced meaningful defines
- fix comment in scmi_unregister_notifier
- move pr_infos to dev_dbg
- removed MAP_EVT_TO_ENABLE_CMD (will be inlined)
V7 --> V8
- Fixed init check, un-needed atomics removed
V6 --> V7
- removed un-needed ktime.h include
V4 --> V5
- fix kernel-doc
- reviewed REVT_NOTIFY_ENABLE macro
- added matching barrier for late_init
V3 --> V4
- split registered_handlers hashtable on a per-protocol basis to reduce unneeded contention
- introduced pending_handlers table and related late_init worker to finalize handlers registration upon effective protocols' registrations
- introduced further safe accessors macros for registered_protocols and registered_events arrays
V2 --> V3
- refactored get/put event_handler
- removed generic non-handle-based API
V1 --> V2
- splitted out of V1 patch 04
- moved from IDR maps to real HashTables to store event_handlers
- added proper enable_events refcounting via __scmi_enable_evt() [was broken in V1 when using ALL_SRCIDs notification chains]
- reviewed hashtable cleanup strategy in scmi_notifications_exit()
- added scmi_register_event_notifier()/scmi_unregister_event_notifier() to include/linux/scmi_protocol.h as a candidate user API
[no EXPORTs still]
- added notify_ops to handle during initialization as an additional internal API for scmi_drivers
--- drivers/firmware/arm_scmi/notify.c | 726 +++++++++++++++++++++++++++++ include/linux/scmi_protocol.h | 46 ++ 2 files changed, 772 insertions(+)
drivers/firmware/arm_scmi/notify.c +726 -0
@@ -19,18 +19,50 @@* this core its set of supported events using scmi_register_protocol_events(): * all the needed descriptors are stored in the &struct registered_protocols and * &struct registered_events arrays. +* +* Kernel users interested in some specific event can register their callbacks +* providing the usual notifier_block descriptor, since this core implements +* events' delivery using the standard Kernel notification chains machinery. +* +* Given the number of possible events defined by SCMI and the extensibility +* of the SCMI Protocol itself, the underlying notification chains are created +* and destroyed dynamically on demand depending on the number of users +* effectively registered for an event, so that no support structures or chains +* are allocated until at least one user has registered a notifier_block for +* such event. Similarly, events' generation itself is enabled at the platform +* level only after at least one user has registered, and it is shutdown after +* the last user for that event has gone. +* +* All users provided callbacks and allocated notification-chains are stored in +* the @registered_events_handlers hashtable. Callbacks' registration requests +* for still to be registered events are instead kept in the dedicated common +* hashtable @pending_events_handlers. +* +* An event is identified univocally by the tuple (proto_id, evt_id, src_id) +* and is served by its own dedicated notification chain; information contained +* in such tuples is used, in a few different ways, to generate the needed +* hash-keys. +* +* Here proto_id and evt_id are simply the protocol_id and message_id numbers +* as described in the SCMI Protocol specification, while src_id represents an +* optional, protocol dependent, source identifier (like domain_id, perf_id +* or sensor_id and so forth). */ #define dev_fmt (fmt) "SCMI Notifications - " fmt +#define pr_fmt (fmt) "SCMI Notifications - " fmt#include <linux/bitfield.h> #include <linux/bug.h> #include <linux/compiler.h> #include <linux/device.h> #include <linux/err.h> +#include <linux/hashtable.h> #include <linux/kernel.h> #include <linux/kfifo.h> +#include <linux/list.h> #include <linux/mutex.h> +#include <linux/notifier.h> #include <linux/refcount.h> #include <linux/scmi_protocol.h> #include <linux/slab.h>
@@ -55,6 +87,86 @@#define MAKE_ALL_SRCS_KEY (p, e) MAKE_HASH_KEY((p), (e), SRC_ID_MASK) +/* +* Assumes that the stored obj includes its own hash-key in a field named 'key': +* with this simplification this macro can be equally used for all the objects' +* types hashed by this implementation. +* +* @__ht: The hashtable name +* @__obj: A pointer to the object type to be retrieved from the hashtable; +* it will be used as a cursor while scanning the hastable and it will +* be possibly left as NULL when @__k is not found +* @__k: The key to search for +*/ +#define KEY_FIND (__ht, __obj, __k) \ +({ \ + typeof(__k) k_ = __k; \ + typeof(__obj) obj_; \ + \ + hash_for_each_possible((__ht), obj_, hash, k_) \ + if (obj_->key == k_) \ + break; \ + __obj = obj_; \ +}) + +#define KEY_XTRACT_PROTO_ID (key) FIELD_GET(PROTO_ID_MASK, (key)) +#define KEY_XTRACT_EVT_ID (key) FIELD_GET(EVT_ID_MASK, (key)) +#define KEY_XTRACT_SRC_ID (key) FIELD_GET(SRC_ID_MASK, (key)) + +/* +* A set of macros used to access safely @registered_protocols and +* @registered_events arrays; these are fixed in size and each entry is possibly +* populated at protocols' registration time and then only read but NEVER +* modified or removed. +*/ +#define SCMI_GET_PROTO (__ni, __pid) \ +({ \ + typeof(__ni) ni_ = __ni; \ + struct scmi_registered_events_desc *__pd = NULL; \ + \ + if (ni_) \ + __pd = READ_ONCE(ni_->registered_protocols[(__pid)]); \ + __pd; \ +}) + +#define SCMI_GET_REVT_FROM_PD (__pd, __eid) \ +({ \ + typeof(__pd) pd_ = __pd; \ + typeof(__eid) eid_ = __eid; \ + struct scmi_registered_event *__revt = NULL; \ + \ + if (pd_ && eid_ < pd_->num_events) \ + __revt = READ_ONCE(pd_->registered_events[eid_]); \ + __revt; \ +}) + +#define SCMI_GET_REVT (__ni, __pid, __eid) \ +({ \ + struct scmi_registered_event *__revt; \ + struct scmi_registered_events_desc *__pd; \ + \ + __pd = SCMI_GET_PROTO((__ni), (__pid)); \ + __revt = SCMI_GET_REVT_FROM_PD(__pd, (__eid)); \ + __revt; \ +}) + +/* A couple of utility macros to limit cruft when calling protocols' helpers */ +#define REVT_NOTIFY_SET_STATUS (revt, eid, sid, state) \ +({ \ + typeof(revt) r = revt; \ + r->proto->ops->set_notify_enabled(r->proto->ni->handle, \ + (eid), (sid), (state)); \ +}) + +#define REVT_NOTIFY_ENABLE (revt, eid, sid) \ + REVT_NOTIFY_SET_STATUS((revt), (eid), (sid), true) + +#define REVT_NOTIFY_DISABLE (revt, eid, sid) \ + REVT_NOTIFY_SET_STATUS((revt), (eid), (sid), false) + +#define SCMI_PENDING_HASH_SZ 4 +#define SCMI_REGISTERED_HASH_SZ 6 +struct scmi_registered_events_desc ;/**
@@ -62,9 +174,13 @@ struct scmi_registered_events_desc;* core * @gid: GroupID used for devres * @handle: A reference to the platform instance +* @init_work: A work item to perform final initializations of pending handlers +* @pending_mtx: A mutex to protect @pending_events_handlers * @registered_protocols: A statically allocated array containing pointers to * all the registered protocol-level specific information * related to events' handling +* @pending_events_handlers: An hashtable containing all pending events' +* handlers descriptors * * Each platform instance, represented by a handle, has its own instance of * the notification subsystem represented by this structure.
@@ -72,7 +188,11 @@ struct scmi_registered_events_desc;struct scmi_notify_instance {void *gid;struct scmi_handle *handle; +struct work_struct init_work; +/* lock to protect pending_events_handlers */ +struct mutex pending_mtx;struct scmi_registered_events_desc **registered_protocols; + DECLARE_HASHTABLE(pending_events_handlers, SCMI_PENDING_HASH_SZ); };/**
@@ -121,6 +241,9 @@ struct scmi_registered_event;* @registered_events: A dynamically allocated array holding all the registered * events' descriptors, whose fixed-size is determined at * compile time. +* @registered_mtx: A mutex to protect @registered_events_handlers +* @registered_events_handlers: An hashtable containing all events' handlers +* descriptors registered for this protocol * * All protocols that register at least one event have their protocol-specific * information stored here, together with the embedded allocated events_queue.
@@ -141,6 +264,9 @@ struct scmi_registered_events_desc {void *in_flight;int num_events;struct scmi_registered_event **registered_events; +/* mutex to protect registered_events_handlers */ +struct mutex registered_mtx; +DECLARE_HASHTABLE (registered_events_handlers,SCMI_REGISTERED_HASH_SZ ); };/**
@@ -173,6 +299,38 @@ struct scmi_registered_event {struct mutex sources_mtx; }; +/** +* struct scmi_event_handler - Event handler information +* @key: The used hashkey +* @users: A reference count for number of active users for this handler +* @r_evt: A reference to the associated registered event; when this is NULL +* this handler is pending, which means that identifies a set of +* callbacks intended to be attached to an event which is still not +* known nor registered by any protocol at that point in time +* @chain: The notification chain dedicated to this specific event tuple +* @hash: The hlist_node used for collision handling +* @enabled: A boolean which records if event's generation has been already +* enabled for this handler as a whole +* +* This structure collects all the information needed to process a received +* event identified by the tuple (proto_id, evt_id, src_id). +* These descriptors are stored in a per-protocol @registered_events_handlers +* table using as a key a value derived from that tuple. +*/ +struct scmi_event_handler { +u32 key; +refcount_t users; +struct scmi_registered_event *r_evt; +struct blocking_notifier_head chain; +struct hlist_node hash; +bool enabled; +}; + +#define IS_HNDL_PENDING (hndl) (!(hndl)->r_evt) + +static void scmi_put_handler_unlocked (struct scmi_notify_instance *ni, +struct scmi_event_handler *hndl); +/** * scmi_kfifo_free() - Devres action helper to free the kfifo * @kfifo: The kfifo to free
@@ -258,6 +416,10 @@ scmi_allocate_registered_events_desc(struct scmi_notify_instance *ni,return ERR_PTR (-ENOMEM ); pd->num_events = num_events; +/* Initialize per protocol handlers table */ +mutex_init (&pd->registered_mtx); +hash_init (pd->registered_events_handlers); +return pd; }
@@ -349,6 +511,12 @@ int scmi_register_protocol_events(const struct scmi_handle *handle,devres_close_group (ni->handle->dev, ni->gid); +/* +* Finalize any pending events' handler which could have been waiting +* for this protocol's events registration. +*/ +schedule_work (&ni->init_work); +return 0 ; err:
@@ -359,6 +527,558 @@ int scmi_register_protocol_events(const struct scmi_handle *handle,return -ENOMEM ; } +/** +* scmi_allocate_event_handler() - Allocate Event handler +* @ni: A reference to the notification instance to use +* @evt_key: 32bit key uniquely bind to the event identified by the tuple +* (proto_id, evt_id, src_id) +* +* Allocate an event handler and related notification chain associated with +* the provided event handler key. +* Note that, at this point, a related registered_event is still to be +* associated to this handler descriptor (hndl->r_evt == NULL), so the handler +* is initialized as pending. +* +* Context: Assumes to be called with @pending_mtx already acquired. +* Return: the freshly allocated structure on Success +*/ +static struct scmi_event_handler * +scmi_allocate_event_handler (struct scmi_notify_instance *ni,u32 evt_key) +{ +struct scmi_event_handler *hndl; + + hndl =kzalloc (sizeof (*hndl),GFP_KERNEL ); +if (!hndl) +return NULL ; + hndl->key = evt_key; +BLOCKING_INIT_NOTIFIER_HEAD (&hndl->chain); +refcount_set (&hndl->users,1 ); +/* New handlers are created pending */ +hash_add (ni->pending_events_handlers, &hndl->hash, hndl->key); + +return hndl; +} + +/** +* scmi_free_event_handler() - Free the provided Event handler +* @hndl: The event handler structure to free +* +* Context: Assumes to be called with proper locking acquired depending +* on the situation. +*/ +static void scmi_free_event_handler (struct scmi_event_handler *hndl) +{ +hash_del (&hndl->hash); +kfree (hndl); +} + +/** +* scmi_bind_event_handler() - Helper to attempt binding an handler to an event +* @ni: A reference to the notification instance to use +* @hndl: The event handler to bind +* +* If an associated registered event is found, move the handler from the pending +* into the registered table. +* +* Context: Assumes to be called with @pending_mtx already acquired. +* +* Return: 0 on Success +*/ +static inline int scmi_bind_event_handler (struct scmi_notify_instance *ni, +struct scmi_event_handler *hndl) +{ +struct scmi_registered_event *r_evt; + + r_evt =SCMI_GET_REVT (ni,KEY_XTRACT_PROTO_ID (hndl->key), +KEY_XTRACT_EVT_ID (hndl->key)); +if (!r_evt) +return -EINVAL ; + +/* Remove from pending and insert into registered */ +hash_del (&hndl->hash); + hndl->r_evt = r_evt; +mutex_lock (&r_evt->proto->registered_mtx); +hash_add (r_evt->proto->registered_events_handlers, + &hndl->hash, hndl->key); +mutex_unlock (&r_evt->proto->registered_mtx); + +return 0 ; +} + +/** +* scmi_valid_pending_handler() - Helper to check pending status of handlers +* @ni: A reference to the notification instance to use +* @hndl: The event handler to check +* +* An handler is considered pending when its r_evt == NULL, because the related +* event was still unknown at handler's registration time; anyway, since all +* protocols register their supported events once for all at protocols' +* initialization time, a pending handler cannot be considered valid anymore if +* the underlying event (which it is waiting for), belongs to an already +* initialized and registered protocol. +* +* Return: 0 on Success +*/ +static inline int scmi_valid_pending_handler (struct scmi_notify_instance *ni, +struct scmi_event_handler *hndl) +{ +struct scmi_registered_events_desc *pd; + +if (!IS_HNDL_PENDING (hndl)) +return -EINVAL ; + + pd =SCMI_GET_PROTO (ni,KEY_XTRACT_PROTO_ID (hndl->key)); +if (pd) +return -EINVAL ; + +return 0 ; +} + +/** +* scmi_register_event_handler() - Register whenever possible an Event handler +* @ni: A reference to the notification instance to use +* @hndl: The event handler to register +* +* At first try to bind an event handler to its associated event, then check if +* it was at least a valid pending handler: if it was not bound nor valid return +* false. +* +* Valid pending incomplete bindings will be periodically retried by a dedicated +* worker which is kicked each time a new protocol completes its own +* registration phase. +* +* Context: Assumes to be called with @pending_mtx acquired. +* +* Return: 0 on Success +*/ +static int scmi_register_event_handler (struct scmi_notify_instance *ni, +struct scmi_event_handler *hndl) +{ +int ret; + + ret =scmi_bind_event_handler (ni, hndl); +if (!ret) { +dev_dbg (ni->handle->dev,"registered NEW handler - key:%X\n" , + hndl->key); + }else { + ret =scmi_valid_pending_handler (ni, hndl); +if (!ret) +dev_dbg (ni->handle->dev, +"registered PENDING handler - key:%X\n" , + hndl->key); + } + +return ret; +} + +/** +* __scmi_event_handler_get_ops() - Utility to get or create an event handler +* @ni: A reference to the notification instance to use +* @evt_key: The event key to use +* @create: A boolean flag to specify if a handler must be created when +* not already existent +* +* Search for the desired handler matching the key in both the per-protocol +* registered table and the common pending table: +* * if found adjust users refcount +* * if not found and @create is true, create and register the new handler: +* handler could end up being registered as pending if no matching event +* could be found. +* +* An handler is guaranteed to reside in one and only one of the tables at +* any one time; to ensure this the whole search and create is performed +* holding the @pending_mtx lock, with @registered_mtx additionally acquired +* if needed. +* +* Note that when a nested acquisition of these mutexes is needed the locking +* order is always (same as in @init_work): +* 1. pending_mtx +* 2. registered_mtx +* +* Events generation is NOT enabled right after creation within this routine +* since at creation time we usually want to have all setup and ready before +* events really start flowing. +* +* Return: A properly refcounted handler on Success, NULL on Failure +*/ +static inline struct scmi_event_handler * +__scmi_event_handler_get_ops (struct scmi_notify_instance *ni, +u32 evt_key,bool create) +{ +struct scmi_registered_event *r_evt; +struct scmi_event_handler *hndl =NULL ; + + r_evt =SCMI_GET_REVT (ni,KEY_XTRACT_PROTO_ID (evt_key), +KEY_XTRACT_EVT_ID (evt_key)); + +mutex_lock (&ni->pending_mtx); +/* Search registered events at first ... if possible at all */ +if (r_evt) { +mutex_lock (&r_evt->proto->registered_mtx); + hndl =KEY_FIND (r_evt->proto->registered_events_handlers, + hndl, evt_key); +if (hndl) +refcount_inc (&hndl->users); +mutex_unlock (&r_evt->proto->registered_mtx); + } + +/* ...then amongst pending. */ +if (!hndl) { + hndl =KEY_FIND (ni->pending_events_handlers, hndl, evt_key); +if (hndl) +refcount_inc (&hndl->users); + } + +/* Create if still not found and required */ +if (!hndl && create) { + hndl =scmi_allocate_event_handler (ni, evt_key); +if (hndl &&scmi_register_event_handler (ni, hndl)) { +dev_dbg (ni->handle->dev, +"purging UNKNOWN handler - key:%X\n" , + hndl->key); +/* this hndl can be only a pending one */ +scmi_put_handler_unlocked (ni, hndl); + hndl =NULL ; + } + } +mutex_unlock (&ni->pending_mtx); + +return hndl; +} + +static struct scmi_event_handler * +scmi_get_handler (struct scmi_notify_instance *ni,u32 evt_key) +{ +return __scmi_event_handler_get_ops (ni, evt_key, false); +} + +static struct scmi_event_handler * +scmi_get_or_create_handler (struct scmi_notify_instance *ni,u32 evt_key) +{ +return __scmi_event_handler_get_ops (ni, evt_key, true); +} + +/** +* __scmi_enable_evt() - Enable/disable events generation +* @r_evt: The registered event to act upon +* @src_id: The src_id to act upon +* @enable: The action to perform: true->Enable, false->Disable +* +* Takes care of proper refcounting while performing enable/disable: handles +* the special case of ALL sources requests by itself. +* Returns successfully if at least one of the required src_id has been +* successfully enabled/disabled. +* +* Return: 0 on Success +*/ +static inline int __scmi_enable_evt (struct scmi_registered_event *r_evt, +u32 src_id,bool enable) +{ +int retvals =0 ; +u32 num_sources; +refcount_t *sid; + +if (src_id ==SRC_ID_MASK ) { + src_id =0 ; + num_sources = r_evt->num_sources; + }else if (src_id < r_evt->num_sources) { + num_sources =1 ; + }else { +return -EINVAL ; + } + +mutex_lock (&r_evt->sources_mtx); +if (enable) { +for (; num_sources; src_id++, num_sources--) { +int ret =0 ; + + sid = &r_evt->sources[src_id]; +if (refcount_read (sid) ==0 ) { + ret =REVT_NOTIFY_ENABLE (r_evt, r_evt->evt->id, + src_id); +if (!ret) +refcount_set (sid,1 ); + }else { +refcount_inc (sid); + } + retvals += !ret; + } + }else { +for (; num_sources; src_id++, num_sources--) { + sid = &r_evt->sources[src_id]; +if (refcount_dec_and_test (sid)) +REVT_NOTIFY_DISABLE (r_evt, + r_evt->evt->id, src_id); + } + retvals =1 ; + } +mutex_unlock (&r_evt->sources_mtx); + +return retvals ?0 : -EINVAL ; +} + +static int scmi_enable_events (struct scmi_event_handler *hndl) +{ +int ret =0 ; + +if (!hndl->enabled) { + ret =__scmi_enable_evt (hndl->r_evt, +KEY_XTRACT_SRC_ID (hndl->key), true); +if (!ret) + hndl->enabled = true; + } + +return ret; +} + +static int scmi_disable_events (struct scmi_event_handler *hndl) +{ +int ret =0 ; + +if (hndl->enabled) { + ret =__scmi_enable_evt (hndl->r_evt, +KEY_XTRACT_SRC_ID (hndl->key), false); +if (!ret) + hndl->enabled = false; + } + +return ret; +} + +/** +* scmi_put_handler_unlocked() - Put an event handler +* @ni: A reference to the notification instance to use +* @hndl: The event handler to act upon +* +* After having got exclusive access to the registered handlers hashtable, +* update the refcount and if @hndl is no more in use by anyone: +* * ask for events' generation disabling +* * unregister and free the handler itself +* +* Context: Assumes all the proper locking has been managed by the caller. +*/ +static void scmi_put_handler_unlocked (struct scmi_notify_instance *ni, +struct scmi_event_handler *hndl) +{ +if (refcount_dec_and_test (&hndl->users)) { +if (!IS_HNDL_PENDING (hndl)) +scmi_disable_events (hndl); +scmi_free_event_handler (hndl); + } +} + +static void scmi_put_handler (struct scmi_notify_instance *ni, +struct scmi_event_handler *hndl) +{ +struct scmi_registered_event *r_evt = hndl->r_evt; + +mutex_lock (&ni->pending_mtx); +if (r_evt) +mutex_lock (&r_evt->proto->registered_mtx); + +scmi_put_handler_unlocked (ni, hndl); + +if (r_evt) +mutex_unlock (&r_evt->proto->registered_mtx); +mutex_unlock (&ni->pending_mtx); +} + +/** +* scmi_event_handler_enable_events() - Enable events associated to an handler +* @hndl: The Event handler to act upon +* +* Return: 0 on Success +*/ +static int scmi_event_handler_enable_events (struct scmi_event_handler *hndl) +{ +if (scmi_enable_events (hndl)) { +pr_err ("Failed to ENABLE events for key:%X !\n" , hndl->key); +return -EINVAL ; + } + +return 0 ; +} + +/** +* scmi_register_notifier() - Register a notifier_block for an event +* @handle: The handle identifying the platform instance against which the +* callback is registered +* @proto_id: Protocol ID +* @evt_id: Event ID +* @src_id: Source ID, when NULL register for events coming form ALL possible +* sources +* @nb: A standard notifier block to register for the specified event +* +* Generic helper to register a notifier_block against a protocol event. +* +* A notifier_block @nb will be registered for each distinct event identified +* by the tuple (proto_id, evt_id, src_id) on a dedicated notification chain +* so that: +* +* (proto_X, evt_Y, src_Z) --> chain_X_Y_Z +* +* @src_id meaning is protocol specific and identifies the origin of the event +* (like domain_id, sensor_id and so forth). +* +* @src_id can be NULL to signify that the caller is interested in receiving +* notifications from ALL the available sources for that protocol OR simply that +* the protocol does not support distinct sources. +* +* As soon as one user for the specified tuple appears, an handler is created, +* and that specific event's generation is enabled at the platform level, unless +* an associated registered event is found missing, meaning that the needed +* protocol is still to be initialized and the handler has just been registered +* as still pending. +* +* Return: 0 on Success +*/ +static int scmi_register_notifier (const struct scmi_handle *handle, +u8 proto_id,u8 evt_id,u32 *src_id, +struct notifier_block *nb) +{ +int ret =0 ; +u32 evt_key; +struct scmi_event_handler *hndl; +struct scmi_notify_instance *ni; + +/* Ensure notify_priv is updated */ +smp_rmb (); +if (!handle->notify_priv) +return -ENODEV ; + ni = handle->notify_priv; + + evt_key =MAKE_HASH_KEY (proto_id, evt_id, + src_id ? *src_id :SRC_ID_MASK ); + hndl =scmi_get_or_create_handler (ni, evt_key); +if (!hndl) +return -EINVAL ; + +blocking_notifier_chain_register (&hndl->chain, nb); + +/* Enable events for not pending handlers */ +if (!IS_HNDL_PENDING (hndl)) { + ret =scmi_event_handler_enable_events (hndl); +if (ret) +scmi_put_handler (ni, hndl); + } + +return ret; +} + +/** +* scmi_unregister_notifier() - Unregister a notifier_block for an event +* @handle: The handle identifying the platform instance against which the +* callback is unregistered +* @proto_id: Protocol ID +* @evt_id: Event ID +* @src_id: Source ID +* @nb: The notifier_block to unregister +* +* Takes care to unregister the provided @nb from the notification chain +* associated to the specified event and, if there are no more users for the +* event handler, frees also the associated event handler structures. +* (this could possibly cause disabling of event's generation at platform level) +* +* Return: 0 on Success +*/ +static int scmi_unregister_notifier (const struct scmi_handle *handle, +u8 proto_id,u8 evt_id,u32 *src_id, +struct notifier_block *nb) +{ +u32 evt_key; +struct scmi_event_handler *hndl; +struct scmi_notify_instance *ni; + +/* Ensure notify_priv is updated */ +smp_rmb (); +if (!handle->notify_priv) +return -ENODEV ; + ni = handle->notify_priv; + + evt_key =MAKE_HASH_KEY (proto_id, evt_id, + src_id ? *src_id :SRC_ID_MASK ); + hndl =scmi_get_handler (ni, evt_key); +if (!hndl) +return -EINVAL ; + +/* +* Note that this chain unregistration call is safe on its own +* being internally protected by an rwsem. +*/ +blocking_notifier_chain_unregister (&hndl->chain, nb); +scmi_put_handler (ni, hndl); + +/* +* This balances the initial get issued in @scmi_register_notifier. +* If this notifier_block happened to be the last known user callback +* for this event, the handler is here freed and the event's generation +* stopped. +* +* Note that, an ongoing concurrent lookup on the delivery workqueue +* path could still hold the refcount to 1 even after this routine +* completes: in such a case it will be the final put on the delivery +* path which will finally free this unused handler. +*/ +scmi_put_handler (ni, hndl); + +return 0 ; +} + +/** +* scmi_protocols_late_init() - Worker for late initialization +* @work: The work item to use associated to the proper SCMI instance +* +* This kicks in whenever a new protocol has completed its own registration via +* scmi_register_protocol_events(): it is in charge of scanning the table of +* pending handlers (registered by users while the related protocol was still +* not initialized) and finalizing their initialization whenever possible; +* invalid pending handlers are purged at this point in time. +*/ +static void scmi_protocols_late_init (struct work_struct *work) +{ +int bkt; +struct scmi_event_handler *hndl; +struct scmi_notify_instance *ni; +struct hlist_node *tmp; + + ni = container_of(work, struct scmi_notify_instance, init_work); + +/* Ensure protocols and events are up to date */ +smp_rmb (); + +mutex_lock (&ni->pending_mtx); +hash_for_each_safe (ni->pending_events_handlers, bkt, tmp, hndl, hash) { +int ret; + + ret =scmi_bind_event_handler (ni, hndl); +if (!ret) { +dev_dbg (ni->handle->dev, +"finalized PENDING handler - key:%X\n" , + hndl->key); + ret =scmi_event_handler_enable_events (hndl); + }else { + ret =scmi_valid_pending_handler (ni, hndl); + } +if (ret) { +dev_dbg (ni->handle->dev, +"purging PENDING handler - key:%X\n" , + hndl->key); +/* this hndl can be only a pending one */ +scmi_put_handler_unlocked (ni, hndl); + } + } +mutex_unlock (&ni->pending_mtx); +} + +/* +* notify_ops are attached to the handle so that can be accessed +* directly from an scmi_driver to register its own notifiers. +*/ +static struct scmi_notify_ops notify_ops = { + .register_event_notifier = scmi_register_notifier, + .unregister_event_notifier = scmi_unregister_notifier, +}; +/** * scmi_notification_init() - Initializes Notification Core Support * @handle: The handle identifying the platform instance to initialize
@@ -406,6 +1126,12 @@ int scmi_notification_init(struct scmi_handle *handle)if (!ni->registered_protocols) goto err; +mutex_init (&ni->pending_mtx); +hash_init (ni->pending_events_handlers); + +INIT_WORK (&ni->init_work, scmi_protocols_late_init); + + handle->notify_ops = ¬ify_ops; handle->notify_priv = ni;/* Ensure handle is up to date */ smp_wmb ();
include/linux/scmi_protocol.h +46 -0
70 lines not on this page · raw message
Signature · 1 line
2.17.1
Cristian Marussi
reviewerPATCH v11 3/9 firmware: arm_scmi: Add notification dispatch and delivery
In reply to Cristian MarussiAdd the core SCMI notifications dispatch and delivery support logic which is able to dispatch well-known received events from the Rx interrupt handler to the dedicated deferred worker. From there, it will deliver the events to the registered users' callbacks.
Dispatch and delivery support is just added here, still not enabled.
---
V10 --> V11
- removed likely/unlikely
- fix IS_ERR_OR_NULL
V8 --> V9
- fixed pr_ to dev_
V7 --> V8
- Fixed enabled check in scmi_notify() not to use atomics
- Added a few comments about queueing works
V5 --> V6
- added handle argument to fill_custom_report()
V4 --> V5
- fixed kernel-doc
- fixed unneded var initialization
V3 --> V4
- dispatcher now handles dequeuing of events in chunks (header+payload):
handling of these in_flight events let us remove one unneeded memcpy on RX interrupt path (scmi_notify)
- deferred dispatcher now access their own per-protocol handlers' table reducing locking contention on the RX path
V2 --> V3
- exposing wq in sysfs via WQ_SYSFS
V1 --> V2
- splitted out of V1 patch 04
- moved from IDR maps to real HashTables to store event_handlers
- simplified delivery logic
--- drivers/firmware/arm_scmi/notify.c | 367 ++++++++++++++++++++++++++++- drivers/firmware/arm_scmi/notify.h | 10 + 2 files changed, 373 insertions(+), 4 deletions(-)
drivers/firmware/arm_scmi/notify.c +363 -4
@@ -47,6 +47,27 @@* as described in the SCMI Protocol specification, while src_id represents an * optional, protocol dependent, source identifier (like domain_id, perf_id * or sensor_id and so forth). +* +* Upon reception of a notification message from the platform the SCMI RX ISR +* passes the received message payload and some ancillary information (including +* an arrival timestamp in nanoseconds) to the core via @scmi_notify() which +* pushes the event-data itself on a protocol-dedicated kfifo queue for further +* deferred processing as specified in @scmi_events_dispatcher(). +* +* Each protocol has it own dedicated work_struct and worker which, once kicked +* by the ISR, takes care to empty its own dedicated queue, deliverying the +* queued items into the proper notification-chain: notifications processing can +* proceed concurrently on distinct workers only between events belonging to +* different protocols while delivery of events within the same protocol is +* still strictly sequentially ordered by time of arrival. +* +* Events' information is then extracted from the SCMI Notification messages and +* conveyed, converted into a custom per-event report struct, as the void *data +* param to the user callback provided by the registered notifier_block, so that +* from the user perspective his callback will look invoked like: +* +* int user_cb(struct notifier_block *nb, unsigned long event_id, void *report) +* */ #define dev_fmt (fmt) "SCMI Notifications - " fmt
@@ -67,6 +88,7 @@#include <linux/scmi_protocol.h> #include <linux/slab.h> #include <linux/types.h> +#include <linux/workqueue.h> #include "notify.h"
@@ -164,6 +186,13 @@#define REVT_NOTIFY_DISABLE (revt, eid, sid) \ REVT_NOTIFY_SET_STATUS((revt), (eid), (sid), false) +#define REVT_FILL_REPORT (revt, ...) \ +({ \ + typeof(revt) r = revt; \ + r->proto->ops->fill_custom_report(r->proto->ni->handle, \ + __VA_ARGS__); \ +}) +#define SCMI_PENDING_HASH_SZ 4#define SCMI_REGISTERED_HASH_SZ 6
@@ -175,6 +204,7 @@ struct scmi_registered_events_desc;* @gid: GroupID used for devres * @handle: A reference to the platform instance * @init_work: A work item to perform final initializations of pending handlers +* @notify_wq: A reference to the allocated Kernel cmwq * @pending_mtx: A mutex to protect @pending_events_handlers * @registered_protocols: A statically allocated array containing pointers to * all the registered protocol-level specific information
@@ -189,6 +219,7 @@ struct scmi_notify_instance {void *gid;struct scmi_handle *handle;struct work_struct init_work; +struct workqueue_struct *notify_wq;/* lock to protect pending_events_handlers */ struct mutex pending_mtx;struct scmi_registered_events_desc **registered_protocols;
@@ -199,12 +230,16 @@ struct scmi_notify_instance {* struct events_queue - Describes a queue and its associated worker * @sz: Size in bytes of the related kfifo * @kfifo: A dedicated Kernel kfifo descriptor +* @notify_work: A custom work item bound to this queue +* @wq: A reference to the associated workqueue * * Each protocol has its own dedicated events_queue descriptor. */ struct events_queue { -size_t sz; -struct kfifo kfifo; +size_t sz; +struct kfifo kfifo; +struct work_struct notify_work; +struct workqueue_struct *wq; };/**
@@ -328,9 +363,270 @@ struct scmi_event_handler {#define IS_HNDL_PENDING (hndl) (!(hndl)->r_evt) +static struct scmi_event_handler * +scmi_get_active_handler (struct scmi_notify_instance *ni,u32 evt_key); +static void scmi_put_active_handler (struct scmi_notify_instance *ni, +struct scmi_event_handler *hndl);static void scmi_put_handler_unlocked (struct scmi_notify_instance *ni,struct scmi_event_handler *hndl); +/** +* scmi_lookup_and_call_event_chain() - Lookup the proper chain and call it +* @ni: A reference to the notification instance to use +* @evt_key: The key to use to lookup the related notification chain +* @report: The customized event-specific report to pass down to the callbacks +* as their *data parameter. +*/ +static inline void +scmi_lookup_and_call_event_chain (struct scmi_notify_instance *ni, +u32 evt_key,void *report) +{ +int ret; +struct scmi_event_handler *hndl; + +/* +* Here ensure the event handler cannot vanish while using it. +* It is legitimate, though, for an handler not to be found at all here, +* e.g. when it has been unregistered by the user after some events had +* already been queued. +*/ + hndl =scmi_get_active_handler (ni, evt_key); +if (!hndl) +return ; + + ret =blocking_notifier_call_chain (&hndl->chain, +KEY_XTRACT_EVT_ID (evt_key), + report); +/* Notifiers are NOT supposed to cut the chain ... */ +WARN_ON_ONCE (ret &NOTIFY_STOP_MASK ); + +scmi_put_active_handler (ni, hndl); +} + +/** +* scmi_process_event_header() - Dequeue and process an event header +* @eq: The queue to use +* @pd: The protocol descriptor to use +* +* Read an event header from the protocol queue into the dedicated scratch +* buffer and looks for a matching registered event; in case an anomalously +* sized read is detected just flush the queue. +* +* Return: +* * a reference to the matching registered event when found +* * ERR_PTR(-EINVAL) when NO registered event could be found +* * NULL when the queue is empty +*/ +static inline struct scmi_registered_event * +scmi_process_event_header (struct events_queue *eq, +struct scmi_registered_events_desc *pd) +{ +unsigned int outs; +struct scmi_registered_event *r_evt; + + outs =kfifo_out (&eq->kfifo, pd->eh, +sizeof (struct scmi_event_header )); +if (!outs) +return NULL ; +if (outs !=sizeof (struct scmi_event_header )) { +dev_err (pd->ni->handle->dev,"corrupted EVT header. Flush.\n" ); +kfifo_reset_out (&eq->kfifo); +return NULL ; + } + + r_evt =SCMI_GET_REVT_FROM_PD (pd, pd->eh->evt_id); +if (!r_evt) + r_evt =ERR_PTR (-EINVAL ); + +return r_evt; +} + +/** +* scmi_process_event_payload() - Dequeue and process an event payload +* @eq: The queue to use +* @pd: The protocol descriptor to use +* @r_evt: The registered event descriptor to use +* +* Read an event payload from the protocol queue into the dedicated scratch +* buffer, fills a custom report and then look for matching event handlers and +* call them; skip any unknown event (as marked by scmi_process_event_header()) +* and in case an anomalously sized read is detected just flush the queue. +* +* Return: False when the queue is empty +*/ +static inline bool +scmi_process_event_payload (struct events_queue *eq, +struct scmi_registered_events_desc *pd, +struct scmi_registered_event *r_evt) +{ +u32 src_id, key; +unsigned int outs; +void *report =NULL ; + + outs =kfifo_out (&eq->kfifo, pd->eh->payld, pd->eh->payld_sz); +if (!outs) +return false; + +/* Any in-flight event has now been officially processed */ + pd->in_flight =NULL ; + +if (outs != pd->eh->payld_sz) { +dev_err (pd->ni->handle->dev,"corrupted EVT Payload. Flush.\n" ); +kfifo_reset_out (&eq->kfifo); +return false; + } + +if (IS_ERR (r_evt)) { +dev_warn (pd->ni->handle->dev, +"SKIP UNKNOWN EVT - proto:%X evt:%d\n" , + pd->id, pd->eh->evt_id); +return true; + } + + report =REVT_FILL_REPORT (r_evt, pd->eh->evt_id, pd->eh->timestamp, + pd->eh->payld, pd->eh->payld_sz, + r_evt->report, &src_id); +if (!report) { +dev_err (pd->ni->handle->dev, +"report not available - proto:%X evt:%d\n" , + pd->id, pd->eh->evt_id); +return true; + } + +/* At first search for a generic ALL src_ids handler... */ + key =MAKE_ALL_SRCS_KEY (pd->id, pd->eh->evt_id); +scmi_lookup_and_call_event_chain (pd->ni, key, report); + +/* ...then search for any specific src_id */ + key =MAKE_HASH_KEY (pd->id, pd->eh->evt_id, src_id); +scmi_lookup_and_call_event_chain (pd->ni, key, report); + +return true; +} + +/** +* scmi_events_dispatcher() - Common worker logic for all work items. +* @work: The work item to use, which is associated to a dedicated events_queue +* +* Logic: +* 1. dequeue one pending RX notification (queued in SCMI RX ISR context) +* 2. generate a custom event report from the received event message +* 3. lookup for any registered ALL_SRC_IDs handler: +* - > call the related notification chain passing in the report +* 4. lookup for any registered specific SRC_ID handler: +* - > call the related notification chain passing in the report +* +* Note that: +* * a dedicated per-protocol kfifo queue is used: in this way an anomalous +* flood of events cannot saturate other protocols' queues. +* * each per-protocol queue is associated to a distinct work_item, which +* means, in turn, that: +* + all protocols can process their dedicated queues concurrently +* (since notify_wq:max_active != 1) +* + anyway at most one worker instance is allowed to run on the same queue +* concurrently: this ensures that we can have only one concurrent +* reader/writer on the associated kfifo, so that we can use it lock-less +* +* Context: Process context. +*/ +static void scmi_events_dispatcher (struct work_struct *work) +{ +struct events_queue *eq; +struct scmi_registered_events_desc *pd; +struct scmi_registered_event *r_evt; + + eq = container_of(work, struct events_queue, notify_work); + pd = container_of(eq, struct scmi_registered_events_desc, equeue); +/* +* In order to keep the queue lock-less and the number of memcopies +* to the bare minimum needed, the dispatcher accounts for the +* possibility of per-protocol in-flight events: i.e. an event whose +* reception could end up being split across two subsequent runs of this +* worker, first the header, then the payload. +*/ +do { +if (!pd->in_flight) { + r_evt =scmi_process_event_header (eq, pd); +if (!r_evt) +break ; + pd->in_flight = r_evt; + }else { + r_evt = pd->in_flight; + } + }while (scmi_process_event_payload (eq, pd, r_evt)); +} + +/** +* scmi_notify() - Queues a notification for further deferred processing +* @handle: The handle identifying the platform instance from which the +* dispatched event is generated +* @proto_id: Protocol ID +* @evt_id: Event ID (msgID) +* @buf: Event Message Payload (without the header) +* @len: Event Message Payload size +* @ts: RX Timestamp in nanoseconds (boottime) +* +* Context: Called in interrupt context to queue a received event for +* deferred processing. +* +* Return: 0 on Success +*/ +int scmi_notify (const struct scmi_handle *handle,u8 proto_id,u8 evt_id, +const void *buf,size_t len,u64 ts) +{ +struct scmi_registered_event *r_evt; +struct scmi_event_header eh; +struct scmi_notify_instance *ni; + +/* Ensure notify_priv is updated */ +smp_rmb (); +if (!handle->notify_priv) +return 0 ; + ni = handle->notify_priv; + + r_evt =SCMI_GET_REVT (ni, proto_id, evt_id); +if (!r_evt) +return -EINVAL ; + +if (len > r_evt->evt->max_payld_sz) { +dev_err (handle->dev,"discard badly sized message\n" ); +return -EINVAL ; + } +if (kfifo_avail (&r_evt->proto->equeue.kfifo) <sizeof (eh) + len) { +dev_warn (handle->dev, +"queue full, dropping proto_id:%d evt_id:%d ts:%lld\n" , + proto_id, evt_id, ts); +return -ENOMEM ; + } + + eh.timestamp = ts; + eh.evt_id = evt_id; + eh.payld_sz = len; +/* +* Header and payload are enqueued with two distinct kfifo_in() (so non +* atomic), but this situation is handled properly on the consumer side +* with in-flight events tracking. +*/ +kfifo_in (&r_evt->proto->equeue.kfifo, &eh,sizeof (eh)); +kfifo_in (&r_evt->proto->equeue.kfifo, buf, len); +/* +* Don't care about return value here since we just want to ensure that +* a work is queued all the times whenever some items have been pushed +* on the kfifo: +* - if work was already queued it will simply fail to queue a new one +* since it is not needed +* - if work was not queued already it will be now, even in case work +* was in fact already running: this behavior avoids any possible race +* when this function pushes new items onto the kfifos after the +* related executing worker had already determined the kfifo to be +* empty and it was terminating. +*/ +queue_work (r_evt->proto->equeue.wq, + &r_evt->proto->equeue.notify_work); + +return 0 ; +} +/** * scmi_kfifo_free() - Devres action helper to free the kfifo * @kfifo: The kfifo to free
@@ -353,13 +649,22 @@ static void scmi_kfifo_free(void *kfifo)static int scmi_initialize_events_queue (struct scmi_notify_instance *ni,struct events_queue *equeue,size_t sz) { +int ret; +if (kfifo_alloc (&equeue->kfifo, sz,GFP_KERNEL ))return -ENOMEM ;/* Size could have been roundup to power-of-two */ equeue->sz =kfifo_size (&equeue->kfifo); -return devm_add_action_or_reset (ni->handle->dev, scmi_kfifo_free, - &equeue->kfifo); + ret =devm_add_action_or_reset (ni->handle->dev, scmi_kfifo_free, + &equeue->kfifo); +if (ret) +return ret; + +INIT_WORK (&equeue->notify_work, scmi_events_dispatcher); + equeue->wq = ni->notify_wq; + +return ret; }/**
@@ -758,6 +1063,37 @@ scmi_get_or_create_handler(struct scmi_notify_instance *ni, u32 evt_key)return __scmi_event_handler_get_ops (ni, evt_key, true); } +/** +* scmi_get_active_handler() - Helper to get active handlers only +* @ni: A reference to the notification instance to use +* @evt_key: The event key to use +* +* Search for the desired handler matching the key only in the per-protocol +* table of registered handlers: this is called only from the dispatching path +* so want to be as quick as possible and do not care about pending. +* +* Return: A properly refcounted active handler +*/ +static struct scmi_event_handler * +scmi_get_active_handler (struct scmi_notify_instance *ni,u32 evt_key) +{ +struct scmi_registered_event *r_evt; +struct scmi_event_handler *hndl =NULL ; + + r_evt =SCMI_GET_REVT (ni,KEY_XTRACT_PROTO_ID (evt_key), +KEY_XTRACT_EVT_ID (evt_key)); +if (r_evt) { +mutex_lock (&r_evt->proto->registered_mtx); + hndl =KEY_FIND (r_evt->proto->registered_events_handlers, + hndl, evt_key); +if (hndl) +refcount_inc (&hndl->users); +mutex_unlock (&r_evt->proto->registered_mtx); + } + +return hndl; +} +/** * __scmi_enable_evt() - Enable/disable events generation * @r_evt: The registered event to act upon
@@ -883,6 +1219,16 @@ static void scmi_put_handler(struct scmi_notify_instance *ni,mutex_unlock (&ni->pending_mtx); } +static void scmi_put_active_handler (struct scmi_notify_instance *ni, +struct scmi_event_handler *hndl) +{ +struct scmi_registered_event *r_evt = hndl->r_evt; + +mutex_lock (&r_evt->proto->registered_mtx); +scmi_put_handler_unlocked (ni, hndl); +mutex_unlock (&r_evt->proto->registered_mtx); +} +/** * scmi_event_handler_enable_events() - Enable events associated to an handler * @hndl: The Event handler to act upon
@@ -1121,6 +1467,12 @@ int scmi_notification_init(struct scmi_handle *handle) ni->gid = gid; ni->handle = handle; + ni->notify_wq =alloc_workqueue ("scmi_notify" , +WQ_UNBOUND |WQ_FREEZABLE |WQ_SYSFS , +0 ); +if (!ni->notify_wq) + goto err; + ni->registered_protocols =devm_kcalloc (handle->dev,SCMI_MAX_PROTO ,sizeof (char *),GFP_KERNEL );if (!ni->registered_protocols)
@@ -1162,5 +1514,12 @@ void scmi_notification_exit(struct scmi_handle *handle)return ; ni = handle->notify_priv; + handle->notify_priv =NULL ; +/* Ensure handle is up to date */ +smp_wmb (); + +/* Destroy while letting pending work complete */ +destroy_workqueue (ni->notify_wq); +devres_release_group (ni->handle->dev, ni->gid); }
drivers/firmware/arm_scmi/notify.h +10 -0
@@ -35,6 +35,11 @@ struct scmi_event {* @set_notify_enabled: Enable/disable the required evt_id/src_id notifications * using the proper custom protocol commands. * Return 0 on Success +* @fill_custom_report: fills a custom event report from the provided +* event message payld identifying the event +* specific src_id. +* Return NULL on failure otherwise @report now fully +* populated * * Context: Helpers described in &struct scmi_event_ops are called only in * process context.
@@ -42,6 +47,9 @@ struct scmi_event {struct scmi_event_ops {int (*set_notify_enabled)(const struct scmi_handle *handle,u8 evt_id,u32 src_id,bool enabled); +void *(*fill_custom_report)(const struct scmi_handle *handle, +u8 evt_id,u64 timestamp,const void *payld, +size_t payld_sz,void *report,u32 *src_id); };int scmi_notification_init (struct scmi_handle *handle);
@@ -52,5 +60,7 @@ int scmi_register_protocol_events(const struct scmi_handle *handle,const struct scmi_event_ops *ops, const struct scmi_event *evt, int num_events, int num_sources); +int scmi_notify (const struct scmi_handle *handle,u8 proto_id,u8 evt_id, +const void *buf,size_t len,u64 ts);#endif /* _SCMI_NOTIFY_H */
Signature · 1 line
2.17.1
Cristian Marussi
reviewerPATCH v11 4/9 firmware: arm_scmi: Enable notification core
In reply to Cristian MarussiInitialize and enable SCMI notifications core support during bus/driver probe phase, so that protocols can start registering their supported events during their initialization.
---
V3 --> V4
- simplified core initialization: protocols events' registrations is now disjoint from users' callback registrations, so that events' generation can be enabled earlier for registered events and delayed for pending ones in order to support deferred (or missing) protocol initialization
V2 --> V3
- reviewed core initialization: all implemented protocols must complete their protocol-events registration phases before notifications can be enabled as a whole; in the meantime any user's callback registration requests possibly issued while the notifications were not enabled remain pending: a dedicated worker completes the handlers registration once all protocols have been initialized.
NOTE THAT this can lead to ISSUES with late inserted or missing SCMI modules (i.e. for protocols defined in the DT and implemented by the platform but lazily loaded or not loaded at all.), since in these scenarios notifications dispatching will be enabled later or never.
- reviewed core exit: protocol users (devices) are accounted on probe/ remove, and protocols' events are unregisteredonce last user go (can happen only at shutdown)
V1 --> V2
- added timestamping
- moved notification init/exit and using devres
--- drivers/firmware/arm_scmi/driver.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/firmware/arm_scmi/driver.c +10 -0
@@ -26,6 +26,7 @@#include <linux/slab.h> #include "common.h" +#include "notify.h" #define CREATE_TRACE_POINTS #include <trace/events/scmi.h>
@@ -204,11 +205,13 @@ __scmi_xfer_put(struct scmi_xfers_info *minfo, struct scmi_xfer *xfer)static void scmi_handle_notification (struct scmi_chan_info *cinfo,u32 msg_hdr) { +u64 ts;struct scmi_xfer *xfer;struct device *dev = cinfo->dev;struct scmi_info *info =handle_to_scmi_info (cinfo->handle);struct scmi_xfers_info *minfo = &info->rx_minfo; + ts =ktime_get_boottime_ns (); xfer =scmi_xfer_get (cinfo->handle, minfo);if (IS_ERR (xfer)) { dev_err(dev, "failed to get free message slot (%ld)\n",
@@ -221,6 +224,8 @@ static void scmi_handle_notification(struct scmi_chan_info *cinfo, u32 msg_hdr)scmi_dump_header_dbg (dev, &xfer->hdr); info->desc->ops->fetch_notification (cinfo, info->desc->max_msg_size, xfer); +scmi_notify (cinfo->handle, xfer->hdr.protocol_id, + xfer->hdr.id, xfer->rx.buf, xfer->rx.len, ts); trace_scmi_rx_done(xfer->transfer_id, xfer->hdr.id, xfer->hdr.protocol_id, xfer->hdr.seq,
@@ -788,6 +793,9 @@ static int scmi_probe(struct platform_device *pdev)if (ret)return ret; +if (scmi_notification_init (handle)) +dev_err (dev,"SCMI Notifications NOT available.\n" ); + ret =scmi_base_protocol_init (handle);if (ret) {dev_err (dev,"unable to communicate with SCMI(%d)\n" , ret);
@@ -830,6 +838,8 @@ static int scmi_remove(struct platform_device *pdev)struct scmi_info *info =platform_get_drvdata (pdev);struct idr *idr = &info->tx_idr; +scmi_notification_exit (&info->handle); +mutex_lock (&scmi_list_mutex);if (info->users) ret = -EBUSY ;
Signature · 1 line
2.17.1
Cristian Marussi
reviewerPATCH v11 5/9 firmware: arm_scmi: Add power notifications support
In reply to Cristian MarussiMake SCMI power protocol register with the notification core.
---
V10 --> V11
- fix set_notify_enabled
V8 --> V9
- moved pr_info to pr_debug
- removed switch()
- use SCMI_PROTO_QUEUE_SZ
V6 --> V7
- fixed report.timestamp type
- removed POWER_STATE_CHANGE_REQUESTED motification handling (deprecated)
- fixed max_payld_sz initialization
- expose SCMI_EVENT_ in linux/scmi_protocol.h
V5 --> V6
- added handle argument to fill_custom_report()
V4 --> V5
- fixed unsual return construct
V3 --> V4
- scmi_event field renamed
V2 --> V3
- added handle awareness
V1 --> V2
- simplified .set_notify_enabled() implementation moving the ALL_SRCIDs logic out of protocol. ALL_SRCIDs logic is now in charge of the notification core, together with proper reference counting of enables
- switched to devres protocol-registration
--- drivers/firmware/arm_scmi/power.c | 92 +++++++++++++++++++++++++++++-- include/linux/scmi_protocol.h | 12 ++++ 2 files changed, 98 insertions(+), 6 deletions(-)
drivers/firmware/arm_scmi/power.c +86 -6
@@ -5,19 +5,18 @@* Copyright (C) 2018 ARM Ltd. */ +#define pr_fmt (fmt) "SCMI Notifications POWER - " fmt + +#include <linux/scmi_protocol.h> +#include "common.h" +#include "notify.h" enum scmi_power_protocol_cmd {POWER_DOMAIN_ATTRIBUTES =0x3 ,POWER_STATE_SET =0x4 ,POWER_STATE_GET =0x5 ,POWER_STATE_NOTIFY =0x6 , -POWER_STATE_CHANGE_REQUESTED_NOTIFY =0x7 , -}; - -enum scmi_power_protocol_notify { -POWER_STATE_CHANGED =0x0 , -POWER_STATE_CHANGE_REQUESTED =0x1 , };struct scmi_msg_resp_power_attributes {
@@ -48,6 +47,12 @@ struct scmi_power_state_notify {__le32 notify_enable; }; +struct scmi_power_state_notify_payld { +__le32 agent_id; +__le32 domain_id; +__le32 power_state; +}; +struct power_dom_info {bool state_set_sync;bool state_set_async;
@@ -186,6 +191,75 @@ static struct scmi_power_ops power_ops = { .state_get = scmi_power_state_get, }; +static int scmi_power_request_notify (const struct scmi_handle *handle, +u32 domain,bool enable) +{ +int ret; +struct scmi_xfer *t; +struct scmi_power_state_notify *notify; + + ret =scmi_xfer_get_init (handle,POWER_STATE_NOTIFY , +SCMI_PROTOCOL_POWER ,sizeof (*notify),0 , &t); +if (ret) +return ret; + + notify = t->tx.buf; + notify->domain =cpu_to_le32 (domain); + notify->notify_enable = enable ?cpu_to_le32 (BIT (0 )) :0 ; + + ret =scmi_do_xfer (handle, t); + +scmi_xfer_put (handle, t); +return ret; +} + +static int scmi_power_set_notify_enabled (const struct scmi_handle *handle, +u8 evt_id,u32 src_id,bool enable) +{ +int ret; + + ret =scmi_power_request_notify (handle, src_id, enable); +if (ret) +pr_debug ("FAIL_ENABLE - evt[%X] dom[%d] - ret:%d\n" , + evt_id, src_id, ret); + +return ret; +} + +static void *scmi_power_fill_custom_report (const struct scmi_handle *handle, +u8 evt_id,u64 timestamp, +const void *payld,size_t payld_sz, +void *report,u32 *src_id) +{ +const struct scmi_power_state_notify_payld *p = payld; +struct scmi_power_state_changed_report *r = report; + +if (evt_id !=SCMI_EVENT_POWER_STATE_CHANGED ||sizeof (*p) != payld_sz) +return NULL ; + + r->timestamp = timestamp; + r->agent_id =le32_to_cpu (p->agent_id); + r->domain_id =le32_to_cpu (p->domain_id); + r->power_state =le32_to_cpu (p->power_state); + *src_id = r->domain_id; + +return r; +} + +static const struct scmi_event power_events[] = { + { + .id =SCMI_EVENT_POWER_STATE_CHANGED , + .max_payld_sz =sizeof (struct scmi_power_state_notify_payld ), + .max_report_sz = +sizeof (struct scmi_power_state_changed_report ), + }, +}; + +static const struct scmi_event_ops power_event_ops = { + .set_notify_enabled = scmi_power_set_notify_enabled, + .fill_custom_report = scmi_power_fill_custom_report, +}; +static int scmi_power_protocol_init (struct scmi_handle *handle) {int domain;
@@ -214,6 +288,12 @@ static int scmi_power_protocol_init(struct scmi_handle *handle)scmi_power_domain_attributes_get (handle, domain, dom); } +scmi_register_protocol_events (handle, +SCMI_PROTOCOL_POWER ,SCMI_PROTO_QUEUE_SZ , + &power_event_ops, power_events, +ARRAY_SIZE (power_events), + pinfo->num_domains); + pinfo->version = version; handle->power_ops = &power_ops; handle->power_priv = pinfo;
include/linux/scmi_protocol.h +12 -0
@@ -375,4 +375,16 @@ typedef int (*scmi_prot_init_fn_t)(struct scmi_handle *);int scmi_protocol_register (int protocol_id,scmi_prot_init_fn_t fn);void scmi_protocol_unregister (int protocol_id); +/* SCMI Notification API - Custom Event Reports */ +enum scmi_notification_events { +SCMI_EVENT_POWER_STATE_CHANGED =0x0 , +}; + +struct scmi_power_state_changed_report { +u64 timestamp; +u32 agent_id; +u32 domain_id; +u32 power_state; +}; +#endif /* _LINUX_SCMI_PROTOCOL_H */
Signature · 1 line
2.17.1
Cristian Marussi
reviewerPATCH v11 6/9 firmware: arm_scmi: Add perf notifications support
In reply to Cristian MarussiMake SCMI perf protocol register with the notification core.
---
V10 --> V11
- removed likely/unlikely
- Ffix set_notify_enabled
V8 --> V9
- moved pr_info to pr_debug
- inlined MAP_EVT_TO_ENABLE_CMD
- use SCMI_PROTO_QUEUE_SZ
V6 --> V7
- fixed report.timestamp type
- fixed max_payld_sz initialization
- expose SCMI_EVENT_ in linux/scmi_protocol.h
V5 --> V6
- added handle argument to fill_custom_report()
V4 --> V5
- fixed unsual return construct
V3 --> V4
- scmi_event field renamed
V2 --> V3
- added handle awareness
V1 --> V2
- simplified .set_notify_enabled() implementation moving the ALL_SRCIDs logic out of protocol. ALL_SRCIDs logic is now in charge of the notification core, together with proper reference counting of enables
- switched to devres protocol-registration
--- drivers/firmware/arm_scmi/perf.c | 139 +++++++++++++++++++++++++++++-- include/linux/scmi_protocol.h | 17 ++++ 2 files changed, 151 insertions(+), 5 deletions(-)
drivers/firmware/arm_scmi/perf.c +134 -5
@@ -5,15 +5,19 @@* Copyright (C) 2018 ARM Ltd. */ +#define pr_fmt (fmt) "SCMI Notifications PERF - " fmt +#include <linux/bits.h> #include <linux/of.h> #include <linux/io.h> #include <linux/io-64-nonatomic-hi-lo.h> #include <linux/platform_device.h> #include <linux/pm_opp.h> +#include <linux/scmi_protocol.h> #include <linux/sort.h> #include "common.h" +#include "notify.h" enum scmi_performance_protocol_cmd {PERF_DOMAIN_ATTRIBUTES =0x3 ,
@@ -27,11 +31,6 @@ enum scmi_performance_protocol_cmd { PERF_DESCRIBE_FASTCHANNEL = 0xb, }; -enum scmi_performance_protocol_notify { -PERFORMANCE_LIMITS_CHANGED =0x0 , -PERFORMANCE_LEVEL_CHANGED =0x1 , -}; -struct scmi_opp {u32 perf;u32 power;
@@ -86,6 +85,19 @@ struct scmi_perf_notify_level_or_limits {__le32 notify_enable; }; +struct scmi_perf_limits_notify_payld { +__le32 agent_id; +__le32 domain_id; +__le32 range_max; +__le32 range_min; +}; + +struct scmi_perf_level_notify_payld { +__le32 agent_id; +__le32 domain_id; +__le32 performance_level; +}; +struct scmi_msg_resp_perf_describe_levels {__le16 num_returned;__le16 num_remaining;
@@ -158,6 +170,11 @@ struct scmi_perf_info {struct perf_dom_info *dom_info; }; +static enum scmi_performance_protocol_cmd evt_2_cmd[] = { +PERF_NOTIFY_LIMITS , +PERF_NOTIFY_LEVEL , +}; +static int scmi_perf_attributes_get (const struct scmi_handle *handle,struct scmi_perf_info *pi) {
@@ -488,6 +505,29 @@ static int scmi_perf_level_get(const struct scmi_handle *handle, u32 domain,return scmi_perf_mb_level_get (handle, domain, level, poll); } +static int scmi_perf_level_limits_notify (const struct scmi_handle *handle, +u32 domain,int message_id, +bool enable) +{ +int ret; +struct scmi_xfer *t; +struct scmi_perf_notify_level_or_limits *notify; + + ret =scmi_xfer_get_init (handle, message_id,SCMI_PROTOCOL_PERF , +sizeof (*notify),0 , &t); +if (ret) +return ret; + + notify = t->tx.buf; + notify->domain =cpu_to_le32 (domain); + notify->notify_enable = enable ?cpu_to_le32 (BIT (0 )) :0 ; + + ret =scmi_do_xfer (handle, t); + +scmi_xfer_put (handle, t); +return ret; +} +static bool scmi_perf_fc_size_is_valid (u32 msg,u32 size) {if ((msg ==PERF_LEVEL_GET || msg ==PERF_LEVEL_SET ) && size ==4 )
@@ -722,6 +762,89 @@ static struct scmi_perf_ops perf_ops = { .fast_switch_possible = scmi_fast_switch_possible, }; +static int scmi_perf_set_notify_enabled (const struct scmi_handle *handle, +u8 evt_id,u32 src_id,bool enable) +{ +int ret, cmd_id; + +if (evt_id >=ARRAY_SIZE (evt_2_cmd)) +return -EINVAL ; + + cmd_id = evt_2_cmd[evt_id]; + ret =scmi_perf_level_limits_notify (handle, src_id, cmd_id, enable); +if (ret) +pr_debug ("FAIL_ENABLED - evt[%X] dom[%d] - ret:%d\n" , + evt_id, src_id, ret); + +return ret; +} + +static void *scmi_perf_fill_custom_report (const struct scmi_handle *handle, +u8 evt_id,u64 timestamp, +const void *payld,size_t payld_sz, +void *report,u32 *src_id) +{ +void *rep =NULL ; + +switch (evt_id) { +case SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED : + { +const struct scmi_perf_limits_notify_payld *p = payld; +struct scmi_perf_limits_report *r = report; + +if (sizeof (*p) != payld_sz) +break ; + + r->timestamp = timestamp; + r->agent_id =le32_to_cpu (p->agent_id); + r->domain_id =le32_to_cpu (p->domain_id); + r->range_max =le32_to_cpu (p->range_max); + r->range_min =le32_to_cpu (p->range_min); + *src_id = r->domain_id; + rep = r; +break ; + } +case SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED : + { +const struct scmi_perf_level_notify_payld *p = payld; +struct scmi_perf_level_report *r = report; + +if (sizeof (*p) != payld_sz) +break ; + + r->timestamp = timestamp; + r->agent_id =le32_to_cpu (p->agent_id); + r->domain_id =le32_to_cpu (p->domain_id); + r->performance_level =le32_to_cpu (p->performance_level); + *src_id = r->domain_id; + rep = r; +break ; + } +default : +break ; + } + +return rep; +} + +static const struct scmi_event perf_events[] = { + { + .id =SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED , + .max_payld_sz =sizeof (struct scmi_perf_limits_notify_payld ), + .max_report_sz =sizeof (struct scmi_perf_limits_report ), + }, + { + .id =SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED , + .max_payld_sz =sizeof (struct scmi_perf_level_notify_payld ), + .max_report_sz =sizeof (struct scmi_perf_level_report ), + }, +}; + +static const struct scmi_event_ops perf_event_ops = { + .set_notify_enabled = scmi_perf_set_notify_enabled, + .fill_custom_report = scmi_perf_fill_custom_report, +}; +static int scmi_perf_protocol_init (struct scmi_handle *handle) {int domain;
@@ -754,6 +877,12 @@ static int scmi_perf_protocol_init(struct scmi_handle *handle)scmi_perf_domain_init_fc (handle, domain, &dom->fc_info); } +scmi_register_protocol_events (handle, +SCMI_PROTOCOL_PERF ,SCMI_PROTO_QUEUE_SZ , + &perf_event_ops, perf_events, +ARRAY_SIZE (perf_events), + pinfo->num_domains); + pinfo->version = version; handle->perf_ops = &perf_ops; handle->perf_priv = pinfo;
include/linux/scmi_protocol.h +17 -0
@@ -378,6 +378,8 @@ void scmi_protocol_unregister(int protocol_id);/* SCMI Notification API - Custom Event Reports */ enum scmi_notification_events {SCMI_EVENT_POWER_STATE_CHANGED =0x0 , +SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED =0x0 , +SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED =0x1 , };struct scmi_power_state_changed_report {
@@ -387,4 +389,19 @@ struct scmi_power_state_changed_report { u32 power_state; }; +struct scmi_perf_limits_report { +u64 timestamp; +u32 agent_id; +u32 domain_id; +u32 range_max; +u32 range_min; +}; + +struct scmi_perf_level_report { +u64 timestamp; +u32 agent_id; +u32 domain_id; +u32 performance_level; +}; +#endif /* _LINUX_SCMI_PROTOCOL_H */
Signature · 1 line
2.17.1
Cristian Marussi
reviewerPATCH v11 7/9 firmware: arm_scmi: Add sensor notifications support
In reply to Cristian MarussiMake SCMI sensor protocol register with the notification core.
---
V10 --> V11
- fix set_notify_enabled
V8 --> V9
- moved pr_info to pr_debug
- removed switch()
- use SCMI_PROTO_QUEUE_SZ
V6 --> V7
- fixed report.timestamp type
- removed trip_point_notify from .sensor_ops
- fixed max_payld_sz initialization
- expose SCMI_EVENT_ in linux/scmi_protocol.h
V5 --> V6
- added handle argument to fill_custom_report()
V4 --> V5
- fixed unsual return construct
V3 --> V4
- scmi_event field renamed
V2 --> V3
- added handle awareness
V1 --> V2
- simplified .set_notify_enabled() implementation moving the ALL_SRCIDs logic out of protocol. ALL_SRCIDs logic is now in charge of the notification core, together with proper reference counting of enables
- switched to devres protocol-registration
--- drivers/firmware/arm_scmi/sensors.c | 69 ++++++++++++++++++++++++++--- include/linux/scmi_protocol.h | 13 +++--- 2 files changed, 72 insertions(+), 10 deletions(-)
drivers/firmware/arm_scmi/sensors.c +64 -5
@@ -5,7 +5,12 @@* Copyright (C) 2018 ARM Ltd. */ +#define pr_fmt (fmt) "SCMI Notifications SENSOR - " fmt + +#include <linux/scmi_protocol.h> +#include "common.h" +#include "notify.h" enum scmi_sensor_protocol_cmd {SENSOR_DESCRIPTION_GET =0x3 ,
@@ -14,10 +19,6 @@ enum scmi_sensor_protocol_cmd { SENSOR_READING_GET = 0x6, }; -enum scmi_sensor_protocol_notify { -SENSOR_TRIP_POINT_EVENT =0x0 , -}; -struct scmi_msg_resp_sensor_attributes {__le16 num_sensors;u8 max_requests;
@@ -71,6 +72,12 @@ struct scmi_msg_sensor_reading_get {#define SENSOR_READ_ASYNC BIT(0) }; +struct scmi_sensor_trip_notify_payld { +__le32 agent_id; +__le32 sensor_id; +__le32 trip_point_desc; +}; +struct sensors_info {u32 version;int num_sensors;
@@ -271,11 +278,57 @@ static int scmi_sensor_count_get(const struct scmi_handle *handle)static struct scmi_sensor_ops sensor_ops = { .count_get = scmi_sensor_count_get, .info_get = scmi_sensor_info_get, - .trip_point_notify = scmi_sensor_trip_point_notify, .trip_point_config = scmi_sensor_trip_point_config, .reading_get = scmi_sensor_reading_get, }; +static int scmi_sensor_set_notify_enabled (const struct scmi_handle *handle, +u8 evt_id,u32 src_id,bool enable) +{ +int ret; + + ret =scmi_sensor_trip_point_notify (handle, src_id, enable); +if (ret) +pr_debug ("FAIL_ENABLED - evt[%X] dom[%d] - ret:%d\n" , + evt_id, src_id, ret); + +return ret; +} + +static void *scmi_sensor_fill_custom_report (const struct scmi_handle *handle, +u8 evt_id,u64 timestamp, +const void *payld,size_t payld_sz, +void *report,u32 *src_id) +{ +const struct scmi_sensor_trip_notify_payld *p = payld; +struct scmi_sensor_trip_point_report *r = report; + +if (evt_id !=SCMI_EVENT_SENSOR_TRIP_POINT_EVENT || +sizeof (*p) != payld_sz) +return NULL ; + + r->timestamp = timestamp; + r->agent_id =le32_to_cpu (p->agent_id); + r->sensor_id =le32_to_cpu (p->sensor_id); + r->trip_point_desc =le32_to_cpu (p->trip_point_desc); + *src_id = r->sensor_id; + +return r; +} + +static const struct scmi_event sensor_events[] = { + { + .id =SCMI_EVENT_SENSOR_TRIP_POINT_EVENT , + .max_payld_sz =sizeof (struct scmi_sensor_trip_notify_payld ), + .max_report_sz =sizeof (struct scmi_sensor_trip_point_report ), + }, +}; + +static const struct scmi_event_ops sensor_event_ops = { + .set_notify_enabled = scmi_sensor_set_notify_enabled, + .fill_custom_report = scmi_sensor_fill_custom_report, +}; +static int scmi_sensors_protocol_init (struct scmi_handle *handle) {u32 version;
@@ -299,6 +352,12 @@ static int scmi_sensors_protocol_init(struct scmi_handle *handle)scmi_sensor_description_get (handle, sinfo); +scmi_register_protocol_events (handle, +SCMI_PROTOCOL_SENSOR ,SCMI_PROTO_QUEUE_SZ , + &sensor_event_ops, sensor_events, +ARRAY_SIZE (sensor_events), + sinfo->num_sensors); + sinfo->version = version; handle->sensor_ops = &sensor_ops; handle->sensor_priv = sinfo;
include/linux/scmi_protocol.h +8 -5
@@ -176,18 +176,13 @@ enum scmi_sensor_class {* * @count_get: get the count of sensors provided by SCMI * @info_get: get the information of the specified sensor -* @trip_point_notify: control notifications on cross-over events for -* the trip-points * @trip_point_config: selects and configures a trip-point of interest * @reading_get: gets the current value of the sensor */ struct scmi_sensor_ops {int (*count_get)(const struct scmi_handle *handle); -const struct scmi_sensor_info *(*info_get) (const struct scmi_handle *handle,u32 sensor_id); -int (*trip_point_notify)(const struct scmi_handle *handle, -u32 sensor_id,bool enable);int (*trip_point_config)(const struct scmi_handle *handle,u32 sensor_id,u8 trip_id,u64 trip_value); int (*reading_get)(const struct scmi_handle *handle, u32 sensor_id,
@@ -380,6 +375,7 @@ enum scmi_notification_events {SCMI_EVENT_POWER_STATE_CHANGED =0x0 ,SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED =0x0 ,SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED =0x1 , + SCMI_EVENT_SENSOR_TRIP_POINT_EVENT = 0x0, }; struct scmi_power_state_changed_report {
@@ -404,4 +400,11 @@ struct scmi_perf_level_report { u32 performance_level; }; +struct scmi_sensor_trip_point_report { +u64 timestamp; +u32 agent_id; +u32 sensor_id; +u32 trip_point_desc; +}; +#endif /* _LINUX_SCMI_PROTOCOL_H */
Signature · 1 line
2.17.1
Cristian Marussi
reviewerPATCH v11 8/9 firmware: arm_scmi: Add reset notifications support
In reply to Cristian MarussiMake SCMI reset protocol register with the notification core.
---
V10 --> V11
- fix set_notify_enabled
V8 --> V9
- moved pr_info to pr_debug
- removed switch()
- use SCMI_PROTO_QUEUE_SZ
V6 --> V7
- fixed report.timestamp type
- added agent_id notification field
- fixed .max_payld_sz initialization
- expose SCMI_EVENT_ in linux/scmi_protocol.h
V5 --> V6
- added handle argument to fill_custom_report()
V4 --> V5
- fixed unsual return construct
V3 --> V4
- scmi_event field renamed
V2 --> V3
- added handle awareness
V1 --> V2
- simplified .set_notify_enabled() implementation moving the ALL_SRCIDs logic out of protocol. ALL_SRCIDs logic is now in charge of the notification core, together with proper reference counting of enables
- switched to devres protocol-registration
--- drivers/firmware/arm_scmi/reset.c | 96 +++++++++++++++++++++++++++++-- include/linux/scmi_protocol.h | 8 +++ 2 files changed, 100 insertions(+), 4 deletions(-)
drivers/firmware/arm_scmi/reset.c +92 -4
@@ -5,7 +5,12 @@* Copyright (C) 2019 ARM Ltd. */ +#define pr_fmt (fmt) "SCMI Notifications RESET - " fmt + +#include <linux/scmi_protocol.h> +#include "common.h" +#include "notify.h" enum scmi_reset_protocol_cmd {RESET_DOMAIN_ATTRIBUTES =0x3 ,
@@ -13,10 +18,6 @@ enum scmi_reset_protocol_cmd { RESET_NOTIFY = 0x5, }; -enum scmi_reset_protocol_notify { -RESET_ISSUED =0x0 , -}; -#define NUM_RESET_DOMAIN_MASK 0xffff#define RESET_NOTIFY_ENABLE BIT(0)
@@ -40,6 +41,18 @@ struct scmi_msg_reset_domain_reset {#define ARCH_COLD_RESET (ARCH_RESET_TYPE | COLD_RESET_STATE) }; +struct scmi_msg_reset_notify { +__le32 id; +__le32 event_control; +#define RESET_TP_NOTIFY_ALL BIT(0) +}; + +struct scmi_reset_issued_notify_payld { +__le32 agent_id; +__le32 domain_id; +__le32 reset_state; +}; +struct reset_dom_info {bool async_reset;bool reset_notify;
@@ -190,6 +203,75 @@ static struct scmi_reset_ops reset_ops = { .deassert = scmi_reset_domain_deassert, }; +static int scmi_reset_notify (const struct scmi_handle *handle,u32 domain_id, +bool enable) +{ +int ret; +u32 evt_cntl = enable ?RESET_TP_NOTIFY_ALL :0 ; +struct scmi_xfer *t; +struct scmi_msg_reset_notify *cfg; + + ret =scmi_xfer_get_init (handle,RESET_NOTIFY , +SCMI_PROTOCOL_RESET ,sizeof (*cfg),0 , &t); +if (ret) +return ret; + + cfg = t->tx.buf; + cfg->id =cpu_to_le32 (domain_id); + cfg->event_control =cpu_to_le32 (evt_cntl); + + ret =scmi_do_xfer (handle, t); + +scmi_xfer_put (handle, t); +return ret; +} + +static int scmi_reset_set_notify_enabled (const struct scmi_handle *handle, +u8 evt_id,u32 src_id,bool enable) +{ +int ret; + + ret =scmi_reset_notify (handle, src_id, enable); +if (ret) +pr_debug ("FAIL_ENABLED - evt[%X] dom[%d] - ret:%d\n" , + evt_id, src_id, ret); + +return ret; +} + +static void *scmi_reset_fill_custom_report (const struct scmi_handle *handle, +u8 evt_id,u64 timestamp, +const void *payld,size_t payld_sz, +void *report,u32 *src_id) +{ +const struct scmi_reset_issued_notify_payld *p = payld; +struct scmi_reset_issued_report *r = report; + +if (evt_id !=SCMI_EVENT_RESET_ISSUED ||sizeof (*p) != payld_sz) +return NULL ; + + r->timestamp = timestamp; + r->agent_id =le32_to_cpu (p->agent_id); + r->domain_id =le32_to_cpu (p->domain_id); + r->reset_state =le32_to_cpu (p->reset_state); + *src_id = r->domain_id; + +return r; +} + +static const struct scmi_event reset_events[] = { + { + .id =SCMI_EVENT_RESET_ISSUED , + .max_payld_sz =sizeof (struct scmi_reset_issued_notify_payld ), + .max_report_sz =sizeof (struct scmi_reset_issued_report ), + }, +}; + +static const struct scmi_event_ops reset_event_ops = { + .set_notify_enabled = scmi_reset_set_notify_enabled, + .fill_custom_report = scmi_reset_fill_custom_report, +}; +static int scmi_reset_protocol_init (struct scmi_handle *handle) {int domain;
@@ -218,6 +300,12 @@ static int scmi_reset_protocol_init(struct scmi_handle *handle)scmi_reset_domain_attributes_get (handle, domain, dom); } +scmi_register_protocol_events (handle, +SCMI_PROTOCOL_RESET ,SCMI_PROTO_QUEUE_SZ , + &reset_event_ops, reset_events, +ARRAY_SIZE (reset_events), + pinfo->num_domains); + pinfo->version = version; handle->reset_ops = &reset_ops; handle->reset_priv = pinfo;
include/linux/scmi_protocol.h +8 -0
@@ -376,6 +376,7 @@ enum scmi_notification_events {SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED =0x0 ,SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED =0x1 ,SCMI_EVENT_SENSOR_TRIP_POINT_EVENT =0x0 , + SCMI_EVENT_RESET_ISSUED = 0x0, }; struct scmi_power_state_changed_report {
@@ -407,4 +408,11 @@ struct scmi_sensor_trip_point_report { u32 trip_point_desc; }; +struct scmi_reset_issued_report { +u64 timestamp; +u32 agent_id; +u32 domain_id; +u32 reset_state; +}; +#endif /* _LINUX_SCMI_PROTOCOL_H */
Signature · 1 line
2.17.1
Cristian Marussi
reviewerPATCH v11 9/9 firmware: arm_scmi: Add base notifications support
In reply to Cristian MarussiMake SCMI base protocol register with the notification core.
---
V10- >> V11
- fix set_notify_enabled
V8 --> V9
- moved pr_info to pr_debug
- removed switch()
- use SCMI_PROTO_QUEUE_SZ
V6 --> V7
- fixed report.timestamp type
- fix max_payld_sz initialization
- fix report layout and initialization
- expose SCMI_EVENT_ in linux/scmi_protocol.h
V5 --> V6
- added handle argument to fill_custom_report()
V4 --> V5
- fixed unsual return construct
V3 --> V4
- scmi_event field renamed
V2 --> V3
- added handle awareness
V1 --> V2
- simplified .set_notify_enabled() implementation moving the ALL_SRCIDs logic out of protocol. ALL_SRCIDs logic is now in charge of the notification core, together with proper reference counting of enables
- switched to devres protocol-registration
--- drivers/firmware/arm_scmi/base.c | 108 +++++++++++++++++++++++++++++-- include/linux/scmi_protocol.h | 9 +++ 2 files changed, 113 insertions(+), 4 deletions(-)
drivers/firmware/arm_scmi/base.c +104 -4
@@ -5,7 +5,15 @@* Copyright (C) 2018 ARM Ltd. */ +#define pr_fmt (fmt) "SCMI Notifications BASE - " fmt + +#include <linux/scmi_protocol.h> +#include "common.h" +#include "notify.h" + +#define SCMI_BASE_NUM_SOURCES 1 +#define SCMI_BASE_MAX_CMD_ERR_COUNT 1024enum scmi_base_protocol_cmd {BASE_DISCOVER_VENDOR =0x3 ,
@@ -19,16 +27,25 @@ enum scmi_base_protocol_cmd { BASE_RESET_AGENT_CONFIGURATION = 0xb, }; -enum scmi_base_protocol_notify { -BASE_ERROR_EVENT =0x0 , -}; -struct scmi_msg_resp_base_attributes {u8 num_protocols;u8 num_agents;__le16 reserved; }; +struct scmi_msg_base_error_notify { +__le32 event_control; +#define BASE_TP_NOTIFY_ALL BIT(0) +}; + +struct scmi_base_error_notify_payld { +__le32 agent_id; +__le32 error_status; +#define IS_FATAL_ERROR (x) ((x) & BIT(31)) +#define ERROR_CMD_COUNT (x) FIELD_GET(GENMASK(9, 0), (x)) +__le64 msg_reports[SCMI_BASE_MAX_CMD_ERR_COUNT ]; +}; +/** * scmi_base_attributes_get() - gets the implementation details * that are associated with the base protocol.
@@ -222,6 +239,83 @@ static int scmi_base_discover_agent_get(const struct scmi_handle *handle,return ret; } +static int scmi_base_error_notify (const struct scmi_handle *handle,bool enable) +{ +int ret; +u32 evt_cntl = enable ?BASE_TP_NOTIFY_ALL :0 ; +struct scmi_xfer *t; +struct scmi_msg_base_error_notify *cfg; + + ret =scmi_xfer_get_init (handle,BASE_NOTIFY_ERRORS , +SCMI_PROTOCOL_BASE ,sizeof (*cfg),0 , &t); +if (ret) +return ret; + + cfg = t->tx.buf; + cfg->event_control =cpu_to_le32 (evt_cntl); + + ret =scmi_do_xfer (handle, t); + +scmi_xfer_put (handle, t); +return ret; +} + +static int scmi_base_set_notify_enabled (const struct scmi_handle *handle, +u8 evt_id,u32 src_id,bool enable) +{ +int ret; + + ret =scmi_base_error_notify (handle, enable); +if (ret) +pr_debug ("FAIL_ENABLED - evt[%X] ret:%d\n" , evt_id, ret); + +return ret; +} + +static void *scmi_base_fill_custom_report (const struct scmi_handle *handle, +u8 evt_id,u64 timestamp, +const void *payld,size_t payld_sz, +void *report,u32 *src_id) +{ +int i; +const struct scmi_base_error_notify_payld *p = payld; +struct scmi_base_error_report *r = report; + +/* +* BaseError notification payload is variable in size but +* up to a maximum length determined by the struct ponted by p. +* Instead payld_sz is the effective length of this notification +* payload so cannot be greater of the maximum allowed size as +* pointed by p. +*/ +if (evt_id !=SCMI_EVENT_BASE_ERROR_EVENT ||sizeof (*p) < payld_sz) +return NULL ; + + r->timestamp = timestamp; + r->agent_id =le32_to_cpu (p->agent_id); + r->fatal =IS_FATAL_ERROR (le32_to_cpu (p->error_status)); + r->cmd_count =ERROR_CMD_COUNT (le32_to_cpu (p->error_status)); +for (i =0 ; i < r->cmd_count; i++) + r->reports[i] =le64_to_cpu (p->msg_reports[i]); + *src_id =0 ; + +return r; +} + +static const struct scmi_event base_events[] = { + { + .id =SCMI_EVENT_BASE_ERROR_EVENT , + .max_payld_sz =sizeof (struct scmi_base_error_notify_payld ), + .max_report_sz =sizeof (struct scmi_base_error_report ) + +SCMI_BASE_MAX_CMD_ERR_COUNT *sizeof (u64), + }, +}; + +static const struct scmi_event_ops base_event_ops = { + .set_notify_enabled = scmi_base_set_notify_enabled, + .fill_custom_report = scmi_base_fill_custom_report, +}; +int scmi_base_protocol_init (struct scmi_handle *h) {int id, ret;
@@ -256,6 +350,12 @@ int scmi_base_protocol_init(struct scmi_handle *h)dev_dbg (dev,"Found %d protocol(s) %d agent(s)\n" , rev->num_protocols, rev->num_agents); +scmi_register_protocol_events (handle,SCMI_PROTOCOL_BASE , + (4 *SCMI_PROTO_QUEUE_SZ ), + &base_event_ops, base_events, +ARRAY_SIZE (base_events), +SCMI_BASE_NUM_SOURCES ); +for (id =0 ; id < rev->num_agents; id++) {scmi_base_discover_agent_get (handle, id, name);dev_dbg (dev,"Agent %d: %s\n" , id, name);
include/linux/scmi_protocol.h +9 -0
@@ -377,6 +377,7 @@ enum scmi_notification_events {SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED =0x1 ,SCMI_EVENT_SENSOR_TRIP_POINT_EVENT =0x0 ,SCMI_EVENT_RESET_ISSUED =0x0 , + SCMI_EVENT_BASE_ERROR_EVENT = 0x0, }; struct scmi_power_state_changed_report {
@@ -415,4 +416,12 @@ struct scmi_reset_issued_report { u32 reset_state; }; +struct scmi_base_error_report { +u64 timestamp; +u32 agent_id; +bool fatal; +u16 cmd_count; +u64 reports[0 ]; +}; +#endif /* _LINUX_SCMI_PROTOCOL_H */
Signature · 1 line
2.17.1