summaryrefslogtreecommitdiff
path: root/src/core/hle/service/nvnflinger/hos_binder_driver.cpp
blob: aa4127ca35a023ff0afae7ffa223ed36d8e722c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "core/hle/service/cmif_serialization.h"
#include "core/hle/service/nvnflinger/binder.h"
#include "core/hle/service/nvnflinger/hos_binder_driver.h"
#include "core/hle/service/nvnflinger/hos_binder_driver_server.h"
#include <atomic>

namespace Service::Nvnflinger {

IHOSBinderDriver::IHOSBinderDriver(Core::System& system_,
                                   std::shared_ptr<HosBinderDriverServer> server,
                                   std::shared_ptr<SurfaceFlinger> surface_flinger)
    : ServiceFramework{system_, "IHOSBinderDriver"}, m_server(server),
      m_surface_flinger(surface_flinger) {
    static const FunctionInfo functions[] = {
        {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;

Result IHOSBinderDriver::TransactParcel(s32 binder_id, u32 transaction_id,
                                        InBuffer<BufferAttr_HipcMapAlias> parcel_data,
                                        OutBuffer<BufferAttr_HipcMapAlias> parcel_reply,
                                        u32 flags) {
    LOG_DEBUG(Service_VI, "called. id={} transaction={}, flags={}", binder_id, transaction_id,
              flags);

    const auto binder = m_server->TryGetBinder(binder_id);
    R_SUCCEED_IF(binder == nullptr);

    binder->Transact(transaction_id, parcel_data, parcel_reply, flags);

    R_SUCCEED();
}

Result IHOSBinderDriver::AdjustRefcount(s32 binder_id, s32 addval, s32 type) {
    LOG_DEBUG(Service_VI, "called id={}, addval={}, type={}", binder_id, addval, type);

    const auto binder = m_server->TryGetBinder(binder_id);
    R_SUCCEED_IF(binder == nullptr);

    // type 0 = weak reference, type 1 = strong reference
    if (type == 0) {
        binder->AdjustWeakRefcount(addval);
    } else if (type == 1) {
        binder->AdjustStrongRefcount(addval);
    } else {
        LOG_ERROR(Service_VI, "Invalid refcount type {}", type);
        R_THROW(Kernel::ResultInvalidArgument);
    }

    R_SUCCEED();
}

Result IHOSBinderDriver::GetNativeHandle(s32 binder_id, u32 type_id,
                                         OutCopyHandle<Kernel::KReadableEvent> out_handle) {
    LOG_DEBUG(Service_VI, "called id={}, type_id={}", binder_id, type_id);

    const auto binder = m_server->TryGetBinder(binder_id);
    R_UNLESS(binder != nullptr, ResultUnknown);

    *out_handle = binder->GetNativeHandle(type_id);

    R_SUCCEED();
}

Result IHOSBinderDriver::TransactParcelAuto(s32 binder_id, u32 transaction_id,
                                            InBuffer<BufferAttr_HipcAutoSelect> parcel_data,
                                            OutBuffer<BufferAttr_HipcAutoSelect> parcel_reply,
                                            u32 flags) {
    R_RETURN(this->TransactParcel(binder_id, transaction_id, parcel_data, parcel_reply, flags));
}

} // namespace Service::Nvnflinger