mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] firewire: fw-ohci: fix DMA mapping for ar context
@ 2007-10-16 17:25 Stefan Richter
  2007-10-16 17:35 ` Stefan Richter
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Richter @ 2007-10-16 17:25 UTC (permalink / raw)
  To: linux1394-devel; +Cc: linux-kernel, Kristian Høgsberg

The CPU must not touch the buffer after it was DMA-mapped.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
---
 drivers/firewire/fw-ohci.c |   12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

Index: linux/drivers/firewire/fw-ohci.c
===================================================================
--- linux.orig/drivers/firewire/fw-ohci.c
+++ linux/drivers/firewire/fw-ohci.c
@@ -253,12 +253,6 @@ static int ar_context_add_page(struct ar
 	if (ab == NULL)
 		return -ENOMEM;
 
-	ab_bus = dma_map_single(dev, ab, PAGE_SIZE, DMA_BIDIRECTIONAL);
-	if (dma_mapping_error(ab_bus)) {
-		free_page((unsigned long) ab);
-		return -ENOMEM;
-	}
-
 	memset(&ab->descriptor, 0, sizeof(ab->descriptor));
 	ab->descriptor.control        = cpu_to_le16(DESCRIPTOR_INPUT_MORE |
 						    DESCRIPTOR_STATUS |
@@ -269,7 +263,11 @@ static int ar_context_add_page(struct ar
 	ab->descriptor.res_count      = cpu_to_le16(PAGE_SIZE - offset);
 	ab->descriptor.branch_address = 0;
 
-	dma_sync_single_for_device(dev, ab_bus, PAGE_SIZE, DMA_BIDIRECTIONAL);
+	ab_bus = dma_map_single(dev, ab, PAGE_SIZE, DMA_BIDIRECTIONAL);
+	if (dma_mapping_error(ab_bus)) {
+		free_page((unsigned long) ab);
+		return -ENOMEM;
+	}
 
 	ctx->last_buffer->descriptor.branch_address = cpu_to_le32(ab_bus | 1);
 	ctx->last_buffer->next = ab;

-- 
Stefan Richter
-=====-=-=== =-=- =----
http://arcgraph.de/sr/


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] firewire: fw-ohci: fix DMA mapping for ar context
  2007-10-16 17:25 [PATCH] firewire: fw-ohci: fix DMA mapping for ar context Stefan Richter
@ 2007-10-16 17:35 ` Stefan Richter
  2007-10-16 17:40   ` [PATCH corrected] " Stefan Richter
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Richter @ 2007-10-16 17:35 UTC (permalink / raw)
  To: linux1394-devel; +Cc: linux-kernel, Kristian Høgsberg

I wrote:
> @@ -253,12 +253,6 @@ static int ar_context_add_page(struct ar
>  	if (ab == NULL)
>  		return -ENOMEM;
>  
> -	ab_bus = dma_map_single(dev, ab, PAGE_SIZE, DMA_BIDIRECTIONAL);
[...]

Argh, it's bogus.  ab_bus is used immediately after that.  Correction
follows in a minute.
-- 
Stefan Richter
-=====-=-=== =-=- =----
http://arcgraph.de/sr/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH corrected] firewire: fw-ohci: fix DMA mapping for ar context
  2007-10-16 17:35 ` Stefan Richter
@ 2007-10-16 17:40   ` Stefan Richter
  2007-10-16 17:58     ` [PATCH] firewire: fw-ohci: optimize initialization of " Stefan Richter
  2007-10-16 19:49     ` [PATCH corrected] firewire: fw-ohci: fix DMA mapping for ar context Stefan Richter
  0 siblings, 2 replies; 6+ messages in thread
From: Stefan Richter @ 2007-10-16 17:40 UTC (permalink / raw)
  To: linux1394-devel; +Cc: linux-kernel, Kristian Høgsberg

The CPU must not touch the buffer after it was DMA-mapped.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
---
 drivers/firewire/fw-ohci.c |    1 +
 1 file changed, 1 insertion(+)

Index: linux/drivers/firewire/fw-ohci.c
===================================================================
--- linux.orig/drivers/firewire/fw-ohci.c
+++ linux/drivers/firewire/fw-ohci.c
@@ -258,6 +258,7 @@ static int ar_context_add_page(struct ar
 		free_page((unsigned long) ab);
 		return -ENOMEM;
 	}
+	dma_sync_single_for_cpu(dev, ab_bus, PAGE_SIZE, DMA_BIDIRECTIONAL);
 
 	memset(&ab->descriptor, 0, sizeof(ab->descriptor));
 	ab->descriptor.control        = cpu_to_le16(DESCRIPTOR_INPUT_MORE |

-- 
Stefan Richter
-=====-=-=== =-=- =----
http://arcgraph.de/sr/


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] firewire: fw-ohci: optimize initialization of ar context
  2007-10-16 17:40   ` [PATCH corrected] " Stefan Richter
