68d0d6
Bugzilla: N/A
68d0d6
Upstream-status: Fedora mustard
68d0d6
97686d
From 1786bc697d34af944e29437ce44337b0eb8b6799 Mon Sep 17 00:00:00 2001
0a346e
From: Kyle McMartin <kyle@dreadnought.bos.jkkm.org>
97686d
Date: Tue, 26 Nov 2013 12:42:46 -0500
0a346e
Subject: [PATCH] crash-driver
Jesse Keating 7a3296
Jesse Keating 7a3296
---
0a346e
 arch/arm/include/asm/crash.h     |   6 ++
0a346e
 arch/arm64/include/asm/crash.h   |   6 ++
0a346e
 arch/ia64/include/asm/crash.h    |  90 +++++++++++++++++++++++++++
0a346e
 arch/ia64/kernel/ia64_ksyms.c    |   3 +
0a346e
 arch/powerpc/include/asm/crash.h |   6 ++
0a346e
 arch/s390/include/asm/crash.h    |  60 ++++++++++++++++++
97686d
 arch/s390/mm/maccess.c           |   2 +
0a346e
 arch/x86/include/asm/crash.h     |   6 ++
0a346e
 drivers/char/Kconfig             |   3 +
0a346e
 drivers/char/Makefile            |   2 +
0a346e
 drivers/char/crash.c             | 128 +++++++++++++++++++++++++++++++++++++++
0a346e
 include/asm-generic/crash.h      |  72 ++++++++++++++++++++++
97686d
 12 files changed, 384 insertions(+)
0a346e
 create mode 100644 arch/arm/include/asm/crash.h
0a346e
 create mode 100644 arch/arm64/include/asm/crash.h
Jesse Keating 7a3296
 create mode 100644 arch/ia64/include/asm/crash.h
0a346e
 create mode 100644 arch/powerpc/include/asm/crash.h
0a346e
 create mode 100644 arch/s390/include/asm/crash.h
Jesse Keating 7a3296
 create mode 100644 arch/x86/include/asm/crash.h
Jesse Keating 7a3296
 create mode 100644 drivers/char/crash.c
0a346e
 create mode 100644 include/asm-generic/crash.h
Jesse Keating 7a3296
0a346e
diff --git a/arch/arm/include/asm/crash.h b/arch/arm/include/asm/crash.h
0a346e
new file mode 100644
0a346e
index 0000000..1d2e537
0a346e
--- /dev/null
0a346e
+++ b/arch/arm/include/asm/crash.h
0a346e
@@ -0,0 +1,6 @@
0a346e
+#ifndef _ARM_CRASH_H
0a346e
+#define _ARM_CRASH_H
0a346e
+
0a346e
+#include <asm-generic/crash.h>
0a346e
+
0a346e
+#endif /* _ARM_CRASH_H */
0a346e
diff --git a/arch/arm64/include/asm/crash.h b/arch/arm64/include/asm/crash.h
0a346e
new file mode 100644
0a346e
index 0000000..a7fcc28
0a346e
--- /dev/null
0a346e
+++ b/arch/arm64/include/asm/crash.h
0a346e
@@ -0,0 +1,6 @@
0a346e
+#ifndef _ARM64_CRASH_H
0a346e
+#define _ARM64_CRASH_H
0a346e
+
0a346e
+#include <asm-generic/crash.h>
0a346e
+
0a346e
+#endif /* _ARM64_CRASH_H */
Jesse Keating 7a3296
diff --git a/arch/ia64/include/asm/crash.h b/arch/ia64/include/asm/crash.h
Jesse Keating 7a3296
new file mode 100644
0a346e
index 0000000..28bd955
Jesse Keating 7a3296
--- /dev/null
Jesse Keating 7a3296
+++ b/arch/ia64/include/asm/crash.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
+/*
Jesse Keating 7a3296
+ * linux/include/asm-ia64/crash.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
0a346e
index 5b7791d..aee4b87 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);
0a346e
diff --git a/arch/powerpc/include/asm/crash.h b/arch/powerpc/include/asm/crash.h
Jesse Keating 7a3296
new file mode 100644
0a346e
index 0000000..daa8c4d
Jesse Keating 7a3296
--- /dev/null
0a346e
+++ b/arch/powerpc/include/asm/crash.h
0a346e
@@ -0,0 +1,6 @@
0a346e
+#ifndef _PPC64_CRASH_H
0a346e
+#define _PPC64_CRASH_H
Jesse Keating 7a3296
+
0a346e
+#include <asm-generic/crash.h>
0a346e
+
0a346e
+#endif /* _PPC64_CRASH_H */
0a346e
diff --git a/arch/s390/include/asm/crash.h b/arch/s390/include/asm/crash.h
0a346e
new file mode 100644
0a346e
index 0000000..552be5e
0a346e
--- /dev/null
0a346e
+++ b/arch/s390/include/asm/crash.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
97686d
index d1e0e0c..a2be459 100644
97686d
--- a/arch/s390/mm/maccess.c
97686d
+++ b/arch/s390/mm/maccess.c
97686d
@@ -219,6 +219,7 @@ void *xlate_dev_mem_ptr(unsigned long 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)
97686d
@@ -228,3 +229,4 @@ void unxlate_dev_mem_ptr(unsigned long addr, void *buf)
97686d
 	if ((void *) addr != buf)
97686d
 		free_page((unsigned long) buf);
97686d
 }
97686d
+EXPORT_SYMBOL_GPL(unxlate_dev_mem_ptr);
0a346e
diff --git a/arch/x86/include/asm/crash.h b/arch/x86/include/asm/crash.h
0a346e
new file mode 100644
0a346e
index 0000000..27a4156
0a346e
--- /dev/null
0a346e
+++ b/arch/x86/include/asm/crash.h
0a346e
@@ -0,0 +1,6 @@
0a346e
+#ifndef _X86_CRASH_H
0a346e
+#define _X86_CRASH_H
0a346e
+
0a346e
+#include <asm-generic/crash.h>
0a346e
+
0a346e
+#endif /* _X86_CRASH_H */
Josh Boyer 8e3ae9
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
97686d
index fa3243d..83643e5b 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
 
Josh Boyer 8e3ae9
 config DEVKMEM
Josh Boyer 8e3ae9
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
0a346e
index 7ff1d0d..3ed67af 100644
Josh Boyer 8e3ae9
--- a/drivers/char/Makefile
Josh Boyer 8e3ae9
+++ b/drivers/char/Makefile
0a346e
@@ -62,3 +62,5 @@ obj-$(CONFIG_JS_RTC)		+= js-rtc.o
Josh Boyer 8e3ae9
 js-rtc-y = rtc.o
Josh Boyer 8e3ae9
 
Josh Boyer 8e3ae9
 obj-$(CONFIG_TILE_SROM)		+= tile-srom.o
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
0a346e
index 0000000..a142bb3
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>
Jesse Keating 7a3296
+#include <asm/crash.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");
0a346e
diff --git a/include/asm-generic/crash.h b/include/asm-generic/crash.h
0a346e
new file mode 100644
0a346e
index 0000000..8a0a69a
0a346e
--- /dev/null
0a346e
+++ b/include/asm-generic/crash.h
0a346e
@@ -0,0 +1,72 @@
0a346e
+#ifndef __CRASH_H__
0a346e
+#define __CRASH_H__
0a346e
+
0a346e
+/*
0a346e
+ * include/linux/crash.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__ */
Josh Boyer 8e3ae9
-- 
0a346e
1.8.3.1
Jesse Keating 7a3296