x86: ioremap(), extend check to all RAM pages
[sfrench/cifs-2.6.git] / arch / x86 / mm / ioremap.c
index ac3c959e271d2e6e4f16875f0c20b6f792bb8c88..e5608d380176e4bf0e0a3b3f1d0286094641593d 100644 (file)
@@ -35,6 +35,18 @@ unsigned long __phys_addr(unsigned long x)
 }
 EXPORT_SYMBOL(__phys_addr);
 
+static inline int phys_addr_valid(unsigned long addr)
+{
+       return addr < (1UL << boot_cpu_data.x86_phys_bits);
+}
+
+#else
+
+static inline int phys_addr_valid(unsigned long addr)
+{
+       return 1;
+}
+
 #endif
 
 int page_is_ram(unsigned long pagenr)
@@ -106,7 +118,7 @@ static int ioremap_change_attr(unsigned long vaddr, unsigned long size,
  * have to convert them into an offset in a page-aligned mapping, but the
  * caller shouldn't need to know that small detail.
  */
-static void __iomem *__ioremap(unsigned long phys_addr, unsigned long size,
+static void __iomem *__ioremap(resource_size_t phys_addr, unsigned long size,
                               enum ioremap_mode mode)
 {
        unsigned long pfn, offset, last_addr, vaddr;
@@ -118,6 +130,13 @@ static void __iomem *__ioremap(unsigned long phys_addr, unsigned long size,
        if (!size || last_addr < phys_addr)
                return NULL;
 
+       if (!phys_addr_valid(phys_addr)) {
+               printk(KERN_WARNING "ioremap: invalid physical address %lx\n",
+                      phys_addr);
+               WARN_ON_ONCE(1);
+               return NULL;
+       }
+
        /*
         * Don't remap the low PCI/ISA area, it's always mapped..
         */
@@ -127,19 +146,22 @@ static void __iomem *__ioremap(unsigned long phys_addr, unsigned long size,
        /*
         * Don't allow anybody to remap normal RAM that we're using..
         */
-       for (pfn = phys_addr >> PAGE_SHIFT; pfn < max_pfn_mapped &&
-            (pfn << PAGE_SHIFT) < last_addr; pfn++) {
+       for (pfn = phys_addr >> PAGE_SHIFT;
+                               (pfn << PAGE_SHIFT) < last_addr; pfn++) {
+
                if (page_is_ram(pfn) && pfn_valid(pfn) &&
                    !PageReserved(pfn_to_page(pfn)))
                        return NULL;
        }
 
-       WARN_ON_ONCE(page_is_ram(pfn));
-
        switch (mode) {
        case IOR_MODE_UNCACHED:
        default:
-               prot = PAGE_KERNEL_NOCACHE;
+               /*
+                * FIXME: we will use UC MINUS for now, as video fb drivers
+                * depend on it. Upcoming ioremap_wc() will fix this behavior.
+                */
+               prot = PAGE_KERNEL_UC_MINUS;
                break;
        case IOR_MODE_CACHED:
                prot = PAGE_KERNEL;
@@ -195,13 +217,13 @@ static void __iomem *__ioremap(unsigned long phys_addr, unsigned long size,
  *
  * Must be freed with iounmap.
  */
-void __iomem *ioremap_nocache(unsigned long phys_addr, unsigned long size)
+void __iomem *ioremap_nocache(resource_size_t phys_addr, unsigned long size)
 {
        return __ioremap(phys_addr, size, IOR_MODE_UNCACHED);
 }
 EXPORT_SYMBOL(ioremap_nocache);
 
-void __iomem *ioremap_cache(unsigned long phys_addr, unsigned long size)
+void __iomem *ioremap_cache(resource_size_t phys_addr, unsigned long size)
 {
        return __ioremap(phys_addr, size, IOR_MODE_CACHED);
 }
@@ -270,8 +292,8 @@ static int __init early_ioremap_debug_setup(char *str)
 early_param("early_ioremap_debug", early_ioremap_debug_setup);
 
 static __initdata int after_paging_init;
-static __initdata pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)]
-                               __attribute__((aligned(PAGE_SIZE)));
+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)]
+               __section(.bss.page_aligned);
 
 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
 {