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,109 +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::ddsf {
class IDevice;
class DeviceCodeEntry {
NON_COPYABLE(DeviceCodeEntry);
NON_MOVEABLE(DeviceCodeEntry);
private:
ams::DeviceCode m_device_code = ams::InvalidDeviceCode;
IDevice *m_device = nullptr;
public:
constexpr DeviceCodeEntry(ams::DeviceCode dc, IDevice *dev) : m_device_code(dc), m_device(dev) {
AMS_ASSERT(dev != nullptr);
}
constexpr ams::DeviceCode GetDeviceCode() const {
return m_device_code;
}
constexpr IDevice &GetDevice() {
return *m_device;
}
constexpr const IDevice &GetDevice() const {
return *m_device;
}
};
class DeviceCodeEntryHolder {
NON_COPYABLE(DeviceCodeEntryHolder);
NON_MOVEABLE(DeviceCodeEntryHolder);
private:
util::IntrusiveListNode m_list_node;
util::TypedStorage<DeviceCodeEntry> m_entry_storage;
bool m_is_constructed;
public:
using ListTraits = util::IntrusiveListMemberTraits<&DeviceCodeEntryHolder::m_list_node>;
using List = typename ListTraits::ListType;
friend class util::IntrusiveList<DeviceCodeEntryHolder, util::IntrusiveListMemberTraits<&DeviceCodeEntryHolder::m_list_node>>;
public:
DeviceCodeEntryHolder() : m_list_node(), m_entry_storage(), m_is_constructed(false) {
/* ... */
}
~DeviceCodeEntryHolder() {
if (this->IsConstructed()) {
this->Destroy();
}
}
void AddTo(List &list) {
list.push_back(*this);
}
void RemoveFrom(List list) {
list.erase(list.iterator_to(*this));
}
bool IsLinkedToList() const {
return m_list_node.IsLinked();
}
DeviceCodeEntry &Construct(DeviceCode dc, IDevice *dev) {
AMS_ASSERT(!this->IsConstructed());
DeviceCodeEntry *entry = util::ConstructAt(m_entry_storage, dc, dev);
m_is_constructed = true;
return *entry;
}
bool IsConstructed() const {
return m_is_constructed;
}
void Destroy() {
AMS_ASSERT(this->IsConstructed());
util::DestroyAt(m_entry_storage);
m_is_constructed = false;
}
DeviceCodeEntry &Get() {
AMS_ASSERT(this->IsConstructed());
return GetReference(m_entry_storage);
}
const DeviceCodeEntry &Get() const {
AMS_ASSERT(this->IsConstructed());
return GetReference(m_entry_storage);
}
};
}

View File

@@ -1,84 +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/ddsf/ddsf_types.hpp>
#include <stratosphere/ddsf/impl/ddsf_for_each.hpp>
#include <stratosphere/ddsf/ddsf_device_code_entry.hpp>
namespace ams::ddsf {
class IDevice;
class DeviceCodeEntryManager {
private:
ams::MemoryResource *m_memory_resource;
ddsf::DeviceCodeEntryHolder::List m_entry_list;
mutable os::SdkMutex m_entry_list_lock;
private:
void DestroyAllEntries() {
auto it = m_entry_list.begin();
while (it != m_entry_list.end()) {
ddsf::DeviceCodeEntryHolder *entry = std::addressof(*it);
it = m_entry_list.erase(it);
AMS_ASSERT(entry->IsConstructed());
if (entry->IsConstructed()) {
entry->Destroy();
}
m_memory_resource->Deallocate(entry, sizeof(*entry));
}
}
public:
DeviceCodeEntryManager(ams::MemoryResource *mr) : m_memory_resource(mr), m_entry_list(), m_entry_list_lock() { /* ... */ }
~DeviceCodeEntryManager() {
this->DestroyAllEntries();
}
void Reset() {
std::scoped_lock lk(m_entry_list_lock);
this->DestroyAllEntries();
}
Result Add(DeviceCode device_code, IDevice *device);
bool Remove(DeviceCode device_code);
Result FindDeviceCodeEntry(DeviceCodeEntry **out, DeviceCode device_code);
Result FindDeviceCodeEntry(const DeviceCodeEntry **out, DeviceCode device_code) const;
Result FindDevice(IDevice **out, DeviceCode device_code);
Result FindDevice(const IDevice **out, DeviceCode device_code) const;
template<typename F>
int ForEachEntry(F f) {
return impl::ForEach(m_entry_list_lock, m_entry_list, [&](DeviceCodeEntryHolder &holder) -> bool {
AMS_ASSERT(holder.IsConstructed());
return f(holder.Get());
});
}
template<typename F>
int ForEachEntry(F f) const {
return impl::ForEach(m_entry_list_lock, m_entry_list, [&](const DeviceCodeEntryHolder &holder) -> bool {
AMS_ASSERT(holder.IsConstructed());
return f(holder.Get());
});
}
};
}

