blob: 408a2d128de0e966fcfeedb6070a975468a6029b [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 Scull18c78fc2018-08-20 12:57:41 +01009#include "hf/cpu.h"
Andrew Scull18c78fc2018-08-20 12:57:41 +010010#include "hf/vm.h"
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010011
Wedson Almeida Filhofed69022018-07-11 15:39:12 +010012/**
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010013 * The entry point of CPUs when they are turned on. It is supposed to initialise
Wedson Almeida Filho87009642018-07-02 10:20:07 +010014 * all state and return the first vCPU to run.
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010015 */
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +010016struct vcpu *cpu_main(struct cpu *c)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010017{
Olivier Deprezb9adff42021-02-01 12:14:05 +010018 struct vm *first_boot;
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +010019 struct vcpu *vcpu;
Olivier Deprezb9adff42021-02-01 12:14:05 +010020
21 /*
22 * This returns the PVM in the normal world and the first
23 * booted Secure Partition in the secure world.
24 */
25 first_boot = vm_get_first_boot();
Wedson Almeida Filho87009642018-07-02 10:20:07 +010026
J-Alvesb37fd082020-10-22 12:29:21 +010027 vcpu = vm_get_vcpu(first_boot, cpu_index(c));
J-Alvesb37fd082020-10-22 12:29:21 +010028
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +010029 vcpu->cpu = c;
Andrew Scullc960c032018-10-24 15:13:35 +010030
J-Alvesb37fd082020-10-22 12:29:21 +010031 /* Reset the registers to give a clean start for vCPU. */
Olivier Depreze6f7b9d2021-02-01 11:55:48 +010032 vcpu_reset(vcpu);
Andrew Scullc960c032018-10-24 15:13:35 +010033
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +010034 return vcpu;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010035}