0f09adf
From: Dave Anderson <anderson@redhat.com>
95107a7
Date: Tue, 26 Nov 2013 12:42:46 -0500
ee93020
Subject: [PATCH] crash-driver
Jesse Keating 7a32965
0f09adf
Bugzilla: N/A
0f09adf
Upstream-status: Fedora mustard
Jesse Keating 7a32965
---
0f09adf
 arch/arm/include/asm/crash-driver.h     |   6 ++
0f09adf
 arch/arm64/include/asm/crash-driver.h   |   6 ++
0f09adf
 arch/ia64/include/asm/crash-driver.h    |  90 ++++++++++++++++++++++
0f09adf
 arch/ia64/kernel/ia64_ksyms.c           |   3 +
0f09adf
 arch/powerpc/include/asm/crash-driver.h |   6 ++
0f09adf
 arch/s390/include/asm/crash-driver.h    |  60 +++++++++++++++
0f09adf
 arch/s390/mm/maccess.c                  |   2 +
0f09adf
 arch/x86/include/asm/crash-driver.h     |   6 ++
0f09adf
 drivers/char/Kconfig                    |   3 +
0f09adf
 drivers/char/Makefile                   |   2 +
0f09adf
 drivers/char/crash.c                    | 128 ++++++++++++++++++++++++++++++++
0f09adf
 include/asm-generic/crash-driver.h      |  72 ++++++++++++++++++
95107a7
 12 files changed, 384 insertions(+)
0f09adf
 create mode 100644 arch/arm/include/asm/crash-driver.h
0f09adf
 create mode 100644 arch/arm64/include/asm/crash-driver.h
0f09adf
 create mode 100644 arch/ia64/include/asm/crash-driver.h
0f09adf
 create mode 100644 arch/powerpc/include/asm/crash-driver.h
0f09adf
 create mode 100644 arch/s390/include/asm/crash-driver.h
0f09adf
 create mode 100644 arch/x86/include/asm/crash-driver.h
Jesse Keating 7a32965
 create mode 100644 drivers/char/crash.c
0f09adf
 create mode 100644 include/asm-generic/crash-driver.h
