blob: c66e5a4f9c89c7126350b587067434c84513c83e [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
Andrew Scull18c78fc2018-08-20 12:57:41 +010011#include "hf/arch/cpu.h"
12
Fuad Tabbab0ef2a42019-12-19 11:19:25 +000013/* TODO: Fix alignment such that `cpu` structs are in different cache lines. */
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010014struct cpu {
Andrew Walbranc3910f72018-11-27 14:24:36 +000015 /** CPU identifier. Doesn't have to be contiguous. */
Andrew Walbran4d3fa282019-06-26 13:31:15 +010016 cpu_id_t id;
Andrew Scull020ae692018-07-19 16:20:14 +010017
Andrew Walbranc3910f72018-11-27 14:24:36 +000018 /** Pointer to bottom of the stack. */
Andrew Scull020ae692018-07-19 16:20:14 +010019 void *stack_bottom;
20
Andrew Walbran0d7a0682018-12-06 16:48:47 +000021 /** See api.c for the partial ordering on locks. */
Andrew Scull020ae692018-07-19 16:20:14 +010022 struct spinlock lock;
23
Fuad Tabbab0ef2a42019-12-19 11:19:25 +000024 /** Determines whether the CPU is currently on. */
Wedson Almeida Filho87009642018-07-02 10:20:07 +010025 bool is_on;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010026};
27
Andrew Walbran4d3fa282019-06-26 13:31:15 +010028void cpu_module_init(const cpu_id_t *cpu_ids, size_t count);
Wedson Almeida Filho3fcbcff2018-07-10 23:53:39 +010029
Wedson Almeida Filho3fcbcff2018-07-10 23:53:39 +010030size_t cpu_index(struct cpu *c);
Andrew Scull37402872018-10-24 14:23:06 +010031bool cpu_on(struct cpu *c, ipaddr_t entry, uintreg_t arg);
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010032void cpu_off(struct cpu *c);
Andrew Walbran4d3fa282019-06-26 13:31:15 +010033struct cpu *cpu_find(cpu_id_t id);
Mahesh Bireddy8ca57862020-01-07 13:43:21 +053034uint8_t *cpu_get_buffer(struct cpu *c);
35uint32_t cpu_get_buffer_size(struct cpu *c);