gpio: implement more of server library for boot sysmodule client usage
This commit is contained in:
@@ -59,7 +59,7 @@ namespace ams::ddsf {
|
||||
template<typename T>
|
||||
constexpr const T &SafeCastTo() const {
|
||||
this->AssertCastableTo<T>();
|
||||
return static_cast<T &>(*this);
|
||||
return static_cast<const T &>(*this);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -71,7 +71,7 @@ namespace ams::ddsf {
|
||||
template<typename T>
|
||||
constexpr const T *SafeCastToPointer() const {
|
||||
this->AssertCastableTo<T>();
|
||||
return static_cast<T *>(this);
|
||||
return static_cast<const T *>(this);
|
||||
}
|
||||
|
||||
#if defined(AMS_BUILD_FOR_AUDITING) || defined(AMS_BUILD_FOR_DEBUGGING)
|
||||
|
||||
@@ -21,3 +21,6 @@
|
||||
#include <stratosphere/gpio/gpio_api.hpp>
|
||||
#include <stratosphere/gpio/gpio_pad_api.hpp>
|
||||
#include <stratosphere/gpio/driver/gpio_select_driver_api.hpp>
|
||||
#include <stratosphere/gpio/driver/gpio_pad_accessor.hpp>
|
||||
#include <stratosphere/gpio/driver/impl/gpio_pad_session_impl.hpp>
|
||||
#include <stratosphere/gpio/server/gpio_server_api.hpp>
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace ams::gpio::driver {
|
||||
class Pad : public ::ams::ddsf::IDevice {
|
||||
NON_COPYABLE(Pad);
|
||||
NON_MOVEABLE(Pad);
|
||||
AMS_DDSF_CASTABLE_TRAITS(ams::gpio::Pad, ::ams::ddsf::IDevice);
|
||||
AMS_DDSF_CASTABLE_TRAITS(ams::gpio::driver::Pad, ::ams::ddsf::IDevice);
|
||||
private:
|
||||
int pad_number;
|
||||
bool is_interrupt_enabled;
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 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/gpio/gpio_types.hpp>
|
||||
|
||||
namespace ams::gpio::driver {
|
||||
|
||||
namespace impl {
|
||||
|
||||
constexpr inline size_t GpioPadSessionSize = 0x60;
|
||||
constexpr inline size_t GpioPadSessionAlign = 8;
|
||||
struct alignas(GpioPadSessionAlign) GpioPadSessionImplPadded;
|
||||
|
||||
}
|
||||
|
||||
struct GpioPadSession {
|
||||
util::TypedStorage<impl::GpioPadSessionImplPadded, impl::GpioPadSessionSize, impl::GpioPadSessionAlign> _impl;
|
||||
};
|
||||
|
||||
Result OpenSession(GpioPadSession *out, DeviceCode device_code);
|
||||
void CloseSession(GpioPadSession *session);
|
||||
|
||||
Result SetDirection(GpioPadSession *session, gpio::Direction direction);
|
||||
Result GetDirection(gpio::Direction *out, GpioPadSession *session);
|
||||
|
||||
Result SetValue(GpioPadSession *session, gpio::GpioValue value);
|
||||
Result GetValue(gpio::GpioValue *out, GpioPadSession *session);
|
||||
|
||||
/* TODO */
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 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::gpio::driver::impl {
|
||||
|
||||
class EventHolder {
|
||||
NON_COPYABLE(EventHolder);
|
||||
NON_MOVEABLE(EventHolder);
|
||||
private:
|
||||
os::SystemEventType *event;
|
||||
public:
|
||||
constexpr EventHolder() : event(nullptr) { /* ... */ }
|
||||
|
||||
void AttachEvent(os::SystemEventType *event) {
|
||||
this->event = event;
|
||||
}
|
||||
|
||||
os::SystemEventType *DetachEvent() {
|
||||
auto ev = this->event;
|
||||
this->event = nullptr;
|
||||
return ev;
|
||||
}
|
||||
|
||||
os::SystemEventType *GetSystemEvent() {
|
||||
return this->event;
|
||||
}
|
||||
|
||||
bool IsBound() const {
|
||||
return this->event != nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 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/gpio/gpio_types.hpp>
|
||||
#include <stratosphere/gpio/driver/gpio_pad_accessor.hpp>
|
||||
#include <stratosphere/gpio/driver/impl/gpio_event_holder.hpp>
|
||||
#include <stratosphere/ddsf.hpp>
|
||||
|
||||
namespace ams::gpio::driver {
|
||||
|
||||
class Pad;
|
||||
|
||||
}
|
||||
|
||||
namespace ams::gpio::driver::impl {
|
||||
|
||||
class PadSessionImpl : public ::ams::ddsf::ISession {
|
||||
NON_COPYABLE(PadSessionImpl);
|
||||
NON_MOVEABLE(PadSessionImpl);
|
||||
AMS_DDSF_CASTABLE_TRAITS(ams::gpio::driver::impl::PadSessionImpl, ::ams::ddsf::ISession);
|
||||
private:
|
||||
EventHolder event_holder;
|
||||
private:
|
||||
Result UpdateDriverInterruptEnabled();
|
||||
public:
|
||||
PadSessionImpl() : event_holder() { /* ... */ }
|
||||
|
||||
~PadSessionImpl() {
|
||||
this->Close();
|
||||
}
|
||||
|
||||
bool IsInterruptBound() const {
|
||||
return this->event_holder.IsBound();
|
||||
}
|
||||
|
||||
Result Open(Pad *pad, ddsf::AccessMode access_mode);
|
||||
void Close();
|
||||
|
||||
Result BindInterrupt(os::SystemEventType *event);
|
||||
void UnbindInterrupt();
|
||||
|
||||
Result GetInterruptEnabled(bool *out) const;
|
||||
Result SetInterruptEnabled(bool en);
|
||||
void SignalInterruptBoundEvent();
|
||||
};
|
||||
static_assert( sizeof(PadSessionImpl) <= GpioPadSessionSize);
|
||||
static_assert(alignof(PadSessionImpl) <= GpioPadSessionAlign);
|
||||
|
||||
struct alignas(GpioPadSessionAlign) GpioPadSessionImplPadded {
|
||||
PadSessionImpl _impl;
|
||||
u8 _padding[GpioPadSessionSize - sizeof(PadSessionImpl)];
|
||||
};
|
||||
static_assert( sizeof(GpioPadSessionImplPadded) == GpioPadSessionSize);
|
||||
static_assert(alignof(GpioPadSessionImplPadded) == GpioPadSessionAlign);
|
||||
|
||||
ALWAYS_INLINE PadSessionImpl &GetPadSessionImpl(GpioPadSession &session) {
|
||||
return GetReference(session._impl)._impl;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE const PadSessionImpl &GetPadSessionImpl(const GpioPadSession &session) {
|
||||
return GetReference(session._impl)._impl;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE PadSessionImpl &GetOpenPadSessionImpl(GpioPadSession &session) {
|
||||
auto &ref = GetReference(session._impl)._impl;
|
||||
AMS_ASSERT(ref.IsOpen());
|
||||
return ref;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE const PadSessionImpl &GetOpenPadSessionImpl(const GpioPadSession &session) {
|
||||
const auto &ref = GetReference(session._impl)._impl;
|
||||
AMS_ASSERT(ref.IsOpen());
|
||||
return ref;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,10 +16,13 @@
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/gpio/gpio_types.hpp>
|
||||
#include <stratosphere/gpio/sf/gpio_sf_i_manager.hpp>
|
||||
|
||||
namespace ams::gpio {
|
||||
|
||||
void Initialize();
|
||||
void Finalize();
|
||||
|
||||
void InitializeWith(std::shared_ptr<gpio::sf::IManager> &&sp);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 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/gpio/gpio_types.hpp>
|
||||
#include <stratosphere/gpio/sf/gpio_sf_i_manager.hpp>
|
||||
|
||||
namespace ams::gpio::server {
|
||||
|
||||
std::shared_ptr<gpio::sf::IManager> GetServiceObject();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 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/lmem.hpp>
|
||||
#include <stratosphere/sf/sf_lmem_utility.hpp>
|
||||
#include <stratosphere/gpio/sf/gpio_sf_i_manager.hpp>
|
||||
|
||||
namespace ams::gpio::server {
|
||||
|
||||
class ManagerImpl {
|
||||
private:
|
||||
ams::sf::ExpHeapMemoryResource pad_session_memory_resource;
|
||||
typename ams::sf::ServiceObjectAllocator<gpio::sf::IPadSession>
|
||||
public:
|
||||
ManagerImpl();
|
||||
|
||||
~ManagerImpl();
|
||||
public:
|
||||
/* Actual commands. */
|
||||
Result OpenSessionForDev(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, s32 pad_descriptor) {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result OpenSession(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name) {
|
||||
::GpioPadSession p;
|
||||
R_TRY(::gpioOpenSession(std::addressof(p), static_cast<::GpioPadName>(static_cast<u32>(pad_name))));
|
||||
|
||||
out.SetValue(ams::sf::MakeShared<gpio::sf::IPadSession, RemotePadSessionImpl>(p));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result OpenSessionForTest(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name) {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result IsWakeEventActive(ams::sf::Out<bool> out, gpio::GpioPadName pad_name) {
|
||||
return ::gpioIsWakeEventActive2(out.GetPointer(), static_cast<::GpioPadName>(static_cast<u32>(pad_name)));
|
||||
}
|
||||
|
||||
Result GetWakeEventActiveFlagSet(ams::sf::Out<gpio::WakeBitFlag> out) {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result SetWakeEventActiveFlagSetForDebug(gpio::GpioPadName pad_name, bool is_enabled) {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result SetWakePinDebugMode(s32 mode) {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result OpenSession2(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, DeviceCode device_code, ddsf::AccessMode access_mode) {
|
||||
::GpioPadSession p;
|
||||
R_TRY(::gpioOpenSession2(std::addressof(p), device_code.GetInternalValue(), access_mode));
|
||||
|
||||
out.SetValue(ams::sf::MakeShared<gpio::sf::IPadSession, RemotePadSessionImpl>(p));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result IsWakeEventActive2(ams::sf::Out<bool> out, DeviceCode device_code) {
|
||||
return ::gpioIsWakeEventActive2(out.GetPointer(), device_code.GetInternalValue());
|
||||
}
|
||||
|
||||
Result SetWakeEventActiveFlagSetForDebug2(DeviceCode device_code, bool is_enabled) {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result SetRetryValues(u32 arg0, u32 arg1) {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
};
|
||||
static_assert(gpio::sf::IsIManager<ManagerImpl>);
|
||||
|
||||
}
|
||||
@@ -24,7 +24,13 @@ namespace ams::sf {
|
||||
private:
|
||||
lmem::HeapHandle handle;
|
||||
public:
|
||||
explicit ExpHeapMemoryResource(lmem::HeapHandle h) : handle(h) { /* ... */ }
|
||||
constexpr ExpHeapMemoryResource() : handle() { /* ... */ }
|
||||
constexpr explicit ExpHeapMemoryResource(lmem::HeapHandle h) : handle(h) { /* ... */ }
|
||||
|
||||
void Attach(lmem::HeapHandle h) {
|
||||
AMS_ABORT_UNLESS(this->handle == lmem::HeapHandle());
|
||||
this->handle = h;
|
||||
}
|
||||
|
||||
lmem::HeapHandle GetHandle() const { return this->handle; }
|
||||
private:
|
||||
@@ -45,7 +51,13 @@ namespace ams::sf {
|
||||
private:
|
||||
lmem::HeapHandle handle;
|
||||
public:
|
||||
explicit UnitHeapMemoryResource(lmem::HeapHandle h) : handle(h) { /* ... */ }
|
||||
constexpr UnitHeapMemoryResource() : handle() { /* ... */ }
|
||||
constexpr explicit UnitHeapMemoryResource(lmem::HeapHandle h) : handle(h) { /* ... */ }
|
||||
|
||||
void Attach(lmem::HeapHandle h) {
|
||||
AMS_ABORT_UNLESS(this->handle == lmem::HeapHandle());
|
||||
this->handle = h;
|
||||
}
|
||||
|
||||
lmem::HeapHandle GetHandle() const { return this->handle; }
|
||||
private:
|
||||
|
||||
@@ -62,6 +62,40 @@ namespace ams::sf {
|
||||
return std::make_shared<typename Interface::ImplSharedPointer<Impl>>(std::make_shared<Impl>(std::forward<Arguments>(args)...));
|
||||
}
|
||||
|
||||
template<typename Interface, typename Impl>
|
||||
class ServiceObjectAllocator {
|
||||
public:
|
||||
using value_type = typename Interface::ImplHolder<Impl>;
|
||||
private:
|
||||
MemoryResource * const memory_resource;
|
||||
public:
|
||||
constexpr ServiceObjectAllocator(MemoryResource *mr) : memory_resource(mr) { /* ... */ }
|
||||
|
||||
value_type *allocate(size_t n) const {
|
||||
void *mem = this->memory_resource->Allocate(n * sizeof(value_type), alignof(value_type));
|
||||
AMS_ABORT_UNLESS(mem != nullptr);
|
||||
return mem;
|
||||
}
|
||||
|
||||
void deallocate(void *p, size_t n) const {
|
||||
this->memory_resource->Deallocate(p, n * sizeof(value_type), alignof(value_type));
|
||||
}
|
||||
|
||||
inline bool operator==(const ServiceObjectAllocator &rhs) const {
|
||||
return this->memory_resource->is_equal(*rhs->memory_resource);
|
||||
}
|
||||
|
||||
inline bool operator!=(const ServiceObjectAllocator &rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Interface, typename Impl, typename Allocator, typename... Arguments>
|
||||
requires std::constructible_from<Impl, Arguments...>
|
||||
constexpr ALWAYS_INLINE std::shared_ptr<typename Interface::ImplHolder<Impl>> AllocateShared(const Allocator &allocator, Arguments &&... args) {
|
||||
return std::allocate_shared<typename Interface::ImplHolder<Impl>>(allocator, std::forward<Arguments>(args)...);
|
||||
}
|
||||
|
||||
template<typename Interface, typename Impl>
|
||||
constexpr ALWAYS_INLINE std::shared_ptr<typename Interface::ImplPointer<Impl>> GetSharedPointerTo(Impl *impl) {
|
||||
return std::make_shared<typename Interface::ImplPointer<Impl>>(impl);
|
||||
@@ -72,4 +106,4 @@ namespace ams::sf {
|
||||
return GetSharedPointerTo<Interface, Impl>(std::addressof(impl));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user