mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-23 16:53:58 -05:00
of: Provide a function to request and map memory
A call to of_iomap does not request the memory region. This patch adds the function of_io_request_and_map which requests the memory region before mapping it. Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com> Suggested-by: Thomas Gleixner <tglx@linutronix.de> Suggested-by: Rob Herring <robh@kernel.org> Acked-by: Rob Herring <robh@kernel.org> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
This commit is contained in:
parent
7e1391876c
commit
efd342fb00
4 changed files with 49 additions and 2 deletions
|
@ -702,6 +702,42 @@ void __iomem *of_iomap(struct device_node *np, int index)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(of_iomap);
|
EXPORT_SYMBOL(of_iomap);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* of_io_request_and_map - Requests a resource and maps the memory mapped IO
|
||||||
|
* for a given device_node
|
||||||
|
* @device: the device whose io range will be mapped
|
||||||
|
* @index: index of the io range
|
||||||
|
* @name: name of the resource
|
||||||
|
*
|
||||||
|
* Returns a pointer to the requested and mapped memory or an ERR_PTR() encoded
|
||||||
|
* error code on failure. Usage example:
|
||||||
|
*
|
||||||
|
* base = of_io_request_and_map(node, 0, "foo");
|
||||||
|
* if (IS_ERR(base))
|
||||||
|
* return PTR_ERR(base);
|
||||||
|
*/
|
||||||
|
void __iomem *of_io_request_and_map(struct device_node *np, int index,
|
||||||
|
char *name)
|
||||||
|
{
|
||||||
|
struct resource res;
|
||||||
|
void __iomem *mem;
|
||||||
|
|
||||||
|
if (of_address_to_resource(np, index, &res))
|
||||||
|
return IOMEM_ERR_PTR(-EINVAL);
|
||||||
|
|
||||||
|
if (!request_mem_region(res.start, resource_size(&res), name))
|
||||||
|
return IOMEM_ERR_PTR(-EBUSY);
|
||||||
|
|
||||||
|
mem = ioremap(res.start, resource_size(&res));
|
||||||
|
if (!mem) {
|
||||||
|
release_mem_region(res.start, resource_size(&res));
|
||||||
|
return IOMEM_ERR_PTR(-ENOMEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mem;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(of_io_request_and_map);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* of_dma_get_range - Get DMA range info
|
* of_dma_get_range - Get DMA range info
|
||||||
* @np: device node to get DMA range info
|
* @np: device node to get DMA range info
|
||||||
|
|
|
@ -58,6 +58,8 @@ static inline void devm_ioport_unmap(struct device *dev, void __iomem *addr)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define IOMEM_ERR_PTR(err) (__force void __iomem *)ERR_PTR(err)
|
||||||
|
|
||||||
void __iomem *devm_ioremap(struct device *dev, resource_size_t offset,
|
void __iomem *devm_ioremap(struct device *dev, resource_size_t offset,
|
||||||
unsigned long size);
|
unsigned long size);
|
||||||
void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset,
|
void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset,
|
||||||
|
|
|
@ -109,7 +109,12 @@ static inline bool of_dma_is_coherent(struct device_node *np)
|
||||||
extern int of_address_to_resource(struct device_node *dev, int index,
|
extern int of_address_to_resource(struct device_node *dev, int index,
|
||||||
struct resource *r);
|
struct resource *r);
|
||||||
void __iomem *of_iomap(struct device_node *node, int index);
|
void __iomem *of_iomap(struct device_node *node, int index);
|
||||||
|
void __iomem *of_io_request_and_map(struct device_node *device,
|
||||||
|
int index, char *name);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
#include <linux/io.h>
|
||||||
|
|
||||||
static inline int of_address_to_resource(struct device_node *dev, int index,
|
static inline int of_address_to_resource(struct device_node *dev, int index,
|
||||||
struct resource *r)
|
struct resource *r)
|
||||||
{
|
{
|
||||||
|
@ -120,6 +125,12 @@ static inline void __iomem *of_iomap(struct device_node *device, int index)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void __iomem *of_io_request_and_map(struct device_node *device,
|
||||||
|
int index, char *name)
|
||||||
|
{
|
||||||
|
return IOMEM_ERR_PTR(-EINVAL);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
|
#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
|
||||||
|
|
|
@ -86,8 +86,6 @@ void devm_iounmap(struct device *dev, void __iomem *addr)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(devm_iounmap);
|
EXPORT_SYMBOL(devm_iounmap);
|
||||||
|
|
||||||
#define IOMEM_ERR_PTR(err) (__force void __iomem *)ERR_PTR(err)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* devm_ioremap_resource() - check, request region, and ioremap resource
|
* devm_ioremap_resource() - check, request region, and ioremap resource
|
||||||
* @dev: generic device to handle the resource for
|
* @dev: generic device to handle the resource for
|
||||||
|
|
Loading…
Add table
Reference in a new issue