blob: b12032e531535e2f9d8c7dd8c442219d5eb92b39 [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 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Andrew Scull18c78fc2018-08-20 12:57:41 +010017#include "hf/cpu.h"
Andrew Scull18c78fc2018-08-20 12:57:41 +010018#include "hf/vm.h"
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010019
Wedson Almeida Filhofed69022018-07-11 15:39:12 +010020/**
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010021 * The entry point of CPUs when they are turned on. It is supposed to initialise
Wedson Almeida Filho87009642018-07-02 10:20:07 +010022 * all state and return the first vCPU to run.
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010023 */
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +010024struct vcpu *cpu_main(struct cpu *c)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010025{
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +010026 struct vcpu *vcpu;
Wedson Almeida Filho87009642018-07-02 10:20:07 +010027
Andrew Walbran42347a92019-05-09 13:59:03 +010028 vcpu = vm_get_vcpu(vm_find(HF_PRIMARY_VM_ID), cpu_index(c));
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +010029 vcpu->cpu = c;
Andrew Scullc960c032018-10-24 15:13:35 +010030
Fuad Tabbac8eede32019-10-31 11:17:50 +000031 arch_cpu_init();
32
Andrew Scullc960c032018-10-24 15:13:35 +010033 /* Reset the registers to give a clean start for the primary's vCPU. */
Fuad Tabba5c738432019-12-02 11:02:42 +000034 arch_regs_reset(vcpu);
Andrew Scullc960c032018-10-24 15:13:35 +010035
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +010036 return vcpu;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010037}