Revert "hoc-clk: add live vdd2, live boost clock and basic pwm dimming"

This reverts commit 15b7df8ef1.
This commit is contained in:
souldbminersmwc
2025-11-09 16:14:52 -05:00
parent 22ec140738
commit 21a3f953d7
3804 changed files with 435 additions and 570162 deletions

View File

@@ -1,52 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#if defined(ATMOSPHERE_OS_HORIZON)
#include <stratosphere/os/impl/os_internal_busy_mutex_impl.os.horizon.hpp>
#elif defined(ATMOSPHERE_OS_WINDOWS) || defined(ATMOSPHERE_OS_LINUX) || defined(ATMOSPHERE_OS_MACOS)
#include <stratosphere/os/impl/os_internal_busy_mutex_impl.os.generic.hpp>
#else
#error "Unknown OS for ams::os::impl::InternalBusyMutexImpl"
#endif
namespace ams::os::impl {
class InternalBusyMutex {
private:
InternalBusyMutexImpl m_impl;
public:
constexpr InternalBusyMutex() : m_impl() { /* ... */ }
ALWAYS_INLINE void Initialize() { m_impl.Initialize(); }
ALWAYS_INLINE void Finalize() { m_impl.Finalize(); }
ALWAYS_INLINE bool IsLocked() const { return m_impl.IsLocked(); }
ALWAYS_INLINE void Lock() { return m_impl.Lock(); }
ALWAYS_INLINE bool TryLock() { return m_impl.TryLock(); }
ALWAYS_INLINE void Unlock() { return m_impl.Unlock(); }
ALWAYS_INLINE void lock() { return this->Lock(); }
ALWAYS_INLINE bool try_lock() { return this->TryLock(); }
ALWAYS_INLINE void unlock() { return this->Unlock(); }
};
using InternalBusyMutexStorage = util::TypedStorage<InternalBusyMutex>;
}

View File

@@ -1,62 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::os::impl {
class InternalBusyMutexImpl {
private:
std::atomic<bool> m_value{false};
u8 m_padding[3]{};
public:
constexpr InternalBusyMutexImpl() = default;
ALWAYS_INLINE void Initialize() { m_value.store(false, std::memory_order_relaxed); }
ALWAYS_INLINE void Finalize() { /* ... */ }
ALWAYS_INLINE bool IsLocked() const { return m_value.load(std::memory_order_acquire); }
ALWAYS_INLINE bool TryLock() {
bool expected = false;
return m_value.compare_exchange_weak(expected, true, std::memory_order_acquire, std::memory_order_acquire);
}
ALWAYS_INLINE void Lock() {
while (!this->TryLock()) {
#if defined(ATMOSPHERE_ARCH_X64) || defined(ATMOSPHERE_ARCH_X86)
_mm_pause();
#elif defined(ATMOSPHERE_ARCH_ARM64) || defined(ATMOSPHERE_ARCH_ARM)
__asm__ __volatile__("yield" ::: "memory");
#else
#error "InternalBusyMutex requires yield intrinsics"
#endif
}
}
ALWAYS_INLINE void Unlock() {
m_value.store(false, std::memory_order_release);
}
};
static_assert(sizeof(InternalBusyMutexImpl) == sizeof(u32));
#define AMS_OS_INTERNAL_BUSY_MUTEX_IMPL_CONSTANT_INITIALIZE_ARRAY_VALUES 0
}

View File

@@ -1,40 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::os::impl {
class InternalBusyMutexImpl {
private:
u32 m_value;
public:
constexpr InternalBusyMutexImpl() : m_value(0) { /* ... */ }
constexpr void Initialize() { m_value = 0; }
constexpr void Finalize() { /* ... */ }
constexpr bool IsLocked() const { return m_value != 0; }
void Lock();
bool TryLock();
void Unlock();
};
#define AMS_OS_INTERNAL_BUSY_MUTEX_IMPL_CONSTANT_INITIALIZE_ARRAY_VALUES 0
}

View File

@@ -1,66 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os/os_condition_variable_common.hpp>
#if defined(AMS_OS_IMPL_USE_PTHREADS)
#include <stratosphere/os/impl/os_internal_condition_variable_impl.pthread.hpp>
#elif defined(ATMOSPHERE_OS_HORIZON)
#include <stratosphere/os/impl/os_internal_condition_variable_impl.os.horizon.hpp>
#elif defined(ATMOSPHERE_OS_WINDOWS)
#include <stratosphere/os/impl/os_internal_condition_variable_impl.os.windows.hpp>
#else
#error "Unknown OS for ams::os::impl::InternalConditionVariableImpl"
#endif
namespace ams::os::impl {
class InternalConditionVariable {
private:
InternalConditionVariableImpl m_impl;
public:
constexpr InternalConditionVariable() : m_impl() { /* ... */ }
void Initialize() {
m_impl.Initialize();
}
void Finalize() {
m_impl.Finalize();
}
void Signal() {
m_impl.Signal();
}
void Broadcast() {
m_impl.Broadcast();
}
void Wait(InternalCriticalSection *cs) {
m_impl.Wait(cs);
}
ConditionVariableStatus TimedWait(InternalCriticalSection *cs, const TimeoutHelper &timeout_helper) {
return m_impl.TimedWait(cs, timeout_helper);
}
};
using InternalConditionVariableStorage = util::TypedStorage<InternalConditionVariable>;
}

View File

@@ -1,48 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os/os_condition_variable_common.hpp>
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
namespace ams::os::impl {
class TimeoutHelper;
class InternalConditionVariableImpl {
private:
u32 m_value;
public:
constexpr InternalConditionVariableImpl() : m_value(0) { /* ... */ }
constexpr void Initialize() {
m_value = 0;
}
constexpr void Finalize() { /* ... */ }
void Signal();
void Broadcast();
void Wait(InternalCriticalSection *cs);
ConditionVariableStatus TimedWait(InternalCriticalSection *cs, const TimeoutHelper &timeout_helper);
};
using InternalConditionVariableStorageTypeForConstantInitialize = u32;
#define AMS_OS_INTERNAL_CONDITION_VARIABLE_IMPL_CONSTANT_INITIALIZER {0}
}

View File

@@ -1,67 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os/os_condition_variable_common.hpp>
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
namespace ams::os::impl {
class TimeoutHelper;
struct WindowsConditionVariable;
using WindowsConditionVariableStorage = util::TypedStorage<WindowsConditionVariable, sizeof(void *), alignof(void *)>;
#if defined(ATMOSPHERE_ARCH_X64)
#define AMS_OS_WINDOWS_CONDITION_VARIABLE_CONSTANT_INITIALIZE_ARRAY_VALUES 0, 0
#elif defined(ATMOSPHERE_ARCH_X86)
#define AMS_OS_WINDOWS_CONDITION_VARIABLE_CONSTANT_INITIALIZE_ARRAY_VALUES 0
#else
#error "Unknown architecture for WindowsConditionVariable initializer"
#endif
class InternalConditionVariableImpl {
private:
u32 m_value;
public:
union {
s32 _arr[sizeof(WindowsConditionVariableStorage) / sizeof(s32)];
WindowsConditionVariableStorage m_windows_cv_storage;
};
constexpr InternalConditionVariableImpl() : _arr{AMS_OS_WINDOWS_CONDITION_VARIABLE_CONSTANT_INITIALIZE_ARRAY_VALUES} { /* ... */ }
constexpr ~InternalConditionVariableImpl() {
if (!std::is_constant_evaluated()) {
this->Finalize();
}
}
void Initialize();
void Finalize();
void Signal();
void Broadcast();
void Wait(InternalCriticalSection *cs);
ConditionVariableStatus TimedWait(InternalCriticalSection *cs, const TimeoutHelper &timeout_helper);
};
struct InternalConditionVariableStorageTypeForConstantInitialize { s32 _arr[sizeof(WindowsConditionVariableStorage) / sizeof(s32)]; };
#define AMS_OS_INTERNAL_CONDITION_VARIABLE_IMPL_CONSTANT_INITIALIZER { AMS_OS_WINDOWS_CONDITION_VARIABLE_CONSTANT_INITIALIZE_ARRAY_VALUES }
}

View File

