blob: 66cbaddde32312ffeb84452ac0287cc4716d5e09 [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
Fuad Tabbab0ef2a42019-12-19 11:19:25 +000019/* TODO: Fix alignment such that `cpu` structs are in different cache lines. */
Karl Meakin2ad6b662024-07-29 20:45:40 +010020/* NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding) */
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010021struct cpu {
Andrew Walbranc3910f72018-11-27 14:24:36 +000022 /** CPU identifier. Doesn't have to be contiguous. */
Andrew Walbran4d3fa282019-06-26 13:31:15 +010023 cpu_id_t id;
Andrew Scull020ae692018-07-19 16:20:14 +010024
Andrew Walbranc3910f72018-11-27 14:24:36 +000025 /** Pointer to bottom of the stack. */
Andrew Scull020ae692018-07-19 16:20:14 +010026 void *stack_bottom;
27
Andrew Walbran0d7a0682018-12-06 16:48:47 +000028 /** See api.c for the partial ordering on locks. */
Andrew Scull020ae692018-07-19 16:20:14 +010029 struct spinlock lock;
30
Fuad Tabbab0ef2a42019-12-19 11:19:25 +000031 /** Determines whether the CPU is currently on. */
Wedson Almeida Filho87009642018-07-02 10:20:07 +010032 bool is_on;
J-Alvesea8ccfe2024-10-09 11:47:24 +010033
34 /* In case there is a pending SRI for the NWd. */
35 bool is_sri_delayed;
Daniel Boulbyf3cf28c2024-08-22 10:46:23 +010036
37 /* Track pending IPIs. */
38 struct vcpu *ipi_target_vcpu;
Madhukar Pappireddyeed861e2024-09-25 13:50:54 -050039
40 /**
41 * A list of entries associated with vCPUs having pending timer
42 * deadline.
43 */
44 struct timer_pending_vcpu_list pending_timer_vcpus_list;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010045};
46
Andrew Walbran4d3fa282019-06-26 13:31:15 +010047void cpu_module_init(const cpu_id_t *cpu_ids, size_t count);
Wedson Almeida Filho3fcbcff2018-07-10 23:53:39 +010048
Wedson Almeida Filho3fcbcff2018-07-10 23:53:39 +010049size_t cpu_index(struct cpu *c);
Olivier Deprez7d5e5532020-09-22 15:06:58 +020050struct cpu *cpu_find_index(size_t index);
Olivier Deprez70f8a4a2022-09-26 09:17:56 +020051bool cpu_on(struct cpu *c);
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010052void cpu_off(struct cpu *c);
Andrew Walbran4d3fa282019-06-26 13:31:15 +010053struct cpu *cpu_find(cpu_id_t id);
Mahesh Bireddy8ca57862020-01-07 13:43:21 +053054uint8_t *cpu_get_buffer(struct cpu *c);
55uint32_t cpu_get_buffer_size(struct cpu *c);
Olivier Deprez64b421e2022-10-06 10:28:20 +020056
57#endif