Factor out platform dependent things unrelated to device drivers into a
new platform module. These are probed in early boot, and have the responsibility of determining the layout of physical memory, determining the CPU timebase frequency, and handling the zoo of SMP mechanisms found on PowerPC. Reviewed by: marcel, raj Book-E parts by: raj
This commit is contained in:
parent
e872228f51
commit
b40ce02a2f
@ -81,6 +81,7 @@ powerpc/aim/mp_cpudep.c optional aim smp
|
||||
powerpc/aim/nexus.c optional aim
|
||||
powerpc/aim/ofw_machdep.c optional aim
|
||||
powerpc/aim/ofwmagic.S optional aim
|
||||
powerpc/aim/platform_chrp.c optional aim
|
||||
powerpc/aim/swtch.S optional aim
|
||||
powerpc/aim/trap.c optional aim
|
||||
powerpc/aim/uma_machdep.c optional aim
|
||||
@ -90,6 +91,7 @@ powerpc/booke/copyinout.c optional e500
|
||||
powerpc/booke/interrupt.c optional e500
|
||||
powerpc/booke/locore.S optional e500 no-obj
|
||||
powerpc/booke/machdep.c optional e500
|
||||
powerpc/booke/platform_bare.c optional mpc85xx
|
||||
powerpc/booke/pmap.c optional e500
|
||||
powerpc/booke/swtch.S optional e500
|
||||
powerpc/booke/trap.c optional e500
|
||||
@ -155,6 +157,8 @@ powerpc/powerpc/mp_machdep.c optional smp
|
||||
powerpc/powerpc/openpic.c standard
|
||||
powerpc/powerpc/pic_if.m standard
|
||||
powerpc/powerpc/pmap_dispatch.c standard
|
||||
powerpc/powerpc/platform.c standard
|
||||
powerpc/powerpc/platform_if.m standard
|
||||
powerpc/powerpc/sc_machdep.c optional sc
|
||||
powerpc/powerpc/setjmp.S standard
|
||||
powerpc/powerpc/sigcode.S standard
|
||||
|
@ -125,44 +125,27 @@ decr_intr(struct trapframe *frame)
|
||||
void
|
||||
decr_init(void)
|
||||
{
|
||||
int qhandle, phandle;
|
||||
char name[32];
|
||||
unsigned int msr;
|
||||
|
||||
phandle = 0;
|
||||
struct cpuref cpu;
|
||||
register_t msr;
|
||||
|
||||
/*
|
||||
* Get this info during autoconf? XXX
|
||||
* Check the BSP's timebase frequency. Sometimes we can't find the BSP, so fall
|
||||
* back to the first CPU in this case.
|
||||
*/
|
||||
for (qhandle = OF_peer(0); qhandle; qhandle = phandle) {
|
||||
if (OF_getprop(qhandle, "device_type", name, sizeof name) >= 0
|
||||
&& !strcmp(name, "cpu")
|
||||
&& OF_getprop(qhandle, "timebase-frequency",
|
||||
&ticks_per_sec, sizeof ticks_per_sec) >= 0) {
|
||||
/*
|
||||
* Should check for correct CPU here? XXX
|
||||
*/
|
||||
msr = mfmsr();
|
||||
mtmsr(msr & ~PSL_EE);
|
||||
|
||||
ns_per_tick = 1000000000 / ticks_per_sec;
|
||||
ticks_per_intr = ticks_per_sec / hz;
|
||||
mtdec(ticks_per_intr);
|
||||
if (platform_smp_get_bsp(&cpu) != 0)
|
||||
platform_smp_first_cpu(&cpu);
|
||||
|
||||
mtmsr(msr);
|
||||
ticks_per_sec = platform_timebase_freq(&cpu);
|
||||
|
||||
break;
|
||||
}
|
||||
if ((phandle = OF_child(qhandle)))
|
||||
continue;
|
||||
while (qhandle) {
|
||||
if ((phandle = OF_peer(qhandle)))
|
||||
break;
|
||||
qhandle = OF_parent(qhandle);
|
||||
}
|
||||
}
|
||||
if (!phandle)
|
||||
panic("no cpu node");
|
||||
msr = mfmsr();
|
||||
mtmsr(msr & ~PSL_EE);
|
||||
|
||||
ns_per_tick = 1000000000 / ticks_per_sec;
|
||||
ticks_per_intr = ticks_per_sec / hz;
|
||||
mtdec(ticks_per_intr);
|
||||
|
||||
mtmsr(msr);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -114,7 +114,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <machine/metadata.h>
|
||||
#include <machine/mmuvar.h>
|
||||
#include <machine/pcb.h>
|
||||
#include <machine/powerpc.h>
|
||||
#include <machine/reg.h>
|
||||
#include <machine/sigframe.h>
|
||||
#include <machine/spr.h>
|
||||
@ -472,14 +471,22 @@ powerpc_init(u_int startkernel, u_int endkernel, u_int basekernel, void *mdp)
|
||||
*/
|
||||
mtmsr(msr);
|
||||
isync();
|
||||
|
||||
/*
|
||||
* Choose a platform module so we can get the physical memory map.
|
||||
*/
|
||||
|
||||
platform_probe_and_attach();
|
||||
|
||||
/*
|
||||
* Initialise virtual memory.
|
||||
* Initialise virtual memory. Use BUS_PROBE_GENERIC priority
|
||||
* in case the platform module had a better idea of what we
|
||||
* should do.
|
||||
*/
|
||||
if (ppc64)
|
||||
pmap_mmu_install(MMU_TYPE_G5, 0);
|
||||
pmap_mmu_install(MMU_TYPE_G5, BUS_PROBE_GENERIC);
|
||||
else
|
||||
pmap_mmu_install(MMU_TYPE_OEA, 0);
|
||||
pmap_mmu_install(MMU_TYPE_OEA, BUS_PROBE_GENERIC);
|
||||
|
||||
pmap_bootstrap(startkernel, endkernel);
|
||||
mtmsr(mfmsr() | PSL_IR|PSL_DR|PSL_ME|PSL_RI);
|
||||
|
@ -141,7 +141,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <vm/uma.h>
|
||||
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/powerpc.h>
|
||||
#include <machine/platform.h>
|
||||
#include <machine/bat.h>
|
||||
#include <machine/frame.h>
|
||||
#include <machine/md_var.h>
|
||||
|
@ -143,7 +143,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <vm/uma.h>
|
||||
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/powerpc.h>
|
||||
#include <machine/platform.h>
|
||||
#include <machine/frame.h>
|
||||
#include <machine/md_var.h>
|
||||
#include <machine/psl.h>
|
||||
|
@ -54,91 +54,6 @@ extern register_t l3cr_config;
|
||||
|
||||
void *ap_pcpu;
|
||||
|
||||
static int
|
||||
powerpc_smp_fill_cpuref(struct cpuref *cpuref, phandle_t cpu)
|
||||
{
|
||||
int cpuid, res;
|
||||
|
||||
cpuref->cr_hwref = cpu;
|
||||
res = OF_getprop(cpu, "reg", &cpuid, sizeof(cpuid));
|
||||
if (res < 0)
|
||||
return (ENOENT);
|
||||
|
||||
cpuref->cr_cpuid = cpuid & 0xff;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
powerpc_smp_first_cpu(struct cpuref *cpuref)
|
||||
{
|
||||
char buf[8];
|
||||
phandle_t cpu, dev, root;
|
||||
int res;
|
||||
|
||||
root = OF_peer(0);
|
||||
|
||||
dev = OF_child(root);
|
||||
while (dev != 0) {
|
||||
res = OF_getprop(dev, "name", buf, sizeof(buf));
|
||||
if (res > 0 && strcmp(buf, "cpus") == 0)
|
||||
break;
|
||||
dev = OF_peer(dev);
|
||||
}
|
||||
if (dev == 0)
|
||||
return (ENOENT);
|
||||
|
||||
cpu = OF_child(dev);
|
||||
while (cpu != 0) {
|
||||
res = OF_getprop(cpu, "device_type", buf, sizeof(buf));
|
||||
if (res > 0 && strcmp(buf, "cpu") == 0)
|
||||
break;
|
||||
cpu = OF_peer(cpu);
|
||||
}
|
||||
if (cpu == 0)
|
||||
return (ENOENT);
|
||||
|
||||
return (powerpc_smp_fill_cpuref(cpuref, cpu));
|
||||
}
|
||||
|
||||
int
|
||||
powerpc_smp_next_cpu(struct cpuref *cpuref)
|
||||
{
|
||||
char buf[8];
|
||||
phandle_t cpu;
|
||||
int res;
|
||||
|
||||
cpu = OF_peer(cpuref->cr_hwref);
|
||||
while (cpu != 0) {
|
||||
res = OF_getprop(cpu, "device_type", buf, sizeof(buf));
|
||||
if (res > 0 && strcmp(buf, "cpu") == 0)
|
||||
break;
|
||||
cpu = OF_peer(cpu);
|
||||
}
|
||||
if (cpu == 0)
|
||||
return (ENOENT);
|
||||
|
||||
return (powerpc_smp_fill_cpuref(cpuref, cpu));
|
||||
}
|
||||
|
||||
int
|
||||
powerpc_smp_get_bsp(struct cpuref *cpuref)
|
||||
{
|
||||
ihandle_t inst;
|
||||
phandle_t bsp, chosen;
|
||||
int res;
|
||||
|
||||
chosen = OF_finddevice("/chosen");
|
||||
if (chosen == 0)
|
||||
return (ENXIO);
|
||||
|
||||
res = OF_getprop(chosen, "cpu", &inst, sizeof(inst));
|
||||
if (res < 0)
|
||||
return (ENXIO);
|
||||
|
||||
bsp = OF_instance_to_package(inst);
|
||||
return (powerpc_smp_fill_cpuref(cpuref, bsp));
|
||||
}
|
||||
|
||||
static register_t
|
||||
l2_enable(void)
|
||||
{
|
||||
@ -269,31 +184,3 @@ cpudep_ap_bootstrap(void)
|
||||
return (sp);
|
||||
}
|
||||
|
||||
int
|
||||
powerpc_smp_start_cpu(struct pcpu *pc)
|
||||
{
|
||||
phandle_t cpu;
|
||||
volatile uint8_t *rstvec;
|
||||
int res, reset, timeout;
|
||||
|
||||
cpu = pc->pc_hwref;
|
||||
res = OF_getprop(cpu, "soft-reset", &reset, sizeof(reset));
|
||||
if (res < 0)
|
||||
return (ENXIO);
|
||||
|
||||
ap_pcpu = pc;
|
||||
|
||||
rstvec = (uint8_t *)(0x80000000 + reset);
|
||||
|
||||
*rstvec = 4;
|
||||
powerpc_sync();
|
||||
DELAY(1);
|
||||
*rstvec = 0;
|
||||
powerpc_sync();
|
||||
|
||||
timeout = 1000;
|
||||
while (!pc->pc_awake && timeout--)
|
||||
DELAY(100);
|
||||
|
||||
return ((pc->pc_awake) ? 0 : EBUSY);
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <machine/bus.h>
|
||||
#include <machine/md_var.h>
|
||||
#include <machine/powerpc.h>
|
||||
#include <machine/platform.h>
|
||||
#include <machine/ofw_machdep.h>
|
||||
|
||||
#define OFMEM_REGIONS 32
|
||||
@ -144,7 +144,7 @@ memr_merge(struct mem_region *from, struct mem_region *to)
|
||||
* to provide space for two additional entry beyond the terminating one.
|
||||
*/
|
||||
void
|
||||
mem_regions(struct mem_region **memp, int *memsz,
|
||||
ofw_mem_regions(struct mem_region **memp, int *memsz,
|
||||
struct mem_region **availp, int *availsz)
|
||||
{
|
||||
phandle_t phandle;
|
||||
|
236
sys/powerpc/aim/platform_chrp.c
Normal file
236
sys/powerpc/aim/platform_chrp.c
Normal file
@ -0,0 +1,236 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Marcel Moolenaar
|
||||
* Copyright (c) 2009 Nathan Whitehorn
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/bus.h>
|
||||
#include <sys/pcpu.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/smp.h>
|
||||
|
||||
#include <machine/bus.h>
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/hid.h>
|
||||
#include <machine/platformvar.h>
|
||||
#include <machine/smp.h>
|
||||
#include <machine/spr.h>
|
||||
|
||||
#include <dev/ofw/openfirm.h>
|
||||
#include <machine/ofw_machdep.h>
|
||||
|
||||
#include "platform_if.h"
|
||||
|
||||
#ifdef SMP
|
||||
extern void *ap_pcpu;
|
||||
#endif
|
||||
|
||||
static int chrp_probe(platform_t);
|
||||
void chrp_mem_regions(platform_t, struct mem_region **phys, int *physsz,
|
||||
struct mem_region **avail, int *availsz);
|
||||
static u_long chrp_timebase_freq(platform_t, struct cpuref *cpuref);
|
||||
static int chrp_smp_first_cpu(platform_t, struct cpuref *cpuref);
|
||||
static int chrp_smp_next_cpu(platform_t, struct cpuref *cpuref);
|
||||
static int chrp_smp_get_bsp(platform_t, struct cpuref *cpuref);
|
||||
static int chrp_smp_start_cpu(platform_t, struct pcpu *cpu);
|
||||
|
||||
static platform_method_t chrp_methods[] = {
|
||||
PLATFORMMETHOD(platform_probe, chrp_probe),
|
||||
PLATFORMMETHOD(platform_mem_regions, chrp_mem_regions),
|
||||
PLATFORMMETHOD(platform_timebase_freq, chrp_timebase_freq),
|
||||
|
||||
PLATFORMMETHOD(platform_smp_first_cpu, chrp_smp_first_cpu),
|
||||
PLATFORMMETHOD(platform_smp_next_cpu, chrp_smp_next_cpu),
|
||||
PLATFORMMETHOD(platform_smp_get_bsp, chrp_smp_get_bsp),
|
||||
PLATFORMMETHOD(platform_smp_start_cpu, chrp_smp_start_cpu),
|
||||
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
static platform_def_t chrp_platform = {
|
||||
"chrp",
|
||||
chrp_methods,
|
||||
0
|
||||
};
|
||||
|
||||
PLATFORM_DEF(chrp_platform);
|
||||
|
||||
static int
|
||||
chrp_probe(platform_t plat)
|
||||
{
|
||||
if (OF_finddevice("/memory") != -1)
|
||||
return (BUS_PROBE_GENERIC);
|
||||
|
||||
return (ENXIO);
|
||||
}
|
||||
|
||||
void
|
||||
chrp_mem_regions(platform_t plat, struct mem_region **phys, int *physsz,
|
||||
struct mem_region **avail, int *availsz)
|
||||
{
|
||||
ofw_mem_regions(phys,physsz,avail,availsz);
|
||||
}
|
||||
|
||||
static u_long
|
||||
chrp_timebase_freq(platform_t plat, struct cpuref *cpuref)
|
||||
{
|
||||
phandle_t phandle;
|
||||
u_long ticks = -1;
|
||||
|
||||
phandle = cpuref->cr_hwref;
|
||||
|
||||
OF_getprop(phandle, "timebase-frequency", &ticks, sizeof(ticks));
|
||||
|
||||
if (ticks <= 0)
|
||||
panic("Unable to determine timebase frequency!");
|
||||
|
||||
return (ticks);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
chrp_smp_fill_cpuref(struct cpuref *cpuref, phandle_t cpu)
|
||||
{
|
||||
int cpuid, res;
|
||||
|
||||
cpuref->cr_hwref = cpu;
|
||||
res = OF_getprop(cpu, "reg", &cpuid, sizeof(cpuid));
|
||||
if (res < 0)
|
||||
return (ENOENT);
|
||||
|
||||
cpuref->cr_cpuid = cpuid & 0xff;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
chrp_smp_first_cpu(platform_t plat, struct cpuref *cpuref)
|
||||
{
|
||||
char buf[8];
|
||||
phandle_t cpu, dev, root;
|
||||
int res;
|
||||
|
||||
root = OF_peer(0);
|
||||
|
||||
dev = OF_child(root);
|
||||
while (dev != 0) {
|
||||
res = OF_getprop(dev, "name", buf, sizeof(buf));
|
||||
if (res > 0 && strcmp(buf, "cpus") == 0)
|
||||
break;
|
||||
dev = OF_peer(dev);
|
||||
}
|
||||
if (dev == 0)
|
||||
return (ENOENT);
|
||||
|
||||
cpu = OF_child(dev);
|
||||
while (cpu != 0) {
|
||||
res = OF_getprop(cpu, "device_type", buf, sizeof(buf));
|
||||
if (res > 0 && strcmp(buf, "cpu") == 0)
|
||||
break;
|
||||
cpu = OF_peer(cpu);
|
||||
}
|
||||
if (cpu == 0)
|
||||
return (ENOENT);
|
||||
|
||||
return (chrp_smp_fill_cpuref(cpuref, cpu));
|
||||
}
|
||||
|
||||
static int
|
||||
chrp_smp_next_cpu(platform_t plat, struct cpuref *cpuref)
|
||||
{
|
||||
char buf[8];
|
||||
phandle_t cpu;
|
||||
int res;
|
||||
|
||||
cpu = OF_peer(cpuref->cr_hwref);
|
||||
while (cpu != 0) {
|
||||
res = OF_getprop(cpu, "device_type", buf, sizeof(buf));
|
||||
if (res > 0 && strcmp(buf, "cpu") == 0)
|
||||
break;
|
||||
cpu = OF_peer(cpu);
|
||||
}
|
||||
if (cpu == 0)
|
||||
return (ENOENT);
|
||||
|
||||
return (chrp_smp_fill_cpuref(cpuref, cpu));
|
||||
}
|
||||
|
||||
static int
|
||||
chrp_smp_get_bsp(platform_t plat, struct cpuref *cpuref)
|
||||
{
|
||||
ihandle_t inst;
|
||||
phandle_t bsp, chosen;
|
||||
int res;
|
||||
|
||||
chosen = OF_finddevice("/chosen");
|
||||
if (chosen == 0)
|
||||
return (ENXIO);
|
||||
|
||||
res = OF_getprop(chosen, "cpu", &inst, sizeof(inst));
|
||||
if (res < 0)
|
||||
return (ENXIO);
|
||||
|
||||
bsp = OF_instance_to_package(inst);
|
||||
return (chrp_smp_fill_cpuref(cpuref, bsp));
|
||||
}
|
||||
|
||||
static int
|
||||
chrp_smp_start_cpu(platform_t plat, struct pcpu *pc)
|
||||
{
|
||||
#ifdef SMP
|
||||
phandle_t cpu;
|
||||
volatile uint8_t *rstvec;
|
||||
int res, reset, timeout;
|
||||
|
||||
cpu = pc->pc_hwref;
|
||||
res = OF_getprop(cpu, "soft-reset", &reset, sizeof(reset));
|
||||
if (res < 0)
|
||||
return (ENXIO);
|
||||
|
||||
ap_pcpu = pc;
|
||||
|
||||
rstvec = (uint8_t *)(0x80000000 + reset);
|
||||
|
||||
*rstvec = 4;
|
||||
powerpc_sync();
|
||||
DELAY(1);
|
||||
*rstvec = 0;
|
||||
powerpc_sync();
|
||||
|
||||
timeout = 1000;
|
||||
while (!pc->pc_awake && timeout--)
|
||||
DELAY(100);
|
||||
|
||||
return ((pc->pc_awake) ? 0 : EBUSY);
|
||||
#else
|
||||
/* No SMP support */
|
||||
return (ENXIO);
|
||||
#endif
|
||||
}
|
||||
|
@ -89,7 +89,6 @@
|
||||
#include <machine/frame.h>
|
||||
#include <machine/md_var.h>
|
||||
#include <machine/pcb.h>
|
||||
#include <machine/powerpc.h>
|
||||
|
||||
#include <dev/ofw/openfirm.h>
|
||||
|
||||
|
@ -67,6 +67,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/interrupt.h>
|
||||
|
||||
#include <machine/clock.h>
|
||||
#include <machine/platform.h>
|
||||
#include <machine/psl.h>
|
||||
#include <machine/spr.h>
|
||||
#include <machine/cpu.h>
|
||||
@ -123,29 +124,22 @@ void
|
||||
cpu_initclocks(void)
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
decr_config (unsigned long freq)
|
||||
{
|
||||
ticks_per_sec = freq;
|
||||
decr_timecounter.tc_frequency = freq;
|
||||
decr_tc_init();
|
||||
}
|
||||
|
||||
void
|
||||
decr_init (void)
|
||||
{
|
||||
struct cpuref cpu;
|
||||
unsigned int msr;
|
||||
|
||||
/*
|
||||
* Should check for correct CPU here? XXX
|
||||
*/
|
||||
if (platform_smp_get_bsp(&cpu) != 0)
|
||||
platform_smp_first_cpu(&cpu);
|
||||
ticks_per_sec = platform_timebase_freq(&cpu);
|
||||
|
||||
msr = mfmsr();
|
||||
mtmsr(msr & ~(PSL_EE));
|
||||
|
||||
tc_init(&decr_timecounter);
|
||||
|
||||
ns_per_tick = 1000000000 / ticks_per_sec;
|
||||
ticks_per_intr = ticks_per_sec / hz;
|
||||
|
||||
@ -173,6 +167,15 @@ mftb (void)
|
||||
return tb;
|
||||
}
|
||||
|
||||
void
|
||||
decr_tc_init(void)
|
||||
{
|
||||
|
||||
decr_timecounter.tc_frequency = ticks_per_sec;
|
||||
tc_init(&decr_timecounter);
|
||||
}
|
||||
|
||||
|
||||
static unsigned
|
||||
decr_get_timecount(struct timecounter *tc)
|
||||
{
|
||||
|
@ -127,11 +127,10 @@ __FBSDID("$FreeBSD$");
|
||||
#include <machine/trap.h>
|
||||
#include <machine/md_var.h>
|
||||
#include <machine/mmuvar.h>
|
||||
#include <machine/pmap.h>
|
||||
#include <machine/sigframe.h>
|
||||
#include <machine/metadata.h>
|
||||
#include <machine/bootinfo.h>
|
||||
#include <machine/powerpc.h>
|
||||
#include <machine/platform.h>
|
||||
|
||||
#include <sys/linker.h>
|
||||
#include <sys/reboot.h>
|
||||
@ -157,9 +156,6 @@ extern unsigned char __sbss_start[];
|
||||
extern unsigned char __sbss_end[];
|
||||
extern unsigned char _end[];
|
||||
|
||||
extern struct mem_region availmem_regions[];
|
||||
extern int availmem_regions_sz;
|
||||
|
||||
extern void dcache_enable(void);
|
||||
extern void dcache_inval(void);
|
||||
extern void icache_enable(void);
|
||||
@ -339,9 +335,7 @@ e500_init(u_int32_t startkernel, u_int32_t endkernel, void *mdp)
|
||||
struct pcpu *pc;
|
||||
void *kmdp;
|
||||
vm_offset_t end;
|
||||
struct bi_mem_region *mr;
|
||||
uint32_t csr;
|
||||
int i;
|
||||
|
||||
kmdp = NULL;
|
||||
|
||||
@ -381,31 +375,9 @@ e500_init(u_int32_t startkernel, u_int32_t endkernel, void *mdp)
|
||||
while(1);
|
||||
}
|
||||
|
||||
/* Initialize memory regions table */
|
||||
mr = bootinfo_mr();
|
||||
for (i = 0; i < bootinfo->bi_mem_reg_no; i++, mr++) {
|
||||
if (i == MEM_REGIONS)
|
||||
break;
|
||||
if (mr->mem_base < 1048576) {
|
||||
availmem_regions[i].mr_start = 1048576;
|
||||
availmem_regions[i].mr_size = mr->mem_size -
|
||||
(1048576 - mr->mem_base);
|
||||
} else {
|
||||
availmem_regions[i].mr_start = mr->mem_base;
|
||||
availmem_regions[i].mr_size = mr->mem_size;
|
||||
}
|
||||
}
|
||||
availmem_regions_sz = i;
|
||||
|
||||
/* Initialize TLB1 handling */
|
||||
tlb1_init(bootinfo->bi_bar_base);
|
||||
|
||||
/*
|
||||
* Time Base and Decrementer are updated every 8 CCB bus clocks.
|
||||
* HID0[SEL_TBCLK] = 0
|
||||
*/
|
||||
decr_config(bootinfo->bi_bus_clk / 8);
|
||||
|
||||
/* Init params/tunables that can be overridden by the loader. */
|
||||
init_param1();
|
||||
|
||||
@ -450,6 +422,9 @@ e500_init(u_int32_t startkernel, u_int32_t endkernel, void *mdp)
|
||||
kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
|
||||
#endif
|
||||
|
||||
/* Initialise platform module */
|
||||
platform_probe_and_attach();
|
||||
|
||||
/* Initialise virtual memory. */
|
||||
pmap_mmu_install(MMU_TYPE_BOOKE, 0);
|
||||
pmap_bootstrap(startkernel, end);
|
||||
|
185
sys/powerpc/booke/platform_bare.c
Normal file
185
sys/powerpc/booke/platform_bare.c
Normal file
@ -0,0 +1,185 @@
|
||||
/*-
|
||||
* Copyright (c) 2008-2009 Semihalf, Rafal Jaworowski
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/bus.h>
|
||||
#include <sys/pcpu.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/smp.h>
|
||||
|
||||
#include <machine/bootinfo.h>
|
||||
#include <machine/bus.h>
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/hid.h>
|
||||
#include <machine/platform.h>
|
||||
#include <machine/platformvar.h>
|
||||
#include <machine/smp.h>
|
||||
#include <machine/spr.h>
|
||||
#include <machine/vmparam.h>
|
||||
|
||||
#include <powerpc/mpc85xx/mpc85xx.h>
|
||||
#include <powerpc/mpc85xx/ocpbus.h>
|
||||
|
||||
#include "platform_if.h"
|
||||
|
||||
static int cpu;
|
||||
|
||||
static int bare_probe(platform_t);
|
||||
static void bare_mem_regions(platform_t, struct mem_region **phys, int *physsz,
|
||||
struct mem_region **avail, int *availsz);
|
||||
static u_long bare_timebase_freq(platform_t, struct cpuref *cpuref);
|
||||
static int bare_smp_first_cpu(platform_t, struct cpuref *cpuref);
|
||||
static int bare_smp_next_cpu(platform_t, struct cpuref *cpuref);
|
||||
static int bare_smp_get_bsp(platform_t, struct cpuref *cpuref);
|
||||
static int bare_smp_start_cpu(platform_t, struct pcpu *cpu);
|
||||
|
||||
static platform_method_t bare_methods[] = {
|
||||
PLATFORMMETHOD(platform_probe, bare_probe),
|
||||
PLATFORMMETHOD(platform_mem_regions, bare_mem_regions),
|
||||
PLATFORMMETHOD(platform_timebase_freq, bare_timebase_freq),
|
||||
|
||||
PLATFORMMETHOD(platform_smp_first_cpu, bare_smp_first_cpu),
|
||||
PLATFORMMETHOD(platform_smp_next_cpu, bare_smp_next_cpu),
|
||||
PLATFORMMETHOD(platform_smp_get_bsp, bare_smp_get_bsp),
|
||||
PLATFORMMETHOD(platform_smp_start_cpu, bare_smp_start_cpu),
|
||||
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
static platform_def_t bare_platform = {
|
||||
"bare metal",
|
||||
bare_methods,
|
||||
0
|
||||
};
|
||||
|
||||
PLATFORM_DEF(bare_platform);
|
||||
|
||||
static int
|
||||
bare_probe(platform_t plat)
|
||||
{
|
||||
|
||||
return (BUS_PROBE_GENERIC);
|
||||
}
|
||||
|
||||
#define MEM_REGIONS 8
|
||||
static struct mem_region avail_regions[MEM_REGIONS];
|
||||
|
||||
void
|
||||
bare_mem_regions(platform_t plat, struct mem_region **phys, int *physsz,
|
||||
struct mem_region **avail, int *availsz)
|
||||
{
|
||||
struct bi_mem_region *mr;
|
||||
int i;
|
||||
|
||||
/* Initialize memory regions table */
|
||||
mr = bootinfo_mr();
|
||||
for (i = 0; i < bootinfo->bi_mem_reg_no; i++, mr++) {
|
||||
if (i == MEM_REGIONS)
|
||||
break;
|
||||
if (mr->mem_base < 1048576) {
|
||||
avail_regions[i].mr_start = 1048576;
|
||||
avail_regions[i].mr_size = mr->mem_size -
|
||||
(1048576 - mr->mem_base);
|
||||
} else {
|
||||
avail_regions[i].mr_start = mr->mem_base;
|
||||
avail_regions[i].mr_size = mr->mem_size;
|
||||
}
|
||||
}
|
||||
*availsz = i;
|
||||
*avail = avail_regions;
|
||||
|
||||
/* On the bare metal platform phys == avail memory */
|
||||
*physsz = *availsz;
|
||||
*phys = *avail;
|
||||
}
|
||||
|
||||
static u_long
|
||||
bare_timebase_freq(platform_t plat, struct cpuref *cpuref)
|
||||
{
|
||||
u_long ticks = -1;
|
||||
|
||||
/*
|
||||
* Time Base and Decrementer are updated every 8 CCB bus clocks.
|
||||
* HID0[SEL_TBCLK] = 0
|
||||
*/
|
||||
ticks = bootinfo->bi_bus_clk / 8;
|
||||
if (ticks <= 0)
|
||||
panic("Unable to determine timebase frequency!");
|
||||
|
||||
return (ticks);
|
||||
}
|
||||
|
||||
static int
|
||||
bare_smp_first_cpu(platform_t plat, struct cpuref *cpuref)
|
||||
{
|
||||
|
||||
cpu = 0;
|
||||
cpuref->cr_cpuid = cpu;
|
||||
cpuref->cr_hwref = cpuref->cr_cpuid;
|
||||
if (bootverbose)
|
||||
printf("powerpc_smp_first_cpu: cpuid %d\n", cpuref->cr_cpuid);
|
||||
cpu++;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
bare_smp_next_cpu(platform_t plat, struct cpuref *cpuref)
|
||||
{
|
||||
|
||||
if (cpu >= MAXCPU)
|
||||
return (ENOENT);
|
||||
|
||||
cpuref->cr_cpuid = cpu++;
|
||||
cpuref->cr_hwref = cpuref->cr_cpuid;
|
||||
if (bootverbose)
|
||||
printf("powerpc_smp_next_cpu: cpuid %d\n", cpuref->cr_cpuid);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
bare_smp_get_bsp(platform_t plat, struct cpuref *cpuref)
|
||||
{
|
||||
|
||||
cpuref->cr_cpuid = mfspr(SPR_PIR);
|
||||
cpuref->cr_hwref = cpuref->cr_cpuid;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
bare_smp_start_cpu(platform_t plat, struct pcpu *pc)
|
||||
{
|
||||
|
||||
/* No SMP support */
|
||||
return (ENXIO);
|
||||
}
|
@ -79,7 +79,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <machine/bootinfo.h>
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/pcb.h>
|
||||
#include <machine/powerpc.h>
|
||||
#include <machine/platform.h>
|
||||
|
||||
#include <machine/tlb.h>
|
||||
#include <machine/spr.h>
|
||||
@ -122,8 +122,11 @@ vm_size_t kernsize;
|
||||
static vm_offset_t data_start;
|
||||
static vm_size_t data_end;
|
||||
|
||||
struct mem_region availmem_regions[MEM_REGIONS];
|
||||
int availmem_regions_sz;
|
||||
/* Phys/avail memory regions. */
|
||||
static struct mem_region *availmem_regions;
|
||||
static int availmem_regions_sz;
|
||||
static struct mem_region *physmem_regions;
|
||||
static int physmem_regions_sz;
|
||||
|
||||
/* Reserved KVA space and mutex for mmu_booke_zero_page. */
|
||||
static vm_offset_t zero_page_va;
|
||||
@ -1013,6 +1016,10 @@ mmu_booke_bootstrap(mmu_t mmu, vm_offset_t start, vm_offset_t kernelend)
|
||||
* align all regions. Non-page aligned memory isn't very interesting
|
||||
* to us. Also, sort the entries for ascending addresses.
|
||||
*/
|
||||
|
||||
/* Retrieve phys/avail mem regions */
|
||||
mem_regions(&physmem_regions, &physmem_regions_sz,
|
||||
&availmem_regions, &availmem_regions_sz);
|
||||
sz = 0;
|
||||
cnt = availmem_regions_sz;
|
||||
debugf("processing avail regions:\n");
|
||||
|
@ -124,7 +124,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <machine/md_var.h>
|
||||
#include <machine/pcb.h>
|
||||
#include <machine/spr.h>
|
||||
#include <machine/powerpc.h>
|
||||
#include <machine/platform.h>
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/vm_param.h>
|
||||
|
@ -55,7 +55,6 @@ void busdma_swi(void);
|
||||
int is_physical_memory(vm_offset_t addr);
|
||||
int mem_valid(vm_offset_t addr, int len);
|
||||
|
||||
void decr_config(unsigned long);
|
||||
void decr_init(void);
|
||||
void decr_tc_init(void);
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <sys/rman.h>
|
||||
#include <sys/bus.h>
|
||||
#include <dev/ofw/openfirm.h>
|
||||
#include <machine/platform.h>
|
||||
|
||||
typedef uint32_t cell_t;
|
||||
|
||||
@ -42,4 +43,9 @@ void OF_getetheraddr(device_t dev, u_char *addr);
|
||||
void OF_initial_setup(void *fdt_ptr, void *junk, int (*openfirm)(void *));
|
||||
boolean_t OF_bootstrap(void);
|
||||
|
||||
void OF_halt(void);
|
||||
void OF_reboot(void);
|
||||
|
||||
void ofw_mem_regions(struct mem_region **, int *, struct mem_region **, int *);
|
||||
|
||||
#endif /* _MACHINE_OFW_MACHDEP_H_ */
|
||||
|
@ -32,8 +32,11 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _MACHINE_POWERPC_H_
|
||||
#define _MACHINE_POWERPC_H_
|
||||
#ifndef _MACHINE_PLATFORM_H_
|
||||
#define _MACHINE_PLATFORM_H_
|
||||
|
||||
#include <machine/smp.h>
|
||||
#include <machine/pcpu.h>
|
||||
|
||||
struct mem_region {
|
||||
vm_offset_t mr_start;
|
||||
@ -42,18 +45,14 @@ struct mem_region {
|
||||
|
||||
void mem_regions(struct mem_region **, int *, struct mem_region **, int *);
|
||||
|
||||
/*
|
||||
* These two functions get used solely in boot() in machdep.c.
|
||||
*
|
||||
* Not sure whether boot itself should be implementation dependent instead. XXX
|
||||
*/
|
||||
void OF_halt(void);
|
||||
void OF_reboot(void);
|
||||
|
||||
int dk_match(char *name);
|
||||
|
||||
void ofrootfound(void);
|
||||
|
||||
extern int booted_partition;
|
||||
|
||||
#endif /* _MACHINE_POWERPC_H_ */
|
||||
u_long platform_timebase_freq(struct cpuref *);
|
||||
|
||||
int platform_smp_first_cpu(struct cpuref *);
|
||||
int platform_smp_next_cpu(struct cpuref *);
|
||||
int platform_smp_get_bsp(struct cpuref *);
|
||||
int platform_smp_start_cpu(struct pcpu *);
|
||||
|
||||
const char *installed_platform(void);
|
||||
void platform_probe_and_attach(void);
|
||||
|
||||
#endif /* _MACHINE_PLATFORM_H_ */
|
88
sys/powerpc/include/platformvar.h
Normal file
88
sys/powerpc/include/platformvar.h
Normal file
@ -0,0 +1,88 @@
|
||||
/*-
|
||||
* Copyright (c) 2005 Peter Grehan
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _MACHINE_PLATFORMVAR_H_
|
||||
#define _MACHINE_PLATFORMVAR_H_
|
||||
|
||||
/*
|
||||
* A PowerPC platform implementation is declared with a kernel object and
|
||||
* an associated method table, similar to a device driver.
|
||||
*
|
||||
* e.g.
|
||||
*
|
||||
* static platform_method_t chrp_methods[] = {
|
||||
* PLATFORMMETHOD(platform_probe, chrp_probe),
|
||||
* PLATFORMMETHOD(platform_mem_regions, ofw_mem_regions),
|
||||
* ...
|
||||
* PLATFORMMETHOD(platform_smp_first_cpu, chrp_smp_first_cpu),
|
||||
* { 0, 0 }
|
||||
* };
|
||||
*
|
||||
* static platform_def_t chrp_platform = {
|
||||
* "chrp",
|
||||
* chrp_methods,
|
||||
* sizeof(chrp_platform_softc), // or 0 if no softc
|
||||
* };
|
||||
*
|
||||
* PLATFORM_DEF(chrp_platform);
|
||||
*/
|
||||
|
||||
#include <sys/kobj.h>
|
||||
|
||||
struct platform_kobj {
|
||||
/*
|
||||
* A platform instance is a kernel object
|
||||
*/
|
||||
KOBJ_FIELDS;
|
||||
|
||||
/*
|
||||
* Utility elements that an instance may use
|
||||
*/
|
||||
struct mtx platform_mtx; /* available for instance use */
|
||||
void *platform_iptr; /* instance data pointer */
|
||||
|
||||
/*
|
||||
* Opaque data that can be overlaid with an instance-private
|
||||
* structure. Platform code can test that this is large enough at
|
||||
* compile time with a sizeof() test againt it's softc. There
|
||||
* is also a run-time test when the platform kernel object is
|
||||
* registered.
|
||||
*/
|
||||
#define PLATFORM_OPAQUESZ 64
|
||||
u_int platform_opaque[PLATFORM_OPAQUESZ];
|
||||
};
|
||||
|
||||
typedef struct platform_kobj *platform_t;
|
||||
typedef struct kobj_class platform_def_t;
|
||||
#define platform_method_t kobj_method_t
|
||||
|
||||
#define PLATFORMMETHOD KOBJMETHOD
|
||||
|
||||
#define PLATFORM_DEF(name) DATA_SET(platform_set, name)
|
||||
|
||||
#endif /* _MACHINE_PLATFORMVAR_H_ */
|
@ -143,7 +143,6 @@ struct md_page {
|
||||
TAILQ_HEAD(, pv_entry) pv_list;
|
||||
};
|
||||
|
||||
#define MEM_REGIONS 8
|
||||
#define pmap_page_is_mapped(m) (!TAILQ_EMPTY(&(m)->md.pv_list))
|
||||
|
||||
#endif /* AIM */
|
||||
|
@ -46,11 +46,6 @@ struct cpuref {
|
||||
u_int cr_cpuid;
|
||||
};
|
||||
|
||||
int powerpc_smp_first_cpu(struct cpuref *);
|
||||
int powerpc_smp_get_bsp(struct cpuref *);
|
||||
int powerpc_smp_next_cpu(struct cpuref *);
|
||||
int powerpc_smp_start_cpu(struct pcpu *);
|
||||
|
||||
void pmap_cpu_bootstrap(int);
|
||||
uint32_t cpudep_ap_bootstrap(void);
|
||||
void machdep_ap_bootstrap(void);
|
||||
|
@ -419,6 +419,7 @@
|
||||
#define SPR_DAC2 0x3f7 /* 4.. Data Address Compare 2 */
|
||||
#define SPR_PIR 0x3ff /* .6. Processor Identification Register */
|
||||
#elif defined(E500)
|
||||
#define SPR_PIR 0x11e /* ..8 Processor Identification Register */
|
||||
#define SPR_DBSR 0x130 /* ..8 Debug Status Register */
|
||||
#define DBSR_IDE 0x80000000 /* Imprecise debug event. */
|
||||
#define DBSR_UDE 0x40000000 /* Unconditional debug event. */
|
||||
|
@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <machine/bus.h>
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/intr_machdep.h>
|
||||
#include <machine/platform.h>
|
||||
#include <machine/smp.h>
|
||||
|
||||
#include "pic_if.h"
|
||||
@ -88,10 +89,10 @@ cpu_mp_setmaxid(void)
|
||||
int error;
|
||||
|
||||
mp_ncpus = 0;
|
||||
error = powerpc_smp_first_cpu(&cpuref);
|
||||
error = platform_smp_first_cpu(&cpuref);
|
||||
while (!error) {
|
||||
mp_ncpus++;
|
||||
error = powerpc_smp_next_cpu(&cpuref);
|
||||
error = platform_smp_next_cpu(&cpuref);
|
||||
}
|
||||
/* Sanity. */
|
||||
if (mp_ncpus == 0)
|
||||
@ -121,11 +122,11 @@ cpu_mp_start(void)
|
||||
struct pcpu *pc;
|
||||
int error;
|
||||
|
||||
error = powerpc_smp_get_bsp(&bsp);
|
||||
error = platform_smp_get_bsp(&bsp);
|
||||
KASSERT(error == 0, ("Don't know BSP"));
|
||||
KASSERT(bsp.cr_cpuid == 0, ("%s: cpuid != 0", __func__));
|
||||
|
||||
error = powerpc_smp_first_cpu(&cpu);
|
||||
error = platform_smp_first_cpu(&cpu);
|
||||
while (!error) {
|
||||
if (cpu.cr_cpuid >= MAXCPU) {
|
||||
printf("SMP: cpu%d: skipped -- ID out of range\n",
|
||||
@ -150,7 +151,7 @@ cpu_mp_start(void)
|
||||
all_cpus |= pc->pc_cpumask;
|
||||
|
||||
next:
|
||||
error = powerpc_smp_next_cpu(&cpu);
|
||||
error = platform_smp_next_cpu(&cpu);
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,7 +189,7 @@ cpu_mp_unleash(void *dummy)
|
||||
if (!pc->pc_bsp) {
|
||||
printf("Waking up CPU %d (dev=%x)\n", pc->pc_cpuid,
|
||||
pc->pc_hwref);
|
||||
powerpc_smp_start_cpu(pc);
|
||||
platform_smp_start_cpu(pc);
|
||||
} else {
|
||||
__asm __volatile("mfspr %0,1023" : "=r"(pc->pc_pir));
|
||||
pc->pc_awake = 1;
|
||||
|
177
sys/powerpc/powerpc/platform.c
Normal file
177
sys/powerpc/powerpc/platform.c
Normal file
@ -0,0 +1,177 @@
|
||||
/*-
|
||||
* Copyright (c) 2005 Peter Grehan
|
||||
* Copyright (c) 2009 Nathan Whitehorn
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* Dispatch platform calls to the appropriate platform implementation
|
||||
* through a previously registered kernel object.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/ktr.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/vm_page.h>
|
||||
|
||||
#include <machine/platform.h>
|
||||
#include <machine/platformvar.h>
|
||||
#include <machine/smp.h>
|
||||
|
||||
#include "platform_if.h"
|
||||
|
||||
static platform_def_t *plat_def_impl;
|
||||
static platform_t plat_obj;
|
||||
static struct kobj_ops plat_kernel_kops;
|
||||
static struct platform_kobj plat_kernel_obj;
|
||||
|
||||
static char plat_name[64] = "";
|
||||
SYSCTL_STRING(_hw, OID_AUTO, platform, CTLFLAG_RD | CTLFLAG_TUN,
|
||||
plat_name, 0, "Platform currently in use");
|
||||
|
||||
void
|
||||
mem_regions(struct mem_region **phys, int *physsz, struct mem_region **avail,
|
||||
int *availsz)
|
||||
{
|
||||
PLATFORM_MEM_REGIONS(plat_obj, phys, physsz, avail, availsz);
|
||||
}
|
||||
|
||||
const char *
|
||||
installed_platform()
|
||||
{
|
||||
return (plat_def_impl->name);
|
||||
}
|
||||
|
||||
u_long
|
||||
platform_timebase_freq(struct cpuref *cpu)
|
||||
{
|
||||
return (PLATFORM_TIMEBASE_FREQ(plat_obj, cpu));
|
||||
}
|
||||
|
||||
int
|
||||
platform_smp_first_cpu(struct cpuref *cpu)
|
||||
{
|
||||
return (PLATFORM_SMP_FIRST_CPU(plat_obj, cpu));
|
||||
}
|
||||
|
||||
int
|
||||
platform_smp_next_cpu(struct cpuref *cpu)
|
||||
{
|
||||
return (PLATFORM_SMP_NEXT_CPU(plat_obj, cpu));
|
||||
}
|
||||
|
||||
int
|
||||
platform_smp_get_bsp(struct cpuref *cpu)
|
||||
{
|
||||
return (PLATFORM_SMP_GET_BSP(plat_obj, cpu));
|
||||
}
|
||||
|
||||
int
|
||||
platform_smp_start_cpu(struct pcpu *cpu)
|
||||
{
|
||||
return (PLATFORM_SMP_START_CPU(plat_obj, cpu));
|
||||
}
|
||||
|
||||
/*
|
||||
* Platform install routines. Highest priority wins, using the same
|
||||
* algorithm as bus attachment.
|
||||
*/
|
||||
SET_DECLARE(platform_set, platform_def_t);
|
||||
|
||||
void
|
||||
platform_probe_and_attach()
|
||||
{
|
||||
platform_def_t **platpp, *platp;
|
||||
int prio, best_prio;
|
||||
|
||||
plat_obj = &plat_kernel_obj;
|
||||
best_prio = 0;
|
||||
|
||||
/*
|
||||
* Try to locate the best platform kobj
|
||||
*/
|
||||
SET_FOREACH(platpp, platform_set) {
|
||||
platp = *platpp;
|
||||
|
||||
/*
|
||||
* Take care of compiling the selected class, and
|
||||
* then statically initialise the MMU object
|
||||
*/
|
||||
kobj_class_compile_static(platp, &plat_kernel_kops);
|
||||
kobj_init((kobj_t)plat_obj, platp);
|
||||
|
||||
prio = PLATFORM_PROBE(plat_obj);
|
||||
|
||||
/* Check for errors */
|
||||
if (prio > 0)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Check if this module was specifically requested through
|
||||
* the loader tunable we provide.
|
||||
*/
|
||||
if (strcmp(platp->name,plat_name) == 0) {
|
||||
plat_def_impl = platp;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Otherwise, see if it is better than our current best */
|
||||
if (plat_def_impl == NULL || prio > best_prio) {
|
||||
best_prio = prio;
|
||||
plat_def_impl = platp;
|
||||
}
|
||||
|
||||
/*
|
||||
* We can't free the KOBJ, since it is static. Luckily,
|
||||
* this has no ill effects since it gets reset every time.
|
||||
*/
|
||||
}
|
||||
|
||||
if (plat_def_impl == NULL)
|
||||
panic("No platform module found!");
|
||||
|
||||
/*
|
||||
* Recompile to make sure we ended with the
|
||||
* correct one, and then attach.
|
||||
*/
|
||||
|
||||
kobj_class_compile_static(plat_def_impl, &plat_kernel_kops);
|
||||
kobj_init((kobj_t)plat_obj, plat_def_impl);
|
||||
|
||||
strlcpy(plat_name,plat_def_impl->name,sizeof(plat_name));
|
||||
|
||||
PLATFORM_ATTACH(plat_obj);
|
||||
}
|
||||
|
163
sys/powerpc/powerpc/platform_if.m
Normal file
163
sys/powerpc/powerpc/platform_if.m
Normal file
@ -0,0 +1,163 @@
|
||||
#-
|
||||
# Copyright (c) 2009 Nathan Whitehorn
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
# SUCH DAMAGE.
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
#include <machine/platform.h>
|
||||
#include <machine/platformvar.h>
|
||||
#include <machine/smp.h>
|
||||
|
||||
/**
|
||||
* @defgroup PLATFORM platform - KObj methods for PowerPC platform
|
||||
* implementations
|
||||
* @brief A set of methods required by all platform implementations.
|
||||
* These are used to bring up secondary CPUs, supply the physical memory
|
||||
* map, etc.
|
||||
*@{
|
||||
*/
|
||||
|
||||
INTERFACE platform;
|
||||
|
||||
#
|
||||
# Default implementations
|
||||
#
|
||||
CODE {
|
||||
static void platform_null_attach(platform_t plat)
|
||||
{
|
||||
return;
|
||||
}
|
||||
static int platform_null_smp_first_cpu(platform_t plat,
|
||||
struct cpuref *cpuref)
|
||||
{
|
||||
cpuref->cr_hwref = -1;
|
||||
cpuref->cr_cpuid = 0;
|
||||
return (0);
|
||||
}
|
||||
static int platform_null_smp_next_cpu(platform_t plat,
|
||||
struct cpuref *_cpuref)
|
||||
{
|
||||
return (ENOENT);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Probe for whether we are on this platform, returning the standard
|
||||
* newbus probe codes. If we have Open Firmware or a flattened device tree,
|
||||
* it is guaranteed to be available at this point.
|
||||
*/
|
||||
METHOD int probe {
|
||||
platform_t _plat;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Attach this platform module. This happens before the MMU is online,
|
||||
* so the platform module can install its own high-priority MMU module at
|
||||
* this point.
|
||||
*/
|
||||
METHOD int attach {
|
||||
platform_t _plat;
|
||||
} DEFAULT platform_null_attach;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Return the system's physical memory map.
|
||||
*
|
||||
* It shall provide the total and the available regions of RAM.
|
||||
* The available regions need not take the kernel into account.
|
||||
*
|
||||
* @param _memp Array of physical memory chunks
|
||||
* @param _memsz Number of physical memory chunks
|
||||
* @param _availp Array of available physical memory chunks
|
||||
* @param _availsz Number of available physical memory chunks
|
||||
*/
|
||||
|
||||
METHOD void mem_regions {
|
||||
platform_t _plat;
|
||||
struct mem_region **_memp;
|
||||
int *_memsz;
|
||||
struct mem_region **_availp;
|
||||
int *_availsz;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get the CPU's timebase frequency, in ticks per second.
|
||||
*
|
||||
* @param _cpu CPU whose timebase to query
|
||||
*/
|
||||
|
||||
METHOD u_long timebase_freq {
|
||||
platform_t _plat;
|
||||
struct cpuref *_cpu;
|
||||
};
|
||||
|
||||
# SMP bits
|
||||
|
||||
/**
|
||||
* @brief Fill the first CPU's cpuref
|
||||
*
|
||||
* @param _cpuref CPU
|
||||
*/
|
||||
METHOD int smp_first_cpu {
|
||||
platform_t _plat;
|
||||
struct cpuref *_cpuref;
|
||||
} DEFAULT platform_null_smp_first_cpu;
|
||||
|
||||
/**
|
||||
* @brief Fill the next CPU's cpuref
|
||||
*
|
||||
* @param _cpuref CPU
|
||||
*/
|
||||
METHOD int smp_next_cpu {
|
||||
platform_t _plat;
|
||||
struct cpuref *_cpuref;
|
||||
} DEFAULT platform_null_smp_next_cpu;
|
||||
|
||||
/**
|
||||
* @brief Find the boot processor
|
||||
*
|
||||
* @param _cpuref CPU
|
||||
*/
|
||||
METHOD int smp_get_bsp {
|
||||
platform_t _plat;
|
||||
struct cpuref *_cpuref;
|
||||
} DEFAULT platform_null_smp_first_cpu;
|
||||
|
||||
/**
|
||||
* @brief Start a CPU
|
||||
*
|
||||
* @param _cpuref CPU
|
||||
*/
|
||||
METHOD int smp_start_cpu {
|
||||
platform_t _plat;
|
||||
struct pcpu *_cpu;
|
||||
};
|
||||
|
@ -509,7 +509,7 @@ pmap_mmu_install(char *name, int prio)
|
||||
|
||||
if (mmup->name &&
|
||||
!strcmp(mmup->name, name) &&
|
||||
prio >= curr_prio) {
|
||||
(prio >= curr_prio || mmu_def_impl == NULL)) {
|
||||
curr_prio = prio;
|
||||
mmu_def_impl = mmup;
|
||||
return (TRUE);
|
||||
|
Loading…
Reference in New Issue
Block a user