os/block: Remove use of Dataspace::phys_addr

Issue #2243
This commit is contained in:
Norman Feske 2022-02-11 14:04:36 +01:00
parent de6c65c453
commit 84435662aa
9 changed files with 53 additions and 27 deletions

View File

@ -49,16 +49,18 @@ class Block::Session_component_base
Driver_factory &_driver_factory;
Driver &_driver;
Ram_dataspace_capability _rq_ds;
Driver::Dma_buffer _rq;
Session_component_base(Driver_factory &factory, size_t tx_buf_size)
: _driver_factory(factory),
_driver(*factory.create()),
_rq_ds(_driver.alloc_dma_buffer(tx_buf_size, UNCACHED)) {}
:
_driver_factory(factory),
_driver(*factory.create()),
_rq(_driver.alloc_dma_buffer(tx_buf_size, UNCACHED))
{ }
~Session_component_base()
{
_driver.free_dma_buffer(_rq_ds);
_driver.free_dma_buffer(_rq.ds);
_driver_factory.destroy(&_driver);
}
};
@ -211,8 +213,8 @@ class Block::Session_component : public Block::Session_component_base,
size_t buf_size,
bool writeable)
: Session_component_base(driver_factory, buf_size),
Driver_session(rm, _rq_ds, ep.rpc_ep()),
_rq_phys(Dataspace_client(_rq_ds).phys_addr()),
Driver_session(rm, _rq.ds, ep.rpc_ep()),
_rq_phys(_rq.dma_addr),
_sink_ack(ep, *this, &Session_component::_signal),
_sink_submit(ep, *this, &Session_component::_signal),
_req_queue_full(false),

View File

@ -187,14 +187,18 @@ class Block::Driver : Genode::Interface
*/
virtual bool dma_enabled() { return false; }
struct Dma_buffer
{
Genode::Ram_dataspace_capability ds;
Genode::addr_t dma_addr;
};
/**
* Allocate buffer which is suitable for DMA.
*
* Note: has to be overriden by DMA-capable devices
*/
virtual Genode::Ram_dataspace_capability
alloc_dma_buffer(Genode::size_t size, Genode::Cache cache) {
return _ram.alloc(size, cache); }
virtual Dma_buffer alloc_dma_buffer(Genode::size_t, Genode::Cache) = 0;
/**
* Free buffer which is suitable for DMA.

View File

@ -21,11 +21,10 @@
using namespace Adma2;
Table::Table(Ram_allocator &ram, Region_map &rm)
Table::Table(Platform::Connection &platform)
:
_ds(ram, rm, _ds_size, UNCACHED),
_base_virt(_ds.local_addr<Desc::access_t>()),
_base_phys(Dataspace_client(_ds.cap()).phys_addr())
_ds(platform, _ds_size, UNCACHED),
_base_virt(_ds.local_addr<Desc::access_t>())
{ }

View File

@ -16,7 +16,7 @@
/* Genode includes */
#include <util/register.h>
#include <base/attached_ram_dataspace.h>
#include <platform_session/dma_buffer.h>
namespace Adma2
{
@ -52,6 +52,7 @@ struct Adma2::Desc : Register<64>
struct Address : Bitfield<32, 32> { };
};
/**
* Descriptor table
*/
@ -62,9 +63,8 @@ class Adma2::Table
static size_t constexpr _max_desc = 1024;
static size_t constexpr _ds_size = _max_desc * sizeof(Desc::access_t);
Attached_ram_dataspace _ds;
Platform::Dma_buffer _ds;
Desc::access_t * const _base_virt;
addr_t const _base_phys;
/*
* Noncopyable
@ -74,7 +74,7 @@ class Adma2::Table
public:
Table(Ram_allocator &ram, Region_map &rm);
Table(Platform::Connection &platform);
/**
* Marshal descriptors according to block request
@ -91,7 +91,7 @@ class Adma2::Table
* Accessors
*/
addr_t base_phys() const { return _base_phys; }
addr_t base_dma() const { return _ds.dma_addr(); }
};
#endif /* _ADMA2_H_ */

