Skip to content

Commit 789befd

Browse files
vlsunilrafaeljw
authored andcommitted
arm64: PCI: Migrate ACPI related functions to pci-acpi.c
The functions defined in arm64 for ACPI support are required for RISC-V also. To avoid duplication, move these functions to common location. Signed-off-by: Sunil V L <[email protected]> Acked-by: Bjorn Helgaas <[email protected]> Acked-by: Will Deacon <[email protected]> Tested-by: Björn Töpel <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent e9252c3 commit 789befd

File tree

2 files changed

+182
-191
lines changed

2 files changed

+182
-191
lines changed

arch/arm64/kernel/pci.c

Lines changed: 0 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,7 @@
66
* Copyright (C) 2014 ARM Ltd.
77
*/
88

9-
#include <linux/acpi.h>
10-
#include <linux/init.h>
11-
#include <linux/io.h>
12-
#include <linux/kernel.h>
13-
#include <linux/mm.h>
149
#include <linux/pci.h>
15-
#include <linux/pci-acpi.h>
16-
#include <linux/pci-ecam.h>
17-
#include <linux/slab.h>
18-
19-
#ifdef CONFIG_ACPI
20-
/*
21-
* Try to assign the IRQ number when probing a new device
22-
*/
23-
int pcibios_alloc_irq(struct pci_dev *dev)
24-
{
25-
if (!acpi_disabled)
26-
acpi_pci_irq_enable(dev);
27-
28-
return 0;
29-
}
30-
#endif
3110

