Merge branches 'acpi-scan', 'acpi-bus' and 'acpi-platform'
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 30 Sep 2022 18:28:22 +0000 (20:28 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 30 Sep 2022 18:28:22 +0000 (20:28 +0200)
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'

arch/loongarch/Kconfig
arch/loongarch/kernel/dma.c
arch/loongarch/kernel/setup.c
drivers/acpi/acpi_platform.c
drivers/acpi/arm64/dma.c
drivers/acpi/bus.c
drivers/acpi/scan.c
include/acpi/acpi_bus.h
include/linux/acpi.h

index c7dd6ad..551dd99 100644 (file)
@@ -10,7 +10,6 @@ config LOONGARCH
        select ARCH_ENABLE_MEMORY_HOTPLUG
        select ARCH_ENABLE_MEMORY_HOTREMOVE
        select ARCH_HAS_ACPI_TABLE_UPGRADE      if ACPI
-       select ARCH_HAS_PHYS_TO_DMA
        select ARCH_HAS_PTE_SPECIAL
        select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
        select ARCH_INLINE_READ_LOCK if !PREEMPTION
index 8c9b531..7a9c6a9 100644 (file)
@@ -2,39 +2,29 @@
 /*
  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
  */
-#include <linux/init.h>
+#include <linux/acpi.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>
-#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)
+void acpi_arch_dma_setup(struct device *dev)
 {
-       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;
 }
index 8f5c2f9..d97c69d 100644 (file)
@@ -247,7 +247,7 @@ static void __init arch_mem_init(char **cmdline_p)
        sparse_init();
        memblock_set_bottom_up(true);
 
-       plat_swiotlb_setup();
+       swiotlb_init(true, SWIOTLB_VERBOSE);
 
        dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
 
index 1a1c78b..fe00a57 100644 (file)
 #include "internal.h"
 
 static const struct acpi_device_id forbidden_id_list[] = {
+       {"ACPI0009", 0},        /* IOxAPIC */
+       {"ACPI000A", 0},        /* IOAPIC */
        {"PNP0000",  0},        /* PIC */
        {"PNP0100",  0},        /* Timer */
        {"PNP0200",  0},        /* AT DMA Controller */
-       {"ACPI0009", 0},        /* IOxAPIC */
-       {"ACPI000A", 0},        /* IOAPIC */
        {"SMB0001",  0},        /* ACPI SMBUS virtual device */
-       {"", 0},
+       { }
 };
 
 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,
 
        INIT_LIST_HEAD(&resource_list);
        count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
-       if (count < 0) {
+       if (count < 0)
                return NULL;
-       } else if (count > 0) {
-               resources = kcalloc(count, sizeof(struct resource),
-                                   GFP_KERNEL);
+       if (count > 0) {
+               resources = kcalloc(count, sizeof(*resources), GFP_KERNEL);
                if (!resources) {
-                       dev_err(&adev->dev, "No memory for resources\n");
                        acpi_dev_free_resource_list(&resource_list);
                        return ERR_PTR(-ENOMEM);
                }
@@ -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.name = dev_name(&adev->dev);
-       pdevinfo.id = -1;
+       pdevinfo.id = PLATFORM_DEVID_NONE;
        pdevinfo.res = resources;
        pdevinfo.num_res = count;
        pdevinfo.fwnode = acpi_fwnode_handle(adev);
index f16739a..93d7965 100644 (file)
@@ -4,11 +4,12 @@
 #include <linux/device.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;
        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
@@ -26,7 +27,19 @@ void acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size)
        else
                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)
                ret = iort_dma_get_ranges(dev, &size);
        if (!ret) {
@@ -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
                 * firmware.
                 */
-               end = dmaaddr + size - 1;
+               end = size - 1;
                mask = DMA_BIT_MASK(ilog2(end) + 1);
                dev->bus_dma_limit = end;
                dev->coherent_dma_mask = min(dev->coherent_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!" : "");
 }
index f43c6a4..45eb901 100644 (file)
@@ -456,7 +456,7 @@ out_free:
                              Notification Handling
    -------------------------------------------------------------------------- */
 
-/**
+/*
  * acpi_bus_notify
  * ---------------
  * 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)
 
 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;
 
-       if (!dev->driver->acpi_match_table)
+       if (!acpi_ids)
                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)
                return NULL;
 
@@ -948,14 +949,13 @@ EXPORT_SYMBOL(acpi_match_device_ids);
 bool acpi_driver_match_device(struct device *dev,
                              const struct device_driver *drv)
 {
-       if (!drv->acpi_match_table)
-               return acpi_of_match_device(ACPI_COMPANION(dev),
-                                           drv->of_match_table,
-                                           NULL);
-
-       return __acpi_match_device(acpi_companion_match(dev),
-                                  drv->acpi_match_table, drv->of_match_table,
-                                  NULL, NULL);
+       const struct acpi_device_id *acpi_ids = drv->acpi_match_table;
+       const struct of_device_id *of_ids = drv->of_match_table;
+
+       if (!acpi_ids)
+               return acpi_of_match_device(ACPI_COMPANION(dev), of_ids, NULL);
+
+       return __acpi_match_device(acpi_companion_match(dev), acpi_ids, of_ids, NULL, NULL);
 }
 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 ret;
-
        if (acpi_disabled)
                return -ENODEV;
        driver->drv.name = driver->name;
        driver->drv.bus = &acpi_bus_type;
        driver->drv.owner = driver->owner;
 
-       ret = driver_register(&driver->drv);
-       return ret;
+       return driver_register(&driver->drv);
 }
 
 EXPORT_SYMBOL(acpi_bus_register_driver);
index d027742..558664d 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/platform_data/x86/apple.h>
 #include <linux/pgtable.h>
 #include <linux/crc32.h>
+#include <linux/dma-direct.h>
 
 #include "internal.h"
 
@@ -1463,25 +1464,21 @@ enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev)
  * acpi_dma_get_range() - Get device DMA parameters.
  *
  * @dev: device to configure
- * @dma_addr: pointer device DMA address result
- * @offset: pointer to the DMA offset result
- * @size: pointer to DMA range size result
+ * @map: pointer to DMA ranges result
  *
- * Evaluate DMA regions and return respectively DMA region start, offset
- * and size in dma_addr, offset and size on parsing success; it does not
- * update the passed in values on failure.
+ * Evaluate DMA regions and return pointer to DMA regions on
+ * parsing success; it does not update the passed in values on failure.
  *
  * Return 0 on success, < 0 on failure.
  */
-int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
-                      u64 *size)
+int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
 {
        struct acpi_device *adev;
        LIST_HEAD(list);
        struct resource_entry *rentry;
        int ret;
        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
@@ -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);
        if (ret > 0) {
+               r = kcalloc(ret + 1, sizeof(*r), GFP_KERNEL);
+               if (!r) {
+                       ret = -ENOMEM;
+                       goto out;
+               }
+
                list_for_each_entry(rentry, &list, node) {
-                       if (dma_offset && rentry->offset != dma_offset) {
+                       if (rentry->res->start >= rentry->res->end) {
+                               kfree(r);
                                ret = -EINVAL;
-                               dev_warn(dma_dev, "Can't handle multiple windows with different offsets\n");
+                               dev_dbg(dma_dev, "Invalid DMA regions configuration\n");
                                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) {
-                       ret = -EINVAL;
-                       dev_dbg(dma_dev, "Invalid DMA regions configuration\n");
-                       goto out;
+                       r->cpu_start = rentry->res->start;
+                       r->dma_start = rentry->res->start - rentry->offset;
+                       r->size = resource_size(rentry->res);
+                       r->offset = rentry->offset;
+                       r++;
                }
 
-               *dma_addr = dma_start - dma_offset;
-               len = dma_end - dma_start;
-               *size = max(len, len + 1);
-               *offset = dma_offset;
+               *map = r;
        }
  out:
        acpi_dev_free_resource_list(&list);
@@ -1620,20 +1614,19 @@ int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
                          const u32 *input_id)
 {
        const struct iommu_ops *iommu;
-       u64 dma_addr = 0, size = 0;
 
        if (attr == DEV_DMA_NOT_SUPPORTED) {
                set_dma_ops(dev, &dma_dummy_ops);
                return 0;
        }
 
-       acpi_arch_dma_setup(dev, &dma_addr, &size);
+       acpi_arch_dma_setup(dev);
 
        iommu = acpi_iommu_configure_id(dev, input_id);
        if (PTR_ERR(iommu) == -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);
 
        return 0;
index f016c15..3cd269d 100644 (file)
@@ -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,
                           struct fwnode_handle *fwnode,
                           const struct iommu_ops *ops);
-int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
-                      u64 *size);
+int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map);
 int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
                           const u32 *input_id);
 static inline int acpi_dma_configure(struct device *dev,
index ed4aa39..85a35f6 100644 (file)
@@ -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);
 
+#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
 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
 static inline void
 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
 
 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)
        return DEV_DMA_NOT_SUPPORTED;
 }
 
-static inline int acpi_dma_get_range(struct device *dev, u64 *dma_addr,
-                                    u64 *offset, u64 *size)
+static inline int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
 {
        return -ENODEV;
 }