2011-08-04 13:55:54 +00:00
|
|
|
From f72d640713d01b3b704c6e84ab49b62f19fc9c22 Mon Sep 17 00:00:00 2001
|
2010-07-29 23:46:31 +00:00
|
|
|
From: Kyle McMartin <kyle@phobos.i.jkkm.org>
|
|
|
|
Date: Tue, 30 Mar 2010 00:16:25 -0400
|
2011-08-04 13:55:54 +00:00
|
|
|
Subject: [PATCH] dev-crash-driver.patch
|
2010-07-29 23:46:31 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
arch/ia64/include/asm/crash.h | 90 +++++++++++++++++++++++++++++
|
|
|
|
arch/ia64/kernel/ia64_ksyms.c | 3 +
|
|
|
|
arch/x86/include/asm/crash.h | 75 ++++++++++++++++++++++++
|
|
|
|
arch/x86/mm/ioremap.c | 2 +
|
2011-08-04 13:55:54 +00:00
|
|
|
drivers/char/Kconfig | 3 +
|
2010-07-29 23:46:31 +00:00
|
|
|
drivers/char/Makefile | 2 +
|
|
|
|
drivers/char/crash.c | 128 +++++++++++++++++++++++++++++++++++++++++
|
2011-08-04 13:55:54 +00:00
|
|
|
7 files changed, 303 insertions(+), 0 deletions(-)
|
2010-07-29 23:46:31 +00:00
|
|
|
create mode 100644 arch/ia64/include/asm/crash.h
|
|
|
|
create mode 100644 arch/x86/include/asm/crash.h
|
|
|
|
create mode 100644 drivers/char/crash.c
|
|
|
|
|
|
|
|
diff --git a/arch/ia64/include/asm/crash.h b/arch/ia64/include/asm/crash.h
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..541af84
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/arch/ia64/include/asm/crash.h
|
|
|
|
@@ -0,0 +1,90 @@
|
|
|
|
+#ifndef _ASM_IA64_CRASH_H
|
|
|
|
+#define _ASM_IA64_CRASH_H
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+ * linux/include/asm-ia64/crash.h
|
|
|
|
+ *
|
|
|
|
+ * Copyright (c) 2004 Red Hat, Inc. All rights reserved.
|
|
|
|
+ *
|
|
|
|
+ * This program is free software; you can redistribute it and/or modify
|
|
|
|
+ * it under the terms of the GNU General Public License as published by
|
|
|
|
+ * the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
+ * any later version.
|
|
|
|
+ *
|
|
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
+ * GNU General Public License for more details.
|
|
|
|
+ *
|
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
|
+ * along with this program; if not, write to the Free Software
|
|
|
|
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+#ifdef __KERNEL__
|
|
|
|
+
|
|
|
|
+#include <linux/efi.h>
|
|
|
|
+#include <linux/mm.h>
|
|
|
|
+#include <asm/mmzone.h>
|
|
|
|
+
|
|
|
|
+static inline void *
|
|
|
|
+map_virtual(u64 offset, struct page **pp)
|
|
|
|
+{
|
|
|
|
+ struct page *page;
|
|
|
|
+ unsigned long pfn;
|
|
|
|
+ u32 type;
|
|
|
|
+
|
|
|
|
+ if (REGION_NUMBER(offset) == 5) {
|
|
|
|
+ char byte;
|
|
|
|
+
|
|
|
|
+ if (__get_user(byte, (char *)offset) == 0)
|
|
|
|
+ return (void *)offset;
|
|
|
|
+ else
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ switch (type = efi_mem_type(offset))
|
|
|
|
+ {
|
|
|
|
+ case EFI_LOADER_CODE:
|
|
|
|
+ case EFI_LOADER_DATA:
|
|
|
|
+ case EFI_BOOT_SERVICES_CODE:
|
|
|
|
+ case EFI_BOOT_SERVICES_DATA:
|
|
|
|
+ case EFI_CONVENTIONAL_MEMORY:
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ default:
|
|
|
|
+ printk(KERN_INFO
|
|
|
|
+ "crash memory driver: invalid memory type for %lx: %d\n",
|
|
|
|
+ offset, type);
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pfn = offset >> PAGE_SHIFT;
|
|
|
|
+
|
|
|
|
+ if (!pfn_valid(pfn)) {
|
|
|
|
+ printk(KERN_INFO
|
|
|
|
+ "crash memory driver: invalid pfn: %lx )\n", pfn);
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ page = pfn_to_page(pfn);
|
|
|
|
+
|
|
|
|
+ if (!page->virtual) {
|
|
|
|
+ printk(KERN_INFO
|
|
|
|
+ "crash memory driver: offset: %lx page: %lx page->virtual: NULL\n",
|
|
|
|
+ offset, (unsigned long)page);
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return (page->virtual + (offset & (PAGE_SIZE-1)));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static inline void unmap_virtual(struct page *page)
|
|
|
|
+{
|
|
|
|
+ return;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#endif /* __KERNEL__ */
|
|
|
|
+
|
|
|
|
+#endif /* _ASM_IA64_CRASH_H */
|
|
|
|
diff --git a/arch/ia64/kernel/ia64_ksyms.c b/arch/ia64/kernel/ia64_ksyms.c
|
|
|
|
index 7f4a0ed..552fe24 100644
|
|
|
|
--- a/arch/ia64/kernel/ia64_ksyms.c
|
|
|
|
+++ b/arch/ia64/kernel/ia64_ksyms.c
|
|
|
|
@@ -84,6 +84,9 @@ EXPORT_SYMBOL(ia64_save_scratch_fpregs);
|
|
|
|
#include <asm/unwind.h>
|
|
|
|
EXPORT_SYMBOL(unw_init_running);
|
|
|
|
|
|
|
|
+#include <linux/efi.h>
|
|
|
|
+EXPORT_SYMBOL_GPL(efi_mem_type);
|
|
|
|
+
|
|
|
|
#if defined(CONFIG_IA64_ESI) || defined(CONFIG_IA64_ESI_MODULE)
|
|
|
|
extern void esi_call_phys (void);
|
|
|
|
EXPORT_SYMBOL_GPL(esi_call_phys);
|
|
|
|
diff --git a/arch/x86/include/asm/crash.h b/arch/x86/include/asm/crash.h
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..dfcc006
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/arch/x86/include/asm/crash.h
|
2013-07-10 14:33:31 +00:00
|
|
|
@@ -0,0 +1,73 @@
|
2010-07-29 23:46:31 +00:00
|
|
|
+#ifndef _ASM_I386_CRASH_H
|
|
|
|
+#define _ASM_I386_CRASH_H
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+ * linux/include/asm-i386/crash.h
|
|
|
|
+ *
|
|
|
|
+ * Copyright (c) 2004 Red Hat, Inc. All rights reserved.
|
|
|
|
+ *
|
|
|
|
+ * This program is free software; you can redistribute it and/or modify
|
|
|
|
+ * it under the terms of the GNU General Public License as published by
|
|
|
|
+ * the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
+ * any later version.
|
|
|
|
+ *
|
|
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
+ * GNU General Public License for more details.
|
|
|
|
+ *
|
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
|
+ * along with this program; if not, write to the Free Software
|
|
|
|
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+#ifdef __KERNEL__
|
|
|
|
+
|
|
|
|
+#include <linux/mm.h>
|
|
|
|
+#include <linux/highmem.h>
|
|
|
|
+#include <asm/mmzone.h>
|
|
|
|
+
|
|
|
|
+static inline void *
|
|
|
|
+map_virtual(u64 offset, struct page **pp)
|
|
|
|
+{
|
|
|
|
+ struct page *page;
|
|
|
|
+ unsigned long pfn;
|
|
|
|
+ void *vaddr;
|
|
|
|
+
|
|
|
|
+ pfn = (unsigned long)(offset >> PAGE_SHIFT);
|
|
|
|
+
|
|
|
|
+ if (!page_is_ram(pfn)) {
|
|
|
|
+ printk(KERN_INFO
|
|
|
|
+ "crash memory driver: !page_is_ram(pfn: %lx)\n", pfn);
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!pfn_valid(pfn)) {
|
|
|
|
+ printk(KERN_INFO
|
|
|
|
+ "crash memory driver: invalid pfn: %lx )\n", pfn);
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ page = pfn_to_page(pfn);
|
|
|
|
+
|
|
|
|
+ vaddr = kmap(page);
|
|
|
|
+ if (!vaddr) {
|
|
|
|
+ printk(KERN_INFO
|
|
|
|
+ "crash memory driver: pfn: %lx kmap(page: %lx) failed\n",
|
|
|
|
+ pfn, (unsigned long)page);
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ *pp = page;
|
|
|
|
+ return (vaddr + (offset & (PAGE_SIZE-1)));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static inline void unmap_virtual(struct page *page)
|
|
|
|
+{
|
|
|
|
+ kunmap(page);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#endif /* __KERNEL__ */
|
|
|
|
+
|
|
|
|
+#endif /* _ASM_I386_CRASH_H */
|
2011-08-04 13:55:54 +00:00
|
|
|
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
|
|
|
|
index 423fd56..e04a561 100644
|
|
|
|
--- a/drivers/char/Kconfig
|
|
|
|
+++ b/drivers/char/Kconfig
|
|
|
|
@@ -4,6 +4,9 @@
|
|
|
|
|
|
|
|
menu "Character devices"
|
|
|
|
|
|
|
|
+config CRASH
|
|
|
|
+ tristate "Crash Utility memory driver"
|
|
|
|
+
|
|
|
|
source "drivers/tty/Kconfig"
|
|
|
|
|
|
|
|
config DEVKMEM
|
|
|
|
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
|
|
|
|
index 32762ba..3d5d525 100644
|
|
|
|
--- a/drivers/char/Makefile
|
|
|
|
+++ b/drivers/char/Makefile
|
|
|
|
@@ -65,3 +65,5 @@ obj-$(CONFIG_JS_RTC) += js-rtc.o
|
|
|
|
js-rtc-y = rtc.o
|
|
|
|
|
|
|
|
obj-$(CONFIG_TILE_SROM) += tile-srom.o
|
|
|
|
+
|
|
|
|
+obj-$(CONFIG_CRASH) += crash.o
|
2010-07-29 23:46:31 +00:00
|
|
|
diff --git a/drivers/char/crash.c b/drivers/char/crash.c
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..e5437de
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/drivers/char/crash.c
|
|
|
|
@@ -0,0 +1,128 @@
|
|
|
|
+/*
|
|
|
|
+ * linux/drivers/char/crash.c
|
|
|
|
+ *
|
|
|
|
+ * Copyright (C) 2004 Dave Anderson <anderson@redhat.com>
|
|
|
|
+ * Copyright (C) 2004 Red Hat, Inc.
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+/******************************************************************************
|
|
|
|
+ *
|
|
|
|
+ * This program is free software; you can redistribute it and/or modify
|
|
|
|
+ * it under the terms of the GNU General Public License as published by
|
|
|
|
+ * the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
+ * any later version.
|
|
|
|
+ *
|
|
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
+ * GNU General Public License for more details.
|
|
|
|
+ *
|
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
|
+ * along with this program; if not, write to the Free Software
|
|
|
|
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
+ *
|
|
|
|
+ *****************************************************************************/
|
|
|
|
+
|
|
|
|
+#include <linux/module.h>
|
|
|
|
+#include <linux/types.h>
|
|
|
|
+#include <linux/miscdevice.h>
|
|
|
|
+#include <linux/init.h>
|
|
|
|
+#include <asm/io.h>
|
|
|
|
+#include <asm/uaccess.h>
|
|
|
|
+#include <asm/types.h>
|
|
|
|
+#include <asm/crash.h>
|
|
|
|
+
|
|
|
|
+#define CRASH_VERSION "1.0"
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+ * These are the file operation functions that allow crash utility
|
|
|
|
+ * access to physical memory.
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+static loff_t
|
|
|
|
+crash_llseek(struct file * file, loff_t offset, int orig)
|
|
|
|
+{
|
|
|
|
+ switch (orig) {
|
|
|
|
+ case 0:
|
|
|
|
+ file->f_pos = offset;
|
|
|
|
+ return file->f_pos;
|
|
|
|
+ case 1:
|
|
|
|
+ file->f_pos += offset;
|
|
|
|
+ return file->f_pos;
|
|
|
|
+ default:
|
|
|
|
+ return -EINVAL;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+ * Determine the page address for an address offset value,
|
|
|
|
+ * get a virtual address for it, and copy it out.
|
|
|
|
+ * Accesses must fit within a page.
|
|
|
|
+ */
|
|
|
|
+static ssize_t
|
|
|
|
+crash_read(struct file *file, char *buf, size_t count, loff_t *poff)
|
|
|
|
+{
|
|
|
|
+ void *vaddr;
|
|
|
|
+ struct page *page;
|
|
|
|
+ u64 offset;
|
|
|
|
+ ssize_t read;
|
|
|
|
+
|
|
|
|
+ offset = *poff;
|
|
|
|
+ if (offset >> PAGE_SHIFT != (offset+count-1) >> PAGE_SHIFT)
|
|
|
|
+ return -EINVAL;
|
|
|
|
+
|
|
|
|
+ vaddr = map_virtual(offset, &page);
|
|
|
|
+ if (!vaddr)
|
|
|
|
+ return -EFAULT;
|
|
|
|
+
|
|
|
|
+ if (copy_to_user(buf, vaddr, count)) {
|
|
|
|
+ unmap_virtual(page);
|
|
|
|
+ return -EFAULT;
|
|
|
|
+ }
|
|
|
|
+ unmap_virtual(page);
|
|
|
|
+
|
|
|
|
+ read = count;
|
|
|
|
+ *poff += read;
|
|
|
|
+ return read;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static struct file_operations crash_fops = {
|
|
|
|
+ .owner = THIS_MODULE,
|
|
|
|
+ .llseek = crash_llseek,
|
|
|
|
+ .read = crash_read,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static struct miscdevice crash_dev = {
|
|
|
|
+ MISC_DYNAMIC_MINOR,
|
|
|
|
+ "crash",
|
|
|
|
+ &crash_fops
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static int __init
|
|
|
|
+crash_init(void)
|
|
|
|
+{
|
|
|
|
+ int ret;
|
|
|
|
+
|
|
|
|
+ ret = misc_register(&crash_dev);
|
|
|
|
+ if (ret) {
|
|
|
|
+ printk(KERN_ERR
|
|
|
|
+ "crash memory driver: cannot misc_register (MISC_DYNAMIC_MINOR)\n");
|
|
|
|
+ goto out;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ret = 0;
|
|
|
|
+ printk(KERN_INFO "crash memory driver: version %s\n", CRASH_VERSION);
|
|
|
|
+out:
|
|
|
|
+ return ret;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void __exit
|
|
|
|
+crash_cleanup_module(void)
|
|
|
|
+{
|
|
|
|
+ misc_deregister(&crash_dev);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+module_init(crash_init);
|
|
|
|
+module_exit(crash_cleanup_module);
|
|
|
|
+
|
|
|
|
+MODULE_LICENSE("GPL");
|
2011-08-04 13:55:54 +00:00
|
|
|
--
|
|
|
|
1.7.6
|
2010-07-29 23:46:31 +00:00
|
|
|
|