]> rtime.felk.cvut.cz Git - jailhouse.git/blob - hypervisor/arch/arm/setup.c
arm: better error reporting and panic dump
[jailhouse.git] / hypervisor / arch / arm / setup.c
1 /*
2  * Jailhouse, a Linux-based partitioning hypervisor
3  *
4  * Copyright (c) Siemens AG, 2013
5  *
6  * Authors:
7  *  Jan Kiszka <jan.kiszka@siemens.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.  See
10  * the COPYING file in the top-level directory.
11  */
12
13 #include <asm/control.h>
14 #include <asm/irqchip.h>
15 #include <asm/percpu.h>
16 #include <asm/platform.h>
17 #include <asm/setup.h>
18 #include <asm/sysregs.h>
19 #include <jailhouse/control.h>
20 #include <jailhouse/entry.h>
21 #include <jailhouse/paging.h>
22 #include <jailhouse/string.h>
23
24 unsigned int cache_line_size;
25
26 static int arch_check_features(void)
27 {
28         u32 pfr1;
29         u32 ctr;
30
31         arm_read_sysreg(ID_PFR1_EL1, pfr1);
32
33         if (!PFR1_VIRT(pfr1))
34                 return -ENODEV;
35
36         arm_read_sysreg(CTR_EL0, ctr);
37         /* Extract the minimal cache line size */
38         cache_line_size = 4 << (ctr >> 16 & 0xf);
39
40         return 0;
41 }
42
43 int arch_init_early(void)
44 {
45         int err = 0;
46
47         if ((err = arch_check_features()) != 0)
48                 return err;
49
50         err = arch_mmu_cell_init(&root_cell);
51         if (err)
52                 return err;
53
54         err = arch_map_device(UART_BASE_PHYS, UART_BASE_VIRT, PAGE_SIZE);
55
56         return err;
57 }
58
59 int arch_cpu_init(struct per_cpu *cpu_data)
60 {
61         int err = 0;
62         unsigned long hcr = HCR_VM_BIT | HCR_IMO_BIT | HCR_FMO_BIT;
63
64         cpu_data->psci_mbox.entry = 0;
65
66         /*
67          * Copy the registers to restore from the linux stack here, because we
68          * won't be able to access it later
69          */
70         memcpy(&cpu_data->linux_reg, (void *)cpu_data->linux_sp, NUM_ENTRY_REGS
71                         * sizeof(unsigned long));
72
73         err = switch_exception_level(cpu_data);
74         if (err)
75                 return err;
76
77         /*
78          * Save pointer in the thread local storage
79          * Must be done early in order to handle aborts and errors in the setup
80          * code.
81          */
82         arm_write_sysreg(TPIDR_EL2, cpu_data);
83
84         /* Setup guest traps */
85         arm_write_sysreg(HCR, hcr);
86
87         err = arch_spin_init();
88         if (err)
89                 return err;
90
91         err = arch_mmu_cpu_cell_init(cpu_data);
92         if (err)
93                 return err;
94
95         err = irqchip_init();
96         if (err)
97                 return err;
98
99         err = irqchip_cpu_init(cpu_data);
100
101         return err;
102 }
103
104 int arch_init_late(void)
105 {
106         return map_root_memory_regions();
107 }
108
109 void arch_cpu_activate_vmm(struct per_cpu *cpu_data)
110 {
111         /* Return to the kernel */
112         cpu_return_el1(cpu_data);
113
114         while (1);
115 }
116
117 void arch_cpu_restore(struct per_cpu *cpu_data)
118 {
119 }
120
121 // catch missing symbols
122 void arch_shutdown_cpu(unsigned int cpu_id) {}
123 void arch_shutdown(void) {}