Skip to contentSkip to conversation

x86: Add a function to assign IRQ numbers to PCI device

PATCH New Bin Meng 2 participants 9 messages Apr 24, 2015 – Apr 25, 2015 1 message not in the archive x86

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Bin Meng

author
#1 lore raw

PATCH v2 1/4 x86: Add a function to assign IRQ numbers to PCI device

Add a function to assign an IRQ number to PCI device's interrupt line register in its configuration space, so that the PCI device can have its interrupt working under PIC mode after OS boots up.

---

Changes in v2: None

 arch/x86/cpu/pci.c         | 21 +++++++++++++++++++++
 arch/x86/include/asm/pci.h | 14 ++++++++++++++
 2 files changed, 35 insertions(+)
arch/x86/cpu/pci.c +21 -0
index e23b233..c209f15 100644
@@ -151,3 +151,24 @@ int pci_x86_write_config(struct udevice *bus, pci_dev_t bdf, uint offset,
 
 	return 0;
 }
+
+void pci_assign_irqs(int bus, int device, int func, u8 irq[4])
+{
+	pci_dev_t bdf;
+	u8 pin, line;
+
+	bdf = PCI_BDF(bus, device, func);
+
+	pin = x86_pci_read_config8(bdf, PCI_INTERRUPT_PIN);
+
+	/* PCI spec says all values except 1..4 are reserved */
+	if ((pin < 1) || (pin > 4))
+		return;
+
+	line = irq[pin - 1];
+
+	debug("Assigning IRQ %d to PCI device %d.%x.%d (INT%c)\n",
+	      line, bus, device, func, 'A' + pin - 1);
+
+	x86_pci_write_config8(bdf, PCI_INTERRUPT_LINE, line);
+}
arch/x86/include/asm/pci.h +14 -0
index a1969ed..56eaa25 100644
@@ -64,6 +64,20 @@ int pci_x86_read_config(struct udevice *bus, pci_dev_t bdf, uint offset,
 int pci_x86_write_config(struct udevice *bus, pci_dev_t bdf, uint offset,
 			 ulong value, enum pci_size_t size);
 
+/**
+ * Assign IRQ number to a PCI device
+ *
+ * This function assigns IRQ for a PCI device. If the device does not exist
+ * or does not require interrupts then this function has no effect.
+ *
+ * @bus:	PCI bus number
+ * @device:	PCI device number
+ * @func:	PCI function number
+ * @irq:	An array of IRQ numbers that are assigned to INTA through
+ *		INTD of this PCI device.
+ */
+void pci_assign_irqs(int bus, int device, int func, u8 irq[4]);
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _PCI_I386_H_ */
Signature · 1 line
1.8.2.1
#2 lore raw

PATCH v2 1/4 x86: Add a function to assign IRQ numbers to PCI device

Quoted 6 lines · Bin Meng

Add a function to assign an IRQ number to PCI device's interrupt line register in its configuration space, so that the PCI device can have its interrupt working under PIC mode after OS boots up.

Quoted 7 lines

---

Changes in v2: None

 arch/x86/cpu/pci.c         | 21 +++++++++++++++++++++
 arch/x86/include/asm/pci.h | 14 ++++++++++++++
 2 files changed, 35 insertions(+)

Applied to u-boot-x86, thanks!

author
#3 lore raw

PATCH v2 2/4 x86: Write configuration tables in last_stage_init()

In reply to a message not in the archive

We can write the configuration table in last_stage_init() for all x86 boards, but not with coreboot since coreboot already has them.

---

Changes in v2: None

 arch/x86/cpu/cpu.c            | 10 +++++++++
 arch/x86/include/asm/tables.h | 49 +++++++++++++++++++++++++++++++++++++++++++
 arch/x86/lib/Makefile         |  1 +
 arch/x86/lib/tables.c         | 30 ++++++++++++++++++++++++++
 include/configs/x86-common.h  |  1 +
 5 files changed, 91 insertions(+)
 create mode 100644 arch/x86/include/asm/tables.h
 create mode 100644 arch/x86/lib/tables.c
arch/x86/cpu/cpu.c +10 -0
index a9ca50b..c9614f1 100644
@@ -29,6 +29,7 @@
 #include <asm/processor.h>
 #include <asm/processor-flags.h>
 #include <asm/interrupt.h>
+#include <asm/tables.h>
 #include <linux/compiler.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -593,3 +594,12 @@ void show_boot_progress(int val)
 #endif
 	outb(val, POST_PORT);
 }
