Skip to contentSkip to conversation

pci_set_dma_mask() + doc :)

RFC In review Zach Brown 2 participants 2 messages Mar 2, 2001

Subsystems (2)
lore
Share & tools
lore

Zach Brown

author
#0 lore raw

RFC 1/1 pci_set_dma_mask() + doc :)

please feel free to flame or apply, I'm not sure I'm really fond of the code example..

- z

include/linux/pci.h renamed from include/linux/pci.h.dmasup +1 -0
@@ -527,6 +527,7 @@
 
 int pci_enable_device(struct pci_dev *dev);
 void pci_set_master(struct pci_dev *dev);
+int pci_set_dma_mask(struct pci_dev *dev, dma_addr_t mask);
 int pci_set_power_state(struct pci_dev *dev, int state);
 int pci_assign_resource(struct pci_dev *dev, int i);
 
include/asm-i386/pci.h renamed from include/asm-i386/pci.h.dmasup +8 -0
@@ -152,6 +152,14 @@
  */
 extern inline int pci_dma_supported(struct pci_dev *hwdev, dma_addr_t mask)
 {
+        /*
+         * we fall back to GFP_DMA when the mask isn't all 1s,
+         * so we can't guarantee allocations that must be
+         * within a tighter range than GFP_DMA..
+         */
+        if(mask < 0x00ffffff)
+                return 0;
+
 	return 1;
 }
 
drivers/pci/pci.c renamed from drivers/pci/pci.c.dmasup +13 -0
@@ -518,6 +518,18 @@
 	pcibios_set_master(dev);
 }
 
+int
+pci_set_dma_mask(struct pci_dev *dev, dma_addr_t mask)
+{
+    if(! pci_dma_supported(dev, mask))
+        return -EIO;
+
+    dev->dma_mask = mask;
+
+    return 0;
+}
+    
+
 /*
  * Translate the low bits of the PCI base
  * to the resource type
@@ -1206,6 +1218,7 @@
 EXPORT_SYMBOL(pci_find_slot);
 EXPORT_SYMBOL(pci_find_subsys);
 EXPORT_SYMBOL(pci_set_master);
+EXPORT_SYMBOL(pci_set_dma_mask);
 EXPORT_SYMBOL(pci_set_power_state);
 EXPORT_SYMBOL(pci_assign_resource);
 EXPORT_SYMBOL(pci_register_driver);
Documentation/DMA-mapping.txt renamed from Documentation/DMA-mapping.txt.dmasup +26 -3
@@ -71,12 +71,35 @@
 	if (! pci_dma_supported(pdev, 0x00ffffff))
 		goto ignore_this_device;
 
+When DMA is possible for a given mask, the PCI layer must be informed of the
+mask for later allocation operations on the device.  This is achieved by
+setting the dma_mask member of the pci_dev structure, like so:
+
+#define MY_HW_DMA_MASK 0x00ffffff
+
+	if (! pci_dma_supported(pdev, MY_HW_DMA_MASK))
+		goto ignore_this_device;
+
+	pdev->dma_mask = MY_HW_DMA_MASK;
+
+A helper function is provided which performs this common code sequence:
+
+	int pci_set_dma_mask(struct pci_dev *pdev, dma_addr_t device_mask)
+
+Unlike pci_dma_supported(), this returns -EIO when the PCI layer will not be
+able to DMA with addresses restricted by that mask, and returns 0 when DMA
+transfers are possible.  If the call succeeds, the dma_mask will have been
+updated so that your driver need not worry about it.
+
 There is a case which we are aware of at this time, which is worth
 mentioning in this documentation.  If your device supports multiple
 functions (for example a sound card provides playback and record
 functions) and the various different functions have _different_
 DMA addressing limitations, you may wish to probe each mask and
-only provide the functionality which the machine can handle.
+only provide the functionality which the machine can handle.  It
+is important that the last call to pci_set_dma_mask() be for the 
+most specific mask.
+
 Here is pseudo-code showing how this might be done:
 
 	#define PLAYBACK_ADDRESS_BITS	0xffffffff
@@ -86,14 +109,14 @@
 	struct pci_dev *pdev;
 
 	...
-	if (pci_dma_supported(pdev, PLAYBACK_ADDRESS_BITS)) {
+	if (pci_set_dma_mask(pdev, PLAYBACK_ADDRESS_BITS)) {
 		card->playback_enabled = 1;
 	} else {
 		card->playback_enabled = 0;
 		printk(KERN_WARN "%s: Playback disabled due to DMA limitations.\n",
 		       card->name);
 	}
-	if (pci_dma_supported(pdev, RECORD_ADDRESS_BITS)) {
+	if (pci_set_dma_mask(pdev, RECORD_ADDRESS_BITS)) {
 		card->record_enabled = 1;
 	} else {
 		card->record_enabled = 0;
#1 lore raw
Quoted 2 lines · Zach Brown

please feel free to flame or apply, I'm not sure I'm really fond of the code example..

Seems fine to me.

Later,
David S. Miller
[email protected]