Skip to contentSkip to conversation

xen/include: introduce resource.h

PATCH Superseded [email protected] 3 participants 5 messages Feb 7, 2025 – Feb 11, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/include: introduce resource.h

Move resource definitions to a new architecture-agnostic shared header file.

---
Link to the original patch:
https://lore.kernel.org/xen-devel/[email protected]/
---

---
 xen/common/device-tree/device-tree.c | 21 +----------------
 xen/drivers/passthrough/arm/smmu.c   | 15 +-----------
 xen/include/xen/resource.h           | 34 ++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 34 deletions(-)
 create mode 100644 xen/include/xen/resource.h
xen/common/device-tree/device-tree.c +1 -20
index d0528c5825..e8f810b2fe 100644
@@ -24,6 +24,7 @@
 #include <xen/ctype.h>
 #include <asm/setup.h>
 #include <xen/err.h>
+#include <xen/resource.h>
 
 const void *device_tree_flattened;
 dt_irq_xlate_func dt_irq_xlate;
@@ -535,26 +536,6 @@ int dt_child_n_size_cells(const struct dt_device_node *parent)
     return __dt_n_size_cells(parent, true);
 }
 
-/*
- * These are defined in Linux where much of this code comes from, but
- * are currently unused outside this file in the context of Xen.
- */
-#define IORESOURCE_BITS         0x000000ff      /* Bus-specific bits */
-
-#define IORESOURCE_TYPE_BITS    0x00001f00      /* Resource type */
-#define IORESOURCE_IO           0x00000100      /* PCI/ISA I/O ports */
-#define IORESOURCE_MEM          0x00000200
-#define IORESOURCE_REG          0x00000300      /* Register offsets */
-#define IORESOURCE_IRQ          0x00000400
-#define IORESOURCE_DMA          0x00000800
-#define IORESOURCE_BUS          0x00001000
-
-#define IORESOURCE_PREFETCH     0x00002000      /* No side effects */
-#define IORESOURCE_READONLY     0x00004000
-#define IORESOURCE_CACHEABLE    0x00008000
-#define IORESOURCE_RANGELENGTH  0x00010000
-#define IORESOURCE_SHADOWABLE   0x00020000
-
 /*
  * Default translator (generic bus)
  */
xen/drivers/passthrough/arm/smmu.c +1 -14
index 03d22bce1e..aa6a968b57 100644
@@ -50,6 +50,7 @@
 #include <xen/rbtree.h>
 #include <xen/sched.h>
 #include <xen/sizes.h>
+#include <xen/resource.h>
 #include <asm/atomic.h>
 #include <asm/device.h>
 #include <asm/io.h>
@@ -70,22 +71,8 @@
 #define of_property_read_u32(np, pname, out) (!dt_property_read_u32(np, pname, out))
 #define of_property_read_bool dt_property_read_bool
 #define of_parse_phandle_with_args dt_parse_phandle_with_args
-
-/* Xen: Helpers to get device MMIO and IRQs */
-struct resource
-{
-	paddr_t addr;
-	paddr_t size;
-	unsigned int type;
-};
-
-#define resource_size(res) (res)->size;
-
 #define platform_device dt_device_node
 
-#define IORESOURCE_MEM 0
-#define IORESOURCE_IRQ 1
-
 static struct resource *platform_get_resource(struct platform_device *pdev,
 					      unsigned int type,
 					      unsigned int num)
xen/include/xen/resource.h new file +34 -0
new file mode 100644
index 0000000000..5d10363128
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * System resource description.
+ */
+#ifndef XEN__RESOURCE_H
+#define XEN__RESOURCE_H
+
+#define IORESOURCE_BITS         0x000000FFU      /* Bus-specific bits */
+
+#define IORESOURCE_TYPE_BITS    0x00001F00U      /* Resource type */
+#define IORESOURCE_IO           0x00000100U      /* PCI/ISA I/O ports */
+#define IORESOURCE_MEM          0x00000200U
+#define IORESOURCE_REG          0x00000300U      /* Register offsets */
+#define IORESOURCE_IRQ          0x00000400U
+#define IORESOURCE_DMA          0x00000800U
+#define IORESOURCE_BUS          0x00001000U
+
+#define IORESOURCE_PREFETCH     0x00002000U      /* No side effects */
+#define IORESOURCE_READONLY     0x00004000U
+#define IORESOURCE_CACHEABLE    0x00008000U
+#define IORESOURCE_RANGELENGTH  0x00010000U
+#define IORESOURCE_SHADOWABLE   0x00020000U
+
+#define IORESOURCE_UNKNOWN      (~0U)
+
+struct resource {
+    paddr_t addr;
+    paddr_t size;
+    unsigned int type;
+};
+
+#define resource_size(res)      ((res)->size)
+
+#endif /* XEN__RESOURCE_H */
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · On Fri, 7 Feb 2025, [email protected] wrote:

Move resource definitions to a new architecture-agnostic shared header file.

Quoted 129 lines

---
Link to the original patch:
https://lore.kernel.org/xen-devel/[email protected]/
---

---
 xen/common/device-tree/device-tree.c | 21 +----------------
 xen/drivers/passthrough/arm/smmu.c   | 15 +-----------
 xen/include/xen/resource.h           | 34 ++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 34 deletions(-)
 create mode 100644 xen/include/xen/resource.h
xen/common/device-tree/device-tree.c +1 -20
index d0528c5825..e8f810b2fe 100644
@@ -24,6 +24,7 @@
 #include <xen/ctype.h>
 #include <asm/setup.h>
 #include <xen/err.h>
+#include <xen/resource.h>
 
 const void *device_tree_flattened;
 dt_irq_xlate_func dt_irq_xlate;
@@ -535,26 +536,6 @@ int dt_child_n_size_cells(const struct dt_device_node *parent)
     return __dt_n_size_cells(parent, true);
 }
 
-/*
- * These are defined in Linux where much of this code comes from, but
- * are currently unused outside this file in the context of Xen.
- */
-#define IORESOURCE_BITS         0x000000ff      /* Bus-specific bits */
-
-#define IORESOURCE_TYPE_BITS    0x00001f00      /* Resource type */
-#define IORESOURCE_IO           0x00000100      /* PCI/ISA I/O ports */
-#define IORESOURCE_MEM          0x00000200
-#define IORESOURCE_REG          0x00000300      /* Register offsets */
-#define IORESOURCE_IRQ          0x00000400
-#define IORESOURCE_DMA          0x00000800
-#define IORESOURCE_BUS          0x00001000
-
-#define IORESOURCE_PREFETCH     0x00002000      /* No side effects */
-#define IORESOURCE_READONLY     0x00004000
-#define IORESOURCE_CACHEABLE    0x00008000
-#define IORESOURCE_RANGELENGTH  0x00010000
-#define IORESOURCE_SHADOWABLE   0x00020000
-
 /*
  * Default translator (generic bus)
  */
xen/drivers/passthrough/arm/smmu.c +1 -14
index 03d22bce1e..aa6a968b57 100644
@@ -50,6 +50,7 @@
 #include <xen/rbtree.h>
 #include <xen/sched.h>
 #include <xen/sizes.h>
+#include <xen/resource.h>
 #include <asm/atomic.h>
 #include <asm/device.h>
 #include <asm/io.h>
@@ -70,22 +71,8 @@
 #define of_property_read_u32(np, pname, out) (!dt_property_read_u32(np, pname, out))
 #define of_property_read_bool dt_property_read_bool
 #define of_parse_phandle_with_args dt_parse_phandle_with_args
-
-/* Xen: Helpers to get device MMIO and IRQs */
-struct resource
-{
-	paddr_t addr;
-	paddr_t size;
-	unsigned int type;
-};
-
-#define resource_size(res) (res)->size;
-
 #define platform_device dt_device_node
 
-#define IORESOURCE_MEM 0
-#define IORESOURCE_IRQ 1
-
 static struct resource *platform_get_resource(struct platform_device *pdev,
 					      unsigned int type,
 					      unsigned int num)
xen/include/xen/resource.h new file +34 -0
new file mode 100644
index 0000000000..5d10363128
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * System resource description.
+ */
+#ifndef XEN__RESOURCE_H
+#define XEN__RESOURCE_H
+
+#define IORESOURCE_BITS         0x000000FFU      /* Bus-specific bits */
+
+#define IORESOURCE_TYPE_BITS    0x00001F00U      /* Resource type */
+#define IORESOURCE_IO           0x00000100U      /* PCI/ISA I/O ports */
+#define IORESOURCE_MEM          0x00000200U
+#define IORESOURCE_REG          0x00000300U      /* Register offsets */
+#define IORESOURCE_IRQ          0x00000400U
+#define IORESOURCE_DMA          0x00000800U
+#define IORESOURCE_BUS          0x00001000U
+
+#define IORESOURCE_PREFETCH     0x00002000U      /* No side effects */
+#define IORESOURCE_READONLY     0x00004000U
+#define IORESOURCE_CACHEABLE    0x00008000U
+#define IORESOURCE_RANGELENGTH  0x00010000U
+#define IORESOURCE_SHADOWABLE   0x00020000U
+
+#define IORESOURCE_UNKNOWN      (~0U)
+
+struct resource {
+    paddr_t addr;
+    paddr_t size;
+    unsigned int type;
+};
+
+#define resource_size(res)      ((res)->size)
+
+#endif /* XEN__RESOURCE_H */
Signature · 1 line
2.34.1
#2 lore raw
Quoted 6 lines · Stefano Stabellini
Quoted 3 lines · On Fri, 7 Feb 2025, [email protected] wrote:

