[POWERPC] pseries: phyp dump: Reserve and release memory
[deliverable/linux.git] / arch / powerpc / platforms / pseries / phyp_dump.c
1 /*
2 * Hypervisor-assisted dump
3 *
4 * Linas Vepstas, Manish Ahuja 2008
5 * Copyright 2008 IBM Corp.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 */
13
14 #include <linux/init.h>
15 #include <linux/mm.h>
16 #include <linux/pfn.h>
17 #include <linux/swap.h>
18
19 #include <asm/page.h>
20 #include <asm/phyp_dump.h>
21 #include <asm/machdep.h>
22 #include <asm/prom.h>
23
24 /* Variables, used to communicate data between early boot and late boot */
25 static struct phyp_dump phyp_dump_vars;
26 struct phyp_dump *phyp_dump_info = &phyp_dump_vars;
27
28 /**
29 * release_memory_range -- release memory previously lmb_reserved
30 * @start_pfn: starting physical frame number
31 * @nr_pages: number of pages to free.
32 *
33 * This routine will release memory that had been previously
34 * lmb_reserved in early boot. The released memory becomes
35 * available for genreal use.
36 */
37 static void
38 release_memory_range(unsigned long start_pfn, unsigned long nr_pages)
39 {
40 struct page *rpage;
41 unsigned long end_pfn;
42 long i;
43
44 end_pfn = start_pfn + nr_pages;
45
46 for (i = start_pfn; i <= end_pfn; i++) {
47 rpage = pfn_to_page(i);
48 if (PageReserved(rpage)) {
49 ClearPageReserved(rpage);
50 init_page_count(rpage);
51 __free_page(rpage);
52 totalram_pages++;
53 }
54 }
55 }
56
57 static int __init phyp_dump_setup(void)
58 {
59 unsigned long start_pfn, nr_pages;
60
61 /* If no memory was reserved in early boot, there is nothing to do */
62 if (phyp_dump_info->init_reserve_size == 0)
63 return 0;
64
65 /* Release memory that was reserved in early boot */
66 start_pfn = PFN_DOWN(phyp_dump_info->init_reserve_start);
67 nr_pages = PFN_DOWN(phyp_dump_info->init_reserve_size);
68 release_memory_range(start_pfn, nr_pages);
69
70 return 0;
71 }
72 machine_subsys_initcall(pseries, phyp_dump_setup);
73
74 int __init early_init_dt_scan_phyp_dump(unsigned long node,
75 const char *uname, int depth, void *data)
76 {
77 const unsigned int *sizes;
78
79 phyp_dump_info->phyp_dump_configured = 0;
80 phyp_dump_info->phyp_dump_is_active = 0;
81
82 if (depth != 1 || strcmp(uname, "rtas") != 0)
83 return 0;
84
85 if (of_get_flat_dt_prop(node, "ibm,configure-kernel-dump", NULL))
86 phyp_dump_info->phyp_dump_configured++;
87
88 if (of_get_flat_dt_prop(node, "ibm,dump-kernel", NULL))
89 phyp_dump_info->phyp_dump_is_active++;
90
91 sizes = of_get_flat_dt_prop(node, "ibm,configure-kernel-dump-sizes",
92 NULL);
93 if (!sizes)
94 return 0;
95
96 if (sizes[0] == 1)
97 phyp_dump_info->cpu_state_size = *((unsigned long *)&sizes[1]);
98
99 if (sizes[3] == 2)
100 phyp_dump_info->hpte_region_size =
101 *((unsigned long *)&sizes[4]);
102 return 1;
103 }
This page took 0.035107 seconds and 5 git commands to generate.