blob: 45624e588d828c10d4bf95e5752b1ee5b9e59642 [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
J-Alves13394022021-06-30 13:48:49 +01009#include "hf/arch/plat/ffa.h"
10
Andrew Scull18c78fc2018-08-20 12:57:41 +010011#include "hf/cpu.h"
J-Alves13394022021-06-30 13:48:49 +010012#include "hf/dlog.h"
Andrew Scull18c78fc2018-08-20 12:57:41 +010013#include "hf/vm.h"
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010014
J-Alves13394022021-06-30 13:48:49 +010015#include "vmapi/hf/ffa.h"
16
Wedson Almeida Filhofed69022018-07-11 15:39:12 +010017/**
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010018 * The entry point of CPUs when they are turned on. It is supposed to initialise
Wedson Almeida Filho87009642018-07-02 10:20:07 +010019 * all state and return the first vCPU to run.
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010020 */
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +010021struct vcpu *cpu_main(struct cpu *c)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010022{
Olivier Deprezb9adff42021-02-01 12:14:05 +010023 struct vm *first_boot;
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +010024 struct vcpu *vcpu;
Olivier Deprezb9adff42021-02-01 12:14:05 +010025
26 /*
27 * This returns the PVM in the normal world and the first
28 * booted Secure Partition in the secure world.
29 */
30 first_boot = vm_get_first_boot();
Wedson Almeida Filho87009642018-07-02 10:20:07 +010031
J-Alvesb37fd082020-10-22 12:29:21 +010032 vcpu = vm_get_vcpu(first_boot, cpu_index(c));
J-Alvesb37fd082020-10-22 12:29:21 +010033
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +010034 vcpu->cpu = c;
Andrew Scullc960c032018-10-24 15:13:35 +010035
J-Alvesb37fd082020-10-22 12:29:21 +010036 /* Reset the registers to give a clean start for vCPU. */
Olivier Depreze6f7b9d2021-02-01 11:55:48 +010037 vcpu_reset(vcpu);
Andrew Scullc960c032018-10-24 15:13:35 +010038
J-Alves7ac49052022-02-08 17:20:53 +000039 /* Set the designated GP with the physical core index. */
40 vcpu_set_phys_core_idx(vcpu);
41
J-Alves13394022021-06-30 13:48:49 +010042 /* Initialize SRI for running core. */
43 plat_ffa_sri_init(c);
44
J-Alves7e67d102022-04-13 13:22:39 +010045 vm_set_boot_info_gp_reg(first_boot, vcpu);
46
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +010047 return vcpu;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010048}