From 0d6d9bd4c1d587d62508ad6e8ae68fd4094bc427 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 22 Sep 2025 13:09:10 -0400 Subject: kern: dma: Add DMA address helpers Signed-off-by: Ian Moffett --- src/sys/include/io/dma/alloc.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/sys/include/io') diff --git a/src/sys/include/io/dma/alloc.h b/src/sys/include/io/dma/alloc.h index b1034c4..f18fc1d 100644 --- a/src/sys/include/io/dma/alloc.h +++ b/src/sys/include/io/dma/alloc.h @@ -31,8 +31,31 @@ #define _DMA_ALLOC_H_ #include +#include #include +/* + * Represents a physical address that may be used + * with direct memory access + */ +typedef uintptr_t dma_addr_t; + +/* + * Convert virtual DMA pages to physical DMA + * addresses. + */ +__always_inline static dma_addr_t +dma_get_pa(void *pgbuf) +{ + return VIRT_TO_PHYS(pgbuf); +} + +__always_inline static void * +dma_get_va(dma_addr_t pa) +{ + return PHYS_TO_VIRT(pa); +} + /* * Allocate a buffer suitable for Direct Memory * Access -- cgit v1.2.3