Skip to contentSkip to conversation

DMI/APIC updates 2 of 4: boot-time-ioremap

PATCH New Mikael Pettersson 1 participant 1 message Jan 2, 2002

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 DMI/APIC updates 2 of 4: boot-time-ioremap

Linus,

This is part 2 of 4 of a patch set for 2.5.2-pre6 to move the x86 DMI scan to an earlier point in the boot sequence. This is motivated by the UP APIC code, which must be disabled on some machines with broken BIOSen, but there are also other cases that would benefit from it. Tested. Please apply.

This second patch (patch-boot-time-ioremap) implements bt_ioremap(), a clone of ioremap() which works early in the boot process. It requires the boot-time-fixmaps patch I posted previously.

/Mikael

arch/i386/mm/ioremap.c +65 -0
diff -ruN linux-2.5.2-pre6/arch/i386/mm/ioremap.c linux-2.5.2-pre6.boot-time-ioremap/arch/i386/mm/ioremap.c
@@ -161,3 +161,68 @@
 	if (addr > high_memory)
 		return vfree((void *) (PAGE_MASK & (unsigned long) addr));
 }
+
+void __init *bt_ioremap(unsigned long phys_addr, unsigned long size)
+{
+	unsigned long offset, last_addr;
+	unsigned int nrpages;
+	enum fixed_addresses idx;
+
+	/* Don't allow wraparound or zero size */
+	last_addr = phys_addr + size - 1;
+	if (!size || last_addr < phys_addr)
+		return NULL;
+
+	/*
+	 * Don't remap the low PCI/ISA area, it's always mapped..
+	 */
+	if (phys_addr >= 0xA0000 && last_addr < 0x100000)
+		return phys_to_virt(phys_addr);
+
+	/*
+	 * Mappings have to be page-aligned
+	 */
+	offset = phys_addr & ~PAGE_MASK;
+	phys_addr &= PAGE_MASK;
+	size = PAGE_ALIGN(last_addr) - phys_addr;
+
+	/*
+	 * Mappings have to fit in the FIX_BTMAP area.
+	 */
+	nrpages = size >> PAGE_SHIFT;
+	if (nrpages > NR_FIX_BTMAPS)
+		return NULL;
+
+	/*
+	 * Ok, go for it..
+	 */
+	idx = FIX_BTMAP_BEGIN;
+	while (nrpages > 0) {
+		set_fixmap(idx, phys_addr);
+		phys_addr += PAGE_SIZE;
+		--idx;
+		--nrpages;
+	}
+	return (void*) (offset + fix_to_virt(FIX_BTMAP_BEGIN));
+}
+
+void __init bt_iounmap(void *addr, unsigned long size)
+{
+	unsigned long virt_addr;
+	unsigned long offset;
+	unsigned int nrpages;
+	enum fixed_addresses idx;
+
+	virt_addr = (unsigned long)addr;
+	if (virt_addr < fix_to_virt(FIX_BTMAP_BEGIN))
+		return;
+	offset = virt_addr & ~PAGE_MASK;
+	nrpages = PAGE_ALIGN(offset + size - 1) >> PAGE_SHIFT;
+
+	idx = FIX_BTMAP_BEGIN;
+	while (nrpages > 0) {
+		__set_fixmap(idx, 0, __pgprot(0));
+		--idx;
+		--nrpages;
+	}
+}
include/asm-i386/io.h +8 -0
diff -ruN linux-2.5.2-pre6/include/asm-i386/io.h linux-2.5.2-pre6.boot-time-ioremap/include/asm-i386/io.h
@@ -95,6 +95,14 @@
 extern void iounmap(void *addr);
 
 /*
+ * bt_ioremap() and bt_iounmap() are for temporary early boot-time
+ * mappings, before the real ioremap() is functional.
+ * A boot-time mapping is currently limited to at most 16 pages.
+ */
+extern void *bt_ioremap(unsigned long offset, unsigned long size);
+extern void bt_iounmap(void *addr, unsigned long size);
+
+/*
  * IO bus memory addresses are also 1:1 with the physical address
  */
 #define virt_to_bus virt_to_phys