View File

@@ -1,80 +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.hpp>
#include <stratosphere/ddsf/ddsf_i_event_handler.hpp>
namespace ams::ddsf {
class EventHandlerManager;
class EventHandlerManager {
NON_COPYABLE(EventHandlerManager);
NON_MOVEABLE(EventHandlerManager);
private:
struct LoopControlCommandParameters;
private:
bool m_is_initialized;
bool m_is_looping;
os::SdkConditionVariable m_is_looping_cv;
os::MultiWaitType m_multi_wait;
os::ThreadType *m_loop_thread;
os::Event m_loop_control_event;
os::MultiWaitHolderType m_loop_control_event_holder;
LoopControlCommandParameters *m_loop_control_command_params;
os::LightEvent m_loop_control_command_done_event;
os::SdkMutex m_loop_control_lock;
private:
void ProcessControlCommand(LoopControlCommandParameters *params);
void ProcessControlCommandImpl(LoopControlCommandParameters *params);
public:
EventHandlerManager()
: m_is_initialized(false), m_is_looping(false), m_is_looping_cv(), m_multi_wait(),
m_loop_thread(), m_loop_control_event(os::EventClearMode_AutoClear), m_loop_control_event_holder(),
m_loop_control_command_params(), m_loop_control_command_done_event(os::EventClearMode_AutoClear),
m_loop_control_lock()
{
this->Initialize();
}
~EventHandlerManager() {
if (m_is_looping) {
AMS_ASSERT(!this->IsRunningOnLoopThread());
this->RequestStop();
}
if (m_is_initialized) {
this->Finalize();
}
}
bool IsRunningOnLoopThread() const { return m_loop_thread == os::GetCurrentThread(); }
bool IsLooping() const { return m_is_looping; }
void Initialize();
void Finalize();
void RegisterHandler(IEventHandler *handler);
void UnregisterHandler(IEventHandler *handler);
void WaitLoopEnter();
void WaitLoopExit();
void RequestStop();
void LoopAuto();
};
}

View File