@ 2007-10-16 17:58     ` Stefan Richter
  2007-10-16 18:30       ` [PATCH] firewire: fw-ohci: avoid an atomic allocation Stefan Richter
  2007-10-16 19:49     ` [PATCH corrected] firewire: fw-ohci: fix DMA mapping for ar context Stefan Richter
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Richter @ 2007-10-16 17:58 UTC (permalink / raw)
  To: linux1394-devel; +Cc: linux-kernel, Kristian Høgsberg

Sync only the parts for CPU which are actually accessed by the CPU.
Replace a memset by direct assignment.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
---
 drivers/firewire/fw-ohci.c |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

Index: linux/drivers/firewire/fw-ohci.c
===================================================================
--- linux.orig/drivers/firewire/fw-ohci.c
+++ linux/drivers/firewire/fw-ohci.c
@@ -258,19 +258,21 @@ static int ar_context_add_page(struct ar
 		free_page((unsigned long) ab);
 		return -ENOMEM;
 	}
-	dma_sync_single_for_cpu(dev, ab_bus, PAGE_SIZE, DMA_BIDIRECTIONAL);
+	dma_sync_single_for_cpu(dev, ab_bus, sizeof(ab->descriptor),
+				DMA_BIDIRECTIONAL);
 
-	memset(&ab->descriptor, 0, sizeof(ab->descriptor));
-	ab->descriptor.control        = cpu_to_le16(DESCRIPTOR_INPUT_MORE |
-						    DESCRIPTOR_STATUS |
-						    DESCRIPTOR_BRANCH_ALWAYS);
 	offset = offsetof(struct ar_buffer, data);
-	ab->descriptor.req_count      = cpu_to_le16(PAGE_SIZE - offset);
-	ab->descriptor.data_address   = cpu_to_le32(ab_bus + offset);
-	ab->descriptor.res_count      = cpu_to_le16(PAGE_SIZE - offset);
-	ab->descriptor.branch_address = 0;
+	ab->descriptor.req_count       = cpu_to_le16(PAGE_SIZE - offset);
+	ab->descriptor.control         = cpu_to_le16(DESCRIPTOR_INPUT_MORE |
+						     DESCRIPTOR_STATUS |
+						     DESCRIPTOR_BRANCH_ALWAYS);
+	ab->descriptor.data_address    = cpu_to_le32(ab_bus + offset);
+	ab->descriptor.branch_address  = 0;
+	ab->descriptor.res_count       = cpu_to_le16(PAGE_SIZE - offset);
+	ab->descriptor.transfer_status = 0;
 
-	dma_sync_single_for_device(dev, ab_bus, PAGE_SIZE, DMA_BIDIRECTIONAL);
+	dma_sync_single_for_device(dev, ab_bus, sizeof(ab->descriptor),
+				   DMA_BIDIRECTIONAL);
 
 	ctx->last_buffer->descriptor.branch_address = cpu_to_le32(ab_bus | 1);
 	ctx->last_buffer->next = ab;

-- 
Stefan Richter
-=====-=-=== =-=- =----
http://arcgraph.de/sr/


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] firewire: fw-ohci: avoid an atomic allocation
  2007-10-16 17:58     ` [PATCH] firewire: fw-ohci: optimize initialization of " Stefan Richter
