summaryrefslogtreecommitdiff
path: root/arch/arm/mach-uniphier/cache_uniphier.c
blob: e47f977fe5a50e368c39c4136da5e2375305dd60 (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
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
 * Copyright (C) 2012-2014 Panasonic Corporation
 *   Author: Masahiro Yamada <yamada.m@jp.panasonic.com>
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
#include <asm/io.h>
#include <asm/armv7.h>
#include <asm/arch/ssc-regs.h>

#ifdef CONFIG_UNIPHIER_L2CACHE_ON
static void uniphier_cache_maint_all(u32 operation)
{
	/* try until the command is successfully set */
	do {
		writel(SSCOQM_S_ALL | SSCOQM_CE | operation, SSCOQM);
	} while (readl(SSCOPPQSEF) & (SSCOPPQSEF_FE | SSCOPPQSEF_OE));

	/* wait until the operation is completed */
	while (readl(SSCOLPQS) != SSCOLPQS_EF)
		;

	/* clear the complete notification flag */
	writel(SSCOLPQS_EF, SSCOLPQS);

	writel(SSCOPE_CM_SYNC, SSCOPE); /* drain internal buffers */
	readl(SSCOPE); /* need a read back to confirm */
}

void v7_outer_cache_flush_all(void)
{
	uniphier_cache_maint_all(SSCOQM_CM_WB_INV);
}

void v7_outer_cache_inval_all(void)
{
	uniphier_cache_maint_all(SSCOQM_CM_INV);
}

static void __uniphier_cache_maint_range(u32 start, u32 size, u32 operation)
{
	/* try until the command is successfully set */
	do {
		writel(SSCOQM_S_ADDRESS | SSCOQM_CE | operation, SSCOQM);
		writel(start, SSCOQAD);
		writel(size, SSCOQSZ);

	} while (readl(SSCOPPQSEF) & (SSCOPPQSEF_FE | SSCOPPQSEF_OE));

	/* wait until the operation is completed */
	while (readl(SSCOLPQS) != SSCOLPQS_EF)
		;

	/* clear the complete notification flag */
	writel(SSCOLPQS_EF, SSCOLPQS);
}

static void uniphier_cache_maint_range(u32 start, u32 end, u32 operation)
{
	u32 size;

	/*
	 * If start address is not aligned to cache-line,
	 * do cache operation for the first cache-line
	 */
	start = start & ~(SSC_LINE_SIZE - 1);

	if (start == 0 && end >= (u32)(-SSC_LINE_SIZE)) {
		/* this means cache operation for all range */
		uniphier_cache_maint_all(operation);
		return;
	}

	/*
	 * If end address is not aligned to cache-line,
	 * do cache operation for the last cache-line
	 */
	size = (end - start + SSC_LINE_SIZE - 1) & ~(SSC_LINE_SIZE - 1);

	while (size) {
		u32 chunk_size = size > SSC_RANGE_OP_MAX_SIZE ?
						SSC_RANGE_OP_MAX_SIZE : size;
		__uniphier_cache_maint_range(start, chunk_size, operation);

		start += chunk_size;
		size -= chunk_size;
	}

	writel(SSCOPE_CM_SYNC, SSCOPE); /* drain internal buffers */
	readl(SSCOPE); /* need a read back to confirm */
}

void v7_outer_cache_flush_range(u32 start, u32 end)
{
	uniphier_cache_maint_range(start, end, SSCOQM_CM_WB_INV);
}

void v7_outer_cache_inval_range(u32 start, u32 end)
{
	uniphier_cache_maint_range(start, end, SSCOQM_CM_INV);
}

void v7_outer_cache_enable(void)
{
	u32 tmp;
	tmp = readl(SSCC);
	tmp |= SSCC_ON;
	writel(tmp, SSCC);
}
#endif

void v7_outer_cache_disable(void)
{
	u32 tmp;
	tmp = readl(SSCC);
	tmp &= ~SSCC_ON;
	writel(tmp, SSCC);
}

void wakeup_secondary(void);

void enable_caches(void)
{
	uint32_t reg;

#ifdef CONFIG_UNIPHIER_SMP
	/*
	 * The secondary CPU must move to DDR,
	 * before L2 disable.
	 * On SPL, the Page Table is located on the L2.
	 */
	wakeup_secondary();
#endif
	/*
	 * UniPhier SoCs must use L2 cache for init stack pointer.
	 * We disable L2 and L1 in this order.
	 * If CONFIG_SYS_DCACHE_OFF is not defined,
	 * caches are enabled again with a new page table.
	 */

	/* L2 disable */
	v7_outer_cache_disable();

	/* L1 disable */
	reg = get_cr();
	reg &= ~(CR_C | CR_M);
	set_cr(reg);

#ifndef CONFIG_SYS_DCACHE_OFF
	dcache_enable();
#endif
}