aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2015-11-06 19:30:10 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2015-11-06 19:30:10 -0500
commitf2115faaf0df42623638dfbfc5bdaab6ef7375ab (patch)
treef8bbd5a1ad3fbcb0b60e455d0dcf29a9fc25602c
parent0d51ce9ca1116e8f4dc87cb51db8dd250327e9bb (diff)
parent29dbe1f0af88b4162d2b57e790db7a51ab061f35 (diff)
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
-rw-r--r--drivers/acpi/acpi_platform.c7
-rw-r--r--drivers/acpi/glue.c8
-rw-r--r--drivers/acpi/scan.c42
-rw-r--r--drivers/base/property.c32
-rw-r--r--drivers/crypto/ccp/ccp-platform.c15
-rw-r--r--drivers/net/ethernet/amd/xgbe/xgbe-main.c8
-rw-r--r--drivers/of/of_pci.c20
-rw-r--r--drivers/pci/probe.c32
-rw-r--r--include/acpi/acpi_bus.h36
-rw-r--r--include/linux/acpi.h7
-rw-r--r--include/linux/of_pci.h3
-rw-r--r--include/linux/property.h10
12 files changed, 144 insertions, 76 deletions
diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c
index 06a67d5f2846..296b7a14893a 100644
--- a/drivers/acpi/acpi_platform.c
+++ b/drivers/acpi/acpi_platform.c
@@ -103,7 +103,12 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev)
103 pdevinfo.res = resources; 103 pdevinfo.res = resources;
104 pdevinfo.num_res = count; 104 pdevinfo.num_res = count;
105 pdevinfo.fwnode = acpi_fwnode_handle(adev); 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 pdev = platform_device_register_full(&pdevinfo); 112 pdev = platform_device_register_full(&pdevinfo);
108 if (IS_ERR(pdev)) 113 if (IS_ERR(pdev))
109 dev_err(&adev->dev, "platform device creation failed: %ld\n", 114 dev_err(&adev->dev, "platform device creation failed: %ld\n",
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index 1470ae4f98c0..5ea5dc219f56 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -168,7 +168,7 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
168 struct list_head *physnode_list; 168 struct list_head *physnode_list;
169 unsigned int node_id; 169 unsigned int node_id;
170 int retval = -EINVAL; 170 int retval = -EINVAL;
171 bool coherent; 171 enum dev_dma_attr attr;
172 172
173 if (has_acpi_companion(dev)) { 173 if (has_acpi_companion(dev)) {
174 if (acpi_dev) { 174 if (acpi_dev) {
@@ -225,8 +225,10 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
225 if (!has_acpi_companion(dev)) 225 if (!has_acpi_companion(dev))
226 ACPI_COMPANION_SET(dev, acpi_dev); 226 ACPI_COMPANION_SET(dev, acpi_dev);
227 227
228 if (acpi_check_dma(acpi_dev, &coherent)) 228 attr = acpi_get_dma_attr(acpi_dev);
229 arch_setup_dma_ops(dev, 0, 0, NULL, coherent); 229 if (attr != DEV_DMA_NOT_SUPPORTED)
230 arch_setup_dma_ops(dev, 0, 0, NULL,
231 attr == DEV_DMA_COHERENT);
230 232
231 acpi_physnode_link_name(physical_node_name, node_id); 233 acpi_physnode_link_name(physical_node_name, node_id);
232 retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj, 234 retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index daf9fc8329e6..78d5f02a073b 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1308,6 +1308,48 @@ void acpi_free_pnp_ids(struct acpi_device_pnp *pnp)
1308 kfree(pnp->unique_id); 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 */
1317bool 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 */
1342enum 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
1311static void acpi_init_coherency(struct acpi_device *adev) 1353static void acpi_init_coherency(struct acpi_device *adev)
1312{ 1354{
1313 unsigned long long cca = 0; 1355 unsigned long long cca = 0;
diff --git a/drivers/base/property.c b/drivers/base/property.c
index de40623bbd8a..1325ff225cc4 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -598,18 +598,34 @@ unsigned int device_get_child_node_count(struct device *dev)
598} 598}
599EXPORT_SYMBOL_GPL(device_get_child_node_count); 599EXPORT_SYMBOL_GPL(device_get_child_node_count);
600 600
601bool device_dma_is_coherent(struct device *dev) 601bool device_dma_supported(struct device *dev)
602{ 602{
603 bool coherent = false; 603 /* For DT, this is always supported.
604 604 * For ACPI, this depends on CCA, which
605 * is determined by the acpi_dma_supported().
606 */
605 if (IS_ENABLED(CONFIG_OF) && dev->of_node) 607 if (IS_ENABLED(CONFIG_OF) && dev->of_node)
606 coherent = of_dma_is_coherent(dev->of_node); 608 return true;
607 else 609
608 acpi_check_dma(ACPI_COMPANION(dev), &coherent); 610 return acpi_dma_supported(ACPI_COMPANION(dev));
611}
612EXPORT_SYMBOL_GPL(device_dma_supported);
609 613
610 return coherent; 614enum 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;
611} 627}
612EXPORT_SYMBOL_GPL(device_dma_is_coherent); 628EXPORT_SYMBOL_GPL(device_get_dma_attr);
613 629
614/** 630/**
615 * device_get_phy_mode - Get phy mode for given device 631 * device_get_phy_mode - Get phy mode for given device
diff --git a/drivers/crypto/ccp/ccp-platform.c b/drivers/crypto/ccp/ccp-platform.c
index 8b923b7e9389..01b50cb4c982 100644
--- a/drivers/crypto/ccp/ccp-platform.c
+++ b/drivers/crypto/ccp/ccp-platform.c
@@ -94,6 +94,7 @@ static int ccp_platform_probe(struct platform_device *pdev)
94 struct ccp_device *ccp; 94 struct ccp_device *ccp;
95 struct ccp_platform *ccp_platform; 95 struct ccp_platform *ccp_platform;
96 struct device *dev = &pdev->dev; 96 struct device *dev = &pdev->dev;
97 enum dev_dma_attr attr;
97 struct resource *ior; 98 struct resource *ior;
98 int ret; 99 int ret;
99 100
@@ -118,18 +119,24 @@ static int ccp_platform_probe(struct platform_device *pdev)
118 } 119 }
119 ccp->io_regs = ccp->io_map; 120 ccp->io_regs = ccp->io_map;
120 121
121 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48)); 122 attr = device_get_dma_attr(dev);
122 if (ret) { 123 if (attr == DEV_DMA_NOT_SUPPORTED) {
123 dev_err(dev, "dma_set_mask_and_coherent failed (%d)\n", ret); 124 dev_err(dev, "DMA is not supported");
124 goto e_err; 125 goto e_err;
125 } 126 }
126 127
127 ccp_platform->coherent = device_dma_is_coherent(ccp->dev); 128 ccp_platform->coherent = (attr == DEV_DMA_COHERENT);
128 if (ccp_platform->coherent) 129 if (ccp_platform->coherent)
129 ccp->axcache = CACHE_WB_NO_ALLOC; 130 ccp->axcache = CACHE_WB_NO_ALLOC;
130 else 131 else
131 ccp->axcache = CACHE_NONE; 132 ccp->axcache = CACHE_NONE;
132 133
134 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48));
135 if (ret) {
136 dev_err(dev, "dma_set_mask_and_coherent failed (%d)\n", ret);
137 goto e_err;
138 }
139
133 dev_set_drvdata(dev, ccp); 140 dev_set_drvdata(dev, ccp);
134 141
135 ret = ccp_init(ccp); 142 ret = ccp_init(ccp);
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
index 7dd893331785..618d952c2984 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
@@ -342,6 +342,7 @@ static int xgbe_probe(struct platform_device *pdev)
342 struct resource *res; 342 struct resource *res;
343 const char *phy_mode; 343 const char *phy_mode;
344 unsigned int i, phy_memnum, phy_irqnum; 344 unsigned int i, phy_memnum, phy_irqnum;
345 enum dev_dma_attr attr;
345 int ret; 346 int ret;
346 347
347 DBGPR("--> xgbe_probe\n"); 348 DBGPR("--> xgbe_probe\n");
@@ -609,7 +610,12 @@ static int xgbe_probe(struct platform_device *pdev)
609 goto err_io; 610 goto err_io;
610 611
611 /* Set the DMA coherency values */ 612 /* Set the DMA coherency values */
612 pdata->coherent = device_dma_is_coherent(pdata->dev); 613 attr = device_get_dma_attr(dev);
614 if (attr == DEV_DMA_NOT_SUPPORTED) {
615 dev_err(dev, "DMA is not supported");
616 goto err_io;
617 }
618 pdata->coherent = (attr == DEV_DMA_COHERENT);
613 if (pdata->coherent) { 619 if (pdata->coherent) {
614 pdata->axdomain = XGBE_DMA_OS_AXDOMAIN; 620 pdata->axdomain = XGBE_DMA_OS_AXDOMAIN;
615 pdata->arcache = XGBE_DMA_OS_ARCACHE; 621 pdata->arcache = XGBE_DMA_OS_ARCACHE;
diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
index 5751dc5b6494..b66ee4ebf650 100644
--- a/drivers/of/of_pci.c
+++ b/drivers/of/of_pci.c
@@ -117,26 +117,6 @@ int of_get_pci_domain_nr(struct device_node *node)
117} 117}
118EXPORT_SYMBOL_GPL(of_get_pci_domain_nr); 118EXPORT_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 */
127void 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}
138EXPORT_SYMBOL_GPL(of_pci_dma_configure);
139
140#if defined(CONFIG_OF_ADDRESS) 120#if defined(CONFIG_OF_ADDRESS)
141/** 121/**
142 * of_pci_get_host_bridge_resources - Parse PCI host bridge resources from DT 122 * of_pci_get_host_bridge_resources - Parse PCI host bridge resources from DT
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index f14a970b61fa..0dac52633f01 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -6,12 +6,14 @@
6#include <linux/delay.h> 6#include <linux/delay.h>
7#include <linux/init.h> 7#include <linux/init.h>
8#include <linux/pci.h> 8#include <linux/pci.h>
9#include <linux/of_device.h>
9#include <linux/of_pci.h> 10#include <linux/of_pci.h>
10#include <linux/pci_hotplug.h> 11#include <linux/pci_hotplug.h>
11#include <linux/slab.h> 12#include <linux/slab.h>
12#include <linux/module.h> 13#include <linux/module.h>
13#include <linux/cpumask.h> 14#include <linux/cpumask.h>
14#include <linux/pci-aspm.h> 15#include <linux/pci-aspm.h>
16#include <linux/acpi.h>
15#include <asm-generic/pci-bridge.h> 17#include <asm-generic/pci-bridge.h>
16#include "pci.h" 18#include "pci.h"
17 19
@@ -1666,6 +1668,34 @@ static void pci_set_msi_domain(struct pci_dev *dev)
1666 dev_set_msi_domain(&dev->dev, d); 1668 dev_set_msi_domain(&dev->dev, d);
1667} 1669}
1668 1670
1671/**
1672 * pci_dma_configure - Setup DMA configuration
1673 * @dev: ptr to pci_dev struct of the PCI device
1674 *
1675 * Function to update PCI devices's DMA configuration using the same
1676 * info from the OF node or ACPI node of host bridge's parent (if any).
1677 */
1678static void pci_dma_configure(struct pci_dev *dev)
1679{
1680 struct device *bridge = pci_get_host_bridge_device(dev);
1681
1682 if (IS_ENABLED(CONFIG_OF) && dev->dev.of_node) {
1683 if (bridge->parent)
1684 of_dma_configure(&dev->dev, bridge->parent->of_node);
1685 } else if (has_acpi_companion(bridge)) {
1686 struct acpi_device *adev = to_acpi_device_node(bridge->fwnode);
1687 enum dev_dma_attr attr = acpi_get_dma_attr(adev);
1688
1689 if (attr == DEV_DMA_NOT_SUPPORTED)
1690 dev_warn(&dev->dev, "DMA not supported.\n");
1691 else
1692 arch_setup_dma_ops(&dev->dev, 0, 0, NULL,
1693 attr == DEV_DMA_COHERENT);
1694 }
1695
1696 pci_put_host_bridge_device(bridge);
1697}
1698
1669void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) 1699void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
1670{ 1700{
1671 int ret; 1701 int ret;
@@ -1679,7 +1709,7 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
1679 dev->dev.dma_mask = &dev->dma_mask; 1709 dev->dev.dma_mask = &dev->dma_mask;
1680 dev->dev.dma_parms = &dev->dma_parms; 1710 dev->dev.dma_parms = &dev->dma_parms;
1681 dev->dev.coherent_dma_mask = 0xffffffffull; 1711 dev->dev.coherent_dma_mask = 0xffffffffull;
1682 of_pci_dma_configure(dev); 1712 pci_dma_configure(dev);
1683 1713
1684 pci_set_dma_max_seg_size(dev, 65536); 1714 pci_set_dma_max_seg_size(dev, 65536);
1685 pci_set_dma_seg_boundary(dev, 0xffffffff); 1715 pci_set_dma_seg_boundary(dev, 0xffffffff);
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index d11eff8a4efe..ad0a5ff3d4cd 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -390,39 +390,6 @@ struct acpi_data_node {
390 struct completion kobj_done; 390 struct completion kobj_done;
391}; 391};
392 392
393static 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
426static inline bool is_acpi_node(struct fwnode_handle *fwnode) 393static inline bool is_acpi_node(struct fwnode_handle *fwnode)
427{ 394{
428 return fwnode && (fwnode->type == FWNODE_ACPI 395 return fwnode && (fwnode->type == FWNODE_ACPI
@@ -595,6 +562,9 @@ struct acpi_pci_root {
595 562
596/* helper */ 563/* helper */
597 564
565bool acpi_dma_supported(struct acpi_device *adev);
566enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev);
567
598struct acpi_device *acpi_find_child_device(struct acpi_device *parent, 568struct acpi_device *acpi_find_child_device(struct acpi_device *parent,
599 u64 address, bool check_children); 569 u64 address, bool check_children);
600int acpi_is_root_bridge(acpi_handle); 570int acpi_is_root_bridge(acpi_handle);
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index d6f95bb481d4..b729eb3f1137 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -596,11 +596,16 @@ static inline int acpi_device_modalias(struct device *dev,
596 return -ENODEV; 596 return -ENODEV;
597} 597}
598 598
599static inline bool acpi_check_dma(struct acpi_device *adev, bool *coherent) 599static inline bool acpi_dma_supported(struct acpi_device *adev)
600{ 600{
601 return false; 601 return false;
602} 602}
603 603
604static inline enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev)
605{
606 return DEV_DMA_NOT_SUPPORTED;
607}
608
604#define ACPI_PTR(_ptr) (NULL) 609#define ACPI_PTR(_ptr) (NULL)
605 610
606#endif /* !CONFIG_ACPI */ 611#endif /* !CONFIG_ACPI */
diff --git a/include/linux/of_pci.h b/include/linux/of_pci.h
index 29fd3fe1c035..ce0e5abeb454 100644
--- a/include/linux/of_pci.h
+++ b/include/linux/of_pci.h
@@ -16,7 +16,6 @@ int of_pci_get_devfn(struct device_node *np);
16int of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin); 16int of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin);
17int of_pci_parse_bus_range(struct device_node *node, struct resource *res); 17int of_pci_parse_bus_range(struct device_node *node, struct resource *res);
18int of_get_pci_domain_nr(struct device_node *node); 18int of_get_pci_domain_nr(struct device_node *node);
19void of_pci_dma_configure(struct pci_dev *pci_dev);
20#else 19#else
21static inline int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq) 20static inline int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq)
22{ 21{
@@ -51,8 +50,6 @@ of_get_pci_domain_nr(struct device_node *node)
51{ 50{
52 return -1; 51 return -1;
53} 52}
54
55static inline void of_pci_dma_configure(struct pci_dev *pci_dev) { }
56#endif 53#endif
57 54
58#if defined(CONFIG_OF_ADDRESS) 55#if defined(CONFIG_OF_ADDRESS)
diff --git a/include/linux/property.h b/include/linux/property.h
index 463de52fe891..0a3705a7c9f2 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -27,6 +27,12 @@ enum dev_prop_type {
27 DEV_PROP_MAX, 27 DEV_PROP_MAX,
28}; 28};
29 29
30enum dev_dma_attr {
31 DEV_DMA_NOT_SUPPORTED,
32 DEV_DMA_NON_COHERENT,
33 DEV_DMA_COHERENT,
34};
35
30bool device_property_present(struct device *dev, const char *propname); 36bool device_property_present(struct device *dev, const char *propname);
31int device_property_read_u8_array(struct device *dev, const char *propname, 37int device_property_read_u8_array(struct device *dev, const char *propname,
32 u8 *val, size_t nval); 38 u8 *val, size_t nval);
@@ -168,7 +174,9 @@ struct property_set {
168 174
169void device_add_property_set(struct device *dev, struct property_set *pset); 175void device_add_property_set(struct device *dev, struct property_set *pset);
170 176
171bool device_dma_is_coherent(struct device *dev); 177bool device_dma_supported(struct device *dev);
178
179enum dev_dma_attr device_get_dma_attr(struct device *dev);
172 180
173int device_get_phy_mode(struct device *dev); 181int device_get_phy_mode(struct device *dev);
174 182