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> |
| 32 | #include <linux/lmb.h> |
| 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 | |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 45 | /* export that to outside world */ |
| 46 | struct device_node *of_chosen; |
| 47 | |
Grant Likely | 86e0322 | 2009-12-10 23:42:21 -0700 | [diff] [blame] | 48 | void __init early_init_dt_scan_chosen_arch(unsigned long node) |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 49 | { |
Grant Likely | 86e0322 | 2009-12-10 23:42:21 -0700 | [diff] [blame] | 50 | /* No Microblaze specific code here */ |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 51 | } |
| 52 | |
Grant Likely | 51975db | 2010-02-01 21:34:14 -0700 | [diff] [blame^] | 53 | void __init early_init_dt_add_memory_arch(u64 base, u64 size) |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 54 | { |
Grant Likely | 51975db | 2010-02-01 21:34:14 -0700 | [diff] [blame^] | 55 | lmb_add(base, size); |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 56 | } |
| 57 | |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 58 | #ifdef CONFIG_EARLY_PRINTK |
| 59 | /* MS this is Microblaze specifig function */ |
| 60 | static int __init early_init_dt_scan_serial(unsigned long node, |
| 61 | const char *uname, int depth, void *data) |
| 62 | { |
| 63 | unsigned long l; |
| 64 | char *p; |
| 65 | int *addr; |
| 66 | |
| 67 | pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname); |
| 68 | |
| 69 | /* find all serial nodes */ |
| 70 | if (strncmp(uname, "serial", 6) != 0) |
| 71 | return 0; |
| 72 | |
| 73 | early_init_dt_check_for_initrd(node); |
| 74 | |
| 75 | /* find compatible node with uartlite */ |
| 76 | p = of_get_flat_dt_prop(node, "compatible", &l); |
| 77 | if ((strncmp(p, "xlnx,xps-uartlite", 17) != 0) && |
| 78 | (strncmp(p, "xlnx,opb-uartlite", 17) != 0)) |
| 79 | return 0; |
| 80 | |
| 81 | addr = of_get_flat_dt_prop(node, "reg", &l); |
| 82 | return *addr; /* return address */ |
| 83 | } |
| 84 | |
| 85 | /* this function is looking for early uartlite console - Microblaze specific */ |
| 86 | int __init early_uartlite_console(void) |
| 87 | { |
| 88 | return of_scan_flat_dt(early_init_dt_scan_serial, NULL); |
| 89 | } |
| 90 | #endif |
| 91 | |
| 92 | void __init early_init_devtree(void *params) |
| 93 | { |
| 94 | pr_debug(" -> early_init_devtree(%p)\n", params); |
| 95 | |
| 96 | /* Setup flat device-tree pointer */ |
| 97 | initial_boot_params = params; |
| 98 | |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 99 | /* Retrieve various informations from the /chosen node of the |
| 100 | * device-tree, including the platform type, initrd location and |
| 101 | * size, TCE reserve, and more ... |
| 102 | */ |
| 103 | of_scan_flat_dt(early_init_dt_scan_chosen, NULL); |
| 104 | |
| 105 | /* Scan memory nodes and rebuild LMBs */ |
| 106 | lmb_init(); |
| 107 | of_scan_flat_dt(early_init_dt_scan_root, NULL); |
| 108 | of_scan_flat_dt(early_init_dt_scan_memory, NULL); |
| 109 | |
| 110 | /* Save command line for /proc/cmdline and then parse parameters */ |
| 111 | strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE); |
| 112 | parse_early_param(); |
| 113 | |
| 114 | lmb_analyze(); |
| 115 | |
| 116 | pr_debug("Phys. mem: %lx\n", (unsigned long) lmb_phys_mem_size()); |
| 117 | |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 118 | pr_debug(" <- early_init_devtree()\n"); |
| 119 | } |
| 120 | |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 121 | /******* |
| 122 | * |
| 123 | * New implementation of the OF "find" APIs, return a refcounted |
| 124 | * object, call of_node_put() when done. The device tree and list |
| 125 | * are protected by a rw_lock. |
| 126 | * |
| 127 | * Note that property management will need some locking as well, |
| 128 | * this isn't dealt with yet. |
| 129 | * |
| 130 | *******/ |
| 131 | |
Michal Simek | 12e8414 | 2009-03-27 14:25:12 +0100 | [diff] [blame] | 132 | #if defined(CONFIG_DEBUG_FS) && defined(DEBUG) |
| 133 | static struct debugfs_blob_wrapper flat_dt_blob; |
| 134 | |
| 135 | static int __init export_flat_device_tree(void) |
| 136 | { |
| 137 | struct dentry *d; |
| 138 | |
| 139 | flat_dt_blob.data = initial_boot_params; |
| 140 | flat_dt_blob.size = initial_boot_params->totalsize; |
| 141 | |
| 142 | d = debugfs_create_blob("flat-device-tree", S_IFREG | S_IRUSR, |
| 143 | of_debugfs_root, &flat_dt_blob); |
| 144 | if (!d) |
| 145 | return 1; |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | device_initcall(export_flat_device_tree); |
| 150 | #endif |