diff options
author | Emil Medve <Emilian.Medve@Freescale.com> | 2008-05-02 16:34:04 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2008-05-05 02:47:14 -0400 |
commit | b41e5fffe8b81fc939067d8c1c195cc79115d5a3 (patch) | |
tree | 7839043d5c430029efdb023e69d6a717fa8ff86e | |
parent | af3ce514ade2fd0e18c5d078d138a6c1137a33df (diff) |
[POWERPC] devres: Add devm_ioremap_prot()
We provide an ioremap_flags, so this provides a corresponding
devm_ioremap_prot. The slight name difference is at Ben
Herrenschmidt's request as he plans on changing ioremap_flags to
ioremap_prot in the future.
Signed-off-by: Emil Medve <Emilian.Medve@Freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Acked-by: Tejun Heo <htejun@gmail.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
-rw-r--r-- | arch/powerpc/lib/Makefile | 1 | ||||
-rw-r--r-- | arch/powerpc/lib/devres.c | 42 | ||||
-rw-r--r-- | include/asm-powerpc/io.h | 8 | ||||
-rw-r--r-- | include/linux/io.h | 1 | ||||
-rw-r--r-- | lib/devres.c | 2 |
5 files changed, 52 insertions, 2 deletions
diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile index 4bb023f4c869..f1d2cdc5331b 100644 --- a/arch/powerpc/lib/Makefile +++ b/arch/powerpc/lib/Makefile | |||
@@ -23,3 +23,4 @@ obj-$(CONFIG_SMP) += locks.o | |||
23 | endif | 23 | endif |
24 | 24 | ||
25 | obj-$(CONFIG_PPC_LIB_RHEAP) += rheap.o | 25 | obj-$(CONFIG_PPC_LIB_RHEAP) += rheap.o |
26 | obj-$(CONFIG_HAS_IOMEM) += devres.o | ||
diff --git a/arch/powerpc/lib/devres.c b/arch/powerpc/lib/devres.c new file mode 100644 index 000000000000..292115d98ea9 --- /dev/null +++ b/arch/powerpc/lib/devres.c | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2008 Freescale Semiconductor, Inc. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation; either version | ||
7 | * 2 of the License, or (at your option) any later version. | ||
8 | */ | ||
9 | |||
10 | #include <linux/device.h> /* devres_*(), devm_ioremap_release() */ | ||
11 | #include <linux/io.h> /* ioremap_flags() */ | ||
12 | #include <linux/module.h> /* EXPORT_SYMBOL() */ | ||
13 | |||
14 | /** | ||
15 | * devm_ioremap_prot - Managed ioremap_flags() | ||
16 | * @dev: Generic device to remap IO address for | ||
17 | * @offset: BUS offset to map | ||
18 | * @size: Size of map | ||
19 | * @flags: Page flags | ||
20 | * | ||
21 | * Managed ioremap_prot(). Map is automatically unmapped on driver | ||
22 | * detach. | ||
23 | */ | ||
24 | void __iomem *devm_ioremap_prot(struct device *dev, resource_size_t offset, | ||
25 | size_t size, unsigned long flags) | ||
26 | { | ||
27 | void __iomem **ptr, *addr; | ||
28 | |||
29 | ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL); | ||
30 | if (!ptr) | ||
31 | return NULL; | ||
32 | |||
33 | addr = ioremap_flags(offset, size, flags); | ||
34 | if (addr) { | ||
35 | *ptr = addr; | ||
36 | devres_add(dev, ptr); | ||
37 | } else | ||
38 | devres_free(ptr); | ||
39 | |||
40 | return addr; | ||
41 | } | ||
42 | EXPORT_SYMBOL(devm_ioremap_prot); | ||
diff --git a/include/asm-powerpc/io.h b/include/asm-powerpc/io.h index afae0697e8ce..e0062d73db1c 100644 --- a/include/asm-powerpc/io.h +++ b/include/asm-powerpc/io.h | |||
@@ -2,7 +2,7 @@ | |||
2 | #define _ASM_POWERPC_IO_H | 2 | #define _ASM_POWERPC_IO_H |
3 | #ifdef __KERNEL__ | 3 | #ifdef __KERNEL__ |
4 | 4 | ||
5 | /* | 5 | /* |
6 | * This program is free software; you can redistribute it and/or | 6 | * This program is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU General Public License | 7 | * modify it under the terms of the GNU General Public License |
8 | * as published by the Free Software Foundation; either version | 8 | * as published by the Free Software Foundation; either version |
@@ -18,6 +18,9 @@ extern int check_legacy_ioport(unsigned long base_port); | |||
18 | #define _PNPWRP 0xa79 | 18 | #define _PNPWRP 0xa79 |
19 | #define PNPBIOS_BASE 0xf000 | 19 | #define PNPBIOS_BASE 0xf000 |
20 | 20 | ||
21 | #include <linux/device.h> | ||
22 | #include <linux/io.h> | ||
23 | |||
21 | #include <linux/compiler.h> | 24 | #include <linux/compiler.h> |
22 | #include <asm/page.h> | 25 | #include <asm/page.h> |
23 | #include <asm/byteorder.h> | 26 | #include <asm/byteorder.h> |
@@ -744,6 +747,9 @@ static inline void * bus_to_virt(unsigned long address) | |||
744 | 747 | ||
745 | #define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set) | 748 | #define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set) |
746 | 749 | ||
750 | void __iomem *devm_ioremap_prot(struct device *dev, resource_size_t offset, | ||
751 | size_t size, unsigned long flags); | ||
752 | |||
747 | #endif /* __KERNEL__ */ | 753 | #endif /* __KERNEL__ */ |
748 | 754 | ||
749 | #endif /* _ASM_POWERPC_IO_H */ | 755 | #endif /* _ASM_POWERPC_IO_H */ |
diff --git a/include/linux/io.h b/include/linux/io.h index 3a03a3604cce..6c7f0ba0d5fa 100644 --- a/include/linux/io.h +++ b/include/linux/io.h | |||
@@ -65,5 +65,6 @@ void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset, | |||
65 | void devm_iounmap(struct device *dev, void __iomem *addr); | 65 | void devm_iounmap(struct device *dev, void __iomem *addr); |
66 | int check_signature(const volatile void __iomem *io_addr, | 66 | int check_signature(const volatile void __iomem *io_addr, |
67 | const unsigned char *signature, int length); | 67 | const unsigned char *signature, int length); |
68 | void devm_ioremap_release(struct device *dev, void *res); | ||
68 | 69 | ||
69 | #endif /* _LINUX_IO_H */ | 70 | #endif /* _LINUX_IO_H */ |
diff --git a/lib/devres.c b/lib/devres.c index 26c87c49d776..72c8909006da 100644 --- a/lib/devres.c +++ b/lib/devres.c | |||
@@ -2,7 +2,7 @@ | |||
2 | #include <linux/io.h> | 2 | #include <linux/io.h> |
3 | #include <linux/module.h> | 3 | #include <linux/module.h> |
4 | 4 | ||
5 | static void devm_ioremap_release(struct device *dev, void *res) | 5 | void devm_ioremap_release(struct device *dev, void *res) |
6 | { | 6 | { |
7 | iounmap(*(void __iomem **)res); | 7 | iounmap(*(void __iomem **)res); |
8 | } | 8 | } |