Re: [PATCH V5 09/18] MIPS: Loongson: Add swiotlb to support big memory (>4GB).

2012-08-15 Thread Huacai Chen
On Thu, Aug 16, 2012 at 4:24 AM, Ralf Baechle wrote: > On Mon, Aug 13, 2012 at 01:54:47PM -0400, Konrad Rzeszutek Wilk wrote: > >> > +static void *loongson_dma_alloc_coherent(struct device *dev, size_t size, >> > + dma_addr_t *dma_handle, gfp_t gfp, struct >> >

Re: [PATCH V5 09/18] MIPS: Loongson: Add swiotlb to support big memory (>4GB).

2012-08-15 Thread Ralf Baechle
On Mon, Aug 13, 2012 at 01:54:47PM -0400, Konrad Rzeszutek Wilk wrote: > > +static void *loongson_dma_alloc_coherent(struct device *dev, size_t size, > > + dma_addr_t *dma_handle, gfp_t gfp, struct > > dma_attrs *attrs) > > +{ > > + void *ret; > > + > > + if

Re: [PATCH V5 09/18] MIPS: Loongson: Add swiotlb to support big memory (4GB).

2012-08-15 Thread Ralf Baechle
On Mon, Aug 13, 2012 at 01:54:47PM -0400, Konrad Rzeszutek Wilk wrote: +static void *loongson_dma_alloc_coherent(struct device *dev, size_t size, + dma_addr_t *dma_handle, gfp_t gfp, struct dma_attrs *attrs) +{ + void *ret; + + if

Re: [PATCH V5 09/18] MIPS: Loongson: Add swiotlb to support big memory (4GB).

2012-08-15 Thread Huacai Chen
On Thu, Aug 16, 2012 at 4:24 AM, Ralf Baechle r...@linux-mips.org wrote: On Mon, Aug 13, 2012 at 01:54:47PM -0400, Konrad Rzeszutek Wilk wrote: +static void *loongson_dma_alloc_coherent(struct device *dev, size_t size, + dma_addr_t *dma_handle, gfp_t gfp, struct

Re: [PATCH V5 09/18] MIPS: Loongson: Add swiotlb to support big memory (>4GB).

2012-08-14 Thread Huacai Chen
On Tue, Aug 14, 2012 at 1:54 AM, Konrad Rzeszutek Wilk wrote: >> +static void *loongson_dma_alloc_coherent(struct device *dev, size_t size, >> + dma_addr_t *dma_handle, gfp_t gfp, struct >> dma_attrs *attrs) >> +{ >> + void *ret; >> + >> + if

Re: [PATCH V5 09/18] MIPS: Loongson: Add swiotlb to support big memory (>4GB).

2012-08-14 Thread David Daney
On 08/13/2012 10:57 PM, Huacai Chen wrote: Hi, David, Seems like you are the original author of code in arch/mips/cavium-octeon/dma-octeon.c. Could you please tell me why we need mb() in alloc_coherent(), map_page(), map_sg()? It seems like because of cache coherency (CPU write some data, then

Re: [PATCH V5 09/18] MIPS: Loongson: Add swiotlb to support big memory (4GB).

2012-08-14 Thread David Daney
On 08/13/2012 10:57 PM, Huacai Chen wrote: Hi, David, Seems like you are the original author of code in arch/mips/cavium-octeon/dma-octeon.c. Could you please tell me why we need mb() in alloc_coherent(), map_page(), map_sg()? It seems like because of cache coherency (CPU write some data, then

Re: [PATCH V5 09/18] MIPS: Loongson: Add swiotlb to support big memory (4GB).

2012-08-14 Thread Huacai Chen
On Tue, Aug 14, 2012 at 1:54 AM, Konrad Rzeszutek Wilk konrad.w...@oracle.com wrote: +static void *loongson_dma_alloc_coherent(struct device *dev, size_t size, + dma_addr_t *dma_handle, gfp_t gfp, struct dma_attrs *attrs) +{ + void *ret; + + if

Re: [PATCH V5 09/18] MIPS: Loongson: Add swiotlb to support big memory (>4GB).

2012-08-13 Thread Huacai Chen
Hi, David, Seems like you are the original author of code in arch/mips/cavium-octeon/dma-octeon.c. Could you please tell me why we need mb() in alloc_coherent(), map_page(), map_sg()? It seems like because of cache coherency (CPU write some data, then map the page for a device, if without mb(),

Re: [PATCH V5 09/18] MIPS: Loongson: Add swiotlb to support big memory (>4GB).

2012-08-13 Thread Huacai Chen
Most of the code are copied from arch/mips/cavium-octeon/dma-octeon.c and they work well. Anyway, I'll try your suggestions, thank you. On Tue, Aug 14, 2012 at 1:54 AM, Konrad Rzeszutek Wilk wrote: >> +static void *loongson_dma_alloc_coherent(struct device *dev, size_t size, >> +

Re: [PATCH V5 09/18] MIPS: Loongson: Add swiotlb to support big memory (>4GB).

2012-08-13 Thread Konrad Rzeszutek Wilk
> +static void *loongson_dma_alloc_coherent(struct device *dev, size_t size, > + dma_addr_t *dma_handle, gfp_t gfp, struct > dma_attrs *attrs) > +{ > + void *ret; > + > + if (dma_alloc_from_coherent(dev, size, dma_handle, )) > + return ret; > + > +

Re: [PATCH V5 09/18] MIPS: Loongson: Add swiotlb to support big memory (4GB).

2012-08-13 Thread Konrad Rzeszutek Wilk
+static void *loongson_dma_alloc_coherent(struct device *dev, size_t size, + dma_addr_t *dma_handle, gfp_t gfp, struct dma_attrs *attrs) +{ + void *ret; + + if (dma_alloc_from_coherent(dev, size, dma_handle, ret)) + return ret; + + /*

Re: [PATCH V5 09/18] MIPS: Loongson: Add swiotlb to support big memory (4GB).

2012-08-13 Thread Huacai Chen
Most of the code are copied from arch/mips/cavium-octeon/dma-octeon.c and they work well. Anyway, I'll try your suggestions, thank you. On Tue, Aug 14, 2012 at 1:54 AM, Konrad Rzeszutek Wilk konrad.w...@oracle.com wrote: +static void *loongson_dma_alloc_coherent(struct device *dev, size_t size,

Re: [PATCH V5 09/18] MIPS: Loongson: Add swiotlb to support big memory (4GB).

2012-08-13 Thread Huacai Chen
Hi, David, Seems like you are the original author of code in arch/mips/cavium-octeon/dma-octeon.c. Could you please tell me why we need mb() in alloc_coherent(), map_page(), map_sg()? It seems like because of cache coherency (CPU write some data, then map the page for a device, if without mb(),

[PATCH V5 09/18] MIPS: Loongson: Add swiotlb to support big memory (>4GB).

2012-08-11 Thread Huacai Chen
This is probably a workaround because Loongson doesn't support DMA address above 4GB. If memory is more than 4GB, CONFIG_SWIOTLB and ZONE_DMA32 should be selected. In this way, DMA pages are allocated below 4GB preferably. However, CONFIG_SWIOTLB+ZONE_DMA32 is not enough, so, we provide a

[PATCH V5 09/18] MIPS: Loongson: Add swiotlb to support big memory (4GB).

2012-08-11 Thread Huacai Chen
This is probably a workaround because Loongson doesn't support DMA address above 4GB. If memory is more than 4GB, CONFIG_SWIOTLB and ZONE_DMA32 should be selected. In this way, DMA pages are allocated below 4GB preferably. However, CONFIG_SWIOTLB+ZONE_DMA32 is not enough, so, we provide a