summaryrefslogtreecommitdiff
path: root/drivers/cxl/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/cxl/core.c')
-rw-r--r--drivers/cxl/core.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/drivers/cxl/core.c b/drivers/cxl/core.c
index f836aaab03e0..c1efa11207b5 100644
--- a/drivers/cxl/core.c
+++ b/drivers/cxl/core.c
@@ -79,11 +79,33 @@ void cxl_probe_device_regs(struct device *dev, void __iomem *base,
}
EXPORT_SYMBOL_GPL(cxl_probe_device_regs);
+static void __iomem *devm_cxl_iomap_block(struct pci_dev *pdev,
+ resource_size_t addr,
+ resource_size_t length)
+{
+ struct device *dev = &pdev->dev;
+ void __iomem *ret_val;
+ struct resource *res;
+
+ res = devm_request_mem_region(dev, addr, length, pci_name(pdev));
+ if (!res) {
+ resource_size_t end = addr + length - 1;
+
+ dev_err(dev, "Failed to request region %pa-%pa\n", &addr, &end);
+ return NULL;
+ }
+
+ ret_val = devm_ioremap(dev, addr, length);
+ if (!ret_val)
+ dev_err(dev, "Failed to map region %pr\n", res);
+
+ return ret_val;
+}
+
int cxl_map_device_regs(struct pci_dev *pdev,
struct cxl_device_regs *regs,
struct cxl_register_map *map)
{
- struct device *dev = &pdev->dev;
resource_size_t phys_addr;
phys_addr = pci_resource_start(pdev, map->barno);
@@ -95,7 +117,9 @@ int cxl_map_device_regs(struct pci_dev *pdev,
addr = phys_addr + map->device_map.status.offset;
length = map->device_map.status.size;
- regs->status = devm_ioremap(dev, addr, length);
+ regs->status = devm_cxl_iomap_block(pdev, addr, length);
+ if (!regs->status)
+ return -ENOMEM;
}
if (map->device_map.mbox.valid) {
@@ -104,7 +128,9 @@ int cxl_map_device_regs(struct pci_dev *pdev,
addr = phys_addr + map->device_map.mbox.offset;
length = map->device_map.mbox.size;
- regs->mbox = devm_ioremap(dev, addr, length);
+ regs->mbox = devm_cxl_iomap_block(pdev, addr, length);
+ if (!regs->mbox)
+ return -ENOMEM;
}
if (map->device_map.memdev.valid) {
@@ -113,7 +139,9 @@ int cxl_map_device_regs(struct pci_dev *pdev,
addr = phys_addr + map->device_map.memdev.offset;
length = map->device_map.memdev.size;
- regs->memdev = devm_ioremap(dev, addr, length);
+ regs->memdev = devm_cxl_iomap_block(pdev, addr, length);
+ if (!regs->memdev)
+ return -ENOMEM;
}
return 0;