blob: af7391ff1fd2090cab2b8c4b637698ab132dbc85 [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 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Andrew Scullfbc938a2018-08-20 14:09:28 +010017#pragma once
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010018
Andrew Scull18c78fc2018-08-20 12:57:41 +010019#include "hf/arch/cpu.h"
20
Fuad Tabbab0ef2a42019-12-19 11:19:25 +000021/* TODO: Fix alignment such that `cpu` structs are in different cache lines. */
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010022struct cpu {
Andrew Walbranc3910f72018-11-27 14:24:36 +000023 /** CPU identifier. Doesn't have to be contiguous. */
Andrew Walbran4d3fa282019-06-26 13:31:15 +010024 cpu_id_t id;
Andrew Scull020ae692018-07-19 16:20:14 +010025
Andrew Walbranc3910f72018-11-27 14:24:36 +000026 /** Pointer to bottom of the stack. */
Andrew Scull020ae692018-07-19 16:20:14 +010027 void *stack_bottom;
28
Andrew Walbran0d7a0682018-12-06 16:48:47 +000029 /** See api.c for the partial ordering on locks. */
Andrew Scull020ae692018-07-19 16:20:14 +010030 struct spinlock lock;
31
Fuad Tabbab0ef2a42019-12-19 11:19:25 +000032 /** Determines whether the CPU is currently on. */
Wedson Almeida Filho87009642018-07-02 10:20:07 +010033 bool is_on;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010034};
35
Andrew Walbran4d3fa282019-06-26 13:31:15 +010036void cpu_module_init(const cpu_id_t *cpu_ids, size_t count);
Wedson Almeida Filho3fcbcff2018-07-10 23:53:39 +010037
Wedson Almeida Filho3fcbcff2018-07-10 23:53:39 +010038size_t cpu_index(struct cpu *c);
Andrew Scull37402872018-10-24 14:23:06 +010039bool cpu_on(struct cpu *c, ipaddr_t entry, uintreg_t arg);
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010040void cpu_off(struct cpu *c);
Andrew Walbran4d3fa282019-06-26 13:31:15 +010041struct cpu *cpu_find(cpu_id_t id);
Jose Marinho20713fa2019-08-07 15:42:07 +010042uint8_t *cpu_get_buffer(cpu_id_t cpu_id);
43uint32_t cpu_get_buffer_size(cpu_id_t cpu_id);