Merge branch 'pci/ioremap' into next
* pci/ioremap: PCI: versatile: Update PCI config space remap function PCI: keystone-dw: Update PCI config space remap function PCI: layerscape: Update PCI config space remap function PCI: hisi: Update PCI config space remap function PCI: tegra: Update PCI config space remap function PCI: xgene: Update PCI config space remap function PCI: armada8k: Update PCI config space remap function PCI: designware: Update PCI config space remap function PCI: iproc-platform: Update PCI config space remap function PCI: qcom: Update PCI config space remap function PCI: rockchip: Update PCI config space remap function PCI: spear13xx: Update PCI config space remap function PCI: xilinx-nwl: Update PCI config space remap function PCI: xilinx: Update PCI config space remap function PCI: ECAM: Map config region with pci_remap_cfgspace() PCI: Implement devm_pci_remap_cfgspace() devres: fix devm_ioremap_*() offset parameter kerneldoc description ARM: Implement pci_remap_cfgspace() interface ARM64: Implement pci_remap_cfgspace() interface linux/io.h: Add pci_remap_cfgspace() interface PCI: Remove __weak tag from pci_remap_iospace()
This commit is contained in:
@@ -3363,7 +3363,7 @@ unsigned long __weak pci_address_to_pio(phys_addr_t address)
|
||||
* Only architectures that have memory mapped IO functions defined
|
||||
* (and the PCI_IOBASE value defined) should call this function.
|
||||
*/
|
||||
int __weak pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr)
|
||||
int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr)
|
||||
{
|
||||
#if defined(PCI_IOBASE) && defined(CONFIG_MMU)
|
||||
unsigned long vaddr = (unsigned long)PCI_IOBASE + res->start;
|
||||
@@ -3403,6 +3403,88 @@ void pci_unmap_iospace(struct resource *res)
|
||||
}
|
||||
EXPORT_SYMBOL(pci_unmap_iospace);
|
||||
|
||||
/**
|
||||
* devm_pci_remap_cfgspace - Managed pci_remap_cfgspace()
|
||||
* @dev: Generic device to remap IO address for
|
||||
* @offset: Resource address to map
|
||||
* @size: Size of map
|
||||
*
|
||||
* Managed pci_remap_cfgspace(). Map is automatically unmapped on driver
|
||||
* detach.
|
||||
*/
|
||||
void __iomem *devm_pci_remap_cfgspace(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 = pci_remap_cfgspace(offset, size);
|
||||
if (addr) {
|
||||
*ptr = addr;
|
||||
devres_add(dev, ptr);
|
||||
} else
|
||||
devres_free(ptr);
|
||||
|
||||
return addr;
|
||||
}
|
||||
EXPORT_SYMBOL(devm_pci_remap_cfgspace);
|
||||
|
||||
/**
|
||||
* devm_pci_remap_cfg_resource - check, request region and ioremap cfg resource
|
||||
* @dev: generic device to handle the resource for
|
||||
* @res: configuration space resource to be handled
|
||||
*
|
||||
* Checks that a resource is a valid memory region, requests the memory
|
||||
* region and ioremaps with pci_remap_cfgspace() API that ensures the
|
||||
* proper PCI configuration space memory attributes are guaranteed.
|
||||
*
|
||||
* 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_pci_remap_cfg_resource(&pdev->dev, res);
|
||||
* if (IS_ERR(base))
|
||||
* return PTR_ERR(base);
|
||||
*/
|
||||
void __iomem *devm_pci_remap_cfg_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_pci_remap_cfgspace(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;
|
||||
}
|
||||
EXPORT_SYMBOL(devm_pci_remap_cfg_resource);
|
||||
|
||||
static void __pci_set_master(struct pci_dev *dev, bool enable)
|
||||
{
|
||||
u16 old_cmd, cmd;
|
||||
|
Reference in New Issue
Block a user