2011-07-22 13:32:29 +02:00
|
|
|
/*
|
|
|
|
* QEMU PowerPC e500v2 ePAPR spinning code
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Freescale Semiconductor, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Author: Alexander Graf, <agraf@suse.de>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* This code is not really a device, but models an interface that usually
|
|
|
|
* firmware takes care of. It's used when QEMU plays the role of firmware.
|
|
|
|
*
|
|
|
|
* Specification:
|
|
|
|
*
|
|
|
|
* https://www.power.org/resources/downloads/Power_ePAPR_APPROVED_v1.1.pdf
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-01-26 19:16:58 +01:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/hw.h"
|
|
|
|
#include "hw/sysbus.h"
|
2017-01-10 11:59:55 +01:00
|
|
|
#include "sysemu/hw_accel.h"
|
|
|
|
#include "sysemu/sysemu.h"
|
2016-06-28 15:50:05 +02:00
|
|
|
#include "e500.h"
|
2011-07-22 13:32:29 +02:00
|
|
|
|
|
|
|
#define MAX_CPUS 32
|
|
|
|
|
|
|
|
typedef struct spin_info {
|
|
|
|
uint64_t addr;
|
|
|
|
uint64_t r3;
|
|
|
|
uint32_t resv;
|
|
|
|
uint32_t pir;
|
|
|
|
uint64_t reserved;
|
2012-07-18 18:12:37 +02:00
|
|
|
} QEMU_PACKED SpinInfo;
|
2011-07-22 13:32:29 +02:00
|
|
|
|
2013-07-27 13:03:07 +02:00
|
|
|
#define TYPE_E500_SPIN "e500-spin"
|
|
|
|
#define E500_SPIN(obj) OBJECT_CHECK(SpinState, (obj), TYPE_E500_SPIN)
|
|
|
|
|
|
|
|
typedef struct SpinState {
|
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
2011-07-22 13:32:29 +02:00
|
|
|
MemoryRegion iomem;
|
|
|
|
SpinInfo spin[MAX_CPUS];
|
|
|
|
} SpinState;
|
|
|
|
|
2017-01-06 01:26:27 +01:00
|
|
|
static void spin_reset(DeviceState *dev)
|
2011-07-22 13:32:29 +02:00
|
|
|
{
|
2017-01-06 01:26:27 +01:00
|
|
|
SpinState *s = E500_SPIN(dev);
|
2011-07-22 13:32:29 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_CPUS; i++) {
|
|
|
|
SpinInfo *info = &s->spin[i];
|
|
|
|
|
2014-04-07 16:48:42 +02:00
|
|
|
stl_p(&info->pir, i);
|
|
|
|
stq_p(&info->r3, i);
|
|
|
|
stq_p(&info->addr, 1);
|
2011-07-22 13:32:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-14 01:38:23 +01:00
|
|
|
static void mmubooke_create_initial_mapping(CPUPPCState *env,
|
2011-07-22 13:32:29 +02:00
|
|
|
target_ulong va,
|
2012-10-23 12:30:10 +02:00
|
|
|
hwaddr pa,
|
|
|
|
hwaddr len)
|
2011-07-22 13:32:29 +02:00
|
|
|
{
|
|
|
|
ppcmas_tlb_t *tlb = booke206_get_tlbm(env, 1, 0, 1);
|
2012-10-23 12:30:10 +02:00
|
|
|
hwaddr size;
|
2011-07-22 13:32:29 +02:00
|
|
|
|
|
|
|
size = (booke206_page_size_to_tlb(len) << MAS1_TSIZE_SHIFT);
|
|
|
|
tlb->mas1 = MAS1_VALID | size;
|
|
|
|
tlb->mas2 = (va & TARGET_PAGE_MASK) | MAS2_M;
|
|
|
|
tlb->mas7_3 = pa & TARGET_PAGE_MASK;
|
|
|
|
tlb->mas7_3 |= MAS3_UR | MAS3_UW | MAS3_UX | MAS3_SR | MAS3_SW | MAS3_SX;
|
2012-03-26 19:56:46 +02:00
|
|
|
env->tlb_dirty = true;
|
2011-07-22 13:32:29 +02:00
|
|
|
}
|
|
|
|
|
2016-10-31 10:36:08 +01:00
|
|
|
static void spin_kick(CPUState *cs, run_on_cpu_data data)
|
2011-07-22 13:32:29 +02:00
|
|
|
{
|
2016-08-02 19:27:33 +02:00
|
|
|
PowerPCCPU *cpu = POWERPC_CPU(cs);
|
|
|
|
CPUPPCState *env = &cpu->env;
|
2016-10-31 10:36:08 +01:00
|
|
|
SpinInfo *curspin = data.host_ptr;
|
2012-10-23 12:30:10 +02:00
|
|
|
hwaddr map_size = 64 * 1024 * 1024;
|
|
|
|
hwaddr map_start;
|
2011-07-22 13:32:29 +02:00
|
|
|
|
2016-08-02 19:27:33 +02:00
|
|
|
cpu_synchronize_state(cs);
|
2016-06-24 00:35:17 +02:00
|
|
|
stl_p(&curspin->pir, env->spr[SPR_BOOKE_PIR]);
|
2011-07-22 13:32:29 +02:00
|
|
|
env->nip = ldq_p(&curspin->addr) & (map_size - 1);
|
|
|
|
env->gpr[3] = ldq_p(&curspin->r3);
|
|
|
|
env->gpr[4] = 0;
|
|
|
|
env->gpr[5] = 0;
|
|
|
|
env->gpr[6] = 0;
|
|
|
|
env->gpr[7] = map_size;
|
|
|
|
env->gpr[8] = 0;
|
|
|
|
env->gpr[9] = 0;
|
|
|
|
|
|
|
|
map_start = ldq_p(&curspin->addr) & ~(map_size - 1);
|
|
|
|
mmubooke_create_initial_mapping(env, 0, map_start, map_size);
|
|
|
|
|
2016-08-02 19:27:33 +02:00
|
|
|
cs->halted = 0;
|
|
|
|
cs->exception_index = -1;
|
|
|
|
cs->stopped = false;
|
|
|
|
qemu_cpu_kick(cs);
|
2011-07-22 13:32:29 +02:00
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void spin_write(void *opaque, hwaddr addr, uint64_t value,
|
2011-07-22 13:32:29 +02:00
|
|
|
unsigned len)
|
|
|
|
{
|
|
|
|
SpinState *s = opaque;
|
|
|
|
int env_idx = addr / sizeof(SpinInfo);
|
2013-02-15 15:56:27 +01:00
|
|
|
CPUState *cpu;
|
2011-07-22 13:32:29 +02:00
|
|
|
SpinInfo *curspin = &s->spin[env_idx];
|
|
|
|
uint8_t *curspin_p = (uint8_t*)curspin;
|
|
|
|
|
2013-02-15 15:56:27 +01:00
|
|
|
cpu = qemu_get_cpu(env_idx);
|
2012-12-17 06:18:02 +01:00
|
|
|
if (cpu == NULL) {
|
2011-07-22 13:32:29 +02:00
|
|
|
/* Unknown CPU */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-17 06:18:02 +01:00
|
|
|
if (cpu->cpu_index == 0) {
|
2011-07-22 13:32:29 +02:00
|
|
|
/* primary CPU doesn't spin */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
curspin_p = &curspin_p[addr % sizeof(SpinInfo)];
|
|
|
|
switch (len) {
|
|
|
|
case 1:
|
|
|
|
stb_p(curspin_p, value);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
stw_p(curspin_p, value);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
stl_p(curspin_p, value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(ldq_p(&curspin->addr) & 1)) {
|
|
|
|
/* run CPU */
|
2016-10-31 10:36:08 +01:00
|
|
|
run_on_cpu(cpu, spin_kick, RUN_ON_CPU_HOST_PTR(curspin));
|
2011-07-22 13:32:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t spin_read(void *opaque, hwaddr addr, unsigned len)
|
2011-07-22 13:32:29 +02:00
|
|
|
{
|
|
|
|
SpinState *s = opaque;
|
|
|
|
uint8_t *spin_p = &((uint8_t*)s->spin)[addr];
|
|
|
|
|
|
|
|
switch (len) {
|
|
|
|
case 1:
|
|
|
|
return ldub_p(spin_p);
|
|
|
|
case 2:
|
|
|
|
return lduw_p(spin_p);
|
|
|
|
case 4:
|
|
|
|
return ldl_p(spin_p);
|
|
|
|
default:
|
2012-04-28 17:52:31 +02:00
|
|
|
hw_error("ppce500: unexpected %s with len = %u", __func__, len);
|
2011-07-22 13:32:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-25 03:37:12 +01:00
|
|
|
static const MemoryRegionOps spin_rw_ops = {
|
2011-07-22 13:32:29 +02:00
|
|
|
.read = spin_read,
|
|
|
|
.write = spin_write,
|
|
|
|
.endianness = DEVICE_BIG_ENDIAN,
|
|
|
|
};
|
|
|
|
|
2017-01-06 01:26:27 +01:00
|
|
|
static void ppce500_spin_initfn(Object *obj)
|
2011-07-22 13:32:29 +02:00
|
|
|
{
|
2017-01-06 01:26:27 +01:00
|
|
|
SysBusDevice *dev = SYS_BUS_DEVICE(obj);
|
2013-07-27 13:03:07 +02:00
|
|
|
SpinState *s = E500_SPIN(dev);
|
2011-07-22 13:32:29 +02:00
|
|
|
|
2017-01-06 01:26:27 +01:00
|
|
|
memory_region_init_io(&s->iomem, obj, &spin_rw_ops, s,
|
2013-06-07 03:25:08 +02:00
|
|
|
"e500 spin pv device", sizeof(SpinInfo) * MAX_CPUS);
|
2011-11-27 10:38:10 +01:00
|
|
|
sysbus_init_mmio(dev, &s->iomem);
|
2011-07-22 13:32:29 +02:00
|
|
|
}
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static void ppce500_spin_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2017-01-06 01:26:27 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2017-01-06 01:26:27 +01:00
|
|
|
dc->reset = spin_reset;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo ppce500_spin_info = {
|
2013-07-27 13:03:07 +02:00
|
|
|
.name = TYPE_E500_SPIN,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(SpinState),
|
2017-01-06 01:26:27 +01:00
|
|
|
.instance_init = ppce500_spin_initfn,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = ppce500_spin_class_init,
|
2011-07-22 13:32:29 +02:00
|
|
|
};
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void ppce500_spin_register_types(void)
|
2011-07-22 13:32:29 +02:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&ppce500_spin_info);
|
2011-07-22 13:32:29 +02:00
|
|
|
}
|
2012-02-09 15:20:55 +01:00
|
|
|
|
|
|
|
type_init(ppce500_spin_register_types)
|