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