blob: 7dd71d2e0c4a53157eb5331b8c34af882a061e4f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Aneesh Bansal4b636c32016-01-22 17:05:59 +05302/*
3 * Copyright 2012-2016 Freescale Semiconductor, Inc.
Aneesh Bansal4b636c32016-01-22 17:05:59 +05304 */
5
6#include <common.h>
Simon Glass0f2af882020-05-10 11:40:05 -06007#include <log.h>
Aneesh Bansal4b636c32016-01-22 17:05:59 +05308#include <asm/fsl_pamu.h>
9
10DECLARE_GLOBAL_DATA_PTR;
11
12void construct_pamu_addr_table(struct pamu_addr_tbl *tbl, int *num_entries)
13{
14 int i = 0;
15 int j;
16
17 tbl->start_addr[i] =
18 (uint64_t)virt_to_phys((void *)CONFIG_SYS_SDRAM_BASE);
19 tbl->size[i] = (phys_size_t)(min(gd->ram_size, CONFIG_MAX_MEM_MAPPED));
20 tbl->end_addr[i] = tbl->start_addr[i] + tbl->size[i] - 1;
21
22 i++;
23#ifdef CONFIG_SYS_FLASH_BASE_PHYS
24 tbl->start_addr[i] =
25 (uint64_t)virt_to_phys((void *)CONFIG_SYS_FLASH_BASE_PHYS);
26 tbl->size[i] = 256 * 1024 * 1024; /* 256MB flash */
27 tbl->end_addr[i] = tbl->start_addr[i] + tbl->size[i] - 1;
28
29 i++;
30#endif
Sumit Gargf6d96cb2016-07-14 12:27:51 -040031#if (defined(CONFIG_SPL_BUILD) && (CONFIG_SYS_INIT_L3_VADDR))
32 tbl->start_addr[i] =
33 (uint64_t)virt_to_phys((void *)CONFIG_SYS_INIT_L3_VADDR);
34 tbl->size[i] = 256 * 1024; /* 256K CPC flash */
35 tbl->end_addr[i] = tbl->start_addr[i] + tbl->size[i] - 1;
36
37 i++;
38#endif
Aneesh Bansal4b636c32016-01-22 17:05:59 +053039 debug("PAMU address\t\t\tsize\n");
40 for (j = 0; j < i ; j++)
41 debug("%llx \t\t\t%llx\n", tbl->start_addr[j], tbl->size[j]);
42
43 *num_entries = i;
44}
45
46int sec_config_pamu_table(uint32_t liodn_ns, uint32_t liodn_s)
47{
48 struct pamu_addr_tbl tbl;
49 int num_entries = 0;
50 int ret = 0;
51
52 construct_pamu_addr_table(&tbl, &num_entries);
53
54 ret = config_pamu(&tbl, num_entries, liodn_ns);
55 if (ret)
56 return ret;
57
58 ret = config_pamu(&tbl, num_entries, liodn_s);
59 if (ret)
60 return ret;
61
62 return ret;
63}