mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
ACPI: LoongArch: Add acpi_arch_[late]_init()
LoongArch IOMMU scanning flow is similar with virtio-iommu, there is an early init phase and a late init phase. In the early init function, PCI ACS is enabled if there is IOMMU table, and the late init function is called after PCI device scanning, where IOVT table scanning function is executed. Here add acpi_arch_init() and acpi_arch_late_init() API for LoongArch: the acpi_iovt_init() function is to enable PCI ACS function if the IOMMU device exists in IOVT table; while the acpi_iovt_late_init() function is to scan IOVT table and add IOMMU devices. Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
This commit is contained in:
parent
15107b81b8
commit
a9b0c34507
|
|
@ -6,6 +6,7 @@ config LOONGARCH
|
|||
select ACPI_GENERIC_GSI if ACPI
|
||||
select ACPI_MCFG if ACPI
|
||||
select ACPI_HOTPLUG_CPU if ACPI_PROCESSOR && HOTPLUG_CPU
|
||||
select ACPI_IOVT if ACPI
|
||||
select ACPI_PPTT if ACPI
|
||||
select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI
|
||||
select ARCH_BINFMT_ELF_STATE
|
||||
|
|
|
|||
|
|
@ -550,6 +550,10 @@ if ARM64
|
|||
source "drivers/acpi/arm64/Kconfig"
|
||||
endif
|
||||
|
||||
if LOONGARCH
|
||||
source "drivers/acpi/loongarch/Kconfig"
|
||||
endif
|
||||
|
||||
if RISCV
|
||||
source "drivers/acpi/riscv/Kconfig"
|
||||
endif
|
||||
|
|
|
|||
|
|
@ -131,6 +131,6 @@ obj-y += dptf/
|
|||
obj-$(CONFIG_ARM64) += arm64/
|
||||
|
||||
obj-$(CONFIG_ACPI_VIOT) += viot.o
|
||||
|
||||
obj-$(CONFIG_LOONGARCH) += loongarch/
|
||||
obj-$(CONFIG_RISCV) += riscv/
|
||||
obj-$(CONFIG_X86) += x86/
|
||||
|
|
|
|||
|
|
@ -1449,6 +1449,7 @@ struct kobject *acpi_kobj;
|
|||
EXPORT_SYMBOL_GPL(acpi_kobj);
|
||||
|
||||
void __weak __init acpi_arch_init(void) { }
|
||||
void __weak __init acpi_arch_late_init(void) { }
|
||||
|
||||
static int __init acpi_init(void)
|
||||
{
|
||||
|
|
@ -1487,6 +1488,7 @@ static int __init acpi_init(void)
|
|||
acpi_wakeup_device_init();
|
||||
acpi_debugger_init();
|
||||
acpi_setup_sb_notify_handler();
|
||||
acpi_arch_late_init();
|
||||
acpi_viot_init();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
7
drivers/acpi/loongarch/Kconfig
Normal file
7
drivers/acpi/loongarch/Kconfig
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
#
|
||||
# ACPI Configuration for LOONGARCH
|
||||
#
|
||||
|
||||
config ACPI_IOVT
|
||||
bool
|
||||
3
drivers/acpi/loongarch/Makefile
Normal file
3
drivers/acpi/loongarch/Makefile
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
obj-y += init.o
|
||||
obj-$(CONFIG_ACPI_IOVT) += iovt.o
|
||||
16
drivers/acpi/loongarch/init.c
Normal file
16
drivers/acpi/loongarch/init.c
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
#include <linux/acpi.h>
|
||||
#include "init.h"
|
||||
|
||||
void __init acpi_arch_init(void)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_ACPI_IOVT))
|
||||
acpi_iovt_init();
|
||||
}
|
||||
|
||||
void __init acpi_arch_late_init(void)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_ACPI_IOVT))
|
||||
acpi_iovt_late_init();
|
||||
}
|
||||
5
drivers/acpi/loongarch/init.h
Normal file
5
drivers/acpi/loongarch/init.h
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <linux/init.h>
|
||||
|
||||
void __init acpi_iovt_init(void);
|
||||
void __init acpi_iovt_late_init(void);
|
||||
211
drivers/acpi/loongarch/iovt.c
Normal file
211
drivers/acpi/loongarch/iovt.c
Normal file
|
|
@ -0,0 +1,211 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
#include <linux/acpi.h>
|
||||
#include <linux/pci.h>
|
||||
#include "init.h"
|
||||
|
||||
struct iovt_device_entry {
|
||||
struct list_head list;
|
||||
int start_devid, end_devid;
|
||||
};
|
||||
|
||||
struct iovt_fwnode {
|
||||
struct list_head list;
|
||||
struct fwnode_handle *fwnode;
|
||||
int flag;
|
||||
int nid, segment, devid;
|
||||
struct list_head ep_list;
|
||||
};
|
||||
|
||||
static LIST_HEAD(iovt_fwnode_list);
|
||||
static DEFINE_SPINLOCK(iovt_fwnode_lock);
|
||||
|
||||
#ifdef CONFIG_PCI
|
||||
static void __init iovt_enable_acs(struct acpi_iovt_iommu *iommu)
|
||||
{
|
||||
static bool acs_enabled __initdata;
|
||||
|
||||
if (acs_enabled)
|
||||
return;
|
||||
|
||||
/* IOMMU V1 only supports PCI device management */
|
||||
if ((iommu->header.type == ACPI_IOVT_IOMMU_V1) ||
|
||||
(iommu->flags & (ACPI_IOVT_IOMMU_PCI_DEVICE | ACPI_IOVT_IOMMU_MAGAGE_BY_SEGMENT))) {
|
||||
pci_request_acs();
|
||||
acs_enabled = true;
|
||||
}
|
||||
}
|
||||
#else
|
||||
static inline void iovt_enable_acs(struct acpi_iovt_iommu *iommu) { }
|
||||
#endif
|
||||
|
||||
static int __init iovt_get_pci_iommu_fwnode(struct iovt_fwnode *np, u16 segment, u16 bdf)
|
||||
{
|
||||
struct pci_dev *pdev;
|
||||
struct fwnode_handle *fwnode;
|
||||
|
||||
pdev = pci_get_domain_bus_and_slot(segment, PCI_BUS_NUM(bdf), bdf & 0xff);
|
||||
if (!pdev) {
|
||||
pr_err("No PCI IOMMU found for segment 0x%x bdf 0x%x\n", segment, bdf);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
fwnode = dev_fwnode(&pdev->dev);
|
||||
if (!fwnode) {
|
||||
/*
|
||||
* PCI devices aren't necessarily described by ACPI. Create
|
||||
* a fwnode so the IOMMU subsystem can identify this device.
|
||||
*/
|
||||
fwnode = acpi_alloc_fwnode_static();
|
||||
if (!fwnode) {
|
||||
pci_dev_put(pdev);
|
||||
return -ENOMEM;
|
||||
}
|
||||
set_primary_fwnode(&pdev->dev, fwnode);
|
||||
}
|
||||
|
||||
np->fwnode = dev_fwnode(&pdev->dev);
|
||||
if (np->flag & ACPI_IOVT_IOMMU_PXM_VALID)
|
||||
set_dev_node(&pdev->dev, np->nid);
|
||||
pci_dev_put(pdev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __init iovt_add_iommu(struct acpi_iovt_iommu *iommu)
|
||||
{
|
||||
int i, ret;
|
||||
bool is_start = false;
|
||||
struct iovt_fwnode *np;
|
||||
struct iovt_device_entry *entry;
|
||||
struct acpi_iovt_device_entry *ep;
|
||||
|
||||
np = kzalloc_obj(struct iovt_fwnode, GFP_ATOMIC);
|
||||
if (WARN_ON(!np))
|
||||
return -ENOMEM;
|
||||
|
||||
INIT_LIST_HEAD(&np->list);
|
||||
np->flag = iommu->flags;
|
||||
np->segment = iommu->segment;
|
||||
if (np->flag & ACPI_IOVT_IOMMU_PXM_VALID)
|
||||
np->nid = pxm_to_node(iommu->proximity_domain);
|
||||
|
||||
if (np->flag & ACPI_IOVT_IOMMU_PCI_DEVICE) {
|
||||
np->devid = iommu->device_id;
|
||||
ret = iovt_get_pci_iommu_fwnode(np, np->segment, np->devid);
|
||||
if (ret < 0) {
|
||||
kfree(np);
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
np->fwnode = acpi_alloc_fwnode_static();
|
||||
if (!np->fwnode) {
|
||||
kfree(np);
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
/* All devices in the segment are managed by this IOMMU */
|
||||
if (np->flag & ACPI_IOVT_IOMMU_MAGAGE_BY_SEGMENT)
|
||||
goto skip;
|
||||
|
||||
INIT_LIST_HEAD(&np->ep_list);
|
||||
ep = ACPI_ADD_PTR(struct acpi_iovt_device_entry, iommu, iommu->device_entry_offset);
|
||||
for (i = 0; i < iommu->device_entry_num; i++) {
|
||||
switch (ep->type) {
|
||||
case ACPI_IOVT_DEVICE_ENTRY_START:
|
||||
is_start = true;
|
||||
entry->start_devid = ep->device_id;
|
||||
break;
|
||||
case ACPI_IOVT_DEVICE_ENTRY_END:
|
||||
if (!is_start)
|
||||
break;
|
||||
|
||||
entry = kzalloc_obj(struct iovt_device_entry, GFP_ATOMIC);
|
||||
if (!entry)
|
||||
return -ENOMEM;
|
||||
|
||||
is_start = false;
|
||||
entry->end_devid = ep->device_id;
|
||||
list_add_tail(&entry->list, &np->ep_list);
|
||||
break;
|
||||
case ACPI_IOVT_DEVICE_ENTRY_SINGLE:
|
||||
entry = kzalloc_obj(struct iovt_device_entry, GFP_ATOMIC);
|
||||
if (!entry)
|
||||
return -ENOMEM;
|
||||
|
||||
is_start = false;
|
||||
entry->start_devid = ep->device_id;
|
||||
entry->end_devid = ep->device_id;
|
||||
list_add_tail(&entry->list, &np->ep_list);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ep = ACPI_ADD_PTR(struct acpi_iovt_device_entry, ep, ep->length);
|
||||
}
|
||||
|
||||
skip:
|
||||
spin_lock(&iovt_fwnode_lock);
|
||||
list_add_tail(&np->list, &iovt_fwnode_list);
|
||||
spin_unlock(&iovt_fwnode_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __init iovt_init_devices(struct acpi_table_header *header)
|
||||
{
|
||||
int i;
|
||||
struct acpi_table_iovt *iovt;
|
||||
struct acpi_iovt_iommu *iommu;
|
||||
|
||||
/* Get the first IOVT node */
|
||||
iovt = (struct acpi_table_iovt *)header;
|
||||
iommu = ACPI_ADD_PTR(struct acpi_iovt_iommu, iovt, iovt->iommu_offset);
|
||||
for (i = 0; i < iovt->iommu_count; i++) {
|
||||
iovt_add_iommu(iommu);
|
||||
iommu = ACPI_ADD_PTR(struct acpi_iovt_iommu, iommu, iommu->header.length);
|
||||
}
|
||||
}
|
||||
|
||||
void __init acpi_iovt_init(void)
|
||||
{
|
||||
int i;
|
||||
acpi_status status;
|
||||
struct acpi_table_header *hdr;
|
||||
struct acpi_table_iovt *iovt;
|
||||
struct acpi_iovt_iommu *iommu;
|
||||
|
||||
status = acpi_get_table(ACPI_SIG_IOVT, 0, &hdr);
|
||||
if (ACPI_FAILURE(status)) {
|
||||
if (status != AE_NOT_FOUND)
|
||||
pr_err("Failed to get table, %s\n", acpi_format_exception(status));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
iovt = (struct acpi_table_iovt *)&hdr;
|
||||
iommu = ACPI_ADD_PTR(struct acpi_iovt_iommu, iovt, iovt->iommu_offset);
|
||||
for (i = 0; i < iovt->iommu_count; i++) {
|
||||
iovt_enable_acs(iommu);
|
||||
iommu = ACPI_ADD_PTR(struct acpi_iovt_iommu, iommu, iommu->header.length);
|
||||
}
|
||||
|
||||
acpi_put_table(hdr);
|
||||
}
|
||||
|
||||
void __init acpi_iovt_late_init(void)
|
||||
{
|
||||
acpi_status status;
|
||||
struct acpi_table_header *hdr;
|
||||
|
||||
status = acpi_get_table(ACPI_SIG_IOVT, 0, &hdr);
|
||||
if (ACPI_FAILURE(status)) {
|
||||
if (status != AE_NOT_FOUND)
|
||||
pr_err("Failed to get table, %s\n", acpi_format_exception(status));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
iovt_init_devices(hdr);
|
||||
acpi_put_table(hdr);
|
||||
}
|
||||
|
|
@ -1637,6 +1637,7 @@ static inline int acpi_pptt_get_cpumask_from_cache_id(u32 cache_id,
|
|||
#endif
|
||||
|
||||
void acpi_arch_init(void);
|
||||
void acpi_arch_late_init(void);
|
||||
|
||||
#ifdef CONFIG_ACPI_PCC
|
||||
void acpi_init_pcc(void);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user