2 * Copyright (c) 2008-2012 Semihalf.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
38 #include <dev/ofw/openfirm.h>
40 #include <machine/platform.h>
41 #include <machine/platformvar.h>
43 #include "platform_if.h"
45 extern uint32_t *bootinfo;
47 static int bare_probe(platform_t);
48 static void bare_mem_regions(platform_t, struct mem_region *phys, int *physsz,
49 struct mem_region *avail, int *availsz);
50 static u_long bare_timebase_freq(platform_t, struct cpuref *cpuref);
52 static void bare_reset(platform_t);
54 static platform_method_t bare_methods[] = {
55 PLATFORMMETHOD(platform_probe, bare_probe),
56 PLATFORMMETHOD(platform_mem_regions, bare_mem_regions),
57 PLATFORMMETHOD(platform_timebase_freq, bare_timebase_freq),
59 PLATFORMMETHOD(platform_reset, bare_reset),
64 static platform_def_t bare_platform = {
70 PLATFORM_DEF(bare_platform);
73 bare_probe(platform_t plat)
76 if (OF_peer(0) == -1) /* Needs device tree to work */
79 return (BUS_PROBE_GENERIC);
83 bare_mem_regions(platform_t plat, struct mem_region *phys, int *physsz,
84 struct mem_region *avail, int *availsz)
87 ofw_mem_regions(phys, physsz, avail, availsz);
91 bare_timebase_freq(platform_t plat, struct cpuref *cpuref)
94 phandle_t cpus, child;
97 if (bootinfo != NULL) {
98 if (bootinfo[0] == 1) {
99 /* Backward compatibility. See 8-STABLE. */
100 ticks = bootinfo[3] >> 3;
102 /* Compatibility with Juniper's loader. */
103 ticks = bootinfo[5] >> 3;
108 if ((cpus = OF_finddevice("/cpus")) == -1)
111 if ((child = OF_child(cpus)) == 0)
114 switch (OF_getproplen(child, "timebase-frequency")) {
118 OF_getprop(child, "timebase-frequency", &tbase, sizeof(tbase));
125 OF_getprop(child, "timebase-frequency", &tbase, sizeof(tbase));
134 if (OF_getprop(child, "bus-frequency", (void *)&freq,
139 * Time Base and Decrementer are updated every 8 CCB bus clocks.
140 * HID0[SEL_TBCLK] = 0
147 panic("Unable to determine timebase frequency!");
153 bare_reset(platform_t plat)
156 printf("Reset failed...\n");