versal_net_common.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2018-2022, Xilinx, Inc. All rights reserved.
  4. * Copyright (c) 2022-2023, Advanced Micro Devices, Inc. All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #include <common/debug.h>
  9. #include <common/runtime_svc.h>
  10. #include <drivers/generic_delay_timer.h>
  11. #include <lib/mmio.h>
  12. #include <lib/xlat_tables/xlat_tables_v2.h>
  13. #include <plat/common/platform.h>
  14. #include <plat_common.h>
  15. #include <plat_ipi.h>
  16. #include <plat_private.h>
  17. #include <versal_net_def.h>
  18. uint32_t platform_id, platform_version;
  19. /*
  20. * Table of regions to map using the MMU.
  21. * This doesn't include TZRAM as the 'mem_layout' argument passed to
  22. * configure_mmu_elx() will give the available subset of that,
  23. */
  24. const mmap_region_t plat_versal_net_mmap[] = {
  25. MAP_REGION_FLAT(DEVICE0_BASE, DEVICE0_SIZE, MT_DEVICE | MT_RW | MT_SECURE),
  26. MAP_REGION_FLAT(DEVICE1_BASE, DEVICE1_SIZE, MT_DEVICE | MT_RW | MT_SECURE),
  27. MAP_REGION_FLAT(DEVICE2_BASE, DEVICE2_SIZE, MT_DEVICE | MT_RW | MT_SECURE),
  28. MAP_REGION_FLAT(CRF_BASE, CRF_SIZE, MT_DEVICE | MT_RW | MT_SECURE),
  29. MAP_REGION_FLAT(IPI_BASE, IPI_SIZE, MT_DEVICE | MT_RW | MT_SECURE),
  30. { 0 }
  31. };
  32. const mmap_region_t *plat_get_mmap(void)
  33. {
  34. return plat_versal_net_mmap;
  35. }
  36. /* For saving cpu clock for certain platform */
  37. uint32_t cpu_clock;
  38. char *board_name_decode(void)
  39. {
  40. switch (platform_id) {
  41. case VERSAL_NET_SPP:
  42. return "IPP";
  43. case VERSAL_NET_EMU:
  44. return "EMU";
  45. case VERSAL_NET_SILICON:
  46. return "Silicon";
  47. case VERSAL_NET_QEMU:
  48. return "QEMU";
  49. default:
  50. return "Unknown";
  51. }
  52. }
  53. void board_detection(void)
  54. {
  55. uint32_t version_type;
  56. version_type = mmio_read_32(PMC_TAP_VERSION);
  57. platform_id = FIELD_GET(PLATFORM_MASK, version_type);
  58. platform_version = FIELD_GET(PLATFORM_VERSION_MASK, version_type);
  59. if (platform_id == VERSAL_NET_QEMU_COSIM) {
  60. platform_id = VERSAL_NET_QEMU;
  61. }
  62. if ((platform_id == VERSAL_NET_SPP) ||
  63. (platform_id == VERSAL_NET_EMU) ||
  64. (platform_id == VERSAL_NET_QEMU)) {
  65. /*
  66. * 9 is diff for
  67. * 0 means 0.9 version
  68. * 1 means 1.0 version
  69. * 2 means 1.1 version
  70. * etc,
  71. */
  72. platform_version += 9U;
  73. }
  74. /* Make sure that console is setup to see this message */
  75. VERBOSE("Platform id: %d version: %d.%d\n", platform_id,
  76. platform_version / 10U, platform_version % 10U);
  77. }
  78. uint32_t get_uart_clk(void)
  79. {
  80. uint32_t uart_clock;
  81. switch (platform_id) {
  82. case VERSAL_NET_SPP:
  83. uart_clock = 1000000;
  84. break;
  85. case VERSAL_NET_EMU:
  86. uart_clock = 25000000;
  87. break;
  88. case VERSAL_NET_QEMU:
  89. uart_clock = 25000000;
  90. break;
  91. case VERSAL_NET_SILICON:
  92. uart_clock = 100000000;
  93. break;
  94. default:
  95. panic();
  96. }
  97. return uart_clock;
  98. }
  99. void versal_net_config_setup(void)
  100. {
  101. generic_delay_timer_init();
  102. #if (TFA_NO_PM == 0)
  103. /* Configure IPI data for versal_net */
  104. versal_net_ipi_config_table_init();
  105. #endif
  106. }
  107. void syscnt_freq_config_setup(void)
  108. {
  109. uint32_t val;
  110. uintptr_t crl_base, iou_scntrs_base, psx_base;
  111. crl_base = VERSAL_NET_CRL;
  112. iou_scntrs_base = IOU_SCNTRS_BASE;
  113. psx_base = PSX_CRF;
  114. /* Reset for system timestamp generator in FPX */
  115. mmio_write_32(psx_base + PSX_CRF_RST_TIMESTAMP_OFFSET, 0);
  116. /* Global timer init - Program time stamp reference clk */
  117. val = mmio_read_32(crl_base + VERSAL_NET_CRL_TIMESTAMP_REF_CTRL_OFFSET);
  118. val |= VERSAL_NET_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT_BIT;
  119. mmio_write_32(crl_base + VERSAL_NET_CRL_TIMESTAMP_REF_CTRL_OFFSET, val);
  120. /* Clear reset of timestamp reg */
  121. mmio_write_32(crl_base + VERSAL_NET_CRL_RST_TIMESTAMP_OFFSET, 0);
  122. /* Program freq register in System counter and enable system counter. */
  123. mmio_write_32(iou_scntrs_base + IOU_SCNTRS_BASE_FREQ_OFFSET,
  124. cpu_clock);
  125. mmio_write_32(iou_scntrs_base + IOU_SCNTRS_COUNTER_CONTROL_REG_OFFSET,
  126. IOU_SCNTRS_CONTROL_EN);
  127. }