From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y0pao-000457-CS for qemu-devel@nongnu.org; Tue, 16 Dec 2014 05:43:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y0pai-0002Nd-5a for qemu-devel@nongnu.org; Tue, 16 Dec 2014 05:43:02 -0500 Received: from mail-wi0-f182.google.com ([209.85.212.182]:53300) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y0pah-0002NQ-UO for qemu-devel@nongnu.org; Tue, 16 Dec 2014 05:42:56 -0500 Received: by mail-wi0-f182.google.com with SMTP id h11so11952246wiw.15 for ; Tue, 16 Dec 2014 02:42:55 -0800 (PST) From: Eric Auger Date: Tue, 16 Dec 2014 10:42:34 +0000 Message-Id: <1418726555-20532-3-git-send-email-eric.auger@linaro.org> In-Reply-To: <1418726555-20532-1-git-send-email-eric.auger@linaro.org> References: <1418726555-20532-1-git-send-email-eric.auger@linaro.org> Subject: [Qemu-devel] [PATCH v7 2/3] hw/arm/boot: arm_load_kernel implemented as a machine init done notifier List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: eric.auger@st.com, christoffer.dall@linaro.org, qemu-devel@nongnu.org, agraf@suse.de, pbonzini@redhat.com, ard.biesheuvel@linaro.org, zhaoshenglong@huawei.com, a.rigo@virtualopensystems.com, joel.schopp@amd.com Cc: peter.maydell@linaro.org, patches@linaro.org, eric.auger@linaro.org, alex.williamson@redhat.com, a.motakis@virtualopensystems.com, kvmarm@lists.cs.columbia.edu 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 --- 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 e6a3c5b..1f01692 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -478,7 +478,7 @@ static void do_cpu_reset(void *opaque) } } -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; @@ -489,6 +489,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 = + container_of(notifier, ArmLoadKernelNotifier, 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 @@ -667,3 +672,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 cefc9e6..88cf80b 100644 --- a/include/hw/arm/arm.h +++ b/include/hw/arm/arm.h @@ -19,6 +19,16 @@ qemu_irq *armv7m_init(MemoryRegion *system_memory, int flash_size, int sram_size, const char *kernel_filename, const char *cpu_model); +/* + * struct used as a parameter of the arm_load_kernel machine init + * done notifier + */ +typedef struct { + ARMCPU *cpu; /* handle to the first cpu object */ + Notifier notifier; /* actual notifier */ +} ArmLoadKernelNotifier; + + /* arm_boot.c */ struct arm_boot_info { uint64_t ram_size; @@ -61,12 +71,30 @@ 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; hwaddr initrd_size; hwaddr entry; }; + +/** + * 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 -- 1.8.3.2