From patchwork Sat Jun 19 17:26:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 463876 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp1018660jao; Sat, 19 Jun 2021 10:29:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxl3pCARxyK/sM47vjjKmc/Y51FALz4mbgptUIog6VLwVvsD1sfd2fZtATqsWKMq++Gdkic X-Received: by 2002:a6b:7d05:: with SMTP id c5mr12793179ioq.148.1624123747418; Sat, 19 Jun 2021 10:29:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624123747; cv=none; d=google.com; s=arc-20160816; b=kALQf3GyT7X4pIT5ziagOGBU8NarJ+a0F9Fb8GWF7QiTiUXu/ODXHtwsKlB5fCQ4yh WKxt1YQN0JjYEZf5J6nvFj3H+BAHvNQ3RcYYLgUHtrXqeQCzMV9qhGhVp0azGyUWGcJC 0hk328Mw5O0Dzh/tx+orE7DJ9g+UTI2fQLZnoH0vVSXebY6tq/zFeGiZRB3bhR7HVCLa DO9TsXV0LDiKNm/4qnJ/bg295tgfdK/Xqz/GjlqewyTyibZyCyx9PjZjit+uRTTcGi+V tlJCwN/Uem29gZ22QTshXjbkJfiSneX0A96fZ1qGeZbEh3KDWsVVuOksrnrBAmVnzoNb sQhg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Yss0fdcq2xuDYayxCjybFaIy9QYHnfPZU6LWnmiOPAM=; b=HAkDKcSz7SEQwc711NtnyfgXkV5Nz2CNGUR4i6Qiy1NMtZU+7gfAVzhDbPouScSNU1 KYZ/VHKtZvZe8FyWdBRd/2WOi6aEWKQVteuEyqYso99M0r3f4V6e31TiRk/oxNvqE7ax R58FFmjQ7h+QUX5co+2/fHEoKt9SRJ1aL5WPX1Bwz8N4Law8NaWfaMxucQpWAGaWYWty DEGgI0tas9Y5sWmFjxuHGhyjFZOX+STofLhxFxHyDU9LFqTphoDK06sljO5HfpVMgCy7 Iy3pshy2IV1afCligm+FP0DfNHl43CwnHtAWynWaVq1QWcnik/AwgFnkQj9hP84hHgPx 9Z3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xG137mOb; 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 w4si14779434iov.14.2021.06.19.10.29.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 19 Jun 2021 10:29:07 -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=xG137mOb; 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]:41560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luemI-0000eg-OL for patch@linaro.org; Sat, 19 Jun 2021 13:29:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55386) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luejs-0003UA-2v for qemu-devel@nongnu.org; Sat, 19 Jun 2021 13:26:36 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:38606) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luejp-0003aJ-F1 for qemu-devel@nongnu.org; Sat, 19 Jun 2021 13:26:35 -0400 Received: by mail-pj1-x1031.google.com with SMTP id t19-20020a17090ae513b029016f66a73701so2663570pjy.3 for ; Sat, 19 Jun 2021 10:26:33 -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 :mime-version:content-transfer-encoding; bh=Yss0fdcq2xuDYayxCjybFaIy9QYHnfPZU6LWnmiOPAM=; b=xG137mObUWZEgmXMM9MtIBFF2Ugri3uCeIz8VcSm/zxeq7kDSejYp2OCzvIbAxrdDj ax4o7gmZqmEnef2P7svkeULztX/71iZ37iG7xnINDCI9o1Pqa5BUtKEmUqSYW4NYKFr9 gMVs9Yt6OYf0lypQLknltXs2T7snMP9364F3zo48DvKKFRkF3CRfEt/t0vXQyY8EvJLM xmmyz09YTJvr4mMYsOsqfuUC1zD1Ee+5redOYndtnt03+xy0Ulas0tPMp37gtIQDIzZ+ n9kuw50ARn1QNRL6/NP8DL54kARx0wE/uzKHr0TY0jUBw1Z769aoJdWkzNNUoKcoz+EA P80Q== 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:mime-version:content-transfer-encoding; bh=Yss0fdcq2xuDYayxCjybFaIy9QYHnfPZU6LWnmiOPAM=; b=BgcLSzNaAw560FTYGW7zGOkwj8q7pBd/ii+LmqkbKWsMwIeiVhBvAxz9+4CsxAcaam +aYso1bOQmZiIG8VHWu34ZUgpBdkTIbibq9TjBGqbiQePYxtINmc2k2lvspUVFpvvVKj tmevu/AqIu3xlCaBcD7tUqNKOBsD9IAajs1oYssgTJbYjMiDUq9ExQNNg+HZLte83PVy owuKtProgNNsfF9eTc01LvKAnc1b5/jsQfThjfQHhldVEsT+0RvhkPWg7U5wJEem7bQI YNhnG6JWuVDfZrbpy5aBazav6uiNpNXNFH+9DeaHE1AKzYBF86FImfPvpaguEdDJSljA KXow== X-Gm-Message-State: AOAM530f8eJmeURadQ7zd+Z8FohOzi0I4GqXZIZKNEvbdHkMDqdyj5bK ItKb73UXJE19JOTM/Vh/mNFLjJXjcXmc0w== X-Received: by 2002:a17:90b:1d02:: with SMTP id on2mr28573691pjb.128.1624123592286; Sat, 19 Jun 2021 10:26:32 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id co18sm2084241pjb.37.2021.06.19.10.26.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Jun 2021 10:26:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 07/15] softmmu/memory: Simplify access_with_adjusted_size interface Date: Sat, 19 Jun 2021 10:26:18 -0700 Message-Id: <20210619172626.875885-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210619172626.875885-1-richard.henderson@linaro.org> References: <20210619172626.875885-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: alex.bennee@linaro.org, pbonzini@redhat.com, mark.cave-ayland@ilande.co.uk, f4bug@amsat.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Create a typedef for the access_fn callback. Remove the access_size_{min,max} and access_fn arguments, and instead derive these from the MemoryRegion argument. Add a write boolean argument. Mark the function inline. Signed-off-by: Richard Henderson --- softmmu/memory.c | 67 +++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 41 deletions(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/softmmu/memory.c b/softmmu/memory.c index 744c5a80bd..7373d89600 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -509,22 +509,24 @@ static MemTxResult memory_region_write_with_attrs_accessor(MemoryRegion *mr, return mr->ops->write_with_attrs(mr->opaque, addr, tmp, size, attrs); } +typedef MemTxResult MemoryRegionAccessFn(MemoryRegion *mr, + hwaddr addr, + uint64_t *value, + unsigned size, + signed shift, + uint64_t mask, + MemTxAttrs attrs); + static MemTxResult access_with_adjusted_size(hwaddr addr, - uint64_t *value, - unsigned size, - unsigned access_size_min, - unsigned access_size_max, - MemTxResult (*access_fn) - (MemoryRegion *mr, - hwaddr addr, - uint64_t *value, - unsigned size, - signed shift, - uint64_t mask, - MemTxAttrs attrs), - MemoryRegion *mr, - MemTxAttrs attrs) + uint64_t *value, + unsigned size, + MemoryRegion *mr, + MemTxAttrs attrs, + bool write) { + unsigned access_size_min = mr->ops->impl.min_access_size; + unsigned access_size_max = mr->ops->impl.max_access_size; + MemoryRegionAccessFn *access_fn; uint64_t access_mask; unsigned access_size; unsigned i; @@ -537,6 +539,14 @@ static MemTxResult access_with_adjusted_size(hwaddr addr, access_size_max = 4; } + if (write) { + access_fn = (mr->ops->write ? memory_region_write_accessor + : memory_region_write_with_attrs_accessor); + } else { + access_fn = (mr->ops->read ? memory_region_read_accessor + : memory_region_read_with_attrs_accessor); + } + /* FIXME: support unaligned access? */ access_size = MAX(MIN(size, access_size_max), access_size_min); access_mask = MAKE_64BIT_MASK(0, access_size * 8); @@ -1423,19 +1433,7 @@ MemTxResult memory_region_dispatch_read(MemoryRegion *mr, } *pval = 0; - if (mr->ops->read) { - r = access_with_adjusted_size(addr, pval, size, - mr->ops->impl.min_access_size, - mr->ops->impl.max_access_size, - memory_region_read_accessor, - mr, attrs); - } else { - r = access_with_adjusted_size(addr, pval, size, - mr->ops->impl.min_access_size, - mr->ops->impl.max_access_size, - memory_region_read_with_attrs_accessor, - mr, attrs); - } + r = access_with_adjusted_size(addr, pval, size, mr, attrs, false); adjust_endianness(mr, pval, op); return r; } @@ -1486,20 +1484,7 @@ MemTxResult memory_region_dispatch_write(MemoryRegion *mr, return MEMTX_OK; } - if (mr->ops->write) { - return access_with_adjusted_size(addr, &data, size, - mr->ops->impl.min_access_size, - mr->ops->impl.max_access_size, - memory_region_write_accessor, mr, - attrs); - } else { - return - access_with_adjusted_size(addr, &data, size, - mr->ops->impl.min_access_size, - mr->ops->impl.max_access_size, - memory_region_write_with_attrs_accessor, - mr, attrs); - } + return access_with_adjusted_size(addr, &data, size, mr, attrs, true); } void memory_region_init_io(MemoryRegion *mr,