From cacb83b16355d147dc545f1ca51d311ccc54fece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Thu, 23 Sep 2021 18:07:56 +0200 Subject: [PATCH] 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. --- repos/libports/src/lib/libdrm/ioctl_iris.cc | 3 ++- repos/os/include/gpu_session/client.h | 5 ++-- repos/os/include/gpu_session/gpu_session.h | 30 +++++++++++++++++++-- repos/os/src/drivers/gpu/intel/main.cc | 7 ++++- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/repos/libports/src/lib/libdrm/ioctl_iris.cc b/repos/libports/src/lib/libdrm/ioctl_iris.cc index 3f5641e9f6..256a9eb5c0 100644 --- a/repos/libports/src/lib/libdrm/ioctl_iris.cc +++ b/repos/libports/src/lib/libdrm/ioctl_iris.cc @@ -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(_env.rm().attach(b.map_cap)); offset = b.map_offset; diff --git a/repos/os/include/gpu_session/client.h b/repos/os/include/gpu_session/client.h index 83f7f277ad..f9bf79f13d 100644 --- a/repos/os/include/gpu_session/client.h +++ b/repos/os/include/gpu_session/client.h @@ -57,8 +57,9 @@ class Gpu::Session_client : public Genode::Rpc_client call(id); } Genode::Dataspace_capability map_buffer(Buffer_id id, - bool aperture) override { - return call(id, aperture); } + bool aperture, + Mapping_attributes attrs) override { + return call(id, aperture, attrs); } void unmap_buffer(Buffer_id id) override { call(id); } diff --git a/repos/os/include/gpu_session/gpu_session.h b/repos/os/include/gpu_session/gpu_session.h index 4753cab096..0df7f45ffd 100644 --- a/repos/os/include/gpu_session/gpu_session.h +++ b/repos/os/include/gpu_session/gpu_session.h @@ -24,6 +24,30 @@ namespace Gpu { struct Buffer; using Buffer_id = Genode::Id_space::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, diff --git a/repos/os/src/drivers/gpu/intel/main.cc b/repos/os/src/drivers/gpu/intel/main.cc index 1af43359b3..616ba48506 100644 --- a/repos/os/src/drivers/gpu/intel/main.cc +++ b/repos/os/src/drivers/gpu/intel/main.cc @@ -1676,8 +1676,13 @@ class Gpu::Session_component : public Genode::Session_object } 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) {