Skip to content

Commit 00674a3

Browse files
committed
Merge branch 'refs/heads/bits/020-dart' into asahi-wip
2 parents d28857d + 998fd7c commit 00674a3

31 files changed

Lines changed: 913 additions & 439 deletions

arch/arc/mm/dma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size,
9191
* Plug in direct dma map ops.
9292
*/
9393
void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
94-
const struct iommu_ops *iommu, bool coherent)
94+
bool coherent)
9595
{
9696
/*
9797
* IOC hardware snoops all DMA traffic keeping the caches consistent

arch/arm/mm/dma-mapping-nommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size,
3434
}
3535

3636
void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
37-
const struct iommu_ops *iommu, bool coherent)
37+
bool coherent)
3838
{
3939
if (IS_ENABLED(CONFIG_CPU_V7M)) {
4040
/*

arch/arm/mm/dma-mapping.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,7 @@ void arm_iommu_detach_device(struct device *dev)
17131713
EXPORT_SYMBOL_GPL(arm_iommu_detach_device);
17141714

17151715
static void arm_setup_iommu_dma_ops(struct device *dev, u64 dma_base, u64 size,
1716-
const struct iommu_ops *iommu, bool coherent)
1716+
bool coherent)
17171717
{
17181718
struct dma_iommu_mapping *mapping;
17191719

@@ -1748,7 +1748,7 @@ static void arm_teardown_iommu_dma_ops(struct device *dev)
17481748
#else
17491749

17501750
static void arm_setup_iommu_dma_ops(struct device *dev, u64 dma_base, u64 size,
1751-
const struct iommu_ops *iommu, bool coherent)
1751+
bool coherent)
17521752
{
17531753
}
17541754

@@ -1757,7 +1757,7 @@ static void arm_teardown_iommu_dma_ops(struct device *dev) { }
17571757
#endif /* CONFIG_ARM_DMA_USE_IOMMU */
17581758

17591759
void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
1760-
const struct iommu_ops *iommu, bool coherent)
1760+
bool coherent)
17611761
{
17621762
/*
17631763
* Due to legacy code that sets the ->dma_coherent flag from a bus
@@ -1776,8 +1776,8 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
17761776
if (dev->dma_ops)
17771777
return;
17781778

1779-
if (iommu)
1780-
arm_setup_iommu_dma_ops(dev, dma_base, size, iommu, coherent);
1779+
if (device_iommu_mapped(dev))
1780+
arm_setup_iommu_dma_ops(dev, dma_base, size, coherent);
17811781

17821782
xen_setup_dma_ops(dev);
17831783
dev->archdata.dma_ops_setup = true;

arch/arm64/mm/dma-mapping.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void arch_teardown_dma_ops(struct device *dev)
4747
#endif
4848

4949
void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
50-
const struct iommu_ops *iommu, bool coherent)
50+
bool coherent)
5151
{
5252
int cls = cache_line_size_of_cpu();
5353

@@ -58,7 +58,7 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
5858
ARCH_DMA_MINALIGN, cls);
5959

6060
dev->dma_coherent = coherent;
61-
if (iommu)
61+
if (device_iommu_mapped(dev))
6262
iommu_setup_dma_ops(dev, dma_base, dma_base + size - 1);
6363

6464
xen_setup_dma_ops(dev);

arch/mips/mm/dma-noncoherent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size,
138138

139139
#ifdef CONFIG_ARCH_HAS_SETUP_DMA_OPS
140140
void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
141-
const struct iommu_ops *iommu, bool coherent)
141+
bool coherent)
142142
{
143143
dev->dma_coherent = coherent;
144144
}

arch/riscv/mm/dma-noncoherent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void arch_dma_prep_coherent(struct page *page, size_t size)
135135
}
136136

137137
void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
138-
const struct iommu_ops *iommu, bool coherent)
138+
bool coherent)
139139
{
140140
WARN_TAINT(!coherent && riscv_cbom_block_size > ARCH_DMA_MINALIGN,
141141
TAINT_CPU_OUT_OF_SPEC,

drivers/acpi/arm64/iort.c

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,10 +1218,9 @@ static bool iort_pci_rc_supports_ats(struct acpi_iort_node *node)
12181218
return pci_rc->ats_attribute & ACPI_IORT_ATS_SUPPORTED;
12191219
}
12201220

1221-
static int iort_iommu_xlate(struct device *dev, struct acpi_iort_node *node,
1222-
u32 streamid)
1221+
static int iort_iommu_xlate(struct iommu_fwspec *fwspec, struct device *dev,
1222+
struct acpi_iort_node *node, u32 streamid)
12231223
{
1224-
const struct iommu_ops *ops;
12251224
struct fwnode_handle *iort_fwnode;
12261225

12271226
if (!node)
@@ -1239,17 +1238,14 @@ static int iort_iommu_xlate(struct device *dev, struct acpi_iort_node *node,
12391238
* in the kernel or not, defer the IOMMU configuration
12401239
* or just abort it.
12411240
*/
1242-
ops = iommu_ops_from_fwnode(iort_fwnode);
1243-
if (!ops)
1244-
return iort_iommu_driver_enabled(node->type) ?
1245-
-EPROBE_DEFER : -ENODEV;
1246-
1247-
return acpi_iommu_fwspec_init(dev, streamid, iort_fwnode, ops);
1241+
return acpi_iommu_fwspec_init(fwspec, dev, streamid, iort_fwnode,
1242+
iort_iommu_driver_enabled(node->type));
12481243
}
12491244

12501245
struct iort_pci_alias_info {
12511246
struct device *dev;
12521247
struct acpi_iort_node *node;
1248+
struct iommu_fwspec *fwspec;
12531249
};
12541250

12551251
static int iort_pci_iommu_init(struct pci_dev *pdev, u16 alias, void *data)
@@ -1260,7 +1256,7 @@ static int iort_pci_iommu_init(struct pci_dev *pdev, u16 alias, void *data)
12601256

12611257
parent = iort_node_map_id(info->node, alias, &streamid,
12621258
IORT_IOMMU_TYPE);
1263-
return iort_iommu_xlate(info->dev, parent, streamid);
1259+
return iort_iommu_xlate(info->fwspec, info->dev, parent, streamid);
12641260
}
12651261

12661262
static void iort_named_component_init(struct device *dev,
@@ -1280,7 +1276,8 @@ static void iort_named_component_init(struct device *dev,
12801276
dev_warn(dev, "Could not add device properties\n");
12811277
}
12821278

1283-
static int iort_nc_iommu_map(struct device *dev, struct acpi_iort_node *node)
1279+
static int iort_nc_iommu_map(struct iommu_fwspec *fwspec, struct device *dev,
1280+
struct acpi_iort_node *node)
12841281
{
12851282
struct acpi_iort_node *parent;
12861283
int err = -ENODEV, i = 0;
@@ -1293,13 +1290,13 @@ static int iort_nc_iommu_map(struct device *dev, struct acpi_iort_node *node)
12931290
i++);
12941291

12951292
if (parent)
1296-
err = iort_iommu_xlate(dev, parent, streamid);
1293+
err = iort_iommu_xlate(fwspec, dev, parent, streamid);
12971294
} while (parent && !err);
12981295

12991296
return err;
13001297
}
13011298

