Commit c77f54a9 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

Merge branches 'acpi-scan', 'acpi-bus' and 'acpi-platform'

Merge changes related to ACPI device enumeration and ACPI support for
platform devices for 6.1-rc1:

 - Clean up ACPI platform devices support code (Andy Shevchenko, John
   Garry).

 - Clean up ACPI bus management code (Andy Shevchenko, ye xingchen).

 - Add support for multiple DMA windows with different offsets to the
   ACPI device enumeration code and use it on LoongArch (Jianmin Lv).

* acpi-scan:
  LoongArch: Use acpi_arch_dma_setup() and remove ARCH_HAS_PHYS_TO_DMA
  ACPI: scan: Support multiple DMA windows with different offsets

* acpi-bus:
  ACPI: bus: Refactor ACPI matching functions for better readability
  ACPI: bus: Drop kernel doc annotation from acpi_bus_notify()
  ACPI: bus: Remove the unneeded result variable

* acpi-platform:
  ACPI: platform: Use PLATFORM_DEVID_NONE in acpi_create_platform_device()
  ACPI: platform: Sort forbidden_id_list[] in ascending order
  ACPI: platform: Use sizeof(*pointer) instead of sizeof(type)
  ACPI: platform: Remove redundant print on -ENOMEM
  ACPI: platform: Get rid of redundant 'else'
...@@ -10,7 +10,6 @@ config LOONGARCH ...@@ -10,7 +10,6 @@ config LOONGARCH
select ARCH_ENABLE_MEMORY_HOTPLUG select ARCH_ENABLE_MEMORY_HOTPLUG
select ARCH_ENABLE_MEMORY_HOTREMOVE select ARCH_ENABLE_MEMORY_HOTREMOVE
select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
select ARCH_HAS_PHYS_TO_DMA
select ARCH_HAS_PTE_SPECIAL select ARCH_HAS_PTE_SPECIAL
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
select ARCH_INLINE_READ_LOCK if !PREEMPTION select ARCH_INLINE_READ_LOCK if !PREEMPTION
......
...@@ -2,39 +2,29 @@ ...@@ -2,39 +2,29 @@
/* /*
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
*/ */
#include <linux/init.h> #include <linux/acpi.h>
#include <linux/dma-direct.h> #include <linux/dma-direct.h>
#include <linux/dma-mapping.h>
#include <linux/dma-map-ops.h>
#include <linux/swiotlb.h>
#include <asm/bootinfo.h> void acpi_arch_dma_setup(struct device *dev)
#include <asm/dma.h>
#include <asm/loongson.h>
/*
* We extract 4bit node id (bit 44~47) from Loongson-3's
* 48bit physical address space and embed it into 40bit.
*/
static int node_id_offset;
dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
{
long nid = (paddr >> 44) & 0xf;
return ((nid << 44) ^ paddr) | (nid << node_id_offset);
}
phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
{ {
long nid = (daddr >> node_id_offset) & 0xf; int ret;
u64 mask, end = 0;
const struct bus_dma_region *map = NULL;
ret = acpi_dma_get_range(dev, &map);
if (!ret && map) {
const struct bus_dma_region *r = map;
for (end = 0; r->size; r++) {
if (r->dma_start + r->size - 1 > end)
end = r->dma_start + r->size - 1;
}
mask = DMA_BIT_MASK(ilog2(end) + 1);
dev->bus_dma_limit = end;
dev->dma_range_map = map;
dev->coherent_dma_mask = min(dev->coherent_dma_mask, mask);
*dev->dma_mask = min(*dev->dma_mask, mask);
}
return ((nid << node_id_offset) ^ daddr) | (nid << 44);
}
void __init plat_swiotlb_setup(void)
{
swiotlb_init(true, SWIOTLB_VERBOSE);
node_id_offset = ((readl(LS7A_DMA_CFG) & LS7A_DMA_NODE_MASK) >> LS7A_DMA_NODE_SHF) + 36;
} }
...@@ -247,7 +247,7 @@ static void __init arch_mem_init(char **cmdline_p) ...@@ -247,7 +247,7 @@ static void __init arch_mem_init(char **cmdline_p)
sparse_init(); sparse_init();
memblock_set_bottom_up(true); memblock_set_bottom_up(true);
plat_swiotlb_setup(); swiotlb_init(true, SWIOTLB_VERBOSE);
dma_contiguous_reserve(PFN_PHYS(max_low_pfn)); dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
......
...@@ -20,13 +20,13 @@ ...@@ -20,13 +20,13 @@
#include "internal.h" #include "internal.h"
static const struct acpi_device_id forbidden_id_list[] = { static const struct acpi_device_id forbidden_id_list[] = {
{"ACPI0009", 0}, /* IOxAPIC */
{"ACPI000A", 0}, /* IOAPIC */
{"PNP0000", 0}, /* PIC */ {"PNP0000", 0}, /* PIC */
{"PNP0100", 0}, /* Timer */ {"PNP0100", 0}, /* Timer */
{"PNP0200", 0}, /* AT DMA Controller */ {"PNP0200", 0}, /* AT DMA Controller */
{"ACPI0009", 0}, /* IOxAPIC */
{"ACPI000A", 0}, /* IOAPIC */
{"SMB0001", 0}, /* ACPI SMBUS virtual device */ {"SMB0001", 0}, /* ACPI SMBUS virtual device */
{"", 0}, { }
}; };
static struct platform_device *acpi_platform_device_find_by_companion(struct acpi_device *adev) static struct platform_device *acpi_platform_device_find_by_companion(struct acpi_device *adev)
...@@ -114,13 +114,11 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev, ...@@ -114,13 +114,11 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
INIT_LIST_HEAD(&resource_list); INIT_LIST_HEAD(&resource_list);
count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL); count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
if (count < 0) { if (count < 0)
return NULL; return NULL;
} else if (count > 0) { if (count > 0) {
resources = kcalloc(count, sizeof(struct resource), resources = kcalloc(count, sizeof(*resources), GFP_KERNEL);
GFP_KERNEL);
if (!resources) { if (!resources) {
dev_err(&adev->dev, "No memory for resources\n");
acpi_dev_free_resource_list(&resource_list); acpi_dev_free_resource_list(&resource_list);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
...@@ -140,7 +138,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev, ...@@ -140,7 +138,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
*/ */
pdevinfo.parent = parent ? acpi_get_first_physical_node(parent) : NULL; pdevinfo.parent = parent ? acpi_get_first_physical_node(parent) : NULL;
pdevinfo.name = dev_name(&adev->dev); pdevinfo.name = dev_name(&adev->dev);
pdevinfo.id = -1; pdevinfo.id = PLATFORM_DEVID_NONE;
pdevinfo.res = resources; pdevinfo.res = resources;
pdevinfo.num_res = count; pdevinfo.num_res = count;
pdevinfo.fwnode = acpi_fwnode_handle(adev); pdevinfo.fwnode = acpi_fwnode_handle(adev);
......
...@@ -4,11 +4,12 @@ ...@@ -4,11 +4,12 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/dma-direct.h> #include <linux/dma-direct.h>
void acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size) void acpi_arch_dma_setup(struct device *dev)
{ {
int ret; int ret;
u64 end, mask; u64 end, mask;
u64 dmaaddr = 0, size = 0, offset = 0; u64 size = 0;
const struct bus_dma_region *map = NULL;
/* /*
* If @dev is expected to be DMA-capable then the bus code that created * If @dev is expected to be DMA-capable then the bus code that created
...@@ -26,7 +27,19 @@ void acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size) ...@@ -26,7 +27,19 @@ void acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size)
else else
size = 1ULL << 32; size = 1ULL << 32;
ret = acpi_dma_get_range(dev, &dmaaddr, &offset, &size); ret = acpi_dma_get_range(dev, &map);
if (!ret && map) {
const struct bus_dma_region *r = map;
for (end = 0; r->size; r++) {
if (r->dma_start + r->size - 1 > end)
end = r->dma_start + r->size - 1;
}
size = end + 1;
dev->dma_range_map = map;
}
if (ret == -ENODEV) if (ret == -ENODEV)
ret = iort_dma_get_ranges(dev, &size); ret = iort_dma_get_ranges(dev, &size);
if (!ret) { if (!ret) {
...@@ -34,17 +47,10 @@ void acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size) ...@@ -34,17 +47,10 @@ void acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size)
* Limit coherent and dma mask based on size retrieved from * Limit coherent and dma mask based on size retrieved from
* firmware. * firmware.
*/ */
end = dmaaddr + size - 1; end = size - 1;
mask = DMA_BIT_MASK(ilog2(end) + 1); mask = DMA_BIT_MASK(ilog2(end) + 1);
dev->bus_dma_limit = end; dev->bus_dma_limit = end;
dev->coherent_dma_mask = min(dev->coherent_dma_mask, mask); dev->coherent_dma_mask = min(dev->coherent_dma_mask, mask);
*dev->dma_mask = min(*dev->dma_mask, mask); *dev->dma_mask = min(*dev->dma_mask, mask);
} }
*dma_addr = dmaaddr;
*dma_size = size;
ret = dma_direct_set_offset(dev, dmaaddr + offset, dmaaddr, size);
dev_dbg(dev, "dma_offset(%#08llx)%s\n", offset, ret ? " failed!" : "");
} }
...@@ -456,7 +456,7 @@ static void acpi_bus_osc_negotiate_usb_control(void) ...@@ -456,7 +456,7 @@ static void acpi_bus_osc_negotiate_usb_control(void)
Notification Handling Notification Handling
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
/** /*
* acpi_bus_notify * acpi_bus_notify
* --------------- * ---------------
* Callback for all 'system-level' device notifications (values 0x00-0x7F). * Callback for all 'system-level' device notifications (values 0x00-0x7F).
...@@ -925,12 +925,13 @@ static const void *acpi_of_device_get_match_data(const struct device *dev) ...@@ -925,12 +925,13 @@ static const void *acpi_of_device_get_match_data(const struct device *dev)
const void *acpi_device_get_match_data(const struct device *dev) const void *acpi_device_get_match_data(const struct device *dev)
{ {
const struct acpi_device_id *acpi_ids = dev->driver->acpi_match_table;
const struct acpi_device_id *match; const struct acpi_device_id *match;
if (!dev->driver->acpi_match_table) if (!acpi_ids)
return acpi_of_device_get_match_data(dev); return acpi_of_device_get_match_data(dev);
match = acpi_match_device(dev->driver->acpi_match_table, dev); match = acpi_match_device(acpi_ids, dev);
if (!match) if (!match)
return NULL; return NULL;
...@@ -948,14 +949,13 @@ EXPORT_SYMBOL(acpi_match_device_ids); ...@@ -948,14 +949,13 @@ EXPORT_SYMBOL(acpi_match_device_ids);
bool acpi_driver_match_device(struct device *dev, bool acpi_driver_match_device(struct device *dev,
const struct device_driver *drv) const struct device_driver *drv)
{ {
if (!drv->acpi_match_table) const struct acpi_device_id *acpi_ids = drv->acpi_match_table;
return acpi_of_match_device(ACPI_COMPANION(dev), const struct of_device_id *of_ids = drv->of_match_table;
drv->of_match_table,
NULL); if (!acpi_ids)
return acpi_of_match_device(ACPI_COMPANION(dev), of_ids, NULL);
return __acpi_match_device(acpi_companion_match(dev),
drv->acpi_match_table, drv->of_match_table, return __acpi_match_device(acpi_companion_match(dev), acpi_ids, of_ids, NULL, NULL);
NULL, NULL);
} }
EXPORT_SYMBOL_GPL(acpi_driver_match_device); EXPORT_SYMBOL_GPL(acpi_driver_match_device);
...@@ -973,16 +973,13 @@ EXPORT_SYMBOL_GPL(acpi_driver_match_device); ...@@ -973,16 +973,13 @@ EXPORT_SYMBOL_GPL(acpi_driver_match_device);
*/ */
int acpi_bus_register_driver(struct acpi_driver *driver) int acpi_bus_register_driver(struct acpi_driver *driver)
{ {
int ret;
if (acpi_disabled) if (acpi_disabled)
return -ENODEV; return -ENODEV;
driver->drv.name = driver->name; driver->drv.name = driver->name;
driver->drv.bus = &acpi_bus_type; driver->drv.bus = &acpi_bus_type;
driver->drv.owner = driver->owner; driver->drv.owner = driver->owner;
ret = driver_register(&driver->drv); return driver_register(&driver->drv);
return ret;
} }
EXPORT_SYMBOL(acpi_bus_register_driver); EXPORT_SYMBOL(acpi_bus_register_driver);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <linux/platform_data/x86/apple.h> #include <linux/platform_data/x86/apple.h>
#include <linux/pgtable.h> #include <linux/pgtable.h>
#include <linux/crc32.h> #include <linux/crc32.h>
#include <linux/dma-direct.h>
#include "internal.h" #include "internal.h"
...@@ -1463,25 +1464,21 @@ enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev) ...@@ -1463,25 +1464,21 @@ enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev)
* acpi_dma_get_range() - Get device DMA parameters. * acpi_dma_get_range() - Get device DMA parameters.
* *
* @dev: device to configure * @dev: device to configure
* @dma_addr: pointer device DMA address result * @map: pointer to DMA ranges result
* @offset: pointer to the DMA offset result
* @size: pointer to DMA range size result
* *
* Evaluate DMA regions and return respectively DMA region start, offset * Evaluate DMA regions and return pointer to DMA regions on
* and size in dma_addr, offset and size on parsing success; it does not * parsing success; it does not update the passed in values on failure.
* update the passed in values on failure.
* *
* Return 0 on success, < 0 on failure. * Return 0 on success, < 0 on failure.
*/ */
int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset, int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
u64 *size)
{ {
struct acpi_device *adev; struct acpi_device *adev;
LIST_HEAD(list); LIST_HEAD(list);
struct resource_entry *rentry; struct resource_entry *rentry;
int ret; int ret;
struct device *dma_dev = dev; struct device *dma_dev = dev;
u64 len, dma_start = U64_MAX, dma_end = 0, dma_offset = 0; struct bus_dma_region *r;
/* /*
* Walk the device tree chasing an ACPI companion with a _DMA * Walk the device tree chasing an ACPI companion with a _DMA
...@@ -1506,31 +1503,28 @@ int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset, ...@@ -1506,31 +1503,28 @@ int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
ret = acpi_dev_get_dma_resources(adev, &list); ret = acpi_dev_get_dma_resources(adev, &list);
if (ret > 0) { if (ret > 0) {
list_for_each_entry(rentry, &list, node) { r = kcalloc(ret + 1, sizeof(*r), GFP_KERNEL);
if (dma_offset && rentry->offset != dma_offset) { if (!r) {
ret = -EINVAL; ret = -ENOMEM;
dev_warn(dma_dev, "Can't handle multiple windows with different offsets\n");
goto out; goto out;
} }
dma_offset = rentry->offset;
/* Take lower and upper limits */
if (rentry->res->start < dma_start)
dma_start = rentry->res->start;
if (rentry->res->end > dma_end)
dma_end = rentry->res->end;
}
if (dma_start >= dma_end) { list_for_each_entry(rentry, &list, node) {
if (rentry->res->start >= rentry->res->end) {
kfree(r);
ret = -EINVAL; ret = -EINVAL;
dev_dbg(dma_dev, "Invalid DMA regions configuration\n"); dev_dbg(dma_dev, "Invalid DMA regions configuration\n");
goto out; goto out;
} }
*dma_addr = dma_start - dma_offset; r->cpu_start = rentry->res->start;
len = dma_end - dma_start; r->dma_start = rentry->res->start - rentry->offset;
*size = max(len, len + 1); r->size = resource_size(rentry->res);
*offset = dma_offset; r->offset = rentry->offset;
r++;
}
*map = r;
} }
out: out:
acpi_dev_free_resource_list(&list); acpi_dev_free_resource_list(&list);
...@@ -1620,20 +1614,19 @@ int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr, ...@@ -1620,20 +1614,19 @@ int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
const u32 *input_id) const u32 *input_id)
{ {
const struct iommu_ops *iommu; const struct iommu_ops *iommu;
u64 dma_addr = 0, size = 0;
if (attr == DEV_DMA_NOT_SUPPORTED) { if (attr == DEV_DMA_NOT_SUPPORTED) {
set_dma_ops(dev, &dma_dummy_ops); set_dma_ops(dev, &dma_dummy_ops);
return 0; return 0;
} }
acpi_arch_dma_setup(dev, &dma_addr, &size); acpi_arch_dma_setup(dev);
iommu = acpi_iommu_configure_id(dev, input_id); iommu = acpi_iommu_configure_id(dev, input_id);
if (PTR_ERR(iommu) == -EPROBE_DEFER) if (PTR_ERR(iommu) == -EPROBE_DEFER)
return -EPROBE_DEFER; return -EPROBE_DEFER;
arch_setup_dma_ops(dev, dma_addr, size, arch_setup_dma_ops(dev, 0, U64_MAX,
iommu, attr == DEV_DMA_COHERENT); iommu, attr == DEV_DMA_COHERENT);
return 0; return 0;
......
...@@ -619,8 +619,7 @@ enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev); ...@@ -619,8 +619,7 @@ enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev);
int acpi_iommu_fwspec_init(struct device *dev, u32 id, int acpi_iommu_fwspec_init(struct device *dev, u32 id,
struct fwnode_handle *fwnode, struct fwnode_handle *fwnode,
const struct iommu_ops *ops); const struct iommu_ops *ops);
int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset, int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map);
u64 *size);
int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr, int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
const u32 *input_id); const u32 *input_id);
static inline int acpi_dma_configure(struct device *dev, static inline int acpi_dma_configure(struct device *dev,
......
...@@ -279,14 +279,17 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa) { } ...@@ -279,14 +279,17 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa) { }
void acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa); void acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa);
#if defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH)
void acpi_arch_dma_setup(struct device *dev);
#else
static inline void acpi_arch_dma_setup(struct device *dev) { }
#endif
#ifdef CONFIG_ARM64 #ifdef CONFIG_ARM64
void acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa); void acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa);
void acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size);
#else #else
static inline void static inline void
acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { } acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }
static inline void
acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size) { }
#endif #endif
int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma); int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
...@@ -978,8 +981,7 @@ static inline enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev) ...@@ -978,8 +981,7 @@ static inline enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev)
return DEV_DMA_NOT_SUPPORTED; return DEV_DMA_NOT_SUPPORTED;
} }
static inline int acpi_dma_get_range(struct device *dev, u64 *dma_addr, static inline int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
u64 *offset, u64 *size)
{ {
return -ENODEV; return -ENODEV;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment