From patchwork Sat Dec 11 19:11:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 523071 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp4098874imb; Sat, 11 Dec 2021 11:18:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJxDuaiWmv+LtfJqImQBy96PEbiA0qhcVmMDiTz+X478D3hmQC6RMYf2Y5hPziadisQ2mgwo X-Received: by 2002:ad4:550f:: with SMTP id az15mr31775195qvb.100.1639250300951; Sat, 11 Dec 2021 11:18:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639250300; cv=none; d=google.com; s=arc-20160816; b=G6f+aWfDXQj4ci87Y6MXRC+qJHb371HClKRuiSiVcYJk6KMTSKiUa2mYuuXdWcvlqm l3RHhNVNTILAmm8ZDll5JaQuLQMSmR8UW6xVZEmUfSSrTA+gOzYaFP/cMvbI1n9YU3dY FXEAvXBZ8rfCX7oThd5HYdaowrjfpL5xRFBKmGOfHbJBcCuwIDUF1fC9O2WAoRNhZwBk i6Yv6IDjWV+UGOBpzpKG4G45eR4Jhr52GV2woKeVMfTXYG98WhJyVgvtrue12MNK7/3Q 0F0qe9EH4qY9sJBGXH94rWgcdsTKOST3XnbBe8dFZIU9AoVUIolV2WxiPGgdPnONdn8x pG+w== 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=UU9Ga+a5TMHIVvedbmFulE35BgOQRPa9LBAE1rDIpwU=; b=RZH5g56fXTonEEdiXcGbhCQ8j7rhvBnY+j/Jq43kiXGdqWdg4oar9OOfU7rMElUMFG +hyf1j/Z3VkyNRkI6WawuXmlmX0JCYxulxv0AOwZG/ZnbKtgasBac2Yf/hFfrvwsd2o0 GX5XR3SFrej87uGPzie2vzsqO0kcg1i9oRbYX+AQqqnrdhVSe5yYNPTPA46bS24zVEqi yxteb9Sb0Wgk9eGZShep2Z9P9tqt9A4ed7/uyCXCZVqcZ8LQxCwjkHiU/f9/FVlqGX7c DjsVS1ipuYZXSwC7+Mc2Hm59p7gQaZ/7XFfOk+rr2vWNv7CHCPu9qHetWOKgwxEDTifP naJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PMm1wvhe; 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 m4si7200110qtw.308.2021.12.11.11.18.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 11 Dec 2021 11:18:20 -0800 (PST) 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=PMm1wvhe; 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]:35130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mw7sy-0003ua-CF for patch@linaro.org; Sat, 11 Dec 2021 14:18:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47930) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mw7md-0004xe-Ff for qemu-devel@nongnu.org; Sat, 11 Dec 2021 14:11:47 -0500 Received: from [2a00:1450:4864:20::432] (port=46074 helo=mail-wr1-x432.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mw7ma-0006DE-VS for qemu-devel@nongnu.org; Sat, 11 Dec 2021 14:11:47 -0500 Received: by mail-wr1-x432.google.com with SMTP id o13so20287548wrs.12 for ; Sat, 11 Dec 2021 11:11:44 -0800 (PST) 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=UU9Ga+a5TMHIVvedbmFulE35BgOQRPa9LBAE1rDIpwU=; b=PMm1wvheXPbQuQuB8P9oX/1LQyZdKtL8ThYojAzGabUTtYTvsXO3mj2WRXD9kCkewW mf4wXwhVNdavEt9R7aqpwUjuWxk3P8yN7lF18arLj7PLBc1SeC48u0k3lSrNgxGBCrdM cIq7NdQXzuyHhnZwp/sp/1b+PjJOdKMGkFWeE6bLcBVq+Mc9wSSu3QrSbBz+XpDkftAz aJMkpBNmxVaLcXm7rjS4VqR/AE9J7TiBJTGopFsB8f/M09f+YgKWsNxXHkP5dWZLZGU1 tm5U4E0TlQ5EbmpXwlBHmonEildBYJcDXAv2nwlP+np/7hX4NPqWpkecGcHkjHhG4k4o nDBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UU9Ga+a5TMHIVvedbmFulE35BgOQRPa9LBAE1rDIpwU=; b=ROCutcC0/Iu5KBxYOjB0y62kEo3y3LiOElW9BDChZKPky7DrZc/Wf2ewnsBvozpD+L URQ43U7yxi46MM9P4Vq6aQoGd14mvv0nutxcp5ELRzunryiDzWcc8BZLdcqiPr4f/brZ jlhCF5ucDvxoR2CiqP/agTq6dl+RdQuw3OjQzQJ2HvEEb9czzPu0p1HDSMLp7q7FZkYc gIk62rZxac2ecpb01A2761utVBngWoDimAWR+L2l671YVvCdZw0RGRmlCeyT1EqE8vjH QwP7HY7zziZfpGFgeCrSEG0jPetXHAlQTUJ7HWTeFbTqr0L23d3k7SvxN52ztGSe1Wx5 UX/w== X-Gm-Message-State: AOAM531GoTyOzWHsJtl1V4eXjPz6fgz73Ahq8QHtf6SOKF6ig5L31A+p GCBIDNuKMj1pwUPIzazY11pKfw== X-Received: by 2002:adf:fb09:: with SMTP id c9mr21380833wrr.223.1639249903595; Sat, 11 Dec 2021 11:11:43 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id m20sm2205300wmq.11.2021.12.11.11.11.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Dec 2021 11:11:43 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 06/26] hw/intc/arm_gicv3_its: Reduce code duplication in extract_table_params() Date: Sat, 11 Dec 2021 19:11:15 +0000 Message-Id: <20211211191135.1764649-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211191135.1764649-1-peter.maydell@linaro.org> References: <20211211191135.1764649-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::432 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x432.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Shashi Mallela , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The extract_table_params() decodes the fields in the GITS_BASER registers into TableDesc structs. Since the fields are the same for all the GITS_BASER registers, there is currently a lot of code duplication within the switch (type) statement. Refactor so that the cases include only what is genuinely different for each type: the calculation of the number of bits in the ID value that indexes into the table. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée --- hw/intc/arm_gicv3_its.c | 97 +++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 57 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index c97b9982ae1..84808b1e298 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -758,6 +758,9 @@ static void extract_table_params(GICv3ITSState *s) uint64_t value; for (int i = 0; i < 8; i++) { + TableDesc *td; + int idbits; + value = s->baser[i]; if (!value) { @@ -789,73 +792,53 @@ static void extract_table_params(GICv3ITSState *s) type = FIELD_EX64(value, GITS_BASER, TYPE); switch (type) { - case GITS_BASER_TYPE_DEVICE: - memset(&s->dt, 0 , sizeof(s->dt)); - s->dt.valid = FIELD_EX64(value, GITS_BASER, VALID); - - if (!s->dt.valid) { - break; - } - - s->dt.page_sz = page_sz; - s->dt.indirect = FIELD_EX64(value, GITS_BASER, INDIRECT); - s->dt.entry_sz = FIELD_EX64(value, GITS_BASER, ENTRYSIZE); - - if (!s->dt.indirect) { - s->dt.max_entries = (num_pages * page_sz) / s->dt.entry_sz; - } else { - s->dt.max_entries = (((num_pages * page_sz) / - L1TABLE_ENTRY_SIZE) * - (page_sz / s->dt.entry_sz)); - } - - s->dt.max_ids = (1UL << (FIELD_EX64(s->typer, GITS_TYPER, - DEVBITS) + 1)); - - s->dt.base_addr = baser_base_addr(value, page_sz); - + td = &s->dt; + idbits = FIELD_EX64(s->typer, GITS_TYPER, DEVBITS) + 1; break; - case GITS_BASER_TYPE_COLLECTION: - memset(&s->ct, 0 , sizeof(s->ct)); - s->ct.valid = FIELD_EX64(value, GITS_BASER, VALID); - - /* - * GITS_TYPER.HCC is 0 for this implementation - * hence writes are discarded if ct.valid is 0 - */ - if (!s->ct.valid) { - break; - } - - s->ct.page_sz = page_sz; - s->ct.indirect = FIELD_EX64(value, GITS_BASER, INDIRECT); - s->ct.entry_sz = FIELD_EX64(value, GITS_BASER, ENTRYSIZE); - - if (!s->ct.indirect) { - s->ct.max_entries = (num_pages * page_sz) / s->ct.entry_sz; - } else { - s->ct.max_entries = (((num_pages * page_sz) / - L1TABLE_ENTRY_SIZE) * - (page_sz / s->ct.entry_sz)); - } - + td = &s->ct; if (FIELD_EX64(s->typer, GITS_TYPER, CIL)) { - s->ct.max_ids = (1UL << (FIELD_EX64(s->typer, - GITS_TYPER, CIDBITS) + 1)); + idbits = FIELD_EX64(s->typer, GITS_TYPER, CIDBITS) + 1; } else { /* 16-bit CollectionId supported when CIL == 0 */ - s->ct.max_ids = (1UL << 16); + idbits = 16; } - - s->ct.base_addr = baser_base_addr(value, page_sz); - break; - default: - break; + /* + * GITS_BASER.TYPE is read-only, so GITS_BASER_RO_MASK + * ensures we will only see type values corresponding to + * the values set up in gicv3_its_reset(). + */ + g_assert_not_reached(); } + + memset(td, 0, sizeof(*td)); + td->valid = FIELD_EX64(value, GITS_BASER, VALID); + /* + * If GITS_BASER.Valid is 0 for any then we will not process + * interrupts. (GITS_TYPER.HCC is 0 for this implementation, so we + * do not have a special case where the GITS_BASER.Valid bit is 0 + * for the register corresponding to the Collection table but we + * still have to process interrupts using non-memory-backed + * Collection table entries.) + */ + if (!td->valid) { + continue; + } + td->page_sz = page_sz; + td->indirect = FIELD_EX64(value, GITS_BASER, INDIRECT); + td->entry_sz = FIELD_EX64(value, GITS_BASER, ENTRYSIZE); + td->base_addr = baser_base_addr(value, page_sz); + if (!td->indirect) { + td->max_entries = (num_pages * page_sz) / td->entry_sz; + } else { + td->max_entries = (((num_pages * page_sz) / + L1TABLE_ENTRY_SIZE) * + (page_sz / td->entry_sz)); + } + td->max_ids = 1ULL << idbits; } }