blob: 1f73d63e92a765d3ab1d829244a19e57dab8bd8e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Steven J. Hill49bffbd2013-03-25 15:05:40 -05002 * 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 Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * PROM library functions for acquiring/using memory descriptors given to
7 * us from the YAMON.
Steven J. Hill49bffbd2013-03-25 15:05:40 -05008 *
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 Torvalds1da177e2005-04-16 15:20:36 -070013 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/bootmem.h>
Ralf Baechlee01402b2005-07-14 15:57:16 +000016#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#include <asm/bootinfo.h>
Ralf Baechle9c1f1252006-04-03 10:17:21 +010019#include <asm/sections.h>
Steven J. Hillb431f092013-03-25 14:47:05 -050020#include <asm/fw/fw.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Steven J. Hillb431f092013-03-25 14:47:05 -050022static fw_memblock_t mdesc[FW_MAX_MEMBLOCKS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Ralf Baechle70342282013-01-22 12:59:30 +010024/* determined physical memory size, not overridden by command line args */
Ralf Baechlee1a4e462006-07-03 17:02:35 +010025unsigned long physical_memsize = 0L;
26
Steven J. Hillb431f092013-03-25 14:47:05 -050027fw_memblock_t * __init fw_getmdesc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
Steven J. Hill49bffbd2013-03-25 15:05:40 -050029 char *memsize_str, *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 unsigned int memsize;
Dmitri Vorobiev7580c9c2009-10-13 23:43:24 +030031 static char cmdline[COMMAND_LINE_SIZE] __initdata;
Steven J. Hill49bffbd2013-03-25 15:05:40 -050032 long val;
33 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Ralf Baechlee1a4e462006-07-03 17:02:35 +010035 /* otherwise look in the environment */
Steven J. Hillb431f092013-03-25 14:47:05 -050036 memsize_str = fw_getenv("memsize");
Ralf Baechlee1a4e462006-07-03 17:02:35 +010037 if (!memsize_str) {
Steven J. Hill49bffbd2013-03-25 15:05:40 -050038 pr_warn("memsize not set in YAMON, set to default (32Mb)\n");
Ralf Baechlee1a4e462006-07-03 17:02:35 +010039 physical_memsize = 0x02000000;
40 } else {
Steven J. Hill49bffbd2013-03-25 15:05:40 -050041 tmp = kstrtol(memsize_str, 0, &val);
42 physical_memsize = (unsigned long)val;
Ralf Baechlee1a4e462006-07-03 17:02:35 +010043 }
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 Baechlee01402b2005-07-14 15:57:16 +000053 strcpy(cmdline, arcs_cmdline);
54 ptr = strstr(cmdline, "memsize=");
55 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
56 ptr = strstr(ptr, " memsize=");
57
Ralf Baechlee1a4e462006-07-03 17:02:35 +010058 if (ptr)
Ralf Baechlee01402b2005-07-14 15:57:16 +000059 memsize = memparse(ptr + 8, &ptr);
Ralf Baechlee1a4e462006-07-03 17:02:35 +010060 else
61 memsize = physical_memsize;
Elizabeth Oldham73499682006-06-06 10:57:09 +010062
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 memset(mdesc, 0, sizeof(mdesc));
64
Steven J. Hillb431f092013-03-25 14:47:05 -050065 mdesc[0].type = fw_dontuse;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 mdesc[0].base = 0x00000000;
67 mdesc[0].size = 0x00001000;
68
Steven J. Hillb431f092013-03-25 14:47:05 -050069 mdesc[1].type = fw_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 mdesc[1].base = 0x00001000;
71 mdesc[1].size = 0x000ef000;
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 /*
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. Hillb431f092013-03-25 14:47:05 -050080 mdesc[2].type = fw_dontuse;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 mdesc[2].base = 0x000f0000;
82 mdesc[2].size = 0x00010000;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Steven J. Hillb431f092013-03-25 14:47:05 -050084 mdesc[3].type = fw_dontuse;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 mdesc[3].base = 0x00100000;
Steven J. Hill49bffbd2013-03-25 15:05:40 -050086 mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) -
87 mdesc[3].base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Steven J. Hillb431f092013-03-25 14:47:05 -050089 mdesc[4].type = fw_free;
Ralf Baechlefde35052006-04-03 14:44:50 +010090 mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end));
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 mdesc[4].size = memsize - mdesc[4].base;
92
93 return &mdesc[0];
94}
95
Steven J. Hillb431f092013-03-25 14:47:05 -050096static int __init fw_memtype_classify(unsigned int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
98 switch (type) {
Steven J. Hillb431f092013-03-25 14:47:05 -050099 case fw_free:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 return BOOT_MEM_RAM;
Steven J. Hillb431f092013-03-25 14:47:05 -0500101 case fw_code:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 return BOOT_MEM_ROM_DATA;
103 default:
104 return BOOT_MEM_RESERVED;
105 }
106}
107
Steven J. Hillb431f092013-03-25 14:47:05 -0500108void __init fw_meminit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
Steven J. Hillb431f092013-03-25 14:47:05 -0500110 fw_memblock_t *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Steven J. Hillb431f092013-03-25 14:47:05 -0500112 p = fw_getmdesc();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 while (p->size) {
115 long type;
116 unsigned long base, size;
117
Steven J. Hillb431f092013-03-25 14:47:05 -0500118 type = fw_memtype_classify(p->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 base = p->base;
120 size = p->size;
121
122 add_memory_region(base, size, type);
Ralf Baechle70342282013-01-22 12:59:30 +0100123 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 }
125}
126
Atsushi Nemotoc44e8d52006-12-30 00:43:59 +0900127void __init prom_free_prom_memory(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 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 Nemotoc44e8d52006-12-30 00:43:59 +0900136 addr = boot_mem_map.map[i].addr;
Steven J. Hill49bffbd2013-03-25 15:05:40 -0500137 free_init_pages("YAMON memory",
Atsushi Nemotoc44e8d52006-12-30 00:43:59 +0900138 addr, addr + boot_mem_map.map[i].size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}