From: Alejandro Vallejo <agarciav@amd.com>
To: <dmkhn@proton.me>
Cc: <xen-devel@lists.xenproject.org>,
Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>,
Bertrand Marquis <bertrand.marquis@arm.com>,
Michal Orzel <michal.orzel@amd.com>,
"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>,
"Daniel P. Smith" <dpsmith@apertussolutions.com>
Subject: Re: [PATCH 12/19] xen/dt: Move bootfdt functions to xen/bootfdt.h
Date: Mon, 2 Jun 2025 18:41:32 +0200 [thread overview]
Message-ID: <DAC73PSZ4FBD.1U1EU3M2SWY3R@amd.com> (raw)
In-Reply-To: <aDpO1vpKUqWSyBt1@kraken>
On Sat May 31, 2025 at 2:35 AM CEST, dmkhn wrote:
> On Fri, May 30, 2025 at 02:02:20PM +0200, Alejandro Vallejo wrote:
>> Part of an unpicking process to extract bootfdt contents independent of bootinfo
>> to a separate file for x86 to take.
>>
>> Move functions required for early FDT parsing from device_tree.h and arm's
>> setup.h onto bootfdt.h
>>
>> Declaration motion only. Not a functional change.
>>
>> Signed-off-by: Alejandro Vallejo <agarciav@amd.com>
>> ---
>> xen/arch/arm/include/asm/setup.h | 6 ----
>> xen/include/xen/bootfdt.h | 62 ++++++++++++++++++++++++++++++++
>> xen/include/xen/device_tree.h | 34 +-----------------
>> 3 files changed, 63 insertions(+), 39 deletions(-)
>>
>> diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h
>> index 0f9e531a34..32308837a9 100644
>> --- a/xen/arch/arm/include/asm/setup.h
>> +++ b/xen/arch/arm/include/asm/setup.h
>> @@ -55,12 +55,6 @@ void setup_mm(void);
>> extern uint32_t hyp_traps_vector[];
>> void init_traps(void);
>>
>> -void device_tree_get_reg(const __be32 **cell, uint32_t address_cells,
>> - uint32_t size_cells, paddr_t *start, paddr_t *size);
>> -
>> -u32 device_tree_get_u32(const void *fdt, int node,
>> - const char *prop_name, u32 dflt);
>> -
>> int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt,
>> struct rangeset *iomem_ranges, struct rangeset *irq_ranges);
>>
>> diff --git a/xen/include/xen/bootfdt.h b/xen/include/xen/bootfdt.h
>> index fa65e8fcf4..079259c719 100644
>> --- a/xen/include/xen/bootfdt.h
>> +++ b/xen/include/xen/bootfdt.h
>> @@ -2,6 +2,7 @@
>> #ifndef XEN_BOOTFDT_H
>> #define XEN_BOOTFDT_H
>>
>> +#include <xen/byteorder.h>
>> #include <xen/types.h>
>> #include <xen/kernel.h>
>> #include <xen/macros.h>
>> @@ -16,8 +17,53 @@
>> #define NR_MEM_BANKS 256
>> #define NR_SHMEM_BANKS 32
>>
>> +/* Default #address and #size cells */
>> +#define DT_ROOT_NODE_ADDR_CELLS_DEFAULT 2
>> +#define DT_ROOT_NODE_SIZE_CELLS_DEFAULT 1
>> +
>> #define MAX_MODULES 32 /* Current maximum useful modules */
>>
>> +#define DEVICE_TREE_MAX_DEPTH 16
>> +
>> +/* Helper to read a big number; size is in cells (not bytes) */
>> +static inline u64 dt_read_number(const __be32 *cell, int size)
>> +{
>> + u64 r = 0;
>> +
>> + while ( size-- )
>> + r = (r << 32) | be32_to_cpu(*(cell++));
>> + return r;
>> +}
>> +
>> +static inline u64 dt_next_cell(int s, const __be32 **cellp)
>> +{
>> + const __be32 *p = *cellp;
>> +
>> + *cellp = p + s;
>> + return dt_read_number(p, s);
>> +}
>> +
>> +typedef int (*device_tree_node_func)(const void *fdt,
>> + int node, const char *name, int depth,
>> + u32 address_cells, u32 size_cells,
>> + void *data);
>> +
>> +/**
>> + * device_tree_for_each_node - iterate over all device tree sub-nodes
>> + * @fdt: flat device tree.
>> + * @node: parent node to start the search from
>> + * @func: function to call for each sub-node.
>> + * @data: data to pass to @func.
>> + *
>> + * Any nodes nested at DEVICE_TREE_MAX_DEPTH or deeper are ignored.
>> + *
>> + * Returns 0 if all nodes were iterated over successfully. If @func
>> + * returns a value different from 0, that value is returned immediately.
>> + */
>> +int device_tree_for_each_node(const void *fdt, int node,
>> + device_tree_node_func func,
>> + void *data);
>> +
>> typedef enum {
>> BOOTMOD_XEN,
>> BOOTMOD_FDT,
>> @@ -246,4 +292,20 @@ static inline struct membanks *membanks_xzalloc(unsigned int nr,
>> return banks;
>> }
>>
>> +/*
>> + * Interpret the property `prop_name` of `node` as a u32.
>> + *
>> + * Returns the property value on success; otherwise returns `dflt`.
>> + */
>> +uint32_t device_tree_get_u32(const void *fdt, int node,
>> + const char *prop_name, uint32_t dflt);
>
> Suggest using `dt_` prefix (or any other good prefix) for all functions
> in this header for consistency: e.g. there's dt_read_number() but also
> device_tree_get_u32().
I'd be quite happy with an fdt_ prefix, to clearly show they relate to FDTs.
But I didn't want to do that right away because it would obscure the strict code
motion that's going on.
>
>> +
>> +/*
>> + * Interpret the property `prop_name` of `node` as a "reg".
>> + *
>> + * Returns outputs in `start` and `size`.
>> + */
>> +void device_tree_get_reg(const __be32 **cell, uint32_t address_cells,
>> + uint32_t size_cells, paddr_t *start, paddr_t *size);
>> +
>> #endif /* XEN_BOOTFDT_H */
>> diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h
>> index 6dc1fb5159..0a22b1ba1d 100644
>> --- a/xen/include/xen/device_tree.h
>> +++ b/xen/include/xen/device_tree.h
>> @@ -10,6 +10,7 @@
>> #ifndef __XEN_DEVICE_TREE_H__
>> #define __XEN_DEVICE_TREE_H__
>>
>> +#include <xen/bootfdt.h>
>> #include <xen/byteorder.h>
>>
>> #include <asm/device.h>
>> @@ -22,8 +23,6 @@
>> #include <xen/list.h>
>> #include <xen/rwlock.h>
>>
>> -#define DEVICE_TREE_MAX_DEPTH 16
>> -
>> /*
>> * Struct used for matching a device
>> */
>> @@ -164,17 +163,8 @@ struct dt_raw_irq {
>> u32 specifier[DT_MAX_IRQ_SPEC];
>> };
>>
>> -typedef int (*device_tree_node_func)(const void *fdt,
>> - int node, const char *name, int depth,
>> - u32 address_cells, u32 size_cells,
>> - void *data);
>> -
>> extern const void *device_tree_flattened;
>>
>> -int device_tree_for_each_node(const void *fdt, int node,
>> - device_tree_node_func func,
>> - void *data);
>> -
>> /**
>> * dt_unflatten_host_device_tree - Unflatten the host device tree
>> *
>> @@ -245,10 +235,6 @@ void intc_dt_preinit(void);
>> #define dt_node_cmp(s1, s2) strcasecmp((s1), (s2))
>> #define dt_compat_cmp(s1, s2) strcasecmp((s1), (s2))
>>
>> -/* Default #address and #size cells */
>> -#define DT_ROOT_NODE_ADDR_CELLS_DEFAULT 2
>> -#define DT_ROOT_NODE_SIZE_CELLS_DEFAULT 1
>> -
>> #define dt_for_each_property_node(dn, pp) \
>> for ( pp = (dn)->properties; (pp) != NULL; pp = (pp)->next )
>>
>> @@ -258,16 +244,6 @@ void intc_dt_preinit(void);
>> #define dt_for_each_child_node(dt, dn) \
>> for ( dn = (dt)->child; (dn) != NULL; dn = (dn)->sibling )
>>
>> -/* Helper to read a big number; size is in cells (not bytes) */
>> -static inline u64 dt_read_number(const __be32 *cell, int size)
>> -{
>> - u64 r = 0;
>> -
>> - while ( size-- )
>> - r = (r << 32) | be32_to_cpu(*(cell++));
>> - return r;
>> -}
>> -
>> /* Wrapper for dt_read_number() to return paddr_t (instead of uint64_t) */
>> static inline paddr_t dt_read_paddr(const __be32 *cell, int size)
>> {
>> @@ -307,14 +283,6 @@ static inline int dt_size_to_cells(int bytes)
>> return (bytes / sizeof(u32));
>> }
>>
>> -static inline u64 dt_next_cell(int s, const __be32 **cellp)
>> -{
>> - const __be32 *p = *cellp;
>> -
>> - *cellp = p + s;
>> - return dt_read_number(p, s);
>> -}
>> -
>> static inline const char *dt_node_full_name(const struct dt_device_node *np)
>> {
>> return (np && np->full_name) ? np->full_name : "<no-node>";
>> --
>> 2.43.0
>>
>>
next prev parent reply other threads:[~2025-06-02 16:41 UTC|newest]
Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-21 14:35 Hyperlaunch/dom0less code sharing Alejandro Vallejo
2025-05-21 14:42 ` Jan Beulich
2025-05-21 21:07 ` Stefano Stabellini
2025-05-21 15:31 ` Daniel P. Smith
2025-05-21 17:32 ` Daniel P. Smith
2025-05-22 12:02 ` Alejandro Vallejo
2025-05-30 12:02 ` [PATCH 00/19] Allow x86 to unflatten DTs Alejandro Vallejo
2025-05-30 12:02 ` [PATCH 01/19] licence: Add missing SPDX line to bootfdt.h Alejandro Vallejo
2025-05-30 12:41 ` Orzel, Michal
2025-05-30 12:02 ` [PATCH 02/19] x86: Add missing pci_dev forward declaration in asm/pci.h Alejandro Vallejo
2025-05-30 21:04 ` Jason Andryuk
2025-06-02 13:45 ` Alejandro Vallejo
2025-06-02 16:40 ` Jason Andryuk
2025-05-31 0:42 ` Stefano Stabellini
2025-06-02 7:48 ` Jan Beulich
2025-06-02 14:01 ` Alejandro Vallejo
2025-06-02 14:19 ` Jan Beulich
2025-05-30 12:02 ` [PATCH 03/19] riscv: Add missing forward declaration to intc.h Alejandro Vallejo
2025-05-31 0:43 ` Stefano Stabellini
2025-05-30 12:02 ` [PATCH 04/19] xen: Add missing forward declaration to btcpupools_get_domain_pool_id Alejandro Vallejo
2025-05-31 0:46 ` Stefano Stabellini
2025-06-02 14:05 ` Alejandro Vallejo
2025-05-30 12:02 ` [PATCH 05/19] arm: Remove dependencies with membank(s) definitions from setup.h Alejandro Vallejo
2025-05-31 0:51 ` Stefano Stabellini
2025-06-02 14:07 ` Alejandro Vallejo
2025-06-05 13:28 ` Alejandro Vallejo
2025-05-30 12:02 ` [PATCH 06/19] xen: Clean up asm-generic/device.h Alejandro Vallejo
2025-05-31 0:55 ` Stefano Stabellini
2025-06-02 7:51 ` Jan Beulich
2025-06-02 14:19 ` Alejandro Vallejo
2025-06-02 14:24 ` Jan Beulich
2025-06-05 14:15 ` Alejandro Vallejo
2025-06-05 14:20 ` Jan Beulich
2025-06-05 16:48 ` Alejandro Vallejo
2025-06-06 6:24 ` Jan Beulich
2025-05-30 12:02 ` [PATCH 07/19] arm/gnttab: Break cycle between asm/grant_table.h and xen/grant_table.h Alejandro Vallejo
2025-05-30 21:04 ` Jason Andryuk
2025-05-31 0:57 ` Stefano Stabellini
2025-06-02 14:20 ` Alejandro Vallejo
2025-06-02 7:53 ` Jan Beulich
2025-06-02 14:30 ` Alejandro Vallejo
2025-06-02 14:51 ` Jan Beulich
2025-06-02 16:39 ` Alejandro Vallejo
2025-06-03 7:04 ` Jan Beulich
2025-06-05 17:22 ` Alejandro Vallejo
2025-05-30 12:02 ` [PATCH 08/19] xen/dt: Add BOOTMOD_MICROCODE Alejandro Vallejo
2025-05-31 0:59 ` Stefano Stabellini
2025-06-05 17:24 ` Alejandro Vallejo
2025-05-30 12:02 ` [PATCH 09/19] x86: Preinitialise all modules to be of kind BOOTMOD_UNKNOWN Alejandro Vallejo
2025-05-31 1:07 ` Stefano Stabellini
2025-06-02 7:55 ` Jan Beulich
2025-06-05 17:24 ` Alejandro Vallejo
2025-05-30 12:02 ` [PATCH 10/19] x86: Replace boot_module with bootmodule Alejandro Vallejo
2025-05-31 1:15 ` Stefano Stabellini
2025-06-02 16:31 ` Alejandro Vallejo
2025-06-02 17:00 ` Andrew Cooper
2025-06-05 17:28 ` Alejandro Vallejo
2025-06-05 17:40 ` Alejandro Vallejo
2025-06-06 6:56 ` Jan Beulich
2025-06-06 20:14 ` Stefano Stabellini
2025-05-30 12:02 ` [PATCH 11/19] x86: Replace boot_domain with kernel_info Alejandro Vallejo
2025-05-30 12:02 ` [PATCH 12/19] xen/dt: Move bootfdt functions to xen/bootfdt.h Alejandro Vallejo
2025-05-31 0:35 ` dmkhn
2025-06-02 7:29 ` Orzel, Michal
2025-06-03 0:38 ` dmkhn
2025-06-02 16:41 ` Alejandro Vallejo [this message]
2025-06-03 0:42 ` dmkhn
2025-05-31 1:31 ` Stefano Stabellini
2025-05-31 1:40 ` Stefano Stabellini
2025-06-02 20:25 ` Daniel P. Smith
2025-06-05 18:03 ` Alejandro Vallejo
2025-06-05 23:19 ` Stefano Stabellini
2025-06-17 1:32 ` Daniel P. Smith
2025-05-30 12:02 ` [PATCH 13/19] xen/dt: Move bootinfo functions to a new bootinfo.h Alejandro Vallejo
2025-05-31 1:42 ` Stefano Stabellini
2025-06-05 18:04 ` Alejandro Vallejo
2025-05-30 12:02 ` [PATCH 14/19] xen/dt: Rename bootfdt.c -> bootinfo-fdt.c Alejandro Vallejo
2025-05-31 1:44 ` Stefano Stabellini
2025-05-30 12:02 ` [PATCH 15/19] xen/dt: Move bootinfo-independent helpers out of bootinfo-fdt.c Alejandro Vallejo
2025-05-31 0:39 ` dmkhn
2025-06-05 18:11 ` Alejandro Vallejo
2025-05-31 1:47 ` Stefano Stabellini
2025-06-02 8:00 ` Jan Beulich
2025-05-30 12:02 ` [PATCH 16/19] xen/dt: Extract helper to map nodes to module kinds Alejandro Vallejo
2025-05-31 1:48 ` Stefano Stabellini
2025-05-30 12:02 ` [PATCH 17/19] xen/dt: ifdef out DEV_DT-related bits from device_tree.{c,h} Alejandro Vallejo
2025-05-30 12:02 ` [PATCH 18/19] xen/dt: Allow CONFIG_DOM0LESS_BOOT to include device-tree/ Alejandro Vallejo
2025-05-30 12:05 ` [PATCH 19/19] kconfig: Allow x86 to pick CONFIG_DOM0LESS_BOOT Alejandro Vallejo
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=DAC73PSZ4FBD.1U1EU3M2SWY3R@amd.com \
--to=agarciav@amd.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=bertrand.marquis@arm.com \
--cc=dmkhn@proton.me \
--cc=dpsmith@apertussolutions.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/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.