From patchwork Fri Jul 18 13:08:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 33838 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oi0-f71.google.com (mail-oi0-f71.google.com [209.85.218.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B8519208CF for ; Fri, 18 Jul 2014 13:10:25 +0000 (UTC) Received: by mail-oi0-f71.google.com with SMTP id e131sf5609427oig.6 for ; Fri, 18 Jul 2014 06:10:25 -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:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type:content-transfer-encoding; bh=UIRc4LYldk/0jZu1gVu3eFuqwH5mMsGWKsWamcbMZGU=; b=OsYhSO8oi1orPmDoW4BfWfLGQxAPYSvwpY/NdB1s4MKDI56y7uWGfr7e7ytARutgLf fVzobHFhsLJ+vEDdndwjNj3tMgsJa7D/wpp11LETZ1pK/4K3KewtHBRsYIkLIclCKQvM rlCzvqIGDVkmh5++BXLLOB1ORcR8aP8HByb7XukbF/a9Hj85PDPA1PF8+4HtmHhbVaS2 kW8OhDigKgYOdE8Oqt1XmOw4ofvVzQPYG1XXZ7LoD/QhPmezu0MLTCL9N8LFQcF70yOf 89wFNksiE5XkPENMNdpxFVzRyuQ7mqq9TavqJsrv7QFbu6fLRQzlJ+TMZ0zbJB2c1e3N 7SUQ== X-Gm-Message-State: ALoCoQmErFRxhRuIKysrm3v6NCnuqTcA02Xl+jkx4gog2cGNiAW1AC8d+9sbwuZjmjYd+3KwMLYd X-Received: by 10.182.66.33 with SMTP id c1mr2183400obt.39.1405689025293; Fri, 18 Jul 2014 06:10:25 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.29.55 with SMTP id a52ls959689qga.14.gmail; Fri, 18 Jul 2014 06:10:25 -0700 (PDT) X-Received: by 10.220.251.80 with SMTP id mr16mr5578708vcb.11.1405689025188; Fri, 18 Jul 2014 06:10:25 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id gy3si5572463vdb.99.2014.07.18.06.10.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 18 Jul 2014 06:10:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id hq11so5801391vcb.30 for ; Fri, 18 Jul 2014 06:10:24 -0700 (PDT) X-Received: by 10.220.118.136 with SMTP id v8mr5657791vcq.50.1405689023933; Fri, 18 Jul 2014 06:10:23 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp9783vcb; Fri, 18 Jul 2014 06:10:23 -0700 (PDT) X-Received: by 10.224.171.197 with SMTP id i5mr8227462qaz.55.1405689023018; Fri, 18 Jul 2014 06:10:23 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id m6si11319875qag.85.2014.07.18.06.10.22 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 18 Jul 2014 06:10:23 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X87to-0005WE-7U; Fri, 18 Jul 2014 13:08:32 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X87tm-0005Tq-9o for xen-devel@lists.xen.org; Fri, 18 Jul 2014 13:08:30 +0000 Received: from [85.158.143.35:60397] by server-3.bemta-4.messagelabs.com id F5/60-09960-D4C19C35; Fri, 18 Jul 2014 13:08:29 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-8.tower-21.messagelabs.com!1405688907!18580206!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9570 invoked from network); 18 Jul 2014 13:08:28 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-8.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 18 Jul 2014 13:08:28 -0000 X-IronPort-AV: E=Sophos;i="5.01,685,1400025600"; d="scan'208";a="153665164" Received: from accessns.citrite.net (HELO FTLPEX01CL02.citrite.net) ([10.9.154.239]) by FTLPIPO01.CITRIX.COM with ESMTP; 18 Jul 2014 13:08:27 +0000 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.79) with Microsoft SMTP Server id 14.3.181.6; Fri, 18 Jul 2014 09:08:26 -0400 Received: from marilith-n13-p0.uk.xensource.com ([10.80.229.115] helo=localhost.localdomain) by ukmail1.uk.xensource.com with smtp (Exim 4.69) (envelope-from ) id 1X87th-0001RI-63; Fri, 18 Jul 2014 14:08:26 +0100 Received: by localhost.localdomain (sSMTP sendmail emulation); Fri, 18 Jul 2014 14:08:25 +0100 From: Ian Campbell To: Date: Fri, 18 Jul 2014 14:08:15 +0100 Message-ID: <1405688900-11769-5-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1405688876.491.10.camel@kazak.uk.xensource.com> References: <1405688876.491.10.camel@kazak.uk.xensource.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: julien.grall@linaro.org, tim@xen.org, Ian Campbell , stefano.stabellini@eu.citrix.com Subject: [Xen-devel] [PATCH v3 05/10] xen: arm: move boot time fdt parsing into separate file. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ian.campbell@citrix.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: Move the early code for walking the flattened device tree out of device_tree.c. The intention is that eventually only the proper (i.e. unflattened) device tree support will live in device_tree.c. The new home is bootfdt.c to try and better reflect the purpose of the code. Although in theory this early code could be generic in reality it is pretty ARM specific, so place it under xen/arch/arm until a second user wants it. As part of the move rename device_tree_early_init to boot_fdt_info. Drop device_tree_dump, it is unused. Signed-off-by: Ian Campbell Acked-by: Julien Grall Acked-by: Stefano Stabellini --- xen/arch/arm/Makefile | 1 + xen/arch/arm/bootfdt.c | 345 +++++++++++++++++++++++++++++++++++++++ xen/arch/arm/setup.c | 2 +- xen/common/device_tree.c | 358 ----------------------------------------- xen/include/asm-arm/setup.h | 2 + xen/include/xen/device_tree.h | 3 - 6 files changed, 349 insertions(+), 362 deletions(-) create mode 100644 xen/arch/arm/bootfdt.c diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 20f59f4..c13206f 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -21,6 +21,7 @@ obj-y += guestcopy.o obj-y += physdev.o obj-y += platform.o obj-y += setup.o +obj-y += bootfdt.o obj-y += time.o obj-y += smpboot.o obj-y += smp.o diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c new file mode 100644 index 0000000..bcf4882 --- /dev/null +++ b/xen/arch/arm/bootfdt.c @@ -0,0 +1,345 @@ +/* + * Early Device Tree + * + * Copyright (C) 2012-2014 Citrix Systems, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +static bool_t __init device_tree_node_matches(const void *fdt, int node, + const char *match) +{ + const char *name; + size_t match_len; + + name = fdt_get_name(fdt, node, NULL); + match_len = strlen(match); + + /* Match both "match" and "match@..." patterns but not + "match-foo". */ + return strncmp(name, match, match_len) == 0 + && (name[match_len] == '@' || name[match_len] == '\0'); +} + +static bool_t __init device_tree_node_compatible(const void *fdt, int node, + const char *match) +{ + int len, l; + int mlen; + const void *prop; + + mlen = strlen(match); + + prop = fdt_getprop(fdt, node, "compatible", &len); + if ( prop == NULL ) + return 0; + + while ( len > 0 ) { + if ( !dt_compat_cmp(prop, match) ) + return 1; + l = strlen(prop) + 1; + prop += l; + len -= l; + } + + return 0; +} + +static void __init device_tree_get_reg(const __be32 **cell, u32 address_cells, + u32 size_cells, u64 *start, u64 *size) +{ + *start = dt_next_cell(address_cells, cell); + *size = dt_next_cell(size_cells, cell); +} + +static u32 __init device_tree_get_u32(const void *fdt, int node, + const char *prop_name, u32 dflt) +{ + const struct fdt_property *prop; + + prop = fdt_get_property(fdt, node, prop_name, NULL); + if ( !prop || prop->len < sizeof(u32) ) + return dflt; + + return fdt32_to_cpu(*(uint32_t*)prop->data); +} + +/** + * device_tree_for_each_node - iterate over all device tree nodes + * @fdt: flat device tree. + * @func: function to call for each node. + * @data: data to pass to @func. + * + * Any nodes nested at DEVICE_TREE_MAX_DEPTH or deeper are ignored. + * + * Returns 0 if all nodes were iterated over successfully. If @func + * returns a value different from 0, that value is returned immediately. + */ +static int __init device_tree_for_each_node(const void *fdt, + device_tree_node_func func, + void *data) +{ + int node; + int depth; + u32 address_cells[DEVICE_TREE_MAX_DEPTH]; + u32 size_cells[DEVICE_TREE_MAX_DEPTH]; + int ret; + + for ( node = 0, depth = 0; + node >=0 && depth >= 0; + node = fdt_next_node(fdt, node, &depth) ) + { + const char *name = fdt_get_name(fdt, node, NULL); + + if ( depth >= DEVICE_TREE_MAX_DEPTH ) + { + printk("Warning: device tree node `%s' is nested too deep\n", + name); + continue; + } + + address_cells[depth] = device_tree_get_u32(fdt, node, "#address-cells", + depth > 0 ? address_cells[depth-1] : 0); + size_cells[depth] = device_tree_get_u32(fdt, node, "#size-cells", + depth > 0 ? size_cells[depth-1] : 0); + + + ret = func(fdt, node, name, depth, + address_cells[depth-1], size_cells[depth-1], data); + if ( ret != 0 ) + return ret; + } + return 0; +} + +static void __init process_memory_node(const void *fdt, int node, + const char *name, + u32 address_cells, u32 size_cells) +{ + const struct fdt_property *prop; + int i; + int banks; + const __be32 *cell; + paddr_t start, size; + u32 reg_cells = address_cells + size_cells; + + if ( address_cells < 1 || size_cells < 1 ) + { + printk("fdt: node `%s': invalid #address-cells or #size-cells", + name); + return; + } + + prop = fdt_get_property(fdt, node, "reg", NULL); + if ( !prop ) + { + printk("fdt: node `%s': missing `reg' property\n", name); + return; + } + + cell = (const __be32 *)prop->data; + banks = fdt32_to_cpu(prop->len) / (reg_cells * sizeof (u32)); + + for ( i = 0; i < banks && bootinfo.mem.nr_banks < NR_MEM_BANKS; i++ ) + { + device_tree_get_reg(&cell, address_cells, size_cells, &start, &size); + if ( !size ) + continue; + bootinfo.mem.bank[bootinfo.mem.nr_banks].start = start; + bootinfo.mem.bank[bootinfo.mem.nr_banks].size = size; + bootinfo.mem.nr_banks++; + } +} + +static void __init process_multiboot_node(const void *fdt, int node, + const char *name, + u32 address_cells, u32 size_cells) +{ + const struct fdt_property *prop; + const __be32 *cell; + int nr; + struct bootmodule *mod; + int len; + + if ( fdt_node_check_compatible(fdt, node, "xen,linux-zimage") == 0 || + fdt_node_check_compatible(fdt, node, "multiboot,kernel") == 0 ) + nr = MOD_KERNEL; + else if ( fdt_node_check_compatible(fdt, node, "xen,linux-initrd") == 0 || + fdt_node_check_compatible(fdt, node, "multiboot,ramdisk") == 0 ) + nr = MOD_INITRD; + else if ( fdt_node_check_compatible(fdt, node, "xen,xsm-policy") == 0 ) + nr = MOD_XSM; + else + panic("%s not a known xen multiboot type\n", name); + + mod = &bootinfo.modules.module[nr]; + + prop = fdt_get_property(fdt, node, "reg", &len); + if ( !prop ) + panic("node %s missing `reg' property\n", name); + + if ( len < dt_cells_to_size(address_cells + size_cells) ) + panic("fdt: node `%s': `reg` property length is too short\n", + name); + + cell = (const __be32 *)prop->data; + device_tree_get_reg(&cell, address_cells, size_cells, + &mod->start, &mod->size); + + prop = fdt_get_property(fdt, node, "bootargs", &len); + if ( prop ) + { + if ( len > sizeof(mod->cmdline) ) + panic("module %d command line too long\n", nr); + + safe_strcpy(mod->cmdline, prop->data); + } + else + mod->cmdline[0] = 0; + + if ( nr > bootinfo.modules.nr_mods ) + bootinfo.modules.nr_mods = nr; +} + +static void __init process_chosen_node(const void *fdt, int node, + const char *name, + u32 address_cells, u32 size_cells) +{ + const struct fdt_property *prop; + struct bootmodule *mod = &bootinfo.modules.module[MOD_INITRD]; + paddr_t start, end; + int len; + + printk("Checking for initrd in /chosen\n"); + + prop = fdt_get_property(fdt, node, "linux,initrd-start", &len); + if ( !prop ) + /* No initrd present. */ + return; + if ( len != sizeof(u32) && len != sizeof(u64) ) + { + printk("linux,initrd-start property has invalid length %d\n", len); + return; + } + start = dt_read_number((void *)&prop->data, dt_size_to_cells(len)); + + prop = fdt_get_property(fdt, node, "linux,initrd-end", &len); + if ( !prop ) + { + printk("linux,initrd-end not present but -start was\n"); + return; + } + if ( len != sizeof(u32) && len != sizeof(u64) ) + { + printk("linux,initrd-end property has invalid length %d\n", len); + return; + } + end = dt_read_number((void *)&prop->data, dt_size_to_cells(len)); + + if ( start >= end ) + { + printk("linux,initrd limits invalid: %"PRIpaddr" >= %"PRIpaddr"\n", + start, end); + return; + } + + printk("Initrd %"PRIpaddr"-%"PRIpaddr"\n", start, end); + + mod->start = start; + mod->size = end - start; + + bootinfo.modules.nr_mods = max(MOD_INITRD, bootinfo.modules.nr_mods); +} + +static int __init early_scan_node(const void *fdt, + int node, const char *name, int depth, + u32 address_cells, u32 size_cells, + void *data) +{ + if ( device_tree_node_matches(fdt, node, "memory") ) + process_memory_node(fdt, node, name, address_cells, size_cells); + else if ( device_tree_node_compatible(fdt, node, "xen,multiboot-module" ) || + device_tree_node_compatible(fdt, node, "multiboot,module" )) + process_multiboot_node(fdt, node, name, address_cells, size_cells); + else if ( depth == 1 && device_tree_node_matches(fdt, node, "chosen") ) + process_chosen_node(fdt, node, name, address_cells, size_cells); + + return 0; +} + +static void __init early_print_info(void) +{ + struct meminfo *mi = &bootinfo.mem; + struct bootmodules *mods = &bootinfo.modules; + int i, nr_rsvd; + + for ( i = 0; i < mi->nr_banks; i++ ) + printk("RAM: %"PRIpaddr" - %"PRIpaddr"\n", + mi->bank[i].start, + mi->bank[i].start + mi->bank[i].size - 1); + printk("\n"); + for ( i = 1 ; i < mods->nr_mods + 1; i++ ) + printk("MODULE[%d]: %"PRIpaddr" - %"PRIpaddr" %s\n", + i, + mods->module[i].start, + mods->module[i].start + mods->module[i].size, + mods->module[i].cmdline); + nr_rsvd = fdt_num_mem_rsv(device_tree_flattened); + for ( i = 0; i < nr_rsvd; i++ ) + { + paddr_t s, e; + if ( fdt_get_mem_rsv(device_tree_flattened, i, &s, &e) < 0 ) + continue; + /* fdt_get_mem_rsv returns length */ + e += s; + printk(" RESVD[%d]: %"PRIpaddr" - %"PRIpaddr"\n", + i, s, e); + } + printk("\n"); +} + +/** + * boot_fdt_info - initialize bootinfo from a DTB + * @fdt: flattened device tree binary + * + * Returns the size of the DTB. + */ +size_t __init boot_fdt_info(const void *fdt, paddr_t paddr) +{ + struct bootmodule *mod; + int ret; + + ret = fdt_check_header(fdt); + if ( ret < 0 ) + panic("No valid device tree\n"); + + mod = &bootinfo.modules.module[MOD_FDT]; + mod->start = paddr; + mod->size = fdt_totalsize(fdt); + + bootinfo.modules.nr_mods = max(MOD_FDT, bootinfo.modules.nr_mods); + + device_tree_for_each_node((void *)fdt, early_scan_node, NULL); + early_print_info(); + + return fdt_totalsize(fdt); +} + +/* + * 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 b1aa9c3..05336d6 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -684,7 +684,7 @@ void __init start_xen(unsigned long boot_phys_offset, /* This is mapped by head.S */ device_tree_flattened = (void *)BOOT_FDT_VIRT_START + (fdt_paddr & ((1 << SECOND_SHIFT) - 1)); - fdt_size = device_tree_early_init(device_tree_flattened, fdt_paddr); + fdt_size = boot_fdt_info(device_tree_flattened, fdt_paddr); cmdline = device_tree_bootargs(device_tree_flattened); printk("Command line: %s\n", cmdline); diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index c0b2b95..689970d 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -22,7 +22,6 @@ #include #include #include -#include #include const void *device_tree_flattened; @@ -89,52 +88,6 @@ struct dt_bus unsigned int (*get_flags)(const __be32 *addr); }; -static bool_t __init device_tree_node_matches(const void *fdt, int node, - const char *match) -{ - const char *name; - size_t match_len; - - name = fdt_get_name(fdt, node, NULL); - match_len = strlen(match); - - /* Match both "match" and "match@..." patterns but not - "match-foo". */ - return strncmp(name, match, match_len) == 0 - && (name[match_len] == '@' || name[match_len] == '\0'); -} - -static bool_t __init device_tree_node_compatible(const void *fdt, int node, - const char *match) -{ - int len, l; - int mlen; - const void *prop; - - mlen = strlen(match); - - prop = fdt_getprop(fdt, node, "compatible", &len); - if ( prop == NULL ) - return 0; - - while ( len > 0 ) { - if ( !dt_compat_cmp(prop, match) ) - return 1; - l = strlen(prop) + 1; - prop += l; - len -= l; - } - - return 0; -} - -static void __init device_tree_get_reg(const __be32 **cell, u32 address_cells, - u32 size_cells, u64 *start, u64 *size) -{ - *start = dt_next_cell(address_cells, cell); - *size = dt_next_cell(size_cells, cell); -} - void dt_get_range(const __be32 **cell, const struct dt_device_node *np, u64 *address, u64 *size) { @@ -162,66 +115,6 @@ void dt_set_range(__be32 **cellp, const struct dt_device_node *np, dt_set_cell(cellp, dt_n_size_cells(np), size); } -static u32 __init device_tree_get_u32(const void *fdt, int node, - const char *prop_name, u32 dflt) -{ - const struct fdt_property *prop; - - prop = fdt_get_property(fdt, node, prop_name, NULL); - if ( !prop || prop->len < sizeof(u32) ) - return dflt; - - return fdt32_to_cpu(*(uint32_t*)prop->data); -} - -/** - * device_tree_for_each_node - iterate over all device tree nodes - * @fdt: flat device tree. - * @func: function to call for each node. - * @data: data to pass to @func. - * - * Any nodes nested at DEVICE_TREE_MAX_DEPTH or deeper are ignored. - * - * Returns 0 if all nodes were iterated over successfully. If @func - * returns a value different from 0, that value is returned immediately. - */ -static int __init device_tree_for_each_node(const void *fdt, - device_tree_node_func func, - void *data) -{ - int node; - int depth; - u32 address_cells[DEVICE_TREE_MAX_DEPTH]; - u32 size_cells[DEVICE_TREE_MAX_DEPTH]; - int ret; - - for ( node = 0, depth = 0; - node >=0 && depth >= 0; - node = fdt_next_node(fdt, node, &depth) ) - { - const char *name = fdt_get_name(fdt, node, NULL); - - if ( depth >= DEVICE_TREE_MAX_DEPTH ) - { - printk("Warning: device tree node `%s' is nested too deep\n", - name); - continue; - } - - address_cells[depth] = device_tree_get_u32(fdt, node, "#address-cells", - depth > 0 ? address_cells[depth-1] : 0); - size_cells[depth] = device_tree_get_u32(fdt, node, "#size-cells", - depth > 0 ? size_cells[depth-1] : 0); - - - ret = func(fdt, node, name, depth, - address_cells[depth-1], size_cells[depth-1], data); - if ( ret != 0 ) - return ret; - } - return 0; -} - /** * device_tree_bootargs - return the bootargs (the Xen command line) * @fdt flat device tree. @@ -253,257 +146,6 @@ const char *device_tree_bootargs(const void *fdt) return prop->data; } -static int dump_node(const void *fdt, int node, const char *name, int depth, - u32 address_cells, u32 size_cells, void *data) -{ - char prefix[2*DEVICE_TREE_MAX_DEPTH + 1] = ""; - int i; - int prop; - - for ( i = 0; i < depth; i++ ) - safe_strcat(prefix, " "); - - if ( name[0] == '\0' ) - name = "/"; - printk("%s%s:\n", prefix, name); - - for ( prop = fdt_first_property_offset(fdt, node); - prop >= 0; - prop = fdt_next_property_offset(fdt, prop) ) - { - const struct fdt_property *p; - - p = fdt_get_property_by_offset(fdt, prop, NULL); - - printk("%s %s\n", prefix, fdt_string(fdt, fdt32_to_cpu(p->nameoff))); - } - - return 0; -} - -/** - * device_tree_dump - print a text representation of a device tree - * @fdt: flat device tree to print - */ -void __init device_tree_dump(const void *fdt) -{ - device_tree_for_each_node(fdt, dump_node, NULL); -} - - -static void __init process_memory_node(const void *fdt, int node, - const char *name, - u32 address_cells, u32 size_cells) -{ - const struct fdt_property *prop; - int i; - int banks; - const __be32 *cell; - paddr_t start, size; - u32 reg_cells = address_cells + size_cells; - - if ( address_cells < 1 || size_cells < 1 ) - { - printk("fdt: node `%s': invalid #address-cells or #size-cells", - name); - return; - } - - prop = fdt_get_property(fdt, node, "reg", NULL); - if ( !prop ) - { - printk("fdt: node `%s': missing `reg' property\n", name); - return; - } - - cell = (const __be32 *)prop->data; - banks = fdt32_to_cpu(prop->len) / (reg_cells * sizeof (u32)); - - for ( i = 0; i < banks && bootinfo.mem.nr_banks < NR_MEM_BANKS; i++ ) - { - device_tree_get_reg(&cell, address_cells, size_cells, &start, &size); - if ( !size ) - continue; - bootinfo.mem.bank[bootinfo.mem.nr_banks].start = start; - bootinfo.mem.bank[bootinfo.mem.nr_banks].size = size; - bootinfo.mem.nr_banks++; - } -} - -static void __init process_multiboot_node(const void *fdt, int node, - const char *name, - u32 address_cells, u32 size_cells) -{ - const struct fdt_property *prop; - const __be32 *cell; - int nr; - struct bootmodule *mod; - int len; - - if ( fdt_node_check_compatible(fdt, node, "xen,linux-zimage") == 0 || - fdt_node_check_compatible(fdt, node, "multiboot,kernel") == 0 ) - nr = MOD_KERNEL; - else if ( fdt_node_check_compatible(fdt, node, "xen,linux-initrd") == 0 || - fdt_node_check_compatible(fdt, node, "multiboot,ramdisk") == 0 ) - nr = MOD_INITRD; - else if ( fdt_node_check_compatible(fdt, node, "xen,xsm-policy") == 0 ) - nr = MOD_XSM; - else - panic("%s not a known xen multiboot type\n", name); - - mod = &bootinfo.modules.module[nr]; - - prop = fdt_get_property(fdt, node, "reg", &len); - if ( !prop ) - panic("node %s missing `reg' property\n", name); - - if ( len < dt_cells_to_size(address_cells + size_cells) ) - panic("fdt: node `%s': `reg` property length is too short\n", - name); - - cell = (const __be32 *)prop->data; - device_tree_get_reg(&cell, address_cells, size_cells, - &mod->start, &mod->size); - - prop = fdt_get_property(fdt, node, "bootargs", &len); - if ( prop ) - { - if ( len > sizeof(mod->cmdline) ) - panic("module %d command line too long\n", nr); - - safe_strcpy(mod->cmdline, prop->data); - } - else - mod->cmdline[0] = 0; - - if ( nr > bootinfo.modules.nr_mods ) - bootinfo.modules.nr_mods = nr; -} - -static void __init process_chosen_node(const void *fdt, int node, - const char *name, - u32 address_cells, u32 size_cells) -{ - const struct fdt_property *prop; - struct bootmodule *mod = &bootinfo.modules.module[MOD_INITRD]; - paddr_t start, end; - int len; - - printk("Checking for initrd in /chosen\n"); - - prop = fdt_get_property(fdt, node, "linux,initrd-start", &len); - if ( !prop ) - /* No initrd present. */ - return; - if ( len != sizeof(u32) && len != sizeof(u64) ) - { - printk("linux,initrd-start property has invalid length %d\n", len); - return; - } - start = dt_read_number((void *)&prop->data, dt_size_to_cells(len)); - - prop = fdt_get_property(fdt, node, "linux,initrd-end", &len); - if ( !prop ) - { - printk("linux,initrd-end not present but -start was\n"); - return; - } - if ( len != sizeof(u32) && len != sizeof(u64) ) - { - printk("linux,initrd-end property has invalid length %d\n", len); - return; - } - end = dt_read_number((void *)&prop->data, dt_size_to_cells(len)); - - if ( start >= end ) - { - printk("linux,initrd limits invalid: %"PRIpaddr" >= %"PRIpaddr"\n", - start, end); - return; - } - - printk("Initrd %"PRIpaddr"-%"PRIpaddr"\n", start, end); - - mod->start = start; - mod->size = end - start; - - bootinfo.modules.nr_mods = max(MOD_INITRD, bootinfo.modules.nr_mods); -} - -static int __init early_scan_node(const void *fdt, - int node, const char *name, int depth, - u32 address_cells, u32 size_cells, - void *data) -{ - if ( device_tree_node_matches(fdt, node, "memory") ) - process_memory_node(fdt, node, name, address_cells, size_cells); - else if ( device_tree_node_compatible(fdt, node, "xen,multiboot-module" ) || - device_tree_node_compatible(fdt, node, "multiboot,module" )) - process_multiboot_node(fdt, node, name, address_cells, size_cells); - else if ( depth == 1 && device_tree_node_matches(fdt, node, "chosen") ) - process_chosen_node(fdt, node, name, address_cells, size_cells); - - return 0; -} - -static void __init early_print_info(void) -{ - struct meminfo *mi = &bootinfo.mem; - struct bootmodules *mods = &bootinfo.modules; - int i, nr_rsvd; - - for ( i = 0; i < mi->nr_banks; i++ ) - printk("RAM: %"PRIpaddr" - %"PRIpaddr"\n", - mi->bank[i].start, - mi->bank[i].start + mi->bank[i].size - 1); - printk("\n"); - for ( i = 1 ; i < mods->nr_mods + 1; i++ ) - printk("MODULE[%d]: %"PRIpaddr" - %"PRIpaddr" %s\n", - i, - mods->module[i].start, - mods->module[i].start + mods->module[i].size, - mods->module[i].cmdline); - nr_rsvd = fdt_num_mem_rsv(device_tree_flattened); - for ( i = 0; i < nr_rsvd; i++ ) - { - paddr_t s, e; - if ( fdt_get_mem_rsv(device_tree_flattened, i, &s, &e) < 0 ) - continue; - /* fdt_get_mem_rsv returns length */ - e += s; - printk(" RESVD[%d]: %"PRIpaddr" - %"PRIpaddr"\n", - i, s, e); - } - printk("\n"); -} - -/** - * device_tree_early_init - initialize early info from a DTB - * @fdt: flattened device tree binary - * - * Returns the size of the DTB. - */ -size_t __init device_tree_early_init(const void *fdt, paddr_t paddr) -{ - struct bootmodule *mod; - int ret; - - ret = fdt_check_header(fdt); - if ( ret < 0 ) - panic("No valid device tree\n"); - - mod = &bootinfo.modules.module[MOD_FDT]; - mod->start = paddr; - mod->size = fdt_totalsize(fdt); - - bootinfo.modules.nr_mods = max(MOD_FDT, bootinfo.modules.nr_mods); - - device_tree_for_each_node((void *)fdt, early_scan_node, NULL); - early_print_info(); - - return fdt_totalsize(fdt); -} - static void __init *unflatten_dt_alloc(unsigned long *mem, unsigned long size, unsigned long align) { diff --git a/xen/include/asm-arm/setup.h b/xen/include/asm-arm/setup.h index ea0dc46..21dbcd4 100644 --- a/xen/include/asm-arm/setup.h +++ b/xen/include/asm-arm/setup.h @@ -53,6 +53,8 @@ int construct_dom0(struct domain *d); void discard_initial_modules(void); +size_t __init boot_fdt_info(const void *fdt, paddr_t paddr); + #endif /* * Local variables: diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 717ef55..7e6ab6b 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -159,10 +159,7 @@ typedef int (*device_tree_node_func)(const void *fdt, extern const void *device_tree_flattened; -size_t __init device_tree_early_init(const void *fdt, paddr_t paddr); - const char __init *device_tree_bootargs(const void *fdt); -void __init device_tree_dump(const void *fdt); /** * dt_unflatten_host_device_tree - Unflatten the host device tree