libdrm: move Gpu::Vram into separate namespace

Because the implemantations for Lima and Vivante are linked into a
single library we cannot have two Gpu::Vram classes in the same
namespace. In case this happens any methods using the same signature are
weak symbols and the first one found by ld will be used = undefined
behavior.

issue #5356
issue #5369
This commit is contained in:
Sebastian Sumpf 2024-10-22 19:41:32 +02:00 committed by Christian Helmuth
parent 08bf219b28
commit db02e04d0c
2 changed files with 31 additions and 22 deletions

View File

@ -266,11 +266,15 @@ namespace Etnaviv {
using namespace Genode;
using namespace Gpu;
struct Vram;
struct Call;
} /* namespace Etnaviv */
struct Gpu::Vram
struct Gpu::Vram { };
/* use separate namespace for Vram implementation */
struct Etnaviv::Vram : Gpu::Vram
{
struct Allocation_failed : Genode::Exception { };
@ -346,7 +350,7 @@ class Etnaviv::Call
Gpu::Vram const &_vram;
Buffer(Genode::Id_space<Buffer> &space,
Gpu::Vram const &vram)
Vram const &vram)
:
_elem { *this, space,
Genode::Id_space<Buffer>::Id { .value = vram.id().value } },
@ -440,7 +444,7 @@ class Etnaviv::Call
* required by the Gpu session to pass on the driver specific
* command buffer.
*/
Gpu::Vram *_exec_buffer;
Vram *_exec_buffer;
public:
@ -457,8 +461,8 @@ class Etnaviv::Call
_fd { _open_gpu() },
_id { _stat_gpu(_fd) },
_elem { *this, space },
_exec_buffer { new (alloc) Gpu::Vram(_gpu, _exec_buffer_size,
_vram_space) }
_exec_buffer { new (alloc) Vram(_gpu, _exec_buffer_size,
_vram_space) }
{ }
~Gpu_context()
@ -486,13 +490,13 @@ class Etnaviv::Call
Gpu::Vram_capability export_vram(Gpu::Vram_id id)
{
Gpu::Vram_capability cap { };
_try_apply(id, [&] (Gpu::Vram const &b) {
_try_apply(id, [&] (Vram const &b) {
cap = _gpu.export_vram(b.id());
});
return cap;
}
Buffer *import_vram(Gpu::Vram_capability cap, Gpu::Vram const &v)
Buffer *import_vram(Gpu::Vram_capability cap, Vram const &v)
{
Buffer *b = nullptr;
@ -675,7 +679,7 @@ class Etnaviv::Call
[&] () {
_main_ctx->gpu().upgrade_ram(donate);
});
} catch (Gpu::Vram::Allocation_failed) {
} catch (Vram::Allocation_failed) {
return;
}

View File

@ -198,6 +198,7 @@ namespace Lima {
using namespace Genode;
using namespace Gpu;
struct Vram;
struct Call;
} /* namespace Lima */
@ -205,7 +206,11 @@ namespace Lima {
/*
* Gpu::Vram encapsulates a buffer object allocation
*/
struct Gpu::Vram
struct Gpu::Vram { };
/* use separate namespace for Vram implementation */
struct Lima::Vram : Gpu::Vram
{
struct Allocation_failed : Genode::Exception { };
@ -331,10 +336,10 @@ class Lima::Call
{
Genode::Id_space<Buffer>::Element const _elem;
Gpu::Vram const &_vram;
Vram const &_vram;
Buffer(Genode::Id_space<Buffer> &space,
Gpu::Vram const &vram)
Vram const &vram)
:
_elem { *this, space,
Genode::Id_space<Buffer>::Id { .value = vram.id().value } },
@ -437,7 +442,7 @@ class Lima::Call
* required by the Gpu session to pass on driver specific
* command buffer.
*/
Gpu::Vram *_exec_buffer;
Vram *_exec_buffer;
public:
@ -455,9 +460,9 @@ class Lima::Call
_id { _stat_gpu(_fd) },
_elem { *this, space },
_va_alloc { va_alloc },
_exec_buffer { new (alloc) Gpu::Vram(_gpu, _exec_buffer_size,
_va_alloc.alloc(_exec_buffer_size),
_vram_space) }
_exec_buffer { new (alloc) Vram(_gpu, _exec_buffer_size,
_va_alloc.alloc(_exec_buffer_size),
_vram_space) }
{ }
~Gpu_context()
@ -482,16 +487,16 @@ class Lima::Call
return _gpu;
}
Gpu::Vram_capability export_vram(Gpu::Vram_id id)
Gpu::Vram_capability export_vram(Vram_id id)
{
Gpu::Vram_capability cap { };
_try_apply(id, [&] (Gpu::Vram const &b) {
_try_apply(id, [&] (Vram const &b) {
cap = _gpu.export_vram(b.id());
});
return cap;
}
Buffer *import_vram(Gpu::Vram_capability cap, Gpu::Vram const &v)
Buffer *import_vram(Gpu::Vram_capability cap, Vram const &v)
{
Buffer *b = nullptr;
@ -764,7 +769,7 @@ class Lima::Call
[&] () {
_main_ctx->gpu().upgrade_ram(donate);
});
} catch (Gpu::Vram::Allocation_failed) {
} catch (Vram::Allocation_failed) {
_va_alloc.free(va);
return;
}
@ -802,7 +807,7 @@ class Lima::Call
Buffer_space::Id const id = { .value = handle };
if (!gc.buffer_space_contains(id)) {
(void)_apply_handle(handle, [&] (Gpu::Vram const &v) {
(void)_apply_handle(handle, [&] (Vram const &v) {
Gpu::Vram_capability cap = _main_ctx->export_vram(v.id());
if (gc.import_vram(cap, v) == nullptr) {
Genode::error("could force mapping of buffer ", handle);
@ -824,7 +829,7 @@ class Lima::Call
if (!gc.buffer_space_contains(id)) {
bool imported = false;
(void)_apply_handle(bo.handle, [&] (Gpu::Vram const &v) {
(void)_apply_handle(bo.handle, [&] (Vram const &v) {
Gpu::Vram_capability cap = _main_ctx->export_vram(v.id());
if (gc.import_vram(cap, v) == nullptr)
return;
@ -986,7 +991,7 @@ class Lima::Call
_gpu_context_space.for_each<Gpu_context>(free_buffer);
return _apply_handle(gem_close.handle,
[&] (Gpu::Vram &b) {
[&] (Lima::Vram &b) {
_va_alloc.free(b.va);
destroy(_heap, &b);
}) ? 0 : -1;