at v4.12-rc4 62 lines 1.7 kB view raw
1/* 2 * memconsole.c 3 * 4 * Architecture-independent parts of the memory based BIOS console. 5 * 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. 16 */ 17 18#include <linux/init.h> 19#include <linux/sysfs.h> 20#include <linux/kobject.h> 21#include <linux/module.h> 22 23#include "memconsole.h" 24 25static char *memconsole_baseaddr; 26static size_t memconsole_length; 27 28static ssize_t memconsole_read(struct file *filp, struct kobject *kobp, 29 struct bin_attribute *bin_attr, char *buf, 30 loff_t pos, size_t count) 31{ 32 return memory_read_from_buffer(buf, count, &pos, memconsole_baseaddr, 33 memconsole_length); 34} 35 36static struct bin_attribute memconsole_bin_attr = { 37 .attr = {.name = "log", .mode = 0444}, 38 .read = memconsole_read, 39}; 40 41void memconsole_setup(void *baseaddr, size_t length) 42{ 43 memconsole_baseaddr = baseaddr; 44 memconsole_length = length; 45} 46EXPORT_SYMBOL(memconsole_setup); 47 48int memconsole_sysfs_init(void) 49{ 50 memconsole_bin_attr.size = memconsole_length; 51 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr); 52} 53EXPORT_SYMBOL(memconsole_sysfs_init); 54 55void memconsole_exit(void) 56{ 57 sysfs_remove_bin_file(firmware_kobj, &memconsole_bin_attr); 58} 59EXPORT_SYMBOL(memconsole_exit); 60 61MODULE_AUTHOR("Google, Inc."); 62MODULE_LICENSE("GPL");