cregit-Linux how code gets into the kernel

Release 4.9 lib/devres.c

Directory: lib
#include <linux/err.h>
#include <linux/pci.h>
#include <linux/io.h>
#include <linux/gfp.h>
#include <linux/export.h>


void devm_ioremap_release(struct device *dev, void *res) { iounmap(*(void __iomem **)res); }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro26100.00%1100.00%
Total26100.00%1100.00%


static int devm_ioremap_match(struct device *dev, void *res, void *match_data) { return *(void **)res == match_data; }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro30100.00%1100.00%
Total30100.00%1100.00%

/** * devm_ioremap - Managed ioremap() * @dev: Generic device to remap IO address for * @offset: BUS offset 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) { void __iomem **ptr, *addr; ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL); if (!ptr) return NULL; addr = ioremap(offset, size); if (addr) { *ptr = addr; devres_add(dev, ptr); } else devres_free(ptr); return addr; }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro8497.67%133.33%
kumar galakumar gala11.16%133.33%
cristian stoicacristian stoica11.16%133.33%
Total86100.00%3100.00%

EXPORT_SYMBOL(devm_ioremap); /** * devm_ioremap_nocache - Managed ioremap_nocache() * @dev: Generic device to remap IO address for * @offset: BUS offset to map * @size: Size of map * * Managed ioremap_nocache(). Map is automatically unmapped on driver * detach. */
void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset, resource_size_t size) { void __iomem **ptr, *addr; ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL); if (!ptr) return NULL; addr = ioremap_nocache(offset, size); if (addr) { *ptr = addr; devres_add(dev, ptr); } else devres_free(ptr); return addr; }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro8497.67%133.33%
kumar galakumar gala11.16%133.33%
cristian stoicacristian stoica11.16%133.33%
Total86100.00%3100.00%

EXPORT_SYMBOL(devm_ioremap_nocache); /** * devm_ioremap_wc - Managed ioremap_wc() * @dev: Generic device to remap IO address for * @offset: BUS offset 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) { void __iomem **ptr, *addr; ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL); if (!ptr) return NULL; addr = ioremap_wc(offset, size); if (addr) { *ptr = addr; devres_add(dev, ptr); } else devres_free(ptr); return addr; }

Contributors

PersonTokensPropCommitsCommitProp
abhilash kesavanabhilash kesavan86100.00%1100.00%
Total86100.00%1100.00%

EXPORT_SYMBOL(devm_ioremap_wc); /** * 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) { WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match, (__force void *)addr)); iounmap(addr); }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro3384.62%133.33%
maxin b. johnmaxin b. john512.82%133.33%
steven rostedtsteven rostedt12.56%133.33%
Total39100.00%3100.00%

EXPORT_SYMBOL(devm_iounmap); /** * 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. * * Returns a pointer to the remapped memory or an ERR_PTR() encoded error code * on failure. 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); */
void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res) { resource_size_t size; const char *name; void __iomem *dest_ptr; BUG_ON(!dev); if (!res || resource_type(res) != IORESOURCE_MEM) { dev_err(dev, "invalid resource\n"); return IOMEM_ERR_PTR(-EINVAL); } size = resource_size(res); name = res->name ?: dev_name(dev); if (!devm_request_mem_region(dev, res->start, size, name)) { dev_err(dev, "can't request region for resource %pR\n", res); return IOMEM_ERR_PTR(-EBUSY); } dest_ptr = devm_ioremap(dev, res->start, size); if (!dest_ptr) { dev_err(dev, "ioremap failed for resource %pR\n", res); devm_release_mem_region(dev, res->start, size); dest_ptr = IOMEM_ERR_PTR(-ENOMEM); } return dest_ptr; }

Contributors

PersonTokensPropCommitsCommitProp
wolfram sangwolfram sang14586.31%133.33%
thierry redingthierry reding2011.90%133.33%
steven rostedtsteven rostedt31.79%133.33%
Total168100.00%3100.00%

EXPORT_SYMBOL(devm_ioremap_resource); #ifdef CONFIG_HAS_IOPORT_MAP /* * Generic iomap devres */
static void devm_ioport_map_release(struct device *dev, void *res) { ioport_unmap(*(void __iomem **)res); }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro27100.00%1100.00%
Total27100.00%1100.00%


