2011-04-01 08:15:21 +04:00
|
|
|
/*
|
|
|
|
* QEMU sPAPR VIO code
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 David Gibson, IBM Corporation <dwg@au1.ibm.com>
|
|
|
|
* Based on the s390 virtio bus code:
|
|
|
|
* Copyright (c) 2009 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hw.h"
|
|
|
|
#include "sysemu.h"
|
|
|
|
#include "boards.h"
|
|
|
|
#include "monitor.h"
|
|
|
|
#include "loader.h"
|
|
|
|
#include "elf.h"
|
|
|
|
#include "hw/sysbus.h"
|
|
|
|
#include "kvm.h"
|
|
|
|
#include "device_tree.h"
|
2011-04-01 08:15:30 +04:00
|
|
|
#include "kvm_ppc.h"
|
2011-04-01 08:15:21 +04:00
|
|
|
|
|
|
|
#include "hw/spapr.h"
|
|
|
|
#include "hw/spapr_vio.h"
|
2011-05-26 13:52:44 +04:00
|
|
|
#include "hw/xics.h"
|
2011-04-01 08:15:21 +04:00
|
|
|
|
|
|
|
#ifdef CONFIG_FDT
|
|
|
|
#include <libfdt.h>
|
|
|
|
#endif /* CONFIG_FDT */
|
|
|
|
|
|
|
|
/* #define DEBUG_SPAPR */
|
|
|
|
|
|
|
|
#ifdef DEBUG_SPAPR
|
|
|
|
#define dprintf(fmt, ...) \
|
|
|
|
do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
|
|
|
|
#else
|
|
|
|
#define dprintf(fmt, ...) \
|
|
|
|
do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
2012-03-28 20:01:36 +04:00
|
|
|
static Property spapr_vio_props[] = {
|
|
|
|
DEFINE_PROP_UINT32("irq", VIOsPAPRDevice, vio_irq_num, 0), \
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2012-05-02 11:00:20 +04:00
|
|
|
static const TypeInfo spapr_vio_bus_info = {
|
|
|
|
.name = TYPE_SPAPR_VIO_BUS,
|
|
|
|
.parent = TYPE_BUS,
|
|
|
|
.instance_size = sizeof(VIOsPAPRBus),
|
2011-04-01 08:15:21 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg)
|
|
|
|
{
|
2011-12-24 01:34:39 +04:00
|
|
|
BusChild *kid;
|
2011-04-01 08:15:21 +04:00
|
|
|
VIOsPAPRDevice *dev = NULL;
|
|
|
|
|
2011-12-24 01:34:39 +04:00
|
|
|
QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
|
|
|
|
dev = (VIOsPAPRDevice *)kid->child;
|
2011-04-01 08:15:21 +04:00
|
|
|
if (dev->reg == reg) {
|
2011-11-13 21:18:58 +04:00
|
|
|
return dev;
|
2011-04-01 08:15:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-13 21:18:58 +04:00
|
|
|
return NULL;
|
2011-04-01 08:15:21 +04:00
|
|
|
}
|
|
|
|
|
2011-11-15 22:53:13 +04:00
|
|
|
static char *vio_format_dev_name(VIOsPAPRDevice *dev)
|
|
|
|
{
|
2011-12-16 02:31:06 +04:00
|
|
|
VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
|
2011-11-15 22:53:13 +04:00
|
|
|
char *name;
|
|
|
|
|
|
|
|
/* Device tree style name device@reg */
|
2011-12-16 02:31:06 +04:00
|
|
|
if (asprintf(&name, "%s@%x", pc->dt_name, dev->reg) < 0) {
|
2011-11-15 22:53:13 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2011-04-01 08:15:21 +04:00
|
|
|
#ifdef CONFIG_FDT
|
|
|
|
static int vio_make_devnode(VIOsPAPRDevice *dev,
|
|
|
|
void *fdt)
|
|
|
|
{
|
2011-12-16 02:31:06 +04:00
|
|
|
VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
|
2011-11-15 22:53:13 +04:00
|
|
|
int vdevice_off, node_off, ret;
|
|
|
|
char *dt_name;
|
2011-04-01 08:15:21 +04:00
|
|
|
|
|
|
|
vdevice_off = fdt_path_offset(fdt, "/vdevice");
|
|
|
|
if (vdevice_off < 0) {
|
|
|
|
return vdevice_off;
|
|
|
|
}
|
|
|
|
|
2011-11-15 22:53:13 +04:00
|
|
|
dt_name = vio_format_dev_name(dev);
|
|
|
|
if (!dt_name) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
node_off = fdt_add_subnode(fdt, vdevice_off, dt_name);
|
|
|
|
free(dt_name);
|
2011-04-01 08:15:21 +04:00
|
|
|
if (node_off < 0) {
|
|
|
|
return node_off;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = fdt_setprop_cell(fdt, node_off, "reg", dev->reg);
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-12-16 02:31:06 +04:00
|
|
|
if (pc->dt_type) {
|
2011-04-01 08:15:21 +04:00
|
|
|
ret = fdt_setprop_string(fdt, node_off, "device_type",
|
2011-12-16 02:31:06 +04:00
|
|
|
pc->dt_type);
|
2011-04-01 08:15:21 +04:00
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-16 02:31:06 +04:00
|
|
|
if (pc->dt_compatible) {
|
2011-04-01 08:15:21 +04:00
|
|
|
ret = fdt_setprop_string(fdt, node_off, "compatible",
|
2011-12-16 02:31:06 +04:00
|
|
|
pc->dt_compatible);
|
2011-04-01 08:15:21 +04:00
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-01 08:15:26 +04:00
|
|
|
if (dev->qirq) {
|
|
|
|
uint32_t ints_prop[] = {cpu_to_be32(dev->vio_irq_num), 0};
|
|
|
|
|
|
|
|
ret = fdt_setprop(fdt, node_off, "interrupts", ints_prop,
|
|
|
|
sizeof(ints_prop));
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-27 08:50:44 +04:00
|
|
|
ret = spapr_dma_dt(fdt, node_off, "ibm,my-dma-window", dev->dma);
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
2011-04-01 08:15:28 +04:00
|
|
|
}
|
|
|
|
|
2011-12-16 02:31:06 +04:00
|
|
|
if (pc->devnode) {
|
|
|
|
ret = (pc->devnode)(dev, fdt, node_off);
|
2011-04-01 08:15:21 +04:00
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return node_off;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_FDT */
|
|
|
|
|
2011-04-01 08:15:30 +04:00
|
|
|
/*
|
|
|
|
* CRQ handling
|
|
|
|
*/
|
2012-03-14 04:38:23 +04:00
|
|
|
static target_ulong h_reg_crq(CPUPPCState *env, sPAPREnvironment *spapr,
|
2011-04-01 08:15:30 +04:00
|
|
|
target_ulong opcode, target_ulong *args)
|
|
|
|
{
|
|
|
|
target_ulong reg = args[0];
|
|
|
|
target_ulong queue_addr = args[1];
|
|
|
|
target_ulong queue_len = args[2];
|
|
|
|
VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
|
|
|
|
|
|
|
|
if (!dev) {
|
2012-03-29 01:39:45 +04:00
|
|
|
hcall_dprintf("Unit 0x" TARGET_FMT_lx " does not exist\n", reg);
|
2011-04-01 08:15:30 +04:00
|
|
|
return H_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We can't grok a queue size bigger than 256M for now */
|
|
|
|
if (queue_len < 0x1000 || queue_len > 0x10000000) {
|
2012-03-29 01:39:45 +04:00
|
|
|
hcall_dprintf("Queue size too small or too big (0x" TARGET_FMT_lx
|
|
|
|
")\n", queue_len);
|
2011-04-01 08:15:30 +04:00
|
|
|
return H_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check queue alignment */
|
|
|
|
if (queue_addr & 0xfff) {
|
2012-03-29 01:39:45 +04:00
|
|
|
hcall_dprintf("Queue not aligned (0x" TARGET_FMT_lx ")\n", queue_addr);
|
2011-04-01 08:15:30 +04:00
|
|
|
return H_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if device supports CRQs */
|
|
|
|
if (!dev->crq.SendFunc) {
|
2012-03-29 01:39:46 +04:00
|
|
|
hcall_dprintf("Device does not support CRQ\n");
|
2011-04-01 08:15:30 +04:00
|
|
|
return H_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Already a queue ? */
|
|
|
|
if (dev->crq.qsize) {
|
2012-03-29 01:39:46 +04:00
|
|
|
hcall_dprintf("CRQ already registered\n");
|
2011-04-01 08:15:30 +04:00
|
|
|
return H_RESOURCE;
|
|
|
|
}
|
|
|
|
dev->crq.qladdr = queue_addr;
|
|
|
|
dev->crq.qsize = queue_len;
|
|
|
|
dev->crq.qnext = 0;
|
|
|
|
|
|
|
|
dprintf("CRQ for dev 0x" TARGET_FMT_lx " registered at 0x"
|
|
|
|
TARGET_FMT_lx "/0x" TARGET_FMT_lx "\n",
|
|
|
|
reg, queue_addr, queue_len);
|
|
|
|
return H_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-03-29 01:39:46 +04:00
|
|
|
static target_ulong free_crq(VIOsPAPRDevice *dev)
|
|
|
|
{
|
|
|
|
dev->crq.qladdr = 0;
|
|
|
|
dev->crq.qsize = 0;
|
|
|
|
dev->crq.qnext = 0;
|
|
|
|
|
|
|
|
dprintf("CRQ for dev 0x%" PRIx32 " freed\n", dev->reg);
|
|
|
|
|
|
|
|
return H_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:23 +04:00
|
|
|
static target_ulong h_free_crq(CPUPPCState *env, sPAPREnvironment *spapr,
|
2011-04-01 08:15:30 +04:00
|
|
|
target_ulong opcode, target_ulong *args)
|
|
|
|
{
|
|
|
|
target_ulong reg = args[0];
|
|
|
|
VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
|
|
|
|
|
|
|
|
if (!dev) {
|
2012-03-29 01:39:45 +04:00
|
|
|
hcall_dprintf("Unit 0x" TARGET_FMT_lx " does not exist\n", reg);
|
2011-04-01 08:15:30 +04:00
|
|
|
return H_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2012-03-29 01:39:46 +04:00
|
|
|
return free_crq(dev);
|
2011-04-01 08:15:30 +04:00
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:23 +04:00
|
|
|
static target_ulong h_send_crq(CPUPPCState *env, sPAPREnvironment *spapr,
|
2011-04-01 08:15:30 +04:00
|
|
|
target_ulong opcode, target_ulong *args)
|
|
|
|
{
|
|
|
|
target_ulong reg = args[0];
|
|
|
|
target_ulong msg_hi = args[1];
|
|
|
|
target_ulong msg_lo = args[2];
|
|
|
|
VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
|
|
|
|
uint64_t crq_mangle[2];
|
|
|
|
|
|
|
|
if (!dev) {
|
2012-03-29 01:39:45 +04:00
|
|
|
hcall_dprintf("Unit 0x" TARGET_FMT_lx " does not exist\n", reg);
|
2011-04-01 08:15:30 +04:00
|
|
|
return H_PARAMETER;
|
|
|
|
}
|
|
|
|
crq_mangle[0] = cpu_to_be64(msg_hi);
|
|
|
|
crq_mangle[1] = cpu_to_be64(msg_lo);
|
|
|
|
|
|
|
|
if (dev->crq.SendFunc) {
|
|
|
|
return dev->crq.SendFunc(dev, (uint8_t *)crq_mangle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return H_HARDWARE;
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:23 +04:00
|
|
|
static target_ulong h_enable_crq(CPUPPCState *env, sPAPREnvironment *spapr,
|
2011-04-01 08:15:30 +04:00
|
|
|
target_ulong opcode, target_ulong *args)
|
|
|
|
{
|
|
|
|
target_ulong reg = args[0];
|
|
|
|
VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
|
|
|
|
|
|
|
|
if (!dev) {
|
2012-03-29 01:39:45 +04:00
|
|
|
hcall_dprintf("Unit 0x" TARGET_FMT_lx " does not exist\n", reg);
|
2011-04-01 08:15:30 +04:00
|
|
|
return H_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns negative error, 0 success, or positive: queue full */
|
|
|
|
int spapr_vio_send_crq(VIOsPAPRDevice *dev, uint8_t *crq)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
uint8_t byte;
|
|
|
|
|
|
|
|
if (!dev->crq.qsize) {
|
|
|
|
fprintf(stderr, "spapr_vio_send_creq on uninitialized queue\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Maybe do a fast path for KVM just writing to the pages */
|
2012-06-27 08:50:44 +04:00
|
|
|
rc = spapr_vio_dma_read(dev, dev->crq.qladdr + dev->crq.qnext, &byte, 1);
|
2011-04-01 08:15:30 +04:00
|
|
|
if (rc) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
if (byte != 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-06-27 08:50:44 +04:00
|
|
|
rc = spapr_vio_dma_write(dev, dev->crq.qladdr + dev->crq.qnext + 8,
|
2011-04-01 08:15:30 +04:00
|
|
|
&crq[8], 8);
|
|
|
|
if (rc) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
kvmppc_eieio();
|
|
|
|
|
2012-06-27 08:50:44 +04:00
|
|
|
rc = spapr_vio_dma_write(dev, dev->crq.qladdr + dev->crq.qnext, crq, 8);
|
2011-04-01 08:15:30 +04:00
|
|
|
if (rc) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->crq.qnext = (dev->crq.qnext + 16) % dev->crq.qsize;
|
|
|
|
|
|
|
|
if (dev->signal_state & 1) {
|
|
|
|
qemu_irq_pulse(dev->qirq);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-04-01 08:15:32 +04:00
|
|
|
/* "quiesce" handling */
|
|
|
|
|
|
|
|
static void spapr_vio_quiesce_one(VIOsPAPRDevice *dev)
|
|
|
|
{
|
2012-06-27 08:50:44 +04:00
|
|
|
VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
|
|
|
|
uint32_t liobn = SPAPR_VIO_BASE_LIOBN | dev->reg;
|
2011-04-01 08:15:32 +04:00
|
|
|
|
2012-06-27 08:50:44 +04:00
|
|
|
if (dev->dma) {
|
|
|
|
spapr_tce_free(dev->dma);
|
2011-04-01 08:15:32 +04:00
|
|
|
}
|
2012-06-27 08:50:44 +04:00
|
|
|
dev->dma = spapr_tce_new_dma_context(liobn, pc->rtce_window_size);
|
2011-04-01 08:15:32 +04:00
|
|
|
|
|
|
|
dev->crq.qladdr = 0;
|
|
|
|
dev->crq.qsize = 0;
|
|
|
|
dev->crq.qnext = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rtas_set_tce_bypass(sPAPREnvironment *spapr, uint32_t token,
|
|
|
|
uint32_t nargs, target_ulong args,
|
|
|
|
uint32_t nret, target_ulong rets)
|
|
|
|
{
|
|
|
|
VIOsPAPRBus *bus = spapr->vio_bus;
|
|
|
|
VIOsPAPRDevice *dev;
|
|
|
|
uint32_t unit, enable;
|
|
|
|
|
|
|
|
if (nargs != 2) {
|
|
|
|
rtas_st(rets, 0, -3);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
unit = rtas_ld(args, 0);
|
|
|
|
enable = rtas_ld(args, 1);
|
|
|
|
dev = spapr_vio_find_by_reg(bus, unit);
|
|
|
|
if (!dev) {
|
|
|
|
rtas_st(rets, 0, -3);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (enable) {
|
2012-06-27 08:50:44 +04:00
|
|
|
spapr_tce_free(dev->dma);
|
|
|
|
dev->dma = NULL;
|
2011-04-01 08:15:32 +04:00
|
|
|
} else {
|
2012-06-27 08:50:44 +04:00
|
|
|
VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
|
|
|
|
uint32_t liobn = SPAPR_VIO_BASE_LIOBN | dev->reg;
|
|
|
|
|
|
|
|
dev->dma = spapr_tce_new_dma_context(liobn, pc->rtce_window_size);
|
2011-04-01 08:15:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
rtas_st(rets, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rtas_quiesce(sPAPREnvironment *spapr, uint32_t token,
|
|
|
|
uint32_t nargs, target_ulong args,
|
|
|
|
uint32_t nret, target_ulong rets)
|
|
|
|
{
|
|
|
|
VIOsPAPRBus *bus = spapr->vio_bus;
|
2011-12-24 01:34:39 +04:00
|
|
|
BusChild *kid;
|
2011-04-01 08:15:32 +04:00
|
|
|
VIOsPAPRDevice *dev = NULL;
|
|
|
|
|
|
|
|
if (nargs != 0) {
|
|
|
|
rtas_st(rets, 0, -3);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-24 01:34:39 +04:00
|
|
|
QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
|
|
|
|
dev = (VIOsPAPRDevice *)kid->child;
|
2011-04-01 08:15:32 +04:00
|
|
|
spapr_vio_quiesce_one(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
rtas_st(rets, 0, 0);
|
|
|
|
}
|
|
|
|
|
2012-04-25 21:55:41 +04:00
|
|
|
static VIOsPAPRDevice *reg_conflict(VIOsPAPRDevice *dev)
|
2011-12-12 22:24:35 +04:00
|
|
|
{
|
2012-04-25 21:55:41 +04:00
|
|
|
VIOsPAPRBus *bus = DO_UPCAST(VIOsPAPRBus, bus, dev->qdev.parent_bus);
|
2011-12-24 01:34:39 +04:00
|
|
|
BusChild *kid;
|
2012-04-25 21:55:41 +04:00
|
|
|
VIOsPAPRDevice *other;
|
2011-12-12 22:24:35 +04:00
|
|
|
|
|
|
|
/*
|
2012-04-25 21:55:41 +04:00
|
|
|
* Check for a device other than the given one which is already
|
|
|
|
* using the requested address. We have to open code this because
|
|
|
|
* the given dev might already be in the list.
|
2011-12-12 22:24:35 +04:00
|
|
|
*/
|
2011-12-24 01:34:39 +04:00
|
|
|
QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
|
|
|
|
other = DO_UPCAST(VIOsPAPRDevice, qdev, kid->child);
|
2011-12-12 22:24:35 +04:00
|
|
|
|
2012-04-25 21:55:41 +04:00
|
|
|
if (other != dev && other->reg == dev->reg) {
|
|
|
|
return other;
|
2011-12-12 22:24:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-12 06:44:13 +04:00
|
|
|
static void spapr_vio_busdev_reset(DeviceState *qdev)
|
2012-03-29 01:39:46 +04:00
|
|
|
{
|
2012-04-12 06:44:13 +04:00
|
|
|
VIOsPAPRDevice *dev = DO_UPCAST(VIOsPAPRDevice, qdev, qdev);
|
|
|
|
VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
|
2012-03-29 01:39:46 +04:00
|
|
|
|
|
|
|
if (dev->crq.qsize) {
|
|
|
|
free_crq(dev);
|
|
|
|
}
|
2012-04-12 06:44:13 +04:00
|
|
|
|
|
|
|
if (pc->reset) {
|
|
|
|
pc->reset(dev);
|
|
|
|
}
|
2012-03-29 01:39:46 +04:00
|
|
|
}
|
|
|
|
|
2011-12-10 01:02:56 +04:00
|
|
|
static int spapr_vio_busdev_init(DeviceState *qdev)
|
2011-04-01 08:15:21 +04:00
|
|
|
{
|
|
|
|
VIOsPAPRDevice *dev = (VIOsPAPRDevice *)qdev;
|
2011-12-16 02:31:06 +04:00
|
|
|
VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
|
2012-06-27 08:50:44 +04:00
|
|
|
uint32_t liobn;
|
2011-04-01 08:15:21 +04:00
|
|
|
char *id;
|
2011-12-12 22:24:35 +04:00
|
|
|
|
2012-04-25 21:55:41 +04:00
|
|
|
if (dev->reg != -1) {
|
|
|
|
/*
|
|
|
|
* Explicitly assigned address, just verify that no-one else
|
|
|
|
* is using it. other mechanism). We have to open code this
|
|
|
|
* rather than using spapr_vio_find_by_reg() because sdev
|
|
|
|
* itself is already in the list.
|
|
|
|
*/
|
|
|
|
VIOsPAPRDevice *other = reg_conflict(dev);
|
|
|
|
|
|
|
|
if (other) {
|
|
|
|
fprintf(stderr, "vio: %s and %s devices conflict at address %#x\n",
|
|
|
|
object_get_typename(OBJECT(qdev)),
|
|
|
|
object_get_typename(OBJECT(&other->qdev)),
|
|
|
|
dev->reg);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Need to assign an address */
|
|
|
|
VIOsPAPRBus *bus = DO_UPCAST(VIOsPAPRBus, bus, dev->qdev.parent_bus);
|
|
|
|
|
|
|
|
do {
|
|
|
|
dev->reg = bus->next_reg++;
|
|
|
|
} while (reg_conflict(dev));
|
2011-12-12 22:24:35 +04:00
|
|
|
}
|
2011-04-01 08:15:21 +04:00
|
|
|
|
2011-11-15 22:53:13 +04:00
|
|
|
/* Don't overwrite ids assigned on the command line */
|
|
|
|
if (!dev->qdev.id) {
|
|
|
|
id = vio_format_dev_name(dev);
|
|
|
|
if (!id) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
dev->qdev.id = id;
|
2011-04-01 08:15:21 +04:00
|
|
|
}
|
|
|
|
|
pseries: Add support for level interrupts to XICS
The pseries "xics" interrupt controller, like most interrupt
controllers can support both message (i.e. edge sensitive) interrupts
and level sensitive interrupts, but it needs to know which are which.
When I implemented the xics emulation for qemu, the only devices we
supported were the PAPR virtual IO devices. These devices only use
message interrupts, so they were the only ones I implemented in xics.
Since then, however, we have added support for PCI devices, which use
level sensitive interrupts. It turns out the message interrupt logic
still actually works most of the time for these, but there are
circumstances where we can lost interrupts due to the incorrect
interrupt logic.
This patch, therefore, implements the correct xics level-sensitive
interrupt logic. The type of the interrupt is set when a device
allocates a new xics interrupt.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Alexander Graf <agraf@suse.de>
2012-03-07 19:12:21 +04:00
|
|
|
dev->qirq = spapr_allocate_msi(dev->vio_irq_num, &dev->vio_irq_num);
|
2011-09-16 00:49:49 +04:00
|
|
|
if (!dev->qirq) {
|
|
|
|
return -1;
|
2011-05-26 13:52:46 +04:00
|
|
|
}
|
2011-04-01 08:15:21 +04:00
|
|
|
|
2012-06-27 08:50:44 +04:00
|
|
|
liobn = SPAPR_VIO_BASE_LIOBN | dev->reg;
|
|
|
|
dev->dma = spapr_tce_new_dma_context(liobn, pc->rtce_window_size);
|
2011-04-01 08:15:28 +04:00
|
|
|
|
2011-12-16 02:31:06 +04:00
|
|
|
return pc->init(dev);
|
2011-04-01 08:15:21 +04:00
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:23 +04:00
|
|
|
static target_ulong h_vio_signal(CPUPPCState *env, sPAPREnvironment *spapr,
|
2011-04-01 08:15:26 +04:00
|
|
|
target_ulong opcode,
|
|
|
|
target_ulong *args)
|
|
|
|
{
|
|
|
|
target_ulong reg = args[0];
|
|
|
|
target_ulong mode = args[1];
|
|
|
|
VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
|
2011-12-16 02:31:06 +04:00
|
|
|
VIOsPAPRDeviceClass *pc;
|
2011-04-01 08:15:26 +04:00
|
|
|
|
|
|
|
if (!dev) {
|
|
|
|
return H_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2011-12-16 02:31:06 +04:00
|
|
|
pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
|
2011-04-01 08:15:26 +04:00
|
|
|
|
2011-12-16 02:31:06 +04:00
|
|
|
if (mode & ~pc->signal_mask) {
|
2011-04-01 08:15:26 +04:00
|
|
|
return H_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->signal_state = mode;
|
|
|
|
|
|
|
|
return H_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-04-01 08:15:21 +04:00
|
|
|
VIOsPAPRBus *spapr_vio_bus_init(void)
|
|
|
|
{
|
|
|
|
VIOsPAPRBus *bus;
|
|
|
|
BusState *qbus;
|
|
|
|
DeviceState *dev;
|
|
|
|
|
|
|
|
/* Create bridge device */
|
|
|
|
dev = qdev_create(NULL, "spapr-vio-bridge");
|
|
|
|
qdev_init_nofail(dev);
|
|
|
|
|
|
|
|
/* Create bus on bridge device */
|
|
|
|
|
2012-05-02 11:00:20 +04:00
|
|
|
qbus = qbus_create(TYPE_SPAPR_VIO_BUS, dev, "spapr-vio");
|
2011-04-01 08:15:21 +04:00
|
|
|
bus = DO_UPCAST(VIOsPAPRBus, bus, qbus);
|
2012-04-25 21:55:41 +04:00
|
|
|
bus->next_reg = 0x1000;
|
2011-04-01 08:15:21 +04:00
|
|
|
|
2011-04-01 08:15:26 +04:00
|
|
|
/* hcall-vio */
|
|
|
|
spapr_register_hypercall(H_VIO_SIGNAL, h_vio_signal);
|
|
|
|
|
2011-04-01 08:15:30 +04:00
|
|
|
/* hcall-crq */
|
|
|
|
spapr_register_hypercall(H_REG_CRQ, h_reg_crq);
|
|
|
|
spapr_register_hypercall(H_FREE_CRQ, h_free_crq);
|
|
|
|
spapr_register_hypercall(H_SEND_CRQ, h_send_crq);
|
|
|
|
spapr_register_hypercall(H_ENABLE_CRQ, h_enable_crq);
|
|
|
|
|
2011-04-01 08:15:32 +04:00
|
|
|
/* RTAS calls */
|
|
|
|
spapr_rtas_register("ibm,set-tce-bypass", rtas_set_tce_bypass);
|
|
|
|
spapr_rtas_register("quiesce", rtas_quiesce);
|
|
|
|
|
2011-04-01 08:15:21 +04:00
|
|
|
return bus;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Represents sPAPR hcall VIO devices */
|
|
|
|
|
|
|
|
static int spapr_vio_bridge_init(SysBusDevice *dev)
|
|
|
|
{
|
|
|
|
/* nothing */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-24 23:12:29 +04:00
|
|
|
static void spapr_vio_bridge_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 07:34:16 +04:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
|
2012-01-24 23:12:29 +04:00
|
|
|
|
2011-12-08 07:34:16 +04:00
|
|
|
k->init = spapr_vio_bridge_init;
|
|
|
|
dc->no_user = 1;
|
2012-01-24 23:12:29 +04:00
|
|
|
}
|
|
|
|
|
2011-12-08 07:34:16 +04:00
|
|
|
static TypeInfo spapr_vio_bridge_info = {
|
|
|
|
.name = "spapr-vio-bridge",
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(SysBusDevice),
|
|
|
|
.class_init = spapr_vio_bridge_class_init,
|
2011-04-01 08:15:21 +04:00
|
|
|
};
|
|
|
|
|
2011-12-08 07:34:16 +04:00
|
|
|
static void vio_spapr_device_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *k = DEVICE_CLASS(klass);
|
|
|
|
k->init = spapr_vio_busdev_init;
|
2012-04-12 06:44:13 +04:00
|
|
|
k->reset = spapr_vio_busdev_reset;
|
2012-05-02 11:00:20 +04:00
|
|
|
k->bus_type = TYPE_SPAPR_VIO_BUS;
|
2012-03-28 20:12:47 +04:00
|
|
|
k->props = spapr_vio_props;
|
2011-12-08 07:34:16 +04:00
|
|
|
}
|
|
|
|
|
2011-12-16 02:31:06 +04:00
|
|
|
static TypeInfo spapr_vio_type_info = {
|
|
|
|
.name = TYPE_VIO_SPAPR_DEVICE,
|
|
|
|
.parent = TYPE_DEVICE,
|
|
|
|
.instance_size = sizeof(VIOsPAPRDevice),
|
|
|
|
.abstract = true,
|
|
|
|
.class_size = sizeof(VIOsPAPRDeviceClass),
|
2011-12-08 07:34:16 +04:00
|
|
|
.class_init = vio_spapr_device_class_init,
|
2011-12-16 02:31:06 +04:00
|
|
|
};
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
static void spapr_vio_register_types(void)
|
2011-04-01 08:15:21 +04:00
|
|
|
{
|
2012-05-02 11:00:20 +04:00
|
|
|
type_register_static(&spapr_vio_bus_info);
|
2011-12-08 07:34:16 +04:00
|
|
|
type_register_static(&spapr_vio_bridge_info);
|
2011-12-16 02:31:06 +04:00
|
|
|
type_register_static(&spapr_vio_type_info);
|
2011-04-01 08:15:21 +04:00
|
|
|
}
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
type_init(spapr_vio_register_types)
|
2011-04-01 08:15:21 +04:00
|
|
|
|
|
|
|
#ifdef CONFIG_FDT
|
2011-12-12 22:24:32 +04:00
|
|
|
static int compare_reg(const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
VIOsPAPRDevice const *dev1, *dev2;
|
|
|
|
|
|
|
|
dev1 = (VIOsPAPRDevice *)*(DeviceState **)p1;
|
|
|
|
dev2 = (VIOsPAPRDevice *)*(DeviceState **)p2;
|
|
|
|
|
|
|
|
if (dev1->reg < dev2->reg) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (dev1->reg == dev2->reg) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dev1->reg > dev2->reg */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-04-01 08:15:21 +04:00
|
|
|
int spapr_populate_vdevice(VIOsPAPRBus *bus, void *fdt)
|
|
|
|
{
|
2011-12-12 22:24:32 +04:00
|
|
|
DeviceState *qdev, **qdevs;
|
2011-12-24 01:34:39 +04:00
|
|
|
BusChild *kid;
|
2011-12-12 22:24:32 +04:00
|
|
|
int i, num, ret = 0;
|
2011-04-01 08:15:21 +04:00
|
|
|
|
2011-12-12 22:24:32 +04:00
|
|
|
/* Count qdevs on the bus list */
|
|
|
|
num = 0;
|
2011-12-24 01:34:39 +04:00
|
|
|
QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
|
2011-12-12 22:24:32 +04:00
|
|
|
num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy out into an array of pointers */
|
|
|
|
qdevs = g_malloc(sizeof(qdev) * num);
|
|
|
|
num = 0;
|
2011-12-24 01:34:39 +04:00
|
|
|
QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
|
|
|
|
qdevs[num++] = kid->child;
|
2011-12-12 22:24:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort the array */
|
|
|
|
qsort(qdevs, num, sizeof(qdev), compare_reg);
|
|
|
|
|
|
|
|
/* Hack alert. Give the devices to libfdt in reverse order, we happen
|
|
|
|
* to know that will mean they are in forward order in the tree. */
|
|
|
|
for (i = num - 1; i >= 0; i--) {
|
|
|
|
VIOsPAPRDevice *dev = (VIOsPAPRDevice *)(qdevs[i]);
|
2011-04-01 08:15:21 +04:00
|
|
|
|
|
|
|
ret = vio_make_devnode(dev, fdt);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
2011-12-12 22:24:32 +04:00
|
|
|
goto out;
|
2011-04-01 08:15:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-12 22:24:32 +04:00
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
free(qdevs);
|
|
|
|
|
|
|
|
return ret;
|
2011-04-01 08:15:21 +04:00
|
|
|
}
|
2011-12-13 08:24:34 +04:00
|
|
|
|
|
|
|
int spapr_populate_chosen_stdout(void *fdt, VIOsPAPRBus *bus)
|
|
|
|
{
|
|
|
|
VIOsPAPRDevice *dev;
|
|
|
|
char *name, *path;
|
|
|
|
int ret, offset;
|
|
|
|
|
|
|
|
dev = spapr_vty_get_default(bus);
|
|
|
|
if (!dev)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
offset = fdt_path_offset(fdt, "/chosen");
|
|
|
|
if (offset < 0) {
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = vio_format_dev_name(dev);
|
|
|
|
if (!name) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asprintf(&path, "/vdevice/%s", name) < 0) {
|
|
|
|
path = NULL;
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = fdt_setprop_string(fdt, offset, "linux,stdout-path", path);
|
|
|
|
out:
|
|
|
|
free(name);
|
|
|
|
free(path);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2011-04-01 08:15:21 +04:00
|
|
|
#endif /* CONFIG_FDT */
|