Re: [PATCH v9 05/16] PCI: imx6: Using "linux,pci-domain" as slot ID

From: Bjorn Helgaas
Date: Fri Feb 02 2024 - 16:54:43 EST


On Fri, Jan 19, 2024 at 12:11:11PM -0500, Frank Li wrote:
> Avoid use get slot id by compared with register physical address. If there
> are more than 2 slots, compared logic will become complex.
>
> "linux,pci-domain" already exist at dts since commit:
> commit (c0b70f05c87f3b arm64: dts: imx8mq: use_dt_domains for pci node).
>
> So it is safe to remove compare basic address code:
> ...
> if (dbi_base->start == IMX8MQ_PCIE2_BASE_ADDR)
> imx6_pcie->controller_id = 1;
> ...

I have no idea what this is telling me. I guess you don't want to use
IMX8MQ_PCIE2_BASE_ADDR to decide something? That much sounds good:
the *address* of some MMIO space doesn't tell us anything about the
function of that space.

I expect the "compatible" string to tell the driver what the
programming model of the device is.

> + /* Using linux,pci-domain as PCI slot id */
> + imx6_pcie->controller_id = of_get_pci_domain_nr(node);
> + /*
> + * If there are no "linux,pci-domain" property specified in DT, then assume only one
> + * controller is available.
> + */
> + if (imx6_pcie->controller_id == -EINVAL)
> + imx6_pcie->controller_id = 0;
> + else if (imx6_pcie->controller_id < 0)
> + return dev_err_probe(dev, imx6_pcie->controller_id,
> + "linux,pci-domain have wrong value\n");

Maybe I'm missing something here. It looks like this driver uses
controller_id to distinguish between hardware variants or maybe
between two Root Ports (slots?) in the same SoC?

imx6_pcie_grp_offset
return imx6_pcie->controller_id == 1 ? IOMUXC_GPR16 : IOMUXC_GPR14;

imx6_pcie_configure_type
id = imx6_pcie->controller_id
if (!drvdata->mode_mask[id]) # <-- looks unsafe
id = 0;
regmap_update_bits(drvdata->mode_off[id], ...)

(This "mode_mask[id]" looks like it will reference garbage if the DT
supplies "linux,pci-domain = <2>". A bogus DT shouldn't be able to
cause a driver to misbehave like that.)

That doesn't seem related to "linux,pci-domain" at all.

Bjorn