Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / arch / x86 / kernel / resource.c
1 #ifdef CONFIG_XEN
2 # define e820 machine_e820
3 # include <asm/hypervisor.h>
4 #endif
5 #include <linux/ioport.h>
6 #include <asm/e820.h>
7
8 static void resource_clip(struct resource *res, resource_size_t start,
9                           resource_size_t end)
10 {
11         resource_size_t low = 0, high = 0;
12
13         if (res->end < start || res->start > end)
14                 return;         /* no conflict */
15
16         if (res->start < start)
17                 low = start - res->start;
18
19         if (res->end > end)
20                 high = res->end - end;
21
22         /* Keep the area above or below the conflict, whichever is larger */
23         if (low > high)
24                 res->end = start - 1;
25         else
26                 res->start = end + 1;
27 }
28
29 static void remove_e820_regions(struct resource *avail)
30 {
31         int i;
32         struct e820entry *entry;
33
34         for (i = 0; i < e820.nr_map; i++) {
35                 entry = &e820.map[i];
36
37                 resource_clip(avail, entry->addr,
38                               entry->addr + entry->size - 1);
39         }
40 }
41
42 void arch_remove_reservations(struct resource *avail)
43 {
44 #ifdef CONFIG_XEN
45         if (!is_initial_xendomain())
46                 return;
47 #endif
48         /* Trim out BIOS areas (low 1MB and high 2MB) and E820 regions */
49         if (avail->flags & IORESOURCE_MEM) {
50                 if (avail->start < BIOS_END)
51                         avail->start = BIOS_END;
52                 resource_clip(avail, BIOS_ROM_BASE, BIOS_ROM_END);
53
54                 remove_e820_regions(avail);
55         }
56 }