Skip to content

Commit c77f54a

Browse files
committed
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'
4 parents d61991d + c78c43f + fe79e39 + 2814108 commit c77f54a

File tree

9 files changed

+89
-105
lines changed

9 files changed

+89
-105
lines changed

arch/loongarch/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ config LOONGARCH
1010
select ARCH_ENABLE_MEMORY_HOTPLUG
1111
select ARCH_ENABLE_MEMORY_HOTREMOVE
1212
select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
13-
select ARCH_HAS_PHYS_TO_DMA
1413
select ARCH_HAS_PTE_SPECIAL
1514
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
1615
select ARCH_INLINE_READ_LOCK if !PREEMPTION

arch/loongarch/kernel/dma.c

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,29 @@
22
/*
33
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
44
*/
5-
#include <linux/init.h>
5+
#include <linux/acpi.h>
66
#include <linux/dma-direct.h>
7-
#include <linux/dma-mapping.h>
8-
#include <linux/dma-map-ops.h>
9-
#include <linux/swiotlb.h>
107

11-
#include <asm/bootinfo.h>
12-
#include <asm/dma.h>
13-
#include <asm/loongson.h>
14-
15-
/*
16-
* We extract 4bit node id (bit 44~47) from Loongson-3's
17-
* 48bit physical address space and embed it into 40bit.
18-
*/
19-
20-
static int node_id_offset;
21-
22-
dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
23-
{
24-
long nid = (paddr >> 44) & 0xf;
25-
26-
return ((nid << 44) ^ paddr) | (nid << node_id_offset);
27-
}
28-
29-
phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
8+
void acpi_arch_dma_setup(struct device *dev)
309
{
31-
long nid = (daddr >> node_id_offset) & 0xf;
10+
int ret;
11+
u64 mask, end = 0;
12+
const struct bus_dma_region *map = NULL;
13+
14+
ret = acpi_dma_get_range(dev, &map);
15+
if (!ret && map) {
16+
const struct bus_dma_region *r = map;
17+
18+
for (end = 0; r->size; r++) {
19+
if (r->dma_start + r->size - 1 > end)
20+
end = r->dma_start + r->size - 1;
21+
}
22+
23+
mask = DMA_BIT_MASK(ilog2(end) + 1);
24+
dev->bus_dma_limit = end;
25+
dev->dma_range_map = map;
26+
dev->coherent_dma_mask = min(dev->coherent_dma_mask, mask);
27+
*dev->dma_mask = min(*dev->dma_mask, mask);
28+
}
3229

33-
return ((nid << node_id_offset) ^ daddr) | (nid << 44);
34-
}
35-
36-
void __init plat_swiotlb_setup(void)
37-
{
38-
swiotlb_init(true, SWIOTLB_VERBOSE);
39-
node_id_offset = ((readl(LS7A_DMA_CFG) & LS7A_DMA_NODE_MASK) >> LS7A_DMA_NODE_SHF) + 36;
4030
}

arch/loongarch/kernel/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ static void __init arch_mem_init(char **cmdline_p)
247247
sparse_init();
248248
memblock_set_bottom_up(true);
249249

250-
plat_swiotlb_setup();
250+
swiotlb_init(true, SWIOTLB_VERBOSE);
251251

252252
dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
253253

drivers/acpi/acpi_platform.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
#include "internal.h"
2121

2222
static const struct acpi_device_id forbidden_id_list[] = {
23+
{"ACPI0009", 0}, /* IOxAPIC */
24+
{"ACPI000A", 0}, /* IOAPIC */
2325
{"PNP0000", 0}, /* PIC */
2426
{"PNP0100", 0}, /* Timer */
2527
{"PNP0200", 0}, /* AT DMA Controller */
26-
{"ACPI0009", 0}, /* IOxAPIC */
27-
{"ACPI000A", 0}, /* IOAPIC */
2828
{"SMB0001", 0}, /* ACPI SMBUS virtual device */
29-
{"", 0},
29+
{ }
3030
};
3131

3232
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,
114114

