2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
6 #include <linux/module.h>
7 #include <linux/bootmem.h>
11 #include <as-layout.h>
17 static int physmem_fd
= -1;
19 /* Changed during early boot */
20 unsigned long high_physmem
;
21 EXPORT_SYMBOL(high_physmem
);
23 extern unsigned long long physmem_size
;
25 void __init
mem_total_pages(unsigned long physmem
, unsigned long iomem
,
26 unsigned long highmem
)
28 unsigned long phys_pages
, highmem_pages
;
29 unsigned long iomem_pages
, total_pages
;
31 phys_pages
= physmem
>> PAGE_SHIFT
;
32 iomem_pages
= iomem
>> PAGE_SHIFT
;
33 highmem_pages
= highmem
>> PAGE_SHIFT
;
35 total_pages
= phys_pages
+ iomem_pages
+ highmem_pages
;
37 max_mapnr
= total_pages
;
40 void map_memory(unsigned long virt
, unsigned long phys
, unsigned long len
,
46 fd
= phys_mapping(phys
, &offset
);
47 err
= os_map_memory((void *) virt
, fd
, offset
, len
, r
, w
, x
);
50 printk(KERN_ERR
"try increasing the host's "
51 "/proc/sys/vm/max_map_count to <physical "
52 "memory size>/4096\n");
53 panic("map_memory(0x%lx, %d, 0x%llx, %ld, %d, %d, %d) failed, "
54 "err = %d\n", virt
, fd
, offset
, len
, r
, w
, x
, err
);
58 extern int __syscall_stub_start
;
61 * setup_physmem() - Setup physical memory for UML
62 * @start: Start address of the physical kernel memory,
63 * i.e start address of the executable image.
64 * @reserve_end: end address of the physical kernel memory.
65 * @len: Length of total physical memory that should be mapped/made
66 * available, in bytes.
67 * @highmem: Number of highmem bytes that should be mapped/made available.
69 * Creates an unlinked temporary file of size (len + highmem) and memory maps
70 * it on the last executable image address (uml_reserved).
72 * The offset is needed as the length of the total physical memory
73 * (len + highmem) includes the size of the memory used be the executable image,
74 * but the mapped-to address is the last address of the executable image
75 * (uml_reserved == end address of executable image).
77 * The memory mapped memory of the temporary file is used as backing memory
78 * of all user space processes/kernel tasks.
80 void __init
setup_physmem(unsigned long start
, unsigned long reserve_end
,
81 unsigned long len
, unsigned long long highmem
)
83 unsigned long reserve
= reserve_end
- start
;
84 unsigned long pfn
= PFN_UP(__pa(reserve_end
));
85 unsigned long delta
= (len
- reserve
) >> PAGE_SHIFT
;
86 unsigned long offset
, bootmap_size
;
90 offset
= uml_reserved
- uml_physmem
;
91 map_size
= len
- offset
;
93 printf("Too few physical memory! Needed=%d, given=%d\n",
98 physmem_fd
= create_mem_file(len
+ highmem
);
100 err
= os_map_memory((void *) uml_reserved
, physmem_fd
, offset
,
103 printf("setup_physmem - mapping %ld bytes of memory at 0x%p "
104 "failed - errno = %d\n", map_size
,
105 (void *) uml_reserved
, err
);
110 * Special kludge - This page will be mapped in to userspace processes
111 * from physmem_fd, so it needs to be written out there.
113 os_seek_file(physmem_fd
, __pa(&__syscall_stub_start
));
114 os_write_file(physmem_fd
, &__syscall_stub_start
, PAGE_SIZE
);
115 os_fsync_file(physmem_fd
);
117 bootmap_size
= init_bootmem(pfn
, pfn
+ delta
);
118 free_bootmem(__pa(reserve_end
) + bootmap_size
,
119 len
- bootmap_size
- reserve
);
122 int phys_mapping(unsigned long phys
, unsigned long long *offset_out
)
126 if (phys
< physmem_size
) {
130 else if (phys
< __pa(end_iomem
)) {
131 struct iomem_region
*region
= iomem_regions
;
133 while (region
!= NULL
) {
134 if ((phys
>= region
->phys
) &&
135 (phys
< region
->phys
+ region
->size
)) {
137 *offset_out
= phys
- region
->phys
;
140 region
= region
->next
;
143 else if (phys
< __pa(end_iomem
) + highmem
) {
145 *offset_out
= phys
- iomem_size
;
151 static int __init
uml_mem_setup(char *line
, int *add
)
154 physmem_size
= memparse(line
,&retptr
);
157 __uml_setup("mem=", uml_mem_setup
,
158 "mem=<Amount of desired ram>\n"
159 " This controls how much \"physical\" memory the kernel allocates\n"
160 " for the system. The size is specified as a number followed by\n"
161 " one of 'k', 'K', 'm', 'M', which have the obvious meanings.\n"
162 " This is not related to the amount of memory in the host. It can\n"
163 " be more, and the excess, if it's ever used, will just be swapped out.\n"
164 " Example: mem=64M\n\n"
167 extern int __init
parse_iomem(char *str
, int *add
);
169 __uml_setup("iomem=", parse_iomem
,
170 "iomem=<name>,<file>\n"
171 " Configure <file> as an IO memory region named <name>.\n\n"
175 * This list is constructed in parse_iomem and addresses filled in in
176 * setup_iomem, both of which run during early boot. Afterwards, it's
179 struct iomem_region
*iomem_regions
;
181 /* Initialized in parse_iomem and unchanged thereafter */
184 unsigned long find_iomem(char *driver
, unsigned long *len_out
)
186 struct iomem_region
*region
= iomem_regions
;
188 while (region
!= NULL
) {
189 if (!strcmp(region
->driver
, driver
)) {
190 *len_out
= region
->size
;
194 region
= region
->next
;
199 EXPORT_SYMBOL(find_iomem
);
201 static int setup_iomem(void)
203 struct iomem_region
*region
= iomem_regions
;
204 unsigned long iomem_start
= high_physmem
+ PAGE_SIZE
;
207 while (region
!= NULL
) {
208 err
= os_map_memory((void *) iomem_start
, region
->fd
, 0,
209 region
->size
, 1, 1, 0);
211 printk(KERN_ERR
"Mapping iomem region for driver '%s' "
212 "failed, errno = %d\n", region
->driver
, -err
);
214 region
->virt
= iomem_start
;
215 region
->phys
= __pa(region
->virt
);
218 iomem_start
+= region
->size
+ PAGE_SIZE
;
219 region
= region
->next
;
225 __initcall(setup_iomem
);
This page took 0.038768 seconds and 6 git commands to generate.