1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * This file supports the /sys/firmware/sgi_uv interfaces for SGI UV.
4  *
5  *  Copyright (c) 2008 Silicon Graphics, Inc.  All Rights Reserved.
6  *  Copyright (c) Russ Anderson
7  */
8 
9 #include <linux/device.h>
10 #include <asm/uv/bios.h>
11 #include <asm/uv/uv.h>
12 
13 struct kobject *sgi_uv_kobj;
14 
partition_id_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)15 static ssize_t partition_id_show(struct kobject *kobj,
16 			struct kobj_attribute *attr, char *buf)
17 {
18 	return snprintf(buf, PAGE_SIZE, "%ld\n", sn_partition_id);
19 }
20 
coherence_id_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)21 static ssize_t coherence_id_show(struct kobject *kobj,
22 			struct kobj_attribute *attr, char *buf)
23 {
24 	return snprintf(buf, PAGE_SIZE, "%ld\n", uv_partition_coherence_id());
25 }
26 
27 static struct kobj_attribute partition_id_attr =
28 	__ATTR(partition_id, S_IRUGO, partition_id_show, NULL);
29 
30 static struct kobj_attribute coherence_id_attr =
31 	__ATTR(coherence_id, S_IRUGO, coherence_id_show, NULL);
32 
33 
sgi_uv_sysfs_init(void)34 static int __init sgi_uv_sysfs_init(void)
35 {
36 	unsigned long ret;
37 
38 	if (!is_uv_system())
39 		return -ENODEV;
40 
41 	if (!sgi_uv_kobj)
42 		sgi_uv_kobj = kobject_create_and_add("sgi_uv", firmware_kobj);
43 	if (!sgi_uv_kobj) {
44 		printk(KERN_WARNING "kobject_create_and_add sgi_uv failed\n");
45 		return -EINVAL;
46 	}
47 
48 	ret = sysfs_create_file(sgi_uv_kobj, &partition_id_attr.attr);
49 	if (ret) {
50 		printk(KERN_WARNING "sysfs_create_file partition_id failed\n");
51 		return ret;
52 	}
53 
54 	ret = sysfs_create_file(sgi_uv_kobj, &coherence_id_attr.attr);
55 	if (ret) {
56 		printk(KERN_WARNING "sysfs_create_file coherence_id failed\n");
57 		return ret;
58 	}
59 
60 	return 0;
61 }
62 
63 device_initcall(sgi_uv_sysfs_init);
64