Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4208450pxv; Mon, 19 Jul 2021 20:31:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjltQ7sc07A9YSrrtyq8tpZ7fyOJ+OKEeR8WovQRUYAYB3xAYuSFAiW3M4MW+7Ur6kUCNk X-Received: by 2002:a6b:e417:: with SMTP id u23mr10180533iog.91.1626751864207; Mon, 19 Jul 2021 20:31:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626751864; cv=none; d=google.com; s=arc-20160816; b=ltRuAalQ95PeM2rd6PItxWHEItg8HHPu9KCTStSzTovlbOqS/8OTS5OFVs29TBwPiN XHeHga+CHrhqzUlS6WLRoUf67sclM6oWbq449wNCGOt7MwoB0qVMcUGhU6y6FW0eucVj USa6ULdOkkBHV7quISzyzHJgAq7HE+Iw61dcrZ7s2Wkq4vcPuf5rFS7LF5CqCUbqF91V voACTIQmm8GwClxhKiakQUvn5NPrZ03h8LGWUEkDuxb9ZNMi2lRgdU1UUBVJXpSCfjxU 4Wppay/OTTREogCC8/6HQbKvfjB+ArVTQF47oSxgW4TgovahPsugsJwuggyACB/entwo xIgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date; bh=+CbhVkeHm434aLdXbkqfaNJR+70qbFZa3lSfCLGGQK4=; b=W9E3sFS1bMWEgEEr1lTELqGWHWw88XT+i1tq8MJBRdj6sj7AX/mTJTsT9YbzavET9V Rjo/uxFPuj0U27czHEYy3mQ3jbuY0/SJDukk3/h0cZ0gJNPfDCWJgQGRGKOTa04sviL5 TfRXs3k13vXwAcoOpFsBsCojR8OSenHz+bR6ho5FP15AaH6G7y3F3p44Zv1qv5rfJI9H TTZ5xi6QCYESvkHf77QDfICLYvZXdD/e/46GnsulXc5z3Buqp7xlHA2GS/yGcLsfHgFa SdYof+XGUUpClPDVlexnJlt8Ho662V2tXMvBSZZAxQRYyUmsutkbeBdPccIjy0QWY8kM z1Xg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y11si22875659jat.64.2021.07.19.20.30.52; Mon, 19 Jul 2021 20:31:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346882AbhGTCtR (ORCPT + 99 others); Mon, 19 Jul 2021 22:49:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235999AbhGTCrO (ORCPT ); Mon, 19 Jul 2021 22:47:14 -0400 Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E01EBC061574; Mon, 19 Jul 2021 20:27:52 -0700 (PDT) Received: by angie.orcam.me.uk (Postfix, from userid 500) id 67F0892009D; Tue, 20 Jul 2021 05:27:49 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 609F192009B; Tue, 20 Jul 2021 05:27:49 +0200 (CEST) Date: Tue, 20 Jul 2021 05:27:49 +0200 (CEST) From: "Maciej W. Rozycki" To: Nikolai Zhubr , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Bjorn Helgaas , "Rafael J. Wysocki" , Len Brown , Pavel Machek , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel cc: x86@kernel.org, linux-pci@vger.kernel.org, linux-pm@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/6] x86: Add support for 0x22/0x23 port I/O configuration space In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Define macros and accessors for the configuration space addressed indirectly with an index register and a data register at the port I/O locations of 0x22 and 0x23 respectively. This space is defined by the Intel MultiProcessor Specification for the IMCR register used to switch between the PIC and the APIC mode[1], by Cyrix processors for their configuration[2][3], and also some chipsets. Given the lack of atomicity with the indirect addressing a spinlock is required to protect accesses, although for Cyrix processors it is enough if accesses are executed with interrupts locally disabled, because the registers are local to the accessing CPU, and IMCR is only ever poked at by the BSP and early enough for interrupts not to have been configured yet. Therefore existing code does not have to change or use the new spinlock and neither it does. Put the spinlock in a library file then, so that it does not get pulled unnecessarily for configurations that do not refer it. Convert Cyrix accessors to wrappers so as to retain the brevity and clarity of the `getCx86' and `setCx86' calls. References: [1] "MultiProcessor Specification", Version 1.4, Intel Corporation, Order Number: 242016-006, May 1997, Section 3.6.2.1 "PIC Mode", pp. 3-7, 3-8 [2] "5x86 Microprocessor", Cyrix Corporation, Order Number: 94192-00, July 1995, Section 2.3.2.4 "Configuration Registers", p. 2-23 [3] "6x86 Processor", Cyrix Corporation, Order Number: 94175-01, March 1996, Section 2.4.4 "6x86 Configuration Registers", p. 2-23 Signed-off-by: Maciej W. Rozycki --- Verified with `objdump' not to change arch/x86/kernel/apic/apic.o or arch/x86/kernel/cpu/cyrix.o code produced. --- arch/x86/include/asm/pc-conf-reg.h | 33 +++++++++++++++++++++++++++++++++ arch/x86/include/asm/processor-cyrix.h | 8 ++++---- arch/x86/kernel/apic/apic.c | 9 +++------ arch/x86/lib/Makefile | 1 + arch/x86/lib/pc-conf-reg.c | 13 +++++++++++++ 5 files changed, 54 insertions(+), 10 deletions(-) linux-x86-pc-conf-reg.diff Index: linux-macro-pirq/arch/x86/include/asm/pc-conf-reg.h =================================================================== --- /dev/null +++ linux-macro-pirq/arch/x86/include/asm/pc-conf-reg.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Support for the configuration register space at port I/O locations + * 0x22 and 0x23 variously used by PC architectures, e.g. the MP Spec, + * Cyrix CPUs, numerous chipsets. + */ +#ifndef _ASM_X86_PC_CONF_REG_H +#define _ASM_X86_PC_CONF_REG_H + +#include +#include +#include + +#define PC_CONF_INDEX 0x22 +#define PC_CONF_DATA 0x23 + +#define PC_CONF_MPS_IMCR 0x70 + +extern raw_spinlock_t pc_conf_lock; + +static inline u8 pc_conf_get(u8 reg) +{ + outb(reg, PC_CONF_INDEX); + return inb(PC_CONF_DATA); +} + +static inline void pc_conf_set(u8 reg, u8 data) +{ + outb(reg, PC_CONF_INDEX); + outb(data, PC_CONF_DATA); +} + +#endif /* _ASM_X86_PC_CONF_REG_H */ Index: linux-macro-pirq/arch/x86/include/asm/processor-cyrix.h =================================================================== --- linux-macro-pirq.orig/arch/x86/include/asm/processor-cyrix.h +++ linux-macro-pirq/arch/x86/include/asm/processor-cyrix.h @@ -5,14 +5,14 @@ * Access order is always 0x22 (=offset), 0x23 (=value) */ +#include + static inline u8 getCx86(u8 reg) { - outb(reg, 0x22); - return inb(0x23); + return pc_conf_get(reg); } static inline void setCx86(u8 reg, u8 data) { - outb(reg, 0x22); - outb(data, 0x23); + pc_conf_set(reg, data); } Index: linux-macro-pirq/arch/x86/kernel/apic/apic.c =================================================================== --- linux-macro-pirq.orig/arch/x86/kernel/apic/apic.c +++ linux-macro-pirq/arch/x86/kernel/apic/apic.c @@ -38,6 +38,7 @@ #include #include +#include #include #include #include @@ -132,18 +133,14 @@ static int enabled_via_apicbase __ro_aft */ static inline void imcr_pic_to_apic(void) { - /* select IMCR register */ - outb(0x70, 0x22); /* NMI and 8259 INTR go through APIC */ - outb(0x01, 0x23); + pc_conf_set(PC_CONF_MPS_IMCR, 0x01); } static inline void imcr_apic_to_pic(void) { - /* select IMCR register */ - outb(0x70, 0x22); /* NMI and 8259 INTR go directly to BSP */ - outb(0x00, 0x23); + pc_conf_set(PC_CONF_MPS_IMCR, 0x00); } #endif Index: linux-macro-pirq/arch/x86/lib/Makefile =================================================================== --- linux-macro-pirq.orig/arch/x86/lib/Makefile +++ linux-macro-pirq/arch/x86/lib/Makefile @@ -44,6 +44,7 @@ obj-$(CONFIG_SMP) += msr-smp.o cache-smp lib-y := delay.o misc.o cmdline.o cpu.o lib-y += usercopy_$(BITS).o usercopy.o getuser.o putuser.o lib-y += memcpy_$(BITS).o +lib-y += pc-conf-reg.o lib-$(CONFIG_ARCH_HAS_COPY_MC) += copy_mc.o copy_mc_64.o lib-$(CONFIG_INSTRUCTION_DECODER) += insn.o inat.o insn-eval.o lib-$(CONFIG_RANDOMIZE_BASE) += kaslr.o Index: linux-macro-pirq/arch/x86/lib/pc-conf-reg.c =================================================================== --- /dev/null +++ linux-macro-pirq/arch/x86/lib/pc-conf-reg.c @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Support for the configuration register space at port I/O locations + * 0x22 and 0x23 variously used by PC architectures, e.g. the MP Spec, + * Cyrix CPUs, numerous chipsets. As the space is indirectly addressed + * it may have to be protected with a spinlock, depending on the context. + */ + +#include + +#include + +DEFINE_RAW_SPINLOCK(pc_conf_lock);