2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (C) 2008 Semihalf, Rafal Jaworowski
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include "opt_platform.h"
33 #include <sys/param.h>
34 #include <sys/systm.h>
36 #include <sys/mutex.h>
37 #include <sys/reboot.h>
41 #include <vm/vm_param.h>
44 #include <machine/cpu.h>
45 #include <machine/cpufunc.h>
46 #include <machine/machdep.h>
47 #include <machine/pio.h>
48 #include <machine/spr.h>
50 #include <dev/fdt/fdt_common.h>
52 #include <dev/fdt/fdt_common.h>
53 #include <dev/ofw/ofw_bus.h>
54 #include <dev/ofw/ofw_bus_subr.h>
55 #include <dev/ofw/openfirm.h>
57 #include <powerpc/mpc85xx/mpc85xx.h>
60 * MPC85xx system specific routines
64 ccsr_read4(uintptr_t addr)
66 volatile uint32_t *ptr = (void *)addr;
72 ccsr_write4(uintptr_t addr, uint32_t val)
74 volatile uint32_t *ptr = (void *)addr;
86 ver = SVR_VER(mfspr(SPR_SVR));
114 law_write(uint32_t n, uint64_t bar, uint32_t sr)
117 if (mpc85xx_is_qoriq()) {
118 ccsr_write4(OCP85XX_LAWBARH(n), bar >> 32);
119 ccsr_write4(OCP85XX_LAWBARL(n), bar);
120 ccsr_write4(OCP85XX_LAWSR_QORIQ(n), sr);
121 ccsr_read4(OCP85XX_LAWSR_QORIQ(n));
123 ccsr_write4(OCP85XX_LAWBAR(n), bar >> 12);
124 ccsr_write4(OCP85XX_LAWSR_85XX(n), sr);
125 ccsr_read4(OCP85XX_LAWSR_85XX(n));
129 * The last write to LAWAR should be followed by a read
130 * of LAWAR before any device try to use any of windows.
131 * What more the read of LAWAR should be followed by isync
139 law_read(uint32_t n, uint64_t *bar, uint32_t *sr)
142 if (mpc85xx_is_qoriq()) {
143 *bar = (uint64_t)ccsr_read4(OCP85XX_LAWBARH(n)) << 32 |
144 ccsr_read4(OCP85XX_LAWBARL(n));
145 *sr = ccsr_read4(OCP85XX_LAWSR_QORIQ(n));
147 *bar = (uint64_t)ccsr_read4(OCP85XX_LAWBAR(n)) << 12;
148 *sr = ccsr_read4(OCP85XX_LAWSR_85XX(n));
159 law_max = law_getmax();
161 for (i = 0; i < law_max; i++) {
162 law_read(i, &bar, &sr);
163 if ((sr & 0x80000000) == 0)
170 #define _LAW_SR(trgt,size) (0x80000000 | (trgt << 20) | \
171 (flsl(size + (size - 1)) - 2))
174 law_enable(int trgt, uint64_t bar, uint32_t size)
183 law_max = law_getmax();
184 sr = _LAW_SR(trgt, size);
186 /* Bail if already programmed. */
187 for (i = 0; i < law_max; i++) {
188 law_read(i, &bar_tmp, &sr_tmp);
189 if (sr == sr_tmp && bar == bar_tmp)
193 /* Find an unused access window. */
199 law_write(i, bar, sr);
204 law_disable(int trgt, uint64_t bar, uint32_t size)
210 law_max = law_getmax();
211 sr = _LAW_SR(trgt, size);
213 /* Find and disable requested LAW. */
214 for (i = 0; i < law_max; i++) {
215 law_read(i, &bar_tmp, &sr_tmp);
216 if (sr == sr_tmp && bar == bar_tmp) {
226 law_pci_target(struct resource *res, int *trgt_mem, int *trgt_io)
232 ver = SVR_VER(mfspr(SPR_SVR));
234 start = rman_get_start(res) & 0xf000;
249 if (ver == SVR_MPC8548E || ver == SVR_MPC8548)
256 if (ver == SVR_MPC8548E || ver == SVR_MPC8548)
275 /* Flash invalidate the CPC and clear all the locks */
276 ccsr_write4(OCP85XX_CPC_CSR0, OCP85XX_CPC_CSR0_FI |
277 OCP85XX_CPC_CSR0_LFC);
278 while (ccsr_read4(OCP85XX_CPC_CSR0) & (OCP85XX_CPC_CSR0_FI |
279 OCP85XX_CPC_CSR0_LFC))
287 ccsr_write4(OCP85XX_CPC_CSR0, OCP85XX_CPC_CSR0_CE |
288 OCP85XX_CPC_CSR0_PE);
289 /* Read back to sync write */
290 ccsr_read4(OCP85XX_CPC_CSR0);
294 mpc85xx_enable_l3_cache(void)
296 uint32_t csr, size, ver;
298 /* Enable L3 CoreNet Platform Cache (CPC) */
299 ver = SVR_VER(mfspr(SPR_SVR));
300 if (ver == SVR_P2041 || ver == SVR_P2041E || ver == SVR_P3041 ||
301 ver == SVR_P3041E || ver == SVR_P5020 || ver == SVR_P5020E) {
302 csr = ccsr_read4(OCP85XX_CPC_CSR0);
303 if ((csr & OCP85XX_CPC_CSR0_CE) == 0) {
308 csr = ccsr_read4(OCP85XX_CPC_CSR0);
309 if ((boothowto & RB_VERBOSE) != 0 ||
310 (csr & OCP85XX_CPC_CSR0_CE) == 0) {
311 size = OCP85XX_CPC_CFG0_SZ_K(ccsr_read4(OCP85XX_CPC_CFG0));
312 printf("L3 Corenet Platform Cache: %d KB %sabled\n",
313 size, (csr & OCP85XX_CPC_CSR0_CE) == 0 ?
320 mpc85xx_is_qoriq(void)
322 uint16_t pvr = mfpvr() >> 16;
324 /* QorIQ register set is only in e500mc and derivative core based SoCs. */
325 if (pvr == FSL_E500mc || pvr == FSL_E5500 || pvr == FSL_E6500)
332 mpc85xx_get_platform_clock(void)
335 static uint32_t freq;
340 soc = OF_finddevice("/soc");
342 /* freq isn't modified on error. */
343 OF_getencprop(soc, "bus-frequency", (void *)&freq, sizeof(freq));
349 mpc85xx_get_system_clock(void)
353 freq = mpc85xx_get_platform_clock();