• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6/arch/avr32/mm/
1/*
2 * Copyright (C) 2004-2006 Atmel Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8#include <linux/vmalloc.h>
9#include <linux/mm.h>
10#include <linux/module.h>
11#include <linux/io.h>
12#include <linux/slab.h>
13
14#include <asm/pgtable.h>
15#include <asm/addrspace.h>
16
17/*
18 * Re-map an arbitrary physical address space into the kernel virtual
19 * address space. Needed when the kernel wants to access physical
20 * memory directly.
21 */
22void __iomem *__ioremap(unsigned long phys_addr, size_t size,
23			unsigned long flags)
24{
25	unsigned long addr;
26	struct vm_struct *area;
27	unsigned long offset, last_addr;
28	pgprot_t prot;
29
30	/*
31	 * Check if we can simply use the P4 segment. This area is
32	 * uncacheable, so if caching/buffering is requested, we can't
33	 * use it.
34	 */
35	if ((phys_addr >= P4SEG) && (flags == 0))
36		return (void __iomem *)phys_addr;
37
38	/* Don't allow wraparound or zero size */
39	last_addr = phys_addr + size - 1;
40	if (!size || last_addr < phys_addr)
41		return NULL;
42
43	if (PHYSADDR(P2SEGADDR(phys_addr)) == phys_addr)
44		return (void __iomem *)P2SEGADDR(phys_addr);
45
46	/* Mappings have to be page-aligned */
47	offset = phys_addr & ~PAGE_MASK;
48	phys_addr &= PAGE_MASK;
49	size = PAGE_ALIGN(last_addr + 1) - phys_addr;
50
51	prot = __pgprot(_PAGE_PRESENT | _PAGE_GLOBAL | _PAGE_RW | _PAGE_DIRTY
52			| _PAGE_ACCESSED | _PAGE_TYPE_SMALL | flags);
53
54	/*
55	 * Ok, go for it..
56	 */
57	area = get_vm_area(size, VM_IOREMAP);
58	if (!area)
59		return NULL;
60	area->phys_addr = phys_addr;
61	addr = (unsigned long )area->addr;
62	if (ioremap_page_range(addr, addr + size, phys_addr, prot)) {
63		vunmap((void *)addr);
64		return NULL;
65	}
66
67	return (void __iomem *)(offset + (char *)addr);
68}
69EXPORT_SYMBOL(__ioremap);
70
71void __iounmap(void __iomem *addr)
72{
73	struct vm_struct *p;
74
75	if ((unsigned long)addr >= P4SEG)
76		return;
77	if (PXSEG(addr) == P2SEG)
78		return;
79
80	p = remove_vm_area((void *)(PAGE_MASK & (unsigned long __force)addr));
81	if (unlikely(!p)) {
82		printk (KERN_ERR "iounmap: bad address %p\n", addr);
83		return;
84	}
85
86	kfree (p);
87}
88EXPORT_SYMBOL(__iounmap);
89