Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame] | 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * PROM library functions for acquiring/using memory descriptors given to |
| 7 | * us from the YAMON. |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame] | 8 | * |
| 9 | * Copyright (C) 1999,2000,2012 MIPS Technologies, Inc. |
| 10 | * All rights reserved. |
| 11 | * Authors: Carsten Langgaard <carstenl@mips.com> |
| 12 | * Steven J. Hill <sjhill@mips.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/bootmem.h> |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 16 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | #include <asm/bootinfo.h> |
Paul Burton | 3a551e2 | 2014-07-14 12:37:39 +0100 | [diff] [blame] | 19 | #include <asm/maar.h> |
Ralf Baechle | 9c1f125 | 2006-04-03 10:17:21 +0100 | [diff] [blame] | 20 | #include <asm/sections.h> |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 21 | #include <asm/fw/fw.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 23 | static fw_memblock_t mdesc[FW_MAX_MEMBLOCKS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 25 | /* determined physical memory size, not overridden by command line args */ |
Ralf Baechle | e1a4e46 | 2006-07-03 17:02:35 +0100 | [diff] [blame] | 26 | unsigned long physical_memsize = 0L; |
| 27 | |
Markos Chandras | e6ca4e5 | 2014-01-15 13:55:07 +0000 | [diff] [blame] | 28 | fw_memblock_t * __init fw_getmdesc(int eva) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | { |
Markos Chandras | acd8bc1 | 2014-05-23 13:31:32 +0100 | [diff] [blame] | 30 | char *memsize_str, *ememsize_str = NULL, *ptr; |
Ralf Baechle | f8647b5 | 2014-06-04 22:53:02 +0200 | [diff] [blame] | 31 | unsigned long memsize = 0, ememsize = 0; |
Dmitri Vorobiev | 7580c9c | 2009-10-13 23:43:24 +0300 | [diff] [blame] | 32 | static char cmdline[COMMAND_LINE_SIZE] __initdata; |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame] | 33 | int tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Ralf Baechle | e1a4e46 | 2006-07-03 17:02:35 +0100 | [diff] [blame] | 35 | /* otherwise look in the environment */ |
Markos Chandras | e6ca4e5 | 2014-01-15 13:55:07 +0000 | [diff] [blame] | 36 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 37 | memsize_str = fw_getenv("memsize"); |
Markos Chandras | 6461568 | 2014-08-18 15:04:11 +0100 | [diff] [blame^] | 38 | if (memsize_str) { |
| 39 | tmp = kstrtoul(memsize_str, 0, &memsize); |
| 40 | if (tmp) |
| 41 | pr_warn("Failed to read the 'memsize' env variable.\n"); |
| 42 | } |
Markos Chandras | e6ca4e5 | 2014-01-15 13:55:07 +0000 | [diff] [blame] | 43 | if (eva) { |
| 44 | /* Look for ememsize for EVA */ |
| 45 | ememsize_str = fw_getenv("ememsize"); |
Markos Chandras | 6461568 | 2014-08-18 15:04:11 +0100 | [diff] [blame^] | 46 | if (ememsize_str) { |
| 47 | tmp = kstrtoul(ememsize_str, 0, &ememsize); |
| 48 | if (tmp) |
| 49 | pr_warn("Failed to read the 'ememsize' env variable.\n"); |
| 50 | } |
Markos Chandras | e6ca4e5 | 2014-01-15 13:55:07 +0000 | [diff] [blame] | 51 | } |
| 52 | if (!memsize && !ememsize) { |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame] | 53 | pr_warn("memsize not set in YAMON, set to default (32Mb)\n"); |
Ralf Baechle | e1a4e46 | 2006-07-03 17:02:35 +0100 | [diff] [blame] | 54 | physical_memsize = 0x02000000; |
| 55 | } else { |
Markos Chandras | e6ca4e5 | 2014-01-15 13:55:07 +0000 | [diff] [blame] | 56 | /* If ememsize is set, then set physical_memsize to that */ |
| 57 | physical_memsize = ememsize ? : memsize; |
Ralf Baechle | e1a4e46 | 2006-07-03 17:02:35 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | #ifdef CONFIG_CPU_BIG_ENDIAN |
| 61 | /* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last |
| 62 | word of physical memory */ |
| 63 | physical_memsize -= PAGE_SIZE; |
| 64 | #endif |
| 65 | |
| 66 | /* Check the command line for a memsize directive that overrides |
| 67 | the physical/default amount */ |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 68 | strcpy(cmdline, arcs_cmdline); |
| 69 | ptr = strstr(cmdline, "memsize="); |
| 70 | if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' ')) |
| 71 | ptr = strstr(ptr, " memsize="); |
Markos Chandras | e6ca4e5 | 2014-01-15 13:55:07 +0000 | [diff] [blame] | 72 | /* And now look for ememsize */ |
| 73 | if (eva) { |
| 74 | ptr = strstr(cmdline, "ememsize="); |
| 75 | if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' ')) |
| 76 | ptr = strstr(ptr, " ememsize="); |
| 77 | } |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 78 | |
Ralf Baechle | e1a4e46 | 2006-07-03 17:02:35 +0100 | [diff] [blame] | 79 | if (ptr) |
Markos Chandras | e6ca4e5 | 2014-01-15 13:55:07 +0000 | [diff] [blame] | 80 | memsize = memparse(ptr + 8 + (eva ? 1 : 0), &ptr); |
Ralf Baechle | e1a4e46 | 2006-07-03 17:02:35 +0100 | [diff] [blame] | 81 | else |
| 82 | memsize = physical_memsize; |
Elizabeth Oldham | 7349968 | 2006-06-06 10:57:09 +0100 | [diff] [blame] | 83 | |
Markos Chandras | e6ca4e5 | 2014-01-15 13:55:07 +0000 | [diff] [blame] | 84 | /* Last 64K for HIGHMEM arithmetics */ |
| 85 | if (memsize > 0x7fff0000) |
| 86 | memsize = 0x7fff0000; |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | memset(mdesc, 0, sizeof(mdesc)); |
| 89 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 90 | mdesc[0].type = fw_dontuse; |
Markos Chandras | 3bdd8e6 | 2014-01-15 14:13:05 +0000 | [diff] [blame] | 91 | mdesc[0].base = PHYS_OFFSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | mdesc[0].size = 0x00001000; |
| 93 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 94 | mdesc[1].type = fw_code; |
Markos Chandras | 3bdd8e6 | 2014-01-15 14:13:05 +0000 | [diff] [blame] | 95 | mdesc[1].base = mdesc[0].base + 0x00001000UL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | mdesc[1].size = 0x000ef000; |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | /* |
| 99 | * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the |
| 100 | * south bridge and PCI access always forwarded to the ISA Bus and |
| 101 | * BIOSCS# is always generated. |
| 102 | * This mean that this area can't be used as DMA memory for PCI |
| 103 | * devices. |
| 104 | */ |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 105 | mdesc[2].type = fw_dontuse; |
Markos Chandras | 3bdd8e6 | 2014-01-15 14:13:05 +0000 | [diff] [blame] | 106 | mdesc[2].base = mdesc[0].base + 0x000f0000UL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | mdesc[2].size = 0x00010000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 109 | mdesc[3].type = fw_dontuse; |
Markos Chandras | 3bdd8e6 | 2014-01-15 14:13:05 +0000 | [diff] [blame] | 110 | mdesc[3].base = mdesc[0].base + 0x00100000UL; |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame] | 111 | mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) - |
Markos Chandras | 3bdd8e6 | 2014-01-15 14:13:05 +0000 | [diff] [blame] | 112 | 0x00100000UL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 114 | mdesc[4].type = fw_free; |
Markos Chandras | 3bdd8e6 | 2014-01-15 14:13:05 +0000 | [diff] [blame] | 115 | mdesc[4].base = mdesc[0].base + CPHYSADDR(PFN_ALIGN(&_end)); |
| 116 | mdesc[4].size = memsize - CPHYSADDR(mdesc[4].base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
| 118 | return &mdesc[0]; |
| 119 | } |
| 120 | |
Markos Chandras | d1965c0 | 2014-01-15 14:07:57 +0000 | [diff] [blame] | 121 | static void free_init_pages_eva_malta(void *begin, void *end) |
| 122 | { |
| 123 | free_init_pages("unused kernel", __pa_symbol((unsigned long *)begin), |
| 124 | __pa_symbol((unsigned long *)end)); |
| 125 | } |
| 126 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 127 | static int __init fw_memtype_classify(unsigned int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { |
| 129 | switch (type) { |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 130 | case fw_free: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | return BOOT_MEM_RAM; |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 132 | case fw_code: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | return BOOT_MEM_ROM_DATA; |
| 134 | default: |
| 135 | return BOOT_MEM_RESERVED; |
| 136 | } |
| 137 | } |
| 138 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 139 | void __init fw_meminit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | { |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 141 | fw_memblock_t *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Markos Chandras | e6ca4e5 | 2014-01-15 13:55:07 +0000 | [diff] [blame] | 143 | p = fw_getmdesc(config_enabled(CONFIG_EVA)); |
Markos Chandras | d1965c0 | 2014-01-15 14:07:57 +0000 | [diff] [blame] | 144 | free_init_pages_eva = (config_enabled(CONFIG_EVA) ? |
| 145 | free_init_pages_eva_malta : NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
| 147 | while (p->size) { |
| 148 | long type; |
| 149 | unsigned long base, size; |
| 150 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 151 | type = fw_memtype_classify(p->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | base = p->base; |
| 153 | size = p->size; |
| 154 | |
| 155 | add_memory_region(base, size, type); |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 156 | p++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | |
Atsushi Nemoto | c44e8d5 | 2006-12-30 00:43:59 +0900 | [diff] [blame] | 160 | void __init prom_free_prom_memory(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | unsigned long addr; |
| 163 | int i; |
| 164 | |
| 165 | for (i = 0; i < boot_mem_map.nr_map; i++) { |
| 166 | if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA) |
| 167 | continue; |
| 168 | |
Atsushi Nemoto | c44e8d5 | 2006-12-30 00:43:59 +0900 | [diff] [blame] | 169 | addr = boot_mem_map.map[i].addr; |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame] | 170 | free_init_pages("YAMON memory", |
Atsushi Nemoto | c44e8d5 | 2006-12-30 00:43:59 +0900 | [diff] [blame] | 171 | addr, addr + boot_mem_map.map[i].size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
Paul Burton | 3a551e2 | 2014-07-14 12:37:39 +0100 | [diff] [blame] | 174 | |
| 175 | unsigned platform_maar_init(unsigned num_pairs) |
| 176 | { |
| 177 | phys_addr_t mem_end = (physical_memsize & ~0xffffull) - 1; |
| 178 | struct maar_config cfg[] = { |
| 179 | /* DRAM preceding I/O */ |
| 180 | { 0x00000000, 0x0fffffff, MIPS_MAAR_S }, |
| 181 | |
| 182 | /* DRAM following I/O */ |
| 183 | { 0x20000000, mem_end, MIPS_MAAR_S }, |
| 184 | |
| 185 | /* DRAM alias in upper half of physical */ |
| 186 | { 0x80000000, 0x80000000 + mem_end, MIPS_MAAR_S }, |
| 187 | }; |
| 188 | unsigned i, num_cfg = ARRAY_SIZE(cfg); |
| 189 | |
| 190 | /* If DRAM fits before I/O, drop the region following it */ |
| 191 | if (physical_memsize <= 0x10000000) { |
| 192 | num_cfg--; |
| 193 | for (i = 1; i < num_cfg; i++) |
| 194 | cfg[i] = cfg[i + 1]; |
| 195 | } |
| 196 | |
| 197 | return maar_config(cfg, num_cfg, num_pairs); |
| 198 | } |