mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
xen/dt: Move bootfdt functions to xen/bootfdt.h
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 <alejandro.garciavallejo@amd.com> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> Reviewed-by: Oleksii Kurochko<oleksii.kurochko@gmail.com> # riscv
This commit is contained in:
1 parent
87e0ea6155
commit
f52ff91ebd
8 files changed
+108
-90
No files matched your search
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <xen/bitmap.h>
|
||||
#include <xen/bootfdt.h>
|
||||
#include <xen/ctype.h>
|
||||
#include <xen/device_tree.h>
|
||||
#include <xen/errno.h>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <xen/bootfdt.h>
|
||||
#include <xen/cpumask.h>
|
||||
#include <xen/device_tree.h>
|
||||
#include <xen/errno.h>
|
||||
|
||||
@@ -215,18 +215,6 @@ u32 __init device_tree_get_u32(const void *fdt, int node,
|
||||
return fdt32_to_cpu(get_unaligned_t(uint32_t, prop->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 __init device_tree_for_each_node(const void *fdt, int node,
|
||||
device_tree_node_func func,
|
||||
void *data)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <xen/bitops.h>
|
||||
#include <xen/bootfdt.h>
|
||||
#include <xen/types.h>
|
||||
#include <xen/init.h>
|
||||
#include <xen/guest_access.h>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
|
||||
#include <xen/bootfdt.h>
|
||||
#include <xen/event.h>
|
||||
#include <xen/static-evtchn.h>
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
* Copyright (C) 2022 Arm Ltd.
|
||||
*/
|
||||
|
||||
#include <xen/bootfdt.h>
|
||||
#include <xen/acpi.h>
|
||||
#include <xen/sched.h>
|
||||
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
#ifndef XEN_BOOTFDT_H
|
||||
#define XEN_BOOTFDT_H
|
||||
|
||||
#include <xen/byteorder.h>
|
||||
#include <xen/bug.h>
|
||||
#include <xen/types.h>
|
||||
#include <xen/kernel.h>
|
||||
#include <xen/lib.h>
|
||||
#include <xen/macros.h>
|
||||
#include <xen/xmalloc.h>
|
||||
|
||||
@@ -16,8 +19,92 @@
|
||||
#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 = be32_to_cpu(*cell);
|
||||
|
||||
switch ( size )
|
||||
{
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
r = (r << 32) | be32_to_cpu(cell[1]);
|
||||
break;
|
||||
default:
|
||||
/* Nonsensical size. default to 1 */
|
||||
printk(XENLOG_ERR "dt_read_number(,%d) bad size\n", size);
|
||||
ASSERT_UNREACHABLE();
|
||||
break;
|
||||
};
|
||||
|
||||
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)
|
||||
{
|
||||
uint64_t dt_r;
|
||||
paddr_t r;
|
||||
|
||||
/*
|
||||
* dt_read_number will return uint64_t whereas paddr_t may not be 64-bit.
|
||||
* Thus, there is an implicit cast from uint64_t to paddr_t.
|
||||
*/
|
||||
dt_r = dt_read_number(cell, size);
|
||||
|
||||
if ( dt_r != (paddr_t)dt_r )
|
||||
{
|
||||
printk("Physical address greater than max width supported\n");
|
||||
WARN();
|
||||
}
|
||||
|
||||
/*
|
||||
* Xen will truncate the address/size if it is greater than the maximum
|
||||
* supported width and it will give an appropriate warning.
|
||||
*/
|
||||
r = dt_r;
|
||||
|
||||
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,
|
||||
@@ -261,4 +348,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`.
|
||||
*/
|
||||
u32 device_tree_get_u32(const void *fdt, int node,
|
||||
const char *prop_name, u32 dflt);
|
||||
|
||||
/*
|
||||
* 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 */
|
||||
@@ -22,8 +22,6 @@
|
||||
#include <xen/list.h>
|
||||
#include <xen/rwlock.h>
|
||||
|
||||
#define DEVICE_TREE_MAX_DEPTH 16
|
||||
|
||||
/*
|
||||
* Struct used for matching a device
|
||||
*/
|
||||
@@ -164,17 +162,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 +234,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,55 +243,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 = be32_to_cpu(*cell);
|
||||
|
||||
switch ( size )
|
||||
{
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
r = (r << 32) | be32_to_cpu(cell[1]);
|
||||
break;
|
||||
default:
|
||||
/* Nonsensical size. default to 1 */
|
||||
printk(XENLOG_ERR "dt_read_number(,%d) bad size\n", size);
|
||||
ASSERT_UNREACHABLE();
|
||||
break;
|
||||
};
|
||||
|
||||
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)
|
||||
{
|
||||
uint64_t dt_r;
|
||||
paddr_t r;
|
||||
|
||||
/*
|
||||
* dt_read_number will return uint64_t whereas paddr_t may not be 64-bit.
|
||||
* Thus, there is an implicit cast from uint64_t to paddr_t.
|
||||
*/
|
||||
dt_r = dt_read_number(cell, size);
|
||||
|
||||
if ( dt_r != (paddr_t)dt_r )
|
||||
{
|
||||
printk("Physical address greater than max width supported\n");
|
||||
WARN();
|
||||
}
|
||||
|
||||
/*
|
||||
* Xen will truncate the address/size if it is greater than the maximum
|
||||
* supported width and it will give an appropriate warning.
|
||||
*/
|
||||
r = dt_r;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Helper to convert a number of cells to bytes */
|
||||
static inline int dt_cells_to_size(int size)
|
||||
{
|
||||
@@ -319,14 +255,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>";
|
||||
@@ -984,12 +912,6 @@ int dt_map_id(const struct dt_device_node *np, uint32_t id,
|
||||
|
||||
struct dt_device_node *dt_find_node_by_phandle(dt_phandle handle);
|
||||
|
||||
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);
|
||||
|
||||
#ifdef CONFIG_DEVICE_TREE_DEBUG
|
||||
#define dt_dprintk(fmt, args...) \
|
||||
printk(XENLOG_DEBUG fmt, ## args)
|
||||
|
||||