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> |
Ralf Baechle | 9c1f125 | 2006-04-03 10:17:21 +0100 | [diff] [blame] | 19 | #include <asm/sections.h> |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 20 | #include <asm/fw/fw.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 22 | static fw_memblock_t mdesc[FW_MAX_MEMBLOCKS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 24 | /* determined physical memory size, not overridden by command line args */ |
Ralf Baechle | e1a4e46 | 2006-07-03 17:02:35 +0100 | [diff] [blame] | 25 | unsigned long physical_memsize = 0L; |
| 26 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 27 | fw_memblock_t * __init fw_getmdesc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | { |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame^] | 29 | char *memsize_str, *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | unsigned int memsize; |
Dmitri Vorobiev | 7580c9c | 2009-10-13 23:43:24 +0300 | [diff] [blame] | 31 | static char cmdline[COMMAND_LINE_SIZE] __initdata; |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame^] | 32 | long val; |
| 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 */ |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 36 | memsize_str = fw_getenv("memsize"); |
Ralf Baechle | e1a4e46 | 2006-07-03 17:02:35 +0100 | [diff] [blame] | 37 | if (!memsize_str) { |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame^] | 38 | pr_warn("memsize not set in YAMON, set to default (32Mb)\n"); |
Ralf Baechle | e1a4e46 | 2006-07-03 17:02:35 +0100 | [diff] [blame] | 39 | physical_memsize = 0x02000000; |
| 40 | } else { |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame^] | 41 | tmp = kstrtol(memsize_str, 0, &val); |
| 42 | physical_memsize = (unsigned long)val; |
Ralf Baechle | e1a4e46 | 2006-07-03 17:02:35 +0100 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | #ifdef CONFIG_CPU_BIG_ENDIAN |
| 46 | /* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last |
| 47 | word of physical memory */ |
| 48 | physical_memsize -= PAGE_SIZE; |
| 49 | #endif |
| 50 | |
| 51 | /* Check the command line for a memsize directive that overrides |
| 52 | the physical/default amount */ |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 53 | strcpy(cmdline, arcs_cmdline); |
| 54 | ptr = strstr(cmdline, "memsize="); |
| 55 | if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' ')) |
| 56 | ptr = strstr(ptr, " memsize="); |
| 57 | |
Ralf Baechle | e1a4e46 | 2006-07-03 17:02:35 +0100 | [diff] [blame] | 58 | if (ptr) |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 59 | memsize = memparse(ptr + 8, &ptr); |
Ralf Baechle | e1a4e46 | 2006-07-03 17:02:35 +0100 | [diff] [blame] | 60 | else |
| 61 | memsize = physical_memsize; |
Elizabeth Oldham | 7349968 | 2006-06-06 10:57:09 +0100 | [diff] [blame] | 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | memset(mdesc, 0, sizeof(mdesc)); |
| 64 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 65 | mdesc[0].type = fw_dontuse; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | mdesc[0].base = 0x00000000; |
| 67 | mdesc[0].size = 0x00001000; |
| 68 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 69 | mdesc[1].type = fw_code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | mdesc[1].base = 0x00001000; |
| 71 | mdesc[1].size = 0x000ef000; |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | /* |
| 74 | * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the |
| 75 | * south bridge and PCI access always forwarded to the ISA Bus and |
| 76 | * BIOSCS# is always generated. |
| 77 | * This mean that this area can't be used as DMA memory for PCI |
| 78 | * devices. |
| 79 | */ |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 80 | mdesc[2].type = fw_dontuse; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | mdesc[2].base = 0x000f0000; |
| 82 | mdesc[2].size = 0x00010000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 84 | mdesc[3].type = fw_dontuse; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | mdesc[3].base = 0x00100000; |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame^] | 86 | mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) - |
| 87 | mdesc[3].base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 89 | mdesc[4].type = fw_free; |
Ralf Baechle | fde3505 | 2006-04-03 14:44:50 +0100 | [diff] [blame] | 90 | mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | mdesc[4].size = memsize - mdesc[4].base; |
| 92 | |
| 93 | return &mdesc[0]; |
| 94 | } |
| 95 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 96 | static int __init fw_memtype_classify(unsigned int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { |
| 98 | switch (type) { |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 99 | case fw_free: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | return BOOT_MEM_RAM; |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 101 | case fw_code: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | return BOOT_MEM_ROM_DATA; |
| 103 | default: |
| 104 | return BOOT_MEM_RESERVED; |
| 105 | } |
| 106 | } |
| 107 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 108 | void __init fw_meminit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 110 | fw_memblock_t *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 112 | p = fw_getmdesc(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | while (p->size) { |
| 115 | long type; |
| 116 | unsigned long base, size; |
| 117 | |
Steven J. Hill | b431f09 | 2013-03-25 14:47:05 -0500 | [diff] [blame] | 118 | type = fw_memtype_classify(p->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | base = p->base; |
| 120 | size = p->size; |
| 121 | |
| 122 | add_memory_region(base, size, type); |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 123 | p++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
Atsushi Nemoto | c44e8d5 | 2006-12-30 00:43:59 +0900 | [diff] [blame] | 127 | void __init prom_free_prom_memory(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | unsigned long addr; |
| 130 | int i; |
| 131 | |
| 132 | for (i = 0; i < boot_mem_map.nr_map; i++) { |
| 133 | if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA) |
| 134 | continue; |
| 135 | |
Atsushi Nemoto | c44e8d5 | 2006-12-30 00:43:59 +0900 | [diff] [blame] | 136 | addr = boot_mem_map.map[i].addr; |
Steven J. Hill | 49bffbd | 2013-03-25 15:05:40 -0500 | [diff] [blame^] | 137 | free_init_pages("YAMON memory", |
Atsushi Nemoto | c44e8d5 | 2006-12-30 00:43:59 +0900 | [diff] [blame] | 138 | addr, addr + boot_mem_map.map[i].size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | } |