From 59011a04a10d20804eb1eb4c8164b64d0f0ca824 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 14 Feb 2024 00:09:29 -0500 Subject: [PATCH] vi: rewrite IHOSBinderDriver --- src/core/hle/service/nvnflinger/binder.h | 5 +- .../nvnflinger/buffer_queue_producer.cpp | 9 ++- .../nvnflinger/buffer_queue_producer.h | 3 +- src/core/hle/service/vi/hos_binder_driver.cpp | 67 ++++++++----------- src/core/hle/service/vi/hos_binder_driver.h | 18 +++-- 5 files changed, 53 insertions(+), 49 deletions(-) diff --git a/src/core/hle/service/nvnflinger/binder.h b/src/core/hle/service/nvnflinger/binder.h index aef1477e3..179938192 100644 --- a/src/core/hle/service/nvnflinger/binder.h +++ b/src/core/hle/service/nvnflinger/binder.h @@ -6,6 +6,8 @@ #pragma once +#include + #include "common/common_types.h" namespace Kernel { @@ -38,7 +40,8 @@ enum class TransactionId { class IBinder { public: virtual ~IBinder() = default; - virtual void Transact(HLERequestContext& ctx, android::TransactionId code, u32 flags) = 0; + virtual void Transact(android::TransactionId code, u32 flags, std::span parcel_data, + std::span parcel_reply) = 0; virtual Kernel::KReadableEvent& GetNativeHandle() = 0; }; diff --git a/src/core/hle/service/nvnflinger/buffer_queue_producer.cpp b/src/core/hle/service/nvnflinger/buffer_queue_producer.cpp index 5d8762d25..ec83beb9b 100644 --- a/src/core/hle/service/nvnflinger/buffer_queue_producer.cpp +++ b/src/core/hle/service/nvnflinger/buffer_queue_producer.cpp @@ -807,9 +807,10 @@ Status BufferQueueProducer::SetPreallocatedBuffer(s32 slot, return Status::NoError; } -void BufferQueueProducer::Transact(HLERequestContext& ctx, TransactionId code, u32 flags) { +void BufferQueueProducer::Transact(TransactionId code, u32 flags, std::span parcel_data, + std::span parcel_reply) { Status status{Status::NoError}; - InputParcel parcel_in{ctx.ReadBuffer()}; + InputParcel parcel_in{parcel_data}; OutputParcel parcel_out{}; switch (code) { @@ -917,7 +918,9 @@ void BufferQueueProducer::Transact(HLERequestContext& ctx, TransactionId code, u parcel_out.Write(status); - ctx.WriteBuffer(parcel_out.Serialize()); + const auto serialized = parcel_out.Serialize(); + std::memcpy(parcel_reply.data(), serialized.data(), + std::min(parcel_reply.size(), serialized.size())); } Kernel::KReadableEvent& BufferQueueProducer::GetNativeHandle() { diff --git a/src/core/hle/service/nvnflinger/buffer_queue_producer.h b/src/core/hle/service/nvnflinger/buffer_queue_producer.h index 64c17d56c..4682b0f84 100644 --- a/src/core/hle/service/nvnflinger/buffer_queue_producer.h +++ b/src/core/hle/service/nvnflinger/buffer_queue_producer.h @@ -47,7 +47,8 @@ public: Service::Nvidia::NvCore::NvMap& nvmap_); ~BufferQueueProducer(); - void Transact(HLERequestContext& ctx, android::TransactionId code, u32 flags) override; + void Transact(android::TransactionId code, u32 flags, std::span parcel_data, + std::span parcel_reply) override; Kernel::KReadableEvent& GetNativeHandle() override; diff --git a/src/core/hle/service/vi/hos_binder_driver.cpp b/src/core/hle/service/vi/hos_binder_driver.cpp index e04acc297..ba0317245 100644 --- a/src/core/hle/service/vi/hos_binder_driver.cpp +++ b/src/core/hle/service/vi/hos_binder_driver.cpp @@ -1,64 +1,53 @@ // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/cmif_serialization.h" #include "core/hle/service/nvnflinger/binder.h" #include "core/hle/service/nvnflinger/hos_binder_driver_server.h" #include "core/hle/service/vi/hos_binder_driver.h" namespace Service::VI { -IHOSBinderDriver::IHOSBinderDriver(Core::System& system_, - Nvnflinger::HosBinderDriverServer& server_) - : ServiceFramework{system_, "IHOSBinderDriver"}, server(server_) { +IHOSBinderDriver::IHOSBinderDriver(Core::System& system_, Nvnflinger::HosBinderDriverServer& server) + : ServiceFramework{system_, "IHOSBinderDriver"}, m_server(server) { static const FunctionInfo functions[] = { - {0, &IHOSBinderDriver::TransactParcel, "TransactParcel"}, - {1, &IHOSBinderDriver::AdjustRefcount, "AdjustRefcount"}, - {2, &IHOSBinderDriver::GetNativeHandle, "GetNativeHandle"}, - {3, &IHOSBinderDriver::TransactParcel, "TransactParcelAuto"}, + {0, C<&IHOSBinderDriver::TransactParcel>, "TransactParcel"}, + {1, C<&IHOSBinderDriver::AdjustRefcount>, "AdjustRefcount"}, + {2, C<&IHOSBinderDriver::GetNativeHandle>, "GetNativeHandle"}, + {3, C<&IHOSBinderDriver::TransactParcelAuto>, "TransactParcelAuto"}, }; RegisterHandlers(functions); } IHOSBinderDriver::~IHOSBinderDriver() = default; -void IHOSBinderDriver::TransactParcel(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const u32 id = rp.Pop(); - const auto transaction = static_cast(rp.Pop()); - const u32 flags = rp.Pop(); - - LOG_DEBUG(Service_VI, "called. id=0x{:08X} transaction={:X}, flags=0x{:08X}", id, transaction, +Result IHOSBinderDriver::TransactParcel(s32 binder_id, android::TransactionId transaction_id, + InBuffer parcel_data, + OutBuffer parcel_reply, + u32 flags) { + LOG_DEBUG(Service_VI, "called. id={} transaction={}, flags={}", binder_id, transaction_id, flags); - - server.TryGetProducer(id)->Transact(ctx, transaction, flags); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + m_server.TryGetProducer(binder_id)->Transact(transaction_id, flags, parcel_data, parcel_reply); + R_SUCCEED(); } -void IHOSBinderDriver::AdjustRefcount(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const u32 id = rp.Pop(); - const s32 addval = rp.PopRaw(); - const u32 type = rp.Pop(); - - LOG_WARNING(Service_VI, "(STUBBED) called id={}, addval={:08X}, type={:08X}", id, addval, type); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IHOSBinderDriver::AdjustRefcount(s32 binder_id, s32 addval, s32 type) { + LOG_WARNING(Service_VI, "(STUBBED) called id={}, addval={}, type={}", binder_id, addval, type); + R_SUCCEED(); } -void IHOSBinderDriver::GetNativeHandle(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const u32 id = rp.Pop(); - const u32 unknown = rp.Pop(); +Result IHOSBinderDriver::GetNativeHandle(s32 binder_id, u32 type_id, + OutCopyHandle out_handle) { + LOG_WARNING(Service_VI, "(STUBBED) called id={}, type_id={}", binder_id, type_id); + *out_handle = &m_server.TryGetProducer(binder_id)->GetNativeHandle(); + R_SUCCEED(); +} - LOG_WARNING(Service_VI, "(STUBBED) called id={}, unknown={:08X}", id, unknown); - - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(ResultSuccess); - rb.PushCopyObjects(server.TryGetProducer(id)->GetNativeHandle()); +Result IHOSBinderDriver::TransactParcelAuto(s32 binder_id, android::TransactionId transaction_id, + InBuffer parcel_data, + OutBuffer parcel_reply, + u32 flags) { + R_RETURN(this->TransactParcel(binder_id, transaction_id, parcel_data, parcel_reply, flags)); } } // namespace Service::VI diff --git a/src/core/hle/service/vi/hos_binder_driver.h b/src/core/hle/service/vi/hos_binder_driver.h index 24780c7d8..ed6e8cdbe 100644 --- a/src/core/hle/service/vi/hos_binder_driver.h +++ b/src/core/hle/service/vi/hos_binder_driver.h @@ -1,22 +1,30 @@ // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include "core/hle/service/cmif_types.h" +#include "core/hle/service/nvnflinger/binder.h" #include "core/hle/service/service.h" namespace Service::VI { class IHOSBinderDriver final : public ServiceFramework { public: - explicit IHOSBinderDriver(Core::System& system_, Nvnflinger::HosBinderDriverServer& server_); + explicit IHOSBinderDriver(Core::System& system_, Nvnflinger::HosBinderDriverServer& server); ~IHOSBinderDriver() override; private: - void TransactParcel(HLERequestContext& ctx); - void AdjustRefcount(HLERequestContext& ctx); - void GetNativeHandle(HLERequestContext& ctx); + Result TransactParcel(s32 binder_id, android::TransactionId transaction_id, + InBuffer parcel_data, + OutBuffer parcel_reply, u32 flags); + Result AdjustRefcount(s32 binder_id, s32 addval, s32 type); + Result GetNativeHandle(s32 binder_id, u32 type_id, + OutCopyHandle out_handle); + Result TransactParcelAuto(s32 binder_id, android::TransactionId transaction_id, + InBuffer parcel_data, + OutBuffer parcel_reply, u32 flags); private: - Nvnflinger::HosBinderDriverServer& server; + Nvnflinger::HosBinderDriverServer& m_server; }; } // namespace Service::VI