diff --git a/repos/dde_linux/src/include/lx_kit/memory.h b/repos/dde_linux/src/include/lx_kit/memory.h index 4745a586a3..df794b81e8 100644 --- a/repos/dde_linux/src/include/lx_kit/memory.h +++ b/repos/dde_linux/src/include/lx_kit/memory.h @@ -36,15 +36,16 @@ class Lx_kit::Mem_allocator { private: - Attached_dataspace _ds; - addr_t const _dma_addr; + Ram_dataspace_capability _ram_ds_cap; + Attached_dataspace _ds; + addr_t const _dma_addr; public: - Buffer(Region_map & rm, - Dataspace_capability cap, - addr_t dma_addr) - : _ds(rm, cap), _dma_addr(dma_addr) {} + Buffer(Region_map & rm, + Ram_dataspace_capability cap, + addr_t dma_addr) + : _ram_ds_cap(cap), _ds(rm, cap), _dma_addr(dma_addr) {} size_t dma_addr() const { return _dma_addr; } size_t size() const { return _ds.size(); } @@ -52,6 +53,8 @@ class Lx_kit::Mem_allocator return (addr_t) _ds.local_addr(); } Attached_dataspace & ds() { return _ds; } + + Ram_dataspace_capability ram_ds_cap() { return _ram_ds_cap; } }; struct Buffer_info @@ -105,6 +108,7 @@ class Lx_kit::Mem_allocator Cache cache_attr); Attached_dataspace & alloc_dataspace(size_t size); + void free_dataspace(void *addr); Dataspace_capability attached_dataspace_cap(void *addr); void * alloc(size_t size, size_t align); diff --git a/repos/dde_linux/src/lib/lx_kit/memory.cc b/repos/dde_linux/src/lib/lx_kit/memory.cc index 847b55ad8b..5e3b18eac6 100644 --- a/repos/dde_linux/src/lib/lx_kit/memory.cc +++ b/repos/dde_linux/src/lib/lx_kit/memory.cc @@ -49,6 +49,34 @@ Genode::Attached_dataspace & Lx_kit::Mem_allocator::alloc_dataspace(size_t size) } +void Lx_kit::Mem_allocator::free_dataspace(void * addr) +{ + Buffer *buffer = nullptr; + + _virt_to_dma.apply(Buffer_info::Query_addr(addr), + [&] (Buffer_info const & info) { + buffer = &info.buffer; + }); + + if (!buffer) { + warning(__func__, ": no buffer for addr: ", addr, " found"); + return; + } + + void const * virt_addr = (void const *)buffer->virt_addr(); + void const * dma_addr = (void const *)buffer->dma_addr(); + + _virt_to_dma.remove(Buffer_info::Query_addr(virt_addr)); + _dma_to_virt.remove(Buffer_info::Query_addr(dma_addr)); + + Ram_dataspace_capability ds_cap = buffer->ram_ds_cap(); + + destroy(_heap, buffer); + + _platform.free_dma_buffer(ds_cap); +} + + Genode::Dataspace_capability Lx_kit::Mem_allocator::attached_dataspace_cap(void * addr) { Genode::Dataspace_capability ret { };