+
+#ifndef CONFIG_SYS_COREBOOT
+int last_stage_init(void)
+{
+	write_tables();
+
+	return 0;
+}
+#endif
arch/x86/include/asm/tables.h new file +49 -0

49 lines not on this page · raw message

arch/x86/lib/Makefile +1 -0
index e49de05..0de0d89 100644
@@ -26,6 +26,7 @@ obj-y	+= relocate.o
 obj-y += physmem.o
 obj-$(CONFIG_X86_RAMTEST) += ramtest.o
 obj-y	+= string.o
+obj-y	+= tables.o
 obj-$(CONFIG_SYS_X86_TSC_TIMER)	+= tsc_timer.o
 obj-$(CONFIG_CMD_ZBOOT)	+= zimage.o
 obj-$(CONFIG_HAVE_FSP) += fsp/
arch/x86/lib/tables.c new file +30 -0
new file mode 100644
index 0000000..b390a4b
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2015, Bin Meng <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/tables.h>
+
+u8 table_compute_checksum(void *v, int len)
+{
+	u8 *bytes = v;
+	u8 checksum = 0;
+	int i;
+
+	for (i = 0; i < len; i++)
+		checksum -= bytes[i];
+
+	return checksum;
+}
+
+void write_tables(void)
+{
+	u32 __maybe_unused rom_table_end = ROM_TABLE_ADDR;
+
+#if CONFIG_GENERATE_PIRQ_TABLE
+	rom_table_end = write_pirq_routing_table(rom_table_end);
+	rom_table_end = ALIGN(rom_table_end, 1024);
+#endif
+}
include/configs/x86-common.h +1 -0
index 07a5aca..3e21e09 100644
@@ -20,6 +20,7 @@
 #define CONFIG_PHYSMEM
 #define CONFIG_DISPLAY_BOARDINFO_LATE
 #define CONFIG_DISPLAY_CPUINFO
+#define CONFIG_LAST_STAGE_INIT
 
 #define CONFIG_LMB
 #define CONFIG_OF_LIBFDT
Signature · 1 line
1.8.2.1
#4 lore raw

PATCH v2 2/4 x86: Write configuration tables in last_stage_init()

Quoted 9 lines · Bin Meng

We can write the configuration table in last_stage_init() for all x86 boards, but not with coreboot since coreboot already has them.

---

Changes in v2: None

Quoted 8 lines
 arch/x86/cpu/cpu.c            | 10 +++++++++
 arch/x86/include/asm/tables.h | 49 +++++++++++++++++++++++++++++++++++++++++++
 arch/x86/lib/Makefile         |  1 +
 arch/x86/lib/tables.c         | 30 ++++++++++++++++++++++++++
 include/configs/x86-common.h  |  1 +
 5 files changed, 91 insertions(+)
 create mode 100644 arch/x86/include/asm/tables.h
 create mode 100644 arch/x86/lib/tables.c

Applied to u-boot-x86, thanks!

author
#5 lore raw

PATCH v2 3/4 x86: Support platform PIRQ routing

In reply to a message not in the archive

On x86 boards, platform chipset receives up to four different interrupt signals from PCI devices (INTA/B/C/D), which in turn will be routed to chipset internal PIRQ lines then routed to 8259 PIC finally if configuring the whole system to work under the so-called PIC mode (in contrast to symmetric IO mode which uses IOAPIC).

We add two major APIs to aid this, one for routing PIRQ and the other one for generating a PIRQ routing table.

---

