1.1 --- a/pkg/devices/lcd/src/jz4740/lcd-jz4740-device.cc Tue Sep 27 23:21:50 2022 +0200
1.2 +++ b/pkg/devices/lcd/src/jz4740/lcd-jz4740-device.cc Sun May 28 22:35:09 2023 +0200
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * Common LCD device support for the JZ4740 and related SoCs.
1.6 *
1.7 - * Copyright (C) 2018, 2020 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2018, 2020, 2023 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 @@ -28,11 +28,14 @@
1.13 #include "lcd-jz4740-device.h"
1.14
1.15 #include <l4/re/dataspace>
1.16 +#include <l4/re/dma_space>
1.17 #include <l4/re/env>
1.18 #include <l4/re/mem_alloc>
1.19 #include <l4/re/rm>
1.20 #include <l4/re/util/cap_alloc>
1.21 +#include <l4/sys/factory>
1.22 #include <l4/sys/types.h>
1.23 +#include <l4/vbus/vbus>
1.24
1.25 #include <stdint.h>
1.26
1.27 @@ -124,9 +127,10 @@
1.28
1.29 l4_size_t fb_size_out, desc_size_out;
1.30
1.31 - // Memory allocation capability.
1.32 + // Memory allocation capabilities.
1.33
1.34 L4::Cap<L4Re::Dataspace> descmem;
1.35 + L4::Cap<L4Re::Dma_space> dma;
1.36
1.37 // Test for existing setup.
1.38
1.39 @@ -141,6 +145,28 @@
1.40 descmem = L4Re::Util::cap_alloc.alloc<L4Re::Dataspace>();
1.41 if (!descmem.is_valid()) return 1;
1.42
1.43 + dma = L4Re::Util::cap_alloc.alloc<L4Re::Dma_space>();
1.44 + if (!dma.is_valid()) return 1;
1.45 +
1.46 + // Create the DMA space.
1.47 +
1.48 + L4::Cap<L4vbus::Vbus> vbus = L4Re::Env::env()->get_cap<L4vbus::Vbus>("vbus");
1.49 + if (!vbus.is_valid()) return 1;
1.50 +
1.51 + if (l4_error(L4Re::Env::env()->user_factory()->create(dma)))
1.52 + return 1;
1.53 +
1.54 + l4vbus_device_handle_t device = L4VBUS_NULL;
1.55 + l4vbus_resource_t dma_resource;
1.56 +
1.57 + if (!find_resource(&device, &dma_resource, L4VBUS_RESOURCE_DMA_DOMAIN))
1.58 + return 1;
1.59 +
1.60 + if (vbus->assign_dma_domain(dma_resource.start,
1.61 + L4VBUS_DMAD_BIND | L4VBUS_DMAD_L4RE_DMA_SPACE,
1.62 + dma))
1.63 + return 1;
1.64 +
1.65 // Obtain the memory requirements.
1.66
1.67 Lcd_jz4740_chip *chip = static_cast<Lcd_jz4740_chip *>(_chip);
1.68 @@ -161,13 +187,15 @@
1.69
1.70 // Map the allocated memory, obtaining virtual addresses.
1.71
1.72 - const l4_size_t attach_flags = L4Re::Rm::Search_addr | L4Re::Rm::Eager_map;
1.73 + const L4Re::Rm::F::Flags flags = L4Re::Rm::F::Search_addr |
1.74 + L4Re::Rm::F::Eager_map |
1.75 + L4Re::Rm::F::RW;
1.76
1.77 fb_vaddr = 0;
1.78 desc_vaddr = 0;
1.79
1.80 - if (L4Re::Env::env()->rm()->attach(&fb_vaddr, fb_size, attach_flags, _fbmem, 0) ||
1.81 - L4Re::Env::env()->rm()->attach(&desc_vaddr, desc_size, attach_flags, descmem, 0))
1.82 + if (L4Re::Env::env()->rm()->attach(&fb_vaddr, fb_size, flags, _fbmem, 0) ||
1.83 + L4Re::Env::env()->rm()->attach(&desc_vaddr, desc_size, flags, descmem, 0))
1.84 return 1;
1.85
1.86 // Obtain physical addresses for the framebuffer and descriptors.
1.87 @@ -178,8 +206,16 @@
1.88 fb_size_out = fb_size;
1.89 desc_size_out = desc_size;
1.90
1.91 - if (_fbmem->phys(0, fb_paddr, fb_size_out) ||
1.92 - descmem->phys(0, desc_paddr, desc_size_out))
1.93 + if (dma->map(L4::Ipc::make_cap_rw(_fbmem), 0, &fb_size_out,
1.94 + L4Re::Dma_space::Attributes::None,
1.95 + L4Re::Dma_space::Direction::To_device,
1.96 + &fb_paddr))
1.97 + return 1;
1.98 +
1.99 + if (dma->map(L4::Ipc::make_cap_rw(descmem), 0, &desc_size_out,
1.100 + L4Re::Dma_space::Attributes::None,
1.101 + L4Re::Dma_space::Direction::To_device,
1.102 + &desc_paddr))
1.103 return 1;
1.104
1.105 // Test the mapped region sizes.