htc: implement (fixing linker errors) through HtclowManagerImpl::OpenDriver

This commit is contained in:
Michael Scire
2021-02-08 01:25:10 -08:00
committed by SciresM
parent 1687bf2e07
commit c878123274
30 changed files with 582 additions and 22 deletions

View File

@@ -21,9 +21,20 @@ namespace ams::htclow::mux {
Mux::Mux(PacketFactory *pf, ctrl::HtcctrlStateMachine *sm)
: m_packet_factory(pf), m_state_machine(sm), m_task_manager(), m_wake_event(os::EventClearMode_ManualClear),
m_channel_impl_map(pf, sm, std::addressof(m_task_manager), std::addressof(m_wake_event)), m_global_send_buffer(pf),
m_mutex(), m_is_sleeping(false), m_version(5)
m_mutex(), m_is_sleeping(false), m_version(ProtocolVersion)
{
/* ... */
}
void Mux::SetVersion(u16 version) {
/* Set our version. */
m_version = version;
/* Set all entries in our map. */
/* NOTE: Nintendo does this highly inefficiently... */
for (auto &pair : m_channel_impl_map.GetMap()) {
m_channel_impl_map[pair.first].SetVersion(m_version);
}
}
}

View File

@@ -34,6 +34,8 @@ namespace ams::htclow::mux {
u16 m_version;
public:
Mux(PacketFactory *pf, ctrl::HtcctrlStateMachine *sm);
void SetVersion(u16 version);
};
}

View File

@@ -0,0 +1,30 @@
/*
* 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/>.
*/
#include <stratosphere.hpp>
#include "htclow_mux_channel_impl.hpp"
namespace ams::htclow::mux {
void ChannelImpl::SetVersion(s16 version) {
/* Sanity check the version. */
AMS_ASSERT(version <= ProtocolVersion);
/* Set version. */
m_version = version;
m_send_buffer.SetVersion(version);
}
}

View File

@@ -0,0 +1,56 @@
/*
* 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 <stratosphere.hpp>
#include "htclow_mux_task_manager.hpp"
#include "htclow_mux_send_buffer.hpp"
namespace ams::htclow {
class PacketFactory;
namespace ctrl {
class HtcctrlStateMachine;
}
}
namespace ams::htclow::mux {
class ChannelImpl {
private:
impl::ChannelInternalType m_channel;
PacketFactory *m_packet_factory;
ctrl::HtcctrlStateMachine *m_state_machine;
TaskManager *m_task_manager;
os::Event *m_event;
SendBuffer m_send_buffer;
RingBuffer m_receive_buffer;
s16 m_version;
/* TODO: Channel config */
/* TODO: tracking variables. */
std::optional<u64> m_108;
os::Event m_send_packet_event;
/* TODO: Channel state. */
public:
ChannelImpl(impl::ChannelInternalType channel, PacketFactory *pf, ctrl::HtcctrlStateMachine *sm, TaskManager *tm, os::Event *ev);
void SetVersion(s16 version);
};
}

View File

@@ -30,4 +30,17 @@ namespace ams::htclow::mux {
}
}
ChannelImpl &ChannelImplMap::GetChannelImpl(int index) {
return GetReference(m_channel_storage[index]);
}
ChannelImpl &ChannelImplMap::GetChannelImpl(impl::ChannelInternalType channel) {
/* Find the channel. */
auto it = m_map.find(channel);
AMS_ASSERT(it != m_map.end());
/* Return the implementation object. */
return this->GetChannelImpl(it->second);
}
}

View File

@@ -15,19 +15,7 @@
*/
#pragma once
#include <stratosphere.hpp>
#include "htclow_mux_task_manager.hpp"
namespace ams::htclow {
class PacketFactory;
namespace ctrl {
class HtcctrlStateMachine;
}
}
#include "htclow_mux_channel_impl.hpp"
namespace ams::htclow::mux {
@@ -47,10 +35,22 @@ namespace ams::htclow::mux {
os::Event *m_event;
u8 m_map_buffer[MapRequiredMemorySize];
MapType m_map;
u8 m_storage[0x5200]; /* TODO */
TYPED_STORAGE(ChannelImpl) m_channel_storage[MaxChannelCount];
bool m_storage_valid[MaxChannelCount];
public:
ChannelImplMap(PacketFactory *pf, ctrl::HtcctrlStateMachine *sm, TaskManager *tm, os::Event *ev);
ChannelImpl &GetChannelImpl(impl::ChannelInternalType channel);
private:
ChannelImpl &GetChannelImpl(int index);
public:
MapType &GetMap() {
return m_map;
}
ChannelImpl &operator[](impl::ChannelInternalType channel) {
return this->GetChannelImpl(channel);
}
};
}

View File

@@ -0,0 +1,34 @@
/*
* 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 <stratosphere.hpp>
namespace ams::htclow::mux {
class RingBuffer {
private:
void *m_buffer;
void *m_read_only_buffer;
bool m_is_read_only;
size_t m_buffer_size;
size_t m_data_size;
size_t m_offset;
bool m_has_copied;
public:
RingBuffer() : m_buffer(), m_read_only_buffer(), m_is_read_only(true), m_buffer_size(), m_data_size(), m_offset(), m_has_copied(false) { /* ... */ }
};
}

View File

@@ -0,0 +1,26 @@
/*
* 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/>.
*/
#include <stratosphere.hpp>
#include "htclow_mux_channel_impl.hpp"
namespace ams::htclow::mux {
void SendBuffer::SetVersion(s16 version) {
/* Set version. */
m_version = version;
}
}

View File

@@ -0,0 +1,46 @@
/*
* 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 <stratosphere.hpp>
#include "../htclow_packet.hpp"
#include "htclow_mux_ring_buffer.hpp"
namespace ams::htclow {
class PacketFactory;
}
namespace ams::htclow::mux {
class SendBuffer {
private:
using PacketList = util::IntrusiveListBaseTraits<Packet>::ListType;
private:
impl::ChannelInternalType m_channel;
PacketFactory *m_packet_factory;
RingBuffer m_ring_buffer;
PacketList m_packet_list;
s16 m_version;
bool m_flow_control_enabled;
size_t m_max_packet_size;
public:
SendBuffer(impl::ChannelInternalType channel, PacketFactory *pf);
void SetVersion(s16 version);
};
}