qemu_v8.mk: Add option to compile with GICv3

QEMU supports the virtualization extensions only in emulated
GICv3. So, add an option to build TF-A, OP-TEE with GICv3.
To enable this, use GICV3=y with make.

Signed-off-by: Ruchika Gupta <ruchika.gupta@linaro.org>
Reviewed-by: Jerome Forissier <jerome@forissier.org>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
diff --git a/qemu_v8.mk b/qemu_v8.mk
index ec5a8ed..36519d6 100644
--- a/qemu_v8.mk
+++ b/qemu_v8.mk
@@ -26,6 +26,9 @@
 # Option to use U-Boot in the boot flow instead of EDK2
 UBOOT ?= n
 
+# Option to build with GICV3 enabled
+GICV3 ?= n
+
 ################################################################################
 # Paths to git projects and various binaries
 ################################################################################
@@ -69,6 +72,14 @@
 BL33_DEPS		?= edk2
 endif
 
+ifeq ($(GICV3),y)
+	TFA_GIC_DRIVER	?= QEMU_GICV3
+	QEMU_GIC_VERSION = 3
+else
+	TFA_GIC_DRIVER	?= QEMU_GICV2
+	QEMU_GIC_VERSION = 2
+endif
+
 ################################################################################
 # Targets
 ################################################################################
@@ -115,6 +126,7 @@
 	BL32_EXTRA2=$(OPTEE_OS_PAGEABLE_V2_BIN) \
 	BL33=$(BL33_BIN) \
 	PLAT=qemu \
+	QEMU_USE_GIC_DRIVER=$(TFA_GIC_DRIVER) \
 	ARM_TSP_RAM_LOCATION=tdram \
 	BL32_RAM_LOCATION=tdram \
 	SPD=opteed \
@@ -241,7 +253,7 @@
 ################################################################################
 # OP-TEE
 ################################################################################
-OPTEE_OS_COMMON_FLAGS += DEBUG=$(DEBUG)
+OPTEE_OS_COMMON_FLAGS += DEBUG=$(DEBUG) CFG_ARM_GICV3=$(GICV3)
 optee-os: optee-os-common
 
 optee-os-clean: optee-os-clean-common
@@ -306,7 +318,8 @@
 		-nographic \
 		-serial tcp:localhost:54320 -serial tcp:localhost:54321 \
 		-smp $(QEMU_SMP) \
-		-s -S -machine virt,secure=on -cpu cortex-a57 \
+		-s -S -machine virt,secure=on,gic-version=$(QEMU_GIC_VERSION) \
+		-cpu cortex-a57 \
 		-d unimp -semihosting-config enable=on,target=native \
 		-m 1057 \
 		-bios bl1.bin \
@@ -328,6 +341,7 @@
 	cd $(BINARIES_PATH) && \
 		export QEMU=$(QEMU_BUILD)/aarch64-softmmu/qemu-system-aarch64 && \
 		export QEMU_SMP=$(QEMU_SMP) && \
+		export QEMU_GIC=$(QEMU_GIC_VERSION) && \
 		expect $(ROOT)/build/qemu-check.exp -- $(check-args) || \
 		(if [ "$(DUMP_LOGS_ON_ERROR)" ]; then \
 			echo "== $$PWD/serial0.log:"; \