--- /dev/null
+/*
+ * xen/arch/arm/platform.c
+ *
+ * Helpers to execute platform specific code.
+ *
+ * Julien Grall <julien.grall@linaro.org>
+ * Copyright (C) 2013 Linaro Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <asm/platform.h>
+#include <xen/device_tree.h>
+#include <xen/init.h>
+
+extern const struct platform_desc _splatform[], _eplatform[];
+
+/* Pointer to the current platform description */
+static const struct platform_desc *platform;
+
+
+static bool_t __init platform_is_compatible(const struct platform_desc *plat)
+{
+ const char *const *compat;
+
+ if ( !plat->compatible )
+ return 0;
+
+ for ( compat = plat->compatible; *compat; compat++ )
+ {
+ if ( dt_machine_is_compatible(*compat) )
+ return 1;
+ }
+
+ return 0;
+}
+
+/* List of possible platform */
+static void dump_platform_table(void)
+{
+ const struct platform_desc *p;
+
+ printk("Available platform support:\n");
+
+ for ( p = _splatform; p != _eplatform; p++ )
+ printk(" - %s\n", p->name);
+}
+
+int __init platform_init(void)
+{
+ int res = 0;
+
+ ASSERT(platform == NULL);
+
+ /* Looking for the platform description */
+ for ( platform = _splatform; platform != _eplatform; platform++ )
+ {
+ if ( platform_is_compatible(platform) )
+ break;
+ }
+
+ /* We don't have specific operations for this platform */
+ if ( platform == _eplatform )
+ {
+ /* TODO: dump DT machine compatible node */
+ printk(XENLOG_WARNING "WARNING: Unrecognized/unsupported device tree "
+ "compatible list\n");
+ dump_platform_table();
+ platform = NULL;
+ }
+ else
+ printk(XENLOG_INFO "Platform: %s\n", platform->name);
+
+ if ( platform && platform->init )
+ res = platform->init();
+
+ return res;
+}
+
+int __init platform_init_time(void)
+{
+ int res = 0;
+
+ if ( platform && platform->init_time )
+ res = platform->init_time();
+
+ return res;
+}
+
+int __init platform_specific_mapping(struct domain *d)
+{
+ int res = 0;
+
+ if ( platform && platform->specific_mapping )
+ res = platform->specific_mapping(d);
+
+ return res;
+}
+
+void platform_reset(void)
+{
+ if ( platform && platform->reset )
+ platform->reset();
+}
+
+void platform_poweroff(void)
+{
+ if ( platform && platform->poweroff )
+ platform->poweroff();
+}
+
+bool_t platform_has_quirk(uint32_t quirk)
+{
+ uint32_t quirks = 0;
+
+ if ( platform && platform->quirks )
+ quirks = platform->quirks();
+
+ return !!(quirks & quirk);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
#include <asm/time.h>
#include <asm/gic.h>
#include <asm/cpufeature.h>
+#include <asm/platform.h>
/*
* Unfortunately the hypervisor timer interrupt appears to be buggy in
timer_irq[TIMER_HYP_PPI].irq,
timer_irq[TIMER_VIRT_PPI].irq);
+ res = platform_init_time();
+ if ( res )
+ return res;
+
/* Check that this CPU supports the Generic Timer interface */
if ( !cpu_has_gentimer )
panic("CPU does not support the Generic Timer v1 interface.\n");
cpu_khz = READ_SYSREG32(CNTFRQ_EL0) / 1000;
+
boot_count = READ_SYSREG64(CNTPCT_EL0);
printk("Using generic timer at %lu KHz\n", cpu_khz);
--- /dev/null
+#ifndef __ASM_ARM_PLATFORM_H
+#define __ASM_ARM_PLATFORM_H
+
+#include <xen/init.h>
+#include <xen/sched.h>
+#include <xen/mm.h>
+
+/* Describe specific operation for a board */
+struct platform_desc {
+ /* Platform name */
+ const char *name;
+ /* Array of device tree 'compatible' strings */
+ const char *const *compatible;
+ /* Platform initialization */
+ int (*init)(void);
+ int (*init_time)(void);
+ /* Specific mapping for dom0 */
+ int (*specific_mapping)(struct domain *d);
+ /* Platform reset */
+ void (*reset)(void);
+ /* Platform power-off */
+ void (*poweroff)(void);
+ /*
+ * Platform quirks
+ * Defined has a function because a platform can support multiple
+ * board with different quirk on each
+ */
+ uint32_t (*quirks)(void);
+};
+
+int __init platform_init(void);
+int __init platform_init_time(void);
+int __init platform_specific_mapping(struct domain *d);
+void platform_reset(void);
+void platform_poweroff(void);
+bool_t platform_has_quirk(uint32_t quirk);
+
+#define PLATFORM_START(_name, _namestr) \
+static const struct platform_desc __plat_desc_##_name __used \
+__attribute__((__section__(".arch.info"))) = { \
+ .name = _namestr,
+
+#define PLATFORM_END \
+};
+
+#endif /* __ASM_ARM_PLATFORM_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */