source: trunk/packages/xen-3.1/xen-3.1/xen/arch/ia64/vmx/vmx_hypercall.c @ 34

Last change on this file since 34 was 34, checked in by hartmans, 17 years ago

Add xen and xen-common

File size: 3.9 KB
Line 
1/* -*-  Mode:C; c-basic-offset:4; tab-width:4; indent-tabs-mode:nil -*- */
2/*
3 * vmx_hyparcall.c: handling hypercall from domain
4 * Copyright (c) 2005, Intel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place - Suite 330, Boston, MA 02111-1307 USA.
18 *
19 *  Xuefei Xu (Anthony Xu) (Anthony.xu@intel.com)
20 */
21
22#include <xen/config.h>
23#include <xen/errno.h>
24#include <asm/vmx_vcpu.h>
25#include <xen/guest_access.h>
26#include <public/event_channel.h>
27#include <asm/vmmu.h>
28#include <asm/tlb.h>
29#include <asm/regionreg.h>
30#include <asm/page.h>
31#include <xen/mm.h>
32#include <xen/multicall.h>
33#include <xen/hypercall.h>
34#include <public/version.h>
35#include <asm/dom_fw.h>
36#include <xen/domain.h>
37#include <asm/vmx.h>
38#include <asm/viosapic.h>
39
40static int hvmop_set_isa_irq_level(
41    XEN_GUEST_HANDLE(xen_hvm_set_isa_irq_level_t) uop)
42{
43    struct xen_hvm_set_isa_irq_level op;
44    struct domain *d;
45    int rc;
46
47    if ( copy_from_guest(&op, uop, 1) )
48        return -EFAULT;
49
50    if ( !IS_PRIV(current->domain) )
51        return -EPERM;
52
53    if ( op.isa_irq > 15 )
54        return -EINVAL;
55
56    d = get_domain_by_id(op.domid);
57    if ( d == NULL )
58        return -ESRCH;
59
60    rc = -EINVAL;
61    if ( !is_hvm_domain(d) )
62        goto out;
63
64    rc = 0;
65    viosapic_set_irq(d, op.isa_irq, op.level);
66
67 out:
68    put_domain(d);
69    return rc;
70}
71
72static int hvmop_set_pci_intx_level(
73    XEN_GUEST_HANDLE(xen_hvm_set_pci_intx_level_t) uop)
74{
75    struct xen_hvm_set_pci_intx_level op;
76    struct domain *d;
77    int rc;
78
79    if ( copy_from_guest(&op, uop, 1) )
80        return -EFAULT;
81
82    if ( !IS_PRIV(current->domain) )
83        return -EPERM;
84
85    if ( (op.domain > 0) || (op.bus > 0) || (op.device > 31) || (op.intx > 3) )
86        return -EINVAL;
87
88    d = get_domain_by_id(op.domid);
89    if ( d == NULL )
90        return -ESRCH;
91
92    rc = -EINVAL;
93    if ( !is_hvm_domain(d) )
94        goto out;
95
96    rc = 0;
97    viosapic_set_pci_irq(d, op.device, op.intx, op.level);
98
99 out:
100    put_domain(d);
101    return rc;
102}
103
104
105
106long
107do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void) arg)
108{
109    long rc = 0;
110
111    switch (op) {
112    case HVMOP_set_param:
113    case HVMOP_get_param:
114    {
115        struct xen_hvm_param a;
116        struct domain *d;
117
118        if (copy_from_guest(&a, arg, 1))
119            return -EFAULT;
120
121        if (a.index > HVM_NR_PARAMS)
122            return -EINVAL;
123
124        if (a.domid == DOMID_SELF) {
125            d = get_current_domain();
126        }
127        else if (IS_PRIV(current->domain)) {
128            d = get_domain_by_id(a.domid);
129            if (d == NULL)
130                return -ESRCH;
131        }
132        else
133            return -EPERM;
134
135        if (op == HVMOP_set_param) {
136            d->arch.hvm_domain.params[a.index] = a.value;
137            rc = 0;
138        }
139        else {
140            a.value = d->arch.hvm_domain.params[a.index];
141            rc = copy_to_guest(arg, &a, 1) ? -EFAULT : 0;
142        }
143
144        put_domain(d);
145        break;
146    }
147
148    case HVMOP_set_pci_intx_level:
149        rc = hvmop_set_pci_intx_level(
150            guest_handle_cast(arg, xen_hvm_set_pci_intx_level_t));
151        break;
152
153    case HVMOP_set_isa_irq_level:
154        rc = hvmop_set_isa_irq_level(
155            guest_handle_cast(arg, xen_hvm_set_isa_irq_level_t));
156        break;
157
158    case HVMOP_set_pci_link_route:
159        rc = 0;
160        break;
161
162    default:
163        gdprintk(XENLOG_INFO, "Bad HVM op %ld.\n", op);
164        rc = -ENOSYS;
165    }
166    return rc;
167}
Note: See TracBrowser for help on using the repository browser.