1/* SPDX-License-Identifier: GPL-2.0 OR MIT */
2/**********************************************************
3 * Copyright 2015-2021 VMware, Inc.
4 *
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:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
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
23 * SOFTWARE.
24 *
25 **********************************************************/
26#ifndef VM_BASIC_TYPES_H
27#define VM_BASIC_TYPES_H
28
29#include <linux/kernel.h>
30#include <linux/mm.h>
31#include <asm/page.h>
32
33typedef u32 uint32;
34typedef s32 int32;
35typedef u64 uint64;
36typedef u16 uint16;
37typedef s16 int16;
38typedef u8 uint8;
39typedef s8 int8;
40
41typedef uint64 PA;
42typedef uint32 PPN;
43typedef uint32 PPN32;
44typedef uint64 PPN64;
45
46typedef bool Bool;
47
48#define MAX_UINT64 U64_MAX
49#define MAX_UINT32 U32_MAX
50#define MAX_UINT16 U16_MAX
51
52#define CONST64U(x) x##ULL
53
54#ifndef MBYTES_SHIFT
55#define MBYTES_SHIFT 20
56#endif
57#ifndef MBYTES_2_BYTES
58#define MBYTES_2_BYTES(_nbytes) ((uint64)(_nbytes) << MBYTES_SHIFT)
59#endif
60
61/*
62 * MKS Guest Stats types
63 */
64
65typedef struct MKSGuestStatCounter {
66 atomic64_t count;
67} MKSGuestStatCounter;
68
69typedef struct MKSGuestStatCounterTime {
70 MKSGuestStatCounter counter;
71 atomic64_t selfCycles;
72 atomic64_t totalCycles;
73} MKSGuestStatCounterTime;
74
75/*
76 * Flags for MKSGuestStatInfoEntry::flags below
77 */
78
79#define MKS_GUEST_STAT_FLAG_NONE 0
80#define MKS_GUEST_STAT_FLAG_TIME (1U << 0)
81
82typedef __attribute__((aligned(32))) struct MKSGuestStatInfoEntry {
83 union {
84 const char *s;
85 uint64 u;
86 } name;
87 union {
88 const char *s;
89 uint64 u;
90 } description;
91 uint64 flags;
92 union {
93 MKSGuestStatCounter *counter;
94 MKSGuestStatCounterTime *counterTime;
95 uint64 u;
96 } stat;
97} MKSGuestStatInfoEntry;
98
99#define INVALID_PPN64 ((PPN64)0x000fffffffffffffULL)
100
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))
113
114/*
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
120 * stats data.
121 *
122 * Since the MKSGuestStatInfoEntry structures contain userlevel
123 * pointers, the InstanceDescriptor also contains pointers to the
124 * beginning of these sections allowing the host side code to correctly
125 * interpret the pointers.
126 *
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.
131 */
132
133typedef 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;
145
146#endif
147

source code of linux/drivers/gpu/drm/vmwgfx/device_include/vm_basic_types.h