xref: /openbmc/u-boot/arch/powerpc/cpu/mpc8xxx/pamu_table.c (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2f698e9f3SAneesh Bansal /*
3f698e9f3SAneesh Bansal  * Copyright 2012-2016 Freescale Semiconductor, Inc.
4f698e9f3SAneesh Bansal  */
5f698e9f3SAneesh Bansal 
6f698e9f3SAneesh Bansal #include <common.h>
7f698e9f3SAneesh Bansal #include <asm/fsl_pamu.h>
8f698e9f3SAneesh Bansal 
9f698e9f3SAneesh Bansal DECLARE_GLOBAL_DATA_PTR;
10f698e9f3SAneesh Bansal 
construct_pamu_addr_table(struct pamu_addr_tbl * tbl,int * num_entries)11f698e9f3SAneesh Bansal void construct_pamu_addr_table(struct pamu_addr_tbl *tbl, int *num_entries)
12f698e9f3SAneesh Bansal {
13f698e9f3SAneesh Bansal 	int i = 0;
14f698e9f3SAneesh Bansal 	int j;
15f698e9f3SAneesh Bansal 
16f698e9f3SAneesh Bansal 	tbl->start_addr[i] =
17f698e9f3SAneesh Bansal 			(uint64_t)virt_to_phys((void *)CONFIG_SYS_SDRAM_BASE);
18f698e9f3SAneesh Bansal 	tbl->size[i] = (phys_size_t)(min(gd->ram_size, CONFIG_MAX_MEM_MAPPED));
19f698e9f3SAneesh Bansal 	tbl->end_addr[i] = tbl->start_addr[i] +  tbl->size[i] - 1;
20f698e9f3SAneesh Bansal 
21f698e9f3SAneesh Bansal 	i++;
22f698e9f3SAneesh Bansal #ifdef CONFIG_SYS_FLASH_BASE_PHYS
23f698e9f3SAneesh Bansal 	tbl->start_addr[i] =
24f698e9f3SAneesh Bansal 		(uint64_t)virt_to_phys((void *)CONFIG_SYS_FLASH_BASE_PHYS);
25f698e9f3SAneesh Bansal 	tbl->size[i] = 256 * 1024 * 1024; /* 256MB flash */
26f698e9f3SAneesh Bansal 	tbl->end_addr[i] = tbl->start_addr[i] +  tbl->size[i] - 1;
27f698e9f3SAneesh Bansal 
28f698e9f3SAneesh Bansal 	i++;
29f698e9f3SAneesh Bansal #endif
308f01397bSSumit Garg #if (defined(CONFIG_SPL_BUILD) && (CONFIG_SYS_INIT_L3_VADDR))
318f01397bSSumit Garg 	tbl->start_addr[i] =
328f01397bSSumit Garg 		(uint64_t)virt_to_phys((void *)CONFIG_SYS_INIT_L3_VADDR);
338f01397bSSumit Garg 	tbl->size[i] = 256 * 1024; /* 256K CPC flash */
348f01397bSSumit Garg 	tbl->end_addr[i] = tbl->start_addr[i] +  tbl->size[i] - 1;
358f01397bSSumit Garg 
368f01397bSSumit Garg 	i++;
378f01397bSSumit Garg #endif
38f698e9f3SAneesh Bansal 	debug("PAMU address\t\t\tsize\n");
39f698e9f3SAneesh Bansal 	for (j = 0; j < i ; j++)
40f698e9f3SAneesh Bansal 		debug("%llx \t\t\t%llx\n",  tbl->start_addr[j],  tbl->size[j]);
41f698e9f3SAneesh Bansal 
42f698e9f3SAneesh Bansal 	*num_entries = i;
43f698e9f3SAneesh Bansal }
44f698e9f3SAneesh Bansal 
sec_config_pamu_table(uint32_t liodn_ns,uint32_t liodn_s)45f698e9f3SAneesh Bansal int sec_config_pamu_table(uint32_t liodn_ns, uint32_t liodn_s)
46f698e9f3SAneesh Bansal {
47f698e9f3SAneesh Bansal 	struct pamu_addr_tbl tbl;
48f698e9f3SAneesh Bansal 	int num_entries = 0;
49f698e9f3SAneesh Bansal 	int ret = 0;
50f698e9f3SAneesh Bansal 
51f698e9f3SAneesh Bansal 	construct_pamu_addr_table(&tbl, &num_entries);
52f698e9f3SAneesh Bansal 
53f698e9f3SAneesh Bansal 	ret = config_pamu(&tbl, num_entries, liodn_ns);
54f698e9f3SAneesh Bansal 	if (ret)
55f698e9f3SAneesh Bansal 		return ret;
56f698e9f3SAneesh Bansal 
57f698e9f3SAneesh Bansal 	ret = config_pamu(&tbl, num_entries, liodn_s);
58f698e9f3SAneesh Bansal 	if (ret)
59f698e9f3SAneesh Bansal 		return ret;
60f698e9f3SAneesh Bansal 
61f698e9f3SAneesh Bansal 	return ret;
62f698e9f3SAneesh Bansal }
63