From nobody Tue Apr 8 04:52:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1567527960; cv=none; d=zoho.com; s=zohoarc; b=UfJgaKX/FWCT/eIfwJtD5UCRmPleIq8wt8ovMSTdg8KpDdAqwbgBlNbjVp9t1b7xNSYUqzWQb/GEJcSPVl+uZWFqa3SI6t4mVfbSUOuHPKa1G7KFvWhwWtBvkQHYEdtWHfq2RAluNfuYMKDRUZgeWJfxLjkxiDFEuWuO05TgTjo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567527960; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=6ErdebiJGL3Qh8ExlZC8PccbHjvi9peZ59d7ZiPKACI=; b=KvO6+o1PV9pPZq406cs3ug4IC7uDUu+5Uxkawk4RtfJyJvfrDGShkLNZRkcAJAcke5SJRb+K2GGebRwAwDEMQGN0UePwgiJIUV+HOteZ+dOqnrhH1V+p8mmHvlxPA8iQjK60Qy2J7+WbaiVjK9sRZKDnYq9e7hNhMK8SPyWdE0s= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1567527960599337.8761746776421; Tue, 3 Sep 2019 09:26:00 -0700 (PDT) Received: from localhost ([::1]:48836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5Bd1-00023O-57 for importer@patchew.org; Tue, 03 Sep 2019 12:25:59 -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) 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) 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-Google-Smtp-Source: APXvYqwE4V2q4xHhpQLSPiKJ/ZzRKpOFGEQtrvKV+d+uyLL3YuRBOwz5sYcYa4dYH5LDRgW5fVtjNw== X-Received: by 2002:a17:902:bb85:: with SMTP id m5mr1865929pls.336.1567526953000; Tue, 03 Sep 2019 09:09:13 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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.n= guyen@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(-) 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 =20 +#include "qemu/host-utils.h" + typedef enum MemOp { MO_8 =3D 0, MO_16 =3D 1, @@ -107,14 +109,20 @@ typedef enum MemOp { MO_SSIZE =3D MO_SIZE | MO_SIGN, } MemOp; =20 -/* 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|writ= e} - * "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)) =3D=3D 0 && size >=3D 1 && size <=3D 8); +#endif + return ctz32(size); } =20 #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(MemoryRegio= n *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); =20 /** 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(Memo= ryRegion *mr, MemTxResult memory_region_dispatch_read(MemoryRegion *mr, hwaddr addr, uint64_t *pval, - unsigned size, + MemOp op, MemTxAttrs attrs) { + unsigned size =3D memop_size(op); MemTxResult r; =20 if (!memory_region_access_valid(mr, addr, size, false, attrs)) { @@ -1490,9 +1491,11 @@ static bool memory_region_dispatch_write_eventfds(Me= moryRegion *mr, MemTxResult memory_region_dispatch_write(MemoryRegion *mr, hwaddr addr, uint64_t data, - unsigned size, + MemOp op, MemTxAttrs attrs) { + unsigned size =3D memop_size(op); + if (!memory_region_access_valid(mr, addr, size, true, attrs)) { unassigned_mem_write(mr, addr, data, size); return MEMTX_DECODE_ERROR; --=20 2.17.1