ioremap.c (b855192c08fcb14adbc5d3a7cab182022d433cca) ioremap.c (78c86e5e5691fc84d5fbea0cd4ac7147e87b7490)
1/*
2 * Re-map IO memory to kernel address space so that we can access it.
3 * This is needed for high PCI addresses that aren't mapped in the
4 * 640k-1MB IO memory area on PC's
5 *
6 * (C) Copyright 1995 1996 Linus Torvalds
7 */
8

--- 8 unchanged lines hidden (view full) ---

17#include <asm/cacheflush.h>
18#include <asm/e820.h>
19#include <asm/fixmap.h>
20#include <asm/pgtable.h>
21#include <asm/tlbflush.h>
22#include <asm/pgalloc.h>
23#include <asm/pat.h>
24
1/*
2 * Re-map IO memory to kernel address space so that we can access it.
3 * This is needed for high PCI addresses that aren't mapped in the
4 * 640k-1MB IO memory area on PC's
5 *
6 * (C) Copyright 1995 1996 Linus Torvalds
7 */
8

--- 8 unchanged lines hidden (view full) ---

17#include <asm/cacheflush.h>
18#include <asm/e820.h>
19#include <asm/fixmap.h>
20#include <asm/pgtable.h>
21#include <asm/tlbflush.h>
22#include <asm/pgalloc.h>
23#include <asm/pat.h>
24
25static inline int phys_addr_valid(resource_size_t addr)
26{
27#ifdef CONFIG_PHYS_ADDR_T_64BIT
28 return !(addr >> boot_cpu_data.x86_phys_bits);
29#else
30 return 1;
31#endif
32}
25#include "physaddr.h"
33
26
34#ifdef CONFIG_X86_64
35
36unsigned long __phys_addr(unsigned long x)
37{
38 if (x >= __START_KERNEL_map) {
39 x -= __START_KERNEL_map;
40 VIRTUAL_BUG_ON(x >= KERNEL_IMAGE_SIZE);
41 x += phys_base;
42 } else {
43 VIRTUAL_BUG_ON(x < PAGE_OFFSET);
44 x -= PAGE_OFFSET;
45 VIRTUAL_BUG_ON(!phys_addr_valid(x));
46 }
47 return x;
48}
49EXPORT_SYMBOL(__phys_addr);
50
51bool __virt_addr_valid(unsigned long x)
52{
53 if (x >= __START_KERNEL_map) {
54 x -= __START_KERNEL_map;
55 if (x >= KERNEL_IMAGE_SIZE)
56 return false;
57 x += phys_base;
58 } else {
59 if (x < PAGE_OFFSET)
60 return false;
61 x -= PAGE_OFFSET;
62 if (!phys_addr_valid(x))
63 return false;
64 }
65
66 return pfn_valid(x >> PAGE_SHIFT);
67}
68EXPORT_SYMBOL(__virt_addr_valid);
69
70#else
71
72#ifdef CONFIG_DEBUG_VIRTUAL
73unsigned long __phys_addr(unsigned long x)
74{
75 /* VMALLOC_* aren't constants */
76 VIRTUAL_BUG_ON(x < PAGE_OFFSET);
77 VIRTUAL_BUG_ON(__vmalloc_start_set && is_vmalloc_addr((void *) x));
78 return x - PAGE_OFFSET;
79}
80EXPORT_SYMBOL(__phys_addr);
81#endif
82
83bool __virt_addr_valid(unsigned long x)
84{
85 if (x < PAGE_OFFSET)
86 return false;
87 if (__vmalloc_start_set && is_vmalloc_addr((void *) x))
88 return false;
89 if (x >= FIXADDR_START)
90 return false;
91 return pfn_valid((x - PAGE_OFFSET) >> PAGE_SHIFT);
92}
93EXPORT_SYMBOL(__virt_addr_valid);
94
95#endif
96
97int page_is_ram(unsigned long pagenr)
98{
99 resource_size_t addr, end;
100 int i;
101
102 /*
103 * A special case is the first 4Kb of memory;
104 * This is a BIOS owned area, not kernel ram, but generally

--- 118 unchanged lines hidden (view full) ---

223 */
224 offset = phys_addr & ~PAGE_MASK;
225 phys_addr &= PAGE_MASK;
226 size = PAGE_ALIGN(last_addr+1) - phys_addr;
227
228 retval = reserve_memtype(phys_addr, (u64)phys_addr + size,
229 prot_val, &new_prot_val);
230 if (retval) {
27int page_is_ram(unsigned long pagenr)
28{
29 resource_size_t addr, end;
30 int i;
31
32 /*
33 * A special case is the first 4Kb of memory;
34 * This is a BIOS owned area, not kernel ram, but generally

--- 118 unchanged lines hidden (view full) ---

153 */
154 offset = phys_addr & ~PAGE_MASK;
155 phys_addr &= PAGE_MASK;
156 size = PAGE_ALIGN(last_addr+1) - phys_addr;
157
158 retval = reserve_memtype(phys_addr, (u64)phys_addr + size,
159 prot_val, &new_prot_val);
160 if (retval) {
231 printk(KERN_ERR "ioremap reserve_memtype failed %d\n", retval);
161 pr_debug("Warning: reserve_memtype returned %d\n", retval);
232 return NULL;
233 }
234
235 if (prot_val != new_prot_val) {
162 return NULL;
163 }
164
165 if (prot_val != new_prot_val) {
236 if (!is_new_memtype_allowed(phys_addr, size,
237 prot_val, new_prot_val)) {
238 printk(KERN_ERR
166 /*
167 * Do not fallback to certain memory types with certain
168 * requested type:
169 * - request is uc-, return cannot be write-back
170 * - request is uc-, return cannot be write-combine
171 * - request is write-combine, return cannot be write-back
172 */
173 if ((prot_val == _PAGE_CACHE_UC_MINUS &&
174 (new_prot_val == _PAGE_CACHE_WB ||
175 new_prot_val == _PAGE_CACHE_WC)) ||
176 (prot_val == _PAGE_CACHE_WC &&
177 new_prot_val == _PAGE_CACHE_WB)) {
178 pr_debug(
239 "ioremap error for 0x%llx-0x%llx, requested 0x%lx, got 0x%lx\n",
240 (unsigned long long)phys_addr,
241 (unsigned long long)(phys_addr + size),
242 prot_val, new_prot_val);
243 free_memtype(phys_addr, phys_addr + size);
244 return NULL;
245 }
246 prot_val = new_prot_val;

--- 494 unchanged lines hidden ---
179 "ioremap error for 0x%llx-0x%llx, requested 0x%lx, got 0x%lx\n",
180 (unsigned long long)phys_addr,
181 (unsigned long long)(phys_addr + size),
182 prot_val, new_prot_val);
183 free_memtype(phys_addr, phys_addr + size);
184 return NULL;
185 }
186 prot_val = new_prot_val;

--- 494 unchanged lines hidden ---