blob: 2dae0800ce2c49ea8f0260d186a11bdff910259b [file] [log] [blame]
Lukas Auerfa33f082019-03-17 19:28:32 +01001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2019 Fraunhofer AISEC,
4 * Lukas Auer <lukas.auer@aisec.fraunhofer.de>
5 */
6
7#ifndef _ASM_RISCV_SMP_H
8#define _ASM_RISCV_SMP_H
9
10/**
11 * struct ipi_data - Inter-processor interrupt (IPI) data structure
12 *
13 * IPIs are used for SMP support to communicate to other harts what function to
14 * call. Functions are in the form
15 * void (*addr)(ulong hart, ulong arg0, ulong arg1).
16 *
17 * The function address and the two arguments, arg0 and arg1, are stored in the
18 * IPI data structure. The hart ID is inserted by the hart handling the IPI and
19 * calling the function.
20 *
Sean Andersonf760c9a2020-09-21 07:51:37 -040021 * @valid is used to determine whether a sent IPI originated from U-Boot. It is
22 * initialized to zero by board_init_f_alloc_reserve. When U-Boot sends its
23 * first IPI, it is set to 1. This prevents already-pending IPIs not sent by
24 * U-Boot from being taken.
25 *
Lukas Auerfa33f082019-03-17 19:28:32 +010026 * @addr: Address of function
27 * @arg0: First argument of function
28 * @arg1: Second argument of function
Sean Andersonf760c9a2020-09-21 07:51:37 -040029 * @valid: Whether this IPI is valid
Lukas Auerfa33f082019-03-17 19:28:32 +010030 */
31struct ipi_data {
32 ulong addr;
33 ulong arg0;
34 ulong arg1;
Sean Andersonf760c9a2020-09-21 07:51:37 -040035 unsigned int valid;
Lukas Auerfa33f082019-03-17 19:28:32 +010036};
37
38/**
39 * handle_ipi() - interrupt handler for software interrupts
40 *
41 * The IPI interrupt handler must be called to handle software interrupts. It
42 * calls the function specified in the hart's IPI data structure.
43 *
44 * @hart: Hart ID of the current hart
45 */
46void handle_ipi(ulong hart);
47
48/**
49 * smp_call_function() - Call a function on all other harts
50 *
51 * Send IPIs with the specified function call to all harts.
52 *
53 * @addr: Address of function
54 * @arg0: First argument of function
55 * @arg1: Second argument of function
Lukas Auer90ae2812019-12-08 23:28:51 +010056 * @wait: Wait for harts to acknowledge request
Lukas Auerfa33f082019-03-17 19:28:32 +010057 * @return 0 if OK, -ve on error
58 */
Lukas Auer90ae2812019-12-08 23:28:51 +010059int smp_call_function(ulong addr, ulong arg0, ulong arg1, int wait);
Lukas Auerfa33f082019-03-17 19:28:32 +010060
Sean Anderson40686c32020-06-24 06:41:18 -040061/**
62 * riscv_init_ipi() - Initialize inter-process interrupt (IPI) driver
63 *
64 * Platform code must provide this function. This function is called once after
65 * the cpu driver is initialized. No other riscv_*_ipi() calls will be made
66 * before this function is called.
67 *
68 * @return 0 if OK, -ve on error
69 */
70int riscv_init_ipi(void);
71
72/**
73 * riscv_send_ipi() - Send inter-processor interrupt (IPI)
74 *
75 * Platform code must provide this function.
76 *
77 * @hart: Hart ID of receiving hart
78 * @return 0 if OK, -ve on error
79 */
80int riscv_send_ipi(int hart);
81
82/**
83 * riscv_clear_ipi() - Clear inter-processor interrupt (IPI)
84 *
85 * Platform code must provide this function.
86 *
87 * @hart: Hart ID of hart to be cleared
88 * @return 0 if OK, -ve on error
89 */
90int riscv_clear_ipi(int hart);
91
92/**
93 * riscv_get_ipi() - Get status of inter-processor interrupt (IPI)
94 *
95 * Platform code must provide this function.
96 *
97 * @hart: Hart ID of hart to be checked
98 * @pending: Pointer to variable with result of the check,
99 * 1 if IPI is pending, 0 otherwise
100 * @return 0 if OK, -ve on error
101 */
102int riscv_get_ipi(int hart, int *pending);
103
Lukas Auerfa33f082019-03-17 19:28:32 +0100104#endif