.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * PowerNV OPAL in-memory console interface |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright 2014 IBM Corp. |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or |
---|
7 | | - * modify it under the terms of the GNU General Public License |
---|
8 | | - * as published by the Free Software Foundation; either version |
---|
9 | | - * 2 of the License, or (at your option) any later version. |
---|
10 | 6 | */ |
---|
11 | 7 | |
---|
12 | 8 | #include <asm/io.h> |
---|
.. | .. |
---|
15 | 11 | #include <linux/of.h> |
---|
16 | 12 | #include <linux/types.h> |
---|
17 | 13 | #include <asm/barrier.h> |
---|
| 14 | + |
---|
| 15 | +#include "powernv.h" |
---|
18 | 16 | |
---|
19 | 17 | /* OPAL in-memory console. Defined in OPAL source at core/console.c */ |
---|
20 | 18 | struct memcons { |
---|
.. | .. |
---|
33 | 31 | |
---|
34 | 32 | static struct memcons *opal_memcons = NULL; |
---|
35 | 33 | |
---|
36 | | -ssize_t opal_msglog_copy(char *to, loff_t pos, size_t count) |
---|
| 34 | +ssize_t memcons_copy(struct memcons *mc, char *to, loff_t pos, size_t count) |
---|
37 | 35 | { |
---|
38 | 36 | const char *conbuf; |
---|
39 | 37 | ssize_t ret; |
---|
40 | 38 | size_t first_read = 0; |
---|
41 | 39 | uint32_t out_pos, avail; |
---|
42 | 40 | |
---|
43 | | - if (!opal_memcons) |
---|
| 41 | + if (!mc) |
---|
44 | 42 | return -ENODEV; |
---|
45 | 43 | |
---|
46 | | - out_pos = be32_to_cpu(READ_ONCE(opal_memcons->out_pos)); |
---|
| 44 | + out_pos = be32_to_cpu(READ_ONCE(mc->out_pos)); |
---|
47 | 45 | |
---|
48 | 46 | /* Now we've read out_pos, put a barrier in before reading the new |
---|
49 | 47 | * data it points to in conbuf. */ |
---|
50 | 48 | smp_rmb(); |
---|
51 | 49 | |
---|
52 | | - conbuf = phys_to_virt(be64_to_cpu(opal_memcons->obuf_phys)); |
---|
| 50 | + conbuf = phys_to_virt(be64_to_cpu(mc->obuf_phys)); |
---|
53 | 51 | |
---|
54 | 52 | /* When the buffer has wrapped, read from the out_pos marker to the end |
---|
55 | 53 | * of the buffer, and then read the remaining data as in the un-wrapped |
---|
.. | .. |
---|
57 | 55 | if (out_pos & MEMCONS_OUT_POS_WRAP) { |
---|
58 | 56 | |
---|
59 | 57 | out_pos &= MEMCONS_OUT_POS_MASK; |
---|
60 | | - avail = be32_to_cpu(opal_memcons->obuf_size) - out_pos; |
---|
| 58 | + avail = be32_to_cpu(mc->obuf_size) - out_pos; |
---|
61 | 59 | |
---|
62 | 60 | ret = memory_read_from_buffer(to, count, &pos, |
---|
63 | 61 | conbuf + out_pos, avail); |
---|
.. | .. |
---|
75 | 73 | } |
---|
76 | 74 | |
---|
77 | 75 | /* Sanity check. The firmware should not do this to us. */ |
---|
78 | | - if (out_pos > be32_to_cpu(opal_memcons->obuf_size)) { |
---|
| 76 | + if (out_pos > be32_to_cpu(mc->obuf_size)) { |
---|
79 | 77 | pr_err("OPAL: memory console corruption. Aborting read.\n"); |
---|
80 | 78 | return -EINVAL; |
---|
81 | 79 | } |
---|
.. | .. |
---|
90 | 88 | return ret; |
---|
91 | 89 | } |
---|
92 | 90 | |
---|
| 91 | +ssize_t opal_msglog_copy(char *to, loff_t pos, size_t count) |
---|
| 92 | +{ |
---|
| 93 | + return memcons_copy(opal_memcons, to, pos, count); |
---|
| 94 | +} |
---|
| 95 | + |
---|
93 | 96 | static ssize_t opal_msglog_read(struct file *file, struct kobject *kobj, |
---|
94 | 97 | struct bin_attribute *bin_attr, char *to, |
---|
95 | 98 | loff_t pos, size_t count) |
---|
.. | .. |
---|
102 | 105 | .read = opal_msglog_read |
---|
103 | 106 | }; |
---|
104 | 107 | |
---|
105 | | -void __init opal_msglog_init(void) |
---|
| 108 | +struct memcons *memcons_init(struct device_node *node, const char *mc_prop_name) |
---|
106 | 109 | { |
---|
107 | 110 | u64 mcaddr; |
---|
108 | 111 | struct memcons *mc; |
---|
109 | 112 | |
---|
110 | | - if (of_property_read_u64(opal_node, "ibm,opal-memcons", &mcaddr)) { |
---|
111 | | - pr_warn("OPAL: Property ibm,opal-memcons not found, no message log\n"); |
---|
112 | | - return; |
---|
| 113 | + if (of_property_read_u64(node, mc_prop_name, &mcaddr)) { |
---|
| 114 | + pr_warn("%s property not found, no message log\n", |
---|
| 115 | + mc_prop_name); |
---|
| 116 | + goto out_err; |
---|
113 | 117 | } |
---|
114 | 118 | |
---|
115 | 119 | mc = phys_to_virt(mcaddr); |
---|
116 | 120 | if (!mc) { |
---|
117 | | - pr_warn("OPAL: memory console address is invalid\n"); |
---|
118 | | - return; |
---|
| 121 | + pr_warn("memory console address is invalid\n"); |
---|
| 122 | + goto out_err; |
---|
119 | 123 | } |
---|
120 | 124 | |
---|
121 | 125 | if (be64_to_cpu(mc->magic) != MEMCONS_MAGIC) { |
---|
122 | | - pr_warn("OPAL: memory console version is invalid\n"); |
---|
| 126 | + pr_warn("memory console version is invalid\n"); |
---|
| 127 | + goto out_err; |
---|
| 128 | + } |
---|
| 129 | + |
---|
| 130 | + return mc; |
---|
| 131 | + |
---|
| 132 | +out_err: |
---|
| 133 | + return NULL; |
---|
| 134 | +} |
---|
| 135 | + |
---|
| 136 | +u32 memcons_get_size(struct memcons *mc) |
---|
| 137 | +{ |
---|
| 138 | + return be32_to_cpu(mc->ibuf_size) + be32_to_cpu(mc->obuf_size); |
---|
| 139 | +} |
---|
| 140 | + |
---|
| 141 | +void __init opal_msglog_init(void) |
---|
| 142 | +{ |
---|
| 143 | + opal_memcons = memcons_init(opal_node, "ibm,opal-memcons"); |
---|
| 144 | + if (!opal_memcons) { |
---|
| 145 | + pr_warn("OPAL: memcons failed to load from ibm,opal-memcons\n"); |
---|
123 | 146 | return; |
---|
124 | 147 | } |
---|
125 | 148 | |
---|
126 | | - /* Report maximum size */ |
---|
127 | | - opal_msglog_attr.size = be32_to_cpu(mc->ibuf_size) + |
---|
128 | | - be32_to_cpu(mc->obuf_size); |
---|
129 | | - |
---|
130 | | - opal_memcons = mc; |
---|
| 149 | + opal_msglog_attr.size = memcons_get_size(opal_memcons); |
---|
131 | 150 | } |
---|
132 | 151 | |
---|
133 | 152 | void __init opal_msglog_sysfs_init(void) |
---|