blob: ee749dd11954dce8f527108f15d361cc8fe3edb0 [file] [log] [blame]
Lukas Auer83d573d2019-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
Tom Rinib6b99002023-10-12 19:03:59 -040010#include <linux/types.h>
11
Lukas Auer83d573d2019-03-17 19:28:32 +010012/**
13 * struct ipi_data - Inter-processor interrupt (IPI) data structure
14 *
15 * IPIs are used for SMP support to communicate to other harts what function to
16 * call. Functions are in the form
17 * void (*addr)(ulong hart, ulong arg0, ulong arg1).
18 *
19 * The function address and the two arguments, arg0 and arg1, are stored in the
20 * IPI data structure. The hart ID is inserted by the hart handling the IPI and
21 * calling the function.
22 *
Sean Andersonff184fe2020-09-21 07:51:37 -040023 * @valid is used to determine whether a sent IPI originated from U-Boot. It is
24 * initialized to zero by board_init_f_alloc_reserve. When U-Boot sends its
25 * first IPI, it is set to 1. This prevents already-pending IPIs not sent by
26 * U-Boot from being taken.
27 *
Lukas Auer83d573d2019-03-17 19:28:32 +010028 * @addr: Address of function
29 * @arg0: First argument of function
30 * @arg1: Second argument of function
Sean Andersonff184fe2020-09-21 07:51:37 -040031 * @valid: Whether this IPI is valid
Lukas Auer83d573d2019-03-17 19:28:32 +010032 */
33struct ipi_data {
34 ulong addr;
35 ulong arg0;
36 ulong arg1;
Sean Andersonff184fe2020-09-21 07:51:37 -040037 unsigned int valid;
Lukas Auer83d573d2019-03-17 19:28:32 +010038};
39
40/**
41 * handle_ipi() - interrupt handler for software interrupts
42 *
43 * The IPI interrupt handler must be called to handle software interrupts. It
44 * calls the function specified in the hart's IPI data structure.
45 *
46 * @hart: Hart ID of the current hart
47 */
48void handle_ipi(ulong hart);
49
50/**
51 * smp_call_function() - Call a function on all other harts
52 *
53 * Send IPIs with the specified function call to all harts.
54 *
55 * @addr: Address of function
56 * @arg0: First argument of function
57 * @arg1: Second argument of function
Lukas Auerc308e012019-12-08 23:28:51 +010058 * @wait: Wait for harts to acknowledge request
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010059 * Return: 0 if OK, -ve on error
Lukas Auer83d573d2019-03-17 19:28:32 +010060 */
Lukas Auerc308e012019-12-08 23:28:51 +010061int smp_call_function(ulong addr, ulong arg0, ulong arg1, int wait);
Lukas Auer83d573d2019-03-17 19:28:32 +010062
Sean Andersonb1d0cb32020-06-24 06:41:18 -040063/**
64 * riscv_init_ipi() - Initialize inter-process interrupt (IPI) driver
65 *
66 * Platform code must provide this function. This function is called once after
67 * the cpu driver is initialized. No other riscv_*_ipi() calls will be made
68 * before this function is called.
69 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010070 * Return: 0 if OK, -ve on error
Sean Andersonb1d0cb32020-06-24 06:41:18 -040071 */
72int riscv_init_ipi(void);
73
74/**
75 * riscv_send_ipi() - Send inter-processor interrupt (IPI)
76 *
77 * Platform code must provide this function.
78 *
79 * @hart: Hart ID of receiving hart
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010080 * Return: 0 if OK, -ve on error
Sean Andersonb1d0cb32020-06-24 06:41:18 -040081 */
82int riscv_send_ipi(int hart);
83
84/**
85 * riscv_clear_ipi() - Clear inter-processor interrupt (IPI)
86 *
87 * Platform code must provide this function.
88 *
89 * @hart: Hart ID of hart to be cleared
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010090 * Return: 0 if OK, -ve on error
Sean Andersonb1d0cb32020-06-24 06:41:18 -040091 */
92int riscv_clear_ipi(int hart);
93
94/**
95 * riscv_get_ipi() - Get status of inter-processor interrupt (IPI)
96 *
97 * Platform code must provide this function.
98 *
99 * @hart: Hart ID of hart to be checked
100 * @pending: Pointer to variable with result of the check,
101 * 1 if IPI is pending, 0 otherwise
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100102 * Return: 0 if OK, -ve on error
Sean Andersonb1d0cb32020-06-24 06:41:18 -0400103 */
104int riscv_get_ipi(int hart, int *pending);
105
Lukas Auer83d573d2019-03-17 19:28:32 +0100106#endif