Changes in v2: None

 arch/x86/Kconfig                    |  31 ++++++++
 arch/x86/include/asm/pirq_routing.h | 139 ++++++++++++++++++++++++++++++++++++
 arch/x86/lib/Makefile               |   1 +
 arch/x86/lib/pirq_routing.c         | 129 +++++++++++++++++++++++++++++++++
 4 files changed, 300 insertions(+)
 create mode 100644 arch/x86/include/asm/pirq_routing.h
 create mode 100644 arch/x86/lib/pirq_routing.c
arch/x86/Kconfig +31 -0
index 3f1401a..aaceaef 100644
@@ -442,6 +442,37 @@ config TSC_FREQ_IN_MHZ
 	help
 	  The running frequency in MHz of Time-Stamp Counter (TSC).
 
+menu "System tables"
+
+config GENERATE_PIRQ_TABLE
+	bool "Generate a PIRQ table"
+	default n
+	help
+	  Generate a PIRQ routing table for this board. The PIRQ routing table
+	  is generated by U-Boot in the system memory from 0xf0000 to 0xfffff
+	  at every 16-byte boundary with a PCI IRQ routing signature ("$PIR").
+	  It specifies the interrupt router information as well how all the PCI
+	  devices' interrupt pins are wired to PIRQs.
+
+endmenu
+
+config MAX_PIRQ_LINKS
+	int
+	default 8
+	help
+	  This variable specifies the number of PIRQ interrupt links which are
+	  routable. On most older chipsets, this is 4, PIRQA through PIRQD.
+	  Some newer chipsets offer more than four links, commonly up to PIRQH.
+
+config IRQ_SLOT_COUNT
+	int
+	default 128
+	help
+	  U-Boot can support up to 254 IRQ slot info in the PIRQ routing table
+	  which in turns forms a table of exact 4KiB. The default value 128
+	  should be enough for most boards. If this does not fit your board,
+	  change it according to your needs.
+
 source "board/coreboot/coreboot/Kconfig"
 
 source "board/google/chromebook_link/Kconfig"
arch/x86/include/asm/pirq_routing.h new file +139 -0

139 lines not on this page · raw message

arch/x86/lib/Makefile +1 -0
index 0de0d89..0178fe1 100644
@@ -22,6 +22,7 @@ ifndef CONFIG_DM_PCI
 obj-$(CONFIG_PCI) += pci_type1.o
 endif
 obj-y	+= pch-uclass.o
+obj-y	+= pirq_routing.o
 obj-y	+= relocate.o
 obj-y += physmem.o
 obj-$(CONFIG_X86_RAMTEST) += ramtest.o
arch/x86/lib/pirq_routing.c new file +129 -0

129 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#6 lore raw

PATCH v2 3/4 x86: Support platform PIRQ routing

Quoted 16 lines · Bin Meng

On x86 boards, platform chipset receives up to four different interrupt signals from PCI devices (INTA/B/C/D), which in turn will be routed to chipset internal PIRQ lines then routed to 8259 PIC finally if configuring the whole system to work under the so-called PIC mode (in contrast to symmetric IO mode which uses IOAPIC).

We add two major APIs to aid this, one for routing PIRQ and the other one for generating a PIRQ routing table.

---

Changes in v2: None

Quoted 7 lines
 arch/x86/Kconfig                    |  31 ++++++++
 arch/x86/include/asm/pirq_routing.h | 139 ++++++++++++++++++++++++++++++++++++
 arch/x86/lib/Makefile               |   1 +
 arch/x86/lib/pirq_routing.c         | 129 +++++++++++++++++++++++++++++++++
 4 files changed, 300 insertions(+)
 create mode 100644 arch/x86/include/asm/pirq_routing.h
 create mode 100644 arch/x86/lib/pirq_routing.c

Applied to u-boot-x86, thanks!

author
#7 lore raw

PATCH v2 4/4 x86: queensbay: Implement PIRQ routing

In reply to a message not in the archive

Implement Intel Queensbay platform-specific PIRQ routing support. The chipset PIRQ routing setup is called in the arch_misc_init().

---

