1.1 --- a/pkg/devices/lcd/src/jz4740/lcd-jz4740-device.cc Tue Oct 24 17:32:54 2023 +0200
1.2 +++ b/pkg/devices/lcd/src/jz4740/lcd-jz4740-device.cc Tue Oct 24 17:33:39 2023 +0200
1.3 @@ -19,6 +19,7 @@
1.4 * Boston, MA 02110-1301, USA
1.5 */
1.6
1.7 +#include <l4/devices/dma.h>
1.8 #include <l4/devices/lcd-jz4740.h>
1.9 #include <l4/devices/lcd-jz4780.h>
1.10 #include <l4/devices/panel-loader.h>
1.11 @@ -26,13 +27,8 @@
1.12 #include "lcd-jz4740-device.h"
1.13
1.14 #include <l4/re/c/dataspace.h>
1.15 -#include <l4/re/c/dma_space.h>
1.16 -#include <l4/re/c/mem_alloc.h>
1.17 #include <l4/re/env.h>
1.18 -#include <l4/re/protocols.h>
1.19 -#include <l4/sys/factory.h>
1.20 #include <l4/sys/types.h>
1.21 -#include <l4/vbus/vbus.h>
1.22
1.23 #include <ipc/cap_alloc.h>
1.24 #include <ipc/mem_ipc.h>
1.25 @@ -124,100 +120,35 @@
1.26 int
1.27 Lcd_jz4740_device::_setup_memory()
1.28 {
1.29 - // Framebuffer and descriptor sizes.
1.30 -
1.31 - unsigned long fb_size, desc_size;
1.32 -
1.33 - // Size of physically contiguous regions to be allocated.
1.34 -
1.35 - l4_size_t fb_size_out, desc_size_out;
1.36 -
1.37 - // Memory allocation capabilities.
1.38 -
1.39 - l4_cap_idx_t descmem, dma, vbus;
1.40 -
1.41 // Test for existing setup.
1.42
1.43 if (fb_vaddr)
1.44 return 0;
1.45
1.46 - // Create the DMA space.
1.47 -
1.48 - dma = ipc_cap_alloc();
1.49 -
1.50 - if (l4_is_invalid_cap(dma))
1.51 - return 1;
1.52 -
1.53 - vbus = l4re_env_get_cap("vbus");
1.54 -
1.55 - if (l4_is_invalid_cap(vbus))
1.56 - return 1;
1.57 -
1.58 - if (l4_error(l4_factory_create(l4re_env()->mem_alloc, L4RE_PROTO_DMA_SPACE, dma)))
1.59 - return 1;
1.60 -
1.61 - l4vbus_device_handle_t device = L4VBUS_NULL;
1.62 - l4vbus_resource_t dma_resource;
1.63 -
1.64 - if (!find_resource(&device, &dma_resource, L4VBUS_RESOURCE_DMA_DOMAIN))
1.65 - return 1;
1.66 -
1.67 - if (l4vbus_assign_dma_domain(vbus, dma_resource.start,
1.68 - L4VBUS_DMAD_BIND | L4VBUS_DMAD_L4RE_DMA_SPACE,
1.69 - dma))
1.70 - return 1;
1.71 -
1.72 // Obtain the memory requirements.
1.73
1.74 Lcd_jz4740_chip *chip = static_cast<Lcd_jz4740_chip *>(_chip);
1.75
1.76 - fb_size = chip->get_screen_size();
1.77 - desc_size = chip->get_descriptors_size();
1.78 + // Framebuffer and descriptor sizes.
1.79 +
1.80 + unsigned long fb_size = chip->get_screen_size(),
1.81 + desc_size = chip->get_descriptors_size();
1.82
1.83 // Allocate memory for the framebuffer at 2**6 == 64 byte == 16 word alignment,
1.84 // also for the descriptors.
1.85 // NOTE: A 64 word burst mode is available on the JZ4780 that would
1.86 // NOTE: necessitate 64 word alignment for the framebuffer.
1.87
1.88 - const l4_size_t alloc_flags = L4RE_MA_CONTINUOUS | L4RE_MA_PINNED;
1.89 - const l4re_rm_flags_t attach_flags = L4RE_RM_F_SEARCH_ADDR | L4RE_RM_F_RW;
1.90 -
1.91 - // Map the allocated memory, obtaining virtual addresses.
1.92 -
1.93 - fb_vaddr = 0;
1.94 - desc_vaddr = 0;
1.95 + long err = get_dma_region(fb_size, 8, &fb_vaddr, &fb_paddr, &_fbmem);
1.96
1.97 - if (ipc_new_dataspace(fb_size, alloc_flags, 8, &_fbmem))
1.98 - return 1;
1.99 -
1.100 - if (ipc_new_dataspace(desc_size, alloc_flags, 6, &descmem))
1.101 - return 1;
1.102 -
1.103 - if (ipc_attach_dataspace_align(_fbmem, fb_size, attach_flags, 8, (void **) &fb_vaddr))
1.104 - return 1;
1.105 -
1.106 - if (ipc_attach_dataspace_align(descmem, desc_size, attach_flags, 6, (void **) &desc_vaddr))
1.107 + if (err)
1.108 return 1;
1.109
1.110 - // Obtain physical addresses for the framebuffer and descriptors.
1.111 -
1.112 - fb_paddr = 0;
1.113 - desc_paddr = 0;
1.114 -
1.115 - fb_size_out = fb_size;
1.116 - desc_size_out = desc_size;
1.117 + l4_cap_idx_t descmem;
1.118
1.119 - if (l4re_dma_space_map(dma, _fbmem | L4_CAP_FPAGE_RW, 0, &fb_size_out, 0,
1.120 - L4RE_DMA_SPACE_TO_DEVICE, &fb_paddr))
1.121 - return 1;
1.122 + err = get_dma_region(desc_size, 6, &desc_vaddr, &desc_paddr, &descmem);
1.123
1.124 - if (l4re_dma_space_map(dma, descmem | L4_CAP_FPAGE_RW, 0, &desc_size_out, 0,
1.125 - L4RE_DMA_SPACE_TO_DEVICE, &desc_paddr))
1.126 - return 1;
1.127 -
1.128 - // Test the mapped region sizes.
1.129 -
1.130 - if ((fb_size_out != fb_size) || (desc_size_out != desc_size))
1.131 + if (err)
1.132 return 1;
1.133
1.134 return 0;