blob: 8896b77d0b033e37f7ede868e82949898a637a7a [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;
Andrew Scullc960c032018-10-24 15:13:35 +010027 struct vm *vm;
Wedson Almeida Filho87009642018-07-02 10:20:07 +010028
Andrew Walbran42347a92019-05-09 13:59:03 +010029 vcpu = vm_get_vcpu(vm_find(HF_PRIMARY_VM_ID), cpu_index(c));
Andrew Scullc960c032018-10-24 15:13:35 +010030 vm = vcpu->vm;
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +010031 vcpu->cpu = c;
Andrew Scullc960c032018-10-24 15:13:35 +010032
Fuad Tabbac8eede32019-10-31 11:17:50 +000033 arch_cpu_init();
34
Andrew Scullc960c032018-10-24 15:13:35 +010035 /* Reset the registers to give a clean start for the primary's vCPU. */
Andrew Scullbb3ab6c2018-11-26 20:38:49 +000036 arch_regs_reset(&vcpu->regs, true, vm->id, c->id, vm->ptable.root);
Andrew Scullc960c032018-10-24 15:13:35 +010037
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +010038 return vcpu;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010039}