Re: [v7 2/5] PCI: Refactor capability search functions to eliminate code duplication

Hans Zhang
2025-04-03T16:29:45Z

On 2025/4/3 20:24, Hans Zhang wrote:
>
>
> On 2025/4/3 17:15, Ilpo Järvinen wrote:
>>>> I don't like how 1 & 2 patches are split into two. IMO, they mostly
>>>> belong
>>>> together. However, (IMO) you can introduce the new all-size config
>>>> space
>>>> accessor in a separate patch before the combined patch.
>>>>
>>>
>>> Ok. I'll change it to the following. The rest I'll combine into a patch.
>>>
>>> diff --git a/drivers/pci/access.c b/drivers/pci/access.c
>>> index b123da16b63b..bb2e26c2eb81 100644
>>> --- a/drivers/pci/access.c
>>> +++ b/drivers/pci/access.c
>>> @@ -85,6 +85,23 @@ EXPORT_SYMBOL(pci_bus_write_config_byte);
>>>   EXPORT_SYMBOL(pci_bus_write_config_word);
>>>   EXPORT_SYMBOL(pci_bus_write_config_dword);
>>>
>>> +
>>
>> Extra newline
>>
>
> Hi Ilpo,
>
> Thanks your for reply. Will delete.
>

Hi Ilpo,

The [v9 1/6]patch I plan to submit is as follows, please review it.

From c099691ff1e980ff4633c55e94abcd888000e2cc Mon Sep 17 00:00:00 2001
From: Hans Zhang <18255117159@163.com>
Date: Fri, 4 Apr 2025 00:19:32 +0800
Subject: [v9 1/6] PCI: Introduce generic bus config read helper function

The primary PCI config space accessors are tied to the size of the read
(byte/word/dword). Upcoming refactoring of PCI capability discovery logic
requires passing a config accessor function that must be able to perform
read with different sizes.

Add any size config space read accessor pci_bus_read_config() to allow
giving it as the config space accessor to the upcoming PCI capability
discovery macro.

Reconstructs the PCI function discovery logic to prepare for unified
configuration of access modes. No function changes are intended.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
drivers/pci/access.c | 17 +++++++++++++++++
drivers/pci/pci.h | 2 ++
2 files changed, 19 insertions(+)

diff --git a/drivers/pci/access.c b/drivers/pci/access.c
index b123da16b63b..603332658ab3 100644
--- a/drivers/pci/access.c
+++ b/drivers/pci/access.c
@@ -85,6 +85,23 @@ EXPORT_SYMBOL(pci_bus_write_config_byte);
EXPORT_SYMBOL(pci_bus_write_config_word);
EXPORT_SYMBOL(pci_bus_write_config_dword);

+int pci_bus_read_config(void *priv, unsigned int devfn, int where, u32
size,
+ u32 *val)
+{
+ struct pci_bus *bus = priv;
+ int ret;
+
+ if (size == 1)
+ ret = pci_bus_read_config_byte(bus, devfn, where, (u8 *)val);
+ else if (size == 2)
+ ret = pci_bus_read_config_word(bus, devfn, where, (u16 *)val);
+ else
+ ret = pci_bus_read_config_dword(bus, devfn, where, val);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(pci_bus_read_config);
+
int pci_generic_config_read(struct pci_bus *bus, unsigned int devfn,
int where, int size, u32 *val)
{
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 2e9cf26a9ee9..6a7c88b9cd35 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -88,6 +88,8 @@ extern bool pci_early_dump;
bool pcie_cap_has_lnkctl(const struct pci_dev *dev);
bool pcie_cap_has_lnkctl2(const struct pci_dev *dev);
bool pcie_cap_has_rtctl(const struct pci_dev *dev);
+int pci_bus_read_config(void *priv, unsigned int devfn, int where, u32
size,
+ u32 *val);

/* Functions internal to the PCI core code */

Best regards,
Hans