| 1 |
|
| 2 |
|
| 3 |
#ifndef _MCALL_H |
| 4 |
#define _MCALL_H |
| 5 |
|
| 6 |
|
| 7 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 70 |
void hls_init(uint32_t hart_id, void *fdt); |
| 71 |
|
| 72 |
|
| 73 |
void mtime_init(void); |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
void set_msip(int hartid, int val); |
| 83 |
|
| 84 |
#endif |
| 85 |
|
| 86 |
#endif |