2017-04-26 09:10:52 +00:00
|
|
|
/*
|
|
|
|
* \brief Gpu session interface.
|
|
|
|
* \author Josef Soentgen
|
|
|
|
* \date 2017-04-28
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Genode Labs GmbH
|
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__GPU_SESSION__GPU_SESSION_H_
|
|
|
|
#define _INCLUDE__GPU_SESSION__GPU_SESSION_H_
|
|
|
|
|
2021-09-23 15:37:51 +00:00
|
|
|
#include <base/id_space.h>
|
2017-04-26 09:10:52 +00:00
|
|
|
#include <session/session.h>
|
|
|
|
|
|
|
|
namespace Gpu {
|
|
|
|
|
|
|
|
using addr_t = Genode::uint64_t;
|
|
|
|
|
2021-09-23 15:37:51 +00:00
|
|
|
struct Buffer;
|
|
|
|
using Buffer_id = Genode::Id_space<Buffer>::Id;
|
|
|
|
|
2017-04-26 09:10:52 +00:00
|
|
|
struct Info;
|
|
|
|
struct Session;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Gpu information
|
|
|
|
*
|
|
|
|
* Used to query information in the DRM backend
|
|
|
|
*/
|
|
|
|
struct Gpu::Info
|
|
|
|
{
|
|
|
|
using Chip_id = Genode::uint16_t;
|
|
|
|
using Features = Genode::uint32_t;
|
|
|
|
using size_t = Genode::size_t;
|
|
|
|
using Context_id = Genode::uint32_t;
|
|
|
|
|
|
|
|
Chip_id chip_id;
|
|
|
|
Features features;
|
|
|
|
size_t aperture_size;
|
|
|
|
Context_id ctx_id;
|
|
|
|
|
2021-06-18 12:07:21 +00:00
|
|
|
struct Execution_buffer_sequence {
|
|
|
|
Genode::uint64_t id;
|
|
|
|
} last_completed;
|
|
|
|
|
2021-08-05 09:06:31 +00:00
|
|
|
struct Revision { Genode::uint8_t value; } revision;
|
|
|
|
struct Slice_mask { unsigned value; } slice_mask;
|
|
|
|
struct Subslice_mask { unsigned value; } subslice_mask;
|
|
|
|
struct Eu_total { unsigned value; } eus;
|
|
|
|
struct Subslices { unsigned value; } subslices;
|
2021-06-18 12:07:21 +00:00
|
|
|
|
|
|
|
Info(Chip_id chip_id, Features features, size_t aperture_size,
|
2021-08-05 09:06:31 +00:00
|
|
|
Context_id ctx_id, Execution_buffer_sequence last,
|
|
|
|
Revision rev, Slice_mask s_mask, Subslice_mask ss_mask,
|
|
|
|
Eu_total eu, Subslices subslice)
|
2017-04-26 09:10:52 +00:00
|
|
|
:
|
|
|
|
chip_id(chip_id), features(features),
|
2021-06-18 12:07:21 +00:00
|
|
|
aperture_size(aperture_size), ctx_id(ctx_id),
|
2021-08-05 09:06:31 +00:00
|
|
|
last_completed(last),
|
|
|
|
revision(rev),
|
|
|
|
slice_mask(s_mask),
|
|
|
|
subslice_mask(ss_mask),
|
|
|
|
eus(eu),
|
|
|
|
subslices(subslice)
|
2017-04-26 09:10:52 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Gpu session interface
|
|
|
|
*/
|
|
|
|
struct Gpu::Session : public Genode::Session
|
|
|
|
{
|
2021-09-23 15:37:51 +00:00
|
|
|
struct Out_of_ram : Genode::Exception { };
|
|
|
|
struct Out_of_caps : Genode::Exception { };
|
|
|
|
struct Invalid_state : Genode::Exception { };
|
|
|
|
struct Conflicting_id : Genode::Exception { };
|
2017-09-05 12:03:36 +00:00
|
|
|
struct Mapping_buffer_failed : Genode::Exception { };
|
2017-04-26 09:10:52 +00:00
|
|
|
|
|
|
|
enum { REQUIRED_QUOTA = 1024 * 1024, CAP_QUOTA = 8, };
|
|
|
|
|
|
|
|
static const char *service_name() { return "Gpu"; }
|
|
|
|
|
|
|
|
virtual ~Session() { }
|
|
|
|
|
|
|
|
/***********************
|
|
|
|
** Session interface **
|
|
|
|
***********************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query GPU information
|
|
|
|
*/
|
|
|
|
virtual Info info() const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute commands from given buffer
|
|
|
|
*
|
2021-09-23 15:37:51 +00:00
|
|
|
* \param id buffer id
|
2017-04-26 09:10:52 +00:00
|
|
|
* \param size size of the batch buffer in bytes
|
2021-06-18 12:07:21 +00:00
|
|
|
*
|
|
|
|
* \return execution buffer sequence number for complete checks
|
|
|
|
*
|
|
|
|
* \throw Invalid_state is thrown if the provided buffer is not valid, e.g not mapped
|
2017-04-26 09:10:52 +00:00
|
|
|
*/
|
2021-09-23 15:37:51 +00:00
|
|
|
virtual Gpu::Info::Execution_buffer_sequence exec_buffer(Buffer_id id, Genode::size_t size) = 0;
|
2017-04-26 09:10:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register completion signal handler
|
|
|
|
*
|
|
|
|
* \param sigh signal handler that is called when the execution
|
|
|
|
* has completed
|
|
|
|
*/
|
|
|
|
virtual void completion_sigh(Genode::Signal_context_capability sigh) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocate buffer dataspace
|
|
|
|
*
|
2021-09-23 15:37:51 +00:00
|
|
|
* \param id buffer id to be associated with the buffer
|
2017-04-26 09:10:52 +00:00
|
|
|
* \param size size of buffer in bytes
|
|
|
|
*
|
|
|
|
* \throw Out_of_ram
|
|
|
|
* \throw Out_of_caps
|
2021-09-23 15:37:51 +00:00
|
|
|
* \throw Conflicting_id
|
2017-04-26 09:10:52 +00:00
|
|
|
*/
|
2021-09-23 15:37:51 +00:00
|
|
|
virtual Genode::Dataspace_capability alloc_buffer(Buffer_id id, Genode::size_t size) = 0;
|
2017-04-26 09:10:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Free buffer dataspace
|
|
|
|
*
|
|
|
|
* \param ds dataspace capability for buffer
|
|
|
|
*/
|
2021-09-23 15:37:51 +00:00
|
|
|
virtual void free_buffer(Buffer_id id) = 0;
|
2017-04-26 09:10:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Map buffer
|
|
|
|
*
|
2021-09-23 15:37:51 +00:00
|
|
|
* \param id buffer id
|
2017-04-26 09:10:52 +00:00
|
|
|
* \param aperture if true create CPU accessible mapping through
|
|
|
|
* GGTT window, otherwise create PPGTT mapping
|
2017-09-05 12:03:36 +00:00
|
|
|
*
|
|
|
|
* \throw Mapping_buffer_failed
|
2017-04-26 09:10:52 +00:00
|
|
|
*/
|
2021-09-23 15:37:51 +00:00
|
|
|
virtual Genode::Dataspace_capability map_buffer(Buffer_id id,
|
2017-04-26 09:10:52 +00:00
|
|
|
bool aperture) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unmap buffer
|
|
|
|
*
|
2021-09-23 15:37:51 +00:00
|
|
|
* \param id buffer id
|
2017-04-26 09:10:52 +00:00
|
|
|
*/
|
2021-09-23 15:37:51 +00:00
|
|
|
virtual void unmap_buffer(Buffer_id id) = 0;
|
2017-04-26 09:10:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Map buffer in PPGTT
|
|
|
|
*
|
2021-09-23 15:37:51 +00:00
|
|
|
* \param id buffer id
|
2017-04-26 09:10:52 +00:00
|
|
|
* \param va virtual address
|
2017-09-05 12:03:36 +00:00
|
|
|
*
|
|
|
|
* \throw Mapping_buffer_failed
|
|
|
|
* \throw Out_of_ram
|
2017-04-26 09:10:52 +00:00
|
|
|
*/
|
2021-09-23 15:37:51 +00:00
|
|
|
virtual bool map_buffer_ppgtt(Buffer_id id, Gpu::addr_t va) = 0;
|
2017-04-26 09:10:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unmap buffer
|
|
|
|
*
|
2021-09-23 15:37:51 +00:00
|
|
|
* \param id buffer id
|
2017-04-26 09:10:52 +00:00
|
|
|
*/
|
2021-09-23 15:37:51 +00:00
|
|
|
virtual void unmap_buffer_ppgtt(Buffer_id id, Gpu::addr_t) = 0;
|
2017-04-26 09:10:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set tiling for buffer
|
|
|
|
*
|
2021-09-23 15:37:51 +00:00
|
|
|
* \param id buffer id
|
2017-04-26 09:10:52 +00:00
|
|
|
* \param mode tiling mode
|
|
|
|
*/
|
2021-09-23 15:37:51 +00:00
|
|
|
virtual bool set_tiling(Buffer_id id, unsigned mode) = 0;
|
2017-04-26 09:10:52 +00:00
|
|
|
|
|
|
|
/*******************
|
|
|
|
** RPC interface **
|
|
|
|
*******************/
|
|
|
|
|
|
|
|
GENODE_RPC(Rpc_info, Info, info);
|
2021-06-18 12:07:21 +00:00
|
|
|
GENODE_RPC_THROW(Rpc_exec_buffer, Gpu::Info::Execution_buffer_sequence, exec_buffer,
|
|
|
|
GENODE_TYPE_LIST(Invalid_state),
|
2021-09-23 15:37:51 +00:00
|
|
|
Gpu::Buffer_id, Genode::size_t);
|
2017-04-26 09:10:52 +00:00
|
|
|
GENODE_RPC(Rpc_completion_sigh, void, completion_sigh,
|
|
|
|
Genode::Signal_context_capability);
|
|
|
|
GENODE_RPC_THROW(Rpc_alloc_buffer, Genode::Dataspace_capability, alloc_buffer,
|
|
|
|
GENODE_TYPE_LIST(Out_of_ram),
|
2021-09-23 15:37:51 +00:00
|
|
|
Gpu::Buffer_id, Genode::size_t);
|
|
|
|
GENODE_RPC(Rpc_free_buffer, void, free_buffer, Gpu::Buffer_id);
|
2017-04-26 09:10:52 +00:00
|
|
|
GENODE_RPC_THROW(Rpc_map_buffer, Genode::Dataspace_capability, map_buffer,
|
2017-09-05 12:03:36 +00:00
|
|
|
GENODE_TYPE_LIST(Mapping_buffer_failed, Out_of_ram),
|
2021-09-23 15:37:51 +00:00
|
|
|
Gpu::Buffer_id, bool);
|
2017-04-26 09:10:52 +00:00
|
|
|
GENODE_RPC(Rpc_unmap_buffer, void, unmap_buffer,
|
2021-09-23 15:37:51 +00:00
|
|
|
Gpu::Buffer_id);
|
2017-04-26 09:10:52 +00:00
|
|
|
GENODE_RPC_THROW(Rpc_map_buffer_ppgtt, bool, map_buffer_ppgtt,
|
2017-09-05 12:03:36 +00:00
|
|
|
GENODE_TYPE_LIST(Mapping_buffer_failed, Out_of_ram),
|
2021-09-23 15:37:51 +00:00
|
|
|
Gpu::Buffer_id, Gpu::addr_t);
|
2017-04-26 09:10:52 +00:00
|
|
|
GENODE_RPC(Rpc_unmap_buffer_ppgtt, void, unmap_buffer_ppgtt,
|
2021-09-23 15:37:51 +00:00
|
|
|
Gpu::Buffer_id, Gpu::addr_t);
|
2017-04-26 09:10:52 +00:00
|
|
|
GENODE_RPC(Rpc_set_tiling, bool, set_tiling,
|
2021-09-23 15:37:51 +00:00
|
|
|
Gpu::Buffer_id, unsigned);
|
2017-04-26 09:10:52 +00:00
|
|
|
|
|
|
|
GENODE_RPC_INTERFACE(Rpc_info, Rpc_exec_buffer,
|
|
|
|
Rpc_completion_sigh, Rpc_alloc_buffer,
|
|
|
|
Rpc_free_buffer, Rpc_map_buffer, Rpc_unmap_buffer,
|
|
|
|
Rpc_map_buffer_ppgtt, Rpc_unmap_buffer_ppgtt,
|
|
|
|
Rpc_set_tiling);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__GPU_SESSION__GPU_SESSION_H_ */
|