2020-07-14 12:26:02 +02:00
|
|
|
/*
|
2021-10-04 21:59:10 +02:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2020-07-14 12:26:02 +02:00
|
|
|
*
|
|
|
|
* 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 <mesosphere.hpp>
|
|
|
|
|
|
|
|
namespace ams::kern {
|
|
|
|
|
|
|
|
Result KInterruptEvent::Initialize(int32_t interrupt_name, ams::svc::InterruptType type) {
|
|
|
|
MESOSPHERE_ASSERT_THIS();
|
|
|
|
|
2021-04-07 10:25:42 +02:00
|
|
|
/* Verify the interrupt is defined and global. */
|
|
|
|
R_UNLESS(Kernel::GetInterruptManager().IsInterruptDefined(interrupt_name), svc::ResultOutOfRange());
|
|
|
|
R_UNLESS(Kernel::GetInterruptManager().IsGlobal(interrupt_name), svc::ResultOutOfRange());
|
|
|
|
|
2020-07-14 12:26:02 +02:00
|
|
|
/* Set interrupt id. */
|
2020-12-18 02:18:47 +01:00
|
|
|
m_interrupt_id = interrupt_name;
|
2020-07-14 12:26:02 +02:00
|
|
|
|
2021-04-07 10:25:42 +02:00
|
|
|
/* Set core id. */
|
|
|
|
m_core_id = GetCurrentCoreId();
|
|
|
|
|
2020-07-14 12:26:02 +02:00
|
|
|
/* Initialize readable event base. */
|
|
|
|
KReadableEvent::Initialize(nullptr);
|
|
|
|
|
2022-10-12 06:49:39 +02:00
|
|
|
/* Bind ourselves as the handler for our interrupt id. */
|
|
|
|
R_TRY(Kernel::GetInterruptManager().BindHandler(this, m_interrupt_id, m_core_id, KInterruptController::PriorityLevel_High, true, type == ams::svc::InterruptType_Level));
|
2020-07-14 12:26:02 +02:00
|
|
|
|
|
|
|
/* Mark initialized. */
|
2020-12-18 02:18:47 +01:00
|
|
|
m_is_initialized = true;
|
2022-02-14 23:45:32 +01:00
|
|
|
R_SUCCEED();
|
2020-07-14 12:26:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KInterruptEvent::Finalize() {
|
|
|
|
MESOSPHERE_ASSERT_THIS();
|
|
|
|
|
2022-10-12 06:49:39 +02:00
|
|
|
/* Unbind ourselves as the handler for our interrupt id. */
|
|
|
|
Kernel::GetInterruptManager().UnbindHandler(m_interrupt_id, m_core_id);
|
|
|
|
|
|
|
|
/* Synchronize the unbind on all cores, before proceeding. */
|
|
|
|
KDpcManager::Sync();
|
2020-12-01 23:17:25 +01:00
|
|
|
|
|
|
|
/* Perform inherited finalization. */
|
2021-10-24 06:13:26 +02:00
|
|
|
KReadableEvent::Finalize();
|
2020-07-14 12:26:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Result KInterruptEvent::Reset() {
|
|
|
|
MESOSPHERE_ASSERT_THIS();
|
|
|
|
|
2021-09-18 00:34:24 +02:00
|
|
|
/* Lock the scheduler. */
|
|
|
|
KScopedSchedulerLock sl;
|
2020-07-14 12:26:02 +02:00
|
|
|
|
|
|
|
/* Clear the event. */
|
|
|
|
R_TRY(KReadableEvent::Reset());
|
|
|
|
|
|
|
|
/* Clear the interrupt. */
|
2021-04-07 10:25:42 +02:00
|
|
|
Kernel::GetInterruptManager().ClearInterrupt(m_interrupt_id, m_core_id);
|
2020-07-14 12:26:02 +02:00
|
|
|
|
2022-02-14 23:45:32 +01:00
|
|
|
R_SUCCEED();
|
2020-07-14 12:26:02 +02:00
|
|
|
}
|
|
|
|
|
2022-10-12 06:49:39 +02:00
|
|
|
KInterruptTask *KInterruptEvent::OnInterrupt(s32 interrupt_id) {
|
2020-07-14 12:26:02 +02:00
|
|
|
MESOSPHERE_ASSERT_THIS();
|
2020-08-17 23:20:24 +02:00
|
|
|
MESOSPHERE_UNUSED(interrupt_id);
|
2020-07-14 12:26:02 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2022-10-12 06:49:39 +02:00
|
|
|
void KInterruptEvent::DoTask() {
|
2020-07-14 12:26:02 +02:00
|
|
|
MESOSPHERE_ASSERT_THIS();
|
|
|
|
|
2021-09-18 00:34:24 +02:00
|
|
|
/* Lock the scheduler. */
|
|
|
|
KScopedSchedulerLock sl;
|
2020-07-14 12:26:02 +02:00
|
|
|
|
2022-10-12 06:49:39 +02:00
|
|
|
/* Signal. */
|
|
|
|
this->Signal();
|
2020-07-14 12:26:02 +02:00
|
|
|
}
|
|
|
|
}
|