3211
/*
3312
* raw_pci_read/write - Platform-specific PCI config space access.
@@ -61,173 +40,3 @@ int pcibus_to_node(struct pci_bus *bus)
6140
EXPORT_SYMBOL(pcibus_to_node);
6241

6342
#endif
64-
65-
#ifdef CONFIG_ACPI
66-
67-
struct acpi_pci_generic_root_info {
68-
struct acpi_pci_root_info common;
69-
struct pci_config_window *cfg; /* config space mapping */
70-
};
71-
72-
int acpi_pci_bus_find_domain_nr(struct pci_bus *bus)
73-
{
74-
struct pci_config_window *cfg = bus->sysdata;
75-
struct acpi_device *adev = to_acpi_device(cfg->parent);
76-
struct acpi_pci_root *root = acpi_driver_data(adev);
77-
78-
return root->segment;
79-
}
80-
81-
int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
82-
{
83-
struct pci_config_window *cfg;
84-
struct acpi_device *adev;
85-
struct device *bus_dev;
86-
87-
if (acpi_disabled)
88-
return 0;
89-
90-
cfg = bridge->bus->sysdata;
91-
92-
/*
93-
* On Hyper-V there is no corresponding ACPI device for a root bridge,
94-
* therefore ->parent is set as NULL by the driver. And set 'adev' as
95-
* NULL in this case because there is no proper ACPI device.
96-
*/
97-
if (!cfg->parent)
98-
adev = NULL;
99-
else
100-
adev = to_acpi_device(cfg->parent);
101-
102-
bus_dev = &bridge->bus->dev;
103-
104-
ACPI_COMPANION_SET(&bridge->dev, adev);
105-
set_dev_node(bus_dev, acpi_get_node(acpi_device_handle(adev)));
106-
107-
return 0;
108-
}
109-
110-
static int pci_acpi_root_prepare_resources(struct acpi_pci_root_info *ci)
111-
{
112-
struct resource_entry *entry, *tmp;
113-
int status;
114-
115-
status = acpi_pci_probe_root_resources(ci);
116-
resource_list_for_each_entry_safe(entry, tmp, &ci->resources) {
117-
if (!(entry->res->flags & IORESOURCE_WINDOW))
118-
resource_list_destroy_entry(entry);
119-
}
120-
return status;
121-
}
122-
123-
/*
124-
* Lookup the bus range for the domain in MCFG, and set up config space
125-
* mapping.
126-
*/
127-
static struct pci_config_window *
128-
pci_acpi_setup_ecam_mapping(struct acpi_pci_root *root)
129-
{
130-
struct device *dev = &root->device->dev;
131-
struct resource *bus_res = &root->secondary;
132-
u16 seg = root->segment;
133-
const struct pci_ecam_ops *ecam_ops;
134-
struct resource cfgres;
135-
struct acpi_device *adev;
136-
struct pci_config_window *cfg;
137-
int ret;
138-
139-
ret = pci_mcfg_lookup(root, &cfgres, &ecam_ops);
140-
if (ret) {
141-
dev_err(dev, "%04x:%pR ECAM region not found\n", seg, bus_res);
142-
return NULL;
143-
}
144-
145-
adev = acpi_resource_consumer(&cfgres);
146-
if (adev)
147-
dev_info(dev, "ECAM area %pR reserved by %s\n", &cfgres,
148-
dev_name(&adev->dev));
149-
else
150-
dev_warn(dev, FW_BUG "ECAM area %pR not reserved in ACPI namespace\n",
151-
&cfgres);
152-
153-
cfg = pci_ecam_create(dev, &cfgres, bus_res, ecam_ops);
154-
if (IS_ERR(cfg)) {
155-
dev_err(dev, "%04x:%pR error %ld mapping ECAM\n", seg, bus_res,
156-
PTR_ERR(cfg));
157-
return NULL;
158-
}
159-
160-
return cfg;
161-
}
162-
163-
/* release_info: free resources allocated by init_info */
164-
static void pci_acpi_generic_release_info(struct acpi_pci_root_info *ci)
165-
{
166-
struct acpi_pci_generic_root_info *ri;
167-
168-
ri = container_of(ci, struct acpi_pci_generic_root_info, common);
169-
pci_ecam_free(ri->cfg);
170-
kfree(ci->ops);
171-
kfree(ri);
172-
}
173-
174-
/* Interface called from ACPI code to setup PCI host controller */
175-
struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
176-
{
177-
struct acpi_pci_generic_root_info *ri;
178-
struct pci_bus *bus, *child;
179-
struct acpi_pci_root_ops *root_ops;
180-
struct pci_host_bridge *host;
181-
182-
ri = kzalloc(sizeof(*ri), GFP_KERNEL);
183-
if (!ri)
184-
return NULL;
185-
186-
root_ops = kzalloc(sizeof(*root_ops), GFP_KERNEL);
187-
if (!root_ops) {
188-
kfree(ri);
189-
return NULL;
190-
}
191-
192-
ri->cfg = pci_acpi_setup_ecam_mapping(root);
193-
if (!ri->cfg) {
194-
kfree(ri);
195-
kfree(root_ops);
196-
return NULL;
197-
}
198-
199-
root_ops->release_info = pci_acpi_generic_release_info;
200-
root_ops->prepare_resources = pci_acpi_root_prepare_resources;
201-
root_ops->pci_ops = (struct pci_ops *)&ri->cfg->ops->pci_ops;
202-
bus = acpi_pci_root_create(root, root_ops, &ri->common, ri->cfg);
203-
if (!bus)
204-
return NULL;
205-
206-
/* If we must preserve the resource configuration, claim now */
207-
host = pci_find_host_bridge(bus);
208-
if (host->preserve_config)
209-
pci_bus_claim_resources(bus);
210-
211-
/*
212-
* Assign whatever was left unassigned. If we didn't claim above,
213-
* this will reassign everything.
214-
*/
215-
pci_assign_unassigned_root_bus_resources(bus);
216-
217-
list_for_each_entry(child, &bus->children, node)
218-
pcie_bus_configure_settings(child);
219-
220-
return bus;
221-
}
222-
223-
void pcibios_add_bus(struct pci_bus *bus)
224-
{
225-
acpi_pci_add_bus(bus);
226-
}
227-
228-
void pcibios_remove_bus(struct pci_bus *bus)
229-
{
230-
acpi_pci_remove_bus(bus);
231-
}
232-
233-
#endif

