1*a215bf01Scherry /* 2*a215bf01Scherry * Permission is hereby granted, free of charge, to any person obtaining a copy 3*a215bf01Scherry * of this software and associated documentation files (the "Software"), to 4*a215bf01Scherry * deal in the Software without restriction, including without limitation the 5*a215bf01Scherry * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 6*a215bf01Scherry * sell copies of the Software, and to permit persons to whom the Software is 7*a215bf01Scherry * furnished to do so, subject to the following conditions: 8*a215bf01Scherry * 9*a215bf01Scherry * The above copyright notice and this permission notice shall be included in 10*a215bf01Scherry * all copies or substantial portions of the Software. 11*a215bf01Scherry * 12*a215bf01Scherry * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13*a215bf01Scherry * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14*a215bf01Scherry * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15*a215bf01Scherry * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16*a215bf01Scherry * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17*a215bf01Scherry * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18*a215bf01Scherry * DEALINGS IN THE SOFTWARE. 19*a215bf01Scherry * 20*a215bf01Scherry * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. 21*a215bf01Scherry */ 22*a215bf01Scherry 23*a215bf01Scherry #ifndef __XEN_PUBLIC_PMU_H__ 24*a215bf01Scherry #define __XEN_PUBLIC_PMU_H__ 25*a215bf01Scherry 26*a215bf01Scherry #include "xen.h" 27*a215bf01Scherry #if defined(__i386__) || defined(__x86_64__) 28*a215bf01Scherry #include "arch-x86/pmu.h" 29*a215bf01Scherry #elif defined (__arm__) || defined (__aarch64__) 30*a215bf01Scherry #include "arch-arm.h" 31*a215bf01Scherry #else 32*a215bf01Scherry #error "Unsupported architecture" 33*a215bf01Scherry #endif 34*a215bf01Scherry 35*a215bf01Scherry #define XENPMU_VER_MAJ 0 36*a215bf01Scherry #define XENPMU_VER_MIN 1 37*a215bf01Scherry 38*a215bf01Scherry /* 39*a215bf01Scherry * ` enum neg_errnoval 40*a215bf01Scherry * ` HYPERVISOR_xenpmu_op(enum xenpmu_op cmd, struct xenpmu_params *args); 41*a215bf01Scherry * 42*a215bf01Scherry * @cmd == XENPMU_* (PMU operation) 43*a215bf01Scherry * @args == struct xenpmu_params 44*a215bf01Scherry */ 45*a215bf01Scherry /* ` enum xenpmu_op { */ 46*a215bf01Scherry #define XENPMU_mode_get 0 /* Also used for getting PMU version */ 47*a215bf01Scherry #define XENPMU_mode_set 1 48*a215bf01Scherry #define XENPMU_feature_get 2 49*a215bf01Scherry #define XENPMU_feature_set 3 50*a215bf01Scherry #define XENPMU_init 4 51*a215bf01Scherry #define XENPMU_finish 5 52*a215bf01Scherry #define XENPMU_lvtpc_set 6 53*a215bf01Scherry #define XENPMU_flush 7 /* Write cached MSR values to HW */ 54*a215bf01Scherry /* ` } */ 55*a215bf01Scherry 56*a215bf01Scherry /* Parameters structure for HYPERVISOR_xenpmu_op call */ 57*a215bf01Scherry struct xen_pmu_params { 58*a215bf01Scherry /* IN/OUT parameters */ 59*a215bf01Scherry struct { 60*a215bf01Scherry uint32_t maj; 61*a215bf01Scherry uint32_t min; 62*a215bf01Scherry } version; 63*a215bf01Scherry uint64_t val; 64*a215bf01Scherry 65*a215bf01Scherry /* IN parameters */ 66*a215bf01Scherry uint32_t vcpu; 67*a215bf01Scherry uint32_t pad; 68*a215bf01Scherry }; 69*a215bf01Scherry typedef struct xen_pmu_params xen_pmu_params_t; 70*a215bf01Scherry DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t); 71*a215bf01Scherry 72*a215bf01Scherry /* PMU modes: 73*a215bf01Scherry * - XENPMU_MODE_OFF: No PMU virtualization 74*a215bf01Scherry * - XENPMU_MODE_SELF: Guests can profile themselves 75*a215bf01Scherry * - XENPMU_MODE_HV: Guests can profile themselves, dom0 profiles 76*a215bf01Scherry * itself and Xen 77*a215bf01Scherry * - XENPMU_MODE_ALL: Only dom0 has access to VPMU and it profiles 78*a215bf01Scherry * everyone: itself, the hypervisor and the guests. 79*a215bf01Scherry */ 80*a215bf01Scherry #define XENPMU_MODE_OFF 0 81*a215bf01Scherry #define XENPMU_MODE_SELF (1<<0) 82*a215bf01Scherry #define XENPMU_MODE_HV (1<<1) 83*a215bf01Scherry #define XENPMU_MODE_ALL (1<<2) 84*a215bf01Scherry 85*a215bf01Scherry /* 86*a215bf01Scherry * PMU features: 87*a215bf01Scherry * - XENPMU_FEATURE_INTEL_BTS: Intel BTS support (ignored on AMD) 88*a215bf01Scherry * - XENPMU_FEATURE_IPC_ONLY: Restrict PMCs to the most minimum set possible. 89*a215bf01Scherry * Instructions, cycles, and ref cycles. Can be 90*a215bf01Scherry * used to calculate instructions-per-cycle (IPC) 91*a215bf01Scherry * (ignored on AMD). 92*a215bf01Scherry * - XENPMU_FEATURE_ARCH_ONLY: Restrict PMCs to the Intel Pre-Defined 93*a215bf01Scherry * Architectural Performance Events exposed by 94*a215bf01Scherry * cpuid and listed in the Intel developer's manual 95*a215bf01Scherry * (ignored on AMD). 96*a215bf01Scherry */ 97*a215bf01Scherry #define XENPMU_FEATURE_INTEL_BTS (1<<0) 98*a215bf01Scherry #define XENPMU_FEATURE_IPC_ONLY (1<<1) 99*a215bf01Scherry #define XENPMU_FEATURE_ARCH_ONLY (1<<2) 100*a215bf01Scherry 101*a215bf01Scherry /* 102*a215bf01Scherry * Shared PMU data between hypervisor and PV(H) domains. 103*a215bf01Scherry * 104*a215bf01Scherry * The hypervisor fills out this structure during PMU interrupt and sends an 105*a215bf01Scherry * interrupt to appropriate VCPU. 106*a215bf01Scherry * Architecture-independent fields of xen_pmu_data are WO for the hypervisor 107*a215bf01Scherry * and RO for the guest but some fields in xen_pmu_arch can be writable 108*a215bf01Scherry * by both the hypervisor and the guest (see arch-$arch/pmu.h). 109*a215bf01Scherry */ 110*a215bf01Scherry struct xen_pmu_data { 111*a215bf01Scherry /* Interrupted VCPU */ 112*a215bf01Scherry uint32_t vcpu_id; 113*a215bf01Scherry 114*a215bf01Scherry /* 115*a215bf01Scherry * Physical processor on which the interrupt occurred. On non-privileged 116*a215bf01Scherry * guests set to vcpu_id; 117*a215bf01Scherry */ 118*a215bf01Scherry uint32_t pcpu_id; 119*a215bf01Scherry 120*a215bf01Scherry /* 121*a215bf01Scherry * Domain that was interrupted. On non-privileged guests set to DOMID_SELF. 122*a215bf01Scherry * On privileged guests can be DOMID_SELF, DOMID_XEN, or, when in 123*a215bf01Scherry * XENPMU_MODE_ALL mode, domain ID of another domain. 124*a215bf01Scherry */ 125*a215bf01Scherry domid_t domain_id; 126*a215bf01Scherry 127*a215bf01Scherry uint8_t pad[6]; 128*a215bf01Scherry 129*a215bf01Scherry /* Architecture-specific information */ 130*a215bf01Scherry struct xen_pmu_arch pmu; 131*a215bf01Scherry }; 132*a215bf01Scherry 133*a215bf01Scherry #endif /* __XEN_PUBLIC_PMU_H__ */ 134*a215bf01Scherry 135*a215bf01Scherry /* 136*a215bf01Scherry * Local variables: 137*a215bf01Scherry * mode: C 138*a215bf01Scherry * c-file-style: "BSD" 139*a215bf01Scherry * c-basic-offset: 4 140*a215bf01Scherry * tab-width: 4 141*a215bf01Scherry * indent-tabs-mode: nil 142*a215bf01Scherry * End: 143*a215bf01Scherry */ 144