115115
INIT_LIST_HEAD(&resource_list);
116116
count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
117-
if (count < 0) {
117+
if (count < 0)
118118
return NULL;
119-
} else if (count > 0) {
120-
resources = kcalloc(count, sizeof(struct resource),
121-
GFP_KERNEL);
119+
if (count > 0) {
120+
resources = kcalloc(count, sizeof(*resources), GFP_KERNEL);
122121
if (!resources) {
123-
dev_err(&adev->dev, "No memory for resources\n");
124122
acpi_dev_free_resource_list(&resource_list);
125123
return ERR_PTR(-ENOMEM);
126124
}
@@ -140,7 +138,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
140138
*/
141139
pdevinfo.parent = parent ? acpi_get_first_physical_node(parent) : NULL;
142140
pdevinfo.name = dev_name(&adev->dev);
143-
pdevinfo.id = -1;
141+
pdevinfo.id = PLATFORM_DEVID_NONE;
144142
pdevinfo.res = resources;
145143
pdevinfo.num_res = count;
146144
pdevinfo.fwnode = acpi_fwnode_handle(adev);

drivers/acpi/arm64/dma.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
#include <linux/device.h>
55
#include <linux/dma-direct.h>
66

7-
void acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size)
7+
void acpi_arch_dma_setup(struct device *dev)
88
{
99
int ret;
1010
u64 end, mask;
11-
u64 dmaaddr = 0, size = 0, offset = 0;
11+
u64 size = 0;
12+
const struct bus_dma_region *map = NULL;
1213

1314
/*
1415
* If @dev is expected to be DMA-capable then the bus code that created
@@ -26,25 +27,30 @@ void acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size)
2627
else
2728
size = 1ULL << 32;
2829

29-
ret = acpi_dma_get_range(dev, &dmaaddr, &offset, &size);
30+
ret = acpi_dma_get_range(dev, &map);
31+
if (!ret && map) {
32+
const struct bus_dma_region *r = map;
33+
34+
for (end = 0; r->size; r++) {
35+
if (r->dma_start + r->size - 1 > end)
36+
end = r->dma_start + r->size - 1;
37+
}
38+
39+
size = end + 1;
40+
dev->dma_range_map = map;
41+
}
42+
3043
if (ret == -ENODEV)
3144
ret = iort_dma_get_ranges(dev, &size);
3245
if (!ret) {
3346
/*
3447
* Limit coherent and dma mask based on size retrieved from
3548
* firmware.
3649
*/
37-
end = dmaaddr + size - 1;
50+
end = size - 1;
3851
mask = DMA_BIT_MASK(ilog2(end) + 1);
3952
dev->bus_dma_limit = end;
4053
dev->coherent_dma_mask = min(dev->coherent_dma_mask, mask);
4154
*dev->dma_mask = min(*dev->dma_mask, mask);
4255
}
43-
44-
*dma_addr = dmaaddr;
45-
*dma_size = size;
46-
47-
ret = dma_direct_set_offset(dev, dmaaddr + offset, dmaaddr, size);
48-
49-
dev_dbg(dev, "dma_offset(%#08llx)%s\n", offset, ret ? " failed!" : "");
5056
}

drivers/acpi/bus.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ static void acpi_bus_osc_negotiate_usb_control(void)
456456
Notification Handling
457457
-------------------------------------------------------------------------- */
458458

459-
/**
459+
/*
460460
* acpi_bus_notify
461461
* ---------------
462462
* 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)
925925

926926
const void *acpi_device_get_match_data(const struct device *dev)
927927
{
928+
const struct acpi_device_id *acpi_ids = dev->driver->acpi_match_table;
928929
const struct acpi_device_id *match;
929930

930-
if (!dev->driver->acpi_match_table)
931+
if (!acpi_ids)
931932
return acpi_of_device_get_match_data(dev);
932933

933-
match = acpi_match_device(dev->driver->acpi_match_table, dev);
934+
match = acpi_match_device(acpi_ids, dev);
934935
if (!match)
935936
return NULL;
936937

@@ -948,14 +949,13 @@ EXPORT_SYMBOL(acpi_match_device_ids);
948949
bool acpi_driver_match_device(struct device *dev,
949950
const struct device_driver *drv)
950951
{
951-
if (!drv->acpi_match_table)
952-
return acpi_of_match_device(ACPI_COMPANION(dev),
953-
drv->of_match_table,
954-
NULL);
955-
956-
return __acpi_match_device(acpi_companion_match(dev),
957-
drv->acpi_match_table, drv->of_match_table,
958-
NULL, NULL);
952+
const struct acpi_device_id *acpi_ids = drv->acpi_match_table;
953+
const struct of_device_id *of_ids = drv->of_match_table;
954+
955+
if (!acpi_ids)
956+
return acpi_of_match_device(ACPI_COMPANION(dev), of_ids, NULL);
957+
958+
return __acpi_match_device(acpi_companion_match(dev), acpi_ids, of_ids, NULL, NULL);
959959
}
960960
EXPORT_SYMBOL_GPL(acpi_driver_match_device);
961961

@@ -973,16 +973,13 @@ EXPORT_SYMBOL_GPL(acpi_driver_match_device);
973973
*/
974974
int acpi_bus_register_driver(struct acpi_driver *driver)
975975
{
976-
int ret;
977-
978976
if (acpi_disabled)
979977
return -ENODEV;
980978
driver->drv.name = driver->name;
981979
driver->drv.bus = &acpi_bus_type;
982980
driver->drv.owner = driver->owner;
983981

984-
ret = driver_register(&driver->drv);
985-
return ret;
982+
return driver_register(&driver->drv);
986983
}
987984

988985
EXPORT_SYMBOL(acpi_bus_register_driver);

drivers/acpi/scan.c

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/platform_data/x86/apple.h>
2121
#include <linux/pgtable.h>
2222
#include <linux/crc32.h>
23+
#include <linux/dma-direct.h>
2324

2425
#include "internal.h"
2526

