Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * memconsole.c |
| 3 | * |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 4 | * Architecture-independent parts of the memory based BIOS console. |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 5 | * |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 6 | * Copyright 2017 Google Inc. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License v2.0 as published by |
| 10 | * the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 18 | #include <linux/init.h> |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 19 | #include <linux/sysfs.h> |
| 20 | #include <linux/kobject.h> |
| 21 | #include <linux/module.h> |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 22 | |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 23 | #include "memconsole.h" |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 24 | |
Julius Werner | 7918cfc | 2017-05-02 15:16:29 -0700 | [diff] [blame] | 25 | static ssize_t (*memconsole_read_func)(char *, loff_t, size_t); |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 26 | |
| 27 | static ssize_t memconsole_read(struct file *filp, struct kobject *kobp, |
| 28 | struct bin_attribute *bin_attr, char *buf, |
| 29 | loff_t pos, size_t count) |
| 30 | { |
Julius Werner | 7918cfc | 2017-05-02 15:16:29 -0700 | [diff] [blame] | 31 | if (WARN_ON_ONCE(!memconsole_read_func)) |
| 32 | return -EIO; |
| 33 | return memconsole_read_func(buf, pos, count); |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | static struct bin_attribute memconsole_bin_attr = { |
| 37 | .attr = {.name = "log", .mode = 0444}, |
| 38 | .read = memconsole_read, |
| 39 | }; |
| 40 | |
Julius Werner | 7918cfc | 2017-05-02 15:16:29 -0700 | [diff] [blame] | 41 | void memconsole_setup(ssize_t (*read_func)(char *, loff_t, size_t)) |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 42 | { |
Julius Werner | 7918cfc | 2017-05-02 15:16:29 -0700 | [diff] [blame] | 43 | memconsole_read_func = read_func; |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 44 | } |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 45 | EXPORT_SYMBOL(memconsole_setup); |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 46 | |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 47 | int memconsole_sysfs_init(void) |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 48 | { |
Michel Lespinasse | cb88759 | 2014-01-28 05:06:22 -0800 | [diff] [blame] | 49 | return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr); |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 50 | } |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 51 | EXPORT_SYMBOL(memconsole_sysfs_init); |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 52 | |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 53 | void memconsole_exit(void) |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 54 | { |
| 55 | sysfs_remove_bin_file(firmware_kobj, &memconsole_bin_attr); |
| 56 | } |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 57 | EXPORT_SYMBOL(memconsole_exit); |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 58 | |
| 59 | MODULE_AUTHOR("Google, Inc."); |
| 60 | MODULE_LICENSE("GPL"); |