1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Copyright (C) 2016 Socionext Inc. 4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com> 5 */ 6 7 #include <common.h> 8 #include <linux/libfdt.h> 9 #include <asm/spin_table.h> 10 11 int spin_table_update_dt(void *fdt) 12 { 13 int cpus_offset, offset; 14 const char *prop; 15 int ret; 16 unsigned long rsv_addr = (unsigned long)&spin_table_reserve_begin; 17 unsigned long rsv_size = &spin_table_reserve_end - 18 &spin_table_reserve_begin; 19 20 cpus_offset = fdt_path_offset(fdt, "/cpus"); 21 if (cpus_offset < 0) 22 return -ENODEV; 23 24 for (offset = fdt_first_subnode(fdt, cpus_offset); 25 offset >= 0; 26 offset = fdt_next_subnode(fdt, offset)) { 27 prop = fdt_getprop(fdt, offset, "device_type", NULL); 28 if (!prop || strcmp(prop, "cpu")) 29 continue; 30 31 /* 32 * In the first loop, we check if every CPU node specifies 33 * spin-table. Otherwise, just return successfully to not 34 * disturb other methods, like psci. 35 */ 36 prop = fdt_getprop(fdt, offset, "enable-method", NULL); 37 if (!prop || strcmp(prop, "spin-table")) 38 return 0; 39 } 40 41 for (offset = fdt_first_subnode(fdt, cpus_offset); 42 offset >= 0; 43 offset = fdt_next_subnode(fdt, offset)) { 44 prop = fdt_getprop(fdt, offset, "device_type", NULL); 45 if (!prop || strcmp(prop, "cpu")) 46 continue; 47 48 ret = fdt_setprop_u64(fdt, offset, "cpu-release-addr", 49 (unsigned long)&spin_table_cpu_release_addr); 50 if (ret) 51 return -ENOSPC; 52 } 53 54 ret = fdt_add_mem_rsv(fdt, rsv_addr, rsv_size); 55 if (ret) 56 return -ENOSPC; 57 58 printf(" Reserved memory region for spin-table: addr=%lx size=%lx\n", 59 rsv_addr, rsv_size); 60 61 return 0; 62 } 63