[dma] Modify DMA API to simplify calculation of medial addresses

Redefine the value stored within a DMA mapping to be the offset
between physical addresses and DMA addresses within the mapped region.

Provide a dma() wrapper function to calculate the DMA address for any
pointer within a mapped region, thereby simplifying the use cases when
a device needs to be given addresses other than the region start
address.

On a platform using the "flat" DMA implementation the DMA offset for
any mapped region is always zero, with the result that dma_map() can
be optimised away completely and dma() reduces to a straightforward
call to virt_to_phys().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2020-11-25 16:15:55 +00:00
parent 24ef743778
commit cf12a41703
7 changed files with 100 additions and 58 deletions
+3 -7
View File
@@ -513,7 +513,7 @@ int intel_create_ring ( struct intel_nic *intel, struct intel_ring *ring ) {
memset ( ring->desc, 0, ring->len );
/* Program ring address */
address = ring->map.addr;
address = dma ( &ring->map, ring->desc );
writel ( ( address & 0xffffffffUL ),
( intel->regs + ring->reg + INTEL_xDBAL ) );
if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) {
@@ -571,7 +571,6 @@ void intel_refill_rx ( struct intel_nic *intel ) {
struct dma_mapping *map;
unsigned int rx_idx;
unsigned int rx_tail;
physaddr_t address;
unsigned int refilled = 0;
/* Refill ring */
@@ -596,8 +595,7 @@ void intel_refill_rx ( struct intel_nic *intel ) {
intel->rx.ring.prod++;
/* Populate receive descriptor */
address = map->addr;
intel->rx.ring.describe ( rx, address, 0 );
intel->rx.ring.describe ( rx, dma ( map, iobuf->data ), 0 );
DBGC2 ( intel, "INTEL %p RX %d is [%lx,%lx)\n",
intel, rx_idx, virt_to_phys ( iobuf->data ),
@@ -762,7 +760,6 @@ int intel_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
struct dma_mapping *map;
unsigned int tx_idx;
unsigned int tx_tail;
physaddr_t address;
size_t len;
int rc;
@@ -783,9 +780,8 @@ int intel_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
intel->tx.ring.prod++;
/* Populate transmit descriptor */
address = map->addr;
len = iob_len ( iobuf );
intel->tx.ring.describe ( tx, address, len );
intel->tx.ring.describe ( tx, dma ( map, iobuf->data ), len );
wmb();
/* Notify card that there are packets ready to transmit */