sparc32: Added LEON dma_ops
PATCH 1/1 sparc32: Added LEON dma_ops
From: Kristoffer Glembo <[email protected]>
Added leon3_dma_ops and mmu_inval_dma_area.
--- arch/sparc/include/asm/dma-mapping.h | 13 +--- arch/sparc/kernel/ioport.c | 139 +++++++++++++++++++++++++--------- 2 files changed, 103 insertions(+), 49 deletions(-)
arch/sparc/include/asm/dma-mapping.h +1 -12
@@ -51,17 +51,6 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) return (dma_addr = DMA_ERROR_CODE); } -static inline int dma_set_mask (struct device *dev,u64 mask) -{ -#ifdef CONFIG_PCI -if (dev->bus = &pci_bus_type) { -if (!dev->dma_mask || !dma_supported (dev, mask)) -return -EINVAL ; - *dev->dma_mask = mask; -return 0 ; - } -#endif -return -EINVAL ; -} +extern int dma_set_mask (struct device *dev,u64 dma_mask);#endif
arch/sparc/kernel/ioport.c +102 -37
267 lines not on this page · raw message
Signature · 1 line
1.5.4
Quoted 3 lines · Daniel Hellstrom
From: Kristoffer Glembo <[email protected]>
Added
leon3_dma_opsandmmu_inval_dma_area.
Hi Kristoffer.
This patch mixes cleanup with added functionality. I would have preferred that you divided this into several smaller patches.
I am not familiar with the area that your patch touches - but I have tried to give some feedback below.
Sam
Quoted 16 lines
--- arch/sparc/include/asm/dma-mapping.h | 13 +--- arch/sparc/kernel/ioport.c | 139 +++++++++++++++++++++++++--------- 2 files changed, 103 insertions(+), 49 deletions(-)arch/sparc/include/asm/dma-mapping.h +0
-3@@ -51,17 +51,6 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)return (dma_addr =DMA_ERROR_CODE ); } -static inline int dma_set_mask (struct device *dev,u64 mask) -{ -#ifdef CONFIG_PCI
arch/sparc/include/asm/dma-mapping.h static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) · line 54
Quoted 10 lines
arch/sparc/include/asm/dma-mapping.h +1
-9-if (dev->bus = &pci_bus_type) { -if (!dev->dma_mask || !dma_supported (dev, mask)) -return -EINVAL ; - *dev->dma_mask = mask; -return 0 ; - } -#endif -return -EINVAL ; -} +extern int dma_set_mask (struct device *dev,u64 dma_mask);
So dma_set_mask() is moved to ioport.c
arch/sparc/include/asm/dma-mapping.h static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
Quoted 10 lines
arch/sparc/include/asm/dma-mapping.h +9
-0+int dma_set_mask (struct device *dev,u64 dma_mask) +{ +#ifdef CONFIG_PCI +if (dev->bus = &pci_bus_type) +return pci_set_dma_mask (to_pci_dev (dev), dma_mask); +#endif +return -EOPNOTSUPP ; +} +EXPORT_SYMBOL (dma_set_mask);
And it is now an exported symbol - looks OK.
But the new implementation differs from the old implementation.
Grepping for pci_set_dma_mask() turned up this implmentation:
static inline int pci_set_dma_mask(struct pci_dev *dev, u64 mask)
{
return dma_set_mask(&dev->dev, mask);
}It looks like an infinite loop??
Note: This change alone warrant an independent patch.
Quoted 12 lines
#endif
arch/sparc/kernel/ioport.c +0
-3@@ -50,10 +50,15 @@#include <asm/io-unit.h> #include <asm/leon.h> -#ifdef CONFIG_SPARC_LEON -#define mmu_inval_dma_area (p, l) leon_flush_dcache_all() -#else
arch/sparc/kernel/ioport.c line 62
Quoted 10 lines
arch/sparc/kernel/ioport.c +8
-0+#ifndef CONFIG_SPARC_LEON #define mmu_inval_dma_area (p, l)/* Anton pulled it out for 2.4.0-xx */ +#else +static inline void mmu_inval_dma_area (unsigned long va,unsigned long len) +{ +if (!sparc_leon3_snooping_enabled ()) { +leon_flush_dcache_all (); + } +}#endif
This is better than before as we no longer has a double definition. But why do we call mmu_inval_dma_area() wich is empty in SPARC32 build from SBUS code? LEON does not support SBUS only AMBA + PCI IIRC. Hmm - looking at Kconfig LEON supports SBUS too. Is that correct?
arch/sparc/kernel/ioport.c static void *sbus_alloc_coherent(struct device *dev, size_t len, · line 262
Quoted 8 lines
arch/sparc/kernel/ioport.c +1
-1static struct resource *_sparc_find_resource(struct resource *r,@@ -254,7 +259,7 @@ static void *sbus_alloc_coherent(struct device *dev, size_t len, dma_addr_t *dma_addrp, gfp_t gfp) {struct platform_device *op =to_platform_device (dev); -unsigned long len_total = (len +PAGE_SIZE -1 ) &PAGE_MASK ; +unsigned long len_total =PAGE_ALIGN (len);
PAGE_ALIGN is much better than the old version. But again - please do such cleanup in a separate step. If we are going to revert your functional change we do not want to lose such cleanups.
Quoted 9 lines
arch/sparc/kernel/ioport.c +0
-2unsigned long va;struct resource *res;int order;@@ -287,15 +292,19 @@ static void *sbus_alloc_coherent(struct device *dev, size_t len,* XXX That's where sdev would be used. Currently we load * all iommu tables with the same translations. */ -if (mmu_map_dma_area (dev, dma_addrp, va, res->start, len_total) !=0 ) - goto err_noiommu;
arch/sparc/kernel/ioport.c static void *sbus_alloc_coherent(struct device *dev, size_t len, · line 303
Quoted 10 lines
arch/sparc/kernel/ioport.c +9
-1- +#ifdef CONFIG_SPARC_LEON +sparc_mapiorange (0 ,virt_to_phys (va), res->start, len_total); + *dma_addrp =virt_to_phys (va); +#else +if (mmu_map_dma_area (dev, dma_addrp, va, res->start, len_total) !=0 ) { +release_resource (res); + goto err_nova; + } +#endif
I cannot follow why you need this ugly ifdef here. Some comments please.
Quoted 10 lines
arch/sparc/kernel/ioport.c +0
-2res->name = op->dev.of_node->name;return (void *)(unsigned long )res->start; -err_noiommu: -release_resource (res); err_nova:free_pages (va, order); err_nomem:
arch/sparc/kernel/ioport.c static void sbus_free_coherent(struct device *dev, size_t n, void *p, · line 333
Quoted 5 lines
arch/sparc/kernel/ioport.c +1
-1@@ -321,7 +330,7 @@ static void sbus_free_coherent(struct device *dev, size_t n, void *p,return ; } - n = (n +PAGE_SIZE -1 ) &PAGE_MASK ; + n =PAGE_ALIGN (n);
Another patch..
arch/sparc/kernel/ioport.c static void sbus_free_coherent(struct device *dev, size_t n, void *p, · line 350
Quoted 13 lines
arch/sparc/kernel/ioport.c +5
-0if ((res->end-res->start)+1 != n) {printk ("sbus_free_consistent: region 0x%lx asked 0x%zx\n" , (long )((res->end-res->start)+1 ), n);@@ -333,7 +342,12 @@ static void sbus_free_coherent(struct device *dev, size_t n, void *p,/* mmu_inval_dma_area(va, n); */ /* it's consistent, isn't it */ pgv =virt_to_page (p); + +#ifdef CONFIG_SPARC_LEON +sparc_unmapiorange ((unsigned long )p, n); +#else mmu_unmap_dma_area (dev, ba, n); +#endif
Why? comemnts needed again.
Or better find another way to do this.
Looking a bit around...
Is it correct understood that BTFIXUPSET_CALL() is used to patch in another function here for for example sun4c? So mmu_unmap_dma_area() becomes a call to sun4c_unmap_dma_area()?
Quoted 14 lines
arch/sparc/kernel/ioport.c +0
-3__free_pages (pgv,get_order (n)); }@@ -408,9 +422,6 @@ struct dma_map_ops sbus_dma_ops = { .sync_sg_for_device = sbus_sync_sg_for_device, }; -struct dma_map_ops *dma_ops = &sbus_dma_ops; -EXPORT_SYMBOL (dma_ops); -static int __init sparc_register_ioport (void ) {register_proc_sparc_ioport ();
arch/sparc/kernel/ioport.c arch_initcall(sparc_register_ioport); · line 436
Quoted 5 lines
arch/sparc/kernel/ioport.c +1
-1@@ -422,7 +433,7 @@ arch_initcall(sparc_register_ioport);#endif /* CONFIG_SBUS */ -#ifdef CONFIG_PCI +#if defined(CONFIG_PCI ) || defined(CONFIG_SPARC_LEON )
Why do we need PCI functions when PCI is not defined?
Quoted 13 lines
arch/sparc/kernel/ioport.c +1
-1/* Allocate and map kernel buffer using consistent mode DMA for a device. * hwdev should be valid struct pci_dev pointer for PCI devices. @@ -430,7 +441,7 @@ arch_initcall(sparc_register_ioport);static void *pci32_alloc_coherent (struct device *dev,size_t len,dma_addr_t *pba,gfp_t gfp) { -unsigned long len_total = (len +PAGE_SIZE -1 ) &PAGE_MASK ; +unsigned long len_total =PAGE_ALIGN (len);unsigned long va;struct resource *res;int order;
arch/sparc/kernel/ioport.c static void *pci32_alloc_coherent(struct device *dev, size_t len, · line 469
Quoted 7 lines
arch/sparc/kernel/ioport.c +0
-4@@ -463,10 +474,6 @@ static void *pci32_alloc_coherent(struct device *dev, size_t len,return NULL ; }mmu_inval_dma_area (va, len_total); -#if 0 -/* P3 */ printk ("pci_alloc_consistent: kva %lx uncva %lx phys %lx size %lx\n" , - (long )va, (long )res->start, (long )virt_to_phys (va), len_total); -#endif
unrealted cleanup...
arch/sparc/kernel/ioport.c static void pci32_free_coherent(struct device *dev, size_t n, void *p, · line 508
Quoted 9 lines
arch/sparc/kernel/ioport.c +1
-1sparc_mapiorange (0 ,virt_to_phys (va), res->start, len_total); *pba =virt_to_phys (va);/* equals virt_to_bus (R.I.P.) for us. */ @@ -498,7 +505,7 @@ static void pci32_free_coherent(struct device *dev, size_t n, void *p,return ; } - n = (n +PAGE_SIZE -1 ) &PAGE_MASK ; + n =PAGE_ALIGN (n);
Another patch.
Quoted 5 lines
arch/sparc/kernel/ioport.c +0
-0if ((res->end-res->start)+1 != n) {printk ("pci_free_consistent: region 0x%lx asked 0x%lx\n" , (long )((res->end-res->start)+1 ), (long )n);@@ -515,6 +522,15 @@ static void pci32_free_coherent(struct device *dev, size_t n, void *p,free_pages (pgp,get_order (n));
arch/sparc/kernel/ioport.c static void pci32_free_coherent(struct device *dev, size_t n, void *p, · line 532
Quoted 10 lines
arch/sparc/kernel/ioport.c +8
-0} +static void pci32_unmap_page (struct device *dev,dma_addr_t ba,size_t size, +enum dma_data_direction dir, +struct dma_attrs *attrs) +{ +if (dir !=PCI_DMA_TODEVICE ) +mmu_inval_dma_area ((unsigned long )phys_to_virt (ba), +PAGE_ALIGN (size)); +}
Looks like ordinary SPARC32 gained an unmap_page - correct? Looks like a separate chage to me.
arch/sparc/kernel/ioport.c static int pci32_map_sg(struct device *device, struct scatterlist *sgl, · line 554
Quoted 9 lines
arch/sparc/kernel/ioport.c +1
-1+/* * Same as pci_map_single, but with pages. */ @@ -551,8 +567,7 @@ static int pci32_map_sg(struct device *device, struct scatterlist *sgl,/* IIep is write-through, not flushing. */ for_each_sg (sgl, sg, nents, n) { -BUG_ON (page_address (sg_page (sg)) =NULL );
Why is this BUG_ON() removed?
arch/sparc/kernel/ioport.c static int pci32_map_sg(struct device *device, struct scatterlist *sgl, · line 570
Quoted 2 lines
arch/sparc/kernel/ioport.c +1
-1- sg->dma_address =virt_to_phys (sg_virt (sg)); + sg->dma_address =sg_phys (sg);
Why - is this better or what?
Quoted 4 lines
arch/sparc/kernel/ioport.c +0
-0sg->dma_length = sg->length; }return nents;
arch/sparc/kernel/ioport.c static void pci32_unmap_sg(struct device *dev, struct scatterlist *sgl, · line 591
Quoted 10 lines
arch/sparc/kernel/ioport.c +2
-4@@ -571,10 +586,8 @@ static void pci32_unmap_sg(struct device *dev, struct scatterlist *sgl,if (dir !=PCI_DMA_TODEVICE ) {for_each_sg (sgl, sg, nents, n) { -BUG_ON (page_address (sg_page (sg)) =NULL ); -mmu_inval_dma_area ( - (unsigned long )page_address (sg_page (sg)), - (sg->length +PAGE_SIZE -1 ) &PAGE_MASK ); +mmu_inval_dma_area ((unsigned long )sg_virt (sg), +PAGE_ALIGN (sg->length)); }
Partly same type of comments like above.
arch/sparc/kernel/ioport.c static void pci32_sync_single_for_cpu(struct device *dev, dma_addr_t ba, · line 610
Quoted 8 lines
arch/sparc/kernel/ioport.c +1
-1} }@@ -594,7 +607,7 @@ static void pci32_sync_single_for_cpu(struct device *dev, dma_addr_t ba, {if (dir !=PCI_DMA_TODEVICE ) {mmu_inval_dma_area ((unsigned long )phys_to_virt (ba), - (size +PAGE_SIZE -1 ) &PAGE_MASK ); +PAGE_ALIGN (size));
Another patch...
Same goes for additional spots in this file - I did not comment these.
Quoted 48 lines
arch/sparc/kernel/ioport.c +36
-1+/* LEON3 unmapping functions +* +* We can only invalidate the whole cache so unmap_page and unmap_sg do the +* same thing +*/ +static void leon3_unmap_page (struct device *dev,dma_addr_t ba,size_t size, +enum dma_data_direction dir, +struct dma_attrs *attrs) +{ +if (dir !=PCI_DMA_TODEVICE ) +mmu_inval_dma_area (0 ,0 ); +} + +static void leon3_unmap_sg (struct device *dev,struct scatterlist *sgl, +int nents,enum dma_data_direction dir, +struct dma_attrs *attrs) +{ +if (dir !=PCI_DMA_TODEVICE ) +mmu_inval_dma_area (0 ,0 ); +} +struct dma_map_ops pci32_dma_ops = { .alloc_coherent = pci32_alloc_coherent, .free_coherent = pci32_free_coherent, .map_page = pci32_map_page, + .unmap_page = pci32_unmap_page, .map_sg = pci32_map_sg, .unmap_sg = pci32_unmap_sg, .sync_single_for_cpu = pci32_sync_single_for_cpu,@@ -658,7 +689,30 @@ struct dma_map_ops pci32_dma_ops = { };EXPORT_SYMBOL (pci32_dma_ops); -#endif /* CONFIG_PCI */ +struct dma_map_ops leon3_dma_ops = { + .alloc_coherent = sbus_alloc_coherent, + .free_coherent = sbus_free_coherent, + .map_page = pci32_map_page, + .unmap_page = leon3_unmap_page, + .map_sg = pci32_map_sg, + .unmap_sg = leon3_unmap_sg, + .sync_single_for_cpu = pci32_sync_single_for_cpu, + .sync_single_for_device = pci32_sync_single_for_device, + .sync_sg_for_cpu = pci32_sync_sg_for_cpu, + .sync_sg_for_device = pci32_sync_sg_for_device, +}; + +#endif /* CONFIG_PCI || CONFIG_SPARC_LEON */
arch/sparc/kernel/ioport.c struct dma_map_ops pci32_dma_ops = { · line 715
Quoted 10 lines
arch/sparc/kernel/ioport.c +10
-0+ +#ifdef CONFIG_SPARC_LEON +struct dma_map_ops *dma_ops = &leon3_dma_ops; +#else +struct dma_map_ops *dma_ops = &sbus_dma_ops; +#endif + +#ifdef CONFIG_SBUS +EXPORT_SYMBOL (dma_ops); +#endif
This just looks wrong to me...
Why we need to export only is SBUS is defined - but we define leon3_dma_ops if LEON is defined.
I think this need to be revisited - and then see if you can hide more of the ifdef in dma-mapping.h
Quoted 22 lines
arch/sparc/kernel/ioport.c +11
-0/* * Return whether the given PCI device DMA address mask can be @@ -676,6 +730,17 @@ int dma_supported(struct device *dev, u64 mask) }EXPORT_SYMBOL (dma_supported); +int dma_set_mask (struct device *dev,u64 dma_mask) +{ +#ifdef CONFIG_PCI +if (dev->bus = &pci_bus_type) +return pci_set_dma_mask (to_pci_dev (dev), dma_mask); +#endif +return -EOPNOTSUPP ; +} +EXPORT_SYMBOL (dma_set_mask); + +#ifdef CONFIG_PROC_FS static int sparc_io_proc_show (struct seq_file *m,void *v)
arch/sparc/kernel/ioport.c static const struct file_operations sparc_io_proc_fops = { · line 785
Quoted 5 lines
arch/sparc/kernel/ioport.c +1
-1@@ -717,7 +782,7 @@ static const struct file_operations sparc_io_proc_fops = {static struct resource *_sparc_find_resource (struct resource *root,unsigned long hit) { -struct resource *tmp; +struct resource *tmp;
Minor nit but unrelated change.
Sam
Hi Sam,
Quoted 6 lines · Sam Ravnborg
And it is now an exported symbol - looks OK.
But the new implementation differs from the old implementation.Grepping for
pci_set_dma_mask()turned up this implmentation:
static inline intpci_set_dma_mask(struct pci_dev *dev, u64 mask)
Quoted 9 lines
{ return dma_set_mask(&dev->dev, mask); }It looks like an infinite loop??
Note: This change alone warrant an independent patch.
I'm not quite sure what has happened here. My original patch did not
touch dma_set_mask. I will have to check with Daniel what has gone wrong ...
Quoted 8 lines
Quoted 8 lines
arch/sparc/kernel/ioport.c +0
-1--- a/arch/sparc/kernel/ioport.c b/arch/sparc/kernel/ioport.c@@ -50,10 50,15 @@
#include <asm/io-unit.h>
#include <asm/leon.h>
Quoted 7 lines
arch/sparc/kernel/ioport.c
Quoted 7 lines
arch/sparc/kernel/ioport.c +0
-3-#ifdef CONFIG_SPARC_LEON -#define mmu_inval_dma_area (p, l) leon_flush_dcache_all() -#else #ifndef CONFIG_SPARC_LEON #define mmu_inval_dma_area (p, l)/* Anton pulled it out for 2.4.0-xx */ #else static inline void mmu_inval_dma_area(unsigned long va, unsigned
long len)
Quoted 11 lines
Quoted 6 lines
{
if (!sparc_leon3_snooping_enabled()) {
leon_flush_dcache_all();
}
}
#endifThis is better than before as we no longer has a double definition. But why do we call
mmu_inval_dma_area()wich is empty in SPARC32 build
from SBUS code? LEON does not support SBUS only AMBA PCI IIRC.
Hmm - looking atKconfigLEON supports SBUS too. Is that correct?
My patch tried to touch the generic SPARC32 code as little as
possible. Especially since I have no idea why "Anton pulled it out" from the beginning :-). The first version of the patch did not touch the sbus_ version at all but I changed this because Dave thought it better to reuse it also for LEON. We have no SBUS on our chips but the SBUS code is used every here and there. Maybe this should be cleaned up in the future but this is the current state.
Quoted 11 lines
Quoted 9 lines
#ifdef
CONFIG_SPARC_LEON
sparc_mapiorange(0, virt_to_phys(va), res->start, len_total);*dma_addrp=virt_to_phys(va);
#else
if (mmu_map_dma_area(dev, dma_addrp, va, res->start, len_total)!= 0) {release_resource(res);
gotoerr_nova;
}
#endif
Quoted 3 lines
I cannot follow why you need this ugly ifdef here. Some comments please.
I agree this is not beautiful :-). It is just an attempt to reuse the
sbus version of alloc_coherent to avoid code duplicaion.
Quoted 3 lines
Why? comemnts needed again.
Or better find another way to do this.
Same as above.
Quoted 5 lines
Looking a bit around...
Is it correct understood thatBTFIXUPSET_CALL()is used to patch in another function here for for example sun4c? Sommu_unmap_dma_area()becomes a call tosun4c_unmap_dma_area()?
Routines from iommu.c or io-unit.c are patched in depending on
architecture. They do not apply to LEON ...
Quoted 5 lines
Quoted 2 lines
-#ifdef
CONFIG_PCI
#ifdefined(CONFIG_PCI)||defined(CONFIG_SPARC_LEON)Why do we need PCI functions when PCI is not defined?
Quoted 1 line
Again it is just to avoid code duplication. The pci dma ops inioport.c correspond quite well to what should happen on LEON. It would look nicer to just create LEON specific version of all dma_ops (I did originally) but it would also be wasteful.
Quoted 3 lines
Looks like ordinary SPARC32 gained an
unmap_page- correct? Looks like a separate chage to me.
Indeed!
Quoted 5 lines
Quoted 5 lines
/*
* Same aspci_map_single, but with pages.
*/
@@ -551,8 567,7 @@ static int pci32_map_sg(struct device
*device, struct scatterlist *sgl,
Quoted 5 lines
Quoted 4 lines
/* IIep is write-through, not flushing. */
for_each_sg(sgl, sg, nents, n){
-BUG_ON(page_address(sg_page(sg)) = NULL);Why is this
BUG_ON()removed?
I'm not sure how Daniel has generated this latest version the patch.
I don't remember removing this one ...
Quoted 5 lines
Quoted 3 lines
-
sg->dma_address= virt_to_phys(sg_virt(sg));
sg->dma_address=sg_phys(sg);Why - is this better or what?
Reads cleaner to me.
Quoted 4 lines
This just looks wrong to me...
Why we need to export only is SBUS is defined - but we defineleon3_dma_opsif LEON is defined.
SBUS is always defined. But I generally agree that it should be
refactored somehow. I think that could happen in a separate patch series in the future. As the SPARC32 port is now SBUS must always be defined.
Quoted 3 lines
I think this need to be revisited - and then see if you can hide more of the ifdef in
dma-mapping.h
We will await further feedback and post it again next week.
Thanks,
Kristoffer
Hi Kristoffer.
Quoted 2 lines
My patch tried to touch the generic SPARC32 code as little as possible.
I think it is time to accept that LEON is a first class citizen here and accepts that code shall be well integrated with the rest of SPARC32 rather than avoid touching it.
I know where you are coming from maintaining this out-of-tree. But LEON is now part of the kernel.
For testing you can request the community for help.
There are still people around that run a few SPARC32 systems - albeit they seem to be few these days.
Quoted 1 line
SBUS is always defined.
You are right.
I will kill the remaining ifdefs as they confused me.
Quoted 1 line
We will await further feedback and post it again next week.
It would be better is you tried to split it up already now and address the feedback that you already have.
Then the review is much easier.
Sam
Hi,
Quoted 5 lines
Quoted 1 line
We will await further feedback and post it again next week.
It would be better is you tried to split it up already now and address the feedback that you already have.
Then the review is much easier.
Due to holidays we won't be in the office until Monday unfortunately.
Will send patches then ...
/Kristoffer
Quoted 10 lines · On Thu, Jan 06, 2011 at 10:11:51AM +0100, [email protected] wrote:
Hi,
Quoted 5 lines
Quoted 1 line
We will await further feedback and post it again next week.
It would be better is you tried to split it up already now and address the feedback that you already have.
Then the review is much easier.
Due to holidays we won't be in the office until Monday unfortunately.
Will send patches then ...
Enjoy your holidays!
Looking forward for next submission.
Sam
Sorry, I perhaps screwed up the patch submit to the list, it was me that sent the patch. Today is a public holiday in sweden... I will try to answer it tomorrow or monday.
Daniel
On Wed, 5 Jan 2011 19:16:23 0100, Sam Ravnborg wrote:
Quoted 6 lines · Daniel Hellstrom
Quoted 3 lines
From: Kristoffer Glembo <[email protected]>
Added
leon3_dma_opsandmmu_inval_dma_area.Hi Kristoffer.
Quoted 12 lines
This patch mixes cleanup with added functionality. I would have preferred that you divided this into several smaller patches.
I am not familiar with the area that your patch touches - but I have tried to give some feedback below.
Sam
Quoted 3 lines
--- arch/sparc/include/asm/dma-mapping.h | 13 --- arch/sparc/kernel/ioport.c | 139
---------
Quoted 3 lines
Review
Quoted 3 lines
2 files changed, 103 insertions( ), 49 deletions(-)(quoted diff) +0
-0
b/arch/sparc/include/asm/dma-mapping.h
Quoted 4 lines
Quoted 4 lines
index 8c0e4f7..fadc653 100644
---a/arch/sparc/include/asm/dma-mapping.h
b/arch/sparc/include/asm/dma-mapping.h
@@ -51,17 51,6 @@ static inline int dma_mapping_error(struct
device *dev, dma_addr_t dma_addr)
Quoted 52 lines
Quoted 6 lines
return (
dma_addr=DMA_ERROR_CODE);
}arch/sparc/include/asm/dma-mapping.h +0
-3-static inline int dma_set_mask (struct device *dev,u64 mask) -{ -#ifdef CONFIG_PCI arch/sparc/include/asm/dma-mapping.h static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
Quoted 10 lines
arch/sparc/include/asm/dma-mapping.h +0
-9-if (dev->bus = &pci_bus_type) { -if (!dev->dma_mask || !dma_supported (dev, mask)) -return -EINVAL ; - *dev->dma_mask = mask; -return 0 ; - } -#endif -return -EINVAL ; -}extern int dma_set_mask (struct device *dev,u64 dma_mask);So
dma_set_mask()is moved toioport.cQuoted 10 lines
int
dma_set_mask(struct device *dev, u64 dma_mask){
#ifdefCONFIG_PCI
if (dev->bus=&pci_bus_type)
returnpci_set_dma_mask(to_pci_dev(dev), dma_mask);
#endif
return-EOPNOTSUPP;
}
EXPORT_SYMBOL(dma_set_mask);And it is now an exported symbol - looks OK.
But the new implementation differs from the old implementation.Grepping for
pci_set_dma_mask()turned up this implmentation:
static inline intpci_set_dma_mask(struct pci_dev *dev, u64 mask){ return dma_set_mask(&dev->dev, mask); }It looks like an infinite loop??
Note: This change alone warrant an independent patch.
Quoted 9 lines
#endif
arch/sparc/kernel/ioport.c +0
-1--- a/arch/sparc/kernel/ioport.c b/arch/sparc/kernel/ioport.c@@ -50,10 50,15 @@
#include <asm/io-unit.h>
#include <asm/leon.h>
Quoted 7 lines
arch/sparc/kernel/ioport.c
Quoted 7 lines
arch/sparc/kernel/ioport.c +0
-3-#ifdef CONFIG_SPARC_LEON -#define mmu_inval_dma_area (p, l) leon_flush_dcache_all() -#else #ifndef CONFIG_SPARC_LEON #define mmu_inval_dma_area (p, l)/* Anton pulled it out for 2.4.0-xx */ #else static inline void mmu_inval_dma_area(unsigned long va, unsigned
long len)
Quoted 6 lines
Quoted 6 lines
{
if (!sparc_leon3_snooping_enabled()) {
leon_flush_dcache_all();
}
}
#endif
Quoted 8 lines
This is better than before as we no longer has a double definition. But why do we call
mmu_inval_dma_area()wich is empty in SPARC32 build
from SBUS code? LEON does not support SBUS only AMBA PCI IIRC.
Hmm - looking atKconfigLEON supports SBUS too. Is that correct?Quoted 3 lines
static struct resource *_sparc_find_resource(struct resource *r,
@@ -254,7 259,7 @@ static void *sbus_alloc_coherent(struct
device *dev, size_t len,
Quoted 11 lines
Quoted 5 lines
dma_addr_t*dma_addrp,gfp_tgfp)
{
structplatform_device*op =to_platform_device(dev);
- unsigned longlen_total= (len PAGE_SIZE-1) &PAGE_MASK;
unsigned longlen_total=PAGE_ALIGN(len);
PAGE_ALIGNis much better than the old version. But again - please do such cleanup in a separate step. If we are going to revert your functional change we do not want to lose such cleanups.
Quoted 4 lines
Quoted 4 lines
unsigned long va;
struct resource *res;
int order;
@@ -287,15 292,19 @@ static void *sbus_alloc_coherent(struct
device *dev, size_t len,
Quoted 22 lines
Quoted 7 lines
* XXX That's where sdev would be used. Currently we load
* all iommu tables with the same translations.
*/
- if (mmu_map_dma_area(dev, dma_addrp, va, res->start, len_total)!= 0)
- gotoerr_noiommu;
-
#ifdefCONFIG_SPARC_LEONQuoted 8 lines
sparc_mapiorange(0, virt_to_phys(va), res->start, len_total);*dma_addrp=virt_to_phys(va);
#else
if (mmu_map_dma_area(dev, dma_addrp, va, res->start, len_total)!= 0) {release_resource(res);
gotoerr_nova;
}
#endifI cannot follow why you need this ugly ifdef here. Some comments please.
Quoted 2 lines
res->name = op->dev.of_node->name;
Quoted 8 lines
Quoted 8 lines
return (void *)(unsigned long)res->start;-err_noiommu:
-release_resource(res);
err_nova:
free_pages(va, order);
err_nomem:
@@ -321,7 330,7 @@ static void sbus_free_coherent(struct device
*dev, size_t n, void *p,
Quoted 11 lines
Quoted 5 lines
return; }- n = (n PAGE_SIZE-1) &
PAGE_MASK;
n =PAGE_ALIGN(n);Another patch..
Quoted 4 lines
if ((res->end-res->start) 1 != n) { printk("sbus_free_consistent: region 0x%lx asked 0x%zx\n",
(long)((res->end-res->start) 1), n);@@ -333,7 342,12 @@ static void sbus_free_coherent(struct device
*dev, size_t n, void *p,
Quoted 33 lines
Quoted 9 lines
/* mmu_inval_dma_area(va, n); */ /* it's consistent, isn't it */ pgv = virt_to_page(p);#ifdef
CONFIG_SPARC_LEON
sparc_unmapiorange((unsigned long)p, n);
#else
mmu_unmap_dma_area(dev, ba, n);
#endifWhy? comemnts needed again.
Or better find another way to do this.Looking a bit around...
Is it correct understood thatBTFIXUPSET_CALL()is used to patch in another function here for for example sun4c? Sommu_unmap_dma_area()becomes a call tosun4c_unmap_dma_area()?Quoted 15 lines
__free_pages(pgv, get_order(n));
}
@@ -408,9 422,6 @@ structdma_map_opssbus_dma_ops= {
.sync_sg_for_device =sbus_sync_sg_for_device,
};arch/sparc/kernel/ioport.c +0
-3-struct dma_map_ops *dma_ops = &sbus_dma_ops; -EXPORT_SYMBOL (dma_ops); -static int __init sparc_register_ioport (void ) {register_proc_sparc_ioport ();@@ -422,7 433,7 @@
arch_initcall(sparc_register_ioport);
Quoted 8 lines
Quoted 4 lines
#endif /*
CONFIG_SBUS*/-#ifdef
CONFIG_PCI
#ifdefined(CONFIG_PCI)||defined(CONFIG_SPARC_LEON)Why do we need PCI functions when PCI is not defined?
Quoted 2 lines
/* Allocate and map kernel buffer using consistent mode DMA for
a device.
Quoted 11 lines
Quoted 11 lines
* hwdev should be valid struct
pci_devpointer for PCI devices.
@@ -430,7 441,7 @@arch_initcall(sparc_register_ioport);
static void *pci32_alloc_coherent(struct device *dev,size_tlen,
dma_addr_t*pba,gfp_tgfp)
{
- unsigned longlen_total= (len PAGE_SIZE-1) &PAGE_MASK;
unsigned longlen_total=PAGE_ALIGN(len);
unsigned long va;
struct resource *res;
int order;
@@ -463,10 474,6 @@ static void *pci32_alloc_coherent(struct
device *dev, size_t len,
Quoted 5 lines
arch/sparc/kernel/ioport.c
Quoted 5 lines
return NULL; } mmu_inval_dma_area(va, len_total);arch/sparc/kernel/ioport.c +0
-2-#if 0 -/* P3 */ printk("pci_alloc_consistent: kva %lx uncva %lx phys
%lx size %lx\n",
Quoted 8 lines
arch/sparc/kernel/ioport.c static void *pci32_alloc_coherent(struct device *dev, size_t len, · line 469
Quoted 2 lines
arch/sparc/kernel/ioport.c +0
-2- (long)va, (long)res->start, (long)virt_to_phys(va), len_total); -#endif unrealted cleanup...
Quoted 4 lines
sparc_mapiorange(0, virt_to_phys(va), res->start, len_total);*pba =
virt_to_phys(va); /* equalsvirt_to_bus(R.I.P.) for us. */
@@ -498,7 505,7 @@ static void pci32_free_coherent(struct device
*dev, size_t n, void *p,
Quoted 11 lines
Quoted 5 lines
return; }- n = (n PAGE_SIZE-1) &
PAGE_MASK;
n =PAGE_ALIGN(n);Another patch.
Quoted 4 lines
if ((res->end-res->start) 1 != n) { printk("pci_free_consistent: region 0x%lx asked 0x%lx\n",
(long)((res->end-res->start) 1), (long)n);@@ -515,6 522,15 @@ static void pci32_free_coherent(struct
device *dev, size_t n, void *p,
Quoted 4 lines
Quoted 4 lines
free_pages(pgp, get_order(n));
}static void pci32_unmap_page(struct device *dev,
dma_addr_tba,
size_t size,
Quoted 7 lines
Quoted 7 lines
enum
dma_data_directiondir,
structdma_attrs*attrs)
{
if (dir !=PCI_DMA_TODEVICE) mmu_inval_dma_area((unsigned long)phys_to_virt(ba),PAGE_ALIGN(size));}
Quoted 8 lines
Looks like ordinary SPARC32 gained an
unmap_page- correct? Looks like a separate chage to me.Quoted 5 lines
/*
* Same aspci_map_single, but with pages.
*/
@@ -551,8 567,7 @@ static int pci32_map_sg(struct device
*device, struct scatterlist *sgl,
Quoted 9 lines
Quoted 4 lines
/* IIep is write-through, not flushing. */
for_each_sg(sgl, sg, nents, n){
-BUG_ON(page_address(sg_page(sg)) = NULL);Why is this
BUG_ON()removed?Quoted 2 lines
-
sg->dma_address= virt_to_phys(sg_virt(sg));
sg->dma_address=sg_phys(sg);
Quoted 6 lines
Why - is this better or what?
Quoted 4 lines
sg->dma_length=sg->length;
}
return nents;
@@ -571,10 586,8 @@ static void pci32_unmap_sg(struct device
*dev, struct scatterlist *sgl,
Quoted 11 lines
arch/sparc/kernel/ioport.c
Quoted 10 lines
if (dir !=
PCI_DMA_TODEVICE) {
for_each_sg(sgl, sg, nents, n){
-BUG_ON(page_address(sg_page(sg)) = NULL);
- mmu_inval_dma_area(arch/sparc/kernel/ioport.c +0
-2- (unsigned long )page_address (sg_page (sg)), - (sg->length PAGE_SIZE-1) & PAGE_MASK);mmu_inval_dma_area ((unsigned long )sg_virt (sg),PAGE_ALIGN (sg->length)); }
Quoted 6 lines
Partly same type of comments like above.
Quoted 3 lines
}
}
@@ -594,7 607,7 @@ static void pci32_sync_single_for_cpu(struct
device *dev, dma_addr_t ba,
Quoted 11 lines
Quoted 5 lines
{
if (dir !=PCI_DMA_TODEVICE) { mmu_inval_dma_area((unsigned long)phys_to_virt(ba),- (size PAGE_SIZE-1) & PAGE_MASK); PAGE_ALIGN(size));Another patch...
Same goes for additional spots in this file - I did not comment these.Quoted 3 lines
/* LEON3 unmapping functions
*
* We can only invalidate the whole cache sounmap_pageand
unmap_sg do the
Quoted 3 lines
Quoted 3 lines
* same thing
*/
static void leon3_unmap_page(struct device *dev,dma_addr_tba,
size_t size,
Quoted 79 lines
Quoted 49 lines
enum
dma_data_directiondir,
structdma_attrs*attrs)
{
if (dir !=PCI_DMA_TODEVICE)
mmu_inval_dma_area(0, 0);
}static void leon3_unmap_sg(struct device *dev, struct scatterlist *sgl,
int nents, enumdma_data_directiondir,
structdma_attrs*attrs)
{
if (dir !=PCI_DMA_TODEVICE)
mmu_inval_dma_area(0, 0);
}struct
dma_map_opspci32_dma_ops= {
.alloc_coherent =pci32_alloc_coherent, .free_coherent =pci32_free_coherent, .map_page =pci32_map_page,
.unmap_page =pci32_unmap_page,
.map_sg =pci32_map_sg,
.unmap_sg =pci32_unmap_sg, .sync_single_for_cpu =pci32_sync_single_for_cpu,
@@ -658,7 689,30 @@ structdma_map_opspci32_dma_ops= {
};
EXPORT_SYMBOL(pci32_dma_ops);-#endif /*
CONFIG_PCI*/
structdma_map_opsleon3_dma_ops= {
.alloc_coherent =sbus_alloc_coherent, .free_coherent =sbus_free_coherent,
.map_page =pci32_map_page,
.unmap_page =leon3_unmap_page,
.map_sg =pci32_map_sg,
.unmap_sg =leon3_unmap_sg, .sync_single_for_cpu =pci32_sync_single_for_cpu, .sync_single_for_device =pci32_sync_single_for_device, .sync_sg_for_cpu =pci32_sync_sg_for_cpu, .sync_sg_for_device =pci32_sync_sg_for_device,
};#endif /*
CONFIG_PCI||CONFIG_SPARC_LEON*/#ifdef
CONFIG_SPARC_LEON
structdma_map_ops*dma_ops=&leon3_dma_ops;
#else
structdma_map_ops*dma_ops=&sbus_dma_ops;
#endifQuoted 3 lines
#ifdef
CONFIG_SBUS
EXPORT_SYMBOL(dma_ops);
#endifThis just looks wrong to me...
Why we need to export only is SBUS is defined - but we defineleon3_dma_opsif LEON is defined.I think this need to be revisited - and then see if you can hide more of the ifdef in
dma-mapping.hQuoted 18 lines
/*
* Return whether the given PCI device DMA address mask can be
@@ -676,6 730,17 @@ intdma_supported(struct device *dev, u64 mask)
}
EXPORT_SYMBOL(dma_supported);int
dma_set_mask(struct device *dev, u64 dma_mask){
#ifdefCONFIG_PCI
if (dev->bus=&pci_bus_type)
returnpci_set_dma_mask(to_pci_dev(dev), dma_mask);
#endif
return-EOPNOTSUPP;
}
EXPORT_SYMBOL(dma_set_mask);
Quoted 4 lines
Quoted 4 lines
#ifdef
CONFIG_PROC_FSstatic int
sparc_io_proc_show(struct seq_file *m, void *v)
@@ -717,7 782,7 @@ static const structfile_operations
sparc_io_proc_fops = {
Quoted 11 lines
Quoted 5 lines
static struct resource *_sparc_find_resource(struct resource *root,
unsigned long hit)
{
- struct resource *tmp;
struct resource *tmp;Minor nit but unrelated change.
Sam