summaryrefslogtreecommitdiffstats
path: root/src/audio_core/adsp/mailbox.h
diff options
context:
space:
mode:
authorKelebek1 <eeeedddccc@hotmail.co.uk>2023-08-31 16:09:15 +0200
committerKelebek1 <eeeedddccc@hotmail.co.uk>2023-09-04 18:12:16 +0200
commitebd19dec99d9809a669f63294745d7c8facc6d31 (patch)
treecd1f34cac0c091c2ffd16c429ac33b8fe133e06e /src/audio_core/adsp/mailbox.h
parentMerge pull request #11420 from t895/long-install-fix (diff)
downloadyuzu-ebd19dec99d9809a669f63294745d7c8facc6d31.tar
yuzu-ebd19dec99d9809a669f63294745d7c8facc6d31.tar.gz
yuzu-ebd19dec99d9809a669f63294745d7c8facc6d31.tar.bz2
yuzu-ebd19dec99d9809a669f63294745d7c8facc6d31.tar.lz
yuzu-ebd19dec99d9809a669f63294745d7c8facc6d31.tar.xz
yuzu-ebd19dec99d9809a669f63294745d7c8facc6d31.tar.zst
yuzu-ebd19dec99d9809a669f63294745d7c8facc6d31.zip
Diffstat (limited to '')
-rw-r--r--src/audio_core/adsp/mailbox.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/audio_core/adsp/mailbox.h b/src/audio_core/adsp/mailbox.h
new file mode 100644
index 000000000..c31b73717
--- /dev/null
+++ b/src/audio_core/adsp/mailbox.h
@@ -0,0 +1,69 @@
+// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include "common/bounded_threadsafe_queue.h"
+#include "common/common_types.h"
+
+namespace AudioCore::ADSP {
+
+enum class AppMailboxId : u32 {
+ Invalid = 0,
+ AudioRenderer = 50,
+ AudioRendererMemoryMapUnmap = 51,
+};
+
+enum class Direction : u32 {
+ Host,
+ DSP,
+};
+
+struct MailboxMessage {
+ u32 msg;
+ std::span<u8> data;
+};
+
+class Mailbox {
+public:
+ void Initialize(AppMailboxId id_) {
+ Reset();
+ id = id_;
+ }
+
+ AppMailboxId Id() const noexcept {
+ return id;
+ }
+
+ void Send(Direction dir, MailboxMessage&& message) {
+ auto& queue = dir == Direction::Host ? host_queue : adsp_queue;
+ queue.EmplaceWait(std::move(message));
+ }
+
+ MailboxMessage Receive(Direction dir, bool block = true) {
+ auto& queue = dir == Direction::Host ? host_queue : adsp_queue;
+ MailboxMessage t;
+ if (block) {
+ queue.PopWait(t);
+ } else {
+ queue.TryPop(t);
+ }
+ return t;
+ }
+
+ void Reset() {
+ id = AppMailboxId::Invalid;
+ MailboxMessage t;
+ while (host_queue.TryPop(t)) {
+ }
+ while (adsp_queue.TryPop(t)) {
+ }
+ }
+
+private:
+ AppMailboxId id{0};
+ Common::SPSCQueue<MailboxMessage> host_queue;
+ Common::SPSCQueue<MailboxMessage> adsp_queue;
+};
+
+} // namespace AudioCore::ADSP