Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'acpi-pci'

* acpi-pci:
PCI: ACPI: Add support for PCI device DMA coherency
PCI: OF: Move of_pci_dma_configure() to pci_dma_configure()
of/pci: Fix pci_get_host_bridge_device leak
device property: ACPI: Remove unused DMA APIs
device property: ACPI: Make use of the new DMA Attribute APIs
device property: Adding DMA Attribute APIs for Generic Devices
ACPI: Adding DMA Attribute APIs for ACPI Device
device property: Introducing enum dev_dma_attr
ACPI: Honor ACPI _CCA attribute setting

Conflicts:
drivers/crypto/ccp/ccp-platform.c

+146 -78
+6 -1
drivers/acpi/acpi_platform.c
··· 103 103 pdevinfo.res = resources; 104 104 pdevinfo.num_res = count; 105 105 pdevinfo.fwnode = acpi_fwnode_handle(adev); 106 - pdevinfo.dma_mask = acpi_check_dma(adev, NULL) ? DMA_BIT_MASK(32) : 0; 106 + 107 + if (acpi_dma_supported(adev)) 108 + pdevinfo.dma_mask = DMA_BIT_MASK(32); 109 + else 110 + pdevinfo.dma_mask = 0; 111 + 107 112 pdev = platform_device_register_full(&pdevinfo); 108 113 if (IS_ERR(pdev)) 109 114 dev_err(&adev->dev, "platform device creation failed: %ld\n",
+5 -3
drivers/acpi/glue.c
··· 168 168 struct list_head *physnode_list; 169 169 unsigned int node_id; 170 170 int retval = -EINVAL; 171 - bool coherent; 171 + enum dev_dma_attr attr; 172 172 173 173 if (has_acpi_companion(dev)) { 174 174 if (acpi_dev) { ··· 225 225 if (!has_acpi_companion(dev)) 226 226 ACPI_COMPANION_SET(dev, acpi_dev); 227 227 228 - if (acpi_check_dma(acpi_dev, &coherent)) 229 - arch_setup_dma_ops(dev, 0, 0, NULL, coherent); 228 + attr = acpi_get_dma_attr(acpi_dev); 229 + if (attr != DEV_DMA_NOT_SUPPORTED) 230 + arch_setup_dma_ops(dev, 0, 0, NULL, 231 + attr == DEV_DMA_COHERENT); 230 232 231 233 acpi_physnode_link_name(physical_node_name, node_id); 232 234 retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
+42
drivers/acpi/scan.c
··· 1308 1308 kfree(pnp->unique_id); 1309 1309 } 1310 1310 1311 + /** 1312 + * acpi_dma_supported - Check DMA support for the specified device. 1313 + * @adev: The pointer to acpi device 1314 + * 1315 + * Return false if DMA is not supported. Otherwise, return true 1316 + */ 1317 + bool acpi_dma_supported(struct acpi_device *adev) 1318 + { 1319 + if (!adev) 1320 + return false; 1321 + 1322 + if (adev->flags.cca_seen) 1323 + return true; 1324 + 1325 + /* 1326 + * Per ACPI 6.0 sec 6.2.17, assume devices can do cache-coherent 1327 + * DMA on "Intel platforms". Presumably that includes all x86 and 1328 + * ia64, and other arches will set CONFIG_ACPI_CCA_REQUIRED=y. 1329 + */ 1330 + if (!IS_ENABLED(CONFIG_ACPI_CCA_REQUIRED)) 1331 + return true; 1332 + 1333 + return false; 1334 + } 1335 + 1336 + /** 1337 + * acpi_get_dma_attr - Check the supported DMA attr for the specified device. 1338 + * @adev: The pointer to acpi device 1339 + * 1340 + * Return enum dev_dma_attr. 1341 + */ 1342 + enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev) 1343 + { 1344 + if (!acpi_dma_supported(adev)) 1345 + return DEV_DMA_NOT_SUPPORTED; 1346 + 1347 + if (adev->flags.coherent_dma) 1348 + return DEV_DMA_COHERENT; 1349 + else 1350 + return DEV_DMA_NON_COHERENT; 1351 + } 1352 + 1311 1353 static void acpi_init_coherency(struct acpi_device *adev) 1312 1354 { 1313 1355 unsigned long long cca = 0;
+24 -8
drivers/base/property.c
··· 598 598 } 599 599 EXPORT_SYMBOL_GPL(device_get_child_node_count); 600 600 601 - bool device_dma_is_coherent(struct device *dev) 601 + bool device_dma_supported(struct device *dev) 602 602 { 603 - bool coherent = false; 604 - 603 + /* For DT, this is always supported. 604 + * For ACPI, this depends on CCA, which 605 + * is determined by the acpi_dma_supported(). 606 + */ 605 607 if (IS_ENABLED(CONFIG_OF) && dev->of_node) 606 - coherent = of_dma_is_coherent(dev->of_node); 607 - else 608 - acpi_check_dma(ACPI_COMPANION(dev), &coherent); 608 + return true; 609 609 610 - return coherent; 610 + return acpi_dma_supported(ACPI_COMPANION(dev)); 611 611 } 612 - EXPORT_SYMBOL_GPL(device_dma_is_coherent); 612 + EXPORT_SYMBOL_GPL(device_dma_supported); 613 + 614 + enum dev_dma_attr device_get_dma_attr(struct device *dev) 615 + { 616 + enum dev_dma_attr attr = DEV_DMA_NOT_SUPPORTED; 617 + 618 + if (IS_ENABLED(CONFIG_OF) && dev->of_node) { 619 + if (of_dma_is_coherent(dev->of_node)) 620 + attr = DEV_DMA_COHERENT; 621 + else 622 + attr = DEV_DMA_NON_COHERENT; 623 + } else 624 + attr = acpi_get_dma_attr(ACPI_COMPANION(dev)); 625 + 626 + return attr; 627 + } 628 + EXPORT_SYMBOL_GPL(device_get_dma_attr); 613 629 614 630 /** 615 631 * device_get_phy_mode - Get phy mode for given device
+13 -6
drivers/crypto/ccp/ccp-platform.c
··· 94 94 struct ccp_device *ccp; 95 95 struct ccp_platform *ccp_platform; 96 96 struct device *dev = &pdev->dev; 97 + enum dev_dma_attr attr; 97 98 struct resource *ior; 98 99 int ret; 99 100 ··· 119 118 } 120 119 ccp->io_regs = ccp->io_map; 121 120 121 + attr = device_get_dma_attr(dev); 122 + if (attr == DEV_DMA_NOT_SUPPORTED) { 123 + dev_err(dev, "DMA is not supported"); 124 + goto e_err; 125 + } 126 + 127 + ccp_platform->coherent = (attr == DEV_DMA_COHERENT); 128 + if (ccp_platform->coherent) 129 + ccp->axcache = CACHE_WB_NO_ALLOC; 130 + else 131 + ccp->axcache = CACHE_NONE; 132 + 122 133 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48)); 123 134 if (ret) { 124 135 dev_err(dev, "dma_set_mask_and_coherent failed (%d)\n", ret); 125 136 goto e_err; 126 137 } 127 - 128 - ccp_platform->coherent = device_dma_is_coherent(ccp->dev); 129 - if (ccp_platform->coherent) 130 - ccp->axcache = CACHE_WB_NO_ALLOC; 131 - else 132 - ccp->axcache = CACHE_NONE; 133 138 134 139 dev_set_drvdata(dev, ccp); 135 140
+7 -1
drivers/net/ethernet/amd/xgbe/xgbe-main.c
··· 342 342 struct resource *res; 343 343 const char *phy_mode; 344 344 unsigned int i, phy_memnum, phy_irqnum; 345 + enum dev_dma_attr attr; 345 346 int ret; 346 347 347 348 DBGPR("--> xgbe_probe\n"); ··· 610 609 goto err_io; 611 610 612 611 /* Set the DMA coherency values */ 613 - pdata->coherent = device_dma_is_coherent(pdata->dev); 612 + attr = device_get_dma_attr(dev); 613 + if (attr == DEV_DMA_NOT_SUPPORTED) { 614 + dev_err(dev, "DMA is not supported"); 615 + goto err_io; 616 + } 617 + pdata->coherent = (attr == DEV_DMA_COHERENT); 614 618 if (pdata->coherent) { 615 619 pdata->axdomain = XGBE_DMA_OS_AXDOMAIN; 616 620 pdata->arcache = XGBE_DMA_OS_ARCACHE;
-20
drivers/of/of_pci.c
··· 117 117 } 118 118 EXPORT_SYMBOL_GPL(of_get_pci_domain_nr); 119 119 120 - /** 121 - * of_pci_dma_configure - Setup DMA configuration 122 - * @dev: ptr to pci_dev struct of the PCI device 123 - * 124 - * Function to update PCI devices's DMA configuration using the same 125 - * info from the OF node of host bridge's parent (if any). 126 - */ 127 - void of_pci_dma_configure(struct pci_dev *pci_dev) 128 - { 129 - struct device *dev = &pci_dev->dev; 130 - struct device *bridge = pci_get_host_bridge_device(pci_dev); 131 - 132 - if (!bridge->parent) 133 - return; 134 - 135 - of_dma_configure(dev, bridge->parent->of_node); 136 - pci_put_host_bridge_device(bridge); 137 - } 138 - EXPORT_SYMBOL_GPL(of_pci_dma_configure); 139 - 140 120 #if defined(CONFIG_OF_ADDRESS) 141 121 /** 142 122 * of_pci_get_host_bridge_resources - Parse PCI host bridge resources from DT
+31 -1
drivers/pci/probe.c
··· 6 6 #include <linux/delay.h> 7 7 #include <linux/init.h> 8 8 #include <linux/pci.h> 9 + #include <linux/of_device.h> 9 10 #include <linux/of_pci.h> 10 11 #include <linux/pci_hotplug.h> 11 12 #include <linux/slab.h> 12 13 #include <linux/module.h> 13 14 #include <linux/cpumask.h> 14 15 #include <linux/pci-aspm.h> 16 + #include <linux/acpi.h> 15 17 #include <asm-generic/pci-bridge.h> 16 18 #include "pci.h" 17 19 ··· 1668 1666 dev_set_msi_domain(&dev->dev, d); 1669 1667 } 1670 1668 1669 + /** 1670 + * pci_dma_configure - Setup DMA configuration 1671 + * @dev: ptr to pci_dev struct of the PCI device 1672 + * 1673 + * Function to update PCI devices's DMA configuration using the same 1674 + * info from the OF node or ACPI node of host bridge's parent (if any). 1675 + */ 1676 + static void pci_dma_configure(struct pci_dev *dev) 1677 + { 1678 + struct device *bridge = pci_get_host_bridge_device(dev); 1679 + 1680 + if (IS_ENABLED(CONFIG_OF) && dev->dev.of_node) { 1681 + if (bridge->parent) 1682 + of_dma_configure(&dev->dev, bridge->parent->of_node); 1683 + } else if (has_acpi_companion(bridge)) { 1684 + struct acpi_device *adev = to_acpi_device_node(bridge->fwnode); 1685 + enum dev_dma_attr attr = acpi_get_dma_attr(adev); 1686 + 1687 + if (attr == DEV_DMA_NOT_SUPPORTED) 1688 + dev_warn(&dev->dev, "DMA not supported.\n"); 1689 + else 1690 + arch_setup_dma_ops(&dev->dev, 0, 0, NULL, 1691 + attr == DEV_DMA_COHERENT); 1692 + } 1693 + 1694 + pci_put_host_bridge_device(bridge); 1695 + } 1696 + 1671 1697 void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) 1672 1698 { 1673 1699 int ret; ··· 1709 1679 dev->dev.dma_mask = &dev->dma_mask; 1710 1680 dev->dev.dma_parms = &dev->dma_parms; 1711 1681 dev->dev.coherent_dma_mask = 0xffffffffull; 1712 - of_pci_dma_configure(dev); 1682 + pci_dma_configure(dev); 1713 1683 1714 1684 pci_set_dma_max_seg_size(dev, 65536); 1715 1685 pci_set_dma_seg_boundary(dev, 0xffffffff);
+3 -33
include/acpi/acpi_bus.h
··· 390 390 struct completion kobj_done; 391 391 }; 392 392 393 - static inline bool acpi_check_dma(struct acpi_device *adev, bool *coherent) 394 - { 395 - bool ret = false; 396 - 397 - if (!adev) 398 - return ret; 399 - 400 - /** 401 - * Currently, we only support _CCA=1 (i.e. coherent_dma=1) 402 - * This should be equivalent to specifyig dma-coherent for 403 - * a device in OF. 404 - * 405 - * For the case when _CCA=0 (i.e. coherent_dma=0 && cca_seen=1), 406 - * There are two cases: 407 - * case 1. Do not support and disable DMA. 408 - * case 2. Support but rely on arch-specific cache maintenance for 409 - * non-coherence DMA operations. 410 - * Currently, we implement case 1 above. 411 - * 412 - * For the case when _CCA is missing (i.e. cca_seen=0) and 413 - * platform specifies ACPI_CCA_REQUIRED, we do not support DMA, 414 - * and fallback to arch-specific default handling. 415 - * 416 - * See acpi_init_coherency() for more info. 417 - */ 418 - if (adev->flags.coherent_dma) { 419 - ret = true; 420 - if (coherent) 421 - *coherent = adev->flags.coherent_dma; 422 - } 423 - return ret; 424 - } 425 - 426 393 static inline bool is_acpi_node(struct fwnode_handle *fwnode) 427 394 { 428 395 return fwnode && (fwnode->type == FWNODE_ACPI ··· 561 594 }; 562 595 563 596 /* helper */ 597 + 598 + bool acpi_dma_supported(struct acpi_device *adev); 599 + enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev); 564 600 565 601 struct acpi_device *acpi_find_child_device(struct acpi_device *parent, 566 602 u64 address, bool check_children);
+6 -1
include/linux/acpi.h
··· 596 596 return -ENODEV; 597 597 } 598 598 599 - static inline bool acpi_check_dma(struct acpi_device *adev, bool *coherent) 599 + static inline bool acpi_dma_supported(struct acpi_device *adev) 600 600 { 601 601 return false; 602 + } 603 + 604 + static inline enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev) 605 + { 606 + return DEV_DMA_NOT_SUPPORTED; 602 607 } 603 608 604 609 #define ACPI_PTR(_ptr) (NULL)
-3
include/linux/of_pci.h
··· 16 16 int of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin); 17 17 int of_pci_parse_bus_range(struct device_node *node, struct resource *res); 18 18 int of_get_pci_domain_nr(struct device_node *node); 19 - void of_pci_dma_configure(struct pci_dev *pci_dev); 20 19 #else 21 20 static inline int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq) 22 21 { ··· 50 51 { 51 52 return -1; 52 53 } 53 - 54 - static inline void of_pci_dma_configure(struct pci_dev *pci_dev) { } 55 54 #endif 56 55 57 56 #if defined(CONFIG_OF_ADDRESS)
+9 -1
include/linux/property.h
··· 27 27 DEV_PROP_MAX, 28 28 }; 29 29 30 + enum dev_dma_attr { 31 + DEV_DMA_NOT_SUPPORTED, 32 + DEV_DMA_NON_COHERENT, 33 + DEV_DMA_COHERENT, 34 + }; 35 + 30 36 bool device_property_present(struct device *dev, const char *propname); 31 37 int device_property_read_u8_array(struct device *dev, const char *propname, 32 38 u8 *val, size_t nval); ··· 174 168 175 169 void device_add_property_set(struct device *dev, struct property_set *pset); 176 170 177 - bool device_dma_is_coherent(struct device *dev); 171 + bool device_dma_supported(struct device *dev); 172 + 173 + enum dev_dma_attr device_get_dma_attr(struct device *dev); 178 174 179 175 int device_get_phy_mode(struct device *dev); 180 176