riscv: add support smp_pause / smp_resume
[coreboot.git] / src / arch / riscv / include / mcall.h
blob29df736d1b5428b9a7102a3e1f82913ea6919edf
1 /*
2 * This file is part of the coreboot project.
4 * Copyright (C) 2013 The ChromiumOS Authors
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #ifndef _MCALL_H
17 #define _MCALL_H
19 // NOTE: this is the size of hls_t below. A static_assert would be
20 // nice to have.
21 #define HLS_SIZE 88
23 /* We save 37 registers, currently. */
24 #define MENTRY_FRAME_SIZE (HLS_SIZE + 37 * 8)
26 #ifndef __ASSEMBLER__
28 #include <arch/encoding.h>
29 #include <stdint.h>
31 typedef struct {
32 unsigned long dev;
33 unsigned long cmd;
34 unsigned long data;
35 unsigned long sbi_private_data;
36 } sbi_device_message;
38 struct blocker {
39 void *arg;
40 void (*fn)(void *arg);
41 uint32_t sync_a;
42 uint32_t sync_b;
45 typedef struct {
46 sbi_device_message *device_request_queue_head;
47 unsigned long device_request_queue_size;
48 sbi_device_message *device_response_queue_head;
49 sbi_device_message *device_response_queue_tail;
51 int hart_id;
52 int ipi_pending;
53 uint64_t *timecmp;
54 uint64_t *time;
55 struct blocker entry;
56 } hls_t;
58 #define MACHINE_STACK_TOP() ({ \
59 /* coverity[uninit_use] : FALSE */ \
60 register uintptr_t sp asm ("sp"); \
61 (void*)((sp + RISCV_PGSIZE) & -RISCV_PGSIZE); })
63 // hart-local storage, at top of stack
64 #define HLS() ((hls_t*)(MACHINE_STACK_TOP() - HLS_SIZE))
65 #define OTHER_HLS(id) ((hls_t*)((void*)HLS() + RISCV_PGSIZE * ((id) - HLS()->hart_id)))
67 #define MACHINE_STACK_SIZE RISCV_PGSIZE
69 void hls_init(uint32_t hart_id); // need to call this before launching linux
71 /* This function is used to initialize HLS()->time/HLS()->timecmp */
72 void mtime_init(void);
75 * This function needs be implement by SoC code.
76 * Although the privileged instruction set defines that MSIP will be
77 * memory-mapped, but does not define how to map. SoC can be implemented as
78 * a bit, a byte, a word, and so on.
79 * So we can't provide code that is related to implementation.
81 void set_msip(int hartid, int val);
83 #endif // __ASSEMBLER__
85 #endif