diff options
author | Denis Orlov <denorl2009@gmail.com> | 2023-06-05 00:45:01 +0300 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2023-06-06 09:12:28 +0200 |
commit | 00ac36614d66c25702ee712e91c793d2ac7dd9a2 (patch) | |
tree | bb8d5612534c523151c9067561c4a6fd2b2a8eba /drivers/net/macb.c | |
parent | 9d1bfb8417329b998407a7141d5a8558f735bf40 (diff) | |
download | barebox-00ac36614d66c25702ee712e91c793d2ac7dd9a2.tar.gz barebox-00ac36614d66c25702ee712e91c793d2ac7dd9a2.tar.xz |
dma: rework dma_sync_single_for_*() interface
Currently, a lot of code handles dma_addr_t values as if they actually
hold CPU addresses. However, this is not always true. For example, MIPS
architecture requires an explicit conversion from the physical address
space to some virtual address space segment to get a valid CPU-side
pointer. Another issue is that DMA ranges that may be specified in a
device tree will not work this way. To get from a virtual address to a
dma handle and vice versa we need to add/subtract some offset, which is
calculated from "dma-ranges" property. Only dma_map_single() was doing
this, but dma_sync_single_for_*() also should.
Improve the interface by adding 'struct device' as the first argument to
the dma_sync_single_for_*(). This allows to do cpu_to_dma/dma_to_cpu()
conversions in common code and call into arch-specific code with proper
cpu-side addresses. To make things more clear, make the virtual address
argument of those arch-side functions be properly represented with a
void* type.
Apply the required changes in device drivers that use the affected
functions, making them pass the appropriate device pointer.
Signed-off-by: Denis Orlov <denorl2009@gmail.com>
Link: https://lore.barebox.org/20230604215002.20240-2-denorl2009@gmail.com
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/net/macb.c')
-rw-r--r-- | drivers/net/macb.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/drivers/net/macb.c b/drivers/net/macb.c index 9dd273a504..4b89c59580 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -119,7 +119,7 @@ static int macb_send(struct eth_device *edev, void *packet, macb->tx_ring[tx_head].ctrl = ctrl; macb->tx_ring[tx_head].addr = (ulong)packet; barrier(); - dma_sync_single_for_device((unsigned long)packet, length, DMA_TO_DEVICE); + dma_sync_single_for_device(macb->dev, (unsigned long)packet, length, DMA_TO_DEVICE); macb_writel(macb, NCR, MACB_BIT(TE) | MACB_BIT(RE) | MACB_BIT(TSTART)); start = get_time_ns(); @@ -132,7 +132,7 @@ static int macb_send(struct eth_device *edev, void *packet, break; } } while (!is_timeout(start, 100 * MSECOND)); - dma_sync_single_for_cpu((unsigned long)packet, length, DMA_TO_DEVICE); + dma_sync_single_for_cpu(macb->dev, (unsigned long)packet, length, DMA_TO_DEVICE); if (ctrl & MACB_BIT(TX_UNDERRUN)) dev_err(macb->dev, "TX underrun\n"); @@ -182,10 +182,10 @@ static int gem_recv(struct eth_device *edev) status = macb->rx_ring[macb->rx_tail].ctrl; length = MACB_BFEXT(RX_FRMLEN, status); buffer = macb->rx_buffer + macb->rx_buffer_size * macb->rx_tail; - dma_sync_single_for_cpu((unsigned long)buffer, length, + dma_sync_single_for_cpu(macb->dev, (unsigned long)buffer, length, DMA_FROM_DEVICE); net_receive(edev, buffer, length); - dma_sync_single_for_device((unsigned long)buffer, length, + dma_sync_single_for_device(macb->dev, (unsigned long)buffer, length, DMA_FROM_DEVICE); macb->rx_ring[macb->rx_tail].addr &= ~MACB_BIT(RX_USED); barrier(); @@ -229,22 +229,22 @@ static int macb_recv(struct eth_device *edev) headlen = macb->rx_buffer_size * (macb->rx_ring_size - macb->rx_tail); taillen = length - headlen; - dma_sync_single_for_cpu((unsigned long)buffer, + dma_sync_single_for_cpu(macb->dev, (unsigned long)buffer, headlen, DMA_FROM_DEVICE); memcpy(macb->rx_packet_buf, buffer, headlen); - dma_sync_single_for_cpu((unsigned long)macb->rx_buffer, + dma_sync_single_for_cpu(macb->dev, (unsigned long)macb->rx_buffer, taillen, DMA_FROM_DEVICE); memcpy(macb->rx_packet_buf + headlen, macb->rx_buffer, taillen); - dma_sync_single_for_device((unsigned long)buffer, + dma_sync_single_for_device(macb->dev, (unsigned long)buffer, headlen, DMA_FROM_DEVICE); - dma_sync_single_for_device((unsigned long)macb->rx_buffer, + dma_sync_single_for_device(macb->dev, (unsigned long)macb->rx_buffer, taillen, DMA_FROM_DEVICE); net_receive(edev, macb->rx_packet_buf, length); } else { - dma_sync_single_for_cpu((unsigned long)buffer, length, + dma_sync_single_for_cpu(macb->dev, (unsigned long)buffer, length, DMA_FROM_DEVICE); net_receive(edev, buffer, length); - dma_sync_single_for_device((unsigned long)buffer, length, + dma_sync_single_for_device(macb->dev, (unsigned long)buffer, length, DMA_FROM_DEVICE); } barrier(); |