powerpc/powernv: add hdat attribute to sysfs
PATCH v4 1/1 powerpc/powernv: add hdat attribute to sysfs
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.
---
Changes between v3 and v4:
- changed sysfs attribute permissions from 0444 to 0400
- fixed makefile to be on same line
- fixed authorship/copyright info
- re-ordered includes
- changed hdat_info struct to a static struct
--- arch/powerpc/include/asm/opal.h | 1 + arch/powerpc/platforms/powernv/Makefile | 2 +- arch/powerpc/platforms/powernv/opal-hdat.c | 60 ++++++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/opal.c | 2 + 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/platforms/powernv/opal-hdat.c
arch/powerpc/include/asm/opal.h +1 -0
@@ -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);
arch/powerpc/platforms/powernv/Makefile +1 -1
@@ -2,7 +2,7 @@ obj-y += setup.o opal-wrappers.o opal.o opal-async.o idle.o obj-y += opal-rtc.o opal-nvram.o opal-lpc.o opal-flash.o obj-y += rng.o opal-elog.o opal-dump.o opal-sysparam.o opal-sensor.o obj-y += opal-msglog.o opal-hmi.o opal-power.o opal-irqchip.o -obj-y += opal-kmsg.o +obj-y += opal-kmsg.o opal-hdat.o obj-$(CONFIG_SMP) += smp.o subcore.o subcore-asm.o obj-$(CONFIG_PCI) += pci.o pci-ioda.o npu-dma.o
arch/powerpc/platforms/powernv/opal-hdat.c new file +60 -0
60 lines not on this page · raw message
arch/powerpc/platforms/powernv/opal.c +2 -0
@@ -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 */
Signature · 1 line
2.9.3
Quoted 81 lines · Matt Brown
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/memas it is reserved memory which is stopped by the/dev/memfilter.Signed-off-by Matt Brown <[email protected]>---
Changes between v3 and v4:
- changed sysfs attribute permissions from 0444 to 0400
- fixed makefile to be on same line
- fixed authorship/copyright info
- re-ordered includes
- changedhdat_infostruct to a static struct--- arch/powerpc/include/asm/opal.h | 1 + arch/powerpc/platforms/powernv/Makefile | 2 +- arch/powerpc/platforms/powernv/opal-hdat.c | 60 ++++++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/opal.c | 2 + 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/platforms/powernv/opal-hdat.carch/powerpc/include/asm/opal.h +1
-0@@ -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);arch/powerpc/platforms/powernv/Makefile +1
-1@@ -2,7 +2,7 @@ obj-y += setup.o opal-wrappers.o opal.o opal-async.o idle.o obj-y += opal-rtc.o opal-nvram.o opal-lpc.o opal-flash.o obj-y += rng.o opal-elog.o opal-dump.o opal-sysparam.o opal-sensor.o obj-y += opal-msglog.o opal-hmi.o opal-power.o opal-irqchip.o -obj-y += opal-kmsg.o +obj-y += opal-kmsg.o opal-hdat.o obj-$(CONFIG_SMP) += smp.o subcore.o subcore-asm.o obj-$(CONFIG_PCI) += pci.o pci-ioda.o npu-dma.oarch/powerpc/platforms/powernv/opal-hdat.c new file +28
-0@@ -0,0 +1,60 @@ +/* +* PowerNV OPAL HDAT interface +* +* Copyright 2017, Matt Brown, IBM Corp. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#include <linux/of.h> +#include <linux/types.h> +#include <asm/io.h> +#include <asm/opal.h> + +static struct { +char *base; +u64 size; +} hdat_info; + +/* 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_info.base) +return -ENODEV ;
arch/powerpc/platforms/powernv/opal-hdat.c line 38
Quoted 10 lines
arch/powerpc/platforms/powernv/opal-hdat.c new file +10
-0+ +return memory_read_from_buffer (to, count, &pos, hdat_info.base, + hdat_info.size); +} + +/* HDAT attribute for sysfs */ +static struct bin_attribute hdat_attr = { + .attr = {.name ="hdat" , .mode =0400 }, + .read = hdat_read +};
Why not BIN_ATTR_RO (like opal_export_symmap() does) ?
(I have comments/thoughts on the OPAL side as well)
Signature · 2 lines
Stewart Smith OPAL Architect, IBM.