Skip to content

Commit cd89edd

Browse files
chenhuacaibjorn-helgaas
authored andcommitted
PCI: loongson: Add ACPI init support
Loongson PCH (LS7A chipset) will be used by both MIPS-based and LoongArch- based Loongson processors. MIPS-based Loongson uses FDT, while LoongArch- based Loongson uses ACPI. Add ACPI init support for the driver in pci-loongson.c because it is currently FDT-only. LoongArch is a new RISC ISA, mainline support will come soon, and documentations are here (in translation): https://github.com/loongson/LoongArch-Documentation Link: https://lore.kernel.org/r/20220714124216.1489304-4-chenhuacai@loongson.cn Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent dee449a commit cd89edd

4 files changed

Lines changed: 87 additions & 20 deletions

File tree

drivers/acpi/pci_mcfg.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ static struct mcfg_fixup mcfg_quirks[] = {
172172
ALTRA_ECAM_QUIRK(1, 14),
173173
ALTRA_ECAM_QUIRK(1, 15),
174174
#endif /* ARM64 */
175+
176+
#ifdef CONFIG_LOONGARCH
177+
#define LOONGSON_ECAM_MCFG(table_id, seg) \
178+
{ "LOONGS", table_id, 1, seg, MCFG_BUS_ANY, &loongson_pci_ecam_ops }
179+
180+
LOONGSON_ECAM_MCFG("\0", 0),
181+
LOONGSON_ECAM_MCFG("LOONGSON", 0),
182+
LOONGSON_ECAM_MCFG("\0", 1),
183+
LOONGSON_ECAM_MCFG("LOONGSON", 1),
184+
#endif /* LOONGARCH */
175185
};
176186

177187
static char mcfg_oem_id[ACPI_OEM_ID_SIZE];

drivers/pci/controller/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ config PCI_HYPERV_INTERFACE
293293
config PCI_LOONGSON
294294
bool "LOONGSON PCI Controller"
295295
depends on MACH_LOONGSON64 || COMPILE_TEST
296-
depends on OF
296+
depends on OF || ACPI
297297
depends on PCI_QUIRKS
298298
default MACH_LOONGSON64
299299
help

drivers/pci/controller/pci-loongson.c

Lines changed: 75 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <linux/of_pci.h>
1010
#include <linux/pci.h>
1111
#include <linux/pci_ids.h>
12+
#include <linux/pci-acpi.h>
13+
#include <linux/pci-ecam.h>
1214

1315
#include "../pci.h"
1416

@@ -97,55 +99,71 @@ static void loongson_mrrs_quirk(struct pci_dev *dev)
9799
}
98100
DECLARE_PCI_FIXUP_ENABLE(PCI_ANY_ID, PCI_ANY_ID, loongson_mrrs_quirk);
99101

100-
static void __iomem *cfg1_map(struct loongson_pci *priv, int bus,
101-
unsigned int devfn, int where)
102+
static struct loongson_pci *pci_bus_to_loongson_pci(struct pci_bus *bus)
102103
{
103-
unsigned long addroff = 0x0;
104+
struct pci_config_window *cfg;
104105

105-
if (bus != 0)
106-
addroff |= BIT(28); /* Type 1 Access */
107-
addroff |= (where & 0xff) | ((where & 0xf00) << 16);
108-
addroff |= (bus << 16) | (devfn << 8);
109-
return priv->cfg1_base + addroff;
106+
if (acpi_disabled)
107+
return (struct loongson_pci *)(bus->sysdata);
108+
109+
cfg = bus->sysdata;
110+
return (struct loongson_pci *)(cfg->priv);
110111
}
111112

112-
static void __iomem *cfg0_map(struct loongson_pci *priv, int bus,
113-
unsigned int devfn, int where)
113+
static void __iomem *cfg0_map(struct loongson_pci *priv, struct pci_bus *bus,
114+
unsigned int devfn, int where)
114115
{
115116
unsigned long addroff = 0x0;
117+
unsigned char busnum = bus->number;
116118

117-
if (bus != 0)
119+
if (!pci_is_root_bus(bus)) {
118120
addroff |= BIT(24); /* Type 1 Access */
119-
addroff |= (bus << 16) | (devfn << 8) | where;
121+
addroff |= (busnum << 16);
122+
}
123+
addroff |= (devfn << 8) | where;
120124
return priv->cfg0_base + addroff;
121125
}
122126

