Skip to content

Commit 85afc31

Browse files
Ben Widawskydjbw
authored andcommitted
cxl/pci: Split cxl_pci_setup_regs()
In preparation for moving parts of register mapping to cxl_core, split cxl_pci_setup_regs() into a helper that finds register blocks, (cxl_find_regblock()), and a generic wrapper that probes the precise register sets within a block (cxl_setup_regs()). Move the actual mapping (cxl_map_regs()) of the only register-set that cxl_pci cares about (memory device registers) up a level from the former cxl_pci_setup_regs() into cxl_pci_probe(). With this change the unused component registers are no longer mapped, but the helpers are primed to move into the core. [djbw: drop cxl_map_regs() for component registers] Signed-off-by: Ben Widawsky <[email protected]> [djbw: rebase on the cxl_register_map refactor] Reviewed-by: Ira Weiny <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Link: https://lore.kernel.org/r/163434053788.914258.18412599112859205220.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent a261e9a commit 85afc31

File tree

1 file changed

+37
-36
lines changed

1 file changed

+37
-36
lines changed

drivers/cxl/pci.c

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -433,72 +433,69 @@ static void cxl_decode_regblock(u32 reg_lo, u32 reg_hi,
433433
}
434434

435435
/**
436-
* cxl_pci_setup_regs() - Setup necessary MMIO.
437-
* @cxlm: The CXL memory device to communicate with.
436+
* cxl_find_regblock() - Locate register blocks by type
437+
* @pdev: The CXL PCI device to enumerate.
438+
* @type: Register Block Indicator id
439+
* @map: Enumeration output, clobbered on error
438440
*
439-
* Return: 0 if all necessary registers mapped.
441+
* Return: 0 if register block enumerated, negative error code otherwise
440442
*
441-
* A memory device is required by spec to implement a certain set of MMIO
442-
* regions. The purpose of this function is to enumerate and map those
443-
* registers.
443+
* A CXL DVSEC may point to one or more register blocks, search for them
444+
* by @type.
444445
*/
445-
static int cxl_pci_setup_regs(struct cxl_mem *cxlm)
446+
static int cxl_find_regblock(struct pci_dev *pdev, enum cxl_regloc_type type,
447+
struct cxl_register_map *map)
446448
{
447449
u32 regloc_size, regblocks;
448-
int regloc, i, n_maps, ret = 0;
449-
struct device *dev = cxlm->dev;
450-
struct pci_dev *pdev = to_pci_dev(dev);
451-
struct cxl_register_map *map, maps[CXL_REGLOC_RBI_TYPES];
450+
int regloc, i;
452451

453452
regloc = cxl_pci_dvsec(pdev, PCI_DVSEC_ID_CXL_REGLOC_DVSEC_ID);
454-
if (!regloc) {
455-
dev_err(dev, "register location dvsec not found\n");
453+
if (!regloc)
456454
return -ENXIO;
457-
}
458455

459-
/* Get the size of the Register Locator DVSEC */
460456
pci_read_config_dword(pdev, regloc + PCI_DVSEC_HEADER1, &regloc_size);
461457
regloc_size = FIELD_GET(PCI_DVSEC_HEADER1_LENGTH_MASK, regloc_size);
462458

463459
regloc += PCI_DVSEC_ID_CXL_REGLOC_BLOCK1_OFFSET;
464460
regblocks = (regloc_size - PCI_DVSEC_ID_CXL_REGLOC_BLOCK1_OFFSET) / 8;
465461

466-
for (i = 0, n_maps = 0; i < regblocks; i++, regloc += 8) {
462+
for (i = 0; i < regblocks; i++, regloc += 8) {
467463
u32 reg_lo, reg_hi;
468464

469465
pci_read_config_dword(pdev, regloc, &reg_lo);
470466
pci_read_config_dword(pdev, regloc + 4, &reg_hi);
471467

472-
map = &maps[n_maps];
473468
cxl_decode_regblock(reg_lo, reg_hi, map);
474469

475-
/* Ignore unknown register block types */
476-
if (map->reg_type > CXL_REGLOC_RBI_MEMDEV)
477-
continue;
470+
if (map->reg_type == type)
471+
return 0;
472+
}
478473

479-
ret = cxl_map_regblock(pdev, map);
480-
if (ret)
481-
return ret;
474+
return -ENODEV;
475+
}
482476

483-
ret = cxl_probe_regs(pdev, map);
484-
cxl_unmap_regblock(pdev, map);
485-
if (ret)
486-
return ret;
477+
static int cxl_setup_regs(struct pci_dev *pdev, enum cxl_regloc_type type,
478+
struct cxl_register_map *map)
479+
{
480+
int rc;
487481

488-
n_maps++;
489-
}
482+
rc = cxl_find_regblock(pdev, type, map);
483+
if (rc)
484+
return rc;
490485

491-
for (i = 0; i < n_maps; i++) {
492-
ret = cxl_map_regs(cxlm, &maps[i]);
493-
if (ret)
494-
break;
495-
}
486+
rc = cxl_map_regblock(pdev, map);
487+
if (rc)
488+
return rc;
489+
490+
rc = cxl_probe_regs(pdev, map);
491+
cxl_unmap_regblock(pdev, map);
496492

497-
return ret;
493+
return rc;
498494
}
499495

500496
static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
501497
{
498+
struct cxl_register_map map;
502499
struct cxl_memdev *cxlmd;
503500
struct cxl_mem *cxlm;
504501
int rc;
@@ -518,7 +515,11 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
518515
if (IS_ERR(cxlm))
519516
return PTR_ERR(cxlm);
520517

521-
rc = cxl_pci_setup_regs(cxlm);
518+
rc = cxl_setup_regs(pdev, CXL_REGLOC_RBI_MEMDEV, &map);
519+
if (rc)
520+
return rc;
521+
522+
rc = cxl_map_regs(cxlm, &map);
522523
if (rc)
523524
return rc;
524525

0 commit comments

Comments
 (0)