1.1 --- a/pkg/devices/lcd/src/jz4740/lcd-jz4740-device.cc Sat Jun 10 22:45:54 2023 +0200
1.2 +++ b/pkg/devices/lcd/src/jz4740/lcd-jz4740-device.cc Sat Jun 10 23:30:38 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, 2021 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2018, 2020, 2021, 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 @@ -26,12 +26,15 @@
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/env.h>
1.19 #include <l4/re/mem_alloc>
1.20 #include <l4/re/rm>
1.21 #include <l4/re/util/cap_alloc>
1.22 +#include <l4/sys/factory>
1.23 #include <l4/sys/types.h>
1.24 +#include <l4/vbus/vbus>
1.25
1.26 #include <stdint.h>
1.27
1.28 @@ -127,9 +130,10 @@
1.29
1.30 l4_size_t fb_size_out, desc_size_out;
1.31
1.32 - // Memory allocation capability.
1.33 + // Memory allocation capabilities.
1.34
1.35 L4::Cap<L4Re::Dataspace> descmem;
1.36 + L4::Cap<L4Re::Dma_space> dma;
1.37
1.38 // Test for existing setup.
1.39
1.40 @@ -144,6 +148,28 @@
1.41 descmem = L4Re::Util::cap_alloc.alloc<L4Re::Dataspace>();
1.42 if (!descmem.is_valid()) return 1;
1.43
1.44 + dma = L4Re::Util::cap_alloc.alloc<L4Re::Dma_space>();
1.45 + if (!dma.is_valid()) return 1;
1.46 +
1.47 + // Create the DMA space.
1.48 +
1.49 + L4::Cap<L4vbus::Vbus> vbus = L4Re::Env::env()->get_cap<L4vbus::Vbus>("vbus");
1.50 + if (!vbus.is_valid()) return 1;
1.51 +
1.52 + if (l4_error(L4Re::Env::env()->user_factory()->create(dma)))
1.53 + return 1;
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 + return 1;
1.60 +
1.61 + if (vbus->assign_dma_domain(dma_resource.start,
1.62 + L4VBUS_DMAD_BIND | L4VBUS_DMAD_L4RE_DMA_SPACE,
1.63 + dma))
1.64 + return 1;
1.65 +
1.66 // Obtain the memory requirements.
1.67
1.68 Lcd_jz4740_chip *chip = static_cast<Lcd_jz4740_chip *>(_chip);
1.69 @@ -164,13 +190,15 @@
1.70
1.71 // Map the allocated memory, obtaining virtual addresses.
1.72
1.73 - const l4_size_t attach_flags = L4Re::Rm::Search_addr | L4Re::Rm::Eager_map;
1.74 + const L4Re::Rm::F::Flags flags = L4Re::Rm::F::Search_addr |
1.75 + L4Re::Rm::F::Eager_map |
1.76 + L4Re::Rm::F::RW;
1.77
1.78 fb_vaddr = 0;
1.79 desc_vaddr = 0;
1.80
1.81 - if (L4Re::Env::env()->rm()->attach(&fb_vaddr, fb_size, attach_flags, _fbmem, 0) ||
1.82 - L4Re::Env::env()->rm()->attach(&desc_vaddr, desc_size, attach_flags, descmem, 0))
1.83 + if (L4Re::Env::env()->rm()->attach(&fb_vaddr, fb_size, flags, _fbmem, 0) ||
1.84 + L4Re::Env::env()->rm()->attach(&desc_vaddr, desc_size, flags, descmem, 0))
1.85 return 1;
1.86
1.87 // Obtain physical addresses for the framebuffer and descriptors.
1.88 @@ -181,8 +209,16 @@
1.89 fb_size_out = fb_size;
1.90 desc_size_out = desc_size;
1.91
1.92 - if (_fbmem->phys(0, fb_paddr, fb_size_out) ||
1.93 - descmem->phys(0, desc_paddr, desc_size_out))
1.94 + if (dma->map(L4::Ipc::make_cap_rw(_fbmem), 0, &fb_size_out,
1.95 + L4Re::Dma_space::Attributes::None,
1.96 + L4Re::Dma_space::Direction::To_device,
1.97 + &fb_paddr))
1.98 + return 1;
1.99 +
1.100 + if (dma->map(L4::Ipc::make_cap_rw(descmem), 0, &desc_size_out,
1.101 + L4Re::Dma_space::Attributes::None,
1.102 + L4Re::Dma_space::Direction::To_device,
1.103 + &desc_paddr))
1.104 return 1;
1.105
1.106 // Test the mapped region sizes.