mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-30 08:03:59 +00:00
lx_kit: free dataspace interface
Allow for freeing of manually managed dataspaces. Fixes #4325.
This commit is contained in:
parent
327ec61ee3
commit
49bf58a2ae
@ -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<void*>(); }
|
||||
|
||||
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);
|
||||
|
@ -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 { };
|
||||
|
Loading…
x
Reference in New Issue
Block a user