| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * ARM GIC support - common bits of emulated and KVM kernel model | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2012 Linaro Limited | 
					
						
							|  |  |  |  * Written by Peter Maydell | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation, either version 2 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License along | 
					
						
							|  |  |  |  * with this program; if not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-26 18:17:05 +00:00
										 |  |  | #include "qemu/osdep.h"
 | 
					
						
							| 
									
										
											  
											
												include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef.  Since then, we've moved to include qemu/osdep.h
everywhere.  Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h.  That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h.  Include qapi/error.h in .c files that need it and don't
get it now.  Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly.  Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h.  Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third.  Unfortunately, the number depending on
qapi-types.h shrinks only a little.  More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
											
										 
											2016-03-14 09:01:28 +01:00
										 |  |  | #include "qapi/error.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-23 16:35:07 +02:00
										 |  |  | #include "qemu/module.h"
 | 
					
						
							| 
									
										
										
										
											2013-03-18 17:36:02 +01:00
										 |  |  | #include "gic_internal.h"
 | 
					
						
							| 
									
										
										
										
											2015-09-08 17:38:43 +01:00
										 |  |  | #include "hw/arm/linux-boot-if.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-12 07:23:51 +02:00
										 |  |  | #include "hw/qdev-properties.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-12 07:23:45 +02:00
										 |  |  | #include "migration/vmstate.h"
 | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-25 12:29:12 +01:00
										 |  |  | static int gic_pre_save(void *opaque) | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-12 11:54:39 +01:00
										 |  |  |     GICState *s = (GICState *)opaque; | 
					
						
							| 
									
										
										
										
											2013-03-05 00:34:41 +00:00
										 |  |  |     ARMGICCommonClass *c = ARM_GIC_COMMON_GET_CLASS(s); | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 00:34:41 +00:00
										 |  |  |     if (c->pre_save) { | 
					
						
							|  |  |  |         c->pre_save(s); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-09-25 12:29:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-05 16:18:00 +01:00
										 |  |  | static int gic_post_load(void *opaque, int version_id) | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-12 11:54:39 +01:00
										 |  |  |     GICState *s = (GICState *)opaque; | 
					
						
							| 
									
										
										
										
											2013-03-05 00:34:41 +00:00
										 |  |  |     ARMGICCommonClass *c = ARM_GIC_COMMON_GET_CLASS(s); | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 00:34:41 +00:00
										 |  |  |     if (c->post_load) { | 
					
						
							|  |  |  |         c->post_load(s); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 17:17:20 +01:00
										 |  |  | static bool gic_virt_state_needed(void *opaque) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     GICState *s = (GICState *)opaque; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return s->virt_extn; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-05 16:18:00 +01:00
										 |  |  | static const VMStateDescription vmstate_gic_irq_state = { | 
					
						
							|  |  |  |     .name = "arm_gic_irq_state", | 
					
						
							|  |  |  |     .version_id = 1, | 
					
						
							|  |  |  |     .minimum_version_id = 1, | 
					
						
							|  |  |  |     .fields = (VMStateField[]) { | 
					
						
							|  |  |  |         VMSTATE_UINT8(enabled, gic_irq_state), | 
					
						
							|  |  |  |         VMSTATE_UINT8(pending, gic_irq_state), | 
					
						
							|  |  |  |         VMSTATE_UINT8(active, gic_irq_state), | 
					
						
							|  |  |  |         VMSTATE_UINT8(level, gic_irq_state), | 
					
						
							|  |  |  |         VMSTATE_BOOL(model, gic_irq_state), | 
					
						
							| 
									
										
										
										
											2013-12-20 22:09:32 -08:00
										 |  |  |         VMSTATE_BOOL(edge_trigger, gic_irq_state), | 
					
						
							| 
									
										
										
										
											2015-05-12 11:57:17 +01:00
										 |  |  |         VMSTATE_UINT8(group, gic_irq_state), | 
					
						
							| 
									
										
										
										
											2013-04-05 16:18:00 +01:00
										 |  |  |         VMSTATE_END_OF_LIST() | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 17:17:20 +01:00
										 |  |  | static const VMStateDescription vmstate_gic_virt_state = { | 
					
						
							|  |  |  |     .name = "arm_gic_virt_state", | 
					
						
							|  |  |  |     .version_id = 1, | 
					
						
							|  |  |  |     .minimum_version_id = 1, | 
					
						
							|  |  |  |     .needed = gic_virt_state_needed, | 
					
						
							|  |  |  |     .fields = (VMStateField[]) { | 
					
						
							|  |  |  |         /* Virtual interface */ | 
					
						
							|  |  |  |         VMSTATE_UINT32_ARRAY(h_hcr, GICState, GIC_NCPU), | 
					
						
							|  |  |  |         VMSTATE_UINT32_ARRAY(h_misr, GICState, GIC_NCPU), | 
					
						
							|  |  |  |         VMSTATE_UINT32_2DARRAY(h_lr, GICState, GIC_MAX_LR, GIC_NCPU), | 
					
						
							|  |  |  |         VMSTATE_UINT32_ARRAY(h_apr, GICState, GIC_NCPU), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /* Virtual CPU interfaces */ | 
					
						
							|  |  |  |         VMSTATE_UINT32_SUB_ARRAY(cpu_ctlr, GICState, GIC_NCPU, GIC_NCPU), | 
					
						
							|  |  |  |         VMSTATE_UINT16_SUB_ARRAY(priority_mask, GICState, GIC_NCPU, GIC_NCPU), | 
					
						
							|  |  |  |         VMSTATE_UINT16_SUB_ARRAY(running_priority, GICState, GIC_NCPU, GIC_NCPU), | 
					
						
							|  |  |  |         VMSTATE_UINT16_SUB_ARRAY(current_pending, GICState, GIC_NCPU, GIC_NCPU), | 
					
						
							|  |  |  |         VMSTATE_UINT8_SUB_ARRAY(bpr, GICState, GIC_NCPU, GIC_NCPU), | 
					
						
							|  |  |  |         VMSTATE_UINT8_SUB_ARRAY(abpr, GICState, GIC_NCPU, GIC_NCPU), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         VMSTATE_END_OF_LIST() | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-05 16:18:00 +01:00
										 |  |  | static const VMStateDescription vmstate_gic = { | 
					
						
							|  |  |  |     .name = "arm_gic", | 
					
						
							| 
									
										
										
										
											2015-09-08 17:38:42 +01:00
										 |  |  |     .version_id = 12, | 
					
						
							|  |  |  |     .minimum_version_id = 12, | 
					
						
							| 
									
										
										
										
											2013-04-05 16:18:00 +01:00
										 |  |  |     .pre_save = gic_pre_save, | 
					
						
							|  |  |  |     .post_load = gic_post_load, | 
					
						
							|  |  |  |     .fields = (VMStateField[]) { | 
					
						
							| 
									
										
										
										
											2015-05-12 11:57:17 +01:00
										 |  |  |         VMSTATE_UINT32(ctlr, GICState), | 
					
						
							| 
									
										
										
										
											2018-08-14 17:17:20 +01:00
										 |  |  |         VMSTATE_UINT32_SUB_ARRAY(cpu_ctlr, GICState, 0, GIC_NCPU), | 
					
						
							| 
									
										
										
										
											2013-04-05 16:18:00 +01:00
										 |  |  |         VMSTATE_STRUCT_ARRAY(irq_state, GICState, GIC_MAXIRQ, 1, | 
					
						
							|  |  |  |                              vmstate_gic_irq_state, gic_irq_state), | 
					
						
							|  |  |  |         VMSTATE_UINT8_ARRAY(irq_target, GICState, GIC_MAXIRQ), | 
					
						
							| 
									
										
										
										
											2013-07-23 03:37:49 +02:00
										 |  |  |         VMSTATE_UINT8_2DARRAY(priority1, GICState, GIC_INTERNAL, GIC_NCPU), | 
					
						
							| 
									
										
										
										
											2013-04-05 16:18:00 +01:00
										 |  |  |         VMSTATE_UINT8_ARRAY(priority2, GICState, GIC_MAXIRQ - GIC_INTERNAL), | 
					
						
							| 
									
										
										
										
											2013-11-18 20:32:00 -08:00
										 |  |  |         VMSTATE_UINT8_2DARRAY(sgi_pending, GICState, GIC_NR_SGIS, GIC_NCPU), | 
					
						
							| 
									
										
										
										
											2018-08-14 17:17:20 +01:00
										 |  |  |         VMSTATE_UINT16_SUB_ARRAY(priority_mask, GICState, 0, GIC_NCPU), | 
					
						
							|  |  |  |         VMSTATE_UINT16_SUB_ARRAY(running_priority, GICState, 0, GIC_NCPU), | 
					
						
							|  |  |  |         VMSTATE_UINT16_SUB_ARRAY(current_pending, GICState, 0, GIC_NCPU), | 
					
						
							|  |  |  |         VMSTATE_UINT8_SUB_ARRAY(bpr, GICState, 0, GIC_NCPU), | 
					
						
							|  |  |  |         VMSTATE_UINT8_SUB_ARRAY(abpr, GICState, 0, GIC_NCPU), | 
					
						
							| 
									
										
										
										
											2013-11-18 19:26:33 -08:00
										 |  |  |         VMSTATE_UINT32_2DARRAY(apr, GICState, GIC_NR_APRS, GIC_NCPU), | 
					
						
							| 
									
										
										
										
											2015-09-08 17:38:42 +01:00
										 |  |  |         VMSTATE_UINT32_2DARRAY(nsapr, GICState, GIC_NR_APRS, GIC_NCPU), | 
					
						
							| 
									
										
										
										
											2013-04-05 16:18:00 +01:00
										 |  |  |         VMSTATE_END_OF_LIST() | 
					
						
							| 
									
										
										
										
											2018-08-14 17:17:20 +01:00
										 |  |  |     }, | 
					
						
							|  |  |  |     .subsections = (const VMStateDescription * []) { | 
					
						
							|  |  |  |         &vmstate_gic_virt_state, | 
					
						
							|  |  |  |         NULL | 
					
						
							| 
									
										
										
										
											2013-04-05 16:18:00 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-13 11:26:21 +01:00
										 |  |  | void gic_init_irqs_and_mmio(GICState *s, qemu_irq_handler handler, | 
					
						
							| 
									
										
										
										
											2018-08-14 17:17:20 +01:00
										 |  |  |                             const MemoryRegionOps *ops, | 
					
						
							|  |  |  |                             const MemoryRegionOps *virt_ops) | 
					
						
							| 
									
										
										
										
											2015-08-13 11:26:21 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     SysBusDevice *sbd = SYS_BUS_DEVICE(s); | 
					
						
							|  |  |  |     int i = s->num_irq - GIC_INTERNAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* For the GIC, also expose incoming GPIO lines for PPIs for each CPU.
 | 
					
						
							|  |  |  |      * GPIO array layout is thus: | 
					
						
							|  |  |  |      *  [0..N-1] SPIs | 
					
						
							|  |  |  |      *  [N..N+31] PPIs for CPU 0 | 
					
						
							|  |  |  |      *  [N+32..N+63] PPIs for CPU 1 | 
					
						
							|  |  |  |      *   ... | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-02-28 12:08:17 +00:00
										 |  |  |     i += (GIC_INTERNAL * s->num_cpu); | 
					
						
							| 
									
										
										
										
											2015-08-13 11:26:21 +01:00
										 |  |  |     qdev_init_gpio_in(DEVICE(s), handler, i); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (i = 0; i < s->num_cpu; i++) { | 
					
						
							|  |  |  |         sysbus_init_irq(sbd, &s->parent_irq[i]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     for (i = 0; i < s->num_cpu; i++) { | 
					
						
							|  |  |  |         sysbus_init_irq(sbd, &s->parent_fiq[i]); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-01-20 11:15:09 +00:00
										 |  |  |     for (i = 0; i < s->num_cpu; i++) { | 
					
						
							|  |  |  |         sysbus_init_irq(sbd, &s->parent_virq[i]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     for (i = 0; i < s->num_cpu; i++) { | 
					
						
							|  |  |  |         sysbus_init_irq(sbd, &s->parent_vfiq[i]); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-14 17:17:20 +01:00
										 |  |  |     if (s->virt_extn) { | 
					
						
							|  |  |  |         for (i = 0; i < s->num_cpu; i++) { | 
					
						
							|  |  |  |             sysbus_init_irq(sbd, &s->maintenance_irq[i]); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-08-13 11:26:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* Distributor */ | 
					
						
							|  |  |  |     memory_region_init_io(&s->iomem, OBJECT(s), ops, s, "gic_dist", 0x1000); | 
					
						
							|  |  |  |     sysbus_init_mmio(sbd, &s->iomem); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 12:08:17 +00:00
										 |  |  |     /* This is the main CPU interface "for this core". It is always
 | 
					
						
							|  |  |  |      * present because it is required by both software emulation and KVM. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     memory_region_init_io(&s->cpuiomem[0], OBJECT(s), ops ? &ops[1] : NULL, | 
					
						
							|  |  |  |                           s, "gic_cpu", s->revision == 2 ? 0x2000 : 0x100); | 
					
						
							|  |  |  |     sysbus_init_mmio(sbd, &s->cpuiomem[0]); | 
					
						
							| 
									
										
										
										
											2018-08-14 17:17:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (s->virt_extn) { | 
					
						
							|  |  |  |         memory_region_init_io(&s->vifaceiomem[0], OBJECT(s), virt_ops, | 
					
						
							|  |  |  |                               s, "gic_viface", 0x1000); | 
					
						
							|  |  |  |         sysbus_init_mmio(sbd, &s->vifaceiomem[0]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         memory_region_init_io(&s->vcpuiomem, OBJECT(s), | 
					
						
							|  |  |  |                               virt_ops ? &virt_ops[1] : NULL, | 
					
						
							|  |  |  |                               s, "gic_vcpu", 0x2000); | 
					
						
							|  |  |  |         sysbus_init_mmio(sbd, &s->vcpuiomem); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-08-13 11:26:21 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 00:34:42 +00:00
										 |  |  | static void arm_gic_common_realize(DeviceState *dev, Error **errp) | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-03-05 00:34:42 +00:00
										 |  |  |     GICState *s = ARM_GIC_COMMON(dev); | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  |     int num_irq = s->num_irq; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-23 03:37:49 +02:00
										 |  |  |     if (s->num_cpu > GIC_NCPU) { | 
					
						
							| 
									
										
										
										
											2013-03-05 00:34:42 +00:00
										 |  |  |         error_setg(errp, "requested %u CPUs exceeds GIC maximum %d", | 
					
						
							| 
									
										
										
										
											2013-07-23 03:37:49 +02:00
										 |  |  |                    s->num_cpu, GIC_NCPU); | 
					
						
							| 
									
										
										
										
											2013-03-05 00:34:42 +00:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (s->num_irq > GIC_MAXIRQ) { | 
					
						
							| 
									
										
										
										
											2013-03-05 00:34:42 +00:00
										 |  |  |         error_setg(errp, | 
					
						
							|  |  |  |                    "requested %u interrupt lines exceeds GIC maximum %d", | 
					
						
							|  |  |  |                    num_irq, GIC_MAXIRQ); | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     /* ITLinesNumber is represented as (N / 32) - 1 (see
 | 
					
						
							|  |  |  |      * gic_dist_readb) so this is an implementation imposed | 
					
						
							|  |  |  |      * restriction, not an architectural one: | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     if (s->num_irq < 32 || (s->num_irq % 32)) { | 
					
						
							| 
									
										
										
										
											2013-03-05 00:34:42 +00:00
										 |  |  |         error_setg(errp, | 
					
						
							|  |  |  |                    "%d interrupt lines unsupported: not divisible by 32", | 
					
						
							|  |  |  |                    num_irq); | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-05-12 11:57:16 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (s->security_extn && | 
					
						
							| 
									
										
										
										
											2017-02-28 12:08:17 +00:00
										 |  |  |         (s->revision == REV_11MPCORE)) { | 
					
						
							| 
									
										
										
										
											2015-05-12 11:57:16 +01:00
										 |  |  |         error_setg(errp, "this GIC revision does not implement " | 
					
						
							|  |  |  |                    "the security extensions"); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-14 17:17:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (s->virt_extn) { | 
					
						
							|  |  |  |         if (s->revision != 2) { | 
					
						
							|  |  |  |             error_setg(errp, "GIC virtualization extensions are only " | 
					
						
							|  |  |  |                        "supported by revision 2"); | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /* For now, set the number of implemented LRs to 4, as found in most
 | 
					
						
							|  |  |  |          * real GICv2. This could be promoted as a QOM property if we need to | 
					
						
							|  |  |  |          * emulate a variant with another num_lrs. | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         s->num_lrs = 4; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void arm_gic_common_reset_irq_state(GICState *s, int first_cpu, | 
					
						
							|  |  |  |                                                   int resetprio) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int i, j; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (i = first_cpu; i < first_cpu + s->num_cpu; i++) { | 
					
						
							|  |  |  |         if (s->revision == REV_11MPCORE) { | 
					
						
							|  |  |  |             s->priority_mask[i] = 0xf0; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             s->priority_mask[i] = resetprio; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         s->current_pending[i] = 1023; | 
					
						
							|  |  |  |         s->running_priority[i] = 0x100; | 
					
						
							|  |  |  |         s->cpu_ctlr[i] = 0; | 
					
						
							|  |  |  |         s->bpr[i] = gic_is_vcpu(i) ? GIC_VIRT_MIN_BPR : GIC_MIN_BPR; | 
					
						
							|  |  |  |         s->abpr[i] = gic_is_vcpu(i) ? GIC_VIRT_MIN_ABPR : GIC_MIN_ABPR; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!gic_is_vcpu(i)) { | 
					
						
							|  |  |  |             for (j = 0; j < GIC_INTERNAL; j++) { | 
					
						
							|  |  |  |                 s->priority1[j][i] = resetprio; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             for (j = 0; j < GIC_NR_SGIS; j++) { | 
					
						
							|  |  |  |                 s->sgi_pending[j][i] = 0; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-14 14:27:11 +00:00
										 |  |  | static void arm_gic_common_reset_hold(Object *obj) | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-12-14 14:27:11 +00:00
										 |  |  |     GICState *s = ARM_GIC_COMMON(obj); | 
					
						
							| 
									
										
										
										
											2015-06-29 19:25:45 +01:00
										 |  |  |     int i, j; | 
					
						
							| 
									
										
										
										
											2015-09-08 17:38:43 +01:00
										 |  |  |     int resetprio; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* If we're resetting a TZ-aware GIC as if secure firmware
 | 
					
						
							|  |  |  |      * had set it up ready to start a kernel in non-secure, | 
					
						
							|  |  |  |      * we need to set interrupt priorities to a "zero for the | 
					
						
							|  |  |  |      * NS view" value. This is particularly critical for the | 
					
						
							|  |  |  |      * priority_mask[] values, because if they are zero then NS | 
					
						
							|  |  |  |      * code cannot ever rewrite the priority to anything else. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     if (s->security_extn && s->irq_reset_nonsecure) { | 
					
						
							|  |  |  |         resetprio = 0x80; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         resetprio = 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  |     memset(s->irq_state, 0, GIC_MAXIRQ * sizeof(gic_irq_state)); | 
					
						
							| 
									
										
										
										
											2018-08-14 17:17:20 +01:00
										 |  |  |     arm_gic_common_reset_irq_state(s, 0, resetprio); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (s->virt_extn) { | 
					
						
							|  |  |  |         /* vCPU states are stored at indexes GIC_NCPU .. GIC_NCPU+num_cpu.
 | 
					
						
							|  |  |  |          * The exposed vCPU interface does not have security extensions. | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         arm_gic_common_reset_irq_state(s, GIC_NCPU, 0); | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-14 17:17:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-29 15:00:29 +01:00
										 |  |  |     for (i = 0; i < GIC_NR_SGIS; i++) { | 
					
						
							| 
									
										
										
										
											2018-08-14 17:17:19 +01:00
										 |  |  |         GIC_DIST_SET_ENABLED(i, ALL_CPU_MASK); | 
					
						
							|  |  |  |         GIC_DIST_SET_EDGE_TRIGGER(i); | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-06-29 19:25:45 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for (i = 0; i < ARRAY_SIZE(s->priority2); i++) { | 
					
						
							| 
									
										
										
										
											2015-09-08 17:38:43 +01:00
										 |  |  |         s->priority2[i] = resetprio; | 
					
						
							| 
									
										
										
										
											2015-06-29 19:25:45 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (i = 0; i < GIC_MAXIRQ; i++) { | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  |         /* For uniprocessor GICs all interrupts always target the sole CPU */ | 
					
						
							| 
									
										
										
										
											2015-06-29 19:25:45 +01:00
										 |  |  |         if (s->num_cpu == 1) { | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  |             s->irq_target[i] = 1; | 
					
						
							| 
									
										
										
										
											2015-06-29 19:25:45 +01:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             s->irq_target[i] = 0; | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-09-08 17:38:43 +01:00
										 |  |  |     if (s->security_extn && s->irq_reset_nonsecure) { | 
					
						
							|  |  |  |         for (i = 0; i < GIC_MAXIRQ; i++) { | 
					
						
							| 
									
										
										
										
											2018-08-14 17:17:19 +01:00
										 |  |  |             GIC_DIST_SET_GROUP(i, ALL_CPU_MASK); | 
					
						
							| 
									
										
										
										
											2015-09-08 17:38:43 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 17:17:20 +01:00
										 |  |  |     if (s->virt_extn) { | 
					
						
							|  |  |  |         for (i = 0; i < s->num_lrs; i++) { | 
					
						
							|  |  |  |             for (j = 0; j < s->num_cpu; j++) { | 
					
						
							|  |  |  |                 s->h_lr[i][j] = 0; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (i = 0; i < s->num_cpu; i++) { | 
					
						
							|  |  |  |             s->h_hcr[i] = 0; | 
					
						
							|  |  |  |             s->h_misr[i] = 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-12 11:57:17 +01:00
										 |  |  |     s->ctlr = 0; | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 17:38:43 +01:00
										 |  |  | static void arm_gic_common_linux_init(ARMLinuxBootIf *obj, | 
					
						
							|  |  |  |                                       bool secure_boot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     GICState *s = ARM_GIC_COMMON(obj); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (s->security_extn && !secure_boot) { | 
					
						
							|  |  |  |         /* We're directly booting a kernel into NonSecure. If this GIC
 | 
					
						
							|  |  |  |          * implements the security extensions then we must configure it | 
					
						
							|  |  |  |          * to have all the interrupts be NonSecure (this is a job that | 
					
						
							|  |  |  |          * is done by the Secure boot firmware in real hardware, and in | 
					
						
							|  |  |  |          * this mode QEMU is acting as a minimalist firmware-and-bootloader | 
					
						
							|  |  |  |          * equivalent). | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         s->irq_reset_nonsecure = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  | static Property arm_gic_common_properties[] = { | 
					
						
							| 
									
										
										
										
											2012-10-12 11:54:39 +01:00
										 |  |  |     DEFINE_PROP_UINT32("num-cpu", GICState, num_cpu, 1), | 
					
						
							|  |  |  |     DEFINE_PROP_UINT32("num-irq", GICState, num_irq, 32), | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  |     /* Revision can be 1 or 2 for GIC architecture specification
 | 
					
						
							|  |  |  |      * versions 1 or 2, or 0 to indicate the legacy 11MPCore GIC. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2012-10-12 11:54:39 +01:00
										 |  |  |     DEFINE_PROP_UINT32("revision", GICState, revision, 1), | 
					
						
							| 
									
										
										
										
											2015-05-12 11:57:16 +01:00
										 |  |  |     /* True if the GIC should implement the security extensions */ | 
					
						
							|  |  |  |     DEFINE_PROP_BOOL("has-security-extensions", GICState, security_extn, 0), | 
					
						
							| 
									
										
										
										
											2018-08-14 17:17:20 +01:00
										 |  |  |     /* True if the GIC should implement the virtualization extensions */ | 
					
						
							|  |  |  |     DEFINE_PROP_BOOL("has-virtualization-extensions", GICState, virt_extn, 0), | 
					
						
							| 
									
										
										
										
											2020-02-24 15:09:22 +05:30
										 |  |  |     DEFINE_PROP_UINT32("num-priority-bits", GICState, n_prio_bits, 8), | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  |     DEFINE_PROP_END_OF_LIST(), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void arm_gic_common_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							| 
									
										
										
										
											2022-12-14 14:27:11 +00:00
										 |  |  |     ResettableClass *rc = RESETTABLE_CLASS(klass); | 
					
						
							| 
									
										
										
										
											2015-09-08 17:38:43 +01:00
										 |  |  |     ARMLinuxBootIfClass *albifc = ARM_LINUX_BOOT_IF_CLASS(klass); | 
					
						
							| 
									
										
										
										
											2013-03-05 00:34:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-14 14:27:11 +00:00
										 |  |  |     rc->phases.hold = arm_gic_common_reset_hold; | 
					
						
							| 
									
										
										
										
											2013-03-05 00:34:42 +00:00
										 |  |  |     dc->realize = arm_gic_common_realize; | 
					
						
							| 
									
										
										
										
											2020-01-10 19:30:32 +04:00
										 |  |  |     device_class_set_props(dc, arm_gic_common_properties); | 
					
						
							| 
									
										
										
										
											2013-04-05 16:18:00 +01:00
										 |  |  |     dc->vmsd = &vmstate_gic; | 
					
						
							| 
									
										
										
										
											2015-09-08 17:38:43 +01:00
										 |  |  |     albifc->arm_linux_init = arm_gic_common_linux_init; | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-10 16:19:07 +01:00
										 |  |  | static const TypeInfo arm_gic_common_type = { | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  |     .name = TYPE_ARM_GIC_COMMON, | 
					
						
							|  |  |  |     .parent = TYPE_SYS_BUS_DEVICE, | 
					
						
							| 
									
										
										
										
											2012-10-12 11:54:39 +01:00
										 |  |  |     .instance_size = sizeof(GICState), | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  |     .class_size = sizeof(ARMGICCommonClass), | 
					
						
							|  |  |  |     .class_init = arm_gic_common_class_init, | 
					
						
							|  |  |  |     .abstract = true, | 
					
						
							| 
									
										
										
										
											2015-09-08 17:38:43 +01:00
										 |  |  |     .interfaces = (InterfaceInfo []) { | 
					
						
							|  |  |  |         { TYPE_ARM_LINUX_BOOT_IF }, | 
					
						
							|  |  |  |         { }, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2012-05-02 16:49:42 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void register_types(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     type_register_static(&arm_gic_common_type); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type_init(register_types) |