Skip to content

Commit 45de405

Browse files
committed
Merge branch 'acpi-riscv'
Merge ACPI and irqchip updates related to external interrupt controller support on RISC-V: - Add ACPI device enumeration support for interrupt controller probing including taking dependencies into account (Sunil V L). - Implement ACPI-based interrupt controller probing on RISC-V (Sunil V L). - Add ACPI support for AIA in riscv-intc and add ACPI support to riscv-imsic, riscv-aplic, and sifive-plic (Sunil V L). * acpi-riscv: irqchip/sifive-plic: Add ACPI support irqchip/riscv-aplic: Add ACPI support irqchip/riscv-imsic: Add ACPI support irqchip/riscv-imsic-state: Create separate function for DT irqchip/riscv-intc: Add ACPI support for AIA ACPI: RISC-V: Implement function to add implicit dependencies ACPI: RISC-V: Initialize GSI mapping structures ACPI: RISC-V: Implement function to reorder irqchip probe entries ACPI: RISC-V: Implement PCI related functionality ACPI: pci_link: Clear the dependencies after probe ACPI: bus: Add RINTC IRQ model for RISC-V ACPI: scan: Define weak function to populate dependencies ACPI: scan: Add RISC-V interrupt controllers to honor list ACPI: scan: Refactor dependency creation ACPI: bus: Add acpi_riscv_init() function ACPI: scan: Add a weak arch_sort_irqchip_probe() to order the IRQCHIP probe arm64: PCI: Migrate ACPI related functions to pci-acpi.c
2 parents 13f4eb6 + 206dd13 commit 45de405

25 files changed

+1111
-373
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

arch/riscv/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ config 32BIT
1313
config RISCV
1414
def_bool y
1515
select ACPI_GENERIC_GSI if ACPI
16+
select ACPI_MCFG if (ACPI && PCI)
1617
select ACPI_PPTT if ACPI
1718
select ACPI_REDUCED_HARDWARE_ONLY if ACPI
1819
select ACPI_SPCR_TABLE if ACPI
@@ -188,6 +189,7 @@ config RISCV
188189
select OF_EARLY_FLATTREE
189190
select OF_IRQ
190191
select PCI_DOMAINS_GENERIC if PCI
192+
select PCI_ECAM if (ACPI && PCI)
191193
select PCI_MSI if PCI
192194
select RISCV_ALTERNATIVE if !XIP_KERNEL
193195
select RISCV_APLIC

arch/riscv/include/asm/irq.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,63 @@
1212

1313
#include <asm-generic/irq.h>
1414

15+
#define INVALID_CONTEXT UINT_MAX
16+
1517
void riscv_set_intc_hwnode_fn(struct fwnode_handle *(*fn)(void));
1618

1719
struct fwnode_handle *riscv_get_intc_hwnode(void);
1820

21+
#ifdef CONFIG_ACPI
22+
23+
enum riscv_irqchip_type {
24+
ACPI_RISCV_IRQCHIP_INTC = 0x00,
25+
ACPI_RISCV_IRQCHIP_IMSIC = 0x01,
26+
ACPI_RISCV_IRQCHIP_PLIC = 0x02,
27+
ACPI_RISCV_IRQCHIP_APLIC = 0x03,
28+
};
29+
30+
int riscv_acpi_get_gsi_info(struct fwnode_handle *fwnode, u32 *gsi_base,
31+
u32 *id, u32 *nr_irqs, u32 *nr_idcs);
32+
struct fwnode_handle *riscv_acpi_get_gsi_domain_id(u32 gsi);
33+
unsigned long acpi_rintc_index_to_hartid(u32 index);
34+
unsigned long acpi_rintc_ext_parent_to_hartid(unsigned int plic_id, unsigned int ctxt_idx);
35+
unsigned int acpi_rintc_get_plic_nr_contexts(unsigned int plic_id);
36+
unsigned int acpi_rintc_get_plic_context(unsigned int plic_id, unsigned int ctxt_idx);
37+
int __init acpi_rintc_get_imsic_mmio_info(u32 index, struct resource *res);
38+
39+
#else
40+
static inline int riscv_acpi_get_gsi_info(struct fwnode_handle *fwnode, u32 *gsi_base,
41+
u32 *id, u32 *nr_irqs, u32 *nr_idcs)
42+
{
43+
return 0;
44+
}
45+
46+
static inline unsigned long acpi_rintc_index_to_hartid(u32 index)
47+
{
48+
return INVALID_HARTID;
49+
}
50+
51+
static inline unsigned long acpi_rintc_ext_parent_to_hartid(unsigned int plic_id,
52+
unsigned int ctxt_idx)
53+
{
54+
return INVALID_HARTID;
55+
}
56+
57+
static inline unsigned int acpi_rintc_get_plic_nr_contexts(unsigned int plic_id)
58+
{
59+
return INVALID_CONTEXT;
60+
}
61+
62+
static inline unsigned int acpi_rintc_get_plic_context(unsigned int plic_id, unsigned int ctxt_idx)
63+
{
64+
return INVALID_CONTEXT;
65+
}
66+
67+
static inline int __init acpi_rintc_get_imsic_mmio_info(u32 index, struct resource *res)
68+
{
69+
return 0;
70+
}
71+
72+
#endif /* CONFIG_ACPI */
73+
1974
#endif /* _ASM_RISCV_IRQ_H */

