Skip to content

Commit d004e4d

Browse files
committed
Merge branch 'x86-apic-cleanups-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'x86-apic-cleanups-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: x86: apic: Cleanup and simplify setup_local_APIC() x86: Further simplify mp_irq info handling x86: Unify 3 similar ways of saving mp_irqs info x86, ioapic: Avoid writing io_apic id if already correct x86, x2apic: Don't map lapic addr for preenabled x2apic systems x86, sfi: Use register_lapic_address() x86, apic: Use register_lapic_address() in init_apic_mapping() x86, apic: Remove early_init_lapic_mapping() x86, apic: Unify identical register_lapic_address() functions
2 parents 128283a + 1c2a48c commit d004e4d

File tree

9 files changed

+75
-228
lines changed

9 files changed

+75
-228
lines changed

arch/x86/include/asm/apic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ extern void init_bsp_APIC(void);
234234
extern void setup_local_APIC(void);
235235
extern void end_local_APIC_setup(void);
236236
extern void init_apic_mappings(void);
237+
void register_lapic_address(unsigned long address);
237238
extern void setup_boot_APIC_clock(void);
238239
extern void setup_secondary_APIC_clock(void);
239240
extern int APIC_init_uniprocessor(void);
@@ -244,7 +245,6 @@ extern int apic_force_enable(void);
244245
* On 32bit this is mach-xxx local
245246
*/
246247
#ifdef CONFIG_X86_64
247-
extern void early_init_lapic_mapping(void);
248248
extern int apic_is_clustered_box(void);
249249
#else
250250
static inline int apic_is_clustered_box(void)

arch/x86/include/asm/io_apic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ extern void mask_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entries);
169169
extern int restore_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entries);
170170

171171
extern int get_nr_irqs_gsi(void);
172+
172173
extern void setup_ioapic_ids_from_mpc(void);
173174
extern void setup_ioapic_ids_from_mpc_nocheck(void);
174175

@@ -183,6 +184,8 @@ int mp_find_ioapic_pin(int ioapic, u32 gsi);
183184
void __init mp_register_ioapic(int id, u32 address, u32 gsi_base);
184185
extern void __init pre_init_apic_IRQ0(void);
185186

187+
extern void mp_save_irq(struct mpc_intsrc *m);
188+
186189
#else /* !CONFIG_X86_IO_APIC */
187190

188191
#define io_apic_assign_pci_irqs 0

arch/x86/kernel/acpi/boot.c

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -852,18 +852,6 @@ static int __init acpi_parse_fadt(struct acpi_table_header *table)
852852
* returns 0 on success, < 0 on error
853853
*/
854854

855-
static void __init acpi_register_lapic_address(unsigned long address)
856-
{
857-
mp_lapic_addr = address;
858-
859-
set_fixmap_nocache(FIX_APIC_BASE, address);
860-
if (boot_cpu_physical_apicid == -1U) {
861-
boot_cpu_physical_apicid = read_apic_id();
862-
apic_version[boot_cpu_physical_apicid] =
863-
GET_APIC_VERSION(apic_read(APIC_LVR));
864-
}
865-
}
866-
867855
static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
868856
{
869857
int count;
@@ -885,7 +873,7 @@ static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
885873
return count;
886874
}
887875

888-
acpi_register_lapic_address(acpi_lapic_addr);
876+
register_lapic_address(acpi_lapic_addr);
889877

890878
return count;
891879
}
@@ -912,7 +900,7 @@ static int __init acpi_parse_madt_lapic_entries(void)
912900
return count;
913901
}
914902

915-
acpi_register_lapic_address(acpi_lapic_addr);
903+
register_lapic_address(acpi_lapic_addr);
916904

917905
count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
918906
acpi_parse_sapic, MAX_LOCAL_APIC);
@@ -954,32 +942,6 @@ static int __init acpi_parse_madt_lapic_entries(void)
954942
extern int es7000_plat;
955943
#endif
956944

