^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * dmi-sysfs.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * This module exports the DMI tables read-only to userspace through the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * sysfs file system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Data is currently found below
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * /sys/firmware/dmi/...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * DMI attributes are presented in attribute files with names
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * formatted using %d-%d, so that the first integer indicates the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * structure type (0-255), and the second field is the instance of that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Copyright 2011 Google, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/kobject.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <asm/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define MAX_ENTRY_TYPE 255 /* Most of these aren't used, but we consider
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) the top entry type is only 8 bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct dmi_sysfs_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct dmi_header dh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct kobject kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) int instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) int position;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct kobject *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * Global list of dmi_sysfs_entry. Even though this should only be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * manipulated at setup and teardown, the lazy nature of the kobject
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * system means we get lazy removes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static LIST_HEAD(entry_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static DEFINE_SPINLOCK(entry_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* dmi_sysfs_attribute - Top level attribute. used by all entries. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct dmi_sysfs_attribute {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct attribute attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) ssize_t (*show)(struct dmi_sysfs_entry *entry, char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define DMI_SYSFS_ATTR(_entry, _name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct dmi_sysfs_attribute dmi_sysfs_attr_##_entry##_##_name = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .attr = {.name = __stringify(_name), .mode = 0400}, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .show = dmi_sysfs_##_entry##_##_name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * dmi_sysfs_mapped_attribute - Attribute where we require the entry be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * mapped in. Use in conjunction with dmi_sysfs_specialize_attr_ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct dmi_sysfs_mapped_attribute {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct attribute attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ssize_t (*show)(struct dmi_sysfs_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) const struct dmi_header *dh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define DMI_SYSFS_MAPPED_ATTR(_entry, _name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct dmi_sysfs_mapped_attribute dmi_sysfs_attr_##_entry##_##_name = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) .attr = {.name = __stringify(_name), .mode = 0400}, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .show = dmi_sysfs_##_entry##_##_name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) /*************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * Generic DMI entry support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) *************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static void dmi_entry_free(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) kfree(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static struct dmi_sysfs_entry *to_entry(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return container_of(kobj, struct dmi_sysfs_entry, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static struct dmi_sysfs_attribute *to_attr(struct attribute *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return container_of(attr, struct dmi_sysfs_attribute, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static ssize_t dmi_sysfs_attr_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct attribute *_attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct dmi_sysfs_entry *entry = to_entry(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct dmi_sysfs_attribute *attr = to_attr(_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /* DMI stuff is only ever admin visible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return attr->show(entry, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static const struct sysfs_ops dmi_sysfs_attr_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .show = dmi_sysfs_attr_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) typedef ssize_t (*dmi_callback)(struct dmi_sysfs_entry *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) const struct dmi_header *dh, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct find_dmi_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct dmi_sysfs_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) dmi_callback callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) void *private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int instance_countdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static void find_dmi_entry_helper(const struct dmi_header *dh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) void *_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct find_dmi_data *data = _data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct dmi_sysfs_entry *entry = data->entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /* Is this the entry we want? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (dh->type != entry->dh.type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (data->instance_countdown != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /* try the next instance? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) data->instance_countdown--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * Don't ever revisit the instance. Short circuit later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * instances by letting the instance_countdown run negative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) data->instance_countdown--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /* Found the entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) data->ret = data->callback(entry, dh, data->private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /* State for passing the read parameters through dmi_find_entry() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct dmi_read_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) loff_t pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) size_t count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static ssize_t find_dmi_entry(struct dmi_sysfs_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) dmi_callback callback, void *private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct find_dmi_data data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) .entry = entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) .callback = callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) .private = private,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) .instance_countdown = entry->instance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) .ret = -EIO, /* To signal the entry disappeared */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) ret = dmi_walk(find_dmi_entry_helper, &data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /* This shouldn't happen, but just in case. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return data.ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * Calculate and return the byte length of the dmi entry identified by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * dh. This includes both the formatted portion as well as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * unformatted string space, including the two trailing nul characters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static size_t dmi_entry_length(const struct dmi_header *dh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) const char *p = (const char *)dh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) p += dh->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) while (p[0] || p[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return 2 + p - (const char *)dh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /*************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * Support bits for specialized DMI entry support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) *************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct dmi_entry_attr_show_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct attribute *attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static ssize_t dmi_entry_attr_show_helper(struct dmi_sysfs_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) const struct dmi_header *dh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) void *_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct dmi_entry_attr_show_data *data = _data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct dmi_sysfs_mapped_attribute *attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) attr = container_of(data->attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct dmi_sysfs_mapped_attribute, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) return attr->show(entry, dh, data->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static ssize_t dmi_entry_attr_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) struct dmi_entry_attr_show_data data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) .attr = attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) .buf = buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* Find the entry according to our parent and call the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * normalized show method hanging off of the attribute */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return find_dmi_entry(to_entry(kobj->parent),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) dmi_entry_attr_show_helper, &data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static const struct sysfs_ops dmi_sysfs_specialize_attr_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) .show = dmi_entry_attr_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /*************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * Specialized DMI entry support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) *************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /*** Type 15 - System Event Table ***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) #define DMI_SEL_ACCESS_METHOD_IO8 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) #define DMI_SEL_ACCESS_METHOD_IO2x8 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) #define DMI_SEL_ACCESS_METHOD_IO16 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #define DMI_SEL_ACCESS_METHOD_PHYS32 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #define DMI_SEL_ACCESS_METHOD_GPNV 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct dmi_system_event_log {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct dmi_header header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) u16 area_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) u16 header_start_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) u16 data_start_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) u8 access_method;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) u8 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) u32 change_token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) u16 index_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) u16 data_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) } io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) u32 phys_addr32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) u16 gpnv_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) u32 access_method_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) u8 header_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) u8 type_descriptors_supported_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) u8 per_log_type_descriptor_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) u8 supported_log_type_descriptos[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) #define DMI_SYSFS_SEL_FIELD(_field) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static ssize_t dmi_sysfs_sel_##_field(struct dmi_sysfs_entry *entry, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) const struct dmi_header *dh, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct dmi_system_event_log sel; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (sizeof(sel) > dmi_entry_length(dh)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return -EIO; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) memcpy(&sel, dh, sizeof(sel)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return sprintf(buf, "%u\n", sel._field); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static DMI_SYSFS_MAPPED_ATTR(sel, _field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) DMI_SYSFS_SEL_FIELD(area_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) DMI_SYSFS_SEL_FIELD(header_start_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) DMI_SYSFS_SEL_FIELD(data_start_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) DMI_SYSFS_SEL_FIELD(access_method);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) DMI_SYSFS_SEL_FIELD(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) DMI_SYSFS_SEL_FIELD(change_token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) DMI_SYSFS_SEL_FIELD(access_method_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) DMI_SYSFS_SEL_FIELD(header_format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) DMI_SYSFS_SEL_FIELD(type_descriptors_supported_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) DMI_SYSFS_SEL_FIELD(per_log_type_descriptor_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static struct attribute *dmi_sysfs_sel_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) &dmi_sysfs_attr_sel_area_length.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) &dmi_sysfs_attr_sel_header_start_offset.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) &dmi_sysfs_attr_sel_data_start_offset.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) &dmi_sysfs_attr_sel_access_method.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) &dmi_sysfs_attr_sel_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) &dmi_sysfs_attr_sel_change_token.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) &dmi_sysfs_attr_sel_access_method_address.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) &dmi_sysfs_attr_sel_header_format.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) &dmi_sysfs_attr_sel_type_descriptors_supported_count.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) &dmi_sysfs_attr_sel_per_log_type_descriptor_length.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static struct kobj_type dmi_system_event_log_ktype = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) .release = dmi_entry_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) .sysfs_ops = &dmi_sysfs_specialize_attr_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) .default_attrs = dmi_sysfs_sel_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) typedef u8 (*sel_io_reader)(const struct dmi_system_event_log *sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) loff_t offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static DEFINE_MUTEX(io_port_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static u8 read_sel_8bit_indexed_io(const struct dmi_system_event_log *sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) loff_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) u8 ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) mutex_lock(&io_port_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) outb((u8)offset, sel->io.index_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) ret = inb(sel->io.data_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) mutex_unlock(&io_port_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static u8 read_sel_2x8bit_indexed_io(const struct dmi_system_event_log *sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) loff_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) u8 ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) mutex_lock(&io_port_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) outb((u8)offset, sel->io.index_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) outb((u8)(offset >> 8), sel->io.index_addr + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) ret = inb(sel->io.data_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) mutex_unlock(&io_port_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) static u8 read_sel_16bit_indexed_io(const struct dmi_system_event_log *sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) loff_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) u8 ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) mutex_lock(&io_port_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) outw((u16)offset, sel->io.index_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) ret = inb(sel->io.data_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) mutex_unlock(&io_port_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static sel_io_reader sel_io_readers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) [DMI_SEL_ACCESS_METHOD_IO8] = read_sel_8bit_indexed_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) [DMI_SEL_ACCESS_METHOD_IO2x8] = read_sel_2x8bit_indexed_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) [DMI_SEL_ACCESS_METHOD_IO16] = read_sel_16bit_indexed_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static ssize_t dmi_sel_raw_read_io(struct dmi_sysfs_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) const struct dmi_system_event_log *sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) char *buf, loff_t pos, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) ssize_t wrote = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) sel_io_reader io_reader = sel_io_readers[sel->access_method];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) while (count && pos < sel->area_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) *(buf++) = io_reader(sel, pos++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) wrote++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return wrote;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) static ssize_t dmi_sel_raw_read_phys32(struct dmi_sysfs_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) const struct dmi_system_event_log *sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) char *buf, loff_t pos, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) u8 __iomem *mapped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) ssize_t wrote = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) mapped = dmi_remap(sel->access_method_address, sel->area_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (!mapped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) while (count && pos < sel->area_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) *(buf++) = readb(mapped + pos++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) wrote++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) dmi_unmap(mapped);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) return wrote;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) static ssize_t dmi_sel_raw_read_helper(struct dmi_sysfs_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) const struct dmi_header *dh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) void *_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) struct dmi_read_state *state = _state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) struct dmi_system_event_log sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (sizeof(sel) > dmi_entry_length(dh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) memcpy(&sel, dh, sizeof(sel));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) switch (sel.access_method) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) case DMI_SEL_ACCESS_METHOD_IO8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) case DMI_SEL_ACCESS_METHOD_IO2x8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) case DMI_SEL_ACCESS_METHOD_IO16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return dmi_sel_raw_read_io(entry, &sel, state->buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) state->pos, state->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) case DMI_SEL_ACCESS_METHOD_PHYS32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) return dmi_sel_raw_read_phys32(entry, &sel, state->buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) state->pos, state->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) case DMI_SEL_ACCESS_METHOD_GPNV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) pr_info("dmi-sysfs: GPNV support missing.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) pr_info("dmi-sysfs: Unknown access method %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) sel.access_method);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static ssize_t dmi_sel_raw_read(struct file *filp, struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) struct bin_attribute *bin_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) char *buf, loff_t pos, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) struct dmi_sysfs_entry *entry = to_entry(kobj->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) struct dmi_read_state state = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) .buf = buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) .pos = pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) .count = count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) return find_dmi_entry(entry, dmi_sel_raw_read_helper, &state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) static struct bin_attribute dmi_sel_raw_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) .attr = {.name = "raw_event_log", .mode = 0400},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) .read = dmi_sel_raw_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) static int dmi_system_event_log(struct dmi_sysfs_entry *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) entry->child = kzalloc(sizeof(*entry->child), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (!entry->child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) ret = kobject_init_and_add(entry->child,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) &dmi_system_event_log_ktype,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) &entry->kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) "system_event_log");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) ret = sysfs_create_bin_file(entry->child, &dmi_sel_raw_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) goto out_del;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) out_del:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) kobject_del(entry->child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) kfree(entry->child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) /*************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) * Generic DMI entry support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) *************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) static ssize_t dmi_sysfs_entry_length(struct dmi_sysfs_entry *entry, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) return sprintf(buf, "%d\n", entry->dh.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) static ssize_t dmi_sysfs_entry_handle(struct dmi_sysfs_entry *entry, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) return sprintf(buf, "%d\n", entry->dh.handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) static ssize_t dmi_sysfs_entry_type(struct dmi_sysfs_entry *entry, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) return sprintf(buf, "%d\n", entry->dh.type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) static ssize_t dmi_sysfs_entry_instance(struct dmi_sysfs_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) return sprintf(buf, "%d\n", entry->instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) static ssize_t dmi_sysfs_entry_position(struct dmi_sysfs_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) return sprintf(buf, "%d\n", entry->position);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) static DMI_SYSFS_ATTR(entry, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) static DMI_SYSFS_ATTR(entry, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) static DMI_SYSFS_ATTR(entry, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) static DMI_SYSFS_ATTR(entry, instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) static DMI_SYSFS_ATTR(entry, position);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) static struct attribute *dmi_sysfs_entry_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) &dmi_sysfs_attr_entry_length.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) &dmi_sysfs_attr_entry_handle.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) &dmi_sysfs_attr_entry_type.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) &dmi_sysfs_attr_entry_instance.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) &dmi_sysfs_attr_entry_position.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) static ssize_t dmi_entry_raw_read_helper(struct dmi_sysfs_entry *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) const struct dmi_header *dh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) void *_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) struct dmi_read_state *state = _state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) size_t entry_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) entry_length = dmi_entry_length(dh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) return memory_read_from_buffer(state->buf, state->count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) &state->pos, dh, entry_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) static ssize_t dmi_entry_raw_read(struct file *filp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) struct bin_attribute *bin_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) char *buf, loff_t pos, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) struct dmi_sysfs_entry *entry = to_entry(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) struct dmi_read_state state = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) .buf = buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) .pos = pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) .count = count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return find_dmi_entry(entry, dmi_entry_raw_read_helper, &state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) static const struct bin_attribute dmi_entry_raw_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) .attr = {.name = "raw", .mode = 0400},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) .read = dmi_entry_raw_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) static void dmi_sysfs_entry_release(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) struct dmi_sysfs_entry *entry = to_entry(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) spin_lock(&entry_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) list_del(&entry->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) spin_unlock(&entry_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) kfree(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) static struct kobj_type dmi_sysfs_entry_ktype = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) .release = dmi_sysfs_entry_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) .sysfs_ops = &dmi_sysfs_attr_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) .default_attrs = dmi_sysfs_entry_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) static struct kset *dmi_kset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) /* Global count of all instances seen. Only for setup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) static int __initdata instance_counts[MAX_ENTRY_TYPE + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) /* Global positional count of all entries seen. Only for setup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) static int __initdata position_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) static void __init dmi_sysfs_register_handle(const struct dmi_header *dh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) void *_ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) struct dmi_sysfs_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) int *ret = _ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) /* If a previous entry saw an error, short circuit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) if (*ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) /* Allocate and register a new entry into the entries set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) entry = kzalloc(sizeof(*entry), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) if (!entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) *ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) /* Set the key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) memcpy(&entry->dh, dh, sizeof(*dh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) entry->instance = instance_counts[dh->type]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) entry->position = position_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) entry->kobj.kset = dmi_kset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) *ret = kobject_init_and_add(&entry->kobj, &dmi_sysfs_entry_ktype, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) "%d-%d", dh->type, entry->instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (*ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) kfree(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) /* Thread on the global list for cleanup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) spin_lock(&entry_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) list_add_tail(&entry->list, &entry_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) spin_unlock(&entry_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) /* Handle specializations by type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) switch (dh->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) case DMI_ENTRY_SYSTEM_EVENT_LOG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) *ret = dmi_system_event_log(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) /* No specialization */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) if (*ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) /* Create the raw binary file to access the entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) *ret = sysfs_create_bin_file(&entry->kobj, &dmi_entry_raw_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) if (*ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) kobject_put(entry->child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) kobject_put(&entry->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) static void cleanup_entry_list(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) struct dmi_sysfs_entry *entry, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) /* No locks, we are on our way out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) list_for_each_entry_safe(entry, next, &entry_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) kobject_put(entry->child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) kobject_put(&entry->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) static int __init dmi_sysfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) if (!dmi_kobj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) pr_debug("dmi-sysfs: dmi entry is absent.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) error = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) dmi_kset = kset_create_and_add("entries", NULL, dmi_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) if (!dmi_kset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) error = dmi_walk(dmi_sysfs_register_handle, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) if (val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) error = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) pr_debug("dmi-sysfs: loaded.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) cleanup_entry_list();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) kset_unregister(dmi_kset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) /* clean up everything. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) static void __exit dmi_sysfs_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) pr_debug("dmi-sysfs: unloading.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) cleanup_entry_list();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) kset_unregister(dmi_kset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) module_init(dmi_sysfs_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) module_exit(dmi_sysfs_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) MODULE_AUTHOR("Mike Waychison <mikew@google.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) MODULE_DESCRIPTION("DMI sysfs support");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) MODULE_LICENSE("GPL");