1 From dfbadb86b3bc43c004671ab6eb46ee160a192e98 Mon Sep 17 00:00:00 2001
2 From: Weijie Gao <weijie.gao@mediatek.com>
3 Date: Fri, 17 Jan 2025 17:18:11 +0800
4 Subject: [PATCH 09/15] pci: mediatek: add support for multiple ports in
5 mediatek pcie gen3 driver
7 One MediaTek PCIe Gen3 controller has only one port, where PCI bus 0
8 on this port represents the controller itself and bus 1 represents
9 the external PCIe device.
11 If multiple PCIe controllers are probed in U-Boot, U-Boot will use
12 bus numbers greater than 2 as input parameters. Therefore, we should
13 convert the BDF bus number to either 0 or 1 by subtracting the
14 offset by controller->seq_.
16 Signed-off-by: Sam Shih <sam.shih@mediatek.com>
17 Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
19 drivers/pci/pcie_mediatek_gen3.c | 24 ++++++++++++++++++++++++
20 1 file changed, 24 insertions(+)
22 --- a/drivers/pci/pcie_mediatek_gen3.c
23 +++ b/drivers/pci/pcie_mediatek_gen3.c
24 @@ -83,6 +83,28 @@ struct mtk_pcie {
28 +static pci_dev_t convert_bdf(const struct udevice *controller, pci_dev_t bdf)
32 + bdfs[0] = PCI_BUS(bdf);
33 + bdfs[1] = PCI_DEV(bdf);
34 + bdfs[2] = PCI_FUNC(bdf);
37 + * One MediaTek PCIe Gen3 controller has only one port, where PCI bus 0 on
38 + * this port represents the controller itself and bus 1 represents the
39 + * external PCIe device. If multiple PCIe controllers are probed in U-Boot,
40 + * U-Boot will use bus numbers greater than 2 as input parameters. Therefore,
41 + * we should convert the BDF bus number to either 0 or 1 by subtracting the
42 + * offset by controller->seq_
45 + bdfs[0] = bdfs[0] - controller->seq_;
47 + return PCI_BDF(bdfs[0], bdfs[1], bdfs[2]);
50 static void mtk_pcie_config_tlp_header(const struct udevice *bus,
53 @@ -91,6 +113,8 @@ static void mtk_pcie_config_tlp_header(c
57 + devfn = convert_bdf(bus, devfn);
60 bytes = (GENMASK(size - 1, 0) & 0xf) << (where & 0x3);