From patchwork Mon Jun 16 11:44:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 31954 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f70.google.com (mail-yh0-f70.google.com [209.85.213.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 33D8C206A0 for ; Mon, 16 Jun 2014 11:46:56 +0000 (UTC) Received: by mail-yh0-f70.google.com with SMTP id a41sf25961365yho.5 for ; Mon, 16 Jun 2014 04:46:56 -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=ene0QoGmpK4q75EIvooY9KTsj9YhpukkjdhpxBzlY2s=; b=dJp5c0pvxBpkqFaEa8/QRqhmewNnPc6caw9/1h5xKOkml16OGXY7xVHS5heQf968oY NNy5094d29OPakbmY0Ktq/8A22n7fFKX0YLZZ8NzFjeULfF3Hj10xJ1EWNMzp3aFh2Ea cb2vNH41GNpOzmwNDEBmBqH860rDca6Gh1qrfUj9zsEDyje7jcABsR/Lbm20961Nip+t kJDi9gaKjG34wt870orim9m72fbXGpOablJ7kUKcM/y9+CHoa4Eww8iA6672BTd0ylzQ 9lvpCjP6ZDU7vJ5fsQfk3xYDvBnly/u5meCtJpPq/xQYWvQs1gTJT0E5L/nFH1CcF9xj BWCA== X-Gm-Message-State: ALoCoQl5M+1m023+3oOKRQcAbQh7JMmLNdMHi0fddcNy0FHEtOLif3tdZeTLxwaowZiqY/fPcSPn X-Received: by 10.58.187.68 with SMTP id fq4mr3492870vec.0.1402919215972; Mon, 16 Jun 2014 04:46:55 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.97.7 with SMTP id l7ls1598193qge.63.gmail; Mon, 16 Jun 2014 04:46:55 -0700 (PDT) X-Received: by 10.58.246.132 with SMTP id xw4mr15944792vec.2.1402919215814; Mon, 16 Jun 2014 04:46:55 -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 sk5si4000170vcb.107.2014.06.16.04.46.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Jun 2014 04:46:55 -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 jz11so5941484veb.31 for ; Mon, 16 Jun 2014 04:46:55 -0700 (PDT) X-Received: by 10.221.9.72 with SMTP id ov8mr3125451vcb.27.1402919215711; Mon, 16 Jun 2014 04:46:55 -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.54.6 with SMTP id vs6csp128514vcb; Mon, 16 Jun 2014 04:46:55 -0700 (PDT) X-Received: by 10.52.179.38 with SMTP id dd6mr13393158vdc.21.1402919215179; Mon, 16 Jun 2014 04:46:55 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id c10si3993391vdg.83.2014.06.16.04.46.54 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 16 Jun 2014 04:46:55 -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 1WwVLw-0003ce-9V; Mon, 16 Jun 2014 11:45:32 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WwVLc-0003NP-0O for xen-devel@lists.xen.org; Mon, 16 Jun 2014 11:45:12 +0000 Received: from [85.158.139.211:12004] by server-12.bemta-5.messagelabs.com id 1A/22-27841-6C8DE935; Mon, 16 Jun 2014 11:45:10 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-6.tower-206.messagelabs.com!1402919104!10179946!5 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 5803 invoked from network); 16 Jun 2014 11:45:09 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-6.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 16 Jun 2014 11:45:09 -0000 X-IronPort-AV: E=Sophos;i="5.01,486,1400025600"; d="scan'208";a="143697250" Received: from accessns.citrite.net (HELO FTLPEX01CL02.citrite.net) ([10.9.154.239]) by FTLPIPO02.CITRIX.COM with ESMTP; 16 Jun 2014 11:45:05 +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; Mon, 16 Jun 2014 07:45:04 -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 1WwVLT-000152-VD; Mon, 16 Jun 2014 12:45:03 +0100 From: Ian Campbell To: Date: Mon, 16 Jun 2014 12:44:58 +0100 Message-ID: <1402919103-29642-5-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1402919079.14907.22.camel@kazak.uk.xensource.com> References: <1402919079.14907.22.camel@kazak.uk.xensource.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: Ian Campbell , stefano.stabellini@eu.citrix.com, Naresh Bhat , julien.grall@linaro.org, tim@xen.org, Roy Franz , Fu Wei Subject: [Xen-devel] [PATCH 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.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 flattended device tree out of device_tree.c. The intention is that eventually only 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