957-
static void assign_to_mp_irq(struct mpc_intsrc *m,
958-
struct mpc_intsrc *mp_irq)
959-
{
960-
memcpy(mp_irq, m, sizeof(struct mpc_intsrc));
961-
}
962-
963-
static int mp_irq_cmp(struct mpc_intsrc *mp_irq,
964-
struct mpc_intsrc *m)
965-
{
966-
return memcmp(mp_irq, m, sizeof(struct mpc_intsrc));
967-
}
968-
969-
static void save_mp_irq(struct mpc_intsrc *m)
970-
{
971-
int i;
972-
973-
for (i = 0; i < mp_irq_entries; i++) {
974-
if (!mp_irq_cmp(&mp_irqs[i], m))
975-
return;
976-
}
977-
978-
assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
979-
if (++mp_irq_entries == MAX_IRQ_SOURCES)
980-
panic("Max # of irq sources exceeded!!\n");
981-
}
982-
983945
void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
984946
{
985947
int ioapic;
@@ -1010,7 +972,7 @@ void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
1010972
mp_irq.dstapic = mp_ioapics[ioapic].apicid; /* APIC ID */
1011973
mp_irq.dstirq = pin; /* INTIN# */
1012974

1013-
save_mp_irq(&mp_irq);
975+
mp_save_irq(&mp_irq);
1014976

1015977
isa_irq_to_gsi[bus_irq] = gsi;
1016978
}
@@ -1085,7 +1047,7 @@ void __init mp_config_acpi_legacy_irqs(void)
10851047
mp_irq.srcbusirq = i; /* Identity mapped */
10861048
mp_irq.dstirq = pin;
10871049

1088-
save_mp_irq(&mp_irq);
1050+
mp_save_irq(&mp_irq);
10891051
}
10901052
}
10911053

@@ -1122,7 +1084,7 @@ static int mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger,
11221084
mp_irq.dstapic = mp_ioapics[ioapic].apicid;
11231085
mp_irq.dstirq = mp_find_ioapic_pin(ioapic, gsi);
11241086

1125-
save_mp_irq(&mp_irq);
1087+
mp_save_irq(&mp_irq);
11261088
#endif
11271089
return 0;
11281090
}

arch/x86/kernel/apic/apic.c

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,12 +1191,15 @@ static void __cpuinit lapic_setup_esr(void)
11911191
oldvalue, value);
11921192
}
11931193

1194-
11951194
/**
11961195
* setup_local_APIC - setup the local APIC
1196+
*
1197+
* Used to setup local APIC while initializing BSP or bringin up APs.
1198+
* Always called with preemption disabled.
11971199
*/
11981200
void __cpuinit setup_local_APIC(void)
11991201
{
1202+
int cpu = smp_processor_id();
12001203
unsigned int value, queued;
12011204
int i, j, acked = 0;
12021205
unsigned long long tsc = 0, ntsc;
@@ -1221,8 +1224,6 @@ void __cpuinit setup_local_APIC(void)
12211224
#endif
12221225
perf_events_lapic_init();
12231226

1224-
preempt_disable();
1225-
12261227
/*
12271228
* Double-check whether this APIC is really registered.
12281229
* This is meaningless in clustered apic mode, so we skip it.
@@ -1338,33 +1339,29 @@ void __cpuinit setup_local_APIC(void)
13381339
* TODO: set up through-local-APIC from through-I/O-APIC? --macro
13391340
*/
13401341
value = apic_read(APIC_LVT0) & APIC_LVT_MASKED;
1341-
if (!smp_processor_id() && (pic_mode || !value)) {
1342+
if (!cpu && (pic_mode || !value)) {
13421343
value = APIC_DM_EXTINT;
1343-
apic_printk(APIC_VERBOSE, "enabled ExtINT on CPU#%d\n",
1344-
smp_processor_id());
1344+
apic_printk(APIC_VERBOSE, "enabled ExtINT on CPU#%d\n", cpu);
13451345
} else {
13461346
value = APIC_DM_EXTINT | APIC_LVT_MASKED;
1347-
apic_printk(APIC_VERBOSE, "masked ExtINT on CPU#%d\n",
1348-
smp_processor_id());
1347+
apic_printk(APIC_VERBOSE, "masked ExtINT on CPU#%d\n", cpu);
13491348
}
13501349
apic_write(APIC_LVT0, value);
13511350

13521351
/*
13531352
* only the BP should see the LINT1 NMI signal, obviously.
13541353
*/
1355-
if (!smp_processor_id())
1354+
if (!cpu)
13561355
value = APIC_DM_NMI;
13571356
else
13581357
value = APIC_DM_NMI | APIC_LVT_MASKED;
13591358
if (!lapic_is_integrated()) /* 82489DX */
13601359
value |= APIC_LVT_LEVEL_TRIGGER;
13611360
apic_write(APIC_LVT1, value);
13621361

1363-
preempt_enable();
1364-
13651362
#ifdef CONFIG_X86_MCE_INTEL
13661363
/* Recheck CMCI information after local APIC is up on CPU #0 */
1367-
if (smp_processor_id() == 0)
1364+
if (!cpu)
13681365
cmci_recheck();
13691366
#endif
13701367
}
@@ -1633,28 +1630,6 @@ static int __init detect_init_APIC(void)
16331630
}
16341631
#endif
16351632

