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 #include <sys/param.h>
38 #include <sys/kernel.h>
41 #include <sys/mutex.h>
42 #include <sys/systm.h>
43 #include <sys/sysctl.h>
44 #include <sys/types.h>
47 #include <vm/vm_page.h>
49 #include <machine/cpu.h>
50 #include <machine/platform.h>
51 #include <machine/platformvar.h>
52 #include <machine/smp.h>
54 #include "platform_if.h"
56 static platform_def_t *plat_def_impl;
57 static platform_t plat_obj;
58 static struct kobj_ops plat_kernel_kops;
59 static struct platform_kobj plat_kernel_obj;
61 static char plat_name[64] = "";
62 SYSCTL_STRING(_hw, OID_AUTO, platform, CTLFLAG_RD | CTLFLAG_TUN,
63 plat_name, 0, "Platform currently in use");
66 mem_regions(struct mem_region **phys, int *physsz, struct mem_region **avail,
69 PLATFORM_MEM_REGIONS(plat_obj, phys, physsz, avail, availsz);
75 return (plat_def_impl->name);
79 platform_timebase_freq(struct cpuref *cpu)
81 return (PLATFORM_TIMEBASE_FREQ(plat_obj, cpu));
85 platform_smp_first_cpu(struct cpuref *cpu)
87 return (PLATFORM_SMP_FIRST_CPU(plat_obj, cpu));
91 platform_smp_next_cpu(struct cpuref *cpu)
93 return (PLATFORM_SMP_NEXT_CPU(plat_obj, cpu));
97 platform_smp_get_bsp(struct cpuref *cpu)
99 return (PLATFORM_SMP_GET_BSP(plat_obj, cpu));
103 platform_smp_start_cpu(struct pcpu *cpu)
105 return (PLATFORM_SMP_START_CPU(plat_obj, cpu));
109 * Reset back to firmware.
114 PLATFORM_RESET(plat_obj);
118 * Platform install routines. Highest priority wins, using the same
119 * algorithm as bus attachment.
121 SET_DECLARE(platform_set, platform_def_t);
124 platform_probe_and_attach()
126 platform_def_t **platpp, *platp;
129 plat_obj = &plat_kernel_obj;
133 * Try to locate the best platform kobj
135 SET_FOREACH(platpp, platform_set) {
139 * Take care of compiling the selected class, and
140 * then statically initialise the MMU object
142 kobj_class_compile_static(platp, &plat_kernel_kops);
143 kobj_init((kobj_t)plat_obj, platp);
145 prio = PLATFORM_PROBE(plat_obj);
147 /* Check for errors */
152 * Check if this module was specifically requested through
153 * the loader tunable we provide.
155 if (strcmp(platp->name,plat_name) == 0) {
156 plat_def_impl = platp;
160 /* Otherwise, see if it is better than our current best */
161 if (plat_def_impl == NULL || prio > best_prio) {
163 plat_def_impl = platp;
167 * We can't free the KOBJ, since it is static. Luckily,
168 * this has no ill effects since it gets reset every time.
172 if (plat_def_impl == NULL)
173 panic("No platform module found!");
176 * Recompile to make sure we ended with the
177 * correct one, and then attach.
180 kobj_class_compile_static(plat_def_impl, &plat_kernel_kops);
181 kobj_init((kobj_t)plat_obj, plat_def_impl);
183 strlcpy(plat_name,plat_def_impl->name,sizeof(plat_name));
185 PLATFORM_ATTACH(plat_obj);