From f51a1dfa877a080781b22122582c3e52b39320d9 Mon Sep 17 00:00:00 2001
From: Jin Yao <yao.jin@linux.intel.com>
Date: Fri, 11 Nov 2016 01:14:47 +0800
Subject: [PATCH 16/16] Add SKX supporting
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
 Makefile               |  2 +-
 common/include/types.h |  5 ++--
 common/os/plat.c       | 12 ++++++---
 common/util.c          |  3 +++
 intel/include/skl.h    | 50 +++++++++++++++++++++++++++++++++++
 intel/skl.c            | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 138 insertions(+), 6 deletions(-)
 create mode 100644 intel/include/skl.h
 create mode 100644 intel/skl.c

diff --git a/Makefile b/Makefile
index a33bfc0..128fb4a 100644
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ COMMON_OBJS = cmd.o disp.o lwp.o numatop.o page.o perf.o \
 OS_OBJS = os_cmd.o os_perf.o os_win.o node.o map.o \
 	os_util.o plat.o pfwrapper.o sym.o os_page.o
 
-INTEL_OBJS = wsm.o snb.o nhm.o bdw.o
+INTEL_OBJS = wsm.o snb.o nhm.o bdw.o skl.o
 
 all: $(PROG)
 
diff --git a/common/include/types.h b/common/include/types.h
index 64ae9a1..5a64db2 100644
--- a/common/include/types.h
+++ b/common/include/types.h
@@ -52,10 +52,11 @@ typedef enum {
 	CPU_WSM_EP,
 	CPU_IVB_EX,
 	CPU_HSX,
-	CPU_BDX
+	CPU_BDX,
+	CPU_SKX
 } cpu_type_t;
 
-#define	CPU_TYPE_NUM	9
+#define	CPU_TYPE_NUM	10
 
 typedef enum {
 	SORT_KEY_INVALID = -1,
diff --git a/common/os/plat.c b/common/os/plat.c
index bb1f166..6063988 100644
--- a/common/os/plat.c
+++ b/common/os/plat.c
@@ -42,6 +42,7 @@
 #include "../../intel/include/wsm.h"
 #include "../../intel/include/snb.h"
 #include "../../intel/include/bdw.h"
+#include "../../intel/include/skl.h"
 
 boolean_t g_cmt_enabled;
 
@@ -55,7 +56,8 @@ s_plat_profiling_config[CPU_TYPE_NUM] = {
 	wsmep_profiling_config,
 	snbep_profiling_config,
 	snbep_profiling_config,
-	bdw_profiling_config
+	bdw_profiling_config,
+	skl_profiling_config
 };
 
 static pfn_plat_ll_config_t
@@ -68,7 +70,8 @@ s_plat_ll_config[CPU_TYPE_NUM] = {
 	wsmep_ll_config,
 	snbep_ll_config,
 	snbep_ll_config,
-	bdw_ll_config
+	bdw_ll_config,
+	skl_ll_config
 };
 
 static pfn_plat_offcore_num_t
@@ -81,7 +84,8 @@ s_plat_offcore_num[CPU_TYPE_NUM] = {
 	wsm_offcore_num,
 	snb_offcore_num,
 	snb_offcore_num,
-	bdw_offcore_num
+	bdw_offcore_num,
+	skl_offcore_num
 };
 
 static cpu_type_t s_cpu_type;
@@ -115,6 +119,8 @@ plat_detect(void)
 	case CPU_HSX:
 		/* fall through */
 	case CPU_BDX:
+		/* fall through */
+	case CPU_SKX:
 		ret = 0;
 		break;
 	default:
diff --git a/common/util.c b/common/util.c
index 22b8a65..49bd851 100644
--- a/common/util.c
+++ b/common/util.c
@@ -399,6 +399,9 @@ cpu_type_get(void)
 		case 79:
 			type = CPU_BDX;
 			break;
+		case 85:
+			type = CPU_SKX;
+			break;
 		}
 	}
 
diff --git a/intel/include/skl.h b/intel/include/skl.h
new file mode 100644
index 0000000..7f458a6
--- /dev/null
+++ b/intel/include/skl.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2013, Intel Corporation
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   * Redistributions of source code must retain the above copyright notice,
+ *     this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *   * Neither the name of Intel Corporation nor the names of its contributors
+ *     may be used to endorse or promote products derived from this software
+ *     without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _NUMATOP_SKL_H
+#define	_NUMATOP_SKL_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <sys/types.h>
+#include <inttypes.h>
+#include "../../common/include/types.h"
+
+struct _plat_event_config;
+
+extern void skl_profiling_config(count_id_t, struct _plat_event_config *);
+extern void skl_ll_config(struct _plat_event_config *);
+extern int skl_offcore_num(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _NUMATOP_SKL_H */
diff --git a/intel/skl.c b/intel/skl.c
new file mode 100644
index 0000000..980efb4
--- /dev/null
+++ b/intel/skl.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2013, Intel Corporation
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   * Redistributions of source code must retain the above copyright notice,
+ *     this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *   * Neither the name of Intel Corporation nor the names of its contributors
+ *     may be used to endorse or promote products derived from this software
+ *     without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* This file contains the bdw platform specific functions. */
+
+#include <inttypes.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <strings.h>
+#include "../common/include/types.h"
+#include "../common/include/os/linux/perf_event.h"
+#include "../common/include/os/plat.h"
+#include "../common/include/os/os_perf.h"
+#include "include/skl.h"
+
+static plat_event_config_t s_skl_config[COUNT_NUM] = {
+	{ PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, 0x53, 0, "cpu_clk_unhalted.core" },
+	{ PERF_TYPE_RAW, 0x01B7, 0x53, 0x638000001, "off_core_response_0" },
+	{ PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES, 0x53, 0, "cpu_clk_unhalted.ref" },
+	{ PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, 0x53, 0, "instr_retired.any" },
+	{ PERF_TYPE_RAW, 0x01BB, 0x53, 0x1f84000001, "off_core_response_1" }
+};
+
+static plat_event_config_t s_skl_ll = {
+	PERF_TYPE_RAW, 0x01CD, 0x53, LL_THRESH, "mem_trans_retired.latency_above_threshold"
+};
+
+void
+skl_profiling_config(count_id_t count_id, plat_event_config_t *cfg)
+{
+	plat_config_get(count_id, cfg, s_skl_config);
+}
+
+void
+skl_ll_config(plat_event_config_t *cfg)
+{
+	memcpy(cfg, &s_skl_ll, sizeof (plat_event_config_t));
+}
+
+int
+skl_offcore_num(void)
+{
+	return (2);
+}
-- 
2.10.2

