blob: f862e929404b25723b46aba8d9ca7ae0ccfece7e [file] [log] [blame]
Andrew Scull11a4a0c2018-12-29 11:38:31 +00001/*
Andrew Walbran692b3252019-03-07 15:51:31 +00002 * Copyright 2018 The Hafnium Authors.
Andrew Scull11a4a0c2018-12-29 11:38:31 +00003 *
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 Scull11a4a0c2018-12-29 11:38:31 +00007 */
8
9#pragma once
10
Andrew Scull11a4a0c2018-12-29 11:38:31 +000011#include <stddef.h>
12#include <stdint.h>
13
Andrew Scullacc1fdd2019-01-04 13:55:14 +000014#include "hf/arch/types.h"
15
Andrew Scull11a4a0c2018-12-29 11:38:31 +000016#include "hf/addr.h"
Fuad Tabba5c738432019-12-02 11:02:42 +000017#include "hf/vcpu.h"
Andrew Scull11a4a0c2018-12-29 11:38:31 +000018
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010019#include "vmapi/hf/ffa.h"
Andrew Walbran95534922019-06-19 11:32:54 +010020
Andrew Scull11a4a0c2018-12-29 11:38:31 +000021/**
Andrew Scullc960c032018-10-24 15:13:35 +010022 * Reset the register values other than the PC and argument which are set with
23 * `arch_regs_set_pc_arg()`.
Andrew Scull11a4a0c2018-12-29 11:38:31 +000024 */
Fuad Tabba5c738432019-12-02 11:02:42 +000025void arch_regs_reset(struct vcpu *vcpu);
Andrew Scull11a4a0c2018-12-29 11:38:31 +000026
27/**
Fuad Tabbaed294af2019-12-20 10:43:01 +000028 * Updates the given registers so that when a vCPU runs, it starts off at the
Andrew Scull11a4a0c2018-12-29 11:38:31 +000029 * given address (pc) with the given argument.
30 *
31 * This function must only be called on an arch_regs that is known not be in use
32 * by any other physical CPU.
33 */
34void arch_regs_set_pc_arg(struct arch_regs *r, ipaddr_t pc, uintreg_t arg);
35
36/**
J-Alvesb7800a12022-01-25 17:55:53 +000037 * Verifies the `gp_reg_num` complies with the number of registers available in
38 * the architecture.
39 */
Karl Meakin2ad6b662024-07-29 20:45:40 +010040bool arch_regs_reg_num_valid(uint32_t gp_reg_num);
J-Alvesb7800a12022-01-25 17:55:53 +000041
42/**
43 * Sets the value of a general purpose register.
44 */
45void arch_regs_set_gp_reg(struct arch_regs *r, uintreg_t value,
Karl Meakin2ad6b662024-07-29 20:45:40 +010046 uint32_t gp_reg_num);
J-Alvesb7800a12022-01-25 17:55:53 +000047
48/**
Andrew Scull11a4a0c2018-12-29 11:38:31 +000049 * Updates the register holding the return value of a function.
50 *
51 * This function must only be called on an arch_regs that is known not be in use
52 * by any other physical CPU.
53 */
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010054void arch_regs_set_retval(struct arch_regs *r, struct ffa_value v);
Fuad Tabbac8eede32019-10-31 11:17:50 +000055
56/**
Andrew Walbrand8d3f5d2020-10-07 18:23:01 +010057 * Extracts SMC or HVC arguments from the registers of a vCPU.
58 *
59 * This function must only be called on an arch_regs that is known not be in use
60 * by any other physical CPU.
61 */
62struct ffa_value arch_regs_get_args(struct arch_regs *regs);
63
64/**
Fuad Tabbac8eede32019-10-31 11:17:50 +000065 * Initialize and reset CPU-wide register values.
66 */
Olivier Deprez148b5602022-03-16 17:13:06 +010067void arch_cpu_init(struct cpu *c);
68
69struct vcpu *arch_vcpu_resume(struct cpu *c);
Madhukar Pappireddy5f4bcbf2023-08-08 14:37:55 -050070
71uint32_t arch_affinity_to_core_pos(uint64_t reg);
72
73uint32_t arch_find_core_pos(void);