Changes in v2:
- Correct a typo in the commit message
- Use a local variable in fill_irq_info()
- Print a debug message if creating pirq table fails
- Use a C structure for RCBA register access

 arch/x86/cpu/queensbay/Makefile              |   2 +-
 arch/x86/cpu/queensbay/irq.c                 | 242 +++++++++++++++++++++++++++
 arch/x86/cpu/queensbay/tnc.c                 |  10 +-
 arch/x86/include/asm/arch-queensbay/device.h |  94 +++++++++++
 arch/x86/include/asm/arch-queensbay/irq.h    |  55 ++++++
 arch/x86/include/asm/arch-queensbay/tnc.h    |  39 ++++-
 arch/x86/include/asm/u-boot-x86.h            |   2 +
 configs/crownbay_defconfig                   |   1 +
 include/configs/crownbay.h                   |   1 +
 9 files changed, 442 insertions(+), 4 deletions(-)
 create mode 100644 arch/x86/cpu/queensbay/irq.c
 create mode 100644 arch/x86/include/asm/arch-queensbay/device.h
 create mode 100644 arch/x86/include/asm/arch-queensbay/irq.h
arch/x86/cpu/queensbay/Makefile +1 -1
index d8761fd..4599a48 100644
@@ -5,5 +5,5 @@
 #
 
 obj-y += fsp_configs.o
-obj-y += tnc.o topcliff.o
+obj-y += irq.o tnc.o topcliff.o
 obj-$(CONFIG_PCI) += tnc_pci.o
arch/x86/cpu/queensbay/irq.c new file +242 -0

242 lines not on this page · raw message

arch/x86/cpu/queensbay/tnc.c +9 -1
index f756a0d..b46a7e9 100644
@@ -8,7 +8,8 @@
 #include <asm/io.h>
 #include <asm/pci.h>
 #include <asm/post.h>
-#include <asm/arch/tnc.h>
+#include <asm/arch/device.h>
+#include <asm/arch/irq.h>
 #include <asm/fsp/fsp_support.h>
 #include <asm/processor.h>
 
@@ -43,3 +44,10 @@ int arch_cpu_init(void)
 
 	return 0;
 }
+
+int arch_misc_init(void)
+{
+	pirq_init();
+
+	return 0;
+}
arch/x86/include/asm/arch-queensbay/device.h new file +94 -0

94 lines not on this page · raw message

arch/x86/include/asm/arch-queensbay/irq.h new file +55 -0

55 lines not on this page · raw message

arch/x86/include/asm/arch-queensbay/tnc.h +37 -2
index 10ea51d..ad9a6c4 100644
@@ -7,8 +7,43 @@
 #ifndef _X86_ARCH_TNC_H_
 #define _X86_ARCH_TNC_H_
 
-#include <pci.h>
+/* Memory BAR Enable */
+#define MEM_BAR_EN	0x00000001
 
-#define TNC_LPC		PCI_BDF(0, 31, 0)
+/* LPC PCI Configuration Registers */
+#define LPC_RCBA	0xf0
+
+/* Root Complex Register Block */
+struct tnc_rcba {
+	u32	rctl;
+	u32	esd;
+	u32	rsvd1[2];
+	u32	hdd;
+	u32	rsvd2;
+	u32	hdba;
+	u32	rsvd3[3129];
+	u32	d31ip;
+	u32	rsvd4[3];
+	u32	d27ip;
+	u32	rsvd5;
+	u32	d02ip;
+	u32	rsvd6;
+	u32	d26ip;
+	u32	d25ip;
+	u32	d24ip;
+	u32	d23ip;
+	u32	d03ip;
+	u32	rsvd7[3];
+	u16	d31ir;
+	u16	rsvd8[3];
+	u16	d27ir;
+	u16	d26ir;
+	u16	d25ir;
+	u16	d24ir;
+	u16	d23ir;
+	u16	rsvd9[7];
+	u16	d02ir;
+	u16	d03ir;
+};
 
 #endif /* _X86_ARCH_TNC_H_ */
arch/x86/include/asm/u-boot-x86.h +2 -0
index c743efd..122e054 100644
@@ -53,6 +53,8 @@ int video_bios_init(void);
 void	board_init_f_r_trampoline(ulong) __attribute__ ((noreturn));
 void	board_init_f_r(void) __attribute__ ((noreturn));
 
+int arch_misc_init(void);
+
 /* Read the time stamp counter */
 static inline __attribute__((no_instrument_function)) uint64_t rdtsc(void)
 {
configs/crownbay_defconfig +1 -0
index ce90553..47763f9 100644
@@ -4,3 +4,4 @@ CONFIG_TARGET_CROWNBAY=y
 CONFIG_OF_CONTROL=y
 CONFIG_OF_SEPARATE=y
 CONFIG_DEFAULT_DEVICE_TREE="crownbay"
+CONFIG_GENERATE_PIRQ_TABLE=y
include/configs/crownbay.h +1 -0
index 42042d1..4fef433 100644
@@ -15,6 +15,7 @@
 
 #define CONFIG_SYS_MONITOR_LEN		(1 << 20)
 #define CONFIG_BOARD_EARLY_INIT_F
+#define CONFIG_ARCH_MISC_INIT
 
 #define CONFIG_NR_DRAM_BANKS		1
 
Signature · 1 line
1.8.2.1
#8 lore raw

PATCH v2 4/4 x86: queensbay: Implement PIRQ routing

Quoted 13 lines · Bin Meng

Implement Intel Queensbay platform-specific PIRQ routing support. The chipset PIRQ routing setup is called in the arch_misc_init().

---

Changes in v2:
- Correct a typo in the commit message
- Use a local variable in fill_irq_info()
- Print a debug message if creating pirq table fails
- Use a C structure for RCBA register access

Quoted 13 lines
 arch/x86/cpu/queensbay/Makefile              |   2 +-
 arch/x86/cpu/queensbay/irq.c                 | 242 +++++++++++++++++++++++++++
 arch/x86/cpu/queensbay/tnc.c                 |  10 +-
 arch/x86/include/asm/arch-queensbay/device.h |  94 +++++++++++
 arch/x86/include/asm/arch-queensbay/irq.h    |  55 ++++++
 arch/x86/include/asm/arch-queensbay/tnc.h    |  39 ++++-
 arch/x86/include/asm/u-boot-x86.h            |   2 +
 configs/crownbay_defconfig                   |   1 +
 include/configs/crownbay.h                   |   1 +
 9 files changed, 442 insertions(+), 4 deletions(-)
 create mode 100644 arch/x86/cpu/queensbay/irq.c
 create mode 100644 arch/x86/include/asm/arch-queensbay/device.h
 create mode 100644 arch/x86/include/asm/arch-queensbay/irq.h
#9 lore raw

PATCH v2 4/4 x86: queensbay: Implement PIRQ routing

Quoted 28 lines · Simon Glass
Quoted 13 lines · Bin Meng

Implement Intel Queensbay platform-specific PIRQ routing support. The chipset PIRQ routing setup is called in the arch_misc_init().

---

Changes in v2:
- Correct a typo in the commit message
- Use a local variable in fill_irq_info()
- Print a debug message if creating pirq table fails
- Use a C structure for RCBA register access

Quoted 13 lines
 arch/x86/cpu/queensbay/Makefile              |   2 +-
 arch/x86/cpu/queensbay/irq.c                 | 242 +++++++++++++++++++++++++++
 arch/x86/cpu/queensbay/tnc.c                 |  10 +-
 arch/x86/include/asm/arch-queensbay/device.h |  94 +++++++++++
 arch/x86/include/asm/arch-queensbay/irq.h    |  55 ++++++
 arch/x86/include/asm/arch-queensbay/tnc.h    |  39 ++++-
 arch/x86/include/asm/u-boot-x86.h            |   2 +
 configs/crownbay_defconfig                   |   1 +
 include/configs/crownbay.h                   |   1 +
 9 files changed, 442 insertions(+), 4 deletions(-)
 create mode 100644 arch/x86/cpu/queensbay/irq.c
 create mode 100644 arch/x86/include/asm/arch-queensbay/device.h
 create mode 100644 arch/x86/include/asm/arch-queensbay/irq.h
Quoted 1 line

Applied to u-boot-x86, thanks!