@@ -1463,25 +1464,21 @@ enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev)
14631464
* acpi_dma_get_range() - Get device DMA parameters.
14641465
*
14651466
* @dev: device to configure
1466-
* @dma_addr: pointer device DMA address result
1467-
* @offset: pointer to the DMA offset result
1468-
* @size: pointer to DMA range size result
1467+
* @map: pointer to DMA ranges result
14691468
*
1470-
* Evaluate DMA regions and return respectively DMA region start, offset
1471-
* and size in dma_addr, offset and size on parsing success; it does not
1472-
* update the passed in values on failure.
1469+
* Evaluate DMA regions and return pointer to DMA regions on
1470+
* parsing success; it does not update the passed in values on failure.
14731471
*
14741472
* Return 0 on success, < 0 on failure.
14751473
*/
1476-
int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
1477-
u64 *size)
1474+
int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
14781475
{
14791476
struct acpi_device *adev;
14801477
LIST_HEAD(list);
14811478
struct resource_entry *rentry;
14821479
int ret;
14831480
struct device *dma_dev = dev;
1484-
u64 len, dma_start = U64_MAX, dma_end = 0, dma_offset = 0;
1481+
struct bus_dma_region *r;
14851482

14861483
/*
14871484
* 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,
15061503

15071504
ret = acpi_dev_get_dma_resources(adev, &list);
15081505
if (ret > 0) {
1506+
r = kcalloc(ret + 1, sizeof(*r), GFP_KERNEL);
1507+
if (!r) {
1508+
ret = -ENOMEM;
1509+
goto out;
1510+
}
1511+
15091512
list_for_each_entry(rentry, &list, node) {
1510-
if (dma_offset && rentry->offset != dma_offset) {
1513+
if (rentry->res->start >= rentry->res->end) {
1514+
kfree(r);
15111515
ret = -EINVAL;
1512-
dev_warn(dma_dev, "Can't handle multiple windows with different offsets\n");
1516+
dev_dbg(dma_dev, "Invalid DMA regions configuration\n");
15131517
goto out;
15141518
}
1515-
dma_offset = rentry->offset;
15161519

1517-
/* Take lower and upper limits */
1518-
if (rentry->res->start < dma_start)
1519-
dma_start = rentry->res->start;
1520-
if (rentry->res->end > dma_end)
1521-
dma_end = rentry->res->end;
1522-
}
1523-
1524-
if (dma_start >= dma_end) {
1525-
ret = -EINVAL;
1526-
dev_dbg(dma_dev, "Invalid DMA regions configuration\n");
1527-
goto out;
1520+
r->cpu_start = rentry->res->start;
1521+
r->dma_start = rentry->res->start - rentry->offset;
1522+
r->size = resource_size(rentry->res);
1523+
r->offset = rentry->offset;
1524+
r++;
15281525
}
15291526

1530-
*dma_addr = dma_start - dma_offset;
1531-
len = dma_end - dma_start;
1532-
*size = max(len, len + 1);
1533-
*offset = dma_offset;
1527+
*map = r;
15341528
}
15351529
out:
15361530
acpi_dev_free_resource_list(&list);
@@ -1620,20 +1614,19 @@ int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
16201614
const u32 *input_id)
16211615
{
16221616
const struct iommu_ops *iommu;
1623-
u64 dma_addr = 0, size = 0;
16241617

16251618
if (attr == DEV_DMA_NOT_SUPPORTED) {
16261619
set_dma_ops(dev, &dma_dummy_ops);
16271620
return 0;
16281621
}
16291622

1630-
acpi_arch_dma_setup(dev, &dma_addr, &size);
1623+
acpi_arch_dma_setup(dev);
16311624

16321625
iommu = acpi_iommu_configure_id(dev, input_id);
16331626
if (PTR_ERR(iommu) == -EPROBE_DEFER)
16341627
return -EPROBE_DEFER;
16351628

1636-
arch_setup_dma_ops(dev, dma_addr, size,
1629+
arch_setup_dma_ops(dev, 0, U64_MAX,
16371630
iommu, attr == DEV_DMA_COHERENT);
16381631

16391632
return 0;

include/acpi/acpi_bus.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,7 @@ enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev);
619619
int acpi_iommu_fwspec_init(struct device *dev, u32 id,
620620
struct fwnode_handle *fwnode,
621621
const struct iommu_ops *ops);
622-
int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
623-
u64 *size);
622+
int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map);
624623
int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
625624
const u32 *input_id);
626625
static inline int acpi_dma_configure(struct device *dev,

include/linux/acpi.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,17 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa) { }
279279

280280
void acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa);
281281

282+
#if defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH)
283+
void acpi_arch_dma_setup(struct device *dev);
284+
#else
285+
static inline void acpi_arch_dma_setup(struct device *dev) { }
286+
#endif
287+
282288
#ifdef CONFIG_ARM64
283289
void acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa);
284-
void acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size);
285290
#else
286291
static inline void
287292
acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }
288-
static inline void
289-
acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size) { }
290293
#endif
291294

292295
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)
978981
return DEV_DMA_NOT_SUPPORTED;
979982
}
980983

981-
static inline int acpi_dma_get_range(struct device *dev, u64 *dma_addr,
982-
u64 *offset, u64 *size)
984+
static inline int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
983985
{
984986
return -ENODEV;
985987
}

0 commit comments

Comments
 (0)