gpu: introduce mapping attributes

The various mapping methods are modelled after the requirements of
the Intel GPUs or rather the Mesa driver back end.

With upcoming support for other driver back ends, we need to
sequeeze their requirements in as well. For now hijack 'map_buffer'
to provide for specifying the kind of attributes the client needs.

For now all buffers mapped in the GGTT for Intel GPUs are treated
as RW.

Issue #4265.
This commit is contained in:
Josef Söntgen 2021-09-23 18:07:56 +02:00 committed by Norman Feske
parent 90e151e2c4
commit cacb83b163
4 changed files with 39 additions and 6 deletions

View File

@ -340,7 +340,8 @@ class Drm_call
try {
_gpu_session.upgrade_ram(4096);
b.map_cap = _gpu_session.map_buffer(b.id(), true);
b.map_cap = _gpu_session.map_buffer(b.id(), true,
Gpu::Mapping_attributes::rw());
b.map_offset = static_cast<Offset>(_env.rm().attach(b.map_cap));
offset = b.map_offset;

View File

@ -57,8 +57,9 @@ class Gpu::Session_client : public Genode::Rpc_client<Session>
call<Rpc_free_buffer>(id); }
Genode::Dataspace_capability map_buffer(Buffer_id id,
bool aperture) override {
return call<Rpc_map_buffer>(id, aperture); }
bool aperture,
Mapping_attributes attrs) override {
return call<Rpc_map_buffer>(id, aperture, attrs); }
void unmap_buffer(Buffer_id id) override {
call<Rpc_unmap_buffer>(id); }

View File

@ -24,6 +24,30 @@ namespace Gpu {
struct Buffer;
using Buffer_id = Genode::Id_space<Buffer>::Id;
/*
* Attributes for mapping a buffer
*/
struct Mapping_attributes
{
bool readable;
bool writeable;
static Mapping_attributes ro()
{
return { .readable = true, .writeable = false };
}
static Mapping_attributes rw()
{
return { .readable = true, .writeable = true };
}
static Mapping_attributes wo()
{
return { .readable = false, .writeable = true };
}
};
struct Sequence_number;
struct Session;
}
@ -118,11 +142,13 @@ struct Gpu::Session : public Genode::Session
* \param id buffer id
* \param aperture if true create CPU accessible mapping through
* GGTT window, otherwise create PPGTT mapping
* \param attrs specify how the buffer is mapped
*
* \throw Mapping_buffer_failed
*/
virtual Genode::Dataspace_capability map_buffer(Buffer_id id,
bool aperture) = 0;
bool aperture,
Mapping_attributes attrs) = 0;
/**
* Unmap buffer
@ -175,7 +201,7 @@ struct Gpu::Session : public Genode::Session
GENODE_RPC(Rpc_free_buffer, void, free_buffer, Gpu::Buffer_id);
GENODE_RPC_THROW(Rpc_map_buffer, Genode::Dataspace_capability, map_buffer,
GENODE_TYPE_LIST(Mapping_buffer_failed, Out_of_ram),
Gpu::Buffer_id, bool);
Gpu::Buffer_id, bool, Gpu::Mapping_attributes);
GENODE_RPC(Rpc_unmap_buffer, void, unmap_buffer,
Gpu::Buffer_id);
GENODE_RPC_THROW(Rpc_map_buffer_ppgtt, bool, map_buffer_ppgtt,

View File

@ -1676,8 +1676,13 @@ class Gpu::Session_component : public Genode::Session_object<Gpu::Session>
}
Genode::Dataspace_capability map_buffer(Gpu::Buffer_id id,
bool aperture) override
bool aperture,
Gpu::Mapping_attributes attrs) override
{
/* treat GGTT mapped buffers as rw */
if (!(attrs.readable && attrs.writeable))
return Genode::Dataspace_capability();
Genode::Dataspace_capability map_cap;
auto lookup_and_map = [&] (Buffer &buffer) {