rcar_common.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (c) 2019-2021, Renesas Electronics Corporation. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <arch_helpers.h>
  8. #include <drivers/console.h>
  9. #include <lib/xlat_tables/xlat_mmu_helpers.h>
  10. #include <plat/common/platform.h>
  11. #include <lib/mmio.h>
  12. #include <cpg_registers.h>
  13. #define MSTP318 (1 << 18)
  14. #define MSTP319 (1 << 19)
  15. #define PMSR 0x5c
  16. #define PMSR_L1FAEG (1U << 31)
  17. #define PMSR_PMEL1RX (1 << 23)
  18. #define PMCTLR 0x60
  19. #define PMSR_L1IATN (1U << 31)
  20. static int rcar_pcie_fixup(unsigned int controller)
  21. {
  22. uint32_t rcar_pcie_base[] = { 0xfe011000, 0xee811000 };
  23. uint32_t addr = rcar_pcie_base[controller];
  24. uint32_t cpg, pmsr;
  25. int ret = 0;
  26. /* Test if PCIECx is enabled */
  27. cpg = mmio_read_32(CPG_MSTPSR3);
  28. if (cpg & (MSTP318 << !controller))
  29. return ret;
  30. pmsr = mmio_read_32(addr + PMSR);
  31. if ((pmsr & PMSR_PMEL1RX) && ((pmsr & 0x70000) != 0x30000)) {
  32. /* Fix applicable */
  33. mmio_write_32(addr + PMCTLR, PMSR_L1IATN);
  34. while (!(mmio_read_32(addr + PMSR) & PMSR_L1FAEG))
  35. ;
  36. mmio_write_32(addr + PMSR, PMSR_L1FAEG | PMSR_PMEL1RX);
  37. ret = 1;
  38. }
  39. return ret;
  40. }
  41. /* RAS functions common to AArch64 ARM platforms */
  42. void plat_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie,
  43. void *handle, uint64_t flags)
  44. {
  45. unsigned int fixed = 0;
  46. fixed |= rcar_pcie_fixup(0);
  47. fixed |= rcar_pcie_fixup(1);
  48. if (fixed)
  49. return;
  50. plat_default_ea_handler(ea_reason, syndrome, cookie, handle, flags);
  51. }
  52. #include <drivers/renesas/rcar/console/console.h>
  53. static console_t rcar_boot_console;
  54. static console_t rcar_runtime_console;
  55. void rcar_console_boot_init(void)
  56. {
  57. int ret;
  58. ret = console_rcar_register(0, 0, 0, &rcar_boot_console);
  59. if (!ret)
  60. panic();
  61. console_set_scope(&rcar_boot_console, CONSOLE_FLAG_BOOT);
  62. }
  63. void rcar_console_boot_end(void)
  64. {
  65. }
  66. void rcar_console_runtime_init(void)
  67. {
  68. int ret;
  69. ret = console_rcar_register(1, 0, 0, &rcar_runtime_console);
  70. if (!ret)
  71. panic();
  72. console_set_scope(&rcar_boot_console, CONSOLE_FLAG_RUNTIME);
  73. }
  74. void rcar_console_runtime_end(void)
  75. {
  76. }