]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
powerpc/powernv: new function to access OPAL msglog
authorAndrew Donnellan <andrew.donnellan@au1.ibm.com>
Tue, 9 Feb 2016 07:17:48 +0000 (18:17 +1100)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 9 Feb 2016 09:27:04 +0000 (20:27 +1100)
Currently, the OPAL msglog/console buffer is exposed as a sysfs file, with
the sysfs read handler responsible for retrieving the log from the OPAL
buffer. We'd like to be able to use it in xmon as well.

Refactor the OPAL msglog code to create a new function, opal_msglog_copy(),
that copies to an arbitrary buffer. Separate the initialisation code into
generic memcons init and sysfs file creation.

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/include/asm/opal.h
arch/powerpc/platforms/powernv/opal-msglog.c
arch/powerpc/platforms/powernv/opal.c

index 07a99e638449acdbbcb9817919d3ce62f0d2b0a9..9d86c665171693da90767981beb5b0755ad6c76d 100644 (file)
@@ -248,6 +248,7 @@ extern int opal_elog_init(void);
 extern void opal_platform_dump_init(void);
 extern void opal_sys_param_init(void);
 extern void opal_msglog_init(void);
+extern void opal_msglog_sysfs_init(void);
 extern int opal_async_comp_init(void);
 extern int opal_sensor_init(void);
 extern int opal_hmi_handler_init(void);
@@ -273,6 +274,8 @@ void opal_free_sg_list(struct opal_sg_list *sg);
 
 extern int opal_error_code(int rc);
 
+ssize_t opal_msglog_copy(char *to, loff_t pos, size_t count);
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_POWERPC_OPAL_H */
index 44ed78af1a0dd53bb9e33f16b3ce465ffc5c6f4f..59fa6e1cbc9b7f6b820d65b7b8b3055cfaecaead 100644 (file)
@@ -31,26 +31,25 @@ struct memcons {
        __be32 in_cons;
 };
 
-static ssize_t opal_msglog_read(struct file *file, struct kobject *kobj,
-                               struct bin_attribute *bin_attr, char *to,
-                               loff_t pos, size_t count)
+static struct memcons *opal_memcons = NULL;
+
+ssize_t opal_msglog_copy(char *to, loff_t pos, size_t count)
 {
-       struct memcons *mc = bin_attr->private;
        const char *conbuf;
        ssize_t ret;
        size_t first_read = 0;
        uint32_t out_pos, avail;
 
-       if (!mc)
+       if (!opal_memcons)
                return -ENODEV;
 
-       out_pos = be32_to_cpu(ACCESS_ONCE(mc->out_pos));
+       out_pos = be32_to_cpu(ACCESS_ONCE(opal_memcons->out_pos));
 
        /* Now we've read out_pos, put a barrier in before reading the new
         * data it points to in conbuf. */
        smp_rmb();
 
-       conbuf = phys_to_virt(be64_to_cpu(mc->obuf_phys));
+       conbuf = phys_to_virt(be64_to_cpu(opal_memcons->obuf_phys));
 
        /* When the buffer has wrapped, read from the out_pos marker to the end
         * of the buffer, and then read the remaining data as in the un-wrapped
@@ -58,7 +57,7 @@ static ssize_t opal_msglog_read(struct file *file, struct kobject *kobj,
        if (out_pos & MEMCONS_OUT_POS_WRAP) {
 
                out_pos &= MEMCONS_OUT_POS_MASK;
-               avail = be32_to_cpu(mc->obuf_size) - out_pos;
+               avail = be32_to_cpu(opal_memcons->obuf_size) - out_pos;
 
                ret = memory_read_from_buffer(to, count, &pos,
                                conbuf + out_pos, avail);
@@ -76,7 +75,7 @@ static ssize_t opal_msglog_read(struct file *file, struct kobject *kobj,
        }
 
        /* Sanity check. The firmware should not do this to us. */
-       if (out_pos > be32_to_cpu(mc->obuf_size)) {
+       if (out_pos > be32_to_cpu(opal_memcons->obuf_size)) {
                pr_err("OPAL: memory console corruption. Aborting read.\n");
                return -EINVAL;
        }
@@ -91,6 +90,13 @@ out:
        return ret;
 }
 
+static ssize_t opal_msglog_read(struct file *file, struct kobject *kobj,
+                               struct bin_attribute *bin_attr, char *to,
+                               loff_t pos, size_t count)
+{
+       return opal_msglog_copy(to, pos, count);
+}
+
 static struct bin_attribute opal_msglog_attr = {
        .attr = {.name = "msglog", .mode = 0444},
        .read = opal_msglog_read
@@ -117,8 +123,11 @@ void __init opal_msglog_init(void)
                return;
        }
 
-       opal_msglog_attr.private = mc;
+       opal_memcons = mc;
+}
 
+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");
 }
index 4e0da5af94a124db13fb524b7cce79f9a1704035..0256d07292524b044b87c9b8423d231e0aa5cf2d 100644 (file)
@@ -724,6 +724,9 @@ static int __init opal_init(void)
                of_node_put(leds);
        }
 
+       /* Initialise OPAL message log interface */
+       opal_msglog_init();
+
        /* Create "opal" kobject under /sys/firmware */
        rc = opal_sysfs_init();
        if (rc == 0) {
@@ -739,8 +742,8 @@ static int __init opal_init(void)
                opal_platform_dump_init();
                /* Setup system parameters interface */
                opal_sys_param_init();
-               /* Setup message log interface. */
-               opal_msglog_init();
+               /* Setup message log sysfs interface. */
+               opal_msglog_sysfs_init();
        }
 
        /* Initialize platform devices: IPMI backend, PRD & flash interface */