2009-05-14 00:34:26 +00:00
|
|
|
/*-
|
|
|
|
* 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>
|
2009-10-18 17:22:08 +00:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/pmap.h>
|
2009-05-14 00:34:26 +00:00
|
|
|
|
2014-01-31 03:55:34 +00:00
|
|
|
#include <machine/altivec.h> /* For save_vec() */
|
2009-05-14 00:34:26 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/cpu.h>
|
2014-01-31 03:55:34 +00:00
|
|
|
#include <machine/fpu.h> /* For save_fpu() */
|
2009-05-14 00:34:26 +00:00
|
|
|
#include <machine/hid.h>
|
|
|
|
#include <machine/platformvar.h>
|
2014-01-31 03:55:34 +00:00
|
|
|
#include <machine/setjmp.h>
|
2009-05-14 00:34:26 +00:00
|
|
|
#include <machine/smp.h>
|
|
|
|
#include <machine/spr.h>
|
|
|
|
|
|
|
|
#include <dev/ofw/openfirm.h>
|
|
|
|
#include <machine/ofw_machdep.h>
|
|
|
|
|
|
|
|
#include "platform_if.h"
|
|
|
|
|
|
|
|
extern void *ap_pcpu;
|
|
|
|
|
2010-08-31 15:27:46 +00:00
|
|
|
static int powermac_probe(platform_t);
|
2013-09-27 13:12:47 +00:00
|
|
|
static int powermac_attach(platform_t);
|
2013-12-01 19:43:15 +00:00
|
|
|
void powermac_mem_regions(platform_t, struct mem_region *phys, int *physsz,
|
|
|
|
struct mem_region *avail, int *availsz);
|
2010-08-31 15:27:46 +00:00
|
|
|
static u_long powermac_timebase_freq(platform_t, struct cpuref *cpuref);
|
|
|
|
static int powermac_smp_first_cpu(platform_t, struct cpuref *cpuref);
|
|
|
|
static int powermac_smp_next_cpu(platform_t, struct cpuref *cpuref);
|
|
|
|
static int powermac_smp_get_bsp(platform_t, struct cpuref *cpuref);
|
|
|
|
static int powermac_smp_start_cpu(platform_t, struct pcpu *cpu);
|
|
|
|
static void powermac_reset(platform_t);
|
2014-01-31 03:55:34 +00:00
|
|
|
static void powermac_sleep(platform_t);
|
2010-08-31 15:27:46 +00:00
|
|
|
|
|
|
|
static platform_method_t powermac_methods[] = {
|
|
|
|
PLATFORMMETHOD(platform_probe, powermac_probe),
|
2013-09-27 13:12:47 +00:00
|
|
|
PLATFORMMETHOD(platform_attach, powermac_attach),
|
2010-08-31 15:27:46 +00:00
|
|
|
PLATFORMMETHOD(platform_mem_regions, powermac_mem_regions),
|
|
|
|
PLATFORMMETHOD(platform_timebase_freq, powermac_timebase_freq),
|
2009-05-14 00:34:26 +00:00
|
|
|
|
2010-08-31 15:27:46 +00:00
|
|
|
PLATFORMMETHOD(platform_smp_first_cpu, powermac_smp_first_cpu),
|
|
|
|
PLATFORMMETHOD(platform_smp_next_cpu, powermac_smp_next_cpu),
|
|
|
|
PLATFORMMETHOD(platform_smp_get_bsp, powermac_smp_get_bsp),
|
|
|
|
PLATFORMMETHOD(platform_smp_start_cpu, powermac_smp_start_cpu),
|
|
|
|
|
|
|
|
PLATFORMMETHOD(platform_reset, powermac_reset),
|
2014-01-31 03:55:34 +00:00
|
|
|
PLATFORMMETHOD(platform_sleep, powermac_sleep),
|
2009-05-14 00:34:26 +00:00
|
|
|
|
2013-02-13 02:21:45 +00:00
|
|
|
PLATFORMMETHOD_END
|
2009-05-14 00:34:26 +00:00
|
|
|
};
|
|
|
|
|
2010-08-31 15:27:46 +00:00
|
|
|
static platform_def_t powermac_platform = {
|
|
|
|
"powermac",
|
|
|
|
powermac_methods,
|
2009-05-14 00:34:26 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2010-08-31 15:27:46 +00:00
|
|
|
PLATFORM_DEF(powermac_platform);
|
2009-05-14 00:34:26 +00:00
|
|
|
|
|
|
|
static int
|
2010-08-31 15:27:46 +00:00
|
|
|
powermac_probe(platform_t plat)
|
2009-05-14 00:34:26 +00:00
|
|
|
{
|
2013-09-09 12:54:08 +00:00
|
|
|
char compat[255];
|
|
|
|
ssize_t compatlen;
|
|
|
|
char *curstr;
|
|
|
|
phandle_t root;
|
|
|
|
|
|
|
|
root = OF_peer(0);
|
|
|
|
if (root == 0)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
compatlen = OF_getprop(root, "compatible", compat, sizeof(compat));
|
|
|
|
|
|
|
|
for (curstr = compat; curstr < compat + compatlen;
|
|
|
|
curstr += strlen(curstr) + 1) {
|
|
|
|
if (strncmp(curstr, "MacRISC", 7) == 0)
|
|
|
|
return (BUS_PROBE_SPECIFIC);
|
|
|
|
}
|
2009-05-14 00:34:26 +00:00
|
|
|
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-12-01 19:43:15 +00:00
|
|
|
powermac_mem_regions(platform_t plat, struct mem_region *phys, int *physsz,
|
|
|
|
struct mem_region *avail, int *availsz)
|
2009-05-14 00:34:26 +00:00
|
|
|
{
|
2013-12-01 19:43:15 +00:00
|
|
|
phandle_t memory;
|
|
|
|
cell_t memoryprop[PHYS_AVAIL_SZ * 2];
|
|
|
|
ssize_t propsize, i, j;
|
|
|
|
int physacells = 1;
|
|
|
|
|
|
|
|
memory = OF_finddevice("/memory");
|
2015-03-10 16:01:43 +00:00
|
|
|
if (memory == -1)
|
|
|
|
memory = OF_finddevice("/memory@0");
|
2013-12-01 19:43:15 +00:00
|
|
|
|
|
|
|
/* "reg" has variable #address-cells, but #size-cells is always 1 */
|
|
|
|
OF_getprop(OF_parent(memory), "#address-cells", &physacells,
|
|
|
|
sizeof(physacells));
|
|
|
|
|
|
|
|
propsize = OF_getprop(memory, "reg", memoryprop, sizeof(memoryprop));
|
|
|
|
propsize /= sizeof(cell_t);
|
|
|
|
for (i = 0, j = 0; i < propsize; i += physacells+1, j++) {
|
|
|
|
phys[j].mr_start = memoryprop[i];
|
|
|
|
if (physacells == 2) {
|
|
|
|
#ifndef __powerpc64__
|
|
|
|
/* On 32-bit PPC, ignore regions starting above 4 GB */
|
|
|
|
if (memoryprop[i] != 0) {
|
|
|
|
j--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
phys[j].mr_start <<= 32;
|
|
|
|
#endif
|
|
|
|
phys[j].mr_start |= memoryprop[i+1];
|
|
|
|
}
|
|
|
|
phys[j].mr_size = memoryprop[i + physacells];
|
|
|
|
}
|
|
|
|
*physsz = j;
|
|
|
|
|
|
|
|
/* "available" always has #address-cells = 1 */
|
|
|
|
propsize = OF_getprop(memory, "available", memoryprop,
|
|
|
|
sizeof(memoryprop));
|
2015-03-10 16:01:43 +00:00
|
|
|
if (propsize <= 0) {
|
|
|
|
for (i = 0; i < *physsz; i++) {
|
|
|
|
avail[i].mr_start = phys[i].mr_start;
|
|
|
|
avail[i].mr_size = phys[i].mr_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
*availsz = *physsz;
|
|
|
|
} else {
|
|
|
|
propsize /= sizeof(cell_t);
|
|
|
|
for (i = 0, j = 0; i < propsize; i += 2, j++) {
|
|
|
|
avail[j].mr_start = memoryprop[i];
|
|
|
|
avail[j].mr_size = memoryprop[i + 1];
|
|
|
|
}
|
2013-12-01 19:43:15 +00:00
|
|
|
|
|
|
|
#ifdef __powerpc64__
|
2015-03-10 16:01:43 +00:00
|
|
|
/* Add in regions above 4 GB to the available list */
|
|
|
|
for (i = 0; i < *physsz; i++) {
|
|
|
|
if (phys[i].mr_start > BUS_SPACE_MAXADDR_32BIT) {
|
|
|
|
avail[j].mr_start = phys[i].mr_start;
|
|
|
|
avail[j].mr_size = phys[i].mr_size;
|
|
|
|
j++;
|
|
|
|
}
|
2013-12-01 19:43:15 +00:00
|
|
|
}
|
|
|
|
#endif
|
2015-03-10 16:01:43 +00:00
|
|
|
*availsz = j;
|
|
|
|
}
|
2009-05-14 00:34:26 +00:00
|
|
|
}
|
|
|
|
|
2013-09-27 13:12:47 +00:00
|
|
|
static int
|
|
|
|
powermac_attach(platform_t plat)
|
|
|
|
{
|
|
|
|
phandle_t rootnode;
|
|
|
|
char model[32];
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Quiesce Open Firmware on PowerMac11,2 and 12,1. It is
|
|
|
|
* necessary there to shut down a background thread doing fan
|
|
|
|
* management, and is harmful on other machines (it will make OF
|
|
|
|
* shut off power to various system components it had turned on).
|
|
|
|
*
|
|
|
|
* Note: we don't need to worry about which OF module we are
|
|
|
|
* using since this is called only from very early boot, within
|
|
|
|
* OF's boot context.
|
|
|
|
*/
|
|
|
|
|
|
|
|
rootnode = OF_finddevice("/");
|
|
|
|
if (OF_getprop(rootnode, "model", model, sizeof(model)) > 0) {
|
|
|
|
if (strcmp(model, "PowerMac11,2") == 0 ||
|
|
|
|
strcmp(model, "PowerMac12,1") == 0) {
|
|
|
|
ofw_quiesce();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2009-05-14 00:34:26 +00:00
|
|
|
static u_long
|
2010-08-31 15:27:46 +00:00
|
|
|
powermac_timebase_freq(platform_t plat, struct cpuref *cpuref)
|
2009-05-14 00:34:26 +00:00
|
|
|
{
|
|
|
|
phandle_t phandle;
|
2010-07-09 14:02:24 +00:00
|
|
|
int32_t ticks = -1;
|
2009-05-14 00:34:26 +00:00
|
|
|
|
|
|
|
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
|
2010-08-31 15:27:46 +00:00
|
|
|
powermac_smp_fill_cpuref(struct cpuref *cpuref, phandle_t cpu)
|
2009-05-14 00:34:26 +00:00
|
|
|
{
|
2013-12-07 22:25:07 +00:00
|
|
|
cell_t cpuid;
|
|
|
|
int res;
|
2009-05-14 00:34:26 +00:00
|
|
|
|
|
|
|
cpuref->cr_hwref = cpu;
|
|
|
|
res = OF_getprop(cpu, "reg", &cpuid, sizeof(cpuid));
|
2009-06-10 12:47:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* psim doesn't have a reg property, so assume 0 as for the
|
|
|
|
* uniprocessor case in the CHRP spec.
|
|
|
|
*/
|
|
|
|
if (res < 0) {
|
|
|
|
cpuid = 0;
|
|
|
|
}
|
2009-05-14 00:34:26 +00:00
|
|
|
|
|
|
|
cpuref->cr_cpuid = cpuid & 0xff;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-08-31 15:27:46 +00:00
|
|
|
powermac_smp_first_cpu(platform_t plat, struct cpuref *cpuref)
|
2009-05-14 00:34:26 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2009-06-10 12:47:54 +00:00
|
|
|
if (dev == 0) {
|
|
|
|
/*
|
|
|
|
* psim doesn't have a name property on the /cpus node,
|
|
|
|
* but it can be found directly
|
|
|
|
*/
|
|
|
|
dev = OF_finddevice("/cpus");
|
2011-12-02 15:24:39 +00:00
|
|
|
if (dev == -1)
|
2009-06-10 12:47:54 +00:00
|
|
|
return (ENOENT);
|
|
|
|
}
|
2009-05-14 00:34:26 +00:00
|
|
|
|
|
|
|
cpu = OF_child(dev);
|
2009-06-10 12:47:54 +00:00
|
|
|
|
2009-05-14 00:34:26 +00:00
|
|
|
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);
|
|
|
|
|
2010-08-31 15:27:46 +00:00
|
|
|
return (powermac_smp_fill_cpuref(cpuref, cpu));
|
2009-05-14 00:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-08-31 15:27:46 +00:00
|
|
|
powermac_smp_next_cpu(platform_t plat, struct cpuref *cpuref)
|
2009-05-14 00:34:26 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2010-08-31 15:27:46 +00:00
|
|
|
return (powermac_smp_fill_cpuref(cpuref, cpu));
|
2009-05-14 00:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-08-31 15:27:46 +00:00
|
|
|
powermac_smp_get_bsp(platform_t plat, struct cpuref *cpuref)
|
2009-05-14 00:34:26 +00:00
|
|
|
{
|
|
|
|
ihandle_t inst;
|
|
|
|
phandle_t bsp, chosen;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
chosen = OF_finddevice("/chosen");
|
2011-12-02 15:24:39 +00:00
|
|
|
if (chosen == -1)
|
2009-05-14 00:34:26 +00:00
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
res = OF_getprop(chosen, "cpu", &inst, sizeof(inst));
|
|
|
|
if (res < 0)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
bsp = OF_instance_to_package(inst);
|
2010-08-31 15:27:46 +00:00
|
|
|
return (powermac_smp_fill_cpuref(cpuref, bsp));
|
2009-05-14 00:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-08-31 15:27:46 +00:00
|
|
|
powermac_smp_start_cpu(platform_t plat, struct pcpu *pc)
|
2009-05-14 00:34:26 +00:00
|
|
|
{
|
|
|
|
#ifdef SMP
|
|
|
|
phandle_t cpu;
|
|
|
|
volatile uint8_t *rstvec;
|
2009-10-18 17:22:08 +00:00
|
|
|
static volatile uint8_t *rstvec_virtbase = NULL;
|
2009-05-14 00:34:26 +00:00
|
|
|
int res, reset, timeout;
|
|
|
|
|
|
|
|
cpu = pc->pc_hwref;
|
|
|
|
res = OF_getprop(cpu, "soft-reset", &reset, sizeof(reset));
|
2010-06-12 21:14:22 +00:00
|
|
|
if (res < 0) {
|
|
|
|
reset = 0x58;
|
|
|
|
|
|
|
|
switch (pc->pc_cpuid) {
|
|
|
|
case 0:
|
|
|
|
reset += 0x03;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
reset += 0x04;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
reset += 0x0f;
|
|
|
|
break;
|
2010-07-09 14:04:16 +00:00
|
|
|
case 3:
|
2010-06-12 21:14:22 +00:00
|
|
|
reset += 0x10;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
}
|
2009-05-14 00:34:26 +00:00
|
|
|
|
|
|
|
ap_pcpu = pc;
|
|
|
|
|
2009-10-18 17:22:08 +00:00
|
|
|
if (rstvec_virtbase == NULL)
|
|
|
|
rstvec_virtbase = pmap_mapdev(0x80000000, PAGE_SIZE);
|
|
|
|
|
|
|
|
rstvec = rstvec_virtbase + reset;
|
2009-05-14 00:34:26 +00:00
|
|
|
|
|
|
|
*rstvec = 4;
|
2010-06-12 21:14:22 +00:00
|
|
|
powerpc_sync();
|
2009-10-23 03:17:02 +00:00
|
|
|
(void)(*rstvec);
|
2009-05-14 00:34:26 +00:00
|
|
|
powerpc_sync();
|
|
|
|
DELAY(1);
|
|
|
|
*rstvec = 0;
|
2010-06-12 21:14:22 +00:00
|
|
|
powerpc_sync();
|
2009-10-23 03:17:02 +00:00
|
|
|
(void)(*rstvec);
|
2009-05-14 00:34:26 +00:00
|
|
|
powerpc_sync();
|
|
|
|
|
2009-10-23 03:17:02 +00:00
|
|
|
timeout = 10000;
|
2009-05-14 00:34:26 +00:00
|
|
|
while (!pc->pc_awake && timeout--)
|
|
|
|
DELAY(100);
|
|
|
|
|
|
|
|
return ((pc->pc_awake) ? 0 : EBUSY);
|
|
|
|
#else
|
|
|
|
/* No SMP support */
|
|
|
|
return (ENXIO);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-08-31 15:27:46 +00:00
|
|
|
static void
|
|
|
|
powermac_reset(platform_t platform)
|
|
|
|
{
|
|
|
|
OF_reboot();
|
|
|
|
}
|
|
|
|
|
2014-01-31 03:55:34 +00:00
|
|
|
void
|
|
|
|
powermac_sleep(platform_t platform)
|
|
|
|
{
|
|
|
|
|
|
|
|
*(unsigned long *)0x80 = 0x100;
|
|
|
|
cpu_sleep();
|
|
|
|
}
|
|
|
|
|