xref: /freebsd/sys/powerpc/mpc85xx/platform_mpc85xx.c (revision fdafd315ad0d0f28a11b9fb4476a9ab059c62b92)
1302acc2eSNathan Whitehorn /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
371e3c308SPedro F. Giffuni  *
4302acc2eSNathan Whitehorn  * Copyright (c) 2008-2012 Semihalf.
5302acc2eSNathan Whitehorn  * All rights reserved.
6302acc2eSNathan Whitehorn  *
7302acc2eSNathan Whitehorn  * Redistribution and use in source and binary forms, with or without
8302acc2eSNathan Whitehorn  * modification, are permitted provided that the following conditions
9302acc2eSNathan Whitehorn  * are met:
10302acc2eSNathan Whitehorn  *
11302acc2eSNathan Whitehorn  * 1. Redistributions of source code must retain the above copyright
12302acc2eSNathan Whitehorn  *    notice, this list of conditions and the following disclaimer.
13302acc2eSNathan Whitehorn  * 2. Redistributions in binary form must reproduce the above copyright
14302acc2eSNathan Whitehorn  *    notice, this list of conditions and the following disclaimer in the
15302acc2eSNathan Whitehorn  *    documentation and/or other materials provided with the distribution.
16302acc2eSNathan Whitehorn  *
17302acc2eSNathan Whitehorn  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18302acc2eSNathan Whitehorn  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19302acc2eSNathan Whitehorn  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20302acc2eSNathan Whitehorn  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21302acc2eSNathan Whitehorn  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22302acc2eSNathan Whitehorn  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23302acc2eSNathan Whitehorn  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24302acc2eSNathan Whitehorn  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25302acc2eSNathan Whitehorn  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26302acc2eSNathan Whitehorn  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27302acc2eSNathan Whitehorn  */
28302acc2eSNathan Whitehorn 
293f068cbfSJustin Hibbits #include "opt_platform.h"
30*fdafd315SWarner Losh 
31302acc2eSNathan Whitehorn #include <sys/param.h>
32302acc2eSNathan Whitehorn #include <sys/systm.h>
33302acc2eSNathan Whitehorn #include <sys/kernel.h>
340d69f00bSJustin Hibbits #include <sys/module.h>
35302acc2eSNathan Whitehorn #include <sys/bus.h>
36302acc2eSNathan Whitehorn #include <sys/pcpu.h>
37302acc2eSNathan Whitehorn #include <sys/proc.h>
38302acc2eSNathan Whitehorn #include <sys/smp.h>
39302acc2eSNathan Whitehorn 
40302acc2eSNathan Whitehorn #include <machine/bus.h>
41302acc2eSNathan Whitehorn #include <machine/cpu.h>
42302acc2eSNathan Whitehorn #include <machine/hid.h>
43253902b4SJustin Hibbits #include <machine/_inttypes.h>
443f068cbfSJustin Hibbits #include <machine/machdep.h>
45253902b4SJustin Hibbits #include <machine/md_var.h>
46302acc2eSNathan Whitehorn #include <machine/platform.h>
47302acc2eSNathan Whitehorn #include <machine/platformvar.h>
48302acc2eSNathan Whitehorn #include <machine/smp.h>
49302acc2eSNathan Whitehorn #include <machine/spr.h>
50302acc2eSNathan Whitehorn #include <machine/vmparam.h>
51302acc2eSNathan Whitehorn 
52302acc2eSNathan Whitehorn #include <dev/fdt/fdt_common.h>
53302acc2eSNathan Whitehorn #include <dev/ofw/ofw_bus.h>
54302acc2eSNathan Whitehorn #include <dev/ofw/ofw_bus_subr.h>
55302acc2eSNathan Whitehorn #include <dev/ofw/openfirm.h>
56302acc2eSNathan Whitehorn 
5752cfe485SNathan Whitehorn #include <vm/vm.h>
5852cfe485SNathan Whitehorn #include <vm/pmap.h>
59253902b4SJustin Hibbits #include <vm/vm_extern.h>
6052cfe485SNathan Whitehorn 
61302acc2eSNathan Whitehorn #include <powerpc/mpc85xx/mpc85xx.h>
62302acc2eSNathan Whitehorn 
63302acc2eSNathan Whitehorn #include "platform_if.h"
64302acc2eSNathan Whitehorn 
65302acc2eSNathan Whitehorn #ifdef SMP
66302acc2eSNathan Whitehorn extern void *ap_pcpu;
67302acc2eSNathan Whitehorn extern vm_paddr_t kernload;		/* Kernel physical load address */
68302acc2eSNathan Whitehorn extern uint8_t __boot_page[];		/* Boot page body */
69ab3f2a38SBrandon Bergren extern vm_paddr_t bp_kernload;		/* Boot page copy of kernload */
70ab3f2a38SBrandon Bergren extern vm_offset_t bp_virtaddr;		/* Virtual address of boot page */
71ea32838aSJustin Hibbits extern vm_offset_t __startkernel;
72253902b4SJustin Hibbits 
73253902b4SJustin Hibbits struct cpu_release {
74253902b4SJustin Hibbits 	uint32_t entry_h;
75253902b4SJustin Hibbits 	uint32_t entry_l;
76253902b4SJustin Hibbits 	uint32_t r3_h;
77253902b4SJustin Hibbits 	uint32_t r3_l;
78253902b4SJustin Hibbits 	uint32_t reserved;
79253902b4SJustin Hibbits 	uint32_t pir;
80253902b4SJustin Hibbits };
81302acc2eSNathan Whitehorn #endif
82302acc2eSNathan Whitehorn 
83302acc2eSNathan Whitehorn extern uint32_t *bootinfo;
84b2f831c0SJustin Hibbits vm_paddr_t ccsrbar_pa;
8552cfe485SNathan Whitehorn vm_offset_t ccsrbar_va;
86b2f831c0SJustin Hibbits vm_size_t ccsrbar_size;
87302acc2eSNathan Whitehorn 
88302acc2eSNathan Whitehorn static int cpu, maxcpu;
89302acc2eSNathan Whitehorn 
900d69f00bSJustin Hibbits static device_t rcpm_dev;
910d69f00bSJustin Hibbits static void dummy_freeze(device_t, bool);
920d69f00bSJustin Hibbits 
930d69f00bSJustin Hibbits static void (*freeze_timebase)(device_t, bool) = dummy_freeze;
940d69f00bSJustin Hibbits 
95302acc2eSNathan Whitehorn static int mpc85xx_probe(platform_t);
96c1cb22d7SNathan Whitehorn static void mpc85xx_mem_regions(platform_t, struct mem_region *phys,
97c1cb22d7SNathan Whitehorn     int *physsz, struct mem_region *avail, int *availsz);
98302acc2eSNathan Whitehorn static u_long mpc85xx_timebase_freq(platform_t, struct cpuref *cpuref);
99302acc2eSNathan Whitehorn static int mpc85xx_smp_first_cpu(platform_t, struct cpuref *cpuref);
100302acc2eSNathan Whitehorn static int mpc85xx_smp_next_cpu(platform_t, struct cpuref *cpuref);
101302acc2eSNathan Whitehorn static int mpc85xx_smp_get_bsp(platform_t, struct cpuref *cpuref);
102302acc2eSNathan Whitehorn static int mpc85xx_smp_start_cpu(platform_t, struct pcpu *cpu);
103de2dd83fSNathan Whitehorn static void mpc85xx_smp_timebase_sync(platform_t, u_long tb, int ap);
104302acc2eSNathan Whitehorn 
105302acc2eSNathan Whitehorn static void mpc85xx_reset(platform_t);
106302acc2eSNathan Whitehorn 
107302acc2eSNathan Whitehorn static platform_method_t mpc85xx_methods[] = {
108302acc2eSNathan Whitehorn 	PLATFORMMETHOD(platform_probe,		mpc85xx_probe),
109302acc2eSNathan Whitehorn 	PLATFORMMETHOD(platform_attach,		mpc85xx_attach),
110302acc2eSNathan Whitehorn 	PLATFORMMETHOD(platform_mem_regions,	mpc85xx_mem_regions),
111302acc2eSNathan Whitehorn 	PLATFORMMETHOD(platform_timebase_freq,	mpc85xx_timebase_freq),
112302acc2eSNathan Whitehorn 
113302acc2eSNathan Whitehorn 	PLATFORMMETHOD(platform_smp_first_cpu,	mpc85xx_smp_first_cpu),
114302acc2eSNathan Whitehorn 	PLATFORMMETHOD(platform_smp_next_cpu,	mpc85xx_smp_next_cpu),
115302acc2eSNathan Whitehorn 	PLATFORMMETHOD(platform_smp_get_bsp,	mpc85xx_smp_get_bsp),
116302acc2eSNathan Whitehorn 	PLATFORMMETHOD(platform_smp_start_cpu,	mpc85xx_smp_start_cpu),
117de2dd83fSNathan Whitehorn 	PLATFORMMETHOD(platform_smp_timebase_sync, mpc85xx_smp_timebase_sync),
118302acc2eSNathan Whitehorn 
119302acc2eSNathan Whitehorn 	PLATFORMMETHOD(platform_reset,		mpc85xx_reset),
120302acc2eSNathan Whitehorn 
121302acc2eSNathan Whitehorn 	PLATFORMMETHOD_END
122302acc2eSNathan Whitehorn };
123302acc2eSNathan Whitehorn 
124fa7a1ca7SJustin Hibbits DEFINE_CLASS_0(mpc85xx, mpc85xx_platform, mpc85xx_methods, 0);
125302acc2eSNathan Whitehorn 
126302acc2eSNathan Whitehorn PLATFORM_DEF(mpc85xx_platform);
127302acc2eSNathan Whitehorn 
128302acc2eSNathan Whitehorn static int
mpc85xx_probe(platform_t plat)129302acc2eSNathan Whitehorn mpc85xx_probe(platform_t plat)
130302acc2eSNathan Whitehorn {
131adbe2685SJustin Hibbits 	u_int pvr = (mfpvr() >> 16) & 0xFFFF;
132302acc2eSNathan Whitehorn 
133adbe2685SJustin Hibbits 	switch (pvr) {
134adbe2685SJustin Hibbits 		case FSL_E500v1:
135adbe2685SJustin Hibbits 		case FSL_E500v2:
136adbe2685SJustin Hibbits 		case FSL_E500mc:
137adbe2685SJustin Hibbits 		case FSL_E5500:
138adbe2685SJustin Hibbits 		case FSL_E6500:
139302acc2eSNathan Whitehorn 			return (BUS_PROBE_DEFAULT);
140adbe2685SJustin Hibbits 	}
141302acc2eSNathan Whitehorn 	return (ENXIO);
142302acc2eSNathan Whitehorn }
143302acc2eSNathan Whitehorn 
144fa7a1ca7SJustin Hibbits int
mpc85xx_attach(platform_t plat)145302acc2eSNathan Whitehorn mpc85xx_attach(platform_t plat)
146302acc2eSNathan Whitehorn {
14752cfe485SNathan Whitehorn 	phandle_t cpus, child, ccsr;
14852cfe485SNathan Whitehorn 	const char *soc_name_guesses[] = {"/soc", "soc", NULL};
14952cfe485SNathan Whitehorn 	const char **name;
15052cfe485SNathan Whitehorn 	pcell_t ranges[6], acells, pacells, scells;
15152cfe485SNathan Whitehorn 	uint64_t ccsrbar, ccsrsize;
152adbe2685SJustin Hibbits 	int i;
153302acc2eSNathan Whitehorn 
154302acc2eSNathan Whitehorn 	if ((cpus = OF_finddevice("/cpus")) != -1) {
155302acc2eSNathan Whitehorn 		for (maxcpu = 0, child = OF_child(cpus); child != 0;
156302acc2eSNathan Whitehorn 		    child = OF_peer(child), maxcpu++)
157302acc2eSNathan Whitehorn 			;
158302acc2eSNathan Whitehorn 	} else
159302acc2eSNathan Whitehorn 		maxcpu = 1;
160302acc2eSNathan Whitehorn 
161302acc2eSNathan Whitehorn 	/*
16252cfe485SNathan Whitehorn 	 * Locate CCSR region. Irritatingly, there is no way to find it
16352cfe485SNathan Whitehorn 	 * unless you already know where it is. Try to infer its location
16452cfe485SNathan Whitehorn 	 * from the device tree.
16552cfe485SNathan Whitehorn 	 */
16652cfe485SNathan Whitehorn 
16752cfe485SNathan Whitehorn 	ccsr = -1;
16852cfe485SNathan Whitehorn 	for (name = soc_name_guesses; *name != NULL && ccsr == -1; name++)
16952cfe485SNathan Whitehorn 		ccsr = OF_finddevice(*name);
17052cfe485SNathan Whitehorn 	if (ccsr == -1) {
17152cfe485SNathan Whitehorn 		char type[64];
17252cfe485SNathan Whitehorn 
17352cfe485SNathan Whitehorn 	 	/* That didn't work. Search for devices of type "soc" */
17452cfe485SNathan Whitehorn 		child = OF_child(OF_peer(0));
17552cfe485SNathan Whitehorn 		for (OF_child(child); child != 0; child = OF_peer(child)) {
17652cfe485SNathan Whitehorn 			if (OF_getprop(child, "device_type", type, sizeof(type))
17752cfe485SNathan Whitehorn 			    <= 0)
17852cfe485SNathan Whitehorn 				continue;
17952cfe485SNathan Whitehorn 
18052cfe485SNathan Whitehorn 			if (strcmp(type, "soc") == 0) {
18152cfe485SNathan Whitehorn 				ccsr = child;
18252cfe485SNathan Whitehorn 				break;
18352cfe485SNathan Whitehorn 			}
18452cfe485SNathan Whitehorn 		}
18552cfe485SNathan Whitehorn 	}
18652cfe485SNathan Whitehorn 
18752cfe485SNathan Whitehorn 	if (ccsr == -1)
18852cfe485SNathan Whitehorn 		panic("Could not locate CCSR window!");
18952cfe485SNathan Whitehorn 
19052cfe485SNathan Whitehorn 	OF_getprop(ccsr, "#size-cells", &scells, sizeof(scells));
19152cfe485SNathan Whitehorn 	OF_getprop(ccsr, "#address-cells", &acells, sizeof(acells));
19252cfe485SNathan Whitehorn 	OF_searchprop(OF_parent(ccsr), "#address-cells", &pacells,
19352cfe485SNathan Whitehorn 	    sizeof(pacells));
19452cfe485SNathan Whitehorn 	OF_getprop(ccsr, "ranges", ranges, sizeof(ranges));
19552cfe485SNathan Whitehorn 	ccsrbar = ccsrsize = 0;
19652cfe485SNathan Whitehorn 	for (i = acells; i < acells + pacells; i++) {
19752cfe485SNathan Whitehorn 		ccsrbar <<= 32;
19852cfe485SNathan Whitehorn 		ccsrbar |= ranges[i];
19952cfe485SNathan Whitehorn 	}
20052cfe485SNathan Whitehorn 	for (i = acells + pacells; i < acells + pacells + scells; i++) {
20152cfe485SNathan Whitehorn 		ccsrsize <<= 32;
20252cfe485SNathan Whitehorn 		ccsrsize |= ranges[i];
20352cfe485SNathan Whitehorn 	}
20452cfe485SNathan Whitehorn 	ccsrbar_va = pmap_early_io_map(ccsrbar, ccsrsize);
205b2f831c0SJustin Hibbits 	ccsrbar_pa = ccsrbar;
206b2f831c0SJustin Hibbits 	ccsrbar_size = ccsrsize;
20752cfe485SNathan Whitehorn 
2083f068cbfSJustin Hibbits 	mpc85xx_enable_l3_cache();
2093f068cbfSJustin Hibbits 
210302acc2eSNathan Whitehorn 	return (0);
211302acc2eSNathan Whitehorn }
212302acc2eSNathan Whitehorn 
213302acc2eSNathan Whitehorn void
mpc85xx_mem_regions(platform_t plat,struct mem_region * phys,int * physsz,struct mem_region * avail,int * availsz)214c1cb22d7SNathan Whitehorn mpc85xx_mem_regions(platform_t plat, struct mem_region *phys, int *physsz,
215c1cb22d7SNathan Whitehorn     struct mem_region *avail, int *availsz)
216302acc2eSNathan Whitehorn {
217302acc2eSNathan Whitehorn 
218302acc2eSNathan Whitehorn 	ofw_mem_regions(phys, physsz, avail, availsz);
219302acc2eSNathan Whitehorn }
220302acc2eSNathan Whitehorn 
221302acc2eSNathan Whitehorn static u_long
mpc85xx_timebase_freq(platform_t plat,struct cpuref * cpuref)222302acc2eSNathan Whitehorn mpc85xx_timebase_freq(platform_t plat, struct cpuref *cpuref)
223302acc2eSNathan Whitehorn {
224302acc2eSNathan Whitehorn 	u_long ticks;
225302acc2eSNathan Whitehorn 	phandle_t cpus, child;
226302acc2eSNathan Whitehorn 	pcell_t freq;
227302acc2eSNathan Whitehorn 
228302acc2eSNathan Whitehorn 	if (bootinfo != NULL) {
229302acc2eSNathan Whitehorn 		if (bootinfo[0] == 1) {
230302acc2eSNathan Whitehorn 			/* Backward compatibility. See 8-STABLE. */
231302acc2eSNathan Whitehorn 			ticks = bootinfo[3] >> 3;
232302acc2eSNathan Whitehorn 		} else {
233302acc2eSNathan Whitehorn 			/* Compatibility with Juniper's loader. */
234302acc2eSNathan Whitehorn 			ticks = bootinfo[5] >> 3;
235302acc2eSNathan Whitehorn 		}
236302acc2eSNathan Whitehorn 	} else
237302acc2eSNathan Whitehorn 		ticks = 0;
238302acc2eSNathan Whitehorn 
239302acc2eSNathan Whitehorn 	if ((cpus = OF_finddevice("/cpus")) == -1)
240302acc2eSNathan Whitehorn 		goto out;
241302acc2eSNathan Whitehorn 
242302acc2eSNathan Whitehorn 	if ((child = OF_child(cpus)) == 0)
243302acc2eSNathan Whitehorn 		goto out;
244302acc2eSNathan Whitehorn 
245302acc2eSNathan Whitehorn 	switch (OF_getproplen(child, "timebase-frequency")) {
246302acc2eSNathan Whitehorn 	case 4:
247302acc2eSNathan Whitehorn 	{
248302acc2eSNathan Whitehorn 		uint32_t tbase;
249302acc2eSNathan Whitehorn 		OF_getprop(child, "timebase-frequency", &tbase, sizeof(tbase));
250302acc2eSNathan Whitehorn 		ticks = tbase;
251302acc2eSNathan Whitehorn 		return (ticks);
252302acc2eSNathan Whitehorn 	}
253302acc2eSNathan Whitehorn 	case 8:
254302acc2eSNathan Whitehorn 	{
255302acc2eSNathan Whitehorn 		uint64_t tbase;
256302acc2eSNathan Whitehorn 		OF_getprop(child, "timebase-frequency", &tbase, sizeof(tbase));
257302acc2eSNathan Whitehorn 		ticks = tbase;
258302acc2eSNathan Whitehorn 		return (ticks);
259302acc2eSNathan Whitehorn 	}
260302acc2eSNathan Whitehorn 	default:
261302acc2eSNathan Whitehorn 		break;
262302acc2eSNathan Whitehorn 	}
263302acc2eSNathan Whitehorn 
264302acc2eSNathan Whitehorn 	freq = 0;
265302acc2eSNathan Whitehorn 	if (OF_getprop(child, "bus-frequency", (void *)&freq,
266302acc2eSNathan Whitehorn 	    sizeof(freq)) <= 0)
267302acc2eSNathan Whitehorn 		goto out;
268302acc2eSNathan Whitehorn 
2696cedae09SJustin Hibbits 	if (freq == 0)
2706cedae09SJustin Hibbits 		goto out;
2716cedae09SJustin Hibbits 
272302acc2eSNathan Whitehorn 	/*
273302acc2eSNathan Whitehorn 	 * Time Base and Decrementer are updated every 8 CCB bus clocks.
274302acc2eSNathan Whitehorn 	 * HID0[SEL_TBCLK] = 0
275302acc2eSNathan Whitehorn 	 */
2766cedae09SJustin Hibbits 	if (mpc85xx_is_qoriq())
2773f068cbfSJustin Hibbits 		ticks = freq / 32;
2786cedae09SJustin Hibbits 	else
279302acc2eSNathan Whitehorn 		ticks = freq / 8;
280302acc2eSNathan Whitehorn 
281302acc2eSNathan Whitehorn out:
282302acc2eSNathan Whitehorn 	if (ticks <= 0)
283302acc2eSNathan Whitehorn 		panic("Unable to determine timebase frequency!");
284302acc2eSNathan Whitehorn 
285302acc2eSNathan Whitehorn 	return (ticks);
286302acc2eSNathan Whitehorn }
287302acc2eSNathan Whitehorn 
288302acc2eSNathan Whitehorn static int
mpc85xx_smp_first_cpu(platform_t plat,struct cpuref * cpuref)289302acc2eSNathan Whitehorn mpc85xx_smp_first_cpu(platform_t plat, struct cpuref *cpuref)
290302acc2eSNathan Whitehorn {
291302acc2eSNathan Whitehorn 
292302acc2eSNathan Whitehorn 	cpu = 0;
293302acc2eSNathan Whitehorn 	cpuref->cr_cpuid = cpu;
294302acc2eSNathan Whitehorn 	cpuref->cr_hwref = cpuref->cr_cpuid;
295302acc2eSNathan Whitehorn 	if (bootverbose)
296302acc2eSNathan Whitehorn 		printf("powerpc_smp_first_cpu: cpuid %d\n", cpuref->cr_cpuid);
297302acc2eSNathan Whitehorn 	cpu++;
298302acc2eSNathan Whitehorn 
299302acc2eSNathan Whitehorn 	return (0);
300302acc2eSNathan Whitehorn }
301302acc2eSNathan Whitehorn 
302302acc2eSNathan Whitehorn static int
mpc85xx_smp_next_cpu(platform_t plat,struct cpuref * cpuref)303302acc2eSNathan Whitehorn mpc85xx_smp_next_cpu(platform_t plat, struct cpuref *cpuref)
304302acc2eSNathan Whitehorn {
305302acc2eSNathan Whitehorn 
306302acc2eSNathan Whitehorn 	if (cpu >= maxcpu)
307302acc2eSNathan Whitehorn 		return (ENOENT);
308302acc2eSNathan Whitehorn 
309302acc2eSNathan Whitehorn 	cpuref->cr_cpuid = cpu++;
310302acc2eSNathan Whitehorn 	cpuref->cr_hwref = cpuref->cr_cpuid;
311302acc2eSNathan Whitehorn 	if (bootverbose)
312302acc2eSNathan Whitehorn 		printf("powerpc_smp_next_cpu: cpuid %d\n", cpuref->cr_cpuid);
313302acc2eSNathan Whitehorn 
314302acc2eSNathan Whitehorn 	return (0);
315302acc2eSNathan Whitehorn }
316302acc2eSNathan Whitehorn 
317302acc2eSNathan Whitehorn static int
mpc85xx_smp_get_bsp(platform_t plat,struct cpuref * cpuref)318302acc2eSNathan Whitehorn mpc85xx_smp_get_bsp(platform_t plat, struct cpuref *cpuref)
319302acc2eSNathan Whitehorn {
320302acc2eSNathan Whitehorn 
321302acc2eSNathan Whitehorn 	cpuref->cr_cpuid = mfspr(SPR_PIR);
322302acc2eSNathan Whitehorn 	cpuref->cr_hwref = cpuref->cr_cpuid;
323302acc2eSNathan Whitehorn 
324302acc2eSNathan Whitehorn 	return (0);
325302acc2eSNathan Whitehorn }
326302acc2eSNathan Whitehorn 
327253902b4SJustin Hibbits #ifdef SMP
328253902b4SJustin Hibbits static int
mpc85xx_smp_start_cpu_epapr(platform_t plat,struct pcpu * pc)329253902b4SJustin Hibbits mpc85xx_smp_start_cpu_epapr(platform_t plat, struct pcpu *pc)
330253902b4SJustin Hibbits {
331253902b4SJustin Hibbits 	vm_paddr_t rel_pa, bptr;
332253902b4SJustin Hibbits 	volatile struct cpu_release *rel;
333253902b4SJustin Hibbits 	vm_offset_t rel_va, rel_page;
334253902b4SJustin Hibbits 	phandle_t node;
335253902b4SJustin Hibbits 	int i;
336253902b4SJustin Hibbits 
337253902b4SJustin Hibbits 	/* If we're calling this, the node already exists. */
338253902b4SJustin Hibbits 	node = OF_finddevice("/cpus");
339253902b4SJustin Hibbits 	for (i = 0, node = OF_child(node); i < pc->pc_cpuid;
340253902b4SJustin Hibbits 	    i++, node = OF_peer(node))
341253902b4SJustin Hibbits 		;
342253902b4SJustin Hibbits 	if (OF_getencprop(node, "cpu-release-addr", (pcell_t *)&rel_pa,
343253902b4SJustin Hibbits 	    sizeof(rel_pa)) == -1) {
344253902b4SJustin Hibbits 		return (ENOENT);
345253902b4SJustin Hibbits 	}
346253902b4SJustin Hibbits 
347253902b4SJustin Hibbits 	rel_page = kva_alloc(PAGE_SIZE);
348253902b4SJustin Hibbits 	if (rel_page == 0)
349253902b4SJustin Hibbits 		return (ENOMEM);
350253902b4SJustin Hibbits 
351253902b4SJustin Hibbits 	critical_enter();
352253902b4SJustin Hibbits 	rel_va = rel_page + (rel_pa & PAGE_MASK);
353253902b4SJustin Hibbits 	pmap_kenter(rel_page, rel_pa & ~PAGE_MASK);
354253902b4SJustin Hibbits 	rel = (struct cpu_release *)rel_va;
355870d94c5SJustin Hibbits 	bptr = pmap_kextract((uintptr_t)__boot_page);
356ab3f2a38SBrandon Bergren 
357253902b4SJustin Hibbits 	cpu_flush_dcache(__DEVOLATILE(struct cpu_release *,rel), sizeof(*rel));
358ab3f2a38SBrandon Bergren 	rel->pir = pc->pc_cpuid; __asm __volatile("sync" ::: "memory");
359ab3f2a38SBrandon Bergren 	rel->entry_h = (bptr >> 32); __asm __volatile("sync" ::: "memory");
360ab3f2a38SBrandon Bergren 	cpu_flush_dcache(__DEVOLATILE(struct cpu_release *,rel), sizeof(*rel));
361ab3f2a38SBrandon Bergren 	rel->entry_l = bptr & 0xffffffff; __asm __volatile("sync" ::: "memory");
362253902b4SJustin Hibbits 	cpu_flush_dcache(__DEVOLATILE(struct cpu_release *,rel), sizeof(*rel));
363253902b4SJustin Hibbits 	if (bootverbose)
364253902b4SJustin Hibbits 		printf("Waking up CPU %d via CPU release page %p\n",
365253902b4SJustin Hibbits 		    pc->pc_cpuid, rel);
366253902b4SJustin Hibbits 	critical_exit();
367253902b4SJustin Hibbits 	pmap_kremove(rel_page);
368253902b4SJustin Hibbits 	kva_free(rel_page, PAGE_SIZE);
369253902b4SJustin Hibbits 
370253902b4SJustin Hibbits 	return (0);
371253902b4SJustin Hibbits }
372253902b4SJustin Hibbits #endif
373253902b4SJustin Hibbits 
374302acc2eSNathan Whitehorn static int
mpc85xx_smp_start_cpu(platform_t plat,struct pcpu * pc)375302acc2eSNathan Whitehorn mpc85xx_smp_start_cpu(platform_t plat, struct pcpu *pc)
376302acc2eSNathan Whitehorn {
377302acc2eSNathan Whitehorn #ifdef SMP
3783f068cbfSJustin Hibbits 	vm_paddr_t bptr;
3793f068cbfSJustin Hibbits 	uint32_t reg;
380f60708c9SJustin Hibbits 	int timeout;
3813f068cbfSJustin Hibbits 	uintptr_t brr;
3823f068cbfSJustin Hibbits 	int cpuid;
383253902b4SJustin Hibbits 	int epapr_boot = 0;
3843f068cbfSJustin Hibbits 	uint32_t tgt;
3853f068cbfSJustin Hibbits 
3866cedae09SJustin Hibbits 	if (mpc85xx_is_qoriq()) {
3873f068cbfSJustin Hibbits 		reg = ccsr_read4(OCP85XX_COREDISR);
3883f068cbfSJustin Hibbits 		cpuid = pc->pc_cpuid;
3893f068cbfSJustin Hibbits 
3906cedae09SJustin Hibbits 		if ((reg & (1 << cpuid)) != 0) {
3913f068cbfSJustin Hibbits 		    printf("%s: CPU %d is disabled!\n", __func__, pc->pc_cpuid);
3923f068cbfSJustin Hibbits 		    return (-1);
3933f068cbfSJustin Hibbits 		}
3943f068cbfSJustin Hibbits 
3953f068cbfSJustin Hibbits 		brr = OCP85XX_BRR;
3966cedae09SJustin Hibbits 	} else {
3973f068cbfSJustin Hibbits 		brr = OCP85XX_EEBPCR;
3983f068cbfSJustin Hibbits 		cpuid = pc->pc_cpuid + 24;
3996cedae09SJustin Hibbits 	}
400f60708c9SJustin Hibbits 	bp_kernload = kernload;
401ab3f2a38SBrandon Bergren 	bp_virtaddr = (vm_offset_t)&__boot_page;
402253902b4SJustin Hibbits 	/*
403ab3f2a38SBrandon Bergren 	 * bp_kernload and bp_virtaddr are in the boot page.  Sync the cache
404ab3f2a38SBrandon Bergren 	 * because ePAPR booting has the other core(s) already running.
405253902b4SJustin Hibbits 	 */
4067599d2ddSJustin Hibbits 	cpu_flush_dcache(&bp_kernload, sizeof(bp_kernload));
407ab3f2a38SBrandon Bergren 	cpu_flush_dcache(&bp_virtaddr, sizeof(bp_virtaddr));
408253902b4SJustin Hibbits 
409253902b4SJustin Hibbits 	ap_pcpu = pc;
410253902b4SJustin Hibbits 	__asm __volatile("msync; isync");
411253902b4SJustin Hibbits 
412253902b4SJustin Hibbits 	/* First try the ePAPR way. */
413253902b4SJustin Hibbits 	if (mpc85xx_smp_start_cpu_epapr(plat, pc) == 0) {
414253902b4SJustin Hibbits 		epapr_boot = 1;
415253902b4SJustin Hibbits 		goto spin_wait;
416253902b4SJustin Hibbits 	}
4176cedae09SJustin Hibbits 
4183f068cbfSJustin Hibbits 	reg = ccsr_read4(brr);
4193f068cbfSJustin Hibbits 	if ((reg & (1 << cpuid)) != 0) {
420302acc2eSNathan Whitehorn 		printf("SMP: CPU %d already out of hold-off state!\n",
421302acc2eSNathan Whitehorn 		    pc->pc_cpuid);
422302acc2eSNathan Whitehorn 		return (ENXIO);
423302acc2eSNathan Whitehorn 	}
424302acc2eSNathan Whitehorn 
4253f068cbfSJustin Hibbits 	/* Flush caches to have our changes hit DRAM. */
4263f068cbfSJustin Hibbits 	cpu_flush_dcache(__boot_page, 4096);
4273f068cbfSJustin Hibbits 
428870d94c5SJustin Hibbits 	bptr = pmap_kextract((uintptr_t)__boot_page);
4293f068cbfSJustin Hibbits 	KASSERT((bptr & 0xfff) == 0,
4303f068cbfSJustin Hibbits 	    ("%s: boot page is not aligned (%#jx)", __func__, (uintmax_t)bptr));
4316cedae09SJustin Hibbits 	if (mpc85xx_is_qoriq()) {
4323f068cbfSJustin Hibbits 		/*
4333f068cbfSJustin Hibbits 		 * Read DDR controller configuration to select proper BPTR target ID.
4343f068cbfSJustin Hibbits 		 *
4353f068cbfSJustin Hibbits 		 * On P5020 bit 29 of DDR1_CS0_CONFIG enables DDR controllers
4363f068cbfSJustin Hibbits 		 * interleaving. If this bit is set, we have to use
4373f068cbfSJustin Hibbits 		 * OCP85XX_TGTIF_RAM_INTL as BPTR target ID. On other QorIQ DPAA SoCs,
4383f068cbfSJustin Hibbits 		 * this bit is reserved and always 0.
4393f068cbfSJustin Hibbits 		 */
4403f068cbfSJustin Hibbits 
4413f068cbfSJustin Hibbits 		reg = ccsr_read4(OCP85XX_DDR1_CS0_CONFIG);
4423f068cbfSJustin Hibbits 		if (reg & (1 << 29))
4433f068cbfSJustin Hibbits 			tgt = OCP85XX_TGTIF_RAM_INTL;
4443f068cbfSJustin Hibbits 		else
4453f068cbfSJustin Hibbits 			tgt = OCP85XX_TGTIF_RAM1;
4463f068cbfSJustin Hibbits 
4473f068cbfSJustin Hibbits 		/*
4483f068cbfSJustin Hibbits 		 * Set BSTR to the physical address of the boot page
4493f068cbfSJustin Hibbits 		 */
4503f068cbfSJustin Hibbits 		ccsr_write4(OCP85XX_BSTRH, bptr >> 32);
4513f068cbfSJustin Hibbits 		ccsr_write4(OCP85XX_BSTRL, bptr);
4523f068cbfSJustin Hibbits 		ccsr_write4(OCP85XX_BSTAR, OCP85XX_ENA_MASK |
4536cedae09SJustin Hibbits 		    (tgt << OCP85XX_TRGT_SHIFT_QORIQ) | (ffsl(PAGE_SIZE) - 2));
4543f068cbfSJustin Hibbits 
4553f068cbfSJustin Hibbits 		/* Read back OCP85XX_BSTAR to synchronize write */
4563f068cbfSJustin Hibbits 		ccsr_read4(OCP85XX_BSTAR);
4573f068cbfSJustin Hibbits 
4583f068cbfSJustin Hibbits 		/*
4593f068cbfSJustin Hibbits 		 * Enable and configure time base on new CPU.
4603f068cbfSJustin Hibbits 		 */
4613f068cbfSJustin Hibbits 
4623f068cbfSJustin Hibbits 		/* Set TB clock source to platform clock / 32 */
4633f068cbfSJustin Hibbits 		reg = ccsr_read4(CCSR_CTBCKSELR);
4643f068cbfSJustin Hibbits 		ccsr_write4(CCSR_CTBCKSELR, reg & ~(1 << pc->pc_cpuid));
4653f068cbfSJustin Hibbits 
4663f068cbfSJustin Hibbits 		/* Enable TB */
4673f068cbfSJustin Hibbits 		reg = ccsr_read4(CCSR_CTBENR);
4683f068cbfSJustin Hibbits 		ccsr_write4(CCSR_CTBENR, reg | (1 << pc->pc_cpuid));
4696cedae09SJustin Hibbits 	} else {
470302acc2eSNathan Whitehorn 		/*
471302acc2eSNathan Whitehorn 		 * Set BPTR to the physical address of the boot page
472302acc2eSNathan Whitehorn 		 */
473302acc2eSNathan Whitehorn 		bptr = (bptr >> 12) | 0x80000000u;
474302acc2eSNathan Whitehorn 		ccsr_write4(OCP85XX_BPTR, bptr);
475302acc2eSNathan Whitehorn 		__asm __volatile("isync; msync");
4766cedae09SJustin Hibbits 	}
477302acc2eSNathan Whitehorn 
478302acc2eSNathan Whitehorn 	/*
479302acc2eSNathan Whitehorn 	 * Release AP from hold-off state
480302acc2eSNathan Whitehorn 	 */
4813f068cbfSJustin Hibbits 	reg = ccsr_read4(brr);
4823f068cbfSJustin Hibbits 	ccsr_write4(brr, reg | (1 << cpuid));
483302acc2eSNathan Whitehorn 	__asm __volatile("isync; msync");
484302acc2eSNathan Whitehorn 
485253902b4SJustin Hibbits spin_wait:
486302acc2eSNathan Whitehorn 	timeout = 500;
487302acc2eSNathan Whitehorn 	while (!pc->pc_awake && timeout--)
488302acc2eSNathan Whitehorn 		DELAY(1000);	/* wait 1ms */
489302acc2eSNathan Whitehorn 
490302acc2eSNathan Whitehorn 	/*
491302acc2eSNathan Whitehorn 	 * Disable boot page translation so that the 4K page at the default
492302acc2eSNathan Whitehorn 	 * address (= 0xfffff000) isn't permanently remapped and thus not
493302acc2eSNathan Whitehorn 	 * usable otherwise.
494302acc2eSNathan Whitehorn 	 */
495253902b4SJustin Hibbits 	if (!epapr_boot) {
4966cedae09SJustin Hibbits 		if (mpc85xx_is_qoriq())
4973f068cbfSJustin Hibbits 			ccsr_write4(OCP85XX_BSTAR, 0);
4986cedae09SJustin Hibbits 		else
499302acc2eSNathan Whitehorn 			ccsr_write4(OCP85XX_BPTR, 0);
500302acc2eSNathan Whitehorn 		__asm __volatile("isync; msync");
501253902b4SJustin Hibbits 	}
502302acc2eSNathan Whitehorn 
503302acc2eSNathan Whitehorn 	if (!pc->pc_awake)
5046cedae09SJustin Hibbits 		panic("SMP: CPU %d didn't wake up.\n", pc->pc_cpuid);
505302acc2eSNathan Whitehorn 	return ((pc->pc_awake) ? 0 : EBUSY);
506302acc2eSNathan Whitehorn #else
507302acc2eSNathan Whitehorn 	/* No SMP support */
508302acc2eSNathan Whitehorn 	return (ENXIO);
509302acc2eSNathan Whitehorn #endif
510302acc2eSNathan Whitehorn }
511302acc2eSNathan Whitehorn 
512302acc2eSNathan Whitehorn static void
mpc85xx_reset(platform_t plat)513302acc2eSNathan Whitehorn mpc85xx_reset(platform_t plat)
514302acc2eSNathan Whitehorn {
515302acc2eSNathan Whitehorn 
516302acc2eSNathan Whitehorn 	/*
517302acc2eSNathan Whitehorn 	 * Try the dedicated reset register first.
518302acc2eSNathan Whitehorn 	 * If the SoC doesn't have one, we'll fall
519302acc2eSNathan Whitehorn 	 * back to using the debug control register.
520302acc2eSNathan Whitehorn 	 */
521302acc2eSNathan Whitehorn 	ccsr_write4(OCP85XX_RSTCR, 2);
522302acc2eSNathan Whitehorn 
523702818d2SJustin Hibbits 	mtmsr(mfmsr() & ~PSL_DE);
524702818d2SJustin Hibbits 
525702818d2SJustin Hibbits 	/* Enable debug interrupts and issue reset. */
526702818d2SJustin Hibbits 	mtspr(SPR_DBCR0, DBCR0_IDM | DBCR0_RST_SYSTEM);
527302acc2eSNathan Whitehorn 	__asm __volatile("isync");
528302acc2eSNathan Whitehorn 
529302acc2eSNathan Whitehorn 	/* Enable Debug Interrupts in MSR. */
530302acc2eSNathan Whitehorn 	mtmsr(mfmsr() | PSL_DE);
531302acc2eSNathan Whitehorn 
532302acc2eSNathan Whitehorn 	printf("Reset failed...\n");
533302acc2eSNathan Whitehorn 	while (1)
534302acc2eSNathan Whitehorn 		;
535302acc2eSNathan Whitehorn }
536302acc2eSNathan Whitehorn 
537637f34cbSJustin Hibbits static void
mpc85xx_smp_timebase_sync(platform_t plat,u_long tb,int ap)538de2dd83fSNathan Whitehorn mpc85xx_smp_timebase_sync(platform_t plat, u_long tb, int ap)
539de2dd83fSNathan Whitehorn {
5400d69f00bSJustin Hibbits 	static volatile bool tb_ready;
5410d69f00bSJustin Hibbits 	static volatile int cpu_done;
542de2dd83fSNathan Whitehorn 
5430d69f00bSJustin Hibbits 	if (ap) {
5440d69f00bSJustin Hibbits 		/* APs.  Hold off until we get a stable timebase. */
5450d69f00bSJustin Hibbits 		while (!tb_ready)
5460d69f00bSJustin Hibbits 			atomic_thread_fence_seq_cst();
547de2dd83fSNathan Whitehorn 		mttb(tb);
5480d69f00bSJustin Hibbits 		atomic_add_int(&cpu_done, 1);
5490d69f00bSJustin Hibbits 		while (cpu_done < mp_ncpus)
5500d69f00bSJustin Hibbits 			atomic_thread_fence_seq_cst();
5510d69f00bSJustin Hibbits 	} else {
5520d69f00bSJustin Hibbits 		/* BSP */
5530d69f00bSJustin Hibbits 		freeze_timebase(rcpm_dev, true);
5540d69f00bSJustin Hibbits 		tb_ready = true;
5550d69f00bSJustin Hibbits 		mttb(tb);
5560d69f00bSJustin Hibbits 		atomic_add_int(&cpu_done, 1);
5570d69f00bSJustin Hibbits 		while (cpu_done < mp_ncpus)
5580d69f00bSJustin Hibbits 			atomic_thread_fence_seq_cst();
5590d69f00bSJustin Hibbits 		freeze_timebase(rcpm_dev, false);
5600d69f00bSJustin Hibbits 	}
561de2dd83fSNathan Whitehorn }
562de2dd83fSNathan Whitehorn 
5630d69f00bSJustin Hibbits /* Fallback freeze.  In case no real handler is found in the device tree. */
5640d69f00bSJustin Hibbits static void
dummy_freeze(device_t dev,bool freeze)5650d69f00bSJustin Hibbits dummy_freeze(device_t dev, bool freeze)
5660d69f00bSJustin Hibbits {
5670d69f00bSJustin Hibbits 	/* Nothing to do here, move along. */
5680d69f00bSJustin Hibbits }
5690d69f00bSJustin Hibbits 
5700d69f00bSJustin Hibbits /* QorIQ Run control/power management timebase management. */
5710d69f00bSJustin Hibbits 
5720d69f00bSJustin Hibbits #define	RCPM_CTBENR	0x00000084
5730d69f00bSJustin Hibbits struct mpc85xx_rcpm_softc {
5740d69f00bSJustin Hibbits 	struct resource *sc_mem;
5750d69f00bSJustin Hibbits };
5760d69f00bSJustin Hibbits 
5770d69f00bSJustin Hibbits static void
mpc85xx_rcpm_freeze_timebase(device_t dev,bool freeze)5780d69f00bSJustin Hibbits mpc85xx_rcpm_freeze_timebase(device_t dev, bool freeze)
5790d69f00bSJustin Hibbits {
5800d69f00bSJustin Hibbits 	struct mpc85xx_rcpm_softc *sc;
5810d69f00bSJustin Hibbits 
5820d69f00bSJustin Hibbits 	sc = device_get_softc(dev);
5830d69f00bSJustin Hibbits 
5840d69f00bSJustin Hibbits 	if (freeze)
5850d69f00bSJustin Hibbits 		bus_write_4(sc->sc_mem, RCPM_CTBENR, 0);
5860d69f00bSJustin Hibbits 	else
5870d69f00bSJustin Hibbits 		bus_write_4(sc->sc_mem, RCPM_CTBENR, (1 << maxcpu) - 1);
5880d69f00bSJustin Hibbits }
5890d69f00bSJustin Hibbits 
5900d69f00bSJustin Hibbits static int
mpc85xx_rcpm_probe(device_t dev)5910d69f00bSJustin Hibbits mpc85xx_rcpm_probe(device_t dev)
5920d69f00bSJustin Hibbits {
5930d69f00bSJustin Hibbits 	if (!ofw_bus_is_compatible(dev, "fsl,qoriq-rcpm-1.0"))
5940d69f00bSJustin Hibbits 		return (ENXIO);
5950d69f00bSJustin Hibbits 
5960d69f00bSJustin Hibbits 	device_set_desc(dev, "QorIQ Run control and power management");
5970d69f00bSJustin Hibbits 	return (BUS_PROBE_GENERIC);
5980d69f00bSJustin Hibbits }
5990d69f00bSJustin Hibbits 
6000d69f00bSJustin Hibbits static int
mpc85xx_rcpm_attach(device_t dev)6010d69f00bSJustin Hibbits mpc85xx_rcpm_attach(device_t dev)
6020d69f00bSJustin Hibbits {
6030d69f00bSJustin Hibbits 	struct mpc85xx_rcpm_softc *sc;
6040d69f00bSJustin Hibbits 	int rid;
6050d69f00bSJustin Hibbits 
6060d69f00bSJustin Hibbits 	sc = device_get_softc(dev);
6070d69f00bSJustin Hibbits 	freeze_timebase = mpc85xx_rcpm_freeze_timebase;
6080d69f00bSJustin Hibbits 	rcpm_dev = dev;
6090d69f00bSJustin Hibbits 
6100d69f00bSJustin Hibbits 	rid = 0;
6110d69f00bSJustin Hibbits 	sc->sc_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
6120d69f00bSJustin Hibbits 	    RF_ACTIVE | RF_SHAREABLE);
6130d69f00bSJustin Hibbits 
6140d69f00bSJustin Hibbits 	return (0);
6150d69f00bSJustin Hibbits }
6160d69f00bSJustin Hibbits 
6170d69f00bSJustin Hibbits static device_method_t mpc85xx_rcpm_methods[] = {
6180d69f00bSJustin Hibbits 	DEVMETHOD(device_probe,		mpc85xx_rcpm_probe),
6190d69f00bSJustin Hibbits 	DEVMETHOD(device_attach,	mpc85xx_rcpm_attach),
6200d69f00bSJustin Hibbits 	DEVMETHOD_END
6210d69f00bSJustin Hibbits };
6220d69f00bSJustin Hibbits 
6230d69f00bSJustin Hibbits static driver_t mpc85xx_rcpm_driver = {
6240d69f00bSJustin Hibbits 	"rcpm",
6250d69f00bSJustin Hibbits 	mpc85xx_rcpm_methods,
6260d69f00bSJustin Hibbits 	sizeof(struct mpc85xx_rcpm_softc)
6270d69f00bSJustin Hibbits };
6280d69f00bSJustin Hibbits 
6295d7d6129SJohn Baldwin EARLY_DRIVER_MODULE(mpc85xx_rcpm, simplebus, mpc85xx_rcpm_driver, 0, 0,
6305d7d6129SJohn Baldwin     BUS_PASS_BUS);
6310d69f00bSJustin Hibbits 
6320d69f00bSJustin Hibbits /* "Global utilities" power management/Timebase management. */
6330d69f00bSJustin Hibbits 
6340d69f00bSJustin Hibbits #define	GUTS_DEVDISR	0x00000070
6350d69f00bSJustin Hibbits #define	  DEVDISR_TB0	0x00004000
6360d69f00bSJustin Hibbits #define	  DEVDISR_TB1	0x00001000
6370d69f00bSJustin Hibbits 
6380d69f00bSJustin Hibbits struct mpc85xx_guts_softc {
6390d69f00bSJustin Hibbits 	struct resource *sc_mem;
6400d69f00bSJustin Hibbits };
6410d69f00bSJustin Hibbits 
6420d69f00bSJustin Hibbits static void
mpc85xx_guts_freeze_timebase(device_t dev,bool freeze)6430d69f00bSJustin Hibbits mpc85xx_guts_freeze_timebase(device_t dev, bool freeze)
6440d69f00bSJustin Hibbits {
6450d69f00bSJustin Hibbits 	struct mpc85xx_guts_softc *sc;
6460d69f00bSJustin Hibbits 	uint32_t devdisr;
6470d69f00bSJustin Hibbits 
6480d69f00bSJustin Hibbits 	sc = device_get_softc(dev);
6490d69f00bSJustin Hibbits 
6500d69f00bSJustin Hibbits 	devdisr = bus_read_4(sc->sc_mem, GUTS_DEVDISR);
6510d69f00bSJustin Hibbits 	if (freeze)
6520d69f00bSJustin Hibbits 		bus_write_4(sc->sc_mem, GUTS_DEVDISR,
6530d69f00bSJustin Hibbits 		    devdisr | (DEVDISR_TB0 | DEVDISR_TB1));
6540d69f00bSJustin Hibbits 	else
6550d69f00bSJustin Hibbits 		bus_write_4(sc->sc_mem, GUTS_DEVDISR,
6560d69f00bSJustin Hibbits 		    devdisr & ~(DEVDISR_TB0 | DEVDISR_TB1));
6570d69f00bSJustin Hibbits }
6580d69f00bSJustin Hibbits 
6590d69f00bSJustin Hibbits static int
mpc85xx_guts_probe(device_t dev)6600d69f00bSJustin Hibbits mpc85xx_guts_probe(device_t dev)
6610d69f00bSJustin Hibbits {
6620d69f00bSJustin Hibbits 	if (!ofw_bus_is_compatible(dev, "fsl,mpc8572-guts") &&
6630d69f00bSJustin Hibbits 	    !ofw_bus_is_compatible(dev, "fsl,p1020-guts") &&
6640d69f00bSJustin Hibbits 	    !ofw_bus_is_compatible(dev, "fsl,p1021-guts") &&
6650d69f00bSJustin Hibbits 	    !ofw_bus_is_compatible(dev, "fsl,p1022-guts") &&
6660d69f00bSJustin Hibbits 	    !ofw_bus_is_compatible(dev, "fsl,p1023-guts") &&
6670d69f00bSJustin Hibbits 	    !ofw_bus_is_compatible(dev, "fsl,p2020-guts"))
6680d69f00bSJustin Hibbits 		return (ENXIO);
6690d69f00bSJustin Hibbits 
6700d69f00bSJustin Hibbits 	device_set_desc(dev, "MPC85xx Global Utilities");
6710d69f00bSJustin Hibbits 	return (BUS_PROBE_GENERIC);
6720d69f00bSJustin Hibbits }
6730d69f00bSJustin Hibbits 
6740d69f00bSJustin Hibbits static int
mpc85xx_guts_attach(device_t dev)6750d69f00bSJustin Hibbits mpc85xx_guts_attach(device_t dev)
6760d69f00bSJustin Hibbits {
6770d69f00bSJustin Hibbits 	struct mpc85xx_rcpm_softc *sc;
6780d69f00bSJustin Hibbits 	int rid;
6790d69f00bSJustin Hibbits 
6800d69f00bSJustin Hibbits 	sc = device_get_softc(dev);
6810d69f00bSJustin Hibbits 	freeze_timebase = mpc85xx_guts_freeze_timebase;
6820d69f00bSJustin Hibbits 	rcpm_dev = dev;
6830d69f00bSJustin Hibbits 
6840d69f00bSJustin Hibbits 	rid = 0;
6850d69f00bSJustin Hibbits 	sc->sc_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
6860d69f00bSJustin Hibbits 	    RF_ACTIVE | RF_SHAREABLE);
6870d69f00bSJustin Hibbits 
6880d69f00bSJustin Hibbits 	return (0);
6890d69f00bSJustin Hibbits }
6900d69f00bSJustin Hibbits 
6910d69f00bSJustin Hibbits static device_method_t mpc85xx_guts_methods[] = {
6920d69f00bSJustin Hibbits 	DEVMETHOD(device_probe,		mpc85xx_guts_probe),
6930d69f00bSJustin Hibbits 	DEVMETHOD(device_attach,	mpc85xx_guts_attach),
6940d69f00bSJustin Hibbits 	DEVMETHOD_END
6950d69f00bSJustin Hibbits };
6960d69f00bSJustin Hibbits 
6970d69f00bSJustin Hibbits static driver_t mpc85xx_guts_driver = {
6980d69f00bSJustin Hibbits 	"guts",
6990d69f00bSJustin Hibbits 	mpc85xx_guts_methods,
7000d69f00bSJustin Hibbits 	sizeof(struct mpc85xx_guts_softc)
7010d69f00bSJustin Hibbits };
7020d69f00bSJustin Hibbits 
7035d7d6129SJohn Baldwin EARLY_DRIVER_MODULE(mpc85xx_guts, simplebus, mpc85xx_guts_driver, 0, 0,
7045d7d6129SJohn Baldwin     BUS_PASS_BUS);
705