Introduce SCI-mediator feature
cover Introduce SCI-mediator feature
Introducing the feature, called SCI mediator.
It's purpose is to redirect SCMI requests from the domains to firmware (SCP, ATF etc), which controls the power/clock/resets etc.
The idea is to make SCP firmware (or similar, such as AT-F) responsible for control power/clock/resets and provide SCMI interface so controls can be shared between the Domains.
Originally, we've met a problem, that the devices, shared between different Domains, can't have an access to HW registers to work with clocks/resets/power etc. You have to pass cpg to the Domain, so the devices can access HW directly. The solution for this is to move HW controls over power/clock/resets to SCP firmware and use Linux-kernel SCMI drivers to pass requests to SCP. Xen is responsible for permissions setting, so Domain can access only to power/clock/resets which are related to this Domain. Also XEN is the mediator which redirects SCMI requests, adding agentID so firmware should know the sender.
SMC is currently used as transport, but this should be configurable.
Here is the high level design:
SCI (System Control Interface) feature can be enabled in xen_config:
Quoted 1 line
CONFIG_SCI=y
Mediator can be configured:
Quoted 1 line
CONFIG_SCMI_SMC=y
Currently, only SCMI_SMC mediator is implemented, which using shared memory region to communicate with firmware and SMC as transport.
Xen scmi should be configured in the device-tree.
Format is the following:
cpu_scp_shm: scp-shmem@0x53FF0000 {
compatible = "arm,scmi-shmem";
reg = <0x0 0x53FF0000 0x0 0x1000>;
};
firmware {
scmi {
compatible = "arm,scmi-smc";
arm,smc-id = <0x82000002>;
shmem = <&cpu_scp_shm>;
#address-cells = <1>;
#size-cells = <0>;
scmi_power: protocol@11 {
reg = <0x11>;
#power-domain-cells = <1>;
};
scmi_clock: protocol@14 {
reg = <0x14>;
#clock-cells = <1>;
};
scmi_reset: protocol@16 {
reg = <0x16>;
#reset-cells = <1>;
};
};
};Where:&cpu_scp_shm is the shared memory for scmi buffers;0x53FF0000, size 0x1000 is the platform specific free address, which provide space for the communication.
&scmi node, which should be copied to Dom0 device-tree.
Device configured to use scmi:
&avb {
scmi_devid = <0>;
clocks = <&scmi_clock 0>;
power-domains = <&scmi_power 0>;
resets = <&scmi_reset 0>;
};Where:scmi_devid - id from the firmware, which is assigned for AVB.
During initialization, XEN scans probes the first SCI-mediator driver which has matching node in the device-tree. If no device-tree was provided, then the first registered mediator driver should be probed.
DomX should be configured:
Device-tree should include the same nodes, described above. &cpu_scp_shm should be altered during domain creation. Xen allocates free page from the memory region, provided in &cpu_scp_shm in XEN device-tree, so each domain should have unique page. Nodes &cpu_scp_shm and /firmware/scmi should be copied from partial device-tree to domain device-tree, so kernel can initialize scmi driver.
SCI mediator can be enabled in dom.cfg the following way:
Quoted 1 line
sci = "
scmi_smc"
which sets scmi_smc to be used for the domain.
Oleksii Moisieiev (5):
xen/arm: add support for Renesas R-Car Gen3 platform xen/arm: add generic SCI mediator framework xen/arm: introduce SCMI-SMC mediator driver tools/arm: add "scmi_smc" option to xl.cfg xen/arm: add SCI mediator support for DomUs
MAINTAINERS | 6 + docs/man/xl.cfg.5.pod.in | 22 + tools/include/libxl.h | 5 + tools/include/xenctrl.h | 3 + tools/include/xenguest.h | 2 + tools/libs/ctrl/xc_domain.c | 23 + tools/libs/guest/xg_dom_arm.c | 5 +- tools/libs/light/libxl_arm.c | 122 ++++- tools/libs/light/libxl_create.c | 54 +- tools/libs/light/libxl_dom.c | 1 + tools/libs/light/libxl_internal.h | 4 + tools/libs/light/libxl_types.idl | 6 + tools/xl/xl_parse.c | 9 + xen/arch/arm/Kconfig | 10 + xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 24 + xen/arch/arm/domain_build.c | 11 + xen/arch/arm/domctl.c | 15 + xen/arch/arm/platforms/Makefile | 1 + xen/arch/arm/platforms/rcar3.c | 47 ++ xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 2 + xen/arch/arm/sci/sci.c | 128 +++++ xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++ xen/arch/arm/setup.c | 1 + xen/arch/arm/xen.lds.S | 7 + xen/include/asm-arm/domain.h | 4 + xen/include/asm-arm/sci/sci.h | 162 ++++++ xen/include/public/arch-arm.h | 11 + xen/include/public/domctl.h | 9 + 30 files changed, 1485 insertions(+), 15 deletions(-) create mode 100644 xen/arch/arm/platforms/rcar3.c create mode 100644 xen/arch/arm/sci/Kconfig create mode 100644 xen/arch/arm/sci/Makefile create mode 100644 xen/arch/arm/sci/sci.c create mode 100644 xen/arch/arm/sci/scmi_smc.c create mode 100644 xen/include/asm-arm/sci/sci.h
Signature · 1 line
2.27.0
RFC 1/5 xen/arm: add support for Renesas R-Car Gen3 platform
Implementation includes platform-specific smc handler for rcar3 platform.
--- xen/arch/arm/platforms/Makefile | 1 + xen/arch/arm/platforms/rcar3.c | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 xen/arch/arm/platforms/rcar3.c
xen/arch/arm/platforms/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_ALL32_PLAT) += exynos5.o obj-$(CONFIG_ALL32_PLAT) += midway.o obj-$(CONFIG_ALL32_PLAT) += omap5.o obj-$(CONFIG_ALL32_PLAT) += rcar2.o +obj-$(CONFIG_RCAR3) += rcar3.o obj-$(CONFIG_ALL64_PLAT) += seattle.o obj-$(CONFIG_ALL_PLAT) += sunxi.o obj-$(CONFIG_ALL64_PLAT) += thunderx.o
xen/arch/arm/platforms/rcar3.c new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [RFC v1 1/5] xen/arm: add support for Renesas R-Car Gen3 platform
Hi, Oleksii!
Quoted 3 lines · Oleksii Moisieiev
Implementation includes platform-specific smc handler for rcar3 platform.
Signed-off-by Oleksii Moisieiev <[email protected]>
Quoted 70 lines
--- xen/arch/arm/platforms/Makefile | 1 + xen/arch/arm/platforms/rcar3.c | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+)create mode 100644
xen/arch/arm/platforms/rcar3.cxen/arch/arm/platforms/Makefile +1
-0@@ -4,6 +4,7 @@ obj-$(CONFIG_ALL32_PLAT) += exynos5.o obj-$(CONFIG_ALL32_PLAT) += midway.o obj-$(CONFIG_ALL32_PLAT) += omap5.o obj-$(CONFIG_ALL32_PLAT) += rcar2.o +obj-$(CONFIG_RCAR3) += rcar3.o obj-$(CONFIG_ALL64_PLAT) += seattle.o obj-$(CONFIG_ALL_PLAT) += sunxi.o obj-$(CONFIG_ALL64_PLAT) += thunderx.oxen/arch/arm/platforms/rcar3.c new file +46
-0@@ -0,0 +1,46 @@ +/* +* xen/arch/arm/platforms/rcar3.c +* +* Renesas R-Car Gen3 specific settings +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021 EPAM Systems +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/platform.h> + +static bool rcar3_smc (struct cpu_user_regs *regs) +{ +return false; +} + +static const char *const rcar3_dt_compat[]__initconst = +{ +"renesas,r8a7795" , +"renesas,r8a7796" , +NULL +}; + +PLATFORM_START (rcar3,"Renesas R-Car Gen3" ) + .compatible = rcar3_dt_compat, + .smc = rcar3_smc +PLATFORM_END + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Re: [RFC v1 1/5] xen/arm: add support for Renesas R-Car Gen3 platform
Hi Oleksandr,
Thank you for the point.
I will add it to the next patch version.
Best regards,
Oleksii
Quoted 78 lines · Oleksandr Andrushchenko
Hi, Oleksii!
Quoted 3 lines · Oleksii Moisieiev
Implementation includes platform-specific smc handler for rcar3 platform.
Signed-off-by Oleksii Moisieiev <[email protected]>Reviewed-by Oleksandr Andrushchenko <[email protected]>Quoted 70 lines
--- xen/arch/arm/platforms/Makefile | 1 + xen/arch/arm/platforms/rcar3.c | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+)create mode 100644
xen/arch/arm/platforms/rcar3.cxen/arch/arm/platforms/Makefile +1
-0@@ -4,6 +4,7 @@ obj-$(CONFIG_ALL32_PLAT) += exynos5.o obj-$(CONFIG_ALL32_PLAT) += midway.o obj-$(CONFIG_ALL32_PLAT) += omap5.o obj-$(CONFIG_ALL32_PLAT) += rcar2.o +obj-$(CONFIG_RCAR3) += rcar3.o obj-$(CONFIG_ALL64_PLAT) += seattle.o obj-$(CONFIG_ALL_PLAT) += sunxi.o obj-$(CONFIG_ALL64_PLAT) += thunderx.oxen/arch/arm/platforms/rcar3.c new file +46
-0@@ -0,0 +1,46 @@ +/* +* xen/arch/arm/platforms/rcar3.c +* +* Renesas R-Car Gen3 specific settings +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021 EPAM Systems +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/platform.h> + +static bool rcar3_smc (struct cpu_user_regs *regs) +{ +return false; +} + +static const char *const rcar3_dt_compat[]__initconst = +{ +"renesas,r8a7795" , +"renesas,r8a7796" , +NULL +}; + +PLATFORM_START (rcar3,"Renesas R-Car Gen3" ) + .compatible = rcar3_dt_compat, + .smc = rcar3_smc +PLATFORM_END + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Re: [RFC v1 1/5] xen/arm: add support for Renesas R-Car Gen3 platform
In reply to Oleksii MoisieievHi,
Quoted 42 lines · Oleksii Moisieiev
Implementation includes platform-specific smc handler for rcar3 platform.
Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/platforms/Makefile | 1 + xen/arch/arm/platforms/rcar3.c | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+)create mode 100644
xen/arch/arm/platforms/rcar3.cxen/arch/arm/platforms/Makefile +1
-0@@ -4,6 +4,7 @@ obj-$(CONFIG_ALL32_PLAT) += exynos5.o obj-$(CONFIG_ALL32_PLAT) += midway.o obj-$(CONFIG_ALL32_PLAT) += omap5.o obj-$(CONFIG_ALL32_PLAT) += rcar2.o +obj-$(CONFIG_RCAR3) += rcar3.o obj-$(CONFIG_ALL64_PLAT) += seattle.o obj-$(CONFIG_ALL_PLAT) += sunxi.o obj-$(CONFIG_ALL64_PLAT) += thunderx.oxen/arch/arm/platforms/rcar3.c new file +15
-0@@ -0,0 +1,46 @@ +/* +* xen/arch/arm/platforms/rcar3.c +* +* Renesas R-Car Gen3 specific settings +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021 EPAM Systems +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of
xen/arch/arm/platforms/rcar3.c line 25
Quoted 10 lines
xen/arch/arm/platforms/rcar3.c new file +10
-0+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/platform.h> + +static bool rcar3_smc (struct cpu_user_regs *regs) +{ +return false; +}
Looking at the rest of the series, this is going to be replaced in patch #2 with:
return sci_handle_call();
SCMI is not specific to RCAR3. So I would expect the function to be called from common code.
If it still needs some platform specific code, then I think it would be best to introduce rcar3.c at the end of the series. So we don't introduce a dummy platform and not hook the code in the middle of patch#2 which is meant to be generic.
I will have a proper review of the rest of the series in the new year.
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC v1 1/5] xen/arm: add support for Renesas R-Car Gen3 platform
Hi Julien,
Quoted 10 lines · Julien Grall
Hi,
Looking at the rest of the series, this is going to be replaced in patch #2 with:
return
sci_handle_call();SCMI is not specific to RCAR3. So I would expect the function to be called from common code.
Quoted 11 lines
If it still needs some platform specific code, then I think it would be best to introduce
rcar3.cat the end of the series. So we don't introduce a dummy platform and not hook the code in the middle of patch#2 which is meant to be generic.I will have a proper review of the rest of the series in the new year.
Cheers,
Signature · 1 line
Julien Grall
That's sound reasonable. My first thought was to move SCM func_id to the different section, such as Arm Architecture Service (see Section 6 of DEN0028D). But I think that SiP service func_id fits best in this case because from guest standpoint all clocks\resets\power-domain ids are SoC implementation specific.
I'm going to leave SMC func_id in SiP range, but refactor SIP smc handler, so no RCAR3 specific code will be needed. So there will be no need to introduce rcar3.c in this patch series.
What do you think about that?
Best regards,
Oleksii.
Re: [RFC v1 1/5] xen/arm: add support for Renesas R-Car Gen3 platform
In reply to Oleksii MoisieievOn Tue, Dec 14, 2021 at 11:35 AM Oleksii Moisieiev < [email protected]> wrote:
Hi Oleksii
[sorry for the possible format issues]
Implementation includes platform-specific smc handler for rcar3 platform.
Quoted 49 lines
Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/platforms/Makefile | 1 + xen/arch/arm/platforms/rcar3.c | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 xen/arch/arm/platforms/rcar3.cxen/arch/arm/platforms/Makefile +1
-0@@ -4,6 +4,7 @@ obj-$(CONFIG_ALL32_PLAT) += exynos5.o obj-$(CONFIG_ALL32_PLAT) += midway.o obj-$(CONFIG_ALL32_PLAT) += omap5.o obj-$(CONFIG_ALL32_PLAT) += rcar2.o +obj-$(CONFIG_RCAR3) += rcar3.o obj-$(CONFIG_ALL64_PLAT) += seattle.o obj-$(CONFIG_ALL_PLAT) += sunxi.o obj-$(CONFIG_ALL64_PLAT) += thunderx.oxen/arch/arm/platforms/rcar3.c new file +20
-0@@ -0,0 +1,46 @@ +/* +* xen/arch/arm/platforms/rcar3.c +* +* Renesas R-Car Gen3 specific settings +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021 EPAM Systems +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/platform.h>
xen/arch/arm/platforms/rcar3.c line 30
Quoted 10 lines
xen/arch/arm/platforms/rcar3.c new file +10
-0+ +static bool rcar3_smc (struct cpu_user_regs *regs) +{ +return false; +} + +static const char *const rcar3_dt_compat[]__initconst = +{ +"renesas,r8a7795" , +"renesas,r8a7796" ,
Please note that since Linux commit:
"9c9f7891093b02eb64ca4e1c7ab776a4296c058f soc: renesas: Identify R-Car M3-W+"
the compatible string for R-Car M3-W+ (ES3.0) SoC is "renesas,r8a77961". So in case we want to have vSCMI feature on this new SoC revision as well we will need
to extend the compatible list.
+ NULL
Quoted 19 lines
xen/arch/arm/platforms/rcar3.c new file +15
-1+}; + +PLATFORM_START (rcar3,"Renesas R-Car Gen3" ) + .compatible = rcar3_dt_compat, + .smc = rcar3_smc +PLATFORM_END + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ --2.27.0
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [RFC v1 1/5] xen/arm: add support for Renesas R-Car Gen3 platform
Hi Oleksandr,
Quoted 69 lines · Oleksandr Tyshchenko
On Tue, Dec 14, 2021 at 11:35 AM Oleksii Moisieiev < [email protected]> wrote:
Hi Oleksii
[sorry for the possible format issues]
Implementation includes platform-specific smc handler for rcar3 platform.
Quoted 49 lines
Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/platforms/Makefile | 1 + xen/arch/arm/platforms/rcar3.c | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 xen/arch/arm/platforms/rcar3.cxen/arch/arm/platforms/Makefile +1
-0@@ -4,6 +4,7 @@ obj-$(CONFIG_ALL32_PLAT) += exynos5.o obj-$(CONFIG_ALL32_PLAT) += midway.o obj-$(CONFIG_ALL32_PLAT) += omap5.o obj-$(CONFIG_ALL32_PLAT) += rcar2.o +obj-$(CONFIG_RCAR3) += rcar3.o obj-$(CONFIG_ALL64_PLAT) += seattle.o obj-$(CONFIG_ALL_PLAT) += sunxi.o obj-$(CONFIG_ALL64_PLAT) += thunderx.oxen/arch/arm/platforms/rcar3.c new file +20
-0@@ -0,0 +1,46 @@ +/* +* xen/arch/arm/platforms/rcar3.c +* +* Renesas R-Car Gen3 specific settings +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021 EPAM Systems +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/platform.h> xen/arch/arm/platforms/rcar3.c line 30
Quoted 10 lines
xen/arch/arm/platforms/rcar3.c new file +10
-0+ +static bool rcar3_smc (struct cpu_user_regs *regs) +{ +return false; +} + +static const char *const rcar3_dt_compat[]__initconst = +{ +"renesas,r8a7795" , +"renesas,r8a7796" ,
Quoted 8 lines
Please note that since Linux commit:
"9c9f7891093b02eb64ca4e1c7ab776a4296c058fsoc: renesas: Identify R-Car M3-W+"
the compatible string for R-Car M3-W+ (ES3.0) SoC is "renesas,r8a77961". So in case we want to have vSCMI feature on this new SoC revision as well we will need
to extend the compatible list.
Thank you for the point, this will be fixed in v2.
Best regards,
Oleksii
Quoted 26 lines
+ NULL
Quoted 19 lines
xen/arch/arm/platforms/rcar3.c new file +15
-1+}; + +PLATFORM_START (rcar3,"Renesas R-Car Gen3" ) + .compatible = rcar3_dt_compat, + .smc = rcar3_smc +PLATFORM_END + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ --2.27.0
Signature · 3 lines
Regards, Oleksandr Tyshchenko
RFC 2/5 xen/arm: add generic SCI mediator framework
In reply to Oleksii MoisieievThis patch adds the basic framework for SCI mediator.
SCI is System Control Interface, which is designed to redirect requests for the Hardware (such as power-domain/clock/resets etc) from the Domains to the firmware. Originally, cpg should be passed to the domain so it can work with power-domains/clocks/resets etc. Considering that cpg can't be split between the Domains, we get the limitation that the devices, which are using power-domains/clocks/resets etc, couldn't be split between the domains.
The solution is to move the power-domain/clock/resets etc to the Firmware (such as SCP firmware or ATF) and provide interface for the Domains. XEN shoud have an entity, caled SCI-Mediator, which is responsible for messages redirection between Domains and Firmware and for permission handling.
This is how it works: user can build XEN with multiple SCI mediators. See the next patches, where SCMI-SMC mediator is introduced. SCI mediator register itself with REGISTER_SCI_MEDIATOR() macro.
At run-time, during initialization, framework calls probe for the first matching device in the device-tree. When no device-tree is present - the first registered mediator should be probed.
--- MAINTAINERS | 6 ++ xen/arch/arm/Kconfig | 8 ++ xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 24 +++++ xen/arch/arm/domain_build.c | 11 +++ xen/arch/arm/platforms/rcar3.c | 3 +- xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/sci.c | 128 ++++++++++++++++++++++++++ xen/arch/arm/setup.c | 1 + xen/arch/arm/xen.lds.S | 7 ++ xen/include/asm-arm/domain.h | 4 + xen/include/asm-arm/sci/sci.h | 162 +++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 10 ++ 13 files changed, 365 insertions(+), 1 deletion(-) create mode 100644 xen/arch/arm/sci/Makefile create mode 100644 xen/arch/arm/sci/sci.c create mode 100644 xen/include/asm-arm/sci/sci.h
MAINTAINERS +6 -0
@@ -512,6 +512,12 @@ S: Supported F: xen/arch/arm/tee/ F: xen/include/asm-arm/tee +SCI MEDIATORS +M: Oleksii Moisieiev <[email protected]> +S: Supported +F: xen/arch/arm/sci +F: xen/include/asm-arm/sci + TOOLSTACK M: Wei Liu <[email protected]> S: Supported
xen/arch/arm/Kconfig +8 -0
@@ -106,6 +106,14 @@ config TEE source "arch/arm/tee/Kconfig" +config SCI + bool "Enable SCI mediators support" + default n + help + This option enables generic SCI (System Control Interface) mediators + support. It allows guests to control system resourcess via one of + SCI mediators implemented in XEN. + endmenu menu "ARM errata workaround via the alternative framework"
xen/arch/arm/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-y += platforms/ endif obj-$(CONFIG_TEE) += tee/ obj-$(CONFIG_HAS_VPCI) += vpci.o +obj-$(CONFIG_SCI) += sci/ obj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o obj-y += bootfdt.init.o
xen/arch/arm/domain.c +24 -0
@@ -34,6 +34,7 @@#include <asm/platform.h> #include <asm/procinfo.h> #include <asm/regs.h> +#include <asm/sci/sci.h> #include <asm/tee/tee.h> #include <asm/vfp.h> #include <asm/vgic.h>
@@ -688,6 +689,13 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)return -EINVAL ; } +if ( config->arch.sci_type !=XEN_DOMCTL_CONFIG_SCI_NONE && + config->arch.sci_type !=sci_get_type () ) + { +dprintk (XENLOG_INFO ,"Unsupported SCI type\n" ); +return -EINVAL ; + } +return 0 ; }
@@ -764,6 +772,15 @@ int arch_domain_create(struct domain *d,/* At this stage vgic_reserve_virq should never fail */ if ( !vgic_reserve_virq (d,GUEST_EVTCHN_PPI ) )BUG (); + +if ( config->arch.sci_type !=XEN_DOMCTL_CONFIG_SCI_NONE ) + { +if ( (rc =sci_domain_init (d, config->arch.sci_type)) !=0 ) + goto fail; + +if ( (rc =sci_get_channel_info (d, &config->arch)) !=0 ) + goto fail; + } }/*
@@ -796,6 +813,7 @@ void arch_domain_destroy(struct domain *d)domain_vgic_free (d);domain_vuart_free (d);free_xenheap_page (d->shared_info); +sci_domain_destroy (d);#ifdef CONFIG_ACPI free_xenheap_pages (d->arch.efi_acpi_table,get_order_from_bytes (d->arch.efi_acpi_len));
@@ -996,6 +1014,7 @@ enum { PROG_xen, PROG_page, PROG_mapping, + PROG_sci, PROG_done, };
@@ -1056,6 +1075,11 @@ int domain_relinquish_resources(struct domain *d)if ( ret )return ret; + PROGRESS(sci): + ret =sci_relinquish_resources (d); +if ( ret ) +return ret; + PROGRESS(done): break;
xen/arch/arm/domain_build.c +11 -0
@@ -22,6 +22,7 @@#include <asm/kernel.h> #include <asm/setup.h> #include <asm/tee/tee.h> +#include <asm/sci/sci.h> #include <asm/platform.h> #include <asm/psci.h> #include <asm/setup.h>
@@ -1894,6 +1895,10 @@ static int __init handle_device(struct domain *d, struct dt_device_node *dev,return res; } } + + res =sci_add_dt_device (d, dev); +if ( res <0 ) +return res; } res =handle_device_interrupts (d, dev, need_mapping);
@@ -3075,6 +3080,10 @@ static int __init construct_dom0(struct domain *d)if ( rc <0 )return rc; + rc =sci_domain_init (d,sci_get_type ()); +if ( rc <0 ) +return rc; +if ( acpi_disabled ) rc =prepare_dtb_hwdom (d, &kinfo);else
@@ -3109,6 +3118,8 @@ void __init create_dom0(void) dom0_cfg.arch.tee_type =tee_get_type (); dom0_cfg.max_vcpus =dom0_max_vcpus (); + dom0_cfg.arch.sci_type =sci_get_type (); +if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu;
xen/arch/arm/platforms/rcar3.c +2 -1
@@ -18,10 +18,11 @@*/ #include <asm/platform.h> +#include <asm/sci/sci.h> static bool rcar3_smc (struct cpu_user_regs *regs) { -return false; +return sci_handle_call (current->domain, regs); } static const char *const rcar3_dt_compat[] __initconst =
xen/arch/arm/sci/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += sci.o
xen/arch/arm/sci/sci.c new file +128 -0
128 lines not on this page · raw message
xen/arch/arm/setup.c +1 -0
@@ -50,6 +50,7 @@#include <asm/cpufeature.h> #include <asm/platform.h> #include <asm/procinfo.h> +#include <asm/sci/sci.h> #include <asm/setup.h> #include <xsm/xsm.h> #include <asm/acpi.h>
xen/arch/arm/xen.lds.S +7 -0
@@ -142,6 +142,13 @@ SECTIONS _eteemediator = .; } :text + . = ALIGN(8); + .scimediator.info : { + _sscimediator = .; + *(.scimediator.info) + _escimediator = .; + } :text + . = ALIGN(PAGE_SIZE); /* Init code and data */ __init_begin = .; .init.text : {
xen/include/asm-arm/domain.h +4 -0
@@ -89,6 +89,10 @@ struct arch_domain#ifdef CONFIG_TEE void *tee;#endif + +#ifdef CONFIG_SCI +void *sci; +#endif } __cacheline_aligned;struct arch_vcpu
xen/include/asm-arm/sci/sci.h new file +162 -0
162 lines not on this page · raw message
xen/include/public/arch-arm.h +10 -0
@@ -314,12 +314,16 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);#define XEN_DOMCTL_CONFIG_TEE_NONE 0#define XEN_DOMCTL_CONFIG_TEE_OPTEE 1 +#define XEN_DOMCTL_CONFIG_SCI_NONE 0 +struct xen_arch_domainconfig {/* IN/OUT */ uint8_t gic_version;/* IN */ uint16_t tee_type;/* IN */ +uint8_t sci_type; +/* IN */ uint32_t nr_spis;/* * OUT
@@ -335,6 +339,12 @@ struct xen_arch_domainconfig {* */ uint32_t clock_frequency; + +/* Sets shared address to sw domains. +* This information is needed to set correct channel in Domain partial +* device-tree +*/ + uint64_t sci_agent_paddr; };#endif /* __XEN__ || __XEN_TOOLS__ */
Signature · 1 line
2.27.0
Re: [RFC v1 2/5] xen/arm: add generic SCI mediator framework
Quoted 172 lines · Oleksii Moisieiev
This patch adds the basic framework for SCI mediator.
SCI is System Control Interface, which is designed to redirect requests for the Hardware (such as power-domain/clock/resets etc) from the Domains to the firmware. Originally, cpg should be passed to the domain so it can work with power-domains/clocks/resets etc. Considering that cpg can't be split between the Domains, we get the limitation that the devices, which are using power-domains/clocks/resets etc, couldn't be split between the domains.
The solution is to move the power-domain/clock/resets etc to the Firmware (such as SCP firmware or ATF) and provide interface for the Domains. XEN shoud have an entity, caled SCI-Mediator, which is responsible for messages redirection between Domains and Firmware and for permission handling.This is how it works: user can build XEN with multiple SCI mediators. See the next patches, where SCMI-SMC mediator is introduced. SCI mediator register itself with
REGISTER_SCI_MEDIATOR()macro.At run-time, during initialization, framework calls probe for the first matching device in the device-tree. When no device-tree is present - the first registered mediator should be probed.
Signed-off-by Oleksii Moisieiev <[email protected]>--- MAINTAINERS | 6 ++ xen/arch/arm/Kconfig | 8 ++ xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 24 +++++ xen/arch/arm/domain_build.c | 11 +++ xen/arch/arm/platforms/rcar3.c | 3 +- xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/sci.c | 128 ++++++++++++++++++++++++++ xen/arch/arm/setup.c | 1 + xen/arch/arm/xen.lds.S | 7 ++ xen/include/asm-arm/domain.h | 4 + xen/include/asm-arm/sci/sci.h | 162 +++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 10 ++ 13 files changed, 365 insertions(+), 1 deletion(-) create mode 100644 xen/arch/arm/sci/Makefile create mode 100644 xen/arch/arm/sci/sci.c create mode 100644 xen/include/asm-arm/sci/sci.hMAINTAINERS +6
-0@@ -512,6 +512,12 @@ S: Supported F: xen/arch/arm/tee/ F: xen/include/asm-arm/tee +SCI MEDIATORS +M: Oleksii Moisieiev <[email protected]> +S: Supported +F: xen/arch/arm/sci +F: xen/include/asm-arm/sci + TOOLSTACK M: Wei Liu <[email protected]> S: Supportedxen/arch/arm/Kconfig +8
-0@@ -106,6 +106,14 @@ config TEE source "arch/arm/tee/Kconfig" +config SCI + bool "Enable SCI mediators support" + default n + help + This option enables generic SCI (System Control Interface) mediators + support. It allows guests to control system resourcess via one of + SCI mediators implemented in XEN. + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/Makefile +1
-0@@ -8,6 +8,7 @@ obj-y += platforms/ endif obj-$(CONFIG_TEE) += tee/ obj-$(CONFIG_HAS_VPCI) += vpci.o +obj-$(CONFIG_SCI) += sci/ obj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o obj-y += bootfdt.init.oxen/arch/arm/domain.c +24
-0@@ -34,6 +34,7 @@#include <asm/platform.h> #include <asm/procinfo.h> #include <asm/regs.h> +#include <asm/sci/sci.h> #include <asm/tee/tee.h> #include <asm/vfp.h> #include <asm/vgic.h> @@ -688,6 +689,13 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)return -EINVAL ; } +if ( config->arch.sci_type !=XEN_DOMCTL_CONFIG_SCI_NONE && + config->arch.sci_type !=sci_get_type () ) + { +dprintk (XENLOG_INFO ,"Unsupported SCI type\n" ); +return -EINVAL ; + } +return 0 ; }@@ -764,6 +772,15 @@ int arch_domain_create(struct domain *d,/* At this stage vgic_reserve_virq should never fail */ if ( !vgic_reserve_virq (d,GUEST_EVTCHN_PPI ) )BUG (); + +if ( config->arch.sci_type !=XEN_DOMCTL_CONFIG_SCI_NONE ) + { +if ( (rc =sci_domain_init (d, config->arch.sci_type)) !=0 ) + goto fail; + +if ( (rc =sci_get_channel_info (d, &config->arch)) !=0 ) + goto fail; + } }/* @@ -796,6 +813,7 @@ void arch_domain_destroy(struct domain *d)domain_vgic_free (d);domain_vuart_free (d);free_xenheap_page (d->shared_info); +sci_domain_destroy (d);#ifdef CONFIG_ACPI free_xenheap_pages (d->arch.efi_acpi_table,get_order_from_bytes (d->arch.efi_acpi_len));@@ -996,6 +1014,7 @@ enum { PROG_xen, PROG_page, PROG_mapping, + PROG_sci, PROG_done, };@@ -1056,6 +1075,11 @@ int domain_relinquish_resources(struct domain *d)if ( ret )return ret; + PROGRESS(sci): + ret =sci_relinquish_resources (d); +if ( ret ) +return ret; + PROGRESS(done): break;xen/arch/arm/domain_build.c +1
-0@@ -22,6 +22,7 @@#include <asm/kernel.h> #include <asm/setup.h> #include <asm/tee/tee.h> +#include <asm/sci/sci.h> #include <asm/platform.h> #include <asm/psci.h> #include <asm/setup.h>
xen/arch/arm/domain_build.c static int __init handle_device(struct domain *d, struct dt_device_node *dev, · line 1902
Quoted 8 lines
xen/arch/arm/domain_build.c +4
-0@@ -1894,6 +1895,10 @@ static int __init handle_device(struct domain *d, struct dt_device_node *dev,return res; } } + + res =sci_add_dt_device (d, dev); +if ( res <0 ) +return res; }
It would be good to add the call to dom0less domUs too
xen/arch/arm/domain_build.c static int __init construct_dom0(struct domain *d) · line 3085
Quoted 8 lines
xen/arch/arm/domain_build.c +3
-0res =handle_device_interrupts (d, dev, need_mapping);@@ -3075,6 +3080,10 @@ static int __init construct_dom0(struct domain *d)if ( rc <0 )return rc; + rc =sci_domain_init (d,sci_get_type ()); +if ( rc <0 ) +return rc;
same here
xen/arch/arm/domain_build.c void __init create_dom0(void) · line 3121
Quoted 8 lines
xen/arch/arm/domain_build.c +1
-0if ( acpi_disabled ) rc =prepare_dtb_hwdom (d, &kinfo);else @@ -3109,6 +3118,8 @@ void __init create_dom0(void) dom0_cfg.arch.tee_type =tee_get_type (); dom0_cfg.max_vcpus =dom0_max_vcpus (); + dom0_cfg.arch.sci_type =sci_get_type ();
and here
Quoted 124 lines
xen/arch/arm/domain_build.c +0
-0if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu;xen/arch/arm/platforms/rcar3.c +2
-1@@ -18,10 +18,11 @@*/ #include <asm/platform.h> +#include <asm/sci/sci.h> static bool rcar3_smc (struct cpu_user_regs *regs) { -return false; +return sci_handle_call (current->domain, regs); } static const char *const rcar3_dt_compat[] __initconst =xen/arch/arm/sci/Makefile new file +1
-0@@ -0,0 +1 @@ +obj-y += sci.oxen/arch/arm/sci/sci.c new file +91
-0@@ -0,0 +1,128 @@ +/* +* xen/arch/arm/sci/sci.c +* +* Generic part of SCI mediator driver +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <xen/errno.h> +#include <xen/init.h> +#include <xen/sched.h> +#include <xen/types.h> + +#include <asm/sci/sci.h> + +extern const struct sci_mediator_desc _sscimediator[], _escimediator[]; +static const struct sci_mediator_desc __read_mostly *cur_mediator; + +bool sci_handle_call (struct domain *d,void *args) +{ +if (unlikely (!cur_mediator) ) +return false; + +return cur_mediator->ops->handle_call (d, args); +} + +int sci_domain_init (struct domain *d,uint16_t sci_type) +{ +if ( sci_type ==XEN_DOMCTL_CONFIG_SCI_NONE ) +return 0 ; + +if (unlikely (!cur_mediator) ) +return -ENODEV ; + +if ( cur_mediator->sci_type != sci_type ) +return -EINVAL ; + +return cur_mediator->ops->domain_init (d); +} + +void sci_domain_destroy (struct domain *d) +{ +if (unlikely (!cur_mediator) ) +return ; + + cur_mediator->ops->domain_destroy (d); +} + +int sci_relinquish_resources (struct domain *d) +{ +if (unlikely (!cur_mediator) ) +return 0 ; + +return cur_mediator->ops->relinquish_resources (d); +} + + +int sci_add_dt_device (struct domain *d,struct dt_device_node *dev) +{ +if (unlikely (!cur_mediator) ) +return 0 ; + +return cur_mediator->ops->add_dt_device (d, dev); +} + +int sci_get_channel_info (struct domain *d, +struct xen_arch_domainconfig *config) +{ +if (unlikely (!cur_mediator) ) +return 0 ; + +return cur_mediator->ops->get_channel_info (d->arch.sci, config); +} + +uint16_t sci_get_type (void ) +{ +if (unlikely (!cur_mediator) ) +return XEN_DOMCTL_CONFIG_SCI_NONE ; + +return cur_mediator->sci_type;
xen/arch/arm/sci/sci.c line 101
Quoted 10 lines
xen/arch/arm/sci/sci.c new file +10
-0+} + +static int __init sci_init (void ) +{ +const struct sci_mediator_desc *desc; +struct dt_device_node *dt =NULL ; + +for ( desc = _sscimediator; desc != _escimediator; desc++ ) + { +if (likely (dt_host) )
I think you can assume that dt_host is correctly set, right? Instead of this check, I would just add:
if ( !acpi_disabled )
return -ENODEV;
at the beginning of sci_init
Quoted 137 lines
xen/arch/arm/sci/sci.c new file +27
-0+ { + dt =dt_find_matching_node (dt_host, desc->dt_match); +if ( !dt ) +continue ; + } + +if ( desc->ops->probe (dt) ) + { +printk (XENLOG_INFO "Using SCI mediator for %s\n" , desc->name); + cur_mediator = desc; +return 0 ; + } + } + +return 0 ; +} + +__initcall (sci_init); + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/arm/setup.c +1
-0@@ -50,6 +50,7 @@#include <asm/cpufeature.h> #include <asm/platform.h> #include <asm/procinfo.h> +#include <asm/sci/sci.h> #include <asm/setup.h> #include <xsm/xsm.h> #include <asm/acpi.h> xen/arch/arm/xen.lds.S +7
-0@@ -142,6 +142,13 @@ SECTIONS _eteemediator = .; } :text + . = ALIGN(8); + .scimediator.info : { + _sscimediator = .; + *(.scimediator.info) + _escimediator = .; + } :text + . = ALIGN(PAGE_SIZE); /* Init code and data */ __init_begin = .; .init.text : {xen/include/asm-arm/domain.h +4
-0@@ -89,6 +89,10 @@ struct arch_domain#ifdef CONFIG_TEE void *tee;#endif + +#ifdef CONFIG_SCI +void *sci; +#endif } __cacheline_aligned;struct arch_vcpu xen/include/asm-arm/sci/sci.h new file +59
-0@@ -0,0 +1,162 @@ +/* +* xen/include/asm-arm/sci/sci.h +* +* Generic part of the SCI (System Control Interface) subsystem. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef __ASM_ARM_SCI_H +#define __ASM_ARM_SCI_H + +#include <xen/lib.h> +#include <xen/types.h> +#include <xen/device_tree.h> + +#ifdef CONFIG_SCI + +struct sci_mediator_ops { + + /* + * Probe for SCI. Should return true if SCI found and + * mediator is initialized. + */ + bool (*probe)(struct dt_device_node *scmi_node); + + /* + * Called during domain construction if toolstack requests to enable + * SCI support so mediator can inform SCP-firmware about new + * guest and create own structures for the new domain. + */ + int (*domain_init)(struct domain *d); + + /* + * Called during domain destruction, releases all resources, that + * were allocated by the mediator. + */ + void (*domain_destroy)(struct domain *d); + + /* + * Called during parsing partial device-sci for the domain. + * Passing device_node so mediator could process the device and + * mark the device as related to the domain if needed. + */ + int (*add_dt_device)(struct domain *d, struct dt_device_node *dev); + + /* + * Called during domain destruction to relinquish resources used + * by mediator itself. This function can return -ERESTART to indicate
xen/include/asm-arm/sci/sci.h line 69
Quoted 10 lines
xen/include/asm-arm/sci/sci.h new file +10
-0+* that it does not finished work and should be called again. +*/ +int (*relinquish_resources)(struct domain *d); + +/* Handle call for current domain */ +bool (*handle_call)(struct domain *d,void *regs); + +/* Gets channel configuration and store it in domainconfig */ +int (*get_channel_info)(void *sci_ops, +struct xen_arch_domainconfig *config);
get_channel_info is the only function I don't understand among these... what is supposed to be stored in struct xen_arch_domainconfig, just sci_agent_paddr?
Also, it seems to be only called right after sci_domain_init, so can't the "get_channel_info" operation just be done as part of domain_init?
Quoted 99 lines
xen/include/asm-arm/sci/sci.h new file +92
-0+}; + +struct sci_mediator_desc { +/* Printable name of the SCI. */ +const char *name; + +/* Mediator callbacks as described above. */ +const struct sci_mediator_ops *ops; + +/* +* ID of SCI. Corresponds to xen_arch_domainconfig.sci_type. +* Should be one of XEN_DOMCTL_CONFIG_SCI_xxx +*/ +uint16_t sci_type; + +/* Match structure to init mediator */ +const struct dt_device_match *dt_match; + +}; + +int sci_domain_init (struct domain *d,uint16_t sci_type); +void sci_domain_destroy (struct domain *d); +int sci_add_dt_device (struct domain *d,struct dt_device_node *dev); +int sci_relinquish_resources (struct domain *d); +bool sci_handle_call (struct domain *d,void *args); +int sci_get_channel_info (struct domain *d, +struct xen_arch_domainconfig *config); +uint16_t sci_get_type (void ); + +#define REGISTER_SCI_MEDIATOR (_name, _namestr, _type, _match, _ops) \ +static const struct sci_mediator_desc __sci_desc_##_name __used \ +__section(".scimediator.info") = { \ + .name = _namestr, \ + .ops = _ops, \ + .sci_type = _type, \ + .dt_match = _match \ +} + +#else +#include <public/errno.h> + +static inline int sci_domain_init (struct domain *d,uint16_t sci_type) +{ +if (likely (sci_type ==XEN_DOMCTL_CONFIG_SCI_NONE ) ) +return 0 ; + +return -XEN_ENODEV ; +} + +static inline void sci_domain_destroy (struct domain *d) +{ +} + +static inline int sci_add_dt_device (struct domain *d, +struct dt_device_node *dev) +{ +return 0 ; +} + +static inline int sci_relinquish_resources (struct domain *d) +{ +return 0 ; +} + +static inline bool sci_handle_call (struct domain *d,void *args) +{ +return false; +} + +static inline int sci_get_channel_info (struct domain *d, +struct xen_arch_domainconfig *config) +{ +return 0 ; +} + +static inline uint16_t sci_get_type (void ) +{ +return XEN_DOMCTL_CONFIG_SCI_NONE ; +} + +#endif /* CONFIG_SCI */ + +#endif /* __ASM_ARM_SCI_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/public/arch-arm.h +0
-0@@ -314,12 +314,16 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);#define XEN_DOMCTL_CONFIG_TEE_NONE 0#define XEN_DOMCTL_CONFIG_TEE_OPTEE 1
xen/include/public/arch-arm.h DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t); · line 325
Quoted 10 lines
xen/include/public/arch-arm.h +3
-0+#define XEN_DOMCTL_CONFIG_SCI_NONE 0 +struct xen_arch_domainconfig {/* IN/OUT */ uint8_t gic_version;/* IN */ uint16_t tee_type;/* IN */ +uint8_t sci_type;
sci_type is uint16_t everywhere else
Quoted 16 lines
xen/include/public/arch-arm.h +7
-0+/* IN */ uint32_t nr_spis;/* * OUT @@ -335,6 +339,12 @@ struct xen_arch_domainconfig {* */ uint32_t clock_frequency; + +/* Sets shared address to sw domains. +* This information is needed to set correct channel in Domain partial +* device-tree +*/ + uint64_t sci_agent_paddr; };#endif /* __XEN__ || __XEN_TOOLS__ */
Re: [RFC v1 2/5] xen/arm: add generic SCI mediator framework
Hi Stefano,
Quoted 175 lines · Stefano Stabellini
Quoted 174 lines · Oleksii Moisieiev
This patch adds the basic framework for SCI mediator.
SCI is System Control Interface, which is designed to redirect requests for the Hardware (such as power-domain/clock/resets etc) from the Domains to the firmware. Originally, cpg should be passed to the domain so it can work with power-domains/clocks/resets etc. Considering that cpg can't be split between the Domains, we get the limitation that the devices, which are using power-domains/clocks/resets etc, couldn't be split between the domains.
The solution is to move the power-domain/clock/resets etc to the Firmware (such as SCP firmware or ATF) and provide interface for the Domains. XEN shoud have an entity, caled SCI-Mediator, which is responsible for messages redirection between Domains and Firmware and for permission handling.This is how it works: user can build XEN with multiple SCI mediators. See the next patches, where SCMI-SMC mediator is introduced. SCI mediator register itself with
REGISTER_SCI_MEDIATOR()macro.At run-time, during initialization, framework calls probe for the first matching device in the device-tree. When no device-tree is present - the first registered mediator should be probed.
Signed-off-by Oleksii Moisieiev <[email protected]>--- MAINTAINERS | 6 ++ xen/arch/arm/Kconfig | 8 ++ xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 24 +++++ xen/arch/arm/domain_build.c | 11 +++ xen/arch/arm/platforms/rcar3.c | 3 +- xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/sci.c | 128 ++++++++++++++++++++++++++ xen/arch/arm/setup.c | 1 + xen/arch/arm/xen.lds.S | 7 ++ xen/include/asm-arm/domain.h | 4 + xen/include/asm-arm/sci/sci.h | 162 +++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 10 ++ 13 files changed, 365 insertions(+), 1 deletion(-) create mode 100644 xen/arch/arm/sci/Makefile create mode 100644 xen/arch/arm/sci/sci.c create mode 100644 xen/include/asm-arm/sci/sci.hMAINTAINERS +6
-0@@ -512,6 +512,12 @@ S: Supported F: xen/arch/arm/tee/ F: xen/include/asm-arm/tee +SCI MEDIATORS +M: Oleksii Moisieiev <[email protected]> +S: Supported +F: xen/arch/arm/sci +F: xen/include/asm-arm/sci + TOOLSTACK M: Wei Liu <[email protected]> S: Supportedxen/arch/arm/Kconfig +8
-0@@ -106,6 +106,14 @@ config TEE source "arch/arm/tee/Kconfig" +config SCI + bool "Enable SCI mediators support" + default n + help + This option enables generic SCI (System Control Interface) mediators + support. It allows guests to control system resourcess via one of + SCI mediators implemented in XEN. + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/Makefile +1
-0@@ -8,6 +8,7 @@ obj-y += platforms/ endif obj-$(CONFIG_TEE) += tee/ obj-$(CONFIG_HAS_VPCI) += vpci.o +obj-$(CONFIG_SCI) += sci/ obj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o obj-y += bootfdt.init.oxen/arch/arm/domain.c +24
-0@@ -34,6 +34,7 @@#include <asm/platform.h> #include <asm/procinfo.h> #include <asm/regs.h> +#include <asm/sci/sci.h> #include <asm/tee/tee.h> #include <asm/vfp.h> #include <asm/vgic.h> @@ -688,6 +689,13 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)return -EINVAL ; } +if ( config->arch.sci_type !=XEN_DOMCTL_CONFIG_SCI_NONE && + config->arch.sci_type !=sci_get_type () ) + { +dprintk (XENLOG_INFO ,"Unsupported SCI type\n" ); +return -EINVAL ; + } +return 0 ; }@@ -764,6 +772,15 @@ int arch_domain_create(struct domain *d,/* At this stage vgic_reserve_virq should never fail */ if ( !vgic_reserve_virq (d,GUEST_EVTCHN_PPI ) )BUG (); + +if ( config->arch.sci_type !=XEN_DOMCTL_CONFIG_SCI_NONE ) + { +if ( (rc =sci_domain_init (d, config->arch.sci_type)) !=0 ) + goto fail; + +if ( (rc =sci_get_channel_info (d, &config->arch)) !=0 ) + goto fail; + } }/* @@ -796,6 +813,7 @@ void arch_domain_destroy(struct domain *d)domain_vgic_free (d);domain_vuart_free (d);free_xenheap_page (d->shared_info); +sci_domain_destroy (d);#ifdef CONFIG_ACPI free_xenheap_pages (d->arch.efi_acpi_table,get_order_from_bytes (d->arch.efi_acpi_len));@@ -996,6 +1014,7 @@ enum { PROG_xen, PROG_page, PROG_mapping, + PROG_sci, PROG_done, };@@ -1056,6 +1075,11 @@ int domain_relinquish_resources(struct domain *d)if ( ret )return ret; + PROGRESS(sci): + ret =sci_relinquish_resources (d); +if ( ret ) +return ret; + PROGRESS(done): break;xen/arch/arm/domain_build.c +1
-0@@ -22,6 +22,7 @@#include <asm/kernel.h> #include <asm/setup.h> #include <asm/tee/tee.h> +#include <asm/sci/sci.h> #include <asm/platform.h> #include <asm/psci.h> #include <asm/setup.h> @@ -1894,6 +1895,10 @@ static int __init handle_device(struct domain *d, struct dt_device_node *dev,return res; }
Quoted 9 lines
xen/arch/arm/domain_build.c static int __init handle_device(struct domain *d, struct dt_device_node *dev, · line 1902
Quoted 6 lines
xen/arch/arm/domain_build.c +4
-0} + + res =sci_add_dt_device (d, dev); +if ( res <0 ) +return res; }It would be good to add the call to dom0less domUs too
Thank you, I will fix all mentioned places in v2.
Quoted 6 lines
Quoted 6 lines
xen/arch/arm/domain_build.c +0
-0res =handle_device_interrupts (d, dev, need_mapping);@@ -3075,6 +3080,10 @@ static int __init construct_dom0(struct domain *d)if ( rc <0 )return rc;
Quoted 6 lines
xen/arch/arm/domain_build.c static int __init construct_dom0(struct domain *d) · line 3085
Quoted 3 lines
xen/arch/arm/domain_build.c +3
-0+ rc =sci_domain_init (d,sci_get_type ()); +if ( rc <0 ) +return rc;same here
TBD in v2
Quoted 8 lines
Quoted 8 lines
xen/arch/arm/domain_build.c +0
-0if ( acpi_disabled ) rc =prepare_dtb_hwdom (d, &kinfo);else @@ -3109,6 +3118,8 @@ void __init create_dom0(void) dom0_cfg.arch.tee_type =tee_get_type (); dom0_cfg.max_vcpus =dom0_max_vcpus ();
Quoted 4 lines
xen/arch/arm/domain_build.c void __init create_dom0(void) · line 3121
Quoted 1 line
xen/arch/arm/domain_build.c +1
-0+ dom0_cfg.arch.sci_type =sci_get_type ();and here
TBD in v2
Quoted 139 lines
Quoted 125 lines
xen/arch/arm/domain_build.c +0
-0if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu;xen/arch/arm/platforms/rcar3.c +2
-1@@ -18,10 +18,11 @@*/ #include <asm/platform.h> +#include <asm/sci/sci.h> static bool rcar3_smc (struct cpu_user_regs *regs) { -return false; +return sci_handle_call (current->domain, regs); } static const char *const rcar3_dt_compat[] __initconst =xen/arch/arm/sci/Makefile new file +1
-0@@ -0,0 +1 @@ +obj-y += sci.oxen/arch/arm/sci/sci.c new file +91
-0@@ -0,0 +1,128 @@ +/* +* xen/arch/arm/sci/sci.c +* +* Generic part of SCI mediator driver +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <xen/errno.h> +#include <xen/init.h> +#include <xen/sched.h> +#include <xen/types.h> + +#include <asm/sci/sci.h> + +extern const struct sci_mediator_desc _sscimediator[], _escimediator[]; +static const struct sci_mediator_desc __read_mostly *cur_mediator; + +bool sci_handle_call (struct domain *d,void *args) +{ +if (unlikely (!cur_mediator) ) +return false; + +return cur_mediator->ops->handle_call (d, args); +} + +int sci_domain_init (struct domain *d,uint16_t sci_type) +{ +if ( sci_type ==XEN_DOMCTL_CONFIG_SCI_NONE ) +return 0 ; + +if (unlikely (!cur_mediator) ) +return -ENODEV ; + +if ( cur_mediator->sci_type != sci_type ) +return -EINVAL ; + +return cur_mediator->ops->domain_init (d); +} + +void sci_domain_destroy (struct domain *d) +{ +if (unlikely (!cur_mediator) ) +return ; + + cur_mediator->ops->domain_destroy (d); +} + +int sci_relinquish_resources (struct domain *d) +{ +if (unlikely (!cur_mediator) ) +return 0 ; + +return cur_mediator->ops->relinquish_resources (d); +} + + +int sci_add_dt_device (struct domain *d,struct dt_device_node *dev) +{ +if (unlikely (!cur_mediator) ) +return 0 ; + +return cur_mediator->ops->add_dt_device (d, dev); +} + +int sci_get_channel_info (struct domain *d, +struct xen_arch_domainconfig *config) +{ +if (unlikely (!cur_mediator) ) +return 0 ; + +return cur_mediator->ops->get_channel_info (d->arch.sci, config); +} + +uint16_t sci_get_type (void ) +{ +if (unlikely (!cur_mediator) ) +return XEN_DOMCTL_CONFIG_SCI_NONE ; + +return cur_mediator->sci_type;xen/arch/arm/sci/sci.c line 101
Quoted 10 lines
xen/arch/arm/sci/sci.c new file +10
-0+} + +static int __init sci_init (void ) +{ +const struct sci_mediator_desc *desc; +struct dt_device_node *dt =NULL ; + +for ( desc = _sscimediator; desc != _escimediator; desc++ ) + { +if (likely (dt_host) )I think you can assume that
dt_hostis correctly set, right? Instead of this check, I would just add:
Quoted 5 lines
if ( !acpi_disabled )
return-ENODEV;at the beginning of
sci_init
Good point! I will it in v2. Thanks.
Quoted 153 lines
Quoted 138 lines
xen/arch/arm/sci/sci.c new file +27
-0+ { + dt =dt_find_matching_node (dt_host, desc->dt_match); +if ( !dt ) +continue ; + } + +if ( desc->ops->probe (dt) ) + { +printk (XENLOG_INFO "Using SCI mediator for %s\n" , desc->name); + cur_mediator = desc; +return 0 ; + } + } + +return 0 ; +} + +__initcall (sci_init); + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/arm/setup.c +1
-0@@ -50,6 +50,7 @@#include <asm/cpufeature.h> #include <asm/platform.h> #include <asm/procinfo.h> +#include <asm/sci/sci.h> #include <asm/setup.h> #include <xsm/xsm.h> #include <asm/acpi.h> xen/arch/arm/xen.lds.S +7
-0@@ -142,6 +142,13 @@ SECTIONS _eteemediator = .; } :text + . = ALIGN(8); + .scimediator.info : { + _sscimediator = .; + *(.scimediator.info) + _escimediator = .; + } :text + . = ALIGN(PAGE_SIZE); /* Init code and data */ __init_begin = .; .init.text : {xen/include/asm-arm/domain.h +4
-0@@ -89,6 +89,10 @@ struct arch_domain#ifdef CONFIG_TEE void *tee;#endif + +#ifdef CONFIG_SCI +void *sci; +#endif } __cacheline_aligned;struct arch_vcpu xen/include/asm-arm/sci/sci.h new file +59
-0@@ -0,0 +1,162 @@ +/* +* xen/include/asm-arm/sci/sci.h +* +* Generic part of the SCI (System Control Interface) subsystem. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef __ASM_ARM_SCI_H +#define __ASM_ARM_SCI_H + +#include <xen/lib.h> +#include <xen/types.h> +#include <xen/device_tree.h> + +#ifdef CONFIG_SCI + +struct sci_mediator_ops { + + /* + * Probe for SCI. Should return true if SCI found and + * mediator is initialized. + */ + bool (*probe)(struct dt_device_node *scmi_node); + + /* + * Called during domain construction if toolstack requests to enable + * SCI support so mediator can inform SCP-firmware about new + * guest and create own structures for the new domain. + */ + int (*domain_init)(struct domain *d); + + /* + * Called during domain destruction, releases all resources, that + * were allocated by the mediator. + */ + void (*domain_destroy)(struct domain *d); + + /* + * Called during parsing partial device-sci for the domain. + * Passing device_node so mediator could process the device and + * mark the device as related to the domain if needed. + */ + int (*add_dt_device)(struct domain *d, struct dt_device_node *dev); + + /* + * Called during domain destruction to relinquish resources used + * by mediator itself. This function can return -ERESTART to indicatexen/include/asm-arm/sci/sci.h line 69
Quoted 10 lines
xen/include/asm-arm/sci/sci.h new file +10
-0+* that it does not finished work and should be called again. +*/ +int (*relinquish_resources)(struct domain *d); + +/* Handle call for current domain */ +bool (*handle_call)(struct domain *d,void *regs); + +/* Gets channel configuration and store it in domainconfig */ +int (*get_channel_info)(void *sci_ops, +struct xen_arch_domainconfig *config);
get_channel_infois the only function I don't understand among these... what is supposed to be stored in structxen_arch_domainconfig, justsci_agent_paddr?
Quoted 3 lines
Also, it seems to be only called right after
sci_domain_init, so can't the "get_channel_info" operation just be done as part ofdomain_init?
We need sci_agent_paddr for Domains. It represents shmem address which should be mapped to guest Domain. We also don't need paddr when we do sci_domain_init for dom0. That's why I've made it as separate call.
Also I named it get_channel_info, not get_channel_paddr, because potentially, the different information can be needed from different SCI implementation, which doesn't need shared memory to pass data for exapmle.
Quoted 132 lines
Quoted 101 lines
xen/include/asm-arm/sci/sci.h new file +92
-0+}; + +struct sci_mediator_desc { +/* Printable name of the SCI. */ +const char *name; + +/* Mediator callbacks as described above. */ +const struct sci_mediator_ops *ops; + +/* +* ID of SCI. Corresponds to xen_arch_domainconfig.sci_type. +* Should be one of XEN_DOMCTL_CONFIG_SCI_xxx +*/ +uint16_t sci_type; + +/* Match structure to init mediator */ +const struct dt_device_match *dt_match; + +}; + +int sci_domain_init (struct domain *d,uint16_t sci_type); +void sci_domain_destroy (struct domain *d); +int sci_add_dt_device (struct domain *d,struct dt_device_node *dev); +int sci_relinquish_resources (struct domain *d); +bool sci_handle_call (struct domain *d,void *args); +int sci_get_channel_info (struct domain *d, +struct xen_arch_domainconfig *config); +uint16_t sci_get_type (void ); + +#define REGISTER_SCI_MEDIATOR (_name, _namestr, _type, _match, _ops) \ +static const struct sci_mediator_desc __sci_desc_##_name __used \ +__section(".scimediator.info") = { \ + .name = _namestr, \ + .ops = _ops, \ + .sci_type = _type, \ + .dt_match = _match \ +} + +#else +#include <public/errno.h> + +static inline int sci_domain_init (struct domain *d,uint16_t sci_type) +{ +if (likely (sci_type ==XEN_DOMCTL_CONFIG_SCI_NONE ) ) +return 0 ; + +return -XEN_ENODEV ; +} + +static inline void sci_domain_destroy (struct domain *d) +{ +} + +static inline int sci_add_dt_device (struct domain *d, +struct dt_device_node *dev) +{ +return 0 ; +} + +static inline int sci_relinquish_resources (struct domain *d) +{ +return 0 ; +} + +static inline bool sci_handle_call (struct domain *d,void *args) +{ +return false; +} + +static inline int sci_get_channel_info (struct domain *d, +struct xen_arch_domainconfig *config) +{ +return 0 ; +} + +static inline uint16_t sci_get_type (void ) +{ +return XEN_DOMCTL_CONFIG_SCI_NONE ; +} + +#endif /* CONFIG_SCI */ + +#endif /* __ASM_ARM_SCI_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/public/arch-arm.h +0
-0@@ -314,12 +314,16 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);#define XEN_DOMCTL_CONFIG_TEE_NONE 0#define XEN_DOMCTL_CONFIG_TEE_OPTEE 1xen/include/public/arch-arm.h DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t); · line 325
Quoted 10 lines
xen/include/public/arch-arm.h +3
-0+#define XEN_DOMCTL_CONFIG_SCI_NONE 0 +struct xen_arch_domainconfig {/* IN/OUT */ uint8_t gic_version;/* IN */ uint16_t tee_type;/* IN */ +uint8_t sci_type;
sci_typeisuint16_teverywhere elseQuoted 16 lines
xen/include/public/arch-arm.h +7
-0+/* IN */ uint32_t nr_spis;/* * OUT @@ -335,6 +339,12 @@ struct xen_arch_domainconfig {* */ uint32_t clock_frequency; + +/* Sets shared address to sw domains. +* This information is needed to set correct channel in Domain partial +* device-tree +*/ + uint64_t sci_agent_paddr; };#endif /* __XEN__ || __XEN_TOOLS__ */
RFC 3/5 xen/arm: introduce SCMI-SMC mediator driver
In reply to Oleksii MoisieievThis is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG.
The following features are implemented:
- request SCMI channels from ATF and pass channels to Domains;
- set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI;
- redirect scmi messages from Domains to ATF.
--- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 5 files changed, 809 insertions(+) create mode 100644 xen/arch/arm/sci/Kconfig create mode 100644 xen/arch/arm/sci/scmi_smc.c
xen/arch/arm/Kconfig +2 -0
@@ -114,6 +114,8 @@ config SCI support. It allows guests to control system resourcess via one of SCI mediators implemented in XEN. +source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework"
xen/arch/arm/sci/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on SCI + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication.
xen/arch/arm/sci/Makefile +1 -0
@@ -1 +1,2 @@ obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.o
xen/arch/arm/sci/scmi_smc.c new file +795 -0
795 lines not on this page · raw message
xen/include/public/arch-arm.h +1 -0
@@ -315,6 +315,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);#define XEN_DOMCTL_CONFIG_TEE_OPTEE 1#define XEN_DOMCTL_CONFIG_SCI_NONE 0 +#define XEN_DOMCTL_CONFIG_SCI_SCMI_SMC 1struct xen_arch_domainconfig {/* IN/OUT */
Signature · 1 line
2.27.0
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
On 14.12.21 11:34, Oleksii Moisieiev wrote:
Hi Oleksii
Quoted 277 lines
This is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG.
The following features are implemented:
- request SCMI channels from ATF and pass channels to Domains;
- set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI;
- redirect scmi messages from Domains to ATF.Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 5 files changed, 809 insertions(+)create mode 100644 xen/arch/arm/sci/Kconfig
create mode 100644xen/arch/arm/sci/scmi_smc.cxen/arch/arm/Kconfig +2
-0@@ -114,6 +114,8 @@ config SCI support. It allows guests to control system resourcess via one of SCI mediators implemented in XEN. +source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/sci/Kconfig new file +10
-0@@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on SCI + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication.xen/arch/arm/sci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.oxen/arch/arm/sci/scmi_smc.c new file +212
-0@@ -0,0 +1,795 @@ +/* +* xen/arch/arm/sci/scmi_smc.c +* +* SCMI mediator driver, using SCP as transport. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/sci/sci.h> +#include <asm/smccc.h> +#include <asm/io.h> +#include <xen/bitops.h> +#include <xen/config.h> +#include <xen/sched.h> +#include <xen/device_tree.h> +#include <xen/iocap.h> +#include <xen/init.h> +#include <xen/err.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/string.h> +#include <xen/time.h> +#include <xen/vmap.h> + +#define SCMI_BASE_PROTOCOL 0x10 +#define SCMI_BASE_PROTOCOL_ATTIBUTES 0x1 +#define SCMI_BASE_SET_DEVICE_PERMISSIONS 0x9 +#define SCMI_BASE_RESET_AGENT_CONFIGURATION 0xB +#define SCMI_BASE_DISCOVER_AGENT 0x7 + +/* SCMI return codes. See section 4.1.4 of SCMI spec (DEN0056C) */ +#define SCMI_SUCCESS 0 +#define SCMI_NOT_SUPPORTED (-1) +#define SCMI_INVALID_PARAMETERS (-2) +#define SCMI_DENIED (-3) +#define SCMI_NOT_FOUND (-4) +#define SCMI_OUT_OF_RANGE (-5) +#define SCMI_BUSY (-6) +#define SCMI_COMMS_ERROR (-7) +#define SCMI_GENERIC_ERROR (-8) +#define SCMI_HARDWARE_ERROR (-9) +#define SCMI_PROTOCOL_ERROR (-10) + +#define DT_MATCH_SCMI_SMC DT_MATCH_COMPATIBLE("arm,scmi-smc") + +#define SCMI_SMC_ID "arm,smc-id" +#define SCMI_SHARED_MEMORY "linux,scmi_mem" +#define SCMI_SHMEM "shmem" + +#define HYP_CHANNEL 0x0 + +#define HDR_ID GENMASK(7,0) +#define HDR_TYPE GENMASK(9, 8) +#define HDR_PROTO GENMASK(17, 10) + +/* SCMI protocol, refer to section 4.2.2.2 (DEN0056C) */ +#define MSG_N_AGENTS_MASK GENMASK(15, 8) + +#define FIELD_GET (_mask, _reg)\ + ((typeof(_mask))(((_reg) & (_mask)) >> (ffs64(_mask) - 1))) +#define FIELD_PREP (_mask, _val)\ + (((typeof(_mask))(_val) << (ffs64(_mask) - 1)) & (_mask)) + +typedef struct scmi_msg_header { +uint8_t id; +uint8_t type; +uint8_t protocol; +}scmi_msg_header_t ; + +typedef struct scmi_perms_tx { +uint32_t agent_id; +uint32_t device_id; +uint32_t flags; +}scmi_perms_tx_t ; + +#define SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE BIT(0, UL) +#define SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR BIT(1, UL) + +#define SCMI_ALLOW_ACCESS BIT(0, UL) + +struct scmi_shared_mem { +uint32_t reserved; +uint32_t channel_status; +uint32_t reserved1[2 ]; +uint32_t flags; +uint32_t length; +uint32_t msg_header; +uint8_t msg_payload[]; +}; + +struct scmi_channel { +int chan_id; +int agent_id; +uint32_t func_id; +int domain_id; +uint64_t paddr; +struct scmi_shared_mem *shmem; +spinlock_t lock; +struct list_head list; +}; + +struct scmi_data { +struct list_head channel_list; +spinlock_t channel_list_lock; +bool initialized; +u64 shmem_addr, shmem_size; +}; + +static struct scmi_data scmi_data; + +/* +* pack_scmi_header() - packs and returns 32-bit header +* +* @hdr: pointer to header containing all the information on message id, +* protocol id and type id. +* +* Return: 32-bit packed message header to be sent to the platform. +*/ +static inline uint32_t pack_scmi_header (scmi_msg_header_t *hdr) +{ +return FIELD_PREP (HDR_ID , hdr->id) | +FIELD_PREP (HDR_TYPE , hdr->type) | +FIELD_PREP (HDR_PROTO , hdr->protocol); +} + +/* +* unpack_scmi_header() - unpacks and records message and protocol id +* +* @msg_hdr: 32-bit packed message header sent from the platform +* @hdr: pointer to header to fetch message and protocol id. +*/ +static inline void unpack_scmi_header (uint32_t msg_hdr,scmi_msg_header_t *hdr) +{ + hdr->id =FIELD_GET (HDR_ID , msg_hdr); + hdr->type =FIELD_GET (HDR_TYPE , msg_hdr); + hdr->protocol =FIELD_GET (HDR_PROTO , msg_hdr); +} + +static inline int channel_is_free (struct scmi_channel *chan_info) +{ +return ( chan_info->shmem->channel_status + &SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE ) ?0 : -EBUSY ; +} + +static int send_smc_message (struct scmi_channel *chan_info, +scmi_msg_header_t *hdr,void *data,int len) +{ +struct arm_smccc_res resp; +int ret; + +printk (XENLOG_DEBUG "scmi: status =%d len=%d\n" , + chan_info->shmem->channel_status, len); +printk (XENLOG_DEBUG "scmi: header id = %d type = %d, proto = %d\n" , + hdr->id, hdr->type, hdr->protocol); + + ret =channel_is_free (chan_info); +if (IS_ERR_VALUE (ret) ) +return ret; + + chan_info->shmem->channel_status =0x0 ; +/* Writing 0x0 right now, but SCMI_SHMEM_FLAG_INTR_ENABLED can be set */ + chan_info->shmem->flags =0x0 ; + chan_info->shmem->length =sizeof (chan_info->shmem->msg_header) + len; + chan_info->shmem->msg_header =pack_scmi_header (hdr); + +printk (XENLOG_DEBUG "scmi: Writing to shmem address %p\n" , + chan_info->shmem); +if ( len >0 && data ) +memcpy ((void *)(chan_info->shmem->msg_payload), data, len); + +arm_smccc_smc (chan_info->func_id,0 ,0 ,0 ,0 ,0 ,0 , chan_info->chan_id, + &resp); + +printk (XENLOG_DEBUG "scmi: scmccc_smc response %d\n" , (int )(resp.a0)); + +if ( resp.a0 ) +return -EOPNOTSUPP ; + +return 0 ; +} + +static int check_scmi_status (int scmi_status) +{ +if ( scmi_status ==SCMI_SUCCESS ) +return 0 ; + +printk (XENLOG_DEBUG "scmi: Error received: %d\n" , scmi_status); + +switch ( scmi_status ) + { +case SCMI_NOT_SUPPORTED : +return -EOPNOTSUPP ; +case SCMI_INVALID_PARAMETERS : +return -EINVAL ; +case SCMI_DENIED : +return -EACCES ; +case SCMI_NOT_FOUND : +return -ENOENT ; +case SCMI_OUT_OF_RANGE : +return -ERANGE ;
xen/arch/arm/sci/scmi_smc.c line 222
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+case SCMI_BUSY : +return -EBUSY ; +case SCMI_COMMS_ERROR : +return -ENOTCONN ; +case SCMI_GENERIC_ERROR : +return -EIO ; +case SCMI_HARDWARE_ERROR : +return -ENXIO ; +case SCMI_PROTOCOL_ERROR : +return -EBADMSG ;
Probably we should add a default: here?
Quoted 174 lines
xen/arch/arm/sci/scmi_smc.c new file +174
-0+ } + +return -EINVAL ; +} + +static int get_smc_response (struct scmi_channel *chan_info, +scmi_msg_header_t *hdr,void *data,int len) +{ +int recv_len; +int ret; + +printk (XENLOG_DEBUG "scmi: get smc responce msgid %d\n" , hdr->id); + + ret =channel_is_free (chan_info); +if (IS_ERR_VALUE (ret) ) +return ret; + + recv_len = chan_info->shmem->length -sizeof (chan_info->shmem->msg_header); + +if ( recv_len <0 ) + { +printk (XENLOG_ERR +"scmi: Wrong size of smc message. Data may be invalid\n" ); +return -EINVAL ; + } + +if ( recv_len > len ) + { +printk (XENLOG_ERR +"scmi: Not enough buffer for message %d, expecting %d\n" , + recv_len, len); +return -EINVAL ; + } + +unpack_scmi_header (chan_info->shmem->msg_header, hdr); + +if ( recv_len >0 ) + { +memcpy (data, chan_info->shmem->msg_payload, recv_len); + } + +return 0 ; +} + +static int do_smc_xfer (struct scmi_channel *channel,scmi_msg_header_t *hdr,void *tx_data,int tx_size, +void *rx_data,int rx_size) +{ +int ret =0 ; + +if ( !hdr ) +return -EINVAL ; + +spin_lock (&channel->lock); + + ret =send_smc_message (channel, hdr, tx_data, tx_size); +if ( ret ) + goto clean; + + ret =get_smc_response (channel, hdr, rx_data, rx_size); +clean: +spin_unlock (&channel->lock); + +return ret; +} + +static struct scmi_channel *get_channel_by_id (uint8_t chan_id) +{ +struct scmi_channel *curr; +bool found = false; + +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry (curr, &scmi_data.channel_list, list) +if ( curr->chan_id == chan_id ) + { + found = true; +break ; + } + +spin_unlock (&scmi_data.channel_list_lock); +if ( found ) +return curr; + +return NULL ; +} + +static struct scmi_channel *get_channel_by_domain (uint8_t domain_id) +{ +struct scmi_channel *curr; +bool found = false; + +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry (curr, &scmi_data.channel_list, list) +if ( curr->domain_id == domain_id ) + { + found = true; +break ; + } + +spin_unlock (&scmi_data.channel_list_lock); +if ( found ) +return curr; + +return NULL ; +} + +static struct scmi_channel *aquire_scmi_channel (int domain_id) +{ +struct scmi_channel *curr; +bool found = false; + +ASSERT (domain_id !=DOMID_INVALID && domain_id >=0 ); + +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry (curr, &scmi_data.channel_list, list) +if ( (curr->domain_id ==DOMID_INVALID ) + && (curr->chan_id !=HYP_CHANNEL ) ) + { + curr->domain_id = domain_id; + found = true; +break ; + } + +spin_unlock (&scmi_data.channel_list_lock); +if ( found ) +return curr; + +return NULL ; +} + +static void relinquish_scmi_channel (struct scmi_channel *channel) +{ +spin_lock (&scmi_data.channel_list_lock); +ASSERT (channel !=NULL ); + channel->domain_id =DOMID_INVALID ; +spin_unlock (&scmi_data.channel_list_lock); +} + +static struct scmi_channel *smc_create_channel (uint8_t chan_id, +uint32_t func_id,uint64_t addr) +{ +struct scmi_channel *channel; +mfn_t mfn; + + channel =get_channel_by_id (chan_id); +if ( channel ) +return ERR_PTR (EEXIST ); + + channel = xmalloc(struct scmi_channel); +if ( !channel ) +return ERR_PTR (ENOMEM ); + + channel->chan_id = chan_id; + channel->func_id = func_id; + channel->domain_id =DOMID_INVALID ; + mfn =maddr_to_mfn (addr); + channel->shmem =vmap (&mfn,1 ); +if ( !channel->shmem ) + { +xfree (channel); +return ERR_PTR (ENOMEM ); + } + +printk (XENLOG_DEBUG "scmi: Got shmem after vmap %p\n" , channel->shmem); + channel->paddr = addr; + channel->shmem->channel_status =SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE ; +spin_lock_init (&channel->lock); +spin_lock (&scmi_data.channel_list_lock); +list_add (&channel->list, &scmi_data.channel_list); +spin_unlock (&scmi_data.channel_list_lock); +return channel; +} + +static int map_memory_to_domain (struct domain *d,uint64_t addr,uint64_t len) +{
xen/arch/arm/sci/scmi_smc.c line 406
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+return iomem_permit_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +} + +static int unmap_memory_from_domain (struct domain *d,uint64_t addr, +uint64_t len) +{ +return iomem_deny_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +}
I wonder, why we need an extra level of indirection here. And if this is really needed, I wonder why map(unmap)_memory* name was chosen, as there is no memory mapping/unmapping really happens here.
xen/arch/arm/sci/scmi_smc.c line 409
Quoted 3 lines
xen/arch/arm/sci/scmi_smc.c new file +3
-0+ +static int dt_update_domain_range (struct domain *d,uint64_t addr, +uint64_t size)
Looks like *d is not used in this function.
Quoted 33 lines
xen/arch/arm/sci/scmi_smc.c new file +33
-0+{ +struct dt_device_node *shmem_node; +__be32 *hw_reg; +const struct dt_property *pp; +uint32_t len; + + shmem_node =dt_find_compatible_node (NULL ,NULL ,"arm,scmi-shmem" ); + +if ( !shmem_node ) + { +printk (XENLOG_ERR "scmi: Unable to find %s node in DT\n" ,SCMI_SHMEM ); +return -EINVAL ; + } + + pp =dt_find_property (shmem_node,"reg" , &len); +if ( !pp ) + { +printk (XENLOG_ERR "scmi: Unable to find regs entry in shmem node\n" ); +return -ENOENT ; + } + + hw_reg = pp->value; +dt_set_range (&hw_reg, shmem_node, addr, size); + +return 0 ; +} + +static void free_channel_list (void ) +{ +struct scmi_channel *curr, *_curr; + +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry_safe (curr, _curr, &scmi_data.channel_list, list)
xen/arch/arm/sci/scmi_smc.c line 452
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+ { +vunmap (curr->shmem); +list_del (&curr->list); +xfree (curr); + } + +spin_unlock (&scmi_data.channel_list_lock); +} + +static __init bool scmi_probe (struct dt_device_node *scmi_node)
Generic question to consider ...
If probe fails for some reason (so we cannot use mediator in Xen) what should we do with SCMI nodes in domain's device-tree (leave as is, drop, etc)?
Quoted 109 lines
xen/arch/arm/sci/scmi_smc.c new file +109
-0+{ +struct dt_device_node *shmem_node; +int ret, i; +struct scmi_channel *channel, *agent_channel; +int n_agents; +scmi_msg_header_t hdr; +struct rx_t { +int32_t status; +uint32_t attributes; + } rx; + +uint32_t func_id; + +ASSERT (scmi_node !=NULL ); + +INIT_LIST_HEAD (&scmi_data.channel_list); +spin_lock_init (&scmi_data.channel_list_lock); + +if ( !dt_property_read_u32 (scmi_node,SCMI_SMC_ID , &func_id) ) + { +printk (XENLOG_ERR "scmi: Unable to read smc-id from DT\n" ); +return false; + } + + shmem_node =dt_find_node_by_name (NULL ,SCMI_SHARED_MEMORY ); +if (IS_ERR_OR_NULL (shmem_node) ) + { +printk (XENLOG_ERR +"scmi: Device tree error, can't parse shmem phandle %ld\n" , +PTR_ERR (shmem_node)); +return false; + } + + ret =dt_device_get_address (shmem_node,0 , &scmi_data.shmem_addr, + &scmi_data.shmem_size); +if (IS_ERR_VALUE (ret) ) +return false; + + channel =smc_create_channel (HYP_CHANNEL , func_id, scmi_data.shmem_addr); +if (IS_ERR (channel) ) +return false; + + hdr.id =SCMI_BASE_PROTOCOL_ATTIBUTES ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + ret =do_smc_xfer (channel, &hdr,NULL ,0 , &rx,sizeof (rx)); +if ( ret ) + goto clean; + + ret =check_scmi_status (rx.status); +if ( ret ) + goto clean; + + n_agents =FIELD_GET (MSG_N_AGENTS_MASK , rx.attributes); +printk (XENLOG_DEBUG "scmi: Got agent count %d\n" , n_agents); + + n_agents = (n_agents > scmi_data.shmem_size /PAGE_SIZE ) ? + scmi_data.shmem_size /PAGE_SIZE : n_agents; + +for ( i =1 ; i < n_agents; i++ ) + { +uint32_t tx_agent_id =0xFFFFFFFF ; +struct { +int32_t status; +uint32_t agent_id; +char name[16 ]; + } da_rx; + + agent_channel =smc_create_channel (i, func_id, scmi_data.shmem_addr + + i *PAGE_SIZE ); +if (IS_ERR (agent_channel) ) + { + ret =PTR_ERR (agent_channel); + goto clean; + } + + hdr.id =SCMI_BASE_DISCOVER_AGENT ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + ret =do_smc_xfer (agent_channel, &hdr, &tx_agent_id, +sizeof (tx_agent_id), &da_rx,sizeof (da_rx)); +if ( ret ) + goto clean; + + ret =check_scmi_status (da_rx.status); +if ( ret ) + goto clean; + +printk (XENLOG_DEBUG "scmi: status=0x%x id=0x%x name=%s\n" , + da_rx.status, da_rx.agent_id, da_rx.name); + + agent_channel->agent_id = da_rx.agent_id; + } + + scmi_data.initialized = true; +return true; + +clean: +free_channel_list (); +return ret ==0 ; +} + +static int scmi_domain_init (struct domain *d) +{ +struct scmi_channel *channel; +int ret; +
xen/arch/arm/sci/scmi_smc.c line 571
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+if ( !scmi_data.initialized ) +return 0 ; + + channel =aquire_scmi_channel (d->domain_id); +if (IS_ERR_OR_NULL (channel) ) +return -ENOENT ; + +printk (XENLOG_INFO "scmi: Aquire SCMI channel id = 0x%x , domain_id = %d" +"paddr = 0x%lx\n" , channel->chan_id, channel->domain_id, + channel->paddr);
It seems this breaks build on Arm32:
scmi_smc.c: In function ‘scmi_domain_init’:/home/otyshchenko/xen/xen/include/xen/config.h:53:24: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘uint64_t {aka long long unsigned int}’ [-Werror=format=] #define XENLOG_INFO "<2>"
^
scmi_smc.c:569:12: note: in expansion of macro ‘XENLOG_INFO’
printk(XENLOG_INFO "scmi: Aquire SCMI channel id = 0x%x , domain_id = %d"
^~~~~~~~~~~
scmi_smc.c:570:25: note: format string is defined here
"paddr = 0x%lx\n", channel->chan_id, channel->domain_id,
~~^
%llx
Quoted 137 lines
xen/arch/arm/sci/scmi_smc.c new file +137
-0+ +if (is_hardware_domain (d) ) + { + ret =map_memory_to_domain (d, scmi_data.shmem_addr, + scmi_data.shmem_size); +if (IS_ERR_VALUE (ret) ) + goto error; + + ret =dt_update_domain_range (d, channel->paddr,PAGE_SIZE ); +if (IS_ERR_VALUE (ret) ) + { +int rc =unmap_memory_from_domain (d, scmi_data.shmem_addr, + scmi_data.shmem_size); +if ( rc ) +printk (XENLOG_ERR "Unable to unmap_memory_from_domain\n" ); + + goto error; + } + } + + d->arch.sci = channel; + +return 0 ; +error: +relinquish_scmi_channel (channel); + +return ret; +} + +static int scmi_add_device_by_devid (struct domain *d,uint32_t scmi_devid) +{ +struct scmi_channel *channel, *agent_channel; +scmi_msg_header_t hdr; +scmi_perms_tx_t tx; +struct rx_t { +int32_t status; +uint32_t attributes; + } rx; +int ret; + +if ( !scmi_data.initialized ) +return 0 ; + +printk (XENLOG_DEBUG "scmi: scmi_devid = %d\n" , scmi_devid); + + agent_channel =get_channel_by_domain (d->domain_id); +if (IS_ERR_OR_NULL (agent_channel) ) +return PTR_ERR (agent_channel); + + channel =get_channel_by_id (HYP_CHANNEL ); +if (IS_ERR_OR_NULL (channel) ) +return PTR_ERR (channel); + + hdr.id =SCMI_BASE_SET_DEVICE_PERMISSIONS ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + tx.agent_id = agent_channel->agent_id; + tx.device_id = scmi_devid; + tx.flags =SCMI_ALLOW_ACCESS ; + + ret =do_smc_xfer (channel, &hdr, &tx,sizeof (tx), &rx,sizeof (&rx)); +if (IS_ERR_VALUE (ret) ) +return ret; + + ret =check_scmi_status (rx.status); +if (IS_ERR_VALUE (ret) ) +return ret; + +return 0 ; +} + +static int scmi_add_dt_device (struct domain *d,struct dt_device_node *dev) +{ +uint32_t scmi_devid; + +if ( (!scmi_data.initialized) || (!d->arch.sci) ) +return 0 ; + +if ( !dt_property_read_u32 (dev,"scmi_devid" , &scmi_devid) ) +return 0 ; + +printk (XENLOG_INFO "scmi: dt_node = %s\n" ,dt_node_full_name (dev)); + +return scmi_add_device_by_devid (d, scmi_devid); +} + +static int scmi_relinquish_resources (struct domain *d) +{ +int ret; +struct scmi_channel *channel, *agent_channel; +scmi_msg_header_t hdr; +struct reset_agent_tx { +uint32_t agent_id; +uint32_t flags; + } tx; +uint32_t rx; + +if ( !d->arch.sci ) +return 0 ; + + agent_channel = d->arch.sci; + +spin_lock (&agent_channel->lock); + tx.agent_id = agent_channel->agent_id; +spin_unlock (&agent_channel->lock); + + channel =get_channel_by_id (HYP_CHANNEL ); +if ( !channel ) + { +printk (XENLOG_ERR +"scmi: Unable to get Hypervisor scmi channel for domain %d\n" , + d->domain_id); +return -EINVAL ; + } + + hdr.id =SCMI_BASE_RESET_AGENT_CONFIGURATION ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + tx.flags =0 ; + + ret =do_smc_xfer (channel, &hdr, &tx,sizeof (tx), &rx,sizeof (rx)); +if ( ret ) +return ret; + + ret =check_scmi_status (rx); + +return ret; +} + +static void scmi_domain_destroy (struct domain *d) +{ +struct scmi_channel *channel; + +if ( !d->arch.sci ) +return ;
xen/arch/arm/sci/scmi_smc.c line 718
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+ + channel = d->arch.sci; +spin_lock (&channel->lock); + +relinquish_scmi_channel (channel); +printk (XENLOG_DEBUG "scmi: Free domain %d\n" , d->domain_id); + + d->arch.sci =NULL ; + +unmap_memory_from_domain (d, channel->paddr,PAGE_SIZE );
I didn't manage to find where corresponding map_memory_from_domain() is called for a non-hardware domain (it seems that scmi_domain_init() only directly handles hardware domain case). Or perhaps, it is called indirectly at do_domctl(): case XEN_DOMCTL_iomem_permission:?
I wonder, do we really need to call this here? Taking into the account that unmap_memory_from_domain() doesn't actually unmap anything, but only removes a range from the iomem_caps rangeset for the domain to be destroyed and all involved rangesets (including iomem_caps) will be removed soon at rangeset_domain_destroy() anyway. Or I missed something?
xen/arch/arm/sci/scmi_smc.c line 720
Quoted 2 lines
xen/arch/arm/sci/scmi_smc.c new file +2
-0+spin_unlock (&channel->lock); +return ;
empty return could be dropped, I think.
Quoted 6 lines
xen/arch/arm/sci/scmi_smc.c new file +6
-0+} + +static bool scmi_handle_call (struct domain *d,void *args) +{ +bool res = false; +struct scmi_channel *agent_channel;
xen/arch/arm/sci/scmi_smc.c line 736
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+struct arm_smccc_res resp; +struct cpu_user_regs *regs = args; + +if ( !d->arch.sci ) +return false; + + agent_channel = d->arch.sci; +spin_lock (&agent_channel->lock); + +if ( agent_channel->func_id != regs->x0 )
This also breaks build on Arm32:
scmi_smc.c: In function ‘scmi_handle_call’:
scmi_smc.c:736:42: error: ‘struct cpu_user_regs’ has no member named ‘x0’; did you mean ‘r0’? if ( agent_channel->func_id != regs->x0 )
^~
r0
cc1: all warnings being treated as errors
***
BTW, I noticed that xen/arch/arm/traps.c contains the following construct, probably we might want something similar here?
#ifdef CONFIG_ARM_64
#define HYPERCALL_RESULT_REG(r) (r)->x0
[snip]
#else
#define HYPERCALL_RESULT_REG(r) (r)->r0
[snip]
#endif
This RFC patch series, so I think, there is no serious issues at the moment, this is rather to let you know for the future (when you drop RFC tag). I have to admit, I often forget to build-test on Arm32 also))
Quoted 71 lines
xen/arch/arm/sci/scmi_smc.c new file +59
-0+ { +printk (XENLOG_ERR "scmi: func_id mismatch, exiting\n" ); + goto unlock; + } + +arm_smccc_smc (agent_channel->func_id,0 ,0 ,0 ,0 ,0 ,0 , + agent_channel->chan_id, &resp); + +set_user_reg (regs,0 , resp.a0); +set_user_reg (regs,1 , resp.a1); +set_user_reg (regs,2 , resp.a2); +set_user_reg (regs,3 , resp.a3); + res = true; +unlock: +spin_unlock (&agent_channel->lock); + +return res; +} + +static int scmi_get_channel_paddr (void *scmi_ops, +struct xen_arch_domainconfig *config) +{ +struct scmi_channel *agent_channel = scmi_ops; + +if ( !agent_channel ) +return -EINVAL ; + + config->sci_agent_paddr = agent_channel->paddr; +return 0 ; +} + +static const struct dt_device_match scmi_smc_match[]__initconst = +{ +DT_MATCH_SCMI_SMC , + {/* sentinel */ }, +}; + +static const struct sci_mediator_ops scmi_ops = +{ + .probe = scmi_probe, + .domain_init = scmi_domain_init, + .domain_destroy = scmi_domain_destroy, + .add_dt_device = scmi_add_dt_device, + .relinquish_resources = scmi_relinquish_resources, + .handle_call = scmi_handle_call, + .get_channel_info = scmi_get_channel_paddr +}; + +REGISTER_SCI_MEDIATOR (scmi_smc,"SCMI-SMC" ,XEN_DOMCTL_CONFIG_SCI_SCMI_SMC , + scmi_smc_match, &scmi_ops); + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/public/arch-arm.h +1
-0@@ -315,6 +315,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);#define XEN_DOMCTL_CONFIG_TEE_OPTEE 1#define XEN_DOMCTL_CONFIG_SCI_NONE 0 +#define XEN_DOMCTL_CONFIG_SCI_SCMI_SMC 1struct xen_arch_domainconfig {/* IN/OUT */
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Hi Oleksandr,
Quoted 285 lines · Oleksandr
On 14.12.21 11:34, Oleksii Moisieiev wrote:
Hi Oleksii
Quoted 279 lines
This is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG.
The following features are implemented:
- request SCMI channels from ATF and pass channels to Domains;
- set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI;
- redirect scmi messages from Domains to ATF.Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 5 files changed, 809 insertions(+)create mode 100644 xen/arch/arm/sci/Kconfig
create mode 100644xen/arch/arm/sci/scmi_smc.cxen/arch/arm/Kconfig +2
-0@@ -114,6 +114,8 @@ config SCI support. It allows guests to control system resourcess via one of SCI mediators implemented in XEN. +source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/sci/Kconfig new file +10
-0@@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on SCI + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication.xen/arch/arm/sci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.oxen/arch/arm/sci/scmi_smc.c new file +216
-0@@ -0,0 +1,795 @@ +/* +* xen/arch/arm/sci/scmi_smc.c +* +* SCMI mediator driver, using SCP as transport. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/sci/sci.h> +#include <asm/smccc.h> +#include <asm/io.h> +#include <xen/bitops.h> +#include <xen/config.h> +#include <xen/sched.h> +#include <xen/device_tree.h> +#include <xen/iocap.h> +#include <xen/init.h> +#include <xen/err.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/string.h> +#include <xen/time.h> +#include <xen/vmap.h> + +#define SCMI_BASE_PROTOCOL 0x10 +#define SCMI_BASE_PROTOCOL_ATTIBUTES 0x1 +#define SCMI_BASE_SET_DEVICE_PERMISSIONS 0x9 +#define SCMI_BASE_RESET_AGENT_CONFIGURATION 0xB +#define SCMI_BASE_DISCOVER_AGENT 0x7 + +/* SCMI return codes. See section 4.1.4 of SCMI spec (DEN0056C) */ +#define SCMI_SUCCESS 0 +#define SCMI_NOT_SUPPORTED (-1) +#define SCMI_INVALID_PARAMETERS (-2) +#define SCMI_DENIED (-3) +#define SCMI_NOT_FOUND (-4) +#define SCMI_OUT_OF_RANGE (-5) +#define SCMI_BUSY (-6) +#define SCMI_COMMS_ERROR (-7) +#define SCMI_GENERIC_ERROR (-8) +#define SCMI_HARDWARE_ERROR (-9) +#define SCMI_PROTOCOL_ERROR (-10) + +#define DT_MATCH_SCMI_SMC DT_MATCH_COMPATIBLE("arm,scmi-smc") + +#define SCMI_SMC_ID "arm,smc-id" +#define SCMI_SHARED_MEMORY "linux,scmi_mem" +#define SCMI_SHMEM "shmem" + +#define HYP_CHANNEL 0x0 + +#define HDR_ID GENMASK(7,0) +#define HDR_TYPE GENMASK(9, 8) +#define HDR_PROTO GENMASK(17, 10) + +/* SCMI protocol, refer to section 4.2.2.2 (DEN0056C) */ +#define MSG_N_AGENTS_MASK GENMASK(15, 8) + +#define FIELD_GET (_mask, _reg)\ + ((typeof(_mask))(((_reg) & (_mask)) >> (ffs64(_mask) - 1))) +#define FIELD_PREP (_mask, _val)\ + (((typeof(_mask))(_val) << (ffs64(_mask) - 1)) & (_mask)) + +typedef struct scmi_msg_header { +uint8_t id; +uint8_t type; +uint8_t protocol; +}scmi_msg_header_t ; + +typedef struct scmi_perms_tx { +uint32_t agent_id; +uint32_t device_id; +uint32_t flags; +}scmi_perms_tx_t ; + +#define SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE BIT(0, UL) +#define SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR BIT(1, UL) + +#define SCMI_ALLOW_ACCESS BIT(0, UL) + +struct scmi_shared_mem { +uint32_t reserved; +uint32_t channel_status; +uint32_t reserved1[2 ]; +uint32_t flags; +uint32_t length; +uint32_t msg_header; +uint8_t msg_payload[]; +}; + +struct scmi_channel { +int chan_id; +int agent_id; +uint32_t func_id; +int domain_id; +uint64_t paddr; +struct scmi_shared_mem *shmem; +spinlock_t lock; +struct list_head list; +}; + +struct scmi_data { +struct list_head channel_list; +spinlock_t channel_list_lock; +bool initialized; +u64 shmem_addr, shmem_size; +}; + +static struct scmi_data scmi_data; + +/* +* pack_scmi_header() - packs and returns 32-bit header +* +* @hdr: pointer to header containing all the information on message id, +* protocol id and type id. +* +* Return: 32-bit packed message header to be sent to the platform. +*/ +static inline uint32_t pack_scmi_header (scmi_msg_header_t *hdr) +{ +return FIELD_PREP (HDR_ID , hdr->id) | +FIELD_PREP (HDR_TYPE , hdr->type) | +FIELD_PREP (HDR_PROTO , hdr->protocol); +} + +/* +* unpack_scmi_header() - unpacks and records message and protocol id +* +* @msg_hdr: 32-bit packed message header sent from the platform +* @hdr: pointer to header to fetch message and protocol id. +*/ +static inline void unpack_scmi_header (uint32_t msg_hdr,scmi_msg_header_t *hdr) +{ + hdr->id =FIELD_GET (HDR_ID , msg_hdr); + hdr->type =FIELD_GET (HDR_TYPE , msg_hdr); + hdr->protocol =FIELD_GET (HDR_PROTO , msg_hdr); +} + +static inline int channel_is_free (struct scmi_channel *chan_info) +{ +return ( chan_info->shmem->channel_status + &SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE ) ?0 : -EBUSY ; +} + +static int send_smc_message (struct scmi_channel *chan_info, +scmi_msg_header_t *hdr,void *data,int len) +{ +struct arm_smccc_res resp; +int ret; + +printk (XENLOG_DEBUG "scmi: status =%d len=%d\n" , + chan_info->shmem->channel_status, len); +printk (XENLOG_DEBUG "scmi: header id = %d type = %d, proto = %d\n" , + hdr->id, hdr->type, hdr->protocol); + + ret =channel_is_free (chan_info); +if (IS_ERR_VALUE (ret) ) +return ret; + + chan_info->shmem->channel_status =0x0 ; +/* Writing 0x0 right now, but SCMI_SHMEM_FLAG_INTR_ENABLED can be set */ + chan_info->shmem->flags =0x0 ; + chan_info->shmem->length =sizeof (chan_info->shmem->msg_header) + len; + chan_info->shmem->msg_header =pack_scmi_header (hdr); + +printk (XENLOG_DEBUG "scmi: Writing to shmem address %p\n" , + chan_info->shmem); +if ( len >0 && data ) +memcpy ((void *)(chan_info->shmem->msg_payload), data, len); + +arm_smccc_smc (chan_info->func_id,0 ,0 ,0 ,0 ,0 ,0 , chan_info->chan_id, + &resp); + +printk (XENLOG_DEBUG "scmi: scmccc_smc response %d\n" , (int )(resp.a0)); + +if ( resp.a0 ) +return -EOPNOTSUPP ; + +return 0 ; +} + +static int check_scmi_status (int scmi_status) +{ +if ( scmi_status ==SCMI_SUCCESS ) +return 0 ; + +printk (XENLOG_DEBUG "scmi: Error received: %d\n" , scmi_status); + +switch ( scmi_status ) + { +case SCMI_NOT_SUPPORTED : +return -EOPNOTSUPP ; +case SCMI_INVALID_PARAMETERS : +return -EINVAL ; +case SCMI_DENIED : +return -EACCES ; +case SCMI_NOT_FOUND : +return -ENOENT ; +case SCMI_OUT_OF_RANGE : +return -ERANGE ; +case SCMI_BUSY : +return -EBUSY ; +case SCMI_COMMS_ERROR : +return -ENOTCONN ;
Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 222
Quoted 6 lines
xen/arch/arm/sci/scmi_smc.c new file +6
-0+case SCMI_GENERIC_ERROR : +return -EIO ; +case SCMI_HARDWARE_ERROR : +return -ENXIO ; +case SCMI_PROTOCOL_ERROR : +return -EBADMSG ;Probably we should add a default: here?
Thanks, I will add the default, so fucntion will look like this:
static int check_scmi_status(int scmi_status)
{
...
switch ( scmi_status )
{
...
default:
return -EINVAL;
}
}Quoted 181 lines
Quoted 181 lines
xen/arch/arm/sci/scmi_smc.c new file +180
-0+ } + +return -EINVAL ; +} + +static int get_smc_response (struct scmi_channel *chan_info, +scmi_msg_header_t *hdr,void *data,int len) +{ +int recv_len; +int ret; + +printk (XENLOG_DEBUG "scmi: get smc responce msgid %d\n" , hdr->id); + + ret =channel_is_free (chan_info); +if (IS_ERR_VALUE (ret) ) +return ret; + + recv_len = chan_info->shmem->length -sizeof (chan_info->shmem->msg_header); + +if ( recv_len <0 ) + { +printk (XENLOG_ERR +"scmi: Wrong size of smc message. Data may be invalid\n" ); +return -EINVAL ; + } + +if ( recv_len > len ) + { +printk (XENLOG_ERR +"scmi: Not enough buffer for message %d, expecting %d\n" , + recv_len, len); +return -EINVAL ; + } + +unpack_scmi_header (chan_info->shmem->msg_header, hdr); + +if ( recv_len >0 ) + { +memcpy (data, chan_info->shmem->msg_payload, recv_len); + } + +return 0 ; +} + +static int do_smc_xfer (struct scmi_channel *channel,scmi_msg_header_t *hdr,void *tx_data,int tx_size, +void *rx_data,int rx_size) +{ +int ret =0 ; + +if ( !hdr ) +return -EINVAL ; + +spin_lock (&channel->lock); + + ret =send_smc_message (channel, hdr, tx_data, tx_size); +if ( ret ) + goto clean; + + ret =get_smc_response (channel, hdr, rx_data, rx_size); +clean: +spin_unlock (&channel->lock); + +return ret; +} + +static struct scmi_channel *get_channel_by_id (uint8_t chan_id) +{ +struct scmi_channel *curr; +bool found = false; + +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry (curr, &scmi_data.channel_list, list) +if ( curr->chan_id == chan_id ) + { + found = true; +break ; + } + +spin_unlock (&scmi_data.channel_list_lock); +if ( found ) +return curr; + +return NULL ; +} + +static struct scmi_channel *get_channel_by_domain (uint8_t domain_id) +{ +struct scmi_channel *curr; +bool found = false; + +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry (curr, &scmi_data.channel_list, list) +if ( curr->domain_id == domain_id ) + { + found = true; +break ; + } + +spin_unlock (&scmi_data.channel_list_lock); +if ( found ) +return curr; + +return NULL ; +} + +static struct scmi_channel *aquire_scmi_channel (int domain_id) +{ +struct scmi_channel *curr; +bool found = false; + +ASSERT (domain_id !=DOMID_INVALID && domain_id >=0 ); + +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry (curr, &scmi_data.channel_list, list) +if ( (curr->domain_id ==DOMID_INVALID ) + && (curr->chan_id !=HYP_CHANNEL ) ) + { + curr->domain_id = domain_id; + found = true; +break ; + } + +spin_unlock (&scmi_data.channel_list_lock); +if ( found ) +return curr; + +return NULL ; +} + +static void relinquish_scmi_channel (struct scmi_channel *channel) +{ +spin_lock (&scmi_data.channel_list_lock); +ASSERT (channel !=NULL ); + channel->domain_id =DOMID_INVALID ; +spin_unlock (&scmi_data.channel_list_lock); +} + +static struct scmi_channel *smc_create_channel (uint8_t chan_id, +uint32_t func_id,uint64_t addr) +{ +struct scmi_channel *channel; +mfn_t mfn; + + channel =get_channel_by_id (chan_id); +if ( channel ) +return ERR_PTR (EEXIST ); + + channel = xmalloc(struct scmi_channel); +if ( !channel ) +return ERR_PTR (ENOMEM ); + + channel->chan_id = chan_id; + channel->func_id = func_id; + channel->domain_id =DOMID_INVALID ; + mfn =maddr_to_mfn (addr); + channel->shmem =vmap (&mfn,1 ); +if ( !channel->shmem ) + { +xfree (channel); +return ERR_PTR (ENOMEM ); + } + +printk (XENLOG_DEBUG "scmi: Got shmem after vmap %p\n" , channel->shmem); + channel->paddr = addr; + channel->shmem->channel_status =SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE ; +spin_lock_init (&channel->lock); +spin_lock (&scmi_data.channel_list_lock); +list_add (&channel->list, &scmi_data.channel_list); +spin_unlock (&scmi_data.channel_list_lock); +return channel; +} + +static int map_memory_to_domain (struct domain *d,uint64_t addr,uint64_t len) +{ +return iomem_permit_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +} + +static int unmap_memory_from_domain (struct domain *d,uint64_t addr, +uint64_t len)
Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 406
Quoted 4 lines
xen/arch/arm/sci/scmi_smc.c new file +4
-0+{ +return iomem_deny_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +}I wonder, why we need an extra level of indirection here. And if this is really needed, I wonder why map(unmap)_memory* name was chosen, as there is no memory mapping/unmapping really happens here.
I've added extra indirection to hide math like paddr_to_pfn(PAGE_ALIGN(addr + len -1)
so you don't have to math in each call. unmap_memory_from_domain called from 2 places, so I moved both calls to separate function. Although, I agree that map/unmap is not perfect name. I consider renaming it to mem_permit_acces and mam_deny_access.
Quoted 7 lines
xen/arch/arm/sci/scmi_smc.c line 409
Quoted 4 lines
xen/arch/arm/sci/scmi_smc.c new file +3
-0+ +static int dt_update_domain_range (struct domain *d,uint64_t addr, +uint64_t size)Looks like *d is not used in this function.
Yep I will remove it. Thanks.
Quoted 42 lines
Quoted 42 lines
xen/arch/arm/sci/scmi_smc.c new file +41
-0+{ +struct dt_device_node *shmem_node; +__be32 *hw_reg; +const struct dt_property *pp; +uint32_t len; + + shmem_node =dt_find_compatible_node (NULL ,NULL ,"arm,scmi-shmem" ); + +if ( !shmem_node ) + { +printk (XENLOG_ERR "scmi: Unable to find %s node in DT\n" ,SCMI_SHMEM ); +return -EINVAL ; + } + + pp =dt_find_property (shmem_node,"reg" , &len); +if ( !pp ) + { +printk (XENLOG_ERR "scmi: Unable to find regs entry in shmem node\n" ); +return -ENOENT ; + } + + hw_reg = pp->value; +dt_set_range (&hw_reg, shmem_node, addr, size); + +return 0 ; +} + +static void free_channel_list (void ) +{ +struct scmi_channel *curr, *_curr; + +spin_lock (&scmi_data.channel_list_lock); + list_for_each_entry_safe (curr, _curr, &scmi_data.channel_list, list) + { +vunmap (curr->shmem); +list_del (&curr->list); +xfree (curr); + } + +spin_unlock (&scmi_data.channel_list_lock); +}
Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 452
Quoted 2 lines
xen/arch/arm/sci/scmi_smc.c new file +2
-0+ +static __init bool scmi_probe (struct dt_device_node *scmi_node)Generic question to consider ...
If probe fails for some reason (so we cannot use mediator in Xen) what should we do with SCMI nodes in domain's device-tree (leave as is, drop, etc)?
If probe fails - then the devices, which were configured to use scmi clocks\resets\power-domains will not work properly. If Domain configuration do not use SCMI - then it will not have the scmi node. So from my standpoint, no additional check is needed before copying scmi nodes to Domain device-tree.
Quoted 124 lines
Quoted 110 lines
xen/arch/arm/sci/scmi_smc.c new file +109
-0+{ +struct dt_device_node *shmem_node; +int ret, i; +struct scmi_channel *channel, *agent_channel; +int n_agents; +scmi_msg_header_t hdr; +struct rx_t { +int32_t status; +uint32_t attributes; + } rx; + +uint32_t func_id; + +ASSERT (scmi_node !=NULL ); + +INIT_LIST_HEAD (&scmi_data.channel_list); +spin_lock_init (&scmi_data.channel_list_lock); + +if ( !dt_property_read_u32 (scmi_node,SCMI_SMC_ID , &func_id) ) + { +printk (XENLOG_ERR "scmi: Unable to read smc-id from DT\n" ); +return false; + } + + shmem_node =dt_find_node_by_name (NULL ,SCMI_SHARED_MEMORY ); +if (IS_ERR_OR_NULL (shmem_node) ) + { +printk (XENLOG_ERR +"scmi: Device tree error, can't parse shmem phandle %ld\n" , +PTR_ERR (shmem_node)); +return false; + } + + ret =dt_device_get_address (shmem_node,0 , &scmi_data.shmem_addr, + &scmi_data.shmem_size); +if (IS_ERR_VALUE (ret) ) +return false; + + channel =smc_create_channel (HYP_CHANNEL , func_id, scmi_data.shmem_addr); +if (IS_ERR (channel) ) +return false; + + hdr.id =SCMI_BASE_PROTOCOL_ATTIBUTES ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + ret =do_smc_xfer (channel, &hdr,NULL ,0 , &rx,sizeof (rx)); +if ( ret ) + goto clean; + + ret =check_scmi_status (rx.status); +if ( ret ) + goto clean; + + n_agents =FIELD_GET (MSG_N_AGENTS_MASK , rx.attributes); +printk (XENLOG_DEBUG "scmi: Got agent count %d\n" , n_agents); + + n_agents = (n_agents > scmi_data.shmem_size /PAGE_SIZE ) ? + scmi_data.shmem_size /PAGE_SIZE : n_agents; + +for ( i =1 ; i < n_agents; i++ ) + { +uint32_t tx_agent_id =0xFFFFFFFF ; +struct { +int32_t status; +uint32_t agent_id; +char name[16 ]; + } da_rx; + + agent_channel =smc_create_channel (i, func_id, scmi_data.shmem_addr + + i *PAGE_SIZE ); +if (IS_ERR (agent_channel) ) + { + ret =PTR_ERR (agent_channel); + goto clean; + } + + hdr.id =SCMI_BASE_DISCOVER_AGENT ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + ret =do_smc_xfer (agent_channel, &hdr, &tx_agent_id, +sizeof (tx_agent_id), &da_rx,sizeof (da_rx)); +if ( ret ) + goto clean; + + ret =check_scmi_status (da_rx.status); +if ( ret ) + goto clean; + +printk (XENLOG_DEBUG "scmi: status=0x%x id=0x%x name=%s\n" , + da_rx.status, da_rx.agent_id, da_rx.name); + + agent_channel->agent_id = da_rx.agent_id; + } + + scmi_data.initialized = true; +return true; + +clean: +free_channel_list (); +return ret ==0 ; +} + +static int scmi_domain_init (struct domain *d) +{ +struct scmi_channel *channel; +int ret; +xen/arch/arm/sci/scmi_smc.c line 571
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+if ( !scmi_data.initialized ) +return 0 ; + + channel =aquire_scmi_channel (d->domain_id); +if (IS_ERR_OR_NULL (channel) ) +return -ENOENT ; + +printk (XENLOG_INFO "scmi: Aquire SCMI channel id = 0x%x , domain_id = %d" +"paddr = 0x%lx\n" , channel->chan_id, channel->domain_id, + channel->paddr);It seems this breaks build on Arm32:
Quoted 15 lines
scmi_smc.c: In function ‘scmi_domain_init’:/home/otyshchenko/xen/xen/include/xen/config.h:53:24: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘uint64_t {aka long long unsigned int}’ [-Werror=format=] #define XENLOG_INFO "<2>"
^
scmi_smc.c:569:12: note: in expansion of macro ‘XENLOG_INFO’ printk(XENLOG_INFO "scmi: Aquire SCMI channel id = 0x%x ,domain_id= %d"
^~~~~~~~~~~
scmi_smc.c:570:25: note: format string is defined here
"paddr = 0x%lx\n",channel->chan_id,channel->domain_id, ~~^
%llx
Thanks a lot. I will work through all buids in v2.
Quoted 146 lines
Quoted 146 lines
xen/arch/arm/sci/scmi_smc.c new file +144
-0+ +if (is_hardware_domain (d) ) + { + ret =map_memory_to_domain (d, scmi_data.shmem_addr, + scmi_data.shmem_size); +if (IS_ERR_VALUE (ret) ) + goto error; + + ret =dt_update_domain_range (d, channel->paddr,PAGE_SIZE ); +if (IS_ERR_VALUE (ret) ) + { +int rc =unmap_memory_from_domain (d, scmi_data.shmem_addr, + scmi_data.shmem_size); +if ( rc ) +printk (XENLOG_ERR "Unable to unmap_memory_from_domain\n" ); + + goto error; + } + } + + d->arch.sci = channel; + +return 0 ; +error: +relinquish_scmi_channel (channel); + +return ret; +} + +static int scmi_add_device_by_devid (struct domain *d,uint32_t scmi_devid) +{ +struct scmi_channel *channel, *agent_channel; +scmi_msg_header_t hdr; +scmi_perms_tx_t tx; +struct rx_t { +int32_t status; +uint32_t attributes; + } rx; +int ret; + +if ( !scmi_data.initialized ) +return 0 ; + +printk (XENLOG_DEBUG "scmi: scmi_devid = %d\n" , scmi_devid); + + agent_channel =get_channel_by_domain (d->domain_id); +if (IS_ERR_OR_NULL (agent_channel) ) +return PTR_ERR (agent_channel); + + channel =get_channel_by_id (HYP_CHANNEL ); +if (IS_ERR_OR_NULL (channel) ) +return PTR_ERR (channel); + + hdr.id =SCMI_BASE_SET_DEVICE_PERMISSIONS ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + tx.agent_id = agent_channel->agent_id; + tx.device_id = scmi_devid; + tx.flags =SCMI_ALLOW_ACCESS ; + + ret =do_smc_xfer (channel, &hdr, &tx,sizeof (tx), &rx,sizeof (&rx)); +if (IS_ERR_VALUE (ret) ) +return ret; + + ret =check_scmi_status (rx.status); +if (IS_ERR_VALUE (ret) ) +return ret; + +return 0 ; +} + +static int scmi_add_dt_device (struct domain *d,struct dt_device_node *dev) +{ +uint32_t scmi_devid; + +if ( (!scmi_data.initialized) || (!d->arch.sci) ) +return 0 ; + +if ( !dt_property_read_u32 (dev,"scmi_devid" , &scmi_devid) ) +return 0 ; + +printk (XENLOG_INFO "scmi: dt_node = %s\n" ,dt_node_full_name (dev)); + +return scmi_add_device_by_devid (d, scmi_devid); +} + +static int scmi_relinquish_resources (struct domain *d) +{ +int ret; +struct scmi_channel *channel, *agent_channel; +scmi_msg_header_t hdr; +struct reset_agent_tx { +uint32_t agent_id; +uint32_t flags; + } tx; +uint32_t rx; + +if ( !d->arch.sci ) +return 0 ; + + agent_channel = d->arch.sci; + +spin_lock (&agent_channel->lock); + tx.agent_id = agent_channel->agent_id; +spin_unlock (&agent_channel->lock); + + channel =get_channel_by_id (HYP_CHANNEL ); +if ( !channel ) + { +printk (XENLOG_ERR +"scmi: Unable to get Hypervisor scmi channel for domain %d\n" , + d->domain_id); +return -EINVAL ; + } + + hdr.id =SCMI_BASE_RESET_AGENT_CONFIGURATION ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + tx.flags =0 ; + + ret =do_smc_xfer (channel, &hdr, &tx,sizeof (tx), &rx,sizeof (rx)); +if ( ret ) +return ret; + + ret =check_scmi_status (rx); + +return ret; +} + +static void scmi_domain_destroy (struct domain *d) +{ +struct scmi_channel *channel; + +if ( !d->arch.sci ) +return ; + + channel = d->arch.sci; +spin_lock (&channel->lock); + +relinquish_scmi_channel (channel); +printk (XENLOG_DEBUG "scmi: Free domain %d\n" , d->domain_id); +
Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 718
Quoted 3 lines
xen/arch/arm/sci/scmi_smc.c new file +3
-0+ d->arch.sci =NULL ; + +unmap_memory_from_domain (d, channel->paddr,PAGE_SIZE );I didn't manage to find where corresponding
map_memory_from_domain()is called for a non-hardware domain (it seems thatscmi_domain_init()only directly handles hardware domain case).
Or perhaps, it is called indirectly atdo_domctl(): caseXEN_DOMCTL_iomem_permission:?
You were right. We need to permit access only for the Hardware domain.
Quoted 8 lines
I wonder, do we really need to call this here? Taking into the account that
unmap_memory_from_domain()doesn't actually unmap anything, but only removes a range from theiomem_capsrangeset
for the domain to be destroyed and all involved rangesets (includingiomem_caps) will be removed soon atrangeset_domain_destroy()anyway. Or I missed something?
unmap_memory_from_domain is also used in scmi_domain_init if error occured after successfull map_memory_to_domain call.
But this is a good point. I think it will be a good idea to make unmap_memory_from_domain in scmi_domain_destroy only for hardware domain. And make sure that for Software domains range is unmapped using XEN_DOMCTL_iomem_permission call.
I'll make those changes in v2.
Quoted 6 lines
xen/arch/arm/sci/scmi_smc.c line 720
Quoted 3 lines
xen/arch/arm/sci/scmi_smc.c new file +2
-0+spin_unlock (&channel->lock); +return ;empty return could be dropped, I think.
Agree. Will be fixed.
Quoted 20 lines
Quoted 7 lines
xen/arch/arm/sci/scmi_smc.c new file +6
-0+} + +static bool scmi_handle_call (struct domain *d,void *args) +{ +bool res = false; +struct scmi_channel *agent_channel;xen/arch/arm/sci/scmi_smc.c line 736
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+struct arm_smccc_res resp; +struct cpu_user_regs *regs = args; + +if ( !d->arch.sci ) +return false; + + agent_channel = d->arch.sci; +spin_lock (&agent_channel->lock); + +if ( agent_channel->func_id != regs->x0 )This also breaks build on Arm32:
Quoted 8 lines
scmi_smc.c: In function ‘scmi_handle_call’:
scmi_smc.c:736:42: error: ‘struct cpu_user_regs’ has no member named ‘x0’; did you mean ‘r0’?
if (agent_channel->func_id!=regs->x0)
^~
r0
cc1: all warnings being treated as errors
Thanks, I will fix it in v2.
Quoted 14 lines
***
BTW, I noticed that
xen/arch/arm/traps.ccontains the following construct, probably we might want something similar here?#ifdef
CONFIG_ARM_64
#defineHYPERCALL_RESULT_REG(r)(r)->x0
[snip]
#else
#defineHYPERCALL_RESULT_REG(r)(r)->r0
[snip]
#endif
Quoted 4 lines
This RFC patch series, so I think, there is no serious issues at the moment, this is rather to let you know for the future (when you drop RFC tag). I have to admit, I often forget to build-test on Arm32 also))
Thank you for understanding. But will try to cover all architectures.
Quoted 76 lines
Quoted 70 lines
xen/arch/arm/sci/scmi_smc.c new file +59
-0+ { +printk (XENLOG_ERR "scmi: func_id mismatch, exiting\n" ); + goto unlock; + } + +arm_smccc_smc (agent_channel->func_id,0 ,0 ,0 ,0 ,0 ,0 , + agent_channel->chan_id, &resp); + +set_user_reg (regs,0 , resp.a0); +set_user_reg (regs,1 , resp.a1); +set_user_reg (regs,2 , resp.a2); +set_user_reg (regs,3 , resp.a3); + res = true; +unlock: +spin_unlock (&agent_channel->lock); + +return res; +} + +static int scmi_get_channel_paddr (void *scmi_ops, +struct xen_arch_domainconfig *config) +{ +struct scmi_channel *agent_channel = scmi_ops; + +if ( !agent_channel ) +return -EINVAL ; + + config->sci_agent_paddr = agent_channel->paddr; +return 0 ; +} + +static const struct dt_device_match scmi_smc_match[]__initconst = +{ +DT_MATCH_SCMI_SMC , + {/* sentinel */ }, +}; + +static const struct sci_mediator_ops scmi_ops = +{ + .probe = scmi_probe, + .domain_init = scmi_domain_init, + .domain_destroy = scmi_domain_destroy, + .add_dt_device = scmi_add_dt_device, + .relinquish_resources = scmi_relinquish_resources, + .handle_call = scmi_handle_call, + .get_channel_info = scmi_get_channel_paddr +}; + +REGISTER_SCI_MEDIATOR (scmi_smc,"SCMI-SMC" ,XEN_DOMCTL_CONFIG_SCI_SCMI_SMC , + scmi_smc_match, &scmi_ops); + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/public/arch-arm.h +1
-0@@ -315,6 +315,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);#define XEN_DOMCTL_CONFIG_TEE_OPTEE 1#define XEN_DOMCTL_CONFIG_SCI_NONE 0 +#define XEN_DOMCTL_CONFIG_SCI_SCMI_SMC 1struct xen_arch_domainconfig {/* IN/OUT */ Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Hi,
Quoted 18 lines · Oleksii Moisieiev
Quoted 8 lines
Quoted 8 lines
xen/arch/arm/sci/scmi_smc.c new file +8
-0+static int map_memory_to_domain (struct domain *d,uint64_t addr,uint64_t len) +{ +return iomem_permit_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +} + +static int unmap_memory_from_domain (struct domain *d,uint64_t addr, +uint64_t len)Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 406
Quoted 4 lines
xen/arch/arm/sci/scmi_smc.c new file +4
-0+{ +return iomem_deny_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +}I wonder, why we need an extra level of indirection here. And if this is really needed, I wonder why map(unmap)_memory* name was chosen, as there is no memory mapping/unmapping really happens here.
Quoted 6 lines
I've added extra indirection to hide math like paddr_to_pfn(PAGE_ALIGN(addr + len -1)
so you don't have to math in each call.unmap_memory_from_domaincalled from 2 places, so I moved both calls to separate function. Although, I agree that map/unmap is not perfect name. I consider renaming it tomem_permit_accesandmam_deny_access.
I haven't looked at the rest of the series. But this discussion caught my eye. This code implies that the address is page-aligned but the length not. Is that intended?
That said, if you give permission to the domain on a full page then it means it may be able to access address it should not. Can you explain why this is fine?
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Hi Julien,
Quoted 28 lines · Julien Grall
Hi,
Quoted 18 lines · Oleksii Moisieiev
Quoted 8 lines
Quoted 8 lines
xen/arch/arm/sci/scmi_smc.c new file +8
-0+static int map_memory_to_domain (struct domain *d,uint64_t addr,uint64_t len) +{ +return iomem_permit_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +} + +static int unmap_memory_from_domain (struct domain *d,uint64_t addr, +uint64_t len)Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 406
Quoted 4 lines
xen/arch/arm/sci/scmi_smc.c new file +4
-0+{ +return iomem_deny_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +}I wonder, why we need an extra level of indirection here. And if this is really needed, I wonder why map(unmap)_memory* name was chosen, as there is no memory mapping/unmapping really happens here.
Quoted 6 lines
I've added extra indirection to hide math like paddr_to_pfn(PAGE_ALIGN(addr + len -1)
so you don't have to math in each call.unmap_memory_from_domaincalled from 2 places, so I moved both calls to separate function. Although, I agree that map/unmap is not perfect name. I consider renaming it tomem_permit_accesandmam_deny_access.
Quoted 8 lines
I haven't looked at the rest of the series. But this discussion caught my eye. This code implies that the address is page-aligned but the length not. Is that intended?
That said, if you give permission to the domain on a full page then it means it may be able to access address it should not. Can you explain why this is fine?
The idea was that xen receives some memory from the dt_node linux,scmi_mem, then we split memory between the agents, so each agent get 1 page (we allocate 0x10 pages right now).
But this is a good point, I think we should check length to be aligned before making any permission changes.
I will add it in v2.
Thank you for remark.
Oleksii.
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Quoted 1 line · Oleksii Moisieiev
Hi Julien,
Hi,
Quoted 33 lines · Julien Grall
Quoted 32 lines
Hi,
Quoted 18 lines · Oleksii Moisieiev
Quoted 8 lines
Quoted 8 lines
xen/arch/arm/sci/scmi_smc.c new file +8
-0+static int map_memory_to_domain (struct domain *d,uint64_t addr,uint64_t len) +{ +return iomem_permit_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +} + +static int unmap_memory_from_domain (struct domain *d,uint64_t addr, +uint64_t len)Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 406
Quoted 4 lines
xen/arch/arm/sci/scmi_smc.c new file +4
-0+{ +return iomem_deny_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +}I wonder, why we need an extra level of indirection here. And if this is really needed, I wonder why map(unmap)_memory* name was chosen, as there is no memory mapping/unmapping really happens here.
Quoted 6 lines
I've added extra indirection to hide math like paddr_to_pfn(PAGE_ALIGN(addr + len -1)
so you don't have to math in each call.unmap_memory_from_domaincalled from 2 places, so I moved both calls to separate function. Although, I agree that map/unmap is not perfect name. I consider renaming it tomem_permit_accesandmam_deny_access.I haven't looked at the rest of the series. But this discussion caught my eye. This code implies that the address is page-aligned but the length not. Is that intended?
Quoted 8 lines
Quoted 4 lines
That said, if you give permission to the domain on a full page then it means it may be able to access address it should not. Can you explain why this is fine?
The idea was that xen receives some memory from the
dt_nodelinux,scmi_mem, then we split memory between the agents, so each agent get 1 page (we allocate0x10pages right now).
Thanks for the clarification. Does this imply the guest will be able to write message directly to the firmware?
If so, this brings a few more questions:
1) What will the guest write in it? Can it contains addresses?
2) What are the expected memory attribute for the regions?
3) What's the threat model for the firmware? Will it verify every
request?
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Hi Julien,
Quoted 45 lines · Julien Grall
Quoted 1 line · Oleksii Moisieiev
Hi Julien,
Hi,
Quoted 38 lines · Julien Grall
Quoted 36 lines
Hi,
Quoted 18 lines · Oleksii Moisieiev
Quoted 8 lines
Quoted 8 lines
xen/arch/arm/sci/scmi_smc.c new file +8
-0+static int map_memory_to_domain (struct domain *d,uint64_t addr,uint64_t len) +{ +return iomem_permit_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +} + +static int unmap_memory_from_domain (struct domain *d,uint64_t addr, +uint64_t len)Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 406
Quoted 4 lines
xen/arch/arm/sci/scmi_smc.c new file +4
-0+{ +return iomem_deny_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +}I wonder, why we need an extra level of indirection here. And if this is really needed, I wonder why map(unmap)_memory* name was chosen, as there is no memory mapping/unmapping really happens here.
Quoted 6 lines
I've added extra indirection to hide math like paddr_to_pfn(PAGE_ALIGN(addr + len -1)
so you don't have to math in each call.unmap_memory_from_domaincalled from 2 places, so I moved both calls to separate function. Although, I agree that map/unmap is not perfect name. I consider renaming it tomem_permit_accesandmam_deny_access.I haven't looked at the rest of the series. But this discussion caught my eye. This code implies that the address is page-aligned but the length not. Is that intended?
That said, if you give permission to the domain on a full page then it means it may be able to access address it should not. Can you explain why this is fine?
Quoted 6 lines
Quoted 3 lines
The idea was that xen receives some memory from the
dt_nodelinux,scmi_mem, then we split memory between the agents, so each agent get 1 page (we allocate0x10pages right now).Thanks for the clarification. Does this imply the guest will be able to write message directly to the firmware?
We used DEN0056C Specification as base. Available on: https://developer.arm.com/documentation/den0056/latest.
SCMI transport is described in Section 5.1. We implemented Shared Memory transport. Firmware has N pages of the shared memory, used to communicate with Agents.
It allocates N agents and assign a page for each agent, such as:
-------------------------------------
| Agent H | Agent 1 | Agent 2 | ... |
-------------------------------------
Agent H is the privilleged Hypervisor agent, which is used to do the base commands,
such as getting Agent list, set\unset permissions etc.
Hypervisor assign agent to the guest and maps page, related to the agent to the Guest.
So the Guest, which is Agent 1 will get an access to Agent 1 page.
Guest places SCMI message to Agent 1 memory, then sends SMC message.
Hypervisor process SMC request, add agent id to the message parameters and redirects it to the Firmware. Based on the agent_id Firmware knows which page it should read.
Then after permission check ( if the resetId/clockID/powerID etc from message
is assigned to agent_id ) it does changes to the HW and places response to Agent
shared memory and marks channel as FREE ( by setting free bit in shared memory ).
Once channel is marked as free - Guest read response from the shared memory.
Non-virtualized systems will work as well. OS should send SMC directly to the Firmware.
Quoted 3 lines
If so, this brings a few more questions:
1) What will the guest write in it? Can it contains addresses?
Guest can write scmi request to the shared memory, which include the following data:
1) protocol_id - which protocol is requested, such as clock, power, reset etc
2) message_id - action that should be done to HW, such as do_reset or get_clock
3) message data - which includes reset_id/clock_id/power_id etc. that should be changed.
Reset IDs and Clock IDs are assigned in Firmware. Guest receives ID, corresponding to the device from the device-tree. dt_node as an example:
&avb {
scmi_devid = <0>;
clocks = <&scmi_clock 0>;
power-domains = <&scmi_power 0>;
resets = <&scmi_reset 0>;
};Quoted 1 line
2) What are the expected memory attribute for the regions?
xen uses iommu_permit_access to pass agent page to the guest. So guest can access the page directly.
Quoted 1 line
3) What's the threat model for the firmware? Will it verify every request?
Firmware reads data from agent page, then makes check if clockid/resetid/powerid etc is assigned to agent.
During building guest, Xen sends permission request to the firmware for each device, which is passed-through to the guest. So for avb from previous example the device_id 0 permission request will be sent. Based on the device_id firmware will set permission for clockid 0, resetid 0 and powerid 0.
Best regards,
Oleksii.
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Quoted 1 line · Oleksii Moisieiev
Hi Julien,
Hello,
Quoted 65 lines · Julien Grall
Quoted 45 lines · Oleksii Moisieiev
Quoted 1 line
Hi Julien,
Hi,
Quoted 38 lines · Julien Grall
Quoted 36 lines
Hi,
Quoted 18 lines · Oleksii Moisieiev
Quoted 8 lines
Quoted 8 lines
(quoted diff) +8
-0+static int map_memory_to_domain(struct domain *d, uint64_t addr, uint64_t len) +{ + return iomem_permit_access(d, paddr_to_pfn(addr), + paddr_to_pfn(PAGE_ALIGN(addr + len -1))); +} + +static int unmap_memory_from_domain(struct domain *d, uint64_t addr, + uint64_t len)Quoted 9 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+{ + return iomem_deny_access(d, paddr_to_pfn(addr), + paddr_to_pfn(PAGE_ALIGN(addr + len -1))); +}I wonder, why we need an extra level of indirection here. And if this is really needed, I wonder why map(unmap)_memory* name was chosen, as there is no memory mapping/unmapping really happens here.
Quoted 6 lines
I've added extra indirection to hide math like paddr_to_pfn(PAGE_ALIGN(addr + len -1)
so you don't have to math in each call.unmap_memory_from_domaincalled from 2 places, so I moved both calls to separate function. Although, I agree that map/unmap is not perfect name. I consider renaming it tomem_permit_accesandmam_deny_access.I haven't looked at the rest of the series. But this discussion caught my eye. This code implies that the address is page-aligned but the length not. Is that intended?
That said, if you give permission to the domain on a full page then it means it may be able to access address it should not. Can you explain why this is fine?
Quoted 6 lines
Quoted 3 lines
The idea was that xen receives some memory from the
dt_nodelinux,scmi_mem, then we split memory between the agents, so each agent get 1 page (we allocate0x10pages right now).Thanks for the clarification. Does this imply the guest will be able to write message directly to the firmware?
We used DEN0056C Specification as base. Available on: https://developer.arm.com/documentation/den0056/latest.
SCMI transport is described in Section 5.1. We implemented Shared Memory transport. Firmware has N pages of the shared memory, used to communicate with Agents.
It allocates N agents and assign a page for each agent, such as:
-------------------------------------
| Agent H | Agent 1 | Agent 2 | ... |
-------------------------------------
Agent H is the privilleged Hypervisor agent, which is used to do the base commands,
such as getting Agent list, set\unset permissions etc.
Hypervisor assign agent to the guest and maps page, related to the agent to the Guest.
So the Guest, which is Agent 1 will get an access to Agent 1 page.
Quoted 7 lines
Guest places SCMI message to Agent 1 memory, then sends SMC message.
Hypervisor process SMC request, add agent id to the message parameters and redirects it to the Firmware. Based on theagent_idFirmware knows which page it should read.
Then after permission check ( if the resetId/clockID/powerID etc from message
is assigned toagent_id) it does changes to the HW and places response to Agent
shared memory and marks channel as FREE ( by setting free bit in shared memory ).
Once channel is marked as free - Guest read response from the shared memory.
So, IIUC, the hypervisor will not control what is written in the shared memory. It will only control the SMC parameters. Is my understanding correct?
Quoted 19 lines
Non-virtualized systems will work as well. OS should send SMC directly to the Firmware.
Quoted 3 lines
If so, this brings a few more questions:
1) What will the guest write in it? Can it contains addresses?Guest can write scmi request to the shared memory, which include the following data:
1)protocol_id- which protocol is requested, such as clock, power, reset etc
2)message_id- action that should be done to HW, such asdo_resetorget_clock
3) message data - which includes reset_id/clock_id/power_id etc. that should be changed.
Reset IDs and Clock IDs are assigned in Firmware. Guest receives ID, corresponding to the device from the device-tree.dt_nodeas an example:&avb { scmi_devid = <0>; clocks = <&scmi_clock 0>; power-domains = <&scmi_power 0>; resets = <&scmi_reset 0>; };
Quoted 3 lines
Quoted 1 line
2) What are the expected memory attribute for the regions?
xen uses
iommu_permit_accessto pass agent page to the guest. So guest can access the page directly.
I think you misunderstood my comment. Memory can be mapped with various type (e.g. Device, Memory) and attribute (cacheable, non-cacheable...). What will the firmware expect? What will the guest OS usually?
The reason I am asking is the attributes have to matched to avoid any coherency issues. At the moment, if you use XEN_DOMCTL_memory_mapping, Xen will configure the stage-2 to use Device nGnRnE. As the result, the result memory access will be Device nGnRnE which is very strict.
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Quoted 78 lines · Julien Grall
Quoted 1 line · Oleksii Moisieiev
Hi Julien,
Hello,
Quoted 65 lines · Julien Grall
Quoted 45 lines · Oleksii Moisieiev
Quoted 1 line
Hi Julien,
Hi,
Quoted 38 lines · Julien Grall
Quoted 36 lines
Hi,
Quoted 18 lines · Oleksii Moisieiev
Quoted 8 lines
Quoted 8 lines
(quoted diff) +8
-0+static int map_memory_to_domain(struct domain *d, uint64_t addr, uint64_t len) +{ + return iomem_permit_access(d, paddr_to_pfn(addr), + paddr_to_pfn(PAGE_ALIGN(addr + len -1))); +} + +static int unmap_memory_from_domain(struct domain *d, uint64_t addr, + uint64_t len)Quoted 9 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+{ + return iomem_deny_access(d, paddr_to_pfn(addr), + paddr_to_pfn(PAGE_ALIGN(addr + len -1))); +}I wonder, why we need an extra level of indirection here. And if this is really needed, I wonder why map(unmap)_memory* name was chosen, as there is no memory mapping/unmapping really happens here.
Quoted 6 lines
I've added extra indirection to hide math like paddr_to_pfn(PAGE_ALIGN(addr + len -1)
so you don't have to math in each call.unmap_memory_from_domaincalled from 2 places, so I moved both calls to separate function. Although, I agree that map/unmap is not perfect name. I consider renaming it tomem_permit_accesandmam_deny_access.I haven't looked at the rest of the series. But this discussion caught my eye. This code implies that the address is page-aligned but the length not. Is that intended?
That said, if you give permission to the domain on a full page then it means it may be able to access address it should not. Can you explain why this is fine?
Quoted 6 lines
Quoted 3 lines
The idea was that xen receives some memory from the
dt_nodelinux,scmi_mem, then we split memory between the agents, so each agent get 1 page (we allocate0x10pages right now).Thanks for the clarification. Does this imply the guest will be able to write message directly to the firmware?
We used DEN0056C Specification as base. Available on: https://urldefense.com/v3/__https://developer.arm.com/documentation/den0056/latest__;!!GF_29dbcQIUBPA!m9pWoxBEjb8Sd1CoV5cpU8MbmLCjohYQxv2ci9tDvMmZ9oCEitqyydZ3rQWXCM5bxvIn$ [developer[.]arm[.]com]. SCMI transport is described in Section 5.1. We implemented Shared Memory transport.
Firmware has N pages of the shared memory, used to communicate with Agents.
It allocates N agents and assign a page for each agent, such as:
-------------------------------------
| Agent H | Agent 1 | Agent 2 | ... |
-------------------------------------
Agent H is the privilleged Hypervisor agent, which is used to do the base commands,
such as getting Agent list, set\unset permissions etc.
Hypervisor assign agent to the guest and maps page, related to the agent to the Guest.
So the Guest, which is Agent 1 will get an access to Agent 1 page.Quoted 7 lines
Guest places SCMI message to Agent 1 memory, then sends SMC message.
Hypervisor process SMC request, add agent id to the message parameters and redirects it to the Firmware. Based on theagent_idFirmware knows which page it should read.
Then after permission check ( if the resetId/clockID/powerID etc from message
is assigned toagent_id) it does changes to the HW and places response to Agent
shared memory and marks channel as FREE ( by setting free bit in shared memory ).
Once channel is marked as free - Guest read response from the shared memory.
Quoted 4 lines
So, IIUC, the hypervisor will not control what is written in the shared memory. It will only control the SMC parameters. Is my understanding correct?
For scmi_smc it will not. But potentially it can make some changes, or convert to the different protocol.
Quoted 23 lines
Quoted 19 lines
Non-virtualized systems will work as well. OS should send SMC directly to the Firmware.
Quoted 3 lines
If so, this brings a few more questions:
1) What will the guest write in it? Can it contains addresses?Guest can write scmi request to the shared memory, which include the following data:
1)protocol_id- which protocol is requested, such as clock, power, reset etc
2)message_id- action that should be done to HW, such asdo_resetorget_clock
3) message data - which includes reset_id/clock_id/power_id etc. that should be changed.
Reset IDs and Clock IDs are assigned in Firmware. Guest receives ID, corresponding to the device from the device-tree.dt_nodeas an example:&avb { scmi_devid = <0>; clocks = <&scmi_clock 0>; power-domains = <&scmi_power 0>; resets = <&scmi_reset 0>; };Quoted 3 lines
Quoted 1 line
2) What are the expected memory attribute for the regions?
xen uses
iommu_permit_accessto pass agent page to the guest. So guest can access the page directly.
Quoted 9 lines
I think you misunderstood my comment. Memory can be mapped with various type (e.g. Device, Memory) and attribute (cacheable, non-cacheable...). What will the firmware expect? What will the guest OS usually?
The reason I am asking is the attributes have to matched to avoid any coherency issues. At the moment, if you use
XEN_DOMCTL_memory_mapping, Xen will configure the stage-2 to use Device nGnRnE. As the result, the result memory access will be Device nGnRnE which is very strict.
Let me share with you the configuration example:
scmi expects memory to be configured in the device-tree:
cpu_scp_shm: scp-shmem@0xXXXXXXX {
compatible = "arm,scmi-shmem";
reg = <0x0 0xXXXXXX 0x0 0x1000>;
};where XXXXXX address I allocate in alloc_magic_pages function. Then I get paddr of the scmi channel for this domain and use XEN_DOMCTL_memory_mapping to map scmi channel address to gfn.
Hope I wass able to answer your question.
Best regards,
Oleksii.
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Hi,
Quoted 19 lines · Oleksii Moisieiev
Quoted 5 lines · Julien Grall
Quoted 3 lines · Oleksii Moisieiev
Quoted 1 line
2) What are the expected memory attribute for the regions?
xen uses
iommu_permit_accessto pass agent page to the guest. So guest can access the page directly.Quoted 9 lines
I think you misunderstood my comment. Memory can be mapped with various type (e.g. Device, Memory) and attribute (cacheable, non-cacheable...). What will the firmware expect? What will the guest OS usually?
The reason I am asking is the attributes have to matched to avoid any coherency issues. At the moment, if you use
XEN_DOMCTL_memory_mapping, Xen will configure the stage-2 to use Device nGnRnE. As the result, the result memory access will be Device nGnRnE which is very strict.Let me share with you the configuration example:
scmi expects memory to be configured in the device-tree:
Quoted 6 lines
cpu_scp_shm: scp-shmem@0xXXXXXXX { compatible = "arm,scmi-shmem"; reg = <0x0 0xXXXXXX 0x0 0x1000>; };where XXXXXX address I allocate in
alloc_magic_pagesfunction.
The goal of alloc_magic_pages() is to allocate RAM. However, what you want is a guest physical address and then map a part of the shared page.
I can see two options here:
1) Hardcode the SCMI region in the memory map
2) Create a new region in the memory map that can be used for
reserving memory for mapping.
We still have plenty of space in the guest memory map. So the former is probably going to be fine for now.
Quoted 3 lines
Then I get paddr of the scmi channel for this domain and use
XEN_DOMCTL_memory_mappingto map scmi channel address to gfn.Quoted 1 line
Hope I wass able to answer your question.
What you provided me is how the guest OS will locate the shared memory. This still doesn't tell me which memory attribute will be used to map the page in Stage-1 (guest page-tables).
To find that out, you want to look at the driver and how the mapping is done. The Linux driver (drivers/firmware/arm_scmi) is using devm_ioremap() (see smc_chan_setup()).
Under the hood, the function devm_ioremap() is using PROT_DEVICE_nGnRE (arm64) which is one of the most restrictive memory attribute.
This means the firmware should be able to deal with the most restrictive attribute and therefore using XEN_DOMCTL_memory_mapping to map the shared page in stage-2 should be fine.
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Hi Julien,
Quoted 27 lines · Julien Grall
Hi,
Quoted 24 lines · Oleksii Moisieiev
Quoted 5 lines · Julien Grall
Quoted 3 lines · Oleksii Moisieiev
Quoted 1 line
2) What are the expected memory attribute for the regions?
xen uses
iommu_permit_accessto pass agent page to the guest. So guest can access the page directly.Quoted 9 lines
I think you misunderstood my comment. Memory can be mapped with various type (e.g. Device, Memory) and attribute (cacheable, non-cacheable...). What will the firmware expect? What will the guest OS usually?
The reason I am asking is the attributes have to matched to avoid any coherency issues. At the moment, if you use
XEN_DOMCTL_memory_mapping, Xen will configure the stage-2 to use Device nGnRnE. As the result, the result memory access will be Device nGnRnE which is very strict.Let me share with you the configuration example:
scmi expects memory to be configured in the device-tree:cpu_scp_shm: scp-shmem@0xXXXXXXX { compatible = "arm,scmi-shmem"; reg = <0x0 0xXXXXXX 0x0 0x1000>; };
Quoted 4 lines
Quoted 1 line
where XXXXXX address I allocate in
alloc_magic_pagesfunction.The goal of
alloc_magic_pages()is to allocate RAM. However, what you want is a guest physical address and then map a part of the shared page.
Do you mean that I can't use alloc_magic_pages to allocate shared memory region for SCMI?
Quoted 5 lines
I can see two options here:
1) Hardcode the SCMI region in the memory map
2) Create a new region in the memory map that can be used for reserving
memory for mapping.
Could you please explain what do you mean under the "new region in the memory map"?
Quoted 16 lines
We still have plenty of space in the guest memory map. So the former is probably going to be fine for now.
Quoted 3 lines
Then I get paddr of the scmi channel for this domain and use
XEN_DOMCTL_memory_mappingto map scmi channel address to gfn.Quoted 1 line
Hope I wass able to answer your question.
What you provided me is how the guest OS will locate the shared memory. This still doesn't tell me which memory attribute will be used to map the page in Stage-1 (guest page-tables).
To find that out, you want to look at the driver and how the mapping is done. The Linux driver (
drivers/firmware/arm_scmi) is usingdevm_ioremap()(seesmc_chan_setup()).
Quoted 7 lines
Under the hood, the function
devm_ioremap()is usingPROT_DEVICE_nGnRE(arm64) which is one of the most restrictive memory attribute.This means the firmware should be able to deal with the most restrictive attribute and therefore using
XEN_DOMCTL_memory_mappingto map the shared page in stage-2 should be fine.
I'm using vmap call to map channel memory (see smc_create_channel()). vmap call sets PAGE_HYPERVISOR flag which sets MT_NORMAL (0x7) flag. Considering that protocol is synchronous and only one agent per channel is expected - this works fine for now.
But I agree that the same memory attributes should be used in xen and kernel. I fill fix that in v2.
Best regards,
Oleksii.
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Quoted 1 line · Oleksii Moisieiev
Hi Julien,
Hi,
Quoted 29 lines · Julien Grall
Quoted 27 lines
Hi,
Quoted 24 lines · Oleksii Moisieiev
Quoted 5 lines · Julien Grall
Quoted 3 lines · Oleksii Moisieiev
Quoted 1 line
2) What are the expected memory attribute for the regions?
xen uses
iommu_permit_accessto pass agent page to the guest. So guest can access the page directly.Quoted 9 lines
I think you misunderstood my comment. Memory can be mapped with various type (e.g. Device, Memory) and attribute (cacheable, non-cacheable...). What will the firmware expect? What will the guest OS usually?
The reason I am asking is the attributes have to matched to avoid any coherency issues. At the moment, if you use
XEN_DOMCTL_memory_mapping, Xen will configure the stage-2 to use Device nGnRnE. As the result, the result memory access will be Device nGnRnE which is very strict.Let me share with you the configuration example:
scmi expects memory to be configured in the device-tree:cpu_scp_shm: scp-shmem@0xXXXXXXX { compatible = "arm,scmi-shmem"; reg = <0x0 0xXXXXXX 0x0 0x1000>; };
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
where XXXXXX address I allocate in
alloc_magic_pagesfunction.The goal of
alloc_magic_pages()is to allocate RAM. However, what you want is a guest physical address and then map a part of the shared page.Do you mean that I can't use
alloc_magic_pagesto allocate shared memory region for SCMI?
Correct. alloc_magic_pages() will allocate a RAM page and then assign to the guest. From your description, this is not what you want because you will call XEN_DOMCTL_memory_mapping (and therefore replace the mapping).
Quoted 9 lines
Quoted 6 lines
I can see two options here:
1) Hardcode the SCMI region in the memory map
2) Create a new region in the memory map that can be used for reserving
memory for mapping.Could you please explain what do you mean under the "new region in the memory map"?
I mean reserving some guest physical address that could be used for map host physical address (e.g. SCMI region, GIC CPU interface...).
So rather than hardcoding the address, we have something more flexible.
Quoted 20 lines
Quoted 20 lines
We still have plenty of space in the guest memory map. So the former is probably going to be fine for now.
Quoted 3 lines
Then I get paddr of the scmi channel for this domain and use
XEN_DOMCTL_memory_mappingto map scmi channel address to gfn.Quoted 1 line
Hope I wass able to answer your question.
What you provided me is how the guest OS will locate the shared memory. This still doesn't tell me which memory attribute will be used to map the page in Stage-1 (guest page-tables).
To find that out, you want to look at the driver and how the mapping is done. The Linux driver (
drivers/firmware/arm_scmi) is usingdevm_ioremap()(seesmc_chan_setup()).Under the hood, the function
devm_ioremap()is usingPROT_DEVICE_nGnRE(arm64) which is one of the most restrictive memory attribute.
Quoted 7 lines
Quoted 4 lines
This means the firmware should be able to deal with the most restrictive attribute and therefore using
XEN_DOMCTL_memory_mappingto map the shared page in stage-2 should be fine.I'm using vmap call to map channel memory (see
smc_create_channel()). vmap call setsPAGE_HYPERVISORflag which setsMT_NORMAL(0x7) flag.
You want to use ioremap().
Quoted 4 lines
Considering that protocol is synchronous and only one agent per channel is expected - this works fine for now.
But I agree that the same memory attributes should be used in xen and kernel. I fill fix that in v2.
I am a bit confused. Are you mapping the full shared memory area in Xen? If yes, why do you need to map the memory that is going to be shared with a domain?
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Quoted 38 lines · Julien Grall
Quoted 1 line · Oleksii Moisieiev
Hi Julien,
Hi,
Quoted 31 lines · Julien Grall
Quoted 29 lines
Hi,
Quoted 25 lines · Oleksii Moisieiev
Quoted 5 lines · Julien Grall
Quoted 3 lines · Oleksii Moisieiev
Quoted 1 line
2) What are the expected memory attribute for the regions?
xen uses
iommu_permit_accessto pass agent page to the guest. So guest can access the page directly.Quoted 9 lines
I think you misunderstood my comment. Memory can be mapped with various type (e.g. Device, Memory) and attribute (cacheable, non-cacheable...). What will the firmware expect? What will the guest OS usually?
The reason I am asking is the attributes have to matched to avoid any coherency issues. At the moment, if you use
XEN_DOMCTL_memory_mapping, Xen will configure the stage-2 to use Device nGnRnE. As the result, the result memory access will be Device nGnRnE which is very strict.Let me share with you the configuration example:
scmi expects memory to be configured in the device-tree:cpu_scp_shm: scp-shmem@0xXXXXXXX { compatible = "arm,scmi-shmem"; reg = <0x0 0xXXXXXX 0x0 0x1000>; };where XXXXXX address I allocate in
alloc_magic_pagesfunction.
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
The goal of
alloc_magic_pages()is to allocate RAM. However, what you want is a guest physical address and then map a part of the shared page.Do you mean that I can't use
alloc_magic_pagesto allocate shared memory region for SCMI?Correct.
alloc_magic_pages()will allocate a RAM page and then assign to the guest. From your description, this is not what you want because you will callXEN_DOMCTL_memory_mapping(and therefore replace the mapping).
Ok thanks, I will refactor this part in v2.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
I can see two options here:
1) Hardcode the SCMI region in the memory map
2) Create a new region in the memory map that can be used for reserving
memory for mapping.
Quoted 8 lines
Quoted 2 lines
Could you please explain what do you mean under the "new region in the memory map"?
I mean reserving some guest physical address that could be used for map host physical address (e.g. SCMI region, GIC CPU interface...).
So rather than hardcoding the address, we have something more flexible.
Ok, I will fix that in v2.
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
We still have plenty of space in the guest memory map. So the former is probably going to be fine for now.
Quoted 3 lines
Then I get paddr of the scmi channel for this domain and use
XEN_DOMCTL_memory_mappingto map scmi channel address to gfn.Quoted 1 line
Hope I wass able to answer your question.
What you provided me is how the guest OS will locate the shared memory. This still doesn't tell me which memory attribute will be used to map the page in Stage-1 (guest page-tables).
To find that out, you want to look at the driver and how the mapping is done. The Linux driver (
drivers/firmware/arm_scmi) is usingdevm_ioremap()(seesmc_chan_setup()).Under the hood, the function
devm_ioremap()is usingPROT_DEVICE_nGnRE(arm64) which is one of the most restrictive memory attribute.This means the firmware should be able to deal with the most restrictive attribute and therefore using
XEN_DOMCTL_memory_mappingto map the shared page in stage-2 should be fine.
Quoted 5 lines
Quoted 2 lines
I'm using vmap call to map channel memory (see
smc_create_channel()). vmap call setsPAGE_HYPERVISORflag which setsMT_NORMAL(0x7) flag.You want to use
ioremap().
I've used ioremap originally, but changed it to vmap because ioremap doesn't support memcpy.
What if I use __vmap with MT_DEVICE_nGnRE flag?
Quoted 9 lines
Quoted 4 lines
Considering that protocol is synchronous and only one agent per channel is expected - this works fine for now.
But I agree that the same memory attributes should be used in xen and kernel. I fill fix that in v2.I am a bit confused. Are you mapping the full shared memory area in Xen? If yes, why do you need to map the memory that is going to be shared with a domain?
Xen should have an access to all agent channels because it should send SCMI_BASE_DISCOVER_AGENT to each channel and receive agent_id during scmi_probe call.
Best regards,
Oleksii
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Hi,
Quoted 61 lines · Oleksii Moisieiev
Quoted 38 lines · Julien Grall
Quoted 1 line · Oleksii Moisieiev
Hi Julien,
Hi,
Quoted 31 lines · Julien Grall
Quoted 29 lines
Hi,
Quoted 25 lines · Oleksii Moisieiev
Quoted 5 lines · Julien Grall
Quoted 3 lines · Oleksii Moisieiev
Quoted 1 line
2) What are the expected memory attribute for the regions?
xen uses
iommu_permit_accessto pass agent page to the guest. So guest can access the page directly.Quoted 9 lines
I think you misunderstood my comment. Memory can be mapped with various type (e.g. Device, Memory) and attribute (cacheable, non-cacheable...). What will the firmware expect? What will the guest OS usually?
The reason I am asking is the attributes have to matched to avoid any coherency issues. At the moment, if you use
XEN_DOMCTL_memory_mapping, Xen will configure the stage-2 to use Device nGnRnE. As the result, the result memory access will be Device nGnRnE which is very strict.Let me share with you the configuration example:
scmi expects memory to be configured in the device-tree:cpu_scp_shm: scp-shmem@0xXXXXXXX { compatible = "arm,scmi-shmem"; reg = <0x0 0xXXXXXX 0x0 0x1000>; };where XXXXXX address I allocate in
alloc_magic_pagesfunction.Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
The goal of
alloc_magic_pages()is to allocate RAM. However, what you want is a guest physical address and then map a part of the shared page.Do you mean that I can't use
alloc_magic_pagesto allocate shared memory region for SCMI?Correct.
alloc_magic_pages()will allocate a RAM page and then assign to the guest. From your description, this is not what you want because you will callXEN_DOMCTL_memory_mapping(and therefore replace the mapping).Ok thanks, I will refactor this part in v2.
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
I can see two options here:
1) Hardcode the SCMI region in the memory map
2) Create a new region in the memory map that can be used for reserving
memory for mapping.Could you please explain what do you mean under the "new region in the memory map"?
Quoted 7 lines
Quoted 5 lines
I mean reserving some guest physical address that could be used for map host physical address (e.g. SCMI region, GIC CPU interface...).
So rather than hardcoding the address, we have something more flexible.
Ok, I will fix that in v2.
Just for avoidance of doubt. I was clarify option 2 and not requesting to implement. That said, if you want to implement option 2 I would be happy to review it.
Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 18 lines
We still have plenty of space in the guest memory map. So the former is probably going to be fine for now.
Quoted 3 lines
Then I get paddr of the scmi channel for this domain and use
XEN_DOMCTL_memory_mappingto map scmi channel address to gfn.Quoted 1 line
Hope I wass able to answer your question.
What you provided me is how the guest OS will locate the shared memory. This still doesn't tell me which memory attribute will be used to map the page in Stage-1 (guest page-tables).
To find that out, you want to look at the driver and how the mapping is done. The Linux driver (
drivers/firmware/arm_scmi) is usingdevm_ioremap()(seesmc_chan_setup()).Quoted 7 lines
Under the hood, the function
devm_ioremap()is usingPROT_DEVICE_nGnRE(arm64) which is one of the most restrictive memory attribute.This means the firmware should be able to deal with the most restrictive attribute and therefore using
XEN_DOMCTL_memory_mappingto map the shared page in stage-2 should be fine.I'm using vmap call to map channel memory (see
smc_create_channel()). vmap call setsPAGE_HYPERVISORflag which setsMT_NORMAL(0x7) flag.
Quoted 6 lines
Quoted 2 lines
You want to use
ioremap().I've used ioremap originally, but changed it to vmap because ioremap doesn't support memcpy.
What if I use__vmapwithMT_DEVICE_nGnREflag?
That's not going to help. Our implementation of memcpy() is using unaligned access (which is forbidden on Device memory).
You will need something similar to memcpy_toio() in Linux. I don't think we have one today in Xen, so I would suggest to import the implementation from Linux.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Considering that protocol is synchronous and only one agent per channel is expected - this works fine for now.
But I agree that the same memory attributes should be used in xen and kernel. I fill fix that in v2.
Quoted 8 lines
Quoted 4 lines
I am a bit confused. Are you mapping the full shared memory area in Xen? If yes, why do you need to map the memory that is going to be shared with a domain?
Xen should have an access to all agent channels because it should send
SCMI_BASE_DISCOVER_AGENTto each channel and receiveagent_idduringscmi_probecall.
Hmmm... Just to confirm, this will only happen during Xen boot? IOW, Xen will never write to the channel when a domain is running?
If yes, then I think it would be best to unmap the channel once they are used. This would prevent all sort of issues (e.g. Xen mistakenly written in them).
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Hi Julien,
Quoted 67 lines · Julien Grall
Hi,
Quoted 64 lines · Oleksii Moisieiev
Quoted 38 lines · Julien Grall
Quoted 1 line · Oleksii Moisieiev
Hi Julien,
Hi,
Quoted 31 lines · Julien Grall
Quoted 29 lines
Hi,
Quoted 25 lines · Oleksii Moisieiev
Quoted 5 lines · Julien Grall
Quoted 3 lines · Oleksii Moisieiev
Quoted 1 line
2) What are the expected memory attribute for the regions?
xen uses
iommu_permit_accessto pass agent page to the guest. So guest can access the page directly.Quoted 9 lines
I think you misunderstood my comment. Memory can be mapped with various type (e.g. Device, Memory) and attribute (cacheable, non-cacheable...). What will the firmware expect? What will the guest OS usually?
The reason I am asking is the attributes have to matched to avoid any coherency issues. At the moment, if you use
XEN_DOMCTL_memory_mapping, Xen will configure the stage-2 to use Device nGnRnE. As the result, the result memory access will be Device nGnRnE which is very strict.Let me share with you the configuration example:
scmi expects memory to be configured in the device-tree:cpu_scp_shm: scp-shmem@0xXXXXXXX { compatible = "arm,scmi-shmem"; reg = <0x0 0xXXXXXX 0x0 0x1000>; };where XXXXXX address I allocate in
alloc_magic_pagesfunction.Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
The goal of
alloc_magic_pages()is to allocate RAM. However, what you want is a guest physical address and then map a part of the shared page.Do you mean that I can't use
alloc_magic_pagesto allocate shared memory region for SCMI?Correct.
alloc_magic_pages()will allocate a RAM page and then assign to the guest. From your description, this is not what you want because you will callXEN_DOMCTL_memory_mapping(and therefore replace the mapping).Ok thanks, I will refactor this part in v2.
Quoted 13 lines
Quoted 9 lines
Quoted 6 lines
I can see two options here:
1) Hardcode the SCMI region in the memory map
2) Create a new region in the memory map that can be used for reserving
memory for mapping.Could you please explain what do you mean under the "new region in the memory map"?
I mean reserving some guest physical address that could be used for map host physical address (e.g. SCMI region, GIC CPU interface...).
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
So rather than hardcoding the address, we have something more flexible.
Ok, I will fix that in v2.
Just for avoidance of doubt. I was clarify option 2 and not requesting to implement. That said, if you want to implement option 2 I would be happy to review it.
I think it's time for me to start working on v2. I think option 2 can be implemented. If not - I will look for an alternative way.
Quoted 36 lines
Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 18 lines
We still have plenty of space in the guest memory map. So the former is probably going to be fine for now.
Quoted 3 lines
Then I get paddr of the scmi channel for this domain and use
XEN_DOMCTL_memory_mappingto map scmi channel address to gfn.Quoted 1 line
Hope I wass able to answer your question.
What you provided me is how the guest OS will locate the shared memory. This still doesn't tell me which memory attribute will be used to map the page in Stage-1 (guest page-tables).
To find that out, you want to look at the driver and how the mapping is done. The Linux driver (
drivers/firmware/arm_scmi) is usingdevm_ioremap()(seesmc_chan_setup()).Quoted 7 lines
Under the hood, the function
devm_ioremap()is usingPROT_DEVICE_nGnRE(arm64) which is one of the most restrictive memory attribute.This means the firmware should be able to deal with the most restrictive attribute and therefore using
XEN_DOMCTL_memory_mappingto map the shared page in stage-2 should be fine.I'm using vmap call to map channel memory (see
smc_create_channel()). vmap call setsPAGE_HYPERVISORflag which setsMT_NORMAL(0x7) flag.Quoted 6 lines
Quoted 2 lines
You want to use
ioremap().I've used ioremap originally, but changed it to vmap because ioremap doesn't support memcpy.
What if I use__vmapwithMT_DEVICE_nGnREflag?
Quoted 7 lines
That's not going to help. Our implementation of
memcpy()is using unaligned access (which is forbidden on Device memory).You will need something similar to
memcpy_toio()in Linux. I don't think we have one today in Xen, so I would suggest to import the implementation from Linux.
Ok. Then I'll import memcpy_toio from Linux kernel.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Considering that protocol is synchronous and only one agent per channel is expected - this works fine for now.
But I agree that the same memory attributes should be used in xen and kernel. I fill fix that in v2.I am a bit confused. Are you mapping the full shared memory area in Xen? If yes, why do you need to map the memory that is going to be shared with a domain?
Quoted 7 lines
Quoted 3 lines
Xen should have an access to all agent channels because it should send
SCMI_BASE_DISCOVER_AGENTto each channel and receiveagent_idduringscmi_probecall.Hmmm... Just to confirm, this will only happen during Xen boot? IOW, Xen will never write to the channel when a domain is running?
Yes. Only during Xen boot.
Quoted 4 lines
If yes, then I think it would be best to unmap the channel once they are used. This would prevent all sort of issues (e.g. Xen mistakenly written in them).
That's a good advise. Thank you.
Best regards,
Oleksii.
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
In reply to Julien GrallHi Julien,
Quoted 67 lines · Julien Grall
Hi,
Quoted 64 lines · Oleksii Moisieiev
Quoted 38 lines · Julien Grall
Quoted 1 line · Oleksii Moisieiev
Hi Julien,
Hi,
Quoted 31 lines · Julien Grall
Quoted 29 lines
Hi,
Quoted 25 lines · Oleksii Moisieiev
Quoted 5 lines · Julien Grall
Quoted 3 lines · Oleksii Moisieiev
Quoted 1 line
2) What are the expected memory attribute for the regions?
xen uses
iommu_permit_accessto pass agent page to the guest. So guest can access the page directly.Quoted 9 lines
I think you misunderstood my comment. Memory can be mapped with various type (e.g. Device, Memory) and attribute (cacheable, non-cacheable...). What will the firmware expect? What will the guest OS usually?
The reason I am asking is the attributes have to matched to avoid any coherency issues. At the moment, if you use
XEN_DOMCTL_memory_mapping, Xen will configure the stage-2 to use Device nGnRnE. As the result, the result memory access will be Device nGnRnE which is very strict.Let me share with you the configuration example:
scmi expects memory to be configured in the device-tree:cpu_scp_shm: scp-shmem@0xXXXXXXX { compatible = "arm,scmi-shmem"; reg = <0x0 0xXXXXXX 0x0 0x1000>; };where XXXXXX address I allocate in
alloc_magic_pagesfunction.Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
The goal of
alloc_magic_pages()is to allocate RAM. However, what you want is a guest physical address and then map a part of the shared page.Do you mean that I can't use
alloc_magic_pagesto allocate shared memory region for SCMI?Correct.
alloc_magic_pages()will allocate a RAM page and then assign to the guest. From your description, this is not what you want because you will callXEN_DOMCTL_memory_mapping(and therefore replace the mapping).Ok thanks, I will refactor this part in v2.
Quoted 13 lines
Quoted 9 lines
Quoted 6 lines
I can see two options here:
1) Hardcode the SCMI region in the memory map
2) Create a new region in the memory map that can be used for reserving
memory for mapping.Could you please explain what do you mean under the "new region in the memory map"?
I mean reserving some guest physical address that could be used for map host physical address (e.g. SCMI region, GIC CPU interface...).
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
So rather than hardcoding the address, we have something more flexible.
Ok, I will fix that in v2.
Just for avoidance of doubt. I was clarify option 2 and not requesting to implement. That said, if you want to implement option 2 I would be happy to review it.
I'm thinking about the best way to reserve address for the domain. We have xen_pfn_t shared_info_pfn in struct xc_dom_image which is not used for Arm architecture. It can be set from shared_info_arm callback, defined in xg_dom_arm.c.
I can use shared_info to store address of the SCMI and then use map_sci_page to call XEN_DOMCTL_memory_mapping.
This will allow me to reuse existing functionality and do not allocate extra RAM.
What do you think about that?
--
Best regards,
Oleksii.
Quoted 69 lines
Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 18 lines
We still have plenty of space in the guest memory map. So the former is probably going to be fine for now.
Quoted 3 lines
Then I get paddr of the scmi channel for this domain and use
XEN_DOMCTL_memory_mappingto map scmi channel address to gfn.Quoted 1 line
Hope I wass able to answer your question.
What you provided me is how the guest OS will locate the shared memory. This still doesn't tell me which memory attribute will be used to map the page in Stage-1 (guest page-tables).
To find that out, you want to look at the driver and how the mapping is done. The Linux driver (
drivers/firmware/arm_scmi) is usingdevm_ioremap()(seesmc_chan_setup()).Quoted 7 lines
Under the hood, the function
devm_ioremap()is usingPROT_DEVICE_nGnRE(arm64) which is one of the most restrictive memory attribute.This means the firmware should be able to deal with the most restrictive attribute and therefore using
XEN_DOMCTL_memory_mappingto map the shared page in stage-2 should be fine.I'm using vmap call to map channel memory (see
smc_create_channel()). vmap call setsPAGE_HYPERVISORflag which setsMT_NORMAL(0x7) flag.Quoted 6 lines
Quoted 2 lines
You want to use
ioremap().I've used ioremap originally, but changed it to vmap because ioremap doesn't support memcpy.
What if I use__vmapwithMT_DEVICE_nGnREflag?That's not going to help. Our implementation of
memcpy()is using unaligned access (which is forbidden on Device memory).You will need something similar to
memcpy_toio()in Linux. I don't think we have one today in Xen, so I would suggest to import the implementation from Linux.Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Considering that protocol is synchronous and only one agent per channel is expected - this works fine for now.
But I agree that the same memory attributes should be used in xen and kernel. I fill fix that in v2.Quoted 8 lines
Quoted 4 lines
I am a bit confused. Are you mapping the full shared memory area in Xen? If yes, why do you need to map the memory that is going to be shared with a domain?
Xen should have an access to all agent channels because it should send
SCMI_BASE_DISCOVER_AGENTto each channel and receiveagent_idduringscmi_probecall.Hmmm... Just to confirm, this will only happen during Xen boot? IOW, Xen will never write to the channel when a domain is running?
If yes, then I think it would be best to unmap the channel once they are used. This would prevent all sort of issues (e.g. Xen mistakenly written in them).
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Quoted 78 lines · Oleksii Moisieiev
Quoted 60 lines · Julien Grall
Quoted 59 lines · Oleksii Moisieiev
Quoted 33 lines · Julien Grall
Quoted 32 lines · Oleksii Moisieiev
Hi Julien,
Quoted 29 lines · Julien Grall
Hi,
Quoted 25 lines · Oleksii Moisieiev
Quoted 9 lines · Julien Grall
Quoted 3 lines · Oleksii Moisieiev
Quoted 1 line
2) What are the expected memory attribute for the regions?
xen uses
iommu_permit_accessto pass agent page to the guest. So guest can access the page directly.I think you misunderstood my comment. Memory can be mapped with various type (e.g. Device, Memory) and attribute (cacheable, non-cacheable...). What will the firmware expect? What will the guest OS usually?
Quoted 5 lines
The reason I am asking is the attributes have to matched to avoid any coherency issues. At the moment, if you use
XEN_DOMCTL_memory_mapping, Xen will configure the stage-2 to use Device nGnRnE. As the result, the result memory access will be Device nGnRnE which is very strict.
:wLet me share with you the configuration example:
scmi expects memory to be configured in the device-tree:cpu_scp_shm: scp-shmem@0xXXXXXXX { compatible = "arm,scmi-shmem"; reg = <0x0 0xXXXXXX 0x0 0x1000>; };where XXXXXX address I allocate in
alloc_magic_pagesfunction.Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
The goal of
alloc_magic_pages()is to allocate RAM. However, what you want is a guest physical address and then map a part of the shared page.Do you mean that I can't use
alloc_magic_pagesto allocate shared memory region for SCMI?Correct.
alloc_magic_pages()will allocate a RAM page and then assign to the guest. From your description, this is not what you want because you will callXEN_DOMCTL_memory_mapping(and therefore replace the mapping).Ok thanks, I will refactor this part in v2.
Quoted 13 lines
Quoted 9 lines
Quoted 6 lines
I can see two options here:
1) Hardcode the SCMI region in the memory map
2) Create a new region in the memory map that can be used for reserving
memory for mapping.Could you please explain what do you mean under the "new region in the memory map"?
I mean reserving some guest physical address that could be used for map host physical address (e.g. SCMI region, GIC CPU interface...).
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
So rather than hardcoding the address, we have something more flexible.
Ok, I will fix that in v2.
Just for avoidance of doubt. I was clarify option 2 and not requesting to implement. That said, if you want to implement option 2 I would be happy to review it.
I'm thinking about the best way to reserve address for the domain. We have
xen_pfn_tshared_info_pfnin structxc_dom_imagewhich is not used for Arm architecture. It can be set fromshared_info_armcallback, defined inxg_dom_arm.c.
I can useshared_infoto store address of the SCMI and then usemap_sci_pageto callXEN_DOMCTL_memory_mapping.
Quoted 4 lines
This will allow me to reuse existing functionality and do not allocate extra RAM.
What do you think about that?
I cannot speak for Julien but I think he meant something else (Julien please correct me if I am wrong.) Exposing addresses via device tree is not a problem.
Normally we pick a fixed address for guest resources, for instance GUEST_GICD_BASE, see xen/include/public/arch-arm.h. We could do that for SCMI as well and it is basically approach 1).
However, it is a bit inflexible and could cause issues with things like direct-map (https://marc.info/?l=xen-devel&m=163997768108997). A more flexible way would be for the SCMI guest address to be dynamically generated somehow.
I am not sure how Julien envisioned the address to be generated exactly.
Thanks to Oleksandr's work we have a way to find large regions of "free" address space. It is currently used for grant-table mappings. Maybe we could use a subset of it for SCMI? It might be best to wait for Julien's answer as he might have a better idea.
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Quoted 97 lines · Stefano Stabellini
Quoted 78 lines · Oleksii Moisieiev
Quoted 60 lines · Julien Grall
Quoted 59 lines · Oleksii Moisieiev
Quoted 33 lines · Julien Grall
Quoted 32 lines · Oleksii Moisieiev
Hi Julien,
Quoted 29 lines · Julien Grall
Hi,
Quoted 25 lines · Oleksii Moisieiev
Quoted 9 lines · Julien Grall
Quoted 3 lines · Oleksii Moisieiev
Quoted 1 line
2) What are the expected memory attribute for the regions?
xen uses
iommu_permit_accessto pass agent page to the guest. So guest can access the page directly.I think you misunderstood my comment. Memory can be mapped with various type (e.g. Device, Memory) and attribute (cacheable, non-cacheable...). What will the firmware expect? What will the guest OS usually?
Quoted 5 lines
The reason I am asking is the attributes have to matched to avoid any coherency issues. At the moment, if you use
XEN_DOMCTL_memory_mapping, Xen will configure the stage-2 to use Device nGnRnE. As the result, the result memory access will be Device nGnRnE which is very strict.
:wLet me share with you the configuration example:
scmi expects memory to be configured in the device-tree:cpu_scp_shm: scp-shmem@0xXXXXXXX { compatible = "arm,scmi-shmem"; reg = <0x0 0xXXXXXX 0x0 0x1000>; };where XXXXXX address I allocate in
alloc_magic_pagesfunction.Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
The goal of
alloc_magic_pages()is to allocate RAM. However, what you want is a guest physical address and then map a part of the shared page.Do you mean that I can't use
alloc_magic_pagesto allocate shared memory region for SCMI?Correct.
alloc_magic_pages()will allocate a RAM page and then assign to the guest. From your description, this is not what you want because you will callXEN_DOMCTL_memory_mapping(and therefore replace the mapping).Ok thanks, I will refactor this part in v2.
Quoted 13 lines
Quoted 9 lines
Quoted 6 lines
I can see two options here:
1) Hardcode the SCMI region in the memory map
2) Create a new region in the memory map that can be used for reserving
memory for mapping.Could you please explain what do you mean under the "new region in the memory map"?
I mean reserving some guest physical address that could be used for map host physical address (e.g. SCMI region, GIC CPU interface...).
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
So rather than hardcoding the address, we have something more flexible.
Ok, I will fix that in v2.
Just for avoidance of doubt. I was clarify option 2 and not requesting to implement. That said, if you want to implement option 2 I would be happy to review it.
I'm thinking about the best way to reserve address for the domain. We have
xen_pfn_tshared_info_pfnin structxc_dom_imagewhich is not used for Arm architecture. It can be set fromshared_info_armcallback, defined inxg_dom_arm.c.
I can useshared_infoto store address of the SCMI and then usemap_sci_pageto callXEN_DOMCTL_memory_mapping.Quoted 4 lines
This will allow me to reuse existing functionality and do not allocate extra RAM.
What do you think about that?
I cannot speak for Julien but I think he meant something else (Julien please correct me if I am wrong.) Exposing addresses via device tree is not a problem.
Normally we pick a fixed address for guest resources, for instance
GUEST_GICD_BASE, seexen/include/public/arch-arm.h. We could do that for SCMI as well and it is basically approach 1).However, it is a bit inflexible and could cause issues with things like
direct-map (https://urldefense.com/v3/__https://marc.info/?l=xen-devel&m=163997768108997__;!!GF_29dbcQIUBPA!kvNsu9pjqIwZ42N2q6aSQhTT_zA3OCEDkr7DwmAiuldEMwj2UiFReaPI8XlxsG-HOZ6v$ [marc[.]info]). A more flexible way would be for the SCMI guest address to be dynamically
generated somehow.
Quoted 6 lines
I am not sure how Julien envisioned the address to be generated exactly.
Thanks to Oleksandr's work we have a way to find large regions of "free" address space. It is currently used for grant-table mappings. Maybe we could use a subset of it for SCMI? It might be best to wait for Julien's answer as he might have a better idea.
Thank you for the answer.
I think it will be best to reserve some space and generate address for SMCI. Hope Julien will advise how it can be done.
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
In reply to Oleksii MoisieievQuoted 114 lines · Oleksii Moisieiev
This is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG.
The following features are implemented:
- request SCMI channels from ATF and pass channels to Domains;
- set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI;
- redirect scmi messages from Domains to ATF.Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 5 files changed, 809 insertions(+) create mode 100644 xen/arch/arm/sci/Kconfig create mode 100644 xen/arch/arm/sci/scmi_smc.cxen/arch/arm/Kconfig +2
-0@@ -114,6 +114,8 @@ config SCI support. It allows guests to control system resourcess via one of SCI mediators implemented in XEN. +source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/sci/Kconfig new file +10
-0@@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on SCI + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication.xen/arch/arm/sci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.oxen/arch/arm/sci/scmi_smc.c new file +49
-0@@ -0,0 +1,795 @@ +/* +* xen/arch/arm/sci/scmi_smc.c +* +* SCMI mediator driver, using SCP as transport. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/sci/sci.h> +#include <asm/smccc.h> +#include <asm/io.h> +#include <xen/bitops.h> +#include <xen/config.h> +#include <xen/sched.h> +#include <xen/device_tree.h> +#include <xen/iocap.h> +#include <xen/init.h> +#include <xen/err.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/string.h> +#include <xen/time.h> +#include <xen/vmap.h> + +#define SCMI_BASE_PROTOCOL 0x10 +#define SCMI_BASE_PROTOCOL_ATTIBUTES 0x1 +#define SCMI_BASE_SET_DEVICE_PERMISSIONS 0x9 +#define SCMI_BASE_RESET_AGENT_CONFIGURATION 0xB +#define SCMI_BASE_DISCOVER_AGENT 0x7 + +/* SCMI return codes. See section 4.1.4 of SCMI spec (DEN0056C) */ +#define SCMI_SUCCESS 0 +#define SCMI_NOT_SUPPORTED (-1) +#define SCMI_INVALID_PARAMETERS (-2) +#define SCMI_DENIED (-3) +#define SCMI_NOT_FOUND (-4) +#define SCMI_OUT_OF_RANGE (-5)
xen/arch/arm/sci/scmi_smc.c line 59
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+#define SCMI_BUSY (-6) +#define SCMI_COMMS_ERROR (-7) +#define SCMI_GENERIC_ERROR (-8) +#define SCMI_HARDWARE_ERROR (-9) +#define SCMI_PROTOCOL_ERROR (-10) + +#define DT_MATCH_SCMI_SMC DT_MATCH_COMPATIBLE("arm,scmi-smc") + +#define SCMI_SMC_ID "arm,smc-id" +#define SCMI_SHARED_MEMORY "linux,scmi_mem"
I could find the following SCMI binding in Linux, which describes the arm,scmi-smc compatible and the arm,smc-id property:
Documentation/devicetree/bindings/firmware/arm,scmi.yaml
However, linux,scmi_mem is not described. Aren't you supposed to read the "shmem" property instead? And the compatible string used for this seems to be "arm,scmi-shmem".
Quoted 85 lines
xen/arch/arm/sci/scmi_smc.c new file +85
-0+#define SCMI_SHMEM "shmem" + +#define HYP_CHANNEL 0x0 + +#define HDR_ID GENMASK(7,0) +#define HDR_TYPE GENMASK(9, 8) +#define HDR_PROTO GENMASK(17, 10) + +/* SCMI protocol, refer to section 4.2.2.2 (DEN0056C) */ +#define MSG_N_AGENTS_MASK GENMASK(15, 8) + +#define FIELD_GET (_mask, _reg)\ + ((typeof(_mask))(((_reg) & (_mask)) >> (ffs64(_mask) - 1))) +#define FIELD_PREP (_mask, _val)\ + (((typeof(_mask))(_val) << (ffs64(_mask) - 1)) & (_mask)) + +typedef struct scmi_msg_header { +uint8_t id; +uint8_t type; +uint8_t protocol; +}scmi_msg_header_t ; + +typedef struct scmi_perms_tx { +uint32_t agent_id; +uint32_t device_id; +uint32_t flags; +}scmi_perms_tx_t ; + +#define SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE BIT(0, UL) +#define SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR BIT(1, UL) + +#define SCMI_ALLOW_ACCESS BIT(0, UL) + +struct scmi_shared_mem { +uint32_t reserved; +uint32_t channel_status; +uint32_t reserved1[2 ]; +uint32_t flags; +uint32_t length; +uint32_t msg_header; +uint8_t msg_payload[]; +}; + +struct scmi_channel { +int chan_id; +int agent_id; +uint32_t func_id; +int domain_id; +uint64_t paddr; +struct scmi_shared_mem *shmem; +spinlock_t lock; +struct list_head list; +}; + +struct scmi_data { +struct list_head channel_list; +spinlock_t channel_list_lock; +bool initialized; +u64 shmem_addr, shmem_size; +}; + +static struct scmi_data scmi_data; + +/* +* pack_scmi_header() - packs and returns 32-bit header +* +* @hdr: pointer to header containing all the information on message id, +* protocol id and type id. +* +* Return: 32-bit packed message header to be sent to the platform. +*/ +static inline uint32_t pack_scmi_header (scmi_msg_header_t *hdr) +{ +return FIELD_PREP (HDR_ID , hdr->id) | +FIELD_PREP (HDR_TYPE , hdr->type) | +FIELD_PREP (HDR_PROTO , hdr->protocol); +} + +/* +* unpack_scmi_header() - unpacks and records message and protocol id +* +* @msg_hdr: 32-bit packed message header sent from the platform +* @hdr: pointer to header to fetch message and protocol id. +*/ +static inline void unpack_scmi_header (uint32_t msg_hdr,scmi_msg_header_t *hdr)
xen/arch/arm/sci/scmi_smc.c line 154
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+{ + hdr->id =FIELD_GET (HDR_ID , msg_hdr); + hdr->type =FIELD_GET (HDR_TYPE , msg_hdr); + hdr->protocol =FIELD_GET (HDR_PROTO , msg_hdr); +} + +static inline int channel_is_free (struct scmi_channel *chan_info) +{ +return ( chan_info->shmem->channel_status + &SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE ) ?0 : -EBUSY ;
Does this need a memory barrier? Or not, because the other end always runs on the same CPU at a different execution level so the channel_status would be always guaranteed to be read as updated?
Quoted 17 lines
xen/arch/arm/sci/scmi_smc.c new file +17
-0+} + +static int send_smc_message (struct scmi_channel *chan_info, +scmi_msg_header_t *hdr,void *data,int len) +{ +struct arm_smccc_res resp; +int ret; + +printk (XENLOG_DEBUG "scmi: status =%d len=%d\n" , + chan_info->shmem->channel_status, len); +printk (XENLOG_DEBUG "scmi: header id = %d type = %d, proto = %d\n" , + hdr->id, hdr->type, hdr->protocol); + + ret =channel_is_free (chan_info); +if (IS_ERR_VALUE (ret) ) +return ret; +
xen/arch/arm/sci/scmi_smc.c line 181
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+ chan_info->shmem->channel_status =0x0 ; +/* Writing 0x0 right now, but SCMI_SHMEM_FLAG_INTR_ENABLED can be set */ + chan_info->shmem->flags =0x0 ; + chan_info->shmem->length =sizeof (chan_info->shmem->msg_header) + len; + chan_info->shmem->msg_header =pack_scmi_header (hdr); + +printk (XENLOG_DEBUG "scmi: Writing to shmem address %p\n" , + chan_info->shmem); +if ( len >0 && data ) +memcpy ((void *)(chan_info->shmem->msg_payload), data, len);
Again, here we don't need a barrier because it is implicit in the SMC?
Don't we need to check that "len" fits in the shared memory?
xen/arch/arm/sci/scmi_smc.c line 189
Quoted 7 lines
xen/arch/arm/sci/scmi_smc.c new file +7
-0+arm_smccc_smc (chan_info->func_id,0 ,0 ,0 ,0 ,0 ,0 , chan_info->chan_id, + &resp); + +printk (XENLOG_DEBUG "scmi: scmccc_smc response %d\n" , (int )(resp.a0)); + +if ( resp.a0 ) +return -EOPNOTSUPP ;
Why is that?
Quoted 38 lines
xen/arch/arm/sci/scmi_smc.c new file +38
-0+return 0 ; +} + +static int check_scmi_status (int scmi_status) +{ +if ( scmi_status ==SCMI_SUCCESS ) +return 0 ; + +printk (XENLOG_DEBUG "scmi: Error received: %d\n" , scmi_status); + +switch ( scmi_status ) + { +case SCMI_NOT_SUPPORTED : +return -EOPNOTSUPP ; +case SCMI_INVALID_PARAMETERS : +return -EINVAL ; +case SCMI_DENIED : +return -EACCES ; +case SCMI_NOT_FOUND : +return -ENOENT ; +case SCMI_OUT_OF_RANGE : +return -ERANGE ; +case SCMI_BUSY : +return -EBUSY ; +case SCMI_COMMS_ERROR : +return -ENOTCONN ; +case SCMI_GENERIC_ERROR : +return -EIO ; +case SCMI_HARDWARE_ERROR : +return -ENXIO ; +case SCMI_PROTOCOL_ERROR : +return -EBADMSG ; + } + +return -EINVAL ; +} + +static int get_smc_response(struct scmi_channel *chan_info,
xen/arch/arm/sci/scmi_smc.c line 238
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+ scmi_msg_header_t *hdr, void *data, int len) +{ +int recv_len; +int ret; + +printk (XENLOG_DEBUG "scmi: get smc responce msgid %d\n" , hdr->id); + + ret =channel_is_free (chan_info); +if (IS_ERR_VALUE (ret) ) +return ret;
I am not familiar with the spec (do you have a link?) but is it expected that the channel is "free" when actually we want to read a message on the channel?
Quoted 45 lines
xen/arch/arm/sci/scmi_smc.c new file +45
-0+ recv_len = chan_info->shmem->length -sizeof (chan_info->shmem->msg_header); + +if ( recv_len <0 ) + { +printk (XENLOG_ERR +"scmi: Wrong size of smc message. Data may be invalid\n" ); +return -EINVAL ; + } + +if ( recv_len > len ) + { +printk (XENLOG_ERR +"scmi: Not enough buffer for message %d, expecting %d\n" , + recv_len, len); +return -EINVAL ; + } + +unpack_scmi_header (chan_info->shmem->msg_header, hdr); + +if ( recv_len >0 ) + { +memcpy (data, chan_info->shmem->msg_payload, recv_len); + } + +return 0 ; +} + +static int do_smc_xfer (struct scmi_channel *channel,scmi_msg_header_t *hdr,void *tx_data,int tx_size, +void *rx_data,int rx_size) +{ +int ret =0 ; + +if ( !hdr ) +return -EINVAL ; + +spin_lock (&channel->lock); + + ret =send_smc_message (channel, hdr, tx_data, tx_size); +if ( ret ) + goto clean; + + ret =get_smc_response (channel, hdr, rx_data, rx_size); +clean: +spin_unlock (&channel->lock); +
xen/arch/arm/sci/scmi_smc.c line 294
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+return ret; +} + +static struct scmi_channel *get_channel_by_id (uint8_t chan_id) +{ +struct scmi_channel *curr; +bool found = false; + +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry (curr, &scmi_data.channel_list, list)
please use parenthesis around the inner if (also in other places)
Quoted 4 lines
xen/arch/arm/sci/scmi_smc.c new file +4
-0+if ( curr->chan_id == chan_id ) + { + found = true; +break ;
xen/arch/arm/sci/scmi_smc.c line 308
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+ } + +spin_unlock (&scmi_data.channel_list_lock); +if ( found ) +return curr; + +return NULL ; +} + +static struct scmi_channel *get_channel_by_domain (uint8_t domain_id)
Use domid_t for domain ids.
Also, wouldn't it be better to implement it as:
static inline struct scmi_channel *get_channel_by_domain(struct domain *d) {
return d->arch.sci
}Quoted 20 lines
xen/arch/arm/sci/scmi_smc.c new file +20
-0+{ +struct scmi_channel *curr; +bool found = false; + +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry (curr, &scmi_data.channel_list, list) +if ( curr->domain_id == domain_id ) + { + found = true; +break ; + } + +spin_unlock (&scmi_data.channel_list_lock); +if ( found ) +return curr; + +return NULL ; +} + +static struct scmi_channel *aquire_scmi_channel (int domain_id)
xen/arch/arm/sci/scmi_smc.c line 338
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+{ +struct scmi_channel *curr; +bool found = false; + +ASSERT (domain_id !=DOMID_INVALID && domain_id >=0 ); + +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry (curr, &scmi_data.channel_list, list) +if ( (curr->domain_id ==DOMID_INVALID ) + && (curr->chan_id !=HYP_CHANNEL ) )
If you use DOMID_XEN for HYP_CHANNEL, then this check becomes more intuitive
Quoted 7 lines
xen/arch/arm/sci/scmi_smc.c new file +7
-0+ { + curr->domain_id = domain_id; + found = true; +break ; + } + +spin_unlock (&scmi_data.channel_list_lock);
xen/arch/arm/sci/scmi_smc.c line 355
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+if ( found ) +return curr; + +return NULL ; +} + +static void relinquish_scmi_channel (struct scmi_channel *channel) +{ +spin_lock (&scmi_data.channel_list_lock); +ASSERT (channel !=NULL );
the ASSERT could be before the spin_lock
Quoted 11 lines
xen/arch/arm/sci/scmi_smc.c new file +11
-0+ channel->domain_id =DOMID_INVALID ; +spin_unlock (&scmi_data.channel_list_lock); +} + +static struct scmi_channel *smc_create_channel (uint8_t chan_id, +uint32_t func_id,uint64_t addr) +{ +struct scmi_channel *channel; +mfn_t mfn; + + channel =get_channel_by_id (chan_id);
xen/arch/arm/sci/scmi_smc.c line 376
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+if ( channel ) +return ERR_PTR (EEXIST ); + + channel = xmalloc(struct scmi_channel); +if ( !channel ) +return ERR_PTR (ENOMEM ); + + channel->chan_id = chan_id; + channel->func_id = func_id; + channel->domain_id =DOMID_INVALID ;
I take you are using DOMID_INVALID to mark a channel used by Xen itself? If so, then DOMID_XEN would be more appropriate.
xen/arch/arm/sci/scmi_smc.c line 378
Quoted 2 lines
xen/arch/arm/sci/scmi_smc.c new file +2
-0+ mfn =maddr_to_mfn (addr); + channel->shmem =vmap (&mfn,1 );
One thing to be careful is the mapping attributes, for a couple of reasons. As you might be aware, the ARM architecture forbids mismatching attributes for mapping memory in different places in the system. So the attributes that we use here must be the same used by the firmware (and/or the guest.)
The second reason to be careful is that in the bindings example Documentation/devicetree/bindings/firmware/arm,scmi.yaml the shared memory is "mmio-sram", which is special. It is not supposed to be normal memory, but it is OK to map it cacheable. Still, it might be more appropriate to use ioremap_cache.
Quoted 28 lines
xen/arch/arm/sci/scmi_smc.c new file +28
-0+if ( !channel->shmem ) + { +xfree (channel); +return ERR_PTR (ENOMEM ); + } + +printk (XENLOG_DEBUG "scmi: Got shmem after vmap %p\n" , channel->shmem); + channel->paddr = addr; + channel->shmem->channel_status =SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE ; +spin_lock_init (&channel->lock); +spin_lock (&scmi_data.channel_list_lock); +list_add (&channel->list, &scmi_data.channel_list); +spin_unlock (&scmi_data.channel_list_lock); +return channel; +} + +static int map_memory_to_domain (struct domain *d,uint64_t addr,uint64_t len) +{ +return iomem_permit_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +} + +static int unmap_memory_from_domain (struct domain *d,uint64_t addr, +uint64_t len) +{ +return iomem_deny_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +}
xen/arch/arm/sci/scmi_smc.c line 416
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+ +static int dt_update_domain_range (struct domain *d,uint64_t addr, +uint64_t size) +{ +struct dt_device_node *shmem_node; +__be32 *hw_reg; +const struct dt_property *pp; +uint32_t len; + + shmem_node =dt_find_compatible_node (NULL ,NULL ,"arm,scmi-shmem" );
Here we are using "arm,scmi-shmem" while below we are checking for "linux,scmi_mem". What's the difference?
Also, this function is looking for "arm,scmi-shmem" in dt_host and replaces its value. For dom0less domUs we'll probably need a make_scmi_node function to create the node from scratch like for instance xen/arch/arm/domain_build.c:make_gic_domU_node.
I wonder if we had such a function whether it wouldn't be better to also use it for dom0 (and blacklist the physical "arm,scmi-shmem" in handle_node so that dom0 doesn't get the real shared memory information by accident).
Quoted 36 lines
xen/arch/arm/sci/scmi_smc.c new file +36
-0+ +if ( !shmem_node ) + { +printk (XENLOG_ERR "scmi: Unable to find %s node in DT\n" ,SCMI_SHMEM ); +return -EINVAL ; + } + + pp =dt_find_property (shmem_node,"reg" , &len); +if ( !pp ) + { +printk (XENLOG_ERR "scmi: Unable to find regs entry in shmem node\n" ); +return -ENOENT ; + } + + hw_reg = pp->value; +dt_set_range (&hw_reg, shmem_node, addr, size); + +return 0 ; +} + +static void free_channel_list (void ) +{ +struct scmi_channel *curr, *_curr; + +spin_lock (&scmi_data.channel_list_lock); + list_for_each_entry_safe (curr, _curr, &scmi_data.channel_list, list) + { +vunmap (curr->shmem); +list_del (&curr->list); +xfree (curr); + } + +spin_unlock (&scmi_data.channel_list_lock); +} + +static __init bool scmi_probe (struct dt_device_node *scmi_node)
xen/arch/arm/sci/scmi_smc.c line 462
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+{ +struct dt_device_node *shmem_node; +int ret, i; +struct scmi_channel *channel, *agent_channel; +int n_agents; +scmi_msg_header_t hdr; +struct rx_t { +int32_t status; +uint32_t attributes; + } rx;
Should rx be defined at the top together with scmi_perms_tx_t and others?
Quoted 4 lines
xen/arch/arm/sci/scmi_smc.c new file +4
-0+uint32_t func_id; + +ASSERT (scmi_node !=NULL ); +
xen/arch/arm/sci/scmi_smc.c line 477
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+INIT_LIST_HEAD (&scmi_data.channel_list); +spin_lock_init (&scmi_data.channel_list_lock); + +if ( !dt_property_read_u32 (scmi_node,SCMI_SMC_ID , &func_id) ) + { +printk (XENLOG_ERR "scmi: Unable to read smc-id from DT\n" ); +return false; + } + + shmem_node =dt_find_node_by_name (NULL ,SCMI_SHARED_MEMORY );
From the spec, it looks like you should be getting the shared memory area from the phandle list "shmem".
Quoted 27 lines
xen/arch/arm/sci/scmi_smc.c new file +27
-0+if (IS_ERR_OR_NULL (shmem_node) ) + { +printk (XENLOG_ERR +"scmi: Device tree error, can't parse shmem phandle %ld\n" , +PTR_ERR (shmem_node)); +return false; + } + + ret =dt_device_get_address (shmem_node,0 , &scmi_data.shmem_addr, + &scmi_data.shmem_size); +if (IS_ERR_VALUE (ret) ) +return false; + + channel =smc_create_channel (HYP_CHANNEL , func_id, scmi_data.shmem_addr); +if (IS_ERR (channel) ) +return false; + + hdr.id =SCMI_BASE_PROTOCOL_ATTIBUTES ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + ret =do_smc_xfer (channel, &hdr,NULL ,0 , &rx,sizeof (rx)); +if ( ret ) + goto clean; + + ret =check_scmi_status (rx.status); +if ( ret )
xen/arch/arm/sci/scmi_smc.c line 514
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+ goto clean; + + n_agents =FIELD_GET (MSG_N_AGENTS_MASK , rx.attributes); +printk (XENLOG_DEBUG "scmi: Got agent count %d\n" , n_agents); + + n_agents = (n_agents > scmi_data.shmem_size /PAGE_SIZE ) ? + scmi_data.shmem_size /PAGE_SIZE : n_agents; + +for ( i =1 ; i < n_agents; i++ ) + {
Given that HYP_CHANNEL is actually zero, it looks like we could do everything here in this loop but starting from i=0?
Quoted 66 lines
xen/arch/arm/sci/scmi_smc.c new file +66
-0+uint32_t tx_agent_id =0xFFFFFFFF ; +struct { +int32_t status; +uint32_t agent_id; +char name[16 ]; + } da_rx; + + agent_channel =smc_create_channel (i, func_id, scmi_data.shmem_addr + + i *PAGE_SIZE ); +if (IS_ERR (agent_channel) ) + { + ret =PTR_ERR (agent_channel); + goto clean; + } + + hdr.id =SCMI_BASE_DISCOVER_AGENT ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + ret =do_smc_xfer (agent_channel, &hdr, &tx_agent_id, +sizeof (tx_agent_id), &da_rx,sizeof (da_rx)); +if ( ret ) + goto clean; + + ret =check_scmi_status (da_rx.status); +if ( ret ) + goto clean; + +printk (XENLOG_DEBUG "scmi: status=0x%x id=0x%x name=%s\n" , + da_rx.status, da_rx.agent_id, da_rx.name); + + agent_channel->agent_id = da_rx.agent_id; + } + + scmi_data.initialized = true; +return true; + +clean: +free_channel_list (); +return ret ==0 ; +} + +static int scmi_domain_init (struct domain *d) +{ +struct scmi_channel *channel; +int ret; + +if ( !scmi_data.initialized ) +return 0 ; + + channel =aquire_scmi_channel (d->domain_id); +if (IS_ERR_OR_NULL (channel) ) +return -ENOENT ; + +printk (XENLOG_INFO "scmi: Aquire SCMI channel id = 0x%x , domain_id = %d" +"paddr = 0x%lx\n" , channel->chan_id, channel->domain_id, + channel->paddr); + +if (is_hardware_domain (d) ) + { + ret =map_memory_to_domain (d, scmi_data.shmem_addr, + scmi_data.shmem_size); +if (IS_ERR_VALUE (ret) ) + goto error; + + ret =dt_update_domain_range (d, channel->paddr,PAGE_SIZE );
xen/arch/arm/sci/scmi_smc.c line 590
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+if (IS_ERR_VALUE (ret) ) + { +int rc =unmap_memory_from_domain (d, scmi_data.shmem_addr, + scmi_data.shmem_size); +if ( rc ) +printk (XENLOG_ERR "Unable to unmap_memory_from_domain\n" ); + + goto error; + } + }
Is dom0 the only domain to get direct access to the shared memory region? If so, I don't think it is a good idea to make Dom0 "special" in this case.
Let me make an example: if we assign a device to a domU since boot, and dom0 wants to change the frequency of a clock that affects the assigned device (likely because it doesn't know it is assigned), then dom0 shouldn't be able to. We might have to perform checks in Xen to make sure dom0 cannot stop the clock for the assigned device.
So I think it would be better if all domains are treated the same way in the mediator unless really necessary.
On the other hand, if all domains get access to the shared memory region, then I don't think this is likely the right place to create the dom0 mapping. We probably want to do it in domain_build.c in a way that can be reused for dom0less domUs.
In regards to shared memory: it looks like the only two functions to access the real shared memory are send_smc_message and get_smc_response. If that is the case, then we actually don't need to expose the real shared memory to any of the domains.
We could simply:
- expose a regular normal memory region as dom0/domU channel memory
- on SMC trap, read from the "fake" shared memory and set the corresponding real shared memory on the appropriate channel
- issue the SMC call
- on return from SMC, copy over data from the real shared memory to the "fake" channel reagion
This is useful if we need to "filter" any of the SCMI commands and options from the domains to the firmware, and also it is useful if the channel memory is not page aligned. But if the permissions are fine-grained enough and also the channel memory is page aligned (and multiple of 4K in size) then we could map the memory.
Quoted 52 lines
xen/arch/arm/sci/scmi_smc.c new file +52
-0+ + d->arch.sci = channel; + +return 0 ; +error: +relinquish_scmi_channel (channel); + +return ret; +} + +static int scmi_add_device_by_devid (struct domain *d,uint32_t scmi_devid) +{ +struct scmi_channel *channel, *agent_channel; +scmi_msg_header_t hdr; +scmi_perms_tx_t tx; +struct rx_t { +int32_t status; +uint32_t attributes; + } rx; +int ret; + +if ( !scmi_data.initialized ) +return 0 ; + +printk (XENLOG_DEBUG "scmi: scmi_devid = %d\n" , scmi_devid); + + agent_channel =get_channel_by_domain (d->domain_id); +if (IS_ERR_OR_NULL (agent_channel) ) +return PTR_ERR (agent_channel); + + channel =get_channel_by_id (HYP_CHANNEL ); +if (IS_ERR_OR_NULL (channel) ) +return PTR_ERR (channel); + + hdr.id =SCMI_BASE_SET_DEVICE_PERMISSIONS ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + tx.agent_id = agent_channel->agent_id; + tx.device_id = scmi_devid; + tx.flags =SCMI_ALLOW_ACCESS ; + + ret =do_smc_xfer (channel, &hdr, &tx,sizeof (tx), &rx,sizeof (&rx)); +if (IS_ERR_VALUE (ret) ) +return ret; + + ret =check_scmi_status (rx.status); +if (IS_ERR_VALUE (ret) ) +return ret; + +return 0 ; +}
xen/arch/arm/sci/scmi_smc.c line 652
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+ +static int scmi_add_dt_device (struct domain *d,struct dt_device_node *dev) +{ +uint32_t scmi_devid; + +if ( (!scmi_data.initialized) || (!d->arch.sci) ) +return 0 ; + +if ( !dt_property_read_u32 (dev,"scmi_devid" , &scmi_devid) ) +return 0 ;
scmi_devid is another property that is not documented in the binding.
Quoted 103 lines
xen/arch/arm/sci/scmi_smc.c new file +103
-0+printk (XENLOG_INFO "scmi: dt_node = %s\n" ,dt_node_full_name (dev)); + +return scmi_add_device_by_devid (d, scmi_devid); +} + +static int scmi_relinquish_resources (struct domain *d) +{ +int ret; +struct scmi_channel *channel, *agent_channel; +scmi_msg_header_t hdr; +struct reset_agent_tx { +uint32_t agent_id; +uint32_t flags; + } tx; +uint32_t rx; + +if ( !d->arch.sci ) +return 0 ; + + agent_channel = d->arch.sci; + +spin_lock (&agent_channel->lock); + tx.agent_id = agent_channel->agent_id; +spin_unlock (&agent_channel->lock); + + channel =get_channel_by_id (HYP_CHANNEL ); +if ( !channel ) + { +printk (XENLOG_ERR +"scmi: Unable to get Hypervisor scmi channel for domain %d\n" , + d->domain_id); +return -EINVAL ; + } + + hdr.id =SCMI_BASE_RESET_AGENT_CONFIGURATION ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + tx.flags =0 ; + + ret =do_smc_xfer (channel, &hdr, &tx,sizeof (tx), &rx,sizeof (rx)); +if ( ret ) +return ret; + + ret =check_scmi_status (rx); + +return ret; +} + +static void scmi_domain_destroy (struct domain *d) +{ +struct scmi_channel *channel; + +if ( !d->arch.sci ) +return ; + + channel = d->arch.sci; +spin_lock (&channel->lock); + +relinquish_scmi_channel (channel); +printk (XENLOG_DEBUG "scmi: Free domain %d\n" , d->domain_id); + + d->arch.sci =NULL ; + +unmap_memory_from_domain (d, channel->paddr,PAGE_SIZE ); +spin_unlock (&channel->lock); +return ; +} + +static bool scmi_handle_call (struct domain *d,void *args) +{ +bool res = false; +struct scmi_channel *agent_channel; +struct arm_smccc_res resp; +struct cpu_user_regs *regs = args; + +if ( !d->arch.sci ) +return false; + + agent_channel = d->arch.sci; +spin_lock (&agent_channel->lock); + +if ( agent_channel->func_id != regs->x0 ) + { +printk (XENLOG_ERR "scmi: func_id mismatch, exiting\n" ); + goto unlock; + } + +arm_smccc_smc (agent_channel->func_id,0 ,0 ,0 ,0 ,0 ,0 , + agent_channel->chan_id, &resp); + +set_user_reg (regs,0 , resp.a0); +set_user_reg (regs,1 , resp.a1); +set_user_reg (regs,2 , resp.a2); +set_user_reg (regs,3 , resp.a3); + res = true; +unlock: +spin_unlock (&agent_channel->lock); + +return res; +} + +static int scmi_get_channel_paddr(void *scmi_ops,
xen/arch/arm/sci/scmi_smc.c line 766
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+ struct xen_arch_domainconfig *config) +{ +struct scmi_channel *agent_channel = scmi_ops; + +if ( !agent_channel ) +return -EINVAL ; + + config->sci_agent_paddr = agent_channel->paddr; +return 0 ; +}
I am still not sure why it couldn't be done by scmi_domain_init.
Quoted 43 lines
xen/arch/arm/sci/scmi_smc.c new file +28
-0+static const struct dt_device_match scmi_smc_match[]__initconst = +{ +DT_MATCH_SCMI_SMC , + {/* sentinel */ }, +}; + +static const struct sci_mediator_ops scmi_ops = +{ + .probe = scmi_probe, + .domain_init = scmi_domain_init, + .domain_destroy = scmi_domain_destroy, + .add_dt_device = scmi_add_dt_device, + .relinquish_resources = scmi_relinquish_resources, + .handle_call = scmi_handle_call, + .get_channel_info = scmi_get_channel_paddr +}; + +REGISTER_SCI_MEDIATOR (scmi_smc,"SCMI-SMC" ,XEN_DOMCTL_CONFIG_SCI_SCMI_SMC , + scmi_smc_match, &scmi_ops); + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/public/arch-arm.h +1
-0@@ -315,6 +315,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);#define XEN_DOMCTL_CONFIG_TEE_OPTEE 1#define XEN_DOMCTL_CONFIG_SCI_NONE 0 +#define XEN_DOMCTL_CONFIG_SCI_SCMI_SMC 1struct xen_arch_domainconfig {/* IN/OUT */ Signature · 1 line
2.27.0
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Hi Stefano,
Quoted 129 lines · Stefano Stabellini
Quoted 114 lines · Oleksii Moisieiev
This is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG.
The following features are implemented:
- request SCMI channels from ATF and pass channels to Domains;
- set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI;
- redirect scmi messages from Domains to ATF.Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 5 files changed, 809 insertions(+) create mode 100644 xen/arch/arm/sci/Kconfig create mode 100644 xen/arch/arm/sci/scmi_smc.cxen/arch/arm/Kconfig +2
-0@@ -114,6 +114,8 @@ config SCI support. It allows guests to control system resourcess via one of SCI mediators implemented in XEN. +source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/sci/Kconfig new file +10
-0@@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on SCI + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication.xen/arch/arm/sci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.oxen/arch/arm/sci/scmi_smc.c new file +49
-0@@ -0,0 +1,795 @@ +/* +* xen/arch/arm/sci/scmi_smc.c +* +* SCMI mediator driver, using SCP as transport. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/sci/sci.h> +#include <asm/smccc.h> +#include <asm/io.h> +#include <xen/bitops.h> +#include <xen/config.h> +#include <xen/sched.h> +#include <xen/device_tree.h> +#include <xen/iocap.h> +#include <xen/init.h> +#include <xen/err.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/string.h> +#include <xen/time.h> +#include <xen/vmap.h> + +#define SCMI_BASE_PROTOCOL 0x10 +#define SCMI_BASE_PROTOCOL_ATTIBUTES 0x1 +#define SCMI_BASE_SET_DEVICE_PERMISSIONS 0x9 +#define SCMI_BASE_RESET_AGENT_CONFIGURATION 0xB +#define SCMI_BASE_DISCOVER_AGENT 0x7 + +/* SCMI return codes. See section 4.1.4 of SCMI spec (DEN0056C) */ +#define SCMI_SUCCESS 0 +#define SCMI_NOT_SUPPORTED (-1) +#define SCMI_INVALID_PARAMETERS (-2) +#define SCMI_DENIED (-3) +#define SCMI_NOT_FOUND (-4) +#define SCMI_OUT_OF_RANGE (-5)xen/arch/arm/sci/scmi_smc.c line 59
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+#define SCMI_BUSY (-6) +#define SCMI_COMMS_ERROR (-7) +#define SCMI_GENERIC_ERROR (-8) +#define SCMI_HARDWARE_ERROR (-9) +#define SCMI_PROTOCOL_ERROR (-10) + +#define DT_MATCH_SCMI_SMC DT_MATCH_COMPATIBLE("arm,scmi-smc") + +#define SCMI_SMC_ID "arm,smc-id" +#define SCMI_SHARED_MEMORY "linux,scmi_mem"I could find the following SCMI binding in Linux, which describes the arm,scmi-smc compatible and the arm,smc-id property:
Quoted 6 lines
Documentation/devicetree/bindings/firmware/arm,scmi.yamlHowever, linux,scmi_mem is not described. Aren't you supposed to read the "shmem" property instead? And the compatible string used for this seems to be "arm,scmi-shmem".
We use linux,scmi_mem node to reserve memory, needed for all channels:
reserved-memory {
/* reserved region for scmi channels*/
scmi_memory: linux,scmi_mem@53FF0000 {
no-map;
reg = <0x0 0x53FF0000 0x0 0x10000>;
};
};arm,scmi-shmem node used in shmem property defines only 1 page needed to the current scmi channel:
cpu_scp_shm: scp-shmem@0x53FF0000 {
compatible = "arm,scmi-shmem";
reg = <0x0 0x53FF0000 0x0 0x1000>;
};For each Domain reg points to unigue page from linux,scmi_mem region, assigned to this agent.
Quoted 92 lines
Quoted 92 lines
xen/arch/arm/sci/scmi_smc.c new file +91
-0+#define SCMI_SHMEM "shmem" + +#define HYP_CHANNEL 0x0 + +#define HDR_ID GENMASK(7,0) +#define HDR_TYPE GENMASK(9, 8) +#define HDR_PROTO GENMASK(17, 10) + +/* SCMI protocol, refer to section 4.2.2.2 (DEN0056C) */ +#define MSG_N_AGENTS_MASK GENMASK(15, 8) + +#define FIELD_GET (_mask, _reg)\ + ((typeof(_mask))(((_reg) & (_mask)) >> (ffs64(_mask) - 1))) +#define FIELD_PREP (_mask, _val)\ + (((typeof(_mask))(_val) << (ffs64(_mask) - 1)) & (_mask)) + +typedef struct scmi_msg_header { +uint8_t id; +uint8_t type; +uint8_t protocol; +}scmi_msg_header_t ; + +typedef struct scmi_perms_tx { +uint32_t agent_id; +uint32_t device_id; +uint32_t flags; +}scmi_perms_tx_t ; + +#define SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE BIT(0, UL) +#define SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR BIT(1, UL) + +#define SCMI_ALLOW_ACCESS BIT(0, UL) + +struct scmi_shared_mem { +uint32_t reserved; +uint32_t channel_status; +uint32_t reserved1[2 ]; +uint32_t flags; +uint32_t length; +uint32_t msg_header; +uint8_t msg_payload[]; +}; + +struct scmi_channel { +int chan_id; +int agent_id; +uint32_t func_id; +int domain_id; +uint64_t paddr; +struct scmi_shared_mem *shmem; +spinlock_t lock; +struct list_head list; +}; + +struct scmi_data { +struct list_head channel_list; +spinlock_t channel_list_lock; +bool initialized; +u64 shmem_addr, shmem_size; +}; + +static struct scmi_data scmi_data; + +/* +* pack_scmi_header() - packs and returns 32-bit header +* +* @hdr: pointer to header containing all the information on message id, +* protocol id and type id. +* +* Return: 32-bit packed message header to be sent to the platform. +*/ +static inline uint32_t pack_scmi_header (scmi_msg_header_t *hdr) +{ +return FIELD_PREP (HDR_ID , hdr->id) | +FIELD_PREP (HDR_TYPE , hdr->type) | +FIELD_PREP (HDR_PROTO , hdr->protocol); +} + +/* +* unpack_scmi_header() - unpacks and records message and protocol id +* +* @msg_hdr: 32-bit packed message header sent from the platform +* @hdr: pointer to header to fetch message and protocol id. +*/ +static inline void unpack_scmi_header (uint32_t msg_hdr,scmi_msg_header_t *hdr) +{ + hdr->id =FIELD_GET (HDR_ID , msg_hdr); + hdr->type =FIELD_GET (HDR_TYPE , msg_hdr); + hdr->protocol =FIELD_GET (HDR_PROTO , msg_hdr); +} +
Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 154
Quoted 4 lines
xen/arch/arm/sci/scmi_smc.c new file +4
-0+static inline int channel_is_free (struct scmi_channel *chan_info) +{ +return ( chan_info->shmem->channel_status + &SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE ) ?0 : -EBUSY ;Does this need a memory barrier? Or not, because the other end always runs on the same CPU at a different execution level so the
channel_statuswould be always guaranteed to be read as updated?
It don't because the other end runs on the same CPU. Other mediator implemetaions, which uses different areas may need memory barrier.
Quoted 22 lines
Quoted 22 lines
xen/arch/arm/sci/scmi_smc.c new file +21
-0+} + +static int send_smc_message (struct scmi_channel *chan_info, +scmi_msg_header_t *hdr,void *data,int len) +{ +struct arm_smccc_res resp; +int ret; + +printk (XENLOG_DEBUG "scmi: status =%d len=%d\n" , + chan_info->shmem->channel_status, len); +printk (XENLOG_DEBUG "scmi: header id = %d type = %d, proto = %d\n" , + hdr->id, hdr->type, hdr->protocol); + + ret =channel_is_free (chan_info); +if (IS_ERR_VALUE (ret) ) +return ret; + + chan_info->shmem->channel_status =0x0 ; +/* Writing 0x0 right now, but SCMI_SHMEM_FLAG_INTR_ENABLED can be set */ + chan_info->shmem->flags =0x0 ; + chan_info->shmem->length =sizeof (chan_info->shmem->msg_header) + len;
Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 181
Quoted 6 lines
xen/arch/arm/sci/scmi_smc.c new file +6
-0+ chan_info->shmem->msg_header =pack_scmi_header (hdr); + +printk (XENLOG_DEBUG "scmi: Writing to shmem address %p\n" , + chan_info->shmem); +if ( len >0 && data ) +memcpy ((void *)(chan_info->shmem->msg_payload), data, len);Again, here we don't need a barrier because it is implicit in the SMC?
As I mentioned before, the other end runs on the same CPU.
Quoted 2 lines
Don't we need to check that "len" fits in the shared memory?
I think it's a good point. I'll add len check in v2.
Quoted 11 lines
xen/arch/arm/sci/scmi_smc.c line 189
Quoted 8 lines
xen/arch/arm/sci/scmi_smc.c new file +7
-0+arm_smccc_smc (chan_info->func_id,0 ,0 ,0 ,0 ,0 ,0 , chan_info->chan_id, + &resp); + +printk (XENLOG_DEBUG "scmi: scmccc_smc response %d\n" , (int )(resp.a0)); + +if ( resp.a0 ) +return -EOPNOTSUPP ;Why is that?
This change was presented in kernel by Sudeep Holla in commit:f7199cf489027ae38a9a82312d13025f7aefa0b8
However, link posted in the commit:
https://lore.kernel.org/r/[email protected]
Leads to slightly different patch:
+ if (res.a0 == SMCCC_RET_NOT_SUPPORTED)
+ return -EOPNOTSUPP;
+ else if (res.a0)
+ return -EINVAL;
+ return 0;
I don't know why it differs from the original commit, but I'll check and place the correct implementation in v2.
Quoted 45 lines
Quoted 45 lines
xen/arch/arm/sci/scmi_smc.c new file +44
-0+return 0 ; +} + +static int check_scmi_status (int scmi_status) +{ +if ( scmi_status ==SCMI_SUCCESS ) +return 0 ; + +printk (XENLOG_DEBUG "scmi: Error received: %d\n" , scmi_status); + +switch ( scmi_status ) + { +case SCMI_NOT_SUPPORTED : +return -EOPNOTSUPP ; +case SCMI_INVALID_PARAMETERS : +return -EINVAL ; +case SCMI_DENIED : +return -EACCES ; +case SCMI_NOT_FOUND : +return -ENOENT ; +case SCMI_OUT_OF_RANGE : +return -ERANGE ; +case SCMI_BUSY : +return -EBUSY ; +case SCMI_COMMS_ERROR : +return -ENOTCONN ; +case SCMI_GENERIC_ERROR : +return -EIO ; +case SCMI_HARDWARE_ERROR : +return -ENXIO ; +case SCMI_PROTOCOL_ERROR : +return -EBADMSG ; + } + +return -EINVAL ; +} + +static int get_smc_response (struct scmi_channel *chan_info, +scmi_msg_header_t *hdr,void *data,int len) +{ +int recv_len; +int ret; + +printk (XENLOG_DEBUG "scmi: get smc responce msgid %d\n" , hdr->id);
Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 170
Quoted 4 lines
xen/arch/arm/sci/scmi_smc.c new file +4
-0+ + ret =channel_is_free (chan_info); +if (IS_ERR_VALUE (ret) ) +return ret;I am not familiar with the spec (do you have a link?) but is it expected that the channel is "free" when actually we want to read a message on the channel?
Here is the link https://developer.arm.com/documentation/den0056/latest
Figure 6 in Section 5.1.1.
Caller marks channel as busy, then callee process message and marks channel as free. We are implementing polling based communication flow.
Quoted 51 lines
Quoted 51 lines
xen/arch/arm/sci/scmi_smc.c new file +49
-0+ recv_len = chan_info->shmem->length -sizeof (chan_info->shmem->msg_header); + +if ( recv_len <0 ) + { +printk (XENLOG_ERR +"scmi: Wrong size of smc message. Data may be invalid\n" ); +return -EINVAL ; + } + +if ( recv_len > len ) + { +printk (XENLOG_ERR +"scmi: Not enough buffer for message %d, expecting %d\n" , + recv_len, len); +return -EINVAL ; + } + +unpack_scmi_header (chan_info->shmem->msg_header, hdr); + +if ( recv_len >0 ) + { +memcpy (data, chan_info->shmem->msg_payload, recv_len); + } + +return 0 ; +} + +static int do_smc_xfer (struct scmi_channel *channel,scmi_msg_header_t *hdr,void *tx_data,int tx_size, +void *rx_data,int rx_size) +{ +int ret =0 ; + +if ( !hdr ) +return -EINVAL ; + +spin_lock (&channel->lock); + + ret =send_smc_message (channel, hdr, tx_data, tx_size); +if ( ret ) + goto clean; + + ret =get_smc_response (channel, hdr, rx_data, rx_size); +clean: +spin_unlock (&channel->lock); + +return ret; +} + +static struct scmi_channel *get_channel_by_id (uint8_t chan_id)
Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 294
Quoted 6 lines
xen/arch/arm/sci/scmi_smc.c new file +6
-0+{ +struct scmi_channel *curr; +bool found = false; + +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry (curr, &scmi_data.channel_list, list)please use parenthesis around the inner if (also in other places)
Thank you for the remark. I will fix it in v2.
Quoted 17 lines
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +4
-0+if ( curr->chan_id == chan_id ) + { + found = true; +break ;xen/arch/arm/sci/scmi_smc.c line 308
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+ } + +spin_unlock (&scmi_data.channel_list_lock); +if ( found ) +return curr; + +return NULL ; +} + +static struct scmi_channel *get_channel_by_domain (uint8_t domain_id)Use
domid_tfor domain ids.
Thanks, I will fix it in v2.
Quoted 7 lines
Also, wouldn't it be better to implement it as:
static inline struct scmi_channel *get_channel_by_domain(struct domain *d) { return d->arch.sci }
That's a good point. I will take a look on it and fix in v2.
Quoted 26 lines
Quoted 26 lines
xen/arch/arm/sci/scmi_smc.c new file +25
-0+{ +struct scmi_channel *curr; +bool found = false; + +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry (curr, &scmi_data.channel_list, list) +if ( curr->domain_id == domain_id ) + { + found = true; +break ; + } + +spin_unlock (&scmi_data.channel_list_lock); +if ( found ) +return curr; + +return NULL ; +} + +static struct scmi_channel *aquire_scmi_channel (int domain_id) +{ +struct scmi_channel *curr; +bool found = false; + +ASSERT (domain_id !=DOMID_INVALID && domain_id >=0 );
Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 338
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +5
-0+ +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry (curr, &scmi_data.channel_list, list) +if ( (curr->domain_id ==DOMID_INVALID ) + && (curr->chan_id !=HYP_CHANNEL ) )If you use
DOMID_XENforHYP_CHANNEL, then this check becomes more intuitive
We do not have direct relation between channel id and domain id. One channel id can be reused by different domain_ids. So from my standpoint, DOMID_XEN doesn't fit here.
Quoted 12 lines
Quoted 12 lines
xen/arch/arm/sci/scmi_smc.c new file +11
-0+ { + curr->domain_id = domain_id; + found = true; +break ; + } + +spin_unlock (&scmi_data.channel_list_lock); +if ( found ) +return curr; + +return NULL ;
Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 355
Quoted 6 lines
xen/arch/arm/sci/scmi_smc.c new file +6
-0+} + +static void relinquish_scmi_channel (struct scmi_channel *channel) +{ +spin_lock (&scmi_data.channel_list_lock); +ASSERT (channel !=NULL );the ASSERT could be before the
spin_lock
Thank you. I will fix it in v2.
Quoted 17 lines
Quoted 17 lines
xen/arch/arm/sci/scmi_smc.c new file +16
-0+ channel->domain_id =DOMID_INVALID ; +spin_unlock (&scmi_data.channel_list_lock); +} + +static struct scmi_channel *smc_create_channel (uint8_t chan_id, +uint32_t func_id,uint64_t addr) +{ +struct scmi_channel *channel; +mfn_t mfn; + + channel =get_channel_by_id (chan_id); +if ( channel ) +return ERR_PTR (EEXIST ); + + channel = xmalloc(struct scmi_channel); +if ( !channel )
Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 376
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +5
-0+return ERR_PTR (ENOMEM ); + + channel->chan_id = chan_id; + channel->func_id = func_id; + channel->domain_id =DOMID_INVALID ;I take you are using
DOMID_INVALIDto mark a channel used by Xen itself? If so, thenDOMID_XENwould be more appropriate.
I use DOMID_INVALID to mark channel as free.
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c line 378
Quoted 3 lines
xen/arch/arm/sci/scmi_smc.c new file +2
-0+ mfn =maddr_to_mfn (addr); + channel->shmem =vmap (&mfn,1 );One thing to be careful is the mapping attributes, for a couple of reasons. As you might be aware, the ARM architecture forbids mismatching attributes for mapping memory in different places in the system. So the attributes that we use here must be the same used by the firmware (and/or the guest.)
Quoted 6 lines
The second reason to be careful is that in the bindings example
Documentation/devicetree/bindings/firmware/arm,scmi.yamlthe shared memory is "mmio-sram", which is special. It is not supposed to be normal memory, but it is OK to map it cacheable. Still, it might be more appropriate to useioremap_cache.
Originally, I used vmap here to have memcpy and it works fine in our setup. But I will do some research and email you with the results.
Quoted 34 lines
Quoted 34 lines
xen/arch/arm/sci/scmi_smc.c new file +33
-0+if ( !channel->shmem ) + { +xfree (channel); +return ERR_PTR (ENOMEM ); + } + +printk (XENLOG_DEBUG "scmi: Got shmem after vmap %p\n" , channel->shmem); + channel->paddr = addr; + channel->shmem->channel_status =SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE ; +spin_lock_init (&channel->lock); +spin_lock (&scmi_data.channel_list_lock); +list_add (&channel->list, &scmi_data.channel_list); +spin_unlock (&scmi_data.channel_list_lock); +return channel; +} + +static int map_memory_to_domain (struct domain *d,uint64_t addr,uint64_t len) +{ +return iomem_permit_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +} + +static int unmap_memory_from_domain (struct domain *d,uint64_t addr, +uint64_t len) +{ +return iomem_deny_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +} + +static int dt_update_domain_range (struct domain *d,uint64_t addr, +uint64_t size) +{ +struct dt_device_node *shmem_node;
Quoted 8 lines
xen/arch/arm/sci/scmi_smc.c line 416
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +5
-0+__be32 *hw_reg; +const struct dt_property *pp; +uint32_t len; + + shmem_node =dt_find_compatible_node (NULL ,NULL ,"arm,scmi-shmem" );Here we are using "arm,scmi-shmem" while below we are checking for "linux,scmi_mem". What's the difference?
linux,scmi_mem (I posted nodes examples above) describes memory region, allocated for all channels, while arm,scmi-shmem points to the exact channel (page in linux,scmi_mem region).
Quoted 11 lines
Also, this function is looking for "arm,scmi-shmem" in
dt_hostand replaces its value. For dom0less domUs we'll probably need amake_scmi_nodefunction to create the node from scratch like for instance xen/arch/arm/domain_build.c:make_gic_domU_node.I wonder if we had such a function whether it wouldn't be better to also use it for dom0 (and blacklist the physical "arm,scmi-shmem" in
handle_nodeso that dom0 doesn't get the real shared memory information by accident).
Thank you for the remark. I will rework this in v2.
Quoted 42 lines
Quoted 42 lines
xen/arch/arm/sci/scmi_smc.c new file +41
-0+ +if ( !shmem_node ) + { +printk (XENLOG_ERR "scmi: Unable to find %s node in DT\n" ,SCMI_SHMEM ); +return -EINVAL ; + } + + pp =dt_find_property (shmem_node,"reg" , &len); +if ( !pp ) + { +printk (XENLOG_ERR "scmi: Unable to find regs entry in shmem node\n" ); +return -ENOENT ; + } + + hw_reg = pp->value; +dt_set_range (&hw_reg, shmem_node, addr, size); + +return 0 ; +} + +static void free_channel_list (void ) +{ +struct scmi_channel *curr, *_curr; + +spin_lock (&scmi_data.channel_list_lock); + list_for_each_entry_safe (curr, _curr, &scmi_data.channel_list, list) + { +vunmap (curr->shmem); +list_del (&curr->list); +xfree (curr); + } + +spin_unlock (&scmi_data.channel_list_lock); +} + +static __init bool scmi_probe (struct dt_device_node *scmi_node) +{ +struct dt_device_node *shmem_node; +int ret, i; +struct scmi_channel *channel, *agent_channel; +int n_agents;
Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 462
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +5
-0+scmi_msg_header_t hdr; +struct rx_t { +int32_t status; +uint32_t attributes; + } rx;Should rx be defined at the top together with
scmi_perms_tx_tand others?
I'd rather move scmi_perms_tx_t to scmi_add_device_by_devid because it's used only in 1 place.
So we will have rx and tx in scmi_add_device_by_devid and rx ( which differs from rx in scmi_add_device_by_devid ) in scmi_probe. I think it will be more understandable and no need to make unique names. What do you think about that?
Quoted 10 lines
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +9
-0+uint32_t func_id; + +ASSERT (scmi_node !=NULL ); + +INIT_LIST_HEAD (&scmi_data.channel_list); +spin_lock_init (&scmi_data.channel_list_lock); + +if ( !dt_property_read_u32 (scmi_node,SCMI_SMC_ID , &func_id) ) + {
Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 477
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +5
-0+printk (XENLOG_ERR "scmi: Unable to read smc-id from DT\n" ); +return false; + } + + shmem_node =dt_find_node_by_name (NULL ,SCMI_SHARED_MEMORY );From the spec, it looks like you should be getting the shared memory area from the phandle list "shmem".
We use SCMI_SHARED_MEMORY to get whole memory region (0x10 pages in my case), we can use for the agents. As you can see below - Hypervisor received number of agents from Firmware and split this region between agents.
Quoted 33 lines
Quoted 33 lines
xen/arch/arm/sci/scmi_smc.c new file +32
-0+if (IS_ERR_OR_NULL (shmem_node) ) + { +printk (XENLOG_ERR +"scmi: Device tree error, can't parse shmem phandle %ld\n" , +PTR_ERR (shmem_node)); +return false; + } + + ret =dt_device_get_address (shmem_node,0 , &scmi_data.shmem_addr, + &scmi_data.shmem_size); +if (IS_ERR_VALUE (ret) ) +return false; + + channel =smc_create_channel (HYP_CHANNEL , func_id, scmi_data.shmem_addr); +if (IS_ERR (channel) ) +return false; + + hdr.id =SCMI_BASE_PROTOCOL_ATTIBUTES ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + ret =do_smc_xfer (channel, &hdr,NULL ,0 , &rx,sizeof (rx)); +if ( ret ) + goto clean; + + ret =check_scmi_status (rx.status); +if ( ret ) + goto clean; + + n_agents =FIELD_GET (MSG_N_AGENTS_MASK , rx.attributes); +printk (XENLOG_DEBUG "scmi: Got agent count %d\n" , n_agents); +
Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 514
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +5
-0+ n_agents = (n_agents > scmi_data.shmem_size /PAGE_SIZE ) ? + scmi_data.shmem_size /PAGE_SIZE : n_agents; + +for ( i =1 ; i < n_agents; i++ ) + {Given that
HYP_CHANNELis actually zero, it looks like we could do everything here in this loop but starting from i=0?
We allocate HYP_CHANNEL before loop because we need it to request number of agents. And we don't need to send SCMI_BASE_DISCOVER_AGENT to HYP_CHANNEL.
Quoted 88 lines
Quoted 67 lines
xen/arch/arm/sci/scmi_smc.c new file +66
-0+uint32_t tx_agent_id =0xFFFFFFFF ; +struct { +int32_t status; +uint32_t agent_id; +char name[16 ]; + } da_rx; + + agent_channel =smc_create_channel (i, func_id, scmi_data.shmem_addr + + i *PAGE_SIZE ); +if (IS_ERR (agent_channel) ) + { + ret =PTR_ERR (agent_channel); + goto clean; + } + + hdr.id =SCMI_BASE_DISCOVER_AGENT ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + ret =do_smc_xfer (agent_channel, &hdr, &tx_agent_id, +sizeof (tx_agent_id), &da_rx,sizeof (da_rx)); +if ( ret ) + goto clean; + + ret =check_scmi_status (da_rx.status); +if ( ret ) + goto clean; + +printk (XENLOG_DEBUG "scmi: status=0x%x id=0x%x name=%s\n" , + da_rx.status, da_rx.agent_id, da_rx.name); + + agent_channel->agent_id = da_rx.agent_id; + } + + scmi_data.initialized = true; +return true; + +clean: +free_channel_list (); +return ret ==0 ; +} + +static int scmi_domain_init (struct domain *d) +{ +struct scmi_channel *channel; +int ret; + +if ( !scmi_data.initialized ) +return 0 ; + + channel =aquire_scmi_channel (d->domain_id); +if (IS_ERR_OR_NULL (channel) ) +return -ENOENT ; + +printk (XENLOG_INFO "scmi: Aquire SCMI channel id = 0x%x , domain_id = %d" +"paddr = 0x%lx\n" , channel->chan_id, channel->domain_id, + channel->paddr); + +if (is_hardware_domain (d) ) + { + ret =map_memory_to_domain (d, scmi_data.shmem_addr, + scmi_data.shmem_size); +if (IS_ERR_VALUE (ret) ) + goto error; + + ret =dt_update_domain_range (d, channel->paddr,PAGE_SIZE );xen/arch/arm/sci/scmi_smc.c line 590
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+if (IS_ERR_VALUE (ret) ) + { +int rc =unmap_memory_from_domain (d, scmi_data.shmem_addr, + scmi_data.shmem_size); +if ( rc ) +printk (XENLOG_ERR "Unable to unmap_memory_from_domain\n" ); + + goto error; + } + }Is dom0 the only domain to get direct access to the shared memory region? If so, I don't think it is a good idea to make Dom0 "special" in this case.
Let me make an example: if we assign a device to a domU since boot, and dom0 wants to change the frequency of a clock that affects the assigned device (likely because it doesn't know it is assigned), then dom0 shouldn't be able to. We might have to perform checks in Xen to make sure dom0 cannot stop the clock for the assigned device.
Quoted 8 lines
So I think it would be better if all domains are treated the same way in the mediator unless really necessary.
On the other hand, if all domains get access to the shared memory region, then I don't think this is likely the right place to create the dom0 mapping. We probably want to do it in
domain_build.cin a way that can be reused for dom0less domUs.
The idea is that all domains have their own page in shared memory region and unigue agent_id. Agent_id is used to set permissions for clocks\resets\power-domains etc. So during creation of domain (domUs or dom0) device-tree is processed using scmi_add_dt_device and clocks\resets\power-domains which are related to dom0 devices will be requested by using SCMI_BASE_SET_DEVICE_PERMISSIONS message. All passed-through devices will be requested during DomU creation. Which means dom0 do not have an access to clocks\resets\power-domains, which are related to DomU.
Quoted 6 lines
In regards to shared memory: it looks like the only two functions to access the real shared memory are
send_smc_messageandget_smc_response. If that is the case, then we actually don't need to expose the real shared memory to any of the domains.
Quoted 8 lines
We could simply:
- expose a regular normal memory region as dom0/domU channel memory
- on SMC trap, read from the "fake" shared memory and set the corresponding real shared memory on the appropriate channel
- issue the SMC call
- on return from SMC, copy over data from the real shared memory to the "fake" channel reagion
Hypervisor redirects only SMC calls from guests and set agent_id to SMC parameters as a7. The idea was to give page for each agent, so we don't need to make additional read/write each time we receive SMC call. All we povide from hypervisor is agent_id. Firmware is responsible for reading memory from the correct address and place the response.
Quoted 7 lines
This is useful if we need to "filter" any of the SCMI commands and options from the domains to the firmware, and also it is useful if the channel memory is not page aligned. But if the permissions are fine-grained enough and also the channel memory is page aligned (and multiple of 4K in size) then we could map the memory.
In current implementation we suppose that channel memory is page aligned. I think that Firmware should be responsible for permissions handling and "filtering", that's why permission calls were added to SCMI spec. I tried to make mediator as thin as possible.
Quoted 57 lines
Quoted 57 lines
xen/arch/arm/sci/scmi_smc.c new file +56
-0+ + d->arch.sci = channel; + +return 0 ; +error: +relinquish_scmi_channel (channel); + +return ret; +} + +static int scmi_add_device_by_devid (struct domain *d,uint32_t scmi_devid) +{ +struct scmi_channel *channel, *agent_channel; +scmi_msg_header_t hdr; +scmi_perms_tx_t tx; +struct rx_t { +int32_t status; +uint32_t attributes; + } rx; +int ret; + +if ( !scmi_data.initialized ) +return 0 ; + +printk (XENLOG_DEBUG "scmi: scmi_devid = %d\n" , scmi_devid); + + agent_channel =get_channel_by_domain (d->domain_id); +if (IS_ERR_OR_NULL (agent_channel) ) +return PTR_ERR (agent_channel); + + channel =get_channel_by_id (HYP_CHANNEL ); +if (IS_ERR_OR_NULL (channel) ) +return PTR_ERR (channel); + + hdr.id =SCMI_BASE_SET_DEVICE_PERMISSIONS ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + tx.agent_id = agent_channel->agent_id; + tx.device_id = scmi_devid; + tx.flags =SCMI_ALLOW_ACCESS ; + + ret =do_smc_xfer (channel, &hdr, &tx,sizeof (tx), &rx,sizeof (&rx)); +if (IS_ERR_VALUE (ret) ) +return ret; + + ret =check_scmi_status (rx.status); +if (IS_ERR_VALUE (ret) ) +return ret; + +return 0 ; +} + +static int scmi_add_dt_device (struct domain *d,struct dt_device_node *dev) +{ +uint32_t scmi_devid;
Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 652
Quoted 6 lines
xen/arch/arm/sci/scmi_smc.c new file +6
-0+ +if ( (!scmi_data.initialized) || (!d->arch.sci) ) +return 0 ; + +if ( !dt_property_read_u32 (dev,"scmi_devid" , &scmi_devid) ) +return 0 ;
scmi_devidis another property that is not documented in the binding.
This property should be added to the device nodes, which are using scmi to work with clocks\resets\power-domains etc. This id should match the device_id, defined in Firmware. Hypervisor send this device_id to the Firmware as parameter to the permission request. Firmware set permissions to clocks\resets\power-domains, related to this device.
Quoted 108 lines
Quoted 108 lines
xen/arch/arm/sci/scmi_smc.c new file +107
-0+printk (XENLOG_INFO "scmi: dt_node = %s\n" ,dt_node_full_name (dev)); + +return scmi_add_device_by_devid (d, scmi_devid); +} + +static int scmi_relinquish_resources (struct domain *d) +{ +int ret; +struct scmi_channel *channel, *agent_channel; +scmi_msg_header_t hdr; +struct reset_agent_tx { +uint32_t agent_id; +uint32_t flags; + } tx; +uint32_t rx; + +if ( !d->arch.sci ) +return 0 ; + + agent_channel = d->arch.sci; + +spin_lock (&agent_channel->lock); + tx.agent_id = agent_channel->agent_id; +spin_unlock (&agent_channel->lock); + + channel =get_channel_by_id (HYP_CHANNEL ); +if ( !channel ) + { +printk (XENLOG_ERR +"scmi: Unable to get Hypervisor scmi channel for domain %d\n" , + d->domain_id); +return -EINVAL ; + } + + hdr.id =SCMI_BASE_RESET_AGENT_CONFIGURATION ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + tx.flags =0 ; + + ret =do_smc_xfer (channel, &hdr, &tx,sizeof (tx), &rx,sizeof (rx)); +if ( ret ) +return ret; + + ret =check_scmi_status (rx); + +return ret; +} + +static void scmi_domain_destroy (struct domain *d) +{ +struct scmi_channel *channel; + +if ( !d->arch.sci ) +return ; + + channel = d->arch.sci; +spin_lock (&channel->lock); + +relinquish_scmi_channel (channel); +printk (XENLOG_DEBUG "scmi: Free domain %d\n" , d->domain_id); + + d->arch.sci =NULL ; + +unmap_memory_from_domain (d, channel->paddr,PAGE_SIZE ); +spin_unlock (&channel->lock); +return ; +} + +static bool scmi_handle_call (struct domain *d,void *args) +{ +bool res = false; +struct scmi_channel *agent_channel; +struct arm_smccc_res resp; +struct cpu_user_regs *regs = args; + +if ( !d->arch.sci ) +return false; + + agent_channel = d->arch.sci; +spin_lock (&agent_channel->lock); + +if ( agent_channel->func_id != regs->x0 ) + { +printk (XENLOG_ERR "scmi: func_id mismatch, exiting\n" ); + goto unlock; + } + +arm_smccc_smc (agent_channel->func_id,0 ,0 ,0 ,0 ,0 ,0 , + agent_channel->chan_id, &resp); + +set_user_reg (regs,0 , resp.a0); +set_user_reg (regs,1 , resp.a1); +set_user_reg (regs,2 , resp.a2); +set_user_reg (regs,3 , resp.a3); + res = true; +unlock: +spin_unlock (&agent_channel->lock); + +return res; +} + +static int scmi_get_channel_paddr (void *scmi_ops, +struct xen_arch_domainconfig *config) +{ +struct scmi_channel *agent_channel = scmi_ops; +
Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 766
Quoted 6 lines
xen/arch/arm/sci/scmi_smc.c new file +6
-0+if ( !agent_channel ) +return -EINVAL ; + + config->sci_agent_paddr = agent_channel->paddr; +return 0 ; +}I am still not sure why it couldn't be done by
scmi_domain_init.
I can move this logic to scmi_domain_init, but in this case I have to add struct xen_arch_domainconfig *config as input parameter to scmi_domain_init and pass NULL from construct_dom0.
Do you think this approach would be better?
Also I think it's reasonable to pass xen_arch_domainconfig so different implementations could set another data they would probably need.
Quoted 44 lines
Quoted 44 lines
xen/arch/arm/sci/scmi_smc.c new file +28
-0+static const struct dt_device_match scmi_smc_match[]__initconst = +{ +DT_MATCH_SCMI_SMC , + {/* sentinel */ }, +}; + +static const struct sci_mediator_ops scmi_ops = +{ + .probe = scmi_probe, + .domain_init = scmi_domain_init, + .domain_destroy = scmi_domain_destroy, + .add_dt_device = scmi_add_dt_device, + .relinquish_resources = scmi_relinquish_resources, + .handle_call = scmi_handle_call, + .get_channel_info = scmi_get_channel_paddr +}; + +REGISTER_SCI_MEDIATOR (scmi_smc,"SCMI-SMC" ,XEN_DOMCTL_CONFIG_SCI_SCMI_SMC , + scmi_smc_match, &scmi_ops); + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/public/arch-arm.h +1
-0@@ -315,6 +315,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);#define XEN_DOMCTL_CONFIG_TEE_OPTEE 1#define XEN_DOMCTL_CONFIG_SCI_NONE 0 +#define XEN_DOMCTL_CONFIG_SCI_SCMI_SMC 1struct xen_arch_domainconfig {/* IN/OUT */ Signature · 1 line
2.27.0
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Quoted 153 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 129 lines · Stefano Stabellini
Quoted 114 lines · Oleksii Moisieiev
This is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG.
The following features are implemented:
- request SCMI channels from ATF and pass channels to Domains;
- set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI;
- redirect scmi messages from Domains to ATF.Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 5 files changed, 809 insertions(+) create mode 100644 xen/arch/arm/sci/Kconfig create mode 100644 xen/arch/arm/sci/scmi_smc.cxen/arch/arm/Kconfig +2
-0@@ -114,6 +114,8 @@ config SCI support. It allows guests to control system resourcess via one of SCI mediators implemented in XEN. +source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/sci/Kconfig new file +10
-0@@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on SCI + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication.xen/arch/arm/sci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.oxen/arch/arm/sci/scmi_smc.c new file +49
-0@@ -0,0 +1,795 @@ +/* +* xen/arch/arm/sci/scmi_smc.c +* +* SCMI mediator driver, using SCP as transport. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/sci/sci.h> +#include <asm/smccc.h> +#include <asm/io.h> +#include <xen/bitops.h> +#include <xen/config.h> +#include <xen/sched.h> +#include <xen/device_tree.h> +#include <xen/iocap.h> +#include <xen/init.h> +#include <xen/err.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/string.h> +#include <xen/time.h> +#include <xen/vmap.h> + +#define SCMI_BASE_PROTOCOL 0x10 +#define SCMI_BASE_PROTOCOL_ATTIBUTES 0x1 +#define SCMI_BASE_SET_DEVICE_PERMISSIONS 0x9 +#define SCMI_BASE_RESET_AGENT_CONFIGURATION 0xB +#define SCMI_BASE_DISCOVER_AGENT 0x7 + +/* SCMI return codes. See section 4.1.4 of SCMI spec (DEN0056C) */ +#define SCMI_SUCCESS 0 +#define SCMI_NOT_SUPPORTED (-1) +#define SCMI_INVALID_PARAMETERS (-2) +#define SCMI_DENIED (-3) +#define SCMI_NOT_FOUND (-4) +#define SCMI_OUT_OF_RANGE (-5)xen/arch/arm/sci/scmi_smc.c line 59
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+#define SCMI_BUSY (-6) +#define SCMI_COMMS_ERROR (-7) +#define SCMI_GENERIC_ERROR (-8) +#define SCMI_HARDWARE_ERROR (-9) +#define SCMI_PROTOCOL_ERROR (-10) + +#define DT_MATCH_SCMI_SMC DT_MATCH_COMPATIBLE("arm,scmi-smc") + +#define SCMI_SMC_ID "arm,smc-id" +#define SCMI_SHARED_MEMORY "linux,scmi_mem"I could find the following SCMI binding in Linux, which describes the arm,scmi-smc compatible and the arm,smc-id property:
Quoted 6 lines
Documentation/devicetree/bindings/firmware/arm,scmi.yamlHowever, linux,scmi_mem is not described. Aren't you supposed to read the "shmem" property instead? And the compatible string used for this seems to be "arm,scmi-shmem".
We use linux,scmi_mem node to reserve memory, needed for all channels:
reserved-memory { /* reserved region for scmi channels*/ scmi_memory: linux,scmi_mem@53FF0000 { no-map; reg = <0x0 0x53FF0000 0x0 0x10000>; }; };arm,scmi-shmem node used in shmem property defines only 1 page needed to the current scmi channel:
Quoted 7 lines
cpu_scp_shm: scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; };For each Domain reg points to unigue page from linux,scmi_mem region, assigned to this agent.
If we were to use "linux,scmi_mem" we would have to introduce it as a compatible string, not as a node name, and it would need to be described in Documentation/devicetree/bindings/firmware/arm,scmi.yaml.
But from your description I don't think it is necessary. We can just use "arm,scmi-shmem" to describe all the required regions:
reserved-memory {
scp-shmem@0x53FF0000 {
compatible = "arm,scmi-shmem";
reg = <0x0 0x53FF0000 0x0 0x1000>;
};
scp-shmem@0x53FF1000 {
compatible = "arm,scmi-shmem";
reg = <0x0 0x53FF1000 0x0 0x1000>;
};
scp-shmem@0x53FF2000 {
compatible = "arm,scmi-shmem";
reg = <0x0 0x53FF2000 0x0 0x1000>;
};
...In other words, if all the individual channel pages are described as "arm,scmi-shmem", why do we also need a single larger region as "linux,scmi_mem"?
Quoted 227 lines
Quoted 91 lines
Quoted 91 lines
xen/arch/arm/sci/scmi_smc.c new file +91
-0+#define SCMI_SHMEM "shmem" + +#define HYP_CHANNEL 0x0 + +#define HDR_ID GENMASK(7,0) +#define HDR_TYPE GENMASK(9, 8) +#define HDR_PROTO GENMASK(17, 10) + +/* SCMI protocol, refer to section 4.2.2.2 (DEN0056C) */ +#define MSG_N_AGENTS_MASK GENMASK(15, 8) + +#define FIELD_GET (_mask, _reg)\ + ((typeof(_mask))(((_reg) & (_mask)) >> (ffs64(_mask) - 1))) +#define FIELD_PREP (_mask, _val)\ + (((typeof(_mask))(_val) << (ffs64(_mask) - 1)) & (_mask)) + +typedef struct scmi_msg_header { +uint8_t id; +uint8_t type; +uint8_t protocol; +}scmi_msg_header_t ; + +typedef struct scmi_perms_tx { +uint32_t agent_id; +uint32_t device_id; +uint32_t flags; +}scmi_perms_tx_t ; + +#define SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE BIT(0, UL) +#define SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR BIT(1, UL) + +#define SCMI_ALLOW_ACCESS BIT(0, UL) + +struct scmi_shared_mem { +uint32_t reserved; +uint32_t channel_status; +uint32_t reserved1[2 ]; +uint32_t flags; +uint32_t length; +uint32_t msg_header; +uint8_t msg_payload[]; +}; + +struct scmi_channel { +int chan_id; +int agent_id; +uint32_t func_id; +int domain_id; +uint64_t paddr; +struct scmi_shared_mem *shmem; +spinlock_t lock; +struct list_head list; +}; + +struct scmi_data { +struct list_head channel_list; +spinlock_t channel_list_lock; +bool initialized; +u64 shmem_addr, shmem_size; +}; + +static struct scmi_data scmi_data; + +/* +* pack_scmi_header() - packs and returns 32-bit header +* +* @hdr: pointer to header containing all the information on message id, +* protocol id and type id. +* +* Return: 32-bit packed message header to be sent to the platform. +*/ +static inline uint32_t pack_scmi_header (scmi_msg_header_t *hdr) +{ +return FIELD_PREP (HDR_ID , hdr->id) | +FIELD_PREP (HDR_TYPE , hdr->type) | +FIELD_PREP (HDR_PROTO , hdr->protocol); +} + +/* +* unpack_scmi_header() - unpacks and records message and protocol id +* +* @msg_hdr: 32-bit packed message header sent from the platform +* @hdr: pointer to header to fetch message and protocol id. +*/ +static inline void unpack_scmi_header (uint32_t msg_hdr,scmi_msg_header_t *hdr) +{ + hdr->id =FIELD_GET (HDR_ID , msg_hdr); + hdr->type =FIELD_GET (HDR_TYPE , msg_hdr); + hdr->protocol =FIELD_GET (HDR_PROTO , msg_hdr); +} +Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 154
Quoted 4 lines
xen/arch/arm/sci/scmi_smc.c new file +4
-0+static inline int channel_is_free (struct scmi_channel *chan_info) +{ +return ( chan_info->shmem->channel_status + &SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE ) ?0 : -EBUSY ;Does this need a memory barrier? Or not, because the other end always runs on the same CPU at a different execution level so the
channel_statuswould be always guaranteed to be read as updated?It don't because the other end runs on the same CPU. Other mediator implemetaions, which uses different areas may need memory barrier.
Quoted 22 lines
Quoted 22 lines
xen/arch/arm/sci/scmi_smc.c new file +21
-0+} + +static int send_smc_message (struct scmi_channel *chan_info, +scmi_msg_header_t *hdr,void *data,int len) +{ +struct arm_smccc_res resp; +int ret; + +printk (XENLOG_DEBUG "scmi: status =%d len=%d\n" , + chan_info->shmem->channel_status, len); +printk (XENLOG_DEBUG "scmi: header id = %d type = %d, proto = %d\n" , + hdr->id, hdr->type, hdr->protocol); + + ret =channel_is_free (chan_info); +if (IS_ERR_VALUE (ret) ) +return ret; + + chan_info->shmem->channel_status =0x0 ; +/* Writing 0x0 right now, but SCMI_SHMEM_FLAG_INTR_ENABLED can be set */ + chan_info->shmem->flags =0x0 ; + chan_info->shmem->length =sizeof (chan_info->shmem->msg_header) + len;Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 181
Quoted 6 lines
xen/arch/arm/sci/scmi_smc.c new file +6
-0+ chan_info->shmem->msg_header =pack_scmi_header (hdr); + +printk (XENLOG_DEBUG "scmi: Writing to shmem address %p\n" , + chan_info->shmem); +if ( len >0 && data ) +memcpy ((void *)(chan_info->shmem->msg_payload), data, len);Again, here we don't need a barrier because it is implicit in the SMC?
As I mentioned before, the other end runs on the same CPU.
Quoted 2 lines
Don't we need to check that "len" fits in the shared memory?
I think it's a good point. I'll add len check in v2.
Quoted 11 lines
xen/arch/arm/sci/scmi_smc.c line 189
Quoted 8 lines
xen/arch/arm/sci/scmi_smc.c new file +7
-0+arm_smccc_smc (chan_info->func_id,0 ,0 ,0 ,0 ,0 ,0 , chan_info->chan_id, + &resp); + +printk (XENLOG_DEBUG "scmi: scmccc_smc response %d\n" , (int )(resp.a0)); + +if ( resp.a0 ) +return -EOPNOTSUPP ;Why is that?
This change was presented in kernel by Sudeep Holla in commit:
f7199cf489027ae38a9a82312d13025f7aefa0b8However, link posted in the commit:
https://lore.kernel.org/r/[email protected]Leads to slightly different patch:
xen/arch/arm/sci/scmi_smc.c new file +5
-0+if (res.a0 ==SMCCC_RET_NOT_SUPPORTED ) +return -EOPNOTSUPP ; +else if (res.a0) +return -EINVAL ; +return 0 ;I don't know why it differs from the original commit, but I'll check and place the correct implementation in v2.
Quoted 45 lines
Quoted 45 lines
xen/arch/arm/sci/scmi_smc.c new file +44
-0+return 0 ; +} + +static int check_scmi_status (int scmi_status) +{ +if ( scmi_status ==SCMI_SUCCESS ) +return 0 ; + +printk (XENLOG_DEBUG "scmi: Error received: %d\n" , scmi_status); + +switch ( scmi_status ) + { +case SCMI_NOT_SUPPORTED : +return -EOPNOTSUPP ; +case SCMI_INVALID_PARAMETERS : +return -EINVAL ; +case SCMI_DENIED : +return -EACCES ; +case SCMI_NOT_FOUND : +return -ENOENT ; +case SCMI_OUT_OF_RANGE : +return -ERANGE ; +case SCMI_BUSY : +return -EBUSY ; +case SCMI_COMMS_ERROR : +return -ENOTCONN ; +case SCMI_GENERIC_ERROR : +return -EIO ; +case SCMI_HARDWARE_ERROR : +return -ENXIO ; +case SCMI_PROTOCOL_ERROR : +return -EBADMSG ; + } + +return -EINVAL ; +} + +static int get_smc_response (struct scmi_channel *chan_info, +scmi_msg_header_t *hdr,void *data,int len) +{ +int recv_len; +int ret; + +printk (XENLOG_DEBUG "scmi: get smc responce msgid %d\n" , hdr->id);Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 170
Quoted 4 lines
xen/arch/arm/sci/scmi_smc.c new file +4
-0+ + ret =channel_is_free (chan_info); +if (IS_ERR_VALUE (ret) ) +return ret;I am not familiar with the spec (do you have a link?) but is it expected that the channel is "free" when actually we want to read a message on the channel?
Quoted 4 lines
Here is the link https://developer.arm.com/documentation/den0056/latest
Figure 6 in Section 5.1.1.
Caller marks channel as busy, then callee process message and marks channel as free. We are implementing polling based communication flow.
OK
Quoted 124 lines
Quoted 49 lines
Quoted 49 lines
xen/arch/arm/sci/scmi_smc.c new file +49
-0+ recv_len = chan_info->shmem->length -sizeof (chan_info->shmem->msg_header); + +if ( recv_len <0 ) + { +printk (XENLOG_ERR +"scmi: Wrong size of smc message. Data may be invalid\n" ); +return -EINVAL ; + } + +if ( recv_len > len ) + { +printk (XENLOG_ERR +"scmi: Not enough buffer for message %d, expecting %d\n" , + recv_len, len); +return -EINVAL ; + } + +unpack_scmi_header (chan_info->shmem->msg_header, hdr); + +if ( recv_len >0 ) + { +memcpy (data, chan_info->shmem->msg_payload, recv_len); + } + +return 0 ; +} + +static int do_smc_xfer (struct scmi_channel *channel,scmi_msg_header_t *hdr,void *tx_data,int tx_size, +void *rx_data,int rx_size) +{ +int ret =0 ; + +if ( !hdr ) +return -EINVAL ; + +spin_lock (&channel->lock); + + ret =send_smc_message (channel, hdr, tx_data, tx_size); +if ( ret ) + goto clean; + + ret =get_smc_response (channel, hdr, rx_data, rx_size); +clean: +spin_unlock (&channel->lock); + +return ret; +} + +static struct scmi_channel *get_channel_by_id (uint8_t chan_id)Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 294
Quoted 6 lines
xen/arch/arm/sci/scmi_smc.c new file +6
-0+{ +struct scmi_channel *curr; +bool found = false; + +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry (curr, &scmi_data.channel_list, list)please use parenthesis around the inner if (also in other places)
Thank you for the remark. I will fix it in v2.
Quoted 17 lines
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +4
-0+if ( curr->chan_id == chan_id ) + { + found = true; +break ;xen/arch/arm/sci/scmi_smc.c line 308
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+ } + +spin_unlock (&scmi_data.channel_list_lock); +if ( found ) +return curr; + +return NULL ; +} + +static struct scmi_channel *get_channel_by_domain (uint8_t domain_id)Use
domid_tfor domain ids.Thanks, I will fix it in v2.
Quoted 7 lines
Also, wouldn't it be better to implement it as:
static inline struct scmi_channel *get_channel_by_domain(struct domain *d) { return d->arch.sci }That's a good point. I will take a look on it and fix in v2.
Quoted 26 lines
Quoted 26 lines
xen/arch/arm/sci/scmi_smc.c new file +25
-0+{ +struct scmi_channel *curr; +bool found = false; + +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry (curr, &scmi_data.channel_list, list) +if ( curr->domain_id == domain_id ) + { + found = true; +break ; + } + +spin_unlock (&scmi_data.channel_list_lock); +if ( found ) +return curr; + +return NULL ; +} + +static struct scmi_channel *aquire_scmi_channel (int domain_id) +{ +struct scmi_channel *curr; +bool found = false; + +ASSERT (domain_id !=DOMID_INVALID && domain_id >=0 );Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 338
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +5
-0+ +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry (curr, &scmi_data.channel_list, list) +if ( (curr->domain_id ==DOMID_INVALID ) + && (curr->chan_id !=HYP_CHANNEL ) )If you use
DOMID_XENforHYP_CHANNEL, then this check becomes more intuitive
Quoted 3 lines
We do not have direct relation between channel id and domain id. One channel id can be reused by different
domain_ids. So from my standpoint,DOMID_XENdoesn't fit here.
Below you wrote that you used DOMID_INVALID to mark a channel as free. That is fine, but then DOMID_INVALID shouldn't be used for HYP_CHANNEL because HYP_CHANNEL is not "free". In this function the check for curr->chan_id != HYP_CHANNEL should be unnecessary and I think the code would look as follows:
list_for_each_entry(curr, &scmi_data.channel_list, list)
{
if ( (curr->domain_id == DOMID_INVALID) )
{Quoted 185 lines
Quoted 11 lines
Quoted 11 lines
xen/arch/arm/sci/scmi_smc.c new file +11
-0+ { + curr->domain_id = domain_id; + found = true; +break ; + } + +spin_unlock (&scmi_data.channel_list_lock); +if ( found ) +return curr; + +return NULL ;Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 355
Quoted 6 lines
xen/arch/arm/sci/scmi_smc.c new file +6
-0+} + +static void relinquish_scmi_channel (struct scmi_channel *channel) +{ +spin_lock (&scmi_data.channel_list_lock); +ASSERT (channel !=NULL );the ASSERT could be before the
spin_lockThank you. I will fix it in v2.
Quoted 17 lines
Quoted 17 lines
xen/arch/arm/sci/scmi_smc.c new file +16
-0+ channel->domain_id =DOMID_INVALID ; +spin_unlock (&scmi_data.channel_list_lock); +} + +static struct scmi_channel *smc_create_channel (uint8_t chan_id, +uint32_t func_id,uint64_t addr) +{ +struct scmi_channel *channel; +mfn_t mfn; + + channel =get_channel_by_id (chan_id); +if ( channel ) +return ERR_PTR (EEXIST ); + + channel = xmalloc(struct scmi_channel); +if ( !channel )Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 376
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +5
-0+return ERR_PTR (ENOMEM ); + + channel->chan_id = chan_id; + channel->func_id = func_id; + channel->domain_id =DOMID_INVALID ;I take you are using
DOMID_INVALIDto mark a channel used by Xen itself? If so, thenDOMID_XENwould be more appropriate.I use
DOMID_INVALIDto mark channel as free.Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c line 378
Quoted 3 lines
xen/arch/arm/sci/scmi_smc.c new file +2
-0+ mfn =maddr_to_mfn (addr); + channel->shmem =vmap (&mfn,1 );One thing to be careful is the mapping attributes, for a couple of reasons. As you might be aware, the ARM architecture forbids mismatching attributes for mapping memory in different places in the system. So the attributes that we use here must be the same used by the firmware (and/or the guest.)
Quoted 6 lines
The second reason to be careful is that in the bindings example
Documentation/devicetree/bindings/firmware/arm,scmi.yamlthe shared memory is "mmio-sram", which is special. It is not supposed to be normal memory, but it is OK to map it cacheable. Still, it might be more appropriate to useioremap_cache.Originally, I used vmap here to have memcpy and it works fine in our setup. But I will do some research and email you with the results.
Quoted 34 lines
Quoted 34 lines
xen/arch/arm/sci/scmi_smc.c new file +33
-0+if ( !channel->shmem ) + { +xfree (channel); +return ERR_PTR (ENOMEM ); + } + +printk (XENLOG_DEBUG "scmi: Got shmem after vmap %p\n" , channel->shmem); + channel->paddr = addr; + channel->shmem->channel_status =SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE ; +spin_lock_init (&channel->lock); +spin_lock (&scmi_data.channel_list_lock); +list_add (&channel->list, &scmi_data.channel_list); +spin_unlock (&scmi_data.channel_list_lock); +return channel; +} + +static int map_memory_to_domain (struct domain *d,uint64_t addr,uint64_t len) +{ +return iomem_permit_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +} + +static int unmap_memory_from_domain (struct domain *d,uint64_t addr, +uint64_t len) +{ +return iomem_deny_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +} + +static int dt_update_domain_range (struct domain *d,uint64_t addr, +uint64_t size) +{ +struct dt_device_node *shmem_node;Quoted 8 lines
xen/arch/arm/sci/scmi_smc.c line 416
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +5
-0+__be32 *hw_reg; +const struct dt_property *pp; +uint32_t len; + + shmem_node =dt_find_compatible_node (NULL ,NULL ,"arm,scmi-shmem" );Here we are using "arm,scmi-shmem" while below we are checking for "linux,scmi_mem". What's the difference?
linux,scmi_mem (I posted nodes examples above) describes memory region, allocated for all channels, while arm,scmi-shmem points to the exact channel (page in linux,scmi_mem region).
Quoted 10 lines
Also, this function is looking for "arm,scmi-shmem" in
dt_hostand replaces its value. For dom0less domUs we'll probably need amake_scmi_nodefunction to create the node from scratch like for instance xen/arch/arm/domain_build.c:make_gic_domU_node.I wonder if we had such a function whether it wouldn't be better to also use it for dom0 (and blacklist the physical "arm,scmi-shmem" in
handle_nodeso that dom0 doesn't get the real shared memory information by accident).Thank you for the remark. I will rework this in v2.
Quoted 42 lines
Quoted 42 lines
xen/arch/arm/sci/scmi_smc.c new file +41
-0+ +if ( !shmem_node ) + { +printk (XENLOG_ERR "scmi: Unable to find %s node in DT\n" ,SCMI_SHMEM ); +return -EINVAL ; + } + + pp =dt_find_property (shmem_node,"reg" , &len); +if ( !pp ) + { +printk (XENLOG_ERR "scmi: Unable to find regs entry in shmem node\n" ); +return -ENOENT ; + } + + hw_reg = pp->value; +dt_set_range (&hw_reg, shmem_node, addr, size); + +return 0 ; +} + +static void free_channel_list (void ) +{ +struct scmi_channel *curr, *_curr; + +spin_lock (&scmi_data.channel_list_lock); + list_for_each_entry_safe (curr, _curr, &scmi_data.channel_list, list) + { +vunmap (curr->shmem); +list_del (&curr->list); +xfree (curr); + } + +spin_unlock (&scmi_data.channel_list_lock); +} + +static __init bool scmi_probe (struct dt_device_node *scmi_node) +{ +struct dt_device_node *shmem_node; +int ret, i; +struct scmi_channel *channel, *agent_channel; +int n_agents;Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 462
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +5
-0+scmi_msg_header_t hdr; +struct rx_t { +int32_t status; +uint32_t attributes; + } rx;Should rx be defined at the top together with
scmi_perms_tx_tand others?
Quoted 6 lines
I'd rather move
scmi_perms_tx_ttoscmi_add_device_by_devidbecause it's used only in 1 place.
So we will have rx and tx inscmi_add_device_by_devidand rx ( which differs from rx inscmi_add_device_by_devid) inscmi_probe. I think it will be more understandable and no need to make unique names. What do you think about that?
I think that's OK
Quoted 19 lines
Quoted 9 lines
Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c new file +9
-0+uint32_t func_id; + +ASSERT (scmi_node !=NULL ); + +INIT_LIST_HEAD (&scmi_data.channel_list); +spin_lock_init (&scmi_data.channel_list_lock); + +if ( !dt_property_read_u32 (scmi_node,SCMI_SMC_ID , &func_id) ) + {Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 477
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +5
-0+printk (XENLOG_ERR "scmi: Unable to read smc-id from DT\n" ); +return false; + } + + shmem_node =dt_find_node_by_name (NULL ,SCMI_SHARED_MEMORY );From the spec, it looks like you should be getting the shared memory area from the phandle list "shmem".
Quoted 3 lines
We use
SCMI_SHARED_MEMORYto get whole memory region (0x10pages in my case), we can use for the agents. As you can see below - Hypervisor received number of agents from Firmware and split this region between agents.
In general we can't use properties that are not part of the device tree spec, either https://www.devicetree.org/specifications/ or
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings
"linux,scmi_mem" is currently absent. Are you aware of any upstreaming activities to get "linux,scmi_mem" upstream under Documentation/devicetree/bindings in Linux?
If "linux,scmi_mem" is going upstream in Linux, then we could use it. Otherwise, first "linux,scmi_mem" needs to be added somewhere under Documentation/devicetree/bindings (probably Documentation/devicetree/bindings/firmware/arm,scmi.yaml), then we can work on the Xen code that makes use of it.
Does it make sense?
Quoted 42 lines
Quoted 32 lines
Quoted 32 lines
xen/arch/arm/sci/scmi_smc.c new file +32
-0+if (IS_ERR_OR_NULL (shmem_node) ) + { +printk (XENLOG_ERR +"scmi: Device tree error, can't parse shmem phandle %ld\n" , +PTR_ERR (shmem_node)); +return false; + } + + ret =dt_device_get_address (shmem_node,0 , &scmi_data.shmem_addr, + &scmi_data.shmem_size); +if (IS_ERR_VALUE (ret) ) +return false; + + channel =smc_create_channel (HYP_CHANNEL , func_id, scmi_data.shmem_addr); +if (IS_ERR (channel) ) +return false; + + hdr.id =SCMI_BASE_PROTOCOL_ATTIBUTES ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + ret =do_smc_xfer (channel, &hdr,NULL ,0 , &rx,sizeof (rx)); +if ( ret ) + goto clean; + + ret =check_scmi_status (rx.status); +if ( ret ) + goto clean; + + n_agents =FIELD_GET (MSG_N_AGENTS_MASK , rx.attributes); +printk (XENLOG_DEBUG "scmi: Got agent count %d\n" , n_agents); +Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 514
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +5
-0+ n_agents = (n_agents > scmi_data.shmem_size /PAGE_SIZE ) ? + scmi_data.shmem_size /PAGE_SIZE : n_agents; + +for ( i =1 ; i < n_agents; i++ ) + {Given that
HYP_CHANNELis actually zero, it looks like we could do everything here in this loop but starting from i=0?
Quoted 3 lines
We allocate
HYP_CHANNELbefore loop because we need it to request number of agents. And we don't need to sendSCMI_BASE_DISCOVER_AGENTtoHYP_CHANNEL.
OK
Quoted 96 lines
Quoted 87 lines
Quoted 66 lines
xen/arch/arm/sci/scmi_smc.c new file +66
-0+uint32_t tx_agent_id =0xFFFFFFFF ; +struct { +int32_t status; +uint32_t agent_id; +char name[16 ]; + } da_rx; + + agent_channel =smc_create_channel (i, func_id, scmi_data.shmem_addr + + i *PAGE_SIZE ); +if (IS_ERR (agent_channel) ) + { + ret =PTR_ERR (agent_channel); + goto clean; + } + + hdr.id =SCMI_BASE_DISCOVER_AGENT ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + ret =do_smc_xfer (agent_channel, &hdr, &tx_agent_id, +sizeof (tx_agent_id), &da_rx,sizeof (da_rx)); +if ( ret ) + goto clean; + + ret =check_scmi_status (da_rx.status); +if ( ret ) + goto clean; + +printk (XENLOG_DEBUG "scmi: status=0x%x id=0x%x name=%s\n" , + da_rx.status, da_rx.agent_id, da_rx.name); + + agent_channel->agent_id = da_rx.agent_id; + } + + scmi_data.initialized = true; +return true; + +clean: +free_channel_list (); +return ret ==0 ; +} + +static int scmi_domain_init (struct domain *d) +{ +struct scmi_channel *channel; +int ret; + +if ( !scmi_data.initialized ) +return 0 ; + + channel =aquire_scmi_channel (d->domain_id); +if (IS_ERR_OR_NULL (channel) ) +return -ENOENT ; + +printk (XENLOG_INFO "scmi: Aquire SCMI channel id = 0x%x , domain_id = %d" +"paddr = 0x%lx\n" , channel->chan_id, channel->domain_id, + channel->paddr); + +if (is_hardware_domain (d) ) + { + ret =map_memory_to_domain (d, scmi_data.shmem_addr, + scmi_data.shmem_size); +if (IS_ERR_VALUE (ret) ) + goto error; + + ret =dt_update_domain_range (d, channel->paddr,PAGE_SIZE );xen/arch/arm/sci/scmi_smc.c line 590
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+if (IS_ERR_VALUE (ret) ) + { +int rc =unmap_memory_from_domain (d, scmi_data.shmem_addr, + scmi_data.shmem_size); +if ( rc ) +printk (XENLOG_ERR "Unable to unmap_memory_from_domain\n" ); + + goto error; + } + }Is dom0 the only domain to get direct access to the shared memory region? If so, I don't think it is a good idea to make Dom0 "special" in this case.
Let me make an example: if we assign a device to a domU since boot, and dom0 wants to change the frequency of a clock that affects the assigned device (likely because it doesn't know it is assigned), then dom0 shouldn't be able to. We might have to perform checks in Xen to make sure dom0 cannot stop the clock for the assigned device.
Quoted 8 lines
So I think it would be better if all domains are treated the same way in the mediator unless really necessary.
On the other hand, if all domains get access to the shared memory region, then I don't think this is likely the right place to create the dom0 mapping. We probably want to do it in
domain_build.cin a way that can be reused for dom0less domUs.
Quoted 9 lines
The idea is that all domains have their own page in shared memory region and unigue
agent_id.Agent_idis used to set permissions for clocks\resets\power-domains etc. So during creation of domain (domUs or dom0) device-tree is processed usingscmi_add_dt_deviceand clocks\resets\power-domains which are related to dom0 devices will be requested by usingSCMI_BASE_SET_DEVICE_PERMISSIONSmessage. All passed-through devices will be requested during DomU creation. Which means dom0 do not have an access to clocks\resets\power-domains, which are related to DomU.
OK, excellent
Quoted 28 lines
Quoted 5 lines
In regards to shared memory: it looks like the only two functions to access the real shared memory are
send_smc_messageandget_smc_response. If that is the case, then we actually don't need to expose the real shared memory to any of the domains.Quoted 8 lines
We could simply:
- expose a regular normal memory region as dom0/domU channel memory
- on SMC trap, read from the "fake" shared memory and set the corresponding real shared memory on the appropriate channel
- issue the SMC call
- on return from SMC, copy over data from the real shared memory to the "fake" channel reagionHypervisor redirects only SMC calls from guests and set
agent_idto SMC parameters as a7. The idea was to give page for each agent, so we don't need to make additional read/write each time we receive SMC call. All we povide from hypervisor isagent_id. Firmware is responsible for reading memory from the correct address and place the response.Quoted 7 lines
This is useful if we need to "filter" any of the SCMI commands and options from the domains to the firmware, and also it is useful if the channel memory is not page aligned. But if the permissions are fine-grained enough and also the channel memory is page aligned (and multiple of 4K in size) then we could map the memory.
Quoted 4 lines
In current implementation we suppose that channel memory is page aligned. I think that Firmware should be responsible for permissions handling and "filtering", that's why permission calls were added to SCMI spec. I tried to make mediator as thin as possible.
OK. Can we check that the channel memory is page aligned at init time and throw an error if it is not the case?
Quoted 66 lines
Quoted 56 lines
Quoted 56 lines
xen/arch/arm/sci/scmi_smc.c new file +56
-0+ + d->arch.sci = channel; + +return 0 ; +error: +relinquish_scmi_channel (channel); + +return ret; +} + +static int scmi_add_device_by_devid (struct domain *d,uint32_t scmi_devid) +{ +struct scmi_channel *channel, *agent_channel; +scmi_msg_header_t hdr; +scmi_perms_tx_t tx; +struct rx_t { +int32_t status; +uint32_t attributes; + } rx; +int ret; + +if ( !scmi_data.initialized ) +return 0 ; + +printk (XENLOG_DEBUG "scmi: scmi_devid = %d\n" , scmi_devid); + + agent_channel =get_channel_by_domain (d->domain_id); +if (IS_ERR_OR_NULL (agent_channel) ) +return PTR_ERR (agent_channel); + + channel =get_channel_by_id (HYP_CHANNEL ); +if (IS_ERR_OR_NULL (channel) ) +return PTR_ERR (channel); + + hdr.id =SCMI_BASE_SET_DEVICE_PERMISSIONS ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + tx.agent_id = agent_channel->agent_id; + tx.device_id = scmi_devid; + tx.flags =SCMI_ALLOW_ACCESS ; + + ret =do_smc_xfer (channel, &hdr, &tx,sizeof (tx), &rx,sizeof (&rx)); +if (IS_ERR_VALUE (ret) ) +return ret; + + ret =check_scmi_status (rx.status); +if (IS_ERR_VALUE (ret) ) +return ret; + +return 0 ; +} + +static int scmi_add_dt_device (struct domain *d,struct dt_device_node *dev) +{ +uint32_t scmi_devid;Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 652
Quoted 6 lines
xen/arch/arm/sci/scmi_smc.c new file +6
-0+ +if ( (!scmi_data.initialized) || (!d->arch.sci) ) +return 0 ; + +if ( !dt_property_read_u32 (dev,"scmi_devid" , &scmi_devid) ) +return 0 ;
scmi_devidis another property that is not documented in the binding.
Quoted 5 lines
This property should be added to the device nodes, which are using scmi to work with clocks\resets\power-domains etc. This id should match the
device_id, defined in Firmware. Hypervisor send thisdevice_idto the Firmware as parameter to the permission request. Firmware set permissions to clocks\resets\power-domains, related to this device.
OK, I see. Unfortunately, scmi_devid is also not described under Documentation/devicetree/bindings/.
This property seems to be actually required for the system to work correctly.
Unless somebody else is already working on this, please send a patch to the Linux kernel mailing list CCing the SCMI maintainers and Rob Herring to introduce scmi_devid as a new property.
Quoted 117 lines
Quoted 107 lines
Quoted 107 lines
xen/arch/arm/sci/scmi_smc.c new file +107
-0+printk (XENLOG_INFO "scmi: dt_node = %s\n" ,dt_node_full_name (dev)); + +return scmi_add_device_by_devid (d, scmi_devid); +} + +static int scmi_relinquish_resources (struct domain *d) +{ +int ret; +struct scmi_channel *channel, *agent_channel; +scmi_msg_header_t hdr; +struct reset_agent_tx { +uint32_t agent_id; +uint32_t flags; + } tx; +uint32_t rx; + +if ( !d->arch.sci ) +return 0 ; + + agent_channel = d->arch.sci; + +spin_lock (&agent_channel->lock); + tx.agent_id = agent_channel->agent_id; +spin_unlock (&agent_channel->lock); + + channel =get_channel_by_id (HYP_CHANNEL ); +if ( !channel ) + { +printk (XENLOG_ERR +"scmi: Unable to get Hypervisor scmi channel for domain %d\n" , + d->domain_id); +return -EINVAL ; + } + + hdr.id =SCMI_BASE_RESET_AGENT_CONFIGURATION ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + tx.flags =0 ; + + ret =do_smc_xfer (channel, &hdr, &tx,sizeof (tx), &rx,sizeof (rx)); +if ( ret ) +return ret; + + ret =check_scmi_status (rx); + +return ret; +} + +static void scmi_domain_destroy (struct domain *d) +{ +struct scmi_channel *channel; + +if ( !d->arch.sci ) +return ; + + channel = d->arch.sci; +spin_lock (&channel->lock); + +relinquish_scmi_channel (channel); +printk (XENLOG_DEBUG "scmi: Free domain %d\n" , d->domain_id); + + d->arch.sci =NULL ; + +unmap_memory_from_domain (d, channel->paddr,PAGE_SIZE ); +spin_unlock (&channel->lock); +return ; +} + +static bool scmi_handle_call (struct domain *d,void *args) +{ +bool res = false; +struct scmi_channel *agent_channel; +struct arm_smccc_res resp; +struct cpu_user_regs *regs = args; + +if ( !d->arch.sci ) +return false; + + agent_channel = d->arch.sci; +spin_lock (&agent_channel->lock); + +if ( agent_channel->func_id != regs->x0 ) + { +printk (XENLOG_ERR "scmi: func_id mismatch, exiting\n" ); + goto unlock; + } + +arm_smccc_smc (agent_channel->func_id,0 ,0 ,0 ,0 ,0 ,0 , + agent_channel->chan_id, &resp); + +set_user_reg (regs,0 , resp.a0); +set_user_reg (regs,1 , resp.a1); +set_user_reg (regs,2 , resp.a2); +set_user_reg (regs,3 , resp.a3); + res = true; +unlock: +spin_unlock (&agent_channel->lock); + +return res; +} + +static int scmi_get_channel_paddr (void *scmi_ops, +struct xen_arch_domainconfig *config) +{ +struct scmi_channel *agent_channel = scmi_ops; +Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 766
Quoted 6 lines
xen/arch/arm/sci/scmi_smc.c new file +6
-0+if ( !agent_channel ) +return -EINVAL ; + + config->sci_agent_paddr = agent_channel->paddr; +return 0 ; +}I am still not sure why it couldn't be done by
scmi_domain_init.
Quoted 4 lines
I can move this logic to
scmi_domain_init, but in this case I have to add structxen_arch_domainconfig*config as input parameter toscmi_domain_initand pass NULL fromconstruct_dom0.
Do you think this approach would be better?
I think it is OK to pass struct xen_arch_domainconfig *config as input parameter to scmi_domain_init.
For dom0, why is sci_agent_paddr not supposed to be set?
Quoted 44 lines
Also I think it's reasonable to pass
xen_arch_domainconfigso different implementations could set another data they would probably need.Quoted 41 lines
Quoted 41 lines
xen/arch/arm/sci/scmi_smc.c new file +28
-0+static const struct dt_device_match scmi_smc_match[]__initconst = +{ +DT_MATCH_SCMI_SMC , + {/* sentinel */ }, +}; + +static const struct sci_mediator_ops scmi_ops = +{ + .probe = scmi_probe, + .domain_init = scmi_domain_init, + .domain_destroy = scmi_domain_destroy, + .add_dt_device = scmi_add_dt_device, + .relinquish_resources = scmi_relinquish_resources, + .handle_call = scmi_handle_call, + .get_channel_info = scmi_get_channel_paddr +}; + +REGISTER_SCI_MEDIATOR (scmi_smc,"SCMI-SMC" ,XEN_DOMCTL_CONFIG_SCI_SCMI_SMC , + scmi_smc_match, &scmi_ops); + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/public/arch-arm.h +1
-0@@ -315,6 +315,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);#define XEN_DOMCTL_CONFIG_TEE_OPTEE 1#define XEN_DOMCTL_CONFIG_SCI_NONE 0 +#define XEN_DOMCTL_CONFIG_SCI_SCMI_SMC 1struct xen_arch_domainconfig {/* IN/OUT */
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Hi Stefano,
Quoted 184 lines · Stefano Stabellini
Quoted 153 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 129 lines · Stefano Stabellini
Quoted 114 lines · Oleksii Moisieiev
This is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG.
The following features are implemented:
- request SCMI channels from ATF and pass channels to Domains;
- set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI;
- redirect scmi messages from Domains to ATF.Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 5 files changed, 809 insertions(+) create mode 100644 xen/arch/arm/sci/Kconfig create mode 100644 xen/arch/arm/sci/scmi_smc.cxen/arch/arm/Kconfig +2
-0@@ -114,6 +114,8 @@ config SCI support. It allows guests to control system resourcess via one of SCI mediators implemented in XEN. +source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/sci/Kconfig new file +10
-0@@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on SCI + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication.xen/arch/arm/sci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.oxen/arch/arm/sci/scmi_smc.c new file +49
-0@@ -0,0 +1,795 @@ +/* +* xen/arch/arm/sci/scmi_smc.c +* +* SCMI mediator driver, using SCP as transport. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/sci/sci.h> +#include <asm/smccc.h> +#include <asm/io.h> +#include <xen/bitops.h> +#include <xen/config.h> +#include <xen/sched.h> +#include <xen/device_tree.h> +#include <xen/iocap.h> +#include <xen/init.h> +#include <xen/err.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/string.h> +#include <xen/time.h> +#include <xen/vmap.h> + +#define SCMI_BASE_PROTOCOL 0x10 +#define SCMI_BASE_PROTOCOL_ATTIBUTES 0x1 +#define SCMI_BASE_SET_DEVICE_PERMISSIONS 0x9 +#define SCMI_BASE_RESET_AGENT_CONFIGURATION 0xB +#define SCMI_BASE_DISCOVER_AGENT 0x7 + +/* SCMI return codes. See section 4.1.4 of SCMI spec (DEN0056C) */ +#define SCMI_SUCCESS 0 +#define SCMI_NOT_SUPPORTED (-1) +#define SCMI_INVALID_PARAMETERS (-2) +#define SCMI_DENIED (-3) +#define SCMI_NOT_FOUND (-4) +#define SCMI_OUT_OF_RANGE (-5)xen/arch/arm/sci/scmi_smc.c line 59
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+#define SCMI_BUSY (-6) +#define SCMI_COMMS_ERROR (-7) +#define SCMI_GENERIC_ERROR (-8) +#define SCMI_HARDWARE_ERROR (-9) +#define SCMI_PROTOCOL_ERROR (-10) + +#define DT_MATCH_SCMI_SMC DT_MATCH_COMPATIBLE("arm,scmi-smc") + +#define SCMI_SMC_ID "arm,smc-id" +#define SCMI_SHARED_MEMORY "linux,scmi_mem"I could find the following SCMI binding in Linux, which describes the arm,scmi-smc compatible and the arm,smc-id property:
Quoted 6 lines
Documentation/devicetree/bindings/firmware/arm,scmi.yamlHowever, linux,scmi_mem is not described. Aren't you supposed to read the "shmem" property instead? And the compatible string used for this seems to be "arm,scmi-shmem".
We use linux,scmi_mem node to reserve memory, needed for all channels:
reserved-memory { /* reserved region for scmi channels*/ scmi_memory: linux,scmi_mem@53FF0000 { no-map; reg = <0x0 0x53FF0000 0x0 0x10000>; }; };arm,scmi-shmem node used in shmem property defines only 1 page needed to the current scmi channel:
Quoted 7 lines
cpu_scp_shm: scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; };For each Domain reg points to unigue page from linux,scmi_mem region, assigned to this agent.
If we were to use "linux,scmi_mem" we would have to introduce it as a compatible string, not as a node name, and it would need to be described in
Documentation/devicetree/bindings/firmware/arm,scmi.yaml.But from your description I don't think it is necessary. We can just use "arm,scmi-shmem" to describe all the required regions:
reserved-memory { scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; }; scp-shmem@0x53FF1000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF1000 0x0 0x1000>; }; scp-shmem@0x53FF2000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF2000 0x0 0x1000>; }; ...
Quoted 4 lines
In other words, if all the individual channel pages are described as "arm,scmi-shmem", why do we also need a single larger region as "linux,scmi_mem"?
That was my first implementation. But I've met a problem with
scmi driver in kernel. I don't remember the exact place, but I remember
there were some if, checking if memory weren't reserved.
That's why I ended up splitting nodes reserved memory region and actual
shmem page.
For linux,scmi_mem node I took format from /reserved-memory/linux,lossy_decompress@54000000, which has no compatible string and provides no-map property.
linux,scmi_shmem node is needed to prevent xen from allocating this
space for the domain.
Very interesting question about should I introduce linux,scmi_mem node and scmi_devid property to the Documentation/devicetree/bindings/firmware/arm,scmi.yaml? Those node and property are needed only for Xen and useless for non-virtualized systems. I can add this node and property description to arm,scmi.yaml, but leave a note that this is Xen specific params. What do you think about it?
Quoted 370 lines
Quoted 228 lines
Quoted 92 lines
Quoted 92 lines
xen/arch/arm/sci/scmi_smc.c new file +91
-0+#define SCMI_SHMEM "shmem" + +#define HYP_CHANNEL 0x0 + +#define HDR_ID GENMASK(7,0) +#define HDR_TYPE GENMASK(9, 8) +#define HDR_PROTO GENMASK(17, 10) + +/* SCMI protocol, refer to section 4.2.2.2 (DEN0056C) */ +#define MSG_N_AGENTS_MASK GENMASK(15, 8) + +#define FIELD_GET (_mask, _reg)\ + ((typeof(_mask))(((_reg) & (_mask)) >> (ffs64(_mask) - 1))) +#define FIELD_PREP (_mask, _val)\ + (((typeof(_mask))(_val) << (ffs64(_mask) - 1)) & (_mask)) + +typedef struct scmi_msg_header { +uint8_t id; +uint8_t type; +uint8_t protocol; +}scmi_msg_header_t ; + +typedef struct scmi_perms_tx { +uint32_t agent_id; +uint32_t device_id; +uint32_t flags; +}scmi_perms_tx_t ; + +#define SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE BIT(0, UL) +#define SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR BIT(1, UL) + +#define SCMI_ALLOW_ACCESS BIT(0, UL) + +struct scmi_shared_mem { +uint32_t reserved; +uint32_t channel_status; +uint32_t reserved1[2 ]; +uint32_t flags; +uint32_t length; +uint32_t msg_header; +uint8_t msg_payload[]; +}; + +struct scmi_channel { +int chan_id; +int agent_id; +uint32_t func_id; +int domain_id; +uint64_t paddr; +struct scmi_shared_mem *shmem; +spinlock_t lock; +struct list_head list; +}; + +struct scmi_data { +struct list_head channel_list; +spinlock_t channel_list_lock; +bool initialized; +u64 shmem_addr, shmem_size; +}; + +static struct scmi_data scmi_data; + +/* +* pack_scmi_header() - packs and returns 32-bit header +* +* @hdr: pointer to header containing all the information on message id, +* protocol id and type id. +* +* Return: 32-bit packed message header to be sent to the platform. +*/ +static inline uint32_t pack_scmi_header (scmi_msg_header_t *hdr) +{ +return FIELD_PREP (HDR_ID , hdr->id) | +FIELD_PREP (HDR_TYPE , hdr->type) | +FIELD_PREP (HDR_PROTO , hdr->protocol); +} + +/* +* unpack_scmi_header() - unpacks and records message and protocol id +* +* @msg_hdr: 32-bit packed message header sent from the platform +* @hdr: pointer to header to fetch message and protocol id. +*/ +static inline void unpack_scmi_header (uint32_t msg_hdr,scmi_msg_header_t *hdr) +{ + hdr->id =FIELD_GET (HDR_ID , msg_hdr); + hdr->type =FIELD_GET (HDR_TYPE , msg_hdr); + hdr->protocol =FIELD_GET (HDR_PROTO , msg_hdr); +} +Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 154
Quoted 4 lines
xen/arch/arm/sci/scmi_smc.c new file +4
-0+static inline int channel_is_free (struct scmi_channel *chan_info) +{ +return ( chan_info->shmem->channel_status + &SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE ) ?0 : -EBUSY ;Does this need a memory barrier? Or not, because the other end always runs on the same CPU at a different execution level so the
channel_statuswould be always guaranteed to be read as updated?It don't because the other end runs on the same CPU. Other mediator implemetaions, which uses different areas may need memory barrier.
Quoted 22 lines
Quoted 22 lines
xen/arch/arm/sci/scmi_smc.c new file +21
-0+} + +static int send_smc_message (struct scmi_channel *chan_info, +scmi_msg_header_t *hdr,void *data,int len) +{ +struct arm_smccc_res resp; +int ret; + +printk (XENLOG_DEBUG "scmi: status =%d len=%d\n" , + chan_info->shmem->channel_status, len); +printk (XENLOG_DEBUG "scmi: header id = %d type = %d, proto = %d\n" , + hdr->id, hdr->type, hdr->protocol); + + ret =channel_is_free (chan_info); +if (IS_ERR_VALUE (ret) ) +return ret; + + chan_info->shmem->channel_status =0x0 ; +/* Writing 0x0 right now, but SCMI_SHMEM_FLAG_INTR_ENABLED can be set */ + chan_info->shmem->flags =0x0 ; + chan_info->shmem->length =sizeof (chan_info->shmem->msg_header) + len;Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 181
Quoted 6 lines
xen/arch/arm/sci/scmi_smc.c new file +6
-0+ chan_info->shmem->msg_header =pack_scmi_header (hdr); + +printk (XENLOG_DEBUG "scmi: Writing to shmem address %p\n" , + chan_info->shmem); +if ( len >0 && data ) +memcpy ((void *)(chan_info->shmem->msg_payload), data, len);Again, here we don't need a barrier because it is implicit in the SMC?
As I mentioned before, the other end runs on the same CPU.
Quoted 2 lines
Don't we need to check that "len" fits in the shared memory?
I think it's a good point. I'll add len check in v2.
Quoted 11 lines
xen/arch/arm/sci/scmi_smc.c line 189
Quoted 8 lines
xen/arch/arm/sci/scmi_smc.c new file +7
-0+arm_smccc_smc (chan_info->func_id,0 ,0 ,0 ,0 ,0 ,0 , chan_info->chan_id, + &resp); + +printk (XENLOG_DEBUG "scmi: scmccc_smc response %d\n" , (int )(resp.a0)); + +if ( resp.a0 ) +return -EOPNOTSUPP ;Why is that?
This change was presented in kernel by Sudeep Holla in commit:
f7199cf489027ae38a9a82312d13025f7aefa0b8However, link posted in the commit:
https://urldefense.com/v3/__https://lore.kernel.org/r/[email protected]__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7Bnhb7jXoB3$ [lore[.]kernel[.]org]Leads to slightly different patch:
xen/arch/arm/sci/scmi_smc.c new file +5
-0+if (res.a0 ==SMCCC_RET_NOT_SUPPORTED ) +return -EOPNOTSUPP ; +else if (res.a0) +return -EINVAL ; +return 0 ;I don't know why it differs from the original commit, but I'll check and place the correct implementation in v2.
Quoted 45 lines
Quoted 45 lines
xen/arch/arm/sci/scmi_smc.c new file +44
-0+return 0 ; +} + +static int check_scmi_status (int scmi_status) +{ +if ( scmi_status ==SCMI_SUCCESS ) +return 0 ; + +printk (XENLOG_DEBUG "scmi: Error received: %d\n" , scmi_status); + +switch ( scmi_status ) + { +case SCMI_NOT_SUPPORTED : +return -EOPNOTSUPP ; +case SCMI_INVALID_PARAMETERS : +return -EINVAL ; +case SCMI_DENIED : +return -EACCES ; +case SCMI_NOT_FOUND : +return -ENOENT ; +case SCMI_OUT_OF_RANGE : +return -ERANGE ; +case SCMI_BUSY : +return -EBUSY ; +case SCMI_COMMS_ERROR : +return -ENOTCONN ; +case SCMI_GENERIC_ERROR : +return -EIO ; +case SCMI_HARDWARE_ERROR : +return -ENXIO ; +case SCMI_PROTOCOL_ERROR : +return -EBADMSG ; + } + +return -EINVAL ; +} + +static int get_smc_response (struct scmi_channel *chan_info, +scmi_msg_header_t *hdr,void *data,int len) +{ +int recv_len; +int ret; + +printk (XENLOG_DEBUG "scmi: get smc responce msgid %d\n" , hdr->id);Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 170
Quoted 4 lines
xen/arch/arm/sci/scmi_smc.c new file +4
-0+ + ret =channel_is_free (chan_info); +if (IS_ERR_VALUE (ret) ) +return ret;I am not familiar with the spec (do you have a link?) but is it expected that the channel is "free" when actually we want to read a message on the channel?
Quoted 4 lines
Here is the link https://urldefense.com/v3/__https://developer.arm.com/documentation/den0056/latest__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhRd1Yyp8$ [developer[.]arm[.]com] Figure 6 in Section 5.1.1.
Caller marks channel as busy, then callee process message and marks channel as free.
We are implementing polling based communication flow.OK
Quoted 124 lines
Quoted 49 lines
Quoted 49 lines
xen/arch/arm/sci/scmi_smc.c new file +49
-0+ recv_len = chan_info->shmem->length -sizeof (chan_info->shmem->msg_header); + +if ( recv_len <0 ) + { +printk (XENLOG_ERR +"scmi: Wrong size of smc message. Data may be invalid\n" ); +return -EINVAL ; + } + +if ( recv_len > len ) + { +printk (XENLOG_ERR +"scmi: Not enough buffer for message %d, expecting %d\n" , + recv_len, len); +return -EINVAL ; + } + +unpack_scmi_header (chan_info->shmem->msg_header, hdr); + +if ( recv_len >0 ) + { +memcpy (data, chan_info->shmem->msg_payload, recv_len); + } + +return 0 ; +} + +static int do_smc_xfer (struct scmi_channel *channel,scmi_msg_header_t *hdr,void *tx_data,int tx_size, +void *rx_data,int rx_size) +{ +int ret =0 ; + +if ( !hdr ) +return -EINVAL ; + +spin_lock (&channel->lock); + + ret =send_smc_message (channel, hdr, tx_data, tx_size); +if ( ret ) + goto clean; + + ret =get_smc_response (channel, hdr, rx_data, rx_size); +clean: +spin_unlock (&channel->lock); + +return ret; +} + +static struct scmi_channel *get_channel_by_id (uint8_t chan_id)Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 294
Quoted 6 lines
xen/arch/arm/sci/scmi_smc.c new file +6
-0+{ +struct scmi_channel *curr; +bool found = false; + +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry (curr, &scmi_data.channel_list, list)please use parenthesis around the inner if (also in other places)
Thank you for the remark. I will fix it in v2.
Quoted 17 lines
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +4
-0+if ( curr->chan_id == chan_id ) + { + found = true; +break ;xen/arch/arm/sci/scmi_smc.c line 308
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+ } + +spin_unlock (&scmi_data.channel_list_lock); +if ( found ) +return curr; + +return NULL ; +} + +static struct scmi_channel *get_channel_by_domain (uint8_t domain_id)Use
domid_tfor domain ids.Thanks, I will fix it in v2.
Quoted 7 lines
Also, wouldn't it be better to implement it as:
static inline struct scmi_channel *get_channel_by_domain(struct domain *d) { return d->arch.sci }That's a good point. I will take a look on it and fix in v2.
Quoted 26 lines
Quoted 26 lines
xen/arch/arm/sci/scmi_smc.c new file +25
-0+{ +struct scmi_channel *curr; +bool found = false; + +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry (curr, &scmi_data.channel_list, list) +if ( curr->domain_id == domain_id ) + { + found = true; +break ; + } + +spin_unlock (&scmi_data.channel_list_lock); +if ( found ) +return curr; + +return NULL ; +} + +static struct scmi_channel *aquire_scmi_channel (int domain_id) +{ +struct scmi_channel *curr; +bool found = false; + +ASSERT (domain_id !=DOMID_INVALID && domain_id >=0 );Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 338
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +5
-0+ +spin_lock (&scmi_data.channel_list_lock); +list_for_each_entry (curr, &scmi_data.channel_list, list) +if ( (curr->domain_id ==DOMID_INVALID ) + && (curr->chan_id !=HYP_CHANNEL ) )If you use
DOMID_XENforHYP_CHANNEL, then this check becomes more intuitiveQuoted 3 lines
We do not have direct relation between channel id and domain id. One channel id can be reused by different
domain_ids. So from my standpoint,DOMID_XENdoesn't fit here.Below you wrote that you used
DOMID_INVALIDto mark a channel as free. That is fine, but thenDOMID_INVALIDshouldn't be used forHYP_CHANNELbecauseHYP_CHANNELis not "free". In this function the check forcurr->chan_id!=HYP_CHANNELshould be unnecessary and I think the code would look as follows:
Quoted 5 lines
list_for_each_entry(curr, &scmi_data.channel_list, list)
{
if ( (curr->domain_id == DOMID_INVALID) )
{Oh, now I understood your point. Thank you for that.
I will use DOMID_XEN for HYP_CHANNEL and remove curr->chan_id != HYP_CHANNEL. This will be fixed in v2.
Quoted 227 lines
Quoted 186 lines
Quoted 12 lines
Quoted 12 lines
xen/arch/arm/sci/scmi_smc.c new file +11
-0+ { + curr->domain_id = domain_id; + found = true; +break ; + } + +spin_unlock (&scmi_data.channel_list_lock); +if ( found ) +return curr; + +return NULL ;Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 355
Quoted 6 lines
xen/arch/arm/sci/scmi_smc.c new file +6
-0+} + +static void relinquish_scmi_channel (struct scmi_channel *channel) +{ +spin_lock (&scmi_data.channel_list_lock); +ASSERT (channel !=NULL );the ASSERT could be before the
spin_lockThank you. I will fix it in v2.
Quoted 17 lines
Quoted 17 lines
xen/arch/arm/sci/scmi_smc.c new file +16
-0+ channel->domain_id =DOMID_INVALID ; +spin_unlock (&scmi_data.channel_list_lock); +} + +static struct scmi_channel *smc_create_channel (uint8_t chan_id, +uint32_t func_id,uint64_t addr) +{ +struct scmi_channel *channel; +mfn_t mfn; + + channel =get_channel_by_id (chan_id); +if ( channel ) +return ERR_PTR (EEXIST ); + + channel = xmalloc(struct scmi_channel); +if ( !channel )Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 376
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +5
-0+return ERR_PTR (ENOMEM ); + + channel->chan_id = chan_id; + channel->func_id = func_id; + channel->domain_id =DOMID_INVALID ;I take you are using
DOMID_INVALIDto mark a channel used by Xen itself? If so, thenDOMID_XENwould be more appropriate.I use
DOMID_INVALIDto mark channel as free.Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c line 378
Quoted 3 lines
xen/arch/arm/sci/scmi_smc.c new file +2
-0+ mfn =maddr_to_mfn (addr); + channel->shmem =vmap (&mfn,1 );One thing to be careful is the mapping attributes, for a couple of reasons. As you might be aware, the ARM architecture forbids mismatching attributes for mapping memory in different places in the system. So the attributes that we use here must be the same used by the firmware (and/or the guest.)
Quoted 6 lines
The second reason to be careful is that in the bindings example
Documentation/devicetree/bindings/firmware/arm,scmi.yamlthe shared memory is "mmio-sram", which is special. It is not supposed to be normal memory, but it is OK to map it cacheable. Still, it might be more appropriate to useioremap_cache.Originally, I used vmap here to have memcpy and it works fine in our setup. But I will do some research and email you with the results.
Quoted 34 lines
Quoted 34 lines
xen/arch/arm/sci/scmi_smc.c new file +33
-0+if ( !channel->shmem ) + { +xfree (channel); +return ERR_PTR (ENOMEM ); + } + +printk (XENLOG_DEBUG "scmi: Got shmem after vmap %p\n" , channel->shmem); + channel->paddr = addr; + channel->shmem->channel_status =SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE ; +spin_lock_init (&channel->lock); +spin_lock (&scmi_data.channel_list_lock); +list_add (&channel->list, &scmi_data.channel_list); +spin_unlock (&scmi_data.channel_list_lock); +return channel; +} + +static int map_memory_to_domain (struct domain *d,uint64_t addr,uint64_t len) +{ +return iomem_permit_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +} + +static int unmap_memory_from_domain (struct domain *d,uint64_t addr, +uint64_t len) +{ +return iomem_deny_access (d,paddr_to_pfn (addr), +paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +} + +static int dt_update_domain_range (struct domain *d,uint64_t addr, +uint64_t size) +{ +struct dt_device_node *shmem_node;Quoted 8 lines
xen/arch/arm/sci/scmi_smc.c line 416
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +5
-0+__be32 *hw_reg; +const struct dt_property *pp; +uint32_t len; + + shmem_node =dt_find_compatible_node (NULL ,NULL ,"arm,scmi-shmem" );Here we are using "arm,scmi-shmem" while below we are checking for "linux,scmi_mem". What's the difference?
linux,scmi_mem (I posted nodes examples above) describes memory region, allocated for all channels, while arm,scmi-shmem points to the exact channel (page in linux,scmi_mem region).
Quoted 10 lines
Also, this function is looking for "arm,scmi-shmem" in
dt_hostand replaces its value. For dom0less domUs we'll probably need amake_scmi_nodefunction to create the node from scratch like for instance xen/arch/arm/domain_build.c:make_gic_domU_node.I wonder if we had such a function whether it wouldn't be better to also use it for dom0 (and blacklist the physical "arm,scmi-shmem" in
handle_nodeso that dom0 doesn't get the real shared memory information by accident).Thank you for the remark. I will rework this in v2.
Quoted 42 lines
Quoted 42 lines
xen/arch/arm/sci/scmi_smc.c new file +41
-0+ +if ( !shmem_node ) + { +printk (XENLOG_ERR "scmi: Unable to find %s node in DT\n" ,SCMI_SHMEM ); +return -EINVAL ; + } + + pp =dt_find_property (shmem_node,"reg" , &len); +if ( !pp ) + { +printk (XENLOG_ERR "scmi: Unable to find regs entry in shmem node\n" ); +return -ENOENT ; + } + + hw_reg = pp->value; +dt_set_range (&hw_reg, shmem_node, addr, size); + +return 0 ; +} + +static void free_channel_list (void ) +{ +struct scmi_channel *curr, *_curr; + +spin_lock (&scmi_data.channel_list_lock); + list_for_each_entry_safe (curr, _curr, &scmi_data.channel_list, list) + { +vunmap (curr->shmem); +list_del (&curr->list); +xfree (curr); + } + +spin_unlock (&scmi_data.channel_list_lock); +} + +static __init bool scmi_probe (struct dt_device_node *scmi_node) +{ +struct dt_device_node *shmem_node; +int ret, i; +struct scmi_channel *channel, *agent_channel; +int n_agents;Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 462
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +5
-0+scmi_msg_header_t hdr; +struct rx_t { +int32_t status; +uint32_t attributes; + } rx;Should rx be defined at the top together with
scmi_perms_tx_tand others?Quoted 6 lines
I'd rather move
scmi_perms_tx_ttoscmi_add_device_by_devidbecause it's used only in 1 place.
So we will have rx and tx inscmi_add_device_by_devidand rx ( which differs from rx inscmi_add_device_by_devid) inscmi_probe. I think it will be more understandable and no need to make unique names. What do you think about that?I think that's OK
Quoted 19 lines
Quoted 9 lines
Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c new file +9
-0+uint32_t func_id; + +ASSERT (scmi_node !=NULL ); + +INIT_LIST_HEAD (&scmi_data.channel_list); +spin_lock_init (&scmi_data.channel_list_lock); + +if ( !dt_property_read_u32 (scmi_node,SCMI_SMC_ID , &func_id) ) + {Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 477
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +5
-0+printk (XENLOG_ERR "scmi: Unable to read smc-id from DT\n" ); +return false; + } + + shmem_node =dt_find_node_by_name (NULL ,SCMI_SHARED_MEMORY );From the spec, it looks like you should be getting the shared memory area from the phandle list "shmem".
Quoted 3 lines
We use
SCMI_SHARED_MEMORYto get whole memory region (0x10pages in my case), we can use for the agents. As you can see below - Hypervisor received number of agents from Firmware and split this region between agents.In general we can't use properties that are not part of the device tree
spec, either https://urldefense.com/v3/__https://www.devicetree.org/specifications/__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXCSnJPN$ [devicetree[.]org] orhttps://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXloYUaj$ [git[.]kernel[.]org]"linux,scmi_mem" is currently absent. Are you aware of any upstreaming activities to get "linux,scmi_mem" upstream under
Documentation/devicetree/bindingsin Linux?
Quoted 8 lines
If "linux,scmi_mem" is going upstream in Linux, then we could use it. Otherwise, first "linux,scmi_mem" needs to be added somewhere under
Documentation/devicetree/bindings(probablyDocumentation/devicetree/bindings/firmware/arm,scmi.yaml), then we can work on the Xen code that makes use of it.Does it make sense?
Yes I agree. I think linux,scmi_mem and scmi_devid should be upstreamed.
I will add those properties to arm,scmi.yaml, mark them as related to XEN and send patch.
Quoted 187 lines
Quoted 43 lines
Quoted 33 lines
Quoted 33 lines
xen/arch/arm/sci/scmi_smc.c new file +32
-0+if (IS_ERR_OR_NULL (shmem_node) ) + { +printk (XENLOG_ERR +"scmi: Device tree error, can't parse shmem phandle %ld\n" , +PTR_ERR (shmem_node)); +return false; + } + + ret =dt_device_get_address (shmem_node,0 , &scmi_data.shmem_addr, + &scmi_data.shmem_size); +if (IS_ERR_VALUE (ret) ) +return false; + + channel =smc_create_channel (HYP_CHANNEL , func_id, scmi_data.shmem_addr); +if (IS_ERR (channel) ) +return false; + + hdr.id =SCMI_BASE_PROTOCOL_ATTIBUTES ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + ret =do_smc_xfer (channel, &hdr,NULL ,0 , &rx,sizeof (rx)); +if ( ret ) + goto clean; + + ret =check_scmi_status (rx.status); +if ( ret ) + goto clean; + + n_agents =FIELD_GET (MSG_N_AGENTS_MASK , rx.attributes); +printk (XENLOG_DEBUG "scmi: Got agent count %d\n" , n_agents); +Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 514
Quoted 5 lines
xen/arch/arm/sci/scmi_smc.c new file +5
-0+ n_agents = (n_agents > scmi_data.shmem_size /PAGE_SIZE ) ? + scmi_data.shmem_size /PAGE_SIZE : n_agents; + +for ( i =1 ; i < n_agents; i++ ) + {Given that
HYP_CHANNELis actually zero, it looks like we could do everything here in this loop but starting from i=0?Quoted 3 lines
We allocate
HYP_CHANNELbefore loop because we need it to request number of agents. And we don't need to sendSCMI_BASE_DISCOVER_AGENTtoHYP_CHANNEL.OK
Quoted 96 lines
Quoted 87 lines
Quoted 66 lines
xen/arch/arm/sci/scmi_smc.c new file +66
-0+uint32_t tx_agent_id =0xFFFFFFFF ; +struct { +int32_t status; +uint32_t agent_id; +char name[16 ]; + } da_rx; + + agent_channel =smc_create_channel (i, func_id, scmi_data.shmem_addr + + i *PAGE_SIZE ); +if (IS_ERR (agent_channel) ) + { + ret =PTR_ERR (agent_channel); + goto clean; + } + + hdr.id =SCMI_BASE_DISCOVER_AGENT ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + ret =do_smc_xfer (agent_channel, &hdr, &tx_agent_id, +sizeof (tx_agent_id), &da_rx,sizeof (da_rx)); +if ( ret ) + goto clean; + + ret =check_scmi_status (da_rx.status); +if ( ret ) + goto clean; + +printk (XENLOG_DEBUG "scmi: status=0x%x id=0x%x name=%s\n" , + da_rx.status, da_rx.agent_id, da_rx.name); + + agent_channel->agent_id = da_rx.agent_id; + } + + scmi_data.initialized = true; +return true; + +clean: +free_channel_list (); +return ret ==0 ; +} + +static int scmi_domain_init (struct domain *d) +{ +struct scmi_channel *channel; +int ret; + +if ( !scmi_data.initialized ) +return 0 ; + + channel =aquire_scmi_channel (d->domain_id); +if (IS_ERR_OR_NULL (channel) ) +return -ENOENT ; + +printk (XENLOG_INFO "scmi: Aquire SCMI channel id = 0x%x , domain_id = %d" +"paddr = 0x%lx\n" , channel->chan_id, channel->domain_id, + channel->paddr); + +if (is_hardware_domain (d) ) + { + ret =map_memory_to_domain (d, scmi_data.shmem_addr, + scmi_data.shmem_size); +if (IS_ERR_VALUE (ret) ) + goto error; + + ret =dt_update_domain_range (d, channel->paddr,PAGE_SIZE );xen/arch/arm/sci/scmi_smc.c line 590
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+if (IS_ERR_VALUE (ret) ) + { +int rc =unmap_memory_from_domain (d, scmi_data.shmem_addr, + scmi_data.shmem_size); +if ( rc ) +printk (XENLOG_ERR "Unable to unmap_memory_from_domain\n" ); + + goto error; + } + }Is dom0 the only domain to get direct access to the shared memory region? If so, I don't think it is a good idea to make Dom0 "special" in this case.
Let me make an example: if we assign a device to a domU since boot, and dom0 wants to change the frequency of a clock that affects the assigned device (likely because it doesn't know it is assigned), then dom0 shouldn't be able to. We might have to perform checks in Xen to make sure dom0 cannot stop the clock for the assigned device.
Quoted 8 lines
So I think it would be better if all domains are treated the same way in the mediator unless really necessary.
On the other hand, if all domains get access to the shared memory region, then I don't think this is likely the right place to create the dom0 mapping. We probably want to do it in
domain_build.cin a way that can be reused for dom0less domUs.Quoted 9 lines
The idea is that all domains have their own page in shared memory region and unigue
agent_id.Agent_idis used to set permissions for clocks\resets\power-domains etc. So during creation of domain (domUs or dom0) device-tree is processed usingscmi_add_dt_deviceand clocks\resets\power-domains which are related to dom0 devices will be requested by usingSCMI_BASE_SET_DEVICE_PERMISSIONSmessage. All passed-through devices will be requested during DomU creation. Which means dom0 do not have an access to clocks\resets\power-domains, which are related to DomU.OK, excellent
Quoted 28 lines
Quoted 5 lines
In regards to shared memory: it looks like the only two functions to access the real shared memory are
send_smc_messageandget_smc_response. If that is the case, then we actually don't need to expose the real shared memory to any of the domains.Quoted 8 lines
We could simply:
- expose a regular normal memory region as dom0/domU channel memory
- on SMC trap, read from the "fake" shared memory and set the corresponding real shared memory on the appropriate channel
- issue the SMC call
- on return from SMC, copy over data from the real shared memory to the "fake" channel reagionHypervisor redirects only SMC calls from guests and set
agent_idto SMC parameters as a7. The idea was to give page for each agent, so we don't need to make additional read/write each time we receive SMC call. All we povide from hypervisor isagent_id. Firmware is responsible for reading memory from the correct address and place the response.Quoted 7 lines
This is useful if we need to "filter" any of the SCMI commands and options from the domains to the firmware, and also it is useful if the channel memory is not page aligned. But if the permissions are fine-grained enough and also the channel memory is page aligned (and multiple of 4K in size) then we could map the memory.
Quoted 8 lines
Quoted 4 lines
In current implementation we suppose that channel memory is page aligned. I think that Firmware should be responsible for permissions handling and "filtering", that's why permission calls were added to SCMI spec. I tried to make mediator as thin as possible.
OK. Can we check that the channel memory is page aligned at init time and throw an error if it is not the case?
Yes. I will add this check in v2.
Quoted 76 lines
Quoted 67 lines
Quoted 57 lines
Quoted 57 lines
xen/arch/arm/sci/scmi_smc.c new file +56
-0+ + d->arch.sci = channel; + +return 0 ; +error: +relinquish_scmi_channel (channel); + +return ret; +} + +static int scmi_add_device_by_devid (struct domain *d,uint32_t scmi_devid) +{ +struct scmi_channel *channel, *agent_channel; +scmi_msg_header_t hdr; +scmi_perms_tx_t tx; +struct rx_t { +int32_t status; +uint32_t attributes; + } rx; +int ret; + +if ( !scmi_data.initialized ) +return 0 ; + +printk (XENLOG_DEBUG "scmi: scmi_devid = %d\n" , scmi_devid); + + agent_channel =get_channel_by_domain (d->domain_id); +if (IS_ERR_OR_NULL (agent_channel) ) +return PTR_ERR (agent_channel); + + channel =get_channel_by_id (HYP_CHANNEL ); +if (IS_ERR_OR_NULL (channel) ) +return PTR_ERR (channel); + + hdr.id =SCMI_BASE_SET_DEVICE_PERMISSIONS ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + tx.agent_id = agent_channel->agent_id; + tx.device_id = scmi_devid; + tx.flags =SCMI_ALLOW_ACCESS ; + + ret =do_smc_xfer (channel, &hdr, &tx,sizeof (tx), &rx,sizeof (&rx)); +if (IS_ERR_VALUE (ret) ) +return ret; + + ret =check_scmi_status (rx.status); +if (IS_ERR_VALUE (ret) ) +return ret; + +return 0 ; +} + +static int scmi_add_dt_device (struct domain *d,struct dt_device_node *dev) +{ +uint32_t scmi_devid;Quoted 9 lines
xen/arch/arm/sci/scmi_smc.c line 652
Quoted 6 lines
xen/arch/arm/sci/scmi_smc.c new file +6
-0+ +if ( (!scmi_data.initialized) || (!d->arch.sci) ) +return 0 ; + +if ( !dt_property_read_u32 (dev,"scmi_devid" , &scmi_devid) ) +return 0 ;
scmi_devidis another property that is not documented in the binding.Quoted 5 lines
This property should be added to the device nodes, which are using scmi to work with clocks\resets\power-domains etc. This id should match the
device_id, defined in Firmware. Hypervisor send thisdevice_idto the Firmware as parameter to the permission request. Firmware set permissions to clocks\resets\power-domains, related to this device.OK, I see. Unfortunately,
scmi_devidis also not described underDocumentation/devicetree/bindings/.
Quoted 7 lines
This property seems to be actually required for the system to work correctly.
Unless somebody else is already working on this, please send a patch to the Linux kernel mailing list CCing the SCMI maintainers and Rob Herring to introduce
scmi_devidas a new property.
I will prepare and send patch introducing scmi_devid and linux,scmi_mem.
Quoted 118 lines
Quoted 118 lines
Quoted 117 lines
Quoted 104 lines
xen/arch/arm/sci/scmi_smc.c new file +103
-0+printk (XENLOG_INFO "scmi: dt_node = %s\n" ,dt_node_full_name (dev)); + +return scmi_add_device_by_devid (d, scmi_devid); +} + +static int scmi_relinquish_resources (struct domain *d) +{ +int ret; +struct scmi_channel *channel, *agent_channel; +scmi_msg_header_t hdr; +struct reset_agent_tx { +uint32_t agent_id; +uint32_t flags; + } tx; +uint32_t rx; + +if ( !d->arch.sci ) +return 0 ; + + agent_channel = d->arch.sci; + +spin_lock (&agent_channel->lock); + tx.agent_id = agent_channel->agent_id; +spin_unlock (&agent_channel->lock); + + channel =get_channel_by_id (HYP_CHANNEL ); +if ( !channel ) + { +printk (XENLOG_ERR +"scmi: Unable to get Hypervisor scmi channel for domain %d\n" , + d->domain_id); +return -EINVAL ; + } + + hdr.id =SCMI_BASE_RESET_AGENT_CONFIGURATION ; + hdr.type =0 ; + hdr.protocol =SCMI_BASE_PROTOCOL ; + + tx.flags =0 ; + + ret =do_smc_xfer (channel, &hdr, &tx,sizeof (tx), &rx,sizeof (rx)); +if ( ret ) +return ret; + + ret =check_scmi_status (rx); + +return ret; +} + +static void scmi_domain_destroy (struct domain *d) +{ +struct scmi_channel *channel; + +if ( !d->arch.sci ) +return ; + + channel = d->arch.sci; +spin_lock (&channel->lock); + +relinquish_scmi_channel (channel); +printk (XENLOG_DEBUG "scmi: Free domain %d\n" , d->domain_id); + + d->arch.sci =NULL ; + +unmap_memory_from_domain (d, channel->paddr,PAGE_SIZE ); +spin_unlock (&channel->lock); +return ; +} + +static bool scmi_handle_call (struct domain *d,void *args) +{ +bool res = false; +struct scmi_channel *agent_channel; +struct arm_smccc_res resp; +struct cpu_user_regs *regs = args; + +if ( !d->arch.sci ) +return false; + + agent_channel = d->arch.sci; +spin_lock (&agent_channel->lock); + +if ( agent_channel->func_id != regs->x0 ) + { +printk (XENLOG_ERR "scmi: func_id mismatch, exiting\n" ); + goto unlock; + } + +arm_smccc_smc (agent_channel->func_id,0 ,0 ,0 ,0 ,0 ,0 , + agent_channel->chan_id, &resp); + +set_user_reg (regs,0 , resp.a0); +set_user_reg (regs,1 , resp.a1); +set_user_reg (regs,2 , resp.a2); +set_user_reg (regs,3 , resp.a3); + res = true; +unlock: +spin_unlock (&agent_channel->lock); + +return res; +} + +static int scmi_get_channel_paddr(void *scmi_ops,xen/arch/arm/sci/scmi_smc.c line 766
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+ struct xen_arch_domainconfig *config) +{ +struct scmi_channel *agent_channel = scmi_ops; + +if ( !agent_channel ) +return -EINVAL ; + + config->sci_agent_paddr = agent_channel->paddr; +return 0 ; +}I am still not sure why it couldn't be done by
scmi_domain_init.
Quoted 7 lines
Quoted 4 lines
I can move this logic to
scmi_domain_init, but in this case I have to add structxen_arch_domainconfig*config as input parameter toscmi_domain_initand pass NULL fromconstruct_dom0.
Do you think this approach would be better?I think it is OK to pass struct
xen_arch_domainconfig*config as input parameter toscmi_domain_init.
Ok, I will fix it in v2.
Quoted 3 lines
For dom0, why is
sci_agent_paddrnot supposed to be set?
paddr is the channel address. We need this address to update reg address of arm,scmi-shmem node in guest device-tree, so guest scmi driver will use shmem related to it.
Quoted 46 lines
Quoted 46 lines
Also I think it's reasonable to pass
xen_arch_domainconfigso different implementations could set another data they would probably need.Quoted 41 lines
Quoted 41 lines
xen/arch/arm/sci/scmi_smc.c new file +28
-0+static const struct dt_device_match scmi_smc_match[]__initconst = +{ +DT_MATCH_SCMI_SMC , + {/* sentinel */ }, +}; + +static const struct sci_mediator_ops scmi_ops = +{ + .probe = scmi_probe, + .domain_init = scmi_domain_init, + .domain_destroy = scmi_domain_destroy, + .add_dt_device = scmi_add_dt_device, + .relinquish_resources = scmi_relinquish_resources, + .handle_call = scmi_handle_call, + .get_channel_info = scmi_get_channel_paddr +}; + +REGISTER_SCI_MEDIATOR (scmi_smc,"SCMI-SMC" ,XEN_DOMCTL_CONFIG_SCI_SCMI_SMC , + scmi_smc_match, &scmi_ops); + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/public/arch-arm.h +1
-0@@ -315,6 +315,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);#define XEN_DOMCTL_CONFIG_TEE_OPTEE 1#define XEN_DOMCTL_CONFIG_SCI_NONE 0 +#define XEN_DOMCTL_CONFIG_SCI_SCMI_SMC 1struct xen_arch_domainconfig {/* IN/OUT */
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Quoted 202 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 184 lines · Stefano Stabellini
Quoted 153 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 129 lines · Stefano Stabellini
Quoted 114 lines · Oleksii Moisieiev
This is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG.
The following features are implemented:
- request SCMI channels from ATF and pass channels to Domains;
- set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI;
- redirect scmi messages from Domains to ATF.Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 5 files changed, 809 insertions(+) create mode 100644 xen/arch/arm/sci/Kconfig create mode 100644 xen/arch/arm/sci/scmi_smc.cxen/arch/arm/Kconfig +2
-0@@ -114,6 +114,8 @@ config SCI support. It allows guests to control system resourcess via one of SCI mediators implemented in XEN. +source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/sci/Kconfig new file +10
-0@@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on SCI + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication.xen/arch/arm/sci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.oxen/arch/arm/sci/scmi_smc.c new file +49
-0@@ -0,0 +1,795 @@ +/* +* xen/arch/arm/sci/scmi_smc.c +* +* SCMI mediator driver, using SCP as transport. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/sci/sci.h> +#include <asm/smccc.h> +#include <asm/io.h> +#include <xen/bitops.h> +#include <xen/config.h> +#include <xen/sched.h> +#include <xen/device_tree.h> +#include <xen/iocap.h> +#include <xen/init.h> +#include <xen/err.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/string.h> +#include <xen/time.h> +#include <xen/vmap.h> + +#define SCMI_BASE_PROTOCOL 0x10 +#define SCMI_BASE_PROTOCOL_ATTIBUTES 0x1 +#define SCMI_BASE_SET_DEVICE_PERMISSIONS 0x9 +#define SCMI_BASE_RESET_AGENT_CONFIGURATION 0xB +#define SCMI_BASE_DISCOVER_AGENT 0x7 + +/* SCMI return codes. See section 4.1.4 of SCMI spec (DEN0056C) */ +#define SCMI_SUCCESS 0 +#define SCMI_NOT_SUPPORTED (-1) +#define SCMI_INVALID_PARAMETERS (-2) +#define SCMI_DENIED (-3) +#define SCMI_NOT_FOUND (-4) +#define SCMI_OUT_OF_RANGE (-5)xen/arch/arm/sci/scmi_smc.c line 59
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+#define SCMI_BUSY (-6) +#define SCMI_COMMS_ERROR (-7) +#define SCMI_GENERIC_ERROR (-8) +#define SCMI_HARDWARE_ERROR (-9) +#define SCMI_PROTOCOL_ERROR (-10) + +#define DT_MATCH_SCMI_SMC DT_MATCH_COMPATIBLE("arm,scmi-smc") + +#define SCMI_SMC_ID "arm,smc-id" +#define SCMI_SHARED_MEMORY "linux,scmi_mem"I could find the following SCMI binding in Linux, which describes the arm,scmi-smc compatible and the arm,smc-id property:
Quoted 6 lines
Documentation/devicetree/bindings/firmware/arm,scmi.yamlHowever, linux,scmi_mem is not described. Aren't you supposed to read the "shmem" property instead? And the compatible string used for this seems to be "arm,scmi-shmem".
We use linux,scmi_mem node to reserve memory, needed for all channels:
reserved-memory { /* reserved region for scmi channels*/ scmi_memory: linux,scmi_mem@53FF0000 { no-map; reg = <0x0 0x53FF0000 0x0 0x10000>; }; };arm,scmi-shmem node used in shmem property defines only 1 page needed to the current scmi channel:
Quoted 7 lines
cpu_scp_shm: scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; };For each Domain reg points to unigue page from linux,scmi_mem region, assigned to this agent.
If we were to use "linux,scmi_mem" we would have to introduce it as a compatible string, not as a node name, and it would need to be described in
Documentation/devicetree/bindings/firmware/arm,scmi.yaml.But from your description I don't think it is necessary. We can just use "arm,scmi-shmem" to describe all the required regions:
reserved-memory { scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; }; scp-shmem@0x53FF1000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF1000 0x0 0x1000>; }; scp-shmem@0x53FF2000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF2000 0x0 0x1000>; }; ...Quoted 4 lines
In other words, if all the individual channel pages are described as "arm,scmi-shmem", why do we also need a single larger region as "linux,scmi_mem"?
That was my first implementation. But I've met a problem with
scmi driver in kernel. I don't remember the exact place, but I remember
there were some if, checking if memory weren't reserved.
That's why I ended up splitting nodes reserved memory region and actual
shmem page.
For linux,scmi_mem node I took format from /reserved-memory/linux,lossy_decompress@54000000, which has no compatible string and provides no-map property.
linux,scmi_shmem node is needed to prevent xen from allocating this
space for the domain.
Quoted 7 lines
Very interesting question about should I introduce linux,scmi_mem node and
scmi_devidproperty to theDocumentation/devicetree/bindings/firmware/arm,scmi.yaml? Those node and property are needed only for Xen and useless for non-virtualized systems. I can add this node and property description to arm,scmi.yaml, but leave a note that this is Xen specific params. What do you think about it?
Reply below
[...]
Quoted 14 lines
Quoted 14 lines
In general we can't use properties that are not part of the device tree
spec, either https://urldefense.com/v3/__https://www.devicetree.org/specifications/__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXCSnJPN$ [devicetree[.]org] orhttps://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXloYUaj$ [git[.]kernel[.]org]"linux,scmi_mem" is currently absent. Are you aware of any upstreaming activities to get "linux,scmi_mem" upstream under
Documentation/devicetree/bindingsin Linux?If "linux,scmi_mem" is going upstream in Linux, then we could use it. Otherwise, first "linux,scmi_mem" needs to be added somewhere under
Documentation/devicetree/bindings(probablyDocumentation/devicetree/bindings/firmware/arm,scmi.yaml), then we can work on the Xen code that makes use of it.
Quoted 5 lines
Quoted 2 lines
Does it make sense?
Yes I agree. I think linux,scmi_mem and
scmi_devidshould be upstreamed.
I will add those properties to arm,scmi.yaml, mark them as related to XEN and send patch.
I didn't realize that linux,scmi_mem and scmi_devid are supposed to be Xen specific. In general, it would be best not to introduce Xen specific properties into generic bindings. It is a problem both from a specification perspective (because it has hard to handle Xen specific cases in fully generic bindings, especially as those bindings are maintained as part of the Linux kernel) and from a user perspective (because now the user has to deal with a Xen-specific dtb, or has to modify the host dtb to add Xen-specific information by hand.)
Let me start from scmi_devid. Why would scmi_devid be Xen-specific? It looks like a generic property that should be needed for the Linux SCMI driver too. Why the Linux driver doesn't need it?
In regards to linux,scmi_mem, I think it would be best to do without it and fix the Linux SCMI driver if we need to do so. Xen should be able to parse the native "arm,scmi-shmem" nodes and Linux (dom0 or domU) should be able to parse the "arm,scmi-shmem" nodes generated by Xen. Either way, I don't think we should need linux,scmi_mem.
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Quoted 246 lines · Stefano Stabellini
Quoted 202 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 184 lines · Stefano Stabellini
Quoted 153 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 129 lines · Stefano Stabellini
Quoted 114 lines · Oleksii Moisieiev
This is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG.
The following features are implemented:
- request SCMI channels from ATF and pass channels to Domains;
- set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI;
- redirect scmi messages from Domains to ATF.Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 5 files changed, 809 insertions(+) create mode 100644 xen/arch/arm/sci/Kconfig create mode 100644 xen/arch/arm/sci/scmi_smc.cxen/arch/arm/Kconfig +2
-0@@ -114,6 +114,8 @@ config SCI support. It allows guests to control system resourcess via one of SCI mediators implemented in XEN. +source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/sci/Kconfig new file +10
-0@@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on SCI + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication.xen/arch/arm/sci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.oxen/arch/arm/sci/scmi_smc.c new file +49
-0@@ -0,0 +1,795 @@ +/* +* xen/arch/arm/sci/scmi_smc.c +* +* SCMI mediator driver, using SCP as transport. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/sci/sci.h> +#include <asm/smccc.h> +#include <asm/io.h> +#include <xen/bitops.h> +#include <xen/config.h> +#include <xen/sched.h> +#include <xen/device_tree.h> +#include <xen/iocap.h> +#include <xen/init.h> +#include <xen/err.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/string.h> +#include <xen/time.h> +#include <xen/vmap.h> + +#define SCMI_BASE_PROTOCOL 0x10 +#define SCMI_BASE_PROTOCOL_ATTIBUTES 0x1 +#define SCMI_BASE_SET_DEVICE_PERMISSIONS 0x9 +#define SCMI_BASE_RESET_AGENT_CONFIGURATION 0xB +#define SCMI_BASE_DISCOVER_AGENT 0x7 + +/* SCMI return codes. See section 4.1.4 of SCMI spec (DEN0056C) */ +#define SCMI_SUCCESS 0 +#define SCMI_NOT_SUPPORTED (-1) +#define SCMI_INVALID_PARAMETERS (-2) +#define SCMI_DENIED (-3) +#define SCMI_NOT_FOUND (-4) +#define SCMI_OUT_OF_RANGE (-5)xen/arch/arm/sci/scmi_smc.c line 59
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+#define SCMI_BUSY (-6) +#define SCMI_COMMS_ERROR (-7) +#define SCMI_GENERIC_ERROR (-8) +#define SCMI_HARDWARE_ERROR (-9) +#define SCMI_PROTOCOL_ERROR (-10) + +#define DT_MATCH_SCMI_SMC DT_MATCH_COMPATIBLE("arm,scmi-smc") + +#define SCMI_SMC_ID "arm,smc-id" +#define SCMI_SHARED_MEMORY "linux,scmi_mem"I could find the following SCMI binding in Linux, which describes the arm,scmi-smc compatible and the arm,smc-id property:
Quoted 6 lines
Documentation/devicetree/bindings/firmware/arm,scmi.yamlHowever, linux,scmi_mem is not described. Aren't you supposed to read the "shmem" property instead? And the compatible string used for this seems to be "arm,scmi-shmem".
We use linux,scmi_mem node to reserve memory, needed for all channels:
reserved-memory { /* reserved region for scmi channels*/ scmi_memory: linux,scmi_mem@53FF0000 { no-map; reg = <0x0 0x53FF0000 0x0 0x10000>; }; };arm,scmi-shmem node used in shmem property defines only 1 page needed to the current scmi channel:
Quoted 7 lines
cpu_scp_shm: scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; };For each Domain reg points to unigue page from linux,scmi_mem region, assigned to this agent.
If we were to use "linux,scmi_mem" we would have to introduce it as a compatible string, not as a node name, and it would need to be described in
Documentation/devicetree/bindings/firmware/arm,scmi.yaml.But from your description I don't think it is necessary. We can just use "arm,scmi-shmem" to describe all the required regions:
reserved-memory { scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; }; scp-shmem@0x53FF1000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF1000 0x0 0x1000>; }; scp-shmem@0x53FF2000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF2000 0x0 0x1000>; }; ...Quoted 4 lines
In other words, if all the individual channel pages are described as "arm,scmi-shmem", why do we also need a single larger region as "linux,scmi_mem"?
That was my first implementation. But I've met a problem with
scmi driver in kernel. I don't remember the exact place, but I remember
there were some if, checking if memory weren't reserved.
That's why I ended up splitting nodes reserved memory region and actual
shmem page.
For linux,scmi_mem node I took format from /reserved-memory/linux,lossy_decompress@54000000, which has no compatible string and provides no-map property.
linux,scmi_shmem node is needed to prevent xen from allocating this
space for the domain.Quoted 7 lines
Very interesting question about should I introduce linux,scmi_mem node and
scmi_devidproperty to theDocumentation/devicetree/bindings/firmware/arm,scmi.yaml? Those node and property are needed only for Xen and useless for non-virtualized systems. I can add this node and property description to arm,scmi.yaml, but leave a note that this is Xen specific params. What do you think about it?Reply below
[...]
Quoted 14 lines
Quoted 14 lines
In general we can't use properties that are not part of the device tree
spec, either https://urldefense.com/v3/__https://www.devicetree.org/specifications/__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXCSnJPN$ [devicetree[.]org] orhttps://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXloYUaj$ [git[.]kernel[.]org]"linux,scmi_mem" is currently absent. Are you aware of any upstreaming activities to get "linux,scmi_mem" upstream under
Documentation/devicetree/bindingsin Linux?If "linux,scmi_mem" is going upstream in Linux, then we could use it. Otherwise, first "linux,scmi_mem" needs to be added somewhere under
Documentation/devicetree/bindings(probablyDocumentation/devicetree/bindings/firmware/arm,scmi.yaml), then we can work on the Xen code that makes use of it.Quoted 5 lines
Quoted 2 lines
Does it make sense?
Yes I agree. I think linux,scmi_mem and
scmi_devidshould be upstreamed.
I will add those properties to arm,scmi.yaml, mark them as related to XEN and send patch.I didn't realize that linux,scmi_mem and
scmi_devidare supposed to be Xen specific. In general, it would be best not to introduce Xen specific properties into generic bindings. It is a problem both from a specification perspective (because it has hard to handle Xen specific cases in fully generic bindings, especially as those bindings are maintained as part of the Linux kernel) and from a user perspective (because now the user has to deal with a Xen-specific dtb, or has to modify the host dtb to add Xen-specific information by hand.)
Quoted 4 lines
Let me start from
scmi_devid. Why wouldscmi_devidbe Xen-specific? It looks like a generic property that should be needed for the Linux SCMI driver too. Why the Linux driver doesn't need it?
scmi_devid used during domain build. It passed as input parameter for SCMI_BASE_SET_DEVICE_PERMISSIONS message. On non-virtualized systems - there is no need of this call, because OS
is the only one entity, running on the system.
I've chatted with Volodymyr_Babchuk and he gave a great idea to add a list of device_ids to dom.cfg, such as:sci_devs = [ 0, 1, 15, 35 ];
Using this approach, we can remove scmi_devid from the device tree and just pass a list of scmi_devids to XEN using additional hypercall. We can probably make hypercall taking devid list as input parameter. This will take only 1 hypercall to setup sci permissions.
Quoted 6 lines
In regards to linux,scmi_mem, I think it would be best to do without it and fix the Linux SCMI driver if we need to do so. Xen should be able to parse the native "arm,scmi-shmem" nodes and Linux (dom0 or domU) should be able to parse the "arm,scmi-shmem" nodes generated by Xen. Either way, I don't think we should need linux,scmi_mem.
This requires further investigation. I will try to make implementation without linux,scmi_mem, using only arm,scmi-shmem nodes and share reuslts with you.
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Quoted 247 lines · Oleksii Moisieiev
Quoted 246 lines · Stefano Stabellini
Quoted 202 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 184 lines · Stefano Stabellini
Quoted 153 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 129 lines · Stefano Stabellini
Quoted 114 lines · Oleksii Moisieiev
This is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG.
The following features are implemented:
- request SCMI channels from ATF and pass channels to Domains;
- set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI;
- redirect scmi messages from Domains to ATF.Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 5 files changed, 809 insertions(+) create mode 100644 xen/arch/arm/sci/Kconfig create mode 100644 xen/arch/arm/sci/scmi_smc.cxen/arch/arm/Kconfig +2
-0@@ -114,6 +114,8 @@ config SCI support. It allows guests to control system resourcess via one of SCI mediators implemented in XEN. +source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/sci/Kconfig new file +10
-0@@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on SCI + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication.xen/arch/arm/sci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.oxen/arch/arm/sci/scmi_smc.c new file +49
-0@@ -0,0 +1,795 @@ +/* +* xen/arch/arm/sci/scmi_smc.c +* +* SCMI mediator driver, using SCP as transport. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/sci/sci.h> +#include <asm/smccc.h> +#include <asm/io.h> +#include <xen/bitops.h> +#include <xen/config.h> +#include <xen/sched.h> +#include <xen/device_tree.h> +#include <xen/iocap.h> +#include <xen/init.h> +#include <xen/err.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/string.h> +#include <xen/time.h> +#include <xen/vmap.h> + +#define SCMI_BASE_PROTOCOL 0x10 +#define SCMI_BASE_PROTOCOL_ATTIBUTES 0x1 +#define SCMI_BASE_SET_DEVICE_PERMISSIONS 0x9 +#define SCMI_BASE_RESET_AGENT_CONFIGURATION 0xB +#define SCMI_BASE_DISCOVER_AGENT 0x7 + +/* SCMI return codes. See section 4.1.4 of SCMI spec (DEN0056C) */ +#define SCMI_SUCCESS 0 +#define SCMI_NOT_SUPPORTED (-1) +#define SCMI_INVALID_PARAMETERS (-2) +#define SCMI_DENIED (-3) +#define SCMI_NOT_FOUND (-4) +#define SCMI_OUT_OF_RANGE (-5)xen/arch/arm/sci/scmi_smc.c line 59
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+#define SCMI_BUSY (-6) +#define SCMI_COMMS_ERROR (-7) +#define SCMI_GENERIC_ERROR (-8) +#define SCMI_HARDWARE_ERROR (-9) +#define SCMI_PROTOCOL_ERROR (-10) + +#define DT_MATCH_SCMI_SMC DT_MATCH_COMPATIBLE("arm,scmi-smc") + +#define SCMI_SMC_ID "arm,smc-id" +#define SCMI_SHARED_MEMORY "linux,scmi_mem"I could find the following SCMI binding in Linux, which describes the arm,scmi-smc compatible and the arm,smc-id property:
Quoted 6 lines
Documentation/devicetree/bindings/firmware/arm,scmi.yamlHowever, linux,scmi_mem is not described. Aren't you supposed to read the "shmem" property instead? And the compatible string used for this seems to be "arm,scmi-shmem".
We use linux,scmi_mem node to reserve memory, needed for all channels:
reserved-memory { /* reserved region for scmi channels*/ scmi_memory: linux,scmi_mem@53FF0000 { no-map; reg = <0x0 0x53FF0000 0x0 0x10000>; }; };arm,scmi-shmem node used in shmem property defines only 1 page needed to the current scmi channel:
Quoted 7 lines
cpu_scp_shm: scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; };For each Domain reg points to unigue page from linux,scmi_mem region, assigned to this agent.
If we were to use "linux,scmi_mem" we would have to introduce it as a compatible string, not as a node name, and it would need to be described in
Documentation/devicetree/bindings/firmware/arm,scmi.yaml.But from your description I don't think it is necessary. We can just use "arm,scmi-shmem" to describe all the required regions:
reserved-memory { scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; }; scp-shmem@0x53FF1000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF1000 0x0 0x1000>; }; scp-shmem@0x53FF2000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF2000 0x0 0x1000>; }; ...Quoted 4 lines
In other words, if all the individual channel pages are described as "arm,scmi-shmem", why do we also need a single larger region as "linux,scmi_mem"?
That was my first implementation. But I've met a problem with
scmi driver in kernel. I don't remember the exact place, but I remember
there were some if, checking if memory weren't reserved.
That's why I ended up splitting nodes reserved memory region and actual
shmem page.
For linux,scmi_mem node I took format from /reserved-memory/linux,lossy_decompress@54000000, which has no compatible string and provides no-map property.
linux,scmi_shmem node is needed to prevent xen from allocating this
space for the domain.Quoted 7 lines
Very interesting question about should I introduce linux,scmi_mem node and
scmi_devidproperty to theDocumentation/devicetree/bindings/firmware/arm,scmi.yaml? Those node and property are needed only for Xen and useless for non-virtualized systems. I can add this node and property description to arm,scmi.yaml, but leave a note that this is Xen specific params. What do you think about it?Reply below
[...]
Quoted 14 lines
Quoted 14 lines
In general we can't use properties that are not part of the device tree
spec, either https://urldefense.com/v3/__https://www.devicetree.org/specifications/__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXCSnJPN$ [devicetree[.]org] orhttps://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXloYUaj$ [git[.]kernel[.]org]"linux,scmi_mem" is currently absent. Are you aware of any upstreaming activities to get "linux,scmi_mem" upstream under
Documentation/devicetree/bindingsin Linux?If "linux,scmi_mem" is going upstream in Linux, then we could use it. Otherwise, first "linux,scmi_mem" needs to be added somewhere under
Documentation/devicetree/bindings(probablyDocumentation/devicetree/bindings/firmware/arm,scmi.yaml), then we can work on the Xen code that makes use of it.Quoted 5 lines
Quoted 2 lines
Does it make sense?
Yes I agree. I think linux,scmi_mem and
scmi_devidshould be upstreamed.
I will add those properties to arm,scmi.yaml, mark them as related to XEN and send patch.I didn't realize that linux,scmi_mem and
scmi_devidare supposed to be Xen specific. In general, it would be best not to introduce Xen specific properties into generic bindings. It is a problem both from a specification perspective (because it has hard to handle Xen specific cases in fully generic bindings, especially as those bindings are maintained as part of the Linux kernel) and from a user perspective (because now the user has to deal with a Xen-specific dtb, or has to modify the host dtb to add Xen-specific information by hand.)
Quoted 8 lines
Quoted 4 lines
Let me start from
scmi_devid. Why wouldscmi_devidbe Xen-specific? It looks like a generic property that should be needed for the Linux SCMI driver too. Why the Linux driver doesn't need it?
scmi_devidused during domain build. It passed as input parameter forSCMI_BASE_SET_DEVICE_PERMISSIONSmessage. On non-virtualized systems - there is no need of this call, because OS
is the only one entity, running on the system.
OK. Even if it is only required for virtualized systems, I think that scmi_devid is important enough that should be part of the upstream binding. I think it is worth starting an email thread on the LKML with Rob Herring and the SCMI maintainers to discuss the addition of scmi_devid to the binding.
Quoted 8 lines
I've chatted with
Volodymyr_Babchukand he gave a great idea to add a list ofdevice_idsto dom.cfg, such as:sci_devs= [ 0, 1, 15, 35 ];Using this approach, we can remove
scmi_devidfrom the device tree and just pass a list ofscmi_devidsto XEN using additional hypercall. We can probably make hypercall taking devid list as input parameter. This will take only 1 hypercall to setup sci permissions.
But how would a user know which are the right SCMI IDs to add to the sci_devs list? Would the user have to go and read the reference manual of the platform to find the SCMI IDs and then write sci_devs by hand? If that is the case, then I think that it would be better to add scmi_devid to device tree.
In general, I think this configuration should happen automatically without user intervention. The user should just specify "enable SCMI" and it should work.
Quoted 9 lines
Quoted 5 lines
In regards to linux,scmi_mem, I think it would be best to do without it and fix the Linux SCMI driver if we need to do so. Xen should be able to parse the native "arm,scmi-shmem" nodes and Linux (dom0 or domU) should be able to parse the "arm,scmi-shmem" nodes generated by Xen. Either way, I don't think we should need linux,scmi_mem.
This requires further investigation. I will try to make implementation without linux,scmi_mem, using only arm,scmi-shmem nodes and share reuslts with you.
OK, thanks.
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Hi Stefano, Oleksii,
Quoted 11 lines · Stefano Stabellini
Quoted 10 lines · Oleksii Moisieiev
Quoted 9 lines · Stefano Stabellini
Quoted 8 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 5 lines · Stefano Stabellini
Quoted 4 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 1 line · Stefano Stabellini
On Tue, 14 Dec 2021, Oleksii Moisieiev wrote:
[...]
Quoted 42 lines
Quoted 33 lines
Quoted 33 lines
Quoted 17 lines
Quoted 17 lines
In general we can't use properties that are not part of the device tree spec, either
https://urldefense.com/v3/__https://www.devicetree.org/specifications/__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXCSnJPN$
[devicetree[.]org] or
https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXloYUaj$
[git[.]kernel[.]org]"linux,scmi_mem" is currently absent. Are you aware of any upstreaming activities to get "linux,scmi_mem" upstream under
Documentation/devicetree/bindingsin Linux?If "linux,scmi_mem" is going upstream in Linux, then we could use it. Otherwise, first "linux,scmi_mem" needs to be added somewhere under
Documentation/devicetree/bindings(probablyDocumentation/devicetree/bindings/firmware/arm,scmi.yaml), then we can work on the Xen code that makes use of it.Quoted 5 lines
Quoted 2 lines
Does it make sense?
Yes I agree. I think linux,scmi_mem and
scmi_devidshould be upstreamed.
I will add those properties to arm,scmi.yaml, mark them as related to XEN and send patch.I didn't realize that linux,scmi_mem and
scmi_devidare supposed to be Xen specific. In general, it would be best not to introduce Xen specific properties into generic bindings. It is a problem both from a specification perspective (because it has hard to handle Xen specific cases in fully generic bindings, especially as those bindings are maintained as part of the Linux kernel) and from a user perspective (because now the user has to deal with a Xen-specific dtb, or has to modify the host dtb to add Xen-specific information by hand.)Quoted 8 lines
Quoted 4 lines
Let me start from
scmi_devid. Why wouldscmi_devidbe Xen-specific? It looks like a generic property that should be needed for the Linux SCMI driver too. Why the Linux driver doesn't need it?
scmi_devidused during domain build. It passed as input parameter forSCMI_BASE_SET_DEVICE_PERMISSIONSmessage. On non-virtualized systems - there is no need of this call, because OS
is the only one entity, running on the system.
Quoted 5 lines
OK. Even if it is only required for virtualized systems, I think that
scmi_devidis important enough that should be part of the upstream binding. I think it is worth starting an email thread on the LKML with Rob Herring and the SCMI maintainers to discuss the addition ofscmi_devidto the binding.
Agree there. Also I want to point that there are other hypervisors, like KVM, which may benefit from this.
Another approach is to name this node "xen,scmdi_devid", but I don't like it.
Quoted 4 lines
Quoted 4 lines
I've chatted with
Volodymyr_Babchukand he gave a great idea to add a list ofdevice_idsto dom.cfg, such as:sci_devs= [ 0, 1, 15, 35 ];
Well, yes. We discussed this possibility, but personally I stick to idea of re-using dt_dev, as we discussed in the different thread.
Quoted 11 lines
Quoted 4 lines
Using this approach, we can remove
scmi_devidfrom the device tree and just pass a list ofscmi_devidsto XEN using additional hypercall. We can probably make hypercall taking devid list as input parameter. This will take only 1 hypercall to setup sci permissions.But how would a user know which are the right SCMI IDs to add to the
sci_devslist? Would the user have to go and read the reference manual of the platform to find the SCMI IDs and then writesci_devsby hand? If that is the case, then I think that it would be better to addscmi_devidto device tree.
Yes, ideally this needs to be done by BSP vendor in the device tree.
Signature · 1 line
Volodymyr Babchuk at EPAM
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
In reply to Stefano StabelliniHi Stefano,
Quoted 257 lines · Stefano Stabellini
Quoted 247 lines · Oleksii Moisieiev
Quoted 246 lines · Stefano Stabellini
Quoted 202 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 184 lines · Stefano Stabellini
Quoted 153 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 129 lines · Stefano Stabellini
Quoted 114 lines · Oleksii Moisieiev
This is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG.
The following features are implemented:
- request SCMI channels from ATF and pass channels to Domains;
- set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI;
- redirect scmi messages from Domains to ATF.Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 5 files changed, 809 insertions(+) create mode 100644 xen/arch/arm/sci/Kconfig create mode 100644 xen/arch/arm/sci/scmi_smc.cxen/arch/arm/Kconfig +2
-0@@ -114,6 +114,8 @@ config SCI support. It allows guests to control system resourcess via one of SCI mediators implemented in XEN. +source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/sci/Kconfig new file +10
-0@@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on SCI + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication.xen/arch/arm/sci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.oxen/arch/arm/sci/scmi_smc.c new file +49
-0@@ -0,0 +1,795 @@ +/* +* xen/arch/arm/sci/scmi_smc.c +* +* SCMI mediator driver, using SCP as transport. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/sci/sci.h> +#include <asm/smccc.h> +#include <asm/io.h> +#include <xen/bitops.h> +#include <xen/config.h> +#include <xen/sched.h> +#include <xen/device_tree.h> +#include <xen/iocap.h> +#include <xen/init.h> +#include <xen/err.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/string.h> +#include <xen/time.h> +#include <xen/vmap.h> + +#define SCMI_BASE_PROTOCOL 0x10 +#define SCMI_BASE_PROTOCOL_ATTIBUTES 0x1 +#define SCMI_BASE_SET_DEVICE_PERMISSIONS 0x9 +#define SCMI_BASE_RESET_AGENT_CONFIGURATION 0xB +#define SCMI_BASE_DISCOVER_AGENT 0x7 + +/* SCMI return codes. See section 4.1.4 of SCMI spec (DEN0056C) */ +#define SCMI_SUCCESS 0 +#define SCMI_NOT_SUPPORTED (-1) +#define SCMI_INVALID_PARAMETERS (-2) +#define SCMI_DENIED (-3) +#define SCMI_NOT_FOUND (-4) +#define SCMI_OUT_OF_RANGE (-5)xen/arch/arm/sci/scmi_smc.c line 59
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+#define SCMI_BUSY (-6) +#define SCMI_COMMS_ERROR (-7) +#define SCMI_GENERIC_ERROR (-8) +#define SCMI_HARDWARE_ERROR (-9) +#define SCMI_PROTOCOL_ERROR (-10) + +#define DT_MATCH_SCMI_SMC DT_MATCH_COMPATIBLE("arm,scmi-smc") + +#define SCMI_SMC_ID "arm,smc-id" +#define SCMI_SHARED_MEMORY "linux,scmi_mem"I could find the following SCMI binding in Linux, which describes the arm,scmi-smc compatible and the arm,smc-id property:
Quoted 6 lines
Documentation/devicetree/bindings/firmware/arm,scmi.yamlHowever, linux,scmi_mem is not described. Aren't you supposed to read the "shmem" property instead? And the compatible string used for this seems to be "arm,scmi-shmem".
We use linux,scmi_mem node to reserve memory, needed for all channels:
reserved-memory { /* reserved region for scmi channels*/ scmi_memory: linux,scmi_mem@53FF0000 { no-map; reg = <0x0 0x53FF0000 0x0 0x10000>; }; };arm,scmi-shmem node used in shmem property defines only 1 page needed to the current scmi channel:
Quoted 7 lines
cpu_scp_shm: scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; };For each Domain reg points to unigue page from linux,scmi_mem region, assigned to this agent.
If we were to use "linux,scmi_mem" we would have to introduce it as a compatible string, not as a node name, and it would need to be described in
Documentation/devicetree/bindings/firmware/arm,scmi.yaml.But from your description I don't think it is necessary. We can just use "arm,scmi-shmem" to describe all the required regions:
reserved-memory { scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; }; scp-shmem@0x53FF1000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF1000 0x0 0x1000>; }; scp-shmem@0x53FF2000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF2000 0x0 0x1000>; }; ...Quoted 4 lines
In other words, if all the individual channel pages are described as "arm,scmi-shmem", why do we also need a single larger region as "linux,scmi_mem"?
That was my first implementation. But I've met a problem with
scmi driver in kernel. I don't remember the exact place, but I remember
there were some if, checking if memory weren't reserved.
That's why I ended up splitting nodes reserved memory region and actual
shmem page.
For linux,scmi_mem node I took format from /reserved-memory/linux,lossy_decompress@54000000, which has no compatible string and provides no-map property.
linux,scmi_shmem node is needed to prevent xen from allocating this
space for the domain.Quoted 7 lines
Very interesting question about should I introduce linux,scmi_mem node and
scmi_devidproperty to theDocumentation/devicetree/bindings/firmware/arm,scmi.yaml? Those node and property are needed only for Xen and useless for non-virtualized systems. I can add this node and property description to arm,scmi.yaml, but leave a note that this is Xen specific params. What do you think about it?Reply below
[...]
Quoted 14 lines
Quoted 14 lines
In general we can't use properties that are not part of the device tree
spec, either https://urldefense.com/v3/__https://www.devicetree.org/specifications/__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXCSnJPN$ [devicetree[.]org] orhttps://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXloYUaj$ [git[.]kernel[.]org]"linux,scmi_mem" is currently absent. Are you aware of any upstreaming activities to get "linux,scmi_mem" upstream under
Documentation/devicetree/bindingsin Linux?If "linux,scmi_mem" is going upstream in Linux, then we could use it. Otherwise, first "linux,scmi_mem" needs to be added somewhere under
Documentation/devicetree/bindings(probablyDocumentation/devicetree/bindings/firmware/arm,scmi.yaml), then we can work on the Xen code that makes use of it.Quoted 5 lines
Quoted 2 lines
Does it make sense?
Yes I agree. I think linux,scmi_mem and
scmi_devidshould be upstreamed.
I will add those properties to arm,scmi.yaml, mark them as related to XEN and send patch.I didn't realize that linux,scmi_mem and
scmi_devidare supposed to be Xen specific. In general, it would be best not to introduce Xen specific properties into generic bindings. It is a problem both from a specification perspective (because it has hard to handle Xen specific cases in fully generic bindings, especially as those bindings are maintained as part of the Linux kernel) and from a user perspective (because now the user has to deal with a Xen-specific dtb, or has to modify the host dtb to add Xen-specific information by hand.)Quoted 8 lines
Quoted 4 lines
Let me start from
scmi_devid. Why wouldscmi_devidbe Xen-specific? It looks like a generic property that should be needed for the Linux SCMI driver too. Why the Linux driver doesn't need it?
scmi_devidused during domain build. It passed as input parameter forSCMI_BASE_SET_DEVICE_PERMISSIONSmessage. On non-virtualized systems - there is no need of this call, because OS
is the only one entity, running on the system.
Quoted 6 lines
OK. Even if it is only required for virtualized systems, I think that
scmi_devidis important enough that should be part of the upstream binding. I think it is worth starting an email thread on the LKML with Rob Herring and the SCMI maintainers to discuss the addition ofscmi_devidto the binding.
Ok I will start the thread about scmi_devid.
Quoted 16 lines
Quoted 9 lines
I've chatted with
Volodymyr_Babchukand he gave a great idea to add a list ofdevice_idsto dom.cfg, such as:sci_devs= [ 0, 1, 15, 35 ];Using this approach, we can remove
scmi_devidfrom the device tree and just pass a list ofscmi_devidsto XEN using additional hypercall. We can probably make hypercall taking devid list as input parameter. This will take only 1 hypercall to setup sci permissions.But how would a user know which are the right SCMI IDs to add to the
sci_devslist? Would the user have to go and read the reference manual of the platform to find the SCMI IDs and then writesci_devsby hand? If that is the case, then I think that it would be better to addscmi_devidto device tree.
Quoted 4 lines
In general, I think this configuration should happen automatically without user intervention. The user should just specify "enable SCMI" and it should work.
Ok. This sounds reasonable.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
In regards to linux,scmi_mem, I think it would be best to do without it and fix the Linux SCMI driver if we need to do so. Xen should be able to parse the native "arm,scmi-shmem" nodes and Linux (dom0 or domU) should be able to parse the "arm,scmi-shmem" nodes generated by Xen. Either way, I don't think we should need linux,scmi_mem.
Quoted 5 lines
Quoted 3 lines
This requires further investigation. I will try to make implementation without linux,scmi_mem, using only arm,scmi-shmem nodes and share reuslts with you.
OK, thanks.
One more question: As you probably seen - Jan had a complains about SCI term. He said SCI is ambiguous with ACPI's System
Control Interrupt. I think of using SC (as System Control) instead. What do you think about it?
Best regards,
Oleksii.
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Quoted 300 lines · Oleksii Moisieiev
Quoted 257 lines · Stefano Stabellini
Quoted 247 lines · Oleksii Moisieiev
Quoted 246 lines · Stefano Stabellini
Quoted 202 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 184 lines · Stefano Stabellini
Quoted 153 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 129 lines · Stefano Stabellini
Quoted 114 lines · Oleksii Moisieiev
This is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG.
The following features are implemented:
- request SCMI channels from ATF and pass channels to Domains;
- set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI;
- redirect scmi messages from Domains to ATF.Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 5 files changed, 809 insertions(+) create mode 100644 xen/arch/arm/sci/Kconfig create mode 100644 xen/arch/arm/sci/scmi_smc.cxen/arch/arm/Kconfig +2
-0@@ -114,6 +114,8 @@ config SCI support. It allows guests to control system resourcess via one of SCI mediators implemented in XEN. +source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/sci/Kconfig new file +10
-0@@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on SCI + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication.xen/arch/arm/sci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.oxen/arch/arm/sci/scmi_smc.c new file +49
-0@@ -0,0 +1,795 @@ +/* +* xen/arch/arm/sci/scmi_smc.c +* +* SCMI mediator driver, using SCP as transport. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/sci/sci.h> +#include <asm/smccc.h> +#include <asm/io.h> +#include <xen/bitops.h> +#include <xen/config.h> +#include <xen/sched.h> +#include <xen/device_tree.h> +#include <xen/iocap.h> +#include <xen/init.h> +#include <xen/err.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/string.h> +#include <xen/time.h> +#include <xen/vmap.h> + +#define SCMI_BASE_PROTOCOL 0x10 +#define SCMI_BASE_PROTOCOL_ATTIBUTES 0x1 +#define SCMI_BASE_SET_DEVICE_PERMISSIONS 0x9 +#define SCMI_BASE_RESET_AGENT_CONFIGURATION 0xB +#define SCMI_BASE_DISCOVER_AGENT 0x7 + +/* SCMI return codes. See section 4.1.4 of SCMI spec (DEN0056C) */ +#define SCMI_SUCCESS 0 +#define SCMI_NOT_SUPPORTED (-1) +#define SCMI_INVALID_PARAMETERS (-2) +#define SCMI_DENIED (-3) +#define SCMI_NOT_FOUND (-4) +#define SCMI_OUT_OF_RANGE (-5)xen/arch/arm/sci/scmi_smc.c line 59
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+#define SCMI_BUSY (-6) +#define SCMI_COMMS_ERROR (-7) +#define SCMI_GENERIC_ERROR (-8) +#define SCMI_HARDWARE_ERROR (-9) +#define SCMI_PROTOCOL_ERROR (-10) + +#define DT_MATCH_SCMI_SMC DT_MATCH_COMPATIBLE("arm,scmi-smc") + +#define SCMI_SMC_ID "arm,smc-id" +#define SCMI_SHARED_MEMORY "linux,scmi_mem"I could find the following SCMI binding in Linux, which describes the arm,scmi-smc compatible and the arm,smc-id property:
Quoted 6 lines
Documentation/devicetree/bindings/firmware/arm,scmi.yamlHowever, linux,scmi_mem is not described. Aren't you supposed to read the "shmem" property instead? And the compatible string used for this seems to be "arm,scmi-shmem".
We use linux,scmi_mem node to reserve memory, needed for all channels:
reserved-memory { /* reserved region for scmi channels*/ scmi_memory: linux,scmi_mem@53FF0000 { no-map; reg = <0x0 0x53FF0000 0x0 0x10000>; }; };arm,scmi-shmem node used in shmem property defines only 1 page needed to the current scmi channel:
Quoted 7 lines
cpu_scp_shm: scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; };For each Domain reg points to unigue page from linux,scmi_mem region, assigned to this agent.
If we were to use "linux,scmi_mem" we would have to introduce it as a compatible string, not as a node name, and it would need to be described in
Documentation/devicetree/bindings/firmware/arm,scmi.yaml.But from your description I don't think it is necessary. We can just use "arm,scmi-shmem" to describe all the required regions:
reserved-memory { scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; }; scp-shmem@0x53FF1000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF1000 0x0 0x1000>; }; scp-shmem@0x53FF2000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF2000 0x0 0x1000>; }; ...Quoted 4 lines
In other words, if all the individual channel pages are described as "arm,scmi-shmem", why do we also need a single larger region as "linux,scmi_mem"?
That was my first implementation. But I've met a problem with
scmi driver in kernel. I don't remember the exact place, but I remember
there were some if, checking if memory weren't reserved.
That's why I ended up splitting nodes reserved memory region and actual
shmem page.
For linux,scmi_mem node I took format from /reserved-memory/linux,lossy_decompress@54000000, which has no compatible string and provides no-map property.
linux,scmi_shmem node is needed to prevent xen from allocating this
space for the domain.Quoted 7 lines
Very interesting question about should I introduce linux,scmi_mem node and
scmi_devidproperty to theDocumentation/devicetree/bindings/firmware/arm,scmi.yaml? Those node and property are needed only for Xen and useless for non-virtualized systems. I can add this node and property description to arm,scmi.yaml, but leave a note that this is Xen specific params. What do you think about it?Reply below
[...]
Quoted 14 lines
Quoted 14 lines
In general we can't use properties that are not part of the device tree
spec, either https://urldefense.com/v3/__https://www.devicetree.org/specifications/__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXCSnJPN$ [devicetree[.]org] orhttps://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXloYUaj$ [git[.]kernel[.]org]"linux,scmi_mem" is currently absent. Are you aware of any upstreaming activities to get "linux,scmi_mem" upstream under
Documentation/devicetree/bindingsin Linux?If "linux,scmi_mem" is going upstream in Linux, then we could use it. Otherwise, first "linux,scmi_mem" needs to be added somewhere under
Documentation/devicetree/bindings(probablyDocumentation/devicetree/bindings/firmware/arm,scmi.yaml), then we can work on the Xen code that makes use of it.Quoted 5 lines
Quoted 2 lines
Does it make sense?
Yes I agree. I think linux,scmi_mem and
scmi_devidshould be upstreamed.
I will add those properties to arm,scmi.yaml, mark them as related to XEN and send patch.I didn't realize that linux,scmi_mem and
scmi_devidare supposed to be Xen specific. In general, it would be best not to introduce Xen specific properties into generic bindings. It is a problem both from a specification perspective (because it has hard to handle Xen specific cases in fully generic bindings, especially as those bindings are maintained as part of the Linux kernel) and from a user perspective (because now the user has to deal with a Xen-specific dtb, or has to modify the host dtb to add Xen-specific information by hand.)Quoted 8 lines
Quoted 4 lines
Let me start from
scmi_devid. Why wouldscmi_devidbe Xen-specific? It looks like a generic property that should be needed for the Linux SCMI driver too. Why the Linux driver doesn't need it?
scmi_devidused during domain build. It passed as input parameter forSCMI_BASE_SET_DEVICE_PERMISSIONSmessage. On non-virtualized systems - there is no need of this call, because OS
is the only one entity, running on the system.Quoted 6 lines
OK. Even if it is only required for virtualized systems, I think that
scmi_devidis important enough that should be part of the upstream binding. I think it is worth starting an email thread on the LKML with Rob Herring and the SCMI maintainers to discuss the addition ofscmi_devidto the binding.Ok I will start the thread about
scmi_devid.Quoted 16 lines
Quoted 9 lines
I've chatted with
Volodymyr_Babchukand he gave a great idea to add a list ofdevice_idsto dom.cfg, such as:sci_devs= [ 0, 1, 15, 35 ];Using this approach, we can remove
scmi_devidfrom the device tree and just pass a list ofscmi_devidsto XEN using additional hypercall. We can probably make hypercall taking devid list as input parameter. This will take only 1 hypercall to setup sci permissions.But how would a user know which are the right SCMI IDs to add to the
sci_devslist? Would the user have to go and read the reference manual of the platform to find the SCMI IDs and then writesci_devsby hand? If that is the case, then I think that it would be better to addscmi_devidto device tree.Quoted 4 lines
In general, I think this configuration should happen automatically without user intervention. The user should just specify "enable SCMI" and it should work.
Ok. This sounds reasonable.
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
In regards to linux,scmi_mem, I think it would be best to do without it and fix the Linux SCMI driver if we need to do so. Xen should be able to parse the native "arm,scmi-shmem" nodes and Linux (dom0 or domU) should be able to parse the "arm,scmi-shmem" nodes generated by Xen. Either way, I don't think we should need linux,scmi_mem.
This requires further investigation. I will try to make implementation without linux,scmi_mem, using only arm,scmi-shmem nodes and share reuslts with you.
Quoted 5 lines
Quoted 1 line
OK, thanks.
One more question: As you probably seen - Jan had a complains about SCI term. He said SCI is ambiguous with ACPI's System
Control Interrupt.
I see his point. As a term I see "SCMI" often and sometimes "SCPI" but "SCI" is the first time I saw it with this patch series.
Quoted 2 lines
I think of using SC (as System Control) instead. What do you think about it?
Yeah, I am not great at naming things but maybe "ARM_SCI"? "SC" alone doesn't give me enough context to guess what it is.
Or we could broaden the scope and call it "firmware_interface"?
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Hi,
Quoted 8 lines · Stefano Stabellini
Quoted 3 lines
One more question: As you probably seen - Jan had a complains about SCI term. He said SCI is ambiguous with ACPI's System
Control Interrupt.I see his point. As a term I see "SCMI" often and sometimes "SCPI" but "SCI" is the first time I saw it with this patch series.
Quoted 5 lines
Quoted 2 lines
I think of using SC (as System Control) instead. What do you think about it?
Yeah, I am not great at naming things but maybe "
ARM_SCI"? "SC" alone doesn't give me enough context to guess what it is.
I might be missing some context. Why are naming everything SCI rather than SMCI?
Quoted 2 lines
Or we could broaden the scope and call it "
firmware_interface"?
How would this be used? Will it be a list of interface that will be exposed to the guest?
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Hi Julien,
Quoted 11 lines · Julien Grall
Hi,
Quoted 8 lines · Stefano Stabellini
Quoted 3 lines
One more question: As you probably seen - Jan had a complains about SCI term. He said SCI is ambiguous with ACPI's System
Control Interrupt.I see his point. As a term I see "SCMI" often and sometimes "SCPI" but "SCI" is the first time I saw it with this patch series.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I think of using SC (as System Control) instead. What do you think about it?
Yeah, I am not great at naming things but maybe "
ARM_SCI"? "SC" alone doesn't give me enough context to guess what it is.I might be missing some context. Why are naming everything SCI rather than SMCI?
Because we're expecting other interfaces and transport to be implemented, such as for example:scmi_mailbox, scpi_smc, scpi_mailbox, ti_sci_smc etc.
Quoted 6 lines
Quoted 3 lines
Or we could broaden the scope and call it "
firmware_interface"?How would this be used? Will it be a list of interface that will be exposed to the guest?
The idea is to set mediator type for each Domain, so for example Xen can use scmi_mailbox to communicate with SCP, Dom0 and DomD are also using scmi_mailbox, but DomU using scmi_smc mediator because we have only 3 mailboxes in system. This is not implemented yet, right now, we are introducing only scmi_smc support. In future, multiple mediator support can be added to Xen.
Best regards,
Oleksii.
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Quoted 1 line · Oleksii Moisieiev
Hi Julien,
Hello,
Quoted 18 lines · Julien Grall
Quoted 17 lines
Hi,
Quoted 13 lines · Stefano Stabellini
Quoted 3 lines
One more question: As you probably seen - Jan had a complains about SCI term. He said SCI is ambiguous with ACPI's System
Control Interrupt.I see his point. As a term I see "SCMI" often and sometimes "SCPI" but "SCI" is the first time I saw it with this patch series.
Quoted 2 lines
I think of using SC (as System Control) instead. What do you think about it?
Yeah, I am not great at naming things but maybe "
ARM_SCI"? "SC" alone doesn't give me enough context to guess what it is.
Quoted 6 lines
Quoted 2 lines
I might be missing some context. Why are naming everything SCI rather than SMCI?
Because we're expecting other interfaces and transport to be implemented, such as for example:
scmi_mailbox,scpi_smc,scpi_mailbox,ti_sci_smcetc.
Oh, now that explain why there is a layer of indirection in Xen. It wasn't very clear from the cover letter why it was present.
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Or we could broaden the scope and call it "
firmware_interface"?How would this be used? Will it be a list of interface that will be exposed to the guest?
Quoted 6 lines
The idea is to set mediator type for each Domain, so for example Xen can use
scmi_mailboxto communicate with SCP, Dom0 and DomD are also usingscmi_mailbox, but DomU usingscmi_smcmediator because we have only 3 mailboxes in system. This is not implemented yet, right now, we are introducing onlyscmi_smcsupport. In future, multiple mediator support can be added to Xen.
Ok. So will there be only one interface at the time for a given domain. Is that correct?
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Quoted 28 lines · Julien Grall
Quoted 1 line · Oleksii Moisieiev
Hi Julien,
Hello,
Quoted 21 lines · Julien Grall
Quoted 19 lines
Hi,
Quoted 8 lines · Stefano Stabellini
Quoted 3 lines
One more question: As you probably seen - Jan had a complains about SCI term. He said SCI is ambiguous with ACPI's System
Control Interrupt.I see his point. As a term I see "SCMI" often and sometimes "SCPI" but "SCI" is the first time I saw it with this patch series.
Quoted 5 lines
Quoted 2 lines
I think of using SC (as System Control) instead. What do you think about it?
Yeah, I am not great at naming things but maybe "
ARM_SCI"? "SC" alone doesn't give me enough context to guess what it is.I might be missing some context. Why are naming everything SCI rather than SMCI?
Quoted 7 lines
Quoted 3 lines
Because we're expecting other interfaces and transport to be implemented, such as for example:
scmi_mailbox,scpi_smc,scpi_mailbox,ti_sci_smcetc.Oh, now that explain why there is a layer of indirection in Xen. It wasn't very clear from the cover letter why it was present.
Please see below.
Quoted 15 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Or we could broaden the scope and call it "
firmware_interface"?How would this be used? Will it be a list of interface that will be exposed to the guest?
Quoted 6 lines
The idea is to set mediator type for each Domain, so for example Xen can use
scmi_mailboxto communicate with SCP, Dom0 and DomD are also usingscmi_mailbox, but DomU usingscmi_smcmediator because we have only 3 mailboxes in system. This is not implemented yet, right now, we are introducing onlyscmi_smcsupport. In future, multiple mediator support can be added to Xen.
Quoted 3 lines
Ok. So will there be only one interface at the time for a given domain. Is that correct?
Correct. The idea is that we provice only one interface to the Domain, so different domains can use different protocols and transport. Those interfaces can be different than the interface Xen uses to connect to SCP. This allows us to vary the configuration. So for example:
Let's take system, that support only 2 mailboxes and communication with SCP can use only mailboxes as transport. We intent to use scmi protocol to manage HW. In this case we use 2 mailboxes for Xen-> SCP communication, and for Dom0 -> Xen. Domu can be configured to use scmi_smc, so the communication should be the following:
DomU --smc--> Xen -mailbox--> SCP Firmware.
Let's say we want to add DomainX with OS XXX, which using yyy protocol with zzz transport. Then we can configure DomX wuth yyy_zzz mediator, so the communication will be the following:
DomX --yyy--> Xen -mailbox--> SCP Firmware
Where Xen knows how to convert message from yyy protocol to scmi protocol.
I considered the alternative way, when we can configure domain with several mediators, so each Domain can be configured to use, for example, scmi_smc for power-domains and scpi_smc for clocks and resets. But I don't see real use-cases for this configuration.
What do you think about that?
Best regards,
Oleksii
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Hi,
Quoted 50 lines · Oleksii Moisieiev
Quoted 26 lines · Julien Grall
Quoted 1 line · Oleksii Moisieiev
Hi Julien,
Hello,
Quoted 21 lines · Julien Grall
Quoted 19 lines
Hi,
Quoted 8 lines · Stefano Stabellini
Quoted 3 lines
One more question: As you probably seen - Jan had a complains about SCI term. He said SCI is ambiguous with ACPI's System
Control Interrupt.I see his point. As a term I see "SCMI" often and sometimes "SCPI" but "SCI" is the first time I saw it with this patch series.
Quoted 5 lines
Quoted 2 lines
I think of using SC (as System Control) instead. What do you think about it?
Yeah, I am not great at naming things but maybe "
ARM_SCI"? "SC" alone doesn't give me enough context to guess what it is.I might be missing some context. Why are naming everything SCI rather than SMCI?
Quoted 7 lines
Quoted 3 lines
Because we're expecting other interfaces and transport to be implemented, such as for example:
scmi_mailbox,scpi_smc,scpi_mailbox,ti_sci_smcetc.Oh, now that explain why there is a layer of indirection in Xen. It wasn't very clear from the cover letter why it was present.
Please see below.
Quoted 15 lines
Quoted 14 lines
Quoted 7 lines
Quoted 4 lines
Or we could broaden the scope and call it "
firmware_interface"?How would this be used? Will it be a list of interface that will be exposed to the guest?
The idea is to set mediator type for each Domain, so for example Xen can use
scmi_mailboxto communicate with SCP, Dom0 and DomD are also usingscmi_mailbox, but DomU usingscmi_smcmediator because we have only 3 mailboxes in system. This is not implemented yet, right now, we are introducing onlyscmi_smcsupport. In future, multiple mediator support can be added to Xen.
Quoted 5 lines
Quoted 3 lines
Ok. So will there be only one interface at the time for a given domain. Is that correct?
Correct. The idea is that we provice only one interface to the Domain, so different domains can use different protocols and transport
I think this is similar to TEE mediator. Specifying in the guest configuration the TEE protocol (e.g. OP-TEE) allows to sanity check what the guest wants match the host. However, I am not convinced there is a need to expose different protocols for domains running on the same platform.
Quoted 2 lines
Those
interfaces can be different than the interface Xen uses to connect to SCP.
I can understand how this looks appealing. However, it may not always be possible to convert the guest protocol to the host protocol. And even if it is possible, it is increasing the complexity and risk.
Quoted 5 lines
This allows us to vary the configuration.
So for example:
Let's take system, that support only 2 mailboxes and communication with SCP can use only mailboxes as transport. We intent to use scmi protocol to manage HW. In this case we use 2 mailboxes for Xen-> SCP
Quoted 8 lines
communication, and for Dom0 -> Xen.
Domu can be configured to usescmi_smc, so the communication should be the following:
DomU --smc--> Xen -mailbox--> SCP Firmware.
Let's say we want to add DomainX with OS XXX, which using yyy protocol with zzz transport. Then we can configure DomX wuthyyy_zzzmediator, so the communication will be the following:
DomX --yyy--> Xen -mailbox--> SCP Firmware
I am a bit confused with your example here. From my understanding, I would say 'smc' is the transport. But in your example above, you suggest this is the protocol. What did I miss?
Quoted 1 line
Where Xen knows how to convert message from yyy protocol to scmi protocol
As I wrote above, when possible, converting protocol could be complex and risky. So do you have a concrete use case for that?
That said, changing the transport (e.g. smc <-> mailbox) would make more sense to me.
Quoted 5 lines
I considered the alternative way, when we can configure domain with several mediators, so each Domain can be configured to use, for example,
scmi_smcfor power-domains andscpi_smcfor clocks and resets. But I don't see real use-cases for this configuration.
Do you mean a platform using both or exposing both to the guest?
Quoted 2 lines
What do you think about that?
So I am a bit unsure how "firmware_interface" would be specified. IMO, the user should only specificy which interface the guest will use (e.g. SCMI via SMC) even if the host end up to use a different transport (e.g. SCMI via mailbox). IOW, the option would not tell how to convert it.
Is it what you had in mind?
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Quoted 56 lines · Julien Grall
Hi,
Quoted 53 lines · Oleksii Moisieiev
Quoted 26 lines · Julien Grall
Quoted 1 line · Oleksii Moisieiev
Hi Julien,
Hello,
Quoted 21 lines · Julien Grall
Quoted 19 lines
Hi,
Quoted 8 lines · Stefano Stabellini
Quoted 3 lines
One more question: As you probably seen - Jan had a complains about SCI term. He said SCI is ambiguous with ACPI's System
Control Interrupt.I see his point. As a term I see "SCMI" often and sometimes "SCPI" but "SCI" is the first time I saw it with this patch series.
Quoted 5 lines
Quoted 2 lines
I think of using SC (as System Control) instead. What do you think about it?
Yeah, I am not great at naming things but maybe "
ARM_SCI"? "SC" alone doesn't give me enough context to guess what it is.I might be missing some context. Why are naming everything SCI rather than SMCI?
Quoted 7 lines
Quoted 3 lines
Because we're expecting other interfaces and transport to be implemented, such as for example:
scmi_mailbox,scpi_smc,scpi_mailbox,ti_sci_smcetc.Oh, now that explain why there is a layer of indirection in Xen. It wasn't very clear from the cover letter why it was present.
Please see below.
Quoted 18 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Or we could broaden the scope and call it "
firmware_interface"?How would this be used? Will it be a list of interface that will be exposed to the guest?
Quoted 6 lines
The idea is to set mediator type for each Domain, so for example Xen can use
scmi_mailboxto communicate with SCP, Dom0 and DomD are also usingscmi_mailbox, but DomU usingscmi_smcmediator because we have only 3 mailboxes in system. This is not implemented yet, right now, we are introducing onlyscmi_smcsupport. In future, multiple mediator support can be added to Xen.Ok. So will there be only one interface at the time for a given domain. Is that correct?
Quoted 8 lines
Quoted 2 lines
Correct. The idea is that we provice only one interface to the Domain, so different domains can use different protocols and transport
I think this is similar to TEE mediator. Specifying in the guest configuration the TEE protocol (e.g. OP-TEE) allows to sanity check what the guest wants match the host. However, I am not convinced there is a need to expose different protocols for domains running on the same platform.
Yes. You're right, I based on TEE mediator during implementation. Please see below my thoughts about different protocols and transports.
Quoted 21 lines
Quoted 2 lines
Those
interfaces can be different than the interface Xen uses to connect to SCP.I can understand how this looks appealing. However, it may not always be possible to convert the guest protocol to the host protocol. And even if it is possible, it is increasing the complexity and risk.
Quoted 5 lines
This allows us to vary the configuration.
So for example:
Let's take system, that support only 2 mailboxes and communication with SCP can use only mailboxes as transport. We intent to use scmi protocol to manage HW. In this case we use 2 mailboxes for Xen-> SCPQuoted 8 lines
communication, and for Dom0 -> Xen.
Domu can be configured to usescmi_smc, so the communication should be the following:
DomU --smc--> Xen -mailbox--> SCP Firmware.
Let's say we want to add DomainX with OS XXX, which using yyy protocol with zzz transport. Then we can configure DomX wuthyyy_zzzmediator, so the communication will be the following:
DomX --yyy--> Xen -mailbox--> SCP Firmware
Quoted 3 lines
I am a bit confused with your example here. From my understanding, I would say 'smc' is the transport. But in your example above, you suggest this is the protocol. What did I miss?
Sorry, that's my fault. I merged 2 exapmles in 1, in which the first example shows different transports and the second one shows different protocols.
The first expample describes the use-case when we have firmware, using mailboxes as transport, but the system we have has number of Domains > than number of the mailboxes.
Let's say Firmware and all Domains are using scmi protocol. In this case I see 2 possible configurations:
1) Firmware and some Domains are using mailbox as transport, other Domains, when all mailboxes are occupied, are using smc as transport. Xen will be responsible to receive smc message and send request to Firmware using mailbox and vice versa.
2) Firmware using mailbox to communicate with Xen, all Domains are using smc. In this case only one mailbox will be used.
Number 2 looks better from my standpoint. In that case we have scmi_smc mediator, which exposes smc transport to domains and uses mailbox to communicate with Firmware.
The second part is that we can change protocol when it's simple and safe. But now I see that this is not a good Idea to make Xen responsible for protocol converting.
Quoted 9 lines
Quoted 2 lines
Where Xen knows how to convert message from yyy protocol to scmi protocol
As I wrote above, when possible, converting protocol could be complex and risky. So do you have a concrete use case for that?
That said, changing the transport (e.g. smc <-> mailbox) would make more sense to me.
I think you're right.
Quoted 8 lines
Quoted 5 lines
I considered the alternative way, when we can configure domain with several mediators, so each Domain can be configured to use, for example,
scmi_smcfor power-domains andscpi_smcfor clocks and resets. But I don't see real use-cases for this configuration.Do you mean a platform using both or exposing both to the guest?
Yes, that's the alternative way I see. Similar to linux kernel, where you are allowed to use for example scmi for clocks and scpi for resets. I don't see the real use-cases for this config, but Xen can follow Linux kernel configuration approach and allow to register 2 mediators: one for scmi_smc and one for scpi_smc.
In this case Domain configuration will look like this:
sci = [
"scmi_smc",
"scpi_smc",
];So both scmi_smc and scpi_smc mediators are exposing protocols to the domains and communicating with Firmware.
Current implementation supports only 1 mediator, but in future I think we should consider the posibility of having several mediators. Where each mediator has it's own channel (transport+protocol) to Firmware and exposes transport+protocol to the guests.
Quoted 9 lines
Quoted 2 lines
What do you think about that?
So I am a bit unsure how "
firmware_interface" would be specified. IMO, the user should only specificy which interface the guest will use (e.g. SCMI via SMC) even if the host end up to use a different transport (e.g. SCMI via mailbox). IOW, the option would not tell how to convert it.Is it what you had in mind?
Yes. That's what I mean.firmware_interface can be specified in xen Device-tree. Different SCI
mediators can be implemented and added to the device-tree. Each mediator has channel (protocol + transports) to the Firmware and exposes protocol + transport to the guests. Protocol to the Firmware should be the same as exposed protocol,
transport may differ and is implementation specific.
Best regards,
Oleksii.
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
In reply to Stefano StabelliniQuoted 311 lines · Stefano Stabellini
Quoted 300 lines · Oleksii Moisieiev
Quoted 257 lines · Stefano Stabellini
Quoted 247 lines · Oleksii Moisieiev
Quoted 246 lines · Stefano Stabellini
Quoted 202 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 184 lines · Stefano Stabellini
Quoted 153 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 129 lines · Stefano Stabellini
Quoted 114 lines · Oleksii Moisieiev
This is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG.
The following features are implemented:
- request SCMI channels from ATF and pass channels to Domains;
- set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI;
- redirect scmi messages from Domains to ATF.Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 5 files changed, 809 insertions(+) create mode 100644 xen/arch/arm/sci/Kconfig create mode 100644 xen/arch/arm/sci/scmi_smc.cxen/arch/arm/Kconfig +2
-0@@ -114,6 +114,8 @@ config SCI support. It allows guests to control system resourcess via one of SCI mediators implemented in XEN. +source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/sci/Kconfig new file +10
-0@@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on SCI + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication.xen/arch/arm/sci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.oxen/arch/arm/sci/scmi_smc.c new file +49
-0@@ -0,0 +1,795 @@ +/* +* xen/arch/arm/sci/scmi_smc.c +* +* SCMI mediator driver, using SCP as transport. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/sci/sci.h> +#include <asm/smccc.h> +#include <asm/io.h> +#include <xen/bitops.h> +#include <xen/config.h> +#include <xen/sched.h> +#include <xen/device_tree.h> +#include <xen/iocap.h> +#include <xen/init.h> +#include <xen/err.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/string.h> +#include <xen/time.h> +#include <xen/vmap.h> + +#define SCMI_BASE_PROTOCOL 0x10 +#define SCMI_BASE_PROTOCOL_ATTIBUTES 0x1 +#define SCMI_BASE_SET_DEVICE_PERMISSIONS 0x9 +#define SCMI_BASE_RESET_AGENT_CONFIGURATION 0xB +#define SCMI_BASE_DISCOVER_AGENT 0x7 + +/* SCMI return codes. See section 4.1.4 of SCMI spec (DEN0056C) */ +#define SCMI_SUCCESS 0 +#define SCMI_NOT_SUPPORTED (-1) +#define SCMI_INVALID_PARAMETERS (-2) +#define SCMI_DENIED (-3) +#define SCMI_NOT_FOUND (-4) +#define SCMI_OUT_OF_RANGE (-5)xen/arch/arm/sci/scmi_smc.c line 59
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+#define SCMI_BUSY (-6) +#define SCMI_COMMS_ERROR (-7) +#define SCMI_GENERIC_ERROR (-8) +#define SCMI_HARDWARE_ERROR (-9) +#define SCMI_PROTOCOL_ERROR (-10) + +#define DT_MATCH_SCMI_SMC DT_MATCH_COMPATIBLE("arm,scmi-smc") + +#define SCMI_SMC_ID "arm,smc-id" +#define SCMI_SHARED_MEMORY "linux,scmi_mem"I could find the following SCMI binding in Linux, which describes the arm,scmi-smc compatible and the arm,smc-id property:
Quoted 6 lines
Documentation/devicetree/bindings/firmware/arm,scmi.yamlHowever, linux,scmi_mem is not described. Aren't you supposed to read the "shmem" property instead? And the compatible string used for this seems to be "arm,scmi-shmem".
We use linux,scmi_mem node to reserve memory, needed for all channels:
reserved-memory { /* reserved region for scmi channels*/ scmi_memory: linux,scmi_mem@53FF0000 { no-map; reg = <0x0 0x53FF0000 0x0 0x10000>; }; };arm,scmi-shmem node used in shmem property defines only 1 page needed to the current scmi channel:
Quoted 7 lines
cpu_scp_shm: scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; };For each Domain reg points to unigue page from linux,scmi_mem region, assigned to this agent.
If we were to use "linux,scmi_mem" we would have to introduce it as a compatible string, not as a node name, and it would need to be described in
Documentation/devicetree/bindings/firmware/arm,scmi.yaml.But from your description I don't think it is necessary. We can just use "arm,scmi-shmem" to describe all the required regions:
reserved-memory { scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; }; scp-shmem@0x53FF1000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF1000 0x0 0x1000>; }; scp-shmem@0x53FF2000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF2000 0x0 0x1000>; }; ...Quoted 4 lines
In other words, if all the individual channel pages are described as "arm,scmi-shmem", why do we also need a single larger region as "linux,scmi_mem"?
That was my first implementation. But I've met a problem with
scmi driver in kernel. I don't remember the exact place, but I remember
there were some if, checking if memory weren't reserved.
That's why I ended up splitting nodes reserved memory region and actual
shmem page.
For linux,scmi_mem node I took format from /reserved-memory/linux,lossy_decompress@54000000, which has no compatible string and provides no-map property.
linux,scmi_shmem node is needed to prevent xen from allocating this
space for the domain.Quoted 7 lines
Very interesting question about should I introduce linux,scmi_mem node and
scmi_devidproperty to theDocumentation/devicetree/bindings/firmware/arm,scmi.yaml? Those node and property are needed only for Xen and useless for non-virtualized systems. I can add this node and property description to arm,scmi.yaml, but leave a note that this is Xen specific params. What do you think about it?Reply below
[...]
Quoted 14 lines
Quoted 14 lines
In general we can't use properties that are not part of the device tree
spec, either https://urldefense.com/v3/__https://www.devicetree.org/specifications/__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXCSnJPN$ [devicetree[.]org] orhttps://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXloYUaj$ [git[.]kernel[.]org]"linux,scmi_mem" is currently absent. Are you aware of any upstreaming activities to get "linux,scmi_mem" upstream under
Documentation/devicetree/bindingsin Linux?If "linux,scmi_mem" is going upstream in Linux, then we could use it. Otherwise, first "linux,scmi_mem" needs to be added somewhere under
Documentation/devicetree/bindings(probablyDocumentation/devicetree/bindings/firmware/arm,scmi.yaml), then we can work on the Xen code that makes use of it.Quoted 5 lines
Quoted 2 lines
Does it make sense?
Yes I agree. I think linux,scmi_mem and
scmi_devidshould be upstreamed.
I will add those properties to arm,scmi.yaml, mark them as related to XEN and send patch.I didn't realize that linux,scmi_mem and
scmi_devidare supposed to be Xen specific. In general, it would be best not to introduce Xen specific properties into generic bindings. It is a problem both from a specification perspective (because it has hard to handle Xen specific cases in fully generic bindings, especially as those bindings are maintained as part of the Linux kernel) and from a user perspective (because now the user has to deal with a Xen-specific dtb, or has to modify the host dtb to add Xen-specific information by hand.)Quoted 8 lines
Quoted 4 lines
Let me start from
scmi_devid. Why wouldscmi_devidbe Xen-specific? It looks like a generic property that should be needed for the Linux SCMI driver too. Why the Linux driver doesn't need it?
scmi_devidused during domain build. It passed as input parameter forSCMI_BASE_SET_DEVICE_PERMISSIONSmessage. On non-virtualized systems - there is no need of this call, because OS
is the only one entity, running on the system.Quoted 6 lines
OK. Even if it is only required for virtualized systems, I think that
scmi_devidis important enough that should be part of the upstream binding. I think it is worth starting an email thread on the LKML with Rob Herring and the SCMI maintainers to discuss the addition ofscmi_devidto the binding.Ok I will start the thread about
scmi_devid.Quoted 16 lines
Quoted 9 lines
I've chatted with
Volodymyr_Babchukand he gave a great idea to add a list ofdevice_idsto dom.cfg, such as:sci_devs= [ 0, 1, 15, 35 ];Using this approach, we can remove
scmi_devidfrom the device tree and just pass a list ofscmi_devidsto XEN using additional hypercall. We can probably make hypercall taking devid list as input parameter. This will take only 1 hypercall to setup sci permissions.But how would a user know which are the right SCMI IDs to add to the
sci_devslist? Would the user have to go and read the reference manual of the platform to find the SCMI IDs and then writesci_devsby hand? If that is the case, then I think that it would be better to addscmi_devidto device tree.Quoted 4 lines
In general, I think this configuration should happen automatically without user intervention. The user should just specify "enable SCMI" and it should work.
Ok. This sounds reasonable.
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
In regards to linux,scmi_mem, I think it would be best to do without it and fix the Linux SCMI driver if we need to do so. Xen should be able to parse the native "arm,scmi-shmem" nodes and Linux (dom0 or domU) should be able to parse the "arm,scmi-shmem" nodes generated by Xen. Either way, I don't think we should need linux,scmi_mem.
This requires further investigation. I will try to make implementation without linux,scmi_mem, using only arm,scmi-shmem nodes and share reuslts with you.
Quoted 5 lines
Quoted 1 line
OK, thanks.
One more question: As you probably seen - Jan had a complains about SCI term. He said SCI is ambiguous with ACPI's System
Control Interrupt.I see his point. As a term I see "SCMI" often and sometimes "SCPI" but "SCI" is the first time I saw it with this patch series.
Quoted 7 lines
Quoted 2 lines
I think of using SC (as System Control) instead. What do you think about it?
Yeah, I am not great at naming things but maybe "
ARM_SCI"? "SC" alone doesn't give me enough context to guess what it is.Or we could broaden the scope and call it "
firmware_interface"?
ARM_SCI sounds good for me.
Best regards,
Oleksii.
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
In reply to Stefano StabelliniQuoted 290 lines · Stefano Stabellini
Quoted 247 lines · Oleksii Moisieiev
Quoted 246 lines · Stefano Stabellini
Quoted 202 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 184 lines · Stefano Stabellini
Quoted 153 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 129 lines · Stefano Stabellini
Quoted 114 lines · Oleksii Moisieiev
This is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG.
The following features are implemented:
- request SCMI channels from ATF and pass channels to Domains;
- set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI;
- redirect scmi messages from Domains to ATF.Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 5 files changed, 809 insertions(+) create mode 100644 xen/arch/arm/sci/Kconfig create mode 100644 xen/arch/arm/sci/scmi_smc.cxen/arch/arm/Kconfig +2
-0@@ -114,6 +114,8 @@ config SCI support. It allows guests to control system resourcess via one of SCI mediators implemented in XEN. +source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/sci/Kconfig new file +10
-0@@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on SCI + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication.xen/arch/arm/sci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.oxen/arch/arm/sci/scmi_smc.c new file +49
-0@@ -0,0 +1,795 @@ +/* +* xen/arch/arm/sci/scmi_smc.c +* +* SCMI mediator driver, using SCP as transport. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/sci/sci.h> +#include <asm/smccc.h> +#include <asm/io.h> +#include <xen/bitops.h> +#include <xen/config.h> +#include <xen/sched.h> +#include <xen/device_tree.h> +#include <xen/iocap.h> +#include <xen/init.h> +#include <xen/err.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/string.h> +#include <xen/time.h> +#include <xen/vmap.h> + +#define SCMI_BASE_PROTOCOL 0x10 +#define SCMI_BASE_PROTOCOL_ATTIBUTES 0x1 +#define SCMI_BASE_SET_DEVICE_PERMISSIONS 0x9 +#define SCMI_BASE_RESET_AGENT_CONFIGURATION 0xB +#define SCMI_BASE_DISCOVER_AGENT 0x7 + +/* SCMI return codes. See section 4.1.4 of SCMI spec (DEN0056C) */ +#define SCMI_SUCCESS 0 +#define SCMI_NOT_SUPPORTED (-1) +#define SCMI_INVALID_PARAMETERS (-2) +#define SCMI_DENIED (-3) +#define SCMI_NOT_FOUND (-4) +#define SCMI_OUT_OF_RANGE (-5)xen/arch/arm/sci/scmi_smc.c line 59
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+#define SCMI_BUSY (-6) +#define SCMI_COMMS_ERROR (-7) +#define SCMI_GENERIC_ERROR (-8) +#define SCMI_HARDWARE_ERROR (-9) +#define SCMI_PROTOCOL_ERROR (-10) + +#define DT_MATCH_SCMI_SMC DT_MATCH_COMPATIBLE("arm,scmi-smc") + +#define SCMI_SMC_ID "arm,smc-id" +#define SCMI_SHARED_MEMORY "linux,scmi_mem"I could find the following SCMI binding in Linux, which describes the arm,scmi-smc compatible and the arm,smc-id property:
Quoted 6 lines
Documentation/devicetree/bindings/firmware/arm,scmi.yamlHowever, linux,scmi_mem is not described. Aren't you supposed to read the "shmem" property instead? And the compatible string used for this seems to be "arm,scmi-shmem".
We use linux,scmi_mem node to reserve memory, needed for all channels:
reserved-memory { /* reserved region for scmi channels*/ scmi_memory: linux,scmi_mem@53FF0000 { no-map; reg = <0x0 0x53FF0000 0x0 0x10000>; }; };arm,scmi-shmem node used in shmem property defines only 1 page needed to the current scmi channel:
Quoted 7 lines
cpu_scp_shm: scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; };For each Domain reg points to unigue page from linux,scmi_mem region, assigned to this agent.
If we were to use "linux,scmi_mem" we would have to introduce it as a compatible string, not as a node name, and it would need to be described in
Documentation/devicetree/bindings/firmware/arm,scmi.yaml.But from your description I don't think it is necessary. We can just use "arm,scmi-shmem" to describe all the required regions:
reserved-memory { scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; }; scp-shmem@0x53FF1000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF1000 0x0 0x1000>; }; scp-shmem@0x53FF2000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF2000 0x0 0x1000>; }; ...Quoted 4 lines
In other words, if all the individual channel pages are described as "arm,scmi-shmem", why do we also need a single larger region as "linux,scmi_mem"?
That was my first implementation. But I've met a problem with
scmi driver in kernel. I don't remember the exact place, but I remember
there were some if, checking if memory weren't reserved.
That's why I ended up splitting nodes reserved memory region and actual
shmem page.
For linux,scmi_mem node I took format from /reserved-memory/linux,lossy_decompress@54000000, which has no compatible string and provides no-map property.
linux,scmi_shmem node is needed to prevent xen from allocating this
space for the domain.Quoted 7 lines
Very interesting question about should I introduce linux,scmi_mem node and
scmi_devidproperty to theDocumentation/devicetree/bindings/firmware/arm,scmi.yaml? Those node and property are needed only for Xen and useless for non-virtualized systems. I can add this node and property description to arm,scmi.yaml, but leave a note that this is Xen specific params. What do you think about it?Reply below
[...]
Quoted 14 lines
Quoted 14 lines
In general we can't use properties that are not part of the device tree
spec, either https://urldefense.com/v3/__https://www.devicetree.org/specifications/__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXCSnJPN$ [devicetree[.]org] orhttps://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXloYUaj$ [git[.]kernel[.]org]"linux,scmi_mem" is currently absent. Are you aware of any upstreaming activities to get "linux,scmi_mem" upstream under
Documentation/devicetree/bindingsin Linux?If "linux,scmi_mem" is going upstream in Linux, then we could use it. Otherwise, first "linux,scmi_mem" needs to be added somewhere under
Documentation/devicetree/bindings(probablyDocumentation/devicetree/bindings/firmware/arm,scmi.yaml), then we can work on the Xen code that makes use of it.Quoted 5 lines
Quoted 2 lines
Does it make sense?
Yes I agree. I think linux,scmi_mem and
scmi_devidshould be upstreamed.
I will add those properties to arm,scmi.yaml, mark them as related to XEN and send patch.I didn't realize that linux,scmi_mem and
scmi_devidare supposed to be Xen specific. In general, it would be best not to introduce Xen specific properties into generic bindings. It is a problem both from a specification perspective (because it has hard to handle Xen specific cases in fully generic bindings, especially as those bindings are maintained as part of the Linux kernel) and from a user perspective (because now the user has to deal with a Xen-specific dtb, or has to modify the host dtb to add Xen-specific information by hand.)Quoted 8 lines
Quoted 4 lines
Let me start from
scmi_devid. Why wouldscmi_devidbe Xen-specific? It looks like a generic property that should be needed for the Linux SCMI driver too. Why the Linux driver doesn't need it?
scmi_devidused during domain build. It passed as input parameter forSCMI_BASE_SET_DEVICE_PERMISSIONSmessage. On non-virtualized systems - there is no need of this call, because OS
is the only one entity, running on the system.OK. Even if it is only required for virtualized systems, I think that
scmi_devidis important enough that should be part of the upstream binding. I think it is worth starting an email thread on the LKML with Rob Herring and the SCMI maintainers to discuss the addition ofscmi_devidto the binding.Quoted 8 lines
I've chatted with
Volodymyr_Babchukand he gave a great idea to add a list ofdevice_idsto dom.cfg, such as:sci_devs= [ 0, 1, 15, 35 ];Using this approach, we can remove
scmi_devidfrom the device tree and just pass a list ofscmi_devidsto XEN using additional hypercall. We can probably make hypercall taking devid list as input parameter. This will take only 1 hypercall to setup sci permissions.But how would a user know which are the right SCMI IDs to add to the
sci_devslist? Would the user have to go and read the reference manual of the platform to find the SCMI IDs and then writesci_devsby hand? If that is the case, then I think that it would be better to addscmi_devidto device tree.In general, I think this configuration should happen automatically without user intervention. The user should just specify "enable SCMI" and it should work.
Quoted 6 lines
Quoted 5 lines
In regards to linux,scmi_mem, I think it would be best to do without it and fix the Linux SCMI driver if we need to do so. Xen should be able to parse the native "arm,scmi-shmem" nodes and Linux (dom0 or domU) should be able to parse the "arm,scmi-shmem" nodes generated by Xen. Either way, I don't think we should need linux,scmi_mem.
Quoted 5 lines
Quoted 3 lines
This requires further investigation. I will try to make implementation without linux,scmi_mem, using only arm,scmi-shmem nodes and share reuslts with you.
OK, thanks.
Hi Stefano,
As I did some investigation about using reserved-memory area linux,scmi_mem and now I need your advice.
I see 2 possible implementations for now:
1) Add memory-region parameter to cpu_scp_shm node which points to the reserved memory region.
So device-tree will look like this:
reserved-memory {
/* reserved region for scmi channels*/
scmi_memory: region@53FF0000{
no-map;
reg = <0x0 0x53FF0000 0x0 0x10000>;
};
};
cpu_scp_shm: scp-shmem@0x53FF0000 {
compatible = "arm,scmi-shmem";
reg = <0x0 0x53FF0000 0x0 0x1000>;
memory-region = <&scmi_memory>;
};So cpu_scp_shm node has a reference to scmi_memory region. This mean that xen can find reserved memory region without adding additional names to the device-tree bindings.
memory-region parameter as a reference to reserved memory and region creation described in:
https://github.com/torvalds/linux/blob/v5.15/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt
This approach I've implemented already and it works.
2) The second approach is the format you suggested:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
reserved-memory { scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; }; scp-shmem@0x53FF1000 {
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF1000 0x0 0x1000>; }; scp-shmem@0x53FF2000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF2000 0x0 0x1000>; }; ...
This approach has an advantage that xen ARM_SCI driver do not know about how channels are placed in the reserved memory, but introduces some disadvantages:
a) We provide extra 14 (in our case) arm,scmi-shmem nodes which are not used in the device-tree. In current implementation I have separate scmi.dtsi file which introduces scmi support for both XEN-based and non-virtualized systems. Having 14 extra channels in the device-tree may be confusing.
b) In case if we have all 15 channels, described in partial device-tree, we should not copy any node to the domain device-tree. I think it will be better to generate arm,scmi-shmem node in the Domain device-tree. The problem is that arm,scmi-smc node, which is using arm,scmi-shmem node can't be generated. I prefer it to be copied from the partial device-tree because it includes some platform specific configuration, such as func-id and list of the protocols (for example different platforms may require different list of the protocols). So in this case we will have 1 node copied and 1 node generated.
I think even for dom0less we should use arm,scmi-smc node from the device-tree because protocol configuration and funcid is related to the platform.
I prefer the second approach and will try to make it if it's OK to copy arm,scmi-smc node from partial Device-tree and generate arm,scmi-shmem node.
What do you think about that?
Also I wanted to mention that I'm not planning to make ARM_SCI support for dom0less in terms of this patch series bacause I can't test dom0less configuration for now. So let me know if some of my functionality breaks dom0less.
--
Best regards
Oleksii.
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Quoted 320 lines · Oleksii Moisieiev
Quoted 290 lines · Stefano Stabellini
Quoted 247 lines · Oleksii Moisieiev
Quoted 246 lines · Stefano Stabellini
Quoted 202 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 184 lines · Stefano Stabellini
Quoted 153 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 129 lines · Stefano Stabellini
Quoted 114 lines · Oleksii Moisieiev
This is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG.
The following features are implemented:
- request SCMI channels from ATF and pass channels to Domains;
- set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI;
- redirect scmi messages from Domains to ATF.Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 5 files changed, 809 insertions(+) create mode 100644 xen/arch/arm/sci/Kconfig create mode 100644 xen/arch/arm/sci/scmi_smc.cxen/arch/arm/Kconfig +2
-0@@ -114,6 +114,8 @@ config SCI support. It allows guests to control system resourcess via one of SCI mediators implemented in XEN. +source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/sci/Kconfig new file +10
-0@@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on SCI + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication.xen/arch/arm/sci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.oxen/arch/arm/sci/scmi_smc.c new file +49
-0@@ -0,0 +1,795 @@ +/* +* xen/arch/arm/sci/scmi_smc.c +* +* SCMI mediator driver, using SCP as transport. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/sci/sci.h> +#include <asm/smccc.h> +#include <asm/io.h> +#include <xen/bitops.h> +#include <xen/config.h> +#include <xen/sched.h> +#include <xen/device_tree.h> +#include <xen/iocap.h> +#include <xen/init.h> +#include <xen/err.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/string.h> +#include <xen/time.h> +#include <xen/vmap.h> + +#define SCMI_BASE_PROTOCOL 0x10 +#define SCMI_BASE_PROTOCOL_ATTIBUTES 0x1 +#define SCMI_BASE_SET_DEVICE_PERMISSIONS 0x9 +#define SCMI_BASE_RESET_AGENT_CONFIGURATION 0xB +#define SCMI_BASE_DISCOVER_AGENT 0x7 + +/* SCMI return codes. See section 4.1.4 of SCMI spec (DEN0056C) */ +#define SCMI_SUCCESS 0 +#define SCMI_NOT_SUPPORTED (-1) +#define SCMI_INVALID_PARAMETERS (-2) +#define SCMI_DENIED (-3) +#define SCMI_NOT_FOUND (-4) +#define SCMI_OUT_OF_RANGE (-5)xen/arch/arm/sci/scmi_smc.c line 59
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+#define SCMI_BUSY (-6) +#define SCMI_COMMS_ERROR (-7) +#define SCMI_GENERIC_ERROR (-8) +#define SCMI_HARDWARE_ERROR (-9) +#define SCMI_PROTOCOL_ERROR (-10) + +#define DT_MATCH_SCMI_SMC DT_MATCH_COMPATIBLE("arm,scmi-smc") + +#define SCMI_SMC_ID "arm,smc-id" +#define SCMI_SHARED_MEMORY "linux,scmi_mem"I could find the following SCMI binding in Linux, which describes the arm,scmi-smc compatible and the arm,smc-id property:
Quoted 6 lines
Documentation/devicetree/bindings/firmware/arm,scmi.yamlHowever, linux,scmi_mem is not described. Aren't you supposed to read the "shmem" property instead? And the compatible string used for this seems to be "arm,scmi-shmem".
We use linux,scmi_mem node to reserve memory, needed for all channels:
reserved-memory { /* reserved region for scmi channels*/ scmi_memory: linux,scmi_mem@53FF0000 { no-map; reg = <0x0 0x53FF0000 0x0 0x10000>; }; };arm,scmi-shmem node used in shmem property defines only 1 page needed to the current scmi channel:
Quoted 7 lines
cpu_scp_shm: scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; };For each Domain reg points to unigue page from linux,scmi_mem region, assigned to this agent.
If we were to use "linux,scmi_mem" we would have to introduce it as a compatible string, not as a node name, and it would need to be described in
Documentation/devicetree/bindings/firmware/arm,scmi.yaml.But from your description I don't think it is necessary. We can just use "arm,scmi-shmem" to describe all the required regions:
reserved-memory { scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; }; scp-shmem@0x53FF1000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF1000 0x0 0x1000>; }; scp-shmem@0x53FF2000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF2000 0x0 0x1000>; }; ...Quoted 4 lines
In other words, if all the individual channel pages are described as "arm,scmi-shmem", why do we also need a single larger region as "linux,scmi_mem"?
That was my first implementation. But I've met a problem with
scmi driver in kernel. I don't remember the exact place, but I remember
there were some if, checking if memory weren't reserved.
That's why I ended up splitting nodes reserved memory region and actual
shmem page.
For linux,scmi_mem node I took format from /reserved-memory/linux,lossy_decompress@54000000, which has no compatible string and provides no-map property.
linux,scmi_shmem node is needed to prevent xen from allocating this
space for the domain.Quoted 7 lines
Very interesting question about should I introduce linux,scmi_mem node and
scmi_devidproperty to theDocumentation/devicetree/bindings/firmware/arm,scmi.yaml? Those node and property are needed only for Xen and useless for non-virtualized systems. I can add this node and property description to arm,scmi.yaml, but leave a note that this is Xen specific params. What do you think about it?Reply below
[...]
Quoted 14 lines
Quoted 14 lines
In general we can't use properties that are not part of the device tree
spec, either https://urldefense.com/v3/__https://www.devicetree.org/specifications/__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXCSnJPN$ [devicetree[.]org] orhttps://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXloYUaj$ [git[.]kernel[.]org]"linux,scmi_mem" is currently absent. Are you aware of any upstreaming activities to get "linux,scmi_mem" upstream under
Documentation/devicetree/bindingsin Linux?If "linux,scmi_mem" is going upstream in Linux, then we could use it. Otherwise, first "linux,scmi_mem" needs to be added somewhere under
Documentation/devicetree/bindings(probablyDocumentation/devicetree/bindings/firmware/arm,scmi.yaml), then we can work on the Xen code that makes use of it.Quoted 5 lines
Quoted 2 lines
Does it make sense?
Yes I agree. I think linux,scmi_mem and
scmi_devidshould be upstreamed.
I will add those properties to arm,scmi.yaml, mark them as related to XEN and send patch.I didn't realize that linux,scmi_mem and
scmi_devidare supposed to be Xen specific. In general, it would be best not to introduce Xen specific properties into generic bindings. It is a problem both from a specification perspective (because it has hard to handle Xen specific cases in fully generic bindings, especially as those bindings are maintained as part of the Linux kernel) and from a user perspective (because now the user has to deal with a Xen-specific dtb, or has to modify the host dtb to add Xen-specific information by hand.)Quoted 8 lines
Quoted 4 lines
Let me start from
scmi_devid. Why wouldscmi_devidbe Xen-specific? It looks like a generic property that should be needed for the Linux SCMI driver too. Why the Linux driver doesn't need it?
scmi_devidused during domain build. It passed as input parameter forSCMI_BASE_SET_DEVICE_PERMISSIONSmessage. On non-virtualized systems - there is no need of this call, because OS
is the only one entity, running on the system.OK. Even if it is only required for virtualized systems, I think that
scmi_devidis important enough that should be part of the upstream binding. I think it is worth starting an email thread on the LKML with Rob Herring and the SCMI maintainers to discuss the addition ofscmi_devidto the binding.Quoted 8 lines
I've chatted with
Volodymyr_Babchukand he gave a great idea to add a list ofdevice_idsto dom.cfg, such as:sci_devs= [ 0, 1, 15, 35 ];Using this approach, we can remove
scmi_devidfrom the device tree and just pass a list ofscmi_devidsto XEN using additional hypercall. We can probably make hypercall taking devid list as input parameter. This will take only 1 hypercall to setup sci permissions.But how would a user know which are the right SCMI IDs to add to the
sci_devslist? Would the user have to go and read the reference manual of the platform to find the SCMI IDs and then writesci_devsby hand? If that is the case, then I think that it would be better to addscmi_devidto device tree.In general, I think this configuration should happen automatically without user intervention. The user should just specify "enable SCMI" and it should work.
Quoted 6 lines
Quoted 5 lines
In regards to linux,scmi_mem, I think it would be best to do without it and fix the Linux SCMI driver if we need to do so. Xen should be able to parse the native "arm,scmi-shmem" nodes and Linux (dom0 or domU) should be able to parse the "arm,scmi-shmem" nodes generated by Xen. Either way, I don't think we should need linux,scmi_mem.
Quoted 5 lines
Quoted 3 lines
This requires further investigation. I will try to make implementation without linux,scmi_mem, using only arm,scmi-shmem nodes and share reuslts with you.
OK, thanks.
Hi Stefano,
As I did some investigation about using reserved-memory area linux,scmi_mem and now I need your advice.
I see 2 possible implementations for now:
1) Add memory-region parameter tocpu_scp_shmnode which points to the reserved memory region.
So device-tree will look like this:reserved-memory { /* reserved region for scmi channels*/ scmi_memory: region@53FF0000{ no-map; reg = <0x0 0x53FF0000 0x0 0x10000>; }; }; cpu_scp_shm: scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; memory-region = <&scmi_memory>; };
Quoted 8 lines
So
cpu_scp_shmnode has a reference toscmi_memoryregion. This mean that xen can find reserved memory region without adding additional names to the device-tree bindings.
memory-region parameter as a reference to reserved memory and region creation described in:
https://github.com/torvalds/linux/blob/v5.15/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txtThis approach I've implemented already and it works.
This approach would require a discussion with the upstream device tree maintainers. Likely, we would need to add a note about the usage of the "memory-region" property to arm,scmi.yaml.
Also, I have the feeling that they would ask to add the "memory-region" property directly to the "arm,scmi-smc" node, as an alternative (or in addition) to the existing "shmem" property.
That said, from my point of view this approach is also a viable option. I don't see any major problems.
The main question (after reading everything else that you wrote below) is whether the "arm,scmi-smc" node in this case could be automatically generated.
Quoted 16 lines
2) The second approach is the format you suggested:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
reserved-memory { scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; }; scp-shmem@0x53FF1000 {Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF1000 0x0 0x1000>; }; scp-shmem@0x53FF2000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF2000 0x0 0x1000>; }; ...
Quoted 8 lines
This approach has an advantage that xen
ARM_SCIdriver do not know about how channels are placed in the reserved memory, but introduces some disadvantages:
a) We provide extra 14 (in our case) arm,scmi-shmem nodes which are not used in the device-tree. In current implementation I have separatescmi.dtsifile which introduces scmi support for both XEN-based and non-virtualized systems. Having 14 extra channels in the device-tree may be confusing.
I can see that while it would be ideal for Xen to see all 14+1 channels in device tree (on the host device tree), we wouldn't want to expose all of them to the domains, not even to dom0.
How many channels do we want dom0 to see by the way? For this discussion, I'll just assume for now that dom0 only sees 1 channel like the domUs.
Now we have a problem: how do we go about "filtering" the "arm,scmi-shmem" device tree nodes? Which is also what you are asking below in point b).
Quoted 1 line
b) In case if we have all 15 channels, described in partial device-tree,
I think you meant "described in the host device tree", right?
Quoted 2 lines
we should not copy any node to the domain device-tree. I think it will be better to generate arm,scmi-shmem node in the Domain device-tree.
Yes, I think it makes sense for Xen to generate the "arm,scmi-shmem" device tree description for the DomU/Dom0 based on the channels allocated to the domain.
Quoted 10 lines
The problem is that arm,scmi-smc node, which is using arm,scmi-shmem node can't be generated. I prefer it to be copied from the partial device-tree because it includes some platform specific configuration, such as func-id and list of the protocols (for example different platforms may require different list of the protocols). So in this case we will have 1 node copied and 1 node generated.
I think even for dom0less we should use arm,scmi-smc node from the device-tree because protocol configuration and funcid is related to the platform.
I am not sure I understood what you wrote. You are saying that the "arm,scmi-smc" node includes some platform specific configurations so it cannot be automatically generated by Xen (or by the tools) and instead it needs to be manually provided as part of the partial dtb for the domU. Is that correct?
If so, I would like to understand the reasons behind it. Manual device tree editing is problematic.
I looked for "func-id" in Documentation/devicetree/bindings/firmware/arm,scmi.yaml but couldn't find any results. Do you have an example of the platform specific configuration or protocol configuration that would make it difficult to automatically generate the "arm,scmi-smc" node for the domains?
Also, is this a problem just for approach #2 or also for approach #1? If it is a problem only for approach #2, then let's just go with approach #1.
Quoted 5 lines
I prefer the second approach and will try to make it if it's OK to copy arm,scmi-smc node from partial Device-tree and generate arm,scmi-shmem node.
What do you think about that?
From a device tree specification perspective, I think both approaches are OK (with a minor comment on the first approach as I wrote above.)
But from a Xen perspective I think it is important that we don't require the user to manually provide the SCMI configuration in the partial DTB. It would be better if we could generate it automatically from Xen or the tools (or even an independent script). Or copy the "arm,scmi-smc" node from the host device tree to the domU device tree without modifications.
So if using approach #1 allows us to automatically generate the "arm,scmi-smc" node for the guest, then I think it's best for sure.
Quoted 4 lines
Also I wanted to mention that I'm not planning to make
ARM_SCIsupport for dom0less in terms of this patch series bacause I can't test dom0less configuration for now. So let me know if some of my functionality breaks dom0less.
That's fine. I don't mean to scope-creep your patch series, which is extremely valuable as is.
That said, I would be happy to provide you with a very simple dom0less configuration for your platform to enable you to test, or alternatively I could write a patch to add dom0less domU support if you are happy to help reviewing and testing it.
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Hi Stefano,
Quoted 338 lines · Stefano Stabellini
Quoted 320 lines · Oleksii Moisieiev
Quoted 290 lines · Stefano Stabellini
Quoted 247 lines · Oleksii Moisieiev
Quoted 246 lines · Stefano Stabellini
Quoted 202 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 184 lines · Stefano Stabellini
Quoted 153 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 129 lines · Stefano Stabellini
Quoted 114 lines · Oleksii Moisieiev
This is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG.
The following features are implemented:
- request SCMI channels from ATF and pass channels to Domains;
- set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI;
- redirect scmi messages from Domains to ATF.Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 5 files changed, 809 insertions(+) create mode 100644 xen/arch/arm/sci/Kconfig create mode 100644 xen/arch/arm/sci/scmi_smc.cxen/arch/arm/Kconfig +2
-0@@ -114,6 +114,8 @@ config SCI support. It allows guests to control system resourcess via one of SCI mediators implemented in XEN. +source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/sci/Kconfig new file +10
-0@@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on SCI + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication.xen/arch/arm/sci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.oxen/arch/arm/sci/scmi_smc.c new file +49
-0@@ -0,0 +1,795 @@ +/* +* xen/arch/arm/sci/scmi_smc.c +* +* SCMI mediator driver, using SCP as transport. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/sci/sci.h> +#include <asm/smccc.h> +#include <asm/io.h> +#include <xen/bitops.h> +#include <xen/config.h> +#include <xen/sched.h> +#include <xen/device_tree.h> +#include <xen/iocap.h> +#include <xen/init.h> +#include <xen/err.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/string.h> +#include <xen/time.h> +#include <xen/vmap.h> + +#define SCMI_BASE_PROTOCOL 0x10 +#define SCMI_BASE_PROTOCOL_ATTIBUTES 0x1 +#define SCMI_BASE_SET_DEVICE_PERMISSIONS 0x9 +#define SCMI_BASE_RESET_AGENT_CONFIGURATION 0xB +#define SCMI_BASE_DISCOVER_AGENT 0x7 + +/* SCMI return codes. See section 4.1.4 of SCMI spec (DEN0056C) */ +#define SCMI_SUCCESS 0 +#define SCMI_NOT_SUPPORTED (-1) +#define SCMI_INVALID_PARAMETERS (-2) +#define SCMI_DENIED (-3) +#define SCMI_NOT_FOUND (-4) +#define SCMI_OUT_OF_RANGE (-5)xen/arch/arm/sci/scmi_smc.c line 59
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+#define SCMI_BUSY (-6) +#define SCMI_COMMS_ERROR (-7) +#define SCMI_GENERIC_ERROR (-8) +#define SCMI_HARDWARE_ERROR (-9) +#define SCMI_PROTOCOL_ERROR (-10) + +#define DT_MATCH_SCMI_SMC DT_MATCH_COMPATIBLE("arm,scmi-smc") + +#define SCMI_SMC_ID "arm,smc-id" +#define SCMI_SHARED_MEMORY "linux,scmi_mem"I could find the following SCMI binding in Linux, which describes the arm,scmi-smc compatible and the arm,smc-id property:
Quoted 6 lines
Documentation/devicetree/bindings/firmware/arm,scmi.yamlHowever, linux,scmi_mem is not described. Aren't you supposed to read the "shmem" property instead? And the compatible string used for this seems to be "arm,scmi-shmem".
We use linux,scmi_mem node to reserve memory, needed for all channels:
reserved-memory { /* reserved region for scmi channels*/ scmi_memory: linux,scmi_mem@53FF0000 { no-map; reg = <0x0 0x53FF0000 0x0 0x10000>; }; };arm,scmi-shmem node used in shmem property defines only 1 page needed to the current scmi channel:
Quoted 7 lines
cpu_scp_shm: scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; };For each Domain reg points to unigue page from linux,scmi_mem region, assigned to this agent.
If we were to use "linux,scmi_mem" we would have to introduce it as a compatible string, not as a node name, and it would need to be described in
Documentation/devicetree/bindings/firmware/arm,scmi.yaml.But from your description I don't think it is necessary. We can just use "arm,scmi-shmem" to describe all the required regions:
reserved-memory { scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; }; scp-shmem@0x53FF1000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF1000 0x0 0x1000>; }; scp-shmem@0x53FF2000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF2000 0x0 0x1000>; }; ...Quoted 4 lines
In other words, if all the individual channel pages are described as "arm,scmi-shmem", why do we also need a single larger region as "linux,scmi_mem"?
That was my first implementation. But I've met a problem with
scmi driver in kernel. I don't remember the exact place, but I remember
there were some if, checking if memory weren't reserved.
That's why I ended up splitting nodes reserved memory region and actual
shmem page.
For linux,scmi_mem node I took format from /reserved-memory/linux,lossy_decompress@54000000, which has no compatible string and provides no-map property.
linux,scmi_shmem node is needed to prevent xen from allocating this
space for the domain.Quoted 7 lines
Very interesting question about should I introduce linux,scmi_mem node and
scmi_devidproperty to theDocumentation/devicetree/bindings/firmware/arm,scmi.yaml? Those node and property are needed only for Xen and useless for non-virtualized systems. I can add this node and property description to arm,scmi.yaml, but leave a note that this is Xen specific params. What do you think about it?Reply below
[...]
Quoted 14 lines
Quoted 14 lines
In general we can't use properties that are not part of the device tree
spec, either https://urldefense.com/v3/__https://www.devicetree.org/specifications/__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXCSnJPN$ [devicetree[.]org] orhttps://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXloYUaj$ [git[.]kernel[.]org]"linux,scmi_mem" is currently absent. Are you aware of any upstreaming activities to get "linux,scmi_mem" upstream under
Documentation/devicetree/bindingsin Linux?If "linux,scmi_mem" is going upstream in Linux, then we could use it. Otherwise, first "linux,scmi_mem" needs to be added somewhere under
Documentation/devicetree/bindings(probablyDocumentation/devicetree/bindings/firmware/arm,scmi.yaml), then we can work on the Xen code that makes use of it.Quoted 5 lines
Quoted 2 lines
Does it make sense?
Yes I agree. I think linux,scmi_mem and
scmi_devidshould be upstreamed.
I will add those properties to arm,scmi.yaml, mark them as related to XEN and send patch.I didn't realize that linux,scmi_mem and
scmi_devidare supposed to be Xen specific. In general, it would be best not to introduce Xen specific properties into generic bindings. It is a problem both from a specification perspective (because it has hard to handle Xen specific cases in fully generic bindings, especially as those bindings are maintained as part of the Linux kernel) and from a user perspective (because now the user has to deal with a Xen-specific dtb, or has to modify the host dtb to add Xen-specific information by hand.)Quoted 8 lines
Quoted 4 lines
Let me start from
scmi_devid. Why wouldscmi_devidbe Xen-specific? It looks like a generic property that should be needed for the Linux SCMI driver too. Why the Linux driver doesn't need it?
scmi_devidused during domain build. It passed as input parameter forSCMI_BASE_SET_DEVICE_PERMISSIONSmessage. On non-virtualized systems - there is no need of this call, because OS
is the only one entity, running on the system.OK. Even if it is only required for virtualized systems, I think that
scmi_devidis important enough that should be part of the upstream binding. I think it is worth starting an email thread on the LKML with Rob Herring and the SCMI maintainers to discuss the addition ofscmi_devidto the binding.Quoted 8 lines
I've chatted with
Volodymyr_Babchukand he gave a great idea to add a list ofdevice_idsto dom.cfg, such as:sci_devs= [ 0, 1, 15, 35 ];Using this approach, we can remove
scmi_devidfrom the device tree and just pass a list ofscmi_devidsto XEN using additional hypercall. We can probably make hypercall taking devid list as input parameter. This will take only 1 hypercall to setup sci permissions.But how would a user know which are the right SCMI IDs to add to the
sci_devslist? Would the user have to go and read the reference manual of the platform to find the SCMI IDs and then writesci_devsby hand? If that is the case, then I think that it would be better to addscmi_devidto device tree.In general, I think this configuration should happen automatically without user intervention. The user should just specify "enable SCMI" and it should work.
Quoted 6 lines
Quoted 5 lines
In regards to linux,scmi_mem, I think it would be best to do without it and fix the Linux SCMI driver if we need to do so. Xen should be able to parse the native "arm,scmi-shmem" nodes and Linux (dom0 or domU) should be able to parse the "arm,scmi-shmem" nodes generated by Xen. Either way, I don't think we should need linux,scmi_mem.
Quoted 5 lines
Quoted 3 lines
This requires further investigation. I will try to make implementation without linux,scmi_mem, using only arm,scmi-shmem nodes and share reuslts with you.
OK, thanks.
Hi Stefano,
As I did some investigation about using reserved-memory area linux,scmi_mem and now I need your advice.
I see 2 possible implementations for now:
1) Add memory-region parameter tocpu_scp_shmnode which points to the reserved memory region.
So device-tree will look like this:reserved-memory { /* reserved region for scmi channels*/ scmi_memory: region@53FF0000{ no-map; reg = <0x0 0x53FF0000 0x0 0x10000>; }; }; cpu_scp_shm: scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; memory-region = <&scmi_memory>; };Quoted 8 lines
So
cpu_scp_shmnode has a reference toscmi_memoryregion. This mean that xen can find reserved memory region without adding additional names to the device-tree bindings.
memory-region parameter as a reference to reserved memory and region creation described in:https://urldefense.com/v3/__https://github.com/torvalds/linux/blob/v5.15/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt__;!!GF_29dbcQIUBPA!k6x19x1gYF1CPlgAZj7std3ifqhq-9DXvuF0nwonNPUwMzZpYHYbrRJziJrgdFIOjyan$ [github[.]com]This approach I've implemented already and it works.
This approach would require a discussion with the upstream device tree maintainers. Likely, we would need to add a note about the usage of the "memory-region" property to arm,scmi.yaml.
Also, I have the feeling that they would ask to add the "memory-region" property directly to the "arm,scmi-smc" node, as an alternative (or in addition) to the existing "shmem" property.
Quoted 7 lines
That said, from my point of view this approach is also a viable option. I don't see any major problems.
The main question (after reading everything else that you wrote below) is whether the "arm,scmi-smc" node in this case could be automatically generated.
arm,scmi-smc node can be generated in both cases. I think I'd leave it as backup in case if the second approach will not work.
Quoted 26 lines
Quoted 17 lines
2) The second approach is the format you suggested:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
reserved-memory { scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; }; scp-shmem@0x53FF1000 {Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF1000 0x0 0x1000>; }; scp-shmem@0x53FF2000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF2000 0x0 0x1000>; }; ...Quoted 8 lines
This approach has an advantage that xen
ARM_SCIdriver do not know about how channels are placed in the reserved memory, but introduces some disadvantages:
a) We provide extra 14 (in our case) arm,scmi-shmem nodes which are not used in the device-tree. In current implementation I have separatescmi.dtsifile which introduces scmi support for both XEN-based and non-virtualized systems. Having 14 extra channels in the device-tree may be confusing.
Quoted 7 lines
I can see that while it would be ideal for Xen to see all 14+1 channels in device tree (on the host device tree), we wouldn't want to expose all of them to the domains, not even to dom0.
How many channels do we want dom0 to see by the way? For this discussion, I'll just assume for now that dom0 only sees 1 channel like the domUs.
For dom0 we need only one channel.
Quoted 5 lines
Now we have a problem: how do we go about "filtering" the "arm,scmi-shmem" device tree nodes? Which is also what you are asking below in point b).
Xen will not need to filter "arm,scmi-shmem" node. It will just create shmem node in Domain device-tree. I don't see any problem for xen configuration here.
What bothers me here is that I set scmi configuration for platform dts, not for xen or domu dts files.
So for example I have the following structure of the dts files for my platform (r8a77961-salvator-xs):
* r8a77961-scmi.dtsi - this file includes all scmi related nodes and setscmi_devid for the devices, that should use scmi.
* r8a77961-salvator-xs.dts - dts file which generates dtb for the platform.
It includes r8a77961-scmi.dtsi so I populate scmi to platform dtb, which is used for system with no hypervisor.
* r8a77961-salvator-xs-xen.dts - dts file for xen which includesr8a77961-salvator-xs.dts and inherits scmi configuration from it.
* r8a77961-salvator-xs-domu.dts - dts file for DomU which includesr8a77961-salvator-xs.dts and inherits scmi configuration from it.
In this case r8a77961-salvator-xs.dtb r8a77961-salvator-xs-xen.dtb r8a77961-salvator-xs-domu.dtb files will inherit 14+1 channel.
I can give you a link to Merge request with this changes if you need it.
For xen and domu dtb it is not a problem because all "arm,scmi-shmem" nodes will be omitted and new will be generated for the domains.
What bothers me is that r8a77961-salvator-xs.dtb will have 14 unused channels.
Just got an idea while writing this: I can create only one "arm,scmi-shmem" node in r8a77961-scmi.dtsi and add 14 more nodes, needed for xen explicitly in r8a77961-salvator-xs-xen.dts.
Then we will have valid configurations for all cases. This can be a solution. What do you think?
Quoted 5 lines
Quoted 2 lines
b) In case if we have all 15 channels, described in partial device-tree,
I think you meant "described in the host device tree", right?
Yeah that's what I've meant.
Quoted 26 lines
Quoted 3 lines
we should not copy any node to the domain device-tree. I think it will be better to generate arm,scmi-shmem node in the Domain device-tree.
Yes, I think it makes sense for Xen to generate the "arm,scmi-shmem" device tree description for the DomU/Dom0 based on the channels allocated to the domain.
Quoted 10 lines
The problem is that arm,scmi-smc node, which is using arm,scmi-shmem node can't be generated. I prefer it to be copied from the partial device-tree because it includes some platform specific configuration, such as func-id and list of the protocols (for example different platforms may require different list of the protocols). So in this case we will have 1 node copied and 1 node generated.
I think even for dom0less we should use arm,scmi-smc node from the device-tree because protocol configuration and funcid is related to the platform.
I am not sure I understood what you wrote. You are saying that the "arm,scmi-smc" node includes some platform specific configurations so it cannot be automatically generated by Xen (or by the tools) and instead it needs to be manually provided as part of the partial dtb for the domU. Is that correct?
Quoted 8 lines
If so, I would like to understand the reasons behind it. Manual device tree editing is problematic.
I looked for "func-id" in
Documentation/devicetree/bindings/firmware/arm,scmi.yamlbut couldn't find any results. Do you have an example of the platform specific configuration or protocol configuration that would make it difficult to automatically generate the "arm,scmi-smc" node for the domains?
Sorry, I used wrong term (used term from the specification), arm,smc-id of cause.
Quoted 5 lines
Also, is this a problem just for approach #2 or also for approach #1? If it is a problem only for approach #2, then let's just go with approach #1.
We can't copy "arm,scmi-smc" in both approaches. The difference is that in the first approach we can copy both "arm,scmi-smc" and "arm,scmi-shmem" nodes while in the second approach we should copy "arm,scmi-smc", but we have to generate "arm,scmi-shmem" node.
arm,scmi-smc node can't be generated because it includes properties and configurations that depends from platform and should be get from the device tree.
Here is "arm,scmi-smc" node expample:
firmware {
scmi {
compatible = "arm,scmi-smc"
arm,smc-id = <0x82000002>;
shmem = <&cpu_scp_shm>;
#address-cells = <1>;
#size-cells = <0>;
scmi_power: protocol@11 {
reg = <0x11>;
#power-domain-cells = <1>;
};
scmi_clock: protocol@14 {
...
};
scmi_reset: protocol@16 {
...
};
...
};
};It has 3 configurable options:
* arm,smc-id parameter, setting func_id for scmi protocol. This id can be
different for different platforms.
For example stm32mp1 architecture use different scm-id for different agents:
https://github.com/ARM-software/arm-trusted-firmware/blob/0586c41b3f2d52aae847b7212e7b0c7e19197ea2/plat/st/stm32mp1/include/stm32mp1_smc.h#L39
* shmem which includes phandle to arm,scmi-shmem node. But this is not
a problem and can be updated.
* list of the protocol subnodes. This is also configurable parameter,
not regs or names, but the number of the protocols. For example onle platform can use power-domains/clock/resets via scmi, when another will require volage-control and sensor-management to be added.
Xen should know this parameters to be able to generate "arm,scmi-smc" node.
Also we're currently discussing new scmi protocol with ARM: Pinctrl over SCMI.
It should allow domains to access pinctrl subsystem, placed in Firmware through SCMI protocol.scmi_pinctrl node will look like this:
firmware {
scmi {
...
scmi_pinctrl: protocol@18 {
reg = <0x18>;
#pinctrl-cells = <0>;
i2c2_pins: i2c2 {
groups = <74>; /* i2c2_a */
function = <15>; /* i2c2 */
};
irq0_pins: irq0 {
groups = <81>; /* intc_ex_irq0 */
function = <19>; /* intc_ex */
};
avb_pins: avb {
mux {
/* avb_link, avb_mdio, avb_mii */
groups = <17>, <21>, <22>;
function = <1>; /* avb */
};
pins_mdio {
groups = <21>; /* avb_mdio */
drive-strength = <24>;
};
pins_mii_tx {
/* PIN_AVB_TX_CTL, PIN_AVB_TXC, PIN_AVB_TD0,
PIN_AVB_TD1, PIN_AVB_TD2, PIN_AVB_TD3 */
pins = <242>, <240>, <236>, <237>, <238>, <239>;
drive-strength = <12>;
};
};
...
};
};
};So "arm,scmi-smc" node will have even more platform specific settings.
Quoted 7 lines
Quoted 6 lines
I prefer the second approach and will try to make it if it's OK to copy arm,scmi-smc node from partial Device-tree and generate arm,scmi-shmem node.
What do you think about that?
Quoted 8 lines
From a device tree specification perspective, I think both approaches are OK (with a minor comment on the first approach as I wrote above.)
But from a Xen perspective I think it is important that we don't require the user to manually provide the SCMI configuration in the partial DTB. It would be better if we could generate it automatically from Xen or the tools (or even an independent script). Or copy the "arm,scmi-smc" node from the host device tree to the domU device tree without modifications.
I think copy "arm,scmi-smc" node is the only option we have. I'm not sure what do you mean under "host device tree" if you mean Xen device-tree - then I think it will not cover the case with stm32mp1 I've mentioned above. I think it will be better to copy "arm,scmi-smc" node from Domu partial Device-tree to Domu device-tree.
So AGENT0 smc-id will be set in xen device-tree and copied to dom0 and AGENT1 scm-is set in domu device-tree and copied to dom-u.
Do you agree with my points?
Quoted 4 lines
So if using approach #1 allows us to automatically generate the "arm,scmi-smc" node for the guest, then I think it's best for sure.
Summarizing all written above I would focus on the second approach and put aside the first approach implementation. If you don't mind.
Quoted 6 lines
Quoted 5 lines
Also I wanted to mention that I'm not planning to make
ARM_SCIsupport for dom0less in terms of this patch series bacause I can't test dom0less configuration for now. So let me know if some of my functionality breaks dom0less.
Quoted 7 lines
That's fine. I don't mean to scope-creep your patch series, which is extremely valuable as is.
That said, I would be happy to provide you with a very simple dom0less configuration for your platform to enable you to test, or alternatively I could write a patch to add dom0less domU support if you are happy to help reviewing and testing it.
I was thinking about making dom0less support in the different patch-series because there are still questions to be discussed.
For example, how arm,scmi-smc node will be generated for DomUs and how the case, when scmi configuration is different for DomU1 and DomU2 (as in case of stm32mp1 when smc-id is different) should be handled.
What do you think about continue without dom0less support and discuss dom0less once we done with the main part?
Oleksii.
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Quoted 417 lines · Oleksii Moisieiev
Quoted 338 lines · Stefano Stabellini
Quoted 320 lines · Oleksii Moisieiev
Quoted 290 lines · Stefano Stabellini
Quoted 247 lines · Oleksii Moisieiev
Quoted 246 lines · Stefano Stabellini
Quoted 202 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 184 lines · Stefano Stabellini
Quoted 153 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 129 lines · Stefano Stabellini
Quoted 114 lines · Oleksii Moisieiev
This is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG.
The following features are implemented:
- request SCMI channels from ATF and pass channels to Domains;
- set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI;
- redirect scmi messages from Domains to ATF.Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 5 files changed, 809 insertions(+) create mode 100644 xen/arch/arm/sci/Kconfig create mode 100644 xen/arch/arm/sci/scmi_smc.cxen/arch/arm/Kconfig +2
-0@@ -114,6 +114,8 @@ config SCI support. It allows guests to control system resourcess via one of SCI mediators implemented in XEN. +source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/sci/Kconfig new file +10
-0@@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on SCI + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication.xen/arch/arm/sci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.oxen/arch/arm/sci/scmi_smc.c new file +49
-0@@ -0,0 +1,795 @@ +/* +* xen/arch/arm/sci/scmi_smc.c +* +* SCMI mediator driver, using SCP as transport. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/sci/sci.h> +#include <asm/smccc.h> +#include <asm/io.h> +#include <xen/bitops.h> +#include <xen/config.h> +#include <xen/sched.h> +#include <xen/device_tree.h> +#include <xen/iocap.h> +#include <xen/init.h> +#include <xen/err.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/string.h> +#include <xen/time.h> +#include <xen/vmap.h> + +#define SCMI_BASE_PROTOCOL 0x10 +#define SCMI_BASE_PROTOCOL_ATTIBUTES 0x1 +#define SCMI_BASE_SET_DEVICE_PERMISSIONS 0x9 +#define SCMI_BASE_RESET_AGENT_CONFIGURATION 0xB +#define SCMI_BASE_DISCOVER_AGENT 0x7 + +/* SCMI return codes. See section 4.1.4 of SCMI spec (DEN0056C) */ +#define SCMI_SUCCESS 0 +#define SCMI_NOT_SUPPORTED (-1) +#define SCMI_INVALID_PARAMETERS (-2) +#define SCMI_DENIED (-3) +#define SCMI_NOT_FOUND (-4) +#define SCMI_OUT_OF_RANGE (-5)xen/arch/arm/sci/scmi_smc.c line 59
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+#define SCMI_BUSY (-6) +#define SCMI_COMMS_ERROR (-7) +#define SCMI_GENERIC_ERROR (-8) +#define SCMI_HARDWARE_ERROR (-9) +#define SCMI_PROTOCOL_ERROR (-10) + +#define DT_MATCH_SCMI_SMC DT_MATCH_COMPATIBLE("arm,scmi-smc") + +#define SCMI_SMC_ID "arm,smc-id" +#define SCMI_SHARED_MEMORY "linux,scmi_mem"I could find the following SCMI binding in Linux, which describes the arm,scmi-smc compatible and the arm,smc-id property:
Quoted 6 lines
Documentation/devicetree/bindings/firmware/arm,scmi.yamlHowever, linux,scmi_mem is not described. Aren't you supposed to read the "shmem" property instead? And the compatible string used for this seems to be "arm,scmi-shmem".
We use linux,scmi_mem node to reserve memory, needed for all channels:
reserved-memory { /* reserved region for scmi channels*/ scmi_memory: linux,scmi_mem@53FF0000 { no-map; reg = <0x0 0x53FF0000 0x0 0x10000>; }; };arm,scmi-shmem node used in shmem property defines only 1 page needed to the current scmi channel:
Quoted 7 lines
cpu_scp_shm: scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; };For each Domain reg points to unigue page from linux,scmi_mem region, assigned to this agent.
If we were to use "linux,scmi_mem" we would have to introduce it as a compatible string, not as a node name, and it would need to be described in
Documentation/devicetree/bindings/firmware/arm,scmi.yaml.But from your description I don't think it is necessary. We can just use "arm,scmi-shmem" to describe all the required regions:
reserved-memory { scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; }; scp-shmem@0x53FF1000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF1000 0x0 0x1000>; }; scp-shmem@0x53FF2000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF2000 0x0 0x1000>; }; ...Quoted 4 lines
In other words, if all the individual channel pages are described as "arm,scmi-shmem", why do we also need a single larger region as "linux,scmi_mem"?
That was my first implementation. But I've met a problem with
scmi driver in kernel. I don't remember the exact place, but I remember
there were some if, checking if memory weren't reserved.
That's why I ended up splitting nodes reserved memory region and actual
shmem page.
For linux,scmi_mem node I took format from /reserved-memory/linux,lossy_decompress@54000000, which has no compatible string and provides no-map property.
linux,scmi_shmem node is needed to prevent xen from allocating this
space for the domain.Quoted 7 lines
Very interesting question about should I introduce linux,scmi_mem node and
scmi_devidproperty to theDocumentation/devicetree/bindings/firmware/arm,scmi.yaml? Those node and property are needed only for Xen and useless for non-virtualized systems. I can add this node and property description to arm,scmi.yaml, but leave a note that this is Xen specific params. What do you think about it?Reply below
[...]
Quoted 14 lines
Quoted 14 lines
In general we can't use properties that are not part of the device tree
spec, either https://urldefense.com/v3/__https://www.devicetree.org/specifications/__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXCSnJPN$ [devicetree[.]org] orhttps://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXloYUaj$ [git[.]kernel[.]org]"linux,scmi_mem" is currently absent. Are you aware of any upstreaming activities to get "linux,scmi_mem" upstream under
Documentation/devicetree/bindingsin Linux?If "linux,scmi_mem" is going upstream in Linux, then we could use it. Otherwise, first "linux,scmi_mem" needs to be added somewhere under
Documentation/devicetree/bindings(probablyDocumentation/devicetree/bindings/firmware/arm,scmi.yaml), then we can work on the Xen code that makes use of it.Quoted 5 lines
Quoted 2 lines
Does it make sense?
Yes I agree. I think linux,scmi_mem and
scmi_devidshould be upstreamed.
I will add those properties to arm,scmi.yaml, mark them as related to XEN and send patch.I didn't realize that linux,scmi_mem and
scmi_devidare supposed to be Xen specific. In general, it would be best not to introduce Xen specific properties into generic bindings. It is a problem both from a specification perspective (because it has hard to handle Xen specific cases in fully generic bindings, especially as those bindings are maintained as part of the Linux kernel) and from a user perspective (because now the user has to deal with a Xen-specific dtb, or has to modify the host dtb to add Xen-specific information by hand.)Quoted 8 lines
Quoted 4 lines
Let me start from
scmi_devid. Why wouldscmi_devidbe Xen-specific? It looks like a generic property that should be needed for the Linux SCMI driver too. Why the Linux driver doesn't need it?
scmi_devidused during domain build. It passed as input parameter forSCMI_BASE_SET_DEVICE_PERMISSIONSmessage. On non-virtualized systems - there is no need of this call, because OS
is the only one entity, running on the system.OK. Even if it is only required for virtualized systems, I think that
scmi_devidis important enough that should be part of the upstream binding. I think it is worth starting an email thread on the LKML with Rob Herring and the SCMI maintainers to discuss the addition ofscmi_devidto the binding.Quoted 8 lines
I've chatted with
Volodymyr_Babchukand he gave a great idea to add a list ofdevice_idsto dom.cfg, such as:sci_devs= [ 0, 1, 15, 35 ];Using this approach, we can remove
scmi_devidfrom the device tree and just pass a list ofscmi_devidsto XEN using additional hypercall. We can probably make hypercall taking devid list as input parameter. This will take only 1 hypercall to setup sci permissions.But how would a user know which are the right SCMI IDs to add to the
sci_devslist? Would the user have to go and read the reference manual of the platform to find the SCMI IDs and then writesci_devsby hand? If that is the case, then I think that it would be better to addscmi_devidto device tree.In general, I think this configuration should happen automatically without user intervention. The user should just specify "enable SCMI" and it should work.
Quoted 6 lines
Quoted 5 lines
In regards to linux,scmi_mem, I think it would be best to do without it and fix the Linux SCMI driver if we need to do so. Xen should be able to parse the native "arm,scmi-shmem" nodes and Linux (dom0 or domU) should be able to parse the "arm,scmi-shmem" nodes generated by Xen. Either way, I don't think we should need linux,scmi_mem.
Quoted 5 lines
Quoted 3 lines
This requires further investigation. I will try to make implementation without linux,scmi_mem, using only arm,scmi-shmem nodes and share reuslts with you.
OK, thanks.
Hi Stefano,
As I did some investigation about using reserved-memory area linux,scmi_mem and now I need your advice.
I see 2 possible implementations for now:
1) Add memory-region parameter tocpu_scp_shmnode which points to the reserved memory region.
So device-tree will look like this:reserved-memory { /* reserved region for scmi channels*/ scmi_memory: region@53FF0000{ no-map; reg = <0x0 0x53FF0000 0x0 0x10000>; }; }; cpu_scp_shm: scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; memory-region = <&scmi_memory>; };Quoted 8 lines
So
cpu_scp_shmnode has a reference toscmi_memoryregion. This mean that xen can find reserved memory region without adding additional names to the device-tree bindings.
memory-region parameter as a reference to reserved memory and region creation described in:https://urldefense.com/v3/__https://github.com/torvalds/linux/blob/v5.15/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt__;!!GF_29dbcQIUBPA!k6x19x1gYF1CPlgAZj7std3ifqhq-9DXvuF0nwonNPUwMzZpYHYbrRJziJrgdFIOjyan$ [github[.]com]This approach I've implemented already and it works.
This approach would require a discussion with the upstream device tree maintainers. Likely, we would need to add a note about the usage of the "memory-region" property to arm,scmi.yaml.
Also, I have the feeling that they would ask to add the "memory-region" property directly to the "arm,scmi-smc" node, as an alternative (or in addition) to the existing "shmem" property.
Quoted 7 lines
That said, from my point of view this approach is also a viable option. I don't see any major problems.
The main question (after reading everything else that you wrote below) is whether the "arm,scmi-smc" node in this case could be automatically generated.
arm,scmi-smc node can be generated in both cases. I think I'd leave it as backup in case if the second approach will not work.
Quoted 26 lines
Quoted 17 lines
2) The second approach is the format you suggested:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
reserved-memory { scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; }; scp-shmem@0x53FF1000 {Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF1000 0x0 0x1000>; }; scp-shmem@0x53FF2000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF2000 0x0 0x1000>; }; ...Quoted 8 lines
This approach has an advantage that xen
ARM_SCIdriver do not know about how channels are placed in the reserved memory, but introduces some disadvantages:
a) We provide extra 14 (in our case) arm,scmi-shmem nodes which are not used in the device-tree. In current implementation I have separatescmi.dtsifile which introduces scmi support for both XEN-based and non-virtualized systems. Having 14 extra channels in the device-tree may be confusing.Quoted 7 lines
I can see that while it would be ideal for Xen to see all 14+1 channels in device tree (on the host device tree), we wouldn't want to expose all of them to the domains, not even to dom0.
How many channels do we want dom0 to see by the way? For this discussion, I'll just assume for now that dom0 only sees 1 channel like the domUs.
For dom0 we need only one channel.
Quoted 5 lines
Now we have a problem: how do we go about "filtering" the "arm,scmi-shmem" device tree nodes? Which is also what you are asking below in point b).
Xen will not need to filter "arm,scmi-shmem" node. It will just create shmem node in Domain device-tree. I don't see any problem for xen configuration here.
What bothers me here is that I set scmi configuration for platform dts, not for xen or domu dts files.
So for example I have the following structure of the dts files for my platform (r8a77961-salvator-xs):
*r8a77961-scmi.dtsi- this file includes all scmi related nodes and setscmi_devidfor the devices, that should use scmi.
*r8a77961-salvator-xs.dts- dts file which generates dtb for the platform.
It includesr8a77961-scmi.dtsiso I populate scmi to platform dtb, which is used for system with no hypervisor.
*r8a77961-salvator-xs-xen.dts- dts file for xen which includesr8a77961-salvator-xs.dtsand inherits scmi configuration from it.
*r8a77961-salvator-xs-domu.dts- dts file for DomU which includesr8a77961-salvator-xs.dtsand inherits scmi configuration from it.In this case r8a77961-salvator-xs.dtb r8a77961-salvator-xs-xen.dtb r8a77961-salvator-xs-domu.dtb files will inherit 14+1 channel.
I can give you a link to Merge request with this changes if you need it.
For xen and domu dtb it is not a problem because all "arm,scmi-shmem" nodes will be omitted and new will be generated for the domains.
Quoted 8 lines
What bothers me is that r8a77961-salvator-xs.dtb will have 14 unused channels.
Just got an idea while writing this: I can create only one "arm,scmi-shmem" node in
r8a77961-scmi.dtsiand add 14 more nodes, needed for xen explicitly inr8a77961-salvator-xs-xen.dts.Then we will have valid configurations for all cases. This can be a solution. What do you think?
It is good that you brought this up because it helps me explain what I mean. And of course it is up to you where you place the nodes in the various dts files at your disposal. Either way it would work but I think they should belong to r8a77961-salvator-xs.dts.
Generally the platform vendor (e.g. Xilinx) provides a device tree description of the platform to use including all the available resources and firmware interfaces. In your case it would be r8a77961-scmi.dtsi + r8a77961-salvator-xs.dts. This is what I call the "host device tree" below. Users should be able to boot a fully functional system using the host device tree pretty much "as is" to run Xen, Linux or any other software.
Certainly the SCMI device tree description should be part of the host device tree, so in your case it would be r8a77961-salvator-xs.dts. And the description should include all 14+1 channels because this is the generic platform description -- we cannot know for sure how the users are going to use the system.
This is why r8a77961-salvator-xs-xen.dts should be as small as possible or ideally inexistent. There shouldn't be a need for a special device tree modification to allow Xen to run. In reality, even at Xilinx we have something like r8a77961-salvator-xs-xen.dts, although it is really small.
But I see that r8a77961-salvator-xs-xen.dts could be viewed as the device tree additions to run hypervisors and from that point of view it is more acceptable to place the 14 channels there.
The biggest problem is r8a77961-salvator-xs-domu.dts: who is going to write it? And how? It wouldn't be provided by the platform vendor, so it is the user the one that has to find a way to write it.
I know the user already has to write a partial DTB for device assignment, but any time the process is more complex than "copy the host device tree node for device XXX to the partial DTB" it is a problem. Errors are made and the system doesn't work.
I think we don't want to make it even more difficult by having to manually produce the SCMI domU description too. The SCMI description for domU could be automatically generated by Xen, or libxl/xl. If that's an issue, then the SCMI description could be automatically generated by an external tool but I think it would make things more complex and harder to maintain.
In short my point of view is:
- r8a77961-scmi.dtsi + r8a77961-salvator-xs.dts should be as generic as possible so the SCMI nodes should have 14+1 channels
- but putting the 14 channels in r8a77961-salvator-xs-xen.dts is still OKish
- it is important that r8a77961-salvator-xs-domu.dts is automatically generated by Xen or libxl or another software tool
Quoted 172 lines
Quoted 4 lines
Quoted 1 line
b) In case if we have all 15 channels, described in partial device-tree,
I think you meant "described in the host device tree", right?
Yeah that's what I've meant.
Quoted 26 lines
Quoted 3 lines
we should not copy any node to the domain device-tree. I think it will be better to generate arm,scmi-shmem node in the Domain device-tree.
Yes, I think it makes sense for Xen to generate the "arm,scmi-shmem" device tree description for the DomU/Dom0 based on the channels allocated to the domain.
Quoted 10 lines
The problem is that arm,scmi-smc node, which is using arm,scmi-shmem node can't be generated. I prefer it to be copied from the partial device-tree because it includes some platform specific configuration, such as func-id and list of the protocols (for example different platforms may require different list of the protocols). So in this case we will have 1 node copied and 1 node generated.
I think even for dom0less we should use arm,scmi-smc node from the device-tree because protocol configuration and funcid is related to the platform.
I am not sure I understood what you wrote. You are saying that the "arm,scmi-smc" node includes some platform specific configurations so it cannot be automatically generated by Xen (or by the tools) and instead it needs to be manually provided as part of the partial dtb for the domU. Is that correct?
Quoted 8 lines
If so, I would like to understand the reasons behind it. Manual device tree editing is problematic.
I looked for "func-id" in
Documentation/devicetree/bindings/firmware/arm,scmi.yamlbut couldn't find any results. Do you have an example of the platform specific configuration or protocol configuration that would make it difficult to automatically generate the "arm,scmi-smc" node for the domains?Sorry, I used wrong term (used term from the specification), arm,smc-id of cause.
Quoted 5 lines
Also, is this a problem just for approach #2 or also for approach #1? If it is a problem only for approach #2, then let's just go with approach #1.
We can't copy "arm,scmi-smc" in both approaches. The difference is that in the first approach we can copy both "arm,scmi-smc" and "arm,scmi-shmem" nodes while in the second approach we should copy "arm,scmi-smc", but we have to generate "arm,scmi-shmem" node.
arm,scmi-smc node can't be generated because it includes properties and configurations that depends from platform and should be get from the device tree.
Here is "arm,scmi-smc" node expample:firmware { scmi { compatible = "arm,scmi-smc" arm,smc-id = <0x82000002>; shmem = <&cpu_scp_shm>; #address-cells = <1>; #size-cells = <0>; scmi_power: protocol@11 { reg = <0x11>; #power-domain-cells = <1>; }; scmi_clock: protocol@14 { ... }; scmi_reset: protocol@16 { ... }; ... }; };It has 3 configurable options:
* arm,smc-id parameter, settingfunc_idfor scmi protocol. This id can be
different for different platforms.
For example stm32mp1 architecture use different scm-id for different agents:
https://github.com/ARM-software/arm-trusted-firmware/blob/0586c41b3f2d52aae847b7212e7b0c7e19197ea2/plat/st/stm32mp1/include/stm32mp1_smc.h#L39* shmem which includes phandle to arm,scmi-shmem node. But this is not
a problem and can be updated.* list of the protocol subnodes. This is also configurable parameter,
not regs or names, but the number of the protocols. For example onle platform can use power-domains/clock/resets via scmi, when another will require volage-control and sensor-management to be added.Xen should know this parameters to be able to generate "arm,scmi-smc" node.
Also we're currently discussing new scmi protocol with ARM: Pinctrl over SCMI.
It should allow domains to access pinctrl subsystem, placed in Firmware through SCMI protocol.
scmi_pinctrlnode will look like this:firmware { scmi { ... scmi_pinctrl: protocol@18 { reg = <0x18>; #pinctrl-cells = <0>; i2c2_pins: i2c2 { groups = <74>; /* i2c2_a */ function = <15>; /* i2c2 */ }; irq0_pins: irq0 { groups = <81>; /* intc_ex_irq0 */ function = <19>; /* intc_ex */ }; avb_pins: avb { mux { /* avb_link, avb_mdio, avb_mii */ groups = <17>, <21>, <22>; function = <1>; /* avb */ }; pins_mdio { groups = <21>; /* avb_mdio */ drive-strength = <24>; }; pins_mii_tx { /* PIN_AVB_TX_CTL, PIN_AVB_TXC, PIN_AVB_TD0, PIN_AVB_TD1, PIN_AVB_TD2, PIN_AVB_TD3 */ pins = <242>, <240>, <236>, <237>, <238>, <239>; drive-strength = <12>; }; }; ... }; }; };So "arm,scmi-smc" node will have even more platform specific settings.
Quoted 7 lines
Quoted 6 lines
I prefer the second approach and will try to make it if it's OK to copy arm,scmi-smc node from partial Device-tree and generate arm,scmi-shmem node.
What do you think about that?
Quoted 8 lines
From a device tree specification perspective, I think both approaches are OK (with a minor comment on the first approach as I wrote above.)
But from a Xen perspective I think it is important that we don't require the user to manually provide the SCMI configuration in the partial DTB. It would be better if we could generate it automatically from Xen or the tools (or even an independent script). Or copy the "arm,scmi-smc" node from the host device tree to the domU device tree without modifications.
I think copy "arm,scmi-smc" node is the only option we have. I'm not sure what do you mean under "host device tree" if you mean Xen device-tree - then I think it will not cover the case with stm32mp1 I've mentioned above. I think it will be better to copy "arm,scmi-smc" node from Domu partial Device-tree to Domu device-tree.
So AGENT0 smc-id will be set in xen device-tree and copied to dom0 and AGENT1 scm-is set in domu device-tree and copied to dom-u.
Quoted 1 line
Do you agree with my points?
I think we are saying similar things, but we are getting mixed up with the terminology. Let's start from the basics :-)
# Host device tree
The device tree given to Xen at boot time. This is the device tree that Xen parses to discover what's available on the platform. In your case, it seems to include r8a77961-salvator-xs-xen.dts.
# Partial DTB
(Ignoring Dom0less) this is the small DTB that gets passed to xl with the "device_tree" option in the xl config file. It is copied verbatim to the domU device tree by xl/libxl.
# Copy the "arm,scmi-smc" node from host device tree
This means that the domU "arm,scmi-smc" node is an exact copy of the host device tree SCMI node. I don't think this is actually possible in most cases because the domU description is typically a bit different from the host description. For instance, the host description could include 14+1 channels while the domU description should only include 1 channel.
# Copy the "arm,scmi-smc" node from the partial DTB
This implies that somebody or something create an "arm,scmi-smc" node for the domU and placed it into the partial DTB. Then, Xen and/or xl/libxl will copy the node from the partial DTB to the DomU device tree. The main question in this case is: who is going to write the partial DTB? We dont want the user (i.e. a person) to have to manually write the SCMI description for the domU. It should be an automated tools that does it. At that point, it is easier if it is Xen or xl/libxl. Alternativaly, we could think of an external tool but I think it would make things more difficult to maintain.
# Generate the "arm,scmi-smc" node for domUs
When I write "generate the arm,scmi-smc node", I mean that Xen and libxl/xl will generate the "arm,scmi-smc" node for the domU. Thus, the node will not be copied from the partial DTB or from the device tree, instead, it should be created directly by Xen and/or libxl/xl.
However, the domU "arm,scmi-smc" node could still be derived from the host device tree "arm,scmi-smc" node. In other words, Xen or xl/libxl would look at the host device tree "arm,scmi-smc" node, copy it to the domU device tree while making as many changes as necessary.
The DomU "arm,scmi-smc" node doesn't have to be entirely fake and static. It could be dynamically created to match the host device tree description. I think this is the best option.
# Conclusion
I am suggesting that Xen and/or libxl automatically produce the "arm,scmi-smc" node for domUs based on the host device tree description and based on the channel mapped to the domU. This way, the user (a person) doesn't have to go and manually edit the domU partial DTB.
Quoted 6 lines
Quoted 3 lines
So if using approach #1 allows us to automatically generate the "arm,scmi-smc" node for the guest, then I think it's best for sure.
Summarizing all written above I would focus on the second approach and put aside the first approach implementation. If you don't mind.
Sure, that's fine by me
Quoted 16 lines
Quoted 5 lines
Quoted 4 lines
Also I wanted to mention that I'm not planning to make
ARM_SCIsupport for dom0less in terms of this patch series bacause I can't test dom0less configuration for now. So let me know if some of my functionality breaks dom0less.Quoted 7 lines
That's fine. I don't mean to scope-creep your patch series, which is extremely valuable as is.
That said, I would be happy to provide you with a very simple dom0less configuration for your platform to enable you to test, or alternatively I could write a patch to add dom0less domU support if you are happy to help reviewing and testing it.
I was thinking about making dom0less support in the different patch-series because there are still questions to be discussed.
Quoted 6 lines
For example, how arm,scmi-smc node will be generated for DomUs and how the case, when scmi configuration is different for DomU1 and DomU2 (as in case of stm32mp1 when smc-id is different) should be handled.
What do you think about continue without dom0less support and discuss dom0less once we done with the main part?
That's OK, especially if you are happy to work on dom0less support later.
Re: [RFC v1 3/5] xen/arm: introduce SCMI-SMC mediator driver
Hi Stefano,
Quoted 472 lines · Stefano Stabellini
Quoted 417 lines · Oleksii Moisieiev
Quoted 338 lines · Stefano Stabellini
Quoted 320 lines · Oleksii Moisieiev
Quoted 290 lines · Stefano Stabellini
Quoted 247 lines · Oleksii Moisieiev
Quoted 246 lines · Stefano Stabellini
Quoted 202 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 184 lines · Stefano Stabellini
Quoted 153 lines · Oleksii Moisieiev
Hi Stefano,
Quoted 129 lines · Stefano Stabellini
Quoted 114 lines · Oleksii Moisieiev
This is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG.
The following features are implemented:
- request SCMI channels from ATF and pass channels to Domains;
- set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI;
- redirect scmi messages from Domains to ATF.Signed-off-by Oleksii Moisieiev <[email protected]>--- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/Makefile | 1 + xen/arch/arm/sci/scmi_smc.c | 795 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 1 + 5 files changed, 809 insertions(+) create mode 100644 xen/arch/arm/sci/Kconfig create mode 100644 xen/arch/arm/sci/scmi_smc.cxen/arch/arm/Kconfig +2
-0@@ -114,6 +114,8 @@ config SCI support. It allows guests to control system resourcess via one of SCI mediators implemented in XEN. +source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework"xen/arch/arm/sci/Kconfig new file +10
-0@@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on SCI + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication.xen/arch/arm/sci/Makefile +1
-0@@ -1 +1,2 @@ obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.oxen/arch/arm/sci/scmi_smc.c new file +49
-0@@ -0,0 +1,795 @@ +/* +* xen/arch/arm/sci/scmi_smc.c +* +* SCMI mediator driver, using SCP as transport. +* +* Oleksii Moisieiev <[email protected]> +* Copyright (C) 2021, EPAM Systems. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <asm/sci/sci.h> +#include <asm/smccc.h> +#include <asm/io.h> +#include <xen/bitops.h> +#include <xen/config.h> +#include <xen/sched.h> +#include <xen/device_tree.h> +#include <xen/iocap.h> +#include <xen/init.h> +#include <xen/err.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/string.h> +#include <xen/time.h> +#include <xen/vmap.h> + +#define SCMI_BASE_PROTOCOL 0x10 +#define SCMI_BASE_PROTOCOL_ATTIBUTES 0x1 +#define SCMI_BASE_SET_DEVICE_PERMISSIONS 0x9 +#define SCMI_BASE_RESET_AGENT_CONFIGURATION 0xB +#define SCMI_BASE_DISCOVER_AGENT 0x7 + +/* SCMI return codes. See section 4.1.4 of SCMI spec (DEN0056C) */ +#define SCMI_SUCCESS 0 +#define SCMI_NOT_SUPPORTED (-1) +#define SCMI_INVALID_PARAMETERS (-2) +#define SCMI_DENIED (-3) +#define SCMI_NOT_FOUND (-4) +#define SCMI_OUT_OF_RANGE (-5)xen/arch/arm/sci/scmi_smc.c line 59
Quoted 10 lines
xen/arch/arm/sci/scmi_smc.c new file +10
-0+#define SCMI_BUSY (-6) +#define SCMI_COMMS_ERROR (-7) +#define SCMI_GENERIC_ERROR (-8) +#define SCMI_HARDWARE_ERROR (-9) +#define SCMI_PROTOCOL_ERROR (-10) + +#define DT_MATCH_SCMI_SMC DT_MATCH_COMPATIBLE("arm,scmi-smc") + +#define SCMI_SMC_ID "arm,smc-id" +#define SCMI_SHARED_MEMORY "linux,scmi_mem"I could find the following SCMI binding in Linux, which describes the arm,scmi-smc compatible and the arm,smc-id property:
Quoted 6 lines
Documentation/devicetree/bindings/firmware/arm,scmi.yamlHowever, linux,scmi_mem is not described. Aren't you supposed to read the "shmem" property instead? And the compatible string used for this seems to be "arm,scmi-shmem".
We use linux,scmi_mem node to reserve memory, needed for all channels:
reserved-memory { /* reserved region for scmi channels*/ scmi_memory: linux,scmi_mem@53FF0000 { no-map; reg = <0x0 0x53FF0000 0x0 0x10000>; }; };arm,scmi-shmem node used in shmem property defines only 1 page needed to the current scmi channel:
Quoted 7 lines
cpu_scp_shm: scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; };For each Domain reg points to unigue page from linux,scmi_mem region, assigned to this agent.
If we were to use "linux,scmi_mem" we would have to introduce it as a compatible string, not as a node name, and it would need to be described in
Documentation/devicetree/bindings/firmware/arm,scmi.yaml.But from your description I don't think it is necessary. We can just use "arm,scmi-shmem" to describe all the required regions:
reserved-memory { scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; }; scp-shmem@0x53FF1000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF1000 0x0 0x1000>; }; scp-shmem@0x53FF2000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF2000 0x0 0x1000>; }; ...Quoted 4 lines
In other words, if all the individual channel pages are described as "arm,scmi-shmem", why do we also need a single larger region as "linux,scmi_mem"?
That was my first implementation. But I've met a problem with
scmi driver in kernel. I don't remember the exact place, but I remember
there were some if, checking if memory weren't reserved.
That's why I ended up splitting nodes reserved memory region and actual
shmem page.
For linux,scmi_mem node I took format from /reserved-memory/linux,lossy_decompress@54000000, which has no compatible string and provides no-map property.
linux,scmi_shmem node is needed to prevent xen from allocating this
space for the domain.Quoted 7 lines
Very interesting question about should I introduce linux,scmi_mem node and
scmi_devidproperty to theDocumentation/devicetree/bindings/firmware/arm,scmi.yaml? Those node and property are needed only for Xen and useless for non-virtualized systems. I can add this node and property description to arm,scmi.yaml, but leave a note that this is Xen specific params. What do you think about it?Reply below
[...]
Quoted 14 lines
Quoted 14 lines
In general we can't use properties that are not part of the device tree
spec, either https://urldefense.com/v3/__https://www.devicetree.org/specifications/__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXCSnJPN$ [devicetree[.]org] orhttps://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings__;!!GF_29dbcQIUBPA!kNodtgmOQBc1iO76_6vTK-O1SoLxee_ChowYQiQYC595rMOsrnmof2zmk7BnhXloYUaj$ [git[.]kernel[.]org]"linux,scmi_mem" is currently absent. Are you aware of any upstreaming activities to get "linux,scmi_mem" upstream under
Documentation/devicetree/bindingsin Linux?If "linux,scmi_mem" is going upstream in Linux, then we could use it. Otherwise, first "linux,scmi_mem" needs to be added somewhere under
Documentation/devicetree/bindings(probablyDocumentation/devicetree/bindings/firmware/arm,scmi.yaml), then we can work on the Xen code that makes use of it.Quoted 5 lines
Quoted 2 lines
Does it make sense?
Yes I agree. I think linux,scmi_mem and
scmi_devidshould be upstreamed.
I will add those properties to arm,scmi.yaml, mark them as related to XEN and send patch.I didn't realize that linux,scmi_mem and
scmi_devidare supposed to be Xen specific. In general, it would be best not to introduce Xen specific properties into generic bindings. It is a problem both from a specification perspective (because it has hard to handle Xen specific cases in fully generic bindings, especially as those bindings are maintained as part of the Linux kernel) and from a user perspective (because now the user has to deal with a Xen-specific dtb, or has to modify the host dtb to add Xen-specific information by hand.)Quoted 8 lines
Quoted 4 lines
Let me start from
scmi_devid. Why wouldscmi_devidbe Xen-specific? It looks like a generic property that should be needed for the Linux SCMI driver too. Why the Linux driver doesn't need it?
scmi_devidused during domain build. It passed as input parameter forSCMI_BASE_SET_DEVICE_PERMISSIONSmessage. On non-virtualized systems - there is no need of this call, because OS
is the only one entity, running on the system.OK. Even if it is only required for virtualized systems, I think that
scmi_devidis important enough that should be part of the upstream binding. I think it is worth starting an email thread on the LKML with Rob Herring and the SCMI maintainers to discuss the addition ofscmi_devidto the binding.Quoted 8 lines
I've chatted with
Volodymyr_Babchukand he gave a great idea to add a list ofdevice_idsto dom.cfg, such as:sci_devs= [ 0, 1, 15, 35 ];Using this approach, we can remove
scmi_devidfrom the device tree and just pass a list ofscmi_devidsto XEN using additional hypercall. We can probably make hypercall taking devid list as input parameter. This will take only 1 hypercall to setup sci permissions.But how would a user know which are the right SCMI IDs to add to the
sci_devslist? Would the user have to go and read the reference manual of the platform to find the SCMI IDs and then writesci_devsby hand? If that is the case, then I think that it would be better to addscmi_devidto device tree.In general, I think this configuration should happen automatically without user intervention. The user should just specify "enable SCMI" and it should work.
Quoted 6 lines
Quoted 5 lines
In regards to linux,scmi_mem, I think it would be best to do without it and fix the Linux SCMI driver if we need to do so. Xen should be able to parse the native "arm,scmi-shmem" nodes and Linux (dom0 or domU) should be able to parse the "arm,scmi-shmem" nodes generated by Xen. Either way, I don't think we should need linux,scmi_mem.
Quoted 5 lines
Quoted 3 lines
This requires further investigation. I will try to make implementation without linux,scmi_mem, using only arm,scmi-shmem nodes and share reuslts with you.
OK, thanks.
Hi Stefano,
As I did some investigation about using reserved-memory area linux,scmi_mem and now I need your advice.
I see 2 possible implementations for now:
1) Add memory-region parameter tocpu_scp_shmnode which points to the reserved memory region.
So device-tree will look like this:reserved-memory { /* reserved region for scmi channels*/ scmi_memory: region@53FF0000{ no-map; reg = <0x0 0x53FF0000 0x0 0x10000>; }; }; cpu_scp_shm: scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; memory-region = <&scmi_memory>; };Quoted 8 lines
So
cpu_scp_shmnode has a reference toscmi_memoryregion. This mean that xen can find reserved memory region without adding additional names to the device-tree bindings.
memory-region parameter as a reference to reserved memory and region creation described in:https://urldefense.com/v3/__https://github.com/torvalds/linux/blob/v5.15/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt__;!!GF_29dbcQIUBPA!k6x19x1gYF1CPlgAZj7std3ifqhq-9DXvuF0nwonNPUwMzZpYHYbrRJziJrgdFIOjyan$ [github[.]com]This approach I've implemented already and it works.
This approach would require a discussion with the upstream device tree maintainers. Likely, we would need to add a note about the usage of the "memory-region" property to arm,scmi.yaml.
Also, I have the feeling that they would ask to add the "memory-region" property directly to the "arm,scmi-smc" node, as an alternative (or in addition) to the existing "shmem" property.
Quoted 7 lines
That said, from my point of view this approach is also a viable option. I don't see any major problems.
The main question (after reading everything else that you wrote below) is whether the "arm,scmi-smc" node in this case could be automatically generated.
arm,scmi-smc node can be generated in both cases. I think I'd leave it as backup in case if the second approach will not work.
Quoted 26 lines
Quoted 17 lines
2) The second approach is the format you suggested:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
reserved-memory { scp-shmem@0x53FF0000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF0000 0x0 0x1000>; }; scp-shmem@0x53FF1000 {Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF1000 0x0 0x1000>; }; scp-shmem@0x53FF2000 { compatible = "arm,scmi-shmem"; reg = <0x0 0x53FF2000 0x0 0x1000>; }; ...Quoted 8 lines
This approach has an advantage that xen
ARM_SCIdriver do not know about how channels are placed in the reserved memory, but introduces some disadvantages:
a) We provide extra 14 (in our case) arm,scmi-shmem nodes which are not used in the device-tree. In current implementation I have separatescmi.dtsifile which introduces scmi support for both XEN-based and non-virtualized systems. Having 14 extra channels in the device-tree may be confusing.Quoted 7 lines
I can see that while it would be ideal for Xen to see all 14+1 channels in device tree (on the host device tree), we wouldn't want to expose all of them to the domains, not even to dom0.
How many channels do we want dom0 to see by the way? For this discussion, I'll just assume for now that dom0 only sees 1 channel like the domUs.
For dom0 we need only one channel.
Quoted 5 lines
Now we have a problem: how do we go about "filtering" the "arm,scmi-shmem" device tree nodes? Which is also what you are asking below in point b).
Xen will not need to filter "arm,scmi-shmem" node. It will just create shmem node in Domain device-tree. I don't see any problem for xen configuration here.
What bothers me here is that I set scmi configuration for platform dts, not for xen or domu dts files.
So for example I have the following structure of the dts files for my platform (r8a77961-salvator-xs):
*r8a77961-scmi.dtsi- this file includes all scmi related nodes and setscmi_devidfor the devices, that should use scmi.
*r8a77961-salvator-xs.dts- dts file which generates dtb for the platform.
It includesr8a77961-scmi.dtsiso I populate scmi to platform dtb, which is used for system with no hypervisor.
*r8a77961-salvator-xs-xen.dts- dts file for xen which includesr8a77961-salvator-xs.dtsand inherits scmi configuration from it.
*r8a77961-salvator-xs-domu.dts- dts file for DomU which includesr8a77961-salvator-xs.dtsand inherits scmi configuration from it.In this case r8a77961-salvator-xs.dtb r8a77961-salvator-xs-xen.dtb r8a77961-salvator-xs-domu.dtb files will inherit 14+1 channel.
I can give you a link to Merge request with this changes if you need it.
For xen and domu dtb it is not a problem because all "arm,scmi-shmem" nodes will be omitted and new will be generated for the domains.
Quoted 8 lines
What bothers me is that r8a77961-salvator-xs.dtb will have 14 unused channels.
Just got an idea while writing this: I can create only one "arm,scmi-shmem" node in
r8a77961-scmi.dtsiand add 14 more nodes, needed for xen explicitly inr8a77961-salvator-xs-xen.dts.Then we will have valid configurations for all cases. This can be a solution. What do you think?
It is good that you brought this up because it helps me explain what I mean. And of course it is up to you where you place the nodes in the various dts files at your disposal. Either way it would work but I think they should belong to
r8a77961-salvator-xs.dts.Generally the platform vendor (e.g. Xilinx) provides a device tree description of the platform to use including all the available resources and firmware interfaces. In your case it would be
r8a77961-scmi.dtsi+r8a77961-salvator-xs.dts. This is what I call the "host device tree" below. Users should be able to boot a fully functional system using the host device tree pretty much "as is" to run Xen, Linux or any other software.Certainly the SCMI device tree description should be part of the host device tree, so in your case it would be
r8a77961-salvator-xs.dts. And the description should include all 14+1 channels because this is the generic platform description -- we cannot know for sure how the users are going to use the system.This is why
r8a77961-salvator-xs-xen.dtsshould be as small as possible or ideally inexistent. There shouldn't be a need for a special device tree modification to allow Xen to run. In reality, even at Xilinx we have something liker8a77961-salvator-xs-xen.dts, although it is really small.But I see that
r8a77961-salvator-xs-xen.dtscould be viewed as the device tree additions to run hypervisors and from that point of view it is more acceptable to place the 14 channels there.The biggest problem is
r8a77961-salvator-xs-domu.dts: who is going to write it? And how? It wouldn't be provided by the platform vendor, so it is the user the one that has to find a way to write it.I know the user already has to write a partial DTB for device assignment, but any time the process is more complex than "copy the host device tree node for device XXX to the partial DTB" it is a problem. Errors are made and the system doesn't work.
I think we don't want to make it even more difficult by having to manually produce the SCMI domU description too. The SCMI description for domU could be automatically generated by Xen, or libxl/xl. If that's an issue, then the SCMI description could be automatically generated by an external tool but I think it would make things more complex and harder to maintain.
Quoted 8 lines
In short my point of view is:
-r8a77961-scmi.dtsi+r8a77961-salvator-xs.dtsshould be as generic as possible so the SCMI nodes should have 14+1 channels
- but putting the 14 channels inr8a77961-salvator-xs-xen.dtsis still OKish
- it is important thatr8a77961-salvator-xs-domu.dtsis automatically generated by Xen or libxl or another software tool
Thank you for the detailed response. I'll put all 14+1 channels to r8a77961-salvator-xs.dts then.
I've described my thoughts about generation of the arm,scmi-smc node below.
Quoted 223 lines
Quoted 173 lines
Quoted 5 lines
Quoted 2 lines
b) In case if we have all 15 channels, described in partial device-tree,
I think you meant "described in the host device tree", right?
Yeah that's what I've meant.
Quoted 26 lines
Quoted 3 lines
we should not copy any node to the domain device-tree. I think it will be better to generate arm,scmi-shmem node in the Domain device-tree.
Yes, I think it makes sense for Xen to generate the "arm,scmi-shmem" device tree description for the DomU/Dom0 based on the channels allocated to the domain.
Quoted 10 lines
The problem is that arm,scmi-smc node, which is using arm,scmi-shmem node can't be generated. I prefer it to be copied from the partial device-tree because it includes some platform specific configuration, such as func-id and list of the protocols (for example different platforms may require different list of the protocols). So in this case we will have 1 node copied and 1 node generated.
I think even for dom0less we should use arm,scmi-smc node from the device-tree because protocol configuration and funcid is related to the platform.
I am not sure I understood what you wrote. You are saying that the "arm,scmi-smc" node includes some platform specific configurations so it cannot be automatically generated by Xen (or by the tools) and instead it needs to be manually provided as part of the partial dtb for the domU. Is that correct?
Quoted 8 lines
If so, I would like to understand the reasons behind it. Manual device tree editing is problematic.
I looked for "func-id" in
Documentation/devicetree/bindings/firmware/arm,scmi.yamlbut couldn't find any results. Do you have an example of the platform specific configuration or protocol configuration that would make it difficult to automatically generate the "arm,scmi-smc" node for the domains?Sorry, I used wrong term (used term from the specification), arm,smc-id of cause.
Quoted 5 lines
Also, is this a problem just for approach #2 or also for approach #1? If it is a problem only for approach #2, then let's just go with approach #1.
We can't copy "arm,scmi-smc" in both approaches. The difference is that in the first approach we can copy both "arm,scmi-smc" and "arm,scmi-shmem" nodes while in the second approach we should copy "arm,scmi-smc", but we have to generate "arm,scmi-shmem" node.
arm,scmi-smc node can't be generated because it includes properties and configurations that depends from platform and should be get from the device tree.
Here is "arm,scmi-smc" node expample:firmware { scmi { compatible = "arm,scmi-smc" arm,smc-id = <0x82000002>; shmem = <&cpu_scp_shm>; #address-cells = <1>; #size-cells = <0>; scmi_power: protocol@11 { reg = <0x11>; #power-domain-cells = <1>; }; scmi_clock: protocol@14 { ... }; scmi_reset: protocol@16 { ... }; ... }; };It has 3 configurable options:
* arm,smc-id parameter, settingfunc_idfor scmi protocol. This id can be
different for different platforms.
For example stm32mp1 architecture use different scm-id for different agents:https://urldefense.com/v3/__https://github.com/ARM-software/arm-trusted-firmware/blob/0586c41b3f2d52aae847b7212e7b0c7e19197ea2/plat/st/stm32mp1/include/stm32mp1_smc.h*L39__;Iw!!GF_29dbcQIUBPA!mTRUjtSg19iVaYo3Cgjop5ckPWqKsHVo1EZCEA1zCbod9KpNSXX291A8vAuNdTCr46MA$ [github[.]com]* shmem which includes phandle to arm,scmi-shmem node. But this is not
a problem and can be updated.* list of the protocol subnodes. This is also configurable parameter,
not regs or names, but the number of the protocols. For example onle platform can use power-domains/clock/resets via scmi, when another will require volage-control and sensor-management to be added.Xen should know this parameters to be able to generate "arm,scmi-smc" node.
Also we're currently discussing new scmi protocol with ARM: Pinctrl over SCMI.
It should allow domains to access pinctrl subsystem, placed in Firmware through SCMI protocol.
scmi_pinctrlnode will look like this:firmware { scmi { ... scmi_pinctrl: protocol@18 { reg = <0x18>; #pinctrl-cells = <0>; i2c2_pins: i2c2 { groups = <74>; /* i2c2_a */ function = <15>; /* i2c2 */ }; irq0_pins: irq0 { groups = <81>; /* intc_ex_irq0 */ function = <19>; /* intc_ex */ }; avb_pins: avb { mux { /* avb_link, avb_mdio, avb_mii */ groups = <17>, <21>, <22>; function = <1>; /* avb */ }; pins_mdio { groups = <21>; /* avb_mdio */ drive-strength = <24>; }; pins_mii_tx { /* PIN_AVB_TX_CTL, PIN_AVB_TXC, PIN_AVB_TD0, PIN_AVB_TD1, PIN_AVB_TD2, PIN_AVB_TD3 */ pins = <242>, <240>, <236>, <237>, <238>, <239>; drive-strength = <12>; }; }; ... }; }; };So "arm,scmi-smc" node will have even more platform specific settings.
Quoted 7 lines
Quoted 6 lines
I prefer the second approach and will try to make it if it's OK to copy arm,scmi-smc node from partial Device-tree and generate arm,scmi-shmem node.
What do you think about that?
Quoted 8 lines
From a device tree specification perspective, I think both approaches are OK (with a minor comment on the first approach as I wrote above.)
But from a Xen perspective I think it is important that we don't require the user to manually provide the SCMI configuration in the partial DTB. It would be better if we could generate it automatically from Xen or the tools (or even an independent script). Or copy the "arm,scmi-smc" node from the host device tree to the domU device tree without modifications.
I think copy "arm,scmi-smc" node is the only option we have. I'm not sure what do you mean under "host device tree" if you mean Xen device-tree - then I think it will not cover the case with stm32mp1 I've mentioned above. I think it will be better to copy "arm,scmi-smc" node from Domu partial Device-tree to Domu device-tree.
So AGENT0 smc-id will be set in xen device-tree and copied to dom0 and AGENT1 scm-is set in domu device-tree and copied to dom-u.Quoted 1 line
Do you agree with my points?
I think we are saying similar things, but we are getting mixed up with the terminology. Let's start from the basics :-)
# Host device tree
The device tree given to Xen at boot time. This is the device tree that Xen parses to discover what's available on the platform. In your case, it seems to includer8a77961-salvator-xs-xen.dts.# Partial DTB
(Ignoring Dom0less) this is the small DTB that gets passed to xl with the "device_tree" option in the xl config file. It is copied verbatim to the domU device tree by xl/libxl.# Copy the "arm,scmi-smc" node from host device tree
This means that the domU "arm,scmi-smc" node is an exact copy of the host device tree SCMI node. I don't think this is actually possible in most cases because the domU description is typically a bit different from the host description. For instance, the host description could include 14+1 channels while the domU description should only include 1 channel.# Copy the "arm,scmi-smc" node from the partial DTB
This implies that somebody or something create an "arm,scmi-smc" node for the domU and placed it into the partial DTB. Then, Xen and/or xl/libxl will copy the node from the partial DTB to the DomU device tree. The main question in this case is: who is going to write the partial DTB? We dont want the user (i.e. a person) to have to manually write the SCMI description for the domU. It should be an automated tools that does it. At that point, it is easier if it is Xen or xl/libxl. Alternativaly, we could think of an external tool but I think it would make things more difficult to maintain.# Generate the "arm,scmi-smc" node for domUs
When I write "generate the arm,scmi-smc node", I mean that Xen and libxl/xl will generate the "arm,scmi-smc" node for the domU. Thus, the node will not be copied from the partial DTB or from the device tree, instead, it should be created directly by Xen and/or libxl/xl.However, the domU "arm,scmi-smc" node could still be derived from the host device tree "arm,scmi-smc" node. In other words, Xen or xl/libxl would look at the host device tree "arm,scmi-smc" node, copy it to the domU device tree while making as many changes as necessary.
The DomU "arm,scmi-smc" node doesn't have to be entirely fake and static. It could be dynamically created to match the host device tree description. I think this is the best option.
Quoted 6 lines
# Conclusion
I am suggesting that Xen and/or libxl automatically produce the "arm,scmi-smc" node for domUs based on the host device tree description and based on the channel mapped to the domU. This way, the user (a person) doesn't have to go and manually edit the domU partial DTB.
That sounds reasonable. The problem is that arm,scmi-smc node can be copmlicated and include a lot of configuration. Also for different mediators this node can be different.
As I inderstand, there is no mechanism for xl to access host device-tree right now. Correct me if I'm wrong.
I see the following way we can generate arm,scmi-smc node for DomU:
We say that if scmi-smc mediator is enabled - then Dom0 is configured to use SCMI. This means that Dom0 device-tree will have arm,scmi-smc node and it can be reached from the userspace.
In this case xl can use infromation from /proc/device-tree/firmware/scmi to generate arm,scmi-smc node for DomU. But in this case xl should know the exact path of scmi node.
Or we can generate some special node, called "shared" in Dom0 device-tree which will include copy of the arm,scmi-smc node, which can be used for domains. In this case xl can scan /proc/device-tree/shared node and find arm,scmi-smc copatible node and use it to generate arm,scmi-smc node for DomU.
Also this can be used for another features in future.
What do you think about this?
Quoted 31 lines
Quoted 7 lines
Quoted 4 lines
So if using approach #1 allows us to automatically generate the "arm,scmi-smc" node for the guest, then I think it's best for sure.
Summarizing all written above I would focus on the second approach and put aside the first approach implementation. If you don't mind.
Sure, that's fine by me
Quoted 20 lines
Quoted 5 lines
Quoted 4 lines
Also I wanted to mention that I'm not planning to make
ARM_SCIsupport for dom0less in terms of this patch series bacause I can't test dom0less configuration for now. So let me know if some of my functionality breaks dom0less.Quoted 7 lines
That's fine. I don't mean to scope-creep your patch series, which is extremely valuable as is.
That said, I would be happy to provide you with a very simple dom0less configuration for your platform to enable you to test, or alternatively I could write a patch to add dom0less domU support if you are happy to help reviewing and testing it.
I was thinking about making dom0less support in the different patch-series because there are still questions to be discussed.
For example, how arm,scmi-smc node will be generated for DomUs and how the case, when scmi configuration is different for DomU1 and DomU2 (as in case of stm32mp1 when smc-id is different) should be handled.
Quoted 5 lines
Quoted 2 lines
What do you think about continue without dom0less support and discuss dom0less once we done with the main part?
That's OK, especially if you are happy to work on dom0less support later.
Sure I will be happy to work on dom0less support later.