Debian Codegraph @

src/arch/riscv/include/mcall.h

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #ifndef _MCALL_H
4 #define _MCALL_H
5
6 // NOTE: this is the size of struct hls below. A static_assert would be
7 // nice to have.
8 #if __riscv_xlen == 64
9 #define HLS_SIZE 96
10 #endif
11
12 #if __riscv_xlen == 32
13 #define HLS_SIZE 56
14 #endif
15
16 /* We save 37 registers, currently. */
17 #define MENTRY_FRAME_SIZE (HLS_SIZE + 37 * __SIZEOF_POINTER__)
18
19 #ifndef __ASSEMBLER__
20
21 #include <arch/encoding.h>
22 #include <arch/smp/atomic.h>
23 #include <stdint.h>
24
25 struct sbi_device_message {
26 unsigned long dev;
27 unsigned long cmd;
28 unsigned long data;
29 unsigned long sbi_private_data;
30 };
31
32 struct blocker {
33 void *arg;
34 void (*fn)(void *arg);
35 atomic_t sync_a;
36 atomic_t sync_b;
37 };
38
39 struct hls {
40 struct sbi_device_message *device_request_queue_head;
41 unsigned long device_request_queue_size;
42 struct sbi_device_message *device_response_queue_head;
43 struct sbi_device_message *device_response_queue_tail;
44
45 int enabled;
46 int hart_id;
47 int ipi_pending;
48 uint64_t *timecmp;
49 uint64_t *time;
50 void *fdt;
51 struct blocker entry;
52 };
53
54 _Static_assert(
55 sizeof(struct hls) == HLS_SIZE,
56 "HLS_SIZE must equal to sizeof(struct hls)");
57
58 register uintptr_t current_stack_pointer asm("sp");
59
60 #define MACHINE_STACK_TOP() ({ \
61 (void *)((current_stack_pointer + RISCV_PGSIZE) & -RISCV_PGSIZE); })
62
63 // hart-local storage, at top of stack
64 #define HLS() ((struct hls *)(MACHINE_STACK_TOP() - HLS_SIZE))
65 #define OTHER_HLS(id) ((struct hls *)((void *)HLS() + RISCV_PGSIZE * ((id) - HLS()->hart_id)))
66
67 #define MACHINE_STACK_SIZE RISCV_PGSIZE
68
69 // need to call this before launching linux
70 void hls_init(uint32_t hart_id, void *fdt);
71
72 /* This function is used to initialize HLS()->time/HLS()->timecmp */
73 void mtime_init(void);
74
75 /*
76 * This function needs be implement by SoC code.
77 * Although the privileged instruction set defines that MSIP will be
78 * memory-mapped, but does not define how to map. SoC can be implemented as
79 * a bit, a byte, a word, and so on.
80 * So we can't provide code that is related to implementation.
81 */
82 void set_msip(int hartid, int val);
83
84 #endif // __ASSEMBLER__
85
86 #endif