debuggers.hg

view xenolinux-2.4.21-sparse/arch/xeno/drivers/dom0/dom0_core.c @ 647:f36f032527a0

bitkeeper revision 1.339.1.2 (3f109e02qA-VmVFt9cmV0JaASgeSeg)

proc_cmd.h, dom0_core.c, xl_block.c:
Bug fixes to new proc interface.
author kaf24@scramble.cl.cam.ac.uk
date Sat Jul 12 23:47:14 2003 +0000 (2003-07-12)
parents 9339f3942f4e
children cda951fc1bef
line source
1 /******************************************************************************
2 * dom0_core.c
3 *
4 * Interface to privileged domain-0 commands.
5 *
6 * Copyright (c) 2002-2003, K A Fraser, B Dragovic
7 */
9 #include <linux/config.h>
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/sched.h>
13 #include <linux/slab.h>
14 #include <linux/string.h>
15 #include <linux/errno.h>
16 #include <linux/proc_fs.h>
17 #include <linux/mm.h>
18 #include <linux/mman.h>
19 #include <linux/swap.h>
20 #include <linux/smp_lock.h>
21 #include <linux/swapctl.h>
22 #include <linux/iobuf.h>
23 #include <linux/highmem.h>
24 #include <linux/pagemap.h>
25 #include <linux/seq_file.h>
27 #include <asm/pgalloc.h>
28 #include <asm/pgtable.h>
29 #include <asm/uaccess.h>
30 #include <asm/tlb.h>
31 #include <asm/proc_cmd.h>
32 #include <asm/hypervisor-ifs/dom0_ops.h>
34 #include "../block/xl_block.h"
36 struct proc_dir_entry *xeno_base;
37 static struct proc_dir_entry *privcmd_intf;
40 static int privcmd_ioctl(struct inode *inode, struct file *file,
41 unsigned int cmd, unsigned long data)
42 {
43 int ret = 0;
45 switch ( cmd )
46 {
47 case IOCTL_PRIVCMD_HYPERCALL:
48 {
49 privcmd_hypercall_t hypercall;
51 if ( copy_from_user(&hypercall, (void *)data, sizeof(hypercall)) )
52 return -EFAULT;
54 __asm__ __volatile__ (
55 "pushl %%ebx; pushl %%ecx; pushl %%edx; pushl %%esi; pushl %%edi; "
56 "movl 4(%%eax),%%ebx ;"
57 "movl 8(%%eax),%%ecx ;"
58 "movl 12(%%eax),%%edx ;"
59 "movl 16(%%eax),%%esi ;"
60 "movl 20(%%eax),%%edi ;"
61 "movl (%%eax),%%eax ;"
62 TRAP_INSTR "; "
63 "popl %%edi; popl %%esi; popl %%edx; popl %%ecx; popl %%ebx"
64 : "=a" (ret) : "0" (&hypercall) : "memory" );
65 }
66 break;
68 case IOCTL_PRIVCMD_BLKMSG:
69 {
70 privcmd_blkmsg_t blkmsg;
71 char *kbuf;
72 int ret;
74 if ( copy_from_user(&blkmsg, (void *)data, sizeof(blkmsg)) )
75 return -EFAULT;
77 if ( blkmsg.buf_size > PAGE_SIZE )
78 return -EINVAL;
80 if ( (kbuf = kmalloc(blkmsg.buf_size, GFP_KERNEL)) == NULL )
81 return -ENOMEM;
83 if ( copy_from_user(kbuf, blkmsg.buf, blkmsg.buf_size) ) {
84 kfree(kbuf);
85 return -EFAULT;
86 }
88 ret = xenolinux_control_msg((int)blkmsg.op, kbuf, blkmsg.buf_size);
89 if ( ret != 0 ) {
90 kfree(kbuf);
91 return ret;
92 }
94 if ( copy_to_user(blkmsg.buf, kbuf, blkmsg.buf_size) ) {
95 kfree(kbuf);
96 return -EFAULT;
97 }
99 kfree(kbuf);
100 }
101 break;
103 case IOCTL_PRIVCMD_LINDEV_TO_XENDEV:
104 {
105 ret = (int)xldev_to_physdev((kdev_t)data);
106 }
107 break;
109 case IOCTL_PRIVCMD_XENDEV_TO_LINDEV:
110 {
111 ret = (int)physdev_to_xldev((unsigned short)data);
112 }
113 break;
115 default:
116 {
117 ret = -EINVAL;
118 }
119 break;
120 }
122 return ret;
123 }
126 static struct file_operations privcmd_file_ops = {
127 ioctl : privcmd_ioctl
128 };
131 static int __init init_module(void)
132 {
133 if ( !(start_info.flags & SIF_PRIVILEGED) )
134 return 0;
136 /* xeno proc root setup */
137 xeno_base = proc_mkdir("xeno", &proc_root);
139 /* xeno control interface */
140 privcmd_intf = create_proc_entry("privcmd", 0400, xeno_base);
141 if ( privcmd_intf != NULL )
142 {
143 privcmd_intf->owner = THIS_MODULE;
144 privcmd_intf->nlink = 1;
145 privcmd_intf->proc_fops = &privcmd_file_ops;
146 }
148 return 0;
149 }
152 static void __exit cleanup_module(void)
153 {
154 if ( privcmd_intf == NULL ) return;
155 remove_proc_entry("xeno", &proc_root);
156 privcmd_intf = NULL;
157 }
160 module_init(init_module);
161 module_exit(cleanup_module);