6a9155
From: Dave Anderson <anderson@redhat.com>
97686d
Date: Tue, 26 Nov 2013 12:42:46 -0500
0a346e
Subject: [PATCH] crash-driver
Jesse Keating 7a3296
6a9155
Bugzilla: N/A
6a9155
Upstream-status: Fedora mustard
Jesse Keating 7a3296
---
980c60
 arch/arm/include/asm/crash-driver.h     |   6 ++
980c60
 arch/arm64/include/asm/crash-driver.h   |   6 ++
6a9155
 arch/ia64/include/asm/crash-driver.h    |  90 ++++++++++++++++++++++
6a9155
 arch/ia64/kernel/ia64_ksyms.c           |   3 +
980c60
 arch/powerpc/include/asm/crash-driver.h |   6 ++
6a9155
 arch/s390/include/asm/crash-driver.h    |  60 +++++++++++++++
6a9155
 arch/s390/mm/maccess.c                  |   2 +
980c60
 arch/x86/include/asm/crash-driver.h     |   6 ++
6a9155
 drivers/char/Kconfig                    |   3 +
6a9155
 drivers/char/Makefile                   |   2 +
6a9155
 drivers/char/crash.c                    | 128 ++++++++++++++++++++++++++++++++
6a9155
 include/asm-generic/crash-driver.h      |  72 ++++++++++++++++++
97686d
 12 files changed, 384 insertions(+)
980c60
 create mode 100644 arch/arm/include/asm/crash-driver.h
980c60
 create mode 100644 arch/arm64/include/asm/crash-driver.h
980c60
 create mode 100644 arch/ia64/include/asm/crash-driver.h
980c60
 create mode 100644 arch/powerpc/include/asm/crash-driver.h
980c60
 create mode 100644 arch/s390/include/asm/crash-driver.h
980c60
 create mode 100644 arch/x86/include/asm/crash-driver.h
Jesse Keating 7a3296
 create mode 100644 drivers/char/crash.c
980c60
 create mode 100644 include/asm-generic/crash-driver.h
