1ff8f06eeSShlomo Pongratz /* 2ff8f06eeSShlomo Pongratz * ARM GICv3 support - common bits of emulated and KVM kernel model 3ff8f06eeSShlomo Pongratz * 4ff8f06eeSShlomo Pongratz * Copyright (c) 2012 Linaro Limited 5ff8f06eeSShlomo Pongratz * Copyright (c) 2015 Huawei. 607e2034dSPavel Fedin * Copyright (c) 2015 Samsung Electronics Co., Ltd. 7ff8f06eeSShlomo Pongratz * Written by Peter Maydell 807e2034dSPavel Fedin * Reworked for GICv3 by Shlomo Pongratz and Pavel Fedin 9ff8f06eeSShlomo Pongratz * 10ff8f06eeSShlomo Pongratz * This program is free software; you can redistribute it and/or modify 11ff8f06eeSShlomo Pongratz * it under the terms of the GNU General Public License as published by 12ff8f06eeSShlomo Pongratz * the Free Software Foundation, either version 2 of the License, or 13ff8f06eeSShlomo Pongratz * (at your option) any later version. 14ff8f06eeSShlomo Pongratz * 15ff8f06eeSShlomo Pongratz * This program is distributed in the hope that it will be useful, 16ff8f06eeSShlomo Pongratz * but WITHOUT ANY WARRANTY; without even the implied warranty of 17ff8f06eeSShlomo Pongratz * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18ff8f06eeSShlomo Pongratz * GNU General Public License for more details. 19ff8f06eeSShlomo Pongratz * 20ff8f06eeSShlomo Pongratz * You should have received a copy of the GNU General Public License along 21ff8f06eeSShlomo Pongratz * with this program; if not, see <http://www.gnu.org/licenses/>. 22ff8f06eeSShlomo Pongratz */ 23ff8f06eeSShlomo Pongratz 248ef94f0bSPeter Maydell #include "qemu/osdep.h" 25da34e65cSMarkus Armbruster #include "qapi/error.h" 2607e2034dSPavel Fedin #include "qom/cpu.h" 27ff8f06eeSShlomo Pongratz #include "hw/intc/arm_gicv3_common.h" 2807e2034dSPavel Fedin #include "gicv3_internal.h" 2907e2034dSPavel Fedin #include "hw/arm/linux-boot-if.h" 30ff8f06eeSShlomo Pongratz 31ff8f06eeSShlomo Pongratz static void gicv3_pre_save(void *opaque) 32ff8f06eeSShlomo Pongratz { 33ff8f06eeSShlomo Pongratz GICv3State *s = (GICv3State *)opaque; 34ff8f06eeSShlomo Pongratz ARMGICv3CommonClass *c = ARM_GICV3_COMMON_GET_CLASS(s); 35ff8f06eeSShlomo Pongratz 36ff8f06eeSShlomo Pongratz if (c->pre_save) { 37ff8f06eeSShlomo Pongratz c->pre_save(s); 38ff8f06eeSShlomo Pongratz } 39ff8f06eeSShlomo Pongratz } 40ff8f06eeSShlomo Pongratz 41ff8f06eeSShlomo Pongratz static int gicv3_post_load(void *opaque, int version_id) 42ff8f06eeSShlomo Pongratz { 43ff8f06eeSShlomo Pongratz GICv3State *s = (GICv3State *)opaque; 44ff8f06eeSShlomo Pongratz ARMGICv3CommonClass *c = ARM_GICV3_COMMON_GET_CLASS(s); 45ff8f06eeSShlomo Pongratz 46ff8f06eeSShlomo Pongratz if (c->post_load) { 47ff8f06eeSShlomo Pongratz c->post_load(s); 48ff8f06eeSShlomo Pongratz } 49ff8f06eeSShlomo Pongratz return 0; 50ff8f06eeSShlomo Pongratz } 51ff8f06eeSShlomo Pongratz 52*4eb833b5SPeter Maydell static bool virt_state_needed(void *opaque) 53*4eb833b5SPeter Maydell { 54*4eb833b5SPeter Maydell GICv3CPUState *cs = opaque; 55*4eb833b5SPeter Maydell 56*4eb833b5SPeter Maydell return cs->num_list_regs != 0; 57*4eb833b5SPeter Maydell } 58*4eb833b5SPeter Maydell 59*4eb833b5SPeter Maydell static const VMStateDescription vmstate_gicv3_cpu_virt = { 60*4eb833b5SPeter Maydell .name = "arm_gicv3_cpu/virt", 61*4eb833b5SPeter Maydell .version_id = 1, 62*4eb833b5SPeter Maydell .minimum_version_id = 1, 63*4eb833b5SPeter Maydell .needed = virt_state_needed, 64*4eb833b5SPeter Maydell .fields = (VMStateField[]) { 65*4eb833b5SPeter Maydell VMSTATE_UINT64_2DARRAY(ich_apr, GICv3CPUState, 3, 4), 66*4eb833b5SPeter Maydell VMSTATE_UINT64(ich_hcr_el2, GICv3CPUState), 67*4eb833b5SPeter Maydell VMSTATE_UINT64_ARRAY(ich_lr_el2, GICv3CPUState, GICV3_LR_MAX), 68*4eb833b5SPeter Maydell VMSTATE_UINT64(ich_vmcr_el2, GICv3CPUState), 69*4eb833b5SPeter Maydell VMSTATE_END_OF_LIST() 70*4eb833b5SPeter Maydell } 71*4eb833b5SPeter Maydell }; 72*4eb833b5SPeter Maydell 73757caeedSPavel Fedin static const VMStateDescription vmstate_gicv3_cpu = { 74757caeedSPavel Fedin .name = "arm_gicv3_cpu", 75757caeedSPavel Fedin .version_id = 1, 76757caeedSPavel Fedin .minimum_version_id = 1, 77757caeedSPavel Fedin .fields = (VMStateField[]) { 78757caeedSPavel Fedin VMSTATE_UINT32(level, GICv3CPUState), 79757caeedSPavel Fedin VMSTATE_UINT32(gicr_ctlr, GICv3CPUState), 80757caeedSPavel Fedin VMSTATE_UINT32_ARRAY(gicr_statusr, GICv3CPUState, 2), 81757caeedSPavel Fedin VMSTATE_UINT32(gicr_waker, GICv3CPUState), 82757caeedSPavel Fedin VMSTATE_UINT64(gicr_propbaser, GICv3CPUState), 83757caeedSPavel Fedin VMSTATE_UINT64(gicr_pendbaser, GICv3CPUState), 84757caeedSPavel Fedin VMSTATE_UINT32(gicr_igroupr0, GICv3CPUState), 85757caeedSPavel Fedin VMSTATE_UINT32(gicr_ienabler0, GICv3CPUState), 86757caeedSPavel Fedin VMSTATE_UINT32(gicr_ipendr0, GICv3CPUState), 87757caeedSPavel Fedin VMSTATE_UINT32(gicr_iactiver0, GICv3CPUState), 88757caeedSPavel Fedin VMSTATE_UINT32(edge_trigger, GICv3CPUState), 89757caeedSPavel Fedin VMSTATE_UINT32(gicr_igrpmodr0, GICv3CPUState), 90757caeedSPavel Fedin VMSTATE_UINT32(gicr_nsacr, GICv3CPUState), 91757caeedSPavel Fedin VMSTATE_UINT8_ARRAY(gicr_ipriorityr, GICv3CPUState, GIC_INTERNAL), 92757caeedSPavel Fedin VMSTATE_UINT64_ARRAY(icc_ctlr_el1, GICv3CPUState, 2), 93757caeedSPavel Fedin VMSTATE_UINT64(icc_pmr_el1, GICv3CPUState), 94757caeedSPavel Fedin VMSTATE_UINT64_ARRAY(icc_bpr, GICv3CPUState, 3), 95757caeedSPavel Fedin VMSTATE_UINT64_2DARRAY(icc_apr, GICv3CPUState, 3, 4), 96757caeedSPavel Fedin VMSTATE_UINT64_ARRAY(icc_igrpen, GICv3CPUState, 3), 97757caeedSPavel Fedin VMSTATE_UINT64(icc_ctlr_el3, GICv3CPUState), 98757caeedSPavel Fedin VMSTATE_END_OF_LIST() 99*4eb833b5SPeter Maydell }, 100*4eb833b5SPeter Maydell .subsections = (const VMStateDescription * []) { 101*4eb833b5SPeter Maydell &vmstate_gicv3_cpu_virt, 102*4eb833b5SPeter Maydell NULL 103757caeedSPavel Fedin } 104757caeedSPavel Fedin }; 105757caeedSPavel Fedin 106ff8f06eeSShlomo Pongratz static const VMStateDescription vmstate_gicv3 = { 107ff8f06eeSShlomo Pongratz .name = "arm_gicv3", 108757caeedSPavel Fedin .version_id = 1, 109757caeedSPavel Fedin .minimum_version_id = 1, 110ff8f06eeSShlomo Pongratz .pre_save = gicv3_pre_save, 111ff8f06eeSShlomo Pongratz .post_load = gicv3_post_load, 112757caeedSPavel Fedin .fields = (VMStateField[]) { 113757caeedSPavel Fedin VMSTATE_UINT32(gicd_ctlr, GICv3State), 114757caeedSPavel Fedin VMSTATE_UINT32_ARRAY(gicd_statusr, GICv3State, 2), 115757caeedSPavel Fedin VMSTATE_UINT32_ARRAY(group, GICv3State, GICV3_BMP_SIZE), 116757caeedSPavel Fedin VMSTATE_UINT32_ARRAY(grpmod, GICv3State, GICV3_BMP_SIZE), 117757caeedSPavel Fedin VMSTATE_UINT32_ARRAY(enabled, GICv3State, GICV3_BMP_SIZE), 118757caeedSPavel Fedin VMSTATE_UINT32_ARRAY(pending, GICv3State, GICV3_BMP_SIZE), 119757caeedSPavel Fedin VMSTATE_UINT32_ARRAY(active, GICv3State, GICV3_BMP_SIZE), 120757caeedSPavel Fedin VMSTATE_UINT32_ARRAY(level, GICv3State, GICV3_BMP_SIZE), 121757caeedSPavel Fedin VMSTATE_UINT32_ARRAY(edge_trigger, GICv3State, GICV3_BMP_SIZE), 122757caeedSPavel Fedin VMSTATE_UINT8_ARRAY(gicd_ipriority, GICv3State, GICV3_MAXIRQ), 123757caeedSPavel Fedin VMSTATE_UINT64_ARRAY(gicd_irouter, GICv3State, GICV3_MAXIRQ), 124757caeedSPavel Fedin VMSTATE_UINT32_ARRAY(gicd_nsacr, GICv3State, 125757caeedSPavel Fedin DIV_ROUND_UP(GICV3_MAXIRQ, 16)), 126757caeedSPavel Fedin VMSTATE_STRUCT_VARRAY_POINTER_UINT32(cpu, GICv3State, num_cpu, 127757caeedSPavel Fedin vmstate_gicv3_cpu, GICv3CPUState), 128757caeedSPavel Fedin VMSTATE_END_OF_LIST() 129757caeedSPavel Fedin } 130ff8f06eeSShlomo Pongratz }; 131ff8f06eeSShlomo Pongratz 132ff8f06eeSShlomo Pongratz void gicv3_init_irqs_and_mmio(GICv3State *s, qemu_irq_handler handler, 133ff8f06eeSShlomo Pongratz const MemoryRegionOps *ops) 134ff8f06eeSShlomo Pongratz { 135ff8f06eeSShlomo Pongratz SysBusDevice *sbd = SYS_BUS_DEVICE(s); 136ff8f06eeSShlomo Pongratz int i; 137ff8f06eeSShlomo Pongratz 138ff8f06eeSShlomo Pongratz /* For the GIC, also expose incoming GPIO lines for PPIs for each CPU. 139ff8f06eeSShlomo Pongratz * GPIO array layout is thus: 140ff8f06eeSShlomo Pongratz * [0..N-1] spi 141ff8f06eeSShlomo Pongratz * [N..N+31] PPIs for CPU 0 142ff8f06eeSShlomo Pongratz * [N+32..N+63] PPIs for CPU 1 143ff8f06eeSShlomo Pongratz * ... 144ff8f06eeSShlomo Pongratz */ 145ff8f06eeSShlomo Pongratz i = s->num_irq - GIC_INTERNAL + GIC_INTERNAL * s->num_cpu; 146ff8f06eeSShlomo Pongratz qdev_init_gpio_in(DEVICE(s), handler, i); 147ff8f06eeSShlomo Pongratz 148ff8f06eeSShlomo Pongratz for (i = 0; i < s->num_cpu; i++) { 1493faf2b0cSPeter Maydell sysbus_init_irq(sbd, &s->cpu[i].parent_irq); 150ff8f06eeSShlomo Pongratz } 151ff8f06eeSShlomo Pongratz for (i = 0; i < s->num_cpu; i++) { 1523faf2b0cSPeter Maydell sysbus_init_irq(sbd, &s->cpu[i].parent_fiq); 153ff8f06eeSShlomo Pongratz } 154b53db42bSPeter Maydell for (i = 0; i < s->num_cpu; i++) { 155b53db42bSPeter Maydell sysbus_init_irq(sbd, &s->cpu[i].parent_virq); 156b53db42bSPeter Maydell } 157b53db42bSPeter Maydell for (i = 0; i < s->num_cpu; i++) { 158b53db42bSPeter Maydell sysbus_init_irq(sbd, &s->cpu[i].parent_vfiq); 159b53db42bSPeter Maydell } 160ff8f06eeSShlomo Pongratz 161ff8f06eeSShlomo Pongratz memory_region_init_io(&s->iomem_dist, OBJECT(s), ops, s, 162ff8f06eeSShlomo Pongratz "gicv3_dist", 0x10000); 163ff8f06eeSShlomo Pongratz memory_region_init_io(&s->iomem_redist, OBJECT(s), ops ? &ops[1] : NULL, s, 164ff8f06eeSShlomo Pongratz "gicv3_redist", 0x20000 * s->num_cpu); 165ff8f06eeSShlomo Pongratz 166ff8f06eeSShlomo Pongratz sysbus_init_mmio(sbd, &s->iomem_dist); 167ff8f06eeSShlomo Pongratz sysbus_init_mmio(sbd, &s->iomem_redist); 168ff8f06eeSShlomo Pongratz } 169ff8f06eeSShlomo Pongratz 170ff8f06eeSShlomo Pongratz static void arm_gicv3_common_realize(DeviceState *dev, Error **errp) 171ff8f06eeSShlomo Pongratz { 172ff8f06eeSShlomo Pongratz GICv3State *s = ARM_GICV3_COMMON(dev); 17307e2034dSPavel Fedin int i; 174ff8f06eeSShlomo Pongratz 175ff8f06eeSShlomo Pongratz /* revision property is actually reserved and currently used only in order 176ff8f06eeSShlomo Pongratz * to keep the interface compatible with GICv2 code, avoiding extra 177ff8f06eeSShlomo Pongratz * conditions. However, in future it could be used, for example, if we 178ff8f06eeSShlomo Pongratz * implement GICv4. 179ff8f06eeSShlomo Pongratz */ 180ff8f06eeSShlomo Pongratz if (s->revision != 3) { 181ff8f06eeSShlomo Pongratz error_setg(errp, "unsupported GIC revision %d", s->revision); 182ff8f06eeSShlomo Pongratz return; 183ff8f06eeSShlomo Pongratz } 18407e2034dSPavel Fedin 18507e2034dSPavel Fedin if (s->num_irq > GICV3_MAXIRQ) { 18607e2034dSPavel Fedin error_setg(errp, 18707e2034dSPavel Fedin "requested %u interrupt lines exceeds GIC maximum %d", 18807e2034dSPavel Fedin s->num_irq, GICV3_MAXIRQ); 18907e2034dSPavel Fedin return; 19007e2034dSPavel Fedin } 19107e2034dSPavel Fedin if (s->num_irq < GIC_INTERNAL) { 19207e2034dSPavel Fedin error_setg(errp, 19307e2034dSPavel Fedin "requested %u interrupt lines is below GIC minimum %d", 19407e2034dSPavel Fedin s->num_irq, GIC_INTERNAL); 19507e2034dSPavel Fedin return; 19607e2034dSPavel Fedin } 19707e2034dSPavel Fedin 19807e2034dSPavel Fedin /* ITLinesNumber is represented as (N / 32) - 1, so this is an 19907e2034dSPavel Fedin * implementation imposed restriction, not an architectural one, 20007e2034dSPavel Fedin * so we don't have to deal with bitfields where only some of the 20107e2034dSPavel Fedin * bits in a 32-bit word should be valid. 20207e2034dSPavel Fedin */ 20307e2034dSPavel Fedin if (s->num_irq % 32) { 20407e2034dSPavel Fedin error_setg(errp, 20507e2034dSPavel Fedin "%d interrupt lines unsupported: not divisible by 32", 20607e2034dSPavel Fedin s->num_irq); 20707e2034dSPavel Fedin return; 20807e2034dSPavel Fedin } 20907e2034dSPavel Fedin 21007e2034dSPavel Fedin s->cpu = g_new0(GICv3CPUState, s->num_cpu); 21107e2034dSPavel Fedin 21207e2034dSPavel Fedin for (i = 0; i < s->num_cpu; i++) { 21307e2034dSPavel Fedin CPUState *cpu = qemu_get_cpu(i); 21407e2034dSPavel Fedin uint64_t cpu_affid; 21507e2034dSPavel Fedin int last; 21607e2034dSPavel Fedin 21707e2034dSPavel Fedin s->cpu[i].cpu = cpu; 21807e2034dSPavel Fedin s->cpu[i].gic = s; 21907e2034dSPavel Fedin 22007e2034dSPavel Fedin /* Pre-construct the GICR_TYPER: 22107e2034dSPavel Fedin * For our implementation: 22207e2034dSPavel Fedin * Top 32 bits are the affinity value of the associated CPU 22307e2034dSPavel Fedin * CommonLPIAff == 01 (redistributors with same Aff3 share LPI table) 22407e2034dSPavel Fedin * Processor_Number == CPU index starting from 0 22507e2034dSPavel Fedin * DPGS == 0 (GICR_CTLR.DPG* not supported) 22607e2034dSPavel Fedin * Last == 1 if this is the last redistributor in a series of 22707e2034dSPavel Fedin * contiguous redistributor pages 22807e2034dSPavel Fedin * DirectLPI == 0 (direct injection of LPIs not supported) 22907e2034dSPavel Fedin * VLPIS == 0 (virtual LPIs not supported) 23007e2034dSPavel Fedin * PLPIS == 0 (physical LPIs not supported) 23107e2034dSPavel Fedin */ 23207e2034dSPavel Fedin cpu_affid = object_property_get_int(OBJECT(cpu), "mp-affinity", NULL); 23307e2034dSPavel Fedin last = (i == s->num_cpu - 1); 23407e2034dSPavel Fedin 23507e2034dSPavel Fedin /* The CPU mp-affinity property is in MPIDR register format; squash 23607e2034dSPavel Fedin * the affinity bytes into 32 bits as the GICR_TYPER has them. 23707e2034dSPavel Fedin */ 23892204403SAndrew Jones cpu_affid = ((cpu_affid & 0xFF00000000ULL) >> 8) | 23992204403SAndrew Jones (cpu_affid & 0xFFFFFF); 24007e2034dSPavel Fedin s->cpu[i].gicr_typer = (cpu_affid << 32) | 24107e2034dSPavel Fedin (1 << 24) | 24207e2034dSPavel Fedin (i << 8) | 24307e2034dSPavel Fedin (last << 4); 24407e2034dSPavel Fedin } 245ff8f06eeSShlomo Pongratz } 246ff8f06eeSShlomo Pongratz 247ff8f06eeSShlomo Pongratz static void arm_gicv3_common_reset(DeviceState *dev) 248ff8f06eeSShlomo Pongratz { 24907e2034dSPavel Fedin GICv3State *s = ARM_GICV3_COMMON(dev); 25007e2034dSPavel Fedin int i; 25107e2034dSPavel Fedin 25207e2034dSPavel Fedin for (i = 0; i < s->num_cpu; i++) { 25307e2034dSPavel Fedin GICv3CPUState *cs = &s->cpu[i]; 25407e2034dSPavel Fedin 25507e2034dSPavel Fedin cs->level = 0; 25607e2034dSPavel Fedin cs->gicr_ctlr = 0; 25707e2034dSPavel Fedin cs->gicr_statusr[GICV3_S] = 0; 25807e2034dSPavel Fedin cs->gicr_statusr[GICV3_NS] = 0; 25907e2034dSPavel Fedin cs->gicr_waker = GICR_WAKER_ProcessorSleep | GICR_WAKER_ChildrenAsleep; 26007e2034dSPavel Fedin cs->gicr_propbaser = 0; 26107e2034dSPavel Fedin cs->gicr_pendbaser = 0; 26207e2034dSPavel Fedin /* If we're resetting a TZ-aware GIC as if secure firmware 26307e2034dSPavel Fedin * had set it up ready to start a kernel in non-secure, we 26407e2034dSPavel Fedin * need to set interrupts to group 1 so the kernel can use them. 26507e2034dSPavel Fedin * Otherwise they reset to group 0 like the hardware. 26607e2034dSPavel Fedin */ 26707e2034dSPavel Fedin if (s->irq_reset_nonsecure) { 26807e2034dSPavel Fedin cs->gicr_igroupr0 = 0xffffffff; 26907e2034dSPavel Fedin } else { 27007e2034dSPavel Fedin cs->gicr_igroupr0 = 0; 27107e2034dSPavel Fedin } 27207e2034dSPavel Fedin 27307e2034dSPavel Fedin cs->gicr_ienabler0 = 0; 27407e2034dSPavel Fedin cs->gicr_ipendr0 = 0; 27507e2034dSPavel Fedin cs->gicr_iactiver0 = 0; 27607e2034dSPavel Fedin cs->edge_trigger = 0xffff; 27707e2034dSPavel Fedin cs->gicr_igrpmodr0 = 0; 27807e2034dSPavel Fedin cs->gicr_nsacr = 0; 27907e2034dSPavel Fedin memset(cs->gicr_ipriorityr, 0, sizeof(cs->gicr_ipriorityr)); 28007e2034dSPavel Fedin 281ce187c3cSPeter Maydell cs->hppi.prio = 0xff; 282ce187c3cSPeter Maydell 28307e2034dSPavel Fedin /* State in the CPU interface must *not* be reset here, because it 28407e2034dSPavel Fedin * is part of the CPU's reset domain, not the GIC device's. 28507e2034dSPavel Fedin */ 28607e2034dSPavel Fedin } 28707e2034dSPavel Fedin 28807e2034dSPavel Fedin /* For our implementation affinity routing is always enabled */ 28907e2034dSPavel Fedin if (s->security_extn) { 29007e2034dSPavel Fedin s->gicd_ctlr = GICD_CTLR_ARE_S | GICD_CTLR_ARE_NS; 29107e2034dSPavel Fedin } else { 29207e2034dSPavel Fedin s->gicd_ctlr = GICD_CTLR_DS | GICD_CTLR_ARE; 29307e2034dSPavel Fedin } 29407e2034dSPavel Fedin 29507e2034dSPavel Fedin s->gicd_statusr[GICV3_S] = 0; 29607e2034dSPavel Fedin s->gicd_statusr[GICV3_NS] = 0; 29707e2034dSPavel Fedin 29807e2034dSPavel Fedin memset(s->group, 0, sizeof(s->group)); 29907e2034dSPavel Fedin memset(s->grpmod, 0, sizeof(s->grpmod)); 30007e2034dSPavel Fedin memset(s->enabled, 0, sizeof(s->enabled)); 30107e2034dSPavel Fedin memset(s->pending, 0, sizeof(s->pending)); 30207e2034dSPavel Fedin memset(s->active, 0, sizeof(s->active)); 30307e2034dSPavel Fedin memset(s->level, 0, sizeof(s->level)); 30407e2034dSPavel Fedin memset(s->edge_trigger, 0, sizeof(s->edge_trigger)); 30507e2034dSPavel Fedin memset(s->gicd_ipriority, 0, sizeof(s->gicd_ipriority)); 30607e2034dSPavel Fedin memset(s->gicd_irouter, 0, sizeof(s->gicd_irouter)); 30707e2034dSPavel Fedin memset(s->gicd_nsacr, 0, sizeof(s->gicd_nsacr)); 308ce187c3cSPeter Maydell /* GICD_IROUTER are UNKNOWN at reset so in theory the guest must 309ce187c3cSPeter Maydell * write these to get sane behaviour and we need not populate the 310ce187c3cSPeter Maydell * pointer cache here; however having the cache be different for 311ce187c3cSPeter Maydell * "happened to be 0 from reset" and "guest wrote 0" would be 312ce187c3cSPeter Maydell * too confusing. 313ce187c3cSPeter Maydell */ 314ce187c3cSPeter Maydell gicv3_cache_all_target_cpustates(s); 31507e2034dSPavel Fedin 31607e2034dSPavel Fedin if (s->irq_reset_nonsecure) { 31707e2034dSPavel Fedin /* If we're resetting a TZ-aware GIC as if secure firmware 31807e2034dSPavel Fedin * had set it up ready to start a kernel in non-secure, we 31907e2034dSPavel Fedin * need to set interrupts to group 1 so the kernel can use them. 32007e2034dSPavel Fedin * Otherwise they reset to group 0 like the hardware. 32107e2034dSPavel Fedin */ 32207e2034dSPavel Fedin for (i = GIC_INTERNAL; i < s->num_irq; i++) { 32307e2034dSPavel Fedin gicv3_gicd_group_set(s, i); 32407e2034dSPavel Fedin } 32507e2034dSPavel Fedin } 32607e2034dSPavel Fedin } 32707e2034dSPavel Fedin 32807e2034dSPavel Fedin static void arm_gic_common_linux_init(ARMLinuxBootIf *obj, 32907e2034dSPavel Fedin bool secure_boot) 33007e2034dSPavel Fedin { 33107e2034dSPavel Fedin GICv3State *s = ARM_GICV3_COMMON(obj); 33207e2034dSPavel Fedin 33307e2034dSPavel Fedin if (s->security_extn && !secure_boot) { 33407e2034dSPavel Fedin /* We're directly booting a kernel into NonSecure. If this GIC 33507e2034dSPavel Fedin * implements the security extensions then we must configure it 33607e2034dSPavel Fedin * to have all the interrupts be NonSecure (this is a job that 33707e2034dSPavel Fedin * is done by the Secure boot firmware in real hardware, and in 33807e2034dSPavel Fedin * this mode QEMU is acting as a minimalist firmware-and-bootloader 33907e2034dSPavel Fedin * equivalent). 34007e2034dSPavel Fedin */ 34107e2034dSPavel Fedin s->irq_reset_nonsecure = true; 34207e2034dSPavel Fedin } 343ff8f06eeSShlomo Pongratz } 344ff8f06eeSShlomo Pongratz 345ff8f06eeSShlomo Pongratz static Property arm_gicv3_common_properties[] = { 346ff8f06eeSShlomo Pongratz DEFINE_PROP_UINT32("num-cpu", GICv3State, num_cpu, 1), 347ff8f06eeSShlomo Pongratz DEFINE_PROP_UINT32("num-irq", GICv3State, num_irq, 32), 348ff8f06eeSShlomo Pongratz DEFINE_PROP_UINT32("revision", GICv3State, revision, 3), 349ff8f06eeSShlomo Pongratz DEFINE_PROP_BOOL("has-security-extensions", GICv3State, security_extn, 0), 350ff8f06eeSShlomo Pongratz DEFINE_PROP_END_OF_LIST(), 351ff8f06eeSShlomo Pongratz }; 352ff8f06eeSShlomo Pongratz 353ff8f06eeSShlomo Pongratz static void arm_gicv3_common_class_init(ObjectClass *klass, void *data) 354ff8f06eeSShlomo Pongratz { 355ff8f06eeSShlomo Pongratz DeviceClass *dc = DEVICE_CLASS(klass); 35607e2034dSPavel Fedin ARMLinuxBootIfClass *albifc = ARM_LINUX_BOOT_IF_CLASS(klass); 357ff8f06eeSShlomo Pongratz 358ff8f06eeSShlomo Pongratz dc->reset = arm_gicv3_common_reset; 359ff8f06eeSShlomo Pongratz dc->realize = arm_gicv3_common_realize; 360ff8f06eeSShlomo Pongratz dc->props = arm_gicv3_common_properties; 361ff8f06eeSShlomo Pongratz dc->vmsd = &vmstate_gicv3; 36207e2034dSPavel Fedin albifc->arm_linux_init = arm_gic_common_linux_init; 363ff8f06eeSShlomo Pongratz } 364ff8f06eeSShlomo Pongratz 365ff8f06eeSShlomo Pongratz static const TypeInfo arm_gicv3_common_type = { 366ff8f06eeSShlomo Pongratz .name = TYPE_ARM_GICV3_COMMON, 367ff8f06eeSShlomo Pongratz .parent = TYPE_SYS_BUS_DEVICE, 368ff8f06eeSShlomo Pongratz .instance_size = sizeof(GICv3State), 369ff8f06eeSShlomo Pongratz .class_size = sizeof(ARMGICv3CommonClass), 370ff8f06eeSShlomo Pongratz .class_init = arm_gicv3_common_class_init, 371ff8f06eeSShlomo Pongratz .abstract = true, 37207e2034dSPavel Fedin .interfaces = (InterfaceInfo []) { 37307e2034dSPavel Fedin { TYPE_ARM_LINUX_BOOT_IF }, 37407e2034dSPavel Fedin { }, 37507e2034dSPavel Fedin }, 376ff8f06eeSShlomo Pongratz }; 377ff8f06eeSShlomo Pongratz 378ff8f06eeSShlomo Pongratz static void register_types(void) 379ff8f06eeSShlomo Pongratz { 380ff8f06eeSShlomo Pongratz type_register_static(&arm_gicv3_common_type); 381ff8f06eeSShlomo Pongratz } 382ff8f06eeSShlomo Pongratz 383ff8f06eeSShlomo Pongratz type_init(register_types) 384