1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Ultravisor high level interfaces
4 *
5 * Copyright 2019, IBM Corporation.
6 *
7 */
8 #include <linux/init.h>
9 #include <linux/printk.h>
10 #include <linux/of_fdt.h>
11 #include <linux/of.h>
12
13 #include <asm/ultravisor.h>
14 #include <asm/firmware.h>
15 #include <asm/machdep.h>
16
17 #include "powernv.h"
18
19 static struct kobject *ultravisor_kobj;
20
early_init_dt_scan_ultravisor(unsigned long node,const char * uname,int depth,void * data)21 int __init early_init_dt_scan_ultravisor(unsigned long node, const char *uname,
22 int depth, void *data)
23 {
24 if (!of_flat_dt_is_compatible(node, "ibm,ultravisor"))
25 return 0;
26
27 powerpc_firmware_features |= FW_FEATURE_ULTRAVISOR;
28 pr_debug("Ultravisor detected!\n");
29 return 1;
30 }
31
32 static struct memcons *uv_memcons;
33
uv_msglog_read(struct file * file,struct kobject * kobj,struct bin_attribute * bin_attr,char * to,loff_t pos,size_t count)34 static ssize_t uv_msglog_read(struct file *file, struct kobject *kobj,
35 struct bin_attribute *bin_attr, char *to,
36 loff_t pos, size_t count)
37 {
38 return memcons_copy(uv_memcons, to, pos, count);
39 }
40
41 static struct bin_attribute uv_msglog_attr = {
42 .attr = {.name = "msglog", .mode = 0400},
43 .read = uv_msglog_read
44 };
45
uv_init(void)46 static int __init uv_init(void)
47 {
48 struct device_node *node;
49
50 if (!firmware_has_feature(FW_FEATURE_ULTRAVISOR))
51 return 0;
52
53 node = of_find_compatible_node(NULL, NULL, "ibm,uv-firmware");
54 if (!node)
55 return -ENODEV;
56
57 uv_memcons = memcons_init(node, "memcons");
58 of_node_put(node);
59 if (!uv_memcons)
60 return -ENOENT;
61
62 uv_msglog_attr.size = memcons_get_size(uv_memcons);
63
64 ultravisor_kobj = kobject_create_and_add("ultravisor", firmware_kobj);
65 if (!ultravisor_kobj)
66 return -ENOMEM;
67
68 return sysfs_create_bin_file(ultravisor_kobj, &uv_msglog_attr);
69 }
70 machine_subsys_initcall(powernv, uv_init);
71