arm64-common.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2016 Stefan Roese <sr@denx.de>
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <fdtdec.h>
  8. #include <linux/libfdt.h>
  9. #include <linux/sizes.h>
  10. #include <pci.h>
  11. #include <asm/io.h>
  12. #include <asm/system.h>
  13. #include <asm/arch/cpu.h>
  14. #include <asm/arch/soc.h>
  15. #include <asm/armv8/mmu.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. /*
  18. * Not all memory is mapped in the MMU. So we need to restrict the
  19. * memory size so that U-Boot does not try to access it. Also, the
  20. * internal registers are located at 0xf000.0000 - 0xffff.ffff.
  21. * Currently only 2GiB are mapped for system memory. This is what
  22. * we pass to the U-Boot subsystem here.
  23. */
  24. #define USABLE_RAM_SIZE 0x80000000
  25. ulong board_get_usable_ram_top(ulong total_size)
  26. {
  27. if (gd->ram_size > USABLE_RAM_SIZE)
  28. return USABLE_RAM_SIZE;
  29. return gd->ram_size;
  30. }
  31. /*
  32. * On ARMv8, MBus is not configured in U-Boot. To enable compilation
  33. * of the already implemented drivers, lets add a dummy version of
  34. * this function so that linking does not fail.
  35. */
  36. const struct mbus_dram_target_info *mvebu_mbus_dram_info(void)
  37. {
  38. return NULL;
  39. }
  40. /* DRAM init code ... */
  41. #define MV_SIP_DRAM_SIZE 0x82000010
  42. static u64 a8k_dram_scan_ap_sz(void)
  43. {
  44. struct pt_regs pregs;
  45. pregs.regs[0] = MV_SIP_DRAM_SIZE;
  46. pregs.regs[1] = SOC_REGS_PHY_BASE;
  47. smc_call(&pregs);
  48. return pregs.regs[0];
  49. }
  50. static void a8k_dram_init_banksize(void)
  51. {
  52. /*
  53. * The firmware (ATF) leaves a 1G whole above the 3G mark for IO
  54. * devices. Higher RAM is mapped at 4G.
  55. *
  56. * Config 2 DRAM banks:
  57. * Bank 0 - max size 4G - 1G
  58. * Bank 1 - ram size - 4G + 1G
  59. */
  60. phys_size_t max_bank0_size = SZ_4G - SZ_1G;
  61. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  62. if (gd->ram_size <= max_bank0_size) {
  63. gd->bd->bi_dram[0].size = gd->ram_size;
  64. return;
  65. }
  66. gd->bd->bi_dram[0].size = max_bank0_size;
  67. if (CONFIG_NR_DRAM_BANKS > 1) {
  68. gd->bd->bi_dram[1].start = SZ_4G;
  69. gd->bd->bi_dram[1].size = gd->ram_size - max_bank0_size;
  70. }
  71. }
  72. int dram_init_banksize(void)
  73. {
  74. if (CONFIG_IS_ENABLED(ARMADA_8K))
  75. a8k_dram_init_banksize();
  76. else
  77. fdtdec_setup_memory_banksize();
  78. return 0;
  79. }
  80. int dram_init(void)
  81. {
  82. if (CONFIG_IS_ENABLED(ARMADA_8K)) {
  83. gd->ram_size = a8k_dram_scan_ap_sz();
  84. if (gd->ram_size != 0)
  85. return 0;
  86. }
  87. if (fdtdec_setup_mem_size_base() != 0)
  88. return -EINVAL;
  89. return 0;
  90. }
  91. int arch_cpu_init(void)
  92. {
  93. /* Nothing to do (yet) */
  94. return 0;
  95. }
  96. int arch_early_init_r(void)
  97. {
  98. struct udevice *dev;
  99. int ret;
  100. int i;
  101. /*
  102. * Loop over all MISC uclass drivers to call the comphy code
  103. * and init all CP110 devices enabled in the DT
  104. */
  105. i = 0;
  106. while (1) {
  107. /* Call the comphy code via the MISC uclass driver */
  108. ret = uclass_get_device(UCLASS_MISC, i++, &dev);
  109. /* We're done, once no further CP110 device is found */
  110. if (ret)
  111. break;
  112. }
  113. /* Cause the SATA device to do its early init */
  114. uclass_first_device(UCLASS_AHCI, &dev);
  115. #ifdef CONFIG_DM_PCI
  116. /* Trigger PCIe devices detection */
  117. pci_init();
  118. #endif
  119. return 0;
  120. }