Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/s390/mm/ioremap.c |
| 3 | * |
| 4 | * S390 version |
| 5 | * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation |
| 6 | * Author(s): Hartmut Penner (hp@de.ibm.com) |
| 7 | * |
| 8 | * Derived from "arch/i386/mm/extable.c" |
| 9 | * (C) Copyright 1995 1996 Linus Torvalds |
| 10 | * |
| 11 | * Re-map IO memory to kernel address space so that we can access it. |
| 12 | * This is needed for high PCI addresses that aren't mapped in the |
| 13 | * 640k-1MB IO memory area on PC's |
| 14 | */ |
| 15 | |
| 16 | #include <linux/vmalloc.h> |
| 17 | #include <linux/mm.h> |
Haavard Skinnemoen | a151ca6 | 2006-12-08 02:38:06 -0800 | [diff] [blame] | 18 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/pgalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | /* |
| 22 | * Generic mapping function (not visible outside): |
| 23 | */ |
| 24 | |
| 25 | /* |
| 26 | * Remap an arbitrary physical address space into the kernel virtual |
| 27 | * address space. Needed when the kernel wants to access high addresses |
| 28 | * directly. |
| 29 | */ |
| 30 | void * __ioremap(unsigned long phys_addr, unsigned long size, unsigned long flags) |
| 31 | { |
| 32 | void * addr; |
| 33 | struct vm_struct * area; |
| 34 | |
| 35 | if (phys_addr < virt_to_phys(high_memory)) |
| 36 | return phys_to_virt(phys_addr); |
| 37 | if (phys_addr & ~PAGE_MASK) |
| 38 | return NULL; |
| 39 | size = PAGE_ALIGN(size); |
| 40 | if (!size || size > phys_addr + size) |
| 41 | return NULL; |
| 42 | area = get_vm_area(size, VM_IOREMAP); |
| 43 | if (!area) |
| 44 | return NULL; |
| 45 | addr = area->addr; |
Haavard Skinnemoen | a151ca6 | 2006-12-08 02:38:06 -0800 | [diff] [blame] | 46 | if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size, |
| 47 | phys_addr, __pgprot(flags))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | vfree(addr); |
| 49 | return NULL; |
| 50 | } |
| 51 | return addr; |
| 52 | } |
| 53 | |
| 54 | void iounmap(void *addr) |
| 55 | { |
| 56 | if (addr > high_memory) |
| 57 | vfree(addr); |
| 58 | } |