^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) * Copyright (C) 2020 Western Digital Corporation or its affiliates.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/libfdt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/pgtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <asm/soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * This is called extremly early, before parse_dtb(), to allow initializing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * SoC hardware before memory or any device driver initialization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) void __init soc_early_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) void (*early_fn)(const void *fdt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) const struct of_device_id *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) const void *fdt = dtb_early_va;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) for (s = (void *)&__soc_early_init_table_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) (void *)s < (void *)&__soc_early_init_table_end; s++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) if (!fdt_node_check_compatible(fdt, 0, s->compatible)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) early_fn = s->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) early_fn(fdt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static bool soc_builtin_dtb_match(unsigned long vendor_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) unsigned long arch_id, unsigned long imp_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) const struct soc_builtin_dtb *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) return entry->vendor_id == vendor_id &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) entry->arch_id == arch_id &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) entry->imp_id == imp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) void * __init soc_lookup_builtin_dtb(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) unsigned long vendor_id, arch_id, imp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) const struct soc_builtin_dtb *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) __asm__ ("csrr %0, mvendorid" : "=r"(vendor_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) __asm__ ("csrr %0, marchid" : "=r"(arch_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) __asm__ ("csrr %0, mimpid" : "=r"(imp_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) for (s = (void *)&__soc_builtin_dtb_table_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) (void *)s < (void *)&__soc_builtin_dtb_table_end; s++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (soc_builtin_dtb_match(vendor_id, arch_id, imp_id, s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return s->dtb_func();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }