blob: 239ca7aebef00aa4ac0a48f8d386380c156c4afc [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-Alves13394022021-06-30 13:48:49 +010039 /* Initialize SRI for running core. */
40 plat_ffa_sri_init(c);
41
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +010042 return vcpu;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010043}