| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Procedures for creating, accessing and interpreting the device tree. |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 8 | 9 | * {engebret|bergner}@us.ibm.com |
|---|
| 9 | 10 | * |
|---|
| 10 | 11 | * Adapted for sparc32 by David S. Miller davem@davemloft.net |
|---|
| 11 | | - * |
|---|
| 12 | | - * This program is free software; you can redistribute it and/or |
|---|
| 13 | | - * modify it under the terms of the GNU General Public License |
|---|
| 14 | | - * as published by the Free Software Foundation; either version |
|---|
| 15 | | - * 2 of the License, or (at your option) any later version. |
|---|
| 16 | 12 | */ |
|---|
| 17 | 13 | |
|---|
| 18 | 14 | #include <linux/kernel.h> |
|---|
| 19 | 15 | #include <linux/types.h> |
|---|
| 20 | 16 | #include <linux/string.h> |
|---|
| 21 | 17 | #include <linux/mm.h> |
|---|
| 22 | | -#include <linux/bootmem.h> |
|---|
| 18 | +#include <linux/memblock.h> |
|---|
| 23 | 19 | |
|---|
| 24 | 20 | #include <asm/prom.h> |
|---|
| 25 | 21 | #include <asm/oplib.h> |
|---|
| .. | .. |
|---|
| 32 | 28 | { |
|---|
| 33 | 29 | void *ret; |
|---|
| 34 | 30 | |
|---|
| 35 | | - ret = __alloc_bootmem(size, SMP_CACHE_BYTES, 0UL); |
|---|
| 36 | | - if (ret != NULL) |
|---|
| 37 | | - memset(ret, 0, size); |
|---|
| 31 | + ret = memblock_alloc(size, SMP_CACHE_BYTES); |
|---|
| 32 | + if (!ret) |
|---|
| 33 | + panic("%s: Failed to allocate %lu bytes\n", __func__, size); |
|---|
| 38 | 34 | |
|---|
| 39 | 35 | prom_early_allocated += size; |
|---|
| 40 | 36 | |
|---|
| .. | .. |
|---|
| 60 | 56 | */ |
|---|
| 61 | 57 | static void __init sparc32_path_component(struct device_node *dp, char *tmp_buf) |
|---|
| 62 | 58 | { |
|---|
| 59 | + const char *name = of_get_property(dp, "name", NULL); |
|---|
| 63 | 60 | struct linux_prom_registers *regs; |
|---|
| 64 | 61 | struct property *rprop; |
|---|
| 65 | 62 | |
|---|
| .. | .. |
|---|
| 69 | 66 | |
|---|
| 70 | 67 | regs = rprop->value; |
|---|
| 71 | 68 | sprintf(tmp_buf, "%s@%x,%x", |
|---|
| 72 | | - dp->name, |
|---|
| 69 | + name, |
|---|
| 73 | 70 | regs->which_io, regs->phys_addr); |
|---|
| 74 | 71 | } |
|---|
| 75 | 72 | |
|---|
| 76 | 73 | /* "name@slot,offset" */ |
|---|
| 77 | 74 | static void __init sbus_path_component(struct device_node *dp, char *tmp_buf) |
|---|
| 78 | 75 | { |
|---|
| 76 | + const char *name = of_get_property(dp, "name", NULL); |
|---|
| 79 | 77 | struct linux_prom_registers *regs; |
|---|
| 80 | 78 | struct property *prop; |
|---|
| 81 | 79 | |
|---|
| .. | .. |
|---|
| 85 | 83 | |
|---|
| 86 | 84 | regs = prop->value; |
|---|
| 87 | 85 | sprintf(tmp_buf, "%s@%x,%x", |
|---|
| 88 | | - dp->name, |
|---|
| 86 | + name, |
|---|
| 89 | 87 | regs->which_io, |
|---|
| 90 | 88 | regs->phys_addr); |
|---|
| 91 | 89 | } |
|---|
| .. | .. |
|---|
| 93 | 91 | /* "name@devnum[,func]" */ |
|---|
| 94 | 92 | static void __init pci_path_component(struct device_node *dp, char *tmp_buf) |
|---|
| 95 | 93 | { |
|---|
| 94 | + const char *name = of_get_property(dp, "name", NULL); |
|---|
| 96 | 95 | struct linux_prom_pci_registers *regs; |
|---|
| 97 | 96 | struct property *prop; |
|---|
| 98 | 97 | unsigned int devfn; |
|---|
| .. | .. |
|---|
| 105 | 104 | devfn = (regs->phys_hi >> 8) & 0xff; |
|---|
| 106 | 105 | if (devfn & 0x07) { |
|---|
| 107 | 106 | sprintf(tmp_buf, "%s@%x,%x", |
|---|
| 108 | | - dp->name, |
|---|
| 107 | + name, |
|---|
| 109 | 108 | devfn >> 3, |
|---|
| 110 | 109 | devfn & 0x07); |
|---|
| 111 | 110 | } else { |
|---|
| 112 | 111 | sprintf(tmp_buf, "%s@%x", |
|---|
| 113 | | - dp->name, |
|---|
| 112 | + name, |
|---|
| 114 | 113 | devfn >> 3); |
|---|
| 115 | 114 | } |
|---|
| 116 | 115 | } |
|---|
| .. | .. |
|---|
| 118 | 117 | /* "name@addrhi,addrlo" */ |
|---|
| 119 | 118 | static void __init ebus_path_component(struct device_node *dp, char *tmp_buf) |
|---|
| 120 | 119 | { |
|---|
| 120 | + const char *name = of_get_property(dp, "name", NULL); |
|---|
| 121 | 121 | struct linux_prom_registers *regs; |
|---|
| 122 | 122 | struct property *prop; |
|---|
| 123 | 123 | |
|---|
| .. | .. |
|---|
| 128 | 128 | regs = prop->value; |
|---|
| 129 | 129 | |
|---|
| 130 | 130 | sprintf(tmp_buf, "%s@%x,%x", |
|---|
| 131 | | - dp->name, |
|---|
| 131 | + name, |
|---|
| 132 | 132 | regs->which_io, regs->phys_addr); |
|---|
| 133 | 133 | } |
|---|
| 134 | 134 | |
|---|
| 135 | | -/* "name:vendor:device@irq,addrlo" */ |
|---|
| 135 | +/* "name@irq,addrlo" */ |
|---|
| 136 | 136 | static void __init ambapp_path_component(struct device_node *dp, char *tmp_buf) |
|---|
| 137 | 137 | { |
|---|
| 138 | + const char *name = of_get_property(dp, "name", NULL); |
|---|
| 138 | 139 | struct amba_prom_registers *regs; |
|---|
| 139 | | - unsigned int *intr, *device, *vendor, reg0; |
|---|
| 140 | + unsigned int *intr; |
|---|
| 141 | + unsigned int reg0; |
|---|
| 140 | 142 | struct property *prop; |
|---|
| 141 | 143 | int interrupt = 0; |
|---|
| 142 | 144 | |
|---|
| .. | .. |
|---|
| 158 | 160 | else |
|---|
| 159 | 161 | intr = prop->value; |
|---|
| 160 | 162 | |
|---|
| 161 | | - prop = of_find_property(dp, "vendor", NULL); |
|---|
| 162 | | - if (!prop) |
|---|
| 163 | | - return; |
|---|
| 164 | | - vendor = prop->value; |
|---|
| 165 | | - prop = of_find_property(dp, "device", NULL); |
|---|
| 166 | | - if (!prop) |
|---|
| 167 | | - return; |
|---|
| 168 | | - device = prop->value; |
|---|
| 169 | | - |
|---|
| 170 | | - sprintf(tmp_buf, "%s:%d:%d@%x,%x", |
|---|
| 171 | | - dp->name, *vendor, *device, |
|---|
| 172 | | - *intr, reg0); |
|---|
| 163 | + sprintf(tmp_buf, "%s@%x,%x", name, *intr, reg0); |
|---|
| 173 | 164 | } |
|---|
| 174 | 165 | |
|---|
| 175 | 166 | static void __init __build_path_component(struct device_node *dp, char *tmp_buf) |
|---|
| .. | .. |
|---|
| 177 | 168 | struct device_node *parent = dp->parent; |
|---|
| 178 | 169 | |
|---|
| 179 | 170 | if (parent != NULL) { |
|---|
| 180 | | - if (!strcmp(parent->type, "pci") || |
|---|
| 181 | | - !strcmp(parent->type, "pciex")) |
|---|
| 171 | + if (of_node_is_type(parent, "pci") || |
|---|
| 172 | + of_node_is_type(parent, "pciex")) |
|---|
| 182 | 173 | return pci_path_component(dp, tmp_buf); |
|---|
| 183 | | - if (!strcmp(parent->type, "sbus")) |
|---|
| 174 | + if (of_node_is_type(parent, "sbus")) |
|---|
| 184 | 175 | return sbus_path_component(dp, tmp_buf); |
|---|
| 185 | | - if (!strcmp(parent->type, "ebus")) |
|---|
| 176 | + if (of_node_is_type(parent, "ebus")) |
|---|
| 186 | 177 | return ebus_path_component(dp, tmp_buf); |
|---|
| 187 | | - if (!strcmp(parent->type, "ambapp")) |
|---|
| 178 | + if (of_node_is_type(parent, "ambapp")) |
|---|
| 188 | 179 | return ambapp_path_component(dp, tmp_buf); |
|---|
| 189 | 180 | |
|---|
| 190 | 181 | /* "isa" is handled with platform naming */ |
|---|
| .. | .. |
|---|
| 196 | 187 | |
|---|
| 197 | 188 | char * __init build_path_component(struct device_node *dp) |
|---|
| 198 | 189 | { |
|---|
| 190 | + const char *name = of_get_property(dp, "name", NULL); |
|---|
| 199 | 191 | char tmp_buf[64], *n; |
|---|
| 200 | 192 | |
|---|
| 201 | 193 | tmp_buf[0] = '\0'; |
|---|
| 202 | 194 | __build_path_component(dp, tmp_buf); |
|---|
| 203 | 195 | if (tmp_buf[0] == '\0') |
|---|
| 204 | | - strcpy(tmp_buf, dp->name); |
|---|
| 196 | + strcpy(tmp_buf, name); |
|---|
| 205 | 197 | |
|---|
| 206 | 198 | n = prom_early_alloc(strlen(tmp_buf) + 1); |
|---|
| 207 | 199 | strcpy(n, tmp_buf); |
|---|
| .. | .. |
|---|
| 232 | 224 | |
|---|
| 233 | 225 | case PROMDEV_TTYB: |
|---|
| 234 | 226 | skip = 1; |
|---|
| 235 | | - /* FALLTHRU */ |
|---|
| 227 | + fallthrough; |
|---|
| 236 | 228 | |
|---|
| 237 | 229 | case PROMDEV_TTYA: |
|---|
| 238 | 230 | type = "serial"; |
|---|
| .. | .. |
|---|
| 255 | 247 | } |
|---|
| 256 | 248 | of_console_device = dp; |
|---|
| 257 | 249 | |
|---|
| 258 | | - strcpy(of_console_path, dp->full_name); |
|---|
| 250 | + sprintf(of_console_path, "%pOF", dp); |
|---|
| 259 | 251 | if (!strcmp(type, "serial")) { |
|---|
| 260 | 252 | strcat(of_console_path, |
|---|
| 261 | 253 | (skip ? ":b" : ":a")); |
|---|
| .. | .. |
|---|
| 278 | 270 | prom_halt(); |
|---|
| 279 | 271 | } |
|---|
| 280 | 272 | dp = of_find_node_by_phandle(node); |
|---|
| 281 | | - type = of_get_property(dp, "device_type", NULL); |
|---|
| 282 | 273 | |
|---|
| 283 | | - if (!type) { |
|---|
| 284 | | - prom_printf("Console stdout lacks " |
|---|
| 285 | | - "device_type property.\n"); |
|---|
| 286 | | - prom_halt(); |
|---|
| 287 | | - } |
|---|
| 288 | | - |
|---|
| 289 | | - if (strcmp(type, "display") && strcmp(type, "serial")) { |
|---|
| 274 | + if (!of_node_is_type(dp, "display") && |
|---|
| 275 | + !of_node_is_type(dp, "serial")) { |
|---|
| 290 | 276 | prom_printf("Console device_type is neither display " |
|---|
| 291 | 277 | "nor serial.\n"); |
|---|
| 292 | 278 | prom_halt(); |
|---|
| .. | .. |
|---|
| 295 | 281 | of_console_device = dp; |
|---|
| 296 | 282 | |
|---|
| 297 | 283 | if (prom_vers == PROM_V2) { |
|---|
| 298 | | - strcpy(of_console_path, dp->full_name); |
|---|
| 284 | + sprintf(of_console_path, "%pOF", dp); |
|---|
| 299 | 285 | switch (*romvec->pv_stdout) { |
|---|
| 300 | 286 | case PROMDEV_TTYA: |
|---|
| 301 | 287 | strcat(of_console_path, ":a"); |
|---|