Jesse Keating 7a3296
980c60
diff --git a/arch/arm/include/asm/crash-driver.h b/arch/arm/include/asm/crash-driver.h
0a346e
new file mode 100644
6a9155
index 000000000000..06e7ae916601
0a346e
--- /dev/null
980c60
+++ b/arch/arm/include/asm/crash-driver.h
0a346e
@@ -0,0 +1,6 @@
0a346e
+#ifndef _ARM_CRASH_H
0a346e
+#define _ARM_CRASH_H
0a346e
+
980c60
+#include <asm-generic/crash-driver.h>
0a346e
+
0a346e
+#endif /* _ARM_CRASH_H */
980c60
diff --git a/arch/arm64/include/asm/crash-driver.h b/arch/arm64/include/asm/crash-driver.h
0a346e
new file mode 100644
6a9155
index 000000000000..43b26da0c5d6
0a346e
--- /dev/null
980c60
+++ b/arch/arm64/include/asm/crash-driver.h
0a346e
@@ -0,0 +1,6 @@
0a346e
+#ifndef _ARM64_CRASH_H
0a346e
+#define _ARM64_CRASH_H
0a346e
+
980c60
+#include <asm-generic/crash-driver.h>
0a346e
+
0a346e
+#endif /* _ARM64_CRASH_H */
980c60
diff --git a/arch/ia64/include/asm/crash-driver.h b/arch/ia64/include/asm/crash-driver.h
Jesse Keating 7a3296
new file mode 100644
6a9155
index 000000000000..404bcb93c112
Jesse Keating 7a3296
--- /dev/null
980c60
+++ b/arch/ia64/include/asm/crash-driver.h
Jesse Keating 7a3296
@@ -0,0 +1,90 @@
Jesse Keating 7a3296
+#ifndef _ASM_IA64_CRASH_H
Jesse Keating 7a3296
+#define _ASM_IA64_CRASH_H
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+/*
980c60
+ * linux/include/asm-ia64/crash-driver.h
Jesse Keating 7a3296
+ *
Jesse Keating 7a3296
+ * Copyright (c) 2004 Red Hat, Inc. All rights reserved.
Jesse Keating 7a3296
+ *
Jesse Keating 7a3296
+ * This program is free software; you can redistribute it and/or modify
Jesse Keating 7a3296
+ * it under the terms of the GNU General Public License as published by
Jesse Keating 7a3296
+ * the Free Software Foundation; either version 2, or (at your option)
Jesse Keating 7a3296
+ * any later version.
Jesse Keating 7a3296
+ *
Jesse Keating 7a3296
+ * This program is distributed in the hope that it will be useful,
Jesse Keating 7a3296
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jesse Keating 7a3296
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Jesse Keating 7a3296
+ * GNU General Public License for more details.
Jesse Keating 7a3296
+ *
Jesse Keating 7a3296
+ * You should have received a copy of the GNU General Public License
Jesse Keating 7a3296
+ * along with this program; if not, write to the Free Software
Jesse Keating 7a3296
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Jesse Keating 7a3296
+ *
Jesse Keating 7a3296
+ */
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+#ifdef __KERNEL__
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+#include <linux/efi.h>
Jesse Keating 7a3296
+#include <linux/mm.h>
Jesse Keating 7a3296
+#include <asm/mmzone.h>
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+static inline void *
Jesse Keating 7a3296
+map_virtual(u64 offset, struct page **pp)
Jesse Keating 7a3296
+{
Jesse Keating 7a3296
+	struct page *page;
Jesse Keating 7a3296
+	unsigned long pfn;
Jesse Keating 7a3296
+	u32 type;
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+	if (REGION_NUMBER(offset) == 5) {
Jesse Keating 7a3296
+		char byte;
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+		if (__get_user(byte, (char *)offset) == 0)
Jesse Keating 7a3296
+			return (void *)offset;
Jesse Keating 7a3296
+		else
Jesse Keating 7a3296
+			return NULL;
Jesse Keating 7a3296
+	}
Jesse Keating 7a3296
+
0a346e
+	switch (type = efi_mem_type(offset))
Jesse Keating 7a3296
+	{
Jesse Keating 7a3296
+	case EFI_LOADER_CODE:
Jesse Keating 7a3296
+	case EFI_LOADER_DATA:
Jesse Keating 7a3296
+	case EFI_BOOT_SERVICES_CODE:
Jesse Keating 7a3296
+	case EFI_BOOT_SERVICES_DATA:
Jesse Keating 7a3296
+	case EFI_CONVENTIONAL_MEMORY:
Jesse Keating 7a3296
+		break;
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+	default:
Jesse Keating 7a3296
+		printk(KERN_INFO
0a346e
+		    "crash memory driver: invalid memory type for %lx: %d\n",
Jesse Keating 7a3296
+			offset, type);
Jesse Keating 7a3296
+		return NULL;
Jesse Keating 7a3296
+	}
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+	pfn = offset >> PAGE_SHIFT;
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+	if (!pfn_valid(pfn)) {
Jesse Keating 7a3296
+		printk(KERN_INFO
Jesse Keating 7a3296
+			"crash memory driver: invalid pfn: %lx )\n", pfn);
Jesse Keating 7a3296
+		return NULL;
Jesse Keating 7a3296
+	}
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+	page = pfn_to_page(pfn);
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+	if (!page->virtual) {
Jesse Keating 7a3296
+		printk(KERN_INFO
0a346e
+		    "crash memory driver: offset: %lx page: %lx page->virtual: NULL\n",
Jesse Keating 7a3296
+			offset, (unsigned long)page);
Jesse Keating 7a3296
+		return NULL;
Jesse Keating 7a3296
+	}
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+	return (page->virtual + (offset & (PAGE_SIZE-1)));
Jesse Keating 7a3296
+}
Jesse Keating 7a3296
+
0a346e
+static inline void unmap_virtual(struct page *page)
0a346e
+{
Jesse Keating 7a3296
+	return;
Jesse Keating 7a3296
+}
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+#endif /* __KERNEL__ */
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+#endif /* _ASM_IA64_CRASH_H */
Jesse Keating 7a3296
diff --git a/arch/ia64/kernel/ia64_ksyms.c b/arch/ia64/kernel/ia64_ksyms.c
6a50f3
index 096731049538..e88887827906 100644
Jesse Keating 7a3296
--- a/arch/ia64/kernel/ia64_ksyms.c
Jesse Keating 7a3296
+++ b/arch/ia64/kernel/ia64_ksyms.c
Jesse Keating 7a3296
@@ -84,6 +84,9 @@ EXPORT_SYMBOL(ia64_save_scratch_fpregs);
Jesse Keating 7a3296
 #include <asm/unwind.h>
Jesse Keating 7a3296
 EXPORT_SYMBOL(unw_init_running);
