Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * memconsole.c
0004  *
0005  * Architecture-independent parts of the memory based BIOS console.
0006  *
0007  * Copyright 2017 Google Inc.
0008  */
0009 
0010 #include <linux/sysfs.h>
0011 #include <linux/kobject.h>
0012 #include <linux/module.h>
0013 
0014 #include "memconsole.h"
0015 
0016 static ssize_t memconsole_read(struct file *filp, struct kobject *kobp,
0017                    struct bin_attribute *bin_attr, char *buf,
0018                    loff_t pos, size_t count)
0019 {
0020     ssize_t (*memconsole_read_func)(char *, loff_t, size_t);
0021 
0022     memconsole_read_func = bin_attr->private;
0023     if (WARN_ON_ONCE(!memconsole_read_func))
0024         return -EIO;
0025 
0026     return memconsole_read_func(buf, pos, count);
0027 }
0028 
0029 static struct bin_attribute memconsole_bin_attr = {
0030     .attr = {.name = "log", .mode = 0444},
0031     .read = memconsole_read,
0032 };
0033 
0034 void memconsole_setup(ssize_t (*read_func)(char *, loff_t, size_t))
0035 {
0036     memconsole_bin_attr.private = read_func;
0037 }
0038 EXPORT_SYMBOL(memconsole_setup);
0039 
0040 int memconsole_sysfs_init(void)
0041 {
0042     return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
0043 }
0044 EXPORT_SYMBOL(memconsole_sysfs_init);
0045 
0046 void memconsole_exit(void)
0047 {
0048     sysfs_remove_bin_file(firmware_kobj, &memconsole_bin_attr);
0049 }
0050 EXPORT_SYMBOL(memconsole_exit);
0051 
0052 MODULE_AUTHOR("Google, Inc.");
0053 MODULE_LICENSE("GPL");