summaryrefslogtreecommitdiff
path: root/src/soc/mediatek/mt8192/devapc.c
blob: 96bd2bdc04410e59e2366e11942870dba7ec3140 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* SPDX-License-Identifier: GPL-2.0-only */

#include <soc/devapc.h>

static void *getreg(uintptr_t base, unsigned int offset)
{
	return (void *)(base + offset);
}

static void infra_master_init(uintptr_t base)
{
	/* Sidband */
	SET32_BITFIELDS(getreg(base, MAS_SEC_0), SCP_SSPM_SEC, 1, CPU_EB_SEC, 1);

	/* Domain */
	SET32_BITFIELDS(getreg(base, MAS_DOM_0), PCIE_DOM, MAS_DOMAIN_1);
	SET32_BITFIELDS(getreg(base, MAS_DOM_1), SCP_SSPM_DOM, MAS_DOMAIN_2,
			CPU_EB_DOM, MAS_DOMAIN_2);

	/*
	 * Domain Remap: TINYSYS to non-EMI (3-bit to 4-bit)
	 *     1. SCP from 3 to 3
	 *     2. DSP from 4 to 4
	 *     3. others from XXX to 15
	 */
	SET32_BITFIELDS(getreg(base, DOM_REMAP_0_0),
			FOUR_BIT_DOM_REMAP_0, MAS_DOMAIN_15,
			FOUR_BIT_DOM_REMAP_1, MAS_DOMAIN_15,
			FOUR_BIT_DOM_REMAP_2, MAS_DOMAIN_15,
			FOUR_BIT_DOM_REMAP_3, MAS_DOMAIN_3,
			FOUR_BIT_DOM_REMAP_4, MAS_DOMAIN_4,
			FOUR_BIT_DOM_REMAP_5, MAS_DOMAIN_15,
			FOUR_BIT_DOM_REMAP_6, MAS_DOMAIN_15,
			FOUR_BIT_DOM_REMAP_7, MAS_DOMAIN_15);

	/*
	 * Domain Remap: MMSYS slave domain remap (4-bit to 2-bit)
	 *     1. From domain 0       to domain 0 (no protection for all)
	 *     2. From domain 1, 2, 4 to domain 1 (forbidden for all)
	 *     3. From domain 3       to domain 3
	 *     4. others from XXX     to domain 0
	 */
	SET32_BITFIELDS(getreg(base, DOM_REMAP_0_0),
			TWO_BIT_DOM_REMAP_0, MAS_DOMAIN_0,
			TWO_BIT_DOM_REMAP_1, MAS_DOMAIN_1,
			TWO_BIT_DOM_REMAP_2, MAS_DOMAIN_1,
			TWO_BIT_DOM_REMAP_3, MAS_DOMAIN_3,
			TWO_BIT_DOM_REMAP_4, MAS_DOMAIN_1);
}

static void peri_master_init(uintptr_t base)
{
	/* Domain */
	SET32_BITFIELDS(getreg(base, MAS_DOM_0), SPM_DOM, MAS_DOMAIN_2);

	/*
	 * Domain Remap: CONNSYS slave domain remap (4-bit to 2-bit)
	 *     1. From domain 0     to domain 0 (no protection for all)
	 *     2. From domain 1 ~ 4 to domain 1 (forbidden for all)
	 *     3. others from XXX   to domain 0
	 */
	SET32_BITFIELDS(getreg(base, DOM_REMAP_1_0),
			TWO_BIT_DOM_REMAP_0, MAS_DOMAIN_0,
			TWO_BIT_DOM_REMAP_1, MAS_DOMAIN_1,
			TWO_BIT_DOM_REMAP_2, MAS_DOMAIN_1,
			TWO_BIT_DOM_REMAP_3, MAS_DOMAIN_1,
			TWO_BIT_DOM_REMAP_4, MAS_DOMAIN_1);

	/*
	 * Domain Remap: TINYSYS slave domain remap (4-bit to 3-bit)
	 *     1. From domain 0     to domain 0 (no protection for all)
	 *     2. From domain 1 ~ 4 to domain 1 (forbidden for all)
	 *     3. others from XXX   to domain 0
	 */
	SET32_BITFIELDS(getreg(base, DOM_REMAP_0_0),
			THREE_BIT_DOM_REMAP_0, MAS_DOMAIN_0,
			THREE_BIT_DOM_REMAP_1, MAS_DOMAIN_1,
			THREE_BIT_DOM_REMAP_2, MAS_DOMAIN_1,
			THREE_BIT_DOM_REMAP_3, MAS_DOMAIN_1,
			THREE_BIT_DOM_REMAP_4, MAS_DOMAIN_1);
}

static void fmem_master_init(uintptr_t base)
{
	/*
	 * Domain Remap: TINYSYS to EMI (3-bit to 4-bit)
	 *     1. SCP from 3 to 3
	 *     2. DSP from 4 to 4
	 *     3. others from XXX to 15
	 */
	SET32_BITFIELDS(getreg(base, DOM_REMAP_0_0),
			FOUR_BIT_DOM_REMAP_0, MAS_DOMAIN_15,
			FOUR_BIT_DOM_REMAP_1, MAS_DOMAIN_15,
			FOUR_BIT_DOM_REMAP_2, MAS_DOMAIN_15,
			FOUR_BIT_DOM_REMAP_3, MAS_DOMAIN_3,
			FOUR_BIT_DOM_REMAP_4, MAS_DOMAIN_4,
			FOUR_BIT_DOM_REMAP_5, MAS_DOMAIN_15,
			FOUR_BIT_DOM_REMAP_6, MAS_DOMAIN_15,
			FOUR_BIT_DOM_REMAP_7, MAS_DOMAIN_15);
}

static void scp_master_init(uintptr_t base)
{
	write32(getreg(base, SCP_DOM), MAS_DOMAIN_3);
	write32(getreg(base, ADSP_DOM), MAS_DOMAIN_4);

	/* Let SCP_DOM and ADSP_DOM registers be read-only for security */
	write32(getreg(base, ONETIME_LOCK), 0x5);
}

struct devapc_init {
	uintptr_t base;
	void (*init)(uintptr_t base);
} devapc_init[DEVAPC_AO_MAX] = {
	{ DEVAPC_INFRA_AO_BASE, infra_master_init },
	{ DEVAPC_PERI_AO_BASE, peri_master_init },
	{ DEVAPC_PERI2_AO_BASE, NULL },
	{ DEVAPC_PERI_PAR_AO_BASE, NULL },
	{ DEVAPC_FMEM_AO_BASE, fmem_master_init },
	{ SCP_CFG_BASE, scp_master_init },
};

void dapc_init(void)
{
	int i;
	uintptr_t devapc_ao_base;
	void (*init_func)(uintptr_t base);

	for (i = 0; i < ARRAY_SIZE(devapc_init); i++) {
		devapc_ao_base = devapc_init[i].base;
		init_func = devapc_init[i].init;

		/* Init dapc */
		write32(getreg(devapc_ao_base, AO_APC_CON), 0x0);
		write32(getreg(devapc_ao_base, AO_APC_CON), 0x1);

		/* Init master */
		if (init_func)
			init_func(devapc_ao_base);
	}
}