xref: /openbmc/u-boot/arch/arm/mach-keystone/msmc.c (revision d9b23e26)
1 /*
2  * MSMC controller utilities
3  *
4  * (C) Copyright 2012-2014
5  *     Texas Instruments Incorporated, <www.ti.com>
6  *
7  * SPDX-License-Identifier:     GPL-2.0+
8  */
9 
10 #include <common.h>
11 #include <asm/arch/msmc.h>
12 
13 struct mpax {
14 	u32	mpaxl;
15 	u32	mpaxh;
16 };
17 
18 struct msms_regs {
19 	u32	pid;
20 	u32	_res_04;
21 	u32	smcerrar;
22 	u32	smcerrxr;
23 	u32	smedcc;
24 	u32	smcea;
25 	u32	smsecc;
26 	u32	smpfar;
27 	u32	smpfxr;
28 	u32	smpfr;
29 	u32	smpfcr;
30 	u32	_res_2c;
31 	u32	sbndc[8];
32 	u32	sbndm;
33 	u32	sbnde;
34 	u32	_res_58;
35 	u32	cfglck;
36 	u32	cfgulck;
37 	u32	cfglckstat;
38 	u32	sms_mpax_lck;
39 	u32	sms_mpax_ulck;
40 	u32	sms_mpax_lckstat;
41 	u32	ses_mpax_lck;
42 	u32	ses_mpax_ulck;
43 	u32	ses_mpax_lckstat;
44 	u32	smestat;
45 	u32	smirstat;
46 	u32	smirc;
47 	u32	smiestat;
48 	u32	smiec;
49 	u32	_res_94_c0[12];
50 	u32	smncerrar;
51 	u32	smncerrxr;
52 	u32	smncea;
53 	u32	_res_d0_1fc[76];
54 	struct mpax sms[16][8];
55 	struct mpax ses[16][8];
56 };
57 
58 
59 void msmc_share_all_segments(int priv_id)
60 {
61 	struct msms_regs *msmc = (struct msms_regs *)KS2_MSMC_CTRL_BASE;
62 	int j;
63 
64 	for (j = 0; j < 8; j++) {
65 		msmc->sms[priv_id][j].mpaxh &= 0xffffff7ful;
66 		msmc->ses[priv_id][j].mpaxh &= 0xffffff7ful;
67 	}
68 }
69 
70 void msmc_map_ses_segment(int priv_id, int ses_pair,
71 			  u32 src_pfn, u32 dst_pfn, enum mpax_seg_size size)
72 {
73 	struct msms_regs *msmc = (struct msms_regs *)KS2_MSMC_CTRL_BASE;
74 
75 	msmc->ses[priv_id][ses_pair].mpaxh = src_pfn << 12 |
76 					     (size & 0x1f) | 0x80;
77 	msmc->ses[priv_id][ses_pair].mpaxl = dst_pfn << 8 | 0x3f;
78 }
79 
80 void msmc_get_ses_mpax(int priv_id, int ses_pair, u32 *mpax)
81 {
82 	struct msms_regs *msmc = (struct msms_regs *)KS2_MSMC_CTRL_BASE;
83 
84 	*mpax++ = msmc->ses[priv_id][ses_pair].mpaxl;
85 	*mpax = msmc->ses[priv_id][ses_pair].mpaxh;
86 }
87 
88 void msmc_set_ses_mpax(int priv_id, int ses_pair, u32 *mpax)
89 {
90 	struct msms_regs *msmc = (struct msms_regs *)KS2_MSMC_CTRL_BASE;
91 
92 	msmc->ses[priv_id][ses_pair].mpaxl = *mpax++;
93 	msmc->ses[priv_id][ses_pair].mpaxh = *mpax;
94 }
95