Re: [RFC PATCH v4 2/8] xen/arm: scmi-smc: update to be used under sci subsystem

2025-05-19 Thread Stefano Stabellini
On Mon, 19 May 2025, Oleksii Moisieiev wrote:
> From: Grygorii Strashko 
> 
> The introduced SCI (System Control Interface) subsystem provides unified
> interface to integrate in Xen SCI drivers which adds support for ARM
> firmware (EL3, SCP) based software interfaces (like SCMI) that are used in
> system management. The SCI subsystem allows to add drivers for different FW
> interfaces or have different drivers for the same FW interface (for example,
> SCMI with different transports).
> 
> This patch updates SCMI over SMC calls handling layer, introduced by
> commit 3e322bef8bc0 ("xen/arm: firmware: Add SCMI over SMC calls handling
> layer"), to be SCI driver:
> - convert to DT device;
> - convert to SCI Xen interface.
> 
> There are no functional changes in general, the driver is just adopted
> to the SCI interface.
> 
> Signed-off-by: Grygorii Strashko 
> Signed-off-by: Oleksii Moisieiev 

Reviewed-by: Stefano Stabellini 


> ---
> 
> 
> 
>  xen/arch/arm/firmware/Kconfig| 13 ++-
>  xen/arch/arm/firmware/scmi-smc.c | 93 +++-
>  xen/arch/arm/include/asm/firmware/scmi-smc.h | 41 -
>  xen/arch/arm/vsmc.c  |  5 +-
>  xen/include/public/arch-arm.h|  1 +
>  5 files changed, 64 insertions(+), 89 deletions(-)
>  delete mode 100644 xen/arch/arm/include/asm/firmware/scmi-smc.h
> 
> diff --git a/xen/arch/arm/firmware/Kconfig b/xen/arch/arm/firmware/Kconfig
> index fc7918c7fc..bbf88fbb9a 100644
> --- a/xen/arch/arm/firmware/Kconfig
> +++ b/xen/arch/arm/firmware/Kconfig
> @@ -8,9 +8,18 @@ config ARM_SCI
>  
>  menu "Firmware Drivers"
>  
> +choice
> + prompt "ARM SCI driver type"
> + default SCMI_SMC
> + help
> + Choose which ARM SCI driver to enable.
> +
> +config ARM_SCI_NONE
> + bool "none"
> +
>  config SCMI_SMC
>   bool "Forward SCMI over SMC calls from hwdom to EL3 firmware"
> - default y
> + select ARM_SCI
>   help
> This option enables basic awareness for SCMI calls using SMC as
> doorbell mechanism and Shared Memory for transport ("arm,scmi-smc"
> @@ -18,4 +27,6 @@ config SCMI_SMC
> firmware node is used to trap and forward corresponding SCMI SMCs
> to firmware running at EL3, for calls coming from the hardware domain.
>  
> +endchoice
> +
>  endmenu
> diff --git a/xen/arch/arm/firmware/scmi-smc.c 
> b/xen/arch/arm/firmware/scmi-smc.c
> index 33473c04b1..13d1137592 100644
> --- a/xen/arch/arm/firmware/scmi-smc.c
> +++ b/xen/arch/arm/firmware/scmi-smc.c
> @@ -9,6 +9,7 @@
>   * Copyright 2024 NXP
>   */
>  
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -16,12 +17,11 @@
>  #include 
>  #include 
>  
> +#include 
>  #include 
> -#include 
>  
>  #define SCMI_SMC_ID_PROP   "arm,smc-id"
>  
> -static bool __ro_after_init scmi_enabled;
>  static uint32_t __ro_after_init scmi_smc_id;
>  
>  /*
> @@ -41,14 +41,11 @@ static bool scmi_is_valid_smc_id(uint32_t fid)
>   *
>   * Returns true if SMC was handled (regardless of response), false otherwise.
>   */
> -bool scmi_handle_smc(struct cpu_user_regs *regs)
> +static bool scmi_handle_smc(struct cpu_user_regs *regs)
>  {
>  uint32_t fid = (uint32_t)get_user_reg(regs, 0);
>  struct arm_smccc_res res;
>  
> -if ( !scmi_enabled )
> -return false;
> -
>  if ( !scmi_is_valid_smc_id(fid) )
>  return false;
>  
> @@ -78,49 +75,45 @@ bool scmi_handle_smc(struct cpu_user_regs *regs)
>  return true;
>  }
>  
> -static int __init scmi_check_smccc_ver(void)
> +static int scmi_smc_domain_init(struct domain *d,
> +struct xen_domctl_createdomain *config)
>  {
> -if ( smccc_ver < ARM_SMCCC_VERSION_1_1 )
> -{
> -printk(XENLOG_WARNING
> -   "SCMI: No SMCCC 1.1 support, SCMI calls forwarding 
> disabled\n");
> -return -ENOSYS;
> -}
> +if ( !is_hardware_domain(d) )
> +return 0;
>  
> +d->arch.sci_enabled = true;
> +printk(XENLOG_DEBUG "SCMI: %pd init\n", d);
>  return 0;
>  }
>  
> -static int __init scmi_dt_init_smccc(void)
> +static void scmi_smc_domain_destroy(struct domain *d)
>  {
> -static const struct dt_device_match scmi_ids[] __initconst =
> -{
> -/* We only support "arm,scmi-smc" binding for now */
> -DT_MATCH_COMPATIBLE("arm,scmi-smc"),
> -{ /* sentinel */ },
> -};
> -const struct dt_device_node *scmi_node;
> -int ret;
> +if ( !is_hardware_domain(d) )
> +return;
>  
> -/* If no SCMI firmware node found, fail silently as it's not mandatory */
> -scmi_node = dt_find_matching_node(NULL, scmi_ids);
> -if ( !scmi_node )
> -return -EOPNOTSUPP;
> +printk(XENLOG_DEBUG "SCMI: %pd destroy\n", d);
> +}
>  
> -ret = dt_property_read_u32(scmi_node, SCMI_SMC_ID_PROP, &scmi_smc_id);
> -if ( !ret )
> +static int __init scmi_check_smccc_ver(void)
> +{
> +if ( smccc_ver < ARM_SMCCC_VERSION_1_1 )
>  {
> - 

[RFC PATCH v4 2/8] xen/arm: scmi-smc: update to be used under sci subsystem

2025-05-19 Thread Oleksii Moisieiev
From: Grygorii Strashko 

The introduced SCI (System Control Interface) subsystem provides unified
interface to integrate in Xen SCI drivers which adds support for ARM
firmware (EL3, SCP) based software interfaces (like SCMI) that are used in
system management. The SCI subsystem allows to add drivers for different FW
interfaces or have different drivers for the same FW interface (for example,
SCMI with different transports).

This patch updates SCMI over SMC calls handling layer, introduced by
commit 3e322bef8bc0 ("xen/arm: firmware: Add SCMI over SMC calls handling
layer"), to be SCI driver:
- convert to DT device;
- convert to SCI Xen interface.

There are no functional changes in general, the driver is just adopted
to the SCI interface.

Signed-off-by: Grygorii Strashko 
Signed-off-by: Oleksii Moisieiev 
---



 xen/arch/arm/firmware/Kconfig| 13 ++-
 xen/arch/arm/firmware/scmi-smc.c | 93 +++-
 xen/arch/arm/include/asm/firmware/scmi-smc.h | 41 -
 xen/arch/arm/vsmc.c  |  5 +-
 xen/include/public/arch-arm.h|  1 +
 5 files changed, 64 insertions(+), 89 deletions(-)
 delete mode 100644 xen/arch/arm/include/asm/firmware/scmi-smc.h

diff --git a/xen/arch/arm/firmware/Kconfig b/xen/arch/arm/firmware/Kconfig
index fc7918c7fc..bbf88fbb9a 100644
--- a/xen/arch/arm/firmware/Kconfig
+++ b/xen/arch/arm/firmware/Kconfig
@@ -8,9 +8,18 @@ config ARM_SCI
 
 menu "Firmware Drivers"
 
+choice
+   prompt "ARM SCI driver type"
+   default SCMI_SMC
+   help
+   Choose which ARM SCI driver to enable.
+
+config ARM_SCI_NONE
+   bool "none"
+
 config SCMI_SMC
bool "Forward SCMI over SMC calls from hwdom to EL3 firmware"
-   default y
+   select ARM_SCI
help
  This option enables basic awareness for SCMI calls using SMC as
  doorbell mechanism and Shared Memory for transport ("arm,scmi-smc"
@@ -18,4 +27,6 @@ config SCMI_SMC
  firmware node is used to trap and forward corresponding SCMI SMCs
  to firmware running at EL3, for calls coming from the hardware domain.
 
+endchoice
+
 endmenu
diff --git a/xen/arch/arm/firmware/scmi-smc.c b/xen/arch/arm/firmware/scmi-smc.c
index 33473c04b1..13d1137592 100644
--- a/xen/arch/arm/firmware/scmi-smc.c
+++ b/xen/arch/arm/firmware/scmi-smc.c
@@ -9,6 +9,7 @@
  * Copyright 2024 NXP
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -16,12 +17,11 @@
 #include 
 #include 
 
+#include 
 #include 
-#include 
 
 #define SCMI_SMC_ID_PROP   "arm,smc-id"
 
-static bool __ro_after_init scmi_enabled;
 static uint32_t __ro_after_init scmi_smc_id;
 
 /*
@@ -41,14 +41,11 @@ static bool scmi_is_valid_smc_id(uint32_t fid)
  *
  * Returns true if SMC was handled (regardless of response), false otherwise.
  */
-bool scmi_handle_smc(struct cpu_user_regs *regs)
+static bool scmi_handle_smc(struct cpu_user_regs *regs)
 {
 uint32_t fid = (uint32_t)get_user_reg(regs, 0);
 struct arm_smccc_res res;
 
-if ( !scmi_enabled )
-return false;
-
 if ( !scmi_is_valid_smc_id(fid) )
 return false;
 
@@ -78,49 +75,45 @@ bool scmi_handle_smc(struct cpu_user_regs *regs)
 return true;
 }
 
-static int __init scmi_check_smccc_ver(void)
+static int scmi_smc_domain_init(struct domain *d,
+struct xen_domctl_createdomain *config)
 {
-if ( smccc_ver < ARM_SMCCC_VERSION_1_1 )
-{
-printk(XENLOG_WARNING
-   "SCMI: No SMCCC 1.1 support, SCMI calls forwarding disabled\n");
-return -ENOSYS;
-}
+if ( !is_hardware_domain(d) )
+return 0;
 
+d->arch.sci_enabled = true;
+printk(XENLOG_DEBUG "SCMI: %pd init\n", d);
 return 0;
 }
 
-static int __init scmi_dt_init_smccc(void)
+static void scmi_smc_domain_destroy(struct domain *d)
 {
-static const struct dt_device_match scmi_ids[] __initconst =
-{
-/* We only support "arm,scmi-smc" binding for now */
-DT_MATCH_COMPATIBLE("arm,scmi-smc"),
-{ /* sentinel */ },
-};
-const struct dt_device_node *scmi_node;
-int ret;
+if ( !is_hardware_domain(d) )
+return;
 
-/* If no SCMI firmware node found, fail silently as it's not mandatory */
-scmi_node = dt_find_matching_node(NULL, scmi_ids);
-if ( !scmi_node )
-return -EOPNOTSUPP;
+printk(XENLOG_DEBUG "SCMI: %pd destroy\n", d);
+}
 
-ret = dt_property_read_u32(scmi_node, SCMI_SMC_ID_PROP, &scmi_smc_id);
-if ( !ret )
+static int __init scmi_check_smccc_ver(void)
+{
+if ( smccc_ver < ARM_SMCCC_VERSION_1_1 )
 {
-printk(XENLOG_ERR "SCMI: No valid \"%s\" property in \"%s\" DT node\n",
-   SCMI_SMC_ID_PROP, scmi_node->full_name);
-return -ENOENT;
+printk(XENLOG_WARNING
+   "SCMI: No SMCCC 1.1 support, SCMI calls forwarding disabled\n");
+return -ENOSYS;
 }
 
-scmi_enabled = true;
-
 return 0;
 }
 
+static const str