blob: 74d61c10000ec918b9434b2fe5d66830b3f7dc30 [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
13#if !defined(__ASSEMBLER__)
14
Andrew Scull18c78fc2018-08-20 12:57:41 +010015#include "hf/arch/cpu.h"
16
Fuad Tabbab0ef2a42019-12-19 11:19:25 +000017/* TODO: Fix alignment such that `cpu` structs are in different cache lines. */
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010018struct cpu {
Andrew Walbranc3910f72018-11-27 14:24:36 +000019 /** CPU identifier. Doesn't have to be contiguous. */
Andrew Walbran4d3fa282019-06-26 13:31:15 +010020 cpu_id_t id;
Andrew Scull020ae692018-07-19 16:20:14 +010021
Andrew Walbranc3910f72018-11-27 14:24:36 +000022 /** Pointer to bottom of the stack. */
Andrew Scull020ae692018-07-19 16:20:14 +010023 void *stack_bottom;
24
Andrew Walbran0d7a0682018-12-06 16:48:47 +000025 /** See api.c for the partial ordering on locks. */
Andrew Scull020ae692018-07-19 16:20:14 +010026 struct spinlock lock;
27
Fuad Tabbab0ef2a42019-12-19 11:19:25 +000028 /** Determines whether the CPU is currently on. */
Wedson Almeida Filho87009642018-07-02 10:20:07 +010029 bool is_on;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010030};
31
Andrew Walbran4d3fa282019-06-26 13:31:15 +010032void cpu_module_init(const cpu_id_t *cpu_ids, size_t count);
Wedson Almeida Filho3fcbcff2018-07-10 23:53:39 +010033
Wedson Almeida Filho3fcbcff2018-07-10 23:53:39 +010034size_t cpu_index(struct cpu *c);
Olivier Deprez7d5e5532020-09-22 15:06:58 +020035struct cpu *cpu_find_index(size_t index);
Andrew Scull37402872018-10-24 14:23:06 +010036bool cpu_on(struct cpu *c, ipaddr_t entry, uintreg_t arg);
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010037void cpu_off(struct cpu *c);
Andrew Walbran4d3fa282019-06-26 13:31:15 +010038struct cpu *cpu_find(cpu_id_t id);
Mahesh Bireddy8ca57862020-01-07 13:43:21 +053039uint8_t *cpu_get_buffer(struct cpu *c);
40uint32_t cpu_get_buffer_size(struct cpu *c);
Olivier Deprez64b421e2022-10-06 10:28:20 +020041
42#endif