1.1 --- a/pkg/landfall-examples/letux400_dma/letux400_dma.cc Tue Oct 24 17:38:28 2023 +0200
1.2 +++ b/pkg/landfall-examples/letux400_dma/letux400_dma.cc Tue Oct 24 17:40:43 2023 +0200
1.3 @@ -19,16 +19,14 @@
1.4 * Boston, MA 02110-1301, USA
1.5 */
1.6
1.7 +#include <l4/devices/dma.h>
1.8 #include <l4/devices/cpm-jz4730.h>
1.9 #include <l4/devices/dma-jz4730.h>
1.10 #include <l4/devices/memory.h>
1.11
1.12 #include <l4/re/c/util/cap_alloc.h>
1.13 #include <l4/re/c/dataspace.h>
1.14 -#include <l4/re/c/dma_space.h>
1.15 -#include <l4/re/c/mem_alloc.h>
1.16 #include <l4/re/c/rm.h>
1.17 -#include <l4/re/protocols.h>
1.18
1.19 #include <l4/sys/err.h>
1.20 #include <l4/sys/factory.h>
1.21 @@ -36,8 +34,6 @@
1.22 #include <l4/sys/irq.h>
1.23 #include <l4/sys/rcv_endpoint.h>
1.24
1.25 -#include <l4/vbus/vbus.h>
1.26 -
1.27 #include <stdio.h>
1.28 #include <string.h>
1.29 #include <unistd.h>
1.30 @@ -61,88 +57,27 @@
1.31 long err;
1.32 void *cpm;
1.33 void *dmac, *dma0;
1.34 - l4_cap_idx_t dma, vbus;
1.35 -
1.36 - dma = l4re_util_cap_alloc();
1.37 - vbus = l4re_env_get_cap("vbus");
1.38 -
1.39 - if (l4_is_invalid_cap(dma))
1.40 - {
1.41 - printf("Could not allocate DMA capability.\n");
1.42 - return 1;
1.43 - }
1.44 -
1.45 - /* Create the DMA space. */
1.46 -
1.47 - err = l4_error(l4_factory_create(l4re_env()->mem_alloc, L4RE_PROTO_DMA_SPACE, dma));
1.48 -
1.49 - if (err)
1.50 - {
1.51 - printf("Could not create DMA space: %s\n", l4sys_errtostr(err));
1.52 - return 1;
1.53 - }
1.54 -
1.55 - l4vbus_device_handle_t device = L4VBUS_NULL;
1.56 - l4vbus_resource_t dma_resource;
1.57 -
1.58 - if (!find_resource(&device, &dma_resource, L4VBUS_RESOURCE_DMA_DOMAIN))
1.59 - {
1.60 - printf("Could not find DMA domain.\n");
1.61 - return 1;
1.62 - }
1.63 -
1.64 - err = l4vbus_assign_dma_domain(vbus, dma_resource.start,
1.65 - L4VBUS_DMAD_BIND | L4VBUS_DMAD_L4RE_DMA_SPACE,
1.66 - dma);
1.67 -
1.68 - if (err)
1.69 - {
1.70 - printf("Could not assign DMA space: %s\n", l4sys_errtostr(err));
1.71 - return 1;
1.72 - }
1.73
1.74 /* Allocate memory to test transfers. */
1.75
1.76 l4_cap_idx_t ds0_mem, ds1_mem;
1.77 - l4_size_t ds0_size = L4_PAGESIZE, ds0_psize, ds1_size = L4_PAGESIZE, ds1_psize;
1.78 + l4_size_t ds0_size = L4_PAGESIZE, ds1_size = L4_PAGESIZE;
1.79 l4_addr_t ds0_addr, ds1_addr;
1.80 l4re_dma_space_dma_addr_t ds0_paddr, ds1_paddr;
1.81
1.82 - ds0_mem = l4re_util_cap_alloc();
1.83 - ds1_mem = l4re_util_cap_alloc();
1.84 + err = get_dma_region(ds0_size, 8, &ds0_addr, &ds0_paddr, &ds0_mem);
1.85
1.86 - if (l4_is_invalid_cap(ds0_mem) || l4_is_invalid_cap(ds1_mem))
1.87 - {
1.88 - printf("Could not allocate memory capabilities.\n");
1.89 - return 1;
1.90 - }
1.91 -
1.92 - if (l4re_ma_alloc_align(ds0_size, ds0_mem, L4RE_MA_CONTINUOUS | L4RE_MA_PINNED, 8) ||
1.93 - l4re_ma_alloc_align(ds1_size, ds1_mem, L4RE_MA_CONTINUOUS | L4RE_MA_PINNED, 8))
1.94 + if (err)
1.95 {
1.96 - printf("Could not allocate memory.\n");
1.97 + printf("Could not allocate region #0.\n");
1.98 return 1;
1.99 }
1.100
1.101 - if (l4re_rm_attach((void **) &ds0_addr, ds0_size,
1.102 - L4RE_RM_F_SEARCH_ADDR | L4RE_RM_F_EAGER_MAP | L4RE_RM_F_RW,
1.103 - ds0_mem, 0, L4_PAGESHIFT) ||
1.104 - l4re_rm_attach((void **) &ds1_addr, ds1_size,
1.105 - L4RE_RM_F_SEARCH_ADDR | L4RE_RM_F_EAGER_MAP | L4RE_RM_F_RW,
1.106 - ds1_mem, 0, L4_PAGESHIFT))
1.107 - {
1.108 - printf("Could not map memory.\n");
1.109 - return 1;
1.110 - }
1.111 -
1.112 - err = l4re_dma_space_map(dma, ds0_mem | L4_CAP_FPAGE_RW, 0, &ds0_psize, 0,
1.113 - L4RE_DMA_SPACE_BIDIRECTIONAL, &ds0_paddr) ||
1.114 - l4re_dma_space_map(dma, ds1_mem | L4_CAP_FPAGE_RW, 0, &ds1_psize, 0,
1.115 - L4RE_DMA_SPACE_BIDIRECTIONAL, &ds1_paddr);
1.116 + err = get_dma_region(ds1_size, 8, &ds1_addr, &ds1_paddr, &ds1_mem);
1.117
1.118 if (err)
1.119 {
1.120 - printf("Could not get physical addresses for memory: %s\n", l4sys_errtostr(err));
1.121 + printf("Could not allocate region #1.\n");
1.122 return 1;
1.123 }
1.124
1.125 @@ -253,13 +188,19 @@
1.126
1.127 printf("Transfer from %llx to %llx...\n", ds0_paddr, ds1_paddr);
1.128
1.129 - unsigned int ntransferred = jz4730_dma_transfer(dma0, (uint32_t) ds0_paddr,
1.130 - (uint32_t) ds1_paddr,
1.131 - L4_PAGESIZE / 4,
1.132 - Dma_trans_unit_size_32_bit,
1.133 - Dma_request_auto);
1.134 + unsigned int count = L4_PAGESIZE / 4;
1.135
1.136 - printf("Transferred: %d\n", ntransferred);
1.137 + unsigned int to_transfer = jz4730_dma_transfer(dma0, (uint32_t) ds0_paddr,
1.138 + (uint32_t) ds1_paddr,
1.139 + count,
1.140 + 1, 1,
1.141 + 4, 4,
1.142 + 4,
1.143 + Dma_request_auto);
1.144 +
1.145 + unsigned int transferred = to_transfer ? count - jz4730_dma_wait(dma0) : 0;
1.146 +
1.147 + printf("Transferred: %d\n", transferred);
1.148 printf("Source: %s\n", (char *) ds0_addr);
1.149 printf("Destination: %s\n", (char *) ds1_addr);
1.150