18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2012 Regents of the University of California
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef _ASM_RISCV_PROCESSOR_H
78c2ecf20Sopenharmony_ci#define _ASM_RISCV_PROCESSOR_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/const.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <vdso/processor.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <asm/ptrace.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/*
168c2ecf20Sopenharmony_ci * This decides where the kernel will search for a free chunk of vm
178c2ecf20Sopenharmony_ci * space during mmap's.
188c2ecf20Sopenharmony_ci */
198c2ecf20Sopenharmony_ci#define TASK_UNMAPPED_BASE	PAGE_ALIGN(TASK_SIZE / 3)
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define STACK_TOP		TASK_SIZE
228c2ecf20Sopenharmony_ci#define STACK_TOP_MAX		STACK_TOP
238c2ecf20Sopenharmony_ci#define STACK_ALIGN		16
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistruct task_struct;
288c2ecf20Sopenharmony_cistruct pt_regs;
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* CPU-specific state of a task */
318c2ecf20Sopenharmony_cistruct thread_struct {
328c2ecf20Sopenharmony_ci	/* Callee-saved registers */
338c2ecf20Sopenharmony_ci	unsigned long ra;
348c2ecf20Sopenharmony_ci	unsigned long sp;	/* Kernel mode stack */
358c2ecf20Sopenharmony_ci	unsigned long s[12];	/* s[0]: frame pointer */
368c2ecf20Sopenharmony_ci	struct __riscv_d_ext_state fstate;
378c2ecf20Sopenharmony_ci};
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define INIT_THREAD {					\
408c2ecf20Sopenharmony_ci	.sp = sizeof(init_stack) + (long)&init_stack,	\
418c2ecf20Sopenharmony_ci}
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define task_pt_regs(tsk)						\
448c2ecf20Sopenharmony_ci	((struct pt_regs *)(task_stack_page(tsk) + THREAD_SIZE		\
458c2ecf20Sopenharmony_ci			    - ALIGN(sizeof(struct pt_regs), STACK_ALIGN)))
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#define KSTK_EIP(tsk)		(task_pt_regs(tsk)->epc)
488c2ecf20Sopenharmony_ci#define KSTK_ESP(tsk)		(task_pt_regs(tsk)->sp)
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/* Do necessary setup to start up a newly executed thread. */
528c2ecf20Sopenharmony_ciextern void start_thread(struct pt_regs *regs,
538c2ecf20Sopenharmony_ci			unsigned long pc, unsigned long sp);
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/* Free all resources held by a thread. */
568c2ecf20Sopenharmony_cistatic inline void release_thread(struct task_struct *dead_task)
578c2ecf20Sopenharmony_ci{
588c2ecf20Sopenharmony_ci}
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ciextern unsigned long get_wchan(struct task_struct *p);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistatic inline void wait_for_interrupt(void)
648c2ecf20Sopenharmony_ci{
658c2ecf20Sopenharmony_ci	__asm__ __volatile__ ("wfi");
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistruct device_node;
698c2ecf20Sopenharmony_ciint riscv_of_processor_hartid(struct device_node *node);
708c2ecf20Sopenharmony_ciint riscv_of_parent_hartid(struct device_node *node);
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ciextern void riscv_fill_hwcap(void);
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci#endif /* _ASM_RISCV_PROCESSOR_H */
77