summaryrefslogtreecommitdiff
path: root/include/sbi_utils
diff options
context:
space:
mode:
authorAnup Patel <anup.patel@wdc.com>2020-11-18 14:10:21 +0300
committerAnup Patel <anup@brainfault.org>2020-12-04 18:40:44 +0300
commitba741ea0ad01314be916f9095384c31c6ccfa363 (patch)
tree2cd0318b82c3bddd8ee84157b32a6f10cb70f254 /include/sbi_utils
parentc0d2baa8c0be532ff0ce77946cc44cdf4de92669 (diff)
downloadopensbi-ba741ea0ad01314be916f9095384c31c6ccfa363.tar.xz
lib: utils: Add helper routines to populate domains from FDT
We add various helper routines to populate domains, iterate domains, iterate domain memregions, and parse HART to domain assignment from the FDT. These helper routines can be used by platform support code and FDT fixup code. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
Diffstat (limited to 'include/sbi_utils')
-rw-r--r--include/sbi_utils/fdt/fdt_domain.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/include/sbi_utils/fdt/fdt_domain.h b/include/sbi_utils/fdt/fdt_domain.h
new file mode 100644
index 0000000..3c02d56
--- /dev/null
+++ b/include/sbi_utils/fdt/fdt_domain.h
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * fdt_domain.c - Flat Device Tree Domain helper routines
+ *
+ * Copyright (c) 2020 Western Digital Corporation or its affiliates.
+ *
+ * Authors:
+ * Anup Patel <anup.patel@wdc.com>
+ */
+
+#ifndef __FDT_DOMAIN_H__
+#define __FDT_DOMAIN_H__
+
+#include <sbi/sbi_types.h>
+
+struct sbi_domain;
+
+/**
+ * Iterate over each domains in device tree
+ *
+ * @param fdt device tree blob
+ * @param opaque private pointer for each iteration
+ * @param fn callback function for each iteration
+ */
+void fdt_iterate_each_domain(void *fdt, void *opaque,
+ void (*fn)(void *fdt, int domain_offset,
+ void *opaque));
+
+/**
+ * Iterate over each memregion of a domain in device tree
+ *
+ * @param fdt device tree blob
+ * @param domain_offset domain DT node offset
+ * @param opaque private pointer for each iteration
+ * @param fn callback function for each iteration
+ */
+void fdt_iterate_each_memregion(void *fdt, int domain_offset, void *opaque,
+ void (*fn)(void *fdt, int domain_offset,
+ int region_offset, u32 region_access,
+ void *opaque));
+
+/**
+ * Fix up the domain configuration in the device tree
+ *
+ * This routine:
+ * 1. Disables MMIO devices not accessible to the coldboot HART domain
+ * 2. Removes "opensbi-domain" DT property from CPU DT nodes
+ * 3. Removes domain configuration DT node under /chosen DT node
+ *
+ * It is recommended that platform support call this function in
+ * their final_init() platform operation.
+ *
+ * @param fdt device tree blob
+ */
+void fdt_domain_fixup(void *fdt);
+
+/**
+ * Get domain instance for given HART
+ *
+ * Note: Domains should be populated before using this function.
+ *
+ * @param hartid the HART for which domain instance is needed
+ *
+ * @return pointer to domain instance on success and NULL on failure
+ */
+struct sbi_domain *fdt_domain_get(u32 hartid);
+
+/**
+ * Populate domains from device tree
+ *
+ * It is recommended that platform support call this function in
+ * their domains_init() platform operation.
+ *
+ * @param fdt device tree blob
+ *
+ * @return 0 on success and negative error code on failure
+ */
+int fdt_domains_populate(void *fdt);
+
+#endif /* __FDT_DOMAIN_H__ */