Move {acpi_}device_init() and device_get_class() to common code
v5 cover Move {acpi_}device_init() and device_get_class() to common code
The {acpi_}device_init() and device_get_class() functions are identical across Arm and RISC-V, and they are likely to remain the same for other architectures like PPC.
Since there is no architecture-specific logic within these functions, they are good candidates to be moved to the common codebase.
This patch series refactors the code by moving these functions to the common directory, reducing code duplication and simplifying future maintenance.
---
Changes in V5:
- Rename SIMPLE_DECL_SECTION to DECL_SECTION_WITH_LADDR and update the other patches correspondingly.
- Drop macros argument for ACPI_DEV_INFO and DT_DEV_INFO.
---
Changes in V4:
- Introduce SIMPLE_DECL_SECTION to cover the cases when an architecture wants to use section declaration without specifying an load address.
- Refactor macors ACPI_DEV_INFO and DT_DEV_INFO and update their defintion.
---
Changes in V3:
- drop _SECTIONS from the name of the macros ADEV_INFO and DT_DEV_INFO
- update the definion of macros ADEV_INFO and DT_DEV_INFO
- drop DEVICE_INIT config.
---
Changes in v2:
- Introduce macros for definition of ACPI and Device Tree sections.
- Introduce CONFIG_DEVICE_INIT to make common/device.o compilable only for Arm, PPC and RISC-V.
---
Oleksii Kurochko (6):
xen: introduce DECL_SECTION_WITH_LADDR
xen: define ACPI and DT device info sections macros xen/arm: use {DT,ACPI}_DEV_INFO for device info sections xen/ppc: add section for device information in linker script xen/riscv: add section for device information in linker script xen/common: move device initialization code to common code
xen/arch/arm/device.c | 71 +-------------------------------- xen/arch/arm/xen.lds.S | 14 +------ xen/arch/ppc/xen.lds.S | 4 ++ xen/arch/riscv/xen.lds.S | 2 + xen/arch/x86/xen.lds.S | 6 ++- xen/common/Makefile | 2 + xen/common/device.c | 82 +++++++++++++++++++++++++++++++++++++++ xen/include/xen/xen.lds.h | 22 +++++++++++ 8 files changed, 120 insertions(+), 83 deletions(-) create mode 100644 xen/common/device.c
Signature · 1 line
2.46.1
PATCH v5 1/6 xen: introduce DECL_SECTION_WITH_LADDR
Introduce DECL_SECTION_WITH_LADDR in order to signal whether DECL_SECTION() should specify a load address or not.
Update {ppc,x86}/xen.lds.S to use DECL_SECTION_WITH_LADDR.
---
Changes in V5:
- s/SIMPLE_DECL_SECTION/DECL_SECTION_WITH_LADDR.
- add space between # and define in x86/xen.lds.S.
- use DECL_SECTION_WITH_LADDR in ppc/xen.lds.S.
- update the commit message.
- add Acked-by: Jan Beulich <[email protected]>.
---
Changes in V4:
- new patch
--- xen/arch/ppc/xen.lds.S | 2 ++ xen/arch/x86/xen.lds.S | 6 ++++-- xen/include/xen/xen.lds.h | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-)
xen/arch/ppc/xen.lds.S +2 -0
@@ -1,4 +1,6 @@ #include <xen/lib.h> + +#define DECL_SECTION_WITH_LADDR #include <xen/xen.lds.h> OUTPUT_ARCH(powerpc:common64)
xen/arch/x86/xen.lds.S +4 -2
@@ -3,6 +3,10 @@ #include <xen/cache.h> #include <xen/lib.h> + +#ifndef EFI +# define DECL_SECTION_WITH_LADDR +#endif #include <xen/xen.lds.h> #include <asm/page.h> #undef ENTRY
@@ -12,9 +16,7 @@ #define FORMAT "pei-x86-64" #undef __XEN_VIRT_START -#undef DECL_SECTION #define __XEN_VIRT_START __image_base__ -#define DECL_SECTION(x) x : ENTRY(efi_start)
xen/include/xen/xen.lds.h +6 -0
@@ -5,6 +5,8 @@* Common macros to be used in architecture specific linker scripts. */ +#ifdef DECL_SECTION_WITH_LADDR +/* * Declare a section whose load address is based at PA 0 rather than * Xen's virtual base address.
@@ -15,6 +17,10 @@# define DECL_SECTION (x) x : AT(ADDR(x) - __XEN_VIRT_START)#endif +#else /* !DECL_SECTION_WITH_LADDR */ +#define DECL_SECTION (x) x : +#endif +/* * To avoid any confusion, please note that the EFI macro does not correspond * to EFI support and is used when linking a native EFI (i.e. PE/COFF) binary,
Signature · 1 line
2.46.1
Re: [PATCH v5 1/6] xen: introduce DECL_SECTION_WITH_LADDR
xen/arch/x86/xen.lds.S line 9
Quoted 10 lines · Oleksii Kurochko
xen/arch/x86/xen.lds.S +4
-0@@ -3,6 +3,10 @@ #include <xen/cache.h> #include <xen/lib.h> + +#ifndef EFI +# define DECL_SECTION_WITH_LADDR +#endif
I think either this wants inserting at the very top or it wants moving down together with ...
xen/arch/x86/xen.lds.S line 10
Quoted 1 line
xen/arch/x86/xen.lds.S +0
-0#include <xen/xen.lds.h>
... this line, past all the #includes (and, much you have it, separated by a blank line, just at both sides). Can adjust while committing of course.
Jan
Re: [PATCH v5 1/6] xen: introduce DECL_SECTION_WITH_LADDR
Quoted 16 lines · Jan Beulich
xen/arch/x86/xen.lds.S line 9
Quoted 10 lines · Oleksii Kurochko
xen/arch/x86/xen.lds.S +0
-0@@ -3,6 +3,10 @@
#include <xen/cache.h>
#include <xen/lib.h>xen/arch/x86/xen.lds.S +4
-0+ +#ifndef EFI +# define DECL_SECTION_WITH_LADDR +#endifI think either this wants inserting at the very top or it wants moving down
together with ...
Quoted 6 lines
Quoted 1 line
#include <
xen/xen.lds.h>... this line, past all the #includes (and, much you have it, separated by a
blank line, just at both sides). Can adjust while committing of course.
Personally, I prefer to move that down. It would be great if you could do that during committing.
Thanks a lot.
~ Oleksii
Re: [PATCH v5 1/6] xen: introduce DECL_SECTION_WITH_LADDR
In reply to Oleksii KurochkoHello Shawn,
Quoted 7 lines · Oleksii Kurochko
Introduce
DECL_SECTION_WITH_LADDRin order to signal whetherDECL_SECTION()should specify a load address or not.Update {
ppc,x86}/xen.lds.Sto useDECL_SECTION_WITH_LADDR.Signed-off-by Oleksii Kurochko <[email protected]>Acked-by Jan Beulich <[email protected]>
Could you please take a look at this patch as it requires your Ack?
Thanks in advance.
~ Oleksii
Quoted 78 lines
---
Changes in V5:
- s/SIMPLE_DECL_SECTION/DECL_SECTION_WITH_LADDR.
- add space between # and define inx86/xen.lds.S.
- useDECL_SECTION_WITH_LADDRinppc/xen.lds.S.
- update the commit message.
- add Acked-by: Jan Beulich <[email protected]>.
---
Changes in V4:
- new patch
---
xen/arch/ppc/xen.lds.S | 2 ++ xen/arch/x86/xen.lds.S | 6 ++++--xen/include/xen/xen.lds.h| 6 ++++++3 files changed, 12 insertions(+), 2 deletions(-)xen/arch/ppc/xen.lds.S +2
-0@@ -1,4 +1,6 @@ #include <xen/lib.h> + +#define DECL_SECTION_WITH_LADDR #include <xen/xen.lds.h>
OUTPUT_ARCH(powerpc:common64)xen/arch/x86/xen.lds.S +0
-0@@ -3,6 +3,10 @@
#include <xen/cache.h>
#include <xen/lib.h>xen/arch/x86/xen.lds.S +4
-0+ +#ifndef EFI +# define DECL_SECTION_WITH_LADDR +#endif#include <
xen/xen.lds.h>
#include <asm/page.h>
#undef ENTRYxen/arch/x86/xen.lds.S +0
-0@@ -12,9 +16,7 @@
#define FORMAT "pei-x86-64"
#undef__XEN_VIRT_START
-#undefDECL_SECTION
#define__XEN_VIRT_START__image_base__
-#defineDECL_SECTION(x)x :
ENTRY(efi_start)xen/include/xen/xen.lds.h +0
-0@@ -5,6 +5,8 @@* Common macros to be used in architecture specific linker scripts. */ xen/include/xen/xen.lds.h +2
-0+#ifdef DECL_SECTION_WITH_LADDR +/*
* Declare a section whose load address is based at PA 0 rather than
* Xen's virtual base address.xen/include/xen/xen.lds.h +0
-0@@ -15,6 +17,10 @@ # define DECL_SECTION(x) x : AT(ADDR(x) - __XEN_VIRT_START) #endifxen/include/xen/xen.lds.h +4
-0+#else /* !DECL_SECTION_WITH_LADDR */ +#define DECL_SECTION (x) x : +#endif +/*
* To avoid any confusion, please note that the EFI macro does not correspond
* to EFI support and is used when linking a native EFI (i.e. PE/COFF) binary,
PATCH v5 2/6 xen: define ACPI and DT device info sections macros
In reply to Oleksii KurochkoIntroduce macros to define device information sections based on the configuration of ACPI or device tree support. These sections are required for common code of device initialization and getting an information about a device.
These macros are expected to be used across different architectures (Arm, PPC, RISC-V), so they are moved to the common xen/xen.lds.h, based on their original definition in Arm.
---
Changes in V5:
- drop macros parameter for ACPI_DEV_INFO and DT_DEV_INFO.
- add Acked-by: Jan Beulich <[email protected]>
---
Changes in V4:
- rename ADEV_INFO to ACPI_DEV_INFO.
- refactor ADEV_INFO and DT_DEV_INFO: add alignment and DECL_SECTION.
---
Changes in V3:
- drop SEC* at the end of ACPI AND DT device info
section mancros.
- refactor ADEV_INFO and DT_DEV_INFO macros.
--- xen/include/xen/xen.lds.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
xen/include/xen/xen.lds.h +16 -0
@@ -120,6 +120,14 @@/* List of constructs other than *_SECTIONS in alphabetical order. */ +#define ACPI_DEV_INFO \ + . = ALIGN(POINTER_ALIGN); \ + DECL_SECTION(.adev.info) { \ + _asdevice = .; \ + *(.adev.info) \ + _aedevice = .; \ + } :text +#define BUGFRAMES \ __start_bug_frames_0 = .; \ *(.bug_frames.0) \
@@ -137,6 +145,14 @@ *(.bug_frames.3) \ __stop_bug_frames_3 = .; +#define DT_DEV_INFO \ + . = ALIGN(POINTER_ALIGN); \ + DECL_SECTION(.dev.info) { \ + _sdevice = .; \ + *(.dev.info) \ + _edevice = .; \ + } :text +#ifdef CONFIG_HYPFS #define HYPFS_PARAM \ . = ALIGN(POINTER_ALIGN); \
Signature · 1 line
2.46.1
PATCH v5 3/6 xen/arm: use {DT,ACPI}_DEV_INFO for device info sections
In reply to Oleksii KurochkoRefactor arm/xen.lds.S by replacing the inline definitions for device info sections with the newly introduced {DT,ACPI}_DEV_INFO macros from xen/xen.lds.h.
Change alignment of DT_DEV_INFO and ACPI_DEV_INFO sections from 8 to POINTER_ALIGN as struct acpi_device_desc and struct device_desc don't have any uint64_t's so it is safe to do that.
---
Changes in V5:
- add Reviewed-by: Michal Orzel <[email protected]>.
- update the commit message ( add information about s/8/POINTER_ALIGN/ for Arm ).
- use newly refactored ACPI_DEV_INFO and DT_DEV_INFO ( drop macros argument )
---
Changes in V4:
- use newly refactored ACPI_DEV_INFO and DT_DEV_INFO
---
Changes in V3:
- use refactored ADEV_INFO and DT_DEV_INFO macros.
--- xen/arch/arm/xen.lds.S | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
xen/arch/arm/xen.lds.S +2 -12
@@ -124,20 +124,10 @@ SECTIONS _eplatform = .; } :text - . = ALIGN(8); - .dev.info : { - _sdevice = .; - *(.dev.info) - _edevice = .; - } :text + DT_DEV_INFO #ifdef CONFIG_ACPI - . = ALIGN(8); - .adev.info : { - _asdevice = .; - *(.adev.info) - _aedevice = .; - } :text + ACPI_DEV_INFO #endif . = ALIGN(8);
Signature · 1 line
2.46.1
PATCH v5 4/6 xen/ppc: add section for device information in linker script
In reply to Oleksii KurochkoIntroduce a new .dev.info section in the PPC linker script to handle device-specific information. This section is required by common code (common/device.c: device_init(), device_get_class() ). This section is aligned to POINTER_ALIGN, with _sdevice and _edevice marking the start and end of the section, respectively.
---
Changes in V5:
- use newly refactored DT_DEV_INFO ( drop macros argument )
---
Changes in V4:
- use newly refactored DT_DEV_INFO
---
Changes in V3:
- use refactored DT_DEV_INFO macros.
- Add Acked-by: Shawn Anastasio <[email protected]>
--- xen/arch/ppc/xen.lds.S | 2 ++ 1 file changed, 2 insertions(+)
xen/arch/ppc/xen.lds.S +2 -0
@@ -96,6 +96,8 @@ SECTIONS CONSTRUCTORS } :text + DT_DEV_INFO /* Devicetree based device info */ + . = ALIGN(PAGE_SIZE); /* Init code and data */ __init_begin = .; DECL_SECTION(.init.text) {
Signature · 1 line
2.46.1
PATCH v5 5/6 xen/riscv: add section for device information in linker script
In reply to Oleksii KurochkoIntroduce a new .dev.info section in the RISC-V linker script to handle device-specific information. This section is required by common code (common/device.c: device_init(), device_get_class() ). This section is aligned to POINTER_ALIGN, with _sdevice and _edevice marking the start and end of the section, respectively.
---
Changes in V5:
- add Acked-by: Jan Beulich <[email protected]>
- use newly refactored DT_DEV_INFO ( drop macros argument )
---
Changes in V4:
- use newly refactored DT_DEV_INFO
---
Changes in V3:
- use refactored DT_DEV_INFO macros.
--- xen/arch/riscv/xen.lds.S | 2 ++ 1 file changed, 2 insertions(+)
xen/arch/riscv/xen.lds.S +2 -0
@@ -91,6 +91,8 @@ SECTIONS CONSTRUCTORS } :text + DT_DEV_INFO /* Devicetree based device info */ + . = ALIGN(PAGE_SIZE); /* Init code and data */ __init_begin = .; .init.text : {
Signature · 1 line
2.46.1
PATCH v5 6/6 xen/common: move device initialization code to common code
In reply to Oleksii KurochkoRemove the device initialization code from xen/arch/arm/device.c and move it to the common code to avoid duplication and make it accessible for both ARM and other architectures.device_get_class(), device_init(), _sdevice[] and _edevice[] are wrapped by "#ifdef CONFIG_HAS_DEVICE_TREE" for the case if an arch doesn't support device tree.
Remove unnecessary inclusions of <asm/device.h> and <xen/init.h> from xen/arch/arm/device.c as no code in the file relies on these headers. Fix the inclusion order by moving <asm/setup.h> after <xen/*> headers to resolve a compilation error:
./include/public/xen.h:968:35: error: unknown type name 'uint64_t'
968 | __DEFINE_XEN_GUEST_HANDLE(uint64, uint64_t);
| ^~~~~~~~ ./include/public/arch-arm.h:191:21: note: in definition of macro '___DEFINE_XEN_GUEST_HANDLE'
191 | typedef union { type *p; uint64_aligned_t q; } \
| ^~~~
./include/public/xen.h:968:1: note: in expansion of macro '__DEFINE_XEN_GUEST_HANDLE' 968 | __DEFINE_XEN_GUEST_HANDLE(uint64, uint64_t);
because <asm/setup.h> includes <public/version.h>, which in turn includes "xen.h", which requires <xen/types.h> to be processed correctly.
Additionally, add <xen/device_tree.h> to device.c as functions from this header are used within the file.
---
Changes in V5:
- Reviewed-by: Michal Orzel <[email protected]>
---
Changes in V4:
- add Reviewed-by: Jan Beulich <[email protected]>
---
Changes in V3:
- drop DEVICE_INIT config.
- update the commit message.
--- xen/arch/arm/device.c | 71 ++----------------------------------- xen/common/Makefile | 2 ++ xen/common/device.c | 82 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 69 deletions(-) create mode 100644 xen/common/device.c
xen/arch/arm/device.c +2 -69
@@ -8,79 +8,12 @@* Copyright (C) 2013 Linaro Limited. */ -#include <asm/device.h> -#include <asm/setup.h> +#include <xen/device_tree.h> #include <xen/errno.h> -#include <xen/init.h> #include <xen/iocap.h> #include <xen/lib.h> -extern const struct device_desc _sdevice[], _edevice[]; - -#ifdef CONFIG_ACPI -extern const struct acpi_device_desc _asdevice[], _aedevice[]; -#endif - -int __init device_init (struct dt_device_node *dev,enum device_class class, -const void *data) -{ -const struct device_desc *desc; - -ASSERT (dev !=NULL ); - -if ( !dt_device_is_available (dev) ||dt_device_for_passthrough (dev) ) -return -ENODEV ; - -for ( desc = _sdevice; desc != _edevice; desc++ ) - { -if ( desc->class != class ) -continue ; - -if (dt_match_node (desc->dt_match, dev) ) - { -ASSERT (desc->init !=NULL ); - -return desc->init (dev, data); - } - - } - -return -EBADF ; -} - -#ifdef CONFIG_ACPI -int __init acpi_device_init (enum device_class class,const void *data,int class_type) -{ -const struct acpi_device_desc *desc; - -for ( desc = _asdevice; desc != _aedevice; desc++ ) - { -if ( ( desc->class != class ) || ( desc->class_type != class_type ) ) -continue ; - -ASSERT (desc->init !=NULL ); - -return desc->init (data); - } - -return -EBADF ; -} -#endif - -enum device_class device_get_class (const struct dt_device_node *dev) -{ -const struct device_desc *desc; - -ASSERT (dev !=NULL ); - -for ( desc = _sdevice; desc != _edevice; desc++ ) - { -if (dt_match_node (desc->dt_match, dev) ) -return desc->class; - } - -return DEVICE_UNKNOWN ; -} +#include <asm/setup.h> int map_irq_to_domain (struct domain *d,unsigned int irq,bool need_mapping,const char *devname)
xen/common/Makefile +2 -0
@@ -6,6 +6,8 @@ obj-$(CONFIG_HYPFS_CONFIG) += config_data.o obj-$(CONFIG_CORE_PARKING) += core_parking.o obj-y += cpu.o obj-$(CONFIG_DEBUG_TRACE) += debugtrace.o +obj-$(CONFIG_HAS_DEVICE_TREE) += device.o +obj-$(filter-out $(CONFIG_X86),$(CONFIG_ACPI)) += device.o obj-$(CONFIG_HAS_DEVICE_TREE) += device-tree/ obj-$(CONFIG_IOREQ_SERVER) += dm.o obj-y += domain.o
xen/common/device.c new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
2.46.1
Hello everyone,
Except the comments ( which Jan wrote could be adjusted while committing ) for patch 1 everything is properly Acked/Reviewed ( if I am not missing something ).
I also checked if the patch series rebase/apply on top of current staging and I hadn't any issue.
Could someone please tell me what should be my next steps? Should I resend this patch series in case I miss something?
Thanks.
~ Oleksii
Quoted 61 lines · Oleksii Kurochko
The {acpi_}device_init() and
device_get_class()functions are identical across
Arm and RISC-V, and they are likely to remain the same for other architectures
like PPC.
Since there is no architecture-specific logic within these functions, they are
good candidates to be moved to the common codebase.This patch series refactors the code by moving these functions to the common
directory, reducing code duplication and simplifying future maintenance.---
Changes in V5:
- RenameSIMPLE_DECL_SECTIONtoDECL_SECTION_WITH_LADDRand update the other
patches correspondingly.
- Drop macros argument forACPI_DEV_INFOandDT_DEV_INFO.
---
Changes in V4:
- IntroduceSIMPLE_DECL_SECTIONto cover the cases when an architecture wants
to use section declaration without specifying an load address.
- Refactor macorsACPI_DEV_INFOandDT_DEV_INFOand update their defintion.
---
Changes in V3:
- drop_SECTIONSfrom the name of the macrosADEV_INFOandDT_DEV_INFO
- update the definion of macrosADEV_INFOandDT_DEV_INFO
- dropDEVICE_INITconfig.
---
Changes in v2:
- Introduce macros for definition of ACPI and Device Tree sections.
- IntroduceCONFIG_DEVICE_INITto makecommon/device.ocompilable only for Arm,
PPC and RISC-V.
---Oleksii Kurochko (6):
xen: introduceDECL_SECTION_WITH_LADDR
xen: define ACPI and DT device info sections macros xen/arm: use {DT,ACPI}_DEV_INFO for device info sections xen/ppc: add section for device information in linker script xen/riscv: add section for device information in linker script xen/common: move device initialization code to common codexen/arch/arm/device.c | 71 +-------------------------------- xen/arch/arm/xen.lds.S | 14 +------ xen/arch/ppc/xen.lds.S | 4 ++ xen/arch/riscv/xen.lds.S | 2 + xen/arch/x86/xen.lds.S | 6 ++-
xen/common/Makefile | 2 +
xen/common/device.c | 82
+++++++++++++++++++++++++++++++++++++++
xen/include/xen/xen.lds.h | 22 +++++++++++8 files changed, 120 insertions(+), 83 deletions(-)create mode 100644
xen/common/device.c
Quoted 3 lines · On 08.10.2024 17:25, [email protected] wrote:
Except the comments ( which Jan wrote could be adjusted while committing ) for patch 1 everything is properly Acked/Reviewed ( if I am not missing something ).
I didn't spot a PPC ack so far; did I miss it?
Jan
Quoted 7 lines · Jan Beulich
Quoted 4 lines · On 08.10.2024 17:25, [email protected] wrote:
Except the comments ( which Jan wrote could be adjusted while committing ) for patch 1 everything is properly Acked/Reviewed ( if I
am not missing something ).I didn't spot a PPC ack so far; did I miss it?
Yeah, you are right I confused ( I thought that he gave his Ack before and I just forgot to add it ) with another one patch where Shawn gave his Ack. I will ask Shawn to look at patch 1.
~ Oleksii