From patchwork Mon May 11 13:40:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 48300 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7E0BF21550 for ; Mon, 11 May 2015 13:51:56 +0000 (UTC) Received: by lbbqq2 with SMTP id qq2sf38811028lbb.0 for ; Mon, 11 May 2015 06:51:55 -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:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=M/SpXS/zzJkZG0suT/aY6qTg09avsuSG92d8zgxnXAM=; b=ag7xLSvF/Rss5Zo7Hm4wP+dhDh80FUl+YAXsB4HVkVfzWRJx+TQp9Rm3IBaLZHlNzU eoM6YCzNK+iQmSYz6XtEcwyu0KKXyOsoZbb9qpETM1wgENvCcV538ivSIsnnmlvgU4Nx KjGN12ccTbl5avgD/+Qv70Hs937GLPhTOJfwrqHKuUHAkdNzZbEG4XluVoxvj5ifFbb4 jXww/wCa9x5D4zwZR0BSncaplrONRD7l14xgBNQpTYMBd7X6AS04t/uuZtIB8V7fOB78 ePe2aqv+Pzsuk36VXMKQdMMUyQZ23IvEIw2PEvydLpY6Cncw61gAWQJz9eW765q9om3a 5LeQ== X-Gm-Message-State: ALoCoQnUJtC44NokzH6bDGWZmIQfWjreVNmt3VkANTTbLs2g037oMr+HAZ9+XV38X+cWn3BQZJuR X-Received: by 10.194.5.229 with SMTP id v5mr7573228wjv.0.1431352315244; Mon, 11 May 2015 06:51:55 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.42.172 with SMTP id p12ls654670lal.40.gmail; Mon, 11 May 2015 06:51:55 -0700 (PDT) X-Received: by 10.112.12.68 with SMTP id w4mr8053086lbb.87.1431352315082; Mon, 11 May 2015 06:51:55 -0700 (PDT) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id wh2si8410003lbb.24.2015.05.11.06.51.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 May 2015 06:51:55 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by layy10 with SMTP id y10so93643050lay.0 for ; Mon, 11 May 2015 06:51:55 -0700 (PDT) X-Received: by 10.152.27.98 with SMTP id s2mr8206087lag.106.1431352314953; Mon, 11 May 2015 06:51:54 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1518429lbb; Mon, 11 May 2015 06:51:54 -0700 (PDT) X-Received: by 10.140.98.245 with SMTP id o108mr13226895qge.36.1431352310727; Mon, 11 May 2015 06:51:50 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 199si13014697qhe.36.2015.05.11.06.51.49 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 11 May 2015 06:51:50 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:37528 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yro7Z-0004Y7-E9 for patch@linaro.org; Mon, 11 May 2015 09:51:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42493) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yrnwx-0002Pm-Ft for qemu-devel@nongnu.org; Mon, 11 May 2015 09:40:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yrnwv-0000hE-41 for qemu-devel@nongnu.org; Mon, 11 May 2015 09:40:50 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:34140) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yrnwu-0000d0-MJ for qemu-devel@nongnu.org; Mon, 11 May 2015 09:40:49 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1Yrnwk-0005es-Tc for qemu-devel@nongnu.org; Mon, 11 May 2015 14:40:38 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 11 May 2015 14:40:24 +0100 Message-Id: <1431351638-21705-6-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1431351638-21705-1-git-send-email-peter.maydell@linaro.org> References: <1431351638-21705-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Subject: [Qemu-devel] [PULL 05/19] hw/intc/arm_gic: Switch to read/write callbacks with tx attributes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.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.45 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Switch the GIC's MMIO callback functions to the read_with_attrs and write_with_attrs functions which provide MemTxAttrs. This will allow the GIC to correctly handle secure and nonsecure register accesses. Signed-off-by: Peter Maydell Reviewed-by: Edgar E. Iglesias Message-id: 1430502643-25909-4-git-send-email-peter.maydell@linaro.org --- hw/intc/arm_gic.c | 144 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 90 insertions(+), 54 deletions(-) diff --git a/hw/intc/arm_gic.c b/hw/intc/arm_gic.c index cdf7408..29015c2 100644 --- a/hw/intc/arm_gic.c +++ b/hw/intc/arm_gic.c @@ -282,7 +282,7 @@ void gic_complete_irq(GICState *s, int cpu, int irq) } } -static uint32_t gic_dist_readb(void *opaque, hwaddr offset) +static uint32_t gic_dist_readb(void *opaque, hwaddr offset, MemTxAttrs attrs) { GICState *s = (GICState *)opaque; uint32_t res; @@ -418,24 +418,30 @@ bad_reg: return 0; } -static uint32_t gic_dist_readw(void *opaque, hwaddr offset) +static MemTxResult gic_dist_read(void *opaque, hwaddr offset, uint64_t *data, + unsigned size, MemTxAttrs attrs) { - uint32_t val; - val = gic_dist_readb(opaque, offset); - val |= gic_dist_readb(opaque, offset + 1) << 8; - return val; -} - -static uint32_t gic_dist_readl(void *opaque, hwaddr offset) -{ - uint32_t val; - val = gic_dist_readw(opaque, offset); - val |= gic_dist_readw(opaque, offset + 2) << 16; - return val; + switch (size) { + case 1: + *data = gic_dist_readb(opaque, offset, attrs); + return MEMTX_OK; + case 2: + *data = gic_dist_readb(opaque, offset, attrs); + *data |= gic_dist_readb(opaque, offset + 1, attrs) << 8; + return MEMTX_OK; + case 4: + *data = gic_dist_readb(opaque, offset, attrs); + *data |= gic_dist_readb(opaque, offset + 1, attrs) << 8; + *data |= gic_dist_readb(opaque, offset + 2, attrs) << 16; + *data |= gic_dist_readb(opaque, offset + 3, attrs) << 24; + return MEMTX_OK; + default: + return MEMTX_ERROR; + } } static void gic_dist_writeb(void *opaque, hwaddr offset, - uint32_t value) + uint32_t value, MemTxAttrs attrs) { GICState *s = (GICState *)opaque; int irq; @@ -612,14 +618,14 @@ bad_reg: } static void gic_dist_writew(void *opaque, hwaddr offset, - uint32_t value) + uint32_t value, MemTxAttrs attrs) { - gic_dist_writeb(opaque, offset, value & 0xff); - gic_dist_writeb(opaque, offset + 1, value >> 8); + gic_dist_writeb(opaque, offset, value & 0xff, attrs); + gic_dist_writeb(opaque, offset + 1, value >> 8, attrs); } static void gic_dist_writel(void *opaque, hwaddr offset, - uint32_t value) + uint32_t value, MemTxAttrs attrs) { GICState *s = (GICState *)opaque; if (offset == 0xf00) { @@ -655,45 +661,72 @@ static void gic_dist_writel(void *opaque, hwaddr offset, gic_update(s); return; } - gic_dist_writew(opaque, offset, value & 0xffff); - gic_dist_writew(opaque, offset + 2, value >> 16); + gic_dist_writew(opaque, offset, value & 0xffff, attrs); + gic_dist_writew(opaque, offset + 2, value >> 16, attrs); +} + +static MemTxResult gic_dist_write(void *opaque, hwaddr offset, uint64_t data, + unsigned size, MemTxAttrs attrs) +{ + switch (size) { + case 1: + gic_dist_writeb(opaque, offset, data, attrs); + return MEMTX_OK; + case 2: + gic_dist_writew(opaque, offset, data, attrs); + return MEMTX_OK; + case 4: + gic_dist_writel(opaque, offset, data, attrs); + return MEMTX_OK; + default: + return MEMTX_ERROR; + } } static const MemoryRegionOps gic_dist_ops = { - .old_mmio = { - .read = { gic_dist_readb, gic_dist_readw, gic_dist_readl, }, - .write = { gic_dist_writeb, gic_dist_writew, gic_dist_writel, }, - }, + .read_with_attrs = gic_dist_read, + .write_with_attrs = gic_dist_write, .endianness = DEVICE_NATIVE_ENDIAN, }; -static uint32_t gic_cpu_read(GICState *s, int cpu, int offset) +static MemTxResult gic_cpu_read(GICState *s, int cpu, int offset, + uint64_t *data, MemTxAttrs attrs) { switch (offset) { case 0x00: /* Control */ - return s->cpu_enabled[cpu]; + *data = s->cpu_enabled[cpu]; + break; case 0x04: /* Priority mask */ - return s->priority_mask[cpu]; + *data = s->priority_mask[cpu]; + break; case 0x08: /* Binary Point */ - return s->bpr[cpu]; + *data = s->bpr[cpu]; + break; case 0x0c: /* Acknowledge */ - return gic_acknowledge_irq(s, cpu); + *data = gic_acknowledge_irq(s, cpu); + break; case 0x14: /* Running Priority */ - return s->running_priority[cpu]; + *data = s->running_priority[cpu]; + break; case 0x18: /* Highest Pending Interrupt */ - return s->current_pending[cpu]; + *data = s->current_pending[cpu]; + break; case 0x1c: /* Aliased Binary Point */ - return s->abpr[cpu]; + *data = s->abpr[cpu]; + break; case 0xd0: case 0xd4: case 0xd8: case 0xdc: - return s->apr[(offset - 0xd0) / 4][cpu]; + *data = s->apr[(offset - 0xd0) / 4][cpu]; + break; default: qemu_log_mask(LOG_GUEST_ERROR, "gic_cpu_read: Bad offset %x\n", (int)offset); - return 0; + return MEMTX_ERROR; } + return MEMTX_OK; } -static void gic_cpu_write(GICState *s, int cpu, int offset, uint32_t value) +static MemTxResult gic_cpu_write(GICState *s, int cpu, int offset, + uint32_t value, MemTxAttrs attrs) { switch (offset) { case 0x00: /* Control */ @@ -708,7 +741,7 @@ static void gic_cpu_write(GICState *s, int cpu, int offset, uint32_t value) break; case 0x10: /* End Of Interrupt */ gic_complete_irq(s, cpu, value & 0x3ff); - return; + return MEMTX_OK; case 0x1c: /* Aliased Binary Point */ if (s->revision >= 2) { s->abpr[cpu] = (value & 0x7); @@ -720,56 +753,59 @@ static void gic_cpu_write(GICState *s, int cpu, int offset, uint32_t value) default: qemu_log_mask(LOG_GUEST_ERROR, "gic_cpu_write: Bad offset %x\n", (int)offset); - return; + return MEMTX_ERROR; } gic_update(s); + return MEMTX_OK; } /* Wrappers to read/write the GIC CPU interface for the current CPU */ -static uint64_t gic_thiscpu_read(void *opaque, hwaddr addr, - unsigned size) +static MemTxResult gic_thiscpu_read(void *opaque, hwaddr addr, uint64_t *data, + unsigned size, MemTxAttrs attrs) { GICState *s = (GICState *)opaque; - return gic_cpu_read(s, gic_get_current_cpu(s), addr); + return gic_cpu_read(s, gic_get_current_cpu(s), addr, data, attrs); } -static void gic_thiscpu_write(void *opaque, hwaddr addr, - uint64_t value, unsigned size) +static MemTxResult gic_thiscpu_write(void *opaque, hwaddr addr, + uint64_t value, unsigned size, + MemTxAttrs attrs) { GICState *s = (GICState *)opaque; - gic_cpu_write(s, gic_get_current_cpu(s), addr, value); + return gic_cpu_write(s, gic_get_current_cpu(s), addr, value, attrs); } /* Wrappers to read/write the GIC CPU interface for a specific CPU. * These just decode the opaque pointer into GICState* + cpu id. */ -static uint64_t gic_do_cpu_read(void *opaque, hwaddr addr, - unsigned size) +static MemTxResult gic_do_cpu_read(void *opaque, hwaddr addr, uint64_t *data, + unsigned size, MemTxAttrs attrs) { GICState **backref = (GICState **)opaque; GICState *s = *backref; int id = (backref - s->backref); - return gic_cpu_read(s, id, addr); + return gic_cpu_read(s, id, addr, data, attrs); } -static void gic_do_cpu_write(void *opaque, hwaddr addr, - uint64_t value, unsigned size) +static MemTxResult gic_do_cpu_write(void *opaque, hwaddr addr, + uint64_t value, unsigned size, + MemTxAttrs attrs) { GICState **backref = (GICState **)opaque; GICState *s = *backref; int id = (backref - s->backref); - gic_cpu_write(s, id, addr, value); + return gic_cpu_write(s, id, addr, value, attrs); } static const MemoryRegionOps gic_thiscpu_ops = { - .read = gic_thiscpu_read, - .write = gic_thiscpu_write, + .read_with_attrs = gic_thiscpu_read, + .write_with_attrs = gic_thiscpu_write, .endianness = DEVICE_NATIVE_ENDIAN, }; static const MemoryRegionOps gic_cpu_ops = { - .read = gic_do_cpu_read, - .write = gic_do_cpu_write, + .read_with_attrs = gic_do_cpu_read, + .write_with_attrs = gic_do_cpu_write, .endianness = DEVICE_NATIVE_ENDIAN, };