blob: cd384fc273cb087495a4f165e90d126d552ed2d0 [file] [log] [blame]
Andrew Scull18834872018-10-12 11:48:09 +01001/*
Andrew Walbran692b3252019-03-07 15:51:31 +00002 * Copyright 2018 The Hafnium Authors.
Andrew Scull18834872018-10-12 11:48:09 +01003 *
Andrew Walbrane959ec12020-06-17 15:01:09 +01004 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/BSD-3-Clause.
Andrew Scull18834872018-10-12 11:48:09 +01007 */
8
Andrew Scullfbc938a2018-08-20 14:09:28 +01009#pragma once
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010010
Olivier Deprez64b421e2022-10-06 10:28:20 +020011#define STACK_SIZE (8192)
12
Karl Meakin2ad6b662024-07-29 20:45:40 +010013#ifndef __ASSEMBLER__
Olivier Deprez64b421e2022-10-06 10:28:20 +020014
Andrew Scull18c78fc2018-08-20 12:57:41 +010015#include "hf/arch/cpu.h"
16
Madhukar Pappireddyeed861e2024-09-25 13:50:54 -050017#include "hf/timer_mgmt.h"
18
Madhukar Pappireddy44b85ff2024-11-25 10:29:22 -060019#define PRIMARY_CPU_IDX 0U
20
Fuad Tabbab0ef2a42019-12-19 11:19:25 +000021/* TODO: Fix alignment such that `cpu` structs are in different cache lines. */
Karl Meakin2ad6b662024-07-29 20:45:40 +010022/* NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding) */
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010023struct cpu {
Andrew Walbranc3910f72018-11-27 14:24:36 +000024 /** CPU identifier. Doesn't have to be contiguous. */
Andrew Walbran4d3fa282019-06-26 13:31:15 +010025 cpu_id_t id;
Andrew Scull020ae692018-07-19 16:20:14 +010026
Andrew Walbranc3910f72018-11-27 14:24:36 +000027 /** Pointer to bottom of the stack. */
Andrew Scull020ae692018-07-19 16:20:14 +010028 void *stack_bottom;
29
Andrew Walbran0d7a0682018-12-06 16:48:47 +000030 /** See api.c for the partial ordering on locks. */
Andrew Scull020ae692018-07-19 16:20:14 +010031 struct spinlock lock;
32
Fuad Tabbab0ef2a42019-12-19 11:19:25 +000033 /** Determines whether the CPU is currently on. */
Wedson Almeida Filho87009642018-07-02 10:20:07 +010034 bool is_on;
J-Alvesea8ccfe2024-10-09 11:47:24 +010035
36 /* In case there is a pending SRI for the NWd. */
37 bool is_sri_delayed;
Daniel Boulbyf3cf28c2024-08-22 10:46:23 +010038
Madhukar Pappireddyeed861e2024-09-25 13:50:54 -050039 /**
40 * A list of entries associated with vCPUs having pending timer
41 * deadline.
42 */
43 struct timer_pending_vcpu_list pending_timer_vcpus_list;
Daniel Boulby7011b5a2024-10-15 18:27:26 +010044
45 /* Head of the list of vcpus with pending IPIs. */
46 struct list_entry pending_ipis;
Madhukar Pappireddy44b85ff2024-11-25 10:29:22 -060047
48 /**
49 * Denotes if the last MP SP's execution context, pinned on this CPU,
50 * has been initialized.
51 */
52 bool last_sp_initialized;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010053};
54
Andrew Walbran4d3fa282019-06-26 13:31:15 +010055void cpu_module_init(const cpu_id_t *cpu_ids, size_t count);
Wedson Almeida Filho3fcbcff2018-07-10 23:53:39 +010056
Wedson Almeida Filho3fcbcff2018-07-10 23:53:39 +010057size_t cpu_index(struct cpu *c);
Olivier Deprez7d5e5532020-09-22 15:06:58 +020058struct cpu *cpu_find_index(size_t index);
Olivier Deprez70f8a4a2022-09-26 09:17:56 +020059bool cpu_on(struct cpu *c);
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010060void cpu_off(struct cpu *c);
Andrew Walbran4d3fa282019-06-26 13:31:15 +010061struct cpu *cpu_find(cpu_id_t id);
Mahesh Bireddy8ca57862020-01-07 13:43:21 +053062uint8_t *cpu_get_buffer(struct cpu *c);
63uint32_t cpu_get_buffer_size(struct cpu *c);
Olivier Deprez64b421e2022-10-06 10:28:20 +020064
65#endif