1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-15 00:16:48 +00:00

thermopshere: add "execute function" sgi

This commit is contained in:
TuxSH 2019-08-12 23:47:14 +02:00
parent 0b69407f8e
commit b2c5ef2611
5 changed files with 114 additions and 12 deletions

View file

@ -17,6 +17,7 @@
#pragma once #pragma once
#include "utils.h" #include "utils.h"
#include "barrier.h" #include "barrier.h"
#include "execute_function.h"
typedef struct CoreCtx { typedef struct CoreCtx {
u64 kernelArgument; // @0x00 u64 kernelArgument; // @0x00
@ -29,8 +30,10 @@ typedef struct CoreCtx {
bool warmboot; // @0x26 bool warmboot; // @0x26
// "Execute function" // "Execute function"
void *asyncFunctionArgs; // @0x28 ExecutedFunction executedFunction; // @0x28
Barrier asyncFunctionBarrier; // @0x30 void *executedFunctionArgs; // @0x30
Barrier executedFunctionBarrier; // @0x38
bool executedFunctionSync; // @0x3C
} CoreCtx; } CoreCtx;
extern CoreCtx g_coreCtxs[4]; extern CoreCtx g_coreCtxs[4];

View file

@ -0,0 +1,49 @@
/*
* 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/>.
*/
#include "execute_function.h"
#include "utils.h"
#include "core_ctx.h"
#include "irq.h"
void executeFunctionOnCores(ExecutedFunction fun, void *args, bool sync, u32 coreList)
{
barrierInit(&currentCoreCtx->executedFunctionBarrier, coreList);
currentCoreCtx->executedFunction = fun;
currentCoreCtx->executedFunctionArgs = args;
currentCoreCtx->executedFunctionSync = sync;
generateSgiForList(ThermosphereSgi_ExecuteFunction, coreList);
}
void executeFunctionOnAllCores(ExecutedFunction fun, void *args, bool sync)
{
executeFunctionOnCores(fun, args, sync, getActiveCoreMask());
}
void executeFunctionOnAllCoresButSelf(ExecutedFunction fun, void *args, bool sync)
{
executeFunctionOnCores(fun, args, sync, getActiveCoreMask() & ~(BIT(currentCoreCtx->coreId)));
}
void executeFunctionInterruptHandler(u32 srcCore)
{
CoreCtx *ctx = &g_coreCtxs[srcCore];
ctx->executedFunction(ctx->executedFunctionArgs);
if (ctx->executedFunctionSync) {
barrierWait(&ctx->executedFunctionBarrier);
}
}

View file

@ -0,0 +1,28 @@
/*
* 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 "types.h"
typedef void (*ExecutedFunction)(void *args);
void executeFunctionOnCores(ExecutedFunction fun, void *args, bool sync, u32 coreList);
void executeFunctionOnAllCores(ExecutedFunction fun, void *args, bool sync);
void executeFunctionOnAllCoresButSelf(ExecutedFunction fun, void *args, bool sync);
void executeFunctionInterruptHandler(u32 srcCore);

View file

@ -121,7 +121,10 @@ void initIrq(void)
initGic(); initGic();
// Configure the interrupts we use here // Configure the interrupts we use here
configureInterrupt(0, 0, false); for (u32 i = 0; i < ThermosphereSgi_Max; i++) {
configureInterrupt(i, 0, false);
}
configureInterrupt(GIC_IRQID_MAINTENANCE, 0, true); configureInterrupt(GIC_IRQID_MAINTENANCE, 0, true);
recursiveSpinlockUnlockRestoreIrq(&g_irqManager.lock, flags); recursiveSpinlockUnlockRestoreIrq(&g_irqManager.lock, flags);
@ -136,6 +139,7 @@ void handleIrqException(ExceptionStackFrame *frame, bool isLowerEl, bool isA32)
// Acknowledge the interrupt. Interrupt goes from pending to active. // Acknowledge the interrupt. Interrupt goes from pending to active.
u32 iar = gicc->iar; u32 iar = gicc->iar;
u32 irqId = iar & 0x3FF; u32 irqId = iar & 0x3FF;
u32 srcCore = (iar >> 12) & 7;
DEBUG("Received irq %x\n", irqId); DEBUG("Received irq %x\n", irqId);
@ -146,7 +150,17 @@ void handleIrqException(ExceptionStackFrame *frame, bool isLowerEl, bool isA32)
bool isGuestInterrupt = false; bool isGuestInterrupt = false;
// TODO: handle the interrupt if it's a host interrupt switch (irqId) {
case ThermosphereSgi_ExecuteFunction:
executeFunctionInterruptHandler(srcCore);
break;
case GIC_IRQID_MAINTENANCE:
/* TODO */
break;
default:
isGuestInterrupt = true;
break;
}
// Priority drop // Priority drop
gicc->eoir = iar; gicc->eoir = iar;

View file

@ -16,6 +16,11 @@
extern const u8 __start__[]; extern const u8 __start__[];
static void testf1(void *p)
{
DEBUG("Hello from sgi 0, p=%016llx\n", p);
}
static void loadKernelViaSemihosting(void) static void loadKernelViaSemihosting(void)
{ {
size_t len = 1<<20; // max len size_t len = 1<<20; // max len
@ -80,6 +85,9 @@ void main(ExceptionStackFrame *frame)
// Test // Test
singleStepSetNextState(frame, SingleStepState_ActivePending); singleStepSetNextState(frame, SingleStepState_ActivePending);
// Test
executeFunctionOnAllCores(testf1, (void *)0x1234567, true);
/*// Test /*// Test
unmaskIrq(); unmaskIrq();
generateSgiForAll(0);*/ generateSgiForAll(0);*/