2 * Copyright (c) 2005 Peter Grehan
3 * Copyright (c) 2009 Nathan Whitehorn
6 * Redistribution and use in source and binary forms, with or without
7 * 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 AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
33 * Dispatch platform calls to the appropriate platform implementation
34 * through a previously registered kernel object.
37 #define _ARM32_BUS_DMA_PRIVATE
38 #include <sys/param.h>
40 #include <sys/kernel.h>
43 #include <sys/mutex.h>
45 #include <sys/systm.h>
47 #include <sys/sysctl.h>
48 #include <sys/types.h>
51 #include <vm/vm_page.h>
53 #include <machine/bus_dma.h>
54 #include <machine/cpu.h>
55 #include <machine/intr.h>
56 #include <machine/machdep.h>
57 #include <machine/md_var.h>
58 #include <machine/platform.h>
59 #include <machine/platformvar.h>
60 #include <machine/smp.h>
62 #include "platform_if.h"
64 static platform_def_t *plat_def_impl;
65 static platform_t plat_obj;
66 static struct kobj_ops plat_kernel_kops;
67 static struct platform_kobj plat_kernel_obj;
69 static char plat_name[64];
70 SYSCTL_STRING(_hw, OID_AUTO, platform, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, plat_name, 0,
71 "Platform currently in use");
74 * Platform install routines. Highest priority wins, using the same
75 * algorithm as bus attachment.
77 SET_DECLARE(platform_set, platform_def_t);
80 static delay_func platform_delay;
84 platform_probe_and_attach(void)
86 platform_def_t **platpp, *platp;
89 plat_obj = &plat_kernel_obj;
93 * We are unable to use TUNABLE_STR as the read will happen
94 * well after this function has returned.
96 TUNABLE_STR_FETCH("hw.platform", plat_name, sizeof(plat_name));
99 * Try to locate the best platform kobj
101 SET_FOREACH(platpp, platform_set) {
105 * Take care of compiling the selected class, and
106 * then statically initialise the MMU object
108 kobj_class_compile_static((kobj_class_t)platp,
110 kobj_init_static((kobj_t)plat_obj, (kobj_class_t)platp);
112 plat_obj->cls = platp;
114 prio = PLATFORM_PROBE(plat_obj);
116 /* Check for errors */
121 * Check if this module was specifically requested through
122 * the loader tunable we provide.
124 if (strcmp(platp->name,plat_name) == 0) {
125 plat_def_impl = platp;
129 /* Otherwise, see if it is better than our current best */
130 if (plat_def_impl == NULL || prio > best_prio) {
132 plat_def_impl = platp;
136 * We can't free the KOBJ, since it is static. Reset the ops
137 * member of this class so that we can come back later.
142 if (plat_def_impl == NULL)
143 panic("No platform module found!");
146 * Recompile to make sure we ended with the
147 * correct one, and then attach.
150 kobj_class_compile_static((kobj_class_t)plat_def_impl,
152 kobj_init_static((kobj_t)plat_obj, (kobj_class_t)plat_def_impl);
154 strlcpy(plat_name, plat_def_impl->name, sizeof(plat_name));
157 /* Set a default delay function */
158 arm_set_delay(platform_delay, NULL);
161 PLATFORM_ATTACH(plat_obj);
165 platform_devmap_init(void)
168 return PLATFORM_DEVMAP_INIT(plat_obj);
172 platform_lastaddr(void)
175 return PLATFORM_LASTADDR(plat_obj);
179 platform_gpio_init(void)
182 PLATFORM_GPIO_INIT(plat_obj);
186 platform_late_init(void)
189 PLATFORM_LATE_INIT(plat_obj);
194 platform_delay(int usec, void *arg __unused)
198 for (; usec > 0; usec--)
199 for (counts = plat_obj->cls->delay_count; counts > 0; counts--)
201 * Prevent the compiler from optimizing
208 #if defined(SMP) && defined(PLATFORM_SMP)
210 platform_mp_setmaxid(void)
213 PLATFORM_MP_SETMAXID(plat_obj);
217 platform_mp_start_ap(void)
220 PLATFORM_MP_START_AP(plat_obj);