From patchwork Fri May 10 15:12:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 16866 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f197.google.com (mail-vc0-f197.google.com [209.85.220.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 571F9238F6 for ; Fri, 10 May 2013 15:13:25 +0000 (UTC) Received: by mail-vc0-f197.google.com with SMTP id gf12sf5094501vcb.8 for ; Fri, 10 May 2013 08:12:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-beenthere:x-received:received-spf :x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=RqD9OdSU/k0SVN5UJDr6pzFsggMULQT91upiw0LCFz8=; b=eWIJL66eI13Cxr+i40ynqEBaCgQm0TADacNeB0Tahhawtqsw1pJ3J1olFHELFYxB8H vEPQtYk7z92zNmZmY7C2ZBjn0EERqTO3VRIPNt38kaKnFHlZOAb6kYMoaQqbiWZRsxXv 3Ga0Yfk6ncLcJZXGILajHVAEcvCQKFqW6wH0MYlTgmYMXn6PzU26IDWablPudbNwaE4w GR0boAfV3kfhnYSaaxaOAl8BhmpnfW/diRyNH2CAqh+kzANAUmjncCRNleN9csw4vTAn VSMiSeY1GWQhQqXXfpsF4laKCtzBdXVcoejtJUrUQZRu02O5f2ia1HF80Q39/EAbiuX+ sQTA== X-Received: by 10.236.29.80 with SMTP id h56mr8656142yha.38.1368198779563; Fri, 10 May 2013 08:12:59 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.83.36 with SMTP id n4ls208518qey.76.gmail; Fri, 10 May 2013 08:12:59 -0700 (PDT) X-Received: by 10.220.109.207 with SMTP id k15mr11335826vcp.34.1368198779357; Fri, 10 May 2013 08:12:59 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id tq4si1470634vdc.105.2013.05.10.08.12.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 10 May 2013 08:12:59 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id kw10so88315vcb.14 for ; Fri, 10 May 2013 08:12:59 -0700 (PDT) X-Received: by 10.52.69.109 with SMTP id d13mr9707009vdu.75.1368198779178; Fri, 10 May 2013 08:12:59 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.217.15 with SMTP id hk15csp59281vcb; Fri, 10 May 2013 08:12:53 -0700 (PDT) X-Received: by 10.194.240.132 with SMTP id wa4mr25389705wjc.52.1368198761696; Fri, 10 May 2013 08:12:41 -0700 (PDT) Received: from mail-wi0-x235.google.com (mail-wi0-x235.google.com [2a00:1450:400c:c05::235]) by mx.google.com with ESMTPS id eg5si789533wic.75.2013.05.10.08.12.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 10 May 2013 08:12:41 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c05::235 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=2a00:1450:400c:c05::235; Received: by mail-wi0-f181.google.com with SMTP id ey16so738797wid.14 for ; Fri, 10 May 2013 08:12:41 -0700 (PDT) X-Received: by 10.180.105.195 with SMTP id go3mr4659775wib.2.1368198756195; Fri, 10 May 2013 08:12:36 -0700 (PDT) Received: from belegaer.uk.xensource.com. (firewall.ctxuk.citrix.com. [46.33.159.2]) by mx.google.com with ESMTPSA id e8sm4080359wic.5.2013.05.10.08.12.34 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 10 May 2013 08:12:35 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Cc: Stefano.Stabellini@eu.citrix.com, ian.campbell@citrix.com, patches@linaro.org, Julien Grall Subject: [PATCH V4 22/32] xen/arm: Allow Xen to run on multiple platform without recompilation Date: Fri, 10 May 2013 16:12:00 +0100 Message-Id: <1368198723-24639-9-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1368198723-24639-1-git-send-email-julien.grall@linaro.org> References: <1368198723-24639-1-git-send-email-julien.grall@linaro.org> X-Gm-Message-State: ALoCoQlwTQKrLrYLn5dvCcUH71j+k8mHMPrkTYQdRobbKhae1ieEioO6WKR4gB4T2H5BXu+/DUlr X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Xen can include various platform support (ie: exynos5, versatile express...) and choose during boot time a set of callbacks for the current board. These callbacks will be called in places where each board can have specific code. For the moment the callbacks are: - platform_init: additional initialization for the platform - platform_init_time: some platform (ie: Exynos 5) needs to initialize the timer with an uncommon way - platform_specific_mapping: add mapping to dom0 which are not specified in the device tree - platform_reset: reset the platform - platform_poweroff: poweroff the platform - platform_quirks: list of quirks for a specific board. Signed-off-by: Julien Grall Acked-by: Ian Campbell Changes in v4: - More precision in the TODO Changes in v3: - Remove platform_{read,write} - Move platform_init_time before reading the timer frequency Changes in v2: - Add platform_poweroff - Add platform_quirks --- xen/arch/arm/Makefile | 1 + xen/arch/arm/domain_build.c | 4 ++ xen/arch/arm/platform.c | 137 ++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/setup.c | 3 + xen/arch/arm/shutdown.c | 2 + xen/arch/arm/time.c | 6 ++ xen/arch/arm/xen.lds.S | 7 ++ xen/include/asm-arm/platform.h | 55 ++++++++++++++++ 8 files changed, 215 insertions(+) create mode 100644 xen/arch/arm/platform.c create mode 100644 xen/include/asm-arm/platform.h diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 4955a21..2717f26 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -18,6 +18,7 @@ obj-y += p2m.o obj-y += percpu.o obj-y += guestcopy.o obj-y += physdev.o +obj-y += platform.o obj-y += setup.o obj-y += time.o obj-y += smpboot.o diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 9a2ccad..75c3006 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -513,6 +514,9 @@ int construct_dom0(struct domain *d) return rc; map_devices_from_device_tree(d); + rc = platform_specific_mapping(d); + if ( rc < 0 ) + return rc; /* The following loads use the domain's p2m */ p2m_load_VTTBR(d); diff --git a/xen/arch/arm/platform.c b/xen/arch/arm/platform.c new file mode 100644 index 0000000..afda302 --- /dev/null +++ b/xen/arch/arm/platform.c @@ -0,0 +1,137 @@ +/* + * xen/arch/arm/platform.c + * + * Helpers to execute platform specific code. + * + * Julien Grall + * 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 +#include +#include + +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: + */ diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index e5f4459..da2a734 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -42,6 +42,7 @@ #include #include #include +#include struct cpuinfo_arm __read_mostly boot_cpu_data; @@ -440,6 +441,8 @@ void __init start_xen(unsigned long boot_phys_offset, processor_id(); + platform_init(); + init_xen_time(); gic_init(); diff --git a/xen/arch/arm/shutdown.c b/xen/arch/arm/shutdown.c index 61b5280..0903842 100644 --- a/xen/arch/arm/shutdown.c +++ b/xen/arch/arm/shutdown.c @@ -5,6 +5,7 @@ #include #include #include +#include static void raw_machine_reset(void) { @@ -21,6 +22,7 @@ static void raw_machine_reset(void) dsb(); isb(); clear_fixmap(FIXMAP_MISC); #endif + platform_reset(); } static void halt_this_cpu(void *arg) diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c index 2e928bc..db849cf 100644 --- a/xen/arch/arm/time.c +++ b/xen/arch/arm/time.c @@ -33,6 +33,7 @@ #include #include #include +#include /* * Unfortunately the hypervisor timer interrupt appears to be buggy in @@ -123,11 +124,16 @@ int __init init_xen_time(void) 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); diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index deab040..3b60668 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -77,6 +77,13 @@ SECTIONS #endif . = ALIGN(8); + .arch.info : { + _splatform = .; + *(.arch.info) + _eplatform = .; + } :text + + . = ALIGN(8); .dev.info : { _sdevice = .; *(.dev.info) diff --git a/xen/include/asm-arm/platform.h b/xen/include/asm-arm/platform.h new file mode 100644 index 0000000..e116265 --- /dev/null +++ b/xen/include/asm-arm/platform.h @@ -0,0 +1,55 @@ +#ifndef __ASM_ARM_PLATFORM_H +#define __ASM_ARM_PLATFORM_H + +#include +#include +#include + +/* 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: + */