Skip to content

Commit

Permalink
From patchwork series 386645
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox Snowpatch committed Dec 14, 2023
1 parent 3c0fd43 commit 91ae724
Show file tree
Hide file tree
Showing 21 changed files with 81 additions and 90 deletions.
1 change: 1 addition & 0 deletions arch/powerpc/include/asm/machdep.h
Expand Up @@ -22,6 +22,7 @@ struct pci_host_bridge;
struct machdep_calls {
const char *name;
const char *compatible;
const char * const *compatibles;
#ifdef CONFIG_PPC64
#ifdef CONFIG_PM
void (*iommu_restore)(void);
Expand Down
8 changes: 6 additions & 2 deletions arch/powerpc/kernel/secure_boot.c
Expand Up @@ -32,8 +32,10 @@ bool is_ppc_secureboot_enabled(void)
if (enabled)
goto out;

if (!of_property_read_u32(of_root, "ibm,secure-boot", &secureboot))
node = of_find_node_by_path("/");
if (!of_property_read_u32(node, "ibm,secure-boot", &secureboot))
enabled = (secureboot > 1);
of_node_put(node);

out:
pr_info("Secure boot mode %s\n", enabled ? "enabled" : "disabled");
Expand All @@ -54,8 +56,10 @@ bool is_ppc_trustedboot_enabled(void)
if (enabled)
goto out;

if (!of_property_read_u32(of_root, "ibm,trusted-boot", &trustedboot))
node = of_find_node_by_path("/");
if (!of_property_read_u32(node, "ibm,trusted-boot", &trustedboot))
enabled = (trustedboot > 0);
of_node_put(node);

out:
pr_info("Trusted boot mode %s\n", enabled ? "enabled" : "disabled");
Expand Down
2 changes: 2 additions & 0 deletions arch/powerpc/kernel/setup-common.c
Expand Up @@ -616,6 +616,8 @@ static __init void probe_machine(void)
DBG(" %s ...\n", machine_id->name);
if (machine_id->compatible && !of_machine_is_compatible(machine_id->compatible))
continue;
if (machine_id->compatibles && !of_machine_compatible_match(machine_id->compatibles))
continue;
memcpy(&ppc_md, machine_id, sizeof(struct machdep_calls));
if (ppc_md.probe && !ppc_md.probe())
continue;
Expand Down
8 changes: 5 additions & 3 deletions arch/powerpc/kexec/ranges.c
Expand Up @@ -385,14 +385,16 @@ int add_opal_mem_range(struct crash_mem **mem_ranges)
int add_reserved_mem_ranges(struct crash_mem **mem_ranges)
{
int n_mem_addr_cells, n_mem_size_cells, i, len, cells, ret = 0;
struct device_node *root = of_find_node_by_path("/");
const __be32 *prop;

prop = of_get_property(of_root, "reserved-ranges", &len);
prop = of_get_property(root, "reserved-ranges", &len);
n_mem_addr_cells = of_n_addr_cells(root);
n_mem_size_cells = of_n_size_cells(root);
of_node_put(root);
if (!prop)
return 0;

n_mem_addr_cells = of_n_addr_cells(of_root);
n_mem_size_cells = of_n_size_cells(of_root);
cells = n_mem_addr_cells + n_mem_size_cells;

/* Each reserved range is an (address,size) pair */
Expand Down
10 changes: 5 additions & 5 deletions arch/powerpc/mm/drmem.c
Expand Up @@ -393,17 +393,17 @@ static const __be32 *of_get_usable_memory(struct device_node *dn)
int walk_drmem_lmbs(struct device_node *dn, void *data,
int (*func)(struct drmem_lmb *, const __be32 **, void *))
{
struct device_node *root = of_find_node_by_path("/");
const __be32 *prop, *usm;
int ret = -ENODEV;

if (!of_root)
if (!root)
return ret;

/* Get the address & size cells */
of_node_get(of_root);
n_root_addr_cells = of_n_addr_cells(of_root);
n_root_size_cells = of_n_size_cells(of_root);
of_node_put(of_root);
n_root_addr_cells = of_n_addr_cells(root);
n_root_size_cells = of_n_size_cells(root);
of_node_put(root);

if (init_drmem_lmb_size(dn))
return ret;
Expand Down
6 changes: 4 additions & 2 deletions arch/powerpc/mm/numa.c
Expand Up @@ -1111,7 +1111,7 @@ static void __init setup_node_data(int nid, u64 start_pfn, u64 end_pfn)

static void __init find_possible_nodes(void)
{
struct device_node *rtas;
struct device_node *rtas, *root;
const __be32 *domains = NULL;
int prop_length, max_nodes;
u32 i;
Expand All @@ -1132,10 +1132,12 @@ static void __init find_possible_nodes(void)
* If the LPAR is migratable, new nodes might be activated after a LPM,
* so we should consider the max number in that case.
*/
if (!of_get_property(of_root, "ibm,migratable-partition", NULL))
root = of_find_node_by_path("/");
if (!of_get_property(root, "ibm,migratable-partition", NULL))
domains = of_get_property(rtas,
"ibm,current-associativity-domains",
&prop_length);
of_node_put(root);
if (!domains) {
domains = of_get_property(rtas, "ibm,max-associativity-domains",
&prop_length);
Expand Down
9 changes: 3 additions & 6 deletions arch/powerpc/platforms/40x/ppc40x_simple.c
Expand Up @@ -59,16 +59,13 @@ static const char * const board[] __initconst = {

static int __init ppc40x_probe(void)
{
if (of_device_compatible_match(of_root, board)) {
pci_set_flags(PCI_REASSIGN_ALL_RSRC);
return 1;
}

return 0;
pci_set_flags(PCI_REASSIGN_ALL_RSRC);
return 1;
}

define_machine(ppc40x_simple) {
.name = "PowerPC 40x Platform",
.compatibles = board,
.probe = ppc40x_probe,
.progress = udbg_progress,
.init_IRQ = uic_init_tree,
Expand Down
4 changes: 1 addition & 3 deletions arch/powerpc/platforms/512x/mpc512x_generic.c
Expand Up @@ -32,16 +32,14 @@ static const char * const board[] __initconst = {
*/
static int __init mpc512x_generic_probe(void)
{
if (!of_device_compatible_match(of_root, board))
return 0;

mpc512x_init_early();

return 1;
}

define_machine(mpc512x_generic) {
.name = "MPC512x generic",
.compatibles = board,
.probe = mpc512x_generic_probe,
.init = mpc512x_init,
.setup_arch = mpc512x_setup_arch,
Expand Down
4 changes: 3 additions & 1 deletion arch/powerpc/platforms/52xx/efika.c
Expand Up @@ -195,8 +195,10 @@ static void __init efika_setup_arch(void)

static int __init efika_probe(void)
{
const char *model = of_get_property(of_root, "model", NULL);
struct device_node *root = of_find_node_by_path("/");
const char *model = of_get_property(root, "model", NULL);

of_node_put(root);
if (model == NULL)
return 0;
if (strcmp(model, "EFIKA5K2"))
Expand Down
10 changes: 1 addition & 9 deletions arch/powerpc/platforms/52xx/lite5200.c
Expand Up @@ -172,17 +172,9 @@ static const char * const board[] __initconst = {
NULL,
};

/*
* Called very early, MMU is off, device-tree isn't unflattened
*/
static int __init lite5200_probe(void)
{
return of_device_compatible_match(of_root, board);
}

define_machine(lite5200) {
.name = "lite5200",
.probe = lite5200_probe,
.compatibles = board,
.setup_arch = lite5200_setup_arch,
.discover_phbs = mpc52xx_setup_pci,
.init = mpc52xx_declare_of_platform_devices,
Expand Down
10 changes: 1 addition & 9 deletions arch/powerpc/platforms/52xx/mpc5200_simple.c
Expand Up @@ -59,17 +59,9 @@ static const char *board[] __initdata = {
NULL
};

/*
* Called very early, MMU is off, device-tree isn't unflattened
*/
static int __init mpc5200_simple_probe(void)
{
return of_device_compatible_match(of_root, board);
}

define_machine(mpc5200_simple_platform) {
.name = "mpc5200-simple-platform",
.probe = mpc5200_simple_probe,
.compatibles = board,
.setup_arch = mpc5200_simple_setup_arch,
.discover_phbs = mpc52xx_setup_pci,
.init = mpc52xx_declare_of_platform_devices,
Expand Down
10 changes: 1 addition & 9 deletions arch/powerpc/platforms/83xx/mpc830x_rdb.c
Expand Up @@ -34,19 +34,11 @@ static const char *board[] __initdata = {
NULL
};

/*
* Called very early, MMU is off, device-tree isn't unflattened
*/
static int __init mpc830x_rdb_probe(void)
{
return of_device_compatible_match(of_root, board);
}

machine_device_initcall(mpc830x_rdb, mpc83xx_declare_of_platform_devices);

define_machine(mpc830x_rdb) {
.name = "MPC830x RDB",
.probe = mpc830x_rdb_probe,
.compatibles = board,
.setup_arch = mpc830x_rdb_setup_arch,
.discover_phbs = mpc83xx_setup_pci,
.init_IRQ = mpc83xx_ipic_init_IRQ,
Expand Down
10 changes: 1 addition & 9 deletions arch/powerpc/platforms/83xx/mpc831x_rdb.c
Expand Up @@ -34,19 +34,11 @@ static const char *board[] __initdata = {
NULL
};

/*
* Called very early, MMU is off, device-tree isn't unflattened
*/
static int __init mpc831x_rdb_probe(void)
{
return of_device_compatible_match(of_root, board);
}

machine_device_initcall(mpc831x_rdb, mpc83xx_declare_of_platform_devices);

define_machine(mpc831x_rdb) {
.name = "MPC831x RDB",
.probe = mpc831x_rdb_probe,
.compatibles = board,
.setup_arch = mpc831x_rdb_setup_arch,
.discover_phbs = mpc83xx_setup_pci,
.init_IRQ = mpc83xx_ipic_init_IRQ,
Expand Down
10 changes: 1 addition & 9 deletions arch/powerpc/platforms/83xx/mpc837x_rdb.c
Expand Up @@ -61,17 +61,9 @@ static const char * const board[] __initconst = {
NULL
};

/*
* Called very early, MMU is off, device-tree isn't unflattened
*/
static int __init mpc837x_rdb_probe(void)
{
return of_device_compatible_match(of_root, board);
}

define_machine(mpc837x_rdb) {
.name = "MPC837x RDB/WLAN",
.probe = mpc837x_rdb_probe,
.compatibles = board,
.setup_arch = mpc837x_rdb_setup_arch,
.discover_phbs = mpc83xx_setup_pci,
.init_IRQ = mpc83xx_ipic_init_IRQ,
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/platforms/85xx/corenet_generic.c
Expand Up @@ -149,7 +149,7 @@ static int __init corenet_generic_probe(void)
extern struct smp_ops_t smp_85xx_ops;
#endif

if (of_device_compatible_match(of_root, boards))
if (of_machine_compatible_match(boards))
return 1;

/* Check if we're running under the Freescale hypervisor */
Expand Down
10 changes: 1 addition & 9 deletions arch/powerpc/platforms/85xx/tqm85xx.c
Expand Up @@ -112,17 +112,9 @@ static const char * const board[] __initconst = {
NULL
};

/*
* Called very early, device-tree isn't unflattened
*/
static int __init tqm85xx_probe(void)
{
return of_device_compatible_match(of_root, board);
}

define_machine(tqm85xx) {
.name = "TQM85xx",
.probe = tqm85xx_probe,
.compatibles = board,
.setup_arch = tqm85xx_setup_arch,
.init_IRQ = tqm85xx_pic_init,
.show_cpuinfo = tqm85xx_show_cpuinfo,
Expand Down
4 changes: 3 additions & 1 deletion arch/powerpc/platforms/pasemi/pci.c
Expand Up @@ -270,16 +270,18 @@ static int __init pas_add_bridge(struct device_node *dev)

void __init pas_pci_init(void)
{
struct device_node *root = of_find_node_by_path("/");
struct device_node *np;
int res;

pci_set_flags(PCI_SCAN_ALL_PCIE_DEVS);

np = of_find_compatible_node(of_root, NULL, "pasemi,rootbus");
np = of_find_compatible_node(root, NULL, "pasemi,rootbus");
if (np) {
res = pas_add_bridge(np);
of_node_put(np);
}
of_node_put(root);
}

void __iomem *__init pasemi_pci_getcfgaddr(struct pci_dev *dev, int offset)
Expand Down
6 changes: 5 additions & 1 deletion arch/powerpc/platforms/pseries/lparcfg.c
Expand Up @@ -346,9 +346,13 @@ static int read_rtas_lpar_name(struct seq_file *m)
*/
static int read_dt_lpar_name(struct seq_file *m)
{
struct device_node *root = of_find_node_by_path("/");
const char *name;
int ret;

if (of_property_read_string(of_root, "ibm,partition-name", &name))
ret = of_property_read_string(root, "ibm,partition-name", &name);
of_node_put(root);
if (ret)
return -ENOENT;

seq_printf(m, "partition_name=%s\n", name);
Expand Down
12 changes: 9 additions & 3 deletions arch/powerpc/platforms/pseries/setup.c
Expand Up @@ -1029,9 +1029,11 @@ static void __init pseries_add_hw_description(void)
return;
}

if (of_property_read_bool(of_root, "ibm,powervm-partition") ||
of_property_read_bool(of_root, "ibm,fw-net-version"))
dn = of_find_node_by_path("/");
if (of_property_read_bool(dn, "ibm,powervm-partition") ||
of_property_read_bool(dn, "ibm,fw-net-version"))
seq_buf_printf(&ppc_hw_desc, "hv:phyp ");
of_node_put(dn);
}

/*
Expand Down Expand Up @@ -1091,7 +1093,11 @@ static void pseries_power_off(void)

static int __init pSeries_probe(void)
{
if (!of_node_is_type(of_root, "chrp"))
struct device_node *root = of_find_node_by_path("/");
bool ret = of_node_is_type(root, "chrp");

of_node_put(root);
if (!ret)
return 0;

/* Cell blades firmware claims to be chrp while it's not. Until this
Expand Down
15 changes: 8 additions & 7 deletions drivers/of/base.c
Expand Up @@ -395,25 +395,26 @@ int of_device_compatible_match(const struct device_node *device,
EXPORT_SYMBOL_GPL(of_device_compatible_match);

/**
* of_machine_is_compatible - Test root of device tree for a given compatible value
* @compat: compatible string to look for in root node's compatible property.
* of_machine_compatible_match - Test root of device tree against a compatible array
* @compats: NULL terminated array of compatible strings to look for in root node's compatible property.
*
* Return: A positive integer if the root node has the given value in its
* Returns true if the root node has any of the given compatible values in its
* compatible property.
*/
int of_machine_is_compatible(const char *compat)
bool of_machine_compatible_match(const char *const *compats)
{
struct device_node *root;
int rc = 0;

root = of_find_node_by_path("/");
if (root) {
rc = of_device_is_compatible(root, compat);
rc = of_device_compatible_match(root, compats);
of_node_put(root);
}
return rc;

return rc != 0;
}
EXPORT_SYMBOL(of_machine_is_compatible);
EXPORT_SYMBOL(of_machine_compatible_match);

/**
* __of_device_is_available - check if a device is available for use
Expand Down

0 comments on commit 91ae724

Please sign in to comment.