All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@citrix.com>
To: freebsd-xen@freebsd.org, freebsd-current@freebsd.org,
	xen-devel@lists.xenproject.org, gibbs@freebsd.org,
	jhb@freebsd.org, kib@freebsd.org, julien.grall@citrix.com
Cc: Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH RFC 02/13] ioapic: introduce hooks for some ioapic ops
Date: Tue, 24 Dec 2013 12:20:51 +0100	[thread overview]
Message-ID: <1387884062-41154-3-git-send-email-roger.pau__17360.9793106609$1387884246$gmane$org@citrix.com> (raw)
In-Reply-To: <1387884062-41154-1-git-send-email-roger.pau@citrix.com>

Create some hooks for IO APIC operations that will diverge from bare
metal when implemented for Xen Dom0.

This patch should not introduce any changes in functionality, it's a
preparatory patch for the implementation of the Xen IO APIC hooks.
---
 sys/amd64/include/apicvar.h |   13 ++++++++
 sys/i386/include/apicvar.h  |   13 ++++++++
 sys/x86/include/apicreg.h   |   12 ++++++++
 sys/x86/x86/io_apic.c       |   65 ++++++++++++++++++++++---------------------
 4 files changed, 71 insertions(+), 32 deletions(-)

diff --git a/sys/amd64/include/apicvar.h b/sys/amd64/include/apicvar.h
index 84e01d4..a48a76b 100644
--- a/sys/amd64/include/apicvar.h
+++ b/sys/amd64/include/apicvar.h
@@ -161,6 +161,19 @@ struct apic_enumerator {
 	SLIST_ENTRY(apic_enumerator) apic_next;
 };
 
+struct ioapic_intsrc {
+	struct intsrc io_intsrc;
+	u_int io_irq;
+	u_int io_intpin:8;
+	u_int io_vector:8;
+	u_int io_cpu:8;
+	u_int io_activehi:1;
+	u_int io_edgetrigger:1;
+	u_int io_masked:1;
+	int io_bus:4;
+	uint32_t io_lowreg;
+};
+
 inthand_t
 	IDTVEC(apic_isr1), IDTVEC(apic_isr2), IDTVEC(apic_isr3),
 	IDTVEC(apic_isr4), IDTVEC(apic_isr5), IDTVEC(apic_isr6),
diff --git a/sys/i386/include/apicvar.h b/sys/i386/include/apicvar.h
index 24c99f0..c8ee9bc 100644
--- a/sys/i386/include/apicvar.h
+++ b/sys/i386/include/apicvar.h
@@ -160,6 +160,19 @@ struct apic_enumerator {
 	SLIST_ENTRY(apic_enumerator) apic_next;
 };
 
+struct ioapic_intsrc {
+	struct intsrc io_intsrc;
+	u_int io_irq;
+	u_int io_intpin:8;
+	u_int io_vector:8;
+	u_int io_cpu:8;
+	u_int io_activehi:1;
+	u_int io_edgetrigger:1;
+	u_int io_masked:1;
+	int io_bus:4;
+	uint32_t io_lowreg;
+};
+
 inthand_t
 	IDTVEC(apic_isr1), IDTVEC(apic_isr2), IDTVEC(apic_isr3),
 	IDTVEC(apic_isr4), IDTVEC(apic_isr5), IDTVEC(apic_isr6),
