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