aboutsummaryrefslogtreecommitdiff
path: root/xen/common/dom0_ops.c
blob: 3ac6e72c0f3b78dbc6064572bbb6a5fa835ec8c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/******************************************************************************
 * dom0_ops.c
 * 
 * Process command requests from domain-0 guest OS.
 * 
 * Copyright (c) 2002, K A Fraser
 */

#include <xeno/config.h>
#include <xeno/types.h>
#include <xeno/lib.h>
#include <xeno/mm.h>
#include <xeno/dom0_ops.h>
#include <xeno/sched.h>
#include <xeno/event.h>
#include <asm/domain_page.h>

extern unsigned int alloc_new_dom_mem(struct task_struct *, unsigned int);

static unsigned int get_domnr(void)
{
    static unsigned int domnr = 0;
    return ++domnr;
}

static void build_page_list(struct task_struct *p)
{
    unsigned long *list;
    unsigned long curr;
    struct list_head *list_ent;

    curr = list_entry(p->pg_head.next, struct pfn_info, list) - frame_table;
    list = (unsigned long *)map_domain_mem(curr << PAGE_SHIFT);

    list_for_each(list_ent, &p->pg_head)
    {
        *list++ = list_entry(list_ent, struct pfn_info, list) - frame_table;

        if( ((unsigned long)list & ~PAGE_MASK) == 0 )
        {
            struct list_head *ent = frame_table[curr].list.next;
            curr = list_entry(ent, struct pfn_info, list) - frame_table;
            unmap_domain_mem(list-1);
            list = (unsigned long *)map_domain_mem(curr << PAGE_SHIFT);
        }
    }

    unmap_domain_mem(list);
}
    
long do_dom0_op(dom0_op_t *u_dom0_op)
{
    long ret = 0;
    dom0_op_t op;

    if ( current->domain != 0 )
        return -EPERM;

    if ( copy_from_user(&op, u_dom0_op, sizeof(op)) )
        return -EFAULT;

    switch ( op.cmd )
    {

    case DOM0_STARTDOM:
    {
        struct task_struct * p = find_domain_by_id(op.u.meminfo.domain);
        if ( (ret = final_setup_guestos(p, &op.u.meminfo)) != 0 )
            break;
        wake_up(p);
        reschedule(p);
        ret = p->domain;
        free_task_struct(p);
    }
    break;

    case DOM0_NEWDOMAIN:
    {
        struct task_struct *p;
        static unsigned int pro = 0;
        unsigned int dom = get_domnr();
        ret = -ENOMEM;

        if ( dom == 0 ) 
            break;

        pro = (pro+1) % smp_num_cpus;
        p = do_newdomain(dom, pro);
        if ( p == NULL ) 
            break;

        ret = alloc_new_dom_mem(p, op.u.newdomain.memory_kb);
        if ( ret != 0 ) 
        {
            __kill_domain(p);
            break;
        }

        build_page_list(p);
        
        ret = p->domain;
        
        op.u.newdomain.domain = ret;
        op.u.newdomain.pg_head = 
            list_entry(p->pg_head.next, struct pfn_info, list) -
            frame_table;
        copy_to_user(u_dom0_op, &op, sizeof(op));
    }
    break;

    case DOM0_KILLDOMAIN:
    {
        unsigned int dom = op.u.killdomain.domain;
        int force = op.u.killdomain.force;
        if ( dom == IDLE_DOMAIN_ID )
        {
            ret = -EPERM;
        }
        else
        {
            ret = kill_other_domain(dom, force);
        }
    }
    break;

    case DOM0_BVTCTL:
    {
        unsigned long  ctx_allow = op.u.bvtctl.ctx_allow;
        ret = sched_bvtctl(ctx_allow);
        
    }
    break;

    case DOM0_ADJUSTDOM:
    {
        unsigned int   dom     = op.u.adjustdom.domain;
        unsigned long  mcu_adv = op.u.adjustdom.mcu_adv;
        unsigned long  warp    = op.u.adjustdom.warp;
        unsigned long  warpl   = op.u.adjustdom.warpl;
        unsigned long  warpu   = op.u.adjustdom.warpu;
        

        if ( dom == IDLE_DOMAIN_ID )
        {
            ret = -EPERM;
        }
        else
        {
            ret = sched_adjdom(dom, mcu_adv, warp, warpl, warpu);
        }
    }
    break;

    case DOM0_GETMEMLIST:
    {
        int i;
        unsigned long pfn = op.u.getmemlist.start_pfn;
        unsigned long *buffer = op.u.getmemlist.buffer;
        struct list_head *list_ent;

        for ( i = 0; i < op.u.getmemlist.num_pfns; i++ )
        {
            /* XXX We trust DOM0 to give us a safe buffer. XXX */
            *buffer++ = pfn;
            list_ent = frame_table[pfn].list.next;
            pfn = list_entry(list_ent, struct pfn_info, list) - frame_table;
        }
    }
    break;

    default:
        ret = -ENOSYS;

    }

    return ret;
}