blob: f5242d3d6e281d3d9b1dc0f790a25ee728125e63 [file] [log] [blame]
Patrick Georgi11f00792020-03-04 15:10:45 +01001/* SPDX-License-Identifier: GPL-2.0-only */
Mike Loptien91597342014-06-12 10:22:27 -06002
Elyes Haouasae1ca822022-10-07 10:02:38 +02003#include <acpi/acpi.h>
Kyösti Mälkki06b20492021-06-07 23:00:00 +03004#include <arch/ioapic.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +00005#include <arch/smp/mpspec.h>
Elyes Haouasae1ca822022-10-07 10:02:38 +02006#include <console/console.h>
Kyösti Mälkkidea42e02021-05-31 20:26:16 +03007#include <cpu/cpu.h>
Eric Biedermanb78c1972004-10-14 20:54:17 +00008#include <cpu/x86/lapic.h>
Elyes Haouasae1ca822022-10-07 10:02:38 +02009#include <device/device.h>
10#include <device/path.h>
Felix Held3b5b66d2024-01-11 22:26:18 +010011#include <device/pci_def.h>
Elyes Haouasae1ca822022-10-07 10:02:38 +020012#include <device/pci_ids.h>
Kyösti Mälkkib78e4622022-12-15 22:12:29 +020013#include <identity.h>
Elyes Haouasae1ca822022-10-07 10:02:38 +020014#include <string.h>
Felix Held0d192892024-02-06 16:55:29 +010015#include <types.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000016
Uwe Hermann55dc2232010-10-25 15:32:07 +000017/* Initialize the specified "mc" struct with initial values. */
Kyösti Mälkkidea42e02021-05-31 20:26:16 +030018void mptable_init(struct mp_config_table *mc)
Uwe Hermann55dc2232010-10-25 15:32:07 +000019{
Uwe Hermannc36d5062010-12-16 19:51:38 +000020 int i;
Kyösti Mälkkidea42e02021-05-31 20:26:16 +030021 u32 lapic_addr = cpu_get_lapic_addr();
Uwe Hermann55dc2232010-10-25 15:32:07 +000022
23 memset(mc, 0, sizeof(*mc));
Uwe Hermannc36d5062010-12-16 19:51:38 +000024
Uwe Hermann55dc2232010-10-25 15:32:07 +000025 memcpy(mc->mpc_signature, MPC_SIGNATURE, 4);
Uwe Hermannc36d5062010-12-16 19:51:38 +000026
Uwe Hermann55dc2232010-10-25 15:32:07 +000027 mc->mpc_length = sizeof(*mc); /* Initially just the header size. */
28 mc->mpc_spec = 0x04; /* MultiProcessor specification 1.4 */
29 mc->mpc_checksum = 0; /* Not yet computed. */
Uwe Hermann55dc2232010-10-25 15:32:07 +000030 mc->mpc_oemptr = 0;
31 mc->mpc_oemsize = 0;
32 mc->mpc_entry_count = 0; /* No entries yet... */
33 mc->mpc_lapic = lapic_addr;
34 mc->mpe_length = 0;
35 mc->mpe_checksum = 0;
36 mc->reserved = 0;
Uwe Hermannc36d5062010-12-16 19:51:38 +000037
Kyösti Mälkkib78e4622022-12-15 22:12:29 +020038 strncpy(mc->mpc_oem, mainboard_vendor, 8);
39 strncpy(mc->mpc_productid, mainboard_part_number, 12);
Uwe Hermannc36d5062010-12-16 19:51:38 +000040
41 /*
42 * The oem/productid fields are exactly 8/12 bytes long. If the resp.
43 * entry is shorter, the remaining bytes are filled with spaces.
44 */
Kyösti Mälkkib78e4622022-12-15 22:12:29 +020045 for (i = MIN(strlen(mainboard_vendor), 8); i < 8; i++)
Uwe Hermannc36d5062010-12-16 19:51:38 +000046 mc->mpc_oem[i] = ' ';
Kyösti Mälkkib78e4622022-12-15 22:12:29 +020047 for (i = MIN(strlen(mainboard_part_number), 12); i < 12; i++)
Uwe Hermannc36d5062010-12-16 19:51:38 +000048 mc->mpc_productid[i] = ' ';
Uwe Hermann55dc2232010-10-25 15:32:07 +000049}
50
Patrick Georgib0a9c5c2011-10-07 23:01:55 +020051static unsigned char smp_compute_checksum(void *v, int len)
Eric Biederman8ca8d762003-04-22 19:02:15 +000052{
53 unsigned char *bytes;
54 unsigned char checksum;
55 int i;
56 bytes = v;
57 checksum = 0;
Lee Leahy9c7c6f72017-03-16 11:24:09 -070058 for (i = 0; i < len; i++)
Eric Biederman8ca8d762003-04-22 19:02:15 +000059 checksum -= bytes[i];
Eric Biederman8ca8d762003-04-22 19:02:15 +000060 return checksum;
61}
62
Lee Leahy6f80ccc2017-03-16 15:18:22 -070063static void *smp_write_floating_table_physaddr(uintptr_t addr,
64 uintptr_t mpf_physptr, unsigned int virtualwire)
Stefan Reinauer4f1cb232006-07-19 15:32:49 +000065{
Edward O'Callaghan0bb0aff2014-05-02 03:58:32 +100066 struct intel_mp_floating *mf;
67 void *v;
Stefan Reinauer14e22772010-04-27 06:56:47 +000068
Yinghai Luf327d9f2008-02-20 17:41:38 +000069 v = (void *)addr;
Edward O'Callaghan0bb0aff2014-05-02 03:58:32 +100070 mf = v;
71 mf->mpf_signature[0] = '_';
72 mf->mpf_signature[1] = 'M';
73 mf->mpf_signature[2] = 'P';
74 mf->mpf_signature[3] = '_';
75 mf->mpf_physptr = mpf_physptr;
76 mf->mpf_length = 1;
77 mf->mpf_specification = 4;
78 mf->mpf_checksum = 0;
79 mf->mpf_feature1 = 0;
Mike Loptiend0167d32014-06-11 14:20:48 -060080 mf->mpf_feature2 = virtualwire?MP_FEATURE_PIC:MP_FEATURE_VIRTUALWIRE;
Edward O'Callaghan0bb0aff2014-05-02 03:58:32 +100081 mf->mpf_feature3 = 0;
82 mf->mpf_feature4 = 0;
83 mf->mpf_feature5 = 0;
84 mf->mpf_checksum = smp_compute_checksum(mf, mf->mpf_length*16);
85 return v;
Stefan Reinauer4f1cb232006-07-19 15:32:49 +000086}
87
Patrick Georgic75c79b2011-10-07 22:41:07 +020088void *smp_write_floating_table(unsigned long addr, unsigned int virtualwire)
89{
90 /* 16 byte align the table address */
91 addr = (addr + 0xf) & (~0xf);
Lee Leahy6f80ccc2017-03-16 15:18:22 -070092 return smp_write_floating_table_physaddr(addr, addr
93 + SMP_FLOATING_TABLE_LEN, virtualwire);
Patrick Georgic75c79b2011-10-07 22:41:07 +020094}
95
Eric Biederman8ca8d762003-04-22 19:02:15 +000096void *smp_next_mpc_entry(struct mp_config_table *mc)
97{
98 void *v;
99 v = (void *)(((char *)mc) + mc->mpc_length);
Mike Loptienbd4553b2014-06-16 10:46:56 -0600100
Eric Biederman8ca8d762003-04-22 19:02:15 +0000101 return v;
102}
Mike Loptienbd4553b2014-06-16 10:46:56 -0600103static void smp_add_mpc_entry(struct mp_config_table *mc, u16 length)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000104{
105 mc->mpc_length += length;
106 mc->mpc_entry_count++;
107}
108
109void *smp_next_mpe_entry(struct mp_config_table *mc)
110{
111 void *v;
112 v = (void *)(((char *)mc) + mc->mpc_length + mc->mpe_length);
Mike Loptienbd4553b2014-06-16 10:46:56 -0600113
Eric Biederman8ca8d762003-04-22 19:02:15 +0000114 return v;
115}
116static void smp_add_mpe_entry(struct mp_config_table *mc, mpe_t mpe)
117{
118 mc->mpe_length += mpe->mpe_length;
119}
120
Mike Loptienbd4553b2014-06-16 10:46:56 -0600121/*
122 * Type 0: Processor Entries:
123 * Entry Type, LAPIC ID, LAPIC Version, CPU Flags EN/BP,
124 * CPU Signature (Stepping, Model, Family), Feature Flags
125 */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000126void smp_write_processor(struct mp_config_table *mc,
Mike Loptienbd4553b2014-06-16 10:46:56 -0600127 u8 apicid, u8 apicver, u8 cpuflag,
128 u32 cpufeature, u32 featureflag)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000129{
130 struct mpc_config_processor *mpc;
131 mpc = smp_next_mpc_entry(mc);
132 memset(mpc, '\0', sizeof(*mpc));
133 mpc->mpc_type = MP_PROCESSOR;
134 mpc->mpc_apicid = apicid;
135 mpc->mpc_apicver = apicver;
136 mpc->mpc_cpuflag = cpuflag;
137 mpc->mpc_cpufeature = cpufeature;
138 mpc->mpc_featureflag = featureflag;
139 smp_add_mpc_entry(mc, sizeof(*mpc));
140}
141
Mike Loptienbd4553b2014-06-16 10:46:56 -0600142/*
143 * If we assume a symmetric processor configuration we can
Eric Biederman8ca8d762003-04-22 19:02:15 +0000144 * get all of the information we need to write the processor
145 * entry from the bootstrap processor.
146 * Plus I don't think linux really even cares.
147 * Having the proper apicid's in the table so the non-bootstrap
148 * processors can be woken up should be enough.
149 */
Eric Biedermanb78c1972004-10-14 20:54:17 +0000150void smp_write_processors(struct mp_config_table *mc)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000151{
Eric Biedermanb78c1972004-10-14 20:54:17 +0000152 int boot_apic_id;
Patrick Georgi07b42152011-10-14 23:02:57 +0200153 int order_id;
Lee Leahye5f29e82017-03-16 14:16:56 -0700154 unsigned int apic_version;
155 unsigned int cpu_features;
156 unsigned int cpu_feature_flags;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100157 struct device *cpu;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000158
Eric Biedermanb78c1972004-10-14 20:54:17 +0000159 boot_apic_id = lapicid();
160 apic_version = lapic_read(LAPIC_LVR) & 0xff;
Subrata Banik53b08c32018-12-10 14:11:35 +0530161 cpu_features = cpu_get_cpuid();
162 cpu_feature_flags = cpu_get_feature_flags_edx();
Patrick Georgi07b42152011-10-14 23:02:57 +0200163 /* order the output of the cpus to fix a bug in kernel 2.6.11 */
Lee Leahy024b13d2017-03-16 13:41:11 -0700164 for (order_id = 0; order_id < 256; order_id++) {
Elyes HAOUASdbf30672016-08-21 17:37:15 +0200165 for (cpu = all_devices; cpu; cpu = cpu->next) {
Edward O'Callaghan0bb0aff2014-05-02 03:58:32 +1000166 unsigned long cpu_flag;
Fabio Aiuto45aae7f2022-09-23 16:51:34 +0200167 if (!is_enabled_cpu(cpu))
Edward O'Callaghan0bb0aff2014-05-02 03:58:32 +1000168 continue;
169
170 cpu_flag = MPC_CPU_ENABLED;
171
172 if (boot_apic_id == cpu->path.apic.apic_id)
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700173 cpu_flag = MPC_CPU_ENABLED
174 | MPC_CPU_BOOTPROCESSOR;
Edward O'Callaghan0bb0aff2014-05-02 03:58:32 +1000175
Elyes HAOUASdbf30672016-08-21 17:37:15 +0200176 if (cpu->path.apic.apic_id == order_id) {
Mike Loptienbd4553b2014-06-16 10:46:56 -0600177 smp_write_processor(mc,
178 cpu->path.apic.apic_id, apic_version,
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700179 cpu_flag, cpu_features,
180 cpu_feature_flags
Edward O'Callaghan0bb0aff2014-05-02 03:58:32 +1000181 );
182 break;
183 }
Eric Biederman8ca8d762003-04-22 19:02:15 +0000184 }
Eric Biederman8ca8d762003-04-22 19:02:15 +0000185 }
186}
187
Mike Loptienbd4553b2014-06-16 10:46:56 -0600188/*
189 * Type 1: Bus Entries:
190 * Entry Type, Bus ID, Bus Type
191 */
Patrick Georgi patrick612fcc32010-11-23 07:19:54 +0000192static void smp_write_bus(struct mp_config_table *mc,
Mike Loptienbd4553b2014-06-16 10:46:56 -0600193 u8 id, const char *bustype)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000194{
195 struct mpc_config_bus *mpc;
196 mpc = smp_next_mpc_entry(mc);
197 memset(mpc, '\0', sizeof(*mpc));
198 mpc->mpc_type = MP_BUS;
199 mpc->mpc_busid = id;
200 memcpy(mpc->mpc_bustype, bustype, sizeof(mpc->mpc_bustype));
201 smp_add_mpc_entry(mc, sizeof(*mpc));
202}
203
Mike Loptienbd4553b2014-06-16 10:46:56 -0600204/*
205 * Type 2: I/O APIC Entries:
206 * Entry Type, APIC ID, Version,
207 * APIC Flags:EN, Address
208 */
Felix Held9c25a032024-02-06 16:43:10 +0100209static void smp_write_ioapic(struct mp_config_table *mc,
Felix Held0d192892024-02-06 16:55:29 +0100210 u8 id, u8 ver, uintptr_t apicaddr)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000211{
212 struct mpc_config_ioapic *mpc;
213 mpc = smp_next_mpc_entry(mc);
214 memset(mpc, '\0', sizeof(*mpc));
215 mpc->mpc_type = MP_IOAPIC;
216 mpc->mpc_apicid = id;
217 mpc->mpc_apicver = ver;
218 mpc->mpc_flags = MPC_APIC_USABLE;
Felix Held0d192892024-02-06 16:55:29 +0100219 mpc->mpc_apicaddr = (void *)apicaddr;
Eric Biederman8ca8d762003-04-22 19:02:15 +0000220 smp_add_mpc_entry(mc, sizeof(*mpc));
221}
222
Felix Held0d192892024-02-06 16:55:29 +0100223u8 smp_write_ioapic_from_hw(struct mp_config_table *mc, uintptr_t apicaddr)
Kyösti Mälkki06b20492021-06-07 23:00:00 +0300224{
225 u8 id = get_ioapic_id(apicaddr);
226 u8 ver = get_ioapic_version(apicaddr);
227 smp_write_ioapic(mc, id, ver, apicaddr);
228 return id;
229}
230
Mike Loptienbd4553b2014-06-16 10:46:56 -0600231/*
232 * Type 3: I/O Interrupt Table Entries:
233 * Entry Type, Int Type, Int Polarity, Int Level,
234 * Source Bus ID, Source Bus IRQ, Dest APIC ID, Dest PIN#
235 */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000236void smp_write_intsrc(struct mp_config_table *mc,
Mike Loptienbd4553b2014-06-16 10:46:56 -0600237 u8 irqtype, u16 irqflag,
238 u8 srcbus, u8 srcbusirq,
239 u8 dstapic, u8 dstirq)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000240{
241 struct mpc_config_intsrc *mpc;
242 mpc = smp_next_mpc_entry(mc);
243 memset(mpc, '\0', sizeof(*mpc));
244 mpc->mpc_type = MP_INTSRC;
245 mpc->mpc_irqtype = irqtype;
246 mpc->mpc_irqflag = irqflag;
247 mpc->mpc_srcbus = srcbus;
248 mpc->mpc_srcbusirq = srcbusirq;
249 mpc->mpc_dstapic = dstapic;
250 mpc->mpc_dstirq = dstirq;
251 smp_add_mpc_entry(mc, sizeof(*mpc));
Eric Biederman8ca8d762003-04-22 19:02:15 +0000252}
253
Mike Loptienbd4553b2014-06-16 10:46:56 -0600254/*
255 * Type 3: I/O Interrupt Table Entries for PCI Devices:
256 * This has the same fields as 'Type 3: I/O Interrupt Table Entries'
257 * but the Source Bus IRQ field has a slightly different
258 * definition:
259 * Bits 1-0: PIRQ pin: INT_A# = 0, INT_B# = 1, INT_C# = 2, INT_D# = 3
260 * Bits 2-6: Originating PCI Device Number (Not its parent bridge device number)
261 * Bit 7: Reserved
262 */
263void smp_write_pci_intsrc(struct mp_config_table *mc,
264 u8 irqtype, u8 srcbus, u8 dev, u8 pirq,
265 u8 dstapic, u8 dstirq)
266{
267 u8 srcbusirq = (dev << 2) | pirq;
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700268 printk(BIOS_SPEW,
269 "\tPCI srcbusirq = 0x%x from dev = 0x%x and pirq = %x\n",
270 srcbusirq, dev, pirq);
271 smp_write_intsrc(mc, irqtype, MP_IRQ_TRIGGER_LEVEL
272 | MP_IRQ_POLARITY_LOW, srcbus, srcbusirq, dstapic, dstirq);
Mike Loptienbd4553b2014-06-16 10:46:56 -0600273}
274
Yinghai Luf327d9f2008-02-20 17:41:38 +0000275void smp_write_intsrc_pci_bridge(struct mp_config_table *mc,
Mike Loptienbd4553b2014-06-16 10:46:56 -0600276 u8 irqtype, u16 irqflag, struct device *dev,
Yinghai Luf327d9f2008-02-20 17:41:38 +0000277 unsigned char dstapic, unsigned char *dstirq)
278{
279 struct device *child;
280
Yinghai Luf327d9f2008-02-20 17:41:38 +0000281 int i;
282 int srcbus;
283 int slot;
284
Yinghai Luf327d9f2008-02-20 17:41:38 +0000285 unsigned char dstirq_x[4];
286
Arthur Heymans7fcd4d52023-08-24 15:12:19 +0200287 if (!dev->downstream)
Arthur Heymans80c79a52023-08-24 15:12:19 +0200288 return;
Yinghai Luf327d9f2008-02-20 17:41:38 +0000289
Arthur Heymans7fcd4d52023-08-24 15:12:19 +0200290 child = dev->downstream->children;
291 srcbus = dev->downstream->secondary;
Yinghai Luf327d9f2008-02-20 17:41:38 +0000292
Arthur Heymans80c79a52023-08-24 15:12:19 +0200293 while (child) {
294 if (child->path.type != DEVICE_PATH_PCI)
295 goto next;
Yinghai Luf327d9f2008-02-20 17:41:38 +0000296
Arthur Heymans80c79a52023-08-24 15:12:19 +0200297 slot = (child->path.pci.devfn >> 3);
298 /* round pins */
299 for (i = 0; i < 4; i++)
300 dstirq_x[i] = dstirq[(i + slot) % 4];
301
302 if ((child->class >> 16) != PCI_BASE_CLASS_BRIDGE) {
303 /* pci device */
304 printk(BIOS_DEBUG, "route irq: %s\n",
305 dev_path(child));
Yinghai Luf327d9f2008-02-20 17:41:38 +0000306 for (i = 0; i < 4; i++)
Arthur Heymans80c79a52023-08-24 15:12:19 +0200307 smp_write_intsrc(mc, irqtype, irqflag,
308 srcbus, (slot<<2)|i, dstapic,
309 dstirq_x[i]);
310 goto next;
Yinghai Luf327d9f2008-02-20 17:41:38 +0000311 }
312
Arthur Heymans80c79a52023-08-24 15:12:19 +0200313 switch (child->class>>8) {
314 case PCI_CLASS_BRIDGE_PCI:
315 case PCI_CLASS_BRIDGE_PCMCIA:
316 case PCI_CLASS_BRIDGE_CARDBUS:
317 printk(BIOS_DEBUG, "route irq bridge: %s\n",
318 dev_path(child));
319 smp_write_intsrc_pci_bridge(mc, irqtype,
320 irqflag, child, dstapic, dstirq_x);
321 }
322
323next:
324 child = child->sibling;
Yinghai Luf327d9f2008-02-20 17:41:38 +0000325 }
326}
Eric Biederman8ca8d762003-04-22 19:02:15 +0000327
Mike Loptienbd4553b2014-06-16 10:46:56 -0600328/*
329 * Type 4: Local Interrupt Assignment Entries:
330 * Entry Type, Int Type, Int Polarity, Int Level,
331 * Source Bus ID, Source Bus IRQ, Dest LAPIC ID,
332 * Dest LAPIC LINTIN#
333 */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000334void smp_write_lintsrc(struct mp_config_table *mc,
Mike Loptienbd4553b2014-06-16 10:46:56 -0600335 u8 irqtype, u16 irqflag,
336 u8 srcbusid, u8 srcbusirq,
337 u8 destapic, u8 destapiclint)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000338{
339 struct mpc_config_lintsrc *mpc;
340 mpc = smp_next_mpc_entry(mc);
341 memset(mpc, '\0', sizeof(*mpc));
342 mpc->mpc_type = MP_LINTSRC;
343 mpc->mpc_irqtype = irqtype;
344 mpc->mpc_irqflag = irqflag;
345 mpc->mpc_srcbusid = srcbusid;
346 mpc->mpc_srcbusirq = srcbusirq;
347 mpc->mpc_destapic = destapic;
348 mpc->mpc_destapiclint = destapiclint;
349 smp_add_mpc_entry(mc, sizeof(*mpc));
350}
351
Mike Loptienbd4553b2014-06-16 10:46:56 -0600352/*
353 * Type 128: System Address Space Mapping Entries
354 * Entry Type, Entry Length, Bus ID, Address Type,
355 * Address Base Lo/Hi, Address Length Lo/Hi
356 */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000357void smp_write_address_space(struct mp_config_table *mc,
Mike Loptienbd4553b2014-06-16 10:46:56 -0600358 u8 busid, u8 address_type,
359 u32 address_base_low, u32 address_base_high,
360 u32 address_length_low, u32 address_length_high)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000361{
362 struct mp_exten_system_address_space *mpe;
363 mpe = smp_next_mpe_entry(mc);
364 memset(mpe, '\0', sizeof(*mpe));
365 mpe->mpe_type = MPE_SYSTEM_ADDRESS_SPACE;
366 mpe->mpe_length = sizeof(*mpe);
367 mpe->mpe_busid = busid;
368 mpe->mpe_address_type = address_type;
369 mpe->mpe_address_base_low = address_base_low;
370 mpe->mpe_address_base_high = address_base_high;
371 mpe->mpe_address_length_low = address_length_low;
372 mpe->mpe_address_length_high = address_length_high;
373 smp_add_mpe_entry(mc, (mpe_t)mpe);
374}
375
Mike Loptienbd4553b2014-06-16 10:46:56 -0600376/*
377 * Type 129: Bus Hierarchy Descriptor Entry
378 * Entry Type, Entry Length, Bus ID, Bus Info,
379 * Parent Bus ID
380 */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000381void smp_write_bus_hierarchy(struct mp_config_table *mc,
Mike Loptienbd4553b2014-06-16 10:46:56 -0600382 u8 busid, u8 bus_info, u8 parent_busid)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000383{
384 struct mp_exten_bus_hierarchy *mpe;
385 mpe = smp_next_mpe_entry(mc);
386 memset(mpe, '\0', sizeof(*mpe));
387 mpe->mpe_type = MPE_BUS_HIERARCHY;
388 mpe->mpe_length = sizeof(*mpe);
389 mpe->mpe_busid = busid;
390 mpe->mpe_bus_info = bus_info;
391 mpe->mpe_parent_busid = parent_busid;
392 smp_add_mpe_entry(mc, (mpe_t)mpe);
393}
394
Mike Loptienbd4553b2014-06-16 10:46:56 -0600395/*
396 * Type 130: Compatibility Bus Address Space Modifier Entry
397 * Entry Type, Entry Length, Bus ID, Address Modifier
398 * Predefined Range List
399 */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000400void smp_write_compatibility_address_space(struct mp_config_table *mc,
Mike Loptienbd4553b2014-06-16 10:46:56 -0600401 u8 busid, u8 address_modifier,
402 u32 range_list)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000403{
404 struct mp_exten_compatibility_address_space *mpe;
405 mpe = smp_next_mpe_entry(mc);
406 memset(mpe, '\0', sizeof(*mpe));
407 mpe->mpe_type = MPE_COMPATIBILITY_ADDRESS_SPACE;
408 mpe->mpe_length = sizeof(*mpe);
409 mpe->mpe_busid = busid;
410 mpe->mpe_address_modifier = address_modifier;
411 mpe->mpe_range_list = range_list;
412 smp_add_mpe_entry(mc, (mpe_t)mpe);
413}
414
Patrick Georgi6eb7a532011-10-07 21:42:52 +0200415void mptable_lintsrc(struct mp_config_table *mc, unsigned long bus_isa)
416{
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700417 smp_write_lintsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE
418 | MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x0);
419 smp_write_lintsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE
420 | MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x1);
Patrick Georgi6eb7a532011-10-07 21:42:52 +0200421}
422
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700423void mptable_add_isa_interrupts(struct mp_config_table *mc,
424 unsigned long bus_isa, unsigned long apicid, int external_int2)
Patrick Georgic5b87c82010-05-20 15:28:19 +0000425{
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700426/*I/O Ints: Type Trigger Polarity
427 * Bus ID IRQ APIC ID PIN# */
Patrick Georgic5b87c82010-05-20 15:28:19 +0000428 smp_write_intsrc(mc, external_int2?mp_INT:mp_ExtINT,
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700429 MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH,
430 bus_isa, 0x0, apicid, 0x0);
431 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH,
432 bus_isa, 0x1, apicid, 0x1);
Patrick Georgic5b87c82010-05-20 15:28:19 +0000433 smp_write_intsrc(mc, external_int2?mp_ExtINT:mp_INT,
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700434 MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH,
435 bus_isa, 0x0, apicid, 0x2);
436 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH,
437 bus_isa, 0x3, apicid, 0x3);
438 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH,
439 bus_isa, 0x4, apicid, 0x4);
440 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH,
441 bus_isa, 0x6, apicid, 0x6);
442 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH,
443 bus_isa, 0x7, apicid, 0x7);
444 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH,
445 bus_isa, 0x8, apicid, 0x8);
446 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH,
447 bus_isa, 0x9, apicid, 0x9);
448 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH,
449 bus_isa, 0xa, apicid, 0xa);
450 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH,
451 bus_isa, 0xb, apicid, 0xb);
452 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH,
453 bus_isa, 0xc, apicid, 0xc);
454 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH,
455 bus_isa, 0xd, apicid, 0xd);
456 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH,
457 bus_isa, 0xe, apicid, 0xe);
458 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH,
459 bus_isa, 0xf, apicid, 0xf);
Patrick Georgic5b87c82010-05-20 15:28:19 +0000460}
Patrick Georgiab272662010-06-25 13:43:22 +0000461
Lee Leahy9c7c6f72017-03-16 11:24:09 -0700462void mptable_write_buses(struct mp_config_table *mc, int *max_pci_bus,
463 int *isa_bus)
464{
Patrick Georgiab272662010-06-25 13:43:22 +0000465 int dummy, i, highest;
466 char buses[256];
467 struct device *dev;
468
Lee Leahy0b5678f2017-03-16 16:01:40 -0700469 if (!max_pci_bus)
470 max_pci_bus = &dummy;
471 if (!isa_bus)
472 isa_bus = &dummy;
Patrick Georgiab272662010-06-25 13:43:22 +0000473
474 *max_pci_bus = 0;
475 highest = 0;
476 memset(buses, 0, sizeof(buses));
477
478 for (dev = all_devices; dev; dev = dev->next) {
Arthur Heymans7fcd4d52023-08-24 15:12:19 +0200479 struct bus *bus = dev->downstream;
Arthur Heymans80c79a52023-08-24 15:12:19 +0200480 if (!bus)
481 continue;
482 if (bus->secondary > 255) {
483 printk(BIOS_ERR, "A bus claims to have a bus ID > 255?!? Aborting\n");
484 return;
Patrick Georgiab272662010-06-25 13:43:22 +0000485 }
Arthur Heymans80c79a52023-08-24 15:12:19 +0200486 buses[bus->secondary] = 1;
487 if (highest < bus->secondary)
488 highest = bus->secondary;
Patrick Georgiab272662010-06-25 13:43:22 +0000489 }
Lee Leahy024b13d2017-03-16 13:41:11 -0700490 for (i = 0; i <= highest; i++) {
Patrick Georgiab272662010-06-25 13:43:22 +0000491 if (buses[i]) {
492 smp_write_bus(mc, i, "PCI ");
493 *max_pci_bus = i;
494 }
495 }
496 *isa_bus = *max_pci_bus + 1;
497 smp_write_bus(mc, *isa_bus, "ISA ");
498}
499
Patrick Georgib0a9c5c2011-10-07 23:01:55 +0200500void *mptable_finalize(struct mp_config_table *mc)
501{
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700502 mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc),
503 mc->mpe_length);
Patrick Georgib0a9c5c2011-10-07 23:01:55 +0200504 mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
Lee Leahy6f80ccc2017-03-16 15:18:22 -0700505 printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
506 mc, smp_next_mpe_entry(mc));
Patrick Georgib0a9c5c2011-10-07 23:01:55 +0200507 return smp_next_mpe_entry(mc);
508}