drivers/pci/pci-acpi.c

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/pci_hotplug.h>
1616
#include <linux/module.h>
1717
#include <linux/pci-acpi.h>
18+
#include <linux/pci-ecam.h>
1819
#include <linux/pm_runtime.h>
1920
#include <linux/pm_qos.h>
2021
#include <linux/rwsem.h>
@@ -1541,3 +1542,184 @@ static int __init acpi_pci_init(void)
15411542
return 0;
15421543
}
15431544
arch_initcall(acpi_pci_init);
1545+
1546+
#if defined(CONFIG_ARM64)
1547+
1548+
/*
1549+
* Try to assign the IRQ number when probing a new device
1550+
*/
1551+
int pcibios_alloc_irq(struct pci_dev *dev)
1552+
{
1553+
if (!acpi_disabled)
1554+
acpi_pci_irq_enable(dev);
1555+
1556+
return 0;
1557+
}
1558+
1559+
struct acpi_pci_generic_root_info {
1560+
struct acpi_pci_root_info common;
1561+
struct pci_config_window *cfg; /* config space mapping */
1562+
};
1563+
1564+
int acpi_pci_bus_find_domain_nr(struct pci_bus *bus)
1565+
{
1566+
struct pci_config_window *cfg = bus->sysdata;
1567+
struct acpi_device *adev = to_acpi_device(cfg->parent);
1568+
struct acpi_pci_root *root = acpi_driver_data(adev);
1569+
1570+
return root->segment;
1571+
}
1572+
1573+
int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
1574+
{
1575+
struct pci_config_window *cfg;
1576+
struct acpi_device *adev;
1577+
struct device *bus_dev;
1578+
1579+
if (acpi_disabled)
1580+
return 0;
1581+
1582+
cfg = bridge->bus->sysdata;
1583+
1584+
/*
1585+
* On Hyper-V there is no corresponding ACPI device for a root bridge,
1586+
* therefore ->parent is set as NULL by the driver. And set 'adev' as
1587+
* NULL in this case because there is no proper ACPI device.
1588+
*/
1589+
if (!cfg->parent)
1590+
adev = NULL;
1591+
else
1592+
adev = to_acpi_device(cfg->parent);
1593+
1594+
bus_dev = &bridge->bus->dev;
1595+
1596+
ACPI_COMPANION_SET(&bridge->dev, adev);
1597+
set_dev_node(bus_dev, acpi_get_node(acpi_device_handle(adev)));
1598+
1599+
return 0;
1600+
}
1601+
1602+
static int pci_acpi_root_prepare_resources(struct acpi_pci_root_info *ci)
1603+
{
1604+
struct resource_entry *entry, *tmp;
1605+
int status;
1606+
1607+
status = acpi_pci_probe_root_resources(ci);
1608+
resource_list_for_each_entry_safe(entry, tmp, &ci->resources) {
1609+
if (!(entry->res->flags & IORESOURCE_WINDOW))
1610+
resource_list_destroy_entry(entry);
1611+
}
1612+
return status;
1613+
}
1614+
1615+
/*
1616+
* Lookup the bus range for the domain in MCFG, and set up config space
1617+
* mapping.
1618+
*/
1619+
static struct pci_config_window *
1620+
pci_acpi_setup_ecam_mapping(struct acpi_pci_root *root)
1621+
{
1622+
struct device *dev = &root->device->dev;
1623+
struct resource *bus_res = &root->secondary;
1624+
u16 seg = root->segment;
1625+
const struct pci_ecam_ops *ecam_ops;
1626+
struct resource cfgres;
1627+
struct acpi_device *adev;
1628+
struct pci_config_window *cfg;
1629+
int ret;
1630+
1631+
ret = pci_mcfg_lookup(root, &cfgres, &ecam_ops);
1632+
if (ret) {
1633+
dev_err(dev, "%04x:%pR ECAM region not found\n", seg, bus_res);
1634+
return NULL;
1635+
}
1636+
1637+
adev = acpi_resource_consumer(&cfgres);
1638+
if (adev)
1639+
dev_info(dev, "ECAM area %pR reserved by %s\n", &cfgres,
1640+
dev_name(&adev->dev));
1641+
else
1642+
dev_warn(dev, FW_BUG "ECAM area %pR not reserved in ACPI namespace\n",
1643+
&cfgres);
1644+
1645+
cfg = pci_ecam_create(dev, &cfgres, bus_res, ecam_ops);
1646+
if (IS_ERR(cfg)) {
1647+
dev_err(dev, "%04x:%pR error %ld mapping ECAM\n", seg, bus_res,
1648+
PTR_ERR(cfg));
1649+
return NULL;
1650+
}
1651+
1652+
return cfg;
1653+
}
1654+
1655+
/* release_info: free resources allocated by init_info */
1656+
static void pci_acpi_generic_release_info(struct acpi_pci_root_info *ci)
1657+
{
1658+
struct acpi_pci_generic_root_info *ri;
1659+
1660+
ri = container_of(ci, struct acpi_pci_generic_root_info, common);
1661+
pci_ecam_free(ri->cfg);
1662+
kfree(ci->ops);
1663+
kfree(ri);
1664+
}
1665+
1666+
/* Interface called from ACPI code to setup PCI host controller */
1667+
struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
1668+
{
1669+
struct acpi_pci_generic_root_info *ri;
1670+
struct pci_bus *bus, *child;
1671+
struct acpi_pci_root_ops *root_ops;
1672+
struct pci_host_bridge *host;
1673+
1674+
ri = kzalloc(sizeof(*ri), GFP_KERNEL);
1675+
if (!ri)
1676+
return NULL;
1677+
1678+
root_ops = kzalloc(sizeof(*root_ops), GFP_KERNEL);
1679+
if (!root_ops) {
1680+
kfree(ri);
1681+
return NULL;
1682+
}
1683+
1684+
ri->cfg = pci_acpi_setup_ecam_mapping(root);
1685+
if (!ri->cfg) {
1686+
kfree(ri);
1687+
kfree(root_ops);
1688+
return NULL;
1689+
}
1690+
1691+
root_ops->release_info = pci_acpi_generic_release_info;
1692+
root_ops->prepare_resources = pci_acpi_root_prepare_resources;
1693+
root_ops->pci_ops = (struct pci_ops *)&ri->cfg->ops->pci_ops;
1694+
bus = acpi_pci_root_create(root, root_ops, &ri->common, ri->cfg);
1695+
if (!bus)
1696+
return NULL;
1697+
1698+
/* If we must preserve the resource configuration, claim now */
1699+
host = pci_find_host_bridge(bus);
1700+
if (host->preserve_config)
1701+
pci_bus_claim_resources(bus);
1702+
1703+
/*
1704+
* Assign whatever was left unassigned. If we didn't claim above,
1705+
* this will reassign everything.
1706+
*/
1707+
pci_assign_unassigned_root_bus_resources(bus);
1708+
1709+
list_for_each_entry(child, &bus->children, node)
1710+
pcie_bus_configure_settings(child);
1711+
1712+
return bus;
1713+
}
1714+
1715+
void pcibios_add_bus(struct pci_bus *bus)
1716+
{
1717+
acpi_pci_add_bus(bus);
1718+
}
1719+
1720+
void pcibios_remove_bus(struct pci_bus *bus)
1721+
{
1722+
acpi_pci_remove_bus(bus);
1723+
}
1724+
1725+
#endif

0 commit comments

Comments
 (0)