diff --git a/sys/x86/include/apicreg.h b/sys/x86/include/apicreg.h
index 283d50e..4629470 100644
--- a/sys/x86/include/apicreg.h
+++ b/sys/x86/include/apicreg.h
@@ -204,6 +204,18 @@ struct IOAPIC {
 
 typedef struct IOAPIC ioapic_t;
 
+struct ioapic_intsrc;
+/*
+ * Struct containing pointers to IO APIC management functions whose
+ * implementation is run time selectable.
+ */
+struct ioapic_ops {
+	u_int    (*read)(volatile ioapic_t *, int);
+	void     (*write)(volatile ioapic_t *, int, u_int);
+	void     (*register_intr)(struct ioapic_intsrc *);
+};
+extern struct ioapic_ops ioapic_ops;
+
 #undef PAD4
 #undef PAD3
 
diff --git a/sys/x86/x86/io_apic.c b/sys/x86/x86/io_apic.c
index 6d62b1e..125d06a 100644
--- a/sys/x86/x86/io_apic.c
+++ b/sys/x86/x86/io_apic.c
@@ -81,19 +81,6 @@ static MALLOC_DEFINE(M_IOAPIC, "io_apic", "I/O APIC structures");
  * ftp://download.intel.com/design/chipsets/datashts/29056601.pdf
  */
 
-struct ioapic_intsrc {
-	struct intsrc io_intsrc;
-	u_int io_irq;
-	u_int io_intpin:8;
-	u_int io_vector:8;
-	u_int io_cpu:8;
-	u_int io_activehi:1;
-	u_int io_edgetrigger:1;
-	u_int io_masked:1;
-	int io_bus:4;
-	uint32_t io_lowreg;
-};
-
 struct ioapic {
 	struct pic io_pic;
 	u_int io_id:8;			/* logical ID */
@@ -106,8 +93,9 @@ struct ioapic {
 	struct ioapic_intsrc io_pins[0];
 };
 
-static u_int	ioapic_read(volatile ioapic_t *apic, int reg);
-static void	ioapic_write(volatile ioapic_t *apic, int reg, u_int val);
+static u_int	native_ioapic_read(volatile ioapic_t *apic, int reg);
+static void	native_ioapic_write(volatile ioapic_t *apic, int reg, u_int val);
+static void	native_ioapic_register_intr(struct ioapic_intsrc *pin);
 static const char *ioapic_bus_string(int bus_type);
 static void	ioapic_print_irq(struct ioapic_intsrc *intpin);
 static void	ioapic_enable_source(struct intsrc *isrc);
@@ -139,6 +127,13 @@ SYSCTL_INT(_hw_apic, OID_AUTO, enable_extint, CTLFLAG_RDTUN, &enable_extint, 0,
     "Enable the ExtINT pin in the first I/O APIC");
 TUNABLE_INT("hw.apic.enable_extint", &enable_extint);
 
+/* Default ioapic_ops implementation. */
+struct ioapic_ops ioapic_ops = {
+	.read =			native_ioapic_read,
+	.write =		native_ioapic_write,
+	.register_intr =	native_ioapic_register_intr,
+};
+
 static __inline void
 _ioapic_eoi_source(struct intsrc *isrc)
 {
@@ -146,7 +141,7 @@ _ioapic_eoi_source(struct intsrc *isrc)
 }
 
 static u_int
-ioapic_read(volatile ioapic_t *apic, int reg)
+native_ioapic_read(volatile ioapic_t *apic, int reg)
 {
 
 	mtx_assert(&icu_lock, MA_OWNED);
@@ -155,7 +150,7 @@ ioapic_read(volatile ioapic_t *apic, int reg)
 }
 
 static void
-ioapic_write(volatile ioapic_t *apic, int reg, u_int val)
+native_ioapic_write(volatile ioapic_t *apic, int reg, u_int val)
 {
 
 	mtx_assert(&icu_lock, MA_OWNED);
@@ -163,6 +158,12 @@ ioapic_write(volatile ioapic_t *apic, int reg, u_int val)
 	apic->iowin = val;
 }
 
+static void
+native_ioapic_register_intr(struct ioapic_intsrc *pin)
+{
+	intr_register_source(&pin->io_intsrc);
+}
+
 static const char *
 ioapic_bus_string(int bus_type)
 {
@@ -212,7 +213,7 @@ ioapic_enable_source(struct intsrc *isrc)
 	mtx_lock_spin(&icu_lock);
 	if (intpin->io_masked) {
 		flags = intpin->io_lowreg & ~IOART_INTMASK;
-		ioapic_write(io->io_addr, IOAPIC_REDTBL_LO(intpin->io_intpin),
+		ioapic_ops.write(io->io_addr, IOAPIC_REDTBL_LO(intpin->io_intpin),
 		    flags);
 		intpin->io_masked = 0;
 	}
@@ -229,7 +230,7 @@ ioapic_disable_source(struct intsrc *isrc, int eoi)
 	mtx_lock_spin(&icu_lock);
 	if (!intpin->io_masked && !intpin->io_edgetrigger) {
 		flags = intpin->io_lowreg | IOART_INTMSET;
-		ioapic_write(io->io_addr, IOAPIC_REDTBL_LO(intpin->io_intpin),
+		ioapic_ops.write(io->io_addr, IOAPIC_REDTBL_LO(intpin->io_intpin),
 		    flags);
 		intpin->io_masked = 1;
 	}
@@ -264,10 +265,10 @@ ioapic_program_intpin(struct ioapic_intsrc *intpin)
 	mtx_assert(&icu_lock, MA_OWNED);
 	if (intpin->io_irq == IRQ_DISABLED || (intpin->io_irq < NUM_IO_INTS &&
 	    intpin->io_vector == 0)) {
-		low = ioapic_read(io->io_addr,
+		low = ioapic_ops.read(io->io_addr,
 		    IOAPIC_REDTBL_LO(intpin->io_intpin));
 		if ((low & IOART_INTMASK) == IOART_INTMCLR)
-			ioapic_write(io->io_addr,
+			ioapic_ops.write(io->io_addr,
 			    IOAPIC_REDTBL_LO(intpin->io_intpin),
 			    low | IOART_INTMSET);
 		return;
@@ -311,12 +312,12 @@ ioapic_program_intpin(struct ioapic_intsrc *intpin)
 	}
 
 	/* Write the values to the APIC. */
-	value = ioapic_read(io->io_addr, IOAPIC_REDTBL_HI(intpin->io_intpin));
+	value = ioapic_ops.read(io->io_addr, IOAPIC_REDTBL_HI(intpin->io_intpin));
 	value &= ~IOART_DEST;
 	value |= high;
-	ioapic_write(io->io_addr, IOAPIC_REDTBL_HI(intpin->io_intpin), value);
+	ioapic_ops.write(io->io_addr, IOAPIC_REDTBL_HI(intpin->io_intpin), value);
 	intpin->io_lowreg = low;
-	ioapic_write(io->io_addr, IOAPIC_REDTBL_LO(intpin->io_intpin), low);
+	ioapic_ops.write(io->io_addr, IOAPIC_REDTBL_LO(intpin->io_intpin), low);
 }
 
 static int
@@ -357,7 +358,7 @@ ioapic_assign_cpu(struct intsrc *isrc, u_int apic_id)
 	 */
 	mtx_lock_spin(&icu_lock);
 	if (!intpin->io_masked && !intpin->io_edgetrigger) {
-		ioapic_write(io->io_addr, IOAPIC_REDTBL_LO(intpin->io_intpin),
+		ioapic_ops.write(io->io_addr, IOAPIC_REDTBL_LO(intpin->io_intpin),
 		    intpin->io_lowreg | IOART_INTMSET);
 		mtx_unlock_spin(&icu_lock);
 		DELAY(100);
@@ -512,7 +513,7 @@ ioapic_create(vm_paddr_t addr, int32_t apic_id, int intbase)
 	/* Map the register window so we can access the device. */
 	apic = pmap_mapdev(addr, IOAPIC_MEM_REGION);
 	mtx_lock_spin(&icu_lock);
-	value = ioapic_read(apic, IOAPIC_VER);
+	value = ioapic_ops.read(apic, IOAPIC_VER);
 	mtx_unlock_spin(&icu_lock);
 
 	/* If it's version register doesn't seem to work, punt. */
@@ -528,9 +529,9 @@ ioapic_create(vm_paddr_t addr, int32_t apic_id, int intbase)
 	io->io_pic = ioapic_template;
 	mtx_lock_spin(&icu_lock);
 	io->io_id = next_id++;
-	io->io_apic_id = ioapic_read(apic, IOAPIC_ID) >> APIC_ID_SHIFT;
+	io->io_apic_id = ioapic_ops.read(apic, IOAPIC_ID) >> APIC_ID_SHIFT;
 	if (apic_id != -1 && io->io_apic_id != apic_id) {
-		ioapic_write(apic, IOAPIC_ID, apic_id << APIC_ID_SHIFT);
+		ioapic_ops.write(apic, IOAPIC_ID, apic_id << APIC_ID_SHIFT);
 		mtx_unlock_spin(&icu_lock);
 		io->io_apic_id = apic_id;
 		printf("ioapic%u: Changing APIC ID to %d\n", io->io_id,
@@ -586,8 +587,8 @@ ioapic_create(vm_paddr_t addr, int32_t apic_id, int intbase)
 		 * be routed to other CPUs later after they are enabled.
 		 */
 		intpin->io_cpu = PCPU_GET(apic_id);
-		value = ioapic_read(apic, IOAPIC_REDTBL_LO(i));
-		ioapic_write(apic, IOAPIC_REDTBL_LO(i), value | IOART_INTMSET);
+		value = ioapic_ops.read(apic, IOAPIC_REDTBL_LO(i));
+		ioapic_ops.write(apic, IOAPIC_REDTBL_LO(i), value | IOART_INTMSET);
 	}
 	mtx_unlock_spin(&icu_lock);
 
@@ -788,7 +789,7 @@ ioapic_register(void *cookie)
 	io = (struct ioapic *)cookie;
 	apic = io->io_addr;
 	mtx_lock_spin(&icu_lock);
-	flags = ioapic_read(apic, IOAPIC_VER) & IOART_VER_VERSION;
+	flags = ioapic_ops.read(apic, IOAPIC_VER) & IOART_VER_VERSION;
 	STAILQ_INSERT_TAIL(&ioapic_list, io, io_next);
 	mtx_unlock_spin(&icu_lock);
 	printf("ioapic%u <Version %u.%u> irqs %u-%u on motherboard\n",
@@ -799,7 +800,7 @@ ioapic_register(void *cookie)
 	intr_register_pic(&io->io_pic);
 	for (i = 0, pin = io->io_pins; i < io->io_numintr; i++, pin++)
 		if (pin->io_irq < NUM_IO_INTS)
-			intr_register_source(&pin->io_intsrc);
+			ioapic_ops.register_intr(pin);
 }
 
 /* A simple new-bus driver to consume PCI I/O APIC devices. */
-- 
1.7.7.5 (Apple Git-26)

  parent reply	other threads:[~2013-12-24 11:22 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1387884062-41154-1-git-send-email-roger.pau@citrix.com>
2013-12-24 11:20 ` [PATCH RFC 01/13] xen: use the hardware e820 map on Dom0 Roger Pau Monne
2013-12-24 11:20 ` Roger Pau Monne [this message]
2013-12-24 11:20 ` [PATCH RFC 03/13] xen: mask event channels while changing affinity Roger Pau Monne
2013-12-24 11:20 ` [PATCH RFC 04/13] xen: implement basic PIRQ support for Dom0 Roger Pau Monne
2014-01-21 18:52   ` John Baldwin
2013-12-24 11:20 ` [PATCH RFC 05/13] xen: implement Xen IO APIC ops Roger Pau Monne
2013-12-24 11:20 ` [PATCH RFC 06/13] xen: Dom0 console fixes Roger Pau Monne
2013-12-24 11:20 ` [PATCH RFC 07/13] xen: implement IO APIC support in Xen mptable parser Roger Pau Monne
2013-12-24 11:20 ` [PATCH RFC 08/13] xen: change order of Xen intr init and IO APIC registration Roger Pau Monne
2013-12-24 11:20 ` [PATCH RFC 09/13] xen: change quality of the MADT ACPI enumerator Roger Pau Monne
2014-02-08 21:42   ` John Baldwin
     [not found]   ` <1980951.95r2q2cca3@ralph.baldwin.cx>
2014-02-14  1:49     ` Andrew Cooper
     [not found]     ` <52FD7624.90202@citrix.com>
2014-02-14 17:51       ` John Baldwin
     [not found]       ` <201402141251.10278.jhb@freebsd.org>
2014-02-17 16:01         ` Roger Pau Monné
2013-12-24 11:20 ` [PATCH RFC 10/13] xen: add ACPI bus to xen_nexus when running as Dom0 Roger Pau Monne
2013-12-24 11:21 ` [PATCH RFC 11/13] pci: introduce a new event on PCI device detection Roger Pau Monne
2013-12-24 11:21 ` [PATCH RFC 12/13] mca: disable cmc enable on Xen PV Roger Pau Monne
2013-12-24 11:21 ` [PATCH RFC 13/13] xenstore: changes needed to boot in Dom0 mode Roger Pau Monne
     [not found] ` <1387884062-41154-4-git-send-email-roger.pau@citrix.com>
2014-01-03 20:45   ` [PATCH RFC 03/13] xen: mask event channels while changing affinity Konrad Rzeszutek Wilk
     [not found] ` <1387884062-41154-2-git-send-email-roger.pau@citrix.com>
2014-01-21 18:25   ` [PATCH RFC 01/13] xen: use the hardware e820 map on Dom0 John Baldwin
     [not found] ` <1387884062-41154-3-git-send-email-roger.pau@citrix.com>
2014-01-21 18:27   ` [PATCH RFC 02/13] ioapic: introduce hooks for some ioapic ops John Baldwin
     [not found] ` <1387884062-41154-6-git-send-email-roger.pau@citrix.com>
2014-01-21 18:55   ` [PATCH RFC 05/13] xen: implement Xen IO APIC ops John Baldwin
     [not found] ` <1387884062-41154-7-git-send-email-roger.pau@citrix.com>
2014-01-21 19:02   ` [PATCH RFC 06/13] xen: Dom0 console fixes John Baldwin
     [not found] ` <1387884062-41154-8-git-send-email-roger.pau@citrix.com>
2014-02-08 21:36   ` [PATCH RFC 07/13] xen: implement IO APIC support in Xen mptable parser John Baldwin
     [not found] ` <1387884062-41154-9-git-send-email-roger.pau@citrix.com>
2014-02-08 21:37   ` [PATCH RFC 08/13] xen: change order of Xen intr init and IO APIC registration John Baldwin
     [not found] ` <1387884062-41154-11-git-send-email-roger.pau@citrix.com>
2014-02-08 21:50   ` [PATCH RFC 10/13] xen: add ACPI bus to xen_nexus when running as Dom0 John Baldwin
     [not found]   ` <2410827.IqfpSAhe3T@ralph.baldwin.cx>
2014-02-14 10:38     ` Roger Pau Monné
     [not found]     ` <52FDF217.3040005@citrix.com>
2014-02-14 17:50       ` John Baldwin
     [not found] ` <1387884062-41154-12-git-send-email-roger.pau@citrix.com>
2014-02-08 21:57   ` [PATCH RFC 11/13] pci: introduce a new event on PCI device detection John Baldwin
     [not found] ` <1387884062-41154-13-git-send-email-roger.pau@citrix.com>
2014-02-08 22:02   ` [PATCH RFC 12/13] mca: disable cmc enable on Xen PV John Baldwin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='1387884062-41154-3-git-send-email-roger.pau__17360.9793106609$1387884246$gmane$org@citrix.com' \
    --to=roger.pau@citrix.com \
    --cc=freebsd-current@freebsd.org \
    --cc=freebsd-xen@freebsd.org \
    --cc=gibbs@freebsd.org \
    --cc=jhb@freebsd.org \
    --cc=julien.grall@citrix.com \
    --cc=kib@freebsd.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.