lib: sbi: Add system_suspend_allowed domain property
authorAndrew Jones <ajones@ventanamicro.com>
Mon, 27 Feb 2023 10:31:03 +0000 (11:31 +0100)
committerAnup Patel <anup@brainfault.org>
Mon, 27 Feb 2023 14:15:28 +0000 (19:45 +0530)
Only privileged domains should be allowed to suspend the entire
system. Give the root domain this property by default and allow
other domains to be given the property by specifying it in the
DT.

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

index 2a9ca3d70ea9481c855c21abcec4c1c0da123a2a..039f262bfec2e997094502c9d0da29656aa531a2 100644 (file)
@@ -52,6 +52,7 @@ has following details:
 * **next_mode** - Privilege mode of the next booting stage for this
   domain. This can be either S-mode or U-mode.
 * **system_reset_allowed** - Is domain allowed to reset the system?
+* **system_suspend_allowed** - Is domain allowed to suspend the system?
 
 The memory regions represented by **regions** in **struct sbi_domain** have
 following additional constraints to align with RISC-V PMP requirements:
@@ -91,6 +92,7 @@ following manner:
 * **next_mode** - Next booting stage mode in coldboot HART scratch space
   is the next mode for the ROOT domain
 * **system_reset_allowed** - The ROOT domain is allowed to reset the system
+* **system_suspend_allowed** - The ROOT domain is allowed to suspend the system
 
 Domain Effects
 --------------
@@ -195,6 +197,8 @@ The DT properties of a domain instance DT node are as follows:
   stage mode of coldboot HART** is used as default value.
 * **system-reset-allowed** (Optional) - A boolean flag representing
   whether the domain instance is allowed to do system reset.
+* **system-suspend-allowed** (Optional) - A boolean flag representing
+  whether the domain instance is allowed to do system suspend.
 
 ### Assigning HART To Domain Instance
 
@@ -260,6 +264,7 @@ be done:
                 next-addr = <0x0 0x80100000>;
                 next-mode = <0x0>;
                 system-reset-allowed;
+                system-suspend-allowed;
             };
 
             udomain: untrusted-domain {
index ab1a944b474b14d2377441934078a392281bbc2e..eaca7f093271fceefd66744994c9831f02e369c8 100644 (file)
@@ -120,6 +120,8 @@ struct sbi_domain {
        unsigned long next_mode;
        /** Is domain allowed to reset the system */
        bool system_reset_allowed;
+       /** Is domain allowed to suspend the system */
+       bool system_suspend_allowed;
 };
 
 /** The root domain instance */
index d2f58a28cbdfe2b32cfa1ae5490e689058e428db..4d7b80a3ddd42b6293b7a5ec2cfef497680ebb8b 100644 (file)
@@ -38,6 +38,7 @@ struct sbi_domain root = {
        .possible_harts = &root_hmask,
        .regions = root_memregs,
        .system_reset_allowed = true,
+       .system_suspend_allowed = true,
 };
 
 bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartid)
@@ -467,6 +468,9 @@ void sbi_domain_dump(const struct sbi_domain *dom, const char *suffix)
 
        sbi_printf("Domain%d SysReset    %s: %s\n",
                   dom->index, suffix, (dom->system_reset_allowed) ? "yes" : "no");
+
+       sbi_printf("Domain%d SysSuspend  %s: %s\n",
+                  dom->index, suffix, (dom->system_suspend_allowed) ? "yes" : "no");
 }
 
 void sbi_domain_dump_all(const char *suffix)
index bc30010a8888c6883dfef43d4187eb12bc4b59a7..adcb94b64137d577adc2f9b0f7582b5cad8465bd 100644 (file)
@@ -417,6 +417,13 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque)
        else
                dom->system_reset_allowed = false;
 
+       /* Read "system-suspend-allowed" DT property */
+       if (fdt_get_property(fdt, domain_offset,
+                            "system-suspend-allowed", NULL))
+               dom->system_suspend_allowed = true;
+       else
+               dom->system_suspend_allowed = false;
+
        /* Find /cpus DT node */
        cpus_offset = fdt_path_offset(fdt, "/cpus");
        if (cpus_offset < 0)