From patchwork Mon Jul 3 11:07:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dou Liyang X-Patchwork-Id: 9822511 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 48BD160246 for ; Mon, 3 Jul 2017 11:10:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A0002817F for ; Mon, 3 Jul 2017 11:10:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DF7F283AD; Mon, 3 Jul 2017 11:10:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 94CF22817F for ; Mon, 3 Jul 2017 11:10:00 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dRzCp-0005ig-NR; Mon, 03 Jul 2017 11:07:51 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dRzCo-0005i3-Ke for xen-devel@lists.xenproject.org; Mon, 03 Jul 2017 11:07:50 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id 2E/6F-03937-6852A595; Mon, 03 Jul 2017 11:07:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrNIsWRWlGSWpSXmKPExsViPb2gRbdVNSr S4NUCZYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNePMk2dsBQ3CFV/myjYwfubvYuTkkBDwk2ha 0c7SxcjBISRQKzF5glUXIxeQuZJRYk//J3YI5xijxKEfN1hAGtgEdCTOND9gB7FFBMIl1q7tZ gMpYhZ4xijx6ecPRpCEsECERM+2vcwgNouAisTDQ6sYQTbwCsRLvF1RBbFYTmLblj1g5ZwCth KTWi6DzRcSsJG409oMFucVEJQ4OfMJWJxZQELi4IsXzBC9ShKv1x1ggbB1Jd79WsEEYWtKbFt 9jg3CNpM4svM/K4QtKLHz+QW2CYwis5CMnYVk7AJGplWMGsWpRWWpRbqGFnpJRZnpGSW5iZk5 uoYGZnq5qcXFiempOYlJxXrJ+bmbGIFBzgAEOxhvbgw4xCjJwaQkyut6MzJSiC8pP6UyI7E4I 76oNCe1+BCjDAeHkgRvhUpUpJBgUWp6akVaZg4w3mDSEhw8SiK8B+4BtfIWFyTmFmemQ6ROMR pzbFi9/gsTx6sJ/78xCbHk5eelSonzVoNMEgApzSjNgxsESwOXGGWlhHkZgU4T4ilILcrNLEG Vf8UozsGoJMybCTKFJzOvBG7fK6BTmIBOaeiJADmlJBEhJdXAKD/Vi6nNteB10v6vTQerpgbO +vxhtaSmVmjVfPb9oj0L2Rp/Xzq1P4jxuJrvQQGuv3eq/U7LnG1qe/TxxzLVF59OphYEbwoNK JTbu+NUb+uSFQwLxKJmbTdkuBMqO8dHSs86ac63pQ92nLz9a9YluX1sllve1+3cN/vE/fTn51 NiJynUpkqyXVJiKc5INNRiLipOBABK08cH/gIAAA== X-Env-Sender: douly.fnst@cn.fujitsu.com X-Msg-Ref: server-5.tower-27.messagelabs.com!1499080061!99818291!3 X-Originating-IP: [59.151.112.132] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 48813 invoked from network); 3 Jul 2017 11:07:48 -0000 Received: from cn.fujitsu.com (HELO heian.cn.fujitsu.com) (59.151.112.132) by server-5.tower-27.messagelabs.com with SMTP; 3 Jul 2017 11:07:48 -0000 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="20783654" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 03 Jul 2017 19:07:46 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id E1CDD47E98A6; Mon, 3 Jul 2017 19:07:39 +0800 (CST) Received: from localhost.localdomain.localdomain (10.167.226.106) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 3 Jul 2017 19:07:44 +0800 From: Dou Liyang To: , , Date: Mon, 3 Jul 2017 19:07:21 +0800 Message-ID: <5d830954bc59f16fd104c9251b3cf2def5217a44.1499074567.git.douly.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.167.226.106] X-yoursite-MailScanner-ID: E1CDD47E98A6.A5861 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: douly.fnst@cn.fujitsu.com Cc: Dou Liyang , bhe@redhat.com, peterz@infradead.org, mingo@kernel.org, ebiederm@xmission.com, hpa@zytor.com, izumi.taku@jp.fujitsu.com, boris.ostrovsky@oracle.com, tglx@linutronix.de Subject: [Xen-devel] [PATCH v6 01/12] x86/apic: Construct a selector for the interrupt delivery mode X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now, there are many switches in kernel which are used to determine the final interrupt delivery mode, as shown below: 1) kconfig: CONFIG_X86_64; CONFIG_X86_LOCAL_APIC; CONFIG_x86_IO_APIC 2) kernel option: disable_apic; skip_ioapic_setup 3) CPU Capability: boot_cpu_has(X86_FEATURE_APIC) 4) MP table: smp_found_config 5) ACPI: acpi_lapic; acpi_ioapic; nr_ioapic These switches are disordered and scattered and there are also some dependencies with each other. These make the code difficult to maintain and read. Construct a selector to unify them into a single function, then, Use this selector to get an interrupt delivery mode directly. Signed-off-by: Dou Liyang --- arch/x86/kernel/apic/apic.c | 59 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c index 2d75faf..ad5a853 100644 --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -1157,6 +1157,65 @@ void __init sync_Arb_IDs(void) APIC_INT_LEVELTRIG | APIC_DM_INIT); } +enum apic_intr_mode { + APIC_PIC, + APIC_VIRTUAL_WIRE, + APIC_SYMMETRIC_IO, +}; + +static int __init apic_intr_mode_select(void) +{ + /* Check kernel option */ + if (disable_apic) { + pr_info("APIC disabled via kernel command line\n"); + return APIC_PIC; + } + + /* Check BIOS */ +#ifdef CONFIG_X86_64 + /* On 64-bit, the APIC must be integrated, Check local APIC only */ + if (!boot_cpu_has(X86_FEATURE_APIC)) { + disable_apic = 1; + pr_info("APIC disabled by BIOS\n"); + return APIC_PIC; + } +#else + /* + * On 32-bit, check whether there is a separate chip or integrated + * APIC + */ + + /* Has a separate chip ? */ + if (!boot_cpu_has(X86_FEATURE_APIC) && !smp_found_config) { + disable_apic = 1; + + return APIC_PIC; + } + + /* Has a local APIC ? */ + if (!boot_cpu_has(X86_FEATURE_APIC) && + APIC_INTEGRATED(boot_cpu_apic_version)) { + disable_apic = 1; + pr_err(FW_BUG "Local APIC %d not detected, force emulation\n", + boot_cpu_physical_apicid); + + return APIC_PIC; + } +#endif + + /* Check MP table or ACPI MADT configuration */ + if (!smp_found_config) { + disable_ioapic_support(); + + if (!acpi_lapic) + pr_info("APIC: ACPI MADT or MP tables are not detected\n"); + + return APIC_VIRTUAL_WIRE; + } + + return APIC_SYMMETRIC_IO; +} + /* * An initial setup of the virtual wire mode. */