arch/riscv/kernel/acpi.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -311,29 +311,26 @@ void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size)
311311
#ifdef CONFIG_PCI
312312

313313
/*
314-
* These interfaces are defined just to enable building ACPI core.
315-
* TODO: Update it with actual implementation when external interrupt
316-
* controller support is added in RISC-V ACPI.
314+
* raw_pci_read/write - Platform-specific PCI config space access.
317315
*/
318-
int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
319-
int reg, int len, u32 *val)
316+
int raw_pci_read(unsigned int domain, unsigned int bus,
317+
unsigned int devfn, int reg, int len, u32 *val)
320318
{
321-
return PCIBIOS_DEVICE_NOT_FOUND;
322-
}
319+
struct pci_bus *b = pci_find_bus(domain, bus);
323320

324-
int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
325-
int reg, int len, u32 val)
326-
{
327-
return PCIBIOS_DEVICE_NOT_FOUND;
321+
if (!b)
322+
return PCIBIOS_DEVICE_NOT_FOUND;
323+
return b->ops->read(b, devfn, reg, len, val);
328324
}
329325

330-
int acpi_pci_bus_find_domain_nr(struct pci_bus *bus)
326+
int raw_pci_write(unsigned int domain, unsigned int bus,
327+
unsigned int devfn, int reg, int len, u32 val)
331328
{
332-
return -1;
333-
}
329+
struct pci_bus *b = pci_find_bus(domain, bus);
334330

335-
struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
336-
{
337-
return NULL;
331+
if (!b)
332+
return PCIBIOS_DEVICE_NOT_FOUND;
333+
return b->ops->write(b, devfn, reg, len, val);
338334
}
335+
339336
#endif /* CONFIG_PCI */

drivers/acpi/bus.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,9 @@ static int __init acpi_bus_init_irq(void)
12031203
case ACPI_IRQ_MODEL_LPIC:
12041204
message = "LPIC";
12051205
break;
1206+
case ACPI_IRQ_MODEL_RINTC:
1207+
message = "RINTC";
1208+
break;
12061209
default:
12071210
pr_info("Unknown interrupt routing model\n");
12081211
return -ENODEV;
@@ -1459,6 +1462,7 @@ static int __init acpi_init(void)
14591462
acpi_hest_init();
14601463
acpi_ghes_init();
14611464
acpi_arm_init();
1465+
acpi_riscv_init();
14621466
acpi_scan_init();
14631467
acpi_ec_init();
14641468
acpi_debugfs_init();

drivers/acpi/pci_link.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,8 @@ static int acpi_pci_link_add(struct acpi_device *device,
748748
if (result)
749749
kfree(link);
750750

751+
acpi_dev_clear_dependencies(device);
752+
751753
return result < 0 ? result : 1;
752754
}
753755

drivers/acpi/riscv/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# SPDX-License-Identifier: GPL-2.0-only
2-
obj-y += rhct.o
2+
obj-y += rhct.o init.o irq.o
33
obj-$(CONFIG_ACPI_PROCESSOR_IDLE) += cpuidle.o
44
obj-$(CONFIG_ACPI_CPPC_LIB) += cppc.o

drivers/acpi/riscv/init.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Copyright (C) 2023-2024, Ventana Micro Systems Inc
4+
* Author: Sunil V L <[email protected]>
5+
*/
6+
7+
#include <linux/acpi.h>
8+
#include "init.h"
9+
10+
void __init acpi_riscv_init(void)
11+
{
12+
riscv_acpi_init_gsi_mapping();
13+
}

drivers/acpi/riscv/init.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
#include <linux/init.h>
3+
4+
void __init riscv_acpi_init_gsi_mapping(void);

0 commit comments

Comments
 (0)