Deleted Added
full compact
platform_powermac.c (209853) platform_powermac.c (212054)
1/*-
2 * Copyright (c) 2008 Marcel Moolenaar
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:

--- 12 unchanged lines hidden (view full) ---

21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2008 Marcel Moolenaar
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:

--- 12 unchanged lines hidden (view full) ---

21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/powerpc/aim/platform_chrp.c 209853 2010-07-09 14:04:16Z nwhitehorn $");
29__FBSDID("$FreeBSD: head/sys/powerpc/powermac/platform_powermac.c 212054 2010-08-31 15:27:46Z nwhitehorn $");
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/bus.h>
35#include <sys/pcpu.h>
36#include <sys/proc.h>
37#include <sys/smp.h>

--- 12 unchanged lines hidden (view full) ---

50#include <machine/ofw_machdep.h>
51
52#include "platform_if.h"
53
54#ifdef SMP
55extern void *ap_pcpu;
56#endif
57
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/bus.h>
35#include <sys/pcpu.h>
36#include <sys/proc.h>
37#include <sys/smp.h>

--- 12 unchanged lines hidden (view full) ---

50#include <machine/ofw_machdep.h>
51
52#include "platform_if.h"
53
54#ifdef SMP
55extern void *ap_pcpu;
56#endif
57
58static int chrp_probe(platform_t);
59void chrp_mem_regions(platform_t, struct mem_region **phys, int *physsz,
58static int powermac_probe(platform_t);
59void powermac_mem_regions(platform_t, struct mem_region **phys, int *physsz,
60 struct mem_region **avail, int *availsz);
60 struct mem_region **avail, int *availsz);
61static u_long chrp_timebase_freq(platform_t, struct cpuref *cpuref);
62static int chrp_smp_first_cpu(platform_t, struct cpuref *cpuref);
63static int chrp_smp_next_cpu(platform_t, struct cpuref *cpuref);
64static int chrp_smp_get_bsp(platform_t, struct cpuref *cpuref);
65static int chrp_smp_start_cpu(platform_t, struct pcpu *cpu);
61static u_long powermac_timebase_freq(platform_t, struct cpuref *cpuref);
62static int powermac_smp_first_cpu(platform_t, struct cpuref *cpuref);
63static int powermac_smp_next_cpu(platform_t, struct cpuref *cpuref);
64static int powermac_smp_get_bsp(platform_t, struct cpuref *cpuref);
65static int powermac_smp_start_cpu(platform_t, struct pcpu *cpu);
66static void powermac_reset(platform_t);
66
67
67static platform_method_t chrp_methods[] = {
68 PLATFORMMETHOD(platform_probe, chrp_probe),
69 PLATFORMMETHOD(platform_mem_regions, chrp_mem_regions),
70 PLATFORMMETHOD(platform_timebase_freq, chrp_timebase_freq),
68static platform_method_t powermac_methods[] = {
69 PLATFORMMETHOD(platform_probe, powermac_probe),
70 PLATFORMMETHOD(platform_mem_regions, powermac_mem_regions),
71 PLATFORMMETHOD(platform_timebase_freq, powermac_timebase_freq),
71
72
72 PLATFORMMETHOD(platform_smp_first_cpu, chrp_smp_first_cpu),
73 PLATFORMMETHOD(platform_smp_next_cpu, chrp_smp_next_cpu),
74 PLATFORMMETHOD(platform_smp_get_bsp, chrp_smp_get_bsp),
75 PLATFORMMETHOD(platform_smp_start_cpu, chrp_smp_start_cpu),
73 PLATFORMMETHOD(platform_smp_first_cpu, powermac_smp_first_cpu),
74 PLATFORMMETHOD(platform_smp_next_cpu, powermac_smp_next_cpu),
75 PLATFORMMETHOD(platform_smp_get_bsp, powermac_smp_get_bsp),
76 PLATFORMMETHOD(platform_smp_start_cpu, powermac_smp_start_cpu),
76
77
78 PLATFORMMETHOD(platform_reset, powermac_reset),
79
77 { 0, 0 }
78};
79
80 { 0, 0 }
81};
82
80static platform_def_t chrp_platform = {
81 "chrp",
82 chrp_methods,
83static platform_def_t powermac_platform = {
84 "powermac",
85 powermac_methods,
83 0
84};
85
86 0
87};
88
86PLATFORM_DEF(chrp_platform);
89PLATFORM_DEF(powermac_platform);
87
88static int
90
91static int
89chrp_probe(platform_t plat)
92powermac_probe(platform_t plat)
90{
91 if (OF_finddevice("/memory") != -1 || OF_finddevice("/memory@0") != -1)
92 return (BUS_PROBE_GENERIC);
93
94 return (ENXIO);
95}
96
97void
93{
94 if (OF_finddevice("/memory") != -1 || OF_finddevice("/memory@0") != -1)
95 return (BUS_PROBE_GENERIC);
96
97 return (ENXIO);
98}
99
100void
98chrp_mem_regions(platform_t plat, struct mem_region **phys, int *physsz,
101powermac_mem_regions(platform_t plat, struct mem_region **phys, int *physsz,
99 struct mem_region **avail, int *availsz)
100{
101 ofw_mem_regions(phys,physsz,avail,availsz);
102}
103
104static u_long
102 struct mem_region **avail, int *availsz)
103{
104 ofw_mem_regions(phys,physsz,avail,availsz);
105}
106
107static u_long
105chrp_timebase_freq(platform_t plat, struct cpuref *cpuref)
108powermac_timebase_freq(platform_t plat, struct cpuref *cpuref)
106{
107 phandle_t phandle;
108 int32_t ticks = -1;
109
110 phandle = cpuref->cr_hwref;
111
112 OF_getprop(phandle, "timebase-frequency", &ticks, sizeof(ticks));
113
114 if (ticks <= 0)
115 panic("Unable to determine timebase frequency!");
116
117 return (ticks);
118}
119
120
121static int
109{
110 phandle_t phandle;
111 int32_t ticks = -1;
112
113 phandle = cpuref->cr_hwref;
114
115 OF_getprop(phandle, "timebase-frequency", &ticks, sizeof(ticks));
116
117 if (ticks <= 0)
118 panic("Unable to determine timebase frequency!");
119
120 return (ticks);
121}
122
123
124static int
122chrp_smp_fill_cpuref(struct cpuref *cpuref, phandle_t cpu)
125powermac_smp_fill_cpuref(struct cpuref *cpuref, phandle_t cpu)
123{
124 cell_t cpuid, res;
125
126 cpuref->cr_hwref = cpu;
127 res = OF_getprop(cpu, "reg", &cpuid, sizeof(cpuid));
128
129 /*
130 * psim doesn't have a reg property, so assume 0 as for the
131 * uniprocessor case in the CHRP spec.
132 */
133 if (res < 0) {
134 cpuid = 0;
135 }
136
137 cpuref->cr_cpuid = cpuid & 0xff;
138 return (0);
139}
140
141static int
126{
127 cell_t cpuid, res;
128
129 cpuref->cr_hwref = cpu;
130 res = OF_getprop(cpu, "reg", &cpuid, sizeof(cpuid));
131
132 /*
133 * psim doesn't have a reg property, so assume 0 as for the
134 * uniprocessor case in the CHRP spec.
135 */
136 if (res < 0) {
137 cpuid = 0;
138 }
139
140 cpuref->cr_cpuid = cpuid & 0xff;
141 return (0);
142}
143
144static int
142chrp_smp_first_cpu(platform_t plat, struct cpuref *cpuref)
145powermac_smp_first_cpu(platform_t plat, struct cpuref *cpuref)
143{
144 char buf[8];
145 phandle_t cpu, dev, root;
146 int res;
147
148 root = OF_peer(0);
149
150 dev = OF_child(root);

--- 19 unchanged lines hidden (view full) ---

170 res = OF_getprop(cpu, "device_type", buf, sizeof(buf));
171 if (res > 0 && strcmp(buf, "cpu") == 0)
172 break;
173 cpu = OF_peer(cpu);
174 }
175 if (cpu == 0)
176 return (ENOENT);
177
146{
147 char buf[8];
148 phandle_t cpu, dev, root;
149 int res;
150
151 root = OF_peer(0);
152
153 dev = OF_child(root);

--- 19 unchanged lines hidden (view full) ---

173 res = OF_getprop(cpu, "device_type", buf, sizeof(buf));
174 if (res > 0 && strcmp(buf, "cpu") == 0)
175 break;
176 cpu = OF_peer(cpu);
177 }
178 if (cpu == 0)
179 return (ENOENT);
180
178 return (chrp_smp_fill_cpuref(cpuref, cpu));
181 return (powermac_smp_fill_cpuref(cpuref, cpu));
179}
180
181static int
182}
183
184static int
182chrp_smp_next_cpu(platform_t plat, struct cpuref *cpuref)
185powermac_smp_next_cpu(platform_t plat, struct cpuref *cpuref)
183{
184 char buf[8];
185 phandle_t cpu;
186 int res;
187
188 cpu = OF_peer(cpuref->cr_hwref);
189 while (cpu != 0) {
190 res = OF_getprop(cpu, "device_type", buf, sizeof(buf));
191 if (res > 0 && strcmp(buf, "cpu") == 0)
192 break;
193 cpu = OF_peer(cpu);
194 }
195 if (cpu == 0)
196 return (ENOENT);
197
186{
187 char buf[8];
188 phandle_t cpu;
189 int res;
190
191 cpu = OF_peer(cpuref->cr_hwref);
192 while (cpu != 0) {
193 res = OF_getprop(cpu, "device_type", buf, sizeof(buf));
194 if (res > 0 && strcmp(buf, "cpu") == 0)
195 break;
196 cpu = OF_peer(cpu);
197 }
198 if (cpu == 0)
199 return (ENOENT);
200
198 return (chrp_smp_fill_cpuref(cpuref, cpu));
201 return (powermac_smp_fill_cpuref(cpuref, cpu));
199}
200
201static int
202}
203
204static int
202chrp_smp_get_bsp(platform_t plat, struct cpuref *cpuref)
205powermac_smp_get_bsp(platform_t plat, struct cpuref *cpuref)
203{
204 ihandle_t inst;
205 phandle_t bsp, chosen;
206 int res;
207
208 chosen = OF_finddevice("/chosen");
209 if (chosen == 0)
210 return (ENXIO);
211
212 res = OF_getprop(chosen, "cpu", &inst, sizeof(inst));
213 if (res < 0)
214 return (ENXIO);
215
216 bsp = OF_instance_to_package(inst);
206{
207 ihandle_t inst;
208 phandle_t bsp, chosen;
209 int res;
210
211 chosen = OF_finddevice("/chosen");
212 if (chosen == 0)
213 return (ENXIO);
214
215 res = OF_getprop(chosen, "cpu", &inst, sizeof(inst));
216 if (res < 0)
217 return (ENXIO);
218
219 bsp = OF_instance_to_package(inst);
217 return (chrp_smp_fill_cpuref(cpuref, bsp));
220 return (powermac_smp_fill_cpuref(cpuref, bsp));
218}
219
220static int
221}
222
223static int
221chrp_smp_start_cpu(platform_t plat, struct pcpu *pc)
224powermac_smp_start_cpu(platform_t plat, struct pcpu *pc)
222{
223#ifdef SMP
224 phandle_t cpu;
225 volatile uint8_t *rstvec;
226 static volatile uint8_t *rstvec_virtbase = NULL;
227 int res, reset, timeout;
228
229 cpu = pc->pc_hwref;

--- 42 unchanged lines hidden (view full) ---

272
273 return ((pc->pc_awake) ? 0 : EBUSY);
274#else
275 /* No SMP support */
276 return (ENXIO);
277#endif
278}
279
225{
226#ifdef SMP
227 phandle_t cpu;
228 volatile uint8_t *rstvec;
229 static volatile uint8_t *rstvec_virtbase = NULL;
230 int res, reset, timeout;
231
232 cpu = pc->pc_hwref;

--- 42 unchanged lines hidden (view full) ---

275
276 return ((pc->pc_awake) ? 0 : EBUSY);
277#else
278 /* No SMP support */
279 return (ENXIO);
280#endif
281}
282
283static void
284powermac_reset(platform_t platform)
285{
286 OF_reboot();
287}
288