pci: provide dma-able memory via pci_drv

This commit is contained in:
Alexander Boettcher 2013-02-18 10:30:29 +01:00 committed by Norman Feske
parent c36f6a04a7
commit d58439ca56
8 changed files with 53 additions and 12 deletions

View File

@ -104,25 +104,26 @@ namespace Block {
}
};
Driver_factory &_driver_factory;
Driver &_driver;
Dataspace_capability _rq_ds;
Rq_thread _rq_thread;
Driver_factory &_driver_factory;
Driver &_driver;
Ram_dataspace_capability _rq_ds;
Rq_thread _rq_thread;
public:
/**
* Constructor
*/
Session_component(Dataspace_capability rq_ds,
Driver_factory &driver_factory,
Rpc_entrypoint &ep)
Session_component(Ram_dataspace_capability rq_ds,
Driver &driver,
Driver_factory &driver_factory,
Rpc_entrypoint &ep)
:
Session_rpc_object(rq_ds, ep),
_driver_factory(driver_factory),
_driver(*_driver_factory.create()),
_driver(driver),
_rq_ds(rq_ds),
_rq_thread(tx_sink(), _driver, Dataspace_client(rq_ds).phys_addr())
_rq_thread(tx_sink(), _driver, Dataspace_client(_rq_ds).phys_addr())
{ }
/**
@ -188,9 +189,11 @@ namespace Block {
throw Root::Quota_exceeded();
}
Driver * driver = _driver_factory.create();
Ram_dataspace_capability ds_cap;
ds_cap = driver->alloc_dma_buffer(tx_buf_size);
return new (md_alloc())
Session_component(env()->ram_session()->alloc(tx_buf_size, false),
_driver_factory, _ep);
Session_component(ds_cap, *driver, _driver_factory, _ep);
}
public:

View File

@ -18,6 +18,8 @@
#include <base/exception.h>
#include <base/stdint.h>
#include <ram_session/ram_session.h>
namespace Block {
@ -91,6 +93,11 @@ namespace Block {
* \return true if DMA is enabled, false otherwise
*/
virtual bool dma_enabled() = 0;
/**
* Allocate buffer which is suitable for DMA.
*/
virtual Genode::Ram_dataspace_capability alloc_dma_buffer(Genode::size_t) = 0;
};

View File

@ -35,6 +35,10 @@ namespace Pci {
Genode::Io_mem_dataspace_capability config_extended(Device_capability device_cap) {
return call<Rpc_config_extended>(device_cap); }
Genode::Ram_dataspace_capability alloc_dma_buffer(Device_capability device_cap,
Genode::size_t size) {
return call<Rpc_alloc_dma_buffer>(device_cap, size); }
};
}

View File

@ -16,6 +16,7 @@
#include <pci_device/pci_device.h>
#include <session/session.h>
#include <ram_session/ram_session.h>
namespace Pci {
@ -55,6 +56,11 @@ namespace Pci {
*/
virtual Genode::Io_mem_dataspace_capability config_extended(Device_capability) = 0;
/**
* Allocate memory suitable for DMA.
*/
virtual Genode::Ram_dataspace_capability alloc_dma_buffer(Device_capability,
Genode::size_t) = 0;
/*********************
** RPC declaration **
*********************/
@ -65,9 +71,14 @@ namespace Pci {
GENODE_RPC(Rpc_release_device, void, release_device, Device_capability);
GENODE_RPC(Rpc_config_extended, Genode::Io_mem_dataspace_capability,
config_extended, Device_capability);
GENODE_RPC_THROW(Rpc_alloc_dma_buffer, Genode::Ram_dataspace_capability,
alloc_dma_buffer,
GENODE_TYPE_LIST(Genode::Ram_session::Quota_exceeded),
Device_capability, Genode::size_t);
GENODE_RPC_INTERFACE(Rpc_first_device, Rpc_next_device,
Rpc_release_device, Rpc_config_extended);
Rpc_release_device, Rpc_config_extended,
Rpc_alloc_dma_buffer);
};
}

View File

@ -770,6 +770,9 @@ class Ahci_driver : public Block::Driver
PERR("%s should not be called", __PRETTY_FUNCTION__);
throw Io_error();
}
Ram_dataspace_capability alloc_dma_buffer(size_t size) {
return env()->ram_session()->alloc(size); }
};

View File

@ -291,6 +291,10 @@ namespace Pci {
return io_mem->dataspace();
}
Genode::Ram_dataspace_capability alloc_dma_buffer(Device_capability device_cap,
Genode::size_t size) {
return Genode::env()->ram_session()->alloc(size, false); }
};

View File

@ -119,6 +119,10 @@ class Block::Omap4_driver : public Block::Driver
}
bool dma_enabled() { return _use_dma; }
Ram_dataspace_capability alloc_dma_buffer(size_t size) {
/* unused */
return Ram_dataspace_capability(); }
};
#endif /* _DRIVER_H_ */

View File

@ -130,6 +130,11 @@ class Sd_card : public Block::Driver
throw Io_error(); }
bool dma_enabled() { return false; }
Genode::Ram_dataspace_capability alloc_dma_buffer(Genode::size_t size)
{
return Genode::env()->ram_session()->alloc(size, false);
}
};
#endif /* _SD_CARD_H_ */