blob: f5345723b9ab9d89e74a2b677ea41516ff421090 [file] [log] [blame]
AlexeiFedorov7c5001a2022-12-14 13:22:33 +00001/*
2 * SPDX-License-Identifier: BSD-3-Clause
3 * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4 */
5
6#include <arch_helpers.h>
Soby Mathew9b2de242024-02-27 16:08:42 +00007#include <arm_dram.h>
AlexeiFedorov7c5001a2022-12-14 13:22:33 +00008#include <assert.h>
AlexeiFedorov7c5001a2022-12-14 13:22:33 +00009#include <rmm_el3_ifc.h>
10
11COMPILER_ASSERT(MAX_DRAM_NUM_BANKS == 2UL);
12
Soby Mathew9b2de242024-02-27 16:08:42 +000013void arm_set_dram_layout(struct ns_dram_info *plat_dram)
AlexeiFedorov7c5001a2022-12-14 13:22:33 +000014{
15 uint64_t num_banks, num_granules = 0UL;
16 struct ns_dram_bank *bank_ptr;
Soby Mathew9b2de242024-02-27 16:08:42 +000017 struct arm_dram_layout *dram_ptr = arm_get_dram_layout();
AlexeiFedorov7c5001a2022-12-14 13:22:33 +000018
Soby Mathew4714e232023-10-04 07:03:08 +010019 assert(!is_mmu_enabled());
20
AlexeiFedorov7c5001a2022-12-14 13:22:33 +000021 /* Number of banks */
22 num_banks = plat_dram->num_banks;
AlexeiFedorov3669cb32023-06-05 14:45:08 +010023 assert(num_banks <= MAX_DRAM_NUM_BANKS);
AlexeiFedorov7c5001a2022-12-14 13:22:33 +000024
25 /* Pointer to dram_bank[] array */
26 bank_ptr = plat_dram->banks;
27
28 for (unsigned long i = 0UL; i < num_banks; i++) {
29 uintptr_t start = bank_ptr->base;
30 uint64_t size = bank_ptr->size;
31 uintptr_t end = start + size - 1UL;
32
33 if (i == 1UL) {
34 /* Start granule index in bank 1 */
AlexeiFedorovee2fc822023-10-31 14:54:39 +000035 dram_ptr->idx_bank_1 = num_granules;
AlexeiFedorov7c5001a2022-12-14 13:22:33 +000036 }
37
38 /* Total number of granules */
39 num_granules += (size / GRANULE_SIZE);
40
Soby Mathew9b2de242024-02-27 16:08:42 +000041 dram_ptr->arm_bank[i].start_addr = start;
42 dram_ptr->arm_bank[i].end_addr = end;
AlexeiFedorov7c5001a2022-12-14 13:22:33 +000043
44 bank_ptr++;
45 }
46
AlexeiFedorovee2fc822023-10-31 14:54:39 +000047 dram_ptr->num_granules = num_granules;
AlexeiFedorov7c5001a2022-12-14 13:22:33 +000048
Soby Mathew9b2de242024-02-27 16:08:42 +000049 inv_dcache_range((uintptr_t)dram_ptr, sizeof(struct arm_dram_layout));
AlexeiFedorov7c5001a2022-12-14 13:22:33 +000050}