From: Matt Brown <matthew.brown.dev@gmail.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: Matt Brown <brownmatt1997@gmail.com>,
Matt Brown <matthew.brown.dev@gmail.com>
Subject: [PATCH] powerpc/powernv: add hdat attribute to sysfs
Date: Thu, 23 Feb 2017 13:29:54 +1100 [thread overview]
Message-ID: <20170223022954.14676-1-matthew.brown.dev@gmail.com> (raw)
From: Matt Brown <brownmatt1997@gmail.com>
The HDAT data area is consumed by skiboot and turned into a device-tree.
In some cases we would like to look directly at the HDAT, so this patch
adds a sysfs node to allow it to be viewed. This is not possible through
/dev/mem as it is reserved memory which is stopped by the /dev/mem filter.
Signed-off-by: Matt Brown <matthew.brown.dev@gmail.com>
---
arch/powerpc/include/asm/opal.h | 1 +
arch/powerpc/platforms/powernv/opal-msglog.c | 49 ++++++++++++++++++++++++++++
arch/powerpc/platforms/powernv/opal.c | 2 ++
3 files changed, 52 insertions(+)
diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 5c7db0f..b26944e 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -277,6 +277,7 @@ extern int opal_async_comp_init(void);
extern int opal_sensor_init(void);
extern int opal_hmi_handler_init(void);
extern int opal_event_init(void);
+extern void opal_hdat_sysfs_init(void);
extern int opal_machine_check(struct pt_regs *regs);
extern bool opal_mce_check_early_recovery(struct pt_regs *regs);
diff --git a/arch/powerpc/platforms/powernv/opal-msglog.c b/arch/powerpc/platforms/powernv/opal-msglog.c
index 39d6ff9..a637055 100644
--- a/arch/powerpc/platforms/powernv/opal-msglog.c
+++ b/arch/powerpc/platforms/powernv/opal-msglog.c
@@ -31,7 +31,13 @@ struct memcons {
__be32 in_cons;
};
+struct hdatInfo {
+ char *base;
+ u64 size;
+};
+
static struct memcons *opal_memcons = NULL;
+static struct hdatInfo hdat_inf;
ssize_t opal_msglog_copy(char *to, loff_t pos, size_t count)
{
@@ -136,3 +142,46 @@ void __init opal_msglog_sysfs_init(void)
if (sysfs_create_bin_file(opal_kobj, &opal_msglog_attr) != 0)
pr_warn("OPAL: sysfs file creation failed\n");
}
+
+
+
+/* Read function for HDAT attribute in sysfs */
+static ssize_t hdat_read(struct file *file, struct kobject *kobj,
+ struct bin_attribute *bin_attr, char *to,
+ loff_t pos, size_t count)
+{
+ if (!hdat_inf.base)
+ return -ENODEV;
+
+ return memory_read_from_buffer(to, count, &pos, hdat_inf.base,
+ hdat_inf.size);
+}
+
+
+/* HDAT attribute for sysfs */
+static struct bin_attribute hdat_attr = {
+ .attr = {.name = "hdat", .mode = 0444},
+ .read = hdat_read
+};
+
+void __init opal_hdat_sysfs_init(void)
+{
+ u64 hdatAddr[2];
+
+ /* Check for the hdat-map prop in device-tree */
+ if (of_property_read_u64_array(opal_node, "hdat-map", hdatAddr, 2)) {
+ pr_debug("OPAL: Property hdat-map not found.\n");
+ return;
+ }
+
+ /* Print out hdat-map values. [0]: base, [1]: size */
+ pr_debug("HDAT Base address: %#llx\n", hdatAddr[0]);
+ pr_debug("HDAT Size: %#llx\n", hdatAddr[1]);
+
+ hdat_inf.base = phys_to_virt(hdatAddr[0]);
+ hdat_inf.size = hdatAddr[1];
+
+ if (sysfs_create_bin_file(opal_kobj, &hdat_attr) != 0)
+ pr_debug("OPAL: sysfs file creation for HDAT failed");
+
+}
diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c
index 2822935..cae3745 100644
--- a/arch/powerpc/platforms/powernv/opal.c
+++ b/arch/powerpc/platforms/powernv/opal.c
@@ -740,6 +740,8 @@ static int __init opal_init(void)
opal_sys_param_init();
/* Setup message log sysfs interface. */
opal_msglog_sysfs_init();
+ /* Create hdat object under sys/firmware/opal */
+ opal_hdat_sysfs_init();
}
/* Initialize platform devices: IPMI backend, PRD & flash interface */
--
2.9.3
next reply other threads:[~2017-02-23 2:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-23 2:29 Matt Brown [this message]
2017-02-23 3:47 ` [PATCH] powerpc/powernv: add hdat attribute to sysfs Oliver O'Halloran
2017-02-23 7:42 ` Andrew Donnellan
2017-02-23 7:44 ` Andrew Donnellan
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=20170223022954.14676-1-matthew.brown.dev@gmail.com \
--to=matthew.brown.dev@gmail.com \
--cc=brownmatt1997@gmail.com \
--cc=linuxppc-dev@lists.ozlabs.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).