Received: by 2002:a17:906:755:b0:a37:6271:4f3c with SMTP id z21csp1790859ejb; Tue, 6 Feb 2024 05:31:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IEghrLtHiBPdmnsZkqUytUsnSlA7w3UFlFLviMbNzwDWkX+k47xk9UC6RZFvCrHeLXnZowT X-Received: by 2002:a05:6102:2367:b0:46d:499e:ae07 with SMTP id o7-20020a056102236700b0046d499eae07mr422960vsa.25.1707226268175; Tue, 06 Feb 2024 05:31:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707226268; cv=none; d=google.com; s=arc-20160816; b=FfYMZLRxNx2wkjzqzmZezGgpvwjjhrf1nNFXPaeORjy6kkBMMamF4ZSR2YSuxwPsm+ AnqY6bDjUicjcywrdJZ9jn44LLVtnsx/Zt0UMisx3aG97MoRWTmcZRY6QkcYgxuF6dZ+ rnFTOXvEfVSDq2PgOF5t3BKHvxnBcPn1W/LjmAnk+a4tAKMfklTqc67jUwgmHoRvrmC8 yPvUDOw02r8+H6lNB4Dyq5SWfMtZHYTIIMEZ6Ro9OTo2CKOY0qQgVIqe/VwU/vWzn3AB ji7wwx9Ek50Q7vz8gJjuG1HYj92sH21Z8lnG0gqsv5YtwpdLBxTJYytxXCFk/TwZLPeG fJ1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=EMtxt4f4Pe35Y41NOxdIdqkHjaw4kvMUbL17jcA12tk=; fh=a0iYnljW0bmtMTH50l5SYdeFiG8dWbgPheDekA05B/o=; b=tlaie5TU+vViK415aqa+uO5YdDbYs/u4tc/+pDFXNbQMOwa2awhz4PneQlBhjIOeu1 BAcVeXDAaW8u1w10xbYpMGTtb1s0VwdYq/vTaqlgFejg9GpXlc6YvcMvhAagdM987/Gy dIYGLZoUhr6DcFYad419Ew1RZnwkcrms9FnPgO7gLZJqW4ys/0+44Bi/XLVVVVqtuBK/ c/TWkA82A99qROCD2q2rjfRVaGGLuZKku3GOy9xOYMhAAy2qNvWCmG+kyTdpCTL2Vc/b MQEkV3sL2h5+TsAgLYkwHRH/KwlsiQYaNe7lbswJGc7bARnZ/xNUnRD29DZ23AvAcc3n SG0A==; darn=linaro.org ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bT2+ZVlD; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org X-Forwarded-Encrypted: i=0; AJvYcCV7GkWWS+5mjoQEX7uM9sV0j/m81NhW1sU2DM+Gvsihsf4ZP1SDHuoBOqVnDedxU4n6wtNZ83ui9AwZfX8Ef6ni4dZ7vGc1 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j8-20020a056102000800b0046d28a86e9dsi255271vsp.627.2024.02.06.05.31.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Feb 2024 05:31:08 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bT2+ZVlD; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rXLWG-0000nF-0a; Tue, 06 Feb 2024 08:29:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rXLW9-0000RV-1k for qemu-arm@nongnu.org; Tue, 06 Feb 2024 08:29:41 -0500 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rXLW4-0008EH-NK for qemu-arm@nongnu.org; Tue, 06 Feb 2024 08:29:40 -0500 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40fe3244bc6so4749805e9.1 for ; Tue, 06 Feb 2024 05:29:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1707226175; x=1707830975; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=EMtxt4f4Pe35Y41NOxdIdqkHjaw4kvMUbL17jcA12tk=; b=bT2+ZVlD5CAsctR3I0n7HIvROAxYZaraclQpnKol+KczY2+5FGCUzrdVvhAkruBIah /vkhoGMqco5GyFEkA3d7ULz8bxQAb3VHtKSF2rhIJtb87uth9kgBw7h/BwP7iyo5qB2d HPjrOD9d5fAduzw06bGazrn2DtPfvP6WvRCx6FQoQwDhXL+lDigfJW1YMC+7TMvEDPKl n0611NNyDWQ64U4DLB+AcNXd75dYujVL1N75MKSEfLPnNOFzdxcbC6sSmLGXnpaG0UkL dC03o1Qt+uxGn+T5BqaPJLe7oQfKNyIdbLxOvAwvqozP8O8amDwVSWjhWQqV6QTP8sRP Nu0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707226175; x=1707830975; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EMtxt4f4Pe35Y41NOxdIdqkHjaw4kvMUbL17jcA12tk=; b=mfhOgcXWvsLGc2dWFY8iQ8DdTXHbK5Mfo8zMljwhEMuUCSTMVPwWS3U+P2RQ5B+jgf dA2ZZFJ9/Q7f3C/l9rGlfPwAQd38OTfY+PGUKRhMtoU+d1XCB4u6ZbYCOics2X4qoJlm rfeMDHNg37iN4Yde24o8fmzTrZpld1NsdjpmALroRhiu83A8Ar8A2cObzQbK7h/XKW8s uu9vwISzNyJkglOrV+iJGkpjqVj6e3COJOwvPabyMBsoILUah0JhbGHoT4dDy8/SdKAf CV9f/0iNwvWbyd6Xr8t1VNSZuCODMNepuHuSPUhlKp7sH8/YLrZrxbQEagrEsc3FHjOw IvzQ== X-Gm-Message-State: AOJu0YwU053+miPSGipzd532FKICXHV3QiHM2NsdALoyAWPSFufvViiV dKBs4qYbOQt+1hyI2ymFDrd1UJtT6IbwD8cKWYvqXr2UZ8SJ159H49fo3Pa2WkSJdSZ44HHWyq8 3 X-Received: by 2002:a05:600c:1c83:b0:40f:de06:fcee with SMTP id k3-20020a05600c1c8300b0040fde06fceemr1985249wms.7.1707226175333; Tue, 06 Feb 2024 05:29:35 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCULJhTN8UK1lKExvZU9CAgCvkM0dShiAaArMWSUIZtML0eKmpYmpaIZG8kG4YFcUyuWkyA1sE/zPv2tv349hAKAst+0Brs= Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id y7-20020a056000108700b0033b470a137esm1492932wrw.79.2024.02.06.05.29.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 05:29:35 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 06/13] hw/misc/mps2-scc: Factor out which-board conditionals Date: Tue, 6 Feb 2024 13:29:24 +0000 Message-Id: <20240206132931.38376-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240206132931.38376-1-peter.maydell@linaro.org> References: <20240206132931.38376-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x333.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: kY/JOOHXYRdn The MPS SCC device has a lot of different flavours for the various different MPS FPGA images, which look mostly similar but have differences in how particular registers are handled. Currently we deal with this with a lot of open-coded checks on scc_partno(), but as we add more board types this is getting a bit hard to read. Factor out the conditions into some functions which we can give more descriptive names to. Signed-off-by: Peter Maydell --- hw/misc/mps2-scc.c | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/hw/misc/mps2-scc.c b/hw/misc/mps2-scc.c index 6c1b1cd3795..02a80bacd71 100644 --- a/hw/misc/mps2-scc.c +++ b/hw/misc/mps2-scc.c @@ -59,6 +59,30 @@ static int scc_partno(MPS2SCC *s) return extract32(s->id, 4, 8); } +/* Is CFG_REG2 present? */ +static bool have_cfg2(MPS2SCC *s) +{ + return scc_partno(s) == 0x524 || scc_partno(s) == 0x547; +} + +/* Is CFG_REG3 present? */ +static bool have_cfg3(MPS2SCC *s) +{ + return scc_partno(s) != 0x524 && scc_partno(s) != 0x547; +} + +/* Is CFG_REG5 present? */ +static bool have_cfg5(MPS2SCC *s) +{ + return scc_partno(s) == 0x524 || scc_partno(s) == 0x547; +} + +/* Is CFG_REG6 present? */ +static bool have_cfg6(MPS2SCC *s) +{ + return scc_partno(s) == 0x524; +} + /* Handle a write via the SYS_CFG channel to the specified function/device. * Return false on error (reported to guest via SYS_CFGCTRL ERROR bit). */ @@ -111,15 +135,13 @@ static uint64_t mps2_scc_read(void *opaque, hwaddr offset, unsigned size) r = s->cfg1; break; case A_CFG2: - if (scc_partno(s) != 0x524 && scc_partno(s) != 0x547) { - /* CFG2 reserved on other boards */ + if (!have_cfg2(s)) { goto bad_offset; } r = s->cfg2; break; case A_CFG3: - if (scc_partno(s) == 0x524 || scc_partno(s) == 0x547) { - /* CFG3 reserved on AN524 */ + if (!have_cfg3(s)) { goto bad_offset; } /* These are user-settable DIP switches on the board. We don't @@ -131,15 +153,13 @@ static uint64_t mps2_scc_read(void *opaque, hwaddr offset, unsigned size) r = s->cfg4; break; case A_CFG5: - if (scc_partno(s) != 0x524 && scc_partno(s) != 0x547) { - /* CFG5 reserved on other boards */ + if (!have_cfg5(s)) { goto bad_offset; } r = s->cfg5; break; case A_CFG6: - if (scc_partno(s) != 0x524) { - /* CFG6 reserved on other boards */ + if (!have_cfg6(s)) { goto bad_offset; } r = s->cfg6; @@ -202,24 +222,21 @@ static void mps2_scc_write(void *opaque, hwaddr offset, uint64_t value, } break; case A_CFG2: - if (scc_partno(s) != 0x524 && scc_partno(s) != 0x547) { - /* CFG2 reserved on other boards */ + if (!have_cfg2(s)) { goto bad_offset; } /* AN524: QSPI Select signal */ s->cfg2 = value; break; case A_CFG5: - if (scc_partno(s) != 0x524 && scc_partno(s) != 0x547) { - /* CFG5 reserved on other boards */ + if (!have_cfg5(s)) { goto bad_offset; } /* AN524: ACLK frequency in Hz */ s->cfg5 = value; break; case A_CFG6: - if (scc_partno(s) != 0x524) { - /* CFG6 reserved on other boards */ + if (!have_cfg6(s)) { goto bad_offset; } /* AN524: Clock divider for BRAM */ -- 2.34.1