blob: d917e9dfb62f80c8e244db6c601941b9a04c0266 [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>
Simon Glass3ba929a2020-10-30 21:38:53 -06009#include <asm/global_data.h>
Aneesh Bansal4b636c32016-01-22 17:05:59 +053010
11DECLARE_GLOBAL_DATA_PTR;
12
13void construct_pamu_addr_table(struct pamu_addr_tbl *tbl, int *num_entries)
14{
15 int i = 0;
16 int j;
17
18 tbl->start_addr[i] =
19 (uint64_t)virt_to_phys((void *)CONFIG_SYS_SDRAM_BASE);
20 tbl->size[i] = (phys_size_t)(min(gd->ram_size, CONFIG_MAX_MEM_MAPPED));
21 tbl->end_addr[i] = tbl->start_addr[i] + tbl->size[i] - 1;
22
23 i++;
24#ifdef CONFIG_SYS_FLASH_BASE_PHYS
25 tbl->start_addr[i] =
26 (uint64_t)virt_to_phys((void *)CONFIG_SYS_FLASH_BASE_PHYS);
27 tbl->size[i] = 256 * 1024 * 1024; /* 256MB flash */
28 tbl->end_addr[i] = tbl->start_addr[i] + tbl->size[i] - 1;
29
30 i++;
31#endif
Sumit Gargf6d96cb2016-07-14 12:27:51 -040032#if (defined(CONFIG_SPL_BUILD) && (CONFIG_SYS_INIT_L3_VADDR))
33 tbl->start_addr[i] =
34 (uint64_t)virt_to_phys((void *)CONFIG_SYS_INIT_L3_VADDR);
35 tbl->size[i] = 256 * 1024; /* 256K CPC flash */
36 tbl->end_addr[i] = tbl->start_addr[i] + tbl->size[i] - 1;
37
38 i++;
39#endif
Aneesh Bansal4b636c32016-01-22 17:05:59 +053040 debug("PAMU address\t\t\tsize\n");
41 for (j = 0; j < i ; j++)
42 debug("%llx \t\t\t%llx\n", tbl->start_addr[j], tbl->size[j]);
43
44 *num_entries = i;
45}
46
47int sec_config_pamu_table(uint32_t liodn_ns, uint32_t liodn_s)
48{
49 struct pamu_addr_tbl tbl;
50 int num_entries = 0;
51 int ret = 0;
52
53 construct_pamu_addr_table(&tbl, &num_entries);
54
55 ret = config_pamu(&tbl, num_entries, liodn_ns);
56 if (ret)
57 return ret;
58
59 ret = config_pamu(&tbl, num_entries, liodn_s);
60 if (ret)
61 return ret;
62
63 return ret;
64}