From patchwork Tue Sep 3 16:08:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 172842 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp75792ily; Tue, 3 Sep 2019 09:25:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqyN6hZvNwCVpXHFwcbqMIOTzB9ojHnu8GZjOrk3+bgqkHstiDqgiSLD4X7V6KXU1TOYUTX3 X-Received: by 2002:a37:4713:: with SMTP id u19mr15265315qka.270.1567527920324; Tue, 03 Sep 2019 09:25:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567527920; cv=none; d=google.com; s=arc-20160816; b=KAiTtQ5wp4ZzM92PhpW+LSmWVFrGB3qd18ovfyBdoz38v6jB252VC8L+54Ut1EdbC+ 1oKDnzodjjT1XntSH9XpuJLaRq4qLXS0I2GfpCTAuAq2WlclQMUWjDNNAaBw43r8de75 nxt4yFcXiTHhX53+UiKHRac28xk8RvBtUwb5UWg5wWoPHg5AJSCacFbMn/ohdzn71736 ro6ezRSezMVlPfDO/c3yqHUne83pwnADife9mIc4c4eyWEvJzlUqJONdwMpi5T+YiPte iyfkD6ndWvo2lt5iaADK5E+InqKmEmqUir0k9K5R8yOCsgUMnJrScydsrTwt8dzhvEaI Fk+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=6ErdebiJGL3Qh8ExlZC8PccbHjvi9peZ59d7ZiPKACI=; b=fPeMUXZi8XmV0gmYtgm3v+ZnYtzFcQPXlOC4z7mpMGJXLBzsSYE5HAxzkgqtrkkBnj 5Zk82GP4RwRtSK/iDwukLusnfmP6Cw0kWDrwbFMGkvTaydyLIVQckSY0x8tNW3OrDaPc zHFntmdfCBmCd/mBfGUtifrbgyVJ0VORdWZVOEagrIFJIb3vgMKLwiVy4eTWiYYUeWyL xKubHOk8GW3KPIJE0auba5OS54BkbUeR1/JCbo14rqnQmXXXnhUAIAnOvh2lRqvRqy5n oC+1cWqahlZnvFmmwDjdnZu9jm4lu0rObsV27h0tE6iAuDPawjklcU6DPU/z+sAvKuxC F3mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="E6H3/wWf"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z185si13083356qkd.67.2019.09.03.09.25.20 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Sep 2019 09:25:20 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="E6H3/wWf"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5BcN-0000Be-Al for patch@linaro.org; Tue, 03 Sep 2019 12:25:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37148) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5BMq-00013e-8b for qemu-devel@nongnu.org; Tue, 03 Sep 2019 12:09:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i5BMo-0003hj-QF for qemu-devel@nongnu.org; Tue, 03 Sep 2019 12:09:16 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:39885) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i5BMo-0003h3-JU for qemu-devel@nongnu.org; Tue, 03 Sep 2019 12:09:14 -0400 Received: by mail-pl1-x641.google.com with SMTP id bd8so1766848plb.6 for ; Tue, 03 Sep 2019 09:09:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6ErdebiJGL3Qh8ExlZC8PccbHjvi9peZ59d7ZiPKACI=; b=E6H3/wWffavhM3CUceTndJaF9g/LEOXq38ED8aoeNpadqTNo2U4yL0CTwLmddhDt+8 nKA6WrHNtVuLI0QPxKEeU8pjBqmP2q8063y4twn1krZ3yywhWB/5HV2KEaCXIClOpZZT cU4SczOTza5xX/YCjAZ8L/FfA37cAd/wz2EmzhTg/QTIAlDz6C/ryR5+H/SJRo4JOBmC xsj4dADVs0CmZkButR2kbzky0LzmDZ0AvQCpj4uf4pU6BRks0eWmnw1aToRQ1bvTo9KB wuJsazI4QJ2EaFhgoyTTtbriqCkIsRigbITeNXii5vijU7WL7zz0LSBaZB+n2Nhgbs0Q dD+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6ErdebiJGL3Qh8ExlZC8PccbHjvi9peZ59d7ZiPKACI=; b=LOAHgSz3HPaq4MED/+1o58SkFrwyb3GXDSnLgZ5tHfu/BaXmfjXbQmAWSIi4I5busm 7L2f8Qh9DNoTDOlZ+umu/qqEG0hQxiTUL0ahzdl5KBMMpZZD6Aiy7UbKybzrYmHGRKRr AiTZuxL5YJ2TwQ/sqtyCisI//8N+V7OkubEJzoNZuq7U1Z/U4CfL4T6z/xOVDy4yp3OL V2HAb8evIdXW5uNuHtdC6eTjco+dWyJZb0VdpBNTQKbcUsxGU1Vl8q4Jw+GMKLjtmGLW OTYdW2mC4iN1MR+up6dU3cPQNoir8mfjO5Jtj2vc5WbfAOsM1gAkc2W9UTHkpkhGawfH f70g== X-Gm-Message-State: APjAAAWhwORgLggto8sxVoerOb9BUBc9W6Zlg7/sUlMbYvUAi0WEPc8+ LYa0NRBN7BC3DYggAmKvSu/Vz+wAVQo= X-Received: by 2002:a17:902:bb85:: with SMTP id m5mr1865929pls.336.1567526953000; Tue, 03 Sep 2019 09:09:13 -0700 (PDT) Received: from localhost.localdomain (97-113-7-119.tukw.qwest.net. [97.113.7.119]) by smtp.gmail.com with ESMTPSA id 127sm28089711pfy.56.2019.09.03.09.09.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 09:09:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 3 Sep 2019 09:08:32 -0700 Message-Id: <20190903160858.5296-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190903160858.5296-1-richard.henderson@linaro.org> References: <20190903160858.5296-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::641 Subject: [Qemu-devel] [PATCH 10/36] memory: Access MemoryRegion with MemOp X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Tony Nguyen Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Tony Nguyen Convert memory_region_dispatch_{read|write} operand "unsigned size" into a "MemOp op". Signed-off-by: Tony Nguyen Reviewed-by: Richard Henderson Message-Id: <1dd82df5801866743f838f1d046475115a1d32da.1566466906.git.tony.nguyen@bt.com> Signed-off-by: Richard Henderson --- include/exec/memop.h | 22 +++++++++++++++------- include/exec/memory.h | 9 +++++---- memory.c | 7 +++++-- 3 files changed, 25 insertions(+), 13 deletions(-) -- 2.17.1 diff --git a/include/exec/memop.h b/include/exec/memop.h index dfd76a1604..0a610b75d9 100644 --- a/include/exec/memop.h +++ b/include/exec/memop.h @@ -12,6 +12,8 @@ #ifndef MEMOP_H #define MEMOP_H +#include "qemu/host-utils.h" + typedef enum MemOp { MO_8 = 0, MO_16 = 1, @@ -107,14 +109,20 @@ typedef enum MemOp { MO_SSIZE = MO_SIZE | MO_SIGN, } MemOp; -/* Size in bytes to MemOp. */ -static inline unsigned size_memop(unsigned size) +/* MemOp to size in bytes. */ +static inline unsigned memop_size(MemOp op) { - /* - * FIXME: No-op to aid conversion of memory_region_dispatch_{read|write} - * "unsigned size" operand into a "MemOp op". - */ - return size; + return 1 << (op & MO_SIZE); +} + +/* Size in bytes to MemOp. */ +static inline MemOp size_memop(unsigned size) +{ +#ifdef CONFIG_DEBUG_TCG + /* Power of 2 up to 8. */ + assert((size & (size - 1)) == 0 && size >= 1 && size <= 8); +#endif + return ctz32(size); } #endif diff --git a/include/exec/memory.h b/include/exec/memory.h index fddc2ff48a..192875b080 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -19,6 +19,7 @@ #include "exec/cpu-common.h" #include "exec/hwaddr.h" #include "exec/memattrs.h" +#include "exec/memop.h" #include "exec/ramlist.h" #include "qemu/bswap.h" #include "qemu/queue.h" @@ -1749,13 +1750,13 @@ void mtree_info(bool flatview, bool dispatch_tree, bool owner); * @mr: #MemoryRegion to access * @addr: address within that region * @pval: pointer to uint64_t which the data is written to - * @size: size of the access in bytes + * @op: size, sign, and endianness of the memory operation * @attrs: memory transaction attributes to use for the access */ MemTxResult memory_region_dispatch_read(MemoryRegion *mr, hwaddr addr, uint64_t *pval, - unsigned size, + MemOp op, MemTxAttrs attrs); /** * memory_region_dispatch_write: perform a write directly to the specified @@ -1764,13 +1765,13 @@ MemTxResult memory_region_dispatch_read(MemoryRegion *mr, * @mr: #MemoryRegion to access * @addr: address within that region * @data: data to write - * @size: size of the access in bytes + * @op: size, sign, and endianness of the memory operation * @attrs: memory transaction attributes to use for the access */ MemTxResult memory_region_dispatch_write(MemoryRegion *mr, hwaddr addr, uint64_t data, - unsigned size, + MemOp op, MemTxAttrs attrs); /** diff --git a/memory.c b/memory.c index 7fd93b1d42..3d87908784 100644 --- a/memory.c +++ b/memory.c @@ -1446,9 +1446,10 @@ static MemTxResult memory_region_dispatch_read1(MemoryRegion *mr, MemTxResult memory_region_dispatch_read(MemoryRegion *mr, hwaddr addr, uint64_t *pval, - unsigned size, + MemOp op, MemTxAttrs attrs) { + unsigned size = memop_size(op); MemTxResult r; if (!memory_region_access_valid(mr, addr, size, false, attrs)) { @@ -1490,9 +1491,11 @@ static bool memory_region_dispatch_write_eventfds(MemoryRegion *mr, MemTxResult memory_region_dispatch_write(MemoryRegion *mr, hwaddr addr, uint64_t data, - unsigned size, + MemOp op, MemTxAttrs attrs) { + unsigned size = memop_size(op); + if (!memory_region_access_valid(mr, addr, size, true, attrs)) { unassigned_mem_write(mr, addr, data, size); return MEMTX_DECODE_ERROR;