PageRenderTime 39ms CodeModel.GetById 16ms app.highlight 17ms RepoModel.GetById 2ms app.codeStats 0ms

/Ethereal-msm8939-beta9/arch/metag/kernel/devtree.c

https://bitbucket.org/MilosStamenkovic95/etherealos
C | 114 lines | 71 code | 15 blank | 28 comment | 10 complexity | d9006c482e17c1e125ed13cca469b783 MD5 | raw file
  1/*
  2 *  linux/arch/metag/kernel/devtree.c
  3 *
  4 *  Copyright (C) 2012 Imagination Technologies Ltd.
  5 *
  6 *  Based on ARM version:
  7 *  Copyright (C) 2009 Canonical Ltd. <jeremy.kerr@canonical.com>
  8 *
  9 * This program is free software; you can redistribute it and/or modify
 10 * it under the terms of the GNU General Public License version 2 as
 11 * published by the Free Software Foundation.
 12 */
 13
 14#include <linux/init.h>
 15#include <linux/export.h>
 16#include <linux/types.h>
 17#include <linux/bootmem.h>
 18#include <linux/memblock.h>
 19#include <linux/of.h>
 20#include <linux/of_fdt.h>
 21
 22#include <asm/setup.h>
 23#include <asm/page.h>
 24#include <asm/mach/arch.h>
 25
 26void __init early_init_dt_add_memory_arch(u64 base, u64 size)
 27{
 28	pr_err("%s(%llx, %llx)\n",
 29	       __func__, base, size);
 30}
 31
 32void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
 33{
 34	return alloc_bootmem_align(size, align);
 35}
 36
 37/**
 38 * setup_machine_fdt - Machine setup when an dtb was passed to the kernel
 39 * @dt:		virtual address pointer to dt blob
 40 *
 41 * If a dtb was passed to the kernel, then use it to choose the correct
 42 * machine_desc and to setup the system.
 43 */
 44struct machine_desc * __init setup_machine_fdt(void *dt)
 45{
 46	struct boot_param_header *devtree = dt;
 47	struct machine_desc *mdesc, *mdesc_best = NULL;
 48	unsigned int score, mdesc_score = ~1;
 49	unsigned long dt_root;
 50	const char *model;
 51
 52	/* check device tree validity */
 53	if (be32_to_cpu(devtree->magic) != OF_DT_HEADER)
 54		return NULL;
 55
 56	/* Search the mdescs for the 'best' compatible value match */
 57	initial_boot_params = devtree;
 58	dt_root = of_get_flat_dt_root();
 59
 60	for_each_machine_desc(mdesc) {
 61		score = of_flat_dt_match(dt_root, mdesc->dt_compat);
 62		if (score > 0 && score < mdesc_score) {
 63			mdesc_best = mdesc;
 64			mdesc_score = score;
 65		}
 66	}
 67	if (!mdesc_best) {
 68		const char *prop;
 69		long size;
 70
 71		pr_err("\nError: unrecognized/unsupported device tree compatible list:\n[ ");
 72
 73		prop = of_get_flat_dt_prop(dt_root, "compatible", &size);
 74		if (prop) {
 75			while (size > 0) {
 76				printk("'%s' ", prop);
 77				size -= strlen(prop) + 1;
 78				prop += strlen(prop) + 1;
 79			}
 80		}
 81		printk("]\n\n");
 82
 83		dump_machine_table(); /* does not return */
 84	}
 85
 86	model = of_get_flat_dt_prop(dt_root, "model", NULL);
 87	if (!model)
 88		model = of_get_flat_dt_prop(dt_root, "compatible", NULL);
 89	if (!model)
 90		model = "<unknown>";
 91	pr_info("Machine: %s, model: %s\n", mdesc_best->name, model);
 92
 93	/* Retrieve various information from the /chosen node */
 94	of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
 95
 96	return mdesc_best;
 97}
 98
 99/**
100 * copy_fdt - Copy device tree into non-init memory.
101 *
102 * We must copy the flattened device tree blob into non-init memory because the
103 * unflattened device tree will reference the strings in it directly.
104 */
105void __init copy_fdt(void)
106{
107	void *alloc = early_init_dt_alloc_memory_arch(
108			be32_to_cpu(initial_boot_params->totalsize), 0x40);
109	if (alloc) {
110		memcpy(alloc, initial_boot_params,
111		       be32_to_cpu(initial_boot_params->totalsize));
112		initial_boot_params = alloc;
113	}
114}