2016-10-22 11:46:39 +02:00
|
|
|
/*
|
|
|
|
* QEMU PowerPC PowerNV CPU Core model
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016, IBM Corporation.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "sysemu/sysemu.h"
|
|
|
|
#include "qapi/error.h"
|
2016-10-22 11:46:41 +02:00
|
|
|
#include "qemu/log.h"
|
2016-10-11 08:56:52 +02:00
|
|
|
#include "target/ppc/cpu.h"
|
2016-10-22 11:46:39 +02:00
|
|
|
#include "hw/ppc/ppc.h"
|
|
|
|
#include "hw/ppc/pnv.h"
|
|
|
|
#include "hw/ppc/pnv_core.h"
|
2016-11-07 19:03:02 +01:00
|
|
|
#include "hw/ppc/pnv_xscom.h"
|
2017-04-03 09:46:03 +02:00
|
|
|
#include "hw/ppc/xics.h"
|
2016-10-22 11:46:39 +02:00
|
|
|
|
2017-10-09 21:51:08 +02:00
|
|
|
static const char *pnv_core_cpu_typename(PnvCore *pc)
|
|
|
|
{
|
|
|
|
const char *core_type = object_class_get_name(object_get_class(OBJECT(pc)));
|
|
|
|
int len = strlen(core_type) - strlen(PNV_CORE_TYPE_SUFFIX);
|
|
|
|
char *s = g_strdup_printf(POWERPC_CPU_TYPE_NAME("%.*s"), len, core_type);
|
|
|
|
const char *cpu_type = object_class_get_name(object_class_by_name(s));
|
|
|
|
g_free(s);
|
|
|
|
return cpu_type;
|
|
|
|
}
|
|
|
|
|
2017-12-15 14:56:01 +01:00
|
|
|
static void pnv_cpu_reset(void *opaque)
|
2016-10-22 11:46:39 +02:00
|
|
|
{
|
|
|
|
PowerPCCPU *cpu = opaque;
|
|
|
|
CPUState *cs = CPU(cpu);
|
|
|
|
CPUPPCState *env = &cpu->env;
|
|
|
|
|
|
|
|
cpu_reset(cs);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the skiboot firmware elects a primary thread to initialize the
|
|
|
|
* system and it can be any.
|
|
|
|
*/
|
|
|
|
env->gpr[3] = PNV_FDT_ADDR;
|
|
|
|
env->nip = 0x10;
|
|
|
|
env->msr |= MSR_HVB; /* Hypervisor mode */
|
|
|
|
}
|
|
|
|
|
2016-10-22 11:46:41 +02:00
|
|
|
/*
|
|
|
|
* These values are read by the PowerNV HW monitors under Linux
|
|
|
|
*/
|
|
|
|
#define PNV_XSCOM_EX_DTS_RESULT0 0x50000
|
|
|
|
#define PNV_XSCOM_EX_DTS_RESULT1 0x50001
|
|
|
|
|
|
|
|
static uint64_t pnv_core_xscom_read(void *opaque, hwaddr addr,
|
|
|
|
unsigned int width)
|
|
|
|
{
|
|
|
|
uint32_t offset = addr >> 3;
|
|
|
|
uint64_t val = 0;
|
|
|
|
|
|
|
|
/* The result should be 38 C */
|
|
|
|
switch (offset) {
|
|
|
|
case PNV_XSCOM_EX_DTS_RESULT0:
|
|
|
|
val = 0x26f024f023f0000ull;
|
|
|
|
break;
|
|
|
|
case PNV_XSCOM_EX_DTS_RESULT1:
|
|
|
|
val = 0x24f000000000000ull;
|
|
|
|
break;
|
|
|
|
default:
|
2018-06-08 14:15:33 +02:00
|
|
|
qemu_log_mask(LOG_UNIMP, "Warning: reading reg=0x%" HWADDR_PRIx "\n",
|
2016-10-22 11:46:41 +02:00
|
|
|
addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pnv_core_xscom_write(void *opaque, hwaddr addr, uint64_t val,
|
|
|
|
unsigned int width)
|
|
|
|
{
|
2018-06-08 14:15:33 +02:00
|
|
|
qemu_log_mask(LOG_UNIMP, "Warning: writing to reg=0x%" HWADDR_PRIx "\n",
|
2016-10-22 11:46:41 +02:00
|
|
|
addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps pnv_core_xscom_ops = {
|
|
|
|
.read = pnv_core_xscom_read,
|
|
|
|
.write = pnv_core_xscom_write,
|
|
|
|
.valid.min_access_size = 8,
|
|
|
|
.valid.max_access_size = 8,
|
|
|
|
.impl.min_access_size = 8,
|
|
|
|
.impl.max_access_size = 8,
|
|
|
|
.endianness = DEVICE_BIG_ENDIAN,
|
|
|
|
};
|
|
|
|
|
2018-06-15 17:25:33 +02:00
|
|
|
static void pnv_realize_vcpu(PowerPCCPU *cpu, PnvChip *chip, Error **errp)
|
2016-10-22 11:46:39 +02:00
|
|
|
{
|
2018-06-13 05:34:36 +02:00
|
|
|
CPUPPCState *env = &cpu->env;
|
|
|
|
int core_pir;
|
|
|
|
int thread_index = 0; /* TODO: TCG supports only one thread */
|
|
|
|
ppc_spr_t *pir = &env->spr_cb[SPR_PIR];
|
2016-10-22 11:46:39 +02:00
|
|
|
Error *local_err = NULL;
|
2018-06-15 17:25:33 +02:00
|
|
|
PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip);
|
2017-04-03 09:46:03 +02:00
|
|
|
|
2018-06-13 05:34:36 +02:00
|
|
|
object_property_set_bool(OBJECT(cpu), true, "realized", &local_err);
|
2017-04-03 09:46:03 +02:00
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
2016-10-22 11:46:39 +02:00
|
|
|
|
2018-06-15 17:25:33 +02:00
|
|
|
cpu->intc = pcc->intc_create(chip, OBJECT(cpu), &local_err);
|
2016-10-22 11:46:39 +02:00
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-13 05:34:36 +02:00
|
|
|
core_pir = object_property_get_uint(OBJECT(cpu), "core-pir", &error_abort);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The PIR of a thread is the core PIR + the thread index. We will
|
|
|
|
* need to find a way to get the thread index when TCG supports
|
|
|
|
* more than 1. We could use the object name ?
|
|
|
|
*/
|
|
|
|
pir->default_value = core_pir + thread_index;
|
|
|
|
|
|
|
|
/* Set time-base frequency to 512 MHz */
|
|
|
|
cpu_ppc_tb_init(env, PNV_TIMEBASE_FREQ);
|
|
|
|
|
|
|
|
qemu_register_reset(pnv_cpu_reset, cpu);
|
2016-10-22 11:46:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pnv_core_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
PnvCore *pc = PNV_CORE(OBJECT(dev));
|
|
|
|
CPUCore *cc = CPU_CORE(OBJECT(dev));
|
2017-10-09 21:51:08 +02:00
|
|
|
const char *typename = pnv_core_cpu_typename(pc);
|
2016-10-22 11:46:39 +02:00
|
|
|
Error *local_err = NULL;
|
|
|
|
void *obj;
|
|
|
|
int i, j;
|
|
|
|
char name[32];
|
2018-06-15 17:25:33 +02:00
|
|
|
Object *chip;
|
2017-04-03 09:46:03 +02:00
|
|
|
|
2018-06-15 17:25:33 +02:00
|
|
|
chip = object_property_get_link(OBJECT(dev), "chip", &local_err);
|
|
|
|
if (!chip) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
error_prepend(errp, "required link 'chip' not found: ");
|
2018-06-26 16:22:14 +02:00
|
|
|
return;
|
2017-04-03 09:46:03 +02:00
|
|
|
}
|
2016-10-22 11:46:39 +02:00
|
|
|
|
2018-06-13 03:57:37 +02:00
|
|
|
pc->threads = g_new(PowerPCCPU *, cc->nr_threads);
|
2016-10-22 11:46:39 +02:00
|
|
|
for (i = 0; i < cc->nr_threads; i++) {
|
2018-06-13 03:57:37 +02:00
|
|
|
obj = object_new(typename);
|
2016-10-22 11:46:39 +02:00
|
|
|
|
2018-06-13 03:57:37 +02:00
|
|
|
pc->threads[i] = POWERPC_CPU(obj);
|
2016-10-22 11:46:39 +02:00
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "thread[%d]", i);
|
2018-06-13 03:55:31 +02:00
|
|
|
object_property_add_child(OBJECT(pc), name, obj, &error_abort);
|
2016-10-22 11:46:39 +02:00
|
|
|
object_property_add_alias(obj, "core-pir", OBJECT(pc),
|
2018-06-13 03:55:31 +02:00
|
|
|
"pir", &error_abort);
|
2016-10-22 11:46:39 +02:00
|
|
|
object_unref(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < cc->nr_threads; j++) {
|
2018-06-15 17:25:33 +02:00
|
|
|
pnv_realize_vcpu(pc->threads[j], PNV_CHIP(chip), &local_err);
|
2016-10-22 11:46:39 +02:00
|
|
|
if (local_err) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
2016-10-22 11:46:41 +02:00
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "xscom-core.%d", cc->core_id);
|
|
|
|
pnv_xscom_region_init(&pc->xscom_regs, OBJECT(dev), &pnv_core_xscom_ops,
|
2018-01-15 19:04:04 +01:00
|
|
|
pc, name, PNV_XSCOM_EX_SIZE);
|
2016-10-22 11:46:39 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
while (--i >= 0) {
|
2018-06-13 03:57:37 +02:00
|
|
|
obj = OBJECT(pc->threads[i]);
|
2016-10-22 11:46:39 +02:00
|
|
|
object_unparent(obj);
|
|
|
|
}
|
|
|
|
g_free(pc->threads);
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
}
|
|
|
|
|
2018-06-13 04:08:42 +02:00
|
|
|
static void pnv_unrealize_vcpu(PowerPCCPU *cpu)
|
|
|
|
{
|
|
|
|
qemu_unregister_reset(pnv_cpu_reset, cpu);
|
|
|
|
object_unparent(cpu->intc);
|
|
|
|
cpu_remove_sync(CPU(cpu));
|
|
|
|
object_unparent(OBJECT(cpu));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pnv_core_unrealize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
PnvCore *pc = PNV_CORE(dev);
|
|
|
|
CPUCore *cc = CPU_CORE(dev);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < cc->nr_threads; i++) {
|
|
|
|
pnv_unrealize_vcpu(pc->threads[i]);
|
|
|
|
}
|
|
|
|
g_free(pc->threads);
|
|
|
|
}
|
|
|
|
|
2016-10-22 11:46:39 +02:00
|
|
|
static Property pnv_core_properties[] = {
|
|
|
|
DEFINE_PROP_UINT32("pir", PnvCore, pir, 0),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void pnv_core_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
|
|
|
|
dc->realize = pnv_core_realize;
|
2018-06-13 04:08:42 +02:00
|
|
|
dc->unrealize = pnv_core_unrealize;
|
2016-10-22 11:46:39 +02:00
|
|
|
dc->props = pnv_core_properties;
|
|
|
|
}
|
|
|
|
|
2017-10-09 21:51:09 +02:00
|
|
|
#define DEFINE_PNV_CORE_TYPE(cpu_model) \
|
|
|
|
{ \
|
|
|
|
.parent = TYPE_PNV_CORE, \
|
|
|
|
.name = PNV_CORE_TYPE_NAME(cpu_model), \
|
2016-10-22 11:46:39 +02:00
|
|
|
}
|
|
|
|
|
2017-10-09 21:51:09 +02:00
|
|
|
static const TypeInfo pnv_core_infos[] = {
|
|
|
|
{
|
|
|
|
.name = TYPE_PNV_CORE,
|
|
|
|
.parent = TYPE_CPU_CORE,
|
|
|
|
.instance_size = sizeof(PnvCore),
|
|
|
|
.class_size = sizeof(PnvCoreClass),
|
|
|
|
.class_init = pnv_core_class_init,
|
|
|
|
.abstract = true,
|
|
|
|
},
|
|
|
|
DEFINE_PNV_CORE_TYPE("power8e_v2.1"),
|
|
|
|
DEFINE_PNV_CORE_TYPE("power8_v2.0"),
|
|
|
|
DEFINE_PNV_CORE_TYPE("power8nvl_v1.0"),
|
|
|
|
DEFINE_PNV_CORE_TYPE("power9_v2.0"),
|
|
|
|
};
|
2016-10-22 11:46:39 +02:00
|
|
|
|
2017-10-09 21:51:09 +02:00
|
|
|
DEFINE_TYPES(pnv_core_infos)
|