View File

@ -16,6 +16,7 @@
#include <timer_session/connection.h>
#include <base/attached_ram_dataspace.h>
#include <base/attached_rom_dataspace.h>
#include <platform_session/dma_buffer.h>
/* local includes */
#include <driver.h>
@ -60,10 +61,8 @@ struct Benchmark
size_t const buf_size_kib { config.xml().attribute_value("buffer_size_kib",
(size_t)0) };
size_t const buf_size { buf_size_kib * 1024 };
Attached_ram_dataspace buf { env.ram(), env.rm(), buf_size, UNCACHED };
Platform::Dma_buffer buf { platform, buf_size, UNCACHED };
char *buf_virt { buf.local_addr<char>() };
addr_t buf_phys { Dataspace_client(buf.cap())
.phys_addr() };
size_t buf_off_done { 0 };
size_t buf_off_pend { 0 };
unsigned req_size_id { 0 };
@ -125,7 +124,7 @@ struct Benchmark
if (drv.dma_enabled()) {
/* request with DMA */
addr_t const phys = buf_phys + buf_off_pend;
addr_t const phys = buf.dma_addr() + buf_off_pend;
switch (operation) {
case READ: drv.read_dma(nr, cnt, phys, pkt); break;
case WRITE: drv.write_dma(nr, cnt, phys, pkt); break; }

View File

@ -250,7 +250,7 @@ int Driver::_prepare_dma_mb(Block::Packet_descriptor packet,
if (_adma2_table.setup_request(req_size, buf_phys)) { return -1; }
/* configure DMA at host */
Mmio::write<Adsaddr>(_adma2_table.base_phys());
Mmio::write<Adsaddr>(_adma2_table.base_dma());
Mmio::write<Blkattr::Blksize>(_block_size());
Mmio::write<Blkattr::Blkcnt>(blk_cnt);

View File

@ -220,7 +220,7 @@ class Sd_card::Driver : public Driver_base,
&Driver::_handle_irq };
Platform::Device::Irq _irq { *this };
Card_info _card_info { _init() };
Adma2::Table _adma2_table { _env.ram(), _env.rm() };
Adma2::Table _adma2_table { _platform };
static bool _supported_host_version(Hostver::access_t hostver);
static void _watermark_level(Wml::access_t &wml);
@ -294,8 +294,15 @@ class Sd_card::Driver : public Driver_base,
bool dma_enabled() override { return true; }
Ram_dataspace_capability alloc_dma_buffer(size_t size, Cache cache) override {
return _env.ram().alloc(size, cache); }
Dma_buffer alloc_dma_buffer(size_t size, Cache cache) override
{
Ram_dataspace_capability ds =
_platform.retry_with_upgrade(Ram_quota{4096}, Cap_quota{2},
[&] () { return _platform.alloc_dma_buffer(size, cache); });
return { .ds = ds,
.dma_addr = _platform.dma_addr(ds) };
}
};
#endif /* _SRC__DRIVERS__SD_CARD__SPEC__IMX__DRIVER_H_ */

View File

@ -128,6 +128,16 @@ class Sd_card::Driver : public Block::Driver,
** Block-driver **
******************/
Dma_buffer alloc_dma_buffer(size_t size, Cache cache) override
{
Ram_dataspace_capability ds =
_platform.retry_with_upgrade(Ram_quota{4096}, Cap_quota{2},
[&] () { return _platform.alloc_dma_buffer(size, cache); });
return { .ds = ds,
.dma_addr = _platform.dma_addr(ds) };
}
Block::Session::Info info() const override
{
return { .block_size = _block_size,

View File

@ -113,6 +113,11 @@ class Lx_block_driver : public Block::Driver
** Block::Driver interface **
*****************************/
Dma_buffer alloc_dma_buffer(Genode::size_t size, Genode::Cache) override
{
return { .ds = _env.ram().alloc(size), .dma_addr = 0 };
}
Block::Session::Info info() const override { return _info; }
void read(Block::sector_t block_number,