@ 2007-10-16 18:30       ` Stefan Richter
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Richter @ 2007-10-16 18:30 UTC (permalink / raw)
  To: linux1394-devel; +Cc: linux-kernel, Kristian Høgsberg

All of the buffers which are allocated during fw-ohci's pci_probe can be
allocated with GFP_KERNEL.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
---
 drivers/firewire/fw-ohci.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Index: linux-2.6.23-rc6/drivers/firewire/fw-ohci.c
===================================================================
--- linux-2.6.23-rc6.orig/drivers/firewire/fw-ohci.c
+++ linux-2.6.23-rc6/drivers/firewire/fw-ohci.c
@@ -242,14 +242,14 @@ ohci_update_phy_reg(struct fw_card *card
 	return 0;
 }
 
-static int ar_context_add_page(struct ar_context *ctx)
+static int ar_context_add_page(struct ar_context *ctx, gfp_t gfp_mask)
 {
 	struct device *dev = ctx->ohci->card.device;
 	struct ar_buffer *ab;
 	dma_addr_t ab_bus;
 	size_t offset;
 
-	ab = (struct ar_buffer *) __get_free_page(GFP_ATOMIC);
+	ab = (struct ar_buffer *) __get_free_page(gfp_mask);
 	if (ab == NULL)
 		return -ENOMEM;
 
@@ -397,7 +397,7 @@ static void ar_context_tasklet(unsigned 
 			buffer = handle_ar_packet(ctx, buffer);
 
 		free_page((unsigned long)buffer);
-		ar_context_add_page(ctx);
+		ar_context_add_page(ctx, GFP_ATOMIC);
 	} else {
 		buffer = ctx->pointer;
 		ctx->pointer = end =
@@ -418,8 +418,8 @@ ar_context_init(struct ar_context *ctx, 
 	ctx->last_buffer = &ab;
 	tasklet_init(&ctx->tasklet, ar_context_tasklet, (unsigned long)ctx);
 
-	ar_context_add_page(ctx);
-	ar_context_add_page(ctx);
+	ar_context_add_page(ctx, GFP_KERNEL);
+	ar_context_add_page(ctx, GFP_KERNEL);
 	ctx->current_buffer = ab.next;
 	ctx->pointer = ctx->current_buffer->data;
 

-- 
Stefan Richter
-=====-=-=== =-=- =----
http://arcgraph.de/sr/


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH corrected] firewire: fw-ohci: fix DMA mapping for ar context
  2007-10-16 17:40   ` [PATCH corrected] " Stefan Richter
  2007-10-16 17:58     ` [PATCH] firewire: fw-ohci: optimize initialization of " Stefan Richter
@ 2007-10-16 19:49     ` Stefan Richter
  1 sibling, 0 replies; 6+ messages in thread
From: Stefan Richter @ 2007-10-16 19:49 UTC (permalink / raw)
  To: linux1394-devel; +Cc: linux-kernel, Kristian Høgsberg

I wrote:
> The CPU must not touch the buffer after it was DMA-mapped.
> 
> Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
> ---
>  drivers/firewire/fw-ohci.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> Index: linux/drivers/firewire/fw-ohci.c
> ===================================================================
> --- linux.orig/drivers/firewire/fw-ohci.c
> +++ linux/drivers/firewire/fw-ohci.c
> @@ -258,6 +258,7 @@ static int ar_context_add_page(struct ar
>  		free_page((unsigned long) ab);
>  		return -ENOMEM;
>  	}
> +	dma_sync_single_for_cpu(dev, ab_bus, PAGE_SIZE, DMA_BIDIRECTIONAL);
>  
>  	memset(&ab->descriptor, 0, sizeof(ab->descriptor));
>  	ab->descriptor.control        = cpu_to_le16(DESCRIPTOR_INPUT_MORE |
> 

This is still not complete:

in ar_context_add_page():
	ctx->last_buffer->descriptor.branch_address = ...;

in ar_context_tasklet():
	dma_unmap_single(ohci->card.device,
		le32_to_cpu(ab->descriptor.data_address) - offset,
		PAGE_SIZE, DMA_BIDIRECTIONAL);

They both access DMA-mapped areas.
-- 
Stefan Richter
-=====-=-=== =-=- =----
http://arcgraph.de/sr/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-10-16 19:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-16 17:25 [PATCH] firewire: fw-ohci: fix DMA mapping for ar context Stefan Richter
2007-10-16 17:35 ` Stefan Richter
2007-10-16 17:40   ` [PATCH corrected] " Stefan Richter
2007-10-16 17:58     ` [PATCH] firewire: fw-ohci: optimize initialization of " Stefan Richter
2007-10-16 18:30       ` [PATCH] firewire: fw-ohci: avoid an atomic allocation Stefan Richter
2007-10-16 19:49     ` [PATCH corrected] firewire: fw-ohci: fix DMA mapping for ar context Stefan Richter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®