# HG changeset patch # User Paul Boddie # Date 1698161619 -7200 # Node ID 4add12ca045f4be5083ff6eafdde3ddbb2ea9783 # Parent 8cc46c51babe18844cb8c79e5072ed089ae7f600 Employed the DMA region allocation utilities. diff -r 8cc46c51babe -r 4add12ca045f pkg/devices/lcd/src/jz4740/lcd-jz4740-device.cc --- a/pkg/devices/lcd/src/jz4740/lcd-jz4740-device.cc Tue Oct 24 17:32:54 2023 +0200 +++ b/pkg/devices/lcd/src/jz4740/lcd-jz4740-device.cc Tue Oct 24 17:33:39 2023 +0200 @@ -19,6 +19,7 @@ * Boston, MA 02110-1301, USA */ +#include #include #include #include @@ -26,13 +27,8 @@ #include "lcd-jz4740-device.h" #include -#include -#include #include -#include -#include #include -#include #include #include @@ -124,100 +120,35 @@ int Lcd_jz4740_device::_setup_memory() { - // Framebuffer and descriptor sizes. - - unsigned long fb_size, desc_size; - - // Size of physically contiguous regions to be allocated. - - l4_size_t fb_size_out, desc_size_out; - - // Memory allocation capabilities. - - l4_cap_idx_t descmem, dma, vbus; - // Test for existing setup. if (fb_vaddr) return 0; - // Create the DMA space. - - dma = ipc_cap_alloc(); - - if (l4_is_invalid_cap(dma)) - return 1; - - vbus = l4re_env_get_cap("vbus"); - - if (l4_is_invalid_cap(vbus)) - return 1; - - if (l4_error(l4_factory_create(l4re_env()->mem_alloc, L4RE_PROTO_DMA_SPACE, dma))) - return 1; - - l4vbus_device_handle_t device = L4VBUS_NULL; - l4vbus_resource_t dma_resource; - - if (!find_resource(&device, &dma_resource, L4VBUS_RESOURCE_DMA_DOMAIN)) - return 1; - - if (l4vbus_assign_dma_domain(vbus, dma_resource.start, - L4VBUS_DMAD_BIND | L4VBUS_DMAD_L4RE_DMA_SPACE, - dma)) - return 1; - // Obtain the memory requirements. Lcd_jz4740_chip *chip = static_cast(_chip); - fb_size = chip->get_screen_size(); - desc_size = chip->get_descriptors_size(); + // Framebuffer and descriptor sizes. + + unsigned long fb_size = chip->get_screen_size(), + desc_size = chip->get_descriptors_size(); // Allocate memory for the framebuffer at 2**6 == 64 byte == 16 word alignment, // also for the descriptors. // NOTE: A 64 word burst mode is available on the JZ4780 that would // NOTE: necessitate 64 word alignment for the framebuffer. - const l4_size_t alloc_flags = L4RE_MA_CONTINUOUS | L4RE_MA_PINNED; - const l4re_rm_flags_t attach_flags = L4RE_RM_F_SEARCH_ADDR | L4RE_RM_F_RW; - - // Map the allocated memory, obtaining virtual addresses. - - fb_vaddr = 0; - desc_vaddr = 0; + long err = get_dma_region(fb_size, 8, &fb_vaddr, &fb_paddr, &_fbmem); - if (ipc_new_dataspace(fb_size, alloc_flags, 8, &_fbmem)) - return 1; - - if (ipc_new_dataspace(desc_size, alloc_flags, 6, &descmem)) - return 1; - - if (ipc_attach_dataspace_align(_fbmem, fb_size, attach_flags, 8, (void **) &fb_vaddr)) - return 1; - - if (ipc_attach_dataspace_align(descmem, desc_size, attach_flags, 6, (void **) &desc_vaddr)) + if (err) return 1; - // Obtain physical addresses for the framebuffer and descriptors. - - fb_paddr = 0; - desc_paddr = 0; - - fb_size_out = fb_size; - desc_size_out = desc_size; + l4_cap_idx_t descmem; - if (l4re_dma_space_map(dma, _fbmem | L4_CAP_FPAGE_RW, 0, &fb_size_out, 0, - L4RE_DMA_SPACE_TO_DEVICE, &fb_paddr)) - return 1; + err = get_dma_region(desc_size, 6, &desc_vaddr, &desc_paddr, &descmem); - if (l4re_dma_space_map(dma, descmem | L4_CAP_FPAGE_RW, 0, &desc_size_out, 0, - L4RE_DMA_SPACE_TO_DEVICE, &desc_paddr)) - return 1; - - // Test the mapped region sizes. - - if ((fb_size_out != fb_size) || (desc_size_out != desc_size)) + if (err) return 1; return 0;