blob: 8a495dbad028075ee97ad69616319efadbc442d8 [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{
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +010018 struct vcpu *vcpu;
Wedson Almeida Filho87009642018-07-02 10:20:07 +010019
Andrew Walbran42347a92019-05-09 13:59:03 +010020 vcpu = vm_get_vcpu(vm_find(HF_PRIMARY_VM_ID), cpu_index(c));
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +010021 vcpu->cpu = c;
Andrew Scullc960c032018-10-24 15:13:35 +010022
Fuad Tabbac8eede32019-10-31 11:17:50 +000023 arch_cpu_init();
24
Andrew Scullc960c032018-10-24 15:13:35 +010025 /* Reset the registers to give a clean start for the primary's vCPU. */
Fuad Tabba5c738432019-12-02 11:02:42 +000026 arch_regs_reset(vcpu);
Andrew Scullc960c032018-10-24 15:13:35 +010027
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +010028 return vcpu;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010029}