Skip to content

Commit d8b7427

Browse files
aakoskinralfbaechle
authored andcommitted
MIPS: cavium-octeon: fix I/O space setup on non-PCI systems
Fix I/O space setup, so that on non-PCI systems using inb()/outb() won't crash the system. Some drivers may try to probe I/O space and for that purpose we can just allocate some normal memory initially. Drivers trying to reserve a region will fail early as we set the size to 0. If a real I/O space is present, the PCI/PCIe support code will re-adjust the values accordingly. Tested with EdgeRouter Lite by enabling CONFIG_SERIO_I8042 that caused the originally reported crash. Reported-by: Faidon Liambotis <paravoid@debian.org> Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi> Acked-by: David Daney <david.daney@cavium.com> Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/5626/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent 83eefab commit d8b7427

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

‎arch/mips/cavium-octeon/setup.c‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* written by Ralf Baechle <ralf@linux-mips.org>
99
*/
1010
#include <linux/compiler.h>
11+
#include <linux/vmalloc.h>
1112
#include <linux/init.h>
1213
#include <linux/kernel.h>
1314
#include <linux/console.h>
@@ -1139,3 +1140,30 @@ static int __init edac_devinit(void)
11391140
return err;
11401141
}
11411142
device_initcall(edac_devinit);
1143+
1144+
static void __initdata *octeon_dummy_iospace;
1145+
1146+
static int __init octeon_no_pci_init(void)
1147+
{
1148+
/*
1149+
* Initially assume there is no PCI. The PCI/PCIe platform code will
1150+
* later re-initialize these to correct values if they are present.
1151+
*/
1152+
octeon_dummy_iospace = vzalloc(IO_SPACE_LIMIT);
1153+
set_io_port_base((unsigned long)octeon_dummy_iospace);
1154+
ioport_resource.start = MAX_RESOURCE;
1155+
ioport_resource.end = 0;
1156+
return 0;
1157+
}
1158+
core_initcall(octeon_no_pci_init);
1159+
1160+
static int __init octeon_no_pci_release(void)
1161+
{
1162+
/*
1163+
* Release the allocated memory if a real IO space is there.
1164+
*/
1165+
if ((unsigned long)octeon_dummy_iospace != mips_io_port_base)
1166+
vfree(octeon_dummy_iospace);
1167+
return 0;
1168+
}
1169+
late_initcall(octeon_no_pci_release);

‎arch/mips/pci/pci-octeon.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -586,15 +586,16 @@ static int __init octeon_pci_setup(void)
586586
else
587587
octeon_dma_bar_type = OCTEON_DMA_BAR_TYPE_BIG;
588588

589-
/* PCI I/O and PCI MEM values */
590-
set_io_port_base(OCTEON_PCI_IOSPACE_BASE);
591-
ioport_resource.start = 0;
592-
ioport_resource.end = OCTEON_PCI_IOSPACE_SIZE - 1;
593589
if (!octeon_is_pci_host()) {
594590
pr_notice("Not in host mode, PCI Controller not initialized\n");
595591
return 0;
596592
}
597593

594+
/* PCI I/O and PCI MEM values */
595+
set_io_port_base(OCTEON_PCI_IOSPACE_BASE);
596+
ioport_resource.start = 0;
597+
ioport_resource.end = OCTEON_PCI_IOSPACE_SIZE - 1;
598+
598599
pr_notice("%s Octeon big bar support\n",
599600
(octeon_dma_bar_type ==
600601
OCTEON_DMA_BAR_TYPE_BIG) ? "Enabling" : "Disabling");

0 commit comments

Comments
 (0)