/*1* Permission is hereby granted, free of charge, to any person obtaining a copy2* of this software and associated documentation files (the "Software"), to3* deal in the Software without restriction, including without limitation the4* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or5* sell copies of the Software, and to permit persons to whom the Software is6* furnished to do so, subject to the following conditions:7*8* The above copyright notice and this permission notice shall be included in9* all copies or substantial portions of the Software.10*11* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR12* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,13* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE14* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER15* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING16* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER17* DEALINGS IN THE SOFTWARE.18*19* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.20*/2122#ifndef __XEN_PUBLIC_ARCH_X86_PMU_H__23#define __XEN_PUBLIC_ARCH_X86_PMU_H__2425/* x86-specific PMU definitions */2627/* AMD PMU registers and structures */28struct xen_pmu_amd_ctxt {29/*30* Offsets to counter and control MSRs (relative to xen_pmu_arch.c.amd).31* For PV(H) guests these fields are RO.32*/33uint32_t counters;34uint32_t ctrls;3536/* Counter MSRs */37uint64_t regs[XEN_FLEX_ARRAY_DIM];38};39typedef struct xen_pmu_amd_ctxt xen_pmu_amd_ctxt_t;40DEFINE_XEN_GUEST_HANDLE(xen_pmu_amd_ctxt_t);4142/* Intel PMU registers and structures */43struct xen_pmu_cntr_pair {44uint64_t counter;45uint64_t control;46};47typedef struct xen_pmu_cntr_pair xen_pmu_cntr_pair_t;48DEFINE_XEN_GUEST_HANDLE(xen_pmu_cntr_pair_t);4950struct xen_pmu_intel_ctxt {51/*52* Offsets to fixed and architectural counter MSRs (relative to53* xen_pmu_arch.c.intel).54* For PV(H) guests these fields are RO.55*/56uint32_t fixed_counters;57uint32_t arch_counters;5859/* PMU registers */60uint64_t global_ctrl;61uint64_t global_ovf_ctrl;62uint64_t global_status;63uint64_t fixed_ctrl;64uint64_t ds_area;65uint64_t pebs_enable;66uint64_t debugctl;6768/* Fixed and architectural counter MSRs */69uint64_t regs[XEN_FLEX_ARRAY_DIM];70};71typedef struct xen_pmu_intel_ctxt xen_pmu_intel_ctxt_t;72DEFINE_XEN_GUEST_HANDLE(xen_pmu_intel_ctxt_t);7374/* Sampled domain's registers */75struct xen_pmu_regs {76uint64_t ip;77uint64_t sp;78uint64_t flags;79uint16_t cs;80uint16_t ss;81uint8_t cpl;82uint8_t pad[3];83};84typedef struct xen_pmu_regs xen_pmu_regs_t;85DEFINE_XEN_GUEST_HANDLE(xen_pmu_regs_t);8687/* PMU flags */88#define PMU_CACHED (1<<0) /* PMU MSRs are cached in the context */89#define PMU_SAMPLE_USER (1<<1) /* Sample is from user or kernel mode */90#define PMU_SAMPLE_REAL (1<<2) /* Sample is from realmode */91#define PMU_SAMPLE_PV (1<<3) /* Sample from a PV guest */9293/*94* Architecture-specific information describing state of the processor at95* the time of PMU interrupt.96* Fields of this structure marked as RW for guest should only be written by97* the guest when PMU_CACHED bit in pmu_flags is set (which is done by the98* hypervisor during PMU interrupt). Hypervisor will read updated data in99* XENPMU_flush hypercall and clear PMU_CACHED bit.100*/101struct xen_pmu_arch {102union {103/*104* Processor's registers at the time of interrupt.105* WO for hypervisor, RO for guests.106*/107xen_pmu_regs_t regs;108/* Padding for adding new registers to xen_pmu_regs in the future */109#define XENPMU_REGS_PAD_SZ 64110uint8_t pad[XENPMU_REGS_PAD_SZ];111} r;112113/* WO for hypervisor, RO for guest */114uint64_t pmu_flags;115116/*117* APIC LVTPC register.118* RW for both hypervisor and guest.119* Only APIC_LVT_MASKED bit is loaded by the hypervisor into hardware120* during XENPMU_flush or XENPMU_lvtpc_set.121*/122union {123uint32_t lapic_lvtpc;124uint64_t pad;125} l;126127/*128* Vendor-specific PMU registers.129* RW for both hypervisor and guest (see exceptions above).130* Guest's updates to this field are verified and then loaded by the131* hypervisor into hardware during XENPMU_flush132*/133union {134xen_pmu_amd_ctxt_t amd;135xen_pmu_intel_ctxt_t intel;136137/*138* Padding for contexts (fixed parts only, does not include MSR banks139* that are specified by offsets)140*/141#define XENPMU_CTXT_PAD_SZ 128142uint8_t pad[XENPMU_CTXT_PAD_SZ];143} c;144};145typedef struct xen_pmu_arch xen_pmu_arch_t;146DEFINE_XEN_GUEST_HANDLE(xen_pmu_arch_t);147148#endif /* __XEN_PUBLIC_ARCH_X86_PMU_H__ */149/*150* Local variables:151* mode: C152* c-file-style: "BSD"153* c-basic-offset: 4154* tab-width: 4155* indent-tabs-mode: nil156* End:157*/158159160161