From patchwork Tue Jun 2 11:29:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 479426 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E49E11412E2 for ; Tue, 2 Jun 2015 21:38:55 +1000 (AEST) Received: from localhost ([::1]:57722 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzkX0-0002Ga-2z for incoming@patchwork.ozlabs.org; Tue, 02 Jun 2015 07:38:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40008) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzkOG-0003FA-DU for qemu-devel@nongnu.org; Tue, 02 Jun 2015 07:29:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YzkOD-0005Oe-6c for qemu-devel@nongnu.org; Tue, 02 Jun 2015 07:29:52 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:33771) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzkOC-0005OW-UY for qemu-devel@nongnu.org; Tue, 02 Jun 2015 07:29:49 -0400 Received: by wiwd19 with SMTP id d19so15916893wiw.0 for ; Tue, 02 Jun 2015 04:29:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=jwjyAOnyJNFhWsvmxGXba+mUvXCak+tJaBVM/hyZQII=; b=YeLZyX30i8A8Zd/e8pTNVZ2kNvT15rOCXz7AJKFRB/haIN1RuU5HzjcwViysq2iHC7 k9ijEHTR3j6mrZStd9nXVPFn6F3YtDwIL29ZWgQAHIGQYSKjYBLuw2girTJLP2yoHuGA 6qjQ1rnYCI/r6cm19tGM+WLoaPYo7Iu07IzE1PIY4FLHuZJehLZCWyEO3QY3hDkXhXb5 myRry1S/nCm7DdTnK97WNgt03pSyaOG0SdaHojZVMcAsDyEo92Fiw26C77KS3qclOge8 tmaGSzfb6EyohF2u95Mnl7m9ziG8iuOvauVZA5Xlp4usTHLoPgQoZtp87yjdXrRrgn+n n+2w== X-Gm-Message-State: ALoCoQlC22dlewjuHMdoy3+BCf4mkyxrtVxwwgtPX3twzqRtsO3g+p8FJkJpRkTwWJqgqMB8/Jc9 X-Received: by 10.194.222.230 with SMTP id qp6mr50659924wjc.70.1433244588363; Tue, 02 Jun 2015 04:29:48 -0700 (PDT) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id n6sm21110645wic.16.2015.06.02.04.29.43 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Jun 2015 04:29:43 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Tue, 2 Jun 2015 12:29:12 +0100 Message-Id: <1433244554-12898-3-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1433244554-12898-1-git-send-email-eric.auger@linaro.org> References: <1433244554-12898-1-git-send-email-eric.auger@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.212.169 Cc: kvmarm@lists.cs.columbia.edu, patches@linaro.org Subject: [Qemu-devel] [PATCH v13 2/4] hw/arm/boot: arm_load_kernel implemented as a machine init done notifier X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Device tree nodes for the platform bus and its children dynamic sysbus devices are added in a machine init done notifier. To load the dtb once, after those latter nodes are built and before ROM freeze, the actual arm_load_kernel existing code is moved into a notifier notify function, arm_load_kernel_notify. arm_load_kernel now only registers the corresponding notifier. Machine files that do not support platform bus stay unchanged. Machine files willing to support dynamic sysbus devices must call arm_load_kernel before sysbus-fdt arm_register_platform_bus_fdt_creator to make sure dynamic sysbus device nodes are integrated in the dtb. Signed-off-by: Eric Auger Reviewed-by: Shannon Zhao Reviewed-by: Alexander Graf Reviewed-by: Alex Bennée --- v11 -> v12: - Add Alex R-b v8 -> v9: - fix compilation with arm-linux-user - reorder fields in ArmLoadKernelNotifier and use DO_UPCAST v7 -> v8: - Add Reviewed-by from Alex & Shannon - rebase on 2.2.0 v6: creation of this patch file --- hw/arm/boot.c | 14 +++++++++++++- include/hw/arm/arm.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index fa69503..d036624 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -557,7 +557,7 @@ static void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key, fw_cfg_add_bytes(fw_cfg, data_key, data, size); } -void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) +static void arm_load_kernel_notify(Notifier *notifier, void *data) { CPUState *cs; int kernel_size; @@ -568,6 +568,11 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) hwaddr entry, kernel_load_offset; int big_endian; static const ARMInsnFixup *primary_loader; + ArmLoadKernelNotifier *n = DO_UPCAST(ArmLoadKernelNotifier, + notifier, notifier); + ARMCPU *cpu = n->cpu; + struct arm_boot_info *info = + container_of(n, struct arm_boot_info, load_kernel_notifier); /* CPU objects (unlike devices) are not automatically reset on system * reset, so we must always register a handler to do so. If we're @@ -775,3 +780,10 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) ARM_CPU(cs)->env.boot_info = info; } } + +void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) +{ + info->load_kernel_notifier.cpu = cpu; + info->load_kernel_notifier.notifier.notify = arm_load_kernel_notify; + qemu_add_machine_init_done_notifier(&info->load_kernel_notifier.notifier); +} diff --git a/include/hw/arm/arm.h b/include/hw/arm/arm.h index 5c940eb..760804c 100644 --- a/include/hw/arm/arm.h +++ b/include/hw/arm/arm.h @@ -13,11 +13,21 @@ #include "exec/memory.h" #include "hw/irq.h" +#include "qemu/notify.h" /* armv7m.c */ qemu_irq *armv7m_init(MemoryRegion *system_memory, int mem_size, int num_irq, const char *kernel_filename, const char *cpu_model); +/* + * struct used as a parameter of the arm_load_kernel machine init + * done notifier + */ +typedef struct { + Notifier notifier; /* actual notifier */ + ARMCPU *cpu; /* handle to the first cpu object */ +} ArmLoadKernelNotifier; + /* arm_boot.c */ struct arm_boot_info { uint64_t ram_size; @@ -64,6 +74,8 @@ struct arm_boot_info { * the user it should implement this hook. */ void (*modify_dtb)(const struct arm_boot_info *info, void *fdt); + /* machine init done notifier executing arm_load_dtb */ + ArmLoadKernelNotifier load_kernel_notifier; /* Used internally by arm_boot.c */ int is_linux; hwaddr initrd_start; @@ -75,6 +87,22 @@ struct arm_boot_info { */ bool firmware_loaded; }; + +/** + * arm_load_kernel - Loads memory with everything needed to boot + * + * @cpu: handle to the first CPU object + * @info: handle to the boot info struct + * Registers a machine init done notifier that copies to memory + * everything needed to boot, depending on machine and user options: + * kernel image, boot loaders, initrd, dtb. Also registers the CPU + * reset handler. + * + * In case the machine file supports the platform bus device and its + * dynamically instantiable sysbus devices, this function must be called + * before sysbus-fdt arm_register_platform_bus_fdt_creator. Indeed the + * machine init done notifiers are called in registration reverse order. + */ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info); /* Multiplication factor to convert from system clock ticks to qemu timer