1 /*
2 * psr.h: Platform Shared Resource related service for guest.
3 *
4 * Copyright (c) 2014, Intel Corporation
5 * Author: Dongxiao Xu <dongxiao.xu@intel.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 */
16 #ifndef __ASM_PSR_H__
17 #define __ASM_PSR_H__
18
19 #include <xen/types.h>
20
21 /* CAT cpuid level */
22 #define PSR_CPUID_LEVEL_CAT 0x10
23
24 /* Resource Type Enumeration */
25 #define PSR_RESOURCE_TYPE_L3 0x2
26 #define PSR_RESOURCE_TYPE_L2 0x4
27 #define PSR_RESOURCE_TYPE_MBA 0x8
28
29 /* L3 Monitoring Features */
30 #define PSR_CMT_L3_OCCUPANCY 0x1
31
32 /* CDP Capability */
33 #define PSR_CAT_CDP_CAPABILITY (1u << 2)
34
35 /* L3 CDP Enable bit*/
36 #define PSR_L3_QOS_CDP_ENABLE_BIT 0x0
37
38 /* Used by psr_get_info() */
39 #define PSR_INFO_IDX_COS_MAX 0
40 #define PSR_INFO_IDX_CAT_CBM_LEN 1
41 #define PSR_INFO_IDX_CAT_FLAGS 2
42 #define PSR_INFO_IDX_MBA_THRTL_MAX 1
43 #define PSR_INFO_IDX_MBA_FLAGS 2
44 #define PSR_INFO_ARRAY_SIZE 3
45
46 struct psr_cmt_l3 {
47 unsigned int features;
48 unsigned int upscaling_factor;
49 unsigned int rmid_max;
50 };
51
52 struct psr_cmt {
53 unsigned int rmid_max;
54 unsigned int features;
55 domid_t *rmid_to_dom;
56 struct psr_cmt_l3 l3;
57 };
58
59 enum psr_type {
60 PSR_TYPE_L3_CBM,
61 PSR_TYPE_L3_CODE,
62 PSR_TYPE_L3_DATA,
63 PSR_TYPE_L2_CBM,
64 PSR_TYPE_MBA_THRTL,
65 PSR_TYPE_UNKNOWN,
66 };
67
68 extern struct psr_cmt *psr_cmt;
69
psr_cmt_enabled(void)70 static inline bool psr_cmt_enabled(void)
71 {
72 return IS_ENABLED(CONFIG_X86_PSR) && psr_cmt;
73 }
74
75 int psr_alloc_rmid(struct domain *d);
76 void psr_free_rmid(struct domain *d);
77
78 int psr_get_info(unsigned int socket, enum psr_type type,
79 uint32_t data[], unsigned int array_len);
80 int psr_get_val(struct domain *d, unsigned int socket,
81 uint32_t *val, enum psr_type type);
82 int psr_set_val(struct domain *d, unsigned int socket,
83 uint64_t new_val, enum psr_type type);
84
85 #ifdef CONFIG_X86_PSR
86 void psr_ctxt_switch_to(struct domain *d);
87 void psr_domain_init(struct domain *d);
88 void psr_domain_free(struct domain *d);
89 #else
psr_ctxt_switch_to(struct domain * d)90 static inline void psr_ctxt_switch_to(struct domain *d) {}
psr_domain_init(struct domain * d)91 static inline void psr_domain_init(struct domain *d) {}
psr_domain_free(struct domain * d)92 static inline void psr_domain_free(struct domain *d) {}
93 #endif
94
95 #endif /* __ASM_PSR_H__ */
96
97 /*
98 * Local variables:
99 * mode: C
100 * c-file-style: "BSD"
101 * c-basic-offset: 4
102 * tab-width: 4
103 * indent-tabs-mode: nil
104 * End:
105 */
106