static int devm_ioport_map_match(struct device *dev, void *res, void *match_data) { return *(void **)res == match_data; }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro30100.00%1100.00%
Total30100.00%1100.00%

/** * 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. */
void __iomem *devm_ioport_map(struct device *dev, unsigned long port, unsigned int nr) { void __iomem **ptr, *addr; ptr = devres_alloc(devm_ioport_map_release, sizeof(*ptr), GFP_KERNEL); if (!ptr) return NULL; addr = ioport_map(port, nr); if (addr) { *ptr = addr; devres_add(dev, ptr); } else devres_free(ptr); return addr; }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro88100.00%1100.00%
Total88100.00%1100.00%

EXPORT_SYMBOL(devm_ioport_map); /** * 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) { ioport_unmap(addr); WARN_ON(devres_destroy(dev, devm_ioport_map_release, devm_ioport_map_match, (__force void *)addr)); }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro3897.44%150.00%
steven rostedtsteven rostedt12.56%150.00%
Total39100.00%2100.00%

EXPORT_SYMBOL(devm_ioport_unmap); #endif /* CONFIG_HAS_IOPORT_MAP */ #ifdef CONFIG_PCI /* * PCI iomap devres */ #define PCIM_IOMAP_MAX PCI_ROM_RESOURCE struct pcim_iomap_devres { void __iomem *table[PCIM_IOMAP_MAX]; };
static void pcim_iomap_release(struct device *gendev, void *res) { struct pci_dev *dev = to_pci_dev(gendev); struct pcim_iomap_devres *this = res; int i; for (i = 0; i < PCIM_IOMAP_MAX; i++) if (this->table[i]) pci_iounmap(dev, this->table[i]); }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro6898.55%150.00%
geliang tanggeliang tang11.45%150.00%
Total69100.00%2100.00%

/** * pcim_iomap_table - access iomap allocation table * @pdev: PCI device to access iomap table for * * Access iomap allocation table for @dev. If iomap table doesn't * exist and @pdev is managed, it will be allocated. All iomaps * recorded in the iomap table are automatically unmapped on driver * detach. * * This function might sleep when the table is first allocated but can * be safely called without context and guaranteed to succed once * allocated. */
void __iomem * const *pcim_iomap_table(struct pci_dev *pdev) { struct pcim_iomap_devres *dr, *new_dr; dr = devres_find(&pdev->dev, pcim_iomap_release, NULL, NULL); if (dr) return dr->table; new_dr = devres_alloc(pcim_iomap_release, sizeof(*new_dr), GFP_KERNEL); if (!new_dr) return NULL; dr = devres_get(&pdev->dev, new_dr, NULL, NULL); return dr->table; }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro91100.00%1100.00%
Total91100.00%1100.00%

EXPORT_SYMBOL(pcim_iomap_table); /** * pcim_iomap - Managed pcim_iomap() * @pdev: PCI device to iomap for * @bar: BAR to iomap * @maxlen: Maximum length of iomap * * Managed pci_iomap(). Map is automatically unmapped on driver * detach. */
void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen) { void __iomem **tbl; BUG_ON(bar >= PCIM_IOMAP_MAX); tbl = (void __iomem **)pcim_iomap_table(pdev); if (!tbl || tbl[bar]) /* duplicate mappings not allowed */ return NULL; tbl[bar] = pci_iomap(pdev, bar, maxlen); return tbl[bar]; }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro79100.00%1100.00%
Total79100.00%1100.00%

EXPORT_SYMBOL(pcim_iomap); /** * pcim_iounmap - Managed pci_iounmap() * @pdev: PCI device to iounmap for * @addr: Address to unmap * * Managed pci_iounmap(). @addr must have been mapped using pcim_iomap(). */
void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr) { void __iomem **tbl; int i; pci_iounmap(pdev, addr); tbl = (void __iomem **)pcim_iomap_table(pdev); BUG_ON(!tbl); for (i = 0; i < PCIM_IOMAP_MAX; i++) if (tbl[i] == addr) { tbl[i] = NULL; return; } WARN_ON(1); }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro87100.00%1100.00%
Total87100.00%1100.00%