Jesse Keating 7a3296
 
Jesse Keating 7a3296
+#include <linux/efi.h>
Jesse Keating 7a3296
+EXPORT_SYMBOL_GPL(efi_mem_type);
Jesse Keating 7a3296
+
Jesse Keating 7a3296
 #if defined(CONFIG_IA64_ESI) || defined(CONFIG_IA64_ESI_MODULE)
Jesse Keating 7a3296
 extern void esi_call_phys (void);
Jesse Keating 7a3296
 EXPORT_SYMBOL_GPL(esi_call_phys);
980c60
diff --git a/arch/powerpc/include/asm/crash-driver.h b/arch/powerpc/include/asm/crash-driver.h
Jesse Keating 7a3296
new file mode 100644
6a9155
index 000000000000..50092d965dc5
Jesse Keating 7a3296
--- /dev/null
980c60
+++ b/arch/powerpc/include/asm/crash-driver.h
0a346e
@@ -0,0 +1,6 @@
0a346e
+#ifndef _PPC64_CRASH_H
0a346e
+#define _PPC64_CRASH_H
Jesse Keating 7a3296
+
980c60
+#include <asm-generic/crash-driver.h>
0a346e
+
0a346e
+#endif /* _PPC64_CRASH_H */
980c60
diff --git a/arch/s390/include/asm/crash-driver.h b/arch/s390/include/asm/crash-driver.h
0a346e
new file mode 100644
6a9155
index 000000000000..552be5e2c571
0a346e
--- /dev/null
980c60
+++ b/arch/s390/include/asm/crash-driver.h
0a346e
@@ -0,0 +1,60 @@
0a346e
+#ifndef _S390_CRASH_H
0a346e
+#define _S390_CRASH_H
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+#ifdef __KERNEL__
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+#include <linux/mm.h>
Jesse Keating 7a3296
+#include <linux/highmem.h>
Jesse Keating 7a3296
+
0a346e
+/*
0a346e
+ * For swapped prefix pages get bounce buffer using xlate_dev_mem_ptr()
0a346e
+ */
0a346e
+static inline void *map_virtual(u64 offset, struct page **pp)
Jesse Keating 7a3296
+{
Jesse Keating 7a3296
+	struct page *page;
Jesse Keating 7a3296
+	unsigned long pfn;
Jesse Keating 7a3296
+	void *vaddr;
Jesse Keating 7a3296
+
0a346e
+	vaddr = xlate_dev_mem_ptr(offset);
0a346e
+	pfn = ((unsigned long) vaddr) >> PAGE_SHIFT;
0a346e
+	if ((unsigned long) vaddr != offset)
0a346e
+		page = pfn_to_page(pfn);
0a346e
+	else
0a346e
+		page = NULL;
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+	if (!page_is_ram(pfn)) {
Jesse Keating 7a3296
+		printk(KERN_INFO
Jesse Keating 7a3296
+		    "crash memory driver: !page_is_ram(pfn: %lx)\n", pfn);
Jesse Keating 7a3296
+		return NULL;
Jesse Keating 7a3296
+	}
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+	if (!pfn_valid(pfn)) {
Jesse Keating 7a3296
+		printk(KERN_INFO
Jesse Keating 7a3296
+		    "crash memory driver: invalid pfn: %lx )\n", pfn);
Jesse Keating 7a3296
+		return NULL;
Jesse Keating 7a3296
+	}
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+	*pp = page;
0a346e
+	return vaddr;
Jesse Keating 7a3296
+}
Jesse Keating 7a3296
+
0a346e
+/*
0a346e
+ * Free bounce buffer if necessary
0a346e
+ */
0a346e
+static inline void unmap_virtual(struct page *page)
0a346e
+{
0a346e
+	void *vaddr;
0a346e
+
0a346e
+	if (page) {
0a346e
+		/*
0a346e
+		 * Because for bounce buffers vaddr will never be 0
0a346e
+		 * unxlate_dev_mem_ptr() will always free the bounce buffer.
0a346e
+		 */
0a346e
+		vaddr = (void *)(page_to_pfn(page) << PAGE_SHIFT);
0a346e
+		unxlate_dev_mem_ptr(0, vaddr);
0a346e
+	}
Jesse Keating 7a3296
+}
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+#endif /* __KERNEL__ */
Jesse Keating 7a3296
+
0a346e
+#endif /* _S390_CRASH_H */
97686d
diff --git a/arch/s390/mm/maccess.c b/arch/s390/mm/maccess.c
cc7213
index 8a993a53fcd6..8f511795b52e 100644
97686d
--- a/arch/s390/mm/maccess.c
97686d
+++ b/arch/s390/mm/maccess.c
cc7213
@@ -197,6 +197,7 @@ void *xlate_dev_mem_ptr(phys_addr_t addr)
97686d
 	put_online_cpus();
