From patchwork Fri Nov 24 08:59:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 169309 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp1014908vqx; Fri, 24 Nov 2023 00:59:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGAA8aARiqxcgkvby8xkFWJb3p7SYcg2c5AonMME+WiBPohZpY33SZL3oKHu/erBocSInOM X-Received: by 2002:a05:6358:7245:b0:16d:a0d3:d285 with SMTP id i5-20020a056358724500b0016da0d3d285mr2188909rwa.18.1700816387805; Fri, 24 Nov 2023 00:59:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700816387; cv=none; d=google.com; s=arc-20160816; b=ASChLrRq8DW+N3hUkRlXDxUWhZfTlfPcXMPXMOpHNtefq2+SMp5t1No+YmMT3282hO nco47WWhEXoepodjDwVUc82P4WyoYk0O5+Pze2mKtaKmnOEUUyhfGd4Ojhvgudqp+bvu c4EFfD7PrZqabwd53qqDk1+ykcJu8fLuzsK/zAN1PXy2otXasyKUdi50tFIPcGXUcE5i lBR4PbpteeUpdXwlyld3EfDgViYkfZmB95WxUQHUKtn2IhNzEBNSSsoyac+8LVeyQvtK 3cG/xd0iE9qJ7t1DtYQgAJfo1oHp3JT1K+RvSiqJb7KAnMzSuAYTDIUPnmzDPfjVDDrQ Os2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=dyctcWrppnGe4+vx0mLpgFIYntSlMv2IVY4OUgzhXWE=; fh=19HNS186+Jyl5jdtGewXWDZ4Mob/11uEP3KmOaN0fqs=; b=TjKs7O2fzaMO/DD3DKy7H0NT9BRO1bdUVWY41UZpmuqI2pkQkp8igIAzPw3yePVO9u QYaOWHEgcT4v7twzRzhIaD0vEuIbooCOg10T54qo0hcAZOfasgVWWxV2+c3S2qw/3ci8 zh214zPFzHkVLJ0d/tbIsNXwaRPyW9Guag801Xb9g62KHUxKy5L2sGPtwDfI+tPdTCu7 5R2meOMhkcWIzey16R1t8HXIIt5mHBg+4WRbcG5iyhiRW63tLx19rbofF2wmbNXERMP/ +68YJveaSTqa4WtkibER0arZPrzzNE3SNvj4LQui9mkWga6cvPaizPHmPiqKkwBbLxFE ATpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Tp5WzV1S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id c15-20020a631c4f000000b005be00724141si3097718pgm.533.2023.11.24.00.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 00:59:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Tp5WzV1S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id A25B88051623; Fri, 24 Nov 2023 00:59:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230332AbjKXI7e (ORCPT + 99 others); Fri, 24 Nov 2023 03:59:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229708AbjKXI7c (ORCPT ); Fri, 24 Nov 2023 03:59:32 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C85612B; Fri, 24 Nov 2023 00:59:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700816378; x=1732352378; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=ZbIvMTgzMhwgOv0/PFWGq6kgqpnExEfBqWPejMpOT00=; b=Tp5WzV1SdlIGppbWw04tkicHforjXZ4PrxLmHc2w1DD+gDQVJceJJaPW cGsnpPgN04EQcUN6CmlGwC0UZ9V8ooBgAY882lsrXeQItnad/dNPdfD1/ JWx50yyJflVvaKL9nrWl5O8stt6tSjcaEVQqxbRvLNyG/FLRTss6Soo3j EEwoC+3nLqA5MVDscOLfSdUfPlMQTr9kemN21TBqqlvNCYVymXt9GtVAS rP0wQK0W/hxzE1e25s/E23coMFyg3R/QejWU4cAa2T9IlnnDmURa5eoI2 Nlp+aZQbLv7073kKDAp3kors3XwBkRj7UDTyOsvcVAL8Voq/KWYkdD0d2 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="396299121" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="396299121" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Nov 2023 00:59:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="9083581" Received: from mvlasov-mobl1.ger.corp.intel.com (HELO localhost) ([10.251.220.89]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Nov 2023 00:59:34 -0800 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: Bjorn Helgaas , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v3 1/1] x86/PCI: Clean up open-coded return code mangling Date: Fri, 24 Nov 2023 10:59:24 +0200 Message-Id: <20231124085924.13830-1-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 24 Nov 2023 00:59:42 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783435244710651402 X-GMAIL-MSGID: 1783435244710651402 PCI BIOS returns a return code in 8 bits of eax register which is extracted by open-coded masks and shifting currently. Name the return code bits with a define and introduce pcibios_get_return_code() helper to extract the return code to improve code readability. In addition, replace zero test with PCIBIOS_SUCCESSFUL. No function changes intended. Signed-off-by: Ilpo Järvinen --- v3: - Add braces around the touched if block v2: - Improve changelog - Add helper to avoid repeating FIELD_GET() - Reuse existing ret variable in pcibios_get_irq_routing_table() arch/x86/pci/pcbios.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c index 4f15280732ed..244c643bb0b5 100644 --- a/arch/x86/pci/pcbios.c +++ b/arch/x86/pci/pcbios.c @@ -3,6 +3,8 @@ * BIOS32 and PCI BIOS handling. */ +#include +#include #include #include #include @@ -29,8 +31,19 @@ #define PCIBIOS_HW_TYPE1_SPEC 0x10 #define PCIBIOS_HW_TYPE2_SPEC 0x20 +/* + * Returned in EAX: + * - AH: return code + */ +#define PCIBIOS_RETURN_CODE GENMASK(15, 8) + int pcibios_enabled; +static u8 pcibios_get_return_code(u32 eax) +{ + return FIELD_GET(PCIBIOS_RETURN_CODE, eax); +} + /* According to the BIOS specification at: * http://members.datafast.net.au/dft0802/specs/bios21.pdf, we could * restrict the x zone to some pages and make it ro. But this may be @@ -154,7 +167,7 @@ static int __init check_pcibios(void) : "memory"); local_irq_restore(flags); - status = (eax >> 8) & 0xff; + status = pcibios_get_return_code(eax); hw_mech = eax & 0xff; major_ver = (ebx >> 8) & 0xff; minor_ver = ebx & 0xff; @@ -227,7 +240,7 @@ static int pci_bios_read(unsigned int seg, unsigned int bus, raw_spin_unlock_irqrestore(&pci_config_lock, flags); - return (int)((result & 0xff00) >> 8); + return pcibios_get_return_code(result); } static int pci_bios_write(unsigned int seg, unsigned int bus, @@ -269,7 +282,7 @@ static int pci_bios_write(unsigned int seg, unsigned int bus, raw_spin_unlock_irqrestore(&pci_config_lock, flags); - return (int)((result & 0xff00) >> 8); + return pcibios_get_return_code(result); } @@ -385,9 +398,10 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void) "m" (opt) : "memory"); DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map); - if (ret & 0xff00) - printk(KERN_ERR "PCI: Error %02x when fetching IRQ routing table.\n", (ret >> 8) & 0xff); - else if (opt.size) { + ret = pcibios_get_return_code(ret); + if (ret) { + printk(KERN_ERR "PCI: Error %02x when fetching IRQ routing table.\n", ret); + } else if (opt.size) { rt = kmalloc(sizeof(struct irq_routing_table) + opt.size, GFP_KERNEL); if (rt) { memset(rt, 0, sizeof(struct irq_routing_table)); @@ -415,7 +429,7 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq) "b" ((dev->bus->number << 8) | dev->devfn), "c" ((irq << 8) | (pin + 10)), "S" (&pci_indirect)); - return !(ret & 0xff00); + return pcibios_get_return_code(ret) == PCIBIOS_SUCCESSFUL; } EXPORT_SYMBOL(pcibios_set_irq_routing);