0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #undef DEBUG
0011
0012 #include <linux/crash_dump.h>
0013 #include <linux/io.h>
0014 #include <linux/memblock.h>
0015 #include <linux/of.h>
0016 #include <asm/code-patching.h>
0017 #include <asm/kdump.h>
0018 #include <asm/firmware.h>
0019 #include <linux/uio.h>
0020 #include <asm/rtas.h>
0021 #include <asm/inst.h>
0022
0023 #ifdef DEBUG
0024 #include <asm/udbg.h>
0025 #define DBG(fmt...) udbg_printf(fmt)
0026 #else
0027 #define DBG(fmt...)
0028 #endif
0029
0030 #ifndef CONFIG_NONSTATIC_KERNEL
0031 void __init reserve_kdump_trampoline(void)
0032 {
0033 memblock_reserve(0, KDUMP_RESERVE_LIMIT);
0034 }
0035
0036 static void __init create_trampoline(unsigned long addr)
0037 {
0038 u32 *p = (u32 *)addr;
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 patch_instruction(p, ppc_inst(PPC_RAW_NOP()));
0049 patch_branch(p + 1, addr + PHYSICAL_START, 0);
0050 }
0051
0052 void __init setup_kdump_trampoline(void)
0053 {
0054 unsigned long i;
0055
0056 DBG(" -> setup_kdump_trampoline()\n");
0057
0058 for (i = KDUMP_TRAMPOLINE_START; i < KDUMP_TRAMPOLINE_END; i += 8) {
0059 create_trampoline(i);
0060 }
0061
0062 #ifdef CONFIG_PPC_PSERIES
0063 create_trampoline(__pa(system_reset_fwnmi) - PHYSICAL_START);
0064 create_trampoline(__pa(machine_check_fwnmi) - PHYSICAL_START);
0065 #endif
0066
0067 DBG(" <- setup_kdump_trampoline()\n");
0068 }
0069 #endif
0070
0071 ssize_t copy_oldmem_page(struct iov_iter *iter, unsigned long pfn,
0072 size_t csize, unsigned long offset)
0073 {
0074 void *vaddr;
0075 phys_addr_t paddr;
0076
0077 if (!csize)
0078 return 0;
0079
0080 csize = min_t(size_t, csize, PAGE_SIZE);
0081 paddr = pfn << PAGE_SHIFT;
0082
0083 if (memblock_is_region_memory(paddr, csize)) {
0084 vaddr = __va(paddr);
0085 csize = copy_to_iter(vaddr + offset, csize, iter);
0086 } else {
0087 vaddr = ioremap_cache(paddr, PAGE_SIZE);
0088 csize = copy_to_iter(vaddr + offset, csize, iter);
0089 iounmap(vaddr);
0090 }
0091
0092 return csize;
0093 }
0094
0095 #ifdef CONFIG_PPC_RTAS
0096
0097
0098
0099
0100 void crash_free_reserved_phys_range(unsigned long begin, unsigned long end)
0101 {
0102 unsigned long addr;
0103 const __be32 *basep, *sizep;
0104 unsigned int rtas_start = 0, rtas_end = 0;
0105
0106 basep = of_get_property(rtas.dev, "linux,rtas-base", NULL);
0107 sizep = of_get_property(rtas.dev, "rtas-size", NULL);
0108
0109 if (basep && sizep) {
0110 rtas_start = be32_to_cpup(basep);
0111 rtas_end = rtas_start + be32_to_cpup(sizep);
0112 }
0113
0114 for (addr = begin; addr < end; addr += PAGE_SIZE) {
0115
0116 if (addr <= rtas_end && ((addr + PAGE_SIZE) > rtas_start))
0117 continue;
0118
0119 free_reserved_page(pfn_to_page(addr >> PAGE_SHIFT));
0120 }
0121 }
0122 #endif