EXPORT_SYMBOL(pcim_iounmap); /** * pcim_iomap_regions - Request and iomap PCI BARs * @pdev: PCI device to map IO resources for * @mask: Mask of BARs to request and iomap * @name: Name used when requesting regions * * Request and iomap regions specified by @mask. */
int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name) { void __iomem * const *iomap; int i, rc; iomap = pcim_iomap_table(pdev); if (!iomap) return -ENOMEM; for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { unsigned long len; if (!(mask & (1 << i))) continue; rc = -EINVAL; len = pci_resource_len(pdev, i); if (!len) goto err_inval; rc = pci_request_region(pdev, i, name); if (rc) goto err_inval; rc = -ENOMEM; if (!pcim_iomap(pdev, i, 0)) goto err_region; } return 0; err_region: pci_release_region(pdev, i); err_inval: while (--i >= 0) { if (!(mask & (1 << i))) continue; pcim_iounmap(pdev, iomap[i]); pci_release_region(pdev, i); } return rc; }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro17991.33%133.33%
frederik deweerdtfrederik deweerdt168.16%133.33%
yinghai luyinghai lu10.51%133.33%
Total196100.00%3100.00%

EXPORT_SYMBOL(pcim_iomap_regions); /** * pcim_iomap_regions_request_all - Request all BARs and iomap specified ones * @pdev: PCI device to map IO resources for * @mask: Mask of BARs to iomap * @name: Name used when requesting regions * * Request all PCI BARs and iomap regions specified by @mask. */
int pcim_iomap_regions_request_all(struct pci_dev *pdev, int mask, const char *name) { int request_mask = ((1 << 6) - 1) & ~mask; int rc; rc = pci_request_selected_regions(pdev, request_mask, name); if (rc) return rc; rc = pcim_iomap_regions(pdev, mask, name); if (rc) pci_release_selected_regions(pdev, request_mask); return rc; }

Contributors

PersonTokensPropCommitsCommitProp
tejun heotejun heo7998.75%150.00%
yinghai luyinghai lu11.25%150.00%
Total80100.00%2100.00%

EXPORT_SYMBOL(pcim_iomap_regions_request_all); /** * pcim_iounmap_regions - Unmap and release PCI BARs * @pdev: PCI device to map IO resources for * @mask: Mask of BARs to unmap and release * * Unmap and release regions specified by @mask. */
void pcim_iounmap_regions(struct pci_dev *pdev, int mask) { void __iomem * const *iomap; int i; iomap = pcim_iomap_table(pdev); if (!iomap) return; for (i = 0; i < PCIM_IOMAP_MAX; i++) { if (!(mask & (1 << i))) continue; pcim_iounmap(pdev, iomap[i]); pci_release_region(pdev, i); } }

Contributors

PersonTokensPropCommitsCommitProp
tejun heotejun heo8097.56%133.33%
yinghai luyinghai lu11.22%133.33%
dan carpenterdan carpenter11.22%133.33%
Total82100.00%3100.00%

EXPORT_SYMBOL(pcim_iounmap_regions); #endif /* CONFIG_PCI */

Overall Contributors

PersonTokensPropCommitsCommitProp
al viroal viro103268.21%14.55%
tejun heotejun heo17311.43%313.64%
wolfram sangwolfram sang1469.65%29.09%
abhilash kesavanabhilash kesavan926.08%14.55%
thierry redingthierry reding281.85%29.09%
frederik deweerdtfrederik deweerdt161.06%14.55%
maxin b. johnmaxin b. john50.33%14.55%
steven rostedtsteven rostedt50.33%14.55%
yinghai luyinghai lu30.20%14.55%
uwe kleine-koeniguwe kleine-koenig20.13%14.55%
cristian stoicacristian stoica20.13%14.55%
kumar galakumar gala20.13%14.55%
jingoo hanjingoo han20.13%14.55%
vasiliy kulikovvasiliy kulikov10.07%14.55%
dan carpenterdan carpenter10.07%14.55%
dan williamsdan williams10.07%14.55%
paul gortmakerpaul gortmaker10.07%14.55%
geliang tanggeliang tang10.07%14.55%
Total1513100.00%22100.00%
Directory: lib