Commit 3229b906 authored by Thomas Zimmermann's avatar Thomas Zimmermann

lib: devres: Add managed arch_phys_wc_add()

Add devm_arch_phys_wc_add() as managed wrapper around arch_phys_wc_add().
Useful for several graphics drivers that set framebuffer memory to write
combining.

v2:
	* fix typo in commit description
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210916181601.9146-2-tzimmermann@suse.de
parent 9c2fce13
...@@ -132,6 +132,8 @@ static inline int arch_phys_wc_index(int handle) ...@@ -132,6 +132,8 @@ static inline int arch_phys_wc_index(int handle)
#endif #endif
#endif #endif
int devm_arch_phys_wc_add(struct device *dev, unsigned long base, unsigned long size);
enum { enum {
/* See memremap() kernel-doc for usage description... */ /* See memremap() kernel-doc for usage description... */
MEMREMAP_WB = 1 << 0, MEMREMAP_WB = 1 << 0,
......
...@@ -528,3 +528,39 @@ void pcim_iounmap_regions(struct pci_dev *pdev, int mask) ...@@ -528,3 +528,39 @@ void pcim_iounmap_regions(struct pci_dev *pdev, int mask)
} }
EXPORT_SYMBOL(pcim_iounmap_regions); EXPORT_SYMBOL(pcim_iounmap_regions);
#endif /* CONFIG_PCI */ #endif /* CONFIG_PCI */
static void devm_arch_phys_ac_add_release(struct device *dev, void *res)
{
arch_phys_wc_del(*((int *)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)
{
int *mtrr;
int ret;
mtrr = devres_alloc(devm_arch_phys_ac_add_release, sizeof(*mtrr), GFP_KERNEL);
if (!mtrr)
return -ENOMEM;
ret = arch_phys_wc_add(base, size);
if (ret < 0) {
devres_free(mtrr);
return ret;
}
*mtrr = ret;
devres_add(dev, mtrr);
return ret;
}
EXPORT_SYMBOL(devm_arch_phys_wc_add);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment