^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Procedures for creating, accessing and interpreting the device tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Paul Mackerras August 1996.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 1996-2005 Paul Mackerras.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * {engebret|bergner}@us.ibm.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Adapted for sparc64 by David S. Miller davem@davemloft.net
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/prom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/oplib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <asm/asi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <asm/upa.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <asm/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include "prom.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) void * __init prom_early_alloc(unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) void *ret = memblock_alloc(size, SMP_CACHE_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) prom_printf("prom_early_alloc(%lu) failed\n", size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) prom_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) prom_early_allocated += size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* The following routines deal with the black magic of fully naming a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * Certain well known named nodes are just the simple name string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * Actual devices have an address specifier appended to the base name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * string, like this "foo@addr". The "addr" can be in any number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * formats, and the platform plus the type of the node determine the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * format and how it is constructed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * For children of the ROOT node, the naming convention is fixed and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * determined by whether this is a sun4u or sun4v system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * For children of other nodes, it is bus type specific. So
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * we walk up the tree until we discover a "device_type" property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * we recognize and we go from there.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * As an example, the boot device on my workstation has a full path:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * /pci@1e,600000/ide@d/disk@0,0:c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static void __init sun4v_path_component(struct device_node *dp, char *tmp_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) const char *name = of_get_property(dp, "name", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct linux_prom64_registers *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct property *rprop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) u32 high_bits, low_bits, type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) rprop = of_find_property(dp, "reg", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (!rprop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) regs = rprop->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (!of_node_is_root(dp->parent)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) sprintf(tmp_buf, "%s@%x,%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) (unsigned int) (regs->phys_addr >> 32UL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) (unsigned int) (regs->phys_addr & 0xffffffffUL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) type = regs->phys_addr >> 60UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) high_bits = (regs->phys_addr >> 32UL) & 0x0fffffffUL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) low_bits = (regs->phys_addr & 0xffffffffUL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (type == 0 || type == 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) const char *prefix = (type == 0) ? "m" : "i";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (low_bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) sprintf(tmp_buf, "%s@%s%x,%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) name, prefix,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) high_bits, low_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) sprintf(tmp_buf, "%s@%s%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) prefix,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) high_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) } else if (type == 12) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) sprintf(tmp_buf, "%s@%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) name, high_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static void __init sun4u_path_component(struct device_node *dp, char *tmp_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) const char *name = of_get_property(dp, "name", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct linux_prom64_registers *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct property *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) prop = of_find_property(dp, "reg", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (!prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) regs = prop->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (!of_node_is_root(dp->parent)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) sprintf(tmp_buf, "%s@%x,%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) (unsigned int) (regs->phys_addr >> 32UL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) (unsigned int) (regs->phys_addr & 0xffffffffUL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) prop = of_find_property(dp, "upa-portid", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (!prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) prop = of_find_property(dp, "portid", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (prop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) unsigned long mask = 0xffffffffUL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (tlb_type >= cheetah)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) mask = 0x7fffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) sprintf(tmp_buf, "%s@%x,%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) *(u32 *)prop->value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) (unsigned int) (regs->phys_addr & mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /* "name@slot,offset" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static void __init sbus_path_component(struct device_node *dp, char *tmp_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) const char *name = of_get_property(dp, "name", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct linux_prom_registers *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct property *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) prop = of_find_property(dp, "reg", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (!prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) regs = prop->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) sprintf(tmp_buf, "%s@%x,%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) regs->which_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) regs->phys_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /* "name@devnum[,func]" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static void __init pci_path_component(struct device_node *dp, char *tmp_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) const char *name = of_get_property(dp, "name", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct linux_prom_pci_registers *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct property *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) unsigned int devfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) prop = of_find_property(dp, "reg", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (!prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) regs = prop->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) devfn = (regs->phys_hi >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (devfn & 0x07) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) sprintf(tmp_buf, "%s@%x,%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) devfn >> 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) devfn & 0x07);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) sprintf(tmp_buf, "%s@%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) devfn >> 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /* "name@UPA_PORTID,offset" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static void __init upa_path_component(struct device_node *dp, char *tmp_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) const char *name = of_get_property(dp, "name", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct linux_prom64_registers *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct property *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) prop = of_find_property(dp, "reg", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (!prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) regs = prop->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) prop = of_find_property(dp, "upa-portid", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (!prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) sprintf(tmp_buf, "%s@%x,%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) *(u32 *) prop->value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) (unsigned int) (regs->phys_addr & 0xffffffffUL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /* "name@reg" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static void __init vdev_path_component(struct device_node *dp, char *tmp_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) const char *name = of_get_property(dp, "name", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct property *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) u32 *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) prop = of_find_property(dp, "reg", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (!prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) regs = prop->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) sprintf(tmp_buf, "%s@%x", name, *regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /* "name@addrhi,addrlo" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static void __init ebus_path_component(struct device_node *dp, char *tmp_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) const char *name = of_get_property(dp, "name", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct linux_prom64_registers *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct property *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) prop = of_find_property(dp, "reg", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (!prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) regs = prop->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) sprintf(tmp_buf, "%s@%x,%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) (unsigned int) (regs->phys_addr >> 32UL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) (unsigned int) (regs->phys_addr & 0xffffffffUL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /* "name@bus,addr" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static void __init i2c_path_component(struct device_node *dp, char *tmp_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) const char *name = of_get_property(dp, "name", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct property *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) u32 *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) prop = of_find_property(dp, "reg", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (!prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) regs = prop->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /* This actually isn't right... should look at the #address-cells
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * property of the i2c bus node etc. etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) sprintf(tmp_buf, "%s@%x,%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) name, regs[0], regs[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) /* "name@reg0[,reg1]" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static void __init usb_path_component(struct device_node *dp, char *tmp_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) const char *name = of_get_property(dp, "name", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) struct property *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) u32 *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) prop = of_find_property(dp, "reg", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (!prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) regs = prop->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (prop->length == sizeof(u32) || regs[1] == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) sprintf(tmp_buf, "%s@%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) name, regs[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) sprintf(tmp_buf, "%s@%x,%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) name, regs[0], regs[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) /* "name@reg0reg1[,reg2reg3]" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static void __init ieee1394_path_component(struct device_node *dp, char *tmp_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) const char *name = of_get_property(dp, "name", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) struct property *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) u32 *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) prop = of_find_property(dp, "reg", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (!prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) regs = prop->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (regs[2] || regs[3]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) sprintf(tmp_buf, "%s@%08x%08x,%04x%08x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) name, regs[0], regs[1], regs[2], regs[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) sprintf(tmp_buf, "%s@%08x%08x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) name, regs[0], regs[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static void __init __build_path_component(struct device_node *dp, char *tmp_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct device_node *parent = dp->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (parent != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) if (of_node_is_type(parent, "pci") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) of_node_is_type(parent, "pciex")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) pci_path_component(dp, tmp_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (of_node_is_type(parent, "sbus")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) sbus_path_component(dp, tmp_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (of_node_is_type(parent, "upa")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) upa_path_component(dp, tmp_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (of_node_is_type(parent, "ebus")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) ebus_path_component(dp, tmp_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (of_node_name_eq(parent, "usb") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) of_node_name_eq(parent, "hub")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) usb_path_component(dp, tmp_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (of_node_is_type(parent, "i2c")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) i2c_path_component(dp, tmp_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (of_node_is_type(parent, "firewire")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) ieee1394_path_component(dp, tmp_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (of_node_is_type(parent, "virtual-devices")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) vdev_path_component(dp, tmp_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) /* "isa" is handled with platform naming */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /* Use platform naming convention. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (tlb_type == hypervisor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) sun4v_path_component(dp, tmp_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) sun4u_path_component(dp, tmp_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) char * __init build_path_component(struct device_node *dp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) const char *name = of_get_property(dp, "name", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) char tmp_buf[64], *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) tmp_buf[0] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) __build_path_component(dp, tmp_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (tmp_buf[0] == '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) strcpy(tmp_buf, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) n = prom_early_alloc(strlen(tmp_buf) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) strcpy(n, tmp_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) static const char *get_mid_prop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) return (tlb_type == spitfire ? "upa-portid" : "portid");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) bool arch_find_n_match_cpu_physical_id(struct device_node *cpun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) int cpu, unsigned int *thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) const char *mid_prop = get_mid_prop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) int this_cpu_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) /* On hypervisor based platforms we interrogate the 'reg'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) * property. On everything else we look for a 'upa-portid',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) * 'portid', or 'cpuid' property.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (tlb_type == hypervisor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) struct property *prop = of_find_property(cpun, "reg", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) u32 *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (!prop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) pr_warn("CPU node missing reg property\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) regs = prop->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) this_cpu_id = regs[0] & 0x0fffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) this_cpu_id = of_getintprop_default(cpun, mid_prop, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (this_cpu_id < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) mid_prop = "cpuid";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) this_cpu_id = of_getintprop_default(cpun, mid_prop, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (this_cpu_id < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) pr_warn("CPU node missing cpu ID property\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (this_cpu_id == cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) if (thread) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) int proc_id = cpu_data(cpu).proc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) /* On sparc64, the cpu thread information is obtained
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) * either from OBP or the machine description. We've
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) * actually probed this information already long before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) * this interface gets called so instead of interrogating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) * both the OF node and the MDESC again, just use what
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) * we discovered already.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (proc_id < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) proc_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) *thread = proc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) static void *of_iterate_over_cpus(void *(*func)(struct device_node *, int, int), int arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) struct device_node *dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) const char *mid_prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) mid_prop = get_mid_prop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) for_each_node_by_type(dp, "cpu") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) int cpuid = of_getintprop_default(dp, mid_prop, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) const char *this_mid_prop = mid_prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) void *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (cpuid < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) this_mid_prop = "cpuid";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) cpuid = of_getintprop_default(dp, this_mid_prop, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) if (cpuid < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) prom_printf("OF: Serious problem, cpu lacks "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) "%s property", this_mid_prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) prom_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if (cpuid >= NR_CPUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) printk(KERN_WARNING "Ignoring CPU %d which is "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) ">= NR_CPUS (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) cpuid, NR_CPUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) ret = func(dp, cpuid, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static void *check_cpu_node(struct device_node *dp, int cpuid, int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) if (id == cpuid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) return dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct device_node *of_find_node_by_cpuid(int cpuid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return of_iterate_over_cpus(check_cpu_node, cpuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) static void *record_one_cpu(struct device_node *dp, int cpuid, int arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) ncpus_probed++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) set_cpu_present(cpuid, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) set_cpu_possible(cpuid, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) void __init of_populate_present_mask(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) if (tlb_type == hypervisor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) ncpus_probed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) of_iterate_over_cpus(record_one_cpu, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) static void *fill_in_one_cpu(struct device_node *dp, int cpuid, int arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) struct device_node *portid_parent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) int portid = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) if (of_find_property(dp, "cpuid", NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) int limit = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) portid_parent = dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) while (limit--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) portid_parent = portid_parent->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) if (!portid_parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) portid = of_getintprop_default(portid_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) "portid", -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) if (portid >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) #ifndef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) /* On uniprocessor we only want the values for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) * real physical cpu the kernel booted onto, however
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) * cpu_data() only has one entry at index 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) if (cpuid != real_hard_smp_processor_id())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) cpuid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) cpu_data(cpuid).clock_tick =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) of_getintprop_default(dp, "clock-frequency", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) if (portid_parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) cpu_data(cpuid).dcache_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) of_getintprop_default(dp, "l1-dcache-size",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 16 * 1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) cpu_data(cpuid).dcache_line_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) of_getintprop_default(dp, "l1-dcache-line-size",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) cpu_data(cpuid).icache_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) of_getintprop_default(dp, "l1-icache-size",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 8 * 1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) cpu_data(cpuid).icache_line_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) of_getintprop_default(dp, "l1-icache-line-size",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) cpu_data(cpuid).ecache_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) of_getintprop_default(dp, "l2-cache-size", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) cpu_data(cpuid).ecache_line_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) of_getintprop_default(dp, "l2-cache-line-size", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) if (!cpu_data(cpuid).ecache_size ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) !cpu_data(cpuid).ecache_line_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) cpu_data(cpuid).ecache_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) of_getintprop_default(portid_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) "l2-cache-size",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) (4 * 1024 * 1024));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) cpu_data(cpuid).ecache_line_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) of_getintprop_default(portid_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) "l2-cache-line-size", 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) cpu_data(cpuid).core_id = portid + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) cpu_data(cpuid).proc_id = portid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) cpu_data(cpuid).dcache_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) of_getintprop_default(dp, "dcache-size", 16 * 1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) cpu_data(cpuid).dcache_line_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) of_getintprop_default(dp, "dcache-line-size", 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) cpu_data(cpuid).icache_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) of_getintprop_default(dp, "icache-size", 16 * 1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) cpu_data(cpuid).icache_line_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) of_getintprop_default(dp, "icache-line-size", 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) cpu_data(cpuid).ecache_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) of_getintprop_default(dp, "ecache-size",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) (4 * 1024 * 1024));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) cpu_data(cpuid).ecache_line_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) of_getintprop_default(dp, "ecache-line-size", 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) cpu_data(cpuid).core_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) cpu_data(cpuid).proc_id = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) void __init of_fill_in_cpu_data(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) if (tlb_type == hypervisor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) of_iterate_over_cpus(fill_in_one_cpu, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) smp_fill_in_sib_core_maps();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) void __init of_console_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) char *msg = "OF stdout device is: %s\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) struct device_node *dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) phandle node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) of_console_path = prom_early_alloc(256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) if (prom_ihandle2path(prom_stdout, of_console_path, 256) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) prom_printf("Cannot obtain path of stdout.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) prom_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) of_console_options = strrchr(of_console_path, ':');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) if (of_console_options) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) of_console_options++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) if (*of_console_options == '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) of_console_options = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) node = prom_inst2pkg(prom_stdout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (!node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) prom_printf("Cannot resolve stdout node from "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) "instance %08x.\n", prom_stdout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) prom_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) dp = of_find_node_by_phandle(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) if (!of_node_is_type(dp, "display") && !of_node_is_type(dp, "serial")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) prom_printf("Console device_type is neither display "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) "nor serial.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) prom_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) of_console_device = dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) printk(msg, of_console_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) }