Jesse Keating 7a32965
0f09adf
diff --git a/arch/arm/include/asm/crash-driver.h b/arch/arm/include/asm/crash-driver.h
ee93020
new file mode 100644
0f09adf
index 000000000000..06e7ae916601
ee93020
--- /dev/null
0f09adf
+++ b/arch/arm/include/asm/crash-driver.h
ee93020
@@ -0,0 +1,6 @@
ee93020
+#ifndef _ARM_CRASH_H
ee93020
+#define _ARM_CRASH_H
ee93020
+
0f09adf
+#include <asm-generic/crash-driver.h>
ee93020
+
ee93020
+#endif /* _ARM_CRASH_H */
0f09adf
diff --git a/arch/arm64/include/asm/crash-driver.h b/arch/arm64/include/asm/crash-driver.h
ee93020
new file mode 100644
0f09adf
index 000000000000..43b26da0c5d6
ee93020
--- /dev/null
0f09adf
+++ b/arch/arm64/include/asm/crash-driver.h
ee93020
@@ -0,0 +1,6 @@
ee93020
+#ifndef _ARM64_CRASH_H
ee93020
+#define _ARM64_CRASH_H
ee93020
+
0f09adf
+#include <asm-generic/crash-driver.h>
ee93020
+
ee93020
+#endif /* _ARM64_CRASH_H */
0f09adf
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
0f09adf
index 000000000000..404bcb93c112
Jesse Keating 7a32965
--- /dev/null
0f09adf
+++ 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
+/*
0f09adf
+ * 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
+
ee93020
+	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
ee93020
+		    "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
ee93020
+		    "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
+
ee93020
+static inline void unmap_virtual(struct page *page)
ee93020
+{
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
0f09adf
index 5b7791dd3965..aee4b870c763 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);
0f09adf
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
0f09adf
index 000000000000..50092d965dc5
Jesse Keating 7a32965
--- /dev/null
0f09adf
+++ b/arch/powerpc/include/asm/crash-driver.h
ee93020
@@ -0,0 +1,6 @@
ee93020
+#ifndef _PPC64_CRASH_H
ee93020
+#define _PPC64_CRASH_H
Jesse Keating 7a32965
+
0f09adf
+#include <asm-generic/crash-driver.h>
ee93020
+
ee93020
+#endif /* _PPC64_CRASH_H */
0f09adf
diff --git a/arch/s390/include/asm/crash-driver.h b/arch/s390/include/asm/crash-driver.h
ee93020
new file mode 100644
0f09adf
index 000000000000..552be5e2c571
ee93020
--- /dev/null
0f09adf
+++ b/arch/s390/include/asm/crash-driver.h
ee93020
@@ -0,0 +1,60 @@
ee93020
+#ifndef _S390_CRASH_H
ee93020
+#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
+
ee93020
+/*
ee93020
+ * For swapped prefix pages get bounce buffer using xlate_dev_mem_ptr()
ee93020
+ */
ee93020
+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
+
ee93020
+	vaddr = xlate_dev_mem_ptr(offset);
ee93020
+	pfn = ((unsigned long) vaddr) >> PAGE_SHIFT;
ee93020
+	if ((unsigned long) vaddr != offset)
ee93020
+		page = pfn_to_page(pfn);
ee93020
+	else
ee93020
+		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;
ee93020
+	return vaddr;
Jesse Keating 7a32965
+}
Jesse Keating 7a32965
+
ee93020
+/*
ee93020
+ * Free bounce buffer if necessary
ee93020
+ */
ee93020
+static inline void unmap_virtual(struct page *page)
ee93020
+{
ee93020
+	void *vaddr;
ee93020
+
ee93020
+	if (page) {
ee93020
+		/*
ee93020
+		 * Because for bounce buffers vaddr will never be 0
ee93020
+		 * unxlate_dev_mem_ptr() will always free the bounce buffer.
ee93020
+		 */
ee93020
+		vaddr = (void *)(page_to_pfn(page) << PAGE_SHIFT);
ee93020
+		unxlate_dev_mem_ptr(0, vaddr);
ee93020
+	}
Jesse Keating 7a32965
+}
Jesse Keating 7a32965
+
Jesse Keating 7a32965
+#endif /* __KERNEL__ */
Jesse Keating 7a32965
+
ee93020
+#endif /* _S390_CRASH_H */
95107a7
diff --git a/arch/s390/mm/maccess.c b/arch/s390/mm/maccess.c
0f09adf
index 2a2e35416d2f..a529181429bb 100644
95107a7
--- a/arch/s390/mm/maccess.c
95107a7
+++ b/arch/s390/mm/maccess.c
0f09adf
@@ -193,6 +193,7 @@ void *xlate_dev_mem_ptr(unsigned long addr)
95107a7
 	put_online_cpus();
95107a7
 	return bounce;
95107a7
 }
95107a7
+EXPORT_SYMBOL_GPL(xlate_dev_mem_ptr);
95107a7
 
95107a7
 /*
95107a7
  * Free converted buffer for /dev/mem access (if necessary)
0f09adf
@@ -202,3 +203,4 @@ void unxlate_dev_mem_ptr(unsigned long addr, void *buf)
95107a7
 	if ((void *) addr != buf)
95107a7
 		free_page((unsigned long) buf);
95107a7
 }
95107a7
+EXPORT_SYMBOL_GPL(unxlate_dev_mem_ptr);
0f09adf
diff --git a/arch/x86/include/asm/crash-driver.h b/arch/x86/include/asm/crash-driver.h
ee93020
new file mode 100644
0f09adf
index 000000000000..fd4736ec99f5
ee93020
--- /dev/null
0f09adf
+++ b/arch/x86/include/asm/crash-driver.h
ee93020
@@ -0,0 +1,6 @@
ee93020
+#ifndef _X86_CRASH_H
ee93020
+#define _X86_CRASH_H
ee93020
+
0f09adf
+#include <asm-generic/crash-driver.h>
ee93020
+
ee93020
+#endif /* _X86_CRASH_H */
8e3ae98
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
1d791ed
index efefd12a0f7b..6a318132b7ee 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
 
8e3ae98
 config DEVKMEM
8e3ae98
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
1d791ed
index d06cde26031b..0832636fd9bc 100644
8e3ae98
--- a/drivers/char/Makefile
8e3ae98
+++ b/drivers/char/Makefile
1d791ed
@@ -62,3 +62,5 @@ js-rtc-y = rtc.o
8e3ae98
 
8e3ae98
 obj-$(CONFIG_TILE_SROM)		+= tile-srom.o
1d791ed
 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
0f09adf
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>
0f09adf
+#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
+
ee93020
+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
+/*
ee93020
+ *  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;
ee93020
+	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) {
ee93020
+		printk(KERN_ERR
Jesse Keating 7a32965
+		    "crash memory driver: cannot misc_register (MISC_DYNAMIC_MINOR)\n");
Jesse Keating 7a32965
+		goto out;
Jesse Keating 7a32965
+	}
ee93020
+
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");
0f09adf
diff --git a/include/asm-generic/crash-driver.h b/include/asm-generic/crash-driver.h
ee93020
new file mode 100644
0f09adf
index 000000000000..25ab9869d566
ee93020
--- /dev/null
0f09adf
+++ b/include/asm-generic/crash-driver.h
ee93020
@@ -0,0 +1,72 @@
ee93020
+#ifndef __CRASH_H__
ee93020
+#define __CRASH_H__
ee93020
+
ee93020
+/*
0f09adf
+ * include/linux/crash-driver.h
ee93020
+ *
ee93020
+ * Copyright (c) 2013 Red Hat, Inc. All rights reserved.
ee93020
+ *
ee93020
+ * This program is free software; you can redistribute it and/or modify
ee93020
+ * it under the terms of the GNU General Public License as published by
ee93020
+ * the Free Software Foundation; either version 2, or (at your option)
ee93020
+ * any later version.
ee93020
+ *
ee93020
+ * This program is distributed in the hope that it will be useful,
ee93020
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
ee93020
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ee93020
+ * GNU General Public License for more details.
ee93020
+ *
ee93020
+ * You should have received a copy of the GNU General Public License
ee93020
+ * along with this program; if not, write to the Free Software
ee93020
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
ee93020
+ *
ee93020
+ */
ee93020
+
ee93020
+#ifdef __KERNEL__
ee93020
+
ee93020
+#include <linux/mm.h>
ee93020
+#include <linux/highmem.h>
ee93020
+
ee93020
+static inline void *
ee93020
+map_virtual(u64 offset, struct page **pp)
ee93020
+{
ee93020
+	struct page *page;
ee93020
+	unsigned long pfn;
ee93020
+	void *vaddr;
ee93020
+
ee93020
+	pfn = (unsigned long)(offset >> PAGE_SHIFT);
ee93020
+
ee93020
+	if (!page_is_ram(pfn)) {
ee93020
+		printk(KERN_INFO
ee93020
+		    "crash memory driver: !page_is_ram(pfn: %lx)\n", pfn);
ee93020
+		return NULL;
ee93020
+	}
ee93020
+
ee93020
+	if (!pfn_valid(pfn)) {
ee93020
+		printk(KERN_INFO
ee93020
+		    "crash memory driver: invalid pfn: %lx )\n", pfn);
ee93020
+		return NULL;
ee93020
+	}
ee93020
+
ee93020
+	page = pfn_to_page(pfn);
ee93020
+
ee93020
+	vaddr = kmap(page);
ee93020
+	if (!vaddr) {
ee93020
+		printk(KERN_INFO
ee93020
+		    "crash memory driver: pfn: %lx kmap(page: %lx) failed\n",
ee93020
+			pfn, (unsigned long)page);
ee93020
+		return NULL;
ee93020
+	}
ee93020
+
ee93020
+	*pp = page;
ee93020
+	return (vaddr + (offset & (PAGE_SIZE-1)));
ee93020
+}
ee93020
+
ee93020
+static inline void unmap_virtual(struct page *page)
ee93020
+{
ee93020
+	kunmap(page);
ee93020
+}
ee93020
+
ee93020
+#endif /* __KERNEL__ */
ee93020
+
ee93020
+#endif /* __CRASH_H__ */
8e3ae98
-- 
1d791ed
2.1.0
Jesse Keating 7a32965