@@ -1,52 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os/os_condition_variable_common.hpp>
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
namespace ams::os::impl {
class TimeoutHelper;
class InternalConditionVariableImpl {
private:
pthread_cond_t m_pthread_cond = PTHREAD_COND_INITIALIZER;
public:
constexpr InternalConditionVariableImpl() = default;
constexpr ~InternalConditionVariableImpl() {
if (!std::is_constant_evaluated()) {
this->Finalize();
}
}
void Initialize();
void Finalize();
void Signal();
void Broadcast();
void Wait(InternalCriticalSection *cs);
ConditionVariableStatus TimedWait(InternalCriticalSection *cs, const TimeoutHelper &timeout_helper);
};
using InternalConditionVariableStorageTypeForConstantInitialize = pthread_cond_t;
#define AMS_OS_INTERNAL_CONDITION_VARIABLE_IMPL_CONSTANT_INITIALIZER ._storage_for_constant_initialize = PTHREAD_COND_INITIALIZER
}

View File

@@ -1,68 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#if defined(AMS_OS_IMPL_USE_PTHREADS)
#include <stratosphere/os/impl/os_internal_critical_section_impl.pthread.hpp>
#elif defined(ATMOSPHERE_OS_HORIZON)
#include <stratosphere/os/impl/os_internal_critical_section_impl.os.horizon.hpp>
#elif defined(ATMOSPHERE_OS_WINDOWS)
#include <stratosphere/os/impl/os_internal_critical_section_impl.os.windows.hpp>
#else
#error "Unknown OS for ams::os::impl::InternalCriticalSectionImpl"
#endif
namespace ams::os::impl {
class InternalCriticalSection {
private:
InternalCriticalSectionImpl m_impl;
public:
constexpr InternalCriticalSection() : m_impl() { /* ... */ }
void Initialize() { m_impl.Initialize(); }
void Finalize() { m_impl.Finalize(); }
void Enter() { return m_impl.Enter(); }
bool TryEnter() { return m_impl.TryEnter(); }
void Leave() { return m_impl.Leave(); }
#if defined(AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD)
bool IsLockedByCurrentThread() const { return m_impl.IsLockedByCurrentThread(); }
#endif
ALWAYS_INLINE void Lock() { return this->Enter(); }
ALWAYS_INLINE bool TryLock() { return this->TryEnter(); }
ALWAYS_INLINE void Unlock() { return this->Leave(); }
ALWAYS_INLINE void lock() { return this->Lock(); }
ALWAYS_INLINE bool try_lock() { return this->TryLock(); }
ALWAYS_INLINE void unlock() { return this->Unlock(); }
InternalCriticalSectionImpl *Get() {
return std::addressof(m_impl);
}
const InternalCriticalSectionImpl *Get() const {
return std::addressof(m_impl);
}
};
using InternalCriticalSectionStorage = util::TypedStorage<InternalCriticalSection>;
}

View File

@@ -1,64 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::os::impl {
#if defined(ATMOSPHERE_OS_HORIZON)
class ReaderWriterLockHorizonImpl;
#endif
class InternalConditionVariableImpl;
class InternalCriticalSectionImpl {
private:
#if defined(ATMOSPHERE_OS_HORIZON)
friend class ReaderWriterLockHorizonImpl;
#endif
friend class InternalConditionVariableImpl;
private:
u32 m_thread_handle;
public:
constexpr InternalCriticalSectionImpl() : m_thread_handle(svc::InvalidHandle) { /* ... */ }
constexpr void Initialize() { m_thread_handle = svc::InvalidHandle; }
constexpr void Finalize() { /* ... */ }
void Enter();
bool TryEnter();
void Leave();
bool IsLockedByCurrentThread() const;
ALWAYS_INLINE void Lock() { return this->Enter(); }
ALWAYS_INLINE bool TryLock() { return this->TryEnter(); }
ALWAYS_INLINE void Unlock() { return this->Leave(); }
ALWAYS_INLINE void lock() { return this->Lock(); }
ALWAYS_INLINE bool try_lock() { return this->TryLock(); }
ALWAYS_INLINE void unlock() { return this->Unlock(); }
};
using InternalCriticalSectionStorageTypeForConstantInitialize = u32;
#define AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CONSTANT_INITIALIZER {0}
#define AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD
}

View File

@@ -1,76 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::os::impl {
class InternalConditionVariableImpl;
struct WindowsCriticalSection;
using WindowsCriticalSectionStorage = util::TypedStorage<WindowsCriticalSection, 8 + 4 * sizeof(void *), alignof(void *)>;
#if defined(ATMOSPHERE_ARCH_X64)
#define AMS_OS_WINDOWS_CRITICAL_SECTION_CONSTANT_INITIALIZE_ARRAY_VALUES -1, -1, -1, 0, 0, 0, 0, 0, 0, 0
#elif defined(ATMOSPHERE_ARCH_X86)
#define AMS_OS_WINDOWS_CRITICAL_SECTION_CONSTANT_INITIALIZE_ARRAY_VALUES -1, -1, 0, 0, 0, 0
#else
#error "Unknown architecture for WindowsCriticalSection initializer"
#endif
class InternalCriticalSectionImpl {
private:
friend class InternalConditionVariableImpl;
private:
union {
s32 _arr[sizeof(WindowsCriticalSectionStorage) / sizeof(s32)];
WindowsCriticalSectionStorage m_windows_critical_section_storage;
};
public:
constexpr InternalCriticalSectionImpl() : _arr{AMS_OS_WINDOWS_CRITICAL_SECTION_CONSTANT_INITIALIZE_ARRAY_VALUES} { /* ... */ }
constexpr ~InternalCriticalSectionImpl() {
if (!std::is_constant_evaluated()) {
this->Finalize();
}
}
void Initialize();
void Finalize();
void Enter();
bool TryEnter();
void Leave();
bool IsLockedByCurrentThread() const;
ALWAYS_INLINE void Lock() { return this->Enter(); }
ALWAYS_INLINE bool TryLock() { return this->TryEnter(); }
ALWAYS_INLINE void Unlock() { return this->Leave(); }
ALWAYS_INLINE void lock() { return this->Lock(); }
ALWAYS_INLINE bool try_lock() { return this->TryLock(); }
ALWAYS_INLINE void unlock() { return this->Unlock(); }
};
struct InternalCriticalSectionStorageTypeForConstantInitialize { s32 _arr[sizeof(WindowsCriticalSectionStorage) / sizeof(s32)]; };
#define AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CONSTANT_INITIALIZER { AMS_OS_WINDOWS_CRITICAL_SECTION_CONSTANT_INITIALIZE_ARRAY_VALUES }
#define AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD
}

View File

@@ -1,75 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os/os_common_types.hpp>
namespace ams::os::impl {
class InternalConditionVariableImpl;
/* NOTE: macOS (and possibly other targets) do not provide adaptive mutex. */
#if defined(PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP)
#define AMS_OS_IMPL_PTHREAD_MUTEX_INITIALIZER PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
#else
#define AMS_OS_IMPL_PTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#endif
#if defined(ATMOSPHERE_OS_LINUX)
#define AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD
#else
//#define AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD
#endif
class InternalCriticalSectionImpl {
private:
friend class InternalConditionVariableImpl;
private:
pthread_mutex_t m_pthread_mutex = AMS_OS_IMPL_PTHREAD_MUTEX_INITIALIZER;
public:
constexpr InternalCriticalSectionImpl() = default;
constexpr ~InternalCriticalSectionImpl() {
if (!std::is_constant_evaluated()) {
this->Finalize();
}
}
void Initialize();
void Finalize();
void Enter();
bool TryEnter();
void Leave();
#if defined(AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CAN_CHECK_LOCKED_BY_CURRENT_THREAD)
bool IsLockedByCurrentThread() const;
#endif
ALWAYS_INLINE void Lock() { return this->Enter(); }
ALWAYS_INLINE bool TryLock() { return this->TryEnter(); }
ALWAYS_INLINE void Unlock() { return this->Leave(); }
ALWAYS_INLINE void lock() { return this->Lock(); }
ALWAYS_INLINE bool try_lock() { return this->TryLock(); }
ALWAYS_INLINE void unlock() { return this->Unlock(); }
};
using InternalCriticalSectionStorageTypeForConstantInitialize = pthread_mutex_t;
#define AMS_OS_INTERNAL_CRITICAL_SECTION_IMPL_CONSTANT_INITIALIZER ._storage_for_constant_initialize = AMS_OS_IMPL_PTHREAD_MUTEX_INITIALIZER
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#if defined(ATMOSPHERE_OS_HORIZON)
#include <stratosphere/os/impl/os_internal_light_event_impl.os.horizon.hpp>
#elif defined(ATMOSPHERE_OS_WINDOWS) || defined(ATMOSPHERE_OS_LINUX) || defined(ATMOSPHERE_OS_MACOS)
#include <stratosphere/os/impl/os_internal_light_event_impl.os.generic.hpp>
#else
#error "Unknown OS for ams::os::impl::InternalLightEventImpl"
#endif
namespace ams::os::impl {
class InternalLightEvent {
private:
InternalLightEventImpl m_impl;
public:
explicit InternalLightEvent(bool signaled) : m_impl(signaled) { /* ... */ }
ALWAYS_INLINE void SignalWithAutoClear() { return m_impl.SignalWithAutoClear(); }
ALWAYS_INLINE void SignalWithManualClear() { return m_impl.SignalWithManualClear(); }
ALWAYS_INLINE void Clear() { return m_impl.Clear(); }
ALWAYS_INLINE void WaitWithAutoClear() { return m_impl.WaitWithAutoClear(); }
ALWAYS_INLINE void WaitWithManualClear() { return m_impl.WaitWithManualClear(); }
ALWAYS_INLINE bool TryWaitWithAutoClear() { return m_impl.TryWaitWithAutoClear(); }
ALWAYS_INLINE bool TryWaitWithManualClear() { return m_impl.TryWaitWithManualClear(); }
ALWAYS_INLINE bool TimedWaitWithAutoClear(const TimeoutHelper &timeout_helper) { return m_impl.TimedWaitWithAutoClear(timeout_helper); }
ALWAYS_INLINE bool TimedWaitWithManualClear(const TimeoutHelper &timeout_helper) { return m_impl.TimedWaitWithManualClear(timeout_helper); }
};
using InternalLightEventStorage = util::TypedStorage<InternalLightEvent>;
}

View File

@@ -1,54 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
#include <stratosphere/os/impl/os_internal_condition_variable.hpp>
namespace ams::os::impl {
class TimeoutHelper;
class InternalLightEventImpl {
private:
u16 m_counter_low;
u8 m_counter_high;
std::atomic<u8> m_signal_state;
InternalCriticalSection m_cs;
InternalConditionVariable m_cv;
public:
explicit InternalLightEventImpl(bool signaled) { this->Initialize(signaled); }
~InternalLightEventImpl() { this->Finalize(); }
void Initialize(bool signaled);
void Finalize();
void SignalWithAutoClear();
void SignalWithManualClear();
void Clear();
void WaitWithAutoClear();
void WaitWithManualClear();
bool TryWaitWithAutoClear();
bool TryWaitWithManualClear();
bool TimedWaitWithAutoClear(const TimeoutHelper &timeout_helper);
bool TimedWaitWithManualClear(const TimeoutHelper &timeout_helper);
};
}

View File

@@ -1,49 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::os::impl {
class TimeoutHelper;
class InternalLightEventImpl {
private:
std::atomic<s32> m_state;
u32 m_padding;
public:
explicit InternalLightEventImpl(bool signaled) { this->Initialize(signaled); }
~InternalLightEventImpl() { this->Finalize(); }
void Initialize(bool signaled);
void Finalize();
void SignalWithAutoClear();
void SignalWithManualClear();
void Clear();
void WaitWithAutoClear();
void WaitWithManualClear();
bool TryWaitWithAutoClear();
bool TryWaitWithManualClear();
bool TimedWaitWithAutoClear(const TimeoutHelper &timeout_helper);
bool TimedWaitWithManualClear(const TimeoutHelper &timeout_helper);
};
}

View File

@@ -1,49 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#if defined(ATMOSPHERE_OS_HORIZON)
#include <stratosphere/os/impl/os_internal_rw_busy_mutex_impl.os.horizon.hpp>
#elif defined(ATMOSPHERE_OS_WINDOWS)
#include <stratosphere/os/impl/os_internal_rw_busy_mutex_impl.os.windows.hpp>
#elif defined(ATMOSPHERE_OS_LINUX)
#include <stratosphere/os/impl/os_internal_rw_busy_mutex_impl.os.linux.hpp>
#elif defined(ATMOSPHERE_OS_MACOS)
#include <stratosphere/os/impl/os_internal_rw_busy_mutex_impl.os.macos.hpp>
#else
#error "Unknown OS for ams::os::impl::InternalReaderWriterBusyMutexImpl"
#endif
namespace ams::os::impl {
class InternalReaderWriterBusyMutex {
private:
InternalReaderWriterBusyMutexImpl m_impl;
public:
constexpr InternalReaderWriterBusyMutex() : m_impl() { /* ... */ }
ALWAYS_INLINE void AcquireReadLock() { return m_impl.AcquireReadLock(); }
ALWAYS_INLINE void ReleaseReadLock() { return m_impl.ReleaseReadLock(); }
ALWAYS_INLINE void AcquireWriteLock() { return m_impl.AcquireWriteLock(); }
ALWAYS_INLINE void ReleaseWriteLock() { return m_impl.ReleaseWriteLock(); }
};
using InternalReaderWriterBusyMutexStorage = util::TypedStorage<InternalReaderWriterBusyMutex>;
}

View File

@@ -1,40 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os/impl/os_internal_rw_busy_mutex_value.hpp>
namespace ams::os::impl {
class InternalReaderWriterBusyMutexImpl {
private:
u32 m_value;
public:
constexpr InternalReaderWriterBusyMutexImpl() : m_value(0) { /* ... */ }
constexpr void Initialize() { m_value = 0; }
void AcquireReadLock();
void ReleaseReadLock();
void AcquireWriteLock();
void ReleaseWriteLock();
};
#define AMS_OS_INTERNAL_READER_WRITER_BUSY_MUTEX_IMPL_CONSTANT_INITIALIZER {0}
}

View File

@@ -1,42 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os/impl/os_internal_rw_busy_mutex_value.hpp>
namespace ams::os::impl {
/* NOTE: The current implementation is based on load/linked store conditional, we should figure out how to do this on x64. */
class InternalReaderWriterBusyMutexImpl {
private:
u32 m_value;
public:
constexpr InternalReaderWriterBusyMutexImpl() : m_value(0) { if (!std::is_constant_evaluated()) { AMS_ABORT("TODO: Linux InternalReaderWriterBusyMutexImpl"); } }
constexpr void Initialize() { m_value = 0; if (!std::is_constant_evaluated()) { AMS_ABORT("TODO: Linux InternalReaderWriterBusyMutexImpl"); } }
void AcquireReadLock() { AMS_ABORT("TODO: Linux InternalReaderWriterBusyMutexImpl"); }
void ReleaseReadLock() { AMS_ABORT("TODO: Linux InternalReaderWriterBusyMutexImpl"); }
void AcquireWriteLock() { AMS_ABORT("TODO: Linux InternalReaderWriterBusyMutexImpl"); }
void ReleaseWriteLock() { AMS_ABORT("TODO: Linux InternalReaderWriterBusyMutexImpl"); }
};
#define AMS_OS_INTERNAL_READER_WRITER_BUSY_MUTEX_IMPL_CONSTANT_INITIALIZER {0}
}

View File

@@ -1,42 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os/impl/os_internal_rw_busy_mutex_value.hpp>
namespace ams::os::impl {
/* NOTE: The current implementation is based on load/linked store conditional, we should figure out how to do this on x64. */
class InternalReaderWriterBusyMutexImpl {
private:
u32 m_value;
public:
constexpr InternalReaderWriterBusyMutexImpl() : m_value(0) { if (!std::is_constant_evaluated()) { AMS_ABORT("TODO: macOS InternalReaderWriterBusyMutexImpl"); } }
constexpr void Initialize() { m_value = 0; if (!std::is_constant_evaluated()) { AMS_ABORT("TODO: macOS InternalReaderWriterBusyMutexImpl"); } }
void AcquireReadLock() { AMS_ABORT("TODO: macOS InternalReaderWriterBusyMutexImpl"); }
void ReleaseReadLock() { AMS_ABORT("TODO: macOS InternalReaderWriterBusyMutexImpl"); }
void AcquireWriteLock() { AMS_ABORT("TODO: macOS InternalReaderWriterBusyMutexImpl"); }
void ReleaseWriteLock() { AMS_ABORT("TODO: macOS InternalReaderWriterBusyMutexImpl"); }
};
#define AMS_OS_INTERNAL_READER_WRITER_BUSY_MUTEX_IMPL_CONSTANT_INITIALIZER {0}
}

View File

@@ -1,43 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os/impl/os_internal_rw_busy_mutex_value.hpp>
namespace ams::os::impl {
/* NOTE: The current implementation is based on load/linked store conditional, we should figure out how to do this on x64. */
/* We could also consider using https://docs.microsoft.com/en-us/windows/win32/sync/slim-reader-writer--srw--locks */
class InternalReaderWriterBusyMutexImpl {
private:
u32 m_value;
public:
constexpr InternalReaderWriterBusyMutexImpl() : m_value(0) { if (!std::is_constant_evaluated()) { AMS_ABORT("TODO: Windows InternalReaderWriterBusyMutexImpl"); } }
constexpr void Initialize() { m_value = 0; if (!std::is_constant_evaluated()) { AMS_ABORT("TODO: Windows InternalReaderWriterBusyMutexImpl"); } }
void AcquireReadLock() { AMS_ABORT("TODO: Windows InternalReaderWriterBusyMutexImpl"); }
void ReleaseReadLock() { AMS_ABORT("TODO: Windows InternalReaderWriterBusyMutexImpl"); }
void AcquireWriteLock() { AMS_ABORT("TODO: Windows InternalReaderWriterBusyMutexImpl"); }
void ReleaseWriteLock() { AMS_ABORT("TODO: Windows InternalReaderWriterBusyMutexImpl"); }
};
#define AMS_OS_INTERNAL_READER_WRITER_BUSY_MUTEX_IMPL_CONSTANT_INITIALIZER {0}
}

View File

@@ -1,59 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::os::impl {
#if defined(ATMOSPHERE_OS_HORIZON) || defined(ATMOSPHERE_OS_WINDOWS) || defined(ATMOSPHERE_OS_LINUX) || defined(ATMOSPHERE_OS_MACOS)
class InternalReaderWriterBusyMutexValue {
public:
static constexpr inline u8 WriterCountMax = std::numeric_limits<u8>::max();
static constexpr ALWAYS_INLINE u16 GetReaderCount(u32 v) {
return static_cast<u16>(v >> 0);
}
static constexpr ALWAYS_INLINE u8 GetWriterCurrent(u32 v) {
return static_cast<u8>(v >> 16);
}
static constexpr ALWAYS_INLINE u8 GetWriterNext(u32 v) {
return static_cast<u8>(v >> 24);
}
static constexpr ALWAYS_INLINE u32 IncrementWriterNext(u32 v) {
return v + (1u << 24);
}
static constexpr ALWAYS_INLINE bool IsWriteLocked(u32 v) {
return GetWriterCurrent(v) != GetWriterNext(v);
}
static ALWAYS_INLINE u8 *GetWriterCurrentPointer(u32 *p) {
if constexpr (util::IsLittleEndian()) {
return reinterpret_cast<u8 *>(reinterpret_cast<uintptr_t>(p)) + 2;
} else {
return reinterpret_cast<u8 *>(reinterpret_cast<uintptr_t>(p)) + 1;
}
}
};
#else
#error "Unknown OS for ams::os::impl::InternalReaderWriterBusyMutexValue"
#endif
}

View File

@@ -1,59 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#if defined(ATMOSPHERE_ARCH_X64)
#include <xmmintrin.h>
#include <emmintrin.h>
#endif
namespace ams::os::impl {
#if defined(ATMOSPHERE_ARCH_X64)
ALWAYS_INLINE void FenceMemoryStoreStore() { __asm__ __volatile__("" ::: "memory"); _mm_sfence(); }
ALWAYS_INLINE void FenceMemoryStoreLoad() { __asm__ __volatile__("" ::: "memory"); _mm_mfence(); }
ALWAYS_INLINE void FenceMemoryStoreAny() { __asm__ __volatile__("" ::: "memory"); _mm_mfence(); }
ALWAYS_INLINE void FenceMemoryLoadStore() { __asm__ __volatile__("" ::: "memory"); _mm_mfence(); }
ALWAYS_INLINE void FenceMemoryLoadLoad() { __asm__ __volatile__("" ::: "memory"); _mm_lfence(); }
ALWAYS_INLINE void FenceMemoryLoadAny() { __asm__ __volatile__("" ::: "memory"); _mm_mfence(); }
ALWAYS_INLINE void FenceMemoryAnyStore() { __asm__ __volatile__("" ::: "memory"); _mm_mfence(); }
ALWAYS_INLINE void FenceMemoryAnyLoad() { __asm__ __volatile__("" ::: "memory"); _mm_mfence(); }
ALWAYS_INLINE void FenceMemoryAnyAny() {__asm__ __volatile__("" ::: "memory"); _mm_mfence(); }
#elif defined(ATMOSPHERE_ARCH_ARM64)
ALWAYS_INLINE void FenceMemoryStoreStore() { __asm__ __volatile__("dmb ishst" ::: "memory"); }
ALWAYS_INLINE void FenceMemoryStoreLoad() { __asm__ __volatile__("dmb ish" ::: "memory"); }
ALWAYS_INLINE void FenceMemoryStoreAny() { __asm__ __volatile__("dmb ish" ::: "memory"); }
ALWAYS_INLINE void FenceMemoryLoadStore() { __asm__ __volatile__("dmb ishld" ::: "memory"); }
ALWAYS_INLINE void FenceMemoryLoadLoad() { __asm__ __volatile__("dmb ishld" ::: "memory"); }
ALWAYS_INLINE void FenceMemoryLoadAny() { __asm__ __volatile__("dmb ishld" ::: "memory"); }
ALWAYS_INLINE void FenceMemoryAnyStore() { __asm__ __volatile__("dmb ish" ::: "memory"); }
ALWAYS_INLINE void FenceMemoryAnyLoad() { __asm__ __volatile__("dmb ish" ::: "memory"); }
ALWAYS_INLINE void FenceMemoryAnyAny() { __asm__ __volatile__("dmb ish" ::: "memory"); }
#else
#error "Unknown architecture for os::impl::FenceMemory* (Generic)"
#endif
}

View File

@@ -1,41 +0,0 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::os::impl {
#if defined(ATMOSPHERE_ARCH_ARM64)
ALWAYS_INLINE void FenceMemoryStoreStore() { __asm__ __volatile__("dmb ishst" ::: "memory"); }
ALWAYS_INLINE void FenceMemoryStoreLoad() { __asm__ __volatile__("dmb ish" ::: "memory"); }
ALWAYS_INLINE void FenceMemoryStoreAny() { __asm__ __volatile__("dmb ish" ::: "memory"); }
ALWAYS_INLINE void FenceMemoryLoadStore() { __asm__ __volatile__("dmb ishld" ::: "memory"); }
ALWAYS_INLINE void FenceMemoryLoadLoad() { __asm__ __volatile__("dmb ishld" ::: "memory"); }
ALWAYS_INLINE void FenceMemoryLoadAny() { __asm__ __volatile__("dmb ishld" ::: "memory"); }
ALWAYS_INLINE void FenceMemoryAnyStore() { __asm__ __volatile__("dmb ish" ::: "memory"); }
ALWAYS_INLINE void FenceMemoryAnyLoad() { __asm__ __volatile__("dmb ish" ::: "memory"); }
ALWAYS_INLINE void FenceMemoryAnyAny() { __asm__ __volatile__("dmb ish" ::: "memory"); }
#else
#error "Unknown architecture for os::impl::FenceMemory* (Horizon)"
#endif
}