1/* 2 * Copyright 2017, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the GNU General Public License version 2. Note that NO WARRANTY is provided. 8 * See "LICENSE_GPLv2.txt" for details. 9 * 10 * @TAG(DATA61_GPL) 11 */ 12 13#ifndef __MODEL_STATEDATA_H_ 14#define __MODEL_STATEDATA_H_ 15 16#include <config.h> 17#include <types.h> 18#include <object/structures.h> 19#include <object/tcb.h> 20#include <mode/types.h> 21 22#ifdef ENABLE_SMP_SUPPORT 23#define NODE_STATE_BEGIN(_name) typedef struct _name { 24#define NODE_STATE_END(_name) } _name ## _t 25#define NODE_STATE_TYPE_DECLARE(_name, _state) _name ## _t _state 26#define NODE_STATE_DECLARE(_type, _state) _type _state 27 28#define SMP_STATE_DEFINE(_type, _state) _type _state 29#define UP_STATE_DEFINE(_type, _state) 30 31#define SMP_COND_STATEMENT(_st) _st 32#define SMP_TERNARY(_smp, _up) _smp 33 34#define MODE_NODE_STATE_ON_CORE(_state, _core) ksSMP[(_core)].cpu.mode._state 35#define ARCH_NODE_STATE_ON_CORE(_state, _core) ksSMP[(_core)].cpu._state 36#define NODE_STATE_ON_CORE(_state, _core) ksSMP[(_core)].system._state 37 38#define CURRENT_CPU_INDEX() getCurrentCPUIndex() 39 40#else 41 42#define NODE_STATE_BEGIN(_name) 43#define NODE_STATE_END(_name) 44#define NODE_STATE_TYPE_DECLARE(_name, _state) 45/* UP states are declared as VISIBLE so that they are accessible in assembly */ 46#define NODE_STATE_DECLARE(_type, _state) extern _type _state VISIBLE 47 48#define SMP_STATE_DEFINE(_name, _state) 49#define UP_STATE_DEFINE(_type, _state) _type _state 50 51#define SMP_COND_STATEMENT(_st) 52#define SMP_TERNARY(_smp, _up) _up 53 54#define MODE_NODE_STATE_ON_CORE(_state, _core) _state 55#define ARCH_NODE_STATE_ON_CORE(_state, _core) _state 56#define NODE_STATE_ON_CORE(_state, _core) _state 57 58#define CURRENT_CPU_INDEX() 0 59 60#endif /* ENABLE_SMP_SUPPORT */ 61 62#define NUM_READY_QUEUES (CONFIG_NUM_DOMAINS * CONFIG_NUM_PRIORITIES) 63#define L2_BITMAP_SIZE ((CONFIG_NUM_PRIORITIES + wordBits - 1) / wordBits) 64 65NODE_STATE_BEGIN(nodeState) 66NODE_STATE_DECLARE(tcb_queue_t, ksReadyQueues[NUM_READY_QUEUES]); 67NODE_STATE_DECLARE(word_t, ksReadyQueuesL1Bitmap[CONFIG_NUM_DOMAINS]); 68NODE_STATE_DECLARE(word_t, ksReadyQueuesL2Bitmap[CONFIG_NUM_DOMAINS][L2_BITMAP_SIZE]); 69NODE_STATE_DECLARE(tcb_t, *ksCurThread); 70NODE_STATE_DECLARE(tcb_t, *ksIdleThread); 71NODE_STATE_DECLARE(tcb_t, *ksSchedulerAction); 72 73#ifdef CONFIG_HAVE_FPU 74/* Current state installed in the FPU, or NULL if the FPU is currently invalid */ 75NODE_STATE_DECLARE(user_fpu_state_t *, ksActiveFPUState); 76/* Number of times we have restored a user context with an active FPU without switching it */ 77NODE_STATE_DECLARE(word_t, ksFPURestoresSinceSwitch); 78#endif /* CONFIG_HAVE_FPU */ 79#ifdef CONFIG_DEBUG_BUILD 80NODE_STATE_DECLARE(tcb_t *, ksDebugTCBs); 81#endif /* CONFIG_DEBUG_BUILD */ 82 83NODE_STATE_END(nodeState); 84 85extern word_t ksNumCPUs; 86 87extern word_t ksWorkUnitsCompleted; 88extern irq_state_t intStateIRQTable[]; 89extern cte_t *intStateIRQNode; 90extern const dschedule_t ksDomSchedule[]; 91extern const word_t ksDomScheduleLength; 92extern word_t ksDomScheduleIdx; 93extern dom_t ksCurDomain; 94extern word_t ksDomainTime; 95extern word_t tlbLockCount VISIBLE; 96 97#ifdef CONFIG_BENCHMARK_USE_KERNEL_LOG_BUFFER 98extern paddr_t ksUserLogBuffer; 99#endif /* CONFIG_BENCHMARK_USE_KERNEL_LOG_BUFFER */ 100 101#define SchedulerAction_ResumeCurrentThread ((tcb_t*)0) 102#define SchedulerAction_ChooseNewThread ((tcb_t*) 1) 103 104#define MODE_NODE_STATE(_state) MODE_NODE_STATE_ON_CORE(_state, getCurrentCPUIndex()) 105#define ARCH_NODE_STATE(_state) ARCH_NODE_STATE_ON_CORE(_state, getCurrentCPUIndex()) 106#define NODE_STATE(_state) NODE_STATE_ON_CORE(_state, getCurrentCPUIndex()) 107 108#endif /* __MODEL_STATEDATA_H_ */ 109