Lines Matching +full:device +full:- +full:addr
1 // SPDX-License-Identifier: GPL-2.0-only
3 #include <linux/io-64-nonatomic-lo-hi.h>
4 #include <linux/device.h>
16 * CXL device capabilities are enumerated by PCI DVSEC (Designated
17 * Vendor-specific) and / or descriptors provided by platform firmware.
18 * They can be defined as a set like the device and component registers
19 * mandated by CXL Section 8.1.12.2 Memory Device PCIe Capabilities and
28 * cxl_probe_component_regs() - Detect CXL Component register blocks
29 * @dev: Host device of the @base mapping
34 * See CXL 2.0 8.2.5.5 CXL Device Register Interface
38 void cxl_probe_component_regs(struct device *dev, void __iomem *base, in cxl_probe_component_regs()
86 rmap = &map->hdm_decoder; in cxl_probe_component_regs()
93 rmap = &map->ras; in cxl_probe_component_regs()
103 rmap->valid = true; in cxl_probe_component_regs()
104 rmap->id = cap_id; in cxl_probe_component_regs()
105 rmap->offset = CXL_CM_OFFSET + offset; in cxl_probe_component_regs()
106 rmap->size = length; in cxl_probe_component_regs()
112 * cxl_probe_device_regs() - Detect CXL Device register blocks
113 * @dev: Host device of the @base mapping
114 * @base: Mapping of CXL 2.0 8.2.8 CXL Device Register Interface
117 * Probe for device register information and return it in map object.
119 void cxl_probe_device_regs(struct device *dev, void __iomem *base, in cxl_probe_device_regs()
148 rmap = &map->status; in cxl_probe_device_regs()
152 rmap = &map->mbox; in cxl_probe_device_regs()
158 dev_dbg(dev, "found Memory Device capability (0x%x)\n", offset); in cxl_probe_device_regs()
159 rmap = &map->memdev; in cxl_probe_device_regs()
171 rmap->valid = true; in cxl_probe_device_regs()
172 rmap->id = cap_id; in cxl_probe_device_regs()
173 rmap->offset = offset; in cxl_probe_device_regs()
174 rmap->size = length; in cxl_probe_device_regs()
179 void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr, in devm_cxl_iomap_block() argument
185 if (WARN_ON_ONCE(addr == CXL_RESOURCE_NONE)) in devm_cxl_iomap_block()
188 res = devm_request_mem_region(dev, addr, length, dev_name(dev)); in devm_cxl_iomap_block()
190 resource_size_t end = addr + length - 1; in devm_cxl_iomap_block()
192 dev_err(dev, "Failed to request region %pa-%pa\n", &addr, &end); in devm_cxl_iomap_block()
196 ret_val = devm_ioremap(dev, addr, length); in devm_cxl_iomap_block()
207 struct device *host = map->host; in cxl_map_component_regs()
210 void __iomem **addr; in cxl_map_component_regs() member
212 { &map->component_map.hdm_decoder, ®s->hdm_decoder }, in cxl_map_component_regs()
213 { &map->component_map.ras, ®s->ras }, in cxl_map_component_regs()
219 resource_size_t addr; in cxl_map_component_regs() local
222 if (!mi->rmap->valid) in cxl_map_component_regs()
224 if (!test_bit(mi->rmap->id, &map_mask)) in cxl_map_component_regs()
226 addr = map->resource + mi->rmap->offset; in cxl_map_component_regs()
227 length = mi->rmap->size; in cxl_map_component_regs()
228 *(mi->addr) = devm_cxl_iomap_block(host, addr, length); in cxl_map_component_regs()
229 if (!*(mi->addr)) in cxl_map_component_regs()
230 return -ENOMEM; in cxl_map_component_regs()
240 struct device *host = map->host; in cxl_map_device_regs()
241 resource_size_t phys_addr = map->resource; in cxl_map_device_regs()
244 void __iomem **addr; in cxl_map_device_regs() member
246 { &map->device_map.status, ®s->status, }, in cxl_map_device_regs()
247 { &map->device_map.mbox, ®s->mbox, }, in cxl_map_device_regs()
248 { &map->device_map.memdev, ®s->memdev, }, in cxl_map_device_regs()
255 resource_size_t addr; in cxl_map_device_regs() local
257 if (!mi->rmap->valid) in cxl_map_device_regs()
260 addr = phys_addr + mi->rmap->offset; in cxl_map_device_regs()
261 length = mi->rmap->size; in cxl_map_device_regs()
262 *(mi->addr) = devm_cxl_iomap_block(host, addr, length); in cxl_map_device_regs()
263 if (!*(mi->addr)) in cxl_map_device_regs()
264 return -ENOMEM; in cxl_map_device_regs()
280 dev_warn(&pdev->dev, in cxl_decode_regblock()
282 &pdev->resource[bar], &offset, reg_type); in cxl_decode_regblock()
286 map->reg_type = reg_type; in cxl_decode_regblock()
287 map->resource = pci_resource_start(pdev, bar) + offset; in cxl_decode_regblock()
288 map->max_size = pci_resource_len(pdev, bar) - offset; in cxl_decode_regblock()
293 * cxl_find_regblock_instance() - Locate a register block by type / index
294 * @pdev: The CXL PCI device to enumerate.
313 .host = &pdev->dev, in cxl_find_regblock_instance()
320 return -ENXIO; in cxl_find_regblock_instance()
326 regblocks = (regloc_size - CXL_DVSEC_REG_LOCATOR_BLOCK1_OFFSET) / 8; in cxl_find_regblock_instance()
337 if (map->reg_type == type) { in cxl_find_regblock_instance()
344 map->resource = CXL_RESOURCE_NONE; in cxl_find_regblock_instance()
345 return -ENODEV; in cxl_find_regblock_instance()
350 * cxl_find_regblock() - Locate register blocks by type
351 * @pdev: The CXL PCI device to enumerate.
368 * cxl_count_regblock() - Count instances of a given regblock type.
369 * @pdev: The CXL PCI device to enumerate.
392 struct device *dev = map->host; in cxl_map_pmu_regs()
395 phys_addr = map->resource; in cxl_map_pmu_regs()
396 regs->pmu = devm_cxl_iomap_block(dev, phys_addr, CXL_PMU_REGMAP_SIZE); in cxl_map_pmu_regs()
397 if (!regs->pmu) in cxl_map_pmu_regs()
398 return -ENOMEM; in cxl_map_pmu_regs()
406 struct device *host = map->host; in cxl_map_regblock()
408 map->base = ioremap(map->resource, map->max_size); in cxl_map_regblock()
409 if (!map->base) { in cxl_map_regblock()
411 return -ENOMEM; in cxl_map_regblock()
414 dev_dbg(host, "Mapped CXL Memory Device resource %pa\n", &map->resource); in cxl_map_regblock()
420 iounmap(map->base); in cxl_unmap_regblock()
421 map->base = NULL; in cxl_unmap_regblock()
428 struct device *host = map->host; in cxl_probe_regs()
429 void __iomem *base = map->base; in cxl_probe_regs()
431 switch (map->reg_type) { in cxl_probe_regs()
433 comp_map = &map->component_map; in cxl_probe_regs()
438 dev_map = &map->device_map; in cxl_probe_regs()
440 if (!dev_map->status.valid || !dev_map->mbox.valid || in cxl_probe_regs()
441 !dev_map->memdev.valid) { in cxl_probe_regs()
443 !dev_map->status.valid ? "status " : "", in cxl_probe_regs()
444 !dev_map->mbox.valid ? "mbox " : "", in cxl_probe_regs()
445 !dev_map->memdev.valid ? "memdev " : ""); in cxl_probe_regs()
446 return -ENXIO; in cxl_probe_regs()
449 dev_dbg(host, "Probing device registers...\n"); in cxl_probe_regs()
473 u16 cxl_rcrb_to_aer(struct device *dev, resource_size_t rcrb) in cxl_rcrb_to_aer()
475 void __iomem *addr; in cxl_rcrb_to_aer() local
485 addr = ioremap(rcrb, SZ_4K); in cxl_rcrb_to_aer()
486 if (!addr) in cxl_rcrb_to_aer()
489 cap_hdr = readl(addr + offset); in cxl_rcrb_to_aer()
496 cap_hdr = readl(addr + offset); in cxl_rcrb_to_aer()
502 iounmap(addr); in cxl_rcrb_to_aer()
509 resource_size_t __rcrb_to_component(struct device *dev, struct cxl_rcrb_info *ri, in __rcrb_to_component()
513 resource_size_t rcrb = ri->base; in __rcrb_to_component()
514 void __iomem *addr; in __rcrb_to_component() local
530 addr = ioremap(rcrb, SZ_4K); in __rcrb_to_component()
531 if (!addr) { in __rcrb_to_component()
532 dev_err(dev, "Failed to map region %pr\n", addr); in __rcrb_to_component()
537 id = readl(addr + PCI_VENDOR_ID); in __rcrb_to_component()
538 cmd = readw(addr + PCI_COMMAND); in __rcrb_to_component()
539 bar0 = readl(addr + PCI_BASE_ADDRESS_0); in __rcrb_to_component()
540 bar1 = readl(addr + PCI_BASE_ADDRESS_1); in __rcrb_to_component()
541 iounmap(addr); in __rcrb_to_component()
545 * Sanity check, see CXL 3.0 Figure 9-8 CXL Device that Does Not in __rcrb_to_component()
573 resource_size_t cxl_rcd_component_reg_phys(struct device *dev, in cxl_rcd_component_reg_phys()
576 if (!dport->rch) in cxl_rcd_component_reg_phys()
578 return __rcrb_to_component(dev, &dport->rcrb, CXL_RCRB_UPSTREAM); in cxl_rcd_component_reg_phys()