1*44e33a5aSSean Rhodes // SPDX-License-Identifier: GPL-2.0-only
2*44e33a5aSSean Rhodes /*
3*44e33a5aSSean Rhodes * memconsole.c
4*44e33a5aSSean Rhodes *
5*44e33a5aSSean Rhodes * Architecture-independent parts of the memory based BIOS console.
6*44e33a5aSSean Rhodes *
7*44e33a5aSSean Rhodes * Copyright 2017 Google Inc.
8*44e33a5aSSean Rhodes */
9*44e33a5aSSean Rhodes
10*44e33a5aSSean Rhodes #include <linux/sysfs.h>
11*44e33a5aSSean Rhodes #include <linux/kobject.h>
12*44e33a5aSSean Rhodes #include <linux/module.h>
13*44e33a5aSSean Rhodes
14*44e33a5aSSean Rhodes #include "memconsole.h"
15*44e33a5aSSean Rhodes
memconsole_read(struct file * filp,struct kobject * kobp,const struct bin_attribute * bin_attr,char * buf,loff_t pos,size_t count)16*44e33a5aSSean Rhodes static ssize_t memconsole_read(struct file *filp, struct kobject *kobp,
17*44e33a5aSSean Rhodes const struct bin_attribute *bin_attr, char *buf,
18*44e33a5aSSean Rhodes loff_t pos, size_t count)
19*44e33a5aSSean Rhodes {
20*44e33a5aSSean Rhodes ssize_t (*memconsole_read_func)(char *, loff_t, size_t);
21*44e33a5aSSean Rhodes
22*44e33a5aSSean Rhodes memconsole_read_func = bin_attr->private;
23*44e33a5aSSean Rhodes if (WARN_ON_ONCE(!memconsole_read_func))
24*44e33a5aSSean Rhodes return -EIO;
25*44e33a5aSSean Rhodes
26*44e33a5aSSean Rhodes return memconsole_read_func(buf, pos, count);
27*44e33a5aSSean Rhodes }
28*44e33a5aSSean Rhodes
29*44e33a5aSSean Rhodes static struct bin_attribute memconsole_bin_attr = {
30*44e33a5aSSean Rhodes .attr = {.name = "log", .mode = 0444},
31*44e33a5aSSean Rhodes .read = memconsole_read,
32*44e33a5aSSean Rhodes };
33*44e33a5aSSean Rhodes
memconsole_setup(ssize_t (* read_func)(char *,loff_t,size_t))34*44e33a5aSSean Rhodes void memconsole_setup(ssize_t (*read_func)(char *, loff_t, size_t))
35*44e33a5aSSean Rhodes {
36*44e33a5aSSean Rhodes memconsole_bin_attr.private = read_func;
37*44e33a5aSSean Rhodes }
38*44e33a5aSSean Rhodes EXPORT_SYMBOL(memconsole_setup);
39*44e33a5aSSean Rhodes
memconsole_sysfs_init(void)40*44e33a5aSSean Rhodes int memconsole_sysfs_init(void)
41*44e33a5aSSean Rhodes {
42*44e33a5aSSean Rhodes return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
43*44e33a5aSSean Rhodes }
44*44e33a5aSSean Rhodes EXPORT_SYMBOL(memconsole_sysfs_init);
45*44e33a5aSSean Rhodes
memconsole_exit(void)46*44e33a5aSSean Rhodes void memconsole_exit(void)
47*44e33a5aSSean Rhodes {
48*44e33a5aSSean Rhodes sysfs_remove_bin_file(firmware_kobj, &memconsole_bin_attr);
49*44e33a5aSSean Rhodes }
50*44e33a5aSSean Rhodes EXPORT_SYMBOL(memconsole_exit);
51*44e33a5aSSean Rhodes
52*44e33a5aSSean Rhodes MODULE_AUTHOR("Google, Inc.");
53*44e33a5aSSean Rhodes MODULE_DESCRIPTION("Architecture-independent parts of the memory based BIOS console");
54*44e33a5aSSean Rhodes MODULE_LICENSE("GPL");
55