1 /*-
2 * Copyright (c) 2005 Peter Grehan
3 * Copyright (c) 2009 Nathan Whitehorn
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
14 *
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
25 * SUCH DAMAGE.
26 *
27 */
28
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD: releng/8.1/sys/powerpc/powerpc/platform.c 192067 2009-05-14 00:34:26Z nwhitehorn $");
31
32 /*
33 * Dispatch platform calls to the appropriate platform implementation
34 * through a previously registered kernel object.
35 */
36
37 #include <sys/param.h>
38 #include <sys/kernel.h>
39 #include <sys/lock.h>
40 #include <sys/ktr.h>
41 #include <sys/mutex.h>
42 #include <sys/systm.h>
43 #include <sys/sysctl.h>
44 #include <sys/types.h>
45
46 #include <vm/vm.h>
47 #include <vm/vm_page.h>
48
49 #include <machine/platform.h>
50 #include <machine/platformvar.h>
51 #include <machine/smp.h>
52
53 #include "platform_if.h"
54
55 static platform_def_t *plat_def_impl;
56 static platform_t plat_obj;
57 static struct kobj_ops plat_kernel_kops;
58 static struct platform_kobj plat_kernel_obj;
59
60 static char plat_name[64] = "";
61 SYSCTL_STRING(_hw, OID_AUTO, platform, CTLFLAG_RD | CTLFLAG_TUN,
62 plat_name, 0, "Platform currently in use");
63
64 void
65 mem_regions(struct mem_region **phys, int *physsz, struct mem_region **avail,
66 int *availsz)
67 {
68 PLATFORM_MEM_REGIONS(plat_obj, phys, physsz, avail, availsz);
69 }
70
71 const char *
72 installed_platform()
73 {
74 return (plat_def_impl->name);
75 }
76
77 u_long
78 platform_timebase_freq(struct cpuref *cpu)
79 {
80 return (PLATFORM_TIMEBASE_FREQ(plat_obj, cpu));
81 }
82
83 int
84 platform_smp_first_cpu(struct cpuref *cpu)
85 {
86 return (PLATFORM_SMP_FIRST_CPU(plat_obj, cpu));
87 }
88
89 int
90 platform_smp_next_cpu(struct cpuref *cpu)
91 {
92 return (PLATFORM_SMP_NEXT_CPU(plat_obj, cpu));
93 }
94
95 int
96 platform_smp_get_bsp(struct cpuref *cpu)
97 {
98 return (PLATFORM_SMP_GET_BSP(plat_obj, cpu));
99 }
100
101 int
102 platform_smp_start_cpu(struct pcpu *cpu)
103 {
104 return (PLATFORM_SMP_START_CPU(plat_obj, cpu));
105 }
106
107 /*
108 * Platform install routines. Highest priority wins, using the same
109 * algorithm as bus attachment.
110 */
111 SET_DECLARE(platform_set, platform_def_t);
112
113 void
114 platform_probe_and_attach()
115 {
116 platform_def_t **platpp, *platp;
117 int prio, best_prio;
118
119 plat_obj = &plat_kernel_obj;
120 best_prio = 0;
121
122 /*
123 * Try to locate the best platform kobj
124 */
125 SET_FOREACH(platpp, platform_set) {
126 platp = *platpp;
127
128 /*
129 * Take care of compiling the selected class, and
130 * then statically initialise the MMU object
131 */
132 kobj_class_compile_static(platp, &plat_kernel_kops);
133 kobj_init((kobj_t)plat_obj, platp);
134
135 prio = PLATFORM_PROBE(plat_obj);
136
137 /* Check for errors */
138 if (prio > 0)
139 continue;
140
141 /*
142 * Check if this module was specifically requested through
143 * the loader tunable we provide.
144 */
145 if (strcmp(platp->name,plat_name) == 0) {
146 plat_def_impl = platp;
147 break;
148 }
149
150 /* Otherwise, see if it is better than our current best */
151 if (plat_def_impl == NULL || prio > best_prio) {
152 best_prio = prio;
153 plat_def_impl = platp;
154 }
155
156 /*
157 * We can't free the KOBJ, since it is static. Luckily,
158 * this has no ill effects since it gets reset every time.
159 */
160 }
161
162 if (plat_def_impl == NULL)
163 panic("No platform module found!");
164
165 /*
166 * Recompile to make sure we ended with the
167 * correct one, and then attach.
168 */
169
170 kobj_class_compile_static(plat_def_impl, &plat_kernel_kops);
171 kobj_init((kobj_t)plat_obj, plat_def_impl);
172
173 strlcpy(plat_name,plat_def_impl->name,sizeof(plat_name));
174
175 PLATFORM_ATTACH(plat_obj);
176 }
177
Cache object: e794a5726a1d5ac07486f4ce8ac9c2e4
|