1da71b7e3SCédric Le Goater /* 2da71b7e3SCédric Le Goater * QEMU PowerPC XIVE2 interrupt controller model (POWER10) 3da71b7e3SCédric Le Goater * 4da71b7e3SCédric Le Goater * Copyright (c) 2019-2022, IBM Corporation. 5da71b7e3SCédric Le Goater * 6da71b7e3SCédric Le Goater * This code is licensed under the GPL version 2 or later. See the 7da71b7e3SCédric Le Goater * COPYING file in the top-level directory. 8da71b7e3SCédric Le Goater */ 9da71b7e3SCédric Le Goater 10da71b7e3SCédric Le Goater #include "qemu/osdep.h" 11da71b7e3SCédric Le Goater #include "qemu/log.h" 12da71b7e3SCédric Le Goater #include "qapi/error.h" 13da71b7e3SCédric Le Goater #include "target/ppc/cpu.h" 14da71b7e3SCédric Le Goater #include "sysemu/cpus.h" 15da71b7e3SCédric Le Goater #include "sysemu/dma.h" 16da71b7e3SCédric Le Goater #include "monitor/monitor.h" 17da71b7e3SCédric Le Goater #include "hw/ppc/fdt.h" 18da71b7e3SCédric Le Goater #include "hw/ppc/pnv.h" 19da71b7e3SCédric Le Goater #include "hw/ppc/pnv_core.h" 20da71b7e3SCédric Le Goater #include "hw/ppc/pnv_xscom.h" 21da71b7e3SCédric Le Goater #include "hw/ppc/xive2.h" 22da71b7e3SCédric Le Goater #include "hw/ppc/pnv_xive.h" 23da71b7e3SCédric Le Goater #include "hw/ppc/xive_regs.h" 24da71b7e3SCédric Le Goater #include "hw/ppc/xive2_regs.h" 25da71b7e3SCédric Le Goater #include "hw/ppc/ppc.h" 26da71b7e3SCédric Le Goater #include "hw/qdev-properties.h" 27da71b7e3SCédric Le Goater #include "sysemu/reset.h" 28da71b7e3SCédric Le Goater 29da71b7e3SCédric Le Goater #include <libfdt.h> 30da71b7e3SCédric Le Goater 31da71b7e3SCédric Le Goater #include "pnv_xive2_regs.h" 32da71b7e3SCédric Le Goater 33da71b7e3SCédric Le Goater #undef XIVE2_DEBUG 34da71b7e3SCédric Le Goater 35da71b7e3SCédric Le Goater /* 36da71b7e3SCédric Le Goater * Virtual structures table (VST) 37da71b7e3SCédric Le Goater */ 38da71b7e3SCédric Le Goater #define SBE_PER_BYTE 4 39da71b7e3SCédric Le Goater 40da71b7e3SCédric Le Goater typedef struct XiveVstInfo { 41da71b7e3SCédric Le Goater const char *name; 42da71b7e3SCédric Le Goater uint32_t size; 43da71b7e3SCédric Le Goater uint32_t max_blocks; 44da71b7e3SCédric Le Goater } XiveVstInfo; 45da71b7e3SCédric Le Goater 46da71b7e3SCédric Le Goater static const XiveVstInfo vst_infos[] = { 47da71b7e3SCédric Le Goater 48da71b7e3SCédric Le Goater [VST_EAS] = { "EAT", sizeof(Xive2Eas), 16 }, 49da71b7e3SCédric Le Goater [VST_ESB] = { "ESB", 1, 16 }, 50da71b7e3SCédric Le Goater [VST_END] = { "ENDT", sizeof(Xive2End), 16 }, 51da71b7e3SCédric Le Goater 52da71b7e3SCédric Le Goater [VST_NVP] = { "NVPT", sizeof(Xive2Nvp), 16 }, 53da71b7e3SCédric Le Goater [VST_NVG] = { "NVGT", sizeof(Xive2Nvgc), 16 }, 54da71b7e3SCédric Le Goater [VST_NVC] = { "NVCT", sizeof(Xive2Nvgc), 16 }, 55da71b7e3SCédric Le Goater 56da71b7e3SCédric Le Goater [VST_IC] = { "IC", 1 /* ? */ , 16 }, /* Topology # */ 57da71b7e3SCédric Le Goater [VST_SYNC] = { "SYNC", 1 /* ? */ , 16 }, /* Topology # */ 58da71b7e3SCédric Le Goater 59da71b7e3SCédric Le Goater /* 60da71b7e3SCédric Le Goater * This table contains the backing store pages for the interrupt 61da71b7e3SCédric Le Goater * fifos of the VC sub-engine in case of overflow. 62da71b7e3SCédric Le Goater * 63da71b7e3SCédric Le Goater * 0 - IPI, 64da71b7e3SCédric Le Goater * 1 - HWD, 65da71b7e3SCédric Le Goater * 2 - NxC, 66da71b7e3SCédric Le Goater * 3 - INT, 67da71b7e3SCédric Le Goater * 4 - OS-Queue, 68da71b7e3SCédric Le Goater * 5 - Pool-Queue, 69da71b7e3SCédric Le Goater * 6 - Hard-Queue 70da71b7e3SCédric Le Goater */ 71da71b7e3SCédric Le Goater [VST_ERQ] = { "ERQ", 1, VC_QUEUE_COUNT }, 72da71b7e3SCédric Le Goater }; 73da71b7e3SCédric Le Goater 74da71b7e3SCédric Le Goater #define xive2_error(xive, fmt, ...) \ 75da71b7e3SCédric Le Goater qemu_log_mask(LOG_GUEST_ERROR, "XIVE[%x] - " fmt "\n", \ 76da71b7e3SCédric Le Goater (xive)->chip->chip_id, ## __VA_ARGS__); 77da71b7e3SCédric Le Goater 78da71b7e3SCédric Le Goater /* 79da71b7e3SCédric Le Goater * QEMU version of the GETFIELD/SETFIELD macros 80da71b7e3SCédric Le Goater * 81da71b7e3SCédric Le Goater * TODO: It might be better to use the existing extract64() and 82da71b7e3SCédric Le Goater * deposit64() but this means that all the register definitions will 83da71b7e3SCédric Le Goater * change and become incompatible with the ones found in skiboot. 84da71b7e3SCédric Le Goater * 85da71b7e3SCédric Le Goater * Keep it as it is for now until we find a common ground. 86da71b7e3SCédric Le Goater */ 87da71b7e3SCédric Le Goater static inline uint64_t GETFIELD(uint64_t mask, uint64_t word) 88da71b7e3SCédric Le Goater { 89da71b7e3SCédric Le Goater return (word & mask) >> ctz64(mask); 90da71b7e3SCédric Le Goater } 91da71b7e3SCédric Le Goater 92da71b7e3SCédric Le Goater static inline uint64_t SETFIELD(uint64_t mask, uint64_t word, 93da71b7e3SCédric Le Goater uint64_t value) 94da71b7e3SCédric Le Goater { 95da71b7e3SCédric Le Goater return (word & ~mask) | ((value << ctz64(mask)) & mask); 96da71b7e3SCédric Le Goater } 97da71b7e3SCédric Le Goater 98da71b7e3SCédric Le Goater /* 99da71b7e3SCédric Le Goater * TODO: Document block id override 100da71b7e3SCédric Le Goater */ 101da71b7e3SCédric Le Goater static uint32_t pnv_xive2_block_id(PnvXive2 *xive) 102da71b7e3SCédric Le Goater { 103da71b7e3SCédric Le Goater uint8_t blk = xive->chip->chip_id; 104da71b7e3SCédric Le Goater uint64_t cfg_val = xive->cq_regs[CQ_XIVE_CFG >> 3]; 105da71b7e3SCédric Le Goater 106da71b7e3SCédric Le Goater if (cfg_val & CQ_XIVE_CFG_HYP_HARD_BLKID_OVERRIDE) { 107da71b7e3SCédric Le Goater blk = GETFIELD(CQ_XIVE_CFG_HYP_HARD_BLOCK_ID, cfg_val); 108da71b7e3SCédric Le Goater } 109da71b7e3SCédric Le Goater 110da71b7e3SCédric Le Goater return blk; 111da71b7e3SCédric Le Goater } 112da71b7e3SCédric Le Goater 113da71b7e3SCédric Le Goater /* 114da71b7e3SCédric Le Goater * Remote access to controllers. HW uses MMIOs. For now, a simple scan 115da71b7e3SCédric Le Goater * of the chips is good enough. 116da71b7e3SCédric Le Goater * 117da71b7e3SCédric Le Goater * TODO: Block scope support 118da71b7e3SCédric Le Goater */ 119da71b7e3SCédric Le Goater static PnvXive2 *pnv_xive2_get_remote(uint8_t blk) 120da71b7e3SCédric Le Goater { 121da71b7e3SCédric Le Goater PnvMachineState *pnv = PNV_MACHINE(qdev_get_machine()); 122da71b7e3SCédric Le Goater int i; 123da71b7e3SCédric Le Goater 124da71b7e3SCédric Le Goater for (i = 0; i < pnv->num_chips; i++) { 125da71b7e3SCédric Le Goater Pnv10Chip *chip10 = PNV10_CHIP(pnv->chips[i]); 126da71b7e3SCédric Le Goater PnvXive2 *xive = &chip10->xive; 127da71b7e3SCédric Le Goater 128da71b7e3SCédric Le Goater if (pnv_xive2_block_id(xive) == blk) { 129da71b7e3SCédric Le Goater return xive; 130da71b7e3SCédric Le Goater } 131da71b7e3SCédric Le Goater } 132da71b7e3SCédric Le Goater return NULL; 133da71b7e3SCédric Le Goater } 134da71b7e3SCédric Le Goater 135da71b7e3SCédric Le Goater /* 136da71b7e3SCédric Le Goater * VST accessors for ESB, EAT, ENDT, NVP 137da71b7e3SCédric Le Goater * 138da71b7e3SCédric Le Goater * Indirect VST tables are arrays of VSDs pointing to a page (of same 139da71b7e3SCédric Le Goater * size). Each page is a direct VST table. 140da71b7e3SCédric Le Goater */ 141da71b7e3SCédric Le Goater 142da71b7e3SCédric Le Goater #define XIVE_VSD_SIZE 8 143da71b7e3SCédric Le Goater 144da71b7e3SCédric Le Goater /* Indirect page size can be 4K, 64K, 2M, 16M. */ 145da71b7e3SCédric Le Goater static uint64_t pnv_xive2_vst_page_size_allowed(uint32_t page_shift) 146da71b7e3SCédric Le Goater { 147da71b7e3SCédric Le Goater return page_shift == 12 || page_shift == 16 || 148da71b7e3SCédric Le Goater page_shift == 21 || page_shift == 24; 149da71b7e3SCédric Le Goater } 150da71b7e3SCédric Le Goater 151da71b7e3SCédric Le Goater static uint64_t pnv_xive2_vst_addr_direct(PnvXive2 *xive, uint32_t type, 152da71b7e3SCédric Le Goater uint64_t vsd, uint32_t idx) 153da71b7e3SCédric Le Goater { 154da71b7e3SCédric Le Goater const XiveVstInfo *info = &vst_infos[type]; 155da71b7e3SCédric Le Goater uint64_t vst_addr = vsd & VSD_ADDRESS_MASK; 156da71b7e3SCédric Le Goater uint64_t vst_tsize = 1ull << (GETFIELD(VSD_TSIZE, vsd) + 12); 157da71b7e3SCédric Le Goater uint32_t idx_max; 158da71b7e3SCédric Le Goater 159da71b7e3SCédric Le Goater idx_max = vst_tsize / info->size - 1; 160da71b7e3SCédric Le Goater if (idx > idx_max) { 161da71b7e3SCédric Le Goater #ifdef XIVE2_DEBUG 162da71b7e3SCédric Le Goater xive2_error(xive, "VST: %s entry %x out of range [ 0 .. %x ] !?", 163da71b7e3SCédric Le Goater info->name, idx, idx_max); 164da71b7e3SCédric Le Goater #endif 165da71b7e3SCédric Le Goater return 0; 166da71b7e3SCédric Le Goater } 167da71b7e3SCédric Le Goater 168da71b7e3SCédric Le Goater return vst_addr + idx * info->size; 169da71b7e3SCédric Le Goater } 170da71b7e3SCédric Le Goater 171da71b7e3SCédric Le Goater static uint64_t pnv_xive2_vst_addr_indirect(PnvXive2 *xive, uint32_t type, 172da71b7e3SCédric Le Goater uint64_t vsd, uint32_t idx) 173da71b7e3SCédric Le Goater { 174da71b7e3SCédric Le Goater const XiveVstInfo *info = &vst_infos[type]; 175da71b7e3SCédric Le Goater uint64_t vsd_addr; 176da71b7e3SCédric Le Goater uint32_t vsd_idx; 177da71b7e3SCédric Le Goater uint32_t page_shift; 178da71b7e3SCédric Le Goater uint32_t vst_per_page; 179da71b7e3SCédric Le Goater 180da71b7e3SCédric Le Goater /* Get the page size of the indirect table. */ 181da71b7e3SCédric Le Goater vsd_addr = vsd & VSD_ADDRESS_MASK; 182da71b7e3SCédric Le Goater ldq_be_dma(&address_space_memory, vsd_addr, &vsd, MEMTXATTRS_UNSPECIFIED); 183da71b7e3SCédric Le Goater 184da71b7e3SCédric Le Goater if (!(vsd & VSD_ADDRESS_MASK)) { 185da71b7e3SCédric Le Goater xive2_error(xive, "VST: invalid %s entry %x !?", info->name, idx); 186da71b7e3SCédric Le Goater return 0; 187da71b7e3SCédric Le Goater } 188da71b7e3SCédric Le Goater 189da71b7e3SCédric Le Goater page_shift = GETFIELD(VSD_TSIZE, vsd) + 12; 190da71b7e3SCédric Le Goater 191da71b7e3SCédric Le Goater if (!pnv_xive2_vst_page_size_allowed(page_shift)) { 192da71b7e3SCédric Le Goater xive2_error(xive, "VST: invalid %s page shift %d", info->name, 193da71b7e3SCédric Le Goater page_shift); 194da71b7e3SCédric Le Goater return 0; 195da71b7e3SCédric Le Goater } 196da71b7e3SCédric Le Goater 197da71b7e3SCédric Le Goater vst_per_page = (1ull << page_shift) / info->size; 198da71b7e3SCédric Le Goater vsd_idx = idx / vst_per_page; 199da71b7e3SCédric Le Goater 200da71b7e3SCédric Le Goater /* Load the VSD we are looking for, if not already done */ 201da71b7e3SCédric Le Goater if (vsd_idx) { 202da71b7e3SCédric Le Goater vsd_addr = vsd_addr + vsd_idx * XIVE_VSD_SIZE; 203da71b7e3SCédric Le Goater ldq_be_dma(&address_space_memory, vsd_addr, &vsd, 204da71b7e3SCédric Le Goater MEMTXATTRS_UNSPECIFIED); 205da71b7e3SCédric Le Goater 206da71b7e3SCédric Le Goater if (!(vsd & VSD_ADDRESS_MASK)) { 207da71b7e3SCédric Le Goater xive2_error(xive, "VST: invalid %s entry %x !?", info->name, idx); 208da71b7e3SCédric Le Goater return 0; 209da71b7e3SCédric Le Goater } 210da71b7e3SCédric Le Goater 211da71b7e3SCédric Le Goater /* 212da71b7e3SCédric Le Goater * Check that the pages have a consistent size across the 213da71b7e3SCédric Le Goater * indirect table 214da71b7e3SCédric Le Goater */ 215da71b7e3SCédric Le Goater if (page_shift != GETFIELD(VSD_TSIZE, vsd) + 12) { 216da71b7e3SCédric Le Goater xive2_error(xive, "VST: %s entry %x indirect page size differ !?", 217da71b7e3SCédric Le Goater info->name, idx); 218da71b7e3SCédric Le Goater return 0; 219da71b7e3SCédric Le Goater } 220da71b7e3SCédric Le Goater } 221da71b7e3SCédric Le Goater 222da71b7e3SCédric Le Goater return pnv_xive2_vst_addr_direct(xive, type, vsd, (idx % vst_per_page)); 223da71b7e3SCédric Le Goater } 224da71b7e3SCédric Le Goater 225da71b7e3SCédric Le Goater static uint64_t pnv_xive2_vst_addr(PnvXive2 *xive, uint32_t type, uint8_t blk, 226da71b7e3SCédric Le Goater uint32_t idx) 227da71b7e3SCédric Le Goater { 228da71b7e3SCédric Le Goater const XiveVstInfo *info = &vst_infos[type]; 229da71b7e3SCédric Le Goater uint64_t vsd; 230da71b7e3SCédric Le Goater 231da71b7e3SCédric Le Goater if (blk >= info->max_blocks) { 232da71b7e3SCédric Le Goater xive2_error(xive, "VST: invalid block id %d for VST %s %d !?", 233da71b7e3SCédric Le Goater blk, info->name, idx); 234da71b7e3SCédric Le Goater return 0; 235da71b7e3SCédric Le Goater } 236da71b7e3SCédric Le Goater 237da71b7e3SCédric Le Goater vsd = xive->vsds[type][blk]; 238da71b7e3SCédric Le Goater 239da71b7e3SCédric Le Goater /* Remote VST access */ 240da71b7e3SCédric Le Goater if (GETFIELD(VSD_MODE, vsd) == VSD_MODE_FORWARD) { 241da71b7e3SCédric Le Goater xive = pnv_xive2_get_remote(blk); 242da71b7e3SCédric Le Goater 243da71b7e3SCédric Le Goater return xive ? pnv_xive2_vst_addr(xive, type, blk, idx) : 0; 244da71b7e3SCédric Le Goater } 245da71b7e3SCédric Le Goater 246da71b7e3SCédric Le Goater if (VSD_INDIRECT & vsd) { 247da71b7e3SCédric Le Goater return pnv_xive2_vst_addr_indirect(xive, type, vsd, idx); 248da71b7e3SCédric Le Goater } 249da71b7e3SCédric Le Goater 250da71b7e3SCédric Le Goater return pnv_xive2_vst_addr_direct(xive, type, vsd, idx); 251da71b7e3SCédric Le Goater } 252da71b7e3SCédric Le Goater 253da71b7e3SCédric Le Goater static int pnv_xive2_vst_read(PnvXive2 *xive, uint32_t type, uint8_t blk, 254da71b7e3SCédric Le Goater uint32_t idx, void *data) 255da71b7e3SCédric Le Goater { 256da71b7e3SCédric Le Goater const XiveVstInfo *info = &vst_infos[type]; 257da71b7e3SCédric Le Goater uint64_t addr = pnv_xive2_vst_addr(xive, type, blk, idx); 258da71b7e3SCédric Le Goater 259da71b7e3SCédric Le Goater if (!addr) { 260da71b7e3SCédric Le Goater return -1; 261da71b7e3SCédric Le Goater } 262da71b7e3SCédric Le Goater 263da71b7e3SCédric Le Goater cpu_physical_memory_read(addr, data, info->size); 264da71b7e3SCédric Le Goater return 0; 265da71b7e3SCédric Le Goater } 266da71b7e3SCédric Le Goater 267da71b7e3SCédric Le Goater #define XIVE_VST_WORD_ALL -1 268da71b7e3SCédric Le Goater 269da71b7e3SCédric Le Goater static int pnv_xive2_vst_write(PnvXive2 *xive, uint32_t type, uint8_t blk, 270da71b7e3SCédric Le Goater uint32_t idx, void *data, uint32_t word_number) 271da71b7e3SCédric Le Goater { 272da71b7e3SCédric Le Goater const XiveVstInfo *info = &vst_infos[type]; 273da71b7e3SCédric Le Goater uint64_t addr = pnv_xive2_vst_addr(xive, type, blk, idx); 274da71b7e3SCédric Le Goater 275da71b7e3SCédric Le Goater if (!addr) { 276da71b7e3SCédric Le Goater return -1; 277da71b7e3SCédric Le Goater } 278da71b7e3SCédric Le Goater 279da71b7e3SCédric Le Goater if (word_number == XIVE_VST_WORD_ALL) { 280da71b7e3SCédric Le Goater cpu_physical_memory_write(addr, data, info->size); 281da71b7e3SCédric Le Goater } else { 282da71b7e3SCédric Le Goater cpu_physical_memory_write(addr + word_number * 4, 283da71b7e3SCédric Le Goater data + word_number * 4, 4); 284da71b7e3SCédric Le Goater } 285da71b7e3SCédric Le Goater return 0; 286da71b7e3SCédric Le Goater } 287da71b7e3SCédric Le Goater 2880aa2612aSCédric Le Goater static int pnv_xive2_get_pq(Xive2Router *xrtr, uint8_t blk, uint32_t idx, 2890aa2612aSCédric Le Goater uint8_t *pq) 2900aa2612aSCédric Le Goater { 2910aa2612aSCédric Le Goater PnvXive2 *xive = PNV_XIVE2(xrtr); 2920aa2612aSCédric Le Goater 2930aa2612aSCédric Le Goater if (pnv_xive2_block_id(xive) != blk) { 2940aa2612aSCédric Le Goater xive2_error(xive, "VST: EAS %x is remote !?", XIVE_EAS(blk, idx)); 2950aa2612aSCédric Le Goater return -1; 2960aa2612aSCédric Le Goater } 2970aa2612aSCédric Le Goater 2980aa2612aSCédric Le Goater *pq = xive_source_esb_get(&xive->ipi_source, idx); 2990aa2612aSCédric Le Goater return 0; 3000aa2612aSCédric Le Goater } 3010aa2612aSCédric Le Goater 3020aa2612aSCédric Le Goater static int pnv_xive2_set_pq(Xive2Router *xrtr, uint8_t blk, uint32_t idx, 3030aa2612aSCédric Le Goater uint8_t *pq) 3040aa2612aSCédric Le Goater { 3050aa2612aSCédric Le Goater PnvXive2 *xive = PNV_XIVE2(xrtr); 3060aa2612aSCédric Le Goater 3070aa2612aSCédric Le Goater if (pnv_xive2_block_id(xive) != blk) { 3080aa2612aSCédric Le Goater xive2_error(xive, "VST: EAS %x is remote !?", XIVE_EAS(blk, idx)); 3090aa2612aSCédric Le Goater return -1; 3100aa2612aSCédric Le Goater } 3110aa2612aSCédric Le Goater 3120aa2612aSCédric Le Goater *pq = xive_source_esb_set(&xive->ipi_source, idx, *pq); 3130aa2612aSCédric Le Goater return 0; 3140aa2612aSCédric Le Goater } 3150aa2612aSCédric Le Goater 316da71b7e3SCédric Le Goater static int pnv_xive2_get_end(Xive2Router *xrtr, uint8_t blk, uint32_t idx, 317da71b7e3SCédric Le Goater Xive2End *end) 318da71b7e3SCédric Le Goater { 319da71b7e3SCédric Le Goater return pnv_xive2_vst_read(PNV_XIVE2(xrtr), VST_END, blk, idx, end); 320da71b7e3SCédric Le Goater } 321da71b7e3SCédric Le Goater 322da71b7e3SCédric Le Goater static int pnv_xive2_write_end(Xive2Router *xrtr, uint8_t blk, uint32_t idx, 323da71b7e3SCédric Le Goater Xive2End *end, uint8_t word_number) 324da71b7e3SCédric Le Goater { 325da71b7e3SCédric Le Goater return pnv_xive2_vst_write(PNV_XIVE2(xrtr), VST_END, blk, idx, end, 326da71b7e3SCédric Le Goater word_number); 327da71b7e3SCédric Le Goater } 328da71b7e3SCédric Le Goater 329da71b7e3SCédric Le Goater static int pnv_xive2_end_update(PnvXive2 *xive) 330da71b7e3SCédric Le Goater { 331da71b7e3SCédric Le Goater uint8_t blk = GETFIELD(VC_ENDC_WATCH_BLOCK_ID, 332da71b7e3SCédric Le Goater xive->vc_regs[(VC_ENDC_WATCH0_SPEC >> 3)]); 333da71b7e3SCédric Le Goater uint32_t idx = GETFIELD(VC_ENDC_WATCH_INDEX, 334da71b7e3SCédric Le Goater xive->vc_regs[(VC_ENDC_WATCH0_SPEC >> 3)]); 335da71b7e3SCédric Le Goater int i; 336da71b7e3SCédric Le Goater uint64_t endc_watch[4]; 337da71b7e3SCédric Le Goater 338da71b7e3SCédric Le Goater for (i = 0; i < ARRAY_SIZE(endc_watch); i++) { 339da71b7e3SCédric Le Goater endc_watch[i] = 340da71b7e3SCédric Le Goater cpu_to_be64(xive->vc_regs[(VC_ENDC_WATCH0_DATA0 >> 3) + i]); 341da71b7e3SCédric Le Goater } 342da71b7e3SCédric Le Goater 343da71b7e3SCédric Le Goater return pnv_xive2_vst_write(xive, VST_END, blk, idx, endc_watch, 344da71b7e3SCédric Le Goater XIVE_VST_WORD_ALL); 345da71b7e3SCédric Le Goater } 346da71b7e3SCédric Le Goater 347da71b7e3SCédric Le Goater static void pnv_xive2_end_cache_load(PnvXive2 *xive) 348da71b7e3SCédric Le Goater { 349da71b7e3SCédric Le Goater uint8_t blk = GETFIELD(VC_ENDC_WATCH_BLOCK_ID, 350da71b7e3SCédric Le Goater xive->vc_regs[(VC_ENDC_WATCH0_SPEC >> 3)]); 351da71b7e3SCédric Le Goater uint32_t idx = GETFIELD(VC_ENDC_WATCH_INDEX, 352da71b7e3SCédric Le Goater xive->vc_regs[(VC_ENDC_WATCH0_SPEC >> 3)]); 353da71b7e3SCédric Le Goater uint64_t endc_watch[4] = { 0 }; 354da71b7e3SCédric Le Goater int i; 355da71b7e3SCédric Le Goater 356da71b7e3SCédric Le Goater if (pnv_xive2_vst_read(xive, VST_END, blk, idx, endc_watch)) { 357da71b7e3SCédric Le Goater xive2_error(xive, "VST: no END entry %x/%x !?", blk, idx); 358da71b7e3SCédric Le Goater } 359da71b7e3SCédric Le Goater 360da71b7e3SCédric Le Goater for (i = 0; i < ARRAY_SIZE(endc_watch); i++) { 361da71b7e3SCédric Le Goater xive->vc_regs[(VC_ENDC_WATCH0_DATA0 >> 3) + i] = 362da71b7e3SCédric Le Goater be64_to_cpu(endc_watch[i]); 363da71b7e3SCédric Le Goater } 364da71b7e3SCédric Le Goater } 365da71b7e3SCédric Le Goater 366da71b7e3SCédric Le Goater static int pnv_xive2_get_nvp(Xive2Router *xrtr, uint8_t blk, uint32_t idx, 367da71b7e3SCédric Le Goater Xive2Nvp *nvp) 368da71b7e3SCédric Le Goater { 369da71b7e3SCédric Le Goater return pnv_xive2_vst_read(PNV_XIVE2(xrtr), VST_NVP, blk, idx, nvp); 370da71b7e3SCédric Le Goater } 371da71b7e3SCédric Le Goater 372da71b7e3SCédric Le Goater static int pnv_xive2_write_nvp(Xive2Router *xrtr, uint8_t blk, uint32_t idx, 373da71b7e3SCédric Le Goater Xive2Nvp *nvp, uint8_t word_number) 374da71b7e3SCédric Le Goater { 375da71b7e3SCédric Le Goater return pnv_xive2_vst_write(PNV_XIVE2(xrtr), VST_NVP, blk, idx, nvp, 376da71b7e3SCédric Le Goater word_number); 377da71b7e3SCédric Le Goater } 378da71b7e3SCédric Le Goater 379da71b7e3SCédric Le Goater static int pnv_xive2_nvp_update(PnvXive2 *xive) 380da71b7e3SCédric Le Goater { 381da71b7e3SCédric Le Goater uint8_t blk = GETFIELD(PC_NXC_WATCH_BLOCK_ID, 382da71b7e3SCédric Le Goater xive->pc_regs[(PC_NXC_WATCH0_SPEC >> 3)]); 383da71b7e3SCédric Le Goater uint32_t idx = GETFIELD(PC_NXC_WATCH_INDEX, 384da71b7e3SCédric Le Goater xive->pc_regs[(PC_NXC_WATCH0_SPEC >> 3)]); 385da71b7e3SCédric Le Goater int i; 386da71b7e3SCédric Le Goater uint64_t nxc_watch[4]; 387da71b7e3SCédric Le Goater 388da71b7e3SCédric Le Goater for (i = 0; i < ARRAY_SIZE(nxc_watch); i++) { 389da71b7e3SCédric Le Goater nxc_watch[i] = 390da71b7e3SCédric Le Goater cpu_to_be64(xive->pc_regs[(PC_NXC_WATCH0_DATA0 >> 3) + i]); 391da71b7e3SCédric Le Goater } 392da71b7e3SCédric Le Goater 393da71b7e3SCédric Le Goater return pnv_xive2_vst_write(xive, VST_NVP, blk, idx, nxc_watch, 394da71b7e3SCédric Le Goater XIVE_VST_WORD_ALL); 395da71b7e3SCédric Le Goater } 396da71b7e3SCédric Le Goater 397da71b7e3SCédric Le Goater static void pnv_xive2_nvp_cache_load(PnvXive2 *xive) 398da71b7e3SCédric Le Goater { 399da71b7e3SCédric Le Goater uint8_t blk = GETFIELD(PC_NXC_WATCH_BLOCK_ID, 400da71b7e3SCédric Le Goater xive->pc_regs[(PC_NXC_WATCH0_SPEC >> 3)]); 401da71b7e3SCédric Le Goater uint32_t idx = GETFIELD(PC_NXC_WATCH_INDEX, 402da71b7e3SCédric Le Goater xive->pc_regs[(PC_NXC_WATCH0_SPEC >> 3)]); 403da71b7e3SCédric Le Goater uint64_t nxc_watch[4] = { 0 }; 404da71b7e3SCédric Le Goater int i; 405da71b7e3SCédric Le Goater 406da71b7e3SCédric Le Goater if (pnv_xive2_vst_read(xive, VST_NVP, blk, idx, nxc_watch)) { 407da71b7e3SCédric Le Goater xive2_error(xive, "VST: no NVP entry %x/%x !?", blk, idx); 408da71b7e3SCédric Le Goater } 409da71b7e3SCédric Le Goater 410da71b7e3SCédric Le Goater for (i = 0; i < ARRAY_SIZE(nxc_watch); i++) { 411da71b7e3SCédric Le Goater xive->pc_regs[(PC_NXC_WATCH0_DATA0 >> 3) + i] = 412da71b7e3SCédric Le Goater be64_to_cpu(nxc_watch[i]); 413da71b7e3SCédric Le Goater } 414da71b7e3SCédric Le Goater } 415da71b7e3SCédric Le Goater 416da71b7e3SCédric Le Goater static int pnv_xive2_get_eas(Xive2Router *xrtr, uint8_t blk, uint32_t idx, 417da71b7e3SCédric Le Goater Xive2Eas *eas) 418da71b7e3SCédric Le Goater { 419da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(xrtr); 420da71b7e3SCédric Le Goater 421da71b7e3SCédric Le Goater if (pnv_xive2_block_id(xive) != blk) { 422da71b7e3SCédric Le Goater xive2_error(xive, "VST: EAS %x is remote !?", XIVE_EAS(blk, idx)); 423da71b7e3SCédric Le Goater return -1; 424da71b7e3SCédric Le Goater } 425da71b7e3SCédric Le Goater 426da71b7e3SCédric Le Goater return pnv_xive2_vst_read(xive, VST_EAS, blk, idx, eas); 427da71b7e3SCédric Le Goater } 428da71b7e3SCédric Le Goater 429e16032b8SCédric Le Goater static uint32_t pnv_xive2_get_config(Xive2Router *xrtr) 430e16032b8SCédric Le Goater { 431e16032b8SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(xrtr); 432e16032b8SCédric Le Goater uint32_t cfg = 0; 433e16032b8SCédric Le Goater 434e16032b8SCédric Le Goater if (xive->cq_regs[CQ_XIVE_CFG >> 3] & CQ_XIVE_CFG_GEN1_TIMA_OS) { 435e16032b8SCédric Le Goater cfg |= XIVE2_GEN1_TIMA_OS; 436e16032b8SCédric Le Goater } 437e16032b8SCédric Le Goater 438*835806f1SCédric Le Goater if (xive->cq_regs[CQ_XIVE_CFG >> 3] & CQ_XIVE_CFG_EN_VP_SAVE_RESTORE) { 439*835806f1SCédric Le Goater cfg |= XIVE2_VP_SAVE_RESTORE; 440*835806f1SCédric Le Goater } 441*835806f1SCédric Le Goater 442e16032b8SCédric Le Goater return cfg; 443e16032b8SCédric Le Goater } 444e16032b8SCédric Le Goater 445da71b7e3SCédric Le Goater static bool pnv_xive2_is_cpu_enabled(PnvXive2 *xive, PowerPCCPU *cpu) 446da71b7e3SCédric Le Goater { 447da71b7e3SCédric Le Goater int pir = ppc_cpu_pir(cpu); 448da71b7e3SCédric Le Goater uint32_t fc = PNV10_PIR2FUSEDCORE(pir); 449da71b7e3SCédric Le Goater uint64_t reg = fc < 8 ? TCTXT_EN0 : TCTXT_EN1; 450da71b7e3SCédric Le Goater uint32_t bit = pir & 0x3f; 451da71b7e3SCédric Le Goater 452da71b7e3SCédric Le Goater return xive->tctxt_regs[reg >> 3] & PPC_BIT(bit); 453da71b7e3SCédric Le Goater } 454da71b7e3SCédric Le Goater 455da71b7e3SCédric Le Goater static int pnv_xive2_match_nvt(XivePresenter *xptr, uint8_t format, 456da71b7e3SCédric Le Goater uint8_t nvt_blk, uint32_t nvt_idx, 457da71b7e3SCédric Le Goater bool cam_ignore, uint8_t priority, 458da71b7e3SCédric Le Goater uint32_t logic_serv, XiveTCTXMatch *match) 459da71b7e3SCédric Le Goater { 460da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(xptr); 461da71b7e3SCédric Le Goater PnvChip *chip = xive->chip; 462da71b7e3SCédric Le Goater int count = 0; 463da71b7e3SCédric Le Goater int i, j; 464747ffe28SCédric Le Goater bool gen1_tima_os = 465747ffe28SCédric Le Goater xive->cq_regs[CQ_XIVE_CFG >> 3] & CQ_XIVE_CFG_GEN1_TIMA_OS; 466da71b7e3SCédric Le Goater 467da71b7e3SCédric Le Goater for (i = 0; i < chip->nr_cores; i++) { 468da71b7e3SCédric Le Goater PnvCore *pc = chip->cores[i]; 469da71b7e3SCédric Le Goater CPUCore *cc = CPU_CORE(pc); 470da71b7e3SCédric Le Goater 471da71b7e3SCédric Le Goater for (j = 0; j < cc->nr_threads; j++) { 472da71b7e3SCédric Le Goater PowerPCCPU *cpu = pc->threads[j]; 473da71b7e3SCédric Le Goater XiveTCTX *tctx; 474da71b7e3SCédric Le Goater int ring; 475da71b7e3SCédric Le Goater 476da71b7e3SCédric Le Goater if (!pnv_xive2_is_cpu_enabled(xive, cpu)) { 477da71b7e3SCédric Le Goater continue; 478da71b7e3SCédric Le Goater } 479da71b7e3SCédric Le Goater 480da71b7e3SCédric Le Goater tctx = XIVE_TCTX(pnv_cpu_state(cpu)->intc); 481da71b7e3SCédric Le Goater 482747ffe28SCédric Le Goater if (gen1_tima_os) { 483747ffe28SCédric Le Goater ring = xive_presenter_tctx_match(xptr, tctx, format, nvt_blk, 484747ffe28SCédric Le Goater nvt_idx, cam_ignore, 485747ffe28SCédric Le Goater logic_serv); 486747ffe28SCédric Le Goater } else { 487da71b7e3SCédric Le Goater ring = xive2_presenter_tctx_match(xptr, tctx, format, nvt_blk, 488da71b7e3SCédric Le Goater nvt_idx, cam_ignore, 489da71b7e3SCédric Le Goater logic_serv); 490747ffe28SCédric Le Goater } 491da71b7e3SCédric Le Goater 492da71b7e3SCédric Le Goater /* 493da71b7e3SCédric Le Goater * Save the context and follow on to catch duplicates, 494da71b7e3SCédric Le Goater * that we don't support yet. 495da71b7e3SCédric Le Goater */ 496da71b7e3SCédric Le Goater if (ring != -1) { 497da71b7e3SCédric Le Goater if (match->tctx) { 498da71b7e3SCédric Le Goater qemu_log_mask(LOG_GUEST_ERROR, "XIVE: already found a " 499da71b7e3SCédric Le Goater "thread context NVT %x/%x\n", 500da71b7e3SCédric Le Goater nvt_blk, nvt_idx); 501da71b7e3SCédric Le Goater return false; 502da71b7e3SCédric Le Goater } 503da71b7e3SCédric Le Goater 504da71b7e3SCédric Le Goater match->ring = ring; 505da71b7e3SCédric Le Goater match->tctx = tctx; 506da71b7e3SCédric Le Goater count++; 507da71b7e3SCédric Le Goater } 508da71b7e3SCédric Le Goater } 509da71b7e3SCédric Le Goater } 510da71b7e3SCédric Le Goater 511da71b7e3SCédric Le Goater return count; 512da71b7e3SCédric Le Goater } 513da71b7e3SCédric Le Goater 514da71b7e3SCédric Le Goater static uint8_t pnv_xive2_get_block_id(Xive2Router *xrtr) 515da71b7e3SCédric Le Goater { 516da71b7e3SCédric Le Goater return pnv_xive2_block_id(PNV_XIVE2(xrtr)); 517da71b7e3SCédric Le Goater } 518da71b7e3SCédric Le Goater 519da71b7e3SCédric Le Goater /* 520da71b7e3SCédric Le Goater * The TIMA MMIO space is shared among the chips and to identify the 521da71b7e3SCédric Le Goater * chip from which the access is being done, we extract the chip id 522da71b7e3SCédric Le Goater * from the PIR. 523da71b7e3SCédric Le Goater */ 524da71b7e3SCédric Le Goater static PnvXive2 *pnv_xive2_tm_get_xive(PowerPCCPU *cpu) 525da71b7e3SCédric Le Goater { 526da71b7e3SCédric Le Goater int pir = ppc_cpu_pir(cpu); 527da71b7e3SCédric Le Goater XivePresenter *xptr = XIVE_TCTX(pnv_cpu_state(cpu)->intc)->xptr; 528da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(xptr); 529da71b7e3SCédric Le Goater 530da71b7e3SCédric Le Goater if (!pnv_xive2_is_cpu_enabled(xive, cpu)) { 531da71b7e3SCédric Le Goater xive2_error(xive, "IC: CPU %x is not enabled", pir); 532da71b7e3SCédric Le Goater } 533da71b7e3SCédric Le Goater return xive; 534da71b7e3SCédric Le Goater } 535da71b7e3SCédric Le Goater 536da71b7e3SCédric Le Goater /* 537da71b7e3SCédric Le Goater * The internal sources of the interrupt controller have no knowledge 538da71b7e3SCédric Le Goater * of the XIVE2 chip on which they reside. Encode the block id in the 539da71b7e3SCédric Le Goater * source interrupt number before forwarding the source event 540da71b7e3SCédric Le Goater * notification to the Router. This is required on a multichip system. 541da71b7e3SCédric Le Goater */ 5420aa2612aSCédric Le Goater static void pnv_xive2_notify(XiveNotifier *xn, uint32_t srcno, bool pq_checked) 543da71b7e3SCédric Le Goater { 544da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(xn); 545da71b7e3SCédric Le Goater uint8_t blk = pnv_xive2_block_id(xive); 546da71b7e3SCédric Le Goater 5470aa2612aSCédric Le Goater xive2_router_notify(xn, XIVE_EAS(blk, srcno), pq_checked); 548da71b7e3SCédric Le Goater } 549da71b7e3SCédric Le Goater 550da71b7e3SCédric Le Goater /* 551da71b7e3SCédric Le Goater * Set Translation Tables 552da71b7e3SCédric Le Goater * 553da71b7e3SCédric Le Goater * TODO add support for multiple sets 554da71b7e3SCédric Le Goater */ 555da71b7e3SCédric Le Goater static int pnv_xive2_stt_set_data(PnvXive2 *xive, uint64_t val) 556da71b7e3SCédric Le Goater { 557da71b7e3SCédric Le Goater uint8_t tsel = GETFIELD(CQ_TAR_SELECT, xive->cq_regs[CQ_TAR >> 3]); 558da71b7e3SCédric Le Goater uint8_t entry = GETFIELD(CQ_TAR_ENTRY_SELECT, 559da71b7e3SCédric Le Goater xive->cq_regs[CQ_TAR >> 3]); 560da71b7e3SCédric Le Goater 561da71b7e3SCédric Le Goater switch (tsel) { 562da71b7e3SCédric Le Goater case CQ_TAR_NVPG: 563da71b7e3SCédric Le Goater case CQ_TAR_ESB: 564da71b7e3SCédric Le Goater case CQ_TAR_END: 565da71b7e3SCédric Le Goater xive->tables[tsel][entry] = val; 566da71b7e3SCédric Le Goater break; 567da71b7e3SCédric Le Goater default: 568da71b7e3SCédric Le Goater xive2_error(xive, "IC: unsupported table %d", tsel); 569da71b7e3SCédric Le Goater return -1; 570da71b7e3SCédric Le Goater } 571da71b7e3SCédric Le Goater 572da71b7e3SCédric Le Goater if (xive->cq_regs[CQ_TAR >> 3] & CQ_TAR_AUTOINC) { 573da71b7e3SCédric Le Goater xive->cq_regs[CQ_TAR >> 3] = SETFIELD(CQ_TAR_ENTRY_SELECT, 574da71b7e3SCédric Le Goater xive->cq_regs[CQ_TAR >> 3], ++entry); 575da71b7e3SCédric Le Goater } 576da71b7e3SCédric Le Goater 577da71b7e3SCédric Le Goater return 0; 578da71b7e3SCédric Le Goater } 579da71b7e3SCédric Le Goater /* 580da71b7e3SCédric Le Goater * Virtual Structure Tables (VST) configuration 581da71b7e3SCédric Le Goater */ 582da71b7e3SCédric Le Goater static void pnv_xive2_vst_set_exclusive(PnvXive2 *xive, uint8_t type, 583da71b7e3SCédric Le Goater uint8_t blk, uint64_t vsd) 584da71b7e3SCédric Le Goater { 585da71b7e3SCédric Le Goater Xive2EndSource *end_xsrc = &xive->end_source; 586da71b7e3SCédric Le Goater XiveSource *xsrc = &xive->ipi_source; 587da71b7e3SCédric Le Goater const XiveVstInfo *info = &vst_infos[type]; 588da71b7e3SCédric Le Goater uint32_t page_shift = GETFIELD(VSD_TSIZE, vsd) + 12; 589da71b7e3SCédric Le Goater uint64_t vst_tsize = 1ull << page_shift; 590da71b7e3SCédric Le Goater uint64_t vst_addr = vsd & VSD_ADDRESS_MASK; 591da71b7e3SCédric Le Goater 592da71b7e3SCédric Le Goater /* Basic checks */ 593da71b7e3SCédric Le Goater 594da71b7e3SCédric Le Goater if (VSD_INDIRECT & vsd) { 595da71b7e3SCédric Le Goater if (!pnv_xive2_vst_page_size_allowed(page_shift)) { 596da71b7e3SCédric Le Goater xive2_error(xive, "VST: invalid %s page shift %d", info->name, 597da71b7e3SCédric Le Goater page_shift); 598da71b7e3SCédric Le Goater return; 599da71b7e3SCédric Le Goater } 600da71b7e3SCédric Le Goater } 601da71b7e3SCédric Le Goater 602da71b7e3SCédric Le Goater if (!QEMU_IS_ALIGNED(vst_addr, 1ull << page_shift)) { 603da71b7e3SCédric Le Goater xive2_error(xive, "VST: %s table address 0x%"PRIx64 604da71b7e3SCédric Le Goater " is not aligned with page shift %d", 605da71b7e3SCédric Le Goater info->name, vst_addr, page_shift); 606da71b7e3SCédric Le Goater return; 607da71b7e3SCédric Le Goater } 608da71b7e3SCédric Le Goater 609da71b7e3SCédric Le Goater /* Record the table configuration (in SRAM on HW) */ 610da71b7e3SCédric Le Goater xive->vsds[type][blk] = vsd; 611da71b7e3SCédric Le Goater 612da71b7e3SCédric Le Goater /* Now tune the models with the configuration provided by the FW */ 613da71b7e3SCédric Le Goater 614da71b7e3SCédric Le Goater switch (type) { 615da71b7e3SCédric Le Goater case VST_ESB: 616da71b7e3SCédric Le Goater /* 617da71b7e3SCédric Le Goater * Backing store pages for the source PQ bits. The model does 618da71b7e3SCédric Le Goater * not use these PQ bits backed in RAM because the XiveSource 619da71b7e3SCédric Le Goater * model has its own. 620da71b7e3SCédric Le Goater * 621da71b7e3SCédric Le Goater * If the table is direct, we can compute the number of PQ 622da71b7e3SCédric Le Goater * entries provisioned by FW (such as skiboot) and resize the 623da71b7e3SCédric Le Goater * ESB window accordingly. 624da71b7e3SCédric Le Goater */ 625da71b7e3SCédric Le Goater if (!(VSD_INDIRECT & vsd)) { 626da71b7e3SCédric Le Goater memory_region_set_size(&xsrc->esb_mmio, vst_tsize * SBE_PER_BYTE 627da71b7e3SCédric Le Goater * (1ull << xsrc->esb_shift)); 628da71b7e3SCédric Le Goater } 629da71b7e3SCédric Le Goater 630da71b7e3SCédric Le Goater memory_region_add_subregion(&xive->esb_mmio, 0, &xsrc->esb_mmio); 631da71b7e3SCédric Le Goater break; 632da71b7e3SCédric Le Goater 633da71b7e3SCédric Le Goater case VST_EAS: /* Nothing to be done */ 634da71b7e3SCédric Le Goater break; 635da71b7e3SCédric Le Goater 636da71b7e3SCédric Le Goater case VST_END: 637da71b7e3SCédric Le Goater /* 638da71b7e3SCédric Le Goater * Backing store pages for the END. 639da71b7e3SCédric Le Goater */ 640da71b7e3SCédric Le Goater if (!(VSD_INDIRECT & vsd)) { 641da71b7e3SCédric Le Goater memory_region_set_size(&end_xsrc->esb_mmio, (vst_tsize / info->size) 642da71b7e3SCédric Le Goater * (1ull << end_xsrc->esb_shift)); 643da71b7e3SCédric Le Goater } 644da71b7e3SCédric Le Goater memory_region_add_subregion(&xive->end_mmio, 0, &end_xsrc->esb_mmio); 645da71b7e3SCédric Le Goater break; 646da71b7e3SCédric Le Goater 647da71b7e3SCédric Le Goater case VST_NVP: /* Not modeled */ 648da71b7e3SCédric Le Goater case VST_NVG: /* Not modeled */ 649da71b7e3SCédric Le Goater case VST_NVC: /* Not modeled */ 650da71b7e3SCédric Le Goater case VST_IC: /* Not modeled */ 651da71b7e3SCédric Le Goater case VST_SYNC: /* Not modeled */ 652da71b7e3SCédric Le Goater case VST_ERQ: /* Not modeled */ 653da71b7e3SCédric Le Goater break; 654da71b7e3SCédric Le Goater 655da71b7e3SCédric Le Goater default: 656da71b7e3SCédric Le Goater g_assert_not_reached(); 657da71b7e3SCédric Le Goater } 658da71b7e3SCédric Le Goater } 659da71b7e3SCédric Le Goater 660da71b7e3SCédric Le Goater /* 661da71b7e3SCédric Le Goater * Both PC and VC sub-engines are configured as each use the Virtual 662da71b7e3SCédric Le Goater * Structure Tables 663da71b7e3SCédric Le Goater */ 664da71b7e3SCédric Le Goater static void pnv_xive2_vst_set_data(PnvXive2 *xive, uint64_t vsd) 665da71b7e3SCédric Le Goater { 666da71b7e3SCédric Le Goater uint8_t mode = GETFIELD(VSD_MODE, vsd); 667da71b7e3SCédric Le Goater uint8_t type = GETFIELD(VC_VSD_TABLE_SELECT, 668da71b7e3SCédric Le Goater xive->vc_regs[VC_VSD_TABLE_ADDR >> 3]); 669da71b7e3SCédric Le Goater uint8_t blk = GETFIELD(VC_VSD_TABLE_ADDRESS, 670da71b7e3SCédric Le Goater xive->vc_regs[VC_VSD_TABLE_ADDR >> 3]); 671da71b7e3SCédric Le Goater uint64_t vst_addr = vsd & VSD_ADDRESS_MASK; 672da71b7e3SCédric Le Goater 673da71b7e3SCédric Le Goater if (type > VST_ERQ) { 674da71b7e3SCédric Le Goater xive2_error(xive, "VST: invalid table type %d", type); 675da71b7e3SCédric Le Goater return; 676da71b7e3SCédric Le Goater } 677da71b7e3SCédric Le Goater 678da71b7e3SCédric Le Goater if (blk >= vst_infos[type].max_blocks) { 679da71b7e3SCédric Le Goater xive2_error(xive, "VST: invalid block id %d for" 680da71b7e3SCédric Le Goater " %s table", blk, vst_infos[type].name); 681da71b7e3SCédric Le Goater return; 682da71b7e3SCédric Le Goater } 683da71b7e3SCédric Le Goater 684da71b7e3SCédric Le Goater if (!vst_addr) { 685da71b7e3SCédric Le Goater xive2_error(xive, "VST: invalid %s table address", 686da71b7e3SCédric Le Goater vst_infos[type].name); 687da71b7e3SCédric Le Goater return; 688da71b7e3SCédric Le Goater } 689da71b7e3SCédric Le Goater 690da71b7e3SCédric Le Goater switch (mode) { 691da71b7e3SCédric Le Goater case VSD_MODE_FORWARD: 692da71b7e3SCédric Le Goater xive->vsds[type][blk] = vsd; 693da71b7e3SCédric Le Goater break; 694da71b7e3SCédric Le Goater 695da71b7e3SCédric Le Goater case VSD_MODE_EXCLUSIVE: 696da71b7e3SCédric Le Goater pnv_xive2_vst_set_exclusive(xive, type, blk, vsd); 697da71b7e3SCédric Le Goater break; 698da71b7e3SCédric Le Goater 699da71b7e3SCédric Le Goater default: 700da71b7e3SCédric Le Goater xive2_error(xive, "VST: unsupported table mode %d", mode); 701da71b7e3SCédric Le Goater return; 702da71b7e3SCédric Le Goater } 703da71b7e3SCédric Le Goater } 704da71b7e3SCédric Le Goater 705da71b7e3SCédric Le Goater /* 706da71b7e3SCédric Le Goater * MMIO handlers 707da71b7e3SCédric Le Goater */ 708da71b7e3SCédric Le Goater 709da71b7e3SCédric Le Goater 710da71b7e3SCédric Le Goater /* 711da71b7e3SCédric Le Goater * IC BAR layout 712da71b7e3SCédric Le Goater * 713da71b7e3SCédric Le Goater * Page 0: Internal CQ register accesses (reads & writes) 714da71b7e3SCédric Le Goater * Page 1: Internal PC register accesses (reads & writes) 715da71b7e3SCédric Le Goater * Page 2: Internal VC register accesses (reads & writes) 716da71b7e3SCédric Le Goater * Page 3: Internal TCTXT (TIMA) reg accesses (read & writes) 717da71b7e3SCédric Le Goater * Page 4: Notify Port page (writes only, w/data), 718da71b7e3SCédric Le Goater * Page 5: Reserved 719da71b7e3SCédric Le Goater * Page 6: Sync Poll page (writes only, dataless) 720da71b7e3SCédric Le Goater * Page 7: Sync Inject page (writes only, dataless) 721da71b7e3SCédric Le Goater * Page 8: LSI Trigger page (writes only, dataless) 722da71b7e3SCédric Le Goater * Page 9: LSI SB Management page (reads & writes dataless) 723da71b7e3SCédric Le Goater * Pages 10-255: Reserved 724da71b7e3SCédric Le Goater * Pages 256-383: Direct mapped Thread Context Area (reads & writes) 725da71b7e3SCédric Le Goater * covering the 128 threads in P10. 726da71b7e3SCédric Le Goater * Pages 384-511: Reserved 727da71b7e3SCédric Le Goater */ 728da71b7e3SCédric Le Goater typedef struct PnvXive2Region { 729da71b7e3SCédric Le Goater const char *name; 730da71b7e3SCédric Le Goater uint32_t pgoff; 731da71b7e3SCédric Le Goater uint32_t pgsize; 732da71b7e3SCédric Le Goater const MemoryRegionOps *ops; 733da71b7e3SCédric Le Goater } PnvXive2Region; 734da71b7e3SCédric Le Goater 735da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_ic_cq_ops; 736da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_ic_pc_ops; 737da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_ic_vc_ops; 738da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_ic_tctxt_ops; 739da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_ic_notify_ops; 740da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_ic_sync_ops; 741da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_ic_lsi_ops; 742da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_ic_tm_indirect_ops; 743da71b7e3SCédric Le Goater 744da71b7e3SCédric Le Goater /* 512 pages. 4K: 2M range, 64K: 32M range */ 745da71b7e3SCédric Le Goater static const PnvXive2Region pnv_xive2_ic_regions[] = { 746da71b7e3SCédric Le Goater { "xive-ic-cq", 0, 1, &pnv_xive2_ic_cq_ops }, 747da71b7e3SCédric Le Goater { "xive-ic-vc", 1, 1, &pnv_xive2_ic_vc_ops }, 748da71b7e3SCédric Le Goater { "xive-ic-pc", 2, 1, &pnv_xive2_ic_pc_ops }, 749da71b7e3SCédric Le Goater { "xive-ic-tctxt", 3, 1, &pnv_xive2_ic_tctxt_ops }, 750da71b7e3SCédric Le Goater { "xive-ic-notify", 4, 1, &pnv_xive2_ic_notify_ops }, 751da71b7e3SCédric Le Goater /* page 5 reserved */ 752da71b7e3SCédric Le Goater { "xive-ic-sync", 6, 2, &pnv_xive2_ic_sync_ops }, 753da71b7e3SCédric Le Goater { "xive-ic-lsi", 8, 2, &pnv_xive2_ic_lsi_ops }, 754da71b7e3SCédric Le Goater /* pages 10-255 reserved */ 755da71b7e3SCédric Le Goater { "xive-ic-tm-indirect", 256, 128, &pnv_xive2_ic_tm_indirect_ops }, 756da71b7e3SCédric Le Goater /* pages 384-511 reserved */ 757da71b7e3SCédric Le Goater }; 758da71b7e3SCédric Le Goater 759da71b7e3SCédric Le Goater /* 760da71b7e3SCédric Le Goater * CQ operations 761da71b7e3SCédric Le Goater */ 762da71b7e3SCédric Le Goater 763da71b7e3SCédric Le Goater static uint64_t pnv_xive2_ic_cq_read(void *opaque, hwaddr offset, 764da71b7e3SCédric Le Goater unsigned size) 765da71b7e3SCédric Le Goater { 766da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 767da71b7e3SCédric Le Goater uint32_t reg = offset >> 3; 768da71b7e3SCédric Le Goater uint64_t val = 0; 769da71b7e3SCédric Le Goater 770da71b7e3SCédric Le Goater switch (offset) { 771da71b7e3SCédric Le Goater case CQ_XIVE_CAP: /* Set at reset */ 772da71b7e3SCédric Le Goater case CQ_XIVE_CFG: 773da71b7e3SCédric Le Goater val = xive->cq_regs[reg]; 774da71b7e3SCédric Le Goater break; 775da71b7e3SCédric Le Goater case CQ_MSGSND: /* TODO check the #cores of the machine */ 776da71b7e3SCédric Le Goater val = 0xffffffff00000000; 777da71b7e3SCédric Le Goater break; 778da71b7e3SCédric Le Goater case CQ_CFG_PB_GEN: 779da71b7e3SCédric Le Goater val = CQ_CFG_PB_GEN_PB_INIT; /* TODO: fix CQ_CFG_PB_GEN default value */ 780da71b7e3SCédric Le Goater break; 781da71b7e3SCédric Le Goater default: 782da71b7e3SCédric Le Goater xive2_error(xive, "CQ: invalid read @%"HWADDR_PRIx, offset); 783da71b7e3SCédric Le Goater } 784da71b7e3SCédric Le Goater 785da71b7e3SCédric Le Goater return val; 786da71b7e3SCédric Le Goater } 787da71b7e3SCédric Le Goater 788da71b7e3SCédric Le Goater static uint64_t pnv_xive2_bar_size(uint64_t val) 789da71b7e3SCédric Le Goater { 790da71b7e3SCédric Le Goater return 1ull << (GETFIELD(CQ_BAR_RANGE, val) + 24); 791da71b7e3SCédric Le Goater } 792da71b7e3SCédric Le Goater 793da71b7e3SCédric Le Goater static void pnv_xive2_ic_cq_write(void *opaque, hwaddr offset, 794da71b7e3SCédric Le Goater uint64_t val, unsigned size) 795da71b7e3SCédric Le Goater { 796da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 797da71b7e3SCédric Le Goater MemoryRegion *sysmem = get_system_memory(); 798da71b7e3SCédric Le Goater uint32_t reg = offset >> 3; 799da71b7e3SCédric Le Goater int i; 800da71b7e3SCédric Le Goater 801da71b7e3SCédric Le Goater switch (offset) { 802da71b7e3SCédric Le Goater case CQ_XIVE_CFG: 803da71b7e3SCédric Le Goater case CQ_RST_CTL: /* TODO: reset all BARs */ 804da71b7e3SCédric Le Goater break; 805da71b7e3SCédric Le Goater 806da71b7e3SCédric Le Goater case CQ_IC_BAR: 807da71b7e3SCédric Le Goater xive->ic_shift = val & CQ_IC_BAR_64K ? 16 : 12; 808da71b7e3SCédric Le Goater if (!(val & CQ_IC_BAR_VALID)) { 809da71b7e3SCédric Le Goater xive->ic_base = 0; 810da71b7e3SCédric Le Goater if (xive->cq_regs[reg] & CQ_IC_BAR_VALID) { 811da71b7e3SCédric Le Goater for (i = 0; i < ARRAY_SIZE(xive->ic_mmios); i++) { 812da71b7e3SCédric Le Goater memory_region_del_subregion(&xive->ic_mmio, 813da71b7e3SCédric Le Goater &xive->ic_mmios[i]); 814da71b7e3SCédric Le Goater } 815da71b7e3SCédric Le Goater memory_region_del_subregion(sysmem, &xive->ic_mmio); 816da71b7e3SCédric Le Goater } 817da71b7e3SCédric Le Goater } else { 818da71b7e3SCédric Le Goater xive->ic_base = val & ~(CQ_IC_BAR_VALID | CQ_IC_BAR_64K); 819da71b7e3SCédric Le Goater if (!(xive->cq_regs[reg] & CQ_IC_BAR_VALID)) { 820da71b7e3SCédric Le Goater for (i = 0; i < ARRAY_SIZE(xive->ic_mmios); i++) { 821da71b7e3SCédric Le Goater memory_region_add_subregion(&xive->ic_mmio, 822da71b7e3SCédric Le Goater pnv_xive2_ic_regions[i].pgoff << xive->ic_shift, 823da71b7e3SCédric Le Goater &xive->ic_mmios[i]); 824da71b7e3SCédric Le Goater } 825da71b7e3SCédric Le Goater memory_region_add_subregion(sysmem, xive->ic_base, 826da71b7e3SCédric Le Goater &xive->ic_mmio); 827da71b7e3SCédric Le Goater } 828da71b7e3SCédric Le Goater } 829da71b7e3SCédric Le Goater break; 830da71b7e3SCédric Le Goater 831da71b7e3SCédric Le Goater case CQ_TM_BAR: 832da71b7e3SCédric Le Goater xive->tm_shift = val & CQ_TM_BAR_64K ? 16 : 12; 833da71b7e3SCédric Le Goater if (!(val & CQ_TM_BAR_VALID)) { 834da71b7e3SCédric Le Goater xive->tm_base = 0; 835da71b7e3SCédric Le Goater if (xive->cq_regs[reg] & CQ_TM_BAR_VALID) { 836da71b7e3SCédric Le Goater memory_region_del_subregion(sysmem, &xive->tm_mmio); 837da71b7e3SCédric Le Goater } 838da71b7e3SCédric Le Goater } else { 839da71b7e3SCédric Le Goater xive->tm_base = val & ~(CQ_TM_BAR_VALID | CQ_TM_BAR_64K); 840da71b7e3SCédric Le Goater if (!(xive->cq_regs[reg] & CQ_TM_BAR_VALID)) { 841da71b7e3SCédric Le Goater memory_region_add_subregion(sysmem, xive->tm_base, 842da71b7e3SCédric Le Goater &xive->tm_mmio); 843da71b7e3SCédric Le Goater } 844da71b7e3SCédric Le Goater } 845da71b7e3SCédric Le Goater break; 846da71b7e3SCédric Le Goater 847da71b7e3SCédric Le Goater case CQ_ESB_BAR: 848da71b7e3SCédric Le Goater xive->esb_shift = val & CQ_BAR_64K ? 16 : 12; 849da71b7e3SCédric Le Goater if (!(val & CQ_BAR_VALID)) { 850da71b7e3SCédric Le Goater xive->esb_base = 0; 851da71b7e3SCédric Le Goater if (xive->cq_regs[reg] & CQ_BAR_VALID) { 852da71b7e3SCédric Le Goater memory_region_del_subregion(sysmem, &xive->esb_mmio); 853da71b7e3SCédric Le Goater } 854da71b7e3SCédric Le Goater } else { 855da71b7e3SCédric Le Goater xive->esb_base = val & CQ_BAR_ADDR; 856da71b7e3SCédric Le Goater if (!(xive->cq_regs[reg] & CQ_BAR_VALID)) { 857da71b7e3SCédric Le Goater memory_region_set_size(&xive->esb_mmio, 858da71b7e3SCédric Le Goater pnv_xive2_bar_size(val)); 859da71b7e3SCédric Le Goater memory_region_add_subregion(sysmem, xive->esb_base, 860da71b7e3SCédric Le Goater &xive->esb_mmio); 861da71b7e3SCédric Le Goater } 862da71b7e3SCédric Le Goater } 863da71b7e3SCédric Le Goater break; 864da71b7e3SCédric Le Goater 865da71b7e3SCédric Le Goater case CQ_END_BAR: 866da71b7e3SCédric Le Goater xive->end_shift = val & CQ_BAR_64K ? 16 : 12; 867da71b7e3SCédric Le Goater if (!(val & CQ_BAR_VALID)) { 868da71b7e3SCédric Le Goater xive->end_base = 0; 869da71b7e3SCédric Le Goater if (xive->cq_regs[reg] & CQ_BAR_VALID) { 870da71b7e3SCédric Le Goater memory_region_del_subregion(sysmem, &xive->end_mmio); 871da71b7e3SCédric Le Goater } 872da71b7e3SCédric Le Goater } else { 873da71b7e3SCédric Le Goater xive->end_base = val & CQ_BAR_ADDR; 874da71b7e3SCédric Le Goater if (!(xive->cq_regs[reg] & CQ_BAR_VALID)) { 875da71b7e3SCédric Le Goater memory_region_set_size(&xive->end_mmio, 876da71b7e3SCédric Le Goater pnv_xive2_bar_size(val)); 877da71b7e3SCédric Le Goater memory_region_add_subregion(sysmem, xive->end_base, 878da71b7e3SCédric Le Goater &xive->end_mmio); 879da71b7e3SCédric Le Goater } 880da71b7e3SCédric Le Goater } 881da71b7e3SCédric Le Goater break; 882da71b7e3SCédric Le Goater 883da71b7e3SCédric Le Goater case CQ_NVC_BAR: 884da71b7e3SCédric Le Goater xive->nvc_shift = val & CQ_BAR_64K ? 16 : 12; 885da71b7e3SCédric Le Goater if (!(val & CQ_BAR_VALID)) { 886da71b7e3SCédric Le Goater xive->nvc_base = 0; 887da71b7e3SCédric Le Goater if (xive->cq_regs[reg] & CQ_BAR_VALID) { 888da71b7e3SCédric Le Goater memory_region_del_subregion(sysmem, &xive->nvc_mmio); 889da71b7e3SCédric Le Goater } 890da71b7e3SCédric Le Goater } else { 891da71b7e3SCédric Le Goater xive->nvc_base = val & CQ_BAR_ADDR; 892da71b7e3SCédric Le Goater if (!(xive->cq_regs[reg] & CQ_BAR_VALID)) { 893da71b7e3SCédric Le Goater memory_region_set_size(&xive->nvc_mmio, 894da71b7e3SCédric Le Goater pnv_xive2_bar_size(val)); 895da71b7e3SCédric Le Goater memory_region_add_subregion(sysmem, xive->nvc_base, 896da71b7e3SCédric Le Goater &xive->nvc_mmio); 897da71b7e3SCédric Le Goater } 898da71b7e3SCédric Le Goater } 899da71b7e3SCédric Le Goater break; 900da71b7e3SCédric Le Goater 901da71b7e3SCédric Le Goater case CQ_NVPG_BAR: 902da71b7e3SCédric Le Goater xive->nvpg_shift = val & CQ_BAR_64K ? 16 : 12; 903da71b7e3SCédric Le Goater if (!(val & CQ_BAR_VALID)) { 904da71b7e3SCédric Le Goater xive->nvpg_base = 0; 905da71b7e3SCédric Le Goater if (xive->cq_regs[reg] & CQ_BAR_VALID) { 906da71b7e3SCédric Le Goater memory_region_del_subregion(sysmem, &xive->nvpg_mmio); 907da71b7e3SCédric Le Goater } 908da71b7e3SCédric Le Goater } else { 909da71b7e3SCédric Le Goater xive->nvpg_base = val & CQ_BAR_ADDR; 910da71b7e3SCédric Le Goater if (!(xive->cq_regs[reg] & CQ_BAR_VALID)) { 911da71b7e3SCédric Le Goater memory_region_set_size(&xive->nvpg_mmio, 912da71b7e3SCédric Le Goater pnv_xive2_bar_size(val)); 913da71b7e3SCédric Le Goater memory_region_add_subregion(sysmem, xive->nvpg_base, 914da71b7e3SCédric Le Goater &xive->nvpg_mmio); 915da71b7e3SCédric Le Goater } 916da71b7e3SCédric Le Goater } 917da71b7e3SCédric Le Goater break; 918da71b7e3SCédric Le Goater 919da71b7e3SCédric Le Goater case CQ_TAR: /* Set Translation Table Address */ 920da71b7e3SCédric Le Goater break; 921da71b7e3SCédric Le Goater case CQ_TDR: /* Set Translation Table Data */ 922da71b7e3SCédric Le Goater pnv_xive2_stt_set_data(xive, val); 923da71b7e3SCédric Le Goater break; 924da71b7e3SCédric Le Goater case CQ_FIRMASK_OR: /* FIR error reporting */ 925da71b7e3SCédric Le Goater break; 926da71b7e3SCédric Le Goater default: 927da71b7e3SCédric Le Goater xive2_error(xive, "CQ: invalid write 0x%"HWADDR_PRIx, offset); 928da71b7e3SCédric Le Goater return; 929da71b7e3SCédric Le Goater } 930da71b7e3SCédric Le Goater 931da71b7e3SCédric Le Goater xive->cq_regs[reg] = val; 932da71b7e3SCédric Le Goater } 933da71b7e3SCédric Le Goater 934da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_ic_cq_ops = { 935da71b7e3SCédric Le Goater .read = pnv_xive2_ic_cq_read, 936da71b7e3SCédric Le Goater .write = pnv_xive2_ic_cq_write, 937da71b7e3SCédric Le Goater .endianness = DEVICE_BIG_ENDIAN, 938da71b7e3SCédric Le Goater .valid = { 939da71b7e3SCédric Le Goater .min_access_size = 8, 940da71b7e3SCédric Le Goater .max_access_size = 8, 941da71b7e3SCédric Le Goater }, 942da71b7e3SCédric Le Goater .impl = { 943da71b7e3SCédric Le Goater .min_access_size = 8, 944da71b7e3SCédric Le Goater .max_access_size = 8, 945da71b7e3SCédric Le Goater }, 946da71b7e3SCédric Le Goater }; 947da71b7e3SCédric Le Goater 948da71b7e3SCédric Le Goater static uint64_t pnv_xive2_ic_vc_read(void *opaque, hwaddr offset, 949da71b7e3SCédric Le Goater unsigned size) 950da71b7e3SCédric Le Goater { 951da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 952da71b7e3SCédric Le Goater uint64_t val = 0; 953da71b7e3SCédric Le Goater uint32_t reg = offset >> 3; 954da71b7e3SCédric Le Goater 955da71b7e3SCédric Le Goater switch (offset) { 956da71b7e3SCédric Le Goater /* 957da71b7e3SCédric Le Goater * VSD table settings. 958da71b7e3SCédric Le Goater */ 959da71b7e3SCédric Le Goater case VC_VSD_TABLE_ADDR: 960da71b7e3SCédric Le Goater case VC_VSD_TABLE_DATA: 961da71b7e3SCédric Le Goater val = xive->vc_regs[reg]; 962da71b7e3SCédric Le Goater break; 963da71b7e3SCédric Le Goater 964da71b7e3SCédric Le Goater /* 965da71b7e3SCédric Le Goater * ESB cache updates (not modeled) 966da71b7e3SCédric Le Goater */ 967da71b7e3SCédric Le Goater case VC_ESBC_FLUSH_CTRL: 968da71b7e3SCédric Le Goater xive->vc_regs[reg] &= ~VC_ESBC_FLUSH_CTRL_POLL_VALID; 969da71b7e3SCédric Le Goater val = xive->vc_regs[reg]; 970da71b7e3SCédric Le Goater break; 971da71b7e3SCédric Le Goater 972da71b7e3SCédric Le Goater /* 973da71b7e3SCédric Le Goater * EAS cache updates (not modeled) 974da71b7e3SCédric Le Goater */ 975da71b7e3SCédric Le Goater case VC_EASC_FLUSH_CTRL: 976da71b7e3SCédric Le Goater xive->vc_regs[reg] &= ~VC_EASC_FLUSH_CTRL_POLL_VALID; 977da71b7e3SCédric Le Goater val = xive->vc_regs[reg]; 978da71b7e3SCédric Le Goater break; 979da71b7e3SCédric Le Goater 980da71b7e3SCédric Le Goater /* 981da71b7e3SCédric Le Goater * END cache updates 982da71b7e3SCédric Le Goater */ 983da71b7e3SCédric Le Goater case VC_ENDC_WATCH0_SPEC: 984da71b7e3SCédric Le Goater xive->vc_regs[reg] &= ~(VC_ENDC_WATCH_FULL | VC_ENDC_WATCH_CONFLICT); 985da71b7e3SCédric Le Goater val = xive->vc_regs[reg]; 986da71b7e3SCédric Le Goater break; 987da71b7e3SCédric Le Goater 988da71b7e3SCédric Le Goater case VC_ENDC_WATCH0_DATA0: 989da71b7e3SCédric Le Goater /* 990da71b7e3SCédric Le Goater * Load DATA registers from cache with data requested by the 991da71b7e3SCédric Le Goater * SPEC register 992da71b7e3SCédric Le Goater */ 993da71b7e3SCédric Le Goater pnv_xive2_end_cache_load(xive); 994da71b7e3SCédric Le Goater val = xive->vc_regs[reg]; 995da71b7e3SCédric Le Goater break; 996da71b7e3SCédric Le Goater 997da71b7e3SCédric Le Goater case VC_ENDC_WATCH0_DATA1 ... VC_ENDC_WATCH0_DATA3: 998da71b7e3SCédric Le Goater val = xive->vc_regs[reg]; 999da71b7e3SCédric Le Goater break; 1000da71b7e3SCédric Le Goater 1001da71b7e3SCédric Le Goater case VC_ENDC_FLUSH_CTRL: 1002da71b7e3SCédric Le Goater xive->vc_regs[reg] &= ~VC_ENDC_FLUSH_CTRL_POLL_VALID; 1003da71b7e3SCédric Le Goater val = xive->vc_regs[reg]; 1004da71b7e3SCédric Le Goater break; 1005da71b7e3SCédric Le Goater 1006da71b7e3SCédric Le Goater /* 1007da71b7e3SCédric Le Goater * Indirect invalidation 1008da71b7e3SCédric Le Goater */ 1009da71b7e3SCédric Le Goater case VC_AT_MACRO_KILL_MASK: 1010da71b7e3SCédric Le Goater val = xive->vc_regs[reg]; 1011da71b7e3SCédric Le Goater break; 1012da71b7e3SCédric Le Goater 1013da71b7e3SCédric Le Goater case VC_AT_MACRO_KILL: 1014da71b7e3SCédric Le Goater xive->vc_regs[reg] &= ~VC_AT_MACRO_KILL_VALID; 1015da71b7e3SCédric Le Goater val = xive->vc_regs[reg]; 1016da71b7e3SCédric Le Goater break; 1017da71b7e3SCédric Le Goater 1018da71b7e3SCédric Le Goater /* 1019da71b7e3SCédric Le Goater * Interrupt fifo overflow in memory backing store (Not modeled) 1020da71b7e3SCédric Le Goater */ 1021da71b7e3SCédric Le Goater case VC_QUEUES_CFG_REM0 ... VC_QUEUES_CFG_REM6: 1022da71b7e3SCédric Le Goater val = xive->vc_regs[reg]; 1023da71b7e3SCédric Le Goater break; 1024da71b7e3SCédric Le Goater 1025da71b7e3SCédric Le Goater /* 1026da71b7e3SCédric Le Goater * Synchronisation 1027da71b7e3SCédric Le Goater */ 1028da71b7e3SCédric Le Goater case VC_ENDC_SYNC_DONE: 1029da71b7e3SCédric Le Goater val = VC_ENDC_SYNC_POLL_DONE; 1030da71b7e3SCédric Le Goater break; 1031da71b7e3SCédric Le Goater default: 1032da71b7e3SCédric Le Goater xive2_error(xive, "VC: invalid read @%"HWADDR_PRIx, offset); 1033da71b7e3SCédric Le Goater } 1034da71b7e3SCédric Le Goater 1035da71b7e3SCédric Le Goater return val; 1036da71b7e3SCédric Le Goater } 1037da71b7e3SCédric Le Goater 1038da71b7e3SCédric Le Goater static void pnv_xive2_ic_vc_write(void *opaque, hwaddr offset, 1039da71b7e3SCédric Le Goater uint64_t val, unsigned size) 1040da71b7e3SCédric Le Goater { 1041da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1042da71b7e3SCédric Le Goater uint32_t reg = offset >> 3; 1043da71b7e3SCédric Le Goater 1044da71b7e3SCédric Le Goater switch (offset) { 1045da71b7e3SCédric Le Goater /* 1046da71b7e3SCédric Le Goater * VSD table settings. 1047da71b7e3SCédric Le Goater */ 1048da71b7e3SCédric Le Goater case VC_VSD_TABLE_ADDR: 1049da71b7e3SCédric Le Goater break; 1050da71b7e3SCédric Le Goater case VC_VSD_TABLE_DATA: 1051da71b7e3SCédric Le Goater pnv_xive2_vst_set_data(xive, val); 1052da71b7e3SCédric Le Goater break; 1053da71b7e3SCédric Le Goater 1054da71b7e3SCédric Le Goater /* 1055da71b7e3SCédric Le Goater * ESB cache updates (not modeled) 1056da71b7e3SCédric Le Goater */ 1057da71b7e3SCédric Le Goater /* case VC_ESBC_FLUSH_CTRL: */ 1058da71b7e3SCédric Le Goater case VC_ESBC_FLUSH_POLL: 1059da71b7e3SCédric Le Goater xive->vc_regs[VC_ESBC_FLUSH_CTRL >> 3] |= VC_ESBC_FLUSH_CTRL_POLL_VALID; 1060da71b7e3SCédric Le Goater /* ESB update */ 1061da71b7e3SCédric Le Goater break; 1062da71b7e3SCédric Le Goater 1063da71b7e3SCédric Le Goater /* 1064da71b7e3SCédric Le Goater * EAS cache updates (not modeled) 1065da71b7e3SCédric Le Goater */ 1066da71b7e3SCédric Le Goater /* case VC_EASC_FLUSH_CTRL: */ 1067da71b7e3SCédric Le Goater case VC_EASC_FLUSH_POLL: 1068da71b7e3SCédric Le Goater xive->vc_regs[VC_EASC_FLUSH_CTRL >> 3] |= VC_EASC_FLUSH_CTRL_POLL_VALID; 1069da71b7e3SCédric Le Goater /* EAS update */ 1070da71b7e3SCédric Le Goater break; 1071da71b7e3SCédric Le Goater 1072da71b7e3SCédric Le Goater /* 1073da71b7e3SCédric Le Goater * END cache updates 1074da71b7e3SCédric Le Goater */ 1075da71b7e3SCédric Le Goater case VC_ENDC_WATCH0_SPEC: 1076da71b7e3SCédric Le Goater val &= ~VC_ENDC_WATCH_CONFLICT; /* HW will set this bit */ 1077da71b7e3SCédric Le Goater break; 1078da71b7e3SCédric Le Goater 1079da71b7e3SCédric Le Goater case VC_ENDC_WATCH0_DATA1 ... VC_ENDC_WATCH0_DATA3: 1080da71b7e3SCédric Le Goater break; 1081da71b7e3SCédric Le Goater case VC_ENDC_WATCH0_DATA0: 1082da71b7e3SCédric Le Goater /* writing to DATA0 triggers the cache write */ 1083da71b7e3SCédric Le Goater xive->vc_regs[reg] = val; 1084da71b7e3SCédric Le Goater pnv_xive2_end_update(xive); 1085da71b7e3SCédric Le Goater break; 1086da71b7e3SCédric Le Goater 1087da71b7e3SCédric Le Goater 1088da71b7e3SCédric Le Goater /* case VC_ENDC_FLUSH_CTRL: */ 1089da71b7e3SCédric Le Goater case VC_ENDC_FLUSH_POLL: 1090da71b7e3SCédric Le Goater xive->vc_regs[VC_ENDC_FLUSH_CTRL >> 3] |= VC_ENDC_FLUSH_CTRL_POLL_VALID; 1091da71b7e3SCédric Le Goater break; 1092da71b7e3SCédric Le Goater 1093da71b7e3SCédric Le Goater /* 1094da71b7e3SCédric Le Goater * Indirect invalidation 1095da71b7e3SCédric Le Goater */ 1096da71b7e3SCédric Le Goater case VC_AT_MACRO_KILL: 1097da71b7e3SCédric Le Goater case VC_AT_MACRO_KILL_MASK: 1098da71b7e3SCédric Le Goater break; 1099da71b7e3SCédric Le Goater 1100da71b7e3SCédric Le Goater /* 1101da71b7e3SCédric Le Goater * Interrupt fifo overflow in memory backing store (Not modeled) 1102da71b7e3SCédric Le Goater */ 1103da71b7e3SCédric Le Goater case VC_QUEUES_CFG_REM0 ... VC_QUEUES_CFG_REM6: 1104da71b7e3SCédric Le Goater break; 1105da71b7e3SCédric Le Goater 1106da71b7e3SCédric Le Goater /* 1107da71b7e3SCédric Le Goater * Synchronisation 1108da71b7e3SCédric Le Goater */ 1109da71b7e3SCédric Le Goater case VC_ENDC_SYNC_DONE: 1110da71b7e3SCédric Le Goater break; 1111da71b7e3SCédric Le Goater 1112da71b7e3SCédric Le Goater default: 1113da71b7e3SCédric Le Goater xive2_error(xive, "VC: invalid write @%"HWADDR_PRIx, offset); 1114da71b7e3SCédric Le Goater return; 1115da71b7e3SCédric Le Goater } 1116da71b7e3SCédric Le Goater 1117da71b7e3SCédric Le Goater xive->vc_regs[reg] = val; 1118da71b7e3SCédric Le Goater } 1119da71b7e3SCédric Le Goater 1120da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_ic_vc_ops = { 1121da71b7e3SCédric Le Goater .read = pnv_xive2_ic_vc_read, 1122da71b7e3SCédric Le Goater .write = pnv_xive2_ic_vc_write, 1123da71b7e3SCédric Le Goater .endianness = DEVICE_BIG_ENDIAN, 1124da71b7e3SCédric Le Goater .valid = { 1125da71b7e3SCédric Le Goater .min_access_size = 8, 1126da71b7e3SCédric Le Goater .max_access_size = 8, 1127da71b7e3SCédric Le Goater }, 1128da71b7e3SCédric Le Goater .impl = { 1129da71b7e3SCédric Le Goater .min_access_size = 8, 1130da71b7e3SCédric Le Goater .max_access_size = 8, 1131da71b7e3SCédric Le Goater }, 1132da71b7e3SCédric Le Goater }; 1133da71b7e3SCédric Le Goater 1134da71b7e3SCédric Le Goater static uint64_t pnv_xive2_ic_pc_read(void *opaque, hwaddr offset, 1135da71b7e3SCédric Le Goater unsigned size) 1136da71b7e3SCédric Le Goater { 1137da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1138da71b7e3SCédric Le Goater uint64_t val = -1; 1139da71b7e3SCédric Le Goater uint32_t reg = offset >> 3; 1140da71b7e3SCédric Le Goater 1141da71b7e3SCédric Le Goater switch (offset) { 1142da71b7e3SCédric Le Goater /* 1143da71b7e3SCédric Le Goater * VSD table settings. 1144da71b7e3SCédric Le Goater */ 1145da71b7e3SCédric Le Goater case PC_VSD_TABLE_ADDR: 1146da71b7e3SCédric Le Goater case PC_VSD_TABLE_DATA: 1147da71b7e3SCédric Le Goater val = xive->pc_regs[reg]; 1148da71b7e3SCédric Le Goater break; 1149da71b7e3SCédric Le Goater 1150da71b7e3SCédric Le Goater /* 1151da71b7e3SCédric Le Goater * cache updates 1152da71b7e3SCédric Le Goater */ 1153da71b7e3SCédric Le Goater case PC_NXC_WATCH0_SPEC: 1154da71b7e3SCédric Le Goater xive->pc_regs[reg] &= ~(PC_NXC_WATCH_FULL | PC_NXC_WATCH_CONFLICT); 1155da71b7e3SCédric Le Goater val = xive->pc_regs[reg]; 1156da71b7e3SCédric Le Goater break; 1157da71b7e3SCédric Le Goater 1158da71b7e3SCédric Le Goater case PC_NXC_WATCH0_DATA0: 1159da71b7e3SCédric Le Goater /* 1160da71b7e3SCédric Le Goater * Load DATA registers from cache with data requested by the 1161da71b7e3SCédric Le Goater * SPEC register 1162da71b7e3SCédric Le Goater */ 1163da71b7e3SCédric Le Goater pnv_xive2_nvp_cache_load(xive); 1164da71b7e3SCédric Le Goater val = xive->pc_regs[reg]; 1165da71b7e3SCédric Le Goater break; 1166da71b7e3SCédric Le Goater 1167da71b7e3SCédric Le Goater case PC_NXC_WATCH0_DATA1 ... PC_NXC_WATCH0_DATA3: 1168da71b7e3SCédric Le Goater val = xive->pc_regs[reg]; 1169da71b7e3SCédric Le Goater break; 1170da71b7e3SCédric Le Goater 1171da71b7e3SCédric Le Goater case PC_NXC_FLUSH_CTRL: 1172da71b7e3SCédric Le Goater xive->pc_regs[reg] &= ~PC_NXC_FLUSH_CTRL_POLL_VALID; 1173da71b7e3SCédric Le Goater val = xive->pc_regs[reg]; 1174da71b7e3SCédric Le Goater break; 1175da71b7e3SCédric Le Goater 1176da71b7e3SCédric Le Goater /* 1177da71b7e3SCédric Le Goater * Indirect invalidation 1178da71b7e3SCédric Le Goater */ 1179da71b7e3SCédric Le Goater case PC_AT_KILL: 1180da71b7e3SCédric Le Goater xive->pc_regs[reg] &= ~PC_AT_KILL_VALID; 1181da71b7e3SCédric Le Goater val = xive->pc_regs[reg]; 1182da71b7e3SCédric Le Goater break; 1183da71b7e3SCédric Le Goater 1184da71b7e3SCédric Le Goater default: 1185da71b7e3SCédric Le Goater xive2_error(xive, "PC: invalid read @%"HWADDR_PRIx, offset); 1186da71b7e3SCédric Le Goater } 1187da71b7e3SCédric Le Goater 1188da71b7e3SCédric Le Goater return val; 1189da71b7e3SCédric Le Goater } 1190da71b7e3SCédric Le Goater 1191da71b7e3SCédric Le Goater static void pnv_xive2_ic_pc_write(void *opaque, hwaddr offset, 1192da71b7e3SCédric Le Goater uint64_t val, unsigned size) 1193da71b7e3SCédric Le Goater { 1194da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1195da71b7e3SCédric Le Goater uint32_t reg = offset >> 3; 1196da71b7e3SCédric Le Goater 1197da71b7e3SCédric Le Goater switch (offset) { 1198da71b7e3SCédric Le Goater 1199da71b7e3SCédric Le Goater /* 1200da71b7e3SCédric Le Goater * VSD table settings. Only taken into account in the VC 1201da71b7e3SCédric Le Goater * sub-engine because the Xive2Router model combines both VC and PC 1202da71b7e3SCédric Le Goater * sub-engines 1203da71b7e3SCédric Le Goater */ 1204da71b7e3SCédric Le Goater case PC_VSD_TABLE_ADDR: 1205da71b7e3SCédric Le Goater case PC_VSD_TABLE_DATA: 1206da71b7e3SCédric Le Goater break; 1207da71b7e3SCédric Le Goater 1208da71b7e3SCédric Le Goater /* 1209da71b7e3SCédric Le Goater * cache updates 1210da71b7e3SCédric Le Goater */ 1211da71b7e3SCédric Le Goater case PC_NXC_WATCH0_SPEC: 1212da71b7e3SCédric Le Goater val &= ~PC_NXC_WATCH_CONFLICT; /* HW will set this bit */ 1213da71b7e3SCédric Le Goater break; 1214da71b7e3SCédric Le Goater 1215da71b7e3SCédric Le Goater case PC_NXC_WATCH0_DATA1 ... PC_NXC_WATCH0_DATA3: 1216da71b7e3SCédric Le Goater break; 1217da71b7e3SCédric Le Goater case PC_NXC_WATCH0_DATA0: 1218da71b7e3SCédric Le Goater /* writing to DATA0 triggers the cache write */ 1219da71b7e3SCédric Le Goater xive->pc_regs[reg] = val; 1220da71b7e3SCédric Le Goater pnv_xive2_nvp_update(xive); 1221da71b7e3SCédric Le Goater break; 1222da71b7e3SCédric Le Goater 1223da71b7e3SCédric Le Goater /* case PC_NXC_FLUSH_CTRL: */ 1224da71b7e3SCédric Le Goater case PC_NXC_FLUSH_POLL: 1225da71b7e3SCédric Le Goater xive->pc_regs[PC_NXC_FLUSH_CTRL >> 3] |= PC_NXC_FLUSH_CTRL_POLL_VALID; 1226da71b7e3SCédric Le Goater break; 1227da71b7e3SCédric Le Goater 1228da71b7e3SCédric Le Goater /* 1229da71b7e3SCédric Le Goater * Indirect invalidation 1230da71b7e3SCédric Le Goater */ 1231da71b7e3SCédric Le Goater case PC_AT_KILL: 1232da71b7e3SCédric Le Goater case PC_AT_KILL_MASK: 1233da71b7e3SCédric Le Goater break; 1234da71b7e3SCédric Le Goater 1235da71b7e3SCédric Le Goater default: 1236da71b7e3SCédric Le Goater xive2_error(xive, "PC: invalid write @%"HWADDR_PRIx, offset); 1237da71b7e3SCédric Le Goater return; 1238da71b7e3SCédric Le Goater } 1239da71b7e3SCédric Le Goater 1240da71b7e3SCédric Le Goater xive->pc_regs[reg] = val; 1241da71b7e3SCédric Le Goater } 1242da71b7e3SCédric Le Goater 1243da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_ic_pc_ops = { 1244da71b7e3SCédric Le Goater .read = pnv_xive2_ic_pc_read, 1245da71b7e3SCédric Le Goater .write = pnv_xive2_ic_pc_write, 1246da71b7e3SCédric Le Goater .endianness = DEVICE_BIG_ENDIAN, 1247da71b7e3SCédric Le Goater .valid = { 1248da71b7e3SCédric Le Goater .min_access_size = 8, 1249da71b7e3SCédric Le Goater .max_access_size = 8, 1250da71b7e3SCédric Le Goater }, 1251da71b7e3SCédric Le Goater .impl = { 1252da71b7e3SCédric Le Goater .min_access_size = 8, 1253da71b7e3SCédric Le Goater .max_access_size = 8, 1254da71b7e3SCédric Le Goater }, 1255da71b7e3SCédric Le Goater }; 1256da71b7e3SCédric Le Goater 1257da71b7e3SCédric Le Goater 1258da71b7e3SCédric Le Goater static uint64_t pnv_xive2_ic_tctxt_read(void *opaque, hwaddr offset, 1259da71b7e3SCédric Le Goater unsigned size) 1260da71b7e3SCédric Le Goater { 1261da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1262da71b7e3SCédric Le Goater uint64_t val = -1; 1263da71b7e3SCédric Le Goater uint32_t reg = offset >> 3; 1264da71b7e3SCédric Le Goater 1265da71b7e3SCédric Le Goater switch (offset) { 1266da71b7e3SCédric Le Goater /* 1267da71b7e3SCédric Le Goater * XIVE2 hardware thread enablement 1268da71b7e3SCédric Le Goater */ 1269da71b7e3SCédric Le Goater case TCTXT_EN0: 1270da71b7e3SCédric Le Goater case TCTXT_EN1: 1271da71b7e3SCédric Le Goater val = xive->tctxt_regs[reg]; 1272da71b7e3SCédric Le Goater break; 1273da71b7e3SCédric Le Goater 1274da71b7e3SCédric Le Goater case TCTXT_EN0_SET: 1275da71b7e3SCédric Le Goater case TCTXT_EN0_RESET: 1276da71b7e3SCédric Le Goater val = xive->tctxt_regs[TCTXT_EN0 >> 3]; 1277da71b7e3SCédric Le Goater break; 1278da71b7e3SCédric Le Goater case TCTXT_EN1_SET: 1279da71b7e3SCédric Le Goater case TCTXT_EN1_RESET: 1280da71b7e3SCédric Le Goater val = xive->tctxt_regs[TCTXT_EN1 >> 3]; 1281da71b7e3SCédric Le Goater break; 1282da71b7e3SCédric Le Goater default: 1283da71b7e3SCédric Le Goater xive2_error(xive, "TCTXT: invalid read @%"HWADDR_PRIx, offset); 1284da71b7e3SCédric Le Goater } 1285da71b7e3SCédric Le Goater 1286da71b7e3SCédric Le Goater return val; 1287da71b7e3SCédric Le Goater } 1288da71b7e3SCédric Le Goater 1289da71b7e3SCédric Le Goater static void pnv_xive2_ic_tctxt_write(void *opaque, hwaddr offset, 1290da71b7e3SCédric Le Goater uint64_t val, unsigned size) 1291da71b7e3SCédric Le Goater { 1292da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1293da71b7e3SCédric Le Goater uint32_t reg = offset >> 3; 1294da71b7e3SCédric Le Goater 1295da71b7e3SCédric Le Goater switch (offset) { 1296da71b7e3SCédric Le Goater /* 1297da71b7e3SCédric Le Goater * XIVE2 hardware thread enablement 1298da71b7e3SCédric Le Goater */ 1299da71b7e3SCédric Le Goater case TCTXT_EN0: /* Physical Thread Enable */ 1300da71b7e3SCédric Le Goater case TCTXT_EN1: /* Physical Thread Enable (fused core) */ 1301da71b7e3SCédric Le Goater break; 1302da71b7e3SCédric Le Goater 1303da71b7e3SCédric Le Goater case TCTXT_EN0_SET: 1304da71b7e3SCédric Le Goater xive->tctxt_regs[TCTXT_EN0 >> 3] |= val; 1305da71b7e3SCédric Le Goater break; 1306da71b7e3SCédric Le Goater case TCTXT_EN1_SET: 1307da71b7e3SCédric Le Goater xive->tctxt_regs[TCTXT_EN1 >> 3] |= val; 1308da71b7e3SCédric Le Goater break; 1309da71b7e3SCédric Le Goater case TCTXT_EN0_RESET: 1310da71b7e3SCédric Le Goater xive->tctxt_regs[TCTXT_EN0 >> 3] &= ~val; 1311da71b7e3SCédric Le Goater break; 1312da71b7e3SCédric Le Goater case TCTXT_EN1_RESET: 1313da71b7e3SCédric Le Goater xive->tctxt_regs[TCTXT_EN1 >> 3] &= ~val; 1314da71b7e3SCédric Le Goater break; 1315da71b7e3SCédric Le Goater 1316da71b7e3SCédric Le Goater default: 1317da71b7e3SCédric Le Goater xive2_error(xive, "TCTXT: invalid write @%"HWADDR_PRIx, offset); 1318da71b7e3SCédric Le Goater return; 1319da71b7e3SCédric Le Goater } 1320da71b7e3SCédric Le Goater 1321da71b7e3SCédric Le Goater xive->pc_regs[reg] = val; 1322da71b7e3SCédric Le Goater } 1323da71b7e3SCédric Le Goater 1324da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_ic_tctxt_ops = { 1325da71b7e3SCédric Le Goater .read = pnv_xive2_ic_tctxt_read, 1326da71b7e3SCédric Le Goater .write = pnv_xive2_ic_tctxt_write, 1327da71b7e3SCédric Le Goater .endianness = DEVICE_BIG_ENDIAN, 1328da71b7e3SCédric Le Goater .valid = { 1329da71b7e3SCédric Le Goater .min_access_size = 8, 1330da71b7e3SCédric Le Goater .max_access_size = 8, 1331da71b7e3SCédric Le Goater }, 1332da71b7e3SCédric Le Goater .impl = { 1333da71b7e3SCédric Le Goater .min_access_size = 8, 1334da71b7e3SCédric Le Goater .max_access_size = 8, 1335da71b7e3SCédric Le Goater }, 1336da71b7e3SCédric Le Goater }; 1337da71b7e3SCédric Le Goater 1338da71b7e3SCédric Le Goater /* 1339da71b7e3SCédric Le Goater * Redirect XSCOM to MMIO handlers 1340da71b7e3SCédric Le Goater */ 1341da71b7e3SCédric Le Goater static uint64_t pnv_xive2_xscom_read(void *opaque, hwaddr offset, 1342da71b7e3SCédric Le Goater unsigned size) 1343da71b7e3SCédric Le Goater { 1344da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1345da71b7e3SCédric Le Goater uint64_t val = -1; 1346da71b7e3SCédric Le Goater uint32_t xscom_reg = offset >> 3; 1347da71b7e3SCédric Le Goater uint32_t mmio_offset = (xscom_reg & 0xFF) << 3; 1348da71b7e3SCédric Le Goater 1349da71b7e3SCédric Le Goater switch (xscom_reg) { 1350da71b7e3SCédric Le Goater case 0x000 ... 0x0FF: 1351da71b7e3SCédric Le Goater val = pnv_xive2_ic_cq_read(opaque, mmio_offset, size); 1352da71b7e3SCédric Le Goater break; 1353da71b7e3SCédric Le Goater case 0x100 ... 0x1FF: 1354da71b7e3SCédric Le Goater val = pnv_xive2_ic_vc_read(opaque, mmio_offset, size); 1355da71b7e3SCédric Le Goater break; 1356da71b7e3SCédric Le Goater case 0x200 ... 0x2FF: 1357da71b7e3SCédric Le Goater val = pnv_xive2_ic_pc_read(opaque, mmio_offset, size); 1358da71b7e3SCédric Le Goater break; 1359da71b7e3SCédric Le Goater case 0x300 ... 0x3FF: 1360da71b7e3SCédric Le Goater val = pnv_xive2_ic_tctxt_read(opaque, mmio_offset, size); 1361da71b7e3SCédric Le Goater break; 1362da71b7e3SCédric Le Goater default: 1363da71b7e3SCédric Le Goater xive2_error(xive, "XSCOM: invalid read @%"HWADDR_PRIx, offset); 1364da71b7e3SCédric Le Goater } 1365da71b7e3SCédric Le Goater 1366da71b7e3SCédric Le Goater return val; 1367da71b7e3SCédric Le Goater } 1368da71b7e3SCédric Le Goater 1369da71b7e3SCédric Le Goater static void pnv_xive2_xscom_write(void *opaque, hwaddr offset, 1370da71b7e3SCédric Le Goater uint64_t val, unsigned size) 1371da71b7e3SCédric Le Goater { 1372da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1373da71b7e3SCédric Le Goater uint32_t xscom_reg = offset >> 3; 1374da71b7e3SCédric Le Goater uint32_t mmio_offset = (xscom_reg & 0xFF) << 3; 1375da71b7e3SCédric Le Goater 1376da71b7e3SCédric Le Goater switch (xscom_reg) { 1377da71b7e3SCédric Le Goater case 0x000 ... 0x0FF: 1378da71b7e3SCédric Le Goater pnv_xive2_ic_cq_write(opaque, mmio_offset, val, size); 1379da71b7e3SCédric Le Goater break; 1380da71b7e3SCédric Le Goater case 0x100 ... 0x1FF: 1381da71b7e3SCédric Le Goater pnv_xive2_ic_vc_write(opaque, mmio_offset, val, size); 1382da71b7e3SCédric Le Goater break; 1383da71b7e3SCédric Le Goater case 0x200 ... 0x2FF: 1384da71b7e3SCédric Le Goater pnv_xive2_ic_pc_write(opaque, mmio_offset, val, size); 1385da71b7e3SCédric Le Goater break; 1386da71b7e3SCédric Le Goater case 0x300 ... 0x3FF: 1387da71b7e3SCédric Le Goater pnv_xive2_ic_tctxt_write(opaque, mmio_offset, val, size); 1388da71b7e3SCédric Le Goater break; 1389da71b7e3SCédric Le Goater default: 1390da71b7e3SCédric Le Goater xive2_error(xive, "XSCOM: invalid write @%"HWADDR_PRIx, offset); 1391da71b7e3SCédric Le Goater } 1392da71b7e3SCédric Le Goater } 1393da71b7e3SCédric Le Goater 1394da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_xscom_ops = { 1395da71b7e3SCédric Le Goater .read = pnv_xive2_xscom_read, 1396da71b7e3SCédric Le Goater .write = pnv_xive2_xscom_write, 1397da71b7e3SCédric Le Goater .endianness = DEVICE_BIG_ENDIAN, 1398da71b7e3SCédric Le Goater .valid = { 1399da71b7e3SCédric Le Goater .min_access_size = 8, 1400da71b7e3SCédric Le Goater .max_access_size = 8, 1401da71b7e3SCédric Le Goater }, 1402da71b7e3SCédric Le Goater .impl = { 1403da71b7e3SCédric Le Goater .min_access_size = 8, 1404da71b7e3SCédric Le Goater .max_access_size = 8, 1405da71b7e3SCédric Le Goater }, 1406da71b7e3SCédric Le Goater }; 1407da71b7e3SCédric Le Goater 1408da71b7e3SCédric Le Goater /* 1409da71b7e3SCédric Le Goater * Notify port page. The layout is compatible between 4K and 64K pages : 1410da71b7e3SCédric Le Goater * 1411da71b7e3SCédric Le Goater * Page 1 Notify page (writes only) 1412da71b7e3SCédric Le Goater * 0x000 - 0x7FF IPI interrupt (NPU) 1413da71b7e3SCédric Le Goater * 0x800 - 0xFFF HW interrupt triggers (PSI, PHB) 1414da71b7e3SCédric Le Goater */ 1415da71b7e3SCédric Le Goater 1416da71b7e3SCédric Le Goater static void pnv_xive2_ic_hw_trigger(PnvXive2 *xive, hwaddr addr, 1417da71b7e3SCédric Le Goater uint64_t val) 1418da71b7e3SCédric Le Goater { 1419da71b7e3SCédric Le Goater uint8_t blk; 1420da71b7e3SCédric Le Goater uint32_t idx; 1421da71b7e3SCédric Le Goater 1422da71b7e3SCédric Le Goater if (val & XIVE_TRIGGER_END) { 1423da71b7e3SCédric Le Goater xive2_error(xive, "IC: END trigger at @0x%"HWADDR_PRIx" data 0x%"PRIx64, 1424da71b7e3SCédric Le Goater addr, val); 1425da71b7e3SCédric Le Goater return; 1426da71b7e3SCédric Le Goater } 1427da71b7e3SCédric Le Goater 1428da71b7e3SCédric Le Goater /* 1429da71b7e3SCédric Le Goater * Forward the source event notification directly to the Router. 1430da71b7e3SCédric Le Goater * The source interrupt number should already be correctly encoded 1431da71b7e3SCédric Le Goater * with the chip block id by the sending device (PHB, PSI). 1432da71b7e3SCédric Le Goater */ 1433da71b7e3SCédric Le Goater blk = XIVE_EAS_BLOCK(val); 1434da71b7e3SCédric Le Goater idx = XIVE_EAS_INDEX(val); 1435da71b7e3SCédric Le Goater 14360aa2612aSCédric Le Goater xive2_router_notify(XIVE_NOTIFIER(xive), XIVE_EAS(blk, idx), 14370aa2612aSCédric Le Goater !!(val & XIVE_TRIGGER_PQ)); 1438da71b7e3SCédric Le Goater } 1439da71b7e3SCédric Le Goater 1440da71b7e3SCédric Le Goater static void pnv_xive2_ic_notify_write(void *opaque, hwaddr offset, 1441da71b7e3SCédric Le Goater uint64_t val, unsigned size) 1442da71b7e3SCédric Le Goater { 1443da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1444da71b7e3SCédric Le Goater 1445da71b7e3SCédric Le Goater /* VC: IPI triggers */ 1446da71b7e3SCédric Le Goater switch (offset) { 1447da71b7e3SCédric Le Goater case 0x000 ... 0x7FF: 1448da71b7e3SCédric Le Goater /* TODO: check IPI notify sub-page routing */ 1449da71b7e3SCédric Le Goater pnv_xive2_ic_hw_trigger(opaque, offset, val); 1450da71b7e3SCédric Le Goater break; 1451da71b7e3SCédric Le Goater 1452da71b7e3SCédric Le Goater /* VC: HW triggers */ 1453da71b7e3SCédric Le Goater case 0x800 ... 0xFFF: 1454da71b7e3SCédric Le Goater pnv_xive2_ic_hw_trigger(opaque, offset, val); 1455da71b7e3SCédric Le Goater break; 1456da71b7e3SCédric Le Goater 1457da71b7e3SCédric Le Goater default: 1458da71b7e3SCédric Le Goater xive2_error(xive, "NOTIFY: invalid write @%"HWADDR_PRIx, offset); 1459da71b7e3SCédric Le Goater } 1460da71b7e3SCédric Le Goater } 1461da71b7e3SCédric Le Goater 1462da71b7e3SCédric Le Goater static uint64_t pnv_xive2_ic_notify_read(void *opaque, hwaddr offset, 1463da71b7e3SCédric Le Goater unsigned size) 1464da71b7e3SCédric Le Goater { 1465da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1466da71b7e3SCédric Le Goater 1467da71b7e3SCédric Le Goater /* loads are invalid */ 1468da71b7e3SCédric Le Goater xive2_error(xive, "NOTIFY: invalid read @%"HWADDR_PRIx, offset); 1469da71b7e3SCédric Le Goater return -1; 1470da71b7e3SCédric Le Goater } 1471da71b7e3SCédric Le Goater 1472da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_ic_notify_ops = { 1473da71b7e3SCédric Le Goater .read = pnv_xive2_ic_notify_read, 1474da71b7e3SCédric Le Goater .write = pnv_xive2_ic_notify_write, 1475da71b7e3SCédric Le Goater .endianness = DEVICE_BIG_ENDIAN, 1476da71b7e3SCédric Le Goater .valid = { 1477da71b7e3SCédric Le Goater .min_access_size = 8, 1478da71b7e3SCédric Le Goater .max_access_size = 8, 1479da71b7e3SCédric Le Goater }, 1480da71b7e3SCédric Le Goater .impl = { 1481da71b7e3SCédric Le Goater .min_access_size = 8, 1482da71b7e3SCédric Le Goater .max_access_size = 8, 1483da71b7e3SCédric Le Goater }, 1484da71b7e3SCédric Le Goater }; 1485da71b7e3SCédric Le Goater 1486da71b7e3SCédric Le Goater static uint64_t pnv_xive2_ic_lsi_read(void *opaque, hwaddr offset, 1487da71b7e3SCédric Le Goater unsigned size) 1488da71b7e3SCédric Le Goater { 1489da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1490da71b7e3SCédric Le Goater 1491da71b7e3SCédric Le Goater xive2_error(xive, "LSI: invalid read @%"HWADDR_PRIx, offset); 1492da71b7e3SCédric Le Goater return -1; 1493da71b7e3SCédric Le Goater } 1494da71b7e3SCédric Le Goater 1495da71b7e3SCédric Le Goater static void pnv_xive2_ic_lsi_write(void *opaque, hwaddr offset, 1496da71b7e3SCédric Le Goater uint64_t val, unsigned size) 1497da71b7e3SCédric Le Goater { 1498da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1499da71b7e3SCédric Le Goater 1500da71b7e3SCédric Le Goater xive2_error(xive, "LSI: invalid write @%"HWADDR_PRIx, offset); 1501da71b7e3SCédric Le Goater } 1502da71b7e3SCédric Le Goater 1503da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_ic_lsi_ops = { 1504da71b7e3SCédric Le Goater .read = pnv_xive2_ic_lsi_read, 1505da71b7e3SCédric Le Goater .write = pnv_xive2_ic_lsi_write, 1506da71b7e3SCédric Le Goater .endianness = DEVICE_BIG_ENDIAN, 1507da71b7e3SCédric Le Goater .valid = { 1508da71b7e3SCédric Le Goater .min_access_size = 8, 1509da71b7e3SCédric Le Goater .max_access_size = 8, 1510da71b7e3SCédric Le Goater }, 1511da71b7e3SCédric Le Goater .impl = { 1512da71b7e3SCédric Le Goater .min_access_size = 8, 1513da71b7e3SCédric Le Goater .max_access_size = 8, 1514da71b7e3SCédric Le Goater }, 1515da71b7e3SCédric Le Goater }; 1516da71b7e3SCédric Le Goater 1517da71b7e3SCédric Le Goater /* 1518da71b7e3SCédric Le Goater * Sync MMIO page (write only) 1519da71b7e3SCédric Le Goater */ 1520da71b7e3SCédric Le Goater #define PNV_XIVE2_SYNC_IPI 0x000 1521da71b7e3SCédric Le Goater #define PNV_XIVE2_SYNC_HW 0x080 1522da71b7e3SCédric Le Goater #define PNV_XIVE2_SYNC_NxC 0x100 1523da71b7e3SCédric Le Goater #define PNV_XIVE2_SYNC_INT 0x180 1524da71b7e3SCédric Le Goater #define PNV_XIVE2_SYNC_OS_ESC 0x200 1525da71b7e3SCédric Le Goater #define PNV_XIVE2_SYNC_POOL_ESC 0x280 1526da71b7e3SCédric Le Goater #define PNV_XIVE2_SYNC_HARD_ESC 0x300 1527da71b7e3SCédric Le Goater 1528da71b7e3SCédric Le Goater static uint64_t pnv_xive2_ic_sync_read(void *opaque, hwaddr offset, 1529da71b7e3SCédric Le Goater unsigned size) 1530da71b7e3SCédric Le Goater { 1531da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1532da71b7e3SCédric Le Goater 1533da71b7e3SCédric Le Goater /* loads are invalid */ 1534da71b7e3SCédric Le Goater xive2_error(xive, "SYNC: invalid read @%"HWADDR_PRIx, offset); 1535da71b7e3SCédric Le Goater return -1; 1536da71b7e3SCédric Le Goater } 1537da71b7e3SCédric Le Goater 1538da71b7e3SCédric Le Goater static void pnv_xive2_ic_sync_write(void *opaque, hwaddr offset, 1539da71b7e3SCédric Le Goater uint64_t val, unsigned size) 1540da71b7e3SCédric Le Goater { 1541da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1542da71b7e3SCédric Le Goater 1543da71b7e3SCédric Le Goater switch (offset) { 1544da71b7e3SCédric Le Goater case PNV_XIVE2_SYNC_IPI: 1545da71b7e3SCédric Le Goater case PNV_XIVE2_SYNC_HW: 1546da71b7e3SCédric Le Goater case PNV_XIVE2_SYNC_NxC: 1547da71b7e3SCédric Le Goater case PNV_XIVE2_SYNC_INT: 1548da71b7e3SCédric Le Goater case PNV_XIVE2_SYNC_OS_ESC: 1549da71b7e3SCédric Le Goater case PNV_XIVE2_SYNC_POOL_ESC: 1550da71b7e3SCédric Le Goater case PNV_XIVE2_SYNC_HARD_ESC: 1551da71b7e3SCédric Le Goater break; 1552da71b7e3SCédric Le Goater default: 1553da71b7e3SCédric Le Goater xive2_error(xive, "SYNC: invalid write @%"HWADDR_PRIx, offset); 1554da71b7e3SCédric Le Goater } 1555da71b7e3SCédric Le Goater } 1556da71b7e3SCédric Le Goater 1557da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_ic_sync_ops = { 1558da71b7e3SCédric Le Goater .read = pnv_xive2_ic_sync_read, 1559da71b7e3SCédric Le Goater .write = pnv_xive2_ic_sync_write, 1560da71b7e3SCédric Le Goater .endianness = DEVICE_BIG_ENDIAN, 1561da71b7e3SCédric Le Goater .valid = { 1562da71b7e3SCédric Le Goater .min_access_size = 8, 1563da71b7e3SCédric Le Goater .max_access_size = 8, 1564da71b7e3SCédric Le Goater }, 1565da71b7e3SCédric Le Goater .impl = { 1566da71b7e3SCédric Le Goater .min_access_size = 8, 1567da71b7e3SCédric Le Goater .max_access_size = 8, 1568da71b7e3SCédric Le Goater }, 1569da71b7e3SCédric Le Goater }; 1570da71b7e3SCédric Le Goater 1571da71b7e3SCédric Le Goater /* 1572da71b7e3SCédric Le Goater * When the TM direct pages of the IC controller are accessed, the 1573da71b7e3SCédric Le Goater * target HW thread is deduced from the page offset. 1574da71b7e3SCédric Le Goater */ 1575da71b7e3SCédric Le Goater static XiveTCTX *pnv_xive2_get_indirect_tctx(PnvXive2 *xive, uint32_t pir) 1576da71b7e3SCédric Le Goater { 1577da71b7e3SCédric Le Goater PnvChip *chip = xive->chip; 1578da71b7e3SCédric Le Goater PowerPCCPU *cpu = NULL; 1579da71b7e3SCédric Le Goater 1580da71b7e3SCédric Le Goater cpu = pnv_chip_find_cpu(chip, pir); 1581da71b7e3SCédric Le Goater if (!cpu) { 1582da71b7e3SCédric Le Goater xive2_error(xive, "IC: invalid PIR %x for indirect access", pir); 1583da71b7e3SCédric Le Goater return NULL; 1584da71b7e3SCédric Le Goater } 1585da71b7e3SCédric Le Goater 1586da71b7e3SCédric Le Goater if (!pnv_xive2_is_cpu_enabled(xive, cpu)) { 1587da71b7e3SCédric Le Goater xive2_error(xive, "IC: CPU %x is not enabled", pir); 1588da71b7e3SCédric Le Goater } 1589da71b7e3SCédric Le Goater 1590da71b7e3SCédric Le Goater return XIVE_TCTX(pnv_cpu_state(cpu)->intc); 1591da71b7e3SCédric Le Goater } 1592da71b7e3SCédric Le Goater 1593da71b7e3SCédric Le Goater static uint64_t pnv_xive2_ic_tm_indirect_read(void *opaque, hwaddr offset, 1594da71b7e3SCédric Le Goater unsigned size) 1595da71b7e3SCédric Le Goater { 1596da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1597da71b7e3SCédric Le Goater uint32_t pir = offset >> xive->ic_shift; 1598da71b7e3SCédric Le Goater XiveTCTX *tctx = pnv_xive2_get_indirect_tctx(xive, pir); 1599da71b7e3SCédric Le Goater uint64_t val = -1; 1600da71b7e3SCédric Le Goater 1601da71b7e3SCédric Le Goater if (tctx) { 1602da71b7e3SCédric Le Goater val = xive_tctx_tm_read(NULL, tctx, offset, size); 1603da71b7e3SCédric Le Goater } 1604da71b7e3SCédric Le Goater 1605da71b7e3SCédric Le Goater return val; 1606da71b7e3SCédric Le Goater } 1607da71b7e3SCédric Le Goater 1608da71b7e3SCédric Le Goater static void pnv_xive2_ic_tm_indirect_write(void *opaque, hwaddr offset, 1609da71b7e3SCédric Le Goater uint64_t val, unsigned size) 1610da71b7e3SCédric Le Goater { 1611da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1612da71b7e3SCédric Le Goater uint32_t pir = offset >> xive->ic_shift; 1613da71b7e3SCédric Le Goater XiveTCTX *tctx = pnv_xive2_get_indirect_tctx(xive, pir); 1614da71b7e3SCédric Le Goater 1615da71b7e3SCédric Le Goater if (tctx) { 1616da71b7e3SCédric Le Goater xive_tctx_tm_write(NULL, tctx, offset, val, size); 1617da71b7e3SCédric Le Goater } 1618da71b7e3SCédric Le Goater } 1619da71b7e3SCédric Le Goater 1620da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_ic_tm_indirect_ops = { 1621da71b7e3SCédric Le Goater .read = pnv_xive2_ic_tm_indirect_read, 1622da71b7e3SCédric Le Goater .write = pnv_xive2_ic_tm_indirect_write, 1623da71b7e3SCédric Le Goater .endianness = DEVICE_BIG_ENDIAN, 1624da71b7e3SCédric Le Goater .valid = { 1625da71b7e3SCédric Le Goater .min_access_size = 8, 1626da71b7e3SCédric Le Goater .max_access_size = 8, 1627da71b7e3SCédric Le Goater }, 1628da71b7e3SCédric Le Goater .impl = { 1629da71b7e3SCédric Le Goater .min_access_size = 8, 1630da71b7e3SCédric Le Goater .max_access_size = 8, 1631da71b7e3SCédric Le Goater }, 1632da71b7e3SCédric Le Goater }; 1633da71b7e3SCédric Le Goater 1634da71b7e3SCédric Le Goater /* 1635da71b7e3SCédric Le Goater * TIMA ops 1636da71b7e3SCédric Le Goater */ 1637da71b7e3SCédric Le Goater 163895d729e2SCédric Le Goater /* 163995d729e2SCédric Le Goater * Special TIMA offsets to handle accesses in a POWER10 way. 164095d729e2SCédric Le Goater * 164195d729e2SCédric Le Goater * Only the CAM line updates done by the hypervisor should be handled 164295d729e2SCédric Le Goater * specifically. 164395d729e2SCédric Le Goater */ 164495d729e2SCédric Le Goater #define HV_PAGE_OFFSET (XIVE_TM_HV_PAGE << TM_SHIFT) 164595d729e2SCédric Le Goater #define HV_PUSH_OS_CTX_OFFSET (HV_PAGE_OFFSET | (TM_QW1_OS + TM_WORD2)) 164695d729e2SCédric Le Goater #define HV_PULL_OS_CTX_OFFSET (HV_PAGE_OFFSET | TM_SPC_PULL_OS_CTX) 164795d729e2SCédric Le Goater 1648da71b7e3SCédric Le Goater static void pnv_xive2_tm_write(void *opaque, hwaddr offset, 1649da71b7e3SCédric Le Goater uint64_t value, unsigned size) 1650da71b7e3SCédric Le Goater { 1651da71b7e3SCédric Le Goater PowerPCCPU *cpu = POWERPC_CPU(current_cpu); 1652da71b7e3SCédric Le Goater PnvXive2 *xive = pnv_xive2_tm_get_xive(cpu); 1653da71b7e3SCédric Le Goater XiveTCTX *tctx = XIVE_TCTX(pnv_cpu_state(cpu)->intc); 165495d729e2SCédric Le Goater XivePresenter *xptr = XIVE_PRESENTER(xive); 1655747ffe28SCédric Le Goater bool gen1_tima_os = 1656747ffe28SCédric Le Goater xive->cq_regs[CQ_XIVE_CFG >> 3] & CQ_XIVE_CFG_GEN1_TIMA_OS; 165795d729e2SCédric Le Goater 165895d729e2SCédric Le Goater /* TODO: should we switch the TM ops table instead ? */ 1659747ffe28SCédric Le Goater if (!gen1_tima_os && offset == HV_PUSH_OS_CTX_OFFSET) { 166095d729e2SCédric Le Goater xive2_tm_push_os_ctx(xptr, tctx, offset, value, size); 166195d729e2SCédric Le Goater return; 166295d729e2SCédric Le Goater } 1663da71b7e3SCédric Le Goater 1664da71b7e3SCédric Le Goater /* Other TM ops are the same as XIVE1 */ 166595d729e2SCédric Le Goater xive_tctx_tm_write(xptr, tctx, offset, value, size); 1666da71b7e3SCédric Le Goater } 1667da71b7e3SCédric Le Goater 1668da71b7e3SCédric Le Goater static uint64_t pnv_xive2_tm_read(void *opaque, hwaddr offset, unsigned size) 1669da71b7e3SCédric Le Goater { 1670da71b7e3SCédric Le Goater PowerPCCPU *cpu = POWERPC_CPU(current_cpu); 1671da71b7e3SCédric Le Goater PnvXive2 *xive = pnv_xive2_tm_get_xive(cpu); 1672da71b7e3SCédric Le Goater XiveTCTX *tctx = XIVE_TCTX(pnv_cpu_state(cpu)->intc); 167395d729e2SCédric Le Goater XivePresenter *xptr = XIVE_PRESENTER(xive); 1674747ffe28SCédric Le Goater bool gen1_tima_os = 1675747ffe28SCédric Le Goater xive->cq_regs[CQ_XIVE_CFG >> 3] & CQ_XIVE_CFG_GEN1_TIMA_OS; 167695d729e2SCédric Le Goater 167795d729e2SCédric Le Goater /* TODO: should we switch the TM ops table instead ? */ 1678747ffe28SCédric Le Goater if (!gen1_tima_os && offset == HV_PULL_OS_CTX_OFFSET) { 167995d729e2SCédric Le Goater return xive2_tm_pull_os_ctx(xptr, tctx, offset, size); 168095d729e2SCédric Le Goater } 1681da71b7e3SCédric Le Goater 1682da71b7e3SCédric Le Goater /* Other TM ops are the same as XIVE1 */ 168395d729e2SCédric Le Goater return xive_tctx_tm_read(xptr, tctx, offset, size); 1684da71b7e3SCédric Le Goater } 1685da71b7e3SCédric Le Goater 1686da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_tm_ops = { 1687da71b7e3SCédric Le Goater .read = pnv_xive2_tm_read, 1688da71b7e3SCédric Le Goater .write = pnv_xive2_tm_write, 1689da71b7e3SCédric Le Goater .endianness = DEVICE_BIG_ENDIAN, 1690da71b7e3SCédric Le Goater .valid = { 1691da71b7e3SCédric Le Goater .min_access_size = 1, 1692da71b7e3SCédric Le Goater .max_access_size = 8, 1693da71b7e3SCédric Le Goater }, 1694da71b7e3SCédric Le Goater .impl = { 1695da71b7e3SCédric Le Goater .min_access_size = 1, 1696da71b7e3SCédric Le Goater .max_access_size = 8, 1697da71b7e3SCédric Le Goater }, 1698da71b7e3SCédric Le Goater }; 1699da71b7e3SCédric Le Goater 1700da71b7e3SCédric Le Goater static uint64_t pnv_xive2_nvc_read(void *opaque, hwaddr offset, 1701da71b7e3SCédric Le Goater unsigned size) 1702da71b7e3SCédric Le Goater { 1703da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1704da71b7e3SCédric Le Goater 1705da71b7e3SCédric Le Goater xive2_error(xive, "NVC: invalid read @%"HWADDR_PRIx, offset); 1706da71b7e3SCédric Le Goater return -1; 1707da71b7e3SCédric Le Goater } 1708da71b7e3SCédric Le Goater 1709da71b7e3SCédric Le Goater static void pnv_xive2_nvc_write(void *opaque, hwaddr offset, 1710da71b7e3SCédric Le Goater uint64_t val, unsigned size) 1711da71b7e3SCédric Le Goater { 1712da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1713da71b7e3SCédric Le Goater 1714da71b7e3SCédric Le Goater xive2_error(xive, "NVC: invalid write @%"HWADDR_PRIx, offset); 1715da71b7e3SCédric Le Goater } 1716da71b7e3SCédric Le Goater 1717da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_nvc_ops = { 1718da71b7e3SCédric Le Goater .read = pnv_xive2_nvc_read, 1719da71b7e3SCédric Le Goater .write = pnv_xive2_nvc_write, 1720da71b7e3SCédric Le Goater .endianness = DEVICE_BIG_ENDIAN, 1721da71b7e3SCédric Le Goater .valid = { 1722da71b7e3SCédric Le Goater .min_access_size = 8, 1723da71b7e3SCédric Le Goater .max_access_size = 8, 1724da71b7e3SCédric Le Goater }, 1725da71b7e3SCédric Le Goater .impl = { 1726da71b7e3SCédric Le Goater .min_access_size = 8, 1727da71b7e3SCédric Le Goater .max_access_size = 8, 1728da71b7e3SCédric Le Goater }, 1729da71b7e3SCédric Le Goater }; 1730da71b7e3SCédric Le Goater 1731da71b7e3SCédric Le Goater static uint64_t pnv_xive2_nvpg_read(void *opaque, hwaddr offset, 1732da71b7e3SCédric Le Goater unsigned size) 1733da71b7e3SCédric Le Goater { 1734da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1735da71b7e3SCédric Le Goater 1736da71b7e3SCédric Le Goater xive2_error(xive, "NVPG: invalid read @%"HWADDR_PRIx, offset); 1737da71b7e3SCédric Le Goater return -1; 1738da71b7e3SCédric Le Goater } 1739da71b7e3SCédric Le Goater 1740da71b7e3SCédric Le Goater static void pnv_xive2_nvpg_write(void *opaque, hwaddr offset, 1741da71b7e3SCédric Le Goater uint64_t val, unsigned size) 1742da71b7e3SCédric Le Goater { 1743da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(opaque); 1744da71b7e3SCédric Le Goater 1745da71b7e3SCédric Le Goater xive2_error(xive, "NVPG: invalid write @%"HWADDR_PRIx, offset); 1746da71b7e3SCédric Le Goater } 1747da71b7e3SCédric Le Goater 1748da71b7e3SCédric Le Goater static const MemoryRegionOps pnv_xive2_nvpg_ops = { 1749da71b7e3SCédric Le Goater .read = pnv_xive2_nvpg_read, 1750da71b7e3SCédric Le Goater .write = pnv_xive2_nvpg_write, 1751da71b7e3SCédric Le Goater .endianness = DEVICE_BIG_ENDIAN, 1752da71b7e3SCédric Le Goater .valid = { 1753da71b7e3SCédric Le Goater .min_access_size = 8, 1754da71b7e3SCédric Le Goater .max_access_size = 8, 1755da71b7e3SCédric Le Goater }, 1756da71b7e3SCédric Le Goater .impl = { 1757da71b7e3SCédric Le Goater .min_access_size = 8, 1758da71b7e3SCédric Le Goater .max_access_size = 8, 1759da71b7e3SCédric Le Goater }, 1760da71b7e3SCédric Le Goater }; 1761da71b7e3SCédric Le Goater 1762da71b7e3SCédric Le Goater /* 1763707ea7abSCédric Le Goater * POWER10 default capabilities: 0x2000120076f000FC 1764da71b7e3SCédric Le Goater */ 1765707ea7abSCédric Le Goater #define PNV_XIVE2_CAPABILITIES 0x2000120076f000FC 1766da71b7e3SCédric Le Goater 1767da71b7e3SCédric Le Goater /* 1768da71b7e3SCédric Le Goater * POWER10 default configuration: 0x0030000033000000 1769da71b7e3SCédric Le Goater * 1770da71b7e3SCédric Le Goater * 8bits thread id was dropped for P10 1771da71b7e3SCédric Le Goater */ 1772da71b7e3SCédric Le Goater #define PNV_XIVE2_CONFIGURATION 0x0030000033000000 1773da71b7e3SCédric Le Goater 1774da71b7e3SCédric Le Goater static void pnv_xive2_reset(void *dev) 1775da71b7e3SCédric Le Goater { 1776da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(dev); 1777da71b7e3SCédric Le Goater XiveSource *xsrc = &xive->ipi_source; 1778da71b7e3SCédric Le Goater Xive2EndSource *end_xsrc = &xive->end_source; 1779da71b7e3SCédric Le Goater 1780da71b7e3SCédric Le Goater xive->cq_regs[CQ_XIVE_CAP >> 3] = xive->capabilities; 1781da71b7e3SCédric Le Goater xive->cq_regs[CQ_XIVE_CFG >> 3] = xive->config; 1782da71b7e3SCédric Le Goater 1783da71b7e3SCédric Le Goater /* HW hardwires the #Topology of the chip in the block field */ 1784da71b7e3SCédric Le Goater xive->cq_regs[CQ_XIVE_CFG >> 3] |= 1785da71b7e3SCédric Le Goater SETFIELD(CQ_XIVE_CFG_HYP_HARD_BLOCK_ID, 0ull, xive->chip->chip_id); 1786da71b7e3SCédric Le Goater 1787da71b7e3SCédric Le Goater /* Set default page size to 64k */ 1788da71b7e3SCédric Le Goater xive->ic_shift = xive->esb_shift = xive->end_shift = 16; 1789da71b7e3SCédric Le Goater xive->nvc_shift = xive->nvpg_shift = xive->tm_shift = 16; 1790da71b7e3SCédric Le Goater 1791da71b7e3SCédric Le Goater /* Clear source MMIOs */ 1792da71b7e3SCédric Le Goater if (memory_region_is_mapped(&xsrc->esb_mmio)) { 1793da71b7e3SCédric Le Goater memory_region_del_subregion(&xive->esb_mmio, &xsrc->esb_mmio); 1794da71b7e3SCédric Le Goater } 1795da71b7e3SCédric Le Goater 1796da71b7e3SCédric Le Goater if (memory_region_is_mapped(&end_xsrc->esb_mmio)) { 1797da71b7e3SCédric Le Goater memory_region_del_subregion(&xive->end_mmio, &end_xsrc->esb_mmio); 1798da71b7e3SCédric Le Goater } 1799da71b7e3SCédric Le Goater } 1800da71b7e3SCédric Le Goater 1801da71b7e3SCédric Le Goater /* 1802da71b7e3SCédric Le Goater * Maximum number of IRQs and ENDs supported by HW. Will be tuned by 1803da71b7e3SCédric Le Goater * software. 1804da71b7e3SCédric Le Goater */ 1805da71b7e3SCédric Le Goater #define PNV_XIVE2_NR_IRQS (PNV10_XIVE2_ESB_SIZE / (1ull << XIVE_ESB_64K_2PAGE)) 1806da71b7e3SCédric Le Goater #define PNV_XIVE2_NR_ENDS (PNV10_XIVE2_END_SIZE / (1ull << XIVE_ESB_64K_2PAGE)) 1807da71b7e3SCédric Le Goater 1808da71b7e3SCédric Le Goater static void pnv_xive2_realize(DeviceState *dev, Error **errp) 1809da71b7e3SCédric Le Goater { 1810da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(dev); 1811da71b7e3SCédric Le Goater PnvXive2Class *pxc = PNV_XIVE2_GET_CLASS(dev); 1812da71b7e3SCédric Le Goater XiveSource *xsrc = &xive->ipi_source; 1813da71b7e3SCédric Le Goater Xive2EndSource *end_xsrc = &xive->end_source; 1814da71b7e3SCédric Le Goater Error *local_err = NULL; 1815da71b7e3SCédric Le Goater int i; 1816da71b7e3SCédric Le Goater 1817da71b7e3SCédric Le Goater pxc->parent_realize(dev, &local_err); 1818da71b7e3SCédric Le Goater if (local_err) { 1819da71b7e3SCédric Le Goater error_propagate(errp, local_err); 1820da71b7e3SCédric Le Goater return; 1821da71b7e3SCédric Le Goater } 1822da71b7e3SCédric Le Goater 1823da71b7e3SCédric Le Goater assert(xive->chip); 1824da71b7e3SCédric Le Goater 1825da71b7e3SCédric Le Goater /* 1826da71b7e3SCédric Le Goater * The XiveSource and Xive2EndSource objects are realized with the 1827da71b7e3SCédric Le Goater * maximum allowed HW configuration. The ESB MMIO regions will be 1828da71b7e3SCédric Le Goater * resized dynamically when the controller is configured by the FW 1829da71b7e3SCédric Le Goater * to limit accesses to resources not provisioned. 1830da71b7e3SCédric Le Goater */ 1831da71b7e3SCédric Le Goater object_property_set_int(OBJECT(xsrc), "flags", XIVE_SRC_STORE_EOI, 1832da71b7e3SCédric Le Goater &error_fatal); 1833da71b7e3SCédric Le Goater object_property_set_int(OBJECT(xsrc), "nr-irqs", PNV_XIVE2_NR_IRQS, 1834da71b7e3SCédric Le Goater &error_fatal); 1835da71b7e3SCédric Le Goater object_property_set_link(OBJECT(xsrc), "xive", OBJECT(xive), 1836da71b7e3SCédric Le Goater &error_fatal); 1837da71b7e3SCédric Le Goater qdev_realize(DEVICE(xsrc), NULL, &local_err); 1838da71b7e3SCédric Le Goater if (local_err) { 1839da71b7e3SCédric Le Goater error_propagate(errp, local_err); 1840da71b7e3SCédric Le Goater return; 1841da71b7e3SCédric Le Goater } 1842da71b7e3SCédric Le Goater 1843da71b7e3SCédric Le Goater object_property_set_int(OBJECT(end_xsrc), "nr-ends", PNV_XIVE2_NR_ENDS, 1844da71b7e3SCédric Le Goater &error_fatal); 1845da71b7e3SCédric Le Goater object_property_set_link(OBJECT(end_xsrc), "xive", OBJECT(xive), 1846da71b7e3SCédric Le Goater &error_abort); 1847da71b7e3SCédric Le Goater qdev_realize(DEVICE(end_xsrc), NULL, &local_err); 1848da71b7e3SCédric Le Goater if (local_err) { 1849da71b7e3SCédric Le Goater error_propagate(errp, local_err); 1850da71b7e3SCédric Le Goater return; 1851da71b7e3SCédric Le Goater } 1852da71b7e3SCédric Le Goater 1853da71b7e3SCédric Le Goater /* XSCOM region, used for initial configuration of the BARs */ 1854da71b7e3SCédric Le Goater memory_region_init_io(&xive->xscom_regs, OBJECT(dev), 1855da71b7e3SCédric Le Goater &pnv_xive2_xscom_ops, xive, "xscom-xive", 1856da71b7e3SCédric Le Goater PNV10_XSCOM_XIVE2_SIZE << 3); 1857da71b7e3SCédric Le Goater 1858da71b7e3SCédric Le Goater /* Interrupt controller MMIO regions */ 1859da71b7e3SCédric Le Goater xive->ic_shift = 16; 1860da71b7e3SCédric Le Goater memory_region_init(&xive->ic_mmio, OBJECT(dev), "xive-ic", 1861da71b7e3SCédric Le Goater PNV10_XIVE2_IC_SIZE); 1862da71b7e3SCédric Le Goater 1863da71b7e3SCédric Le Goater for (i = 0; i < ARRAY_SIZE(xive->ic_mmios); i++) { 1864da71b7e3SCédric Le Goater memory_region_init_io(&xive->ic_mmios[i], OBJECT(dev), 1865da71b7e3SCédric Le Goater pnv_xive2_ic_regions[i].ops, xive, 1866da71b7e3SCédric Le Goater pnv_xive2_ic_regions[i].name, 1867da71b7e3SCédric Le Goater pnv_xive2_ic_regions[i].pgsize << xive->ic_shift); 1868da71b7e3SCédric Le Goater } 1869da71b7e3SCédric Le Goater 1870da71b7e3SCédric Le Goater /* 1871da71b7e3SCédric Le Goater * VC MMIO regions. 1872da71b7e3SCédric Le Goater */ 1873da71b7e3SCédric Le Goater xive->esb_shift = 16; 1874da71b7e3SCédric Le Goater xive->end_shift = 16; 1875da71b7e3SCédric Le Goater memory_region_init(&xive->esb_mmio, OBJECT(xive), "xive-esb", 1876da71b7e3SCédric Le Goater PNV10_XIVE2_ESB_SIZE); 1877da71b7e3SCédric Le Goater memory_region_init(&xive->end_mmio, OBJECT(xive), "xive-end", 1878da71b7e3SCédric Le Goater PNV10_XIVE2_END_SIZE); 1879da71b7e3SCédric Le Goater 1880da71b7e3SCédric Le Goater /* Presenter Controller MMIO region (not modeled) */ 1881da71b7e3SCédric Le Goater xive->nvc_shift = 16; 1882da71b7e3SCédric Le Goater xive->nvpg_shift = 16; 1883da71b7e3SCédric Le Goater memory_region_init_io(&xive->nvc_mmio, OBJECT(dev), 1884da71b7e3SCédric Le Goater &pnv_xive2_nvc_ops, xive, 1885da71b7e3SCédric Le Goater "xive-nvc", PNV10_XIVE2_NVC_SIZE); 1886da71b7e3SCédric Le Goater 1887da71b7e3SCédric Le Goater memory_region_init_io(&xive->nvpg_mmio, OBJECT(dev), 1888da71b7e3SCédric Le Goater &pnv_xive2_nvpg_ops, xive, 1889da71b7e3SCédric Le Goater "xive-nvpg", PNV10_XIVE2_NVPG_SIZE); 1890da71b7e3SCédric Le Goater 1891da71b7e3SCédric Le Goater /* Thread Interrupt Management Area (Direct) */ 1892da71b7e3SCédric Le Goater xive->tm_shift = 16; 1893da71b7e3SCédric Le Goater memory_region_init_io(&xive->tm_mmio, OBJECT(dev), &pnv_xive2_tm_ops, 1894da71b7e3SCédric Le Goater xive, "xive-tima", PNV10_XIVE2_TM_SIZE); 1895da71b7e3SCédric Le Goater 1896da71b7e3SCédric Le Goater qemu_register_reset(pnv_xive2_reset, dev); 1897da71b7e3SCédric Le Goater } 1898da71b7e3SCédric Le Goater 1899da71b7e3SCédric Le Goater static Property pnv_xive2_properties[] = { 1900da71b7e3SCédric Le Goater DEFINE_PROP_UINT64("ic-bar", PnvXive2, ic_base, 0), 1901da71b7e3SCédric Le Goater DEFINE_PROP_UINT64("esb-bar", PnvXive2, esb_base, 0), 1902da71b7e3SCédric Le Goater DEFINE_PROP_UINT64("end-bar", PnvXive2, end_base, 0), 1903da71b7e3SCédric Le Goater DEFINE_PROP_UINT64("nvc-bar", PnvXive2, nvc_base, 0), 1904da71b7e3SCédric Le Goater DEFINE_PROP_UINT64("nvpg-bar", PnvXive2, nvpg_base, 0), 1905da71b7e3SCédric Le Goater DEFINE_PROP_UINT64("tm-bar", PnvXive2, tm_base, 0), 1906da71b7e3SCédric Le Goater DEFINE_PROP_UINT64("capabilities", PnvXive2, capabilities, 1907da71b7e3SCédric Le Goater PNV_XIVE2_CAPABILITIES), 1908da71b7e3SCédric Le Goater DEFINE_PROP_UINT64("config", PnvXive2, config, 1909da71b7e3SCédric Le Goater PNV_XIVE2_CONFIGURATION), 1910da71b7e3SCédric Le Goater DEFINE_PROP_LINK("chip", PnvXive2, chip, TYPE_PNV_CHIP, PnvChip *), 1911da71b7e3SCédric Le Goater DEFINE_PROP_END_OF_LIST(), 1912da71b7e3SCédric Le Goater }; 1913da71b7e3SCédric Le Goater 1914da71b7e3SCédric Le Goater static void pnv_xive2_instance_init(Object *obj) 1915da71b7e3SCédric Le Goater { 1916da71b7e3SCédric Le Goater PnvXive2 *xive = PNV_XIVE2(obj); 1917da71b7e3SCédric Le Goater 1918da71b7e3SCédric Le Goater object_initialize_child(obj, "ipi_source", &xive->ipi_source, 1919da71b7e3SCédric Le Goater TYPE_XIVE_SOURCE); 1920da71b7e3SCédric Le Goater object_initialize_child(obj, "end_source", &xive->end_source, 1921da71b7e3SCédric Le Goater TYPE_XIVE2_END_SOURCE); 1922da71b7e3SCédric Le Goater } 1923da71b7e3SCédric Le Goater 1924da71b7e3SCédric Le Goater static int pnv_xive2_dt_xscom(PnvXScomInterface *dev, void *fdt, 1925da71b7e3SCédric Le Goater int xscom_offset) 1926da71b7e3SCédric Le Goater { 1927da71b7e3SCédric Le Goater const char compat_p10[] = "ibm,power10-xive-x"; 1928da71b7e3SCédric Le Goater char *name; 1929da71b7e3SCédric Le Goater int offset; 1930da71b7e3SCédric Le Goater uint32_t reg[] = { 1931da71b7e3SCédric Le Goater cpu_to_be32(PNV10_XSCOM_XIVE2_BASE), 1932da71b7e3SCédric Le Goater cpu_to_be32(PNV10_XSCOM_XIVE2_SIZE) 1933da71b7e3SCédric Le Goater }; 1934da71b7e3SCédric Le Goater 1935da71b7e3SCédric Le Goater name = g_strdup_printf("xive@%x", PNV10_XSCOM_XIVE2_BASE); 1936da71b7e3SCédric Le Goater offset = fdt_add_subnode(fdt, xscom_offset, name); 1937da71b7e3SCédric Le Goater _FDT(offset); 1938da71b7e3SCédric Le Goater g_free(name); 1939da71b7e3SCédric Le Goater 1940da71b7e3SCédric Le Goater _FDT((fdt_setprop(fdt, offset, "reg", reg, sizeof(reg)))); 1941da71b7e3SCédric Le Goater _FDT(fdt_setprop(fdt, offset, "compatible", compat_p10, 1942da71b7e3SCédric Le Goater sizeof(compat_p10))); 1943da71b7e3SCédric Le Goater return 0; 1944da71b7e3SCédric Le Goater } 1945da71b7e3SCédric Le Goater 1946da71b7e3SCédric Le Goater static void pnv_xive2_class_init(ObjectClass *klass, void *data) 1947da71b7e3SCédric Le Goater { 1948da71b7e3SCédric Le Goater DeviceClass *dc = DEVICE_CLASS(klass); 1949da71b7e3SCédric Le Goater PnvXScomInterfaceClass *xdc = PNV_XSCOM_INTERFACE_CLASS(klass); 1950da71b7e3SCédric Le Goater Xive2RouterClass *xrc = XIVE2_ROUTER_CLASS(klass); 1951da71b7e3SCédric Le Goater XiveNotifierClass *xnc = XIVE_NOTIFIER_CLASS(klass); 1952da71b7e3SCédric Le Goater XivePresenterClass *xpc = XIVE_PRESENTER_CLASS(klass); 1953da71b7e3SCédric Le Goater PnvXive2Class *pxc = PNV_XIVE2_CLASS(klass); 1954da71b7e3SCédric Le Goater 1955da71b7e3SCédric Le Goater xdc->dt_xscom = pnv_xive2_dt_xscom; 1956da71b7e3SCédric Le Goater 1957da71b7e3SCédric Le Goater dc->desc = "PowerNV XIVE2 Interrupt Controller (POWER10)"; 1958da71b7e3SCédric Le Goater device_class_set_parent_realize(dc, pnv_xive2_realize, 1959da71b7e3SCédric Le Goater &pxc->parent_realize); 1960da71b7e3SCédric Le Goater device_class_set_props(dc, pnv_xive2_properties); 1961da71b7e3SCédric Le Goater 1962da71b7e3SCédric Le Goater xrc->get_eas = pnv_xive2_get_eas; 19630aa2612aSCédric Le Goater xrc->get_pq = pnv_xive2_get_pq; 19640aa2612aSCédric Le Goater xrc->set_pq = pnv_xive2_set_pq; 1965da71b7e3SCédric Le Goater xrc->get_end = pnv_xive2_get_end; 1966da71b7e3SCédric Le Goater xrc->write_end = pnv_xive2_write_end; 1967da71b7e3SCédric Le Goater xrc->get_nvp = pnv_xive2_get_nvp; 1968da71b7e3SCédric Le Goater xrc->write_nvp = pnv_xive2_write_nvp; 1969e16032b8SCédric Le Goater xrc->get_config = pnv_xive2_get_config; 1970da71b7e3SCédric Le Goater xrc->get_block_id = pnv_xive2_get_block_id; 1971da71b7e3SCédric Le Goater 1972da71b7e3SCédric Le Goater xnc->notify = pnv_xive2_notify; 1973da71b7e3SCédric Le Goater 1974da71b7e3SCédric Le Goater xpc->match_nvt = pnv_xive2_match_nvt; 1975da71b7e3SCédric Le Goater }; 1976da71b7e3SCédric Le Goater 1977da71b7e3SCédric Le Goater static const TypeInfo pnv_xive2_info = { 1978da71b7e3SCédric Le Goater .name = TYPE_PNV_XIVE2, 1979da71b7e3SCédric Le Goater .parent = TYPE_XIVE2_ROUTER, 1980da71b7e3SCédric Le Goater .instance_init = pnv_xive2_instance_init, 1981da71b7e3SCédric Le Goater .instance_size = sizeof(PnvXive2), 1982da71b7e3SCédric Le Goater .class_init = pnv_xive2_class_init, 1983da71b7e3SCédric Le Goater .class_size = sizeof(PnvXive2Class), 1984da71b7e3SCédric Le Goater .interfaces = (InterfaceInfo[]) { 1985da71b7e3SCédric Le Goater { TYPE_PNV_XSCOM_INTERFACE }, 1986da71b7e3SCédric Le Goater { } 1987da71b7e3SCédric Le Goater } 1988da71b7e3SCédric Le Goater }; 1989da71b7e3SCédric Le Goater 1990da71b7e3SCédric Le Goater static void pnv_xive2_register_types(void) 1991da71b7e3SCédric Le Goater { 1992da71b7e3SCédric Le Goater type_register_static(&pnv_xive2_info); 1993da71b7e3SCédric Le Goater } 1994da71b7e3SCédric Le Goater 1995da71b7e3SCédric Le Goater type_init(pnv_xive2_register_types) 1996da71b7e3SCédric Le Goater 1997da71b7e3SCédric Le Goater static void xive2_nvp_pic_print_info(Xive2Nvp *nvp, uint32_t nvp_idx, 1998da71b7e3SCédric Le Goater Monitor *mon) 1999da71b7e3SCédric Le Goater { 2000da71b7e3SCédric Le Goater uint8_t eq_blk = xive_get_field32(NVP2_W5_VP_END_BLOCK, nvp->w5); 2001da71b7e3SCédric Le Goater uint32_t eq_idx = xive_get_field32(NVP2_W5_VP_END_INDEX, nvp->w5); 2002da71b7e3SCédric Le Goater 2003da71b7e3SCédric Le Goater if (!xive2_nvp_is_valid(nvp)) { 2004da71b7e3SCédric Le Goater return; 2005da71b7e3SCédric Le Goater } 2006da71b7e3SCédric Le Goater 2007*835806f1SCédric Le Goater monitor_printf(mon, " %08x end:%02x/%04x IPB:%02x", 2008da71b7e3SCédric Le Goater nvp_idx, eq_blk, eq_idx, 2009da71b7e3SCédric Le Goater xive_get_field32(NVP2_W2_IPB, nvp->w2)); 2010*835806f1SCédric Le Goater /* 2011*835806f1SCédric Le Goater * When the NVP is HW controlled, more fields are updated 2012*835806f1SCédric Le Goater */ 2013*835806f1SCédric Le Goater if (xive2_nvp_is_hw(nvp)) { 2014*835806f1SCédric Le Goater monitor_printf(mon, " CPPR:%02x", 2015*835806f1SCédric Le Goater xive_get_field32(NVP2_W2_CPPR, nvp->w2)); 2016*835806f1SCédric Le Goater if (xive2_nvp_is_co(nvp)) { 2017*835806f1SCédric Le Goater monitor_printf(mon, " CO:%04x", 2018*835806f1SCédric Le Goater xive_get_field32(NVP2_W1_CO_THRID, nvp->w1)); 2019*835806f1SCédric Le Goater } 2020*835806f1SCédric Le Goater } 2021*835806f1SCédric Le Goater monitor_printf(mon, "\n"); 2022da71b7e3SCédric Le Goater } 2023da71b7e3SCédric Le Goater 2024da71b7e3SCédric Le Goater /* 2025da71b7e3SCédric Le Goater * If the table is direct, we can compute the number of PQ entries 2026da71b7e3SCédric Le Goater * provisioned by FW. 2027da71b7e3SCédric Le Goater */ 2028da71b7e3SCédric Le Goater static uint32_t pnv_xive2_nr_esbs(PnvXive2 *xive) 2029da71b7e3SCédric Le Goater { 2030da71b7e3SCédric Le Goater uint8_t blk = pnv_xive2_block_id(xive); 2031da71b7e3SCédric Le Goater uint64_t vsd = xive->vsds[VST_ESB][blk]; 2032da71b7e3SCédric Le Goater uint64_t vst_tsize = 1ull << (GETFIELD(VSD_TSIZE, vsd) + 12); 2033da71b7e3SCédric Le Goater 2034da71b7e3SCédric Le Goater return VSD_INDIRECT & vsd ? 0 : vst_tsize * SBE_PER_BYTE; 2035da71b7e3SCédric Le Goater } 2036da71b7e3SCédric Le Goater 2037da71b7e3SCédric Le Goater /* 2038da71b7e3SCédric Le Goater * Compute the number of entries per indirect subpage. 2039da71b7e3SCédric Le Goater */ 2040da71b7e3SCédric Le Goater static uint64_t pnv_xive2_vst_per_subpage(PnvXive2 *xive, uint32_t type) 2041da71b7e3SCédric Le Goater { 2042da71b7e3SCédric Le Goater uint8_t blk = pnv_xive2_block_id(xive); 2043da71b7e3SCédric Le Goater uint64_t vsd = xive->vsds[type][blk]; 2044da71b7e3SCédric Le Goater const XiveVstInfo *info = &vst_infos[type]; 2045da71b7e3SCédric Le Goater uint64_t vsd_addr; 2046da71b7e3SCédric Le Goater uint32_t page_shift; 2047da71b7e3SCédric Le Goater 2048da71b7e3SCédric Le Goater /* For direct tables, fake a valid value */ 2049da71b7e3SCédric Le Goater if (!(VSD_INDIRECT & vsd)) { 2050da71b7e3SCédric Le Goater return 1; 2051da71b7e3SCédric Le Goater } 2052da71b7e3SCédric Le Goater 2053da71b7e3SCédric Le Goater /* Get the page size of the indirect table. */ 2054da71b7e3SCédric Le Goater vsd_addr = vsd & VSD_ADDRESS_MASK; 2055da71b7e3SCédric Le Goater ldq_be_dma(&address_space_memory, vsd_addr, &vsd, MEMTXATTRS_UNSPECIFIED); 2056da71b7e3SCédric Le Goater 2057da71b7e3SCédric Le Goater if (!(vsd & VSD_ADDRESS_MASK)) { 2058da71b7e3SCédric Le Goater #ifdef XIVE2_DEBUG 2059da71b7e3SCédric Le Goater xive2_error(xive, "VST: invalid %s entry!?", info->name); 2060da71b7e3SCédric Le Goater #endif 2061da71b7e3SCédric Le Goater return 0; 2062da71b7e3SCédric Le Goater } 2063da71b7e3SCédric Le Goater 2064da71b7e3SCédric Le Goater page_shift = GETFIELD(VSD_TSIZE, vsd) + 12; 2065da71b7e3SCédric Le Goater 2066da71b7e3SCédric Le Goater if (!pnv_xive2_vst_page_size_allowed(page_shift)) { 2067da71b7e3SCédric Le Goater xive2_error(xive, "VST: invalid %s page shift %d", info->name, 2068da71b7e3SCédric Le Goater page_shift); 2069da71b7e3SCédric Le Goater return 0; 2070da71b7e3SCédric Le Goater } 2071da71b7e3SCédric Le Goater 2072da71b7e3SCédric Le Goater return (1ull << page_shift) / info->size; 2073da71b7e3SCédric Le Goater } 2074da71b7e3SCédric Le Goater 2075da71b7e3SCédric Le Goater void pnv_xive2_pic_print_info(PnvXive2 *xive, Monitor *mon) 2076da71b7e3SCédric Le Goater { 2077da71b7e3SCédric Le Goater Xive2Router *xrtr = XIVE2_ROUTER(xive); 2078da71b7e3SCédric Le Goater uint8_t blk = pnv_xive2_block_id(xive); 2079da71b7e3SCédric Le Goater uint8_t chip_id = xive->chip->chip_id; 2080da71b7e3SCédric Le Goater uint32_t srcno0 = XIVE_EAS(blk, 0); 2081da71b7e3SCédric Le Goater uint32_t nr_esbs = pnv_xive2_nr_esbs(xive); 2082da71b7e3SCédric Le Goater Xive2Eas eas; 2083da71b7e3SCédric Le Goater Xive2End end; 2084da71b7e3SCédric Le Goater Xive2Nvp nvp; 2085da71b7e3SCédric Le Goater int i; 2086da71b7e3SCédric Le Goater uint64_t xive_nvp_per_subpage; 2087da71b7e3SCédric Le Goater 2088da71b7e3SCédric Le Goater monitor_printf(mon, "XIVE[%x] Source %08x .. %08x\n", blk, srcno0, 2089da71b7e3SCédric Le Goater srcno0 + nr_esbs - 1); 2090da71b7e3SCédric Le Goater xive_source_pic_print_info(&xive->ipi_source, srcno0, mon); 2091da71b7e3SCédric Le Goater 2092da71b7e3SCédric Le Goater monitor_printf(mon, "XIVE[%x] EAT %08x .. %08x\n", blk, srcno0, 2093da71b7e3SCédric Le Goater srcno0 + nr_esbs - 1); 2094da71b7e3SCédric Le Goater for (i = 0; i < nr_esbs; i++) { 2095da71b7e3SCédric Le Goater if (xive2_router_get_eas(xrtr, blk, i, &eas)) { 2096da71b7e3SCédric Le Goater break; 2097da71b7e3SCédric Le Goater } 2098da71b7e3SCédric Le Goater if (!xive2_eas_is_masked(&eas)) { 2099da71b7e3SCédric Le Goater xive2_eas_pic_print_info(&eas, i, mon); 2100da71b7e3SCédric Le Goater } 2101da71b7e3SCédric Le Goater } 2102da71b7e3SCédric Le Goater 2103da71b7e3SCédric Le Goater monitor_printf(mon, "XIVE[%x] #%d END Escalation EAT\n", chip_id, blk); 2104da71b7e3SCédric Le Goater i = 0; 2105da71b7e3SCédric Le Goater while (!xive2_router_get_end(xrtr, blk, i, &end)) { 2106da71b7e3SCédric Le Goater xive2_end_eas_pic_print_info(&end, i++, mon); 2107da71b7e3SCédric Le Goater } 2108da71b7e3SCédric Le Goater 2109da71b7e3SCédric Le Goater monitor_printf(mon, "XIVE[%x] #%d ENDT\n", chip_id, blk); 2110da71b7e3SCédric Le Goater i = 0; 2111da71b7e3SCédric Le Goater while (!xive2_router_get_end(xrtr, blk, i, &end)) { 2112da71b7e3SCédric Le Goater xive2_end_pic_print_info(&end, i++, mon); 2113da71b7e3SCédric Le Goater } 2114da71b7e3SCédric Le Goater 2115da71b7e3SCédric Le Goater monitor_printf(mon, "XIVE[%x] #%d NVPT %08x .. %08x\n", chip_id, blk, 2116da71b7e3SCédric Le Goater 0, XIVE2_NVP_COUNT - 1); 2117da71b7e3SCédric Le Goater xive_nvp_per_subpage = pnv_xive2_vst_per_subpage(xive, VST_NVP); 2118da71b7e3SCédric Le Goater for (i = 0; i < XIVE2_NVP_COUNT; i += xive_nvp_per_subpage) { 2119da71b7e3SCédric Le Goater while (!xive2_router_get_nvp(xrtr, blk, i, &nvp)) { 2120da71b7e3SCédric Le Goater xive2_nvp_pic_print_info(&nvp, i++, mon); 2121da71b7e3SCédric Le Goater } 2122da71b7e3SCédric Le Goater } 2123da71b7e3SCédric Le Goater } 2124