Subject: tweaking mpbios.c for Xen
To: None <port-i386@netbsd.org, port-amd64@netbsd.org>
From: Manuel Bouyer <bouyer@antioche.eu.org>
List: port-i386
Date: 09/16/2006 17:11:06
--2oS5YaxWCcQjTEyO
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi,
For Xen3/dom0 I need to be able to use the x86 MPBIOS code, but only for
busses and ioapics. In Xen, CPUs and local apics are managed by the hypervisor
and the dom0 doesn't know about them (domains sees virtual CPUs).

The attached patch handle this:
- don't access ioapic or lapic when not configured (it may also be usefull
  to be able to configure MPBIOS without apics for debug purposes)
- don't try to attach CPUs when _MPACPI_NO_CPU is defined.
  xen/include/mpbiosvar.h defines this before including x86/mpbiosvar.h

Does anyone see a problem with this patch ?

-- 
Manuel Bouyer <bouyer@antioche.eu.org>
     NetBSD: 26 ans d'experience feront toujours la difference
--

--2oS5YaxWCcQjTEyO
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="diff.mpbios"

Index: x86/x86/mpbios.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/x86/mpbios.c,v
retrieving revision 1.28
diff -u -r1.28 mpbios.c
--- x86/x86/mpbios.c	4 Jul 2006 00:30:23 -0000	1.28
+++ x86/x86/mpbios.c	16 Sep 2006 15:05:00 -0000
@@ -106,6 +106,8 @@
 __KERNEL_RCSID(0, "$NetBSD: mpbios.c,v 1.28 2006/07/04 00:30:23 christos Exp $");
 
 #include "acpi.h"
+#include "lapic.h"
+#include "ioapic.h"
 #include "opt_acpi.h"
 #include "opt_mpbios.h"
 
@@ -196,8 +198,10 @@
 static void mp_cfg_isa_intr __P((const struct mpbios_int *, uint32_t *));
 static void mp_print_isa_intr (int intr);
 
+#ifndef _MPACPI_NO_CPU
 static void mpbios_cpus __P((struct device *));
 static void mpbios_cpu __P((const uint8_t *, struct device *));
+#endif
 static void mpbios_bus __P((const uint8_t *, struct device *));
 static void mpbios_ioapic __P((const uint8_t *, struct device *));
 static void mpbios_int __P((const uint8_t *, int, struct mp_intr_map *));
@@ -513,7 +517,6 @@
 	paddr_t		lapic_base;
 	const struct mpbios_int *iep;
 	struct mpbios_int ie;
-	struct ioapic_softc *sc;
 
 	printf ("%s: Intel MP Specification ", self->dv_xname);
 
@@ -541,7 +544,9 @@
 		if (mp_cth != NULL)
 			lapic_base = (paddr_t)mp_cth->apic_address;
 
+#if NLAPIC > 0
 		lapic_boot_init(lapic_base);
+#endif
 #if NACPI > 0
 	}
 #endif
@@ -551,11 +556,12 @@
 
 		printf("\n%s: MP default configuration %d\n",
 		    self->dv_xname, mp_fps->mpfb1);
-
+#ifndef _MPACPI_NO_CPU
 #if NACPI > 0
 		if (mpacpi_ncpu == 0)
 #endif
 			mpbios_cpus(self);
+#endif /* !_MPACPI_NO_CPU */
 
 #if NACPI > 0
 		if (mpacpi_nioapic == 0)
@@ -639,7 +645,9 @@
 				if (mpacpi_ncpu)
 					break;
 #endif
+#ifndef _MPACPI_NO_CPU
 				mpbios_cpu(position, self);
+#endif
 				break;
 			case MPS_MCT_BUS:
 				mpbios_bus(position, self);
@@ -656,11 +664,15 @@
 				iep = (const struct mpbios_int *)position;
 				ie = *iep;
 				if (iep->dst_apic_id == MPS_ALL_APICS) {
+#if NIOAPIC > 0
+					struct ioapic_softc *sc;
 					for (sc = ioapics ; sc != NULL;
 					     sc = sc->sc_next) {
 						ie.dst_apic_id = sc->sc_apicid;
 						mpbios_int((char *)&ie, type,
-						    &mp_intrs[cur_intr++]);						}
+						    &mp_intrs[cur_intr++]);
+					}
+#endif
 				} else {
 					mpbios_int(position, type,
 					    &mp_intrs[cur_intr++]);
@@ -698,6 +710,7 @@
 	*napic = mpbios_nioapic;
 }
 
+#ifndef _MPACPI_NO_CPU
 static void
 mpbios_cpu(ent, self)
 	const uint8_t *ent;
@@ -743,6 +756,7 @@
 
 	mpbios_cpu((uint8_t *)&pe, self);
 }
+#endif /* !_MPACPI_NO_CPU */
 
 /*
  * The following functions conspire to compute base ioapic redirection
@@ -1018,7 +1032,6 @@
 	struct device *self;
 {
 	const struct mpbios_ioapic *entry = (const struct mpbios_ioapic *)ent;
-	struct apic_attach_args aaa;
 
 	/* XXX let flags checking happen in ioapic driver.. */
 	if (!(entry->apic_flags & IOAPICENTRY_FLAG_EN))
@@ -1026,6 +1039,9 @@
 
 	mpbios_nioapic++;
 
+#if NIOAPIC > 0
+	{
+	struct apic_attach_args aaa;
 	aaa.aaa_name   = "ioapic";
 	aaa.apic_id = entry->apic_id;
 	aaa.apic_version = entry->apic_version;
@@ -1034,6 +1050,8 @@
 	aaa.flags =  (mp_fps->mpfb2 & 0x80) ? IOAPIC_PICMODE : IOAPIC_VWIRE;
 
 	config_found_sm_loc(self, "cpubus", NULL, &aaa, mp_print, mp_submatch);
+	}
+#endif
 }
 
 static const char inttype_fmt[] = "\177\020"
@@ -1097,7 +1115,11 @@
 	(*mpb->mb_intr_cfg)(entry, &mpi->redir);
 
 	if (enttype == MPS_MCT_IOINT) {
+#if NIOAPIC > 0
 		sc = ioapic_find(id);
+#else
+		sc = NULL;
+#endif
 		if (sc == NULL) {
 			printf("mpbios: can't find ioapic %d\n", id);
 			return;

--2oS5YaxWCcQjTEyO--