gpio: implement more of server library for boot sysmodule client usage

This commit is contained in:
Michael Scire
2020-10-31 03:22:01 -07:00
parent e1dccef7d1
commit 5bc4abb92f
26 changed files with 1162 additions and 24 deletions

View File

@@ -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;

View File

@@ -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 */
}

View File

@@ -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;
}
};
}

View File

@@ -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;
}
}

View File

@@ -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);
}

View File

@@ -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();
}

View File

@@ -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>);
}