2 * linux/drivers/char/crash.c
4 * Copyright (C) 2004 Dave Anderson <anderson@redhat.com>
5 * Copyright (C) 2004 Red Hat, Inc.
8 /******************************************************************************
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *****************************************************************************/
26 #include <linux/module.h>
27 #include <linux/types.h>
28 #include <linux/miscdevice.h>
29 #include <linux/init.h>
31 #include <asm/uaccess.h>
32 #include <asm/types.h>
33 #include <asm/crash.h>
35 #define CRASH_VERSION "1.0"
38 * These are the file operation functions that allow crash utility
39 * access to physical memory.
43 crash_llseek(struct file * file, loff_t offset, int orig)
50 file->f_pos += offset;
58 * Determine the page address for an address offset value,
59 * get a virtual address for it, and copy it out.
60 * Accesses must fit within a page.
63 crash_read(struct file *file, char *buf, size_t count, loff_t *poff)
71 if (offset >> PAGE_SHIFT != (offset+count-1) >> PAGE_SHIFT)
74 vaddr = map_virtual(offset, &page);
78 if (copy_to_user(buf, vaddr, count)) {
89 static struct file_operations crash_fops = {
91 .llseek = crash_llseek,
95 static struct miscdevice crash_dev = {
106 ret = misc_register(&crash_dev);
109 "crash memory driver: cannot misc_register (MISC_DYNAMIC_MINOR)\n");
114 printk(KERN_INFO "crash memory driver: version %s\n", CRASH_VERSION);
120 crash_cleanup_module(void)
122 misc_deregister(&crash_dev);
125 module_init(crash_init);
126 module_exit(crash_cleanup_module);
128 MODULE_LICENSE("GPL");