1302-
static int iort_nc_iommu_map_id(struct device *dev,
1299+
static int iort_nc_iommu_map_id(struct iommu_fwspec *fwspec, struct device *dev,
13031300
struct acpi_iort_node *node,
13041301
const u32 *in_id)
13051302
{
@@ -1308,7 +1305,7 @@ static int iort_nc_iommu_map_id(struct device *dev,
13081305

13091306
parent = iort_node_map_id(node, *in_id, &streamid, IORT_IOMMU_TYPE);
13101307
if (parent)
1311-
return iort_iommu_xlate(dev, parent, streamid);
1308+
return iort_iommu_xlate(fwspec, dev, parent, streamid);
13121309

13131310
return -ENODEV;
13141311
}
@@ -1317,20 +1314,22 @@ static int iort_nc_iommu_map_id(struct device *dev,
13171314
/**
13181315
* iort_iommu_configure_id - Set-up IOMMU configuration for a device.
13191316
*
1317+
* @fwspec: The iommu_fwspec to fill in with fw information about the device
13201318
* @dev: device to configure
13211319
* @id_in: optional input id const value pointer
13221320
*
13231321
* Returns: 0 on success, <0 on failure
13241322
*/
1325-
int iort_iommu_configure_id(struct device *dev, const u32 *id_in)
1323+
int iort_iommu_configure_id(struct iommu_fwspec *fwspec, struct device *dev,
1324+
const u32 *id_in)
13261325
{
13271326
struct acpi_iort_node *node;
13281327
int err = -ENODEV;
13291328

13301329
if (dev_is_pci(dev)) {
1331-
struct iommu_fwspec *fwspec;
13321330
struct pci_bus *bus = to_pci_dev(dev)->bus;
1333-
struct iort_pci_alias_info info = { .dev = dev };
1331+
struct iort_pci_alias_info info = { .dev = dev,
1332+
.fwspec = fwspec };
13341333

13351334
node = iort_scan_node(ACPI_IORT_NODE_PCI_ROOT_COMPLEX,
13361335
iort_match_node_callback, &bus->dev);
@@ -1341,17 +1340,16 @@ int iort_iommu_configure_id(struct device *dev, const u32 *id_in)
13411340
err = pci_for_each_dma_alias(to_pci_dev(dev),
13421341
iort_pci_iommu_init, &info);
13431342

1344-
fwspec = dev_iommu_fwspec_get(dev);
1345-
if (fwspec && iort_pci_rc_supports_ats(node))
1343+
if (iort_pci_rc_supports_ats(node))
13461344
fwspec->flags |= IOMMU_FWSPEC_PCI_RC_ATS;
13471345
} else {
13481346
node = iort_scan_node(ACPI_IORT_NODE_NAMED_COMPONENT,
13491347
iort_match_node_callback, dev);
13501348
if (!node)
13511349
return -ENODEV;
13521350

1353-
err = id_in ? iort_nc_iommu_map_id(dev, node, id_in) :
1354-
iort_nc_iommu_map(dev, node);
1351+
err = id_in ? iort_nc_iommu_map_id(fwspec, dev, node, id_in) :
1352+
iort_nc_iommu_map(fwspec, dev, node);
13551353

13561354
if (!err)
13571355
iort_named_component_init(dev, node);
@@ -1363,8 +1361,6 @@ int iort_iommu_configure_id(struct device *dev, const u32 *id_in)
13631361
#else
13641362
void iort_iommu_get_resv_regions(struct device *dev, struct list_head *head)
13651363
{ }
1366-
int iort_iommu_configure_id(struct device *dev, const u32 *input_id)
1367-
{ return -ENODEV; }
13681364
#endif
13691365

13701366
static int nc_dma_get_range(struct device *dev, u64 *size)

drivers/acpi/scan.c

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,73 +1543,67 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
15431543
}
15441544

15451545
#ifdef CONFIG_IOMMU_API
1546-
int acpi_iommu_fwspec_init(struct device *dev, u32 id,
1547-
struct fwnode_handle *fwnode,
1548-
const struct iommu_ops *ops)
1546+
int acpi_iommu_fwspec_init(struct iommu_fwspec *fwspec, struct device *dev,
1547+
u32 id, struct fwnode_handle *fwnode,
1548+
bool iommu_driver_available)
15491549
{
1550-
int ret = iommu_fwspec_init(dev, fwnode, ops);
1551-
1552-
if (!ret)
1553-
ret = iommu_fwspec_add_ids(dev, &id, 1);
1554-
1555-
return ret;
1556-
}
1557-
1558-
static inline const struct iommu_ops *acpi_iommu_fwspec_ops(struct device *dev)
1559-
{
1560-
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
1550+
int ret;
15611551

1562-
return fwspec ? fwspec->ops : NULL;
1552+
ret = iommu_fwspec_assign_iommu(fwspec, dev, fwnode);
1553+
if (ret) {
1554+
if (ret == -EPROBE_DEFER && !iommu_driver_available)
1555+
return -ENODEV;
1556+
return ret;
1557+
}
1558+
return iommu_fwspec_append_ids(fwspec, &id, 1);
15631559
}
15641560

1565-
static const struct iommu_ops *acpi_iommu_configure_id(struct device *dev,
1566-
const u32 *id_in)
1561+
static int acpi_iommu_configure_id(struct device *dev, const u32 *id_in)
15671562
{
15681563
int err;
1569-
const struct iommu_ops *ops;
1564+
struct iommu_fwspec *fwspec;
15701565

1571-
/*
1572-
* If we already translated the fwspec there is nothing left to do,
1573-
* return the iommu_ops.
1574-
*/
1575-
ops = acpi_iommu_fwspec_ops(dev);
1576-
if (ops)
1577-
return ops;
1566+
fwspec = iommu_fwspec_alloc();
1567+
if (IS_ERR(fwspec))
1568+
return PTR_ERR(fwspec);
15781569

1579-
err = iort_iommu_configure_id(dev, id_in);
1580-
if (err && err != -EPROBE_DEFER)
1581-
err = viot_iommu_configure(dev);
1570+
err = iort_iommu_configure_id(fwspec, dev, id_in);
1571+
if (err == -ENODEV)
1572+
err = viot_iommu_configure(fwspec, dev);
1573+
if (err == -ENODEV || err == -EPROBE_DEFER)
1574+
goto err_free;
1575+
if (err)
1576+
goto err_log;
15821577

1583-
/*
1584-
* If we have reason to believe the IOMMU driver missed the initial
1585-
* iommu_probe_device() call for dev, replay it to get things in order.
1586-
*/
1587-
if (!err && dev->bus)
1588-
err = iommu_probe_device(dev);
1589-
1590-
/* Ignore all other errors apart from EPROBE_DEFER */
1591-
if (err == -EPROBE_DEFER) {
1592-
return ERR_PTR(err);
1593-
} else if (err) {
1594-
dev_dbg(dev, "Adding to IOMMU failed: %d\n", err);
1595-
return NULL;
1578+
err = iommu_probe_device_fwspec(dev, fwspec);
1579+
if (err) {
1580+
/*
1581+
* Ownership for fwspec always passes into
1582+
* iommu_probe_device_fwspec()
1583+
*/
1584+
fwspec = NULL;
1585+
goto err_log;
15961586
}
1597-
return acpi_iommu_fwspec_ops(dev);
1587+
1588+
err_log:
1589+
dev_dbg(dev, "Adding to IOMMU failed: %d\n", err);
1590+
err_free:
1591+
iommu_fwspec_dealloc(fwspec);
1592+
return err;
15981593
}
15991594

16001595
#else /* !CONFIG_IOMMU_API */
16011596

1602-
int acpi_iommu_fwspec_init(struct device *dev, u32 id,
1603-
struct fwnode_handle *fwnode,
1604-
const struct iommu_ops *ops)
1597+
int acpi_iommu_fwspec_init(struct iommu_fwspec *fwspec, struct device *dev,
1598+
u32 id, struct fwnode_handle *fwnode,
1599+
bool iommu_driver_available)
16051600
{
16061601
return -ENODEV;
16071602
}
16081603

1609-
static const struct iommu_ops *acpi_iommu_configure_id(struct device *dev,
1610-
const u32 *id_in)
1604+
static int acpi_iommu_configure_id(struct device *dev, const u32 *id_in)
16111605
{
1612-
return NULL;
1606+
return -ENODEV;
16131607
}
16141608

16151609
#endif /* !CONFIG_IOMMU_API */
@@ -1623,7 +1617,7 @@ static const struct iommu_ops *acpi_iommu_configure_id(struct device *dev,
16231617
int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
16241618
const u32 *input_id)
16251619
{
1626-
const struct iommu_ops *iommu;
1620+
int ret;
16271621

16281622
if (attr == DEV_DMA_NOT_SUPPORTED) {
16291623
set_dma_ops(dev, &dma_dummy_ops);
@@ -1632,12 +1626,16 @@ int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
16321626

16331627
acpi_arch_dma_setup(dev);
16341628

1635-
iommu = acpi_iommu_configure_id(dev, input_id);
1636-
if (PTR_ERR(iommu) == -EPROBE_DEFER)
1629+
ret = acpi_iommu_configure_id(dev, input_id);
1630+
if (ret == -EPROBE_DEFER)
16371631
return -EPROBE_DEFER;
16381632

1639-
arch_setup_dma_ops(dev, 0, U64_MAX,
1640-
iommu, attr == DEV_DMA_COHERENT);
1633+
/*
1634+
* Historically this routine doesn't fail driver probing due to errors
1635+
* in acpi_iommu_configure_id()
1636+
*/
1637+
1638+
arch_setup_dma_ops(dev, 0, U64_MAX, attr == DEV_DMA_COHERENT);
16411639

16421640
return 0;
16431641
}

0 commit comments

Comments
 (0)