@@ -303,6 +303,7 @@ ifeq (y,$(ARCH_WANT_LIBFDT))
CFLAGS_STATOPT += -DCONFIG_HAS_LIBFDT
LIBS_DYNOPT += -lfdt
LIBS_STATOPT += -lfdt
+ OBJS += fdt.o
endif
endif
@@ -1,6 +1,6 @@
#ifndef ARM__FDT_H
#define ARM__FDT_H
-enum phandles {PHANDLE_RESERVED = 0, PHANDLE_GIC, PHANDLE_MSI, PHANDLES_MAX};
+enum phandles {PHANDLE_RESERVED = 0, PHANDLE_GIC, PHANDLE_MSI, ARCH_PHANDLES_MAX};
#endif /* ARM__FDT_H */
new file mode 100644
@@ -0,0 +1,15 @@
+/*
+ * Commonly used FDT functions.
+ */
+
+#include "kvm/fdt.h"
+
+static u32 next_phandle = PHANDLE_RESERVED;
+
+u32 fdt_alloc_phandle(void)
+{
+ if (next_phandle == PHANDLE_RESERVED)
+ next_phandle = ARCH_PHANDLES_MAX;
+
+ return next_phandle++;
+}
@@ -35,4 +35,17 @@ enum irq_type {
} \
} while (0)
+#ifdef CONFIG_HAS_LIBFDT
+
+u32 fdt_alloc_phandle(void);
+
+#else
+
+static inline u32 fdt_alloc_phandle(void)
+{
+ return PHANDLE_RESERVED;
+}
+
+#endif /* CONFIG_HAS_LIBFDT */
+
#endif /* KVM__FDT_H */
@@ -1,6 +1,6 @@
#ifndef KVM__KVM_FDT_H
#define KVM__KVM_FDT_H
-enum phandles {PHANDLE_RESERVED = 0, PHANDLES_MAX};
+enum phandles {PHANDLE_RESERVED = 0, ARCH_PHANDLES_MAX};
#endif /* KVM__KVM_FDT_H */
@@ -1,6 +1,6 @@
#ifndef KVM__KVM_FDT_H
#define KVM__KVM_FDT_H
-enum phandles {PHANDLE_RESERVED = 0, PHANDLE_XICP, PHANDLES_MAX};
+enum phandles {PHANDLE_RESERVED = 0, PHANDLE_XICP, ARCH_PHANDLES_MAX};
#endif /* KVM__KVM_FDT_H */
@@ -1,6 +1,6 @@
#ifndef X86__FDT_ARCH_H
#define X86__FDT_ARCH_H
-enum phandles {PHANDLE_RESERVED = 0, PHANDLES_MAX};
+enum phandles {PHANDLE_RESERVED = 0, ARCH_PHANDLES_MAX};
#endif /* KVM__KVM_FDT_H */
The phandle allocator was removed because static values were sufficient for creating a common irqchip. With adding multiple virtual IOMMUs to the device-tree, there is a need for a dynamic allocation of phandles. Add a simple allocator that returns values above the static ones. Signed-off-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com> --- Makefile | 1 + arm/include/arm-common/fdt-arch.h | 2 +- fdt.c | 15 +++++++++++++++ include/kvm/fdt.h | 13 +++++++++++++ mips/include/kvm/fdt-arch.h | 2 +- powerpc/include/kvm/fdt-arch.h | 2 +- x86/include/kvm/fdt-arch.h | 2 +- 7 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 fdt.c