platform_drv: add phys_addr to add_range()

We need the physical address of a DMA range in order to insert it into
the translation table.

genodelabs/genode#5002
This commit is contained in:
Johannes Schlatow 2023-09-20 22:46:38 +02:00
parent 0182e81b51
commit a80464299a
7 changed files with 18 additions and 8 deletions

View File

@ -238,7 +238,8 @@ Device_component::Device_component(Registry<Device_component> & registry,
auto add_range_fn = [&] (Driver::Io_mmu::Domain & domain) {
_reserved_mem_registry.for_each([&] (Io_mem & iomem) {
domain.add_range(iomem.range, iomem.io_mem->dataspace());
domain.add_range(iomem.range, iomem.range.start,
iomem.io_mem->dataspace());
});
};

View File

@ -70,6 +70,7 @@ void Device_pd::Region_map_client::upgrade_caps()
void Device_pd::add_range(Io_mmu::Range const & range,
addr_t const,
Dataspace_capability const cap)
{
using namespace Genode;
@ -156,5 +157,5 @@ Device_pd::Device_pd(Env & env,
_pd.ref_account(env.pd_session_cap());
buffer_registry.for_each([&] (Dma_buffer const & buf) {
add_range({ buf.dma_addr, buf.size }, buf.cap); });
add_range({ buf.dma_addr, buf.size }, buf.phys_addr, buf.cap); });
}

View File

@ -87,7 +87,9 @@ class Driver::Device_pd : public Io_mmu::Domain
Allocator & md_alloc,
Registry<Dma_buffer> const & buffer_registry);
void add_range(Io_mmu::Range const &, Dataspace_capability const) override;
void add_range(Io_mmu::Range const &,
addr_t const,
Dataspace_capability const) override;
void remove_range(Io_mmu::Range const &) override;
void enable_pci_device(Io_mem_dataspace_capability const,

View File

@ -87,7 +87,8 @@ Dma_buffer & Dma_allocator::alloc_buffer(Ram_dataspace_capability cap,
addr_t dma_addr = _alloc_dma_addr(phys_addr, size, false);
try {
return * new (_md_alloc) Dma_buffer(_registry, *this, cap, dma_addr, size);
return * new (_md_alloc) Dma_buffer(_registry, *this, cap, dma_addr, size,
phys_addr);
} catch (Out_of_ram) {
_free_dma_addr(dma_addr);
throw;

View File

@ -30,6 +30,7 @@ struct Driver::Dma_buffer : Registry<Dma_buffer>::Element
{
Ram_dataspace_capability const cap;
addr_t dma_addr;
addr_t phys_addr;
size_t size;
Dma_allocator & dma_alloc;
@ -37,9 +38,11 @@ struct Driver::Dma_buffer : Registry<Dma_buffer>::Element
Dma_allocator & dma_alloc,
Ram_dataspace_capability const cap,
addr_t dma_addr,
size_t size)
size_t size,
addr_t phys_addr)
: Registry<Dma_buffer>::Element(registry, *this),
cap(cap), dma_addr(dma_addr), size(size), dma_alloc(dma_alloc)
cap(cap), dma_addr(dma_addr), phys_addr(phys_addr),
size(size), dma_alloc(dma_alloc)
{ }
~Dma_buffer();

View File

@ -84,7 +84,9 @@ class Driver::Io_mmu : private Io_mmu_devices::Element
Pci::Bdf const) = 0;
/* interface for adding/removing DMA buffers */
virtual void add_range(Range const &, Dataspace_capability const) = 0;
virtual void add_range(Range const &,
addr_t const,
Dataspace_capability const) = 0;
virtual void remove_range(Range const &) = 0;
Domain(Io_mmu & io_mmu,

View File

@ -346,7 +346,7 @@ Session_component::alloc_dma_buffer(size_t const size, Cache cache)
_env_ram.dataspace_size(ram_cap));
_domain_registry.for_each_domain([&] (Io_mmu::Domain & domain) {
domain.add_range({ buf.dma_addr, buf.size }, buf.cap);
domain.add_range({ buf.dma_addr, buf.size }, buf.phys_addr, buf.cap);
});
} catch (Out_of_ram) {
_env_ram.free(ram_cap);