arm64-common.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (C) 2016 Stefan Roese <sr@denx.de>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <fdtdec.h>
  9. #include <libfdt.h>
  10. #include <asm/io.h>
  11. #include <asm/system.h>
  12. #include <asm/arch/cpu.h>
  13. #include <asm/arch/soc.h>
  14. #include <asm/armv8/mmu.h>
  15. DECLARE_GLOBAL_DATA_PTR;
  16. /*
  17. * Not all memory is mapped in the MMU. So we need to restrict the
  18. * memory size so that U-Boot does not try to access it. Also, the
  19. * internal registers are located at 0xf000.0000 - 0xffff.ffff.
  20. * Currently only 2GiB are mapped for system memory. This is what
  21. * we pass to the U-Boot subsystem here.
  22. */
  23. #define USABLE_RAM_SIZE 0x80000000
  24. ulong board_get_usable_ram_top(ulong total_size)
  25. {
  26. if (gd->ram_size > USABLE_RAM_SIZE)
  27. return USABLE_RAM_SIZE;
  28. return gd->ram_size;
  29. }
  30. /*
  31. * On ARMv8, MBus is not configured in U-Boot. To enable compilation
  32. * of the already implemented drivers, lets add a dummy version of
  33. * this function so that linking does not fail.
  34. */
  35. const struct mbus_dram_target_info *mvebu_mbus_dram_info(void)
  36. {
  37. return NULL;
  38. }
  39. /* DRAM init code ... */
  40. static const void *get_memory_reg_prop(const void *fdt, int *lenp)
  41. {
  42. int offset;
  43. offset = fdt_path_offset(fdt, "/memory");
  44. if (offset < 0)
  45. return NULL;
  46. return fdt_getprop(fdt, offset, "reg", lenp);
  47. }
  48. int dram_init(void)
  49. {
  50. const void *fdt = gd->fdt_blob;
  51. const fdt32_t *val;
  52. int ac, sc, len;
  53. ac = fdt_address_cells(fdt, 0);
  54. sc = fdt_size_cells(fdt, 0);
  55. if (ac < 0 || sc < 1 || sc > 2) {
  56. printf("invalid address/size cells\n");
  57. return -EINVAL;
  58. }
  59. val = get_memory_reg_prop(fdt, &len);
  60. if (len / sizeof(*val) < ac + sc)
  61. return -EINVAL;
  62. val += ac;
  63. gd->ram_size = fdtdec_get_number(val, sc);
  64. debug("DRAM size = %08lx\n", (unsigned long)gd->ram_size);
  65. return 0;
  66. }
  67. void dram_init_banksize(void)
  68. {
  69. const void *fdt = gd->fdt_blob;
  70. const fdt32_t *val;
  71. int ac, sc, cells, len, i;
  72. val = get_memory_reg_prop(fdt, &len);
  73. if (len < 0)
  74. return;
  75. ac = fdt_address_cells(fdt, 0);
  76. sc = fdt_size_cells(fdt, 0);
  77. if (ac < 1 || sc > 2 || sc < 1 || sc > 2) {
  78. printf("invalid address/size cells\n");
  79. return;
  80. }
  81. cells = ac + sc;
  82. len /= sizeof(*val);
  83. for (i = 0; i < CONFIG_NR_DRAM_BANKS && len >= cells;
  84. i++, len -= cells) {
  85. gd->bd->bi_dram[i].start = fdtdec_get_number(val, ac);
  86. val += ac;
  87. gd->bd->bi_dram[i].size = fdtdec_get_number(val, sc);
  88. val += sc;
  89. debug("DRAM bank %d: start = %08lx, size = %08lx\n",
  90. i, (unsigned long)gd->bd->bi_dram[i].start,
  91. (unsigned long)gd->bd->bi_dram[i].size);
  92. }
  93. }
  94. int arch_cpu_init(void)
  95. {
  96. /* Nothing to do (yet) */
  97. return 0;
  98. }
  99. int arch_early_init_r(void)
  100. {
  101. struct udevice *dev;
  102. int ret;
  103. int i;
  104. /*
  105. * Loop over all MISC uclass drivers to call the comphy code
  106. * and init all CP110 devices enabled in the DT
  107. */
  108. i = 0;
  109. while (1) {
  110. /* Call the comphy code via the MISC uclass driver */
  111. ret = uclass_get_device(UCLASS_MISC, i++, &dev);
  112. /* We're done, once no further CP110 device is found */
  113. if (ret)
  114. break;
  115. }
  116. /* Cause the SATA device to do its early init */
  117. uclass_first_device(UCLASS_AHCI, &dev);
  118. return 0;
  119. }