1 /* 2 * QEMU model of Xilinx I/O Module Interrupt Controller 3 * 4 * Copyright (c) 2013 Xilinx Inc 5 * Written by Edgar E. Iglesias <edgar.iglesias@xilinx.com> 6 * Written by Alistair Francis <alistair.francis@xilinx.com> 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a copy 9 * of this software and associated documentation files (the "Software"), to deal 10 * in the Software without restriction, including without limitation the rights 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 * copies of the Software, and to permit persons to whom the Software is 13 * furnished to do so, subject to the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be included in 16 * all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 * THE SOFTWARE. 25 */ 26 27 #include "qemu/osdep.h" 28 #include "hw/sysbus.h" 29 #include "migration/vmstate.h" 30 #include "hw/register.h" 31 #include "qemu/bitops.h" 32 #include "qemu/log.h" 33 #include "qemu/module.h" 34 #include "hw/intc/xlnx-pmu-iomod-intc.h" 35 #include "hw/irq.h" 36 37 #ifndef XLNX_PMU_IO_INTC_ERR_DEBUG 38 #define XLNX_PMU_IO_INTC_ERR_DEBUG 0 39 #endif 40 41 #define DB_PRINT_L(lvl, fmt, args...) do {\ 42 if (XLNX_PMU_IO_INTC_ERR_DEBUG >= lvl) {\ 43 qemu_log(TYPE_XLNX_PMU_IO_INTC ": %s:" fmt, __func__, ## args);\ 44 } \ 45 } while (0) 46 47 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args) 48 49 REG32(IRQ_MODE, 0xc) 50 REG32(GPO0, 0x10) 51 FIELD(GPO0, MAGIC_WORD_1, 24, 8) 52 FIELD(GPO0, MAGIC_WORD_2, 16, 8) 53 FIELD(GPO0, FT_INJECT_FAILURE, 13, 3) 54 FIELD(GPO0, DISABLE_RST_FTSM, 12, 1) 55 FIELD(GPO0, RST_FTSM, 11, 1) 56 FIELD(GPO0, CLR_FTSTS, 10, 1) 57 FIELD(GPO0, RST_ON_SLEEP, 9, 1) 58 FIELD(GPO0, DISABLE_TRACE_COMP, 8, 1) 59 FIELD(GPO0, PIT3_PRESCALE, 7, 1) 60 FIELD(GPO0, PIT2_PRESCALE, 5, 2) 61 FIELD(GPO0, PIT1_PRESCALE, 3, 2) 62 FIELD(GPO0, PIT0_PRESCALE, 1, 2) 63 FIELD(GPO0, DEBUG_REMAP, 0, 1) 64 REG32(GPO1, 0x14) 65 FIELD(GPO1, MIO_5, 5, 1) 66 FIELD(GPO1, MIO_4, 4, 1) 67 FIELD(GPO1, MIO_3, 3, 1) 68 FIELD(GPO1, MIO_2, 2, 1) 69 FIELD(GPO1, MIO_1, 1, 1) 70 FIELD(GPO1, MIO_0, 0, 1) 71 REG32(GPO2, 0x18) 72 FIELD(GPO2, DAP_RPU_WAKE_ACK, 9, 1) 73 FIELD(GPO2, DAP_FP_WAKE_ACK, 8, 1) 74 FIELD(GPO2, PS_STATUS, 7, 1) 75 FIELD(GPO2, PCAP_EN, 6, 1) 76 REG32(GPO3, 0x1c) 77 FIELD(GPO3, PL_GPO_31, 31, 1) 78 FIELD(GPO3, PL_GPO_30, 30, 1) 79 FIELD(GPO3, PL_GPO_29, 29, 1) 80 FIELD(GPO3, PL_GPO_28, 28, 1) 81 FIELD(GPO3, PL_GPO_27, 27, 1) 82 FIELD(GPO3, PL_GPO_26, 26, 1) 83 FIELD(GPO3, PL_GPO_25, 25, 1) 84 FIELD(GPO3, PL_GPO_24, 24, 1) 85 FIELD(GPO3, PL_GPO_23, 23, 1) 86 FIELD(GPO3, PL_GPO_22, 22, 1) 87 FIELD(GPO3, PL_GPO_21, 21, 1) 88 FIELD(GPO3, PL_GPO_20, 20, 1) 89 FIELD(GPO3, PL_GPO_19, 19, 1) 90 FIELD(GPO3, PL_GPO_18, 18, 1) 91 FIELD(GPO3, PL_GPO_17, 17, 1) 92 FIELD(GPO3, PL_GPO_16, 16, 1) 93 FIELD(GPO3, PL_GPO_15, 15, 1) 94 FIELD(GPO3, PL_GPO_14, 14, 1) 95 FIELD(GPO3, PL_GPO_13, 13, 1) 96 FIELD(GPO3, PL_GPO_12, 12, 1) 97 FIELD(GPO3, PL_GPO_11, 11, 1) 98 FIELD(GPO3, PL_GPO_10, 10, 1) 99 FIELD(GPO3, PL_GPO_9, 9, 1) 100 FIELD(GPO3, PL_GPO_8, 8, 1) 101 FIELD(GPO3, PL_GPO_7, 7, 1) 102 FIELD(GPO3, PL_GPO_6, 6, 1) 103 FIELD(GPO3, PL_GPO_5, 5, 1) 104 FIELD(GPO3, PL_GPO_4, 4, 1) 105 FIELD(GPO3, PL_GPO_3, 3, 1) 106 FIELD(GPO3, PL_GPO_2, 2, 1) 107 FIELD(GPO3, PL_GPO_1, 1, 1) 108 FIELD(GPO3, PL_GPO_0, 0, 1) 109 REG32(GPI0, 0x20) 110 FIELD(GPI0, RFT_ECC_FATAL_ERR, 31, 1) 111 FIELD(GPI0, RFT_VOTER_ERR, 30, 1) 112 FIELD(GPI0, RFT_COMPARE_ERR_23, 29, 1) 113 FIELD(GPI0, RFT_COMPARE_ERR_13, 28, 1) 114 FIELD(GPI0, RFT_COMPARE_ERR_12, 27, 1) 115 FIELD(GPI0, RFT_LS_MISMATCH_23_B, 26, 1) 116 FIELD(GPI0, RFT_LS_MISMATCH_13_B, 25, 1) 117 FIELD(GPI0, RFT_LS_MISMATCH_12_B, 24, 1) 118 FIELD(GPI0, RFT_MISMATCH_STATE, 23, 1) 119 FIELD(GPI0, RFT_MISMATCH_CPU, 22, 1) 120 FIELD(GPI0, RFT_SLEEP_RESET, 19, 1) 121 FIELD(GPI0, RFT_LS_MISMATCH_23_A, 18, 1) 122 FIELD(GPI0, RFT_LS_MISMATCH_13_A, 17, 1) 123 FIELD(GPI0, RFT_LS_MISMATCH_12_A, 16, 1) 124 FIELD(GPI0, NFT_ECC_FATAL_ERR, 15, 1) 125 FIELD(GPI0, NFT_VOTER_ERR, 14, 1) 126 FIELD(GPI0, NFT_COMPARE_ERR_23, 13, 1) 127 FIELD(GPI0, NFT_COMPARE_ERR_13, 12, 1) 128 FIELD(GPI0, NFT_COMPARE_ERR_12, 11, 1) 129 FIELD(GPI0, NFT_LS_MISMATCH_23_B, 10, 1) 130 FIELD(GPI0, NFT_LS_MISMATCH_13_B, 9, 1) 131 FIELD(GPI0, NFT_LS_MISMATCH_12_B, 8, 1) 132 FIELD(GPI0, NFT_MISMATCH_STATE, 7, 1) 133 FIELD(GPI0, NFT_MISMATCH_CPU, 6, 1) 134 FIELD(GPI0, NFT_SLEEP_RESET, 3, 1) 135 FIELD(GPI0, NFT_LS_MISMATCH_23_A, 2, 1) 136 FIELD(GPI0, NFT_LS_MISMATCH_13_A, 1, 1) 137 FIELD(GPI0, NFT_LS_MISMATCH_12_A, 0, 1) 138 REG32(GPI1, 0x24) 139 FIELD(GPI1, APB_AIB_ERROR, 31, 1) 140 FIELD(GPI1, AXI_AIB_ERROR, 30, 1) 141 FIELD(GPI1, ERROR_2, 29, 1) 142 FIELD(GPI1, ERROR_1, 28, 1) 143 FIELD(GPI1, ACPU_3_DBG_PWRUP, 23, 1) 144 FIELD(GPI1, ACPU_2_DBG_PWRUP, 22, 1) 145 FIELD(GPI1, ACPU_1_DBG_PWRUP, 21, 1) 146 FIELD(GPI1, ACPU_0_DBG_PWRUP, 20, 1) 147 FIELD(GPI1, FPD_WAKE_GIC_PROXY, 16, 1) 148 FIELD(GPI1, MIO_WAKE_5, 15, 1) 149 FIELD(GPI1, MIO_WAKE_4, 14, 1) 150 FIELD(GPI1, MIO_WAKE_3, 13, 1) 151 FIELD(GPI1, MIO_WAKE_2, 12, 1) 152 FIELD(GPI1, MIO_WAKE_1, 11, 1) 153 FIELD(GPI1, MIO_WAKE_0, 10, 1) 154 FIELD(GPI1, DAP_RPU_WAKE, 9, 1) 155 FIELD(GPI1, DAP_FPD_WAKE, 8, 1) 156 FIELD(GPI1, USB_1_WAKE, 7, 1) 157 FIELD(GPI1, USB_0_WAKE, 6, 1) 158 FIELD(GPI1, R5_1_WAKE, 5, 1) 159 FIELD(GPI1, R5_0_WAKE, 4, 1) 160 FIELD(GPI1, ACPU_3_WAKE, 3, 1) 161 FIELD(GPI1, ACPU_2_WAKE, 2, 1) 162 FIELD(GPI1, ACPU_1_WAKE, 1, 1) 163 FIELD(GPI1, ACPU_0_WAKE, 0, 1) 164 REG32(GPI2, 0x28) 165 FIELD(GPI2, VCC_INT_FP_DISCONNECT, 31, 1) 166 FIELD(GPI2, VCC_INT_DISCONNECT, 30, 1) 167 FIELD(GPI2, VCC_AUX_DISCONNECT, 29, 1) 168 FIELD(GPI2, DBG_ACPU3_RST_REQ, 23, 1) 169 FIELD(GPI2, DBG_ACPU2_RST_REQ, 22, 1) 170 FIELD(GPI2, DBG_ACPU1_RST_REQ, 21, 1) 171 FIELD(GPI2, DBG_ACPU0_RST_REQ, 20, 1) 172 FIELD(GPI2, CP_ACPU3_RST_REQ, 19, 1) 173 FIELD(GPI2, CP_ACPU2_RST_REQ, 18, 1) 174 FIELD(GPI2, CP_ACPU1_RST_REQ, 17, 1) 175 FIELD(GPI2, CP_ACPU0_RST_REQ, 16, 1) 176 FIELD(GPI2, DBG_RCPU1_RST_REQ, 9, 1) 177 FIELD(GPI2, DBG_RCPU0_RST_REQ, 8, 1) 178 FIELD(GPI2, R5_1_SLEEP, 5, 1) 179 FIELD(GPI2, R5_0_SLEEP, 4, 1) 180 FIELD(GPI2, ACPU_3_SLEEP, 3, 1) 181 FIELD(GPI2, ACPU_2_SLEEP, 2, 1) 182 FIELD(GPI2, ACPU_1_SLEEP, 1, 1) 183 FIELD(GPI2, ACPU_0_SLEEP, 0, 1) 184 REG32(GPI3, 0x2c) 185 FIELD(GPI3, PL_GPI_31, 31, 1) 186 FIELD(GPI3, PL_GPI_30, 30, 1) 187 FIELD(GPI3, PL_GPI_29, 29, 1) 188 FIELD(GPI3, PL_GPI_28, 28, 1) 189 FIELD(GPI3, PL_GPI_27, 27, 1) 190 FIELD(GPI3, PL_GPI_26, 26, 1) 191 FIELD(GPI3, PL_GPI_25, 25, 1) 192 FIELD(GPI3, PL_GPI_24, 24, 1) 193 FIELD(GPI3, PL_GPI_23, 23, 1) 194 FIELD(GPI3, PL_GPI_22, 22, 1) 195 FIELD(GPI3, PL_GPI_21, 21, 1) 196 FIELD(GPI3, PL_GPI_20, 20, 1) 197 FIELD(GPI3, PL_GPI_19, 19, 1) 198 FIELD(GPI3, PL_GPI_18, 18, 1) 199 FIELD(GPI3, PL_GPI_17, 17, 1) 200 FIELD(GPI3, PL_GPI_16, 16, 1) 201 FIELD(GPI3, PL_GPI_15, 15, 1) 202 FIELD(GPI3, PL_GPI_14, 14, 1) 203 FIELD(GPI3, PL_GPI_13, 13, 1) 204 FIELD(GPI3, PL_GPI_12, 12, 1) 205 FIELD(GPI3, PL_GPI_11, 11, 1) 206 FIELD(GPI3, PL_GPI_10, 10, 1) 207 FIELD(GPI3, PL_GPI_9, 9, 1) 208 FIELD(GPI3, PL_GPI_8, 8, 1) 209 FIELD(GPI3, PL_GPI_7, 7, 1) 210 FIELD(GPI3, PL_GPI_6, 6, 1) 211 FIELD(GPI3, PL_GPI_5, 5, 1) 212 FIELD(GPI3, PL_GPI_4, 4, 1) 213 FIELD(GPI3, PL_GPI_3, 3, 1) 214 FIELD(GPI3, PL_GPI_2, 2, 1) 215 FIELD(GPI3, PL_GPI_1, 1, 1) 216 FIELD(GPI3, PL_GPI_0, 0, 1) 217 REG32(IRQ_STATUS, 0x30) 218 FIELD(IRQ_STATUS, CSU_PMU_SEC_LOCK, 31, 1) 219 FIELD(IRQ_STATUS, INV_ADDR, 29, 1) 220 FIELD(IRQ_STATUS, PWR_DN_REQ, 28, 1) 221 FIELD(IRQ_STATUS, PWR_UP_REQ, 27, 1) 222 FIELD(IRQ_STATUS, SW_RST_REQ, 26, 1) 223 FIELD(IRQ_STATUS, HW_RST_REQ, 25, 1) 224 FIELD(IRQ_STATUS, ISO_REQ, 24, 1) 225 FIELD(IRQ_STATUS, FW_REQ, 23, 1) 226 FIELD(IRQ_STATUS, IPI3, 22, 1) 227 FIELD(IRQ_STATUS, IPI2, 21, 1) 228 FIELD(IRQ_STATUS, IPI1, 20, 1) 229 FIELD(IRQ_STATUS, IPI0, 19, 1) 230 FIELD(IRQ_STATUS, RTC_ALARM, 18, 1) 231 FIELD(IRQ_STATUS, RTC_EVERY_SECOND, 17, 1) 232 FIELD(IRQ_STATUS, CORRECTABLE_ECC, 16, 1) 233 FIELD(IRQ_STATUS, GPI3, 14, 1) 234 FIELD(IRQ_STATUS, GPI2, 13, 1) 235 FIELD(IRQ_STATUS, GPI1, 12, 1) 236 FIELD(IRQ_STATUS, GPI0, 11, 1) 237 FIELD(IRQ_STATUS, PIT3, 6, 1) 238 FIELD(IRQ_STATUS, PIT2, 5, 1) 239 FIELD(IRQ_STATUS, PIT1, 4, 1) 240 FIELD(IRQ_STATUS, PIT0, 3, 1) 241 REG32(IRQ_PENDING, 0x34) 242 FIELD(IRQ_PENDING, CSU_PMU_SEC_LOCK, 31, 1) 243 FIELD(IRQ_PENDING, INV_ADDR, 29, 1) 244 FIELD(IRQ_PENDING, PWR_DN_REQ, 28, 1) 245 FIELD(IRQ_PENDING, PWR_UP_REQ, 27, 1) 246 FIELD(IRQ_PENDING, SW_RST_REQ, 26, 1) 247 FIELD(IRQ_PENDING, HW_RST_REQ, 25, 1) 248 FIELD(IRQ_PENDING, ISO_REQ, 24, 1) 249 FIELD(IRQ_PENDING, FW_REQ, 23, 1) 250 FIELD(IRQ_PENDING, IPI3, 22, 1) 251 FIELD(IRQ_PENDING, IPI2, 21, 1) 252 FIELD(IRQ_PENDING, IPI1, 20, 1) 253 FIELD(IRQ_PENDING, IPI0, 19, 1) 254 FIELD(IRQ_PENDING, RTC_ALARM, 18, 1) 255 FIELD(IRQ_PENDING, RTC_EVERY_SECOND, 17, 1) 256 FIELD(IRQ_PENDING, CORRECTABLE_ECC, 16, 1) 257 FIELD(IRQ_PENDING, GPI3, 14, 1) 258 FIELD(IRQ_PENDING, GPI2, 13, 1) 259 FIELD(IRQ_PENDING, GPI1, 12, 1) 260 FIELD(IRQ_PENDING, GPI0, 11, 1) 261 FIELD(IRQ_PENDING, PIT3, 6, 1) 262 FIELD(IRQ_PENDING, PIT2, 5, 1) 263 FIELD(IRQ_PENDING, PIT1, 4, 1) 264 FIELD(IRQ_PENDING, PIT0, 3, 1) 265 REG32(IRQ_ENABLE, 0x38) 266 FIELD(IRQ_ENABLE, CSU_PMU_SEC_LOCK, 31, 1) 267 FIELD(IRQ_ENABLE, INV_ADDR, 29, 1) 268 FIELD(IRQ_ENABLE, PWR_DN_REQ, 28, 1) 269 FIELD(IRQ_ENABLE, PWR_UP_REQ, 27, 1) 270 FIELD(IRQ_ENABLE, SW_RST_REQ, 26, 1) 271 FIELD(IRQ_ENABLE, HW_RST_REQ, 25, 1) 272 FIELD(IRQ_ENABLE, ISO_REQ, 24, 1) 273 FIELD(IRQ_ENABLE, FW_REQ, 23, 1) 274 FIELD(IRQ_ENABLE, IPI3, 22, 1) 275 FIELD(IRQ_ENABLE, IPI2, 21, 1) 276 FIELD(IRQ_ENABLE, IPI1, 20, 1) 277 FIELD(IRQ_ENABLE, IPI0, 19, 1) 278 FIELD(IRQ_ENABLE, RTC_ALARM, 18, 1) 279 FIELD(IRQ_ENABLE, RTC_EVERY_SECOND, 17, 1) 280 FIELD(IRQ_ENABLE, CORRECTABLE_ECC, 16, 1) 281 FIELD(IRQ_ENABLE, GPI3, 14, 1) 282 FIELD(IRQ_ENABLE, GPI2, 13, 1) 283 FIELD(IRQ_ENABLE, GPI1, 12, 1) 284 FIELD(IRQ_ENABLE, GPI0, 11, 1) 285 FIELD(IRQ_ENABLE, PIT3, 6, 1) 286 FIELD(IRQ_ENABLE, PIT2, 5, 1) 287 FIELD(IRQ_ENABLE, PIT1, 4, 1) 288 FIELD(IRQ_ENABLE, PIT0, 3, 1) 289 REG32(IRQ_ACK, 0x3c) 290 FIELD(IRQ_ACK, CSU_PMU_SEC_LOCK, 31, 1) 291 FIELD(IRQ_ACK, INV_ADDR, 29, 1) 292 FIELD(IRQ_ACK, PWR_DN_REQ, 28, 1) 293 FIELD(IRQ_ACK, PWR_UP_REQ, 27, 1) 294 FIELD(IRQ_ACK, SW_RST_REQ, 26, 1) 295 FIELD(IRQ_ACK, HW_RST_REQ, 25, 1) 296 FIELD(IRQ_ACK, ISO_REQ, 24, 1) 297 FIELD(IRQ_ACK, FW_REQ, 23, 1) 298 FIELD(IRQ_ACK, IPI3, 22, 1) 299 FIELD(IRQ_ACK, IPI2, 21, 1) 300 FIELD(IRQ_ACK, IPI1, 20, 1) 301 FIELD(IRQ_ACK, IPI0, 19, 1) 302 FIELD(IRQ_ACK, RTC_ALARM, 18, 1) 303 FIELD(IRQ_ACK, RTC_EVERY_SECOND, 17, 1) 304 FIELD(IRQ_ACK, CORRECTABLE_ECC, 16, 1) 305 FIELD(IRQ_ACK, GPI3, 14, 1) 306 FIELD(IRQ_ACK, GPI2, 13, 1) 307 FIELD(IRQ_ACK, GPI1, 12, 1) 308 FIELD(IRQ_ACK, GPI0, 11, 1) 309 FIELD(IRQ_ACK, PIT3, 6, 1) 310 FIELD(IRQ_ACK, PIT2, 5, 1) 311 FIELD(IRQ_ACK, PIT1, 4, 1) 312 FIELD(IRQ_ACK, PIT0, 3, 1) 313 REG32(PIT0_PRELOAD, 0x40) 314 REG32(PIT0_COUNTER, 0x44) 315 REG32(PIT0_CONTROL, 0x48) 316 FIELD(PIT0_CONTROL, PRELOAD, 1, 1) 317 FIELD(PIT0_CONTROL, EN, 0, 1) 318 REG32(PIT1_PRELOAD, 0x50) 319 REG32(PIT1_COUNTER, 0x54) 320 REG32(PIT1_CONTROL, 0x58) 321 FIELD(PIT1_CONTROL, PRELOAD, 1, 1) 322 FIELD(PIT1_CONTROL, EN, 0, 1) 323 REG32(PIT2_PRELOAD, 0x60) 324 REG32(PIT2_COUNTER, 0x64) 325 REG32(PIT2_CONTROL, 0x68) 326 FIELD(PIT2_CONTROL, PRELOAD, 1, 1) 327 FIELD(PIT2_CONTROL, EN, 0, 1) 328 REG32(PIT3_PRELOAD, 0x70) 329 REG32(PIT3_COUNTER, 0x74) 330 REG32(PIT3_CONTROL, 0x78) 331 FIELD(PIT3_CONTROL, PRELOAD, 1, 1) 332 FIELD(PIT3_CONTROL, EN, 0, 1) 333 334 static void xlnx_pmu_io_irq_update(XlnxPMUIOIntc *s) 335 { 336 bool irq_out; 337 338 s->regs[R_IRQ_PENDING] = s->regs[R_IRQ_STATUS] & s->regs[R_IRQ_ENABLE]; 339 irq_out = !!s->regs[R_IRQ_PENDING]; 340 341 DB_PRINT("Setting IRQ output = %d\n", irq_out); 342 343 qemu_set_irq(s->parent_irq, irq_out); 344 } 345 346 static void xlnx_pmu_io_irq_enable_postw(RegisterInfo *reg, uint64_t val64) 347 { 348 XlnxPMUIOIntc *s = XLNX_PMU_IO_INTC(reg->opaque); 349 350 xlnx_pmu_io_irq_update(s); 351 } 352 353 static void xlnx_pmu_io_irq_ack_postw(RegisterInfo *reg, uint64_t val64) 354 { 355 XlnxPMUIOIntc *s = XLNX_PMU_IO_INTC(reg->opaque); 356 uint32_t val = val64; 357 358 /* Only clear */ 359 val &= s->regs[R_IRQ_STATUS]; 360 s->regs[R_IRQ_STATUS] ^= val; 361 362 /* Active level triggered interrupts stay high. */ 363 s->regs[R_IRQ_STATUS] |= s->irq_raw & ~s->cfg.level_edge; 364 365 xlnx_pmu_io_irq_update(s); 366 } 367 368 static const RegisterAccessInfo xlnx_pmu_io_intc_regs_info[] = { 369 { .name = "IRQ_MODE", .addr = A_IRQ_MODE, 370 .rsvd = 0xffffffff, 371 },{ .name = "GPO0", .addr = A_GPO0, 372 },{ .name = "GPO1", .addr = A_GPO1, 373 .rsvd = 0xffffffc0, 374 },{ .name = "GPO2", .addr = A_GPO2, 375 .rsvd = 0xfffffc3f, 376 },{ .name = "GPO3", .addr = A_GPO3, 377 },{ .name = "GPI0", .addr = A_GPI0, 378 .rsvd = 0x300030, 379 .ro = 0xffcfffcf, 380 },{ .name = "GPI1", .addr = A_GPI1, 381 .rsvd = 0xf0e0000, 382 .ro = 0xf0f1ffff, 383 },{ .name = "GPI2", .addr = A_GPI2, 384 .rsvd = 0x1f00fcc0, 385 .ro = 0xe0ff033f, 386 },{ .name = "GPI3", .addr = A_GPI3, 387 .ro = 0xffffffff, 388 },{ .name = "IRQ_STATUS", .addr = A_IRQ_STATUS, 389 .rsvd = 0x40008787, 390 .ro = 0xbfff7878, 391 },{ .name = "IRQ_PENDING", .addr = A_IRQ_PENDING, 392 .rsvd = 0x40008787, 393 .ro = 0xdfff7ff8, 394 },{ .name = "IRQ_ENABLE", .addr = A_IRQ_ENABLE, 395 .rsvd = 0x40008787, 396 .ro = 0x7800, 397 .post_write = xlnx_pmu_io_irq_enable_postw, 398 },{ .name = "IRQ_ACK", .addr = A_IRQ_ACK, 399 .rsvd = 0x40008787, 400 .post_write = xlnx_pmu_io_irq_ack_postw, 401 },{ .name = "PIT0_PRELOAD", .addr = A_PIT0_PRELOAD, 402 .ro = 0xffffffff, 403 },{ .name = "PIT0_COUNTER", .addr = A_PIT0_COUNTER, 404 .ro = 0xffffffff, 405 },{ .name = "PIT0_CONTROL", .addr = A_PIT0_CONTROL, 406 .rsvd = 0xfffffffc, 407 },{ .name = "PIT1_PRELOAD", .addr = A_PIT1_PRELOAD, 408 .ro = 0xffffffff, 409 },{ .name = "PIT1_COUNTER", .addr = A_PIT1_COUNTER, 410 .ro = 0xffffffff, 411 },{ .name = "PIT1_CONTROL", .addr = A_PIT1_CONTROL, 412 .rsvd = 0xfffffffc, 413 },{ .name = "PIT2_PRELOAD", .addr = A_PIT2_PRELOAD, 414 .ro = 0xffffffff, 415 },{ .name = "PIT2_COUNTER", .addr = A_PIT2_COUNTER, 416 .ro = 0xffffffff, 417 },{ .name = "PIT2_CONTROL", .addr = A_PIT2_CONTROL, 418 .rsvd = 0xfffffffc, 419 },{ .name = "PIT3_PRELOAD", .addr = A_PIT3_PRELOAD, 420 .ro = 0xffffffff, 421 },{ .name = "PIT3_COUNTER", .addr = A_PIT3_COUNTER, 422 .ro = 0xffffffff, 423 },{ .name = "PIT3_CONTROL", .addr = A_PIT3_CONTROL, 424 .rsvd = 0xfffffffc, 425 } 426 }; 427 428 static void irq_handler(void *opaque, int irq, int level) 429 { 430 XlnxPMUIOIntc *s = XLNX_PMU_IO_INTC(opaque); 431 uint32_t mask = 1 << irq; 432 uint32_t prev = s->irq_raw; 433 uint32_t temp; 434 435 s->irq_raw &= ~mask; 436 s->irq_raw |= (!!level) << irq; 437 438 /* Turn active-low into active-high. */ 439 s->irq_raw ^= (~s->cfg.positive); 440 s->irq_raw &= mask; 441 442 if (s->cfg.level_edge & mask) { 443 /* Edge triggered. */ 444 temp = (prev ^ s->irq_raw) & s->irq_raw; 445 } else { 446 /* Level triggered. */ 447 temp = s->irq_raw; 448 } 449 s->regs[R_IRQ_STATUS] |= temp; 450 451 xlnx_pmu_io_irq_update(s); 452 } 453 454 static void xlnx_pmu_io_intc_reset(DeviceState *dev) 455 { 456 XlnxPMUIOIntc *s = XLNX_PMU_IO_INTC(dev); 457 unsigned int i; 458 459 for (i = 0; i < ARRAY_SIZE(s->regs_info); ++i) { 460 register_reset(&s->regs_info[i]); 461 } 462 463 xlnx_pmu_io_irq_update(s); 464 } 465 466 static const MemoryRegionOps xlnx_pmu_io_intc_ops = { 467 .read = register_read_memory, 468 .write = register_write_memory, 469 .endianness = DEVICE_LITTLE_ENDIAN, 470 .valid = { 471 .min_access_size = 4, 472 .max_access_size = 4, 473 }, 474 }; 475 476 static Property xlnx_pmu_io_intc_properties[] = { 477 DEFINE_PROP_UINT32("intc-intr-size", XlnxPMUIOIntc, cfg.intr_size, 0), 478 DEFINE_PROP_UINT32("intc-level-edge", XlnxPMUIOIntc, cfg.level_edge, 0), 479 DEFINE_PROP_UINT32("intc-positive", XlnxPMUIOIntc, cfg.positive, 0), 480 DEFINE_PROP_END_OF_LIST(), 481 }; 482 483 static void xlnx_pmu_io_intc_realize(DeviceState *dev, Error **errp) 484 { 485 XlnxPMUIOIntc *s = XLNX_PMU_IO_INTC(dev); 486 487 /* Internal interrupts are edge triggered */ 488 s->cfg.level_edge <<= 16; 489 s->cfg.level_edge |= 0xffff; 490 491 /* Internal interrupts are positive. */ 492 s->cfg.positive <<= 16; 493 s->cfg.positive |= 0xffff; 494 495 /* Max 16 external interrupts. */ 496 assert(s->cfg.intr_size <= 16); 497 498 qdev_init_gpio_in(dev, irq_handler, 16 + s->cfg.intr_size); 499 } 500 501 static void xlnx_pmu_io_intc_init(Object *obj) 502 { 503 XlnxPMUIOIntc *s = XLNX_PMU_IO_INTC(obj); 504 SysBusDevice *sbd = SYS_BUS_DEVICE(obj); 505 RegisterInfoArray *reg_array; 506 507 memory_region_init(&s->iomem, obj, TYPE_XLNX_PMU_IO_INTC, 508 XLNXPMUIOINTC_R_MAX * 4); 509 reg_array = 510 register_init_block32(DEVICE(obj), xlnx_pmu_io_intc_regs_info, 511 ARRAY_SIZE(xlnx_pmu_io_intc_regs_info), 512 s->regs_info, s->regs, 513 &xlnx_pmu_io_intc_ops, 514 XLNX_PMU_IO_INTC_ERR_DEBUG, 515 XLNXPMUIOINTC_R_MAX * 4); 516 memory_region_add_subregion(&s->iomem, 517 0x0, 518 ®_array->mem); 519 sysbus_init_mmio(sbd, &s->iomem); 520 521 sysbus_init_irq(sbd, &s->parent_irq); 522 } 523 524 static const VMStateDescription vmstate_xlnx_pmu_io_intc = { 525 .name = TYPE_XLNX_PMU_IO_INTC, 526 .version_id = 1, 527 .minimum_version_id = 1, 528 .fields = (VMStateField[]) { 529 VMSTATE_UINT32_ARRAY(regs, XlnxPMUIOIntc, XLNXPMUIOINTC_R_MAX), 530 VMSTATE_END_OF_LIST(), 531 } 532 }; 533 534 static void xlnx_pmu_io_intc_class_init(ObjectClass *klass, void *data) 535 { 536 DeviceClass *dc = DEVICE_CLASS(klass); 537 538 dc->reset = xlnx_pmu_io_intc_reset; 539 dc->realize = xlnx_pmu_io_intc_realize; 540 dc->vmsd = &vmstate_xlnx_pmu_io_intc; 541 dc->props = xlnx_pmu_io_intc_properties; 542 } 543 544 static const TypeInfo xlnx_pmu_io_intc_info = { 545 .name = TYPE_XLNX_PMU_IO_INTC, 546 .parent = TYPE_SYS_BUS_DEVICE, 547 .instance_size = sizeof(XlnxPMUIOIntc), 548 .class_init = xlnx_pmu_io_intc_class_init, 549 .instance_init = xlnx_pmu_io_intc_init, 550 }; 551 552 static void xlnx_pmu_io_intc_register_types(void) 553 { 554 type_register_static(&xlnx_pmu_io_intc_info); 555 } 556 557 type_init(xlnx_pmu_io_intc_register_types) 558