Skip to content

Commit a572e68

Browse files
cladischStefan Richter
authored andcommitted
firewire: ohci: fix isochronous DMA synchronization
Add the dma_sync_single_* calls necessary to ensure proper cache synchronization for isochronous data buffers on non-coherent architectures. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
1 parent 32eaeae commit a572e68

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

‎drivers/firewire/ohci.c‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ struct context {
126126
struct fw_ohci *ohci;
127127
u32 regs;
128128
int total_allocation;
129+
u32 current_bus;
129130
bool running;
130131
bool flushing;
131132

@@ -1057,6 +1058,7 @@ static void context_tasklet(unsigned long data)
10571058
address = le32_to_cpu(last->branch_address);
10581059
z = address & 0xf;
10591060
address &= ~0xf;
1061+
ctx->current_bus = address;
10601062

10611063
/* If the branch address points to a buffer outside of the
10621064
* current buffer, advance to the next buffer. */
@@ -2697,6 +2699,7 @@ static int handle_ir_packet_per_buffer(struct context *context,
26972699
struct iso_context *ctx =
26982700
container_of(context, struct iso_context, context);
26992701
struct descriptor *pd;
2702+
u32 buffer_dma;
27002703
__le32 *ir_header;
27012704
void *p;
27022705

@@ -2707,6 +2710,16 @@ static int handle_ir_packet_per_buffer(struct context *context,
27072710
/* Descriptor(s) not done yet, stop iteration */
27082711
return 0;
27092712

2713+
while (!(d->control & cpu_to_le16(DESCRIPTOR_BRANCH_ALWAYS))) {
2714+
d++;
2715+
buffer_dma = le32_to_cpu(d->data_address);
2716+
dma_sync_single_range_for_cpu(context->ohci->card.device,
2717+
buffer_dma & PAGE_MASK,
2718+
buffer_dma & ~PAGE_MASK,
2719+
le16_to_cpu(d->req_count),
2720+
DMA_FROM_DEVICE);
2721+
}
2722+
27102723
p = last + 1;
27112724
copy_iso_headers(ctx, p);
27122725

@@ -2729,11 +2742,19 @@ static int handle_ir_buffer_fill(struct context *context,
27292742
{
27302743
struct iso_context *ctx =
27312744
container_of(context, struct iso_context, context);
2745+
u32 buffer_dma;
27322746

27332747
if (!last->transfer_status)
27342748
/* Descriptor(s) not done yet, stop iteration */
27352749
return 0;
27362750

2751+
buffer_dma = le32_to_cpu(last->data_address);
2752+
dma_sync_single_range_for_cpu(context->ohci->card.device,
2753+
buffer_dma & PAGE_MASK,
2754+
buffer_dma & ~PAGE_MASK,
2755+
le16_to_cpu(last->req_count),
2756+
DMA_FROM_DEVICE);
2757+
27372758
if (le16_to_cpu(last->control) & DESCRIPTOR_IRQ_ALWAYS)
27382759
ctx->base.callback.mc(&ctx->base,
27392760
le32_to_cpu(last->data_address) +
@@ -2744,6 +2765,43 @@ static int handle_ir_buffer_fill(struct context *context,
27442765
return 1;
27452766
}
27462767

2768+
static inline void sync_it_packet_for_cpu(struct context *context,
2769+
struct descriptor *pd)
2770+
{
2771+
__le16 control;
2772+
u32 buffer_dma;
2773+
2774+
/* only packets beginning with OUTPUT_MORE* have data buffers */
2775+
if (pd->control & cpu_to_le16(DESCRIPTOR_BRANCH_ALWAYS))
2776+
return;
2777+
2778+
/* skip over the OUTPUT_MORE_IMMEDIATE descriptor */
2779+
pd += 2;
2780+
2781+
/*
2782+
* If the packet has a header, the first OUTPUT_MORE/LAST descriptor's
2783+
* data buffer is in the context program's coherent page and must not
2784+
* be synced.
2785+
*/
2786+
if ((le32_to_cpu(pd->data_address) & PAGE_MASK) ==
2787+
(context->current_bus & PAGE_MASK)) {
2788+
if (pd->control & cpu_to_le16(DESCRIPTOR_BRANCH_ALWAYS))
2789+
return;
2790+
pd++;
2791+
}
2792+
2793+
do {
2794+
buffer_dma = le32_to_cpu(pd->data_address);
2795+
dma_sync_single_range_for_cpu(context->ohci->card.device,
2796+
buffer_dma & PAGE_MASK,
2797+
buffer_dma & ~PAGE_MASK,
2798+
le16_to_cpu(pd->req_count),
2799+
DMA_TO_DEVICE);
2800+
control = pd->control;
2801+
pd++;
2802+
} while (!(control & cpu_to_le16(DESCRIPTOR_BRANCH_ALWAYS)));
2803+
}
2804+
27472805
static int handle_it_packet(struct context *context,
27482806
struct descriptor *d,
27492807
struct descriptor *last)
@@ -2760,6 +2818,8 @@ static int handle_it_packet(struct context *context,
27602818
/* Descriptor(s) not done yet, stop iteration */
27612819
return 0;
27622820

2821+
sync_it_packet_for_cpu(context, d);
2822+
27632823
i = ctx->header_length;
27642824
if (i + 4 < PAGE_SIZE) {
27652825
/* Present this value as big-endian to match the receive code */
@@ -3129,6 +3189,10 @@ static int queue_iso_transmit(struct iso_context *ctx,
31293189
page_bus = page_private(buffer->pages[page]);
31303190
pd[i].data_address = cpu_to_le32(page_bus + offset);
31313191

3192+
dma_sync_single_range_for_device(ctx->context.ohci->card.device,
3193+
page_bus, offset, length,
3194+
DMA_TO_DEVICE);
3195+
31323196
payload_index += length;
31333197
}
31343198

@@ -3153,6 +3217,7 @@ static int queue_iso_packet_per_buffer(struct iso_context *ctx,
31533217
struct fw_iso_buffer *buffer,
31543218
unsigned long payload)
31553219
{
3220+
struct device *device = ctx->context.ohci->card.device;
31563221
struct descriptor *d, *pd;
31573222
dma_addr_t d_bus, page_bus;
31583223
u32 z, header_z, rest;
@@ -3207,6 +3272,10 @@ static int queue_iso_packet_per_buffer(struct iso_context *ctx,
32073272
page_bus = page_private(buffer->pages[page]);
32083273
pd->data_address = cpu_to_le32(page_bus + offset);
32093274

3275+
dma_sync_single_range_for_device(device, page_bus,
3276+
offset, length,
3277+
DMA_FROM_DEVICE);
3278+
32103279
offset = (offset + length) & ~PAGE_MASK;
32113280
rest -= length;
32123281
if (offset == 0)
@@ -3266,6 +3335,10 @@ static int queue_iso_buffer_fill(struct iso_context *ctx,
32663335
page_bus = page_private(buffer->pages[page]);
32673336
d->data_address = cpu_to_le32(page_bus + offset);
32683337

3338+
dma_sync_single_range_for_device(ctx->context.ohci->card.device,
3339+
page_bus, offset, length,
3340+
DMA_FROM_DEVICE);
3341+
32693342
rest -= length;
32703343
offset = 0;
32713344
page++;

0 commit comments

Comments
 (0)