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-12-26 00:05:36 +00:00
|
|
|
#include "platform/interrupt_config.h"
|
2020-01-17 22:10:26 +00:00
|
|
|
#include "memory_map.h"
|
2019-08-10 23:56:49 +01:00
|
|
|
|
2019-08-17 23:40:47 +01:00
|
|
|
#define IRQ_PRIORITY_HOST 0
|
|
|
|
#define IRQ_PRIORITY_GUEST 1
|
|
|
|
|
2020-01-05 16:04:53 +00:00
|
|
|
#define IRQ_CFGR_SHIFT(id) (2*((id) % 16))
|
|
|
|
|
2019-08-10 23:56:49 +01:00
|
|
|
typedef struct IrqManager {
|
|
|
|
RecursiveSpinlock lock;
|
2020-01-02 23:29:37 +00:00
|
|
|
u16 numSharedInterrupts;
|
2019-12-23 20:12:02 +00:00
|
|
|
u8 priorityShift;
|
2019-08-10 23:56:49 +01:00
|
|
|
u8 numPriorityLevels;
|
|
|
|
u8 numCpuInterfaces;
|
2019-08-17 23:40:47 +01:00
|
|
|
u8 numListRegisters;
|
2019-08-10 23:56:49 +01:00
|
|
|
} 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,
|
2020-01-14 02:09:51 +00:00
|
|
|
ThermosphereSgi_DebugPause = 2,
|
2020-01-29 01:19:38 +00:00
|
|
|
ThermosphereSgi_ReportDebuggerBreak = 3,
|
2019-08-12 22:24:30 +01:00
|
|
|
|
2020-01-14 02:09:51 +00:00
|
|
|
ThermosphereSgi_Max,
|
2019-08-12 22:24:30 +01:00
|
|
|
} ThermosphereSgi;
|
|
|
|
|
2020-01-17 22:10:26 +00:00
|
|
|
static volatile ArmGicV2Distributor *const gicd = (volatile ArmGicV2Distributor *)MEMORY_MAP_VA_GICD;
|
|
|
|
static volatile ArmGicV2Controller *const gicc = (volatile ArmGicV2Controller *)MEMORY_MAP_VA_GICC;
|
|
|
|
static volatile ArmGicV2VirtualInterfaceController *const gich = (volatile ArmGicV2VirtualInterfaceController *)MEMORY_MAP_VA_GICH;
|
|
|
|
|
2019-08-10 23:56:49 +01:00
|
|
|
extern IrqManager g_irqManager;
|
|
|
|
|
|
|
|
void initIrq(void);
|
2020-01-10 19:45:31 +00:00
|
|
|
void configureInterrupt(u16 id, u8 prio, bool isLevelSensitive);
|
2020-01-12 01:59:26 +00:00
|
|
|
bool irqIsGuest(u16 id);
|
|
|
|
void irqSetAffinity(u16 id, u8 affinityMask);
|
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
|
|
|
{
|
2020-01-17 22:10:26 +00:00
|
|
|
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
|
|
|
{
|
2020-01-17 22:10:26 +00:00
|
|
|
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
|
|
|
{
|
2020-01-17 22:10:26 +00:00
|
|
|
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));
|
|
|
|
}
|