mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-16 05:13:40 +00:00
PPC64: use hwref instead of cpuid
On CHRP and PowerNV, use the interrupt server number in the cpuref and pcpu hwref field instead of the device-tree phandle and make the CPU IDs reported to the scheduler dense and with the BSP at 0. Submitted by: Wojciech Macek <wma@semihalf.com> Obtained from: Semihalf Sponsored by: IBM, QCM Technologies Differential revision: https://reviews.freebsd.org/D14011
This commit is contained in:
parent
b74fb1e713
commit
f0393bbf34
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=328534
|
@ -1,5 +1,6 @@
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2015 Nathan Whitehorn
|
* Copyright (c) 2015 Nathan Whitehorn
|
||||||
|
* Copyright (c) 2017-2018 Semihalf
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -73,6 +74,7 @@ static struct cpu_group *powernv_smp_topo(platform_t plat);
|
||||||
#endif
|
#endif
|
||||||
static void powernv_reset(platform_t);
|
static void powernv_reset(platform_t);
|
||||||
static void powernv_cpu_idle(sbintime_t sbt);
|
static void powernv_cpu_idle(sbintime_t sbt);
|
||||||
|
static int powernv_cpuref_init(void);
|
||||||
|
|
||||||
static platform_method_t powernv_methods[] = {
|
static platform_method_t powernv_methods[] = {
|
||||||
PLATFORMMETHOD(platform_probe, powernv_probe),
|
PLATFORMMETHOD(platform_probe, powernv_probe),
|
||||||
|
@ -100,9 +102,13 @@ static platform_def_t powernv_platform = {
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static struct cpuref platform_cpuref[MAXCPU];
|
||||||
|
static int platform_cpuref_cnt;
|
||||||
|
static int platform_cpuref_valid;
|
||||||
|
|
||||||
PLATFORM_DEF(powernv_platform);
|
PLATFORM_DEF(powernv_platform);
|
||||||
|
|
||||||
static int powernv_boot_pir;
|
static uint64_t powernv_boot_pir;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
powernv_probe(platform_t plat)
|
powernv_probe(platform_t plat)
|
||||||
|
@ -126,12 +132,20 @@ powernv_attach(platform_t plat)
|
||||||
/* Ping OPAL again just to make sure */
|
/* Ping OPAL again just to make sure */
|
||||||
opal_check();
|
opal_check();
|
||||||
|
|
||||||
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||||
|
opal_call(OPAL_REINIT_CPUS, 2 /* Little endian */);
|
||||||
|
#else
|
||||||
|
opal_call(OPAL_REINIT_CPUS, 1 /* Big endian */);
|
||||||
|
#endif
|
||||||
|
|
||||||
cpu_idle_hook = powernv_cpu_idle;
|
cpu_idle_hook = powernv_cpu_idle;
|
||||||
powernv_boot_pir = mfspr(SPR_PIR);
|
powernv_boot_pir = mfspr(SPR_PIR);
|
||||||
|
|
||||||
/* Init CPU bits */
|
/* Init CPU bits */
|
||||||
powernv_smp_ap_init(plat);
|
powernv_smp_ap_init(plat);
|
||||||
|
|
||||||
|
powernv_cpuref_init();
|
||||||
|
|
||||||
/* Set SLB count from device tree */
|
/* Set SLB count from device tree */
|
||||||
cpu = OF_peer(0);
|
cpu = OF_peer(0);
|
||||||
cpu = OF_child(cpu);
|
cpu = OF_child(cpu);
|
||||||
|
@ -218,29 +232,13 @@ powernv_mem_regions(platform_t plat, struct mem_region *phys, int *physsz,
|
||||||
|
|
||||||
static u_long
|
static u_long
|
||||||
powernv_timebase_freq(platform_t plat, struct cpuref *cpuref)
|
powernv_timebase_freq(platform_t plat, struct cpuref *cpuref)
|
||||||
{
|
|
||||||
phandle_t phandle;
|
|
||||||
int32_t ticks = -1;
|
|
||||||
|
|
||||||
phandle = cpuref->cr_hwref;
|
|
||||||
|
|
||||||
OF_getencprop(phandle, "timebase-frequency", &ticks, sizeof(ticks));
|
|
||||||
|
|
||||||
if (ticks <= 0)
|
|
||||||
panic("Unable to determine timebase frequency!");
|
|
||||||
|
|
||||||
return (ticks);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
powernv_smp_first_cpu(platform_t plat, struct cpuref *cpuref)
|
|
||||||
{
|
{
|
||||||
char buf[8];
|
char buf[8];
|
||||||
phandle_t cpu, dev, root;
|
phandle_t cpu, dev, root;
|
||||||
int res, cpuid;
|
int res;
|
||||||
|
int32_t ticks = -1;
|
||||||
|
|
||||||
root = OF_peer(0);
|
root = OF_peer(0);
|
||||||
|
|
||||||
dev = OF_child(root);
|
dev = OF_child(root);
|
||||||
while (dev != 0) {
|
while (dev != 0) {
|
||||||
res = OF_getprop(dev, "name", buf, sizeof(buf));
|
res = OF_getprop(dev, "name", buf, sizeof(buf));
|
||||||
|
@ -248,35 +246,96 @@ powernv_smp_first_cpu(platform_t plat, struct cpuref *cpuref)
|
||||||
break;
|
break;
|
||||||
dev = OF_peer(dev);
|
dev = OF_peer(dev);
|
||||||
}
|
}
|
||||||
if (dev == 0) {
|
|
||||||
/*
|
|
||||||
* psim doesn't have a name property on the /cpus node,
|
|
||||||
* but it can be found directly
|
|
||||||
*/
|
|
||||||
dev = OF_finddevice("/cpus");
|
|
||||||
if (dev == 0)
|
|
||||||
return (ENOENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
cpu = OF_child(dev);
|
for (cpu = OF_child(dev); cpu != 0; cpu = OF_peer(cpu)) {
|
||||||
|
|
||||||
while (cpu != 0) {
|
|
||||||
res = OF_getprop(cpu, "device_type", buf, sizeof(buf));
|
res = OF_getprop(cpu, "device_type", buf, sizeof(buf));
|
||||||
if (res > 0 && strcmp(buf, "cpu") == 0)
|
if (res > 0 && strcmp(buf, "cpu") == 0)
|
||||||
break;
|
break;
|
||||||
cpu = OF_peer(cpu);
|
|
||||||
}
|
}
|
||||||
if (cpu == 0)
|
if (cpu == 0)
|
||||||
return (ENOENT);
|
return (512000000);
|
||||||
|
|
||||||
cpuref->cr_hwref = cpu;
|
OF_getencprop(cpu, "timebase-frequency", &ticks, sizeof(ticks));
|
||||||
res = OF_getencprop(cpu, "ibm,ppc-interrupt-server#s", &cpuid,
|
|
||||||
sizeof(cpuid));
|
if (ticks <= 0)
|
||||||
if (res <= 0)
|
panic("Unable to determine timebase frequency!");
|
||||||
res = OF_getencprop(cpu, "reg", &cpuid, sizeof(cpuid));
|
|
||||||
if (res <= 0)
|
return (ticks);
|
||||||
cpuid = 0;
|
|
||||||
cpuref->cr_cpuid = cpuid;
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
powernv_cpuref_init(void)
|
||||||
|
{
|
||||||
|
phandle_t cpu, dev;
|
||||||
|
char buf[32];
|
||||||
|
int a, res, tmp_cpuref_cnt;
|
||||||
|
static struct cpuref tmp_cpuref[MAXCPU];
|
||||||
|
cell_t interrupt_servers[32];
|
||||||
|
uint64_t bsp;
|
||||||
|
|
||||||
|
if (platform_cpuref_valid)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
dev = OF_peer(0);
|
||||||
|
dev = OF_child(dev);
|
||||||
|
while (dev != 0) {
|
||||||
|
res = OF_getprop(dev, "name", buf, sizeof(buf));
|
||||||
|
if (res > 0 && strcmp(buf, "cpus") == 0)
|
||||||
|
break;
|
||||||
|
dev = OF_peer(dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
bsp = 0;
|
||||||
|
tmp_cpuref_cnt = 0;
|
||||||
|
for (cpu = OF_child(dev); cpu != 0; cpu = OF_peer(cpu)) {
|
||||||
|
res = OF_getprop(cpu, "device_type", buf, sizeof(buf));
|
||||||
|
if (res > 0 && strcmp(buf, "cpu") == 0) {
|
||||||
|
res = OF_getproplen(cpu, "ibm,ppc-interrupt-server#s");
|
||||||
|
if (res > 0) {
|
||||||
|
|
||||||
|
|
||||||
|
OF_getencprop(cpu, "ibm,ppc-interrupt-server#s",
|
||||||
|
interrupt_servers, res);
|
||||||
|
|
||||||
|
for (a = 0; a < res/sizeof(cell_t); a++) {
|
||||||
|
tmp_cpuref[tmp_cpuref_cnt].cr_hwref = interrupt_servers[a];
|
||||||
|
tmp_cpuref[tmp_cpuref_cnt].cr_cpuid = tmp_cpuref_cnt;
|
||||||
|
|
||||||
|
if (interrupt_servers[a] == (uint32_t)powernv_boot_pir)
|
||||||
|
bsp = tmp_cpuref_cnt;
|
||||||
|
|
||||||
|
tmp_cpuref_cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Map IDs, so BSP has CPUID 0 regardless of hwref */
|
||||||
|
for (a = bsp; a < tmp_cpuref_cnt; a++) {
|
||||||
|
platform_cpuref[platform_cpuref_cnt].cr_hwref = tmp_cpuref[a].cr_hwref;
|
||||||
|
platform_cpuref[platform_cpuref_cnt].cr_cpuid = platform_cpuref_cnt;
|
||||||
|
platform_cpuref_cnt++;
|
||||||
|
}
|
||||||
|
for (a = 0; a < bsp; a++) {
|
||||||
|
platform_cpuref[platform_cpuref_cnt].cr_hwref = tmp_cpuref[a].cr_hwref;
|
||||||
|
platform_cpuref[platform_cpuref_cnt].cr_cpuid = platform_cpuref_cnt;
|
||||||
|
platform_cpuref_cnt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
platform_cpuref_valid = 1;
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
powernv_smp_first_cpu(platform_t plat, struct cpuref *cpuref)
|
||||||
|
{
|
||||||
|
if (platform_cpuref_valid == 0)
|
||||||
|
return (EINVAL);
|
||||||
|
|
||||||
|
cpuref->cr_cpuid = 0;
|
||||||
|
cpuref->cr_hwref = platform_cpuref[0].cr_hwref;
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -284,43 +343,17 @@ powernv_smp_first_cpu(platform_t plat, struct cpuref *cpuref)
|
||||||
static int
|
static int
|
||||||
powernv_smp_next_cpu(platform_t plat, struct cpuref *cpuref)
|
powernv_smp_next_cpu(platform_t plat, struct cpuref *cpuref)
|
||||||
{
|
{
|
||||||
char buf[8];
|
int id;
|
||||||
phandle_t cpu;
|
|
||||||
int i, res, cpuid;
|
|
||||||
|
|
||||||
/* Check for whether it should be the next thread */
|
if (platform_cpuref_valid == 0)
|
||||||
res = OF_getproplen(cpuref->cr_hwref, "ibm,ppc-interrupt-server#s");
|
return (EINVAL);
|
||||||
if (res > 0) {
|
|
||||||
cell_t interrupt_servers[res/sizeof(cell_t)];
|
|
||||||
OF_getencprop(cpuref->cr_hwref, "ibm,ppc-interrupt-server#s",
|
|
||||||
interrupt_servers, res);
|
|
||||||
for (i = 0; i < res/sizeof(cell_t) - 1; i++) {
|
|
||||||
if (interrupt_servers[i] == cpuref->cr_cpuid) {
|
|
||||||
cpuref->cr_cpuid = interrupt_servers[i+1];
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Next CPU core/package */
|
id = cpuref->cr_cpuid + 1;
|
||||||
cpu = OF_peer(cpuref->cr_hwref);
|
if (id >= platform_cpuref_cnt)
|
||||||
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 (ENOENT);
|
||||||
|
|
||||||
cpuref->cr_hwref = cpu;
|
cpuref->cr_cpuid = platform_cpuref[id].cr_cpuid;
|
||||||
res = OF_getencprop(cpu, "ibm,ppc-interrupt-server#s", &cpuid,
|
cpuref->cr_hwref = platform_cpuref[id].cr_hwref;
|
||||||
sizeof(cpuid));
|
|
||||||
if (res <= 0)
|
|
||||||
res = OF_getencprop(cpu, "reg", &cpuid, sizeof(cpuid));
|
|
||||||
if (res <= 0)
|
|
||||||
cpuid = 0;
|
|
||||||
cpuref->cr_cpuid = cpuid;
|
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -328,35 +361,9 @@ powernv_smp_next_cpu(platform_t plat, struct cpuref *cpuref)
|
||||||
static int
|
static int
|
||||||
powernv_smp_get_bsp(platform_t plat, struct cpuref *cpuref)
|
powernv_smp_get_bsp(platform_t plat, struct cpuref *cpuref)
|
||||||
{
|
{
|
||||||
phandle_t chosen;
|
|
||||||
int cpuid, res;
|
|
||||||
struct cpuref i;
|
|
||||||
|
|
||||||
chosen = OF_finddevice("/chosen");
|
|
||||||
if (chosen == 0)
|
|
||||||
return (ENOENT);
|
|
||||||
|
|
||||||
res = OF_getencprop(chosen, "fdtbootcpu", &cpuid, sizeof(cpuid));
|
|
||||||
if (res < 0)
|
|
||||||
return (ENOENT);
|
|
||||||
|
|
||||||
/* XXX: FDT from kexec lies sometimes. PIR seems not to. */
|
|
||||||
if (cpuid == 0)
|
|
||||||
cpuid = powernv_boot_pir;
|
|
||||||
|
|
||||||
cpuref->cr_cpuid = cpuid;
|
|
||||||
|
|
||||||
if (powernv_smp_first_cpu(plat, &i) != 0)
|
|
||||||
return (ENOENT);
|
|
||||||
cpuref->cr_hwref = i.cr_hwref;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (i.cr_cpuid == cpuid) {
|
|
||||||
cpuref->cr_hwref = i.cr_hwref;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (powernv_smp_next_cpu(plat, &i) == 0);
|
|
||||||
|
|
||||||
|
cpuref->cr_cpuid = platform_cpuref[0].cr_cpuid;
|
||||||
|
cpuref->cr_hwref = platform_cpuref[0].cr_hwref;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,10 +376,10 @@ powernv_smp_start_cpu(platform_t plat, struct pcpu *pc)
|
||||||
ap_pcpu = pc;
|
ap_pcpu = pc;
|
||||||
powerpc_sync();
|
powerpc_sync();
|
||||||
|
|
||||||
result = opal_call(OPAL_START_CPU, pc->pc_cpuid, EXC_RST);
|
result = opal_call(OPAL_START_CPU, pc->pc_hwref, EXC_RST);
|
||||||
if (result != OPAL_SUCCESS) {
|
if (result != OPAL_SUCCESS) {
|
||||||
printf("OPAL error (%d): unable to start AP %d\n",
|
printf("OPAL error (%d): unable to start AP %d\n",
|
||||||
result, pc->pc_cpuid);
|
result, (int)pc->pc_hwref);
|
||||||
return (ENXIO);
|
return (ENXIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,37 +389,49 @@ powernv_smp_start_cpu(platform_t plat, struct pcpu *pc)
|
||||||
static struct cpu_group *
|
static struct cpu_group *
|
||||||
powernv_smp_topo(platform_t plat)
|
powernv_smp_topo(platform_t plat)
|
||||||
{
|
{
|
||||||
struct pcpu *pc, *last_pc;
|
char buf[8];
|
||||||
int i, ncores, ncpus;
|
phandle_t cpu, dev, root;
|
||||||
|
int res, nthreads;
|
||||||
|
|
||||||
ncores = ncpus = 0;
|
root = OF_peer(0);
|
||||||
last_pc = NULL;
|
|
||||||
CPU_FOREACH(i) {
|
dev = OF_child(root);
|
||||||
pc = pcpu_find(i);
|
while (dev != 0) {
|
||||||
if (pc == NULL)
|
res = OF_getprop(dev, "name", buf, sizeof(buf));
|
||||||
continue;
|
if (res > 0 && strcmp(buf, "cpus") == 0)
|
||||||
if (last_pc == NULL || pc->pc_hwref != last_pc->pc_hwref)
|
break;
|
||||||
ncores++;
|
dev = OF_peer(dev);
|
||||||
last_pc = pc;
|
|
||||||
ncpus++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ncpus % ncores != 0) {
|
nthreads = 1;
|
||||||
|
for (cpu = OF_child(dev); cpu != 0; cpu = OF_peer(cpu)) {
|
||||||
|
res = OF_getprop(cpu, "device_type", buf, sizeof(buf));
|
||||||
|
if (res <= 0 || strcmp(buf, "cpu") != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
res = OF_getproplen(cpu, "ibm,ppc-interrupt-server#s");
|
||||||
|
|
||||||
|
if (res >= 0)
|
||||||
|
nthreads = res / sizeof(cell_t);
|
||||||
|
else
|
||||||
|
nthreads = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mp_ncpus % nthreads != 0) {
|
||||||
printf("WARNING: Irregular SMP topology. Performance may be "
|
printf("WARNING: Irregular SMP topology. Performance may be "
|
||||||
"suboptimal (%d CPUS, %d cores)\n", ncpus, ncores);
|
"suboptimal (%d threads, %d on first core)\n",
|
||||||
|
mp_ncpus, nthreads);
|
||||||
return (smp_topo_none());
|
return (smp_topo_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Don't do anything fancier for non-threaded SMP */
|
/* Don't do anything fancier for non-threaded SMP */
|
||||||
if (ncpus == ncores)
|
if (nthreads == 1)
|
||||||
return (smp_topo_none());
|
return (smp_topo_none());
|
||||||
|
|
||||||
#ifdef NOTYET /* smp_topo_1level() fails with non-consecutive CPU IDs */
|
return (smp_topo_1level(CG_SHARE_L1, nthreads, CG_FLAG_SMT));
|
||||||
return (smp_topo_1level(CG_SHARE_L1, ncpus / ncores, CG_FLAG_SMT));
|
|
||||||
#else
|
|
||||||
return (smp_topo_none());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -75,6 +75,7 @@ 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_next_cpu(platform_t, struct cpuref *cpuref);
|
||||||
static int chrp_smp_get_bsp(platform_t, struct cpuref *cpuref);
|
static int chrp_smp_get_bsp(platform_t, struct cpuref *cpuref);
|
||||||
static void chrp_smp_ap_init(platform_t);
|
static void chrp_smp_ap_init(platform_t);
|
||||||
|
static int chrp_cpuref_init(void);
|
||||||
#ifdef SMP
|
#ifdef SMP
|
||||||
static int chrp_smp_start_cpu(platform_t, struct pcpu *cpu);
|
static int chrp_smp_start_cpu(platform_t, struct pcpu *cpu);
|
||||||
static struct cpu_group *chrp_smp_topo(platform_t plat);
|
static struct cpu_group *chrp_smp_topo(platform_t plat);
|
||||||
|
@ -85,6 +86,10 @@ static void chrp_reset(platform_t);
|
||||||
static void phyp_cpu_idle(sbintime_t sbt);
|
static void phyp_cpu_idle(sbintime_t sbt);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static struct cpuref platform_cpuref[MAXCPU];
|
||||||
|
static int platform_cpuref_cnt;
|
||||||
|
static int platform_cpuref_valid;
|
||||||
|
|
||||||
static platform_method_t chrp_methods[] = {
|
static platform_method_t chrp_methods[] = {
|
||||||
PLATFORMMETHOD(platform_probe, chrp_probe),
|
PLATFORMMETHOD(platform_probe, chrp_probe),
|
||||||
PLATFORMMETHOD(platform_attach, chrp_attach),
|
PLATFORMMETHOD(platform_attach, chrp_attach),
|
||||||
|
@ -159,6 +164,7 @@ chrp_attach(platform_t plat)
|
||||||
chrp_smp_ap_init(plat);
|
chrp_smp_ap_init(plat);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
chrp_cpuref_init();
|
||||||
|
|
||||||
/* Some systems (e.g. QEMU) need Open Firmware to stand down */
|
/* Some systems (e.g. QEMU) need Open Firmware to stand down */
|
||||||
ofw_quiesce();
|
ofw_quiesce();
|
||||||
|
@ -295,48 +301,12 @@ chrp_timebase_freq(platform_t plat, struct cpuref *cpuref)
|
||||||
static int
|
static int
|
||||||
chrp_smp_first_cpu(platform_t plat, struct cpuref *cpuref)
|
chrp_smp_first_cpu(platform_t plat, struct cpuref *cpuref)
|
||||||
{
|
{
|
||||||
char buf[8];
|
|
||||||
phandle_t cpu, dev, root;
|
|
||||||
int res, cpuid;
|
|
||||||
|
|
||||||
root = OF_peer(0);
|
if (platform_cpuref_valid == 0)
|
||||||
|
return (EINVAL);
|
||||||
|
|
||||||
dev = OF_child(root);
|
cpuref->cr_cpuid = 0;
|
||||||
while (dev != 0) {
|
cpuref->cr_hwref = platform_cpuref[0].cr_hwref;
|
||||||
res = OF_getprop(dev, "name", buf, sizeof(buf));
|
|
||||||
if (res > 0 && strcmp(buf, "cpus") == 0)
|
|
||||||
break;
|
|
||||||
dev = OF_peer(dev);
|
|
||||||
}
|
|
||||||
if (dev == 0) {
|
|
||||||
/*
|
|
||||||
* psim doesn't have a name property on the /cpus node,
|
|
||||||
* but it can be found directly
|
|
||||||
*/
|
|
||||||
dev = OF_finddevice("/cpus");
|
|
||||||
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);
|
|
||||||
|
|
||||||
cpuref->cr_hwref = cpu;
|
|
||||||
res = OF_getencprop(cpu, "ibm,ppc-interrupt-server#s", &cpuid,
|
|
||||||
sizeof(cpuid));
|
|
||||||
if (res <= 0)
|
|
||||||
res = OF_getencprop(cpu, "reg", &cpuid, sizeof(cpuid));
|
|
||||||
if (res <= 0)
|
|
||||||
cpuid = 0;
|
|
||||||
cpuref->cr_cpuid = cpuid;
|
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -344,43 +314,17 @@ chrp_smp_first_cpu(platform_t plat, struct cpuref *cpuref)
|
||||||
static int
|
static int
|
||||||
chrp_smp_next_cpu(platform_t plat, struct cpuref *cpuref)
|
chrp_smp_next_cpu(platform_t plat, struct cpuref *cpuref)
|
||||||
{
|
{
|
||||||
char buf[8];
|
int id;
|
||||||
phandle_t cpu;
|
|
||||||
int i, res, cpuid;
|
|
||||||
|
|
||||||
/* Check for whether it should be the next thread */
|
if (platform_cpuref_valid == 0)
|
||||||
res = OF_getproplen(cpuref->cr_hwref, "ibm,ppc-interrupt-server#s");
|
return (EINVAL);
|
||||||
if (res > 0) {
|
|
||||||
cell_t interrupt_servers[res/sizeof(cell_t)];
|
|
||||||
OF_getencprop(cpuref->cr_hwref, "ibm,ppc-interrupt-server#s",
|
|
||||||
interrupt_servers, res);
|
|
||||||
for (i = 0; i < res/sizeof(cell_t) - 1; i++) {
|
|
||||||
if (interrupt_servers[i] == cpuref->cr_cpuid) {
|
|
||||||
cpuref->cr_cpuid = interrupt_servers[i+1];
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Next CPU core/package */
|
id = cpuref->cr_cpuid + 1;
|
||||||
cpu = OF_peer(cpuref->cr_hwref);
|
if (id >= platform_cpuref_cnt)
|
||||||
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 (ENOENT);
|
||||||
|
|
||||||
cpuref->cr_hwref = cpu;
|
cpuref->cr_cpuid = platform_cpuref[id].cr_cpuid;
|
||||||
res = OF_getencprop(cpu, "ibm,ppc-interrupt-server#s", &cpuid,
|
cpuref->cr_hwref = platform_cpuref[id].cr_hwref;
|
||||||
sizeof(cpuid));
|
|
||||||
if (res <= 0)
|
|
||||||
res = OF_getencprop(cpu, "reg", &cpuid, sizeof(cpuid));
|
|
||||||
if (res <= 0)
|
|
||||||
cpuid = 0;
|
|
||||||
cpuref->cr_cpuid = cpuid;
|
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -388,33 +332,60 @@ chrp_smp_next_cpu(platform_t plat, struct cpuref *cpuref)
|
||||||
static int
|
static int
|
||||||
chrp_smp_get_bsp(platform_t plat, struct cpuref *cpuref)
|
chrp_smp_get_bsp(platform_t plat, struct cpuref *cpuref)
|
||||||
{
|
{
|
||||||
ihandle_t inst;
|
|
||||||
phandle_t bsp, chosen;
|
|
||||||
int res, cpuid;
|
|
||||||
|
|
||||||
chosen = OF_finddevice("/chosen");
|
cpuref->cr_cpuid = platform_cpuref[0].cr_cpuid;
|
||||||
if (chosen == 0)
|
cpuref->cr_hwref = platform_cpuref[0].cr_hwref;
|
||||||
return (ENXIO);
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
res = OF_getencprop(chosen, "cpu", &inst, sizeof(inst));
|
static int
|
||||||
if (res < 0)
|
chrp_cpuref_init(void)
|
||||||
return (ENXIO);
|
{
|
||||||
|
phandle_t cpu, dev;
|
||||||
|
char buf[32];
|
||||||
|
int a, res;
|
||||||
|
cell_t interrupt_servers[32];
|
||||||
|
uint64_t bsp;
|
||||||
|
|
||||||
bsp = OF_instance_to_package(inst);
|
if (platform_cpuref_valid)
|
||||||
|
return (0);
|
||||||
|
|
||||||
/* Pick the primary thread. Can it be any other? */
|
dev = OF_peer(0);
|
||||||
cpuref->cr_hwref = bsp;
|
dev = OF_child(dev);
|
||||||
res = OF_getencprop(bsp, "ibm,ppc-interrupt-server#s", &cpuid,
|
while (dev != 0) {
|
||||||
sizeof(cpuid));
|
res = OF_getprop(dev, "name", buf, sizeof(buf));
|
||||||
if (res <= 0)
|
if (res > 0 && strcmp(buf, "cpus") == 0)
|
||||||
res = OF_getencprop(bsp, "reg", &cpuid, sizeof(cpuid));
|
break;
|
||||||
if (res <= 0)
|
dev = OF_peer(dev);
|
||||||
cpuid = 0;
|
}
|
||||||
cpuref->cr_cpuid = cpuid;
|
|
||||||
|
bsp = 0;
|
||||||
|
for (cpu = OF_child(dev); cpu != 0; cpu = OF_peer(cpu)) {
|
||||||
|
res = OF_getprop(cpu, "device_type", buf, sizeof(buf));
|
||||||
|
if (res > 0 && strcmp(buf, "cpu") == 0) {
|
||||||
|
res = OF_getproplen(cpu, "ibm,ppc-interrupt-server#s");
|
||||||
|
if (res > 0) {
|
||||||
|
|
||||||
|
|
||||||
|
OF_getencprop(cpu, "ibm,ppc-interrupt-server#s",
|
||||||
|
interrupt_servers, res);
|
||||||
|
|
||||||
|
for (a = 0; a < res/sizeof(cell_t); a++) {
|
||||||
|
platform_cpuref[platform_cpuref_cnt].cr_hwref = interrupt_servers[a];
|
||||||
|
platform_cpuref[platform_cpuref_cnt].cr_cpuid = platform_cpuref_cnt;
|
||||||
|
|
||||||
|
platform_cpuref_cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
platform_cpuref_valid = 1;
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef SMP
|
#ifdef SMP
|
||||||
static int
|
static int
|
||||||
chrp_smp_start_cpu(platform_t plat, struct pcpu *pc)
|
chrp_smp_start_cpu(platform_t plat, struct pcpu *pc)
|
||||||
|
@ -438,7 +409,7 @@ chrp_smp_start_cpu(platform_t plat, struct pcpu *pc)
|
||||||
ap_pcpu = pc;
|
ap_pcpu = pc;
|
||||||
powerpc_sync();
|
powerpc_sync();
|
||||||
|
|
||||||
result = rtas_call_method(start_cpu, 3, 1, pc->pc_cpuid, EXC_RST, pc,
|
result = rtas_call_method(start_cpu, 3, 1, pc->pc_hwref, EXC_RST, pc,
|
||||||
&err);
|
&err);
|
||||||
if (result < 0 || err != 0) {
|
if (result < 0 || err != 0) {
|
||||||
printf("RTAS error (%d/%d): unable to start AP %d\n",
|
printf("RTAS error (%d/%d): unable to start AP %d\n",
|
||||||
|
@ -514,8 +485,8 @@ chrp_smp_ap_init(platform_t platform)
|
||||||
{
|
{
|
||||||
if (!(mfmsr() & PSL_HV)) {
|
if (!(mfmsr() & PSL_HV)) {
|
||||||
/* Register VPA */
|
/* Register VPA */
|
||||||
phyp_hcall(H_REGISTER_VPA, 1UL, PCPU_GET(cpuid),
|
phyp_hcall(H_REGISTER_VPA, 1UL, PCPU_GET(hwref),
|
||||||
splpar_vpa[PCPU_GET(cpuid)]);
|
splpar_vpa[PCPU_GET(hwref)]);
|
||||||
|
|
||||||
/* Set interrupt priority */
|
/* Set interrupt priority */
|
||||||
phyp_hcall(H_CPPR, 0xff);
|
phyp_hcall(H_CPPR, 0xff);
|
||||||
|
|
|
@ -263,6 +263,10 @@ xicp_bind(device_t dev, u_int irq, cpuset_t cpumask)
|
||||||
cell_t status, cpu;
|
cell_t status, cpu;
|
||||||
int ncpus, i, error;
|
int ncpus, i, error;
|
||||||
|
|
||||||
|
/* Ignore IPIs */
|
||||||
|
if (irq == MAX_XICP_IRQS)
|
||||||
|
return;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This doesn't appear to actually support affinity groups, so pick a
|
* This doesn't appear to actually support affinity groups, so pick a
|
||||||
* random CPU.
|
* random CPU.
|
||||||
|
@ -281,6 +285,8 @@ xicp_bind(device_t dev, u_int irq, cpuset_t cpumask)
|
||||||
ncpus++;
|
ncpus++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cpu = pcpu_find(cpu)->pc_hwref;
|
||||||
|
|
||||||
/* XXX: super inefficient */
|
/* XXX: super inefficient */
|
||||||
for (i = 0; i < sc->nintvecs; i++) {
|
for (i = 0; i < sc->nintvecs; i++) {
|
||||||
if (sc->intvecs[i].irq == irq) {
|
if (sc->intvecs[i].irq == irq) {
|
||||||
|
@ -312,9 +318,9 @@ xicp_dispatch(device_t dev, struct trapframe *tf)
|
||||||
|
|
||||||
#ifdef POWERNV
|
#ifdef POWERNV
|
||||||
if (mfmsr() & PSL_HV) {
|
if (mfmsr() & PSL_HV) {
|
||||||
regs = xicp_mem_for_cpu(PCPU_GET(cpuid));
|
regs = xicp_mem_for_cpu(PCPU_GET(hwref));
|
||||||
KASSERT(regs != NULL,
|
KASSERT(regs != NULL,
|
||||||
("Can't find regs for CPU %d", PCPU_GET(cpuid)));
|
("Can't find regs for CPU %ld", (uintptr_t)PCPU_GET(hwref)));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -343,7 +349,7 @@ xicp_dispatch(device_t dev, struct trapframe *tf)
|
||||||
if (regs)
|
if (regs)
|
||||||
bus_write_1(regs, 12, 0xff);
|
bus_write_1(regs, 12, 0xff);
|
||||||
else
|
else
|
||||||
phyp_hcall(H_IPI, (uint64_t)(PCPU_GET(cpuid)),
|
phyp_hcall(H_IPI, (uint64_t)(PCPU_GET(hwref)),
|
||||||
0xff);
|
0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,7 +376,7 @@ xicp_enable(device_t dev, u_int irq, u_int vector)
|
||||||
("Too many XICP interrupts"));
|
("Too many XICP interrupts"));
|
||||||
|
|
||||||
/* Bind to this CPU to start: distrib. ID is last entry in gserver# */
|
/* Bind to this CPU to start: distrib. ID is last entry in gserver# */
|
||||||
cpu = PCPU_GET(cpuid);
|
cpu = PCPU_GET(hwref);
|
||||||
|
|
||||||
mtx_lock(&sc->sc_mtx);
|
mtx_lock(&sc->sc_mtx);
|
||||||
sc->intvecs[sc->nintvecs].irq = irq;
|
sc->intvecs[sc->nintvecs].irq = irq;
|
||||||
|
@ -411,7 +417,7 @@ xicp_eoi(device_t dev, u_int irq)
|
||||||
|
|
||||||
#ifdef POWERNV
|
#ifdef POWERNV
|
||||||
if (mfmsr() & PSL_HV)
|
if (mfmsr() & PSL_HV)
|
||||||
bus_write_4(xicp_mem_for_cpu(PCPU_GET(cpuid)), 4, xirr);
|
bus_write_4(xicp_mem_for_cpu(PCPU_GET(hwref)), 4, xirr);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
phyp_hcall(H_EOI, xirr);
|
phyp_hcall(H_EOI, xirr);
|
||||||
|
@ -422,6 +428,8 @@ xicp_ipi(device_t dev, u_int cpu)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef POWERNV
|
#ifdef POWERNV
|
||||||
|
cpu = pcpu_find(cpu)->pc_hwref;
|
||||||
|
|
||||||
if (mfmsr() & PSL_HV)
|
if (mfmsr() & PSL_HV)
|
||||||
bus_write_1(xicp_mem_for_cpu(cpu), 12, XICP_PRIORITY);
|
bus_write_1(xicp_mem_for_cpu(cpu), 12, XICP_PRIORITY);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue