2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2007-10-16 16:26:47 +08:00
|
|
|
* Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
2005-04-17 06:20:36 +08:00
|
|
|
* Licensed under the GPL
|
|
|
|
*/
|
|
|
|
|
2011-08-19 03:14:10 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/bootmem.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/pfn.h>
|
|
|
|
#include <asm/page.h>
|
2014-10-12 19:02:11 +08:00
|
|
|
#include <asm/sections.h>
|
2011-08-19 03:14:10 +08:00
|
|
|
#include <as-layout.h>
|
|
|
|
#include <init.h>
|
|
|
|
#include <kern.h>
|
|
|
|
#include <mem_user.h>
|
|
|
|
#include <os.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static int physmem_fd = -1;
|
|
|
|
|
|
|
|
/* Changed during early boot */
|
|
|
|
unsigned long high_physmem;
|
2011-08-19 03:14:10 +08:00
|
|
|
EXPORT_SYMBOL(high_physmem);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-07 16:58:57 +08:00
|
|
|
extern unsigned long long physmem_size;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-06-03 13:30:45 +08:00
|
|
|
void __init mem_total_pages(unsigned long physmem, unsigned long iomem,
|
2007-07-24 09:43:48 +08:00
|
|
|
unsigned long highmem)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-06-03 13:30:45 +08:00
|
|
|
unsigned long phys_pages, highmem_pages;
|
|
|
|
unsigned long iomem_pages, total_pages;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-06-03 13:30:45 +08:00
|
|
|
phys_pages = physmem >> PAGE_SHIFT;
|
|
|
|
iomem_pages = iomem >> PAGE_SHIFT;
|
2005-04-17 06:20:36 +08:00
|
|
|
highmem_pages = highmem >> PAGE_SHIFT;
|
|
|
|
|
2014-06-03 13:30:45 +08:00
|
|
|
total_pages = phys_pages + iomem_pages + highmem_pages;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
max_mapnr = total_pages;
|
|
|
|
}
|
|
|
|
|
|
|
|
void map_memory(unsigned long virt, unsigned long phys, unsigned long len,
|
|
|
|
int r, int w, int x)
|
|
|
|
{
|
|
|
|
__u64 offset;
|
|
|
|
int fd, err;
|
|
|
|
|
|
|
|
fd = phys_mapping(phys, &offset);
|
|
|
|
err = os_map_memory((void *) virt, fd, offset, len, r, w, x);
|
2007-10-16 16:26:47 +08:00
|
|
|
if (err) {
|
|
|
|
if (err == -ENOMEM)
|
2007-10-16 16:27:00 +08:00
|
|
|
printk(KERN_ERR "try increasing the host's "
|
2005-04-17 06:20:36 +08:00
|
|
|
"/proc/sys/vm/max_map_count to <physical "
|
|
|
|
"memory size>/4096\n");
|
|
|
|
panic("map_memory(0x%lx, %d, 0x%llx, %ld, %d, %d, %d) failed, "
|
|
|
|
"err = %d\n", virt, fd, offset, len, r, w, x, err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 22:51:26 +08:00
|
|
|
/**
|
|
|
|
* setup_physmem() - Setup physical memory for UML
|
|
|
|
* @start: Start address of the physical kernel memory,
|
|
|
|
* i.e start address of the executable image.
|
|
|
|
* @reserve_end: end address of the physical kernel memory.
|
|
|
|
* @len: Length of total physical memory that should be mapped/made
|
|
|
|
* available, in bytes.
|
|
|
|
* @highmem: Number of highmem bytes that should be mapped/made available.
|
|
|
|
*
|
|
|
|
* Creates an unlinked temporary file of size (len + highmem) and memory maps
|
|
|
|
* it on the last executable image address (uml_reserved).
|
|
|
|
*
|
|
|
|
* The offset is needed as the length of the total physical memory
|
|
|
|
* (len + highmem) includes the size of the memory used be the executable image,
|
|
|
|
* but the mapped-to address is the last address of the executable image
|
|
|
|
* (uml_reserved == end address of executable image).
|
|
|
|
*
|
|
|
|
* The memory mapped memory of the temporary file is used as backing memory
|
|
|
|
* of all user space processes/kernel tasks.
|
|
|
|
*/
|
2007-07-24 09:43:48 +08:00
|
|
|
void __init setup_physmem(unsigned long start, unsigned long reserve_end,
|
|
|
|
unsigned long len, unsigned long long highmem)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long reserve = reserve_end - start;
|
2015-04-03 22:51:26 +08:00
|
|
|
unsigned long pfn = PFN_UP(__pa(reserve_end));
|
|
|
|
unsigned long delta = (len - reserve) >> PAGE_SHIFT;
|
|
|
|
unsigned long offset, bootmap_size;
|
|
|
|
long map_size;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
offset = uml_reserved - uml_physmem;
|
|
|
|
map_size = len - offset;
|
|
|
|
if(map_size <= 0) {
|
|
|
|
printf("Too few physical memory! Needed=%d, given=%d\n",
|
|
|
|
offset, len);
|
|
|
|
exit(1);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
physmem_fd = create_mem_file(len + highmem);
|
|
|
|
|
|
|
|
err = os_map_memory((void *) uml_reserved, physmem_fd, offset,
|
2015-04-03 22:51:26 +08:00
|
|
|
map_size, 1, 1, 1);
|
2007-10-16 16:26:47 +08:00
|
|
|
if (err < 0) {
|
2007-10-16 16:27:11 +08:00
|
|
|
printf("setup_physmem - mapping %ld bytes of memory at 0x%p "
|
2015-04-03 22:51:26 +08:00
|
|
|
"failed - errno = %d\n", map_size,
|
2007-10-16 16:27:11 +08:00
|
|
|
(void *) uml_reserved, err);
|
2005-04-17 06:20:36 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2007-10-16 16:27:00 +08:00
|
|
|
/*
|
|
|
|
* Special kludge - This page will be mapped in to userspace processes
|
[PATCH] uml: skas0 - separate kernel address space on stock hosts
UML has had two modes of operation - an insecure, slow mode (tt mode) in
which the kernel is mapped into every process address space which requires
no host kernel modifications, and a secure, faster mode (skas mode) in
which the UML kernel is in a separate host address space, which requires a
patch to the host kernel.
This patch implements something very close to skas mode for hosts which
don't support skas - I'm calling this skas0. It provides the security of
the skas host patch, and some of the performance gains.
The two main things that are provided by the skas patch, /proc/mm and
PTRACE_FAULTINFO, are implemented in a way that require no host patch.
For the remote address space changing stuff (mmap, munmap, and mprotect),
we set aside two pages in the process above its stack, one of which
contains a little bit of code which can call mmap et al.
To update the address space, the system call information (system call
number and arguments) are written to the stub page above the code. The
%esp is set to the beginning of the data, the %eip is set the the start of
the stub, and it repeatedly pops the information into its registers and
makes the system call until it sees a system call number of zero. This is
to amortize the cost of the context switch across multiple address space
updates.
When the updates are done, it SIGSTOPs itself, and the kernel process
continues what it was doing.
For a PTRACE_FAULTINFO replacement, we set up a SIGSEGV handler in the
child, and let it handle segfaults rather than nullifying them. The
handler is in the same page as the mmap stub. The second page is used as
the stack. The handler reads cr2 and err from the sigcontext, sticks them
at the base of the stack in a faultinfo struct, and SIGSTOPs itself. The
kernel then reads the faultinfo and handles the fault.
A complication on x86_64 is that this involves resetting the registers to
the segfault values when the process is inside the kill system call. This
breaks on x86_64 because %rcx will contain %rip because you tell SYSRET
where to return to by putting the value in %rcx. So, this corrupts $rcx on
return from the segfault. To work around this, I added an
arch_finish_segv, which on x86 does nothing, but which on x86_64 ptraces
the child back through the sigreturn. This causes %rcx to be restored by
sigreturn and avoids the corruption. Ultimately, I think I will replace
this with the trick of having it send itself a blocked signal which will be
unblocked by the sigreturn. This will allow it to be stopped just after
the sigreturn, and PTRACE_SYSCALLed without all the back-and-forth of
PTRACE_SYSCALLing it through sigreturn.
This runs on a stock host, so theoretically (and hopefully), tt mode isn't
needed any more. We need to make sure that this is better in every way
than tt mode, though. I'm concerned about the speed of address space
updates and page fault handling, since they involve extra round-trips to
the child. We can amortize the round-trip cost for large address space
updates by writing all of the operations to the data page and having the
child execute them all at the same time. This will help fork and exec, but
not page faults, since they involve only one page.
I can't think of any way to help page faults, except to add something like
PTRACE_FAULTINFO to the host. There is PTRACE_SIGINFO, but UML doesn't use
siginfo for SIGSEGV (or anything else) because there isn't enough
information in the siginfo struct to handle page faults (the faulting
operation type is missing). Adding that would make PTRACE_SIGINFO a usable
equivalent to PTRACE_FAULTINFO.
As for the code itself:
- The system call stub is in arch/um/kernel/sys-$(SUBARCH)/stub.S. It is
put in its own section of the binary along with stub_segv_handler in
arch/um/kernel/skas/process.c. This is manipulated with run_syscall_stub
in arch/um/kernel/skas/mem_user.c. syscall_stub will execute any system
call at all, but it's only used for mmap, munmap, and mprotect.
- The x86_64 stub calls sigreturn by hand rather than allowing the normal
sigreturn to happen, because the normal sigreturn is a SA_RESTORER in
UML's address space provided by libc. Needless to say, this is not
available in the child's address space. Also, it does a couple of odd
pops before that which restore the stack to the state it was in at the
time the signal handler was called.
- There is a new field in the arch mmu_context, which is now a union.
This is the pid to be manipulated rather than the /proc/mm file
descriptor. Code which deals with this now checks proc_mm to see whether
it should use the usual skas code or the new code.
- userspace_tramp is now used to create a new host process for every UML
process, rather than one per UML processor. It checks proc_mm and
ptrace_faultinfo to decide whether to map in the pages above its stack.
- start_userspace now makes CLONE_VM conditional on proc_mm since we need
separate address spaces now.
- switch_mm_skas now just sets userspace_pid[0] to the new pid rather
than PTRACE_SWITCH_MM. There is an addition to userspace which updates
its idea of the pid being manipulated each time around the loop. This is
important on exec, when the pid will change underneath userspace().
- The stub page has a pte, but it can't be mapped in using tlb_flush
because it is part of tlb_flush. This is why it's required for it to be
mapped in by userspace_tramp.
Other random things:
- The stub section in uml.lds.S is page aligned. This page is written
out to the backing vm file in setup_physmem because it is mapped from
there into user processes.
- There's some confusion with TASK_SIZE now that there are a couple of
extra pages that the process can't use. TASK_SIZE is considered by the
elf code to be the usable process memory, which is reasonable, so it is
decreased by two pages. This confuses the definition of
USER_PGDS_IN_LAST_PML4, making it too small because of the rounding down
of the uneven division. So we round it to the nearest PGDIR_SIZE rather
than the lower one.
- I added a missing PT_SYSCALL_ARG6_OFFSET macro.
- um_mmu.h was made into a userspace-usable file.
- proc_mm and ptrace_faultinfo are globals which say whether the host
supports these features.
- There is a bad interaction between the mm.nr_ptes check at the end of
exit_mmap, stack randomization, and skas0. exit_mmap will stop freeing
pages at the PGDIR_SIZE boundary after the last vma. If the stack isn't
on the last page table page, the last pte page won't be freed, as it
should be since the stub ptes are there, and exit_mmap will BUG because
there is an unfreed page. To get around this, TASK_SIZE is set to the
next lowest PGDIR_SIZE boundary and mm->nr_ptes is decremented after the
calls to init_stub_pte. This ensures that we know the process stack (and
all other process mappings) will be below the top page table page, and
thus we know that mm->nr_ptes will be one too many, and can be
decremented.
Things that need fixing:
- We may need better assurrences that the stub code is PIC.
- The stub pte is set up in init_new_context_skas.
- alloc_pgdir is probably the right place.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-08 08:56:49 +08:00
|
|
|
* from physmem_fd, so it needs to be written out there.
|
|
|
|
*/
|
2014-10-12 19:02:12 +08:00
|
|
|
os_seek_file(physmem_fd, __pa(__syscall_stub_start));
|
|
|
|
os_write_file(physmem_fd, __syscall_stub_start, PAGE_SIZE);
|
2014-03-08 02:37:47 +08:00
|
|
|
os_fsync_file(physmem_fd);
|
[PATCH] uml: skas0 - separate kernel address space on stock hosts
UML has had two modes of operation - an insecure, slow mode (tt mode) in
which the kernel is mapped into every process address space which requires
no host kernel modifications, and a secure, faster mode (skas mode) in
which the UML kernel is in a separate host address space, which requires a
patch to the host kernel.
This patch implements something very close to skas mode for hosts which
don't support skas - I'm calling this skas0. It provides the security of
the skas host patch, and some of the performance gains.
The two main things that are provided by the skas patch, /proc/mm and
PTRACE_FAULTINFO, are implemented in a way that require no host patch.
For the remote address space changing stuff (mmap, munmap, and mprotect),
we set aside two pages in the process above its stack, one of which
contains a little bit of code which can call mmap et al.
To update the address space, the system call information (system call
number and arguments) are written to the stub page above the code. The
%esp is set to the beginning of the data, the %eip is set the the start of
the stub, and it repeatedly pops the information into its registers and
makes the system call until it sees a system call number of zero. This is
to amortize the cost of the context switch across multiple address space
updates.
When the updates are done, it SIGSTOPs itself, and the kernel process
continues what it was doing.
For a PTRACE_FAULTINFO replacement, we set up a SIGSEGV handler in the
child, and let it handle segfaults rather than nullifying them. The
handler is in the same page as the mmap stub. The second page is used as
the stack. The handler reads cr2 and err from the sigcontext, sticks them
at the base of the stack in a faultinfo struct, and SIGSTOPs itself. The
kernel then reads the faultinfo and handles the fault.
A complication on x86_64 is that this involves resetting the registers to
the segfault values when the process is inside the kill system call. This
breaks on x86_64 because %rcx will contain %rip because you tell SYSRET
where to return to by putting the value in %rcx. So, this corrupts $rcx on
return from the segfault. To work around this, I added an
arch_finish_segv, which on x86 does nothing, but which on x86_64 ptraces
the child back through the sigreturn. This causes %rcx to be restored by
sigreturn and avoids the corruption. Ultimately, I think I will replace
this with the trick of having it send itself a blocked signal which will be
unblocked by the sigreturn. This will allow it to be stopped just after
the sigreturn, and PTRACE_SYSCALLed without all the back-and-forth of
PTRACE_SYSCALLing it through sigreturn.
This runs on a stock host, so theoretically (and hopefully), tt mode isn't
needed any more. We need to make sure that this is better in every way
than tt mode, though. I'm concerned about the speed of address space
updates and page fault handling, since they involve extra round-trips to
the child. We can amortize the round-trip cost for large address space
updates by writing all of the operations to the data page and having the
child execute them all at the same time. This will help fork and exec, but
not page faults, since they involve only one page.
I can't think of any way to help page faults, except to add something like
PTRACE_FAULTINFO to the host. There is PTRACE_SIGINFO, but UML doesn't use
siginfo for SIGSEGV (or anything else) because there isn't enough
information in the siginfo struct to handle page faults (the faulting
operation type is missing). Adding that would make PTRACE_SIGINFO a usable
equivalent to PTRACE_FAULTINFO.
As for the code itself:
- The system call stub is in arch/um/kernel/sys-$(SUBARCH)/stub.S. It is
put in its own section of the binary along with stub_segv_handler in
arch/um/kernel/skas/process.c. This is manipulated with run_syscall_stub
in arch/um/kernel/skas/mem_user.c. syscall_stub will execute any system
call at all, but it's only used for mmap, munmap, and mprotect.
- The x86_64 stub calls sigreturn by hand rather than allowing the normal
sigreturn to happen, because the normal sigreturn is a SA_RESTORER in
UML's address space provided by libc. Needless to say, this is not
available in the child's address space. Also, it does a couple of odd
pops before that which restore the stack to the state it was in at the
time the signal handler was called.
- There is a new field in the arch mmu_context, which is now a union.
This is the pid to be manipulated rather than the /proc/mm file
descriptor. Code which deals with this now checks proc_mm to see whether
it should use the usual skas code or the new code.
- userspace_tramp is now used to create a new host process for every UML
process, rather than one per UML processor. It checks proc_mm and
ptrace_faultinfo to decide whether to map in the pages above its stack.
- start_userspace now makes CLONE_VM conditional on proc_mm since we need
separate address spaces now.
- switch_mm_skas now just sets userspace_pid[0] to the new pid rather
than PTRACE_SWITCH_MM. There is an addition to userspace which updates
its idea of the pid being manipulated each time around the loop. This is
important on exec, when the pid will change underneath userspace().
- The stub page has a pte, but it can't be mapped in using tlb_flush
because it is part of tlb_flush. This is why it's required for it to be
mapped in by userspace_tramp.
Other random things:
- The stub section in uml.lds.S is page aligned. This page is written
out to the backing vm file in setup_physmem because it is mapped from
there into user processes.
- There's some confusion with TASK_SIZE now that there are a couple of
extra pages that the process can't use. TASK_SIZE is considered by the
elf code to be the usable process memory, which is reasonable, so it is
decreased by two pages. This confuses the definition of
USER_PGDS_IN_LAST_PML4, making it too small because of the rounding down
of the uneven division. So we round it to the nearest PGDIR_SIZE rather
than the lower one.
- I added a missing PT_SYSCALL_ARG6_OFFSET macro.
- um_mmu.h was made into a userspace-usable file.
- proc_mm and ptrace_faultinfo are globals which say whether the host
supports these features.
- There is a bad interaction between the mm.nr_ptes check at the end of
exit_mmap, stack randomization, and skas0. exit_mmap will stop freeing
pages at the PGDIR_SIZE boundary after the last vma. If the stack isn't
on the last page table page, the last pte page won't be freed, as it
should be since the stub ptes are there, and exit_mmap will BUG because
there is an unfreed page. To get around this, TASK_SIZE is set to the
next lowest PGDIR_SIZE boundary and mm->nr_ptes is decremented after the
calls to init_stub_pte. This ensures that we know the process stack (and
all other process mappings) will be below the top page table page, and
thus we know that mm->nr_ptes will be one too many, and can be
decremented.
Things that need fixing:
- We may need better assurrences that the stub code is PIC.
- The stub pte is set up in init_new_context_skas.
- alloc_pgdir is probably the right place.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-08 08:56:49 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
bootmap_size = init_bootmem(pfn, pfn + delta);
|
|
|
|
free_bootmem(__pa(reserve_end) + bootmap_size,
|
|
|
|
len - bootmap_size - reserve);
|
|
|
|
}
|
|
|
|
|
2007-10-16 16:27:05 +08:00
|
|
|
int phys_mapping(unsigned long phys, unsigned long long *offset_out)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int fd = -1;
|
|
|
|
|
2007-10-16 16:26:47 +08:00
|
|
|
if (phys < physmem_size) {
|
2005-04-17 06:20:36 +08:00
|
|
|
fd = physmem_fd;
|
|
|
|
*offset_out = phys;
|
|
|
|
}
|
2007-10-16 16:26:47 +08:00
|
|
|
else if (phys < __pa(end_iomem)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
struct iomem_region *region = iomem_regions;
|
|
|
|
|
2007-10-16 16:26:47 +08:00
|
|
|
while (region != NULL) {
|
|
|
|
if ((phys >= region->phys) &&
|
|
|
|
(phys < region->phys + region->size)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
fd = region->fd;
|
|
|
|
*offset_out = phys - region->phys;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
region = region->next;
|
|
|
|
}
|
|
|
|
}
|
2007-10-16 16:26:47 +08:00
|
|
|
else if (phys < __pa(end_iomem) + highmem) {
|
2005-04-17 06:20:36 +08:00
|
|
|
fd = physmem_fd;
|
|
|
|
*offset_out = phys - iomem_size;
|
|
|
|
}
|
|
|
|
|
2007-02-10 17:44:10 +08:00
|
|
|
return fd;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init uml_mem_setup(char *line, int *add)
|
|
|
|
{
|
|
|
|
char *retptr;
|
|
|
|
physmem_size = memparse(line,&retptr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
__uml_setup("mem=", uml_mem_setup,
|
|
|
|
"mem=<Amount of desired ram>\n"
|
|
|
|
" This controls how much \"physical\" memory the kernel allocates\n"
|
|
|
|
" for the system. The size is specified as a number followed by\n"
|
|
|
|
" one of 'k', 'K', 'm', 'M', which have the obvious meanings.\n"
|
|
|
|
" This is not related to the amount of memory in the host. It can\n"
|
|
|
|
" be more, and the excess, if it's ever used, will just be swapped out.\n"
|
|
|
|
" Example: mem=64M\n\n"
|
|
|
|
);
|
|
|
|
|
2007-02-10 17:44:09 +08:00
|
|
|
extern int __init parse_iomem(char *str, int *add);
|
|
|
|
|
|
|
|
__uml_setup("iomem=", parse_iomem,
|
|
|
|
"iomem=<name>,<file>\n"
|
|
|
|
" Configure <file> as an IO memory region named <name>.\n\n"
|
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This list is constructed in parse_iomem and addresses filled in in
|
|
|
|
* setup_iomem, both of which run during early boot. Afterwards, it's
|
|
|
|
* unchanged.
|
|
|
|
*/
|
2008-02-05 14:31:17 +08:00
|
|
|
struct iomem_region *iomem_regions;
|
2007-02-10 17:44:09 +08:00
|
|
|
|
2008-02-05 14:31:17 +08:00
|
|
|
/* Initialized in parse_iomem and unchanged thereafter */
|
|
|
|
int iomem_size;
|
2007-02-10 17:44:09 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long find_iomem(char *driver, unsigned long *len_out)
|
|
|
|
{
|
|
|
|
struct iomem_region *region = iomem_regions;
|
|
|
|
|
2007-10-16 16:26:47 +08:00
|
|
|
while (region != NULL) {
|
|
|
|
if (!strcmp(region->driver, driver)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
*len_out = region->size;
|
2007-02-10 17:44:10 +08:00
|
|
|
return region->virt;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-05-02 03:15:53 +08:00
|
|
|
|
|
|
|
region = region->next;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-02-10 17:44:10 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2011-08-19 03:14:10 +08:00
|
|
|
EXPORT_SYMBOL(find_iomem);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-07-24 12:28:49 +08:00
|
|
|
static int setup_iomem(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct iomem_region *region = iomem_regions;
|
|
|
|
unsigned long iomem_start = high_physmem + PAGE_SIZE;
|
|
|
|
int err;
|
|
|
|
|
2007-10-16 16:26:47 +08:00
|
|
|
while (region != NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
err = os_map_memory((void *) iomem_start, region->fd, 0,
|
|
|
|
region->size, 1, 1, 0);
|
2007-10-16 16:26:47 +08:00
|
|
|
if (err)
|
2007-10-16 16:27:00 +08:00
|
|
|
printk(KERN_ERR "Mapping iomem region for driver '%s' "
|
|
|
|
"failed, errno = %d\n", region->driver, -err);
|
2005-04-17 06:20:36 +08:00
|
|
|
else {
|
|
|
|
region->virt = iomem_start;
|
|
|
|
region->phys = __pa(region->virt);
|
|
|
|
}
|
|
|
|
|
|
|
|
iomem_start += region->size + PAGE_SIZE;
|
|
|
|
region = region->next;
|
|
|
|
}
|
|
|
|
|
2007-02-10 17:44:10 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
__initcall(setup_iomem);
|