1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+ 26b6024eaSMasahiro Yamada /* 36b6024eaSMasahiro Yamada * Copyright (C) 2016 Socionext Inc. 46b6024eaSMasahiro Yamada * Author: Masahiro Yamada <yamada.masahiro@socionext.com> 56b6024eaSMasahiro Yamada */ 66b6024eaSMasahiro Yamada 76b6024eaSMasahiro Yamada #include <common.h> 8b08c8c48SMasahiro Yamada #include <linux/libfdt.h> 96b6024eaSMasahiro Yamada #include <asm/spin_table.h> 106b6024eaSMasahiro Yamada 116b6024eaSMasahiro Yamada int spin_table_update_dt(void *fdt) 126b6024eaSMasahiro Yamada { 136b6024eaSMasahiro Yamada int cpus_offset, offset; 146b6024eaSMasahiro Yamada const char *prop; 156b6024eaSMasahiro Yamada int ret; 166b6024eaSMasahiro Yamada unsigned long rsv_addr = (unsigned long)&spin_table_reserve_begin; 176b6024eaSMasahiro Yamada unsigned long rsv_size = &spin_table_reserve_end - 186b6024eaSMasahiro Yamada &spin_table_reserve_begin; 196b6024eaSMasahiro Yamada 206b6024eaSMasahiro Yamada cpus_offset = fdt_path_offset(fdt, "/cpus"); 216b6024eaSMasahiro Yamada if (cpus_offset < 0) 226b6024eaSMasahiro Yamada return -ENODEV; 236b6024eaSMasahiro Yamada 246b6024eaSMasahiro Yamada for (offset = fdt_first_subnode(fdt, cpus_offset); 256b6024eaSMasahiro Yamada offset >= 0; 266b6024eaSMasahiro Yamada offset = fdt_next_subnode(fdt, offset)) { 276b6024eaSMasahiro Yamada prop = fdt_getprop(fdt, offset, "device_type", NULL); 286b6024eaSMasahiro Yamada if (!prop || strcmp(prop, "cpu")) 296b6024eaSMasahiro Yamada continue; 306b6024eaSMasahiro Yamada 316b6024eaSMasahiro Yamada /* 326b6024eaSMasahiro Yamada * In the first loop, we check if every CPU node specifies 336b6024eaSMasahiro Yamada * spin-table. Otherwise, just return successfully to not 346b6024eaSMasahiro Yamada * disturb other methods, like psci. 356b6024eaSMasahiro Yamada */ 366b6024eaSMasahiro Yamada prop = fdt_getprop(fdt, offset, "enable-method", NULL); 376b6024eaSMasahiro Yamada if (!prop || strcmp(prop, "spin-table")) 386b6024eaSMasahiro Yamada return 0; 396b6024eaSMasahiro Yamada } 406b6024eaSMasahiro Yamada 416b6024eaSMasahiro Yamada for (offset = fdt_first_subnode(fdt, cpus_offset); 426b6024eaSMasahiro Yamada offset >= 0; 436b6024eaSMasahiro Yamada offset = fdt_next_subnode(fdt, offset)) { 446b6024eaSMasahiro Yamada prop = fdt_getprop(fdt, offset, "device_type", NULL); 456b6024eaSMasahiro Yamada if (!prop || strcmp(prop, "cpu")) 466b6024eaSMasahiro Yamada continue; 476b6024eaSMasahiro Yamada 486b6024eaSMasahiro Yamada ret = fdt_setprop_u64(fdt, offset, "cpu-release-addr", 496b6024eaSMasahiro Yamada (unsigned long)&spin_table_cpu_release_addr); 506b6024eaSMasahiro Yamada if (ret) 516b6024eaSMasahiro Yamada return -ENOSPC; 526b6024eaSMasahiro Yamada } 536b6024eaSMasahiro Yamada 546b6024eaSMasahiro Yamada ret = fdt_add_mem_rsv(fdt, rsv_addr, rsv_size); 556b6024eaSMasahiro Yamada if (ret) 566b6024eaSMasahiro Yamada return -ENOSPC; 576b6024eaSMasahiro Yamada 586b6024eaSMasahiro Yamada printf(" Reserved memory region for spin-table: addr=%lx size=%lx\n", 596b6024eaSMasahiro Yamada rsv_addr, rsv_size); 606b6024eaSMasahiro Yamada 616b6024eaSMasahiro Yamada return 0; 626b6024eaSMasahiro Yamada } 63