Path: blob/master/arch/powerpc/kernel/crash_dump.c
10817 views
/*1* Routines for doing kexec-based kdump.2*3* Copyright (C) 2005, IBM Corp.4*5* Created by: Michael Ellerman6*7* This source code is licensed under the GNU General Public License,8* Version 2. See the file COPYING for more details.9*/1011#undef DEBUG1213#include <linux/crash_dump.h>14#include <linux/bootmem.h>15#include <linux/memblock.h>16#include <asm/code-patching.h>17#include <asm/kdump.h>18#include <asm/prom.h>19#include <asm/firmware.h>20#include <asm/uaccess.h>21#include <asm/rtas.h>2223#ifdef DEBUG24#include <asm/udbg.h>25#define DBG(fmt...) udbg_printf(fmt)26#else27#define DBG(fmt...)28#endif2930#ifndef CONFIG_RELOCATABLE31void __init reserve_kdump_trampoline(void)32{33memblock_reserve(0, KDUMP_RESERVE_LIMIT);34}3536static void __init create_trampoline(unsigned long addr)37{38unsigned int *p = (unsigned int *)addr;3940/* The maximum range of a single instruction branch, is the current41* instruction's address + (32 MB - 4) bytes. For the trampoline we42* need to branch to current address + 32 MB. So we insert a nop at43* the trampoline address, then the next instruction (+ 4 bytes)44* does a branch to (32 MB - 4). The net effect is that when we45* branch to "addr" we jump to ("addr" + 32 MB). Although it requires46* two instructions it doesn't require any registers.47*/48patch_instruction(p, PPC_INST_NOP);49patch_branch(++p, addr + PHYSICAL_START, 0);50}5152void __init setup_kdump_trampoline(void)53{54unsigned long i;5556DBG(" -> setup_kdump_trampoline()\n");5758for (i = KDUMP_TRAMPOLINE_START; i < KDUMP_TRAMPOLINE_END; i += 8) {59create_trampoline(i);60}6162#ifdef CONFIG_PPC_PSERIES63create_trampoline(__pa(system_reset_fwnmi) - PHYSICAL_START);64create_trampoline(__pa(machine_check_fwnmi) - PHYSICAL_START);65#endif /* CONFIG_PPC_PSERIES */6667DBG(" <- setup_kdump_trampoline()\n");68}69#endif /* CONFIG_RELOCATABLE */7071static int __init parse_savemaxmem(char *p)72{73if (p)74saved_max_pfn = (memparse(p, &p) >> PAGE_SHIFT) - 1;7576return 1;77}78__setup("savemaxmem=", parse_savemaxmem);798081static size_t copy_oldmem_vaddr(void *vaddr, char *buf, size_t csize,82unsigned long offset, int userbuf)83{84if (userbuf) {85if (copy_to_user((char __user *)buf, (vaddr + offset), csize))86return -EFAULT;87} else88memcpy(buf, (vaddr + offset), csize);8990return csize;91}9293/**94* copy_oldmem_page - copy one page from "oldmem"95* @pfn: page frame number to be copied96* @buf: target memory address for the copy; this can be in kernel address97* space or user address space (see @userbuf)98* @csize: number of bytes to copy99* @offset: offset in bytes into the page (based on pfn) to begin the copy100* @userbuf: if set, @buf is in user address space, use copy_to_user(),101* otherwise @buf is in kernel address space, use memcpy().102*103* Copy a page from "oldmem". For this page, there is no pte mapped104* in the current kernel. We stitch up a pte, similar to kmap_atomic.105*/106ssize_t copy_oldmem_page(unsigned long pfn, char *buf,107size_t csize, unsigned long offset, int userbuf)108{109void *vaddr;110111if (!csize)112return 0;113114csize = min_t(size_t, csize, PAGE_SIZE);115116if ((min_low_pfn < pfn) && (pfn < max_pfn)) {117vaddr = __va(pfn << PAGE_SHIFT);118csize = copy_oldmem_vaddr(vaddr, buf, csize, offset, userbuf);119} else {120vaddr = __ioremap(pfn << PAGE_SHIFT, PAGE_SIZE, 0);121csize = copy_oldmem_vaddr(vaddr, buf, csize, offset, userbuf);122iounmap(vaddr);123}124125return csize;126}127128#ifdef CONFIG_PPC_RTAS129/*130* The crashkernel region will almost always overlap the RTAS region, so131* we have to be careful when shrinking the crashkernel region.132*/133void crash_free_reserved_phys_range(unsigned long begin, unsigned long end)134{135unsigned long addr;136const u32 *basep, *sizep;137unsigned int rtas_start = 0, rtas_end = 0;138139basep = of_get_property(rtas.dev, "linux,rtas-base", NULL);140sizep = of_get_property(rtas.dev, "rtas-size", NULL);141142if (basep && sizep) {143rtas_start = *basep;144rtas_end = *basep + *sizep;145}146147for (addr = begin; addr < end; addr += PAGE_SIZE) {148/* Does this page overlap with the RTAS region? */149if (addr <= rtas_end && ((addr + PAGE_SIZE) > rtas_start))150continue;151152ClearPageReserved(pfn_to_page(addr >> PAGE_SHIFT));153init_page_count(pfn_to_page(addr >> PAGE_SHIFT));154free_page((unsigned long)__va(addr));155totalram_pages++;156}157}158#endif159160161