From patchwork Mon Dec 14 15:57:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 11972399 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E817C4361B for ; Mon, 14 Dec 2020 16:00:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D98AB22573 for ; Mon, 14 Dec 2020 16:00:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D98AB22573 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vivier.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:43972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1koqGd-0001il-Sf for qemu-devel@archiver.kernel.org; Mon, 14 Dec 2020 11:00:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34174) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1koqEQ-0007rZ-S4; Mon, 14 Dec 2020 10:57:51 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:44741) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1koqEN-0001Pn-6A; Mon, 14 Dec 2020 10:57:50 -0500 Received: from localhost.localdomain ([82.252.135.218]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1Mwwm5-1juxO10CB1-00yQ8i; Mon, 14 Dec 2020 16:57:42 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 05/19] hw/pci-host/pam: Replace magic number by PAM_REGIONS_COUNT definition Date: Mon, 14 Dec 2020 16:57:19 +0100 Message-Id: <20201214155733.207430-6-laurent@vivier.eu> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201214155733.207430-1-laurent@vivier.eu> References: <20201214155733.207430-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:yWbPKBhYLElznlki5MBnP6phYaUHaTDcWosOaEOxpm9tcG7y6fP WfHvto8f73FKuTOfLWQ1JdQSrhDCZCZAZGge5GQhSCrc+9G1oM4KbYrmD/ct/ZlniR0NuXP 9LDRvXrNgrjsdUN/MQiz3gXj3GP09pCV5u2ZpwOSRIIR63AO8mgAIEItDzBwW2dkfa7Sf85 l/uaVvimA6ucAjhpFLwUg== X-UI-Out-Filterresults: notjunk:1;V03:K0:AjbuZIq1BZU=:YAc6ZOGyf90rBFin/8nn/C KeEI2nNL3Z7JrUypjodL8F9YevL2+oEd2nD7Q2B6/PsgZ1taYHPndwK2UHST0lxfwDBWHgTDS OxgHnBWtw3JStNCJWLV01jo0A5cg9almBMLmbB2h9pgytHzkVTgZttjJ194PLjEC7mi0enqyo zQmjkYDegYUthhcA4NuAcEMb4F/OI64M4/QmtbGmivivv7kWCA5sQlhrXBirpvTB0n9Yots3j 2BGLJ65HxnO71jm3Fx1dN6Q2EHZl8Bi6YFcMlRFQ/xHjlpwoH3TYfUTeEAXZc3fcuI3jxRDZn 5ETc/7u3MgYsITga7hyzJjqwRHcSZimnXIq4410vTNCveihB771WGRjiuH7qBYTtW6t3J5fYM AQmmSJwruVGt0VkP2os4O6XrNxwpuOBpDmbvuVuB/u67LPyctZ9Cnoz2CqMAfpxSLLVtelB6B yQ4iGEGKRQ== Received-SPF: none client-ip=212.227.17.24; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=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: qemu-trivial@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Michael Tokarev , Laurent Vivier , Julia Suvorova Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé While this change helps triskaidekaphobic developers, it is a good practice to avoid magic values and using constant definitions instead. Introduce the PAM_REGIONS_COUNT and use it. No logical change. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Julia Suvorova Message-Id: <20201202132038.1276404-1-philmd@redhat.com> Signed-off-by: Laurent Vivier --- hw/pci-host/pam.c | 2 +- hw/pci-host/q35.c | 2 +- include/hw/pci-host/i440fx.h | 2 +- include/hw/pci-host/pam.h | 2 ++ include/hw/pci-host/q35.h | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/hw/pci-host/pam.c b/hw/pci-host/pam.c index a4962057833f..454dd120db97 100644 --- a/hw/pci-host/pam.c +++ b/hw/pci-host/pam.c @@ -62,7 +62,7 @@ void init_pam(DeviceState *dev, MemoryRegion *ram_memory, void pam_update(PAMMemoryRegion *pam, int idx, uint8_t val) { - assert(0 <= idx && idx <= 12); + assert(0 <= idx && idx < PAM_REGIONS_COUNT); memory_region_set_enabled(&pam->alias[pam->current], false); pam->current = (val >> ((!(idx & 1)) * 4)) & PAM_ATTR_MASK; diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c index b67cb9c29f8e..2eb729dff585 100644 --- a/hw/pci-host/q35.c +++ b/hw/pci-host/q35.c @@ -641,7 +641,7 @@ static void mch_realize(PCIDevice *d, Error **errp) init_pam(DEVICE(mch), mch->ram_memory, mch->system_memory, mch->pci_address_space, &mch->pam_regions[0], PAM_BIOS_BASE, PAM_BIOS_SIZE); - for (i = 0; i < 12; ++i) { + for (i = 0; i < ARRAY_SIZE(mch->pam_regions) - 1; ++i) { init_pam(DEVICE(mch), mch->ram_memory, mch->system_memory, mch->pci_address_space, &mch->pam_regions[i+1], PAM_EXPAN_BASE + i * PAM_EXPAN_SIZE, PAM_EXPAN_SIZE); diff --git a/include/hw/pci-host/i440fx.h b/include/hw/pci-host/i440fx.h index 6c16eaf876dd..24fd53942cab 100644 --- a/include/hw/pci-host/i440fx.h +++ b/include/hw/pci-host/i440fx.h @@ -29,7 +29,7 @@ struct PCII440FXState { MemoryRegion *system_memory; MemoryRegion *pci_address_space; MemoryRegion *ram_memory; - PAMMemoryRegion pam_regions[13]; + PAMMemoryRegion pam_regions[PAM_REGIONS_COUNT]; MemoryRegion smram_region; MemoryRegion smram, low_smram; }; diff --git a/include/hw/pci-host/pam.h b/include/hw/pci-host/pam.h index fec5cd35d60f..c1fd06ba2ae6 100644 --- a/include/hw/pci-host/pam.h +++ b/include/hw/pci-host/pam.h @@ -80,6 +80,8 @@ #define SMRAM_C_BASE_SEG_MASK ((uint8_t)0x7) #define SMRAM_C_BASE_SEG ((uint8_t)0x2) /* hardwired to b010 */ +#define PAM_REGIONS_COUNT 13 + typedef struct PAMMemoryRegion { MemoryRegion alias[4]; /* index = PAM value */ unsigned current; diff --git a/include/hw/pci-host/q35.h b/include/hw/pci-host/q35.h index bbb958176565..ab989698ef8f 100644 --- a/include/hw/pci-host/q35.h +++ b/include/hw/pci-host/q35.h @@ -44,7 +44,7 @@ struct MCHPCIState { MemoryRegion *pci_address_space; MemoryRegion *system_memory; MemoryRegion *address_space_io; - PAMMemoryRegion pam_regions[13]; + PAMMemoryRegion pam_regions[PAM_REGIONS_COUNT]; MemoryRegion smram_region, open_high_smram; MemoryRegion smram, low_smram, high_smram; MemoryRegion tseg_blackhole, tseg_window;