// SPDX-License-Identifier: GPL-2.0 #include <linux/bug.h> #include <linux/device.h> #include <linux/errno.h> #include <linux/export.h> #include <linux/gfp_types.h> #include <linux/io.h> #include <linux/ioport.h> #include <linux/of_address.h> #include <linux/types.h> enum devm_ioremap_type { … }; void devm_ioremap_release(struct device *dev, void *res) { … } static int devm_ioremap_match(struct device *dev, void *res, void *match_data) { … } static void __iomem *__devm_ioremap(struct device *dev, resource_size_t offset, resource_size_t size, enum devm_ioremap_type type) { … } /** * devm_ioremap - Managed ioremap() * @dev: Generic device to remap IO address for * @offset: Resource address to map * @size: Size of map * * Managed ioremap(). Map is automatically unmapped on driver detach. */ void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, resource_size_t size) { … } EXPORT_SYMBOL(…); /** * devm_ioremap_uc - Managed ioremap_uc() * @dev: Generic device to remap IO address for * @offset: Resource address to map * @size: Size of map * * Managed ioremap_uc(). Map is automatically unmapped on driver detach. */ void __iomem *devm_ioremap_uc(struct device *dev, resource_size_t offset, resource_size_t size) { … } EXPORT_SYMBOL_GPL(…); /** * devm_ioremap_wc - Managed ioremap_wc() * @dev: Generic device to remap IO address for * @offset: Resource address to map * @size: Size of map * * Managed ioremap_wc(). Map is automatically unmapped on driver detach. */ void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset, resource_size_t size) { … } EXPORT_SYMBOL(…); /** * devm_iounmap - Managed iounmap() * @dev: Generic device to unmap for * @addr: Address to unmap * * Managed iounmap(). @addr must have been mapped using devm_ioremap*(). */ void devm_iounmap(struct device *dev, void __iomem *addr) { … } EXPORT_SYMBOL(…); static void __iomem * __devm_ioremap_resource(struct device *dev, const struct resource *res, enum devm_ioremap_type type) { … } /** * devm_ioremap_resource() - check, request region, and ioremap resource * @dev: generic device to handle the resource for * @res: resource to be handled * * Checks that a resource is a valid memory region, requests the memory * region and ioremaps it. All operations are managed and will be undone * on driver detach. * * Usage example: * * res = platform_get_resource(pdev, IORESOURCE_MEM, 0); * base = devm_ioremap_resource(&pdev->dev, res); * if (IS_ERR(base)) * return PTR_ERR(base); * * Return: a pointer to the remapped memory or an ERR_PTR() encoded error code * on failure. */ void __iomem *devm_ioremap_resource(struct device *dev, const struct resource *res) { … } EXPORT_SYMBOL(…); /** * devm_ioremap_resource_wc() - write-combined variant of * devm_ioremap_resource() * @dev: generic device to handle the resource for * @res: resource to be handled * * Return: a pointer to the remapped memory or an ERR_PTR() encoded error code * on failure. */ void __iomem *devm_ioremap_resource_wc(struct device *dev, const struct resource *res) { … } /* * devm_of_iomap - Requests a resource and maps the memory mapped IO * for a given device_node managed by a given device * * Checks that a resource is a valid memory region, requests the memory * region and ioremaps it. All operations are managed and will be undone * on driver detach of the device. * * This is to be used when a device requests/maps resources described * by other device tree nodes (children or otherwise). * * @dev: The device "managing" the resource * @node: The device-tree node where the resource resides * @index: index of the MMIO range in the "reg" property * @size: Returns the size of the resource (pass NULL if not needed) * * Usage example: * * base = devm_of_iomap(&pdev->dev, node, 0, NULL); * if (IS_ERR(base)) * return PTR_ERR(base); * * Please Note: This is not a one-to-one replacement for of_iomap() because the * of_iomap() function does not track whether the region is already mapped. If * two drivers try to map the same memory, the of_iomap() function will succeed * but the devm_of_iomap() function will return -EBUSY. * * Return: a pointer to the requested and mapped memory or an ERR_PTR() encoded * error code on failure. */ void __iomem *devm_of_iomap(struct device *dev, struct device_node *node, int index, resource_size_t *size) { … } EXPORT_SYMBOL(…); #ifdef CONFIG_HAS_IOPORT_MAP /* * Generic iomap devres */ static void devm_ioport_map_release(struct device *dev, void *res) { … } static int devm_ioport_map_match(struct device *dev, void *res, void *match_data) { … } /** * devm_ioport_map - Managed ioport_map() * @dev: Generic device to map ioport for * @port: Port to map * @nr: Number of ports to map * * Managed ioport_map(). Map is automatically unmapped on driver * detach. * * Return: a pointer to the remapped memory or NULL on failure. */ void __iomem *devm_ioport_map(struct device *dev, unsigned long port, unsigned int nr) { … } EXPORT_SYMBOL(…); /** * devm_ioport_unmap - Managed ioport_unmap() * @dev: Generic device to unmap for * @addr: Address to unmap * * Managed ioport_unmap(). @addr must have been mapped using * devm_ioport_map(). */ void devm_ioport_unmap(struct device *dev, void __iomem *addr) { … } EXPORT_SYMBOL(…); #endif /* CONFIG_HAS_IOPORT_MAP */ static void devm_arch_phys_ac_add_release(struct device *dev, void *res) { … } /** * devm_arch_phys_wc_add - Managed arch_phys_wc_add() * @dev: Managed device * @base: Memory base address * @size: Size of memory range * * Adds a WC MTRR using arch_phys_wc_add() and sets up a release callback. * See arch_phys_wc_add() for more information. */ int devm_arch_phys_wc_add(struct device *dev, unsigned long base, unsigned long size) { … } EXPORT_SYMBOL(…); struct arch_io_reserve_memtype_wc_devres { … }; static void devm_arch_io_free_memtype_wc_release(struct device *dev, void *res) { … } /** * devm_arch_io_reserve_memtype_wc - Managed arch_io_reserve_memtype_wc() * @dev: Managed device * @start: Memory base address * @size: Size of memory range * * Reserves a memory range with WC caching using arch_io_reserve_memtype_wc() * and sets up a release callback See arch_io_reserve_memtype_wc() for more * information. */ int devm_arch_io_reserve_memtype_wc(struct device *dev, resource_size_t start, resource_size_t size) { … } EXPORT_SYMBOL(…);