From patchwork Thu Jun 26 16:45:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 32580 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f200.google.com (mail-qc0-f200.google.com [209.85.216.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id ED6A420E7A for ; Thu, 26 Jun 2014 16:47:38 +0000 (UTC) Received: by mail-qc0-f200.google.com with SMTP id o8sf6823972qcw.7 for ; Thu, 26 Jun 2014 09:47:38 -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=nqEQkq5bIMkRgIj14x+M1KlcMCpuEBIWoSuRbV0k1PY=; b=fMNUAwXx5kcX8nnXgv68Xi0FZWEVT3lJ6DkNmY3wt0h8OkR+jASnsjweG3jFfqV6BE yCgfsQUlr2EEYVhHnbYANwI2q0yL4jzG7BhwDjGdenVf+EJ8J78Rvn7mmo79Ds8IKHTT A+6Sm27rR5ELWP4CsXkbglCgFDl6elsfNqPcpY5g7LnM5rD97o69UjSjsI4DVnKvS4HQ n3GwoNE4CYzk83YfamW/DIlZ7uHsy/VKj1y1pMa2aphnp6Tmk7Pk3s3bOKuxpQC2e/R4 Qss7QmwIZCd0y0u3ueIbVGLjv3QDUFHhElqE3d2vFK5S1qjglo2htO4YG2f9z18VQ1wC Py9A== X-Gm-Message-State: ALoCoQlbBCDyjSmQACOrj6tgSfYrPNEoteddEKhmKnQzP/0C5JzkgOQ+sS6/C44HsMZ5o0TDxG6n X-Received: by 10.52.146.133 with SMTP id tc5mr7509955vdb.6.1403801258630; Thu, 26 Jun 2014 09:47:38 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.17.19 with SMTP id 19ls297915qgc.69.gmail; Thu, 26 Jun 2014 09:47:38 -0700 (PDT) X-Received: by 10.58.116.4 with SMTP id js4mr3768499veb.38.1403801258503; Thu, 26 Jun 2014 09:47:38 -0700 (PDT) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id j8si4892752vcr.60.2014.06.26.09.47.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 26 Jun 2014 09:47:38 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.172 as permitted sender) client-ip=209.85.128.172; Received: by mail-ve0-f172.google.com with SMTP id jz11so3990037veb.17 for ; Thu, 26 Jun 2014 09:47:38 -0700 (PDT) X-Received: by 10.58.188.199 with SMTP id gc7mr10922115vec.4.1403801258410; Thu, 26 Jun 2014 09:47:38 -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 tc5csp44108vcb; Thu, 26 Jun 2014 09:47:38 -0700 (PDT) X-Received: by 10.224.8.9 with SMTP id f9mr24157789qaf.102.1403801257737; Thu, 26 Jun 2014 09:47:37 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id 107si10132462qgn.94.2014.06.26.09.47.37 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 26 Jun 2014 09:47:37 -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 1X0CoI-0004P1-Ku; Thu, 26 Jun 2014 16:46:06 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X0CoC-0004L7-Rq for xen-devel@lists.xen.org; Thu, 26 Jun 2014 16:46:01 +0000 Received: from [193.109.254.147:29211] by server-6.bemta-14.messagelabs.com id FA/1D-13066-84E4CA35; Thu, 26 Jun 2014 16:46:00 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-9.tower-27.messagelabs.com!1403801153!13922171!4 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 986 invoked from network); 26 Jun 2014 16:45:57 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-9.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 26 Jun 2014 16:45:57 -0000 X-IronPort-AV: E=Sophos;i="5.01,554,1400025600"; d="scan'208";a="147655586" Received: from accessns.citrite.net (HELO FTLPEX01CL01.citrite.net) ([10.9.154.239]) by FTLPIPO01.CITRIX.COM with ESMTP; 26 Jun 2014 16:45:53 +0000 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.78) with Microsoft SMTP Server id 14.3.181.6; Thu, 26 Jun 2014 12:45:52 -0400 Received: from marilith-n13-p0.uk.xensource.com ([10.80.229.115] helo=marilith-n13.uk.xensource.com.) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1X0Co3-0002AU-T3; Thu, 26 Jun 2014 17:45:51 +0100 From: Ian Campbell To: Date: Thu, 26 Jun 2014 17:45:47 +0100 Message-ID: <1403801151-11007-5-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1403801130.31742.1.camel@kazak.uk.xensource.com> References: <1403801130.31742.1.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 v2 5/9] 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.128.172 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 | 343 +++++++++++++++++++++++++++++++++++++++ xen/arch/arm/setup.c | 2 +- xen/common/device_tree.c | 356 ----------------------------------------- xen/include/asm-arm/setup.h | 2 + xen/include/xen/device_tree.h | 3 - 6 files changed, 347 insertions(+), 360 deletions(-) create mode 100644 xen/arch/arm/bootfdt.c diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 63e0460..58a6714 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..11182cd --- /dev/null +++ b/xen/arch/arm/bootfdt.c @@ -0,0 +1,343 @@ +/* + * 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); + 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 63f6b8e..4a84a32 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -678,7 +678,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 a1896d3..89de269 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,255 +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); - 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 74e98f5..0edec85 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -157,10 +157,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