soc.c 1.5 KB

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