Linux Audio

Check our new training course

Loading...
v3.5.6
 
  1/*
  2 * MIPS support for CONFIG_OF device tree support
  3 *
  4 * Copyright (C) 2010 Cisco Systems Inc. <dediao@cisco.com>
  5 *
  6 * This program is free software; you can redistribute it and/or modify
  7 * it under the terms of the GNU General Public License version 2 as
  8 * published by the Free Software Foundation.
  9 */
 10
 11#include <linux/init.h>
 12#include <linux/export.h>
 13#include <linux/errno.h>
 14#include <linux/types.h>
 15#include <linux/bootmem.h>
 16#include <linux/initrd.h>
 17#include <linux/debugfs.h>
 18#include <linux/of.h>
 19#include <linux/of_fdt.h>
 20#include <linux/of_irq.h>
 21#include <linux/of_platform.h>
 22
 
 23#include <asm/page.h>
 24#include <asm/prom.h>
 25
 26int __init early_init_dt_scan_memory_arch(unsigned long node,
 27					  const char *uname, int depth,
 28					  void *data)
 29{
 30	return early_init_dt_scan_memory(node, uname, depth, data);
 31}
 32
 33void __init early_init_dt_add_memory_arch(u64 base, u64 size)
 34{
 35	return add_memory_region(base, size, BOOT_MEM_RAM);
 36}
 37
 38int __init reserve_mem_mach(unsigned long addr, unsigned long size)
 39{
 40	return reserve_bootmem(addr, size, BOOTMEM_DEFAULT);
 41}
 42
 43void __init free_mem_mach(unsigned long addr, unsigned long size)
 44{
 45	return free_bootmem(addr, size);
 46}
 47
 48void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
 
 49{
 50	return __alloc_bootmem(size, align, __pa(MAX_DMA_ADDRESS));
 51}
 
 
 52
 53#ifdef CONFIG_BLK_DEV_INITRD
 54void __init early_init_dt_setup_initrd_arch(unsigned long start,
 55					    unsigned long end)
 56{
 57	initrd_start = (unsigned long)__va(start);
 58	initrd_end = (unsigned long)__va(end);
 59	initrd_below_start_ok = 1;
 
 60}
 61#endif
 62
 63void __init early_init_devtree(void *params)
 
 64{
 65	/* Setup flat device-tree pointer */
 66	initial_boot_params = params;
 67
 68	/* Retrieve various informations from the /chosen node of the
 69	 * device-tree, including the platform type, initrd location and
 70	 * size, and more ...
 71	 */
 72	of_scan_flat_dt(early_init_dt_scan_chosen, arcs_cmdline);
 73
 74
 75	/* Scan memory nodes */
 76	of_scan_flat_dt(early_init_dt_scan_root, NULL);
 77	of_scan_flat_dt(early_init_dt_scan_memory_arch, NULL);
 78}
 79
 80void __init device_tree_init(void)
 81{
 82	unsigned long base, size;
 83
 84	if (!initial_boot_params)
 85		return;
 86
 87	base = virt_to_phys((void *)initial_boot_params);
 88	size = be32_to_cpu(initial_boot_params->totalsize);
 89
 90	/* Before we do anything, lets reserve the dt blob */
 91	reserve_mem_mach(base, size);
 92
 93	unflatten_device_tree();
 94
 95	/* free the space reserved for the dt blob */
 96	free_mem_mach(base, size);
 97}
 98
 99void __init __dt_setup_arch(struct boot_param_header *bph)
100{
101	if (be32_to_cpu(bph->magic) != OF_DT_HEADER) {
102		pr_err("DTB has bad magic, ignoring builtin OF DTB\n");
103
104		return;
 
 
 
 
 
 
105	}
106
107	initial_boot_params = bph;
 
108
109	early_init_devtree(initial_boot_params);
110}
v5.9
 1// SPDX-License-Identifier: GPL-2.0-only
 2/*
 3 * MIPS support for CONFIG_OF device tree support
 4 *
 5 * Copyright (C) 2010 Cisco Systems Inc. <dediao@cisco.com>
 
 
 
 
 6 */
 7
 8#include <linux/init.h>
 9#include <linux/export.h>
10#include <linux/errno.h>
11#include <linux/types.h>
12#include <linux/memblock.h>
 
13#include <linux/debugfs.h>
14#include <linux/of.h>
15#include <linux/of_fdt.h>
 
16#include <linux/of_platform.h>
17
18#include <asm/bootinfo.h>
19#include <asm/page.h>
20#include <asm/prom.h>
21
22static char mips_machine_name[64] = "Unknown";
 
 
 
 
 
23
24__init void mips_set_machine_name(const char *name)
25{
26	if (name == NULL)
27		return;
28
29	strlcpy(mips_machine_name, name, sizeof(mips_machine_name));
30	pr_info("MIPS: machine is %s\n", mips_get_machine_name());
 
31}
32
33char *mips_get_machine_name(void)
34{
35	return mips_machine_name;
36}
37
38#ifdef CONFIG_USE_OF
39void __init early_init_dt_add_memory_arch(u64 base, u64 size)
40{
41	if (base >= PHYS_ADDR_MAX) {
42		pr_warn("Trying to add an invalid memory region, skipped\n");
43		return;
44	}
45
46	/* Truncate the passed memory region instead of type casting */
47	if (base + size - 1 >= PHYS_ADDR_MAX || base + size < base) {
48		pr_warn("Truncate memory region %llx @ %llx to size %llx\n",
49			size, base, PHYS_ADDR_MAX - base);
50		size = PHYS_ADDR_MAX - base;
51	}
52
53	add_memory_region(base, size, BOOT_MEM_RAM);
54}
 
55
56int __init early_init_dt_reserve_memory_arch(phys_addr_t base,
57					phys_addr_t size, bool nomap)
58{
59	add_memory_region(base, size,
60			  nomap ? BOOT_MEM_NOMAP : BOOT_MEM_RESERVED);
 
 
 
 
 
 
61
62	return 0;
 
 
 
63}
64
65void __init __dt_setup_arch(void *bph)
66{
67	if (!early_init_dt_scan(bph))
 
 
68		return;
69
70	mips_set_machine_name(of_flat_dt_get_machine_name());
 
 
 
 
 
 
 
 
 
71}
72
73int __init __dt_register_buses(const char *bus0, const char *bus1)
74{
75	static struct of_device_id of_ids[3];
 
76
77	if (!of_have_populated_dt())
78		panic("device tree not present");
79
80	strlcpy(of_ids[0].compatible, bus0, sizeof(of_ids[0].compatible));
81	if (bus1) {
82		strlcpy(of_ids[1].compatible, bus1,
83			sizeof(of_ids[1].compatible));
84	}
85
86	if (of_platform_populate(NULL, of_ids, NULL, NULL))
87		panic("failed to populate DT");
88
89	return 0;
90}
91
92#endif