1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2012-2016 Freescale Semiconductor, Inc.
4  */
5 
6 #include <common.h>
7 #include <log.h>
8 #include <asm/fsl_pamu.h>
9 #include <asm/global_data.h>
10 
11 DECLARE_GLOBAL_DATA_PTR;
12 
construct_pamu_addr_table(struct pamu_addr_tbl * tbl,int * num_entries)13 void 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
32 #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
40 	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 
sec_config_pamu_table(uint32_t liodn_ns,uint32_t liodn_s)47 int 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 }
65