2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2008-2012 Semihalf.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
40 #include <dev/ofw/openfirm.h>
42 #include <machine/platform.h>
43 #include <machine/platformvar.h>
45 #include "platform_if.h"
47 extern uint32_t *bootinfo;
49 static int bare_probe(platform_t);
50 static void bare_mem_regions(platform_t, struct mem_region *phys, int *physsz,
51 struct mem_region *avail, int *availsz);
52 static u_long bare_timebase_freq(platform_t, struct cpuref *cpuref);
54 static void bare_reset(platform_t);
56 static platform_method_t bare_methods[] = {
57 PLATFORMMETHOD(platform_probe, bare_probe),
58 PLATFORMMETHOD(platform_mem_regions, bare_mem_regions),
59 PLATFORMMETHOD(platform_timebase_freq, bare_timebase_freq),
61 PLATFORMMETHOD(platform_reset, bare_reset),
66 static platform_def_t bare_platform = {
72 PLATFORM_DEF(bare_platform);
75 bare_probe(platform_t plat)
78 if (OF_peer(0) == -1) /* Needs device tree to work */
81 return (BUS_PROBE_GENERIC);
85 bare_mem_regions(platform_t plat, struct mem_region *phys, int *physsz,
86 struct mem_region *avail, int *availsz)
89 ofw_mem_regions(phys, physsz, avail, availsz);
93 bare_timebase_freq(platform_t plat, struct cpuref *cpuref)
96 phandle_t cpus, child;
99 if (bootinfo != NULL) {
100 if (bootinfo[0] == 1) {
101 /* Backward compatibility. See 8-STABLE. */
102 ticks = bootinfo[3] >> 3;
104 /* Compatibility with Juniper's loader. */
105 ticks = bootinfo[5] >> 3;
110 if ((cpus = OF_finddevice("/cpus")) == -1)
113 if ((child = OF_child(cpus)) == 0)
116 switch (OF_getproplen(child, "timebase-frequency")) {
120 OF_getprop(child, "timebase-frequency", &tbase, sizeof(tbase));
127 OF_getprop(child, "timebase-frequency", &tbase, sizeof(tbase));
136 if (OF_getprop(child, "bus-frequency", (void *)&freq,
141 * Time Base and Decrementer are updated every 8 CCB bus clocks.
142 * HID0[SEL_TBCLK] = 0
149 panic("Unable to determine timebase frequency!");
155 bare_reset(platform_t plat)
158 printf("Reset failed...\n");