pci_dma_set_mask()
This patch really has two parts. Most of it adds a helper function that does the
if(pci_dma_supported()) { ->dma_mask = mask }code path. I was using the api today and didn't realize that I had to
set the mask myself, I assumed the _supported call would do it. If
people prefer the struct setting api, thats fine with me :)
It also seems goofy that pci_dma_supported() unconditionally return true on x86. If a device needs a mask smaller than GFP_DMA (admitedly probably won't exist in the real world, one hopes), they're going to have troubles because x86 just falls back to GFP_DMA when the mask isn't 0xffffffff..
all totally untested, of course..
Signature · 58 lines
zach
--- linux-2.4.2/include/linux/pci.h.dmasup Wed Feb 28 10:26:14 2001
+++ linux-2.4.2/include/linux/pci.h Wed Feb 28 10:30:12 2001
@@ -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);
--- linux-2.4.2/include/asm-i386/pci.h.dmasup Wed Feb 28 10:19:01 2001
+++ linux-2.4.2/include/asm-i386/pci.h Wed Feb 28 10:25:40 2001
@@ -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;
}
--- linux-2.4.2/drivers/pci/pci.c.dmasup Wed Feb 28 10:26:34 2001
+++ linux-2.4.2/drivers/pci/pci.c Wed Feb 28 10:27:34 2001
@@ -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 0;
+
+ dev->dma_mask = mask;
+
+ return 1;
+}
+
+
/*
* 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);Review
Quoted 10 lines · Zach Brown
(quoted diff) +10
-0+int +pci_set_dma_mask(struct pci_dev *dev, dma_addr_t mask) +{ + if(! pci_dma_supported(dev, mask)) + return 0; + + dev->dma_mask = mask; + + return 1; +}
pci_dma_supported has a boolean return, but the kernel norm is to return zero on success, and -EFOO on error. I like your proposal with the extremely minor nit that I think pci_set_dma_mask should return ENODEV or EIO or something on error, and zero on success.
Jeff
Signature · 3 lines
Jeff Garzik | "You see, in this world there's two kinds of Building 1024 | people, my friend: Those with loaded guns MandrakeSoft | and those who dig. You dig." --Blondie
Quoted 2 lines
pci_dma_supportedhas a boolean return, but the kernel norm is to return zero on success, and-EFOOon error. I like your proposal with the
*nod* I just followed pci_dma_supported().
Quoted 2 lines
extremely minor nit that I think
pci_set_dma_maskshould return ENODEV or EIO or something on error, and zero on success.
I agree, though I'd like to leave the decision up to people who live and breathe this stuff.
please feel free to make minor adjustments and submit :)
- z
Quoted 7 lines · Zach Brown
Quoted 2 lines
extremely minor nit that I think
pci_set_dma_maskshould return ENODEV or EIO or something on error, and zero on success.I agree, though I'd like to leave the decision up to people who live and breathe this stuff.
please feel free to make minor adjustments and submit :)
Jeff/Zach, I agree, I'm fully for such a patch, but please update the documentation! It is the most important part of the patch.
Later,
David S. Miller
[email protected]
Quoted 2 lines · David S. Miller
Jeff/Zach, I agree, I'm fully for such a patch, but please update the documentation! It is the most important part of the patch.
Very good point. I'll add Jeff's error returning and spin some minor docs and resend.
thanks.