Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 1 | /* |
Andrew Walbran | 692b325 | 2019-03-07 15:51:31 +0000 | [diff] [blame] | 2 | * Copyright 2018 The Hafnium Authors. |
Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 3 | * |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 4 | * 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 Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
Andrew Scull | fbc938a | 2018-08-20 14:09:28 +0100 | [diff] [blame] | 9 | #pragma once |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 10 | |
Olivier Deprez | 64b421e | 2022-10-06 10:28:20 +0200 | [diff] [blame] | 11 | #define STACK_SIZE (8192) |
| 12 | |
Karl Meakin | 2ad6b66 | 2024-07-29 20:45:40 +0100 | [diff] [blame] | 13 | #ifndef __ASSEMBLER__ |
Olivier Deprez | 64b421e | 2022-10-06 10:28:20 +0200 | [diff] [blame] | 14 | |
Andrew Scull | 18c78fc | 2018-08-20 12:57:41 +0100 | [diff] [blame] | 15 | #include "hf/arch/cpu.h" |
| 16 | |
Madhukar Pappireddy | eed861e | 2024-09-25 13:50:54 -0500 | [diff] [blame] | 17 | #include "hf/timer_mgmt.h" |
| 18 | |
Madhukar Pappireddy | 44b85ff | 2024-11-25 10:29:22 -0600 | [diff] [blame] | 19 | #define PRIMARY_CPU_IDX 0U |
| 20 | |
Fuad Tabba | b0ef2a4 | 2019-12-19 11:19:25 +0000 | [diff] [blame] | 21 | /* TODO: Fix alignment such that `cpu` structs are in different cache lines. */ |
Karl Meakin | 2ad6b66 | 2024-07-29 20:45:40 +0100 | [diff] [blame] | 22 | /* NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding) */ |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 23 | struct cpu { |
Andrew Walbran | c3910f7 | 2018-11-27 14:24:36 +0000 | [diff] [blame] | 24 | /** CPU identifier. Doesn't have to be contiguous. */ |
Andrew Walbran | 4d3fa28 | 2019-06-26 13:31:15 +0100 | [diff] [blame] | 25 | cpu_id_t id; |
Andrew Scull | 020ae69 | 2018-07-19 16:20:14 +0100 | [diff] [blame] | 26 | |
Andrew Walbran | c3910f7 | 2018-11-27 14:24:36 +0000 | [diff] [blame] | 27 | /** Pointer to bottom of the stack. */ |
Andrew Scull | 020ae69 | 2018-07-19 16:20:14 +0100 | [diff] [blame] | 28 | void *stack_bottom; |
| 29 | |
Andrew Walbran | 0d7a068 | 2018-12-06 16:48:47 +0000 | [diff] [blame] | 30 | /** See api.c for the partial ordering on locks. */ |
Andrew Scull | 020ae69 | 2018-07-19 16:20:14 +0100 | [diff] [blame] | 31 | struct spinlock lock; |
| 32 | |
Fuad Tabba | b0ef2a4 | 2019-12-19 11:19:25 +0000 | [diff] [blame] | 33 | /** Determines whether the CPU is currently on. */ |
Wedson Almeida Filho | 8700964 | 2018-07-02 10:20:07 +0100 | [diff] [blame] | 34 | bool is_on; |
J-Alves | ea8ccfe | 2024-10-09 11:47:24 +0100 | [diff] [blame] | 35 | |
| 36 | /* In case there is a pending SRI for the NWd. */ |
| 37 | bool is_sri_delayed; |
Daniel Boulby | f3cf28c | 2024-08-22 10:46:23 +0100 | [diff] [blame] | 38 | |
Madhukar Pappireddy | eed861e | 2024-09-25 13:50:54 -0500 | [diff] [blame] | 39 | /** |
| 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 Boulby | 7011b5a | 2024-10-15 18:27:26 +0100 | [diff] [blame] | 44 | |
| 45 | /* Head of the list of vcpus with pending IPIs. */ |
| 46 | struct list_entry pending_ipis; |
Madhukar Pappireddy | 44b85ff | 2024-11-25 10:29:22 -0600 | [diff] [blame] | 47 | |
| 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 Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 53 | }; |
| 54 | |
Andrew Walbran | 4d3fa28 | 2019-06-26 13:31:15 +0100 | [diff] [blame] | 55 | void cpu_module_init(const cpu_id_t *cpu_ids, size_t count); |
Wedson Almeida Filho | 3fcbcff | 2018-07-10 23:53:39 +0100 | [diff] [blame] | 56 | |
Wedson Almeida Filho | 3fcbcff | 2018-07-10 23:53:39 +0100 | [diff] [blame] | 57 | size_t cpu_index(struct cpu *c); |
Olivier Deprez | 7d5e553 | 2020-09-22 15:06:58 +0200 | [diff] [blame] | 58 | struct cpu *cpu_find_index(size_t index); |
Olivier Deprez | 70f8a4a | 2022-09-26 09:17:56 +0200 | [diff] [blame] | 59 | bool cpu_on(struct cpu *c); |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 60 | void cpu_off(struct cpu *c); |
Andrew Walbran | 4d3fa28 | 2019-06-26 13:31:15 +0100 | [diff] [blame] | 61 | struct cpu *cpu_find(cpu_id_t id); |
Mahesh Bireddy | 8ca5786 | 2020-01-07 13:43:21 +0530 | [diff] [blame] | 62 | uint8_t *cpu_get_buffer(struct cpu *c); |
| 63 | uint32_t cpu_get_buffer_size(struct cpu *c); |
Olivier Deprez | 64b421e | 2022-10-06 10:28:20 +0200 | [diff] [blame] | 64 | |
| 65 | #endif |