+static u32 cdns_pcie_read_cfg(void *priv, int where, int size)
+{
+ struct cdns_pcie *pcie = priv;
+ u32 val;
+
+ if (size == 4)
+ val = readl(pcie->reg_base + where);
Should this use cdns_pcie_readl() ?
pci_host_bridge_find_*capability required to read two or four bytes.
reg = read_cfg(priv, cap_ptr, 2);
or
header = read_cfg(priv, pos, 4);
Here I mainly want to write it the same way as size == 2 and size == 1.
Or size == 4 should I write it as cdns_pcie_readl() ?
As is, it seems two functions are added for the same thing for the case
with size == 4 with different names which feels duplication. One could add
cdns_pcie_readw() and cdns_pcie_readb() too but perhaps cdns_pcie_readl()
should just call this new function instead?
+ else if (size == 2)
+ val = readw(pcie->reg_base + where);
+ else if (size == 1)
+ val = readb(pcie->reg_base + where);
+
+ return val;
+}
+
+u8 cdns_pcie_find_capability(struct cdns_pcie *pcie, u8 cap)
+{
+ return pci_host_bridge_find_capability(pcie, cdns_pcie_read_cfg, cap);
+}
+
+u16 cdns_pcie_find_ext_capability(struct cdns_pcie *pcie, u8 cap)
+{
+ return pci_host_bridge_find_ext_capability(pcie, cdns_pcie_read_cfg,
cap);
+}
I'm really wondering why the read config function is provided directly as
an argument. Shouldn't struct pci_host_bridge have some ops that can read
config so wouldn't it make much more sense to pass it and use the func
from there? There seems to ops in pci_host_bridge that has read(), does
that work? If not, why?
No effect.
I'm not sure what you meant?
Because we need to get the offset of the capability before PCIe
enumerates the device.
Is this to say it is needed before the struct pci_host_bridge is created?
I originally added a separate find capability related
function for CDNS in the following patch. It's also copied directly from DWC.
Mani felt there was too much duplicate code and also suggested passing a
callback function that could manipulate the registers of the root port of DWC
or CDNS.
I very much like the direction this patchset is moving (moving shared
part of controllers code to core), I just feel this doesn't go far enough
when it's passing function pointer to the read function.
I admit I've never written a controller driver so perhaps there's
something detail I lack knowledge of but I'd want to understand why
struct pci_ops (which exists both in pci_host_bridge and pci_bus) cannot
be used?