summaryrefslogtreecommitdiffstats
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/ipxe/dma.h22
-rw-r--r--src/include/ipxe/iobuf.h55
-rw-r--r--src/include/ipxe/netdevice.h6
3 files changed, 61 insertions, 22 deletions
diff --git a/src/include/ipxe/dma.h b/src/include/ipxe/dma.h
index 842c9d6ef..b3fa24e47 100644
--- a/src/include/ipxe/dma.h
+++ b/src/include/ipxe/dma.h
@@ -12,7 +12,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
#include <ipxe/api.h>
#include <ipxe/io.h>
-#include <ipxe/iobuf.h>
#include <ipxe/malloc.h>
#include <config/ioapi.h>
@@ -385,25 +384,4 @@ dma_set_mask_64bit ( struct dma_device *dma ) {
dma_set_mask ( dma, ~( ( physaddr_t ) 0 ) );
}
-/**
- * Map I/O buffer for transmitting data to device
- *
- * @v dma DMA device
- * @v map DMA mapping to fill in
- * @v iobuf I/O buffer
- * @ret rc Return status code
- */
-static inline __always_inline int
-dma_map_tx_iob ( struct dma_device *dma, struct dma_mapping *map,
- struct io_buffer *iobuf ) {
-
- /* Map I/O buffer */
- return dma_map ( dma, map, virt_to_phys ( iobuf->data ),
- iob_len ( iobuf ), DMA_TX );
-}
-
-extern struct io_buffer * dma_alloc_rx_iob ( struct dma_device *dma,
- struct dma_mapping *map,
- size_t len );
-
#endif /* _IPXE_DMA_H */
diff --git a/src/include/ipxe/iobuf.h b/src/include/ipxe/iobuf.h
index b40ade350..630a7753c 100644
--- a/src/include/ipxe/iobuf.h
+++ b/src/include/ipxe/iobuf.h
@@ -12,6 +12,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
#include <assert.h>
#include <ipxe/list.h>
+#include <ipxe/dma.h>
/**
* Minimum I/O buffer length
@@ -38,6 +39,9 @@ struct io_buffer {
*/
struct list_head list;
+ /** DMA mapping */
+ struct dma_mapping map;
+
/** Start of the buffer */
void *head;
/** Start of data */
@@ -210,10 +214,61 @@ static inline void iob_populate ( struct io_buffer *iobuf,
(iobuf) = NULL; \
__iobuf; } )
+/**
+ * Map I/O buffer for transmit DMA
+ *
+ * @v iobuf I/O buffer
+ * @v dma DMA device
+ * @ret rc Return status code
+ */
+static inline __always_inline int iob_map_tx ( struct io_buffer *iobuf,
+ struct dma_device *dma ) {
+ return dma_map ( dma, &iobuf->map, virt_to_phys ( iobuf->data ),
+ iob_len ( iobuf ), DMA_TX );
+}
+
+/**
+ * Map empty I/O buffer for receive DMA
+ *
+ * @v iobuf I/O buffer
+ * @v dma DMA device
+ * @ret rc Return status code
+ */
+static inline __always_inline int iob_map_rx ( struct io_buffer *iobuf,
+ struct dma_device *dma ) {
+ assert ( iob_len ( iobuf ) == 0 );
+ return dma_map ( dma, &iobuf->map, virt_to_phys ( iobuf->data ),
+ iob_tailroom ( iobuf ), DMA_RX );
+}
+
+/**
+ * Get I/O buffer DMA address
+ *
+ * @v iobuf I/O buffer
+ * @ret addr DMA address
+ */
+static inline __always_inline physaddr_t iob_dma ( struct io_buffer *iobuf ) {
+ return dma ( &iobuf->map, iobuf->data );
+}
+
+/**
+ * Unmap I/O buffer for DMA
+ *
+ * @v iobuf I/O buffer
+ * @v dma DMA device
+ * @ret rc Return status code
+ */
+static inline __always_inline void iob_unmap ( struct io_buffer *iobuf ) {
+ dma_unmap ( &iobuf->map );
+}
+
extern struct io_buffer * __malloc alloc_iob_raw ( size_t len, size_t align,
size_t offset );
extern struct io_buffer * __malloc alloc_iob ( size_t len );
extern void free_iob ( struct io_buffer *iobuf );
+extern struct io_buffer * __malloc alloc_rx_iob ( size_t len,
+ struct dma_device *dma );
+extern void free_rx_iob ( struct io_buffer *iobuf );
extern void iob_pad ( struct io_buffer *iobuf, size_t min_len );
extern int iob_ensure_headroom ( struct io_buffer *iobuf, size_t len );
extern struct io_buffer * iob_concatenate ( struct list_head *list );
diff --git a/src/include/ipxe/netdevice.h b/src/include/ipxe/netdevice.h
index d498ab697..b9c651c71 100644
--- a/src/include/ipxe/netdevice.h
+++ b/src/include/ipxe/netdevice.h
@@ -246,6 +246,10 @@ struct net_device_operations {
*
* This method is guaranteed to be called only when the device
* is open.
+ *
+ * If the network device has an associated DMA device, then
+ * the I/O buffer will be automatically mapped for transmit
+ * DMA.
*/
int ( * transmit ) ( struct net_device *netdev,
struct io_buffer *iobuf );
@@ -358,6 +362,8 @@ struct net_device {
char name[NETDEV_NAME_LEN];
/** Underlying hardware device */
struct device *dev;
+ /** DMA device */
+ struct dma_device *dma;
/** Network device operations */
struct net_device_operations *op;