netfilter: ctnetlink: add zone support
[safe/jmp/linux-2.6] / include / linux / io-mapping.h
index 82df317..97eb928 100644 (file)
  * See Documentation/io_mapping.txt
  */
 
-/* this struct isn't actually defined anywhere */
-struct io_mapping;
-
 #ifdef CONFIG_HAVE_ATOMIC_IOMAP
 
+struct io_mapping {
+       resource_size_t base;
+       unsigned long size;
+       pgprot_t prot;
+};
+
 /*
  * For small address space machines, mapping large objects
  * into the kernel virtual space isn't practical. Where
@@ -43,23 +46,47 @@ struct io_mapping;
  */
 
 static inline struct io_mapping *
-io_mapping_create_wc(unsigned long base, unsigned long size)
+io_mapping_create_wc(resource_size_t base, unsigned long size)
 {
-       return (struct io_mapping *) base;
+       struct io_mapping *iomap;
+       pgprot_t prot;
+
+       iomap = kmalloc(sizeof(*iomap), GFP_KERNEL);
+       if (!iomap)
+               goto out_err;
+
+       if (iomap_create_wc(base, size, &prot))
+               goto out_free;
+
+       iomap->base = base;
+       iomap->size = size;
+       iomap->prot = prot;
+       return iomap;
+
+out_free:
+       kfree(iomap);
+out_err:
+       return NULL;
 }
 
 static inline void
 io_mapping_free(struct io_mapping *mapping)
 {
+       iomap_free(mapping->base, mapping->size);
+       kfree(mapping);
 }
 
 /* Atomic map/unmap */
 static inline void *
 io_mapping_map_atomic_wc(struct io_mapping *mapping, unsigned long offset)
 {
-       offset += (unsigned long) mapping;
-       return iomap_atomic_prot_pfn(offset >> PAGE_SHIFT, KM_USER0,
-                                    __pgprot(__PAGE_KERNEL_WC));
+       resource_size_t phys_addr;
+       unsigned long pfn;
+
+       BUG_ON(offset >= mapping->size);
+       phys_addr = mapping->base + offset;
+       pfn = (unsigned long) (phys_addr >> PAGE_SHIFT);
+       return iomap_atomic_prot_pfn(pfn, KM_USER0, mapping->prot);
 }
 
 static inline void
@@ -71,8 +98,12 @@ io_mapping_unmap_atomic(void *vaddr)
 static inline void *
 io_mapping_map_wc(struct io_mapping *mapping, unsigned long offset)
 {
-       offset += (unsigned long) mapping;
-       return ioremap_wc(offset, PAGE_SIZE);
+       resource_size_t phys_addr;
+
+       BUG_ON(offset >= mapping->size);
+       phys_addr = mapping->base + offset;
+
+       return ioremap_wc(phys_addr, PAGE_SIZE);
 }
 
 static inline void
@@ -83,9 +114,12 @@ io_mapping_unmap(void *vaddr)
 
 #else
 
+/* this struct isn't actually defined anywhere */
+struct io_mapping;
+
 /* Create the io_mapping object*/
 static inline struct io_mapping *
-io_mapping_create_wc(unsigned long base, unsigned long size)
+io_mapping_create_wc(resource_size_t base, unsigned long size)
 {
        return (struct io_mapping *) ioremap_wc(base, size);
 }