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 
28 /* L3 Monitoring Features */
29 #define PSR_CMT_L3_OCCUPANCY            0x1
30 
31 /* CDP Capability */
32 #define PSR_CAT_CDP_CAPABILITY          (1u << 2)
33 
34 /* L3 CDP Enable bit*/
35 #define PSR_L3_QOS_CDP_ENABLE_BIT       0x0
36 
37 /* Used by psr_get_info() */
38 #define PSR_INFO_IDX_COS_MAX            0
39 #define PSR_INFO_IDX_CAT_CBM_LEN        1
40 #define PSR_INFO_IDX_CAT_FLAG           2
41 #define PSR_INFO_ARRAY_SIZE             3
42 
43 struct psr_cmt_l3 {
44     unsigned int features;
45     unsigned int upscaling_factor;
46     unsigned int rmid_max;
47 };
48 
49 struct psr_cmt {
50     unsigned int rmid_max;
51     unsigned int features;
52     domid_t *rmid_to_dom;
53     struct psr_cmt_l3 l3;
54 };
55 
56 enum cbm_type {
57     PSR_CBM_TYPE_L3,
58     PSR_CBM_TYPE_L3_CODE,
59     PSR_CBM_TYPE_L3_DATA,
60     PSR_CBM_TYPE_L2,
61     PSR_CBM_TYPE_UNKNOWN,
62 };
63 
64 extern struct psr_cmt *psr_cmt;
65 
psr_cmt_enabled(void)66 static inline bool_t psr_cmt_enabled(void)
67 {
68     return !!psr_cmt;
69 }
70 
71 int psr_alloc_rmid(struct domain *d);
72 void psr_free_rmid(struct domain *d);
73 void psr_ctxt_switch_to(struct domain *d);
74 
75 int psr_get_info(unsigned int socket, enum cbm_type type,
76                  uint32_t data[], unsigned int array_len);
77 int psr_get_val(struct domain *d, unsigned int socket,
78                 uint32_t *val, enum cbm_type type);
79 int psr_set_val(struct domain *d, unsigned int socket,
80                 uint64_t val, enum cbm_type type);
81 
82 void psr_domain_init(struct domain *d);
83 void psr_domain_free(struct domain *d);
84 
85 #endif /* __ASM_PSR_H__ */
86 
87 /*
88  * Local variables:
89  * mode: C
90  * c-file-style: "BSD"
91  * c-basic-offset: 4
92  * tab-width: 4
93  * indent-tabs-mode: nil
94  * End:
95  */
96