1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-05 19:51:45 +00:00

tma: Fix sleep/wake semantics, now tested on hardware.

This commit is contained in:
Michael Scire 2018-12-05 07:11:06 -08:00
parent 9fe8b22269
commit d875d84d2d
4 changed files with 11 additions and 2 deletions

View file

@ -80,6 +80,7 @@ class UsbConnection(UsbInterface):
try: try:
# Perform Query + Connection handshake # Perform Query + Connection handshake
print 'Performing handshake...'
self.intf.send_packet(Packet().set_service(ServiceId.USB_QUERY_TARGET)) self.intf.send_packet(Packet().set_service(ServiceId.USB_QUERY_TARGET))
query_resp = self.intf.read_packet() query_resp = self.intf.read_packet()
print 'Found Switch, Protocol version 0x%x' % query_resp.read_u32() print 'Found Switch, Protocol version 0x%x' % query_resp.read_u32()

View file

@ -23,7 +23,6 @@ static constexpr u16 PscPmModuleId_Pcie = 0x13;
static constexpr u16 PscPmModuleId_Tma = 0x1E; static constexpr u16 PscPmModuleId_Tma = 0x1E;
static const u16 g_tma_pm_dependencies[] = { static const u16 g_tma_pm_dependencies[] = {
PscPmModuleId_Pcie,
PscPmModuleId_Usb, PscPmModuleId_Usb,
}; };

View file

@ -93,6 +93,7 @@ void TmaServiceManager::AddWork(TmaWorkType type, TmaTask *task, TmaPacket *pack
work_item->task = task; work_item->task = task;
work_item->packet = packet; work_item->packet = packet;
work_item->work_type = type; work_item->work_type = type;
this->work_queue.Send(reinterpret_cast<uintptr_t>(work_item));
} }
/* Packet management. */ /* Packet management. */
@ -391,6 +392,7 @@ void TmaServiceManager::HandleSleepWork() {
this->wake_signal.Wait(); this->wake_signal.Wait();
/* We're awake now... */ /* We're awake now... */
this->SetAsleep(false);
/* Wake up services. */ /* Wake up services. */
for (auto srv : this->services) { for (auto srv : this->services) {

View file

@ -34,6 +34,7 @@ static TmaConnection *g_active_connection = nullptr;
static TmaServiceManager *g_service_manager = nullptr; static TmaServiceManager *g_service_manager = nullptr;
static HosMutex g_connection_event_mutex; static HosMutex g_connection_event_mutex;
static bool g_has_woken_up = false; static bool g_has_woken_up = false;
static bool g_connected_before_sleep = false;
static bool g_signal_on_disconnect = false; static bool g_signal_on_disconnect = false;
static TmaUsbConnection *g_usb_connection = nullptr; static TmaUsbConnection *g_usb_connection = nullptr;
@ -119,7 +120,7 @@ static void Wake() {
g_usb_connection = new TmaUsbConnection(); g_usb_connection = new TmaUsbConnection();
g_usb_connection->SetConnectionEventCallback(OnConnectionEvent, g_usb_connection); g_usb_connection->SetConnectionEventCallback(OnConnectionEvent, g_usb_connection);
g_usb_connection->Initialize(); g_usb_connection->Initialize();
SetActiveConnection(g_usb_connection); g_active_connection = g_usb_connection;
g_service_manager->Wake(g_active_connection); g_service_manager->Wake(g_active_connection);
} }
@ -128,7 +129,11 @@ static void Wake() {
static void Sleep() { static void Sleep() {
if (!g_service_manager->GetAsleep()) { if (!g_service_manager->GetAsleep()) {
if (g_active_connection->IsConnected()) { if (g_active_connection->IsConnected()) {
g_connected_before_sleep = true;
/* TODO: Send a packet saying we're going to sleep. */ /* TODO: Send a packet saying we're going to sleep. */
} else {
g_connected_before_sleep = false;
} }
g_service_manager->Sleep(); g_service_manager->Sleep();
@ -157,6 +162,7 @@ static void OnPowerManagementEvent(PscPmState state, u32 flags) {
{ {
if (g_service_manager->GetAsleep()) { if (g_service_manager->GetAsleep()) {
Wake(); Wake();
if (g_connected_before_sleep)
{ {
/* Try to restore a connection. */ /* Try to restore a connection. */
bool connected = g_service_manager->GetConnected(); bool connected = g_service_manager->GetConnected();
@ -170,6 +176,7 @@ static void OnPowerManagementEvent(PscPmState state, u32 flags) {
svcSleepThread(1000000ULL); svcSleepThread(1000000ULL);
} }
} }
if (!connected) { if (!connected) {
/* TODO: Signal disconnected */ /* TODO: Signal disconnected */
} }