2019-08-10 23:56:49 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 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 "gicv2.h"
|
|
|
|
#include "spinlock.h"
|
|
|
|
#include "exceptions.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
2019-08-17 23:40:47 +01:00
|
|
|
#define IRQ_PRIORITY_HOST 0
|
|
|
|
#define IRQ_PRIORITY_GUEST 1
|
|
|
|
|
2019-08-10 23:56:49 +01:00
|
|
|
typedef struct IrqManager {
|
|
|
|
RecursiveSpinlock lock;
|
|
|
|
ArmGicV2 gic;
|
|
|
|
u8 numPriorityLevels;
|
|
|
|
u8 numCpuInterfaces;
|
|
|
|
u8 numSharedInterrupts;
|
2019-08-17 23:40:47 +01:00
|
|
|
u8 numListRegisters;
|
2019-08-10 23:56:49 +01:00
|
|
|
// Note: we don't store interrupt handlers since we will handle some SGI + uart interrupt(s)...
|
|
|
|
} IrqManager;
|
|
|
|
|
2019-08-12 22:24:30 +01:00
|
|
|
typedef enum ThermosphereSgi {
|
|
|
|
ThermosphereSgi_ExecuteFunction = 0,
|
2019-08-17 23:40:47 +01:00
|
|
|
ThermosphereSgi_VgicUpdate = 1,
|
2019-08-12 22:24:30 +01:00
|
|
|
|
2019-08-17 23:40:47 +01:00
|
|
|
ThermosphereSgi_Max = 2,
|
2019-08-12 22:24:30 +01:00
|
|
|
} ThermosphereSgi;
|
|
|
|
|
2019-08-10 23:56:49 +01:00
|
|
|
extern IrqManager g_irqManager;
|
|
|
|
|
|
|
|
void initIrq(void);
|
|
|
|
void handleIrqException(ExceptionStackFrame *frame, bool isLowerEl, bool isA32);
|
2019-08-17 23:40:47 +01:00
|
|
|
bool isGuestIrq(u16 id);
|
2019-08-10 23:56:49 +01:00
|
|
|
|
2019-08-12 22:24:30 +01:00
|
|
|
static inline void generateSgiForAllOthers(ThermosphereSgi id)
|
2019-08-10 23:56:49 +01:00
|
|
|
{
|
2019-08-12 22:24:30 +01:00
|
|
|
g_irqManager.gic.gicd->sgir = (1 << 24) | ((u32)id & 0xF);
|
2019-08-10 23:56:49 +01:00
|
|
|
}
|
|
|
|
|
2019-08-12 22:24:30 +01:00
|
|
|
static inline void generateSgiForSelf(ThermosphereSgi id)
|
2019-08-10 23:56:49 +01:00
|
|
|
{
|
2019-08-12 22:24:30 +01:00
|
|
|
g_irqManager.gic.gicd->sgir = (2 << 24) | ((u32)id & 0xF);
|
2019-08-10 23:56:49 +01:00
|
|
|
}
|
|
|
|
|
2019-08-12 22:24:30 +01:00
|
|
|
static inline void generateSgiForList(ThermosphereSgi id, u32 list)
|
2019-08-10 23:56:49 +01:00
|
|
|
{
|
2019-08-12 22:24:30 +01:00
|
|
|
g_irqManager.gic.gicd->sgir = (0 << 24) | (list << 16) | ((u32)id & 0xF);
|
2019-08-10 23:56:49 +01:00
|
|
|
}
|
|
|
|
|
2019-08-12 22:24:30 +01:00
|
|
|
static inline void generateSgiForAll(ThermosphereSgi id)
|
2019-08-10 23:56:49 +01:00
|
|
|
{
|
|
|
|
generateSgiForList(id, MASK(g_irqManager.numCpuInterfaces));
|
|
|
|
}
|