All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: Will Deacon <will.deacon@arm.com>, Marc Zyngier <marc.zyngier@arm.com>
Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: [kvmtool PATCH v10 01/15] FDT: use static phandles
Date: Tue, 25 Apr 2017 15:39:18 +0100	[thread overview]
Message-ID: <20170425143932.17235-2-andre.przywara@arm.com> (raw)
In-Reply-To: <20170425143932.17235-1-andre.przywara@arm.com>

The current implementation of fdt__alloc_phandle() suffers from being
implemented in a static inline function situated in a header file.
This will only create expected results within a single compilation
unit.
It seems a bit over the top to use a function to allocate phandles,
when at the end of the day a phandle is just a unique identifier.
To simplify things - especially with upcoming patches - we just
introduce an enum per architecture to hold all possible phandle sources
and use that instead of the dynamic allocation.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 arm/aarch32/include/kvm/fdt-arch.h | 6 ++++++
 arm/aarch64/include/kvm/fdt-arch.h | 6 ++++++
 arm/fdt.c                          | 7 +++----
 arm/include/arm-common/fdt-arch.h  | 6 ++++++
 include/kvm/fdt.h                  | 8 ++------
 mips/include/kvm/fdt-arch.h        | 6 ++++++
 powerpc/include/kvm/fdt-arch.h     | 6 ++++++
 powerpc/kvm.c                      | 2 --
 x86/include/kvm/fdt-arch.h         | 6 ++++++
 9 files changed, 41 insertions(+), 12 deletions(-)
 create mode 100644 arm/aarch32/include/kvm/fdt-arch.h
 create mode 100644 arm/aarch64/include/kvm/fdt-arch.h
 create mode 100644 arm/include/arm-common/fdt-arch.h
 create mode 100644 mips/include/kvm/fdt-arch.h
 create mode 100644 powerpc/include/kvm/fdt-arch.h
 create mode 100644 x86/include/kvm/fdt-arch.h