123-
static void __iomem *pci_loongson_map_bus(struct pci_bus *bus, unsigned int devfn,
124-
int where)
127+
static void __iomem *cfg1_map(struct loongson_pci *priv, struct pci_bus *bus,
128+
unsigned int devfn, int where)
125129
{
130+
unsigned long addroff = 0x0;
126131
unsigned char busnum = bus->number;
127-
struct pci_host_bridge *bridge = pci_find_host_bridge(bus);
128-
struct loongson_pci *priv = pci_host_bridge_priv(bridge);
132+
133+
if (!pci_is_root_bus(bus)) {
134+
addroff |= BIT(28); /* Type 1 Access */
135+
addroff |= (busnum << 16);
136+
}
137+
addroff |= (devfn << 8) | (where & 0xff) | ((where & 0xf00) << 16);
138+
return priv->cfg1_base + addroff;
139+
}
140+
141+
static void __iomem *pci_loongson_map_bus(struct pci_bus *bus,
142+
unsigned int devfn, int where)
143+
{
144+
struct loongson_pci *priv = pci_bus_to_loongson_pci(bus);
129145

130146
/*
131147
* Do not read more than one device on the bus other than
132-
* the host bus. For our hardware the root bus is always bus 0.
148+
* the host bus.
133149
*/
134150
if (priv->data->flags & FLAG_DEV_FIX &&
135151
!pci_is_root_bus(bus) && PCI_SLOT(devfn) > 0)
136152
return NULL;
137153

138154
/* CFG0 can only access standard space */
139155
if (where < PCI_CFG_SPACE_SIZE && priv->cfg0_base)
140-
return cfg0_map(priv, busnum, devfn, where);
156+
return cfg0_map(priv, bus, devfn, where);
141157

142158
/* CFG1 can access extended space */
143159
if (where < PCI_CFG_SPACE_EXP_SIZE && priv->cfg1_base)
144-
return cfg1_map(priv, busnum, devfn, where);
160+
return cfg1_map(priv, bus, devfn, where);
145161

146162
return NULL;
147163
}
148164

165+
#ifdef CONFIG_OF
166+
149167
static int loongson_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
150168
{
151169
int irq;
@@ -259,3 +277,41 @@ static struct platform_driver loongson_pci_driver = {
259277
.probe = loongson_pci_probe,
260278
};
261279
builtin_platform_driver(loongson_pci_driver);
280+
281+
#endif
282+
283+
#ifdef CONFIG_ACPI
284+
285+
static int loongson_pci_ecam_init(struct pci_config_window *cfg)
286+
{
287+
struct device *dev = cfg->parent;
288+
struct loongson_pci *priv;
289+
struct loongson_pci_data *data;
290+
291+
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
292+
if (!priv)
293+
return -ENOMEM;
294+
295+
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
296+
if (!data)
297+
return -ENOMEM;
298+
299+
cfg->priv = priv;
300+
data->flags = FLAG_CFG1;
301+
priv->data = data;
302+
priv->cfg1_base = cfg->win - (cfg->busr.start << 16);
303+
304+
return 0;
305+
}
306+
307+
const struct pci_ecam_ops loongson_pci_ecam_ops = {
308+
.bus_shift = 16,
309+
.init = loongson_pci_ecam_init,
310+
.pci_ops = {
311+
.map_bus = pci_loongson_map_bus,
312+
.read = pci_generic_config_read,
313+
.write = pci_generic_config_write,
314+
}
315+
};
316+
317+
#endif

include/linux/pci-ecam.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ extern const struct pci_ecam_ops xgene_v1_pcie_ecam_ops; /* APM X-Gene PCIe v1 *
8787
extern const struct pci_ecam_ops xgene_v2_pcie_ecam_ops; /* APM X-Gene PCIe v2.x */
8888
extern const struct pci_ecam_ops al_pcie_ops; /* Amazon Annapurna Labs PCIe */
8989
extern const struct pci_ecam_ops tegra194_pcie_ops; /* Tegra194 PCIe */
90+
extern const struct pci_ecam_ops loongson_pci_ecam_ops; /* Loongson PCIe */
9091
#endif
9192

9293
#if IS_ENABLED(CONFIG_PCI_HOST_COMMON)

0 commit comments

Comments
 (0)