1 /* 2 * Copyright (C) 2005 Hewlett-Packard Co. 3 * written by Aravind Menon & Jose Renato Santos 4 * (email: xenoprof@groups.hp.com) 5 * 6 * Copyright (c) 2006 Isaku Yamahata <yamahata at valinux co jp> 7 * VA Linux Systems Japan K.K. 8 * x86 specific part 9 */ 10 11 #include <xen/guest_access.h> 12 #include <xen/sched.h> 13 #include <xen/xenoprof.h> 14 #include <public/xenoprof.h> 15 #include <compat/xenoprof.h> 16 #include <asm/hvm/support.h> 17 18 #include "op_counter.h" 19 xenoprof_arch_counter(XEN_GUEST_HANDLE_PARAM (void)arg)20int xenoprof_arch_counter(XEN_GUEST_HANDLE_PARAM(void) arg) 21 { 22 struct xenoprof_counter counter; 23 24 if ( copy_from_guest(&counter, arg, 1) ) 25 return -EFAULT; 26 27 if ( counter.ind >= OP_MAX_COUNTER ) 28 return -E2BIG; 29 30 counter_config[counter.ind].count = counter.count; 31 counter_config[counter.ind].enabled = counter.enabled; 32 counter_config[counter.ind].event = counter.event; 33 counter_config[counter.ind].kernel = counter.kernel; 34 counter_config[counter.ind].user = counter.user; 35 counter_config[counter.ind].unit_mask = counter.unit_mask; 36 37 return 0; 38 } 39 xenoprof_arch_ibs_counter(XEN_GUEST_HANDLE_PARAM (void)arg)40int xenoprof_arch_ibs_counter(XEN_GUEST_HANDLE_PARAM(void) arg) 41 { 42 struct xenoprof_ibs_counter ibs_counter; 43 44 if ( copy_from_guest(&ibs_counter, arg, 1) ) 45 return -EFAULT; 46 47 ibs_config.op_enabled = ibs_counter.op_enabled; 48 ibs_config.fetch_enabled = ibs_counter.fetch_enabled; 49 ibs_config.max_cnt_fetch = ibs_counter.max_cnt_fetch; 50 ibs_config.max_cnt_op = ibs_counter.max_cnt_op; 51 ibs_config.rand_en = ibs_counter.rand_en; 52 ibs_config.dispatched_ops = ibs_counter.dispatched_ops; 53 54 return 0; 55 } 56 compat_oprof_arch_counter(XEN_GUEST_HANDLE_PARAM (void)arg)57int compat_oprof_arch_counter(XEN_GUEST_HANDLE_PARAM(void) arg) 58 { 59 struct compat_oprof_counter counter; 60 61 if ( copy_from_guest(&counter, arg, 1) ) 62 return -EFAULT; 63 64 if ( counter.ind >= OP_MAX_COUNTER ) 65 return -E2BIG; 66 67 counter_config[counter.ind].count = counter.count; 68 counter_config[counter.ind].enabled = counter.enabled; 69 counter_config[counter.ind].event = counter.event; 70 counter_config[counter.ind].kernel = counter.kernel; 71 counter_config[counter.ind].user = counter.user; 72 counter_config[counter.ind].unit_mask = counter.unit_mask; 73 74 return 0; 75 } 76 xenoprofile_get_mode(struct vcpu * curr,const struct cpu_user_regs * regs)77int xenoprofile_get_mode(struct vcpu *curr, const struct cpu_user_regs *regs) 78 { 79 if ( !guest_mode(regs) ) 80 return 2; 81 82 if ( !is_hvm_vcpu(curr) ) 83 return guest_kernel_mode(curr, regs); 84 85 switch ( hvm_guest_x86_mode(curr) ) 86 { 87 case 0: /* real mode */ 88 return 1; 89 case 1: /* vm86 mode */ 90 return 0; 91 default: 92 return hvm_get_cpl(curr) != 3; 93 } 94 } 95 96 /* 97 * Local variables: 98 * mode: C 99 * c-file-style: "BSD" 100 * c-basic-offset: 4 101 * tab-width: 4 102 * indent-tabs-mode: nil 103 * End: 104 */ 105