97686d
 	return bounce;
97686d
 }
97686d
+EXPORT_SYMBOL_GPL(xlate_dev_mem_ptr);
97686d
 
97686d
 /*
97686d
  * Free converted buffer for /dev/mem access (if necessary)
cc7213
@@ -206,3 +207,4 @@ void unxlate_dev_mem_ptr(phys_addr_t addr, void *buf)
97686d
 	if ((void *) addr != buf)
97686d
 		free_page((unsigned long) buf);
97686d
 }
97686d
+EXPORT_SYMBOL_GPL(unxlate_dev_mem_ptr);
980c60
diff --git a/arch/x86/include/asm/crash-driver.h b/arch/x86/include/asm/crash-driver.h
0a346e
new file mode 100644
6a9155
index 000000000000..fd4736ec99f5
0a346e
--- /dev/null
980c60
+++ b/arch/x86/include/asm/crash-driver.h
0a346e
@@ -0,0 +1,6 @@
0a346e
+#ifndef _X86_CRASH_H
0a346e
+#define _X86_CRASH_H
0a346e
+
980c60
+#include <asm-generic/crash-driver.h>
0a346e
+
0a346e
+#endif /* _X86_CRASH_H */
Josh Boyer 8e3ae9
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
76c11d
index a043107da2af..b272397f306a 100644
Josh Boyer 8e3ae9
--- a/drivers/char/Kconfig
Josh Boyer 8e3ae9
+++ b/drivers/char/Kconfig
Josh Boyer 8e3ae9
@@ -4,6 +4,9 @@
Josh Boyer 8e3ae9
 
Josh Boyer 8e3ae9
 menu "Character devices"
Josh Boyer 8e3ae9
 
Josh Boyer 8e3ae9
+config CRASH
Josh Boyer 8e3ae9
+	tristate "Crash Utility memory driver"
Josh Boyer 8e3ae9
+
Josh Boyer 8e3ae9
 source "drivers/tty/Kconfig"
Josh Boyer 8e3ae9
 
f1193f
 config DEVMEM
Josh Boyer 8e3ae9
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
76c11d
index d8a7579300d2..31c83630f593 100644
Josh Boyer 8e3ae9
--- a/drivers/char/Makefile
Josh Boyer 8e3ae9
+++ b/drivers/char/Makefile
76c11d
@@ -60,3 +60,5 @@ js-rtc-y = rtc.o
Josh Boyer 8e3ae9
 
Josh Boyer 8e3ae9
 obj-$(CONFIG_TILE_SROM)		+= tile-srom.o
da99f2
 obj-$(CONFIG_XILLYBUS)		+= xillybus/
