From 327ec61ee3374e2a66e49c6dc9e3e40904bdf740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Fri, 5 Nov 2021 17:38:53 +0100 Subject: [PATCH] lx_kit: get buffer dataspace from virt addr Introduce a method to access the dataspace capability of the underlying backing store for a memory allocation. This is necessary for drivers where the memory is managed manually and the capability needs to be given to a client. Issue #4325. --- repos/dde_linux/src/include/lx_kit/memory.h | 1 + repos/dde_linux/src/lib/lx_kit/memory.cc | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/repos/dde_linux/src/include/lx_kit/memory.h b/repos/dde_linux/src/include/lx_kit/memory.h index 20dbab7104..4745a586a3 100644 --- a/repos/dde_linux/src/include/lx_kit/memory.h +++ b/repos/dde_linux/src/include/lx_kit/memory.h @@ -105,6 +105,7 @@ class Lx_kit::Mem_allocator Cache cache_attr); Attached_dataspace & alloc_dataspace(size_t size); + Dataspace_capability attached_dataspace_cap(void *addr); void * alloc(size_t size, size_t align); addr_t dma_addr(void * addr); diff --git a/repos/dde_linux/src/lib/lx_kit/memory.cc b/repos/dde_linux/src/lib/lx_kit/memory.cc index 85a8f3fd95..847b55ad8b 100644 --- a/repos/dde_linux/src/lib/lx_kit/memory.cc +++ b/repos/dde_linux/src/lib/lx_kit/memory.cc @@ -49,6 +49,19 @@ Genode::Attached_dataspace & Lx_kit::Mem_allocator::alloc_dataspace(size_t size) } +Genode::Dataspace_capability Lx_kit::Mem_allocator::attached_dataspace_cap(void * addr) +{ + Genode::Dataspace_capability ret { }; + + _virt_to_dma.apply(Buffer_info::Query_addr(addr), + [&] (Buffer_info const & info) { + ret = info.buffer.ds().cap(); + }); + + return ret; +} + + void * Lx_kit::Mem_allocator::alloc(size_t size, size_t align) { if (!size)