diff options
author | nwhitehorn <nwhitehorn@FreeBSD.org> | 2009-05-14 00:34:26 +0000 |
---|---|---|
committer | nwhitehorn <nwhitehorn@FreeBSD.org> | 2009-05-14 00:34:26 +0000 |
commit | dc1ac440de95721f8b696146577a51ef7a418f59 (patch) | |
tree | 76fac3396a64c911f78e68ca8b02794bc0332825 /sys/powerpc/aim | |
parent | d9c2725c3513aa19672b456422a31a356dccffc5 (diff) | |
download | FreeBSD-src-dc1ac440de95721f8b696146577a51ef7a418f59.zip FreeBSD-src-dc1ac440de95721f8b696146577a51ef7a418f59.tar.gz |
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
Diffstat (limited to 'sys/powerpc/aim')
-rw-r--r-- | sys/powerpc/aim/clock.c | 53 | ||||
-rw-r--r-- | sys/powerpc/aim/machdep.c | 15 | ||||
-rw-r--r-- | sys/powerpc/aim/mmu_oea.c | 2 | ||||
-rw-r--r-- | sys/powerpc/aim/mmu_oea64.c | 2 | ||||
-rw-r--r-- | sys/powerpc/aim/mp_cpudep.c | 113 | ||||
-rw-r--r-- | sys/powerpc/aim/ofw_machdep.c | 4 | ||||
-rw-r--r-- | sys/powerpc/aim/platform_chrp.c | 236 | ||||
-rw-r--r-- | sys/powerpc/aim/vm_machdep.c | 1 |
8 files changed, 269 insertions, 157 deletions
diff --git a/sys/powerpc/aim/clock.c b/sys/powerpc/aim/clock.c index ac6aa2d..2d3eb60 100644 --- a/sys/powerpc/aim/clock.c +++ b/sys/powerpc/aim/clock.c @@ -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); - - mtmsr(msr); - - 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"); + + 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); + + ns_per_tick = 1000000000 / ticks_per_sec; + ticks_per_intr = ticks_per_sec / hz; + mtdec(ticks_per_intr); + + mtmsr(msr); } void diff --git a/sys/powerpc/aim/machdep.c b/sys/powerpc/aim/machdep.c index 4e8909f..590741c 100644 --- a/sys/powerpc/aim/machdep.c +++ b/sys/powerpc/aim/machdep.c @@ -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); diff --git a/sys/powerpc/aim/mmu_oea.c b/sys/powerpc/aim/mmu_oea.c index 71947fa..7eb4beb 100644 --- a/sys/powerpc/aim/mmu_oea.c +++ b/sys/powerpc/aim/mmu_oea.c @@ -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> diff --git a/sys/powerpc/aim/mmu_oea64.c b/sys/powerpc/aim/mmu_oea64.c index 64e8c75..4590363 100644 --- a/sys/powerpc/aim/mmu_oea64.c +++ b/sys/powerpc/aim/mmu_oea64.c @@ -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> diff --git a/sys/powerpc/aim/mp_cpudep.c b/sys/powerpc/aim/mp_cpudep.c index e226d3b..1dc9525 100644 --- a/sys/powerpc/aim/mp_cpudep.c +++ b/sys/powerpc/aim/mp_cpudep.c @@ -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); -} diff --git a/sys/powerpc/aim/ofw_machdep.c b/sys/powerpc/aim/ofw_machdep.c index 977f81a..773d229 100644 --- a/sys/powerpc/aim/ofw_machdep.c +++ b/sys/powerpc/aim/ofw_machdep.c @@ -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; diff --git a/sys/powerpc/aim/platform_chrp.c b/sys/powerpc/aim/platform_chrp.c new file mode 100644 index 0000000..48c7a91 --- /dev/null +++ b/sys/powerpc/aim/platform_chrp.c @@ -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 +} + diff --git a/sys/powerpc/aim/vm_machdep.c b/sys/powerpc/aim/vm_machdep.c index e20ba7b..af83854 100644 --- a/sys/powerpc/aim/vm_machdep.c +++ b/sys/powerpc/aim/vm_machdep.c @@ -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> |