1.1 --- a/pkg/devices/util/src/dma.cc Fri Feb 16 23:11:25 2024 +0100
1.2 +++ b/pkg/devices/util/src/dma.cc Sat Feb 17 23:04:12 2024 +0100
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * DMA-related memory allocation utility functions.
1.6 *
1.7 - * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2023, 2024 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or
1.11 * modify it under the terms of the GNU General Public License as
1.12 @@ -38,13 +38,15 @@
1.13
1.14 // Allocate a memory region of the given size for DMA.
1.15
1.16 -long get_dma_region(unsigned long size, int align, l4_addr_t *vaddr,
1.17 - l4re_dma_space_dma_addr_t *paddr, l4_cap_idx_t *mem)
1.18 +long get_dma_region(unsigned long size, int align, struct dma_region *region)
1.19 {
1.20 // Memory allocation capabilities.
1.21
1.22 l4_cap_idx_t dma, vbus;
1.23
1.24 + region->size = 0;
1.25 + region->align = 0;
1.26 +
1.27 // Obtain capabilities for the DMA region and the vbus.
1.28
1.29 dma = ipc_cap_alloc();
1.30 @@ -82,21 +84,21 @@
1.31
1.32 // Map the allocated memory, obtaining a virtual address.
1.33
1.34 - *vaddr = 0;
1.35 + region->vaddr = 0;
1.36
1.37 - if (ipc_new_dataspace(size, alloc_flags, align, mem))
1.38 + if (ipc_new_dataspace(size, alloc_flags, align, ®ion->mem))
1.39 return -L4_ENOMEM;
1.40
1.41 - if (ipc_attach_dataspace_align(*mem, size, attach_flags, align, (void **) vaddr))
1.42 + if (ipc_attach_dataspace_align(region->mem, size, attach_flags, align, (void **) ®ion->vaddr))
1.43 return -L4_ENOMEM;
1.44
1.45 // Obtain a physical address.
1.46
1.47 l4_size_t size_out = size;
1.48 - *paddr = 0;
1.49 + region->paddr = 0;
1.50
1.51 - if (l4re_dma_space_map(dma, *mem | L4_CAP_FPAGE_RW, 0, &size_out, 0,
1.52 - L4RE_DMA_SPACE_TO_DEVICE, paddr))
1.53 + if (l4re_dma_space_map(dma, region->mem | L4_CAP_FPAGE_RW, 0, &size_out, 0,
1.54 + L4RE_DMA_SPACE_TO_DEVICE, ®ion->paddr))
1.55 return -L4_ENOMEM;
1.56
1.57 // Test the mapped region size.
1.58 @@ -104,5 +106,8 @@
1.59 if (size_out != size)
1.60 return -L4_ENOMEM;
1.61
1.62 + region->size = size_out;
1.63 + region->align = align;
1.64 +
1.65 return L4_EOK;
1.66 }