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