From patchwork Wed May 27 08:47:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 48998 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6987C202A3 for ; Wed, 27 May 2015 08:48:18 +0000 (UTC) Received: by wixv7 with SMTP id v7sf3101519wix.0 for ; Wed, 27 May 2015 01:48:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type :content-transfer-encoding:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=jwjyAOnyJNFhWsvmxGXba+mUvXCak+tJaBVM/hyZQII=; b=gPD52rP10WOLAGK2URbmyAOA5yeh7sYGwvf8PBzJQRcT7eAJXoib+VBJiIslV3Sl5O uykEGfRavd5x/wpxO3aFG+SnoDKoC3f3IruVKvNWUFf40Ht3RZHSqW7Dq31qpjkXVrfJ VAsQWD4nH3PMIKFhLHVxjSMARU3rkuENWjJOcvj48RPxNU/JGY8o1Ei02YBpaw9TEbbg j2jVELTDfuFs9FFGKAnPYb9wzVitZr307ig9pDvFX2+7YGTxkskh9cin8hmy1K2Jvr0g tEDSu4qpqhFxeb7DEByJH2czNOo+MTzds98ducszFqaYPN9mYPXq9BiXpXlgj/apkNvr f5VA== X-Gm-Message-State: ALoCoQnqSlXfpS72UaKAWmZ3CIBjKvwG5z0yhr5X+Sr9kXZKGcvF+2RhrEymbXTIH0mXvvrBCqi1 X-Received: by 10.112.138.2 with SMTP id qm2mr31101026lbb.19.1432716497467; Wed, 27 May 2015 01:48:17 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.42.206 with SMTP id q14ls11721lal.58.gmail; Wed, 27 May 2015 01:48:17 -0700 (PDT) X-Received: by 10.152.115.132 with SMTP id jo4mr27455715lab.102.1432716497324; Wed, 27 May 2015 01:48:17 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id kg7si4025728lbc.176.2015.05.27.01.48.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 May 2015 01:48:17 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by lagv1 with SMTP id v1so2275040lag.3 for ; Wed, 27 May 2015 01:48:17 -0700 (PDT) X-Received: by 10.152.87.204 with SMTP id ba12mr27346062lab.35.1432716497185; Wed, 27 May 2015 01:48:17 -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.112.108.230 with SMTP id hn6csp191637lbb; Wed, 27 May 2015 01:48:16 -0700 (PDT) X-Received: by 10.180.186.99 with SMTP id fj3mr47787053wic.10.1432716494980; Wed, 27 May 2015 01:48:14 -0700 (PDT) Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com. [74.125.82.45]) by mx.google.com with ESMTPS id fa2si20431980wib.27.2015.05.27.01.48.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 May 2015 01:48:14 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.45 as permitted sender) client-ip=74.125.82.45; Received: by wgez8 with SMTP id z8so3190746wge.0 for ; Wed, 27 May 2015 01:48:14 -0700 (PDT) X-Received: by 10.180.205.168 with SMTP id lh8mr3925544wic.24.1432716494733; Wed, 27 May 2015 01:48:14 -0700 (PDT) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id g14sm25717288wjs.47.2015.05.27.01.48.13 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 27 May 2015 01:48:13 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: christoffer.dall@linaro.org, kvmarm@lists.cs.columbia.edu, patches@linaro.org, alex.williamson@redhat.com, agraf@suse.de, pbonzini@redhat.com Subject: [RESEND PATCH v12 2/4] hw/arm/boot: arm_load_kernel implemented as a machine init done notifier Date: Wed, 27 May 2015 09:47:48 +0100 Message-Id: <1432716470-2096-3-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1432716470-2096-1-git-send-email-eric.auger@linaro.org> References: <1432716470-2096-1-git-send-email-eric.auger@linaro.org> MIME-Version: 1.0 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) 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: , 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