Skip to contentSkip to conversation

Change PCI host bridge setup/resources

PATCH In review Thomas Bogendoerfer 4 participants 8 messages Apr 8, 2007 – Apr 10, 2007 MIPS

lore
Share & tools
lore

Thomas Bogendoerfer

author maintainer
#0 lore raw

PATCH 1/1 Change PCI host bridge setup/resources

PCI host bridge setup for SNI RM machines with PCI is quite broken, now that Linux does it's resource setup own its own. It will use IO addresses, which are needed by the EISA config detection and assigns PCI memory addresses, which overlap with ISA legacy addresses (video ram). Below is a patch, which changes the way how the PCI memory addresses are used and sets the minimum IO address to give enough IO space for 8 EISA slots). This patch needs the other PCI resource change, I've posted.

---

arch/mips/sni/pcit.c +22 -100
index 1dfc3f0..00d151f 100644
@@ -43,7 +43,7 @@ static struct platform_device pcit_serial8250_device = {
 };
 
 static struct plat_serial8250_port pcit_cplus_data[] = {
-	PORT(0x3f8, 4),
+	PORT(0x3f8, 0),
 	PORT(0x2f8, 3),
 	PORT(0x3e8, 4),
 	PORT(0x2e8, 3),
@@ -59,9 +59,9 @@ static struct platform_device pcit_cplus_serial8250_device = {
 };
 
 static struct resource sni_io_resource = {
-	.start	= 0x00001000UL,
+	.start	= 0x00000000UL,
 	.end	= 0x03bfffffUL,
-	.name	= "PCIT IO MEM",
+	.name	= "PCIT IO",
 	.flags	= IORESOURCE_IO,
 };
 
@@ -92,6 +92,11 @@ static struct resource pcit_io_resources[] = {
 		.name	= "dma2",
 		.flags	= IORESOURCE_BUSY
 	}, {
+		.start	=  0xcf8,
+		.end	= 0xcfb,
+		.name	= "PCI config addr",
+		.flags	= IORESOURCE_BUSY
+	}, {
 		.start	=  0xcfc,
 		.end	= 0xcff,
 		.name	= "PCI config data",
@@ -100,107 +105,19 @@ static struct resource pcit_io_resources[] = {
 };
 
 static struct resource sni_mem_resource = {
-	.start	= 0x10000000UL,
-	.end	= 0xffffffffUL,
+	.start	= 0x18000000UL,
+	.end	= 0x1fbfffffUL,
 	.name	= "PCIT PCI MEM",
 	.flags	= IORESOURCE_MEM
 };
 
-/*
- * The RM200/RM300 has a few holes in it's PCI/EISA memory address space used
- * for other purposes.  Be paranoid and allocate all of the before the PCI
- * code gets a chance to to map anything else there ...
- *
- * This leaves the following areas available:
- *
- * 0x10000000 - 0x1009ffff (640kB) PCI/EISA/ISA Bus Memory
- * 0x10100000 - 0x13ffffff ( 15MB) PCI/EISA/ISA Bus Memory
- * 0x18000000 - 0x1fbfffff (124MB) PCI/EISA Bus Memory
- * 0x1ff08000 - 0x1ffeffff (816kB) PCI/EISA Bus Memory
- * 0xa0000000 - 0xffffffff (1.5GB) PCI/EISA Bus Memory
- */
-static struct resource pcit_mem_resources[] = {
-	{
-		.start	= 0x14000000,
-		.end	= 0x17bfffff,
-		.name	= "PCI IO",
-		.flags	= IORESOURCE_BUSY
-	}, {
-		.start	= 0x17c00000,
-		.end	= 0x17ffffff,
-		.name	= "Cache Replacement Area",
-		.flags	= IORESOURCE_BUSY
-	}, {
-		.start	= 0x180a0000,
-		.end	= 0x180bffff,
-		.name	= "Video RAM area",
-		.flags	= IORESOURCE_BUSY
-	}, {
-		.start	= 0x180c0000,
-		.end	= 0x180fffff,
-		.name	= "ISA Reserved",
-		.flags	= IORESOURCE_BUSY
-	}, {
-		.start	= 0x19000000,
-		.end	= 0x1fbfffff,
-		.name	= "PCI MEM",
-		.flags	= IORESOURCE_BUSY
-	}, {
-		.start	= 0x1fc00000,
-		.end	= 0x1fc7ffff,
-		.name	= "Boot PROM",
-		.flags	= IORESOURCE_BUSY
-	}, {
-		.start	= 0x1fc80000,
-		.end	= 0x1fcfffff,
-		.name	= "Diag PROM",
-		.flags	= IORESOURCE_BUSY
-	}, {
-		.start	= 0x1fd00000,
-		.end	= 0x1fdfffff,
-		.name	= "X-Bus",
-		.flags	= IORESOURCE_BUSY
-	}, {
-		.start	= 0x1fe00000,
-		.end	= 0x1fefffff,
-		.name	= "BIOS map",
-		.flags	= IORESOURCE_BUSY
-	}, {
-		.start	= 0x1ff00000,
-		.end	= 0x1ff7ffff,
-		.name	= "NVRAM / EEPROM",
-		.flags	= IORESOURCE_BUSY
-	}, {
-		.start	= 0x1fff0000,
-		.end	= 0x1fffefff,
-		.name	= "MAUI ASIC",
-		.flags	= IORESOURCE_BUSY
-	}, {
-		.start	= 0x1ffff000,
-		.end	= 0x1fffffff,
-		.name	= "MP Agent",
-		.flags	= IORESOURCE_BUSY
-	}, {
-		.start	= 0x20000000,
-		.end	= 0x9fffffff,
-		.name	= "Main Memory",
-		.flags	= IORESOURCE_BUSY
-	}
-};
-
 static void __init sni_pcit_resource_init(void)
 {
 	int i;
 
 	/* request I/O space for devices used on all i[345]86 PCs */
 	for (i = 0; i < ARRAY_SIZE(pcit_io_resources); i++)
-		request_resource(&ioport_resource, pcit_io_resources + i);
-
-	/* request mem space for pcimt-specific devices */
-	for (i = 0; i < ARRAY_SIZE(pcit_mem_resources); i++)
-		request_resource(&sni_mem_resource, pcit_mem_resources + i);
-
-	ioport_resource.end = sni_io_resource.end;
+		request_resource(&sni_io_resource, pcit_io_resources + i);
 }
 
 
@@ -209,9 +126,10 @@ extern struct pci_ops sni_pcit_ops;
 static struct pci_controller sni_pcit_controller = {
 	.pci_ops	= &sni_pcit_ops,
 	.mem_resource	= &sni_mem_resource,
-	.mem_offset	= 0x10000000UL,
+	.mem_offset	= 0x00000000UL,
 	.io_resource	= &sni_io_resource,
-	.io_offset	= 0x00000000UL
+	.io_offset	= 0x00000000UL,
+	.io_map_base    = SNI_PORT_BASE
 };
 
 static void enable_pcit_irq(unsigned int irq)
@@ -262,7 +180,7 @@ static void pcit_hwint0(void)
 	int irq;
 
 	clear_c0_status(IE_IRQ0);
-	irq = ffs((pending >> 16) & 0x7f);
+	irq = ffs((pending >> 16) & 0x3f);
 
 	if (likely(irq > 0))
 		do_IRQ (irq + SNI_PCIT_INT_START - 1);
@@ -289,6 +207,8 @@ static void sni_pcit_hwint_cplus(void)
 
 	if (pending & C_IRQ0)
 		pcit_hwint0();
+	else if (pending & C_IRQ1)
+		do_IRQ (MIPS_CPU_IRQ_BASE + 3);
 	else if (pending & C_IRQ2)
 		do_IRQ (MIPS_CPU_IRQ_BASE + 4);
 	else if (pending & C_IRQ3)
@@ -317,21 +237,23 @@ void __init sni_pcit_cplus_irq_init(void)
 	mips_cpu_irq_init();
 	for (i = SNI_PCIT_INT_START; i <= SNI_PCIT_INT_END; i++)
 		set_irq_chip(i, &pcit_irq_type);
-	*(volatile u32 *)SNI_PCIT_INT_REG = 0;
+	*(volatile u32 *)SNI_PCIT_INT_REG = 0x40000000;
 	sni_hwint = sni_pcit_hwint_cplus;
 	change_c0_status(ST0_IM, IE_IRQ0);
-	setup_irq (SNI_PCIT_INT_START + 6, &sni_isa_irq);
+	setup_irq (MIPS_CPU_IRQ_BASE + 3, &sni_isa_irq);
 }
 
 void sni_pcit_init(void)
 {
-	sni_pcit_resource_init();
 	rtc_mips_get_time = mc146818_get_cmos_time;
 	rtc_mips_set_time = mc146818_set_rtc_mmss;
 	board_time_init = sni_cpu_time_init;
+	ioport_resource.end = sni_io_resource.end;
 #ifdef CONFIG_PCI
+	PCIBIOS_MIN_IO = 0x9000;
 	register_pci_controller(&sni_pcit_controller);
 #endif
+	sni_pcit_resource_init();
 }
 
 static int __init snirm_pcit_setup_devinit(void)
arch/mips/sni/pcimt.c +10 -95

148 lines not on this page · raw message

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessary a
good idea.                                                [ RFC1925, 2.3 ]
#1 lore raw
Quoted 14 lines · Thomas Bogendoerfer

PCI host bridge setup for SNI RM machines with PCI is quite broken, now that Linux does it's resource setup own its own. It will use IO addresses, which are needed by the EISA config detection and assigns PCI memory addresses, which overlap with ISA legacy addresses (video ram). Below is a patch, which changes the way how the PCI memory addresses are used and sets the minimum IO address to give enough IO space for 8 EISA slots). This patch needs the other PCI resource change, I've posted.

arch/mips/sni/pcit.c +0 -0
index 1dfc3f0..00d151f 100644

arch/mips/sni/pcit.c static struct platform_device pcit_serial8250_device = { · line 49

Quoted 8 lines
arch/mips/sni/pcit.c +1 -1
@@ -43,7 +43,7 @@ static struct platform_device pcit_serial8250_device = {
 };
 
 static struct plat_serial8250_port pcit_cplus_data[] = {
-	PORT(0x3f8, 4),
+	PORT(0x3f8, 0),
 	PORT(0x2f8, 3),
 	PORT(0x3e8, 4),
 	PORT(0x2e8, 3),

Hm, what is that -- UART #1 without IRQ?

arch/mips/sni/pcit.c static struct platform_device pcit_cplus_serial8250_device = { · line 66

Quoted 11 lines
arch/mips/sni/pcit.c +2 -2
@@ -59,9 +59,9 @@ static struct platform_device pcit_cplus_serial8250_device = {
 };
 
 static struct resource sni_io_resource = {
-	.start	= 0x00001000UL,
+	.start	= 0x00000000UL,
 	.end	= 0x03bfffffUL,
-	.name	= "PCIT IO MEM",
+	.name	= "PCIT IO",
 	.flags	= IORESOURCE_IO,
 };

Why us this necessary, only beacuse compatible peripherals are behind PCI?
EISA is behind PCI as well, yet you're setting PCIBIOS_MIN_IO to 0x9000. Does this all really make sense? :-/

arch/mips/sni/pcit.c static struct resource pcit_io_resources[] = { · line 99

Quoted 9 lines
arch/mips/sni/pcit.c +5 -0
@@ -92,6 +92,11 @@ static struct resource pcit_io_resources[] = {
 		.name	= "dma2",
 		.flags	= IORESOURCE_BUSY
 	}, {
+		.start	=  0xcf8,
+		.end	= 0xcfb,
+		.name	= "PCI config addr",
+		.flags	= IORESOURCE_BUSY
+	}, {

This is certainly *not* a PCI or [E]ISA resource. It's decoded by the
*host* bridge.

arch/mips/sni/pcit.c static struct resource pcit_io_resources[] = { · line 102

Quoted 3 lines
arch/mips/sni/pcit.c +0 -0
 		.start	=  0xcfc,
 		.end	= 0xcff,
 		.name	= "PCI config data",

Well, why not just join them into one?

arch/mips/sni/pcit.c void __init sni_pcit_cplus_irq_init(void) · line 257

Quoted 13 lines

void sni_pcit_init(void)
{

arch/mips/sni/pcit.c +3 -1
-	sni_pcit_resource_init();
 	rtc_mips_get_time = mc146818_get_cmos_time;
 	rtc_mips_set_time = mc146818_set_rtc_mmss;
 	board_time_init = sni_cpu_time_init;
+	ioport_resource.end = sni_io_resource.end;
 #ifdef CONFIG_PCI
+	PCIBIOS_MIN_IO = 0x9000;
 	register_pci_controller(&sni_pcit_controller);
 #endif
+	sni_pcit_resource_init();
 }

WBR, Sergei

author maintainer
#2 lore raw
Quoted 8 lines · Sergei Shtylyov
Quoted 6 lines

static struct plat_serial8250_port pcit_cplus_data[] = {

arch/mips/sni/pcit.c +1 -1
-	PORT(0x3f8, 4),
+	PORT(0x3f8, 0),
	PORT(0x2f8, 3),
	PORT(0x3e8, 4),
	PORT(0x2e8, 3),

Hm, what is that -- UART #1 without IRQ?

workaround for not fully working interrupts on UART1. IRQ 0 means polling. Read the source.

Quoted 5 lines
Quoted 5 lines

static struct resource sni_io_resource = {

(quoted diff) +1 -1
-	.start	= 0x00001000UL,
+	.start	= 0x00000000UL,
	.end	= 0x03bfffffUL,
arch/mips/sni/pcit.c +0 -1
-	.name	= "PCIT IO MEM",
Quoted 8 lines
Quoted 3 lines
arch/mips/sni/pcit.c +1 -0
+	.name	= "PCIT IO",

.flags = IORESOURCE_IO,
};

Why us this necessary, only beacuse compatible peripherals are behind PCI?
EISA is behind PCI as well, yet you're setting PCIBIOS_MIN_IO to 0x9000. Does this all really make sense? :-/

it does, how about reading the PCI code ?

EISA IO address space is 0x0000 - 0xffff, so this IO addresses need to be forwarded by the PCI host bridge. PCIBIOS_MIN_IO is for the PCI address assignment code, and tells this code to start allocating IO space starting at 0x9000. This is needed because the pci eisa code will use n + 0x1000 as EISA slot base addresses, which gives 0x8000 for the 8th (last) slot. So it's IMHO a good idea to avoid collisions between EISA and PCI for IO space.

Quoted 2 lines

This is certainly *not* a PCI or [E]ISA resource. It's decoded by the
*host* bridge.

so ? It's an IO address no device should use, because it won't work. Therefore mark it busy. That's all the code does.

Quoted 5 lines
Quoted 3 lines
		.start	=  0xcfc,
		.end	= 0xcff,
		.name	= "PCI config data",

Well, why not just join them into one?

what's your point ? This stuff is all about giving some hints and avoiding address assignment collisions. I could just drop the whole table and nothing will change, because the PCI code doesn't assign IO addresses below 0x9000. Fine with me, but I think it doesn't hurt to know, what IO addresses are used for some stuff.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessary a
good idea.                                                [ RFC1925, 2.3 ]
#3 lore raw
Quoted 6 lines · Thomas Bogendoerfer
Quoted 2 lines · Sergei Shtylyov

This is certainly *not* a PCI or [E]ISA resource. It's decoded by the
*host* bridge.

so ? It's an IO address no device should use, because it won't work. Therefore mark it busy. That's all the code does.

Yep, it's transparently decoded ISA (which is behind PCI) to control the PCI bus. Just traditional PC legacy hacks :-)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#5 lore raw
In reply to Thomas Bogendoerfer

Hello.

Quoted 11 lines · Thomas Bogendoerfer
Quoted 8 lines
Quoted 6 lines

static struct plat_serial8250_port pcit_cplus_data[] = {

arch/mips/sni/pcit.c +1 -1
-	PORT(0x3f8, 4),
+	PORT(0x3f8, 0),
	PORT(0x2f8, 3),
	PORT(0x3e8, 4),
	PORT(0x2e8, 3),

Hm, what is that -- UART #1 without IRQ?

workaround for not fully working interrupts on UART1. IRQ 0 means polling. Read the source.

Thanks, I've read it quite a lot already. But is UART3 IRQ working (being
the same as UART1's)?

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines

static struct resource sni_io_resource = {

(quoted diff) +1 -1
-	.start	= 0x00001000UL,
+	.start	= 0x00000000UL,
	.end	= 0x03bfffffUL,
Quoted 8 lines
Quoted 4 lines
arch/mips/sni/pcit.c +1 -1
-	.name	= "PCIT IO MEM",
+	.name	= "PCIT IO",

.flags = IORESOURCE_IO,
};

Why us this necessary, only beacuse compatible peripherals are behind
PCI?
EISA is behind PCI as well, yet you're setting PCIBIOS_MIN_IO to 0x9000. Does this all really make sense? :-/

Quoted 1 line

it does, how about reading the PCI code ?

To me, it doesn't make much sense with or without reading the code.
And note that no other boards claim ports 0x0000 thru 0x0fff to PCI.

Quoted 2 lines

EISA IO address space is 0x0000 - 0xffff, so this IO addresses need to be forwarded by the PCI host bridge.

No need to educate me about EISA.

Quoted 3 lines

PCIBIOS_MIN_IO is for the PCI
address assignment code, and tells this code to start allocating IO space starting at 0x9000.

I know that too.

Quoted 4 lines

This is needed because the pci eisa code
will use n + 0x1000 as EISA slot base addresses, which gives 0x8000 for the 8th (last) slot. So it's IMHO a good idea to avoid collisions between EISA and PCI for IO space.

Yeah, and I'd given 0x00009000 as PCI I/O start address for that same
purpose. [E]ISA resources, while being accessed (via PCI bus as a proxy) are generally not a part of PCI bus.

Quoted 5 lines
Quoted 2 lines

This is certainly *not* a PCI or [E]ISA resource. It's decoded by the
*host* bridge.

so ? It's an IO address no device should use, because it won't work. Therefore mark it busy. That's all the code does.

It just shouldn't appear under PCI bus in the resource hierarchy.

Quoted 11 lines
Quoted 5 lines
Quoted 3 lines
		.start	=  0xcfc,
		.end	= 0xcff,
		.name	= "PCI config data",

Well, why not just join them into one?

what's your point ? This stuff is all about giving some hints and avoiding address assignment collisions. I could just drop the whole table and nothing will change, because the PCI code doesn't assign IO addresses below 0x9000. Fine with me, but I think it doesn't hurt to know, what IO addresses are used for some stuff.

You're changing PCI I/O space start address for no apparent reason which
seems to break general 8259 code.

Quoted 1 line

Thomas.

WBR, Sergei

#4 lore raw
In reply to Geert Uytterhoeven

Hello.

Quoted 8 lines · Geert Uytterhoeven
Quoted 5 lines
Quoted 2 lines

This is certainly *not* a PCI or [E]ISA resource. It's decoded by the
*host* bridge.

so ? It's an IO address no device should use, because it won't work. Therefore mark it busy. That's all the code does.

Yep, it's transparently decoded ISA (which is behind PCI) to control the PCI bus. Just traditional PC legacy hacks :-)

Rubbish. I was complaining about the PCI config/data ports at 0xCF8/0xCFC
which are by no means part of either [E]ISA or PCI. They're decoded by the host to PCI bridge.

WBR, Sergei

author maintainer
#6 lore raw
In reply to Sergei Shtylyov
Quoted 5 lines · Sergei Shtylyov
Quoted 2 lines

workaround for not fully working interrupts on UART1. IRQ 0 means polling. Read the source.

Thanks, I've read it quite a lot already. But is UART3 IRQ working (being the same as UART1's)?

right now, none of the ISA interrupts are working on that machine, probably because I'm missing some IRQ routing setup. The workaround is there to get serial console working in userspace.

Quoted 2 lines

To me, it doesn't make much sense with or without reading the code.
And note that no other boards claim ports 0x0000 thru 0x0fff to PCI.

no other board MIPS board has EISA behind PCI afaik. So this is a new situation.

Quoted 3 lines

Yeah, and I'd given 0x00009000 as PCI I/O start address for that same
purpose. [E]ISA resources, while being accessed (via PCI bus as a proxy) are generally not a part of PCI bus.

it would help, if you would try to understand the stuff first. Just read the EISA code...

Quoted 2 lines

You're changing PCI I/O space start address for no apparent reason which
seems to break general 8259 code.

could you try to understand the issue please ? I could leave the i8259 code alone and everything will work as before. Only the entries for the PIC would be missing in /proc/iomem (which I could kludge around by adding them to the pcit/pcimt resource list). Every other platform won't see a difference, because no other platform needs to request the PCI IO space starting at 0x0000.

I've checked the platform device code, and it uses insert_region() like my proposed change for i8259. So I'm pretty sure, that's the way to go.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessary a
good idea.                                                [ RFC1925, 2.3 ]
#7 lore raw
Quoted 5 lines · Thomas Bogendoerfer
Quoted 2 lines

To me, it doesn't make much sense with or without reading the code.
And note that no other boards claim ports 0x0000 thru 0x0fff to PCI.

no other board MIPS board has EISA behind PCI afaik. So this is a new situation.

To everybody involved: quite a few Alpha boxes use the PCEB bridge, which
may or may not be the same as in here, so they may be used as a reference of how things may be set up. Though, being quite an old port, this code may not necessarily represent the best approach possible.

Personally I think ISA and EISA resources that are behind a PCI bus (or
any other, for that matter) should be registered as descendants to that bus. It's only the PC architecture that makes (E)ISA resources special -- almost any other platform will relocate them arbitrarily (they will not start from zero in the host address space, which may even have no notion of the I/O address space at all) and may have multiple copies if multiple PCI buses are used in a non-tree configuration. It may be useful to register PCI I/O windows in the MMIO space as appropriate too.

Also mapping PCI I/O addresses from 0 does make sense in some actual
hardware configurations which do not have any legacy bridges involved, so making sure code is prepared to do this is not an unreasonable thing to do. There is currently (or used to be, not so long ago) a problem with some code somewhere as I tried such a setup with a SWARM board and I recall getting a failure somewhere, which I mean to get back to at one point.

Maciej