2 * Copyright © 2008 Keith Packard <keithp@keithp.com>
4 * This file is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18 #ifndef _LINUX_IO_MAPPING_H
19 #define _LINUX_IO_MAPPING_H
21 #include <linux/types.h>
24 #include <asm/iomap.h>
27 * The io_mapping mechanism provides an abstraction for mapping
28 * individual pages from an io device to the CPU in an efficient fashion.
30 * See Documentation/io_mapping.txt
33 /* this struct isn't actually defined anywhere */
38 /* Create the io_mapping object*/
39 static inline struct io_mapping *
40 io_mapping_create_wc(unsigned long base, unsigned long size)
42 return (struct io_mapping *) ioremap_wc(base, size);
46 io_mapping_free(struct io_mapping *mapping)
51 /* Atomic map/unmap */
53 io_mapping_map_atomic_wc(struct io_mapping *mapping, unsigned long offset)
55 return ((char *) mapping) + offset;
59 io_mapping_unmap_atomic(void *vaddr)
63 /* Non-atomic map/unmap */
65 io_mapping_map_wc(struct io_mapping *mapping, unsigned long offset)
67 return ((char *) mapping) + offset;
71 io_mapping_unmap(void *vaddr)
75 #endif /* CONFIG_X86_64 */
78 static inline struct io_mapping *
79 io_mapping_create_wc(unsigned long base, unsigned long size)
81 return (struct io_mapping *) base;
85 io_mapping_free(struct io_mapping *mapping)
89 /* Atomic map/unmap */
91 io_mapping_map_atomic_wc(struct io_mapping *mapping, unsigned long offset)
93 offset += (unsigned long) mapping;
94 return iomap_atomic_prot_pfn(offset >> PAGE_SHIFT, KM_USER0,
95 __pgprot(__PAGE_KERNEL_WC));
99 io_mapping_unmap_atomic(void *vaddr)
101 iounmap_atomic(vaddr, KM_USER0);
105 io_mapping_map_wc(struct io_mapping *mapping, unsigned long offset)
107 offset += (unsigned long) mapping;
108 return ioremap_wc(offset, PAGE_SIZE);
112 io_mapping_unmap(void *vaddr)
116 #endif /* CONFIG_X86_32 */
118 #endif /* _LINUX_IO_MAPPING_H */