2020-05-24 15:30:55 -05:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef _SMP_H_
|
|
|
|
#define _SMP_H_
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
*
|
2020-05-24 15:30:55 -05:00
|
|
|
* Provides support for multi-threaded operation.
|
|
|
|
*
|
2022-02-19 13:56:55 -06:00
|
|
|
*//*
|
2022-01-29 10:11:15 -06:00
|
|
|
* Copyright (C) 2020-2022 Martin Whitaker.
|
2020-05-24 15:30:55 -05:00
|
|
|
*/
|
|
|
|
|
2021-12-05 07:47:31 -06:00
|
|
|
#include <stdbool.h>
|
2020-05-24 15:30:55 -05:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "boot.h"
|
|
|
|
|
|
|
|
#include "barrier.h"
|
|
|
|
#include "spinlock.h"
|
|
|
|
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
2022-02-02 06:20:39 -06:00
|
|
|
* The maximum number of CPU cores that can be used.
|
2020-05-24 15:30:55 -05:00
|
|
|
*/
|
2022-02-02 06:20:39 -06:00
|
|
|
#define MAX_CPUS (1 + MAX_APS)
|
2020-05-24 15:30:55 -05:00
|
|
|
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
2022-01-31 13:47:32 -06:00
|
|
|
* The current state of a CPU core.
|
2020-05-24 15:30:55 -05:00
|
|
|
*/
|
2022-01-31 13:47:32 -06:00
|
|
|
typedef enum __attribute__ ((packed)) {
|
|
|
|
CPU_STATE_DISABLED = 0,
|
|
|
|
CPU_STATE_ENABLED = 1,
|
2022-02-28 14:21:50 -06:00
|
|
|
CPU_STATE_RUNNING = 2
|
2022-01-31 13:47:32 -06:00
|
|
|
} cpu_state_t;
|
2020-05-24 15:30:55 -05:00
|
|
|
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
2022-01-31 16:59:14 -06:00
|
|
|
* The number of available CPU cores. Initially this is 1, but may increase
|
|
|
|
* after calling smp_init().
|
2020-05-24 15:30:55 -05:00
|
|
|
*/
|
2022-01-31 16:59:14 -06:00
|
|
|
extern int num_available_cpus;
|
2020-05-24 15:30:55 -05:00
|
|
|
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
2022-02-01 09:42:44 -06:00
|
|
|
* Initialises the SMP state and detects the number of available CPU cores.
|
2020-05-24 15:30:55 -05:00
|
|
|
*/
|
2020-12-10 06:52:58 -06:00
|
|
|
void smp_init(bool smp_enable);
|
2020-05-24 15:30:55 -05:00
|
|
|
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
2022-01-31 16:59:14 -06:00
|
|
|
* Starts the APs listed as enabled in cpu_state. Returns 0 on success
|
2022-01-31 13:47:32 -06:00
|
|
|
* or the index number of the lowest-numbered AP that failed to start.
|
2020-05-24 15:30:55 -05:00
|
|
|
*/
|
2022-01-31 16:59:14 -06:00
|
|
|
int smp_start(cpu_state_t cpu_state[MAX_CPUS]);
|
2020-05-24 15:30:55 -05:00
|
|
|
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
2022-02-12 10:16:56 -06:00
|
|
|
* Sends a non-maskable interrupt to the CPU core whose ordinal number
|
|
|
|
* is cpu_num.
|
|
|
|
*/
|
2022-02-28 14:21:50 -06:00
|
|
|
void smp_send_nmi(int cpu_num);
|
2022-02-12 10:16:56 -06:00
|
|
|
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
2022-02-01 09:42:44 -06:00
|
|
|
* Returns the ordinal number of the calling CPU core.
|
2020-05-24 15:30:55 -05:00
|
|
|
*/
|
2022-01-31 16:59:14 -06:00
|
|
|
int smp_my_cpu_num(void);
|
2020-05-24 15:30:55 -05:00
|
|
|
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
2020-05-24 15:30:55 -05:00
|
|
|
* Allocates and initialises a barrier object in pinned memory.
|
|
|
|
*/
|
|
|
|
barrier_t *smp_alloc_barrier(int num_threads);
|
|
|
|
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
2020-05-24 15:30:55 -05:00
|
|
|
* Allocates and initialises a spinlock object in pinned memory.
|
|
|
|
*/
|
|
|
|
spinlock_t *smp_alloc_mutex();
|
|
|
|
|
|
|
|
#endif /* _SMP_H_ */
|