Josh Boyer 8e3ae9
+
Josh Boyer 8e3ae9
+obj-$(CONFIG_CRASH)            += crash.o
Jesse Keating 7a3296
diff --git a/drivers/char/crash.c b/drivers/char/crash.c
Jesse Keating 7a3296
new file mode 100644
6a9155
index 000000000000..085378a1d539
Jesse Keating 7a3296
--- /dev/null
Jesse Keating 7a3296
+++ b/drivers/char/crash.c
Jesse Keating 7a3296
@@ -0,0 +1,128 @@
Jesse Keating 7a3296
+/*
Jesse Keating 7a3296
+ *  linux/drivers/char/crash.c
Jesse Keating 7a3296
+ *
Jesse Keating 7a3296
+ *  Copyright (C) 2004  Dave Anderson <anderson@redhat.com>
Jesse Keating 7a3296
+ *  Copyright (C) 2004  Red Hat, Inc.
Jesse Keating 7a3296
+ */
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+/******************************************************************************
Jesse Keating 7a3296
+ *
Jesse Keating 7a3296
+ *   This program is free software; you can redistribute it and/or modify
Jesse Keating 7a3296
+ *   it under the terms of the GNU General Public License as published by
Jesse Keating 7a3296
+ *   the Free Software Foundation; either version 2, or (at your option)
Jesse Keating 7a3296
+ *   any later version.
Jesse Keating 7a3296
+ *
Jesse Keating 7a3296
+ *   This program is distributed in the hope that it will be useful,
Jesse Keating 7a3296
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
Jesse Keating 7a3296
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Jesse Keating 7a3296
+ *   GNU General Public License for more details.
Jesse Keating 7a3296
+ *
Jesse Keating 7a3296
+ *   You should have received a copy of the GNU General Public License
Jesse Keating 7a3296
+ *   along with this program; if not, write to the Free Software
Jesse Keating 7a3296
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Jesse Keating 7a3296
+ *
Jesse Keating 7a3296
+ *****************************************************************************/
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+#include <linux/module.h>
Jesse Keating 7a3296
+#include <linux/types.h>
Jesse Keating 7a3296
+#include <linux/miscdevice.h>
Jesse Keating 7a3296
+#include <linux/init.h>
Jesse Keating 7a3296
+#include <asm/io.h>
Jesse Keating 7a3296
+#include <asm/uaccess.h>
Jesse Keating 7a3296
+#include <asm/types.h>
980c60
+#include <asm/crash-driver.h>
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+#define CRASH_VERSION   "1.0"
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+/*
Jesse Keating 7a3296
+ *  These are the file operation functions that allow crash utility
Jesse Keating 7a3296
+ *  access to physical memory.
Jesse Keating 7a3296
+ */
Jesse Keating 7a3296
+
0a346e
+static loff_t
Jesse Keating 7a3296
+crash_llseek(struct file * file, loff_t offset, int orig)
Jesse Keating 7a3296
+{
Jesse Keating 7a3296
+	switch (orig) {
Jesse Keating 7a3296
+	case 0:
Jesse Keating 7a3296
+		file->f_pos = offset;
Jesse Keating 7a3296
+		return file->f_pos;
Jesse Keating 7a3296
+	case 1:
Jesse Keating 7a3296
+		file->f_pos += offset;
Jesse Keating 7a3296
+		return file->f_pos;
Jesse Keating 7a3296
+	default:
Jesse Keating 7a3296
+		return -EINVAL;
Jesse Keating 7a3296
+	}
Jesse Keating 7a3296
+}
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+/*
0a346e
+ *  Determine the page address for an address offset value,
Jesse Keating 7a3296
+ *  get a virtual address for it, and copy it out.
Jesse Keating 7a3296
+ *  Accesses must fit within a page.
Jesse Keating 7a3296
+ */
Jesse Keating 7a3296
+static ssize_t
Jesse Keating 7a3296
+crash_read(struct file *file, char *buf, size_t count, loff_t *poff)
Jesse Keating 7a3296
+{
Jesse Keating 7a3296
+	void *vaddr;
Jesse Keating 7a3296
+	struct page *page;
Jesse Keating 7a3296
+	u64 offset;
Jesse Keating 7a3296
+	ssize_t read;
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+	offset = *poff;
0a346e
+	if (offset >> PAGE_SHIFT != (offset+count-1) >> PAGE_SHIFT)
Jesse Keating 7a3296
+		return -EINVAL;
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+	vaddr = map_virtual(offset, &page);
Jesse Keating 7a3296
+	if (!vaddr)
Jesse Keating 7a3296
+		return -EFAULT;
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+	if (copy_to_user(buf, vaddr, count)) {
Jesse Keating 7a3296
+		unmap_virtual(page);
Jesse Keating 7a3296
+		return -EFAULT;
Jesse Keating 7a3296
+	}
Jesse Keating 7a3296
+	unmap_virtual(page);
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+	read = count;
Jesse Keating 7a3296
+	*poff += read;
Jesse Keating 7a3296
+	return read;
Jesse Keating 7a3296
+}
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+static struct file_operations crash_fops = {
Jesse Keating 7a3296
+	.owner = THIS_MODULE,
Jesse Keating 7a3296
+	.llseek = crash_llseek,
Jesse Keating 7a3296
+	.read = crash_read,
Jesse Keating 7a3296
+};
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+static struct miscdevice crash_dev = {
Jesse Keating 7a3296
+	MISC_DYNAMIC_MINOR,
Jesse Keating 7a3296
+	"crash",
Jesse Keating 7a3296
+	&crash_fops
Jesse Keating 7a3296
+};
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+static int __init
Jesse Keating 7a3296
+crash_init(void)
Jesse Keating 7a3296
+{
Jesse Keating 7a3296
+	int ret;
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+	ret = misc_register(&crash_dev);
Jesse Keating 7a3296
+	if (ret) {
0a346e
+		printk(KERN_ERR
Jesse Keating 7a3296
+		    "crash memory driver: cannot misc_register (MISC_DYNAMIC_MINOR)\n");
Jesse Keating 7a3296
+		goto out;
Jesse Keating 7a3296
+	}
0a346e
+
Jesse Keating 7a3296
+	ret = 0;
Jesse Keating 7a3296
+	printk(KERN_INFO "crash memory driver: version %s\n", CRASH_VERSION);
Jesse Keating 7a3296
+out:
Jesse Keating 7a3296
+	return ret;
Jesse Keating 7a3296
+}
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+static void __exit
Jesse Keating 7a3296
+crash_cleanup_module(void)
Jesse Keating 7a3296
+{
Jesse Keating 7a3296
+	misc_deregister(&crash_dev);
Jesse Keating 7a3296
+}
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+module_init(crash_init);
Jesse Keating 7a3296
+module_exit(crash_cleanup_module);
Jesse Keating 7a3296
+
Jesse Keating 7a3296
+MODULE_LICENSE("GPL");
980c60
diff --git a/include/asm-generic/crash-driver.h b/include/asm-generic/crash-driver.h
0a346e
new file mode 100644
6a9155
index 000000000000..25ab9869d566
0a346e
--- /dev/null
980c60
+++ b/include/asm-generic/crash-driver.h
0a346e
@@ -0,0 +1,72 @@
0a346e
+#ifndef __CRASH_H__
0a346e
+#define __CRASH_H__
0a346e
+
0a346e
+/*
980c60
+ * include/linux/crash-driver.h
0a346e
+ *
0a346e
+ * Copyright (c) 2013 Red Hat, Inc. All rights reserved.
0a346e
+ *
0a346e
+ * This program is free software; you can redistribute it and/or modify
0a346e
+ * it under the terms of the GNU General Public License as published by
0a346e
+ * the Free Software Foundation; either version 2, or (at your option)
0a346e
+ * any later version.
0a346e
+ *
0a346e
+ * This program is distributed in the hope that it will be useful,
0a346e
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
0a346e
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0a346e
+ * GNU General Public License for more details.
0a346e
+ *
0a346e
+ * You should have received a copy of the GNU General Public License
0a346e
+ * along with this program; if not, write to the Free Software
0a346e
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0a346e
+ *
0a346e
+ */
0a346e
+
0a346e
+#ifdef __KERNEL__
0a346e
+
0a346e
+#include <linux/mm.h>
0a346e
+#include <linux/highmem.h>
0a346e
+
0a346e
+static inline void *
0a346e
+map_virtual(u64 offset, struct page **pp)
0a346e
+{
0a346e
+	struct page *page;
0a346e
+	unsigned long pfn;
0a346e
+	void *vaddr;
0a346e
+
0a346e
+	pfn = (unsigned long)(offset >> PAGE_SHIFT);
0a346e
+
0a346e
+	if (!page_is_ram(pfn)) {
0a346e
+		printk(KERN_INFO
0a346e
+		    "crash memory driver: !page_is_ram(pfn: %lx)\n", pfn);
0a346e
+		return NULL;
0a346e
+	}
0a346e
+
0a346e
+	if (!pfn_valid(pfn)) {
0a346e
+		printk(KERN_INFO
0a346e
+		    "crash memory driver: invalid pfn: %lx )\n", pfn);
0a346e
+		return NULL;
0a346e
+	}
0a346e
+
0a346e
+	page = pfn_to_page(pfn);
0a346e
+
0a346e
+	vaddr = kmap(page);
0a346e
+	if (!vaddr) {
0a346e
+		printk(KERN_INFO
0a346e
+		    "crash memory driver: pfn: %lx kmap(page: %lx) failed\n",
0a346e
+			pfn, (unsigned long)page);
0a346e
+		return NULL;
0a346e
+	}
0a346e
+
0a346e
+	*pp = page;
0a346e
+	return (vaddr + (offset & (PAGE_SIZE-1)));
0a346e
+}
0a346e
+
0a346e
+static inline void unmap_virtual(struct page *page)
0a346e
+{
0a346e
+	kunmap(page);
0a346e
+}
0a346e
+
0a346e
+#endif /* __KERNEL__ */
0a346e
+
0a346e
+#endif /* __CRASH_H__ */