platform: generic: Add system suspend test
authorAndrew Jones <ajones@ventanamicro.com>
Mon, 27 Feb 2023 10:31:06 +0000 (11:31 +0100)
committerAnup Patel <anup@brainfault.org>
Mon, 27 Feb 2023 14:20:51 +0000 (19:50 +0530)
When the system-suspend-test property is present in the domain config
node as shown below, implement system suspend with a simple 5 second
delay followed by a WFI. This allows testing system suspend when the
low-level firmware doesn't support it.

  / {
    chosen {
      opensbi-domains {
          compatible = "opensbi,domain,config";
          system-suspend-test;
      };

Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
docs/domain_support.md
include/sbi/sbi_system.h
lib/sbi/sbi_system.c
platform/generic/platform.c

index 65b614271661babb089bbd7147799be85a9f18e4..b285d65aec02598f86fd79b15ca4b5483e83820d 100644 (file)
@@ -126,6 +126,9 @@ The DT properties of a domain configuration DT node are as follows:
 * **compatible** (Mandatory) - The compatible string of the domain
   configuration. This DT property should have value *"opensbi,domain,config"*
 
+* **system-suspend-test** (Optional) - When present, enable a system
+  suspend test implementation which simply waits five seconds and issues a WFI.
+
 ### Domain Memory Region Node
 
 The domain memory region DT node describes details of a memory region and
@@ -234,6 +237,7 @@ be done:
     chosen {
         opensbi-domains {
             compatible = "opensbi,domain,config";
+            system-suspend-test;
 
             tmem: tmem {
                 compatible = "opensbi,domain,memregion";
index 11d3d6fd9a68ba06f7061de06eaa8343fc51e85d..33ff7f1a44a67c1d29347d7952eb6edf66ee7043 100644 (file)
@@ -66,6 +66,7 @@ struct sbi_system_suspend_device {
 
 const struct sbi_system_suspend_device *sbi_system_suspend_get_device(void);
 void sbi_system_suspend_set_device(struct sbi_system_suspend_device *dev);
+void sbi_system_suspend_test_enable(void);
 bool sbi_system_suspend_supported(u32 sleep_type);
 int sbi_system_suspend(u32 sleep_type, ulong resume_addr, ulong opaque);
 
index 7fa5ea82b7a6c14b3c7f12b39813d317cfc25f67..6933915a12ed7db836393d7ad54590beb73ddddf 100644 (file)
@@ -17,6 +17,7 @@
 #include <sbi/sbi_system.h>
 #include <sbi/sbi_ipi.h>
 #include <sbi/sbi_init.h>
+#include <sbi/sbi_timer.h>
 
 static SBI_LIST_HEAD(reset_devices_list);
 
@@ -108,6 +109,36 @@ void sbi_system_suspend_set_device(struct sbi_system_suspend_device *dev)
        suspend_dev = dev;
 }
 
+static int sbi_system_suspend_test_check(u32 sleep_type)
+{
+       return sleep_type == SBI_SUSP_SLEEP_TYPE_SUSPEND;
+}
+
+static int sbi_system_suspend_test_suspend(u32 sleep_type,
+                                          unsigned long mmode_resume_addr)
+{
+       if (sleep_type != SBI_SUSP_SLEEP_TYPE_SUSPEND)
+               return SBI_EINVAL;
+
+       sbi_timer_mdelay(5000);
+
+       /* Wait for interrupt */
+       wfi();
+
+       return SBI_OK;
+}
+
+static struct sbi_system_suspend_device sbi_system_suspend_test = {
+       .name = "system-suspend-test",
+       .system_suspend_check = sbi_system_suspend_test_check,
+       .system_suspend = sbi_system_suspend_test_suspend,
+};
+
+void sbi_system_suspend_test_enable(void)
+{
+       sbi_system_suspend_set_device(&sbi_system_suspend_test);
+}
+
 bool sbi_system_suspend_supported(u32 sleep_type)
 {
        return suspend_dev && suspend_dev->system_suspend_check &&
index 0b90fd7c1446edebab0717c36fbb09b7b77d85a0..eeefef4c953336f9d29ea43caa33b69bc3001ced 100644 (file)
@@ -13,6 +13,7 @@
 #include <sbi/sbi_hartmask.h>
 #include <sbi/sbi_platform.h>
 #include <sbi/sbi_string.h>
+#include <sbi/sbi_system.h>
 #include <sbi_utils/fdt/fdt_domain.h>
 #include <sbi_utils/fdt/fdt_fixup.h>
 #include <sbi_utils/fdt/fdt_helper.h>
@@ -219,7 +220,24 @@ static int generic_extensions_init(struct sbi_hart_features *hfeatures)
 
 static int generic_domains_init(void)
 {
-       return fdt_domains_populate(fdt_get_address());
+       void *fdt = fdt_get_address();
+       int offset, ret;
+
+       ret = fdt_domains_populate(fdt);
+       if (ret < 0)
+               return ret;
+
+       offset = fdt_path_offset(fdt, "/chosen");
+
+       if (offset >= 0) {
+               offset = fdt_node_offset_by_compatible(fdt, offset,
+                                                      "opensbi,domain,config");
+               if (offset >= 0 &&
+                   fdt_get_property(fdt, offset, "system-suspend-test", NULL))
+                       sbi_system_suspend_test_enable();
+       }
+
+       return 0;
 }
 
 static u64 generic_tlbr_flush_limit(void)