From: vijay.kilari@gmail.com
To: qemu-arm@nongnu.org, peter.maydell@linaro.org, pbonzini@redhat.com
Cc: qemu-devel@nongnu.org, Prasun.Kapoor@cavium.com,
vijay.kilari@gmail.com, Vijaya Kumar K <Vijaya.Kumar@cavium.com>
Subject: [Qemu-devel] [RFC PATCH v1 1/2] utils: Add helper to read arm MIDR_EL1 register
Date: Tue, 2 Aug 2016 15:50:15 +0530 [thread overview]
Message-ID: <1470133216-6758-2-git-send-email-vijay.kilari@gmail.com> (raw)
In-Reply-To: <1470133216-6758-1-git-send-email-vijay.kilari@gmail.com>
From: Vijaya Kumar K <Vijaya.Kumar@cavium.com>
Add helper API to read MIDR_EL1 registers to fetch
cpu identification information. This helps in
adding errata's and architecture specific features.
This is implemented only for arm architecture.
Signed-off-by: Vijaya Kumar K <Vijaya.Kumar@cavium.com>
---
include/qemu-common.h | 1 +
util/Makefile.objs | 1 +
util/cpuinfo.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 54 insertions(+)
diff --git a/include/qemu-common.h b/include/qemu-common.h
index 1f2cb94..62ad674 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -134,4 +134,5 @@ void page_size_init(void);
* returned. */
bool dump_in_progress(void);
+long int qemu_read_cpuid_info(void);
#endif
diff --git a/util/Makefile.objs b/util/Makefile.objs
index 96cb1e0..9d25a72 100644
--- a/util/Makefile.objs
+++ b/util/Makefile.objs
@@ -35,3 +35,4 @@ util-obj-y += log.o
util-obj-y += qdist.o
util-obj-y += qht.o
util-obj-y += range.o
+util-obj-y += cpuinfo.o
diff --git a/util/cpuinfo.c b/util/cpuinfo.c
new file mode 100644
index 0000000..3ba7194
--- /dev/null
+++ b/util/cpuinfo.c
@@ -0,0 +1,52 @@
+/*
+ * Dealing with arm cpu identification information.
+ *
+ * Copyright (C) 2016 Cavium, Inc.
+ *
+ * Authors:
+ * Vijaya Kumar K <Vijaya.Kumar@cavium.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1
+ * or later. See the COPYING.LIB file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "qemu/cutils.h"
+
+#if defined(__aarch64__)
+
+long int qemu_read_cpuid_info(void)
+{
+ FILE *fp;
+ char *buf;
+ long int midr = 0;
+#define BUF_SIZE 32
+
+ fp = fopen("/sys/devices/system/cpu/cpu0/regs/identification/midr_el1",
+ "r");
+ if (!fp) {
+ return 0;
+ }
+
+ buf = g_malloc0(BUF_SIZE);
+ if (!buf) {
+ fclose(fp);
+ return 0;
+ }
+
+ if (buf != fgets(buf, BUF_SIZE - 1, fp)) {
+ goto out;
+ }
+
+ if (qemu_strtol(buf, NULL, 0, &midr) < 0) {
+ goto out;
+ }
+
+out:
+ g_free(buf);
+ fclose(fp);
+
+ return midr;
+}
+#endif
--
1.7.9.5
next prev parent reply other threads:[~2016-08-02 10:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-02 10:20 [Qemu-devel] [RFC PATCH v1 0/2] Live migration optimization for Thunderx platform vijay.kilari
2016-08-02 10:20 ` vijay.kilari [this message]
2016-08-02 10:48 ` [Qemu-devel] [RFC PATCH v1 1/2] utils: Add helper to read arm MIDR_EL1 register Paolo Bonzini
2016-08-04 9:16 ` Vijay Kilari
2016-08-04 12:16 ` Paolo Bonzini
2016-08-02 11:10 ` Peter Maydell
2016-08-02 10:20 ` [Qemu-devel] [RFC PATCH v1 2/2] utils: Add prefetch for Thunderx platform vijay.kilari
2016-08-06 10:17 ` Richard Henderson
2016-08-12 11:32 ` Vijay Kilari
2016-08-12 13:20 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1470133216-6758-2-git-send-email-vijay.kilari@gmail.com \
--to=vijay.kilari@gmail.com \
--cc=Prasun.Kapoor@cavium.com \
--cc=Vijaya.Kumar@cavium.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).