2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
6 #include "linux/bootmem.h"
10 #include "as-layout.h"
16 static int physmem_fd = -1;
18 /* Changed during early boot */
19 unsigned long high_physmem;
21 extern unsigned long long physmem_size;
23 int __init init_maps(unsigned long physmem, unsigned long iomem,
24 unsigned long highmem)
27 unsigned long phys_len, phys_pages, highmem_len, highmem_pages;
28 unsigned long iomem_len, iomem_pages, total_len, total_pages;
31 phys_pages = physmem >> PAGE_SHIFT;
32 phys_len = phys_pages * sizeof(struct page);
34 iomem_pages = iomem >> PAGE_SHIFT;
35 iomem_len = iomem_pages * sizeof(struct page);
37 highmem_pages = highmem >> PAGE_SHIFT;
38 highmem_len = highmem_pages * sizeof(struct page);
40 total_pages = phys_pages + iomem_pages + highmem_pages;
41 total_len = phys_len + iomem_len + highmem_len;
43 map = alloc_bootmem_low_pages(total_len);
47 for (i = 0; i < total_pages; i++) {
49 memset(p, 0, sizeof(struct page));
51 INIT_LIST_HEAD(&p->lru);
54 max_mapnr = total_pages;
58 void map_memory(unsigned long virt, unsigned long phys, unsigned long len,
64 fd = phys_mapping(phys, &offset);
65 err = os_map_memory((void *) virt, fd, offset, len, r, w, x);
68 printk(KERN_ERR "try increasing the host's "
69 "/proc/sys/vm/max_map_count to <physical "
70 "memory size>/4096\n");
71 panic("map_memory(0x%lx, %d, 0x%llx, %ld, %d, %d, %d) failed, "
72 "err = %d\n", virt, fd, offset, len, r, w, x, err);
76 extern int __syscall_stub_start;
78 void __init setup_physmem(unsigned long start, unsigned long reserve_end,
79 unsigned long len, unsigned long long highmem)
81 unsigned long reserve = reserve_end - start;
82 int pfn = PFN_UP(__pa(reserve_end));
83 int delta = (len - reserve) >> PAGE_SHIFT;
84 int err, offset, bootmap_size;
86 physmem_fd = create_mem_file(len + highmem);
88 offset = uml_reserved - uml_physmem;
89 err = os_map_memory((void *) uml_reserved, physmem_fd, offset,
90 len - offset, 1, 1, 1);
92 printf("setup_physmem - mapping %ld bytes of memory at 0x%p "
93 "failed - errno = %d\n", len - offset,
94 (void *) uml_reserved, err);
99 * Special kludge - This page will be mapped in to userspace processes
100 * from physmem_fd, so it needs to be written out there.
102 os_seek_file(physmem_fd, __pa(&__syscall_stub_start));
103 os_write_file(physmem_fd, &__syscall_stub_start, PAGE_SIZE);
105 bootmap_size = init_bootmem(pfn, pfn + delta);
106 free_bootmem(__pa(reserve_end) + bootmap_size,
107 len - bootmap_size - reserve);
110 int phys_mapping(unsigned long phys, unsigned long long *offset_out)
114 if (phys < physmem_size) {
118 else if (phys < __pa(end_iomem)) {
119 struct iomem_region *region = iomem_regions;
121 while (region != NULL) {
122 if ((phys >= region->phys) &&
123 (phys < region->phys + region->size)) {
125 *offset_out = phys - region->phys;
128 region = region->next;
131 else if (phys < __pa(end_iomem) + highmem) {
133 *offset_out = phys - iomem_size;
139 static int __init uml_mem_setup(char *line, int *add)
142 physmem_size = memparse(line,&retptr);
145 __uml_setup("mem=", uml_mem_setup,
146 "mem=<Amount of desired ram>\n"
147 " This controls how much \"physical\" memory the kernel allocates\n"
148 " for the system. The size is specified as a number followed by\n"
149 " one of 'k', 'K', 'm', 'M', which have the obvious meanings.\n"
150 " This is not related to the amount of memory in the host. It can\n"
151 " be more, and the excess, if it's ever used, will just be swapped out.\n"
152 " Example: mem=64M\n\n"
155 extern int __init parse_iomem(char *str, int *add);
157 __uml_setup("iomem=", parse_iomem,
158 "iomem=<name>,<file>\n"
159 " Configure <file> as an IO memory region named <name>.\n\n"
163 * This list is constructed in parse_iomem and addresses filled in in
164 * setup_iomem, both of which run during early boot. Afterwards, it's
167 struct iomem_region *iomem_regions;
169 /* Initialized in parse_iomem and unchanged thereafter */
172 unsigned long find_iomem(char *driver, unsigned long *len_out)
174 struct iomem_region *region = iomem_regions;
176 while (region != NULL) {
177 if (!strcmp(region->driver, driver)) {
178 *len_out = region->size;
182 region = region->next;
188 static int setup_iomem(void)
190 struct iomem_region *region = iomem_regions;
191 unsigned long iomem_start = high_physmem + PAGE_SIZE;
194 while (region != NULL) {
195 err = os_map_memory((void *) iomem_start, region->fd, 0,
196 region->size, 1, 1, 0);
198 printk(KERN_ERR "Mapping iomem region for driver '%s' "
199 "failed, errno = %d\n", region->driver, -err);
201 region->virt = iomem_start;
202 region->phys = __pa(region->virt);
205 iomem_start += region->size + PAGE_SIZE;
206 region = region->next;
212 __initcall(setup_iomem);