1636-
#ifdef CONFIG_X86_64
1637-
void __init early_init_lapic_mapping(void)
1638-
{
1639-
/*
1640-
* If no local APIC can be found then go out
1641-
* : it means there is no mpatable and MADT
1642-
*/
1643-
if (!smp_found_config)
1644-
return;
1645-
1646-
set_fixmap_nocache(FIX_APIC_BASE, mp_lapic_addr);
1647-
apic_printk(APIC_VERBOSE, "mapped APIC to %16lx (%16lx)\n",
1648-
APIC_BASE, mp_lapic_addr);
1649-
1650-
/*
1651-
* Fetch the APIC ID of the BSP in case we have a
1652-
* default configuration (or the MP table is broken).
1653-
*/
1654-
boot_cpu_physical_apicid = read_apic_id();
1655-
}
1656-
#endif
1657-
16581633
/**
16591634
* init_apic_mappings - initialize APIC mappings
16601635
*/
@@ -1680,10 +1655,7 @@ void __init init_apic_mappings(void)
16801655
* acpi_register_lapic_address()
16811656
*/
16821657
if (!acpi_lapic && !smp_found_config)
1683-
set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
1684-
1685-
apic_printk(APIC_VERBOSE, "mapped APIC to %08lx (%08lx)\n",
1686-
APIC_BASE, apic_phys);
1658+
register_lapic_address(apic_phys);
16871659
}
16881660

16891661
/*
@@ -1705,6 +1677,22 @@ void __init init_apic_mappings(void)
17051677
}
17061678
}
17071679

1680+
void __init register_lapic_address(unsigned long address)
1681+
{
1682+
mp_lapic_addr = address;
1683+
1684+
if (!x2apic_mode) {
1685+
set_fixmap_nocache(FIX_APIC_BASE, address);
1686+
apic_printk(APIC_VERBOSE, "mapped APIC to %16lx (%16lx)\n",
1687+
APIC_BASE, mp_lapic_addr);
1688+
}
1689+
if (boot_cpu_physical_apicid == -1U) {
1690+
boot_cpu_physical_apicid = read_apic_id();
1691+
apic_version[boot_cpu_physical_apicid] =
1692+
GET_APIC_VERSION(apic_read(APIC_LVR));
1693+
}
1694+
}
1695+
17081696
/*
17091697
* This initializes the IO-APIC and APIC hardware if this is
17101698
* a UP kernel.

arch/x86/kernel/apic/io_apic.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,26 @@ static int __init parse_noapic(char *str)
125125
}
126126
early_param("noapic", parse_noapic);
127127

128+
/* Will be called in mpparse/acpi/sfi codes for saving IRQ info */
129+
void mp_save_irq(struct mpc_intsrc *m)
130+
{
131+
int i;
132+
133+
apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
134+
" IRQ %02x, APIC ID %x, APIC INT %02x\n",
135+
m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
136+
m->srcbusirq, m->dstapic, m->dstirq);
137+
138+
for (i = 0; i < mp_irq_entries; i++) {
139+
if (!memcmp(&mp_irqs[i], m, sizeof(*m)))
140+
return;
141+
}
142+
143+
memcpy(&mp_irqs[mp_irq_entries], m, sizeof(*m));
144+
if (++mp_irq_entries == MAX_IRQ_SOURCES)
145+
panic("Max # of irq sources exceeded!!\n");
146+
}
147+
128148
struct irq_pin_list {
129149
int apic, pin;
130150
struct irq_pin_list *next;
@@ -135,6 +155,7 @@ static struct irq_pin_list *alloc_irq_pin_list(int node)
135155
return kzalloc_node(sizeof(struct irq_pin_list), GFP_KERNEL, node);
136156
}
137157

158+
138159
/* irq_cfg is indexed by the sum of all RTEs in all I/O APICs. */
139160
#ifdef CONFIG_SPARSE_IRQ
140161
static struct irq_cfg irq_cfgx[NR_IRQS_LEGACY];
@@ -2006,9 +2027,12 @@ void __init setup_ioapic_ids_from_mpc_nocheck(void)
20062027
= mp_ioapics[apic_id].apicid;
20072028

20082029
/*
2009-
* Read the right value from the MPC table and
2010-
* write it into the ID register.
2030+
* Update the ID register according to the right value
2031+
* from the MPC table if they are different.
20112032
*/
2033+
if (mp_ioapics[apic_id].apicid == reg_00.bits.ID)
2034+
continue;
2035+
20122036
apic_printk(APIC_VERBOSE, KERN_INFO
20132037
"...changing IO-APIC physical APIC ID to %d ...",
20142038
mp_ioapics[apic_id].apicid);

0 commit comments

Comments
 (0)