2018-12-06 02:22:15 +03:00
|
|
|
/*
|
|
|
|
* QEMU PowerPC XIVE interrupt controller model
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* The POWER9 processor comes with a new interrupt controller, called
|
|
|
|
* XIVE as "eXternal Interrupt Virtualization Engine".
|
|
|
|
*
|
|
|
|
* = Overall architecture
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* XIVE Interrupt Controller
|
|
|
|
* +------------------------------------+ IPIs
|
|
|
|
* | +---------+ +---------+ +--------+ | +-------+
|
|
|
|
* | |VC | |CQ | |PC |----> | CORES |
|
|
|
|
* | | esb | | | | |----> | |
|
|
|
|
* | | eas | | Bridge | | tctx |----> | |
|
|
|
|
* | |SC end | | | | nvt | | | |
|
|
|
|
* +------+ | +---------+ +----+----+ +--------+ | +-+-+-+-+
|
|
|
|
* | RAM | +------------------|-----------------+ | | |
|
|
|
|
* | | | | | |
|
|
|
|
* | | | | | |
|
|
|
|
* | | +--------------------v------------------------v-v-v--+ other
|
|
|
|
* | <--+ Power Bus +--> chips
|
|
|
|
* | esb | +---------+-----------------------+------------------+
|
|
|
|
* | eas | | |
|
|
|
|
* | end | +--|------+ |
|
|
|
|
* | nvt | +----+----+ | +----+----+
|
|
|
|
* +------+ |SC | | |SC |
|
|
|
|
* | | | | |
|
|
|
|
* | PQ-bits | | | PQ-bits |
|
|
|
|
* | local |-+ | in VC |
|
|
|
|
* +---------+ +---------+
|
|
|
|
* PCIe NX,NPU,CAPI
|
|
|
|
*
|
|
|
|
* SC: Source Controller (aka. IVSE)
|
|
|
|
* VC: Virtualization Controller (aka. IVRE)
|
|
|
|
* PC: Presentation Controller (aka. IVPE)
|
|
|
|
* CQ: Common Queue (Bridge)
|
|
|
|
*
|
|
|
|
* PQ-bits: 2 bits source state machine (P:pending Q:queued)
|
|
|
|
* esb: Event State Buffer (Array of PQ bits in an IVSE)
|
|
|
|
* eas: Event Assignment Structure
|
|
|
|
* end: Event Notification Descriptor
|
|
|
|
* nvt: Notification Virtual Target
|
|
|
|
* tctx: Thread interrupt Context
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* The XIVE IC is composed of three sub-engines :
|
|
|
|
*
|
|
|
|
* - Interrupt Virtualization Source Engine (IVSE), or Source
|
|
|
|
* Controller (SC). These are found in PCI PHBs, in the PSI host
|
|
|
|
* bridge controller, but also inside the main controller for the
|
|
|
|
* core IPIs and other sub-chips (NX, CAP, NPU) of the
|
|
|
|
* chip/processor. They are configured to feed the IVRE with events.
|
|
|
|
*
|
|
|
|
* - Interrupt Virtualization Routing Engine (IVRE) or Virtualization
|
|
|
|
* Controller (VC). Its job is to match an event source with an
|
|
|
|
* Event Notification Descriptor (END).
|
|
|
|
*
|
|
|
|
* - Interrupt Virtualization Presentation Engine (IVPE) or
|
|
|
|
* Presentation Controller (PC). It maintains the interrupt context
|
|
|
|
* state of each thread and handles the delivery of the external
|
|
|
|
* exception to the thread.
|
|
|
|
*
|
|
|
|
* In XIVE 1.0, the sub-engines used to be referred as:
|
|
|
|
*
|
|
|
|
* SC Source Controller
|
|
|
|
* VC Virtualization Controller
|
|
|
|
* PC Presentation Controller
|
|
|
|
* CQ Common Queue (PowerBUS Bridge)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* = XIVE internal tables
|
|
|
|
*
|
|
|
|
* Each of the sub-engines uses a set of tables to redirect exceptions
|
|
|
|
* from event sources to CPU threads.
|
|
|
|
*
|
|
|
|
* +-------+
|
|
|
|
* User or OS | EQ |
|
|
|
|
* or +------>|entries|
|
|
|
|
* Hypervisor | | .. |
|
|
|
|
* Memory | +-------+
|
|
|
|
* | ^
|
|
|
|
* | |
|
|
|
|
* +-------------------------------------------------+
|
|
|
|
* | |
|
|
|
|
* Hypervisor +------+ +---+--+ +---+--+ +------+
|
|
|
|
* Memory | ESB | | EAT | | ENDT | | NVTT |
|
|
|
|
* (skiboot) +----+-+ +----+-+ +----+-+ +------+
|
|
|
|
* ^ | ^ | ^ | ^
|
|
|
|
* | | | | | | |
|
|
|
|
* +-------------------------------------------------+
|
|
|
|
* | | | | | | |
|
|
|
|
* | | | | | | |
|
|
|
|
* +----|--|--------|--|--------|--|-+ +-|-----+ +------+
|
|
|
|
* | | | | | | | | | | tctx| |Thread|
|
|
|
|
* IPI or --> | + v + v + v |---| + .. |-----> |
|
|
|
|
* HW events --> | | | | | |
|
|
|
|
* IVSE | IVRE | | IVPE | +------+
|
|
|
|
* +---------------------------------+ +-------+
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* The IVSE have a 2-bits state machine, P for pending and Q for queued,
|
|
|
|
* for each source that allows events to be triggered. They are stored in
|
|
|
|
* an Event State Buffer (ESB) array and can be controlled by MMIOs.
|
|
|
|
*
|
|
|
|
* If the event is let through, the IVRE looks up in the Event Assignment
|
|
|
|
* Structure (EAS) table for an Event Notification Descriptor (END)
|
|
|
|
* configured for the source. Each Event Notification Descriptor defines
|
|
|
|
* a notification path to a CPU and an in-memory Event Queue, in which
|
|
|
|
* will be enqueued an EQ data for the OS to pull.
|
|
|
|
*
|
|
|
|
* The IVPE determines if a Notification Virtual Target (NVT) can
|
|
|
|
* handle the event by scanning the thread contexts of the VCPUs
|
|
|
|
* dispatched on the processor HW threads. It maintains the state of
|
|
|
|
* the thread interrupt context (TCTX) of each thread in a NVT table.
|
|
|
|
*
|
|
|
|
* = Acronyms
|
|
|
|
*
|
|
|
|
* Description In XIVE 1.0, used to be referred as
|
|
|
|
*
|
|
|
|
* EAS Event Assignment Structure IVE Interrupt Virt. Entry
|
|
|
|
* EAT Event Assignment Table IVT Interrupt Virt. Table
|
|
|
|
* ENDT Event Notif. Descriptor Table EQDT Event Queue Desc. Table
|
|
|
|
* EQ Event Queue same
|
|
|
|
* ESB Event State Buffer SBE State Bit Entry
|
|
|
|
* NVT Notif. Virtual Target VPD Virtual Processor Desc.
|
|
|
|
* NVTT Notif. Virtual Target Table VPDT Virtual Processor Desc. Table
|
|
|
|
* TCTX Thread interrupt Context
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017-2018, IBM Corporation.
|
|
|
|
*
|
|
|
|
* This code is licensed under the GPL version 2 or later. See the
|
|
|
|
* COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PPC_XIVE_H
|
|
|
|
#define PPC_XIVE_H
|
|
|
|
|
2019-05-13 11:42:33 +03:00
|
|
|
#include "sysemu/kvm.h"
|
2018-12-06 02:22:18 +03:00
|
|
|
#include "hw/sysbus.h"
|
|
|
|
#include "hw/ppc/xive_regs.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2018-12-06 02:22:15 +03:00
|
|
|
|
2018-12-06 02:22:17 +03:00
|
|
|
/*
|
2019-01-09 18:15:32 +03:00
|
|
|
* XIVE Notifier (Interface between Source and Router)
|
2018-12-06 02:22:17 +03:00
|
|
|
*/
|
|
|
|
|
2019-07-18 14:54:04 +03:00
|
|
|
typedef struct XiveNotifier XiveNotifier;
|
2018-12-06 02:22:17 +03:00
|
|
|
|
|
|
|
#define TYPE_XIVE_NOTIFIER "xive-notifier"
|
|
|
|
#define XIVE_NOTIFIER(obj) \
|
2019-07-18 14:54:04 +03:00
|
|
|
INTERFACE_CHECK(XiveNotifier, (obj), TYPE_XIVE_NOTIFIER)
|
2020-09-03 23:43:22 +03:00
|
|
|
typedef struct XiveNotifierClass XiveNotifierClass;
|
2020-09-01 00:07:33 +03:00
|
|
|
DECLARE_CLASS_CHECKERS(XiveNotifierClass, XIVE_NOTIFIER,
|
|
|
|
TYPE_XIVE_NOTIFIER)
|
2018-12-06 02:22:17 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct XiveNotifierClass {
|
2018-12-06 02:22:17 +03:00
|
|
|
InterfaceClass parent;
|
2022-03-02 08:51:39 +03:00
|
|
|
void (*notify)(XiveNotifier *xn, uint32_t lisn, bool pq_checked);
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2018-12-06 02:22:17 +03:00
|
|
|
|
2018-12-06 02:22:15 +03:00
|
|
|
/*
|
|
|
|
* XIVE Interrupt Source
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define TYPE_XIVE_SOURCE "xive-source"
|
2020-09-16 21:25:19 +03:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(XiveSource, XIVE_SOURCE)
|
2018-12-06 02:22:15 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XIVE Interrupt Source characteristics, which define how the ESB are
|
|
|
|
* controlled.
|
|
|
|
*/
|
|
|
|
#define XIVE_SRC_H_INT_ESB 0x1 /* ESB managed with hcall H_INT_ESB */
|
|
|
|
#define XIVE_SRC_STORE_EOI 0x2 /* Store EOI supported */
|
2022-03-02 08:51:39 +03:00
|
|
|
#define XIVE_SRC_PQ_DISABLE 0x4 /* Disable check on the PQ state bits */
|
2018-12-06 02:22:15 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct XiveSource {
|
2018-12-06 02:22:15 +03:00
|
|
|
DeviceState parent;
|
|
|
|
|
|
|
|
/* IRQs */
|
|
|
|
uint32_t nr_irqs;
|
2018-12-06 02:22:16 +03:00
|
|
|
unsigned long *lsi_map;
|
2018-12-06 02:22:15 +03:00
|
|
|
|
2018-12-06 02:22:16 +03:00
|
|
|
/* PQ bits and LSI assertion bit */
|
2018-12-06 02:22:15 +03:00
|
|
|
uint8_t *status;
|
|
|
|
|
|
|
|
/* ESB memory region */
|
|
|
|
uint64_t esb_flags;
|
|
|
|
uint32_t esb_shift;
|
|
|
|
MemoryRegion esb_mmio;
|
2020-08-07 14:32:06 +03:00
|
|
|
MemoryRegion esb_mmio_emulated;
|
2018-12-06 02:22:17 +03:00
|
|
|
|
2019-05-13 11:42:33 +03:00
|
|
|
/* KVM support */
|
|
|
|
void *esb_mmap;
|
2019-06-14 19:59:19 +03:00
|
|
|
MemoryRegion esb_mmio_kvm;
|
2019-05-13 11:42:33 +03:00
|
|
|
|
2018-12-06 02:22:17 +03:00
|
|
|
XiveNotifier *xive;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2018-12-06 02:22:15 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ESB MMIO setting. Can be one page, for both source triggering and
|
|
|
|
* source management, or two different pages. See below for magic
|
|
|
|
* values.
|
|
|
|
*/
|
|
|
|
#define XIVE_ESB_4K 12 /* PSI HB only */
|
|
|
|
#define XIVE_ESB_4K_2PAGE 13
|
|
|
|
#define XIVE_ESB_64K 16
|
|
|
|
#define XIVE_ESB_64K_2PAGE 17
|
|
|
|
|
|
|
|
static inline bool xive_source_esb_has_2page(XiveSource *xsrc)
|
|
|
|
{
|
|
|
|
return xsrc->esb_shift == XIVE_ESB_64K_2PAGE ||
|
|
|
|
xsrc->esb_shift == XIVE_ESB_4K_2PAGE;
|
|
|
|
}
|
|
|
|
|
2020-08-07 14:32:06 +03:00
|
|
|
static inline size_t xive_source_esb_len(XiveSource *xsrc)
|
|
|
|
{
|
|
|
|
return (1ull << xsrc->esb_shift) * xsrc->nr_irqs;
|
|
|
|
}
|
|
|
|
|
2018-12-06 02:22:15 +03:00
|
|
|
/* The trigger page is always the first/even page */
|
|
|
|
static inline hwaddr xive_source_esb_page(XiveSource *xsrc, uint32_t srcno)
|
|
|
|
{
|
|
|
|
assert(srcno < xsrc->nr_irqs);
|
|
|
|
return (1ull << xsrc->esb_shift) * srcno;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* In a two pages ESB MMIO setting, the odd page is for management */
|
|
|
|
static inline hwaddr xive_source_esb_mgmt(XiveSource *xsrc, int srcno)
|
|
|
|
{
|
|
|
|
hwaddr addr = xive_source_esb_page(xsrc, srcno);
|
|
|
|
|
|
|
|
if (xive_source_esb_has_2page(xsrc)) {
|
|
|
|
addr += (1 << (xsrc->esb_shift - 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Each interrupt source has a 2-bit state machine which can be
|
|
|
|
* controlled by MMIO. P indicates that an interrupt is pending (has
|
|
|
|
* been sent to a queue and is waiting for an EOI). Q indicates that
|
|
|
|
* the interrupt has been triggered while pending.
|
|
|
|
*
|
|
|
|
* This acts as a coalescing mechanism in order to guarantee that a
|
|
|
|
* given interrupt only occurs at most once in a queue.
|
|
|
|
*
|
|
|
|
* When doing an EOI, the Q bit will indicate if the interrupt
|
|
|
|
* needs to be re-triggered.
|
|
|
|
*/
|
2018-12-06 02:22:16 +03:00
|
|
|
#define XIVE_STATUS_ASSERTED 0x4 /* Extra bit for LSI */
|
2018-12-06 02:22:15 +03:00
|
|
|
#define XIVE_ESB_VAL_P 0x2
|
|
|
|
#define XIVE_ESB_VAL_Q 0x1
|
|
|
|
|
|
|
|
#define XIVE_ESB_RESET 0x0
|
|
|
|
#define XIVE_ESB_PENDING XIVE_ESB_VAL_P
|
|
|
|
#define XIVE_ESB_QUEUED (XIVE_ESB_VAL_P | XIVE_ESB_VAL_Q)
|
|
|
|
#define XIVE_ESB_OFF XIVE_ESB_VAL_Q
|
|
|
|
|
2021-08-09 16:45:28 +03:00
|
|
|
bool xive_esb_trigger(uint8_t *pq);
|
|
|
|
bool xive_esb_eoi(uint8_t *pq);
|
|
|
|
uint8_t xive_esb_set(uint8_t *pq, uint8_t value);
|
|
|
|
|
2018-12-06 02:22:15 +03:00
|
|
|
/*
|
|
|
|
* "magic" Event State Buffer (ESB) MMIO offsets.
|
|
|
|
*
|
|
|
|
* The following offsets into the ESB MMIO allow to read or manipulate
|
|
|
|
* the PQ bits. They must be used with an 8-byte load instruction.
|
|
|
|
* They all return the previous state of the interrupt (atomically).
|
|
|
|
*
|
|
|
|
* Additionally, some ESB pages support doing an EOI via a store and
|
|
|
|
* some ESBs support doing a trigger via a separate trigger page.
|
|
|
|
*/
|
|
|
|
#define XIVE_ESB_STORE_EOI 0x400 /* Store */
|
|
|
|
#define XIVE_ESB_LOAD_EOI 0x000 /* Load */
|
|
|
|
#define XIVE_ESB_GET 0x800 /* Load */
|
2022-03-02 08:51:39 +03:00
|
|
|
#define XIVE_ESB_INJECT 0x800 /* Store */
|
2018-12-06 02:22:15 +03:00
|
|
|
#define XIVE_ESB_SET_PQ_00 0xc00 /* Load */
|
|
|
|
#define XIVE_ESB_SET_PQ_01 0xd00 /* Load */
|
|
|
|
#define XIVE_ESB_SET_PQ_10 0xe00 /* Load */
|
|
|
|
#define XIVE_ESB_SET_PQ_11 0xf00 /* Load */
|
|
|
|
|
|
|
|
uint8_t xive_source_esb_get(XiveSource *xsrc, uint32_t srcno);
|
|
|
|
uint8_t xive_source_esb_set(XiveSource *xsrc, uint32_t srcno, uint8_t pq);
|
|
|
|
|
2021-10-05 00:21:41 +03:00
|
|
|
/*
|
|
|
|
* Source status helpers
|
|
|
|
*/
|
|
|
|
static inline void xive_source_set_status(XiveSource *xsrc, uint32_t srcno,
|
|
|
|
uint8_t status, bool enable)
|
|
|
|
{
|
|
|
|
if (enable) {
|
|
|
|
xsrc->status[srcno] |= status;
|
|
|
|
} else {
|
|
|
|
xsrc->status[srcno] &= ~status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void xive_source_set_asserted(XiveSource *xsrc, uint32_t srcno,
|
|
|
|
bool enable)
|
|
|
|
{
|
|
|
|
xive_source_set_status(xsrc, srcno, XIVE_STATUS_ASSERTED, enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool xive_source_is_asserted(XiveSource *xsrc, uint32_t srcno)
|
|
|
|
{
|
|
|
|
return xsrc->status[srcno] & XIVE_STATUS_ASSERTED;
|
|
|
|
}
|
|
|
|
|
2018-12-06 02:22:15 +03:00
|
|
|
void xive_source_pic_print_info(XiveSource *xsrc, uint32_t offset,
|
|
|
|
Monitor *mon);
|
|
|
|
|
2018-12-06 02:22:16 +03:00
|
|
|
static inline bool xive_source_irq_is_lsi(XiveSource *xsrc, uint32_t srcno)
|
|
|
|
{
|
|
|
|
assert(srcno < xsrc->nr_irqs);
|
|
|
|
return test_bit(srcno, xsrc->lsi_map);
|
|
|
|
}
|
|
|
|
|
2019-02-12 21:24:06 +03:00
|
|
|
static inline void xive_source_irq_set_lsi(XiveSource *xsrc, uint32_t srcno)
|
2018-12-06 02:22:16 +03:00
|
|
|
{
|
|
|
|
assert(srcno < xsrc->nr_irqs);
|
2019-02-12 21:24:06 +03:00
|
|
|
bitmap_set(xsrc->lsi_map, srcno, 1);
|
2018-12-06 02:22:16 +03:00
|
|
|
}
|
|
|
|
|
2019-01-02 08:57:38 +03:00
|
|
|
void xive_source_set_irq(void *opaque, int srcno, int val);
|
|
|
|
|
2019-01-17 10:53:24 +03:00
|
|
|
/*
|
|
|
|
* XIVE Thread interrupt Management (TM) context
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define TYPE_XIVE_TCTX "xive-tctx"
|
2020-09-16 21:25:19 +03:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(XiveTCTX, XIVE_TCTX)
|
2019-01-17 10:53:24 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XIVE Thread interrupt Management register rings :
|
|
|
|
*
|
|
|
|
* QW-0 User event-based exception state
|
|
|
|
* QW-1 O/S OS context for priority management, interrupt acks
|
|
|
|
* QW-2 Pool hypervisor pool context for virtual processors dispatched
|
|
|
|
* QW-3 Physical physical thread context and security context
|
|
|
|
*/
|
|
|
|
#define XIVE_TM_RING_COUNT 4
|
|
|
|
#define XIVE_TM_RING_SIZE 0x10
|
|
|
|
|
2020-01-06 17:56:41 +03:00
|
|
|
typedef struct XivePresenter XivePresenter;
|
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct XiveTCTX {
|
2019-01-17 10:53:24 +03:00
|
|
|
DeviceState parent_obj;
|
|
|
|
|
|
|
|
CPUState *cs;
|
2019-06-06 20:44:09 +03:00
|
|
|
qemu_irq hv_output;
|
|
|
|
qemu_irq os_output;
|
2019-01-17 10:53:24 +03:00
|
|
|
|
|
|
|
uint8_t regs[XIVE_TM_RING_COUNT * XIVE_TM_RING_SIZE];
|
2020-01-06 17:56:41 +03:00
|
|
|
|
|
|
|
XivePresenter *xptr;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2019-01-17 10:53:24 +03:00
|
|
|
|
2021-09-01 12:41:52 +03:00
|
|
|
static inline uint32_t xive_tctx_word2(uint8_t *ring)
|
|
|
|
{
|
|
|
|
return *((uint32_t *) &ring[TM_WORD2]);
|
|
|
|
}
|
|
|
|
|
2018-12-06 02:22:18 +03:00
|
|
|
/*
|
|
|
|
* XIVE Router
|
|
|
|
*/
|
2020-01-06 17:56:37 +03:00
|
|
|
typedef struct XiveFabric XiveFabric;
|
2018-12-06 02:22:18 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct XiveRouter {
|
2018-12-06 02:22:18 +03:00
|
|
|
SysBusDevice parent;
|
2020-01-06 17:56:37 +03:00
|
|
|
|
|
|
|
XiveFabric *xfb;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2018-12-06 02:22:18 +03:00
|
|
|
|
|
|
|
#define TYPE_XIVE_ROUTER "xive-router"
|
2020-09-01 00:07:37 +03:00
|
|
|
OBJECT_DECLARE_TYPE(XiveRouter, XiveRouterClass,
|
qom: Remove module_obj_name parameter from OBJECT_DECLARE* macros
One of the goals of having less boilerplate on QOM declarations
is to avoid human error. Requiring an extra argument that is
never used is an opportunity for mistakes.
Remove the unused argument from OBJECT_DECLARE_TYPE and
OBJECT_DECLARE_SIMPLE_TYPE.
Coccinelle patch used to convert all users of the macros:
@@
declarer name OBJECT_DECLARE_TYPE;
identifier InstanceType, ClassType, lowercase, UPPERCASE;
@@
OBJECT_DECLARE_TYPE(InstanceType, ClassType,
- lowercase,
UPPERCASE);
@@
declarer name OBJECT_DECLARE_SIMPLE_TYPE;
identifier InstanceType, lowercase, UPPERCASE;
@@
OBJECT_DECLARE_SIMPLE_TYPE(InstanceType,
- lowercase,
UPPERCASE);
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Acked-by: Igor Mammedov <imammedo@redhat.com>
Acked-by: Paul Durrant <paul@xen.org>
Acked-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20200916182519.415636-4-ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2020-09-16 21:25:17 +03:00
|
|
|
XIVE_ROUTER)
|
2018-12-06 02:22:18 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct XiveRouterClass {
|
2018-12-06 02:22:18 +03:00
|
|
|
SysBusDeviceClass parent;
|
|
|
|
|
|
|
|
/* XIVE table accessors */
|
|
|
|
int (*get_eas)(XiveRouter *xrtr, uint8_t eas_blk, uint32_t eas_idx,
|
|
|
|
XiveEAS *eas);
|
2022-03-02 08:51:39 +03:00
|
|
|
int (*get_pq)(XiveRouter *xrtr, uint8_t eas_blk, uint32_t eas_idx,
|
|
|
|
uint8_t *pq);
|
|
|
|
int (*set_pq)(XiveRouter *xrtr, uint8_t eas_blk, uint32_t eas_idx,
|
|
|
|
uint8_t *pq);
|
2018-12-06 02:22:19 +03:00
|
|
|
int (*get_end)(XiveRouter *xrtr, uint8_t end_blk, uint32_t end_idx,
|
|
|
|
XiveEND *end);
|
|
|
|
int (*write_end)(XiveRouter *xrtr, uint8_t end_blk, uint32_t end_idx,
|
|
|
|
XiveEND *end, uint8_t word_number);
|
2018-12-09 22:45:54 +03:00
|
|
|
int (*get_nvt)(XiveRouter *xrtr, uint8_t nvt_blk, uint32_t nvt_idx,
|
|
|
|
XiveNVT *nvt);
|
|
|
|
int (*write_nvt)(XiveRouter *xrtr, uint8_t nvt_blk, uint32_t nvt_idx,
|
|
|
|
XiveNVT *nvt, uint8_t word_number);
|
2019-11-25 09:58:19 +03:00
|
|
|
uint8_t (*get_block_id)(XiveRouter *xrtr);
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2018-12-06 02:22:18 +03:00
|
|
|
|
|
|
|
int xive_router_get_eas(XiveRouter *xrtr, uint8_t eas_blk, uint32_t eas_idx,
|
|
|
|
XiveEAS *eas);
|
2018-12-06 02:22:19 +03:00
|
|
|
int xive_router_get_end(XiveRouter *xrtr, uint8_t end_blk, uint32_t end_idx,
|
|
|
|
XiveEND *end);
|
|
|
|
int xive_router_write_end(XiveRouter *xrtr, uint8_t end_blk, uint32_t end_idx,
|
|
|
|
XiveEND *end, uint8_t word_number);
|
2018-12-09 22:45:54 +03:00
|
|
|
int xive_router_get_nvt(XiveRouter *xrtr, uint8_t nvt_blk, uint32_t nvt_idx,
|
|
|
|
XiveNVT *nvt);
|
|
|
|
int xive_router_write_nvt(XiveRouter *xrtr, uint8_t nvt_blk, uint32_t nvt_idx,
|
|
|
|
XiveNVT *nvt, uint8_t word_number);
|
2022-03-02 08:51:39 +03:00
|
|
|
void xive_router_notify(XiveNotifier *xn, uint32_t lisn, bool pq_checked);
|
2018-12-06 02:22:19 +03:00
|
|
|
|
2019-11-25 09:58:01 +03:00
|
|
|
/*
|
|
|
|
* XIVE Presenter
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct XiveTCTXMatch {
|
|
|
|
XiveTCTX *tctx;
|
|
|
|
uint8_t ring;
|
|
|
|
} XiveTCTXMatch;
|
|
|
|
|
|
|
|
#define TYPE_XIVE_PRESENTER "xive-presenter"
|
|
|
|
#define XIVE_PRESENTER(obj) \
|
|
|
|
INTERFACE_CHECK(XivePresenter, (obj), TYPE_XIVE_PRESENTER)
|
2020-09-03 23:43:22 +03:00
|
|
|
typedef struct XivePresenterClass XivePresenterClass;
|
2020-09-01 00:07:33 +03:00
|
|
|
DECLARE_CLASS_CHECKERS(XivePresenterClass, XIVE_PRESENTER,
|
|
|
|
TYPE_XIVE_PRESENTER)
|
2019-11-25 09:58:01 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct XivePresenterClass {
|
2019-11-25 09:58:01 +03:00
|
|
|
InterfaceClass parent;
|
|
|
|
int (*match_nvt)(XivePresenter *xptr, uint8_t format,
|
|
|
|
uint8_t nvt_blk, uint32_t nvt_idx,
|
|
|
|
bool cam_ignore, uint8_t priority,
|
|
|
|
uint32_t logic_serv, XiveTCTXMatch *match);
|
2020-08-07 14:32:14 +03:00
|
|
|
bool (*in_kernel)(const XivePresenter *xptr);
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2019-11-25 09:58:01 +03:00
|
|
|
|
|
|
|
int xive_presenter_tctx_match(XivePresenter *xptr, XiveTCTX *tctx,
|
|
|
|
uint8_t format,
|
|
|
|
uint8_t nvt_blk, uint32_t nvt_idx,
|
|
|
|
bool cam_ignore, uint32_t logic_serv);
|
2021-08-09 16:45:29 +03:00
|
|
|
bool xive_presenter_notify(XiveFabric *xfb, uint8_t format,
|
|
|
|
uint8_t nvt_blk, uint32_t nvt_idx,
|
|
|
|
bool cam_ignore, uint8_t priority,
|
|
|
|
uint32_t logic_serv);
|
2019-11-25 09:58:01 +03:00
|
|
|
|
2019-11-25 09:58:08 +03:00
|
|
|
/*
|
|
|
|
* XIVE Fabric (Interface between Interrupt Controller and Machine)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define TYPE_XIVE_FABRIC "xive-fabric"
|
|
|
|
#define XIVE_FABRIC(obj) \
|
|
|
|
INTERFACE_CHECK(XiveFabric, (obj), TYPE_XIVE_FABRIC)
|
2020-09-03 23:43:22 +03:00
|
|
|
typedef struct XiveFabricClass XiveFabricClass;
|
2020-09-01 00:07:33 +03:00
|
|
|
DECLARE_CLASS_CHECKERS(XiveFabricClass, XIVE_FABRIC,
|
|
|
|
TYPE_XIVE_FABRIC)
|
2019-11-25 09:58:08 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct XiveFabricClass {
|
2019-11-25 09:58:08 +03:00
|
|
|
InterfaceClass parent;
|
|
|
|
int (*match_nvt)(XiveFabric *xfb, uint8_t format,
|
|
|
|
uint8_t nvt_blk, uint32_t nvt_idx,
|
|
|
|
bool cam_ignore, uint8_t priority,
|
|
|
|
uint32_t logic_serv, XiveTCTXMatch *match);
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2019-11-25 09:58:08 +03:00
|
|
|
|
2018-12-09 22:45:52 +03:00
|
|
|
/*
|
|
|
|
* XIVE END ESBs
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define TYPE_XIVE_END_SOURCE "xive-end-source"
|
2020-09-16 21:25:19 +03:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(XiveENDSource, XIVE_END_SOURCE)
|
2018-12-09 22:45:52 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct XiveENDSource {
|
2018-12-09 22:45:52 +03:00
|
|
|
DeviceState parent;
|
|
|
|
|
|
|
|
uint32_t nr_ends;
|
|
|
|
|
|
|
|
/* ESB memory region */
|
|
|
|
uint32_t esb_shift;
|
|
|
|
MemoryRegion esb_mmio;
|
|
|
|
|
|
|
|
XiveRouter *xrtr;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2018-12-09 22:45:52 +03:00
|
|
|
|
2018-12-06 02:22:19 +03:00
|
|
|
/*
|
|
|
|
* For legacy compatibility, the exceptions define up to 256 different
|
|
|
|
* priorities. P9 implements only 9 levels : 8 active levels [0 - 7]
|
|
|
|
* and the least favored level 0xFF.
|
|
|
|
*/
|
|
|
|
#define XIVE_PRIORITY_MAX 7
|
|
|
|
|
2021-09-01 12:41:51 +03:00
|
|
|
/*
|
|
|
|
* Convert a priority number to an Interrupt Pending Buffer (IPB)
|
|
|
|
* register, which indicates a pending interrupt at the priority
|
|
|
|
* corresponding to the bit number
|
|
|
|
*/
|
|
|
|
static inline uint8_t xive_priority_to_ipb(uint8_t priority)
|
|
|
|
{
|
|
|
|
return priority > XIVE_PRIORITY_MAX ?
|
|
|
|
0 : 1 << (XIVE_PRIORITY_MAX - priority);
|
|
|
|
}
|
|
|
|
|
2018-12-09 22:45:53 +03:00
|
|
|
/*
|
|
|
|
* XIVE Thread Interrupt Management Aera (TIMA)
|
|
|
|
*
|
|
|
|
* This region gives access to the registers of the thread interrupt
|
|
|
|
* management context. It is four page wide, each page providing a
|
|
|
|
* different view of the registers. The page with the lower offset is
|
|
|
|
* the most privileged and gives access to the entire context.
|
|
|
|
*/
|
|
|
|
#define XIVE_TM_HW_PAGE 0x0
|
|
|
|
#define XIVE_TM_HV_PAGE 0x1
|
|
|
|
#define XIVE_TM_OS_PAGE 0x2
|
|
|
|
#define XIVE_TM_USER_PAGE 0x3
|
|
|
|
|
2019-11-25 09:58:12 +03:00
|
|
|
void xive_tctx_tm_write(XivePresenter *xptr, XiveTCTX *tctx, hwaddr offset,
|
|
|
|
uint64_t value, unsigned size);
|
|
|
|
uint64_t xive_tctx_tm_read(XivePresenter *xptr, XiveTCTX *tctx, hwaddr offset,
|
|
|
|
unsigned size);
|
2018-12-09 22:45:53 +03:00
|
|
|
|
|
|
|
void xive_tctx_pic_print_info(XiveTCTX *tctx, Monitor *mon);
|
2020-01-06 17:56:41 +03:00
|
|
|
Object *xive_tctx_create(Object *cpu, XivePresenter *xptr, Error **errp);
|
2019-10-22 19:38:10 +03:00
|
|
|
void xive_tctx_reset(XiveTCTX *tctx);
|
2019-10-24 17:27:22 +03:00
|
|
|
void xive_tctx_destroy(XiveTCTX *tctx);
|
2019-11-25 09:58:16 +03:00
|
|
|
void xive_tctx_ipb_update(XiveTCTX *tctx, uint8_t ring, uint8_t ipb);
|
ppc/xive: Update the state of the External interrupt signal
When pulling or pushing an OS context from/to a CPU, we should
re-evaluate the state of the External interrupt signal. Otherwise, we
can end up catching the External interrupt exception in hypervisor
mode, which is unexpected.
The problem is best illustrated with the following scenario:
1. an External interrupt is raised while the guest is on the CPU.
2. before the guest can ack the External interrupt, an hypervisor
interrupt is raised, for example the Hypervisor Decrementer or
Hypervisor Virtualization interrupt. The hypervisor interrupt forces
the guest to exit while the External interrupt is still pending.
3. the hypervisor handles the hypervisor interrupt. At this point, the
External interrupt is still pending. So it's very likely to be
delivered while the hypervisor is running. That's unexpected and can
result in an infinite loop where the hypervisor catches the External
interrupt, looks for an interrupt in its hypervisor queue, doesn't
find any, exits the interrupt handler with the External interrupt
still raised, repeat...
The fix is simply to always lower the External interrupt signal when
pulling an OS context. It means it needs to be raised again when
re-pushing the OS context. Fortunately, it's already the case, as we
now always call xive_tctx_ipb_update(), which will raise the signal if
needed.
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com>
Message-Id: <20220429071620.177142-3-fbarrat@linux.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-04-29 10:16:20 +03:00
|
|
|
void xive_tctx_reset_os_signal(XiveTCTX *tctx);
|
2018-12-09 22:45:53 +03:00
|
|
|
|
2019-05-13 11:42:33 +03:00
|
|
|
/*
|
|
|
|
* KVM XIVE device helpers
|
|
|
|
*/
|
|
|
|
|
2019-09-25 06:24:14 +03:00
|
|
|
int kvmppc_xive_source_reset_one(XiveSource *xsrc, int srcno, Error **errp);
|
2019-05-13 11:42:33 +03:00
|
|
|
void kvmppc_xive_source_set_irq(void *opaque, int srcno, int val);
|
2020-08-10 19:54:05 +03:00
|
|
|
int kvmppc_xive_cpu_connect(XiveTCTX *tctx, Error **errp);
|
2020-08-10 19:55:29 +03:00
|
|
|
int kvmppc_xive_cpu_synchronize_state(XiveTCTX *tctx, Error **errp);
|
2020-08-10 19:54:26 +03:00
|
|
|
int kvmppc_xive_cpu_get_state(XiveTCTX *tctx, Error **errp);
|
|
|
|
int kvmppc_xive_cpu_set_state(XiveTCTX *tctx, Error **errp);
|
2019-05-13 11:42:33 +03:00
|
|
|
|
2018-12-06 02:22:15 +03:00
|
|
|
#endif /* PPC_XIVE_H */
|