# HG changeset patch # User Paul Boddie # Date 1698162043 -7200 # Node ID ba9d8393e52269d4dcb2d21444a8ae48ec51533b # Parent d72422ee856905db2660f099253b5969f2be4f06 Updated the Letux 400 DMA example to use the revised DMA functionality. diff -r d72422ee8569 -r ba9d8393e522 pkg/landfall-examples/letux400_dma/letux400_dma.cc --- a/pkg/landfall-examples/letux400_dma/letux400_dma.cc Tue Oct 24 17:38:28 2023 +0200 +++ b/pkg/landfall-examples/letux400_dma/letux400_dma.cc Tue Oct 24 17:40:43 2023 +0200 @@ -19,16 +19,14 @@ * Boston, MA 02110-1301, USA */ +#include #include #include #include #include #include -#include -#include #include -#include #include #include @@ -36,8 +34,6 @@ #include #include -#include - #include #include #include @@ -61,88 +57,27 @@ long err; void *cpm; void *dmac, *dma0; - l4_cap_idx_t dma, vbus; - - dma = l4re_util_cap_alloc(); - vbus = l4re_env_get_cap("vbus"); - - if (l4_is_invalid_cap(dma)) - { - printf("Could not allocate DMA capability.\n"); - return 1; - } - - /* Create the DMA space. */ - - err = l4_error(l4_factory_create(l4re_env()->mem_alloc, L4RE_PROTO_DMA_SPACE, dma)); - - if (err) - { - printf("Could not create DMA space: %s\n", l4sys_errtostr(err)); - return 1; - } - - l4vbus_device_handle_t device = L4VBUS_NULL; - l4vbus_resource_t dma_resource; - - if (!find_resource(&device, &dma_resource, L4VBUS_RESOURCE_DMA_DOMAIN)) - { - printf("Could not find DMA domain.\n"); - return 1; - } - - err = l4vbus_assign_dma_domain(vbus, dma_resource.start, - L4VBUS_DMAD_BIND | L4VBUS_DMAD_L4RE_DMA_SPACE, - dma); - - if (err) - { - printf("Could not assign DMA space: %s\n", l4sys_errtostr(err)); - return 1; - } /* Allocate memory to test transfers. */ l4_cap_idx_t ds0_mem, ds1_mem; - l4_size_t ds0_size = L4_PAGESIZE, ds0_psize, ds1_size = L4_PAGESIZE, ds1_psize; + l4_size_t ds0_size = L4_PAGESIZE, ds1_size = L4_PAGESIZE; l4_addr_t ds0_addr, ds1_addr; l4re_dma_space_dma_addr_t ds0_paddr, ds1_paddr; - ds0_mem = l4re_util_cap_alloc(); - ds1_mem = l4re_util_cap_alloc(); + err = get_dma_region(ds0_size, 8, &ds0_addr, &ds0_paddr, &ds0_mem); - if (l4_is_invalid_cap(ds0_mem) || l4_is_invalid_cap(ds1_mem)) - { - printf("Could not allocate memory capabilities.\n"); - return 1; - } - - if (l4re_ma_alloc_align(ds0_size, ds0_mem, L4RE_MA_CONTINUOUS | L4RE_MA_PINNED, 8) || - l4re_ma_alloc_align(ds1_size, ds1_mem, L4RE_MA_CONTINUOUS | L4RE_MA_PINNED, 8)) + if (err) { - printf("Could not allocate memory.\n"); + printf("Could not allocate region #0.\n"); return 1; } - if (l4re_rm_attach((void **) &ds0_addr, ds0_size, - L4RE_RM_F_SEARCH_ADDR | L4RE_RM_F_EAGER_MAP | L4RE_RM_F_RW, - ds0_mem, 0, L4_PAGESHIFT) || - l4re_rm_attach((void **) &ds1_addr, ds1_size, - L4RE_RM_F_SEARCH_ADDR | L4RE_RM_F_EAGER_MAP | L4RE_RM_F_RW, - ds1_mem, 0, L4_PAGESHIFT)) - { - printf("Could not map memory.\n"); - return 1; - } - - err = l4re_dma_space_map(dma, ds0_mem | L4_CAP_FPAGE_RW, 0, &ds0_psize, 0, - L4RE_DMA_SPACE_BIDIRECTIONAL, &ds0_paddr) || - l4re_dma_space_map(dma, ds1_mem | L4_CAP_FPAGE_RW, 0, &ds1_psize, 0, - L4RE_DMA_SPACE_BIDIRECTIONAL, &ds1_paddr); + err = get_dma_region(ds1_size, 8, &ds1_addr, &ds1_paddr, &ds1_mem); if (err) { - printf("Could not get physical addresses for memory: %s\n", l4sys_errtostr(err)); + printf("Could not allocate region #1.\n"); return 1; } @@ -253,13 +188,19 @@ printf("Transfer from %llx to %llx...\n", ds0_paddr, ds1_paddr); - unsigned int ntransferred = jz4730_dma_transfer(dma0, (uint32_t) ds0_paddr, - (uint32_t) ds1_paddr, - L4_PAGESIZE / 4, - Dma_trans_unit_size_32_bit, - Dma_request_auto); + unsigned int count = L4_PAGESIZE / 4; - printf("Transferred: %d\n", ntransferred); + unsigned int to_transfer = jz4730_dma_transfer(dma0, (uint32_t) ds0_paddr, + (uint32_t) ds1_paddr, + count, + 1, 1, + 4, 4, + 4, + Dma_request_auto); + + unsigned int transferred = to_transfer ? count - jz4730_dma_wait(dma0) : 0; + + printf("Transferred: %d\n", transferred); printf("Source: %s\n", (char *) ds0_addr); printf("Destination: %s\n", (char *) ds1_addr);