2020-07-14 11:26:02 +01:00
|
|
|
/*
|
2021-10-04 20:59:10 +01:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2020-07-14 11:26:02 +01: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 09:25:42 +01: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 11:26:02 +01:00
|
|
|
/* Set interrupt id. */
|
2020-12-18 01:18:47 +00:00
|
|
|
m_interrupt_id = interrupt_name;
|
2020-07-14 11:26:02 +01:00
|
|
|
|
2021-04-07 09:25:42 +01:00
|
|
|
/* Set core id. */
|
|
|
|
m_core_id = GetCurrentCoreId();
|
|
|
|
|
2020-07-14 11:26:02 +01:00
|
|
|
/* Initialize readable event base. */
|
|
|
|
KReadableEvent::Initialize(nullptr);
|
|
|
|
|
2022-10-12 05:49:39 +01: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 11:26:02 +01:00
|
|
|
|
|
|
|
/* Mark initialized. */
|
2020-12-18 01:18:47 +00:00
|
|
|
m_is_initialized = true;
|
2022-02-14 22:45:32 +00:00
|
|
|
R_SUCCEED();
|
2020-07-14 11:26:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void KInterruptEvent::Finalize() {
|
|
|
|
MESOSPHERE_ASSERT_THIS();
|
|
|
|
|
2022-10-12 05:49:39 +01: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 22:17:25 +00:00
|
|
|
|
|
|
|
/* Perform inherited finalization. */
|
2021-10-24 05:13:26 +01:00
|
|
|
KReadableEvent::Finalize();
|
2020-07-14 11:26:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result KInterruptEvent::Reset() {
|
|
|
|
MESOSPHERE_ASSERT_THIS();
|
|
|
|
|
2021-09-17 23:34:24 +01:00
|
|
|
/* Lock the scheduler. */
|
|
|
|
KScopedSchedulerLock sl;
|
2020-07-14 11:26:02 +01:00
|
|
|
|
|
|
|
/* Clear the event. */
|
|
|
|
R_TRY(KReadableEvent::Reset());
|
|
|
|
|
|
|
|
/* Clear the interrupt. */
|
2021-04-07 09:25:42 +01:00
|
|
|
Kernel::GetInterruptManager().ClearInterrupt(m_interrupt_id, m_core_id);
|
2020-07-14 11:26:02 +01:00
|
|
|
|
2022-02-14 22:45:32 +00:00
|
|
|
R_SUCCEED();
|
2020-07-14 11:26:02 +01:00
|
|
|
}
|
|
|
|
|
2022-10-12 05:49:39 +01:00
|
|
|
KInterruptTask *KInterruptEvent::OnInterrupt(s32 interrupt_id) {
|
2020-07-14 11:26:02 +01:00
|
|
|
MESOSPHERE_ASSERT_THIS();
|
2020-08-17 22:20:24 +01:00
|
|
|
MESOSPHERE_UNUSED(interrupt_id);
|
2020-07-14 11:26:02 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2022-10-12 05:49:39 +01:00
|
|
|
void KInterruptEvent::DoTask() {
|
2020-07-14 11:26:02 +01:00
|
|
|
MESOSPHERE_ASSERT_THIS();
|
|
|
|
|
2021-09-17 23:34:24 +01:00
|
|
|
/* Lock the scheduler. */
|
|
|
|
KScopedSchedulerLock sl;
|
2020-07-14 11:26:02 +01:00
|
|
|
|
2022-10-12 05:49:39 +01:00
|
|
|
/* Signal. */
|
|
|
|
this->Signal();
|
2020-07-14 11:26:02 +01:00
|
|
|
}
|
|
|
|
}
|