From patchwork Wed Oct 23 15:26:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 21230 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f199.google.com (mail-qc0-f199.google.com [209.85.216.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0AC6623903 for ; Wed, 23 Oct 2013 15:27:01 +0000 (UTC) Received: by mail-qc0-f199.google.com with SMTP id q4sf2175979qcx.10 for ; Wed, 23 Oct 2013 08:27:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:x-gm-message-state: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=2PO5kzXYxxVspC7m83lBbSfbP4Nz/5Ib8Q4SrO2Vgg0=; b=DNnth8j0C7F/wPm2TFfrtnRW94bx8xRdDb7jJ0Y3qMInzuLogFTLll9V4PqfijQGE+ JGsSKejWYmL/lJrsBdyOG9P9etYRJbg38lnTC1mL7Yozke5oOO60RQ1TWTiMFSLZX84Q O1DWg8uIf82C/w6JuSwI6DOnmH1kHDkJ/TOQKMA2U51sS2oJttVQY/45Bh2S6mhTNFAB lvIJygKCW8CsBB7AdAZBKr4iUgQWOGyWC5GqdSxVmvRshD0eS2yvlp/bnDGv5GOroWSX gGSJMJoOFbtt60ZFizryqNNvQ/Yfg+BJ/LTBj1mxIgfqYhsMgJnpPd3UAnQ0WNzMwqo/ Zzxw== X-Received: by 10.52.31.69 with SMTP id y5mr783286vdh.4.1382542021424; Wed, 23 Oct 2013 08:27:01 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.53.2 with SMTP id x2ls526137qeo.34.gmail; Wed, 23 Oct 2013 08:27:01 -0700 (PDT) X-Received: by 10.58.208.130 with SMTP id me2mr1528988vec.13.1382542021326; Wed, 23 Oct 2013 08:27:01 -0700 (PDT) Received: from mail-vb0-f48.google.com (mail-vb0-f48.google.com [209.85.212.48]) by mx.google.com with ESMTPS id tw10si4208397vec.44.2013.10.23.08.27.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 23 Oct 2013 08:27:01 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.48 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.48; Received: by mail-vb0-f48.google.com with SMTP id w16so521170vbf.35 for ; Wed, 23 Oct 2013 08:27:01 -0700 (PDT) X-Gm-Message-State: ALoCoQm5igys/CC5VmFfD0vXTVciy8EbfZ385ZRl95+/vKsIM6rtQsu8r/i77KFTllwcMNXkprOD X-Received: by 10.52.229.234 with SMTP id st10mr857681vdc.34.1382542021159; Wed, 23 Oct 2013 08:27:01 -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.220.174.196 with SMTP id u4csp319986vcz; Wed, 23 Oct 2013 08:27:00 -0700 (PDT) X-Received: by 10.180.20.177 with SMTP id o17mr2069846wie.38.1382542020185; Wed, 23 Oct 2013 08:27:00 -0700 (PDT) Received: from mail-we0-f182.google.com (mail-we0-f182.google.com [74.125.82.182]) by mx.google.com with ESMTPS id ls14si3877578wic.17.2013.10.23.08.26.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 23 Oct 2013 08:27:00 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.182 is neither permitted nor denied by best guess record for domain of christoffer.dall@linaro.org) client-ip=74.125.82.182; Received: by mail-we0-f182.google.com with SMTP id t61so1010182wes.27 for ; Wed, 23 Oct 2013 08:26:59 -0700 (PDT) X-Received: by 10.194.235.138 with SMTP id um10mr2273232wjc.30.1382542019600; Wed, 23 Oct 2013 08:26:59 -0700 (PDT) Received: from hsia.quadriga.com (ip-77-221-165-98.dsl.twang.net. [77.221.165.98]) by mx.google.com with ESMTPSA id eq12sm18027627wic.7.2013.10.23.08.26.58 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 23 Oct 2013 08:26:59 -0700 (PDT) From: Christoffer Dall To: peter.maydell@linaro.org Cc: qemu-devel@nongnu.org, kvmarm@lists.cs.columbia.edu, patches@linaro.org, Christoffer Dall Subject: [PATCH] arm_gic: Keep track of GICD_CPENDR and GICD_SPENDR Date: Wed, 23 Oct 2013 16:26:51 +0100 Message-Id: <1382542011-7098-1-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: References: X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: christoffer.dall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.48 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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: , If software writes to the ISPENDR and sets the pending state of a level-triggered interrupt, the falling edge of the hardware input must not clear the pending state. Conversely, if software writes to the ICPENDR, the pending state of a level-triggered interrupt should only be cleared if the hardware input is not asserted. This requires an extra state variable to keep track of software writes. Signed-off-by: Christoffer Dall --- hw/intc/arm_gic.c | 20 +++++++++++++++++--- hw/intc/arm_gic_common.c | 5 +++-- hw/intc/gic_internal.h | 4 ++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/hw/intc/arm_gic.c b/hw/intc/arm_gic.c index d1ddac1..db54061 100644 --- a/hw/intc/arm_gic.c +++ b/hw/intc/arm_gic.c @@ -101,6 +101,12 @@ static void gic_clear_pending(GICState *s, int irq, int cm, uint8_t src) { unsigned cpu; + /* If a level-triggered interrupt has been set to pending through the + * GICD_SPENDR, then a falling edge does not clear the pending state. + */ + if (GIC_TEST_SW_PENDING(irq, cm)) + return; + GIC_CLEAR_PENDING(irq, cm); if (irq < GIC_NR_SGIS) { cpu = (unsigned)ffs(cm) - 1; @@ -177,8 +183,9 @@ uint32_t gic_acknowledge_irq(GICState *s, int cpu) s->last_active[new_irq][cpu] = s->running_irq[cpu]; /* Clear pending flags for both level and edge triggered interrupts. Level triggered IRQs will be reasserted once they become inactive. */ - gic_clear_pending(s, new_irq, GIC_TEST_MODEL(new_irq) ? ALL_CPU_MASK : cm, - GIC_SGI_SRC(new_irq, cpu)); + cm = GIC_TEST_MODEL(new_irq) ? ALL_CPU_MASK : cm; + GIC_CLEAR_SW_PENDING(new_irq, cm); + gic_clear_pending(s, new_irq, cm, GIC_SGI_SRC(new_irq, cpu)); gic_set_running_irq(s, cpu, new_irq); DPRINTF("ACK %d\n", new_irq); return new_irq; @@ -445,16 +452,23 @@ static void gic_dist_writeb(void *opaque, hwaddr offset, for (i = 0; i < 8; i++) { if (value & (1 << i)) { GIC_SET_PENDING(irq + i, GIC_TARGET(irq + i)); + if (!GIC_TEST_TRIGGER(irq + i)) { + GIC_SET_SW_PENDING(irq + i, GIC_TARGET(irq + i)); + } } } } else if (offset < 0x300) { + int cm = (1 << cpu); /* Interrupt Clear Pending. */ irq = (offset - 0x280) * 8 + GIC_BASE_IRQ; if (irq >= s->num_irq) goto bad_reg; for (i = 0; i < 8; i++, irq++) { if (irq > GIC_NR_SGIS && value & (1 << i)) { - gic_clear_pending(s, irq, 1 << cpu, 0); + GIC_CLEAR_SW_PENDING(irq, cm); + if (GIC_TEST_TRIGGER(irq + i) || !GIC_TEST_LEVEL(irq, cm)) { + GIC_CLEAR_PENDING(irq, cm); + } } } } else if (offset < 0x400) { diff --git a/hw/intc/arm_gic_common.c b/hw/intc/arm_gic_common.c index 1d3b738..7f0615f 100644 --- a/hw/intc/arm_gic_common.c +++ b/hw/intc/arm_gic_common.c @@ -43,11 +43,12 @@ static int gic_post_load(void *opaque, int version_id) static const VMStateDescription vmstate_gic_irq_state = { .name = "arm_gic_irq_state", - .version_id = 1, - .minimum_version_id = 1, + .version_id = 2, + .minimum_version_id = 2, .fields = (VMStateField[]) { VMSTATE_UINT8(enabled, gic_irq_state), VMSTATE_UINT8(pending, gic_irq_state), + VMSTATE_UINT8(sw_pending, gic_irq_state), VMSTATE_UINT8(active, gic_irq_state), VMSTATE_UINT8(level, gic_irq_state), VMSTATE_BOOL(model, gic_irq_state), diff --git a/hw/intc/gic_internal.h b/hw/intc/gic_internal.h index f9133b9..173c607 100644 --- a/hw/intc/gic_internal.h +++ b/hw/intc/gic_internal.h @@ -43,6 +43,9 @@ #define GIC_SET_PENDING(irq, cm) s->irq_state[irq].pending |= (cm) #define GIC_CLEAR_PENDING(irq, cm) s->irq_state[irq].pending &= ~(cm) #define GIC_TEST_PENDING(irq, cm) ((s->irq_state[irq].pending & (cm)) != 0) +#define GIC_SET_SW_PENDING(irq, cm) s->irq_state[irq].sw_pending |= (cm) +#define GIC_CLEAR_SW_PENDING(irq, cm) s->irq_state[irq].sw_pending &= ~(cm) +#define GIC_TEST_SW_PENDING(irq, cm) ((s->irq_state[irq].sw_pending & (cm)) != 0) #define GIC_SET_ACTIVE(irq, cm) s->irq_state[irq].active |= (cm) #define GIC_CLEAR_ACTIVE(irq, cm) s->irq_state[irq].active &= ~(cm) #define GIC_TEST_ACTIVE(irq, cm) ((s->irq_state[irq].active & (cm)) != 0) @@ -65,6 +68,7 @@ typedef struct gic_irq_state { /* The enable bits are only banked for per-cpu interrupts. */ uint8_t enabled; uint8_t pending; + uint8_t sw_pending; /* keep track of GICD_ISPENDR and GICD_ICPENDR writes */ uint8_t active; uint8_t level; bool model; /* 0 = N:N, 1 = 1:N */