Skip to content

Commit 9b08aaa

Browse files
Shannon ZhaoDavid Vrabel
authored andcommitted
ARM: XEN: Move xen_early_init() before efi_init()
Move xen_early_init() before efi_init(), then when calling efi_init() could initialize Xen specific UEFI. Check if it runs on Xen hypervisor through the flat dts. Cc: Russell King <linux@arm.linux.org.uk> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org> Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Reviewed-by: Julien Grall <julien.grall@arm.com> Tested-by: Julien Grall <julien.grall@arm.com> Acked-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent d22cbe6 commit 9b08aaa

3 files changed

Lines changed: 43 additions & 18 deletions

File tree

‎arch/arm/kernel/setup.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,7 @@ void __init setup_arch(char **cmdline_p)
10641064
early_paging_init(mdesc);
10651065
#endif
10661066
setup_dma_zone(mdesc);
1067+
xen_early_init();
10671068
efi_init();
10681069
sanity_check_meminfo();
10691070
arm_memblock_init(mdesc);
@@ -1080,7 +1081,6 @@ void __init setup_arch(char **cmdline_p)
10801081

10811082
arm_dt_init_cpu_maps();
10821083
psci_dt_init();
1083-
xen_early_init();
10841084
#ifdef CONFIG_SMP
10851085
if (is_smp()) {
10861086
if (!mdesc->smp_init || !mdesc->smp_init()) {

‎arch/arm/xen/enlighten.c‎

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/irqreturn.h>
2121
#include <linux/module.h>
2222
#include <linux/of.h>
23+
#include <linux/of_fdt.h>
2324
#include <linux/of_irq.h>
2425
#include <linux/of_address.h>
2526
#include <linux/cpuidle.h>
@@ -53,8 +54,6 @@ struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata;
5354

5455
static __read_mostly unsigned int xen_events_irq;
5556

56-
static __initdata struct device_node *xen_node;
57-
5857
int xen_remap_domain_gfn_array(struct vm_area_struct *vma,
5958
unsigned long addr,
6059
xen_pfn_t *gfn, int nr,
@@ -238,33 +237,52 @@ static irqreturn_t xen_arm_callback(int irq, void *arg)
238237
return IRQ_HANDLED;
239238
}
240239

240+
static __initdata struct {
241+
const char *compat;
242+
const char *prefix;
243+
const char *version;
244+
bool found;
245+
} hyper_node = {"xen,xen", "xen,xen-", NULL, false};
246+
247+
static int __init fdt_find_hyper_node(unsigned long node, const char *uname,
248+
int depth, void *data)
249+
{
250+
const void *s = NULL;
251+
int len;
252+
253+
if (depth != 1 || strcmp(uname, "hypervisor") != 0)
254+
return 0;
255+
256+
if (of_flat_dt_is_compatible(node, hyper_node.compat))
257+
hyper_node.found = true;
258+
259+
s = of_get_flat_dt_prop(node, "compatible", &len);
260+
if (strlen(hyper_node.prefix) + 3 < len &&
261+
!strncmp(hyper_node.prefix, s, strlen(hyper_node.prefix)))
262+
hyper_node.version = s + strlen(hyper_node.prefix);
263+
264+
return 0;
265+
}
266+
241267
/*
242268
* see Documentation/devicetree/bindings/arm/xen.txt for the
243269
* documentation of the Xen Device Tree format.
244270
*/
245271
#define GRANT_TABLE_PHYSADDR 0
246272
void __init xen_early_init(void)
247273
{
248-
int len;
249-
const char *s = NULL;
250-
const char *version = NULL;
251-
const char *xen_prefix = "xen,xen-";
252-
253-
xen_node = of_find_compatible_node(NULL, NULL, "xen,xen");
254-
if (!xen_node) {
274+
of_scan_flat_dt(fdt_find_hyper_node, NULL);
275+
if (!hyper_node.found) {
255276
pr_debug("No Xen support\n");
256277
return;
257278
}
258-
s = of_get_property(xen_node, "compatible", &len);
259-
if (strlen(xen_prefix) + 3 < len &&
260-
!strncmp(xen_prefix, s, strlen(xen_prefix)))
261-
version = s + strlen(xen_prefix);
262-
if (version == NULL) {
279+
280+
if (hyper_node.version == NULL) {
263281
pr_debug("Xen version not found\n");
264282
return;
265283
}
266284

267-
pr_info("Xen %s support found\n", version);
285+
pr_info("Xen %s support found\n", hyper_node.version);
268286

269287
xen_domain_type = XEN_HVM_DOMAIN;
270288

@@ -305,6 +323,14 @@ static void __init xen_acpi_guest_init(void)
305323

306324
static void __init xen_dt_guest_init(void)
307325
{
326+
struct device_node *xen_node;
327+
328+
xen_node = of_find_compatible_node(NULL, NULL, "xen,xen");
329+
if (!xen_node) {
330+
pr_err("Xen support was detected before, but it has disappeared\n");
331+
return;
332+
}
333+
308334
xen_events_irq = irq_of_parse_and_map(xen_node, 0);
309335
}
310336

‎arch/arm64/kernel/setup.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ void __init setup_arch(char **cmdline_p)
257257
*/
258258
cpu_uninstall_idmap();
259259

260+
xen_early_init();
260261
efi_init();
261262
arm64_memblock_init();
262263

@@ -281,8 +282,6 @@ void __init setup_arch(char **cmdline_p)
281282
else
282283
psci_acpi_init();
283284

284-
xen_early_init();
285-
286285
cpu_read_bootcpu_ops();
287286
smp_init_cpus();
288287
smp_build_mpidr_hash();

0 commit comments

Comments
 (0)