Subject: ioapic/mpbios/acpi changes
To: None <port-amd64@netbsd.org, port-i386@netbsd.org>
From: Manuel Bouyer <bouyer@antioche.eu.org>
List: port-i386
Date: 09/23/2006 23:58:51
--/9DWx/yDrRhgMJTb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi,
here is the diff I intend to commit, it contains the changes needed to enable
MPBIOS and ACPI interrupt routing in Xen3/dom0. Overview of the changes:
- mpacpi.c, mpbios.c: allow to build without lapic (in Xen3 lapic is managed
  entirely by the hypervisor)
- ioapic.c: allow custom read/write routines, Xen need hypercalls to talk to
  the ioapic
  In ioapic_addroute(), always initialize sc->sc_pins[]. I can't see why 
  it should not be initialized in the !ioapic_cold case; and in the
  !ioapic_cold case apic_set_redir() doesn't work properly because
  ip_type left to IST_NONE. For Xen I have to enable ioapic very early to be
  able to bind interrupts to events.

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

--/9DWx/yDrRhgMJTb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="diff.acpi_x86"

Index: x86/ioapic.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/x86/ioapic.c,v
retrieving revision 1.13
diff -u -r1.13 ioapic.c
--- x86/ioapic.c	4 Jul 2006 00:30:23 -0000	1.13
+++ x86/ioapic.c	23 Sep 2006 21:55:12 -0000
@@ -149,6 +149,7 @@
 	write_psl(flags);
 }
 
+#ifndef _IOAPIC_CUSTOM_RW
 /*
  * Register read/write routines.
  */
@@ -170,6 +171,7 @@
 	*(sc->sc_reg) = regid;
 	*(sc->sc_data) = val;
 }
+#endif /* !_IOAPIC_CUSTOM_RW */
 
 static inline u_int32_t
 ioapic_read(struct ioapic_softc *sc, int regid)
@@ -278,7 +280,6 @@
 	struct ioapic_softc *sc = (struct ioapic_softc *)self;  
 	struct apic_attach_args  *aaa = (struct apic_attach_args  *) aux;
 	int apic_id;
-	bus_space_handle_t bh;
 	u_int32_t ver_sz;
 	int i;
 	
@@ -294,8 +295,11 @@
 	}
 
 	ioapic_add(sc);
-	
+
 	printf("%s: pa 0x%lx", sc->sc_pic.pic_dev.dv_xname, aaa->apic_address);
+#ifndef _IOAPIC_CUSTOM_RW
+	{
+	bus_space_handle_t bh;
 
 	if (x86_mem_add_mapping(aaa->apic_address, PAGE_SIZE, 0, &bh) != 0) {
 		printf(": map failed\n");
@@ -303,6 +307,9 @@
 	}
 	sc->sc_reg = (volatile u_int32_t *)(bh + IOAPIC_REG);
 	sc->sc_data = (volatile u_int32_t *)(bh + IOAPIC_DATA);	
+	}
+#endif
+	sc->sc_pa = aaa->apic_address;
 
 	sc->sc_pic.pic_type = PIC_IOAPIC;
 	__cpu_simple_lock_init(&sc->sc_pic.pic_lock);
@@ -512,11 +519,11 @@
 	struct ioapic_softc *sc = (struct ioapic_softc *)pic;
 	struct ioapic_pin *pp;
 
+	pp = &sc->sc_pins[pin];
+	pp->ip_type = type;
+	pp->ip_vector = idtvec;
+	pp->ip_cpu = ci;
 	if (ioapic_cold) {
-		pp = &sc->sc_pins[pin];
-		pp->ip_type = type;
-		pp->ip_vector = idtvec;
-		pp->ip_cpu = ci;
 		return;
 	}
 	apic_set_redir(sc, pin, idtvec, ci);
Index: x86/mpacpi.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/x86/mpacpi.c,v
retrieving revision 1.38
diff -u -r1.38 mpacpi.c
--- x86/mpacpi.c	12 Aug 2006 16:19:13 -0000	1.38
+++ x86/mpacpi.c	23 Sep 2006 21:55:12 -0000
@@ -371,7 +371,7 @@
 	mpacpi_ncpu = mpacpi_nintsrc = mpacpi_nioapic = 0;
 	acpi_madt_walk(mpacpi_count, self);
 
-#if NIOAPIC > 0
+#if NLAPIC > 0
 	lapic_boot_init(mpacpi_lapic_base);
 #endif
 
Index: 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/mpbios.c	4 Jul 2006 00:30:23 -0000	1.28
+++ x86/mpbios.c	23 Sep 2006 21:55:12 -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"
 
@@ -513,7 +515,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 +542,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,7 +554,6 @@
 
 		printf("\n%s: MP default configuration %d\n",
 		    self->dv_xname, mp_fps->mpfb1);
-
 #if NACPI > 0
 		if (mpacpi_ncpu == 0)
 #endif
@@ -656,11 +658,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++]);
@@ -1018,7 +1024,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 +1031,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 +1042,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 +1107,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;

--/9DWx/yDrRhgMJTb--