Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Procedures for creating, accessing and interpreting the device tree. |
| 3 | * |
| 4 | * Paul Mackerras August 1996. |
| 5 | * Copyright (C) 1996-2005 Paul Mackerras. |
| 6 | * |
| 7 | * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner. |
| 8 | * {engebret|bergner}@us.ibm.com |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License |
| 12 | * as published by the Free Software Foundation; either version |
| 13 | * 2 of the License, or (at your option) any later version. |
| 14 | */ |
| 15 | |
| 16 | #include <stdarg.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/string.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/threads.h> |
| 21 | #include <linux/spinlock.h> |
| 22 | #include <linux/types.h> |
| 23 | #include <linux/pci.h> |
| 24 | #include <linux/stringify.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/initrd.h> |
| 27 | #include <linux/bitops.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/kexec.h> |
| 30 | #include <linux/debugfs.h> |
| 31 | #include <linux/irq.h> |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 32 | #include <linux/memblock.h> |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 33 | |
| 34 | #include <asm/prom.h> |
| 35 | #include <asm/page.h> |
| 36 | #include <asm/processor.h> |
| 37 | #include <asm/irq.h> |
| 38 | #include <linux/io.h> |
| 39 | #include <asm/system.h> |
| 40 | #include <asm/mmu.h> |
| 41 | #include <asm/pgtable.h> |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 42 | #include <asm/sections.h> |
| 43 | #include <asm/pci-bridge.h> |
| 44 | |
Grant Likely | 51975db | 2010-02-01 21:34:14 -0700 | [diff] [blame] | 45 | void __init early_init_dt_add_memory_arch(u64 base, u64 size) |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 46 | { |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 47 | memblock_add(base, size); |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 48 | } |
| 49 | |
Grant Likely | 672c544 | 2011-01-13 15:36:09 -0700 | [diff] [blame] | 50 | void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align) |
Jeremy Kerr | 4ef7b37 | 2010-02-14 07:13:47 -0700 | [diff] [blame] | 51 | { |
Grant Likely | 672c544 | 2011-01-13 15:36:09 -0700 | [diff] [blame] | 52 | return __va(memblock_alloc(size, align)); |
Jeremy Kerr | 4ef7b37 | 2010-02-14 07:13:47 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 55 | #ifdef CONFIG_EARLY_PRINTK |
Michal Simek | 2aa8e37 | 2011-04-14 11:48:43 +0200 | [diff] [blame] | 56 | char *stdout; |
| 57 | |
| 58 | int __init early_init_dt_scan_chosen_serial(unsigned long node, |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 59 | const char *uname, int depth, void *data) |
| 60 | { |
| 61 | unsigned long l; |
| 62 | char *p; |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 63 | |
Michal Simek | 2aa8e37 | 2011-04-14 11:48:43 +0200 | [diff] [blame] | 64 | pr_debug("%s: depth: %d, uname: %s\n", __func__, depth, uname); |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 65 | |
Michal Simek | 2aa8e37 | 2011-04-14 11:48:43 +0200 | [diff] [blame] | 66 | if (depth == 1 && (strcmp(uname, "chosen") == 0 || |
| 67 | strcmp(uname, "chosen@0") == 0)) { |
| 68 | p = of_get_flat_dt_prop(node, "linux,stdout-path", &l); |
| 69 | if (p != NULL && l > 0) |
| 70 | stdout = p; /* store pointer to stdout-path */ |
| 71 | } |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 72 | |
Michal Simek | 2aa8e37 | 2011-04-14 11:48:43 +0200 | [diff] [blame] | 73 | if (stdout && strstr(stdout, uname)) { |
| 74 | p = of_get_flat_dt_prop(node, "compatible", &l); |
| 75 | pr_debug("Compatible string: %s\n", p); |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 76 | |
Michal Simek | 2aa8e37 | 2011-04-14 11:48:43 +0200 | [diff] [blame] | 77 | if ((strncmp(p, "xlnx,xps-uart16550", 18) == 0) || |
| 78 | (strncmp(p, "xlnx,axi-uart16550", 18) == 0)) { |
| 79 | unsigned int addr; |
| 80 | |
| 81 | *(u32 *)data = UART16550; |
| 82 | |
| 83 | addr = *(u32 *)of_get_flat_dt_prop(node, "reg", &l); |
| 84 | addr += *(u32 *)of_get_flat_dt_prop(node, |
| 85 | "reg-offset", &l); |
| 86 | /* clear register offset */ |
| 87 | return be32_to_cpu(addr) & ~3; |
| 88 | } |
| 89 | if ((strncmp(p, "xlnx,xps-uartlite", 17) == 0) || |
| 90 | (strncmp(p, "xlnx,opb-uartlite", 17) == 0) || |
Michal Simek | ca12adc | 2011-04-06 13:06:45 +0200 | [diff] [blame^] | 91 | (strncmp(p, "xlnx,axi-uartlite", 17) == 0) || |
| 92 | (strncmp(p, "xlnx,mdm", 8) == 0)) { |
Michal Simek | 2aa8e37 | 2011-04-14 11:48:43 +0200 | [diff] [blame] | 93 | unsigned int *addrp; |
| 94 | |
| 95 | *(u32 *)data = UARTLITE; |
| 96 | |
| 97 | addrp = of_get_flat_dt_prop(node, "reg", &l); |
| 98 | return be32_to_cpup(addrp); /* return address */ |
| 99 | } |
| 100 | } |
| 101 | return 0; |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 102 | } |
| 103 | |
Michal Simek | 2aa8e37 | 2011-04-14 11:48:43 +0200 | [diff] [blame] | 104 | /* this function is looking for early console - Microblaze specific */ |
| 105 | int __init of_early_console(void *version) |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 106 | { |
Michal Simek | 2aa8e37 | 2011-04-14 11:48:43 +0200 | [diff] [blame] | 107 | return of_scan_flat_dt(early_init_dt_scan_chosen_serial, version); |
Michal Simek | 67f4aaa | 2010-09-28 16:17:03 +1000 | [diff] [blame] | 108 | } |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 109 | #endif |
| 110 | |
| 111 | void __init early_init_devtree(void *params) |
| 112 | { |
| 113 | pr_debug(" -> early_init_devtree(%p)\n", params); |
| 114 | |
| 115 | /* Setup flat device-tree pointer */ |
| 116 | initial_boot_params = params; |
| 117 | |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 118 | /* Retrieve various informations from the /chosen node of the |
| 119 | * device-tree, including the platform type, initrd location and |
| 120 | * size, TCE reserve, and more ... |
| 121 | */ |
Grant Likely | 85f60ae | 2011-04-29 00:18:16 -0600 | [diff] [blame] | 122 | of_scan_flat_dt(early_init_dt_scan_chosen, cmd_line); |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 123 | |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 124 | /* Scan memory nodes and rebuild MEMBLOCKs */ |
| 125 | memblock_init(); |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 126 | of_scan_flat_dt(early_init_dt_scan_root, NULL); |
| 127 | of_scan_flat_dt(early_init_dt_scan_memory, NULL); |
| 128 | |
| 129 | /* Save command line for /proc/cmdline and then parse parameters */ |
| 130 | strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE); |
| 131 | parse_early_param(); |
| 132 | |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 133 | memblock_analyze(); |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 134 | |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 135 | pr_debug("Phys. mem: %lx\n", (unsigned long) memblock_phys_mem_size()); |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 136 | |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 137 | pr_debug(" <- early_init_devtree()\n"); |
| 138 | } |
| 139 | |
Jeremy Kerr | 1406bc2 | 2010-01-30 01:31:21 -0700 | [diff] [blame] | 140 | #ifdef CONFIG_BLK_DEV_INITRD |
| 141 | void __init early_init_dt_setup_initrd_arch(unsigned long start, |
| 142 | unsigned long end) |
| 143 | { |
| 144 | initrd_start = (unsigned long)__va(start); |
| 145 | initrd_end = (unsigned long)__va(end); |
| 146 | initrd_below_start_ok = 1; |
| 147 | } |
| 148 | #endif |
| 149 | |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 150 | /******* |
| 151 | * |
| 152 | * New implementation of the OF "find" APIs, return a refcounted |
| 153 | * object, call of_node_put() when done. The device tree and list |
| 154 | * are protected by a rw_lock. |
| 155 | * |
| 156 | * Note that property management will need some locking as well, |
| 157 | * this isn't dealt with yet. |
| 158 | * |
| 159 | *******/ |
| 160 | |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 161 | #if defined(CONFIG_DEBUG_FS) && defined(DEBUG) |
| 162 | static struct debugfs_blob_wrapper flat_dt_blob; |
| 163 | |
| 164 | static int __init export_flat_device_tree(void) |
| 165 | { |
| 166 | struct dentry *d; |
| 167 | |
| 168 | flat_dt_blob.data = initial_boot_params; |
| 169 | flat_dt_blob.size = initial_boot_params->totalsize; |
| 170 | |
| 171 | d = debugfs_create_blob("flat-device-tree", S_IFREG | S_IRUSR, |
| 172 | of_debugfs_root, &flat_dt_blob); |
| 173 | if (!d) |
| 174 | return 1; |
| 175 | |
| 176 | return 0; |
| 177 | } |
| 178 | device_initcall(export_flat_device_tree); |
| 179 | #endif |