Skip to content

Commit fb6a040

Browse files
maciej-w-rozyckiKAGA-KOKO
authored andcommitted
x86: Add support for 0x22/0x23 port I/O configuration space
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 <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 36a21d5 commit fb6a040

File tree

5 files changed

+54
-10
lines changed

5 files changed

+54
-10
lines changed

arch/x86/include/asm/pc-conf-reg.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Support for the configuration register space at port I/O locations
4+
* 0x22 and 0x23 variously used by PC architectures, e.g. the MP Spec,
5+
* Cyrix CPUs, numerous chipsets.
6+
*/
7+
#ifndef _ASM_X86_PC_CONF_REG_H
8+
#define _ASM_X86_PC_CONF_REG_H
9+
10+
#include <linux/io.h>
11+
#include <linux/spinlock.h>
12+
#include <linux/types.h>
13+
14+
#define PC_CONF_INDEX 0x22
15+
#define PC_CONF_DATA 0x23
16+
17+
#define PC_CONF_MPS_IMCR 0x70
18+
19+
extern raw_spinlock_t pc_conf_lock;
20+
21+
static inline u8 pc_conf_get(u8 reg)
22+
{
23+
outb(reg, PC_CONF_INDEX);
24+
return inb(PC_CONF_DATA);
25+
}
26+
27+
static inline void pc_conf_set(u8 reg, u8 data)
28+
{
29+
outb(reg, PC_CONF_INDEX);
30+
outb(data, PC_CONF_DATA);
31+
}
32+
33+
#endif /* _ASM_X86_PC_CONF_REG_H */

arch/x86/include/asm/processor-cyrix.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
* Access order is always 0x22 (=offset), 0x23 (=value)
66
*/
77

8+
#include <asm/pc-conf-reg.h>
9+
810
static inline u8 getCx86(u8 reg)
911
{
10-
outb(reg, 0x22);
11-
return inb(0x23);
12+
return pc_conf_get(reg);
1213
}
1314

1415
static inline void setCx86(u8 reg, u8 data)
1516
{
16-
outb(reg, 0x22);
17-
outb(data, 0x23);
17+
pc_conf_set(reg, data);
1818
}

arch/x86/kernel/apic/apic.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
#include <asm/trace/irq_vectors.h>
4040
#include <asm/irq_remapping.h>
41+
#include <asm/pc-conf-reg.h>
4142
#include <asm/perf_event.h>
4243
#include <asm/x86_init.h>
4344
#include <linux/atomic.h>
@@ -132,18 +133,14 @@ static int enabled_via_apicbase __ro_after_init;
132133
*/
133134
static inline void imcr_pic_to_apic(void)
134135
{
135-
/* select IMCR register */
136-
outb(0x70, 0x22);
137136
/* NMI and 8259 INTR go through APIC */
138-
outb(0x01, 0x23);
137+
pc_conf_set(PC_CONF_MPS_IMCR, 0x01);
139138
}
140139

141140
static inline void imcr_apic_to_pic(void)
142141
{
143-
/* select IMCR register */
144-
outb(0x70, 0x22);
145142
/* NMI and 8259 INTR go directly to BSP */
146-
outb(0x00, 0x23);
143+
pc_conf_set(PC_CONF_MPS_IMCR, 0x00);
147144
}
148145
#endif
149146

arch/x86/lib/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ obj-$(CONFIG_SMP) += msr-smp.o cache-smp.o
4444
lib-y := delay.o misc.o cmdline.o cpu.o
4545
lib-y += usercopy_$(BITS).o usercopy.o getuser.o putuser.o
4646
lib-y += memcpy_$(BITS).o
47+
lib-y += pc-conf-reg.o
4748
lib-$(CONFIG_ARCH_HAS_COPY_MC) += copy_mc.o copy_mc_64.o
4849
lib-$(CONFIG_INSTRUCTION_DECODER) += insn.o inat.o insn-eval.o
4950
lib-$(CONFIG_RANDOMIZE_BASE) += kaslr.o

arch/x86/lib/pc-conf-reg.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Support for the configuration register space at port I/O locations
4+
* 0x22 and 0x23 variously used by PC architectures, e.g. the MP Spec,
5+
* Cyrix CPUs, numerous chipsets. As the space is indirectly addressed
6+
* it may have to be protected with a spinlock, depending on the context.
7+
*/
8+
9+
#include <linux/spinlock.h>
10+
11+
#include <asm/pc-conf-reg.h>
12+
13+
DEFINE_RAW_SPINLOCK(pc_conf_lock);

0 commit comments

Comments
 (0)