1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2 /**********************************************************
3 * Copyright 2015-2021 VMware, Inc.
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use, copy,
9 * modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 **********************************************************/
26 #ifndef VM_BASIC_TYPES_H
27 #define VM_BASIC_TYPES_H
29 #include <linux/kernel.h>
48 #define MAX_UINT64 U64_MAX
49 #define MAX_UINT32 U32_MAX
50 #define MAX_UINT16 U16_MAX
52 #define CONST64U(x) x##ULL
55 #define MBYTES_SHIFT 20
57 #ifndef MBYTES_2_BYTES
58 #define MBYTES_2_BYTES(_nbytes) ((uint64)(_nbytes) << MBYTES_SHIFT)
62 * MKS Guest Stats types
65 typedef struct MKSGuestStatCounter {
67 } MKSGuestStatCounter;
69 typedef struct MKSGuestStatCounterTime {
70 MKSGuestStatCounter counter;
71 atomic64_t selfCycles;
72 atomic64_t totalCycles;
73 } MKSGuestStatCounterTime;
76 * Flags for MKSGuestStatInfoEntry::flags below
79 #define MKS_GUEST_STAT_FLAG_NONE 0
80 #define MKS_GUEST_STAT_FLAG_TIME (1U << 0)
82 typedef __attribute__((aligned(32))) struct MKSGuestStatInfoEntry {
93 MKSGuestStatCounter *counter;
94 MKSGuestStatCounterTime *counterTime;
97 } MKSGuestStatInfoEntry;
99 #define INVALID_PPN64 ((PPN64)0x000fffffffffffffULL)
101 #define MKS_GUEST_STAT_INSTANCE_DESC_LENGTH 1024
102 #define MKS_GUEST_STAT_INSTANCE_MAX_STATS 4096
103 #define MKS_GUEST_STAT_INSTANCE_MAX_STAT_PPNS \
104 (PFN_UP(MKS_GUEST_STAT_INSTANCE_MAX_STATS * \
105 sizeof(MKSGuestStatCounterTime)))
106 #define MKS_GUEST_STAT_INSTANCE_MAX_INFO_PPNS \
107 (PFN_UP(MKS_GUEST_STAT_INSTANCE_MAX_STATS * \
108 sizeof(MKSGuestStatInfoEntry)))
109 #define MKS_GUEST_STAT_AVERAGE_NAME_LENGTH 40
110 #define MKS_GUEST_STAT_INSTANCE_MAX_STRS_PPNS \
111 (PFN_UP(MKS_GUEST_STAT_INSTANCE_MAX_STATS * \
112 MKS_GUEST_STAT_AVERAGE_NAME_LENGTH))
115 * The MKSGuestStatInstanceDescriptor is used as main interface to
116 * communicate guest stats back to the host code. The guest must
117 * allocate an instance of this structure at the start of a page and
118 * provide the physical address to the host. From there the host code
119 * can walk this structure to find other (pinned) pages containing the
122 * Since the MKSGuestStatInfoEntry structures contain userlevel
123 * pointers, the InstanceDescriptor also contains pointers to the
124 * begining of these sections allowing the host side code to correctly
125 * interpret the pointers.
127 * Because the host side code never acknowledges anything back to the
128 * guest there is no strict requirement to maintain compatability
129 * across releases. If the interface changes the host might not be
130 * able to log stats, but the guest will continue to run normally.
133 typedef struct MKSGuestStatInstanceDescriptor {
134 uint64 reservedMBZ; /* must be zero for now. */
135 uint64 statStartVA; /* VA of the start of the stats section. */
136 uint64 strsStartVA; /* VA of the start of the strings section. */
137 uint64 statLength; /* length of the stats section in bytes. */
138 uint64 infoLength; /* length of the info entry section in bytes. */
139 uint64 strsLength; /* length of the strings section in bytes. */
140 PPN64 statPPNs[MKS_GUEST_STAT_INSTANCE_MAX_STAT_PPNS]; /* stat counters */
141 PPN64 infoPPNs[MKS_GUEST_STAT_INSTANCE_MAX_INFO_PPNS]; /* stat info */
142 PPN64 strsPPNs[MKS_GUEST_STAT_INSTANCE_MAX_STRS_PPNS]; /* strings */
143 char description[MKS_GUEST_STAT_INSTANCE_DESC_LENGTH];
144 } MKSGuestStatInstanceDescriptor;