linux/drivers/firmware/google/memconsole.c
<<
>>
Prefs
   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 ssize_t (*memconsole_read_func)(char *, loff_t, size_t);
  26
  27static 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{
  31        if (WARN_ON_ONCE(!memconsole_read_func))
  32                return -EIO;
  33        return memconsole_read_func(buf, pos, count);
  34}
  35
  36static struct bin_attribute memconsole_bin_attr = {
  37        .attr = {.name = "log", .mode = 0444},
  38        .read = memconsole_read,
  39};
  40
  41void memconsole_setup(ssize_t (*read_func)(char *, loff_t, size_t))
  42{
  43        memconsole_read_func = read_func;
  44}
  45EXPORT_SYMBOL(memconsole_setup);
  46
  47int memconsole_sysfs_init(void)
  48{
  49        return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
  50}
  51EXPORT_SYMBOL(memconsole_sysfs_init);
  52
  53void memconsole_exit(void)
  54{
  55        sysfs_remove_bin_file(firmware_kobj, &memconsole_bin_attr);
  56}
  57EXPORT_SYMBOL(memconsole_exit);
  58
  59MODULE_AUTHOR("Google, Inc.");
  60MODULE_LICENSE("GPL");
  61