From patchwork Tue Jun 30 13:07:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 50475 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4E540229DF for ; Tue, 30 Jun 2015 13:07:41 +0000 (UTC) Received: by lagx9 with SMTP id x9sf3438665lag.2 for ; Tue, 30 Jun 2015 06:07:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=M6QZF+uOlMnAZUq/ohSVInzFAsvG8ru+bFPxPbNIkYE=; b=bSB5Cl6j7MwyMyh330iQ8mULrYiIkbvbbp0ufC/f8bFubOC93ja5JjwJrpTbRnKKEB r/pOFdfe0I53xmUX3KX9sGjVMVoHXEB0IvkXyzYYpUtU+JwWisKbbuP7mYkV9Gl6AaOs SoNGHE1PiBe/WW937zdXXdvDbSekV8tJ4qfVlCF+1j1ypJ6lZ6UNkxiDF7eI/cahnM7y dKBablxgGxS2kN8sYu97QeRWCTWKiGXbxgBxfNsp6uX+dGVWl/SxY/xsD2ui/zScmrtH R+iGNY/C/C+w8tcaipUHWuGppa7gJpY591BlkTqdEdysKx0MnyhIQKKlHilIMtShvpa4 w6pQ== X-Gm-Message-State: ALoCoQmJMsUVqlJ5q4UKWItldLydoG4whpE4qLeo3PR2rLYY34JV8zoJ0g1jWZZAd7FUpXxMtynR X-Received: by 10.152.27.130 with SMTP id t2mr14052797lag.2.1435669660336; Tue, 30 Jun 2015 06:07:40 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.36 with SMTP id g4ls39797lah.33.gmail; Tue, 30 Jun 2015 06:07:40 -0700 (PDT) X-Received: by 10.152.4.98 with SMTP id j2mr19651445laj.42.1435669660189; Tue, 30 Jun 2015 06:07:40 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id 8si38070890lan.120.2015.06.30.06.07.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jun 2015 06:07:39 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by laar3 with SMTP id r3so12715904laa.0 for ; Tue, 30 Jun 2015 06:07:39 -0700 (PDT) X-Received: by 10.152.4.163 with SMTP id l3mr19922693lal.35.1435669659753; Tue, 30 Jun 2015 06:07:39 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp2437234lbb; Tue, 30 Jun 2015 06:07:38 -0700 (PDT) X-Received: by 10.67.8.71 with SMTP id di7mr43927544pad.46.1435669656846; Tue, 30 Jun 2015 06:07:36 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id dv2si69966214pbc.200.2015.06.30.06.07.34 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 30 Jun 2015 06:07:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1Z9vG5-0000nY-TQ; Tue, 30 Jun 2015 14:07:29 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Peter Crosthwaite , "Edgar E. Iglesias" , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [PATCH 2/5] hw/intc/arm_gic_common: Provide property to make IRQs reset as NonSecure Date: Tue, 30 Jun 2015 14:07:26 +0100 Message-Id: <1435669649-3035-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1435669649-3035-1-git-send-email-peter.maydell@linaro.org> References: <1435669649-3035-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Implement a property which causes the GIC to reset with interrupts configured into group 1 (NonSecure) rather than the usual group 0, and with their initial priority set to the highest NonSecure priority rather than the usual highest Secure priority. This is necessary for the situation where we directly boot a kernel in NonSecure on a system where the GIC supports the security extensions: otherwise the kernel will be unable to access any of its interrupts. The property is writable after realize, because we won't know whether we need to set it until after machine creation is complete. If the setting is changed it will take effect at the next reset. Signed-off-by: Peter Maydell --- hw/intc/arm_gic_common.c | 55 +++++++++++++++++++++++++++++++++++++--- include/hw/intc/arm_gic_common.h | 1 + 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/hw/intc/arm_gic_common.c b/hw/intc/arm_gic_common.c index a64d071..bc8b9c9 100644 --- a/hw/intc/arm_gic_common.c +++ b/hw/intc/arm_gic_common.c @@ -84,6 +84,33 @@ static const VMStateDescription vmstate_gic = { } }; +static bool arm_gic_irq_reset_nonsecure_get(Object *obj, Error **errp) +{ + GICState *s = ARM_GIC_COMMON(obj); + + return s->irq_reset_nonsecure; +} + +static void arm_gic_irq_reset_nonsecure_set(Object *obj, bool val, Error **errp) +{ + GICState *s = ARM_GIC_COMMON(obj); + + s->irq_reset_nonsecure = val; +} + +static void arm_gic_common_init(Object *obj) +{ + /* This property should be set true if the GIC should configure + * IRQs as group 1 (NS) on reset, rather than the usual group 0. + * It is essentially a standard bool property, except that it can be + * set after realize (and will take effect at the next reset). + */ + object_property_add_bool(obj, "irqs-reset-nonsecure", + arm_gic_irq_reset_nonsecure_get, + arm_gic_irq_reset_nonsecure_set, + &error_abort); +} + static void arm_gic_common_realize(DeviceState *dev, Error **errp) { GICState *s = ARM_GIC_COMMON(dev); @@ -124,12 +151,27 @@ static void arm_gic_common_reset(DeviceState *dev) { GICState *s = ARM_GIC_COMMON(dev); int i, j; + 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; + } + memset(s->irq_state, 0, GIC_MAXIRQ * sizeof(gic_irq_state)); for (i = 0 ; i < s->num_cpu; i++) { if (s->revision == REV_11MPCORE) { s->priority_mask[i] = 0xf0; } else { - s->priority_mask[i] = 0; + s->priority_mask[i] = resetprio; } s->current_pending[i] = 1023; s->running_irq[i] = 1023; @@ -138,7 +180,7 @@ static void arm_gic_common_reset(DeviceState *dev) s->bpr[i] = GIC_MIN_BPR; s->abpr[i] = GIC_MIN_ABPR; for (j = 0; j < GIC_INTERNAL; j++) { - s->priority1[j][i] = 0; + s->priority1[j][i] = resetprio; } for (j = 0; j < GIC_NR_SGIS; j++) { s->sgi_pending[j][i] = 0; @@ -150,7 +192,7 @@ static void arm_gic_common_reset(DeviceState *dev) } for (i = 0; i < ARRAY_SIZE(s->priority2); i++) { - s->priority2[i] = 0; + s->priority2[i] = resetprio; } for (i = 0; i < GIC_MAXIRQ; i++) { @@ -161,6 +203,12 @@ static void arm_gic_common_reset(DeviceState *dev) s->irq_target[i] = 0; } } + if (s->security_extn && s->irq_reset_nonsecure) { + for (i = 0; i < GIC_MAXIRQ; i++) { + GIC_SET_GROUP(i, ALL_CPU_MASK); + } + } + s->ctlr = 0; } @@ -191,6 +239,7 @@ static const TypeInfo arm_gic_common_type = { .name = TYPE_ARM_GIC_COMMON, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(GICState), + .instance_init = arm_gic_common_init, .class_size = sizeof(ARMGICCommonClass), .class_init = arm_gic_common_class_init, .abstract = true, diff --git a/include/hw/intc/arm_gic_common.h b/include/hw/intc/arm_gic_common.h index 899db3d..cfc1cce 100644 --- a/include/hw/intc/arm_gic_common.h +++ b/include/hw/intc/arm_gic_common.h @@ -118,6 +118,7 @@ typedef struct GICState { uint32_t num_irq; uint32_t revision; bool security_extn; + bool irq_reset_nonsecure; /* configure IRQs as group 1 (NS) on reset? */ int dev_fd; /* kvm device fd if backed by kvm vgic support */ } GICState;