diff --git a/arm/aarch32/include/kvm/fdt-arch.h b/arm/aarch32/include/kvm/fdt-arch.h
new file mode 100644
index 0000000..e448bf1
--- /dev/null
+++ b/arm/aarch32/include/kvm/fdt-arch.h
@@ -0,0 +1,6 @@
+#ifndef KVM__KVM_FDT_H
+#define KVM__KVM_FDT_H
+
+#include "arm-common/fdt-arch.h"
+
+#endif /* KVM__KVM_FDT_H */
diff --git a/arm/aarch64/include/kvm/fdt-arch.h b/arm/aarch64/include/kvm/fdt-arch.h
new file mode 100644
index 0000000..e448bf1
--- /dev/null
+++ b/arm/aarch64/include/kvm/fdt-arch.h
@@ -0,0 +1,6 @@
+#ifndef KVM__KVM_FDT_H
+#define KVM__KVM_FDT_H
+
+#include "arm-common/fdt-arch.h"
+
+#endif /* KVM__KVM_FDT_H */
diff --git a/arm/fdt.c b/arm/fdt.c
index 381d48f..bcd0c3a 100644
--- a/arm/fdt.c
+++ b/arm/fdt.c
@@ -114,7 +114,6 @@ static int setup_fdt(struct kvm *kvm)
 {
 	struct device_header *dev_hdr;
 	u8 staging_fdt[FDT_MAX_SIZE];
-	u32 gic_phandle		= fdt__alloc_phandle();
 	u64 mem_reg_prop[]	= {
 		cpu_to_fdt64(kvm->arch.memory_guest_start),
 		cpu_to_fdt64(kvm->ram_size),
@@ -134,7 +133,7 @@ static int setup_fdt(struct kvm *kvm)
 
 	/* Header */
 	_FDT(fdt_begin_node(fdt, ""));
-	_FDT(fdt_property_cell(fdt, "interrupt-parent", gic_phandle));
+	_FDT(fdt_property_cell(fdt, "interrupt-parent", PHANDLE_GIC));
 	_FDT(fdt_property_string(fdt, "compatible", "linux,dummy-virt"));
 	_FDT(fdt_property_cell(fdt, "#address-cells", 0x2));
 	_FDT(fdt_property_cell(fdt, "#size-cells", 0x2));
@@ -166,7 +165,7 @@ static int setup_fdt(struct kvm *kvm)
 	/* CPU and peripherals (interrupt controller, timers, etc) */
 	generate_cpu_nodes(fdt, kvm);
 	if (generate_cpu_peripheral_fdt_nodes)
-		generate_cpu_peripheral_fdt_nodes(fdt, kvm, gic_phandle);
+		generate_cpu_peripheral_fdt_nodes(fdt, kvm, PHANDLE_GIC);
 
 	/* Virtio MMIO devices */
 	dev_hdr = device__first_dev(DEVICE_BUS_MMIO);
@@ -185,7 +184,7 @@ static int setup_fdt(struct kvm *kvm)
 	}
 
 	/* PCI host controller */
-	pci__generate_fdt_nodes(fdt, gic_phandle);
+	pci__generate_fdt_nodes(fdt, PHANDLE_GIC);
 
 	/* PSCI firmware */
 	_FDT(fdt_begin_node(fdt, "psci"));
diff --git a/arm/include/arm-common/fdt-arch.h b/arm/include/arm-common/fdt-arch.h
new file mode 100644
index 0000000..53ba633
--- /dev/null
+++ b/arm/include/arm-common/fdt-arch.h
@@ -0,0 +1,6 @@
+#ifndef ARM__FDT_H
+#define ARM__FDT_H
+
+enum phandles {PHANDLE_RESERVED = 0, PHANDLE_GIC, PHANDLES_MAX};
+
+#endif /* ARM__FDT_H */
diff --git a/include/kvm/fdt.h b/include/kvm/fdt.h
index 53d85a4..beadc7f 100644
--- a/include/kvm/fdt.h
+++ b/include/kvm/fdt.h
@@ -7,6 +7,8 @@
 
 #include <linux/types.h>
 
+#include "kvm/fdt-arch.h"
+
 #define FDT_MAX_SIZE	0x10000
 
 /* Those definitions are generic FDT values for specifying IRQ
@@ -33,10 +35,4 @@ enum irq_type {
 		}							\
 	} while (0)
 
-static inline u32 fdt__alloc_phandle(void)
-{
-	static u32 phandle = 0;
-	return ++phandle;
-}
-
 #endif /* KVM__FDT_H */
diff --git a/mips/include/kvm/fdt-arch.h b/mips/include/kvm/fdt-arch.h
new file mode 100644
index 0000000..b030245
--- /dev/null
+++ b/mips/include/kvm/fdt-arch.h
@@ -0,0 +1,6 @@
+#ifndef KVM__KVM_FDT_H
+#define KVM__KVM_FDT_H
+
+enum phandles {PHANDLE_RESERVED = 0, PHANDLES_MAX};
+
+#endif /* KVM__KVM_FDT_H */
diff --git a/powerpc/include/kvm/fdt-arch.h b/powerpc/include/kvm/fdt-arch.h
new file mode 100644
index 0000000..d48c055
--- /dev/null
+++ b/powerpc/include/kvm/fdt-arch.h
@@ -0,0 +1,6 @@
+#ifndef KVM__KVM_FDT_H
+#define KVM__KVM_FDT_H
+
+enum phandles {PHANDLE_RESERVED = 0, PHANDLE_XICP, PHANDLES_MAX};
+
+#endif /* KVM__KVM_FDT_H */
diff --git a/powerpc/kvm.c b/powerpc/kvm.c
index 3c1596d..c738c1d 100644
--- a/powerpc/kvm.c
+++ b/powerpc/kvm.c
@@ -40,8 +40,6 @@
 
 #define HUGETLBFS_PATH "/var/lib/hugetlbfs/global/pagesize-16MB/"
 
-#define PHANDLE_XICP		0x00001111
-
 static char kern_cmdline[2048];
 
 struct kvm_ext kvm_req_ext[] = {
diff --git a/x86/include/kvm/fdt-arch.h b/x86/include/kvm/fdt-arch.h
new file mode 100644
index 0000000..eebd73f
--- /dev/null
+++ b/x86/include/kvm/fdt-arch.h
@@ -0,0 +1,6 @@
+#ifndef X86__FDT_ARCH_H
+#define X86__FDT_ARCH_H
+
+enum phandles {PHANDLE_RESERVED = 0, PHANDLES_MAX};
+
+#endif /* KVM__KVM_FDT_H */
-- 
2.9.0

WARNING: multiple messages have this Message-ID (diff)
From: andre.przywara@arm.com (Andre Przywara)
To: linux-arm-kernel@lists.infradead.org
Subject: [kvmtool PATCH v10 01/15] FDT: use static phandles
Date: Tue, 25 Apr 2017 15:39:18 +0100	[thread overview]
Message-ID: <20170425143932.17235-2-andre.przywara@arm.com> (raw)
In-Reply-To: <20170425143932.17235-1-andre.przywara@arm.com>

The current implementation of fdt__alloc_phandle() suffers from being
implemented in a static inline function situated in a header file.
This will only create expected results within a single compilation
unit.
It seems a bit over the top to use a function to allocate phandles,
when at the end of the day a phandle is just a unique identifier.
To simplify things - especially with upcoming patches - we just
introduce an enum per architecture to hold all possible phandle sources
and use that instead of the dynamic allocation.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 arm/aarch32/include/kvm/fdt-arch.h | 6 ++++++
 arm/aarch64/include/kvm/fdt-arch.h | 6 ++++++
 arm/fdt.c                          | 7 +++----
 arm/include/arm-common/fdt-arch.h  | 6 ++++++
 include/kvm/fdt.h                  | 8 ++------
 mips/include/kvm/fdt-arch.h        | 6 ++++++
 powerpc/include/kvm/fdt-arch.h     | 6 ++++++
 powerpc/kvm.c                      | 2 --
 x86/include/kvm/fdt-arch.h         | 6 ++++++
 9 files changed, 41 insertions(+), 12 deletions(-)
 create mode 100644 arm/aarch32/include/kvm/fdt-arch.h
 create mode 100644 arm/aarch64/include/kvm/fdt-arch.h
 create mode 100644 arm/include/arm-common/fdt-arch.h
 create mode 100644 mips/include/kvm/fdt-arch.h
 create mode 100644 powerpc/include/kvm/fdt-arch.h
 create mode 100644 x86/include/kvm/fdt-arch.h

diff --git a/arm/aarch32/include/kvm/fdt-arch.h b/arm/aarch32/include/kvm/fdt-arch.h
new file mode 100644
index 0000000..e448bf1
--- /dev/null
+++ b/arm/aarch32/include/kvm/fdt-arch.h
@@ -0,0 +1,6 @@
+#ifndef KVM__KVM_FDT_H
+#define KVM__KVM_FDT_H
+
+#include "arm-common/fdt-arch.h"
+
+#endif /* KVM__KVM_FDT_H */
diff --git a/arm/aarch64/include/kvm/fdt-arch.h b/arm/aarch64/include/kvm/fdt-arch.h
new file mode 100644
index 0000000..e448bf1
--- /dev/null
+++ b/arm/aarch64/include/kvm/fdt-arch.h
@@ -0,0 +1,6 @@
+#ifndef KVM__KVM_FDT_H
+#define KVM__KVM_FDT_H
+
+#include "arm-common/fdt-arch.h"
+
+#endif /* KVM__KVM_FDT_H */
diff --git a/arm/fdt.c b/arm/fdt.c
index 381d48f..bcd0c3a 100644
--- a/arm/fdt.c
+++ b/arm/fdt.c
@@ -114,7 +114,6 @@ static int setup_fdt(struct kvm *kvm)
 {
 	struct device_header *dev_hdr;
 	u8 staging_fdt[FDT_MAX_SIZE];
-	u32 gic_phandle		= fdt__alloc_phandle();
 	u64 mem_reg_prop[]	= {
 		cpu_to_fdt64(kvm->arch.memory_guest_start),
 		cpu_to_fdt64(kvm->ram_size),
@@ -134,7 +133,7 @@ static int setup_fdt(struct kvm *kvm)
 
 	/* Header */
 	_FDT(fdt_begin_node(fdt, ""));
-	_FDT(fdt_property_cell(fdt, "interrupt-parent", gic_phandle));
+	_FDT(fdt_property_cell(fdt, "interrupt-parent", PHANDLE_GIC));
 	_FDT(fdt_property_string(fdt, "compatible", "linux,dummy-virt"));
 	_FDT(fdt_property_cell(fdt, "#address-cells", 0x2));
 	_FDT(fdt_property_cell(fdt, "#size-cells", 0x2));
@@ -166,7 +165,7 @@ static int setup_fdt(struct kvm *kvm)
 	/* CPU and peripherals (interrupt controller, timers, etc) */
 	generate_cpu_nodes(fdt, kvm);
 	if (generate_cpu_peripheral_fdt_nodes)
-		generate_cpu_peripheral_fdt_nodes(fdt, kvm, gic_phandle);
+		generate_cpu_peripheral_fdt_nodes(fdt, kvm, PHANDLE_GIC);
 
 	/* Virtio MMIO devices */
 	dev_hdr = device__first_dev(DEVICE_BUS_MMIO);
@@ -185,7 +184,7 @@ static int setup_fdt(struct kvm *kvm)
 	}
 
 	/* PCI host controller */
-	pci__generate_fdt_nodes(fdt, gic_phandle);
+	pci__generate_fdt_nodes(fdt, PHANDLE_GIC);
 
 	/* PSCI firmware */
 	_FDT(fdt_begin_node(fdt, "psci"));
diff --git a/arm/include/arm-common/fdt-arch.h b/arm/include/arm-common/fdt-arch.h
new file mode 100644
index 0000000..53ba633
--- /dev/null
+++ b/arm/include/arm-common/fdt-arch.h
@@ -0,0 +1,6 @@
+#ifndef ARM__FDT_H
+#define ARM__FDT_H
+
+enum phandles {PHANDLE_RESERVED = 0, PHANDLE_GIC, PHANDLES_MAX};
+
+#endif /* ARM__FDT_H */
diff --git a/include/kvm/fdt.h b/include/kvm/fdt.h
index 53d85a4..beadc7f 100644
--- a/include/kvm/fdt.h
+++ b/include/kvm/fdt.h
@@ -7,6 +7,8 @@
 
 #include <linux/types.h>
 
+#include "kvm/fdt-arch.h"
+
 #define FDT_MAX_SIZE	0x10000
 
 /* Those definitions are generic FDT values for specifying IRQ
@@ -33,10 +35,4 @@ enum irq_type {
 		}							\
 	} while (0)
 
-static inline u32 fdt__alloc_phandle(void)
-{
-	static u32 phandle = 0;
-	return ++phandle;
-}
-
 #endif /* KVM__FDT_H */
diff --git a/mips/include/kvm/fdt-arch.h b/mips/include/kvm/fdt-arch.h
new file mode 100644
index 0000000..b030245
--- /dev/null
+++ b/mips/include/kvm/fdt-arch.h
@@ -0,0 +1,6 @@
+#ifndef KVM__KVM_FDT_H
+#define KVM__KVM_FDT_H
+
+enum phandles {PHANDLE_RESERVED = 0, PHANDLES_MAX};
+
+#endif /* KVM__KVM_FDT_H */
diff --git a/powerpc/include/kvm/fdt-arch.h b/powerpc/include/kvm/fdt-arch.h
new file mode 100644
index 0000000..d48c055
--- /dev/null
+++ b/powerpc/include/kvm/fdt-arch.h
@@ -0,0 +1,6 @@
+#ifndef KVM__KVM_FDT_H
+#define KVM__KVM_FDT_H
+
+enum phandles {PHANDLE_RESERVED = 0, PHANDLE_XICP, PHANDLES_MAX};
+
+#endif /* KVM__KVM_FDT_H */
diff --git a/powerpc/kvm.c b/powerpc/kvm.c
index 3c1596d..c738c1d 100644
--- a/powerpc/kvm.c
+++ b/powerpc/kvm.c
@@ -40,8 +40,6 @@
 
 #define HUGETLBFS_PATH "/var/lib/hugetlbfs/global/pagesize-16MB/"
 
-#define PHANDLE_XICP		0x00001111
-
 static char kern_cmdline[2048];
 
 struct kvm_ext kvm_req_ext[] = {
diff --git a/x86/include/kvm/fdt-arch.h b/x86/include/kvm/fdt-arch.h
new file mode 100644
index 0000000..eebd73f
--- /dev/null
+++ b/x86/include/kvm/fdt-arch.h
@@ -0,0 +1,6 @@
+#ifndef X86__FDT_ARCH_H
+#define X86__FDT_ARCH_H
+
+enum phandles {PHANDLE_RESERVED = 0, PHANDLES_MAX};
+
+#endif /* KVM__KVM_FDT_H */
-- 
2.9.0

  reply	other threads:[~2017-04-25 14:39 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-25 14:39 [kvmtool PATCH v10 00/15] kvmtool: arm: ITS emulation and GSI routing support Andre Przywara
2017-04-25 14:39 ` Andre Przywara
2017-04-25 14:39 ` Andre Przywara [this message]
2017-04-25 14:39   ` [kvmtool PATCH v10 01/15] FDT: use static phandles Andre Przywara
2017-04-25 14:39 ` [kvmtool PATCH v10 02/15] arm: use static DT phandle for the GIC Andre Przywara
2017-04-25 14:39   ` Andre Przywara
2017-04-25 14:39 ` [kvmtool PATCH v10 03/15] irq: move IRQ routing into irq.c Andre Przywara
2017-04-25 14:39   ` Andre Przywara
2017-04-25 14:39 ` [kvmtool PATCH v10 04/15] MSI-X: update GSI routing after changed MSI-X configuration Andre Przywara
2017-04-25 14:39   ` Andre Przywara
2017-04-25 14:39 ` [kvmtool PATCH v10 05/15] virtio: fix endianness check for vhost support Andre Przywara
2017-04-25 14:39   ` Andre Przywara
2017-04-25 14:39 ` [kvmtool PATCH v10 06/15] PCI: Only allocate IRQ routing entry when available Andre Przywara
2017-04-25 14:39   ` Andre Przywara
2017-04-25 14:39 ` [kvmtool PATCH v10 07/15] update public Linux headers for GICv3 ITS emulation Andre Przywara
2017-04-25 14:39   ` Andre Przywara
2017-04-25 14:39 ` [kvmtool PATCH v10 08/15] arm: allow vGICv3 emulation Andre Przywara
2017-04-25 14:39   ` Andre Przywara
2017-04-25 14:39 ` [kvmtool PATCH v10 09/15] arm: allow creation of an MSI register frame region Andre Przywara
2017-04-25 14:39   ` Andre Przywara
2017-04-25 14:39 ` [kvmtool PATCH v10 10/15] arm: FDT: create MSI controller DT node Andre Przywara
2017-04-25 14:39   ` Andre Przywara
2017-04-25 14:39 ` [kvmtool PATCH v10 11/15] add kvm__supports_vm_extension() Andre Przywara
2017-04-25 14:39   ` Andre Przywara
2017-04-25 14:39 ` [kvmtool PATCH v10 12/15] PCI: inject PCI device ID on MSI injection Andre Przywara
2017-04-25 14:39   ` Andre Przywara
2017-04-25 14:39 ` [kvmtool PATCH v10 13/15] arm: setup SPI IRQ routing tables Andre Przywara
2017-04-25 14:39   ` Andre Przywara
2017-04-25 14:39 ` [kvmtool PATCH v10 14/15] extend GSI IRQ routing to take a device ID Andre Przywara
2017-04-25 14:39   ` Andre Przywara
2017-04-25 14:39 ` [kvmtool PATCH v10 15/15] arm64: enable GICv3-ITS emulation Andre Przywara
2017-04-25 14:39   ` Andre Przywara
2017-06-08  9:11 ` [kvmtool PATCH v10 00/15] kvmtool: arm: ITS emulation and GSI routing support Marc Zyngier
2017-06-08  9:11   ` Marc Zyngier
2017-06-08  9:36   ` Andre Przywara
2017-06-08  9:36     ` Andre Przywara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170425143932.17235-2-andre.przywara@arm.com \
    --to=andre.przywara@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=marc.zyngier@arm.com \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.