Move resource definitions to a new architecture-agnostic shared header file.

Hmm, don't you think ...

Quoted 8 lines
Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c +0 -4
@@ -70,22 +71,8 @@
 #define of_property_read_u32(np, pname, out) (!dt_property_read_u32(np, pname, out))
 #define of_property_read_bool dt_property_read_bool
 #define of_parse_phandle_with_args dt_parse_phandle_with_args
-
-/* Xen: Helpers to get device MMIO and IRQs */
-struct resource
-{
Quoted 8 lines

xen/drivers/passthrough/arm/smmu.c line 74

Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c +0 -7
-	paddr_t addr;
-	paddr_t size;
-	unsigned int type;
-};
-
-#define resource_size(res) (res)->size;
-
 #define platform_device dt_device_node

... one of the blank lines being removed here would better stay?

Jan

#3 lore raw
Quoted 26 lines · Jan Beulich
Quoted 7 lines · Stefano Stabellini
Quoted 3 lines · On Fri, 7 Feb 2025, [email protected] wrote:

Move resource definitions to a new architecture-agnostic shared header file.

Hmm, don't you think ...

Quoted 11 lines
Quoted 11 lines
xen/drivers/passthrough/arm/smmu.c +0 -7
@@ -70,22 +71,8 @@
 #define of_property_read_u32(np, pname, out) (!dt_property_read_u32(np, pname, out))
 #define of_property_read_bool dt_property_read_bool
 #define of_parse_phandle_with_args dt_parse_phandle_with_args
-
-/* Xen: Helpers to get device MMIO and IRQs */
-struct resource
-{
- paddr_t addr;
- paddr_t size;
- unsigned int type;
Quoted 8 lines
Quoted 5 lines

xen/drivers/passthrough/arm/smmu.c line 74

Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c +0 -4
-};
-
-#define resource_size(res) (res)->size;
-
 #define platform_device dt_device_node

... one of the blank lines being removed here would better stay?

I think the block of assorted macros (the first macro is not of not of_xxx() type) does not need an extra newline.

The resulting block of macros looks like the following:
[[

/* Alias to Xen device tree helpers */
#define device_node dt_device_node
#define of_phandle_args dt_phandle_args
#define of_device_id dt_device_match
#define of_match_node dt_match_node
#define of_property_read_u32(np, pname, out) (!dt_property_read_u32(np, pname, out)) #define of_property_read_bool dt_property_read_bool
#define of_parse_phandle_with_args dt_parse_phandle_with_args
#define platform_device dt_device_node

]]

Quoted 2 lines

Jan

#4 lore raw
Quoted 48 lines · Denis Mukhin
Quoted 23 lines · Stefano Stabellini
Quoted 7 lines · On Fri, 7 Feb 2025, [email protected] wrote:
Quoted 4 lines

Move resource definitions to a new architecture-agnostic shared header file.

Hmm, don't you think ...

Quoted 11 lines
Quoted 11 lines
xen/drivers/passthrough/arm/smmu.c +0 -7
@@ -70,22 +71,8 @@
 #define of_property_read_u32(np, pname, out) (!dt_property_read_u32(np, pname, out))
 #define of_property_read_bool dt_property_read_bool
 #define of_parse_phandle_with_args dt_parse_phandle_with_args
-
-/* Xen: Helpers to get device MMIO and IRQs */
-struct resource
-{
- paddr_t addr;
- paddr_t size;
- unsigned int type;
Quoted 8 lines
Quoted 5 lines

xen/drivers/passthrough/arm/smmu.c line 74

Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c +0 -4
-};
-
-#define resource_size(res) (res)->size;
-
 #define platform_device dt_device_node

... one of the blank lines being removed here would better stay?

I think the block of assorted macros (the first macro is not of not of_xxx() type) does not need an extra newline.

The resulting block of macros looks like the following:
[[

/* Alias to Xen device tree helpers */
#define device_node dt_device_node
#define of_phandle_args dt_phandle_args
#define of_device_id dt_device_match
#define of_match_node dt_match_node
#define of_property_read_u32(np, pname, out) (!dt_property_read_u32(np, pname, out)) #define of_property_read_bool dt_property_read_bool
#define of_parse_phandle_with_args dt_parse_phandle_with_args
#define platform_device dt_device_node

Quoted 1 line

]]

And I think the of_* ones would better be separated by blank lines from the others. Arguably platform_device might then want to move up, immediately next to device_node.

Jan