blob: 836aae7b86b5e1260d809d4cb32bc15bb5129288 [file] [log] [blame]
Konstantin Porotchkin402fcf12018-02-26 16:04:25 +02001/*
2 * Copyright (C) 2018 Marvell International Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 * https://spdx.org/licenses
6 */
7
8/* LLC driver is the Last Level Cache (L3C) driver
9 * for Marvell SoCs in AP806, AP807, and AP810
10 */
11
Konstantin Porotchkin402fcf12018-02-26 16:04:25 +020012#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013
14#include <arch_helpers.h>
15#include <drivers/marvell/cache_llc.h>
16#include <drivers/marvell/ccu.h>
17#include <lib/mmio.h>
18
Konstantin Porotchkin402fcf12018-02-26 16:04:25 +020019#include <mvebu_def.h>
20
21#define CCU_HTC_CR(ap_index) (MVEBU_CCU_BASE(ap_index) + 0x200)
22#define CCU_SET_POC_OFFSET 5
23
24extern void ca72_l2_enable_unique_clean(void);
25
26void llc_cache_sync(int ap_index)
27{
28 mmio_write_32(LLC_SYNC(ap_index), 0);
29 /* Atomic write, no need to wait */
30}
31
32void llc_flush_all(int ap_index)
33{
Konstantin Porotchkinfa8c1302019-03-25 15:35:41 +020034 mmio_write_32(LLC_CLEAN_INV_WAY(ap_index), LLC_ALL_WAYS_MASK);
Konstantin Porotchkin402fcf12018-02-26 16:04:25 +020035 llc_cache_sync(ap_index);
36}
37
38void llc_clean_all(int ap_index)
39{
Konstantin Porotchkinfa8c1302019-03-25 15:35:41 +020040 mmio_write_32(LLC_CLEAN_WAY(ap_index), LLC_ALL_WAYS_MASK);
Konstantin Porotchkin402fcf12018-02-26 16:04:25 +020041 llc_cache_sync(ap_index);
42}
43
44void llc_inv_all(int ap_index)
45{
Konstantin Porotchkinfa8c1302019-03-25 15:35:41 +020046 mmio_write_32(LLC_INV_WAY(ap_index), LLC_ALL_WAYS_MASK);
Konstantin Porotchkin402fcf12018-02-26 16:04:25 +020047 llc_cache_sync(ap_index);
48}
49
50void llc_disable(int ap_index)
51{
52 llc_flush_all(ap_index);
53 mmio_write_32(LLC_CTRL(ap_index), 0);
54 dsbishst();
55}
56
57void llc_enable(int ap_index, int excl_mode)
58{
59 uint32_t val;
60
61 dsbsy();
62 llc_inv_all(ap_index);
63 dsbsy();
64
65 val = LLC_CTRL_EN;
66 if (excl_mode)
67 val |= LLC_EXCLUSIVE_EN;
68
69 mmio_write_32(LLC_CTRL(ap_index), val);
70 dsbsy();
71}
72
73int llc_is_exclusive(int ap_index)
74{
75 uint32_t reg;
76
77 reg = mmio_read_32(LLC_CTRL(ap_index));
78
79 if ((reg & (LLC_CTRL_EN | LLC_EXCLUSIVE_EN)) ==
80 (LLC_CTRL_EN | LLC_EXCLUSIVE_EN))
81 return 1;
82
83 return 0;
84}
85
86void llc_runtime_enable(int ap_index)
87{
88 uint32_t reg;
89
90 reg = mmio_read_32(LLC_CTRL(ap_index));
91 if (reg & LLC_CTRL_EN)
92 return;
93
94 INFO("Enabling LLC\n");
95
96 /*
97 * Enable L2 UniqueClean evictions with data
98 * Note: this configuration assumes that LLC is configured
99 * in exclusive mode.
100 * Later on in the code this assumption will be validated
101 */
102 ca72_l2_enable_unique_clean();
103 llc_enable(ap_index, 1);
104
105 /* Set point of coherency to DDR.
106 * This is required by units which have SW cache coherency
107 */
108 reg = mmio_read_32(CCU_HTC_CR(ap_index));
109 reg |= (0x1 << CCU_SET_POC_OFFSET);
110 mmio_write_32(CCU_HTC_CR(ap_index), reg);
111}
Konstantin Porotchkin2ef36a32019-03-31 16:58:11 +0300112
113#if LLC_SRAM
114void llc_sram_enable(int ap_index)
115{
116 uint32_t tc, way;
117 uint32_t way_addr;
118
119 /* Lockdown all available ways for all traffic classes */
120 for (tc = 0; tc < LLC_TC_NUM; tc++)
121 mmio_write_32(LLC_TCN_LOCK(ap_index, tc), LLC_WAY_MASK);
122
123 /* Clear the high bits of SRAM address */
124 mmio_write_32(LLC_BANKED_MNT_AHR(ap_index), 0);
125
126 way_addr = PLAT_MARVELL_TRUSTED_RAM_BASE;
127 for (way = 0; way < LLC_WAYS; way++) {
128 /* Trigger allocation block command */
129 mmio_write_32(LLC_BLK_ALOC(ap_index),
130 LLC_BLK_ALOC_BASE_ADDR(way_addr) |
131 LLC_BLK_ALOC_WAY_DATA_CLR |
132 LLC_BLK_ALOC_WAY_ID(way));
133 way_addr += LLC_WAY_SIZE;
134 }
135 llc_enable(ap_index, 1);
136}
137
138void llc_sram_disable(int ap_index)
139{
140 uint32_t tc;
141
142 /* Disable the line lockings */
143 for (tc = 0; tc < LLC_TC_NUM; tc++)
144 mmio_write_32(LLC_TCN_LOCK(ap_index, tc), 0);
145
146 /* Invalidate all ways */
147 llc_inv_all(ap_index);
148}
149#endif /* LLC_SRAM */