2019-02-26 02:02:50 +03:00
|
|
|
/*
|
2019-04-04 07:15:30 +03:00
|
|
|
* Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de.
|
|
|
|
* Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef _KERNEL_ARCH_RISCV64_CPU_H
|
|
|
|
#define _KERNEL_ARCH_RISCV64_CPU_H
|
2019-02-26 02:02:50 +03:00
|
|
|
|
|
|
|
|
2019-04-04 07:15:30 +03:00
|
|
|
#include <arch/riscv64/arch_thread_types.h>
|
2021-06-06 16:51:53 +03:00
|
|
|
#include <arch_cpu_defs.h>
|
2019-04-04 07:15:30 +03:00
|
|
|
#include <kernel.h>
|
|
|
|
|
|
|
|
|
|
|
|
#define CPU_MAX_CACHE_LEVEL 8
|
|
|
|
#define CACHE_LINE_SIZE 64
|
|
|
|
|
|
|
|
|
2021-06-06 16:51:53 +03:00
|
|
|
static inline bool
|
|
|
|
get_ac()
|
|
|
|
{
|
|
|
|
SstatusReg status(Sstatus());
|
|
|
|
return status.sum != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
set_ac()
|
|
|
|
{
|
|
|
|
// TODO: Could be done atomically via CSRRS?
|
|
|
|
SstatusReg status(Sstatus());
|
|
|
|
status.sum = 1;
|
|
|
|
SetSstatus(status.val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
clear_ac()
|
|
|
|
{
|
|
|
|
// TODO: Could be done atomically with CSRRC?
|
|
|
|
SstatusReg status(Sstatus());
|
|
|
|
status.sum = 0;
|
|
|
|
SetSstatus(status.val);
|
|
|
|
}
|
2019-04-04 07:15:30 +03:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct arch_cpu_info {
|
2021-11-09 21:39:16 +03:00
|
|
|
uint64 hartId;
|
2019-04-04 07:15:30 +03:00
|
|
|
} arch_cpu_info;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
2019-02-26 02:02:50 +03:00
|
|
|
#endif
|
2019-04-04 07:15:30 +03:00
|
|
|
|
|
|
|
|
2021-06-06 16:51:53 +03:00
|
|
|
void __riscv64_setup_system_time(uint64 conversionFactor);
|
|
|
|
|
|
|
|
|
2019-04-04 07:15:30 +03:00
|
|
|
static inline void
|
|
|
|
arch_cpu_pause(void)
|
|
|
|
{
|
|
|
|
// TODO: CPU pause
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
arch_cpu_idle(void)
|
|
|
|
{
|
2021-06-06 16:51:53 +03:00
|
|
|
Wfi();
|
2019-04-04 07:15:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* _KERNEL_ARCH_RISCV64_CPU_H */
|