@@ -63,6 +63,7 @@
enum psr_feat_type {
PSR_SOCKET_L3_CAT,
PSR_SOCKET_FEAT_NUM,
+ PSR_SOCKET_FEAT_UNKNOWN,
};
/*
@@ -102,6 +103,10 @@ static const struct feat_props {
* values one by one.
*/
enum cbm_type type[PSR_MAX_COS_NUM];
+
+ /* get_feat_info is used to return feature HW info through sysctl. */
+ bool (*get_feat_info)(const struct feat_node *feat,
+ uint32_t data[], unsigned int array_len);
} *feat_props[PSR_SOCKET_FEAT_NUM];
/*
@@ -176,6 +181,22 @@ static void free_socket_resources(unsigned int socket)
info->feat_init = false;
}
+static enum psr_feat_type psr_cbm_type_to_feat_type(enum cbm_type type)
+{
+ enum psr_feat_type feat_type = PSR_SOCKET_FEAT_UNKNOWN;
+
+ switch ( type )
+ {
+ case PSR_CBM_TYPE_L3:
+ feat_type = PSR_SOCKET_L3_CAT;
+ break;
+ default:
+ ASSERT_UNREACHABLE();
+ }
+
+ return feat_type;
+}
+
/* CAT common functions implementation. */
static void cat_init_feature(const struct cpuid_leaf *regs,
struct feat_node *feat,
@@ -213,10 +234,24 @@ static void cat_init_feature(const struct cpuid_leaf *regs,
cpu_to_socket(smp_processor_id()), feat->cos_max, feat->cbm_len);
}
+static bool cat_get_feat_info(const struct feat_node *feat,
+ uint32_t data[], unsigned int array_len)
+{
+ if ( array_len != PSR_INFO_ARRAY_SIZE )
+ return false;
+
+ data[PSR_INFO_IDX_COS_MAX] = feat->cos_max;
+ data[PSR_INFO_IDX_CAT_CBM_LEN] = feat->cbm_len;
+ data[PSR_INFO_IDX_CAT_FLAG] = 0;
+
+ return true;
+}
+
/* L3 CAT props */
static const struct feat_props l3_cat_props = {
.cos_num = 1,
.type[0] = PSR_CBM_TYPE_L3,
+ .get_feat_info = cat_get_feat_info,
};
static void __init parse_psr_bool(char *s, char *value, char *feature,
@@ -429,10 +464,50 @@ void psr_ctxt_switch_to(struct domain *d)
}
}
-int psr_get_cat_l3_info(unsigned int socket, uint32_t *cbm_len,
- uint32_t *cos_max, uint32_t *flags)
+static struct psr_socket_info *get_socket_info(unsigned int socket)
{
- return 0;
+ if ( !socket_info )
+ return ERR_PTR(-ENODEV);
+
+ if ( socket >= nr_sockets )
+ return ERR_PTR(-ERANGE);
+
+ if ( !socket_info[socket].feat_init )
+ return ERR_PTR(-ENOENT);
+
+ return socket_info + socket;
+}
+
+int psr_get_info(unsigned int socket, enum cbm_type type,
+ uint32_t data[], unsigned int array_len)
+{
+ const struct psr_socket_info *info = get_socket_info(socket);
+ const struct feat_node *feat;
+ enum psr_feat_type feat_type;
+
+ ASSERT(data);
+
+ if ( IS_ERR(info) )
+ return PTR_ERR(info);
+
+ feat_type = psr_cbm_type_to_feat_type(type);
+ if ( feat_type >= ARRAY_SIZE(info->features) )
+ return -ENOENT;
+
+ feat = info->features[feat_type];
+ if ( !feat )
+ return -ENOENT;
+
+ if ( !feat_props[feat_type] )
+ {
+ ASSERT_UNREACHABLE();
+ return -ENOENT;
+ }
+
+ if ( feat_props[feat_type]->get_feat_info(feat, data, array_len) )
+ return 0;
+
+ return -EINVAL;
}
int psr_get_l3_cbm(struct domain *d, unsigned int socket,
@@ -175,14 +175,25 @@ long arch_do_sysctl(
switch ( sysctl->u.psr_cat_op.cmd )
{
case XEN_SYSCTL_PSR_CAT_get_l3_info:
- ret = psr_get_cat_l3_info(sysctl->u.psr_cat_op.target,
- &sysctl->u.psr_cat_op.u.l3_info.cbm_len,
- &sysctl->u.psr_cat_op.u.l3_info.cos_max,
- &sysctl->u.psr_cat_op.u.l3_info.flags);
+ {
+ uint32_t data[PSR_INFO_ARRAY_SIZE];
+
+ ret = psr_get_info(sysctl->u.psr_cat_op.target,
+ PSR_CBM_TYPE_L3, data, ARRAY_SIZE(data));
+ if ( ret )
+ break;
+
+ sysctl->u.psr_cat_op.u.l3_info.cos_max =
+ data[PSR_INFO_IDX_COS_MAX];
+ sysctl->u.psr_cat_op.u.l3_info.cbm_len =
+ data[PSR_INFO_IDX_CAT_CBM_LEN];
+ sysctl->u.psr_cat_op.u.l3_info.flags =
+ data[PSR_INFO_IDX_CAT_FLAG];
if ( !ret && __copy_field_to_guest(u_sysctl, sysctl, u.psr_cat_op) )
ret = -EFAULT;
break;
+ }
default:
ret = -EOPNOTSUPP;
@@ -19,20 +19,26 @@
#include <xen/types.h>
/* CAT cpuid level */
-#define PSR_CPUID_LEVEL_CAT 0x10
+#define PSR_CPUID_LEVEL_CAT 0x10
/* Resource Type Enumeration */
#define PSR_RESOURCE_TYPE_L3 0x2
/* L3 Monitoring Features */
-#define PSR_CMT_L3_OCCUPANCY 0x1
+#define PSR_CMT_L3_OCCUPANCY 0x1
/* CDP Capability */
-#define PSR_CAT_CDP_CAPABILITY (1u << 2)
+#define PSR_CAT_CDP_CAPABILITY (1u << 2)
/* L3 CDP Enable bit*/
#define PSR_L3_QOS_CDP_ENABLE_BIT 0x0
+/* Used by psr_get_info() */
+#define PSR_INFO_IDX_COS_MAX 0
+#define PSR_INFO_IDX_CAT_CBM_LEN 1
+#define PSR_INFO_IDX_CAT_FLAG 2
+#define PSR_INFO_ARRAY_SIZE 3
+
struct psr_cmt_l3 {
unsigned int features;
unsigned int upscaling_factor;
@@ -63,8 +69,8 @@ int psr_alloc_rmid(struct domain *d);
void psr_free_rmid(struct domain *d);
void psr_ctxt_switch_to(struct domain *d);
-int psr_get_cat_l3_info(unsigned int socket, uint32_t *cbm_len,
- uint32_t *cos_max, uint32_t *flags);
+int psr_get_info(unsigned int socket, enum cbm_type type,
+ uint32_t data[], unsigned int array_len);
int psr_get_l3_cbm(struct domain *d, unsigned int socket,
uint64_t *cbm, enum cbm_type type);
int psr_set_l3_cbm(struct domain *d, unsigned int socket,