154f59d78SCédric Le Goater /*
254f59d78SCédric Le Goater * QEMU PowerPC PowerNV Processor Service Interface (PSI) model
354f59d78SCédric Le Goater *
454f59d78SCédric Le Goater * Copyright (c) 2015-2017, IBM Corporation.
554f59d78SCédric Le Goater *
654f59d78SCédric Le Goater * This library is free software; you can redistribute it and/or
754f59d78SCédric Le Goater * modify it under the terms of the GNU Lesser General Public
854f59d78SCédric Le Goater * License as published by the Free Software Foundation; either
9f70c5966SChetan Pant * version 2.1 of the License, or (at your option) any later version.
1054f59d78SCédric Le Goater *
1154f59d78SCédric Le Goater * This library is distributed in the hope that it will be useful,
1254f59d78SCédric Le Goater * but WITHOUT ANY WARRANTY; without even the implied warranty of
1354f59d78SCédric Le Goater * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1454f59d78SCédric Le Goater * Lesser General Public License for more details.
1554f59d78SCédric Le Goater *
1654f59d78SCédric Le Goater * You should have received a copy of the GNU Lesser General Public
1754f59d78SCédric Le Goater * License along with this library; if not, see <http://www.gnu.org/licenses/>.
1854f59d78SCédric Le Goater */
1954f59d78SCédric Le Goater
2054f59d78SCédric Le Goater #include "qemu/osdep.h"
21c0a5a477SMarkus Armbruster #include "exec/address-spaces.h"
2264552b6bSMarkus Armbruster #include "hw/irq.h"
2354f59d78SCédric Le Goater #include "target/ppc/cpu.h"
2454f59d78SCédric Le Goater #include "qemu/log.h"
250b8fa32fSMarkus Armbruster #include "qemu/module.h"
2671e8a915SMarkus Armbruster #include "sysemu/reset.h"
2754f59d78SCédric Le Goater #include "qapi/error.h"
28c38536bcSCédric Le Goater #include "monitor/monitor.h"
2954f59d78SCédric Le Goater
3054f59d78SCédric Le Goater
3154f59d78SCédric Le Goater #include "hw/ppc/fdt.h"
3254f59d78SCédric Le Goater #include "hw/ppc/pnv.h"
3354f59d78SCédric Le Goater #include "hw/ppc/pnv_xscom.h"
34a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
3554f59d78SCédric Le Goater #include "hw/ppc/pnv_psi.h"
3654f59d78SCédric Le Goater
3754f59d78SCédric Le Goater #include <libfdt.h>
3854f59d78SCédric Le Goater
3954f59d78SCédric Le Goater #define PSIHB_XSCOM_FIR_RW 0x00
4054f59d78SCédric Le Goater #define PSIHB_XSCOM_FIR_AND 0x01
4154f59d78SCédric Le Goater #define PSIHB_XSCOM_FIR_OR 0x02
4254f59d78SCédric Le Goater #define PSIHB_XSCOM_FIRMASK_RW 0x03
4354f59d78SCédric Le Goater #define PSIHB_XSCOM_FIRMASK_AND 0x04
4454f59d78SCédric Le Goater #define PSIHB_XSCOM_FIRMASK_OR 0x05
4554f59d78SCédric Le Goater #define PSIHB_XSCOM_FIRACT0 0x06
4654f59d78SCédric Le Goater #define PSIHB_XSCOM_FIRACT1 0x07
4754f59d78SCédric Le Goater
4854f59d78SCédric Le Goater /* Host Bridge Base Address Register */
4954f59d78SCédric Le Goater #define PSIHB_XSCOM_BAR 0x0a
5054f59d78SCédric Le Goater #define PSIHB_BAR_EN 0x0000000000000001ull
5154f59d78SCédric Le Goater
5254f59d78SCédric Le Goater /* FSP Base Address Register */
5354f59d78SCédric Le Goater #define PSIHB_XSCOM_FSPBAR 0x0b
5454f59d78SCédric Le Goater
5554f59d78SCédric Le Goater /* PSI Host Bridge Control/Status Register */
5654f59d78SCédric Le Goater #define PSIHB_XSCOM_CR 0x0e
5754f59d78SCédric Le Goater #define PSIHB_CR_FSP_CMD_ENABLE 0x8000000000000000ull
5854f59d78SCédric Le Goater #define PSIHB_CR_FSP_MMIO_ENABLE 0x4000000000000000ull
5954f59d78SCédric Le Goater #define PSIHB_CR_FSP_IRQ_ENABLE 0x1000000000000000ull
6054f59d78SCédric Le Goater #define PSIHB_CR_FSP_ERR_RSP_ENABLE 0x0800000000000000ull
6154f59d78SCédric Le Goater #define PSIHB_CR_PSI_LINK_ENABLE 0x0400000000000000ull
6254f59d78SCédric Le Goater #define PSIHB_CR_FSP_RESET 0x0200000000000000ull
6354f59d78SCédric Le Goater #define PSIHB_CR_PSIHB_RESET 0x0100000000000000ull
6454f59d78SCédric Le Goater #define PSIHB_CR_PSI_IRQ 0x0000800000000000ull
6554f59d78SCédric Le Goater #define PSIHB_CR_FSP_IRQ 0x0000400000000000ull
6654f59d78SCédric Le Goater #define PSIHB_CR_FSP_LINK_ACTIVE 0x0000200000000000ull
6754f59d78SCédric Le Goater #define PSIHB_CR_IRQ_CMD_EXPECT 0x0000010000000000ull
6854f59d78SCédric Le Goater /* and more ... */
6954f59d78SCédric Le Goater
7054f59d78SCédric Le Goater /* PSIHB Status / Error Mask Register */
7154f59d78SCédric Le Goater #define PSIHB_XSCOM_SEMR 0x0f
7254f59d78SCédric Le Goater
7354f59d78SCédric Le Goater /* XIVR, to signal interrupts to the CEC firmware. more XIVR below. */
7454f59d78SCédric Le Goater #define PSIHB_XSCOM_XIVR_FSP 0x10
7554f59d78SCédric Le Goater #define PSIHB_XIVR_SERVER_SH 40
7654f59d78SCédric Le Goater #define PSIHB_XIVR_SERVER_MSK (0xffffull << PSIHB_XIVR_SERVER_SH)
7754f59d78SCédric Le Goater #define PSIHB_XIVR_PRIO_SH 32
7854f59d78SCédric Le Goater #define PSIHB_XIVR_PRIO_MSK (0xffull << PSIHB_XIVR_PRIO_SH)
7954f59d78SCédric Le Goater #define PSIHB_XIVR_SRC_SH 29
8054f59d78SCédric Le Goater #define PSIHB_XIVR_SRC_MSK (0x7ull << PSIHB_XIVR_SRC_SH)
8154f59d78SCédric Le Goater #define PSIHB_XIVR_PENDING 0x01000000ull
8254f59d78SCédric Le Goater
8354f59d78SCédric Le Goater /* PSI Host Bridge Set Control/ Status Register */
8454f59d78SCédric Le Goater #define PSIHB_XSCOM_SCR 0x12
8554f59d78SCédric Le Goater
8654f59d78SCédric Le Goater /* PSI Host Bridge Clear Control/ Status Register */
8754f59d78SCédric Le Goater #define PSIHB_XSCOM_CCR 0x13
8854f59d78SCédric Le Goater
8954f59d78SCédric Le Goater /* DMA Upper Address Register */
9054f59d78SCédric Le Goater #define PSIHB_XSCOM_DMA_UPADD 0x14
9154f59d78SCédric Le Goater
9254f59d78SCédric Le Goater /* Interrupt Status */
9354f59d78SCédric Le Goater #define PSIHB_XSCOM_IRQ_STAT 0x15
9454f59d78SCédric Le Goater #define PSIHB_IRQ_STAT_OCC 0x0000001000000000ull
9554f59d78SCédric Le Goater #define PSIHB_IRQ_STAT_FSI 0x0000000800000000ull
9654f59d78SCédric Le Goater #define PSIHB_IRQ_STAT_LPCI2C 0x0000000400000000ull
9754f59d78SCédric Le Goater #define PSIHB_IRQ_STAT_LOCERR 0x0000000200000000ull
9854f59d78SCédric Le Goater #define PSIHB_IRQ_STAT_EXT 0x0000000100000000ull
9954f59d78SCédric Le Goater
10054f59d78SCédric Le Goater /* remaining XIVR */
10154f59d78SCédric Le Goater #define PSIHB_XSCOM_XIVR_OCC 0x16
10254f59d78SCédric Le Goater #define PSIHB_XSCOM_XIVR_FSI 0x17
10354f59d78SCédric Le Goater #define PSIHB_XSCOM_XIVR_LPCI2C 0x18
10454f59d78SCédric Le Goater #define PSIHB_XSCOM_XIVR_LOCERR 0x19
10554f59d78SCédric Le Goater #define PSIHB_XSCOM_XIVR_EXT 0x1a
10654f59d78SCédric Le Goater
10754f59d78SCédric Le Goater /* Interrupt Requester Source Compare Register */
10854f59d78SCédric Le Goater #define PSIHB_XSCOM_IRSN 0x1b
10954f59d78SCédric Le Goater #define PSIHB_IRSN_COMP_SH 45
11054f59d78SCédric Le Goater #define PSIHB_IRSN_COMP_MSK (0x7ffffull << PSIHB_IRSN_COMP_SH)
11154f59d78SCédric Le Goater #define PSIHB_IRSN_IRQ_MUX 0x0000000800000000ull
11254f59d78SCédric Le Goater #define PSIHB_IRSN_IRQ_RESET 0x0000000400000000ull
11354f59d78SCédric Le Goater #define PSIHB_IRSN_DOWNSTREAM_EN 0x0000000200000000ull
11454f59d78SCédric Le Goater #define PSIHB_IRSN_UPSTREAM_EN 0x0000000100000000ull
11554f59d78SCédric Le Goater #define PSIHB_IRSN_COMPMASK_SH 13
11654f59d78SCédric Le Goater #define PSIHB_IRSN_COMPMASK_MSK (0x7ffffull << PSIHB_IRSN_COMPMASK_SH)
11754f59d78SCédric Le Goater
11854f59d78SCédric Le Goater #define PSIHB_BAR_MASK 0x0003fffffff00000ull
11954f59d78SCédric Le Goater #define PSIHB_FSPBAR_MASK 0x0003ffff00000000ull
12054f59d78SCédric Le Goater
121c38536bcSCédric Le Goater #define PSIHB9_BAR_MASK 0x00fffffffff00000ull
122c38536bcSCédric Le Goater #define PSIHB9_FSPBAR_MASK 0x00ffffff00000000ull
123c38536bcSCédric Le Goater
124b5ea6754SFrederic Barrat /* mmio address to xscom address */
125029699aaSCédric Le Goater #define PSIHB_REG(addr) (((addr) >> 3) + PSIHB_XSCOM_BAR)
126029699aaSCédric Le Goater
127b5ea6754SFrederic Barrat /* xscom address to mmio address */
128b5ea6754SFrederic Barrat #define PSIHB_MMIO(reg) ((reg - PSIHB_XSCOM_BAR) << 3)
129b5ea6754SFrederic Barrat
pnv_psi_set_bar(PnvPsi * psi,uint64_t bar)13054f59d78SCédric Le Goater static void pnv_psi_set_bar(PnvPsi *psi, uint64_t bar)
13154f59d78SCédric Le Goater {
132ae856055SCédric Le Goater PnvPsiClass *ppc = PNV_PSI_GET_CLASS(psi);
13354f59d78SCédric Le Goater MemoryRegion *sysmem = get_system_memory();
13454f59d78SCédric Le Goater uint64_t old = psi->regs[PSIHB_XSCOM_BAR];
13554f59d78SCédric Le Goater
136ae856055SCédric Le Goater psi->regs[PSIHB_XSCOM_BAR] = bar & (ppc->bar_mask | PSIHB_BAR_EN);
13754f59d78SCédric Le Goater
13854f59d78SCédric Le Goater /* Update MR, always remove it first */
13954f59d78SCédric Le Goater if (old & PSIHB_BAR_EN) {
14054f59d78SCédric Le Goater memory_region_del_subregion(sysmem, &psi->regs_mr);
14154f59d78SCédric Le Goater }
14254f59d78SCédric Le Goater
14354f59d78SCédric Le Goater /* Then add it back if needed */
14454f59d78SCédric Le Goater if (bar & PSIHB_BAR_EN) {
145ae856055SCédric Le Goater uint64_t addr = bar & ppc->bar_mask;
14654f59d78SCédric Le Goater memory_region_add_subregion(sysmem, addr, &psi->regs_mr);
14754f59d78SCédric Le Goater }
14854f59d78SCédric Le Goater }
14954f59d78SCédric Le Goater
pnv_psi_update_fsp_mr(PnvPsi * psi)15054f59d78SCédric Le Goater static void pnv_psi_update_fsp_mr(PnvPsi *psi)
15154f59d78SCédric Le Goater {
15254f59d78SCédric Le Goater /* TODO: Update FSP MR if/when we support FSP BAR */
15354f59d78SCédric Le Goater }
15454f59d78SCédric Le Goater
pnv_psi_set_cr(PnvPsi * psi,uint64_t cr)15554f59d78SCédric Le Goater static void pnv_psi_set_cr(PnvPsi *psi, uint64_t cr)
15654f59d78SCédric Le Goater {
15754f59d78SCédric Le Goater uint64_t old = psi->regs[PSIHB_XSCOM_CR];
15854f59d78SCédric Le Goater
15954f59d78SCédric Le Goater psi->regs[PSIHB_XSCOM_CR] = cr;
16054f59d78SCédric Le Goater
16154f59d78SCédric Le Goater /* Check some bit changes */
16254f59d78SCédric Le Goater if ((old ^ psi->regs[PSIHB_XSCOM_CR]) & PSIHB_CR_FSP_MMIO_ENABLE) {
16354f59d78SCédric Le Goater pnv_psi_update_fsp_mr(psi);
16454f59d78SCédric Le Goater }
16554f59d78SCédric Le Goater }
16654f59d78SCédric Le Goater
pnv_psi_set_irsn(PnvPsi * psi,uint64_t val)16754f59d78SCédric Le Goater static void pnv_psi_set_irsn(PnvPsi *psi, uint64_t val)
16854f59d78SCédric Le Goater {
169ae856055SCédric Le Goater ICSState *ics = &PNV8_PSI(psi)->ics;
17054f59d78SCédric Le Goater
17154f59d78SCédric Le Goater /* In this model we ignore the up/down enable bits for now
17254f59d78SCédric Le Goater * as SW doesn't use them (other than setting them at boot).
17354f59d78SCédric Le Goater * We ignore IRQ_MUX, its meaning isn't clear and we don't use
17454f59d78SCédric Le Goater * it and finally we ignore reset (XXX fix that ?)
17554f59d78SCédric Le Goater */
17654f59d78SCédric Le Goater psi->regs[PSIHB_XSCOM_IRSN] = val & (PSIHB_IRSN_COMP_MSK |
17754f59d78SCédric Le Goater PSIHB_IRSN_IRQ_MUX |
17854f59d78SCédric Le Goater PSIHB_IRSN_IRQ_RESET |
17954f59d78SCédric Le Goater PSIHB_IRSN_DOWNSTREAM_EN |
18054f59d78SCédric Le Goater PSIHB_IRSN_UPSTREAM_EN);
18154f59d78SCédric Le Goater
18254f59d78SCédric Le Goater /* We ignore the compare mask as well, our ICS emulation is too
18354f59d78SCédric Le Goater * simplistic to make any use if it, and we extract the offset
18454f59d78SCédric Le Goater * from the compare value
18554f59d78SCédric Le Goater */
18654f59d78SCédric Le Goater ics->offset = (val & PSIHB_IRSN_COMP_MSK) >> PSIHB_IRSN_COMP_SH;
18754f59d78SCédric Le Goater }
18854f59d78SCédric Le Goater
18954f59d78SCédric Le Goater /*
19054f59d78SCédric Le Goater * FSP and PSI interrupts are muxed under the same number.
19154f59d78SCédric Le Goater */
19258858759SCédric Le Goater static const uint32_t xivr_regs[PSI_NUM_INTERRUPTS] = {
19354f59d78SCédric Le Goater [PSIHB_IRQ_FSP] = PSIHB_XSCOM_XIVR_FSP,
19454f59d78SCédric Le Goater [PSIHB_IRQ_OCC] = PSIHB_XSCOM_XIVR_OCC,
19554f59d78SCédric Le Goater [PSIHB_IRQ_FSI] = PSIHB_XSCOM_XIVR_FSI,
19654f59d78SCédric Le Goater [PSIHB_IRQ_LPC_I2C] = PSIHB_XSCOM_XIVR_LPCI2C,
19754f59d78SCédric Le Goater [PSIHB_IRQ_LOCAL_ERR] = PSIHB_XSCOM_XIVR_LOCERR,
19854f59d78SCédric Le Goater [PSIHB_IRQ_EXTERNAL] = PSIHB_XSCOM_XIVR_EXT,
19954f59d78SCédric Le Goater };
20054f59d78SCédric Le Goater
20158858759SCédric Le Goater static const uint32_t stat_regs[PSI_NUM_INTERRUPTS] = {
20254f59d78SCédric Le Goater [PSIHB_IRQ_FSP] = PSIHB_XSCOM_CR,
20354f59d78SCédric Le Goater [PSIHB_IRQ_OCC] = PSIHB_XSCOM_IRQ_STAT,
20454f59d78SCédric Le Goater [PSIHB_IRQ_FSI] = PSIHB_XSCOM_IRQ_STAT,
20554f59d78SCédric Le Goater [PSIHB_IRQ_LPC_I2C] = PSIHB_XSCOM_IRQ_STAT,
20654f59d78SCédric Le Goater [PSIHB_IRQ_LOCAL_ERR] = PSIHB_XSCOM_IRQ_STAT,
20754f59d78SCédric Le Goater [PSIHB_IRQ_EXTERNAL] = PSIHB_XSCOM_IRQ_STAT,
20854f59d78SCédric Le Goater };
20954f59d78SCédric Le Goater
21058858759SCédric Le Goater static const uint64_t stat_bits[PSI_NUM_INTERRUPTS] = {
21154f59d78SCédric Le Goater [PSIHB_IRQ_FSP] = PSIHB_CR_FSP_IRQ,
21254f59d78SCédric Le Goater [PSIHB_IRQ_OCC] = PSIHB_IRQ_STAT_OCC,
21354f59d78SCédric Le Goater [PSIHB_IRQ_FSI] = PSIHB_IRQ_STAT_FSI,
21454f59d78SCédric Le Goater [PSIHB_IRQ_LPC_I2C] = PSIHB_IRQ_STAT_LPCI2C,
21554f59d78SCédric Le Goater [PSIHB_IRQ_LOCAL_ERR] = PSIHB_IRQ_STAT_LOCERR,
21654f59d78SCédric Le Goater [PSIHB_IRQ_EXTERNAL] = PSIHB_IRQ_STAT_EXT,
21754f59d78SCédric Le Goater };
21854f59d78SCédric Le Goater
pnv_psi_power8_set_irq(void * opaque,int irq,int state)219dcf4ca45SCédric Le Goater static void pnv_psi_power8_set_irq(void *opaque, int irq, int state)
220ae856055SCédric Le Goater {
221dcf4ca45SCédric Le Goater PnvPsi *psi = opaque;
22254f59d78SCédric Le Goater uint32_t xivr_reg;
22354f59d78SCédric Le Goater uint32_t stat_reg;
22454f59d78SCédric Le Goater uint32_t src;
22554f59d78SCédric Le Goater bool masked;
22654f59d78SCédric Le Goater
22754f59d78SCédric Le Goater xivr_reg = xivr_regs[irq];
22854f59d78SCédric Le Goater stat_reg = stat_regs[irq];
22954f59d78SCédric Le Goater
23054f59d78SCédric Le Goater src = (psi->regs[xivr_reg] & PSIHB_XIVR_SRC_MSK) >> PSIHB_XIVR_SRC_SH;
23154f59d78SCédric Le Goater if (state) {
23254f59d78SCédric Le Goater psi->regs[stat_reg] |= stat_bits[irq];
23354f59d78SCédric Le Goater /* TODO: optimization, check mask here. That means
23454f59d78SCédric Le Goater * re-evaluating when unmasking
23554f59d78SCédric Le Goater */
236f8df9003SCédric Le Goater qemu_irq_raise(psi->qirqs[src]);
23754f59d78SCédric Le Goater } else {
23854f59d78SCédric Le Goater psi->regs[stat_reg] &= ~stat_bits[irq];
23954f59d78SCédric Le Goater
24054f59d78SCédric Le Goater /* FSP and PSI are muxed so don't lower if either is still set */
24154f59d78SCédric Le Goater if (stat_reg != PSIHB_XSCOM_CR ||
24254f59d78SCédric Le Goater !(psi->regs[stat_reg] & (PSIHB_CR_PSI_IRQ | PSIHB_CR_FSP_IRQ))) {
243f8df9003SCédric Le Goater qemu_irq_lower(psi->qirqs[src]);
24454f59d78SCédric Le Goater } else {
24554f59d78SCédric Le Goater state = true;
24654f59d78SCédric Le Goater }
24754f59d78SCédric Le Goater }
24854f59d78SCédric Le Goater
24954f59d78SCédric Le Goater /* Note about the emulation of the pending bit: This isn't
25054f59d78SCédric Le Goater * entirely correct. The pending bit should be cleared when the
25154f59d78SCédric Le Goater * EOI has been received. However, we don't have callbacks on EOI
25254f59d78SCédric Le Goater * (especially not under KVM) so no way to emulate that properly,
25354f59d78SCédric Le Goater * so instead we just set that bit as the logical "output" of the
25454f59d78SCédric Le Goater * XIVR (ie pending & !masked)
25554f59d78SCédric Le Goater *
25654f59d78SCédric Le Goater * CLG: We could define a new ICS object with a custom eoi()
25754f59d78SCédric Le Goater * handler to clear the pending bit. But I am not sure this would
25854f59d78SCédric Le Goater * be useful for the software anyhow.
25954f59d78SCédric Le Goater */
26054f59d78SCédric Le Goater masked = (psi->regs[xivr_reg] & PSIHB_XIVR_PRIO_MSK) == PSIHB_XIVR_PRIO_MSK;
26154f59d78SCédric Le Goater if (state && !masked) {
26254f59d78SCédric Le Goater psi->regs[xivr_reg] |= PSIHB_XIVR_PENDING;
26354f59d78SCédric Le Goater } else {
26454f59d78SCédric Le Goater psi->regs[xivr_reg] &= ~PSIHB_XIVR_PENDING;
26554f59d78SCédric Le Goater }
26654f59d78SCédric Le Goater }
26754f59d78SCédric Le Goater
pnv_psi_set_xivr(PnvPsi * psi,uint32_t reg,uint64_t val)26854f59d78SCédric Le Goater static void pnv_psi_set_xivr(PnvPsi *psi, uint32_t reg, uint64_t val)
26954f59d78SCédric Le Goater {
270ae856055SCédric Le Goater ICSState *ics = &PNV8_PSI(psi)->ics;
27154f59d78SCédric Le Goater uint16_t server;
27254f59d78SCédric Le Goater uint8_t prio;
27354f59d78SCédric Le Goater uint8_t src;
27454f59d78SCédric Le Goater
27554f59d78SCédric Le Goater psi->regs[reg] = (psi->regs[reg] & PSIHB_XIVR_PENDING) |
27654f59d78SCédric Le Goater (val & (PSIHB_XIVR_SERVER_MSK |
27754f59d78SCédric Le Goater PSIHB_XIVR_PRIO_MSK |
27854f59d78SCédric Le Goater PSIHB_XIVR_SRC_MSK));
27954f59d78SCédric Le Goater val = psi->regs[reg];
28054f59d78SCédric Le Goater server = (val & PSIHB_XIVR_SERVER_MSK) >> PSIHB_XIVR_SERVER_SH;
28154f59d78SCédric Le Goater prio = (val & PSIHB_XIVR_PRIO_MSK) >> PSIHB_XIVR_PRIO_SH;
28254f59d78SCédric Le Goater src = (val & PSIHB_XIVR_SRC_MSK) >> PSIHB_XIVR_SRC_SH;
28354f59d78SCédric Le Goater
28454f59d78SCédric Le Goater if (src >= PSI_NUM_INTERRUPTS) {
28554f59d78SCédric Le Goater qemu_log_mask(LOG_GUEST_ERROR, "PSI: Unsupported irq %d\n", src);
28654f59d78SCédric Le Goater return;
28754f59d78SCédric Le Goater }
28854f59d78SCédric Le Goater
28954f59d78SCédric Le Goater /* Remove pending bit if the IRQ is masked */
29054f59d78SCédric Le Goater if ((psi->regs[reg] & PSIHB_XIVR_PRIO_MSK) == PSIHB_XIVR_PRIO_MSK) {
29154f59d78SCédric Le Goater psi->regs[reg] &= ~PSIHB_XIVR_PENDING;
29254f59d78SCédric Le Goater }
29354f59d78SCédric Le Goater
29454f59d78SCédric Le Goater /* The low order 2 bits are the link pointer (Type II interrupts).
29554f59d78SCédric Le Goater * Shift back to get a valid IRQ server.
29654f59d78SCédric Le Goater */
29754f59d78SCédric Le Goater server >>= 2;
29854f59d78SCédric Le Goater
29954f59d78SCédric Le Goater /* Now because of source remapping, weird things can happen
30054f59d78SCédric Le Goater * if you change the source number dynamically, our simple ICS
30154f59d78SCédric Le Goater * doesn't deal with remapping. So we just poke a different
30254f59d78SCédric Le Goater * ICS entry based on what source number was written. This will
30354f59d78SCédric Le Goater * do for now but a more accurate implementation would instead
30454f59d78SCédric Le Goater * use a fixed server/prio and a remapper of the generated irq.
30554f59d78SCédric Le Goater */
30628976c99SDavid Gibson ics_write_xive(ics, src, server, prio, prio);
30754f59d78SCédric Le Goater }
30854f59d78SCédric Le Goater
pnv_psi_reg_read(PnvPsi * psi,uint32_t offset,bool mmio)30954f59d78SCédric Le Goater static uint64_t pnv_psi_reg_read(PnvPsi *psi, uint32_t offset, bool mmio)
31054f59d78SCédric Le Goater {
31154f59d78SCédric Le Goater uint64_t val = 0xffffffffffffffffull;
31254f59d78SCédric Le Goater
31354f59d78SCédric Le Goater switch (offset) {
31454f59d78SCédric Le Goater case PSIHB_XSCOM_FIR_RW:
31554f59d78SCédric Le Goater case PSIHB_XSCOM_FIRACT0:
31654f59d78SCédric Le Goater case PSIHB_XSCOM_FIRACT1:
31754f59d78SCédric Le Goater case PSIHB_XSCOM_BAR:
31854f59d78SCédric Le Goater case PSIHB_XSCOM_FSPBAR:
31954f59d78SCédric Le Goater case PSIHB_XSCOM_CR:
32054f59d78SCédric Le Goater case PSIHB_XSCOM_XIVR_FSP:
32154f59d78SCédric Le Goater case PSIHB_XSCOM_XIVR_OCC:
32254f59d78SCédric Le Goater case PSIHB_XSCOM_XIVR_FSI:
32354f59d78SCédric Le Goater case PSIHB_XSCOM_XIVR_LPCI2C:
32454f59d78SCédric Le Goater case PSIHB_XSCOM_XIVR_LOCERR:
32554f59d78SCédric Le Goater case PSIHB_XSCOM_XIVR_EXT:
32654f59d78SCédric Le Goater case PSIHB_XSCOM_IRQ_STAT:
32754f59d78SCédric Le Goater case PSIHB_XSCOM_SEMR:
32854f59d78SCédric Le Goater case PSIHB_XSCOM_DMA_UPADD:
32954f59d78SCédric Le Goater case PSIHB_XSCOM_IRSN:
33054f59d78SCédric Le Goater val = psi->regs[offset];
33154f59d78SCédric Le Goater break;
33254f59d78SCédric Le Goater default:
333cdbaf8cdSCédric Le Goater qemu_log_mask(LOG_UNIMP, "PSI: read at 0x%" PRIx32 "\n", offset);
33454f59d78SCédric Le Goater }
33554f59d78SCédric Le Goater return val;
33654f59d78SCédric Le Goater }
33754f59d78SCédric Le Goater
pnv_psi_reg_write(PnvPsi * psi,uint32_t offset,uint64_t val,bool mmio)33854f59d78SCédric Le Goater static void pnv_psi_reg_write(PnvPsi *psi, uint32_t offset, uint64_t val,
33954f59d78SCédric Le Goater bool mmio)
34054f59d78SCédric Le Goater {
34154f59d78SCédric Le Goater switch (offset) {
34254f59d78SCédric Le Goater case PSIHB_XSCOM_FIR_RW:
34354f59d78SCédric Le Goater case PSIHB_XSCOM_FIRACT0:
34454f59d78SCédric Le Goater case PSIHB_XSCOM_FIRACT1:
34554f59d78SCédric Le Goater case PSIHB_XSCOM_SEMR:
34654f59d78SCédric Le Goater case PSIHB_XSCOM_DMA_UPADD:
34754f59d78SCédric Le Goater psi->regs[offset] = val;
34854f59d78SCédric Le Goater break;
34954f59d78SCédric Le Goater case PSIHB_XSCOM_FIR_OR:
35054f59d78SCédric Le Goater psi->regs[PSIHB_XSCOM_FIR_RW] |= val;
35154f59d78SCédric Le Goater break;
35254f59d78SCédric Le Goater case PSIHB_XSCOM_FIR_AND:
35354f59d78SCédric Le Goater psi->regs[PSIHB_XSCOM_FIR_RW] &= val;
35454f59d78SCédric Le Goater break;
35554f59d78SCédric Le Goater case PSIHB_XSCOM_BAR:
35654f59d78SCédric Le Goater /* Only XSCOM can write this one */
35754f59d78SCédric Le Goater if (!mmio) {
35854f59d78SCédric Le Goater pnv_psi_set_bar(psi, val);
35954f59d78SCédric Le Goater } else {
36054f59d78SCédric Le Goater qemu_log_mask(LOG_GUEST_ERROR, "PSI: invalid write of BAR\n");
36154f59d78SCédric Le Goater }
36254f59d78SCédric Le Goater break;
36354f59d78SCédric Le Goater case PSIHB_XSCOM_FSPBAR:
36454f59d78SCédric Le Goater psi->regs[PSIHB_XSCOM_FSPBAR] = val & PSIHB_FSPBAR_MASK;
36554f59d78SCédric Le Goater pnv_psi_update_fsp_mr(psi);
36654f59d78SCédric Le Goater break;
36754f59d78SCédric Le Goater case PSIHB_XSCOM_CR:
36854f59d78SCédric Le Goater pnv_psi_set_cr(psi, val);
36954f59d78SCédric Le Goater break;
37054f59d78SCédric Le Goater case PSIHB_XSCOM_SCR:
37154f59d78SCédric Le Goater pnv_psi_set_cr(psi, psi->regs[PSIHB_XSCOM_CR] | val);
37254f59d78SCédric Le Goater break;
37354f59d78SCédric Le Goater case PSIHB_XSCOM_CCR:
37454f59d78SCédric Le Goater pnv_psi_set_cr(psi, psi->regs[PSIHB_XSCOM_CR] & ~val);
37554f59d78SCédric Le Goater break;
37654f59d78SCédric Le Goater case PSIHB_XSCOM_XIVR_FSP:
37754f59d78SCédric Le Goater case PSIHB_XSCOM_XIVR_OCC:
37854f59d78SCédric Le Goater case PSIHB_XSCOM_XIVR_FSI:
37954f59d78SCédric Le Goater case PSIHB_XSCOM_XIVR_LPCI2C:
38054f59d78SCédric Le Goater case PSIHB_XSCOM_XIVR_LOCERR:
38154f59d78SCédric Le Goater case PSIHB_XSCOM_XIVR_EXT:
38254f59d78SCédric Le Goater pnv_psi_set_xivr(psi, offset, val);
38354f59d78SCédric Le Goater break;
38454f59d78SCédric Le Goater case PSIHB_XSCOM_IRQ_STAT:
38554f59d78SCédric Le Goater /* Read only */
38654f59d78SCédric Le Goater qemu_log_mask(LOG_GUEST_ERROR, "PSI: invalid write of IRQ_STAT\n");
38754f59d78SCédric Le Goater break;
38854f59d78SCédric Le Goater case PSIHB_XSCOM_IRSN:
38954f59d78SCédric Le Goater pnv_psi_set_irsn(psi, val);
39054f59d78SCédric Le Goater break;
39154f59d78SCédric Le Goater default:
392cdbaf8cdSCédric Le Goater qemu_log_mask(LOG_UNIMP, "PSI: write at 0x%" PRIx32 "\n", offset);
39354f59d78SCédric Le Goater }
39454f59d78SCédric Le Goater }
39554f59d78SCédric Le Goater
39654f59d78SCédric Le Goater /*
39754f59d78SCédric Le Goater * The values of the registers when accessed through the MMIO region
39854f59d78SCédric Le Goater * follow the relation : xscom = (mmio + 0x50) >> 3
39954f59d78SCédric Le Goater */
pnv_psi_mmio_read(void * opaque,hwaddr addr,unsigned size)40054f59d78SCédric Le Goater static uint64_t pnv_psi_mmio_read(void *opaque, hwaddr addr, unsigned size)
40154f59d78SCédric Le Goater {
402029699aaSCédric Le Goater return pnv_psi_reg_read(opaque, PSIHB_REG(addr), true);
40354f59d78SCédric Le Goater }
40454f59d78SCédric Le Goater
pnv_psi_mmio_write(void * opaque,hwaddr addr,uint64_t val,unsigned size)40554f59d78SCédric Le Goater static void pnv_psi_mmio_write(void *opaque, hwaddr addr,
40654f59d78SCédric Le Goater uint64_t val, unsigned size)
40754f59d78SCédric Le Goater {
408029699aaSCédric Le Goater pnv_psi_reg_write(opaque, PSIHB_REG(addr), val, true);
40954f59d78SCédric Le Goater }
41054f59d78SCédric Le Goater
41154f59d78SCédric Le Goater static const MemoryRegionOps psi_mmio_ops = {
41254f59d78SCédric Le Goater .read = pnv_psi_mmio_read,
41354f59d78SCédric Le Goater .write = pnv_psi_mmio_write,
41454f59d78SCédric Le Goater .endianness = DEVICE_BIG_ENDIAN,
41554f59d78SCédric Le Goater .valid = {
41654f59d78SCédric Le Goater .min_access_size = 8,
41754f59d78SCédric Le Goater .max_access_size = 8,
41854f59d78SCédric Le Goater },
41954f59d78SCédric Le Goater .impl = {
42054f59d78SCédric Le Goater .min_access_size = 8,
42154f59d78SCédric Le Goater .max_access_size = 8,
42254f59d78SCédric Le Goater },
42354f59d78SCédric Le Goater };
42454f59d78SCédric Le Goater
pnv_psi_xscom_read(void * opaque,hwaddr addr,unsigned size)42554f59d78SCédric Le Goater static uint64_t pnv_psi_xscom_read(void *opaque, hwaddr addr, unsigned size)
42654f59d78SCédric Le Goater {
42754f59d78SCédric Le Goater return pnv_psi_reg_read(opaque, addr >> 3, false);
42854f59d78SCédric Le Goater }
42954f59d78SCédric Le Goater
pnv_psi_xscom_write(void * opaque,hwaddr addr,uint64_t val,unsigned size)43054f59d78SCédric Le Goater static void pnv_psi_xscom_write(void *opaque, hwaddr addr,
43154f59d78SCédric Le Goater uint64_t val, unsigned size)
43254f59d78SCédric Le Goater {
43354f59d78SCédric Le Goater pnv_psi_reg_write(opaque, addr >> 3, val, false);
43454f59d78SCédric Le Goater }
43554f59d78SCédric Le Goater
43654f59d78SCédric Le Goater static const MemoryRegionOps pnv_psi_xscom_ops = {
43754f59d78SCédric Le Goater .read = pnv_psi_xscom_read,
43854f59d78SCédric Le Goater .write = pnv_psi_xscom_write,
43954f59d78SCédric Le Goater .endianness = DEVICE_BIG_ENDIAN,
44054f59d78SCédric Le Goater .valid = {
44154f59d78SCédric Le Goater .min_access_size = 8,
44254f59d78SCédric Le Goater .max_access_size = 8,
44354f59d78SCédric Le Goater },
44454f59d78SCédric Le Goater .impl = {
44554f59d78SCédric Le Goater .min_access_size = 8,
44654f59d78SCédric Le Goater .max_access_size = 8,
44754f59d78SCédric Le Goater }
44854f59d78SCédric Le Goater };
44954f59d78SCédric Le Goater
pnv_psi_reset(DeviceState * dev)450fcb7e4a8SGreg Kurz static void pnv_psi_reset(DeviceState *dev)
451f7eb6a0aSCédric Le Goater {
452f7eb6a0aSCédric Le Goater PnvPsi *psi = PNV_PSI(dev);
453f7eb6a0aSCédric Le Goater
454f7eb6a0aSCédric Le Goater memset(psi->regs, 0x0, sizeof(psi->regs));
455f7eb6a0aSCédric Le Goater
456f7eb6a0aSCédric Le Goater psi->regs[PSIHB_XSCOM_BAR] = psi->bar | PSIHB_BAR_EN;
457f7eb6a0aSCédric Le Goater }
458f7eb6a0aSCédric Le Goater
pnv_psi_reset_handler(void * dev)459fcb7e4a8SGreg Kurz static void pnv_psi_reset_handler(void *dev)
460fcb7e4a8SGreg Kurz {
4614bb32cd7SPeter Maydell device_cold_reset(DEVICE(dev));
462fcb7e4a8SGreg Kurz }
463fcb7e4a8SGreg Kurz
pnv_psi_realize(DeviceState * dev,Error ** errp)464b91cad2fSGreg Kurz static void pnv_psi_realize(DeviceState *dev, Error **errp)
465b91cad2fSGreg Kurz {
466b91cad2fSGreg Kurz PnvPsi *psi = PNV_PSI(dev);
467b91cad2fSGreg Kurz
468b91cad2fSGreg Kurz /* Default BAR for MMIO region */
469b91cad2fSGreg Kurz pnv_psi_set_bar(psi, psi->bar | PSIHB_BAR_EN);
470b91cad2fSGreg Kurz
471b91cad2fSGreg Kurz qemu_register_reset(pnv_psi_reset_handler, dev);
472b91cad2fSGreg Kurz }
473b91cad2fSGreg Kurz
pnv_psi_power8_instance_init(Object * obj)474ae856055SCédric Le Goater static void pnv_psi_power8_instance_init(Object *obj)
47554f59d78SCédric Le Goater {
476ae856055SCédric Le Goater Pnv8Psi *psi8 = PNV8_PSI(obj);
47754f59d78SCédric Le Goater
4789fc7fc4dSMarkus Armbruster object_initialize_child(obj, "ics-psi", &psi8->ics, TYPE_ICS);
47934bdca8fSCédric Le Goater object_property_add_alias(obj, ICS_PROP_XICS, OBJECT(&psi8->ics),
480d2623129SMarkus Armbruster ICS_PROP_XICS);
48154f59d78SCédric Le Goater }
48254f59d78SCédric Le Goater
48354f59d78SCédric Le Goater static const uint8_t irq_to_xivr[] = {
48454f59d78SCédric Le Goater PSIHB_XSCOM_XIVR_FSP,
48554f59d78SCédric Le Goater PSIHB_XSCOM_XIVR_OCC,
48654f59d78SCédric Le Goater PSIHB_XSCOM_XIVR_FSI,
48754f59d78SCédric Le Goater PSIHB_XSCOM_XIVR_LPCI2C,
48854f59d78SCédric Le Goater PSIHB_XSCOM_XIVR_LOCERR,
48954f59d78SCédric Le Goater PSIHB_XSCOM_XIVR_EXT,
49054f59d78SCédric Le Goater };
49154f59d78SCédric Le Goater
pnv_psi_power8_realize(DeviceState * dev,Error ** errp)492ae856055SCédric Le Goater static void pnv_psi_power8_realize(DeviceState *dev, Error **errp)
49354f59d78SCédric Le Goater {
49454f59d78SCédric Le Goater PnvPsi *psi = PNV_PSI(dev);
495ae856055SCédric Le Goater ICSState *ics = &PNV8_PSI(psi)->ics;
49654f59d78SCédric Le Goater unsigned int i;
49754f59d78SCédric Le Goater
49854f59d78SCédric Le Goater /* Create PSI interrupt control source */
499778a2dc5SMarkus Armbruster if (!object_property_set_int(OBJECT(ics), "nr-irqs", PSI_NUM_INTERRUPTS,
500668f62ecSMarkus Armbruster errp)) {
50154f59d78SCédric Le Goater return;
50254f59d78SCédric Le Goater }
503668f62ecSMarkus Armbruster if (!qdev_realize(DEVICE(ics), NULL, errp)) {
50454f59d78SCédric Le Goater return;
50554f59d78SCédric Le Goater }
50654f59d78SCédric Le Goater
50754f59d78SCédric Le Goater for (i = 0; i < ics->nr_irqs; i++) {
50854f59d78SCédric Le Goater ics_set_irq_type(ics, i, true);
50954f59d78SCédric Le Goater }
51054f59d78SCédric Le Goater
511dcf4ca45SCédric Le Goater qdev_init_gpio_in(dev, pnv_psi_power8_set_irq, ics->nr_irqs);
512c05aa140SCédric Le Goater
51328976c99SDavid Gibson psi->qirqs = qemu_allocate_irqs(ics_set_irq, ics, ics->nr_irqs);
514f8df9003SCédric Le Goater
51554f59d78SCédric Le Goater /* XSCOM region for PSI registers */
51654f59d78SCédric Le Goater pnv_xscom_region_init(&psi->xscom_regs, OBJECT(dev), &pnv_psi_xscom_ops,
51754f59d78SCédric Le Goater psi, "xscom-psi", PNV_XSCOM_PSIHB_SIZE);
51854f59d78SCédric Le Goater
51954f59d78SCédric Le Goater /* Initialize MMIO region */
52054f59d78SCédric Le Goater memory_region_init_io(&psi->regs_mr, OBJECT(dev), &psi_mmio_ops, psi,
52154f59d78SCédric Le Goater "psihb", PNV_PSIHB_SIZE);
52254f59d78SCédric Le Goater
52354f59d78SCédric Le Goater /* Default sources in XIVR */
52454f59d78SCédric Le Goater for (i = 0; i < PSI_NUM_INTERRUPTS; i++) {
52554f59d78SCédric Le Goater uint8_t xivr = irq_to_xivr[i];
52654f59d78SCédric Le Goater psi->regs[xivr] = PSIHB_XIVR_PRIO_MSK |
52754f59d78SCédric Le Goater ((uint64_t) i << PSIHB_XIVR_SRC_SH);
52854f59d78SCédric Le Goater }
529f7eb6a0aSCédric Le Goater
530b91cad2fSGreg Kurz pnv_psi_realize(dev, errp);
53154f59d78SCédric Le Goater }
53254f59d78SCédric Le Goater
pnv_psi_dt_xscom(PnvXScomInterface * dev,void * fdt,int xscom_offset)533b168a138SCédric Le Goater static int pnv_psi_dt_xscom(PnvXScomInterface *dev, void *fdt, int xscom_offset)
53454f59d78SCédric Le Goater {
535ae856055SCédric Le Goater PnvPsiClass *ppc = PNV_PSI_GET_CLASS(dev);
53654f59d78SCédric Le Goater char *name;
53754f59d78SCédric Le Goater int offset;
53854f59d78SCédric Le Goater uint32_t reg[] = {
539ae856055SCédric Le Goater cpu_to_be32(ppc->xscom_pcba),
540ae856055SCédric Le Goater cpu_to_be32(ppc->xscom_size)
54154f59d78SCédric Le Goater };
54254f59d78SCédric Le Goater
543ae856055SCédric Le Goater name = g_strdup_printf("psihb@%x", ppc->xscom_pcba);
54454f59d78SCédric Le Goater offset = fdt_add_subnode(fdt, xscom_offset, name);
54554f59d78SCédric Le Goater _FDT(offset);
54654f59d78SCédric Le Goater g_free(name);
54754f59d78SCédric Le Goater
548ae856055SCédric Le Goater _FDT(fdt_setprop(fdt, offset, "reg", reg, sizeof(reg)));
549ae856055SCédric Le Goater _FDT(fdt_setprop_cell(fdt, offset, "#address-cells", 2));
550ae856055SCédric Le Goater _FDT(fdt_setprop_cell(fdt, offset, "#size-cells", 1));
55141c4ef70SGreg Kurz _FDT(fdt_setprop(fdt, offset, "compatible", ppc->compat,
55241c4ef70SGreg Kurz ppc->compat_size));
55354f59d78SCédric Le Goater return 0;
55454f59d78SCédric Le Goater }
55554f59d78SCédric Le Goater
55654f59d78SCédric Le Goater static Property pnv_psi_properties[] = {
55754f59d78SCédric Le Goater DEFINE_PROP_UINT64("bar", PnvPsi, bar, 0),
55854f59d78SCédric Le Goater DEFINE_PROP_UINT64("fsp-bar", PnvPsi, fsp_bar, 0),
55954f59d78SCédric Le Goater DEFINE_PROP_END_OF_LIST(),
56054f59d78SCédric Le Goater };
56154f59d78SCédric Le Goater
pnv_psi_power8_class_init(ObjectClass * klass,void * data)562ae856055SCédric Le Goater static void pnv_psi_power8_class_init(ObjectClass *klass, void *data)
563ae856055SCédric Le Goater {
564ae856055SCédric Le Goater DeviceClass *dc = DEVICE_CLASS(klass);
565ae856055SCédric Le Goater PnvPsiClass *ppc = PNV_PSI_CLASS(klass);
56641c4ef70SGreg Kurz static const char compat[] = "ibm,power8-psihb-x\0ibm,psihb-x";
567ae856055SCédric Le Goater
568ae856055SCédric Le Goater dc->desc = "PowerNV PSI Controller POWER8";
569ae856055SCédric Le Goater dc->realize = pnv_psi_power8_realize;
570ae856055SCédric Le Goater
571ae856055SCédric Le Goater ppc->xscom_pcba = PNV_XSCOM_PSIHB_BASE;
572ae856055SCédric Le Goater ppc->xscom_size = PNV_XSCOM_PSIHB_SIZE;
573ae856055SCédric Le Goater ppc->bar_mask = PSIHB_BAR_MASK;
57441c4ef70SGreg Kurz ppc->compat = compat;
57541c4ef70SGreg Kurz ppc->compat_size = sizeof(compat);
576ae856055SCédric Le Goater }
577ae856055SCédric Le Goater
578ae856055SCédric Le Goater static const TypeInfo pnv_psi_power8_info = {
579ae856055SCédric Le Goater .name = TYPE_PNV8_PSI,
580ae856055SCédric Le Goater .parent = TYPE_PNV_PSI,
581ae856055SCédric Le Goater .instance_size = sizeof(Pnv8Psi),
582ae856055SCédric Le Goater .instance_init = pnv_psi_power8_instance_init,
583ae856055SCédric Le Goater .class_init = pnv_psi_power8_class_init,
584ae856055SCédric Le Goater };
585ae856055SCédric Le Goater
586c38536bcSCédric Le Goater
587c38536bcSCédric Le Goater /* Common registers */
588c38536bcSCédric Le Goater
589c38536bcSCédric Le Goater #define PSIHB9_CR 0x20
590c38536bcSCédric Le Goater #define PSIHB9_SEMR 0x28
591c38536bcSCédric Le Goater
592c38536bcSCédric Le Goater /* P9 registers */
593c38536bcSCédric Le Goater
594c38536bcSCédric Le Goater #define PSIHB9_INTERRUPT_CONTROL 0x58
595c38536bcSCédric Le Goater #define PSIHB9_IRQ_METHOD PPC_BIT(0)
596c38536bcSCédric Le Goater #define PSIHB9_IRQ_RESET PPC_BIT(1)
597c38536bcSCédric Le Goater #define PSIHB9_ESB_CI_BASE 0x60
598c5412b1dSCédric Le Goater #define PSIHB9_ESB_CI_ADDR_MASK PPC_BITMASK(8, 47)
599c5412b1dSCédric Le Goater #define PSIHB9_ESB_CI_VALID PPC_BIT(63)
600c38536bcSCédric Le Goater #define PSIHB9_ESB_NOTIF_ADDR 0x68
601c5412b1dSCédric Le Goater #define PSIHB9_ESB_NOTIF_ADDR_MASK PPC_BITMASK(8, 60)
602c5412b1dSCédric Le Goater #define PSIHB9_ESB_NOTIF_VALID PPC_BIT(63)
603c38536bcSCédric Le Goater #define PSIHB9_IVT_OFFSET 0x70
604c38536bcSCédric Le Goater #define PSIHB9_IVT_OFF_SHIFT 32
605c38536bcSCédric Le Goater
606c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL 0x78 /* assertion */
607c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL_PSI PPC_BIT(0)
608c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL_OCC PPC_BIT(1)
609c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL_FSI PPC_BIT(2)
610c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL_LPCHC PPC_BIT(3)
611c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL_LOCAL_ERR PPC_BIT(4)
612c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL_GLOBAL_ERR PPC_BIT(5)
613c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL_TPM PPC_BIT(6)
614c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL_LPC_SIRQ1 PPC_BIT(7)
615c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL_LPC_SIRQ2 PPC_BIT(8)
616c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL_LPC_SIRQ3 PPC_BIT(9)
617c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL_LPC_SIRQ4 PPC_BIT(10)
618c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL_SBE_I2C PPC_BIT(11)
619c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL_DIO PPC_BIT(12)
620c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL_PSU PPC_BIT(13)
621c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL_I2C_C PPC_BIT(14)
622c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL_I2C_D PPC_BIT(15)
623c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL_I2C_E PPC_BIT(16)
624c38536bcSCédric Le Goater #define PSIHB9_IRQ_LEVEL_SBE PPC_BIT(19)
625c38536bcSCédric Le Goater
626c38536bcSCédric Le Goater #define PSIHB9_IRQ_STAT 0x80 /* P bit */
627c38536bcSCédric Le Goater #define PSIHB9_IRQ_STAT_PSI PPC_BIT(0)
628c38536bcSCédric Le Goater #define PSIHB9_IRQ_STAT_OCC PPC_BIT(1)
629c38536bcSCédric Le Goater #define PSIHB9_IRQ_STAT_FSI PPC_BIT(2)
630c38536bcSCédric Le Goater #define PSIHB9_IRQ_STAT_LPCHC PPC_BIT(3)
631c38536bcSCédric Le Goater #define PSIHB9_IRQ_STAT_LOCAL_ERR PPC_BIT(4)
632c38536bcSCédric Le Goater #define PSIHB9_IRQ_STAT_GLOBAL_ERR PPC_BIT(5)
633c38536bcSCédric Le Goater #define PSIHB9_IRQ_STAT_TPM PPC_BIT(6)
634c38536bcSCédric Le Goater #define PSIHB9_IRQ_STAT_LPC_SIRQ1 PPC_BIT(7)
635c38536bcSCédric Le Goater #define PSIHB9_IRQ_STAT_LPC_SIRQ2 PPC_BIT(8)
636c38536bcSCédric Le Goater #define PSIHB9_IRQ_STAT_LPC_SIRQ3 PPC_BIT(9)
637c38536bcSCédric Le Goater #define PSIHB9_IRQ_STAT_LPC_SIRQ4 PPC_BIT(10)
638c38536bcSCédric Le Goater #define PSIHB9_IRQ_STAT_SBE_I2C PPC_BIT(11)
639c38536bcSCédric Le Goater #define PSIHB9_IRQ_STAT_DIO PPC_BIT(12)
640c38536bcSCédric Le Goater #define PSIHB9_IRQ_STAT_PSU PPC_BIT(13)
641c38536bcSCédric Le Goater
64224c8fa96SCédric Le Goater /* P10 register extensions */
64324c8fa96SCédric Le Goater
64424c8fa96SCédric Le Goater #define PSIHB10_CR PSIHB9_CR
64524c8fa96SCédric Le Goater #define PSIHB10_CR_STORE_EOI PPC_BIT(12)
64624c8fa96SCédric Le Goater
64724c8fa96SCédric Le Goater #define PSIHB10_ESB_CI_BASE PSIHB9_ESB_CI_BASE
64824c8fa96SCédric Le Goater #define PSIHB10_ESB_CI_64K PPC_BIT(1)
64924c8fa96SCédric Le Goater
pnv_psi_notify(XiveNotifier * xf,uint32_t srcno,bool pq_checked)6500aa2612aSCédric Le Goater static void pnv_psi_notify(XiveNotifier *xf, uint32_t srcno, bool pq_checked)
651c38536bcSCédric Le Goater {
652c38536bcSCédric Le Goater PnvPsi *psi = PNV_PSI(xf);
653c38536bcSCédric Le Goater uint64_t notif_port = psi->regs[PSIHB_REG(PSIHB9_ESB_NOTIF_ADDR)];
654c38536bcSCédric Le Goater bool valid = notif_port & PSIHB9_ESB_NOTIF_VALID;
655c38536bcSCédric Le Goater uint64_t notify_addr = notif_port & ~PSIHB9_ESB_NOTIF_VALID;
656c38536bcSCédric Le Goater
657c38536bcSCédric Le Goater uint32_t offset =
658c38536bcSCédric Le Goater (psi->regs[PSIHB_REG(PSIHB9_IVT_OFFSET)] >> PSIHB9_IVT_OFF_SHIFT);
6590aa2612aSCédric Le Goater uint64_t data = offset | srcno;
66006d26eebSCédric Le Goater MemTxResult result;
661c38536bcSCédric Le Goater
6620aa2612aSCédric Le Goater if (pq_checked) {
6630aa2612aSCédric Le Goater data |= XIVE_TRIGGER_PQ;
6640aa2612aSCédric Le Goater }
6650aa2612aSCédric Le Goater
66606d26eebSCédric Le Goater if (!valid) {
66706d26eebSCédric Le Goater return;
66806d26eebSCédric Le Goater }
66906d26eebSCédric Le Goater
67006d26eebSCédric Le Goater address_space_stq_be(&address_space_memory, notify_addr, data,
67106d26eebSCédric Le Goater MEMTXATTRS_UNSPECIFIED, &result);
67206d26eebSCédric Le Goater if (result != MEMTX_OK) {
67306d26eebSCédric Le Goater qemu_log_mask(LOG_GUEST_ERROR, "%s: trigger failed @%"
67406d26eebSCédric Le Goater HWADDR_PRIx "\n", __func__, notif_port);
67506d26eebSCédric Le Goater return;
676c38536bcSCédric Le Goater }
677c38536bcSCédric Le Goater }
678c38536bcSCédric Le Goater
pnv_psi_p9_mmio_read(void * opaque,hwaddr addr,unsigned size)679c38536bcSCédric Le Goater static uint64_t pnv_psi_p9_mmio_read(void *opaque, hwaddr addr, unsigned size)
680c38536bcSCédric Le Goater {
681c38536bcSCédric Le Goater PnvPsi *psi = PNV_PSI(opaque);
682c38536bcSCédric Le Goater uint32_t reg = PSIHB_REG(addr);
683c38536bcSCédric Le Goater uint64_t val = -1;
684c38536bcSCédric Le Goater
685c38536bcSCédric Le Goater switch (addr) {
686c38536bcSCédric Le Goater case PSIHB9_CR:
687c38536bcSCédric Le Goater case PSIHB9_SEMR:
688c38536bcSCédric Le Goater /* FSP stuff */
689c38536bcSCédric Le Goater case PSIHB9_INTERRUPT_CONTROL:
690c38536bcSCédric Le Goater case PSIHB9_ESB_CI_BASE:
691c38536bcSCédric Le Goater case PSIHB9_ESB_NOTIF_ADDR:
692c38536bcSCédric Le Goater case PSIHB9_IVT_OFFSET:
693c38536bcSCédric Le Goater val = psi->regs[reg];
694c38536bcSCédric Le Goater break;
695c38536bcSCédric Le Goater default:
696c38536bcSCédric Le Goater qemu_log_mask(LOG_GUEST_ERROR, "PSI: read at 0x%" PRIx64 "\n", addr);
697c38536bcSCédric Le Goater }
698c38536bcSCédric Le Goater
699c38536bcSCédric Le Goater return val;
700c38536bcSCédric Le Goater }
701c38536bcSCédric Le Goater
pnv_psi_p9_mmio_write(void * opaque,hwaddr addr,uint64_t val,unsigned size)702c38536bcSCédric Le Goater static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr,
703c38536bcSCédric Le Goater uint64_t val, unsigned size)
704c38536bcSCédric Le Goater {
705c38536bcSCédric Le Goater PnvPsi *psi = PNV_PSI(opaque);
706c38536bcSCédric Le Goater Pnv9Psi *psi9 = PNV9_PSI(psi);
707c38536bcSCédric Le Goater uint32_t reg = PSIHB_REG(addr);
708c38536bcSCédric Le Goater MemoryRegion *sysmem = get_system_memory();
709c38536bcSCédric Le Goater
710c38536bcSCédric Le Goater switch (addr) {
711c38536bcSCédric Le Goater case PSIHB9_CR:
71224c8fa96SCédric Le Goater if (val & PSIHB10_CR_STORE_EOI) {
71324c8fa96SCédric Le Goater psi9->source.esb_flags |= XIVE_SRC_STORE_EOI;
71424c8fa96SCédric Le Goater } else {
71524c8fa96SCédric Le Goater psi9->source.esb_flags &= ~XIVE_SRC_STORE_EOI;
71624c8fa96SCédric Le Goater }
71724c8fa96SCédric Le Goater break;
71824c8fa96SCédric Le Goater
719c38536bcSCédric Le Goater case PSIHB9_SEMR:
720c38536bcSCédric Le Goater /* FSP stuff */
721c38536bcSCédric Le Goater break;
722c38536bcSCédric Le Goater case PSIHB9_INTERRUPT_CONTROL:
723c38536bcSCédric Le Goater if (val & PSIHB9_IRQ_RESET) {
7244bb32cd7SPeter Maydell device_cold_reset(DEVICE(&psi9->source));
725c38536bcSCédric Le Goater }
726c38536bcSCédric Le Goater psi->regs[reg] = val;
727c38536bcSCédric Le Goater break;
728c38536bcSCédric Le Goater
729c38536bcSCédric Le Goater case PSIHB9_ESB_CI_BASE:
73024c8fa96SCédric Le Goater if (val & PSIHB10_ESB_CI_64K) {
73124c8fa96SCédric Le Goater psi9->source.esb_shift = XIVE_ESB_64K;
73224c8fa96SCédric Le Goater } else {
73324c8fa96SCédric Le Goater psi9->source.esb_shift = XIVE_ESB_4K;
73424c8fa96SCédric Le Goater }
735c38536bcSCédric Le Goater if (!(val & PSIHB9_ESB_CI_VALID)) {
736c38536bcSCédric Le Goater if (psi->regs[reg] & PSIHB9_ESB_CI_VALID) {
737c38536bcSCédric Le Goater memory_region_del_subregion(sysmem, &psi9->source.esb_mmio);
738c38536bcSCédric Le Goater }
739c38536bcSCédric Le Goater } else {
740c38536bcSCédric Le Goater if (!(psi->regs[reg] & PSIHB9_ESB_CI_VALID)) {
741694616d6SCédric Le Goater hwaddr esb_addr =
742694616d6SCédric Le Goater val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K);
743694616d6SCédric Le Goater memory_region_add_subregion(sysmem, esb_addr,
744c38536bcSCédric Le Goater &psi9->source.esb_mmio);
745c38536bcSCédric Le Goater }
746c38536bcSCédric Le Goater }
747c38536bcSCédric Le Goater psi->regs[reg] = val;
748c38536bcSCédric Le Goater break;
749c38536bcSCédric Le Goater
750c38536bcSCédric Le Goater case PSIHB9_ESB_NOTIF_ADDR:
751c38536bcSCédric Le Goater psi->regs[reg] = val;
752c38536bcSCédric Le Goater break;
753c38536bcSCédric Le Goater case PSIHB9_IVT_OFFSET:
754c38536bcSCédric Le Goater psi->regs[reg] = val;
755c38536bcSCédric Le Goater break;
756c38536bcSCédric Le Goater default:
757c38536bcSCédric Le Goater qemu_log_mask(LOG_GUEST_ERROR, "PSI: write at 0x%" PRIx64 "\n", addr);
758c38536bcSCédric Le Goater }
759c38536bcSCédric Le Goater }
760c38536bcSCédric Le Goater
761c38536bcSCédric Le Goater static const MemoryRegionOps pnv_psi_p9_mmio_ops = {
762c38536bcSCédric Le Goater .read = pnv_psi_p9_mmio_read,
763c38536bcSCédric Le Goater .write = pnv_psi_p9_mmio_write,
764c38536bcSCédric Le Goater .endianness = DEVICE_BIG_ENDIAN,
765c38536bcSCédric Le Goater .valid = {
766c38536bcSCédric Le Goater .min_access_size = 8,
767c38536bcSCédric Le Goater .max_access_size = 8,
768c38536bcSCédric Le Goater },
769c38536bcSCédric Le Goater .impl = {
770c38536bcSCédric Le Goater .min_access_size = 8,
771c38536bcSCédric Le Goater .max_access_size = 8,
772c38536bcSCédric Le Goater },
773c38536bcSCédric Le Goater };
774c38536bcSCédric Le Goater
pnv_psi_p9_xscom_read(void * opaque,hwaddr addr,unsigned size)775c38536bcSCédric Le Goater static uint64_t pnv_psi_p9_xscom_read(void *opaque, hwaddr addr, unsigned size)
776c38536bcSCédric Le Goater {
777b5ea6754SFrederic Barrat uint32_t reg = addr >> 3;
778b5ea6754SFrederic Barrat uint64_t val = -1;
779b5ea6754SFrederic Barrat
780b5ea6754SFrederic Barrat if (reg < PSIHB_XSCOM_BAR) {
781b5ea6754SFrederic Barrat /* FIR, not modeled */
782b5ea6754SFrederic Barrat qemu_log_mask(LOG_UNIMP, "PSI: xscom read at 0x%08x\n", reg);
783b5ea6754SFrederic Barrat } else {
784b5ea6754SFrederic Barrat val = pnv_psi_p9_mmio_read(opaque, PSIHB_MMIO(reg), size);
785b5ea6754SFrederic Barrat }
786b5ea6754SFrederic Barrat return val;
787c38536bcSCédric Le Goater }
788c38536bcSCédric Le Goater
pnv_psi_p9_xscom_write(void * opaque,hwaddr addr,uint64_t val,unsigned size)789c38536bcSCédric Le Goater static void pnv_psi_p9_xscom_write(void *opaque, hwaddr addr,
790c38536bcSCédric Le Goater uint64_t val, unsigned size)
791c38536bcSCédric Le Goater {
792c38536bcSCédric Le Goater PnvPsi *psi = PNV_PSI(opaque);
793b5ea6754SFrederic Barrat uint32_t reg = addr >> 3;
794c38536bcSCédric Le Goater
795b5ea6754SFrederic Barrat if (reg < PSIHB_XSCOM_BAR) {
796b5ea6754SFrederic Barrat /* FIR, not modeled */
797b5ea6754SFrederic Barrat qemu_log_mask(LOG_UNIMP, "PSI: xscom write at 0x%08x\n", reg);
798b5ea6754SFrederic Barrat } else if (reg == PSIHB_XSCOM_BAR) {
799c38536bcSCédric Le Goater pnv_psi_set_bar(psi, val);
800b5ea6754SFrederic Barrat } else {
801b5ea6754SFrederic Barrat pnv_psi_p9_mmio_write(opaque, PSIHB_MMIO(reg), val, size);
802c38536bcSCédric Le Goater }
803c38536bcSCédric Le Goater }
804c38536bcSCédric Le Goater
805c38536bcSCédric Le Goater static const MemoryRegionOps pnv_psi_p9_xscom_ops = {
806c38536bcSCédric Le Goater .read = pnv_psi_p9_xscom_read,
807c38536bcSCédric Le Goater .write = pnv_psi_p9_xscom_write,
808c38536bcSCédric Le Goater .endianness = DEVICE_BIG_ENDIAN,
809c38536bcSCédric Le Goater .valid = {
810c38536bcSCédric Le Goater .min_access_size = 8,
811c38536bcSCédric Le Goater .max_access_size = 8,
812c38536bcSCédric Le Goater },
813c38536bcSCédric Le Goater .impl = {
814c38536bcSCédric Le Goater .min_access_size = 8,
815c38536bcSCédric Le Goater .max_access_size = 8,
816c38536bcSCédric Le Goater }
817c38536bcSCédric Le Goater };
818c38536bcSCédric Le Goater
pnv_psi_power9_set_irq(void * opaque,int irq,int state)819dcf4ca45SCédric Le Goater static void pnv_psi_power9_set_irq(void *opaque, int irq, int state)
820c38536bcSCédric Le Goater {
821dcf4ca45SCédric Le Goater PnvPsi *psi = opaque;
822f3e971acSGreg Kurz uint64_t irq_method = psi->regs[PSIHB_REG(PSIHB9_INTERRUPT_CONTROL)];
823c38536bcSCédric Le Goater
824c38536bcSCédric Le Goater if (irq_method & PSIHB9_IRQ_METHOD) {
825c38536bcSCédric Le Goater qemu_log_mask(LOG_GUEST_ERROR, "PSI: LSI IRQ method no supported\n");
826c38536bcSCédric Le Goater return;
827c38536bcSCédric Le Goater }
828c38536bcSCédric Le Goater
829c38536bcSCédric Le Goater /* Update LSI levels */
830c38536bcSCédric Le Goater if (state) {
831c38536bcSCédric Le Goater psi->regs[PSIHB_REG(PSIHB9_IRQ_LEVEL)] |= PPC_BIT(irq);
832c38536bcSCédric Le Goater } else {
833c38536bcSCédric Le Goater psi->regs[PSIHB_REG(PSIHB9_IRQ_LEVEL)] &= ~PPC_BIT(irq);
834c38536bcSCédric Le Goater }
835c38536bcSCédric Le Goater
836c38536bcSCédric Le Goater qemu_set_irq(psi->qirqs[irq], state);
837c38536bcSCédric Le Goater }
838c38536bcSCédric Le Goater
pnv_psi_power9_reset(DeviceState * dev)839fcb7e4a8SGreg Kurz static void pnv_psi_power9_reset(DeviceState *dev)
840c38536bcSCédric Le Goater {
841c38536bcSCédric Le Goater Pnv9Psi *psi = PNV9_PSI(dev);
842c38536bcSCédric Le Goater
843c38536bcSCédric Le Goater pnv_psi_reset(dev);
844c38536bcSCédric Le Goater
845c38536bcSCédric Le Goater if (memory_region_is_mapped(&psi->source.esb_mmio)) {
846c38536bcSCédric Le Goater memory_region_del_subregion(get_system_memory(), &psi->source.esb_mmio);
847c38536bcSCédric Le Goater }
848c38536bcSCédric Le Goater }
849c38536bcSCédric Le Goater
pnv_psi_power9_instance_init(Object * obj)850c38536bcSCédric Le Goater static void pnv_psi_power9_instance_init(Object *obj)
851c38536bcSCédric Le Goater {
852c38536bcSCédric Le Goater Pnv9Psi *psi = PNV9_PSI(obj);
853c38536bcSCédric Le Goater
8549fc7fc4dSMarkus Armbruster object_initialize_child(obj, "source", &psi->source, TYPE_XIVE_SOURCE);
85524c8fa96SCédric Le Goater object_property_add_alias(obj, "shift", OBJECT(&psi->source), "shift");
856c38536bcSCédric Le Goater }
857c38536bcSCédric Le Goater
pnv_psi_power9_realize(DeviceState * dev,Error ** errp)858c38536bcSCédric Le Goater static void pnv_psi_power9_realize(DeviceState *dev, Error **errp)
859c38536bcSCédric Le Goater {
860c38536bcSCédric Le Goater PnvPsi *psi = PNV_PSI(dev);
861c38536bcSCédric Le Goater XiveSource *xsrc = &PNV9_PSI(psi)->source;
862c38536bcSCédric Le Goater int i;
863c38536bcSCédric Le Goater
8645325cc34SMarkus Armbruster object_property_set_int(OBJECT(xsrc), "nr-irqs", PSIHB9_NUM_IRQS,
865c38536bcSCédric Le Goater &error_fatal);
8665325cc34SMarkus Armbruster object_property_set_link(OBJECT(xsrc), "xive", OBJECT(psi), &error_abort);
8674a1e9449SFrederic Barrat object_property_set_int(OBJECT(xsrc), "reset-pq", XIVE_ESB_RESET,
8684a1e9449SFrederic Barrat &error_abort);
869668f62ecSMarkus Armbruster if (!qdev_realize(DEVICE(xsrc), NULL, errp)) {
870c38536bcSCédric Le Goater return;
871c38536bcSCédric Le Goater }
872c38536bcSCédric Le Goater
873c38536bcSCédric Le Goater for (i = 0; i < xsrc->nr_irqs; i++) {
874c38536bcSCédric Le Goater xive_source_irq_set_lsi(xsrc, i);
875c38536bcSCédric Le Goater }
876c38536bcSCédric Le Goater
877c38536bcSCédric Le Goater psi->qirqs = qemu_allocate_irqs(xive_source_set_irq, xsrc, xsrc->nr_irqs);
878c38536bcSCédric Le Goater
879dcf4ca45SCédric Le Goater qdev_init_gpio_in(dev, pnv_psi_power9_set_irq, xsrc->nr_irqs);
880c05aa140SCédric Le Goater
881c38536bcSCédric Le Goater /* XSCOM region for PSI registers */
882c38536bcSCédric Le Goater pnv_xscom_region_init(&psi->xscom_regs, OBJECT(dev), &pnv_psi_p9_xscom_ops,
883c38536bcSCédric Le Goater psi, "xscom-psi", PNV9_XSCOM_PSIHB_SIZE);
884c38536bcSCédric Le Goater
885c38536bcSCédric Le Goater /* MMIO region for PSI registers */
886c38536bcSCédric Le Goater memory_region_init_io(&psi->regs_mr, OBJECT(dev), &pnv_psi_p9_mmio_ops, psi,
887c38536bcSCédric Le Goater "psihb", PNV9_PSIHB_SIZE);
888c38536bcSCédric Le Goater
889b91cad2fSGreg Kurz pnv_psi_realize(dev, errp);
890c38536bcSCédric Le Goater }
891c38536bcSCédric Le Goater
pnv_psi_power9_class_init(ObjectClass * klass,void * data)892c38536bcSCédric Le Goater static void pnv_psi_power9_class_init(ObjectClass *klass, void *data)
893c38536bcSCédric Le Goater {
894c38536bcSCédric Le Goater DeviceClass *dc = DEVICE_CLASS(klass);
895c38536bcSCédric Le Goater PnvPsiClass *ppc = PNV_PSI_CLASS(klass);
896c38536bcSCédric Le Goater XiveNotifierClass *xfc = XIVE_NOTIFIER_CLASS(klass);
89741c4ef70SGreg Kurz static const char compat[] = "ibm,power9-psihb-x\0ibm,psihb-x";
898c38536bcSCédric Le Goater
899c38536bcSCédric Le Goater dc->desc = "PowerNV PSI Controller POWER9";
900c38536bcSCédric Le Goater dc->realize = pnv_psi_power9_realize;
901fcb7e4a8SGreg Kurz dc->reset = pnv_psi_power9_reset;
902c38536bcSCédric Le Goater
903c38536bcSCédric Le Goater ppc->xscom_pcba = PNV9_XSCOM_PSIHB_BASE;
904c38536bcSCédric Le Goater ppc->xscom_size = PNV9_XSCOM_PSIHB_SIZE;
905c38536bcSCédric Le Goater ppc->bar_mask = PSIHB9_BAR_MASK;
90641c4ef70SGreg Kurz ppc->compat = compat;
90741c4ef70SGreg Kurz ppc->compat_size = sizeof(compat);
908c38536bcSCédric Le Goater
909c38536bcSCédric Le Goater xfc->notify = pnv_psi_notify;
910c38536bcSCédric Le Goater }
911c38536bcSCédric Le Goater
912c38536bcSCédric Le Goater static const TypeInfo pnv_psi_power9_info = {
913c38536bcSCédric Le Goater .name = TYPE_PNV9_PSI,
914c38536bcSCédric Le Goater .parent = TYPE_PNV_PSI,
915c38536bcSCédric Le Goater .instance_size = sizeof(Pnv9Psi),
916c38536bcSCédric Le Goater .instance_init = pnv_psi_power9_instance_init,
917c38536bcSCédric Le Goater .class_init = pnv_psi_power9_class_init,
918c38536bcSCédric Le Goater .interfaces = (InterfaceInfo[]) {
919c38536bcSCédric Le Goater { TYPE_XIVE_NOTIFIER },
920c38536bcSCédric Le Goater { },
921c38536bcSCédric Le Goater },
922c38536bcSCédric Le Goater };
923c38536bcSCédric Le Goater
pnv_psi_power10_class_init(ObjectClass * klass,void * data)9248b50ce85SCédric Le Goater static void pnv_psi_power10_class_init(ObjectClass *klass, void *data)
9258b50ce85SCédric Le Goater {
9268b50ce85SCédric Le Goater DeviceClass *dc = DEVICE_CLASS(klass);
9278b50ce85SCédric Le Goater PnvPsiClass *ppc = PNV_PSI_CLASS(klass);
92841c4ef70SGreg Kurz static const char compat[] = "ibm,power10-psihb-x\0ibm,psihb-x";
9298b50ce85SCédric Le Goater
9308b50ce85SCédric Le Goater dc->desc = "PowerNV PSI Controller POWER10";
9318b50ce85SCédric Le Goater
9328b50ce85SCédric Le Goater ppc->xscom_pcba = PNV10_XSCOM_PSIHB_BASE;
9338b50ce85SCédric Le Goater ppc->xscom_size = PNV10_XSCOM_PSIHB_SIZE;
93441c4ef70SGreg Kurz ppc->compat = compat;
93541c4ef70SGreg Kurz ppc->compat_size = sizeof(compat);
9368b50ce85SCédric Le Goater }
9378b50ce85SCédric Le Goater
9388b50ce85SCédric Le Goater static const TypeInfo pnv_psi_power10_info = {
9398b50ce85SCédric Le Goater .name = TYPE_PNV10_PSI,
9408b50ce85SCédric Le Goater .parent = TYPE_PNV9_PSI,
9418b50ce85SCédric Le Goater .class_init = pnv_psi_power10_class_init,
9428b50ce85SCédric Le Goater };
9438b50ce85SCédric Le Goater
pnv_psi_class_init(ObjectClass * klass,void * data)94454f59d78SCédric Le Goater static void pnv_psi_class_init(ObjectClass *klass, void *data)
94554f59d78SCédric Le Goater {
94654f59d78SCédric Le Goater DeviceClass *dc = DEVICE_CLASS(klass);
94754f59d78SCédric Le Goater PnvXScomInterfaceClass *xdc = PNV_XSCOM_INTERFACE_CLASS(klass);
94854f59d78SCédric Le Goater
949b168a138SCédric Le Goater xdc->dt_xscom = pnv_psi_dt_xscom;
95054f59d78SCédric Le Goater
951ae856055SCédric Le Goater dc->desc = "PowerNV PSI Controller";
9524f67d30bSMarc-André Lureau device_class_set_props(dc, pnv_psi_properties);
953fcb7e4a8SGreg Kurz dc->reset = pnv_psi_reset;
95414de3d4aSGreg Kurz dc->user_creatable = false;
95554f59d78SCédric Le Goater }
95654f59d78SCédric Le Goater
95754f59d78SCédric Le Goater static const TypeInfo pnv_psi_info = {
95854f59d78SCédric Le Goater .name = TYPE_PNV_PSI,
9592f35254aSMarkus Armbruster .parent = TYPE_DEVICE,
96054f59d78SCédric Le Goater .instance_size = sizeof(PnvPsi),
96154f59d78SCédric Le Goater .class_init = pnv_psi_class_init,
962ae856055SCédric Le Goater .class_size = sizeof(PnvPsiClass),
963ae856055SCédric Le Goater .abstract = true,
96454f59d78SCédric Le Goater .interfaces = (InterfaceInfo[]) {
96554f59d78SCédric Le Goater { TYPE_PNV_XSCOM_INTERFACE },
96654f59d78SCédric Le Goater { }
96754f59d78SCédric Le Goater }
96854f59d78SCédric Le Goater };
96954f59d78SCédric Le Goater
pnv_psi_register_types(void)97054f59d78SCédric Le Goater static void pnv_psi_register_types(void)
97154f59d78SCédric Le Goater {
97254f59d78SCédric Le Goater type_register_static(&pnv_psi_info);
973ae856055SCédric Le Goater type_register_static(&pnv_psi_power8_info);
974c38536bcSCédric Le Goater type_register_static(&pnv_psi_power9_info);
9758b50ce85SCédric Le Goater type_register_static(&pnv_psi_power10_info);
97654f59d78SCédric Le Goater }
97754f59d78SCédric Le Goater
978ae856055SCédric Le Goater type_init(pnv_psi_register_types);
979c38536bcSCédric Le Goater
pnv_psi_pic_print_info(Pnv9Psi * psi9,Monitor * mon)980c38536bcSCédric Le Goater void pnv_psi_pic_print_info(Pnv9Psi *psi9, Monitor *mon)
981c38536bcSCédric Le Goater {
982c38536bcSCédric Le Goater PnvPsi *psi = PNV_PSI(psi9);
983c38536bcSCédric Le Goater
984c38536bcSCédric Le Goater uint32_t offset =
985c38536bcSCédric Le Goater (psi->regs[PSIHB_REG(PSIHB9_IVT_OFFSET)] >> PSIHB9_IVT_OFF_SHIFT);
986c38536bcSCédric Le Goater
987c38536bcSCédric Le Goater monitor_printf(mon, "PSIHB Source %08x .. %08x\n",
988c38536bcSCédric Le Goater offset, offset + psi9->source.nr_irqs - 1);
989c38536bcSCédric Le Goater xive_source_pic_print_info(&psi9->source, offset, mon);
990c38536bcSCédric Le Goater }
991