@@ -1,88 +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/ddsf/ddsf_types.hpp>
#include <stratosphere/ddsf/impl/ddsf_type_tag.hpp>
namespace ams::ddsf {
#if defined(AMS_BUILD_FOR_DEBUGGING) || defined(AMS_BUILD_FOR_AUDITING)
#define AMS_DDSF_CASTABLE_TRAITS(__CLASS__, __BASE__) \
static_assert(std::convertible_to<__CLASS__ *, __BASE__ *>); \
public: \
static constexpr inline ::ams::ddsf::impl::TypeTag s_ams_ddsf_castable_type_tag{#__CLASS__, __BASE__::s_ams_ddsf_castable_type_tag}; \
constexpr virtual const ::ams::ddsf::impl::TypeTag &GetTypeTag() const override { return s_ams_ddsf_castable_type_tag; }
#else
#define AMS_DDSF_CASTABLE_TRAITS(__CLASS__, __BASE__) \
static_assert(std::convertible_to<__CLASS__ *, __BASE__ *>); \
public: \
static constexpr inline ::ams::ddsf::impl::TypeTag s_ams_ddsf_castable_type_tag{__BASE__::s_ams_ddsf_castable_type_tag}; \
constexpr virtual const ::ams::ddsf::impl::TypeTag &GetTypeTag() const override { return s_ams_ddsf_castable_type_tag; }
#endif
class ICastable {
private:
constexpr virtual const impl::TypeTag &GetTypeTag() const = 0;
template<typename T>
constexpr ALWAYS_INLINE void AssertCastableTo() const {
AMS_ASSERT(this->IsCastableTo<T>());
}
public:
template<typename T>
constexpr bool IsCastableTo() const {
return this->GetTypeTag().DerivesFrom(T::s_ams_ddsf_castable_type_tag);
}
template<typename T>
constexpr T &SafeCastTo() {
this->AssertCastableTo<T>();
return static_cast<T &>(*this);
}
template<typename T>
constexpr const T &SafeCastTo() const {
this->AssertCastableTo<T>();
return static_cast<const T &>(*this);
}
template<typename T>
constexpr T *SafeCastToPointer() {
this->AssertCastableTo<T>();
return static_cast<T *>(this);
}
template<typename T>
constexpr const T *SafeCastToPointer() const {
this->AssertCastableTo<T>();
return static_cast<const T *>(this);
}
#if defined(AMS_BUILD_FOR_AUDITING) || defined(AMS_BUILD_FOR_DEBUGGING)
constexpr const char *GetClassName() const {
return this->GetTypeTag().GetClassName();
}
#endif
};
}

View File

@@ -1,139 +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_sdk_mutex.hpp>
#include <stratosphere/ddsf/ddsf_types.hpp>
#include <stratosphere/ddsf/impl/ddsf_for_each.hpp>
#include <stratosphere/ddsf/ddsf_i_castable.hpp>
#include <stratosphere/ddsf/ddsf_i_session.hpp>
namespace ams::ddsf {
class IDriver;
class IDevice : public ICastable {
friend Result OpenSession(IDevice *device, ISession *session, AccessMode mode);
friend void CloseSession(ISession *session);
friend class IDriver;
public:
AMS_DDSF_CASTABLE_ROOT_TRAITS(ams::ddsf::IDevice);
private:
util::IntrusiveListNode m_list_node;
IDriver *m_driver;
ISession::List m_session_list;
mutable os::SdkMutex m_session_list_lock;
bool m_is_exclusive_write;
public:
using ListTraits = util::IntrusiveListMemberTraits<&IDevice::m_list_node>;
using List = typename ListTraits::ListType;
friend class util::IntrusiveList<IDevice, util::IntrusiveListMemberTraits<&IDevice::m_list_node>>;
private:
Result AttachSession(ISession *session) {
AMS_ASSERT(session != nullptr);
std::scoped_lock lk(m_session_list_lock);
/* Check if we're allowed to attach the session. */
if (m_is_exclusive_write && session->CheckExclusiveWrite()) {
for (const auto &attached : m_session_list) {
R_UNLESS(!attached.CheckAccess(AccessMode_Write), ddsf::ResultAccessModeDenied());
}
}
/* Attach the session. */
m_session_list.push_back(*session);
R_SUCCEED();
}
void DetachSession(ISession *session) {
AMS_ASSERT(session != nullptr);
std::scoped_lock lk(m_session_list_lock);
m_session_list.erase(m_session_list.iterator_to(*session));
}
void AttachDriver(IDriver *drv) {
AMS_ASSERT(drv != nullptr);
AMS_ASSERT(!this->IsDriverAttached());
m_driver = drv;
AMS_ASSERT(this->IsDriverAttached());
}
void DetachDriver() {
AMS_ASSERT(this->IsDriverAttached());
m_driver = nullptr;
AMS_ASSERT(!this->IsDriverAttached());
}
public:
IDevice(bool exclusive_write) : m_list_node(), m_driver(nullptr), m_session_list(), m_session_list_lock(), m_is_exclusive_write(exclusive_write) {
m_session_list.clear();
}
protected:
virtual ~IDevice() {
m_session_list.clear();
}
public:
void AddTo(List &list) {
list.push_back(*this);
}
void RemoveFrom(List list) {
list.erase(list.iterator_to(*this));
}
bool IsLinkedToList() const {
return m_list_node.IsLinked();
}
IDriver &GetDriver() {
AMS_ASSERT(this->IsDriverAttached());
return *m_driver;
}
const IDriver &GetDriver() const {
AMS_ASSERT(this->IsDriverAttached());
return *m_driver;
}
bool IsDriverAttached() const {
return m_driver != nullptr;
}
template<typename F>
Result ForEachSession(F f, bool return_on_fail) {
R_RETURN(impl::ForEach(m_session_list_lock, m_session_list, f, return_on_fail));
}
template<typename F>
Result ForEachSession(F f, bool return_on_fail) const {
R_RETURN(impl::ForEach(m_session_list_lock, m_session_list, f, return_on_fail));
}
template<typename F>
int ForEachSession(F f) {
return impl::ForEach(m_session_list_lock, m_session_list, f);
}
template<typename F>
int ForEachSession(F f) const {
return impl::ForEach(m_session_list_lock, m_session_list, f);
}
bool HasAnyOpenSession() const {
return !m_session_list.empty();
}
};
}

View File

@@ -1,98 +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_sdk_mutex.hpp>
#include <stratosphere/ddsf/ddsf_types.hpp>
#include <stratosphere/ddsf/impl/ddsf_for_each.hpp>
#include <stratosphere/ddsf/ddsf_i_castable.hpp>
#include <stratosphere/ddsf/ddsf_i_device.hpp>
namespace ams::ddsf {
class IDriver : public ICastable {
public:
AMS_DDSF_CASTABLE_ROOT_TRAITS(ams::ddsf::IDriver);
private:
util::IntrusiveListNode m_list_node;
IDevice::List m_device_list;
mutable os::SdkMutex m_device_list_lock;
public:
using ListTraits = util::IntrusiveListMemberTraits<&IDriver::m_list_node>;
using List = typename ListTraits::ListType;
friend class util::IntrusiveList<IDriver, util::IntrusiveListMemberTraits<&IDriver::m_list_node>>;
private:
public:
IDriver() : m_list_node(), m_device_list(), m_device_list_lock() {
m_device_list.clear();
}
protected:
virtual ~IDriver() {
m_device_list.clear();
}
public:
void AddTo(List &list) {
list.push_back(*this);
}
void RemoveFrom(List list) {
list.erase(list.iterator_to(*this));
}
bool IsLinkedToList() const {
return m_list_node.IsLinked();
}
bool HasAnyDevice() const {
return !m_device_list.empty();
}
void RegisterDevice(IDevice *dev) {
AMS_ASSERT(dev != nullptr);
std::scoped_lock lk(m_device_list_lock);
dev->AttachDriver(this);
m_device_list.push_back(*dev);
}
void UnregisterDevice(IDevice *dev) {
AMS_ASSERT(dev != nullptr);
std::scoped_lock lk(m_device_list_lock);
m_device_list.erase(m_device_list.iterator_to(*dev));
dev->DetachDriver();
}
template<typename F>
Result ForEachDevice(F f, bool return_on_fail) {
R_RETURN(impl::ForEach(m_device_list_lock, m_device_list, f, return_on_fail));
}
template<typename F>
Result ForEachDevice(F f, bool return_on_fail) const {
R_RETURN(impl::ForEach(m_device_list_lock, m_device_list, f, return_on_fail));
}
template<typename F>
int ForEachDevice(F f) {
return impl::ForEach(m_device_list_lock, m_device_list, f);
}
template<typename F>
int ForEachDevice(F f) const {
return impl::ForEach(m_device_list_lock, m_device_list, f);
}
};
}

View File

@@ -1,92 +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.hpp>
namespace ams::ddsf {
class EventHandlerManager;
class IEventHandler {
NON_COPYABLE(IEventHandler);
NON_MOVEABLE(IEventHandler);
friend class EventHandlerManager;
private:
os::MultiWaitHolderType m_holder;
uintptr_t m_user_data;
bool m_is_initialized;
bool m_is_registered;
private:
void Link(os::MultiWaitType *multi_wait) {
AMS_ASSERT(this->IsInitialized());
AMS_ASSERT(!this->IsRegistered());
AMS_ASSERT(multi_wait != nullptr);
os::LinkMultiWaitHolder(multi_wait, std::addressof(m_holder));
}
void Unlink() {
AMS_ASSERT(this->IsInitialized());
AMS_ASSERT(this->IsRegistered());
os::UnlinkMultiWaitHolder(std::addressof(m_holder));
}
static IEventHandler &ToEventHandler(os::MultiWaitHolderType *holder) {
AMS_ASSERT(holder != nullptr);
auto &event_handler = *reinterpret_cast<IEventHandler *>(os::GetMultiWaitHolderUserData(holder));
AMS_ASSERT(event_handler.IsInitialized());
return event_handler;
}
public:
IEventHandler() : m_holder(), m_user_data(0), m_is_initialized(false), m_is_registered(false) { /* ... */ }
virtual ~IEventHandler() {
if (this->IsRegistered()) {
this->Unlink();
}
if (this->IsInitialized()) {
this->Finalize();
}
}
bool IsInitialized() const { return m_is_initialized; }
bool IsRegistered() const { return m_is_registered; }
uintptr_t GetUserData() const { return m_user_data; }
void SetUserData(uintptr_t d) { m_user_data = d; }
template<typename T>
void Initialize(T *object) {
AMS_ASSERT(object != nullptr);
AMS_ASSERT(!this->IsInitialized());
os::InitializeMultiWaitHolder(std::addressof(m_holder), object);
os::SetMultiWaitHolderUserData(std::addressof(m_holder), reinterpret_cast<uintptr_t>(this));
m_is_initialized = true;
m_is_registered = false;
}
void Finalize() {
AMS_ASSERT(this->IsInitialized());
AMS_ASSERT(!this->IsRegistered());
os::FinalizeMultiWaitHolder(std::addressof(m_holder));
m_is_initialized = false;
m_is_registered = false;
}
protected:
virtual void HandleEvent() = 0;
};
}

View File

@@ -1,99 +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/ddsf/ddsf_types.hpp>
#include <stratosphere/ddsf/impl/ddsf_for_each.hpp>
#include <stratosphere/ddsf/ddsf_i_castable.hpp>
namespace ams::ddsf {
class ISession;
class IDevice;
Result OpenSession(IDevice *device, ISession *session, AccessMode access_mode);
void CloseSession(ISession *session);
class ISession : public ICastable {
friend Result OpenSession(IDevice *device, ISession *session, AccessMode mode);
friend void CloseSession(ISession *session);
public:
AMS_DDSF_CASTABLE_ROOT_TRAITS(ams::ddsf::IDevice);
private:
util::IntrusiveListNode m_list_node;
IDevice *m_device;
AccessMode m_access_mode;
public:
using ListTraits = util::IntrusiveListMemberTraits<&ISession::m_list_node>;
using List = typename ListTraits::ListType;
friend class util::IntrusiveList<ISession, util::IntrusiveListMemberTraits<&ISession::m_list_node>>;
private:
void AttachDevice(IDevice *dev, AccessMode mode) {
AMS_ASSERT(dev != nullptr);
AMS_ASSERT(!this->IsOpen());
m_device = dev;
m_access_mode = mode;
AMS_ASSERT(this->IsOpen());
}
void DetachDevice() {
/* AMS_ASSERT(this->IsOpen()); */
m_device = nullptr;
m_access_mode = AccessMode_None;
AMS_ASSERT(!this->IsOpen());
}
public:
ISession() : m_list_node(), m_device(nullptr), m_access_mode() { /* ... */ }
protected:
virtual ~ISession() { this->DetachDevice(); AMS_ASSERT(!this->IsOpen()); }
public:
void AddTo(List &list) {
list.push_back(*this);
}
void RemoveFrom(List list) {
list.erase(list.iterator_to(*this));
}
bool IsLinkedToList() const {
return m_list_node.IsLinked();
}
IDevice &GetDevice() {
AMS_ASSERT(this->IsOpen());
return *m_device;
}
const IDevice &GetDevice() const {
AMS_ASSERT(this->IsOpen());
return *m_device;
}
bool IsOpen() const {
return m_device != nullptr;
}
bool CheckAccess(AccessMode mode) const {
AMS_ASSERT(this->IsOpen());
return ((~m_access_mode) & mode) == 0;
}
bool CheckExclusiveWrite() const {
return this->CheckAccess(AccessMode_Write) && !this->CheckAccess(AccessMode_Shared);
}
};
}

View File

@@ -1,31 +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/ddsf/ddsf_device_code_entry.hpp>
namespace ams::ddsf {
void SetMemoryResource(ams::MemoryResource *mr);
ams::MemoryResource *GetMemoryResource();
static constexpr size_t DeviceCodeEntryHolderSize = sizeof(DeviceCodeEntryHolder);
void SetDeviceCodeEntryHolderMemoryResource(ams::MemoryResource *mr);
ams::MemoryResource *GetDeviceCodeEntryHolderMemoryResource();
}

View File

@@ -1,33 +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::ddsf {
enum AccessMode {
AccessMode_None = (0u << 0),
AccessMode_Read = (1u << 0),
AccessMode_Write = (1u << 1),
AccessMode_Shared = (1u << 2),
AccessMode_ReadWrite = AccessMode_Read | AccessMode_Write,
AccessMode_WriteShared = AccessMode_Write | AccessMode_Shared,
AccessMode_ReadWriteShared = AccessMode_Read | AccessMode_WriteShared,
};
}

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>
namespace ams::ddsf::impl {
template<typename Lock, typename List, typename F>
inline Result ForEach(Lock &lock, List &list, F f, bool return_on_fail) {
std::scoped_lock lk(lock);
Result result = ResultSuccess();
for (auto && it : list) {
if (const auto cur_result = f(std::addressof(it)); R_FAILED(cur_result)) {
if (return_on_fail) {
R_RETURN(cur_result);
} else if (R_SUCCEEDED(result)) {
result = cur_result;
}
}
}
R_RETURN(result);
}
template<typename List, typename F, typename Lock>
inline int ForEach(Lock &lock, List &list, F f) {
std::scoped_lock lk(lock);
int success_count = 0;
for (auto && it : list) {
if (!f(it)) {
return success_count;
}
++success_count;
}
return success_count;
}
}

View File

@@ -1,70 +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/ddsf/ddsf_types.hpp>
namespace ams::ddsf::impl {
#if defined(AMS_BUILD_FOR_DEBUGGING) || defined(AMS_BUILD_FOR_AUDITING)
#define AMS_DDSF_CASTABLE_ROOT_TRAITS(__CLASS__) \
public: \
static constexpr inline ::ams::ddsf::impl::TypeTag s_ams_ddsf_castable_type_tag{#__CLASS__}; \
constexpr virtual const ::ams::ddsf::impl::TypeTag &GetTypeTag() const override { return s_ams_ddsf_castable_type_tag; }
#else
#define AMS_DDSF_CASTABLE_ROOT_TRAITS(__CLASS__) \
public: \
static constexpr inline ::ams::ddsf::impl::TypeTag s_ams_ddsf_castable_type_tag{}; \
constexpr virtual const ::ams::ddsf::impl::TypeTag &GetTypeTag() const override { return s_ams_ddsf_castable_type_tag; }
#endif
class TypeTag {
private:
const char * const m_class_name;
const TypeTag * const m_base;
public:
#if !(defined(AMS_BUILD_FOR_DEBUGGING) || defined(AMS_BUILD_FOR_AUDITING))
constexpr TypeTag() : m_class_name(nullptr), m_base(nullptr) { /* ... */}
constexpr TypeTag(const TypeTag &b) : m_class_name(nullptr), m_base(std::addressof(b)) { if (!std::is_constant_evaluated()) { AMS_ASSERT(this != m_base); } }
constexpr TypeTag(const char *c) : m_class_name(nullptr), m_base(nullptr) { AMS_UNUSED(c); }
constexpr TypeTag(const char *c, const TypeTag &b) : m_class_name(nullptr), m_base(std::addressof(b)) { if (!std::is_constant_evaluated()) { AMS_UNUSED(c); AMS_ASSERT(this != m_base); } }
#else
constexpr TypeTag(const char *c) : m_class_name(c), m_base(nullptr) { /* ... */ }
constexpr TypeTag(const char *c, const TypeTag &b) : m_class_name(c), m_base(std::addressof(b)) { if (!std::is_constant_evaluated()) { AMS_ASSERT(this != m_base); } }
#endif
constexpr const char * GetClassName() const { return m_class_name; }
constexpr bool Is(const TypeTag &rhs) const { return this == std::addressof(rhs); }
constexpr bool DerivesFrom(const TypeTag &rhs) const {
const TypeTag * cur = this;
while (cur != nullptr) {
if (cur == std::addressof(rhs)) {
return true;
}
cur = cur->m_base;
}
return false;
}
};
}