1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-24 19:26:04 +00:00
Atmosphere/thermosphere/src/irq.h

79 lines
2.3 KiB
C
Raw Normal View History

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"
#include "platform/interrupt_config.h"
#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
#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;
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,
ThermosphereSgi_ReportDebuggerBreak = 3,
2020-01-14 02:09:51 +00:00
ThermosphereSgi_Max,
} ThermosphereSgi;
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);
bool irqIsGuest(u16 id);
void irqSetAffinity(u16 id, u8 affinityMask);
2019-08-10 23:56:49 +01:00
static inline void generateSgiForAllOthers(ThermosphereSgi id)
2019-08-10 23:56:49 +01:00
{
gicd->sgir = (1 << 24) | ((u32)id & 0xF);
2019-08-10 23:56:49 +01:00
}
static inline void generateSgiForSelf(ThermosphereSgi id)
2019-08-10 23:56:49 +01:00
{
gicd->sgir = (2 << 24) | ((u32)id & 0xF);
2019-08-10 23:56:49 +01:00
}
static inline void generateSgiForList(ThermosphereSgi id, u32 list)
2019-08-10 23:56:49 +01:00
{
gicd->sgir = (0 << 24) | (list << 16) | ((u32)id & 0xF);
2019-08-10 23:56:49 +01:00
}
static inline void generateSgiForAll(ThermosphereSgi id)
2019-08-10 23:56:49 +01:00
{
generateSgiForList(id, MASK(g_irqManager.numCpuInterfaces));
}