mirror of
https://github.com/torvalds/linux.git
synced 2024-12-27 05:11:48 +00:00
5a0e3ad6af
percpu.h is included by sched.h and module.h and thus ends up being included when building most .c files. percpu.h includes slab.h which in turn includes gfp.h making everything defined by the two files universally available and complicating inclusion dependencies. percpu.h -> slab.h dependency is about to be removed. Prepare for this change by updating users of gfp and slab facilities include those headers directly instead of assuming availability. As this conversion needs to touch large number of source files, the following script is used as the basis of conversion. http://userweb.kernel.org/~tj/misc/slabh-sweep.py The script does the followings. * Scan files for gfp and slab usages and update includes such that only the necessary includes are there. ie. if only gfp is used, gfp.h, if slab is used, slab.h. * When the script inserts a new include, it looks at the include blocks and try to put the new include such that its order conforms to its surrounding. It's put in the include block which contains core kernel includes, in the same order that the rest are ordered - alphabetical, Christmas tree, rev-Xmas-tree or at the end if there doesn't seem to be any matching order. * If the script can't find a place to put a new include (mostly because the file doesn't have fitting include block), it prints out an error message indicating which .h file needs to be added to the file. The conversion was done in the following steps. 1. The initial automatic conversion of all .c files updated slightly over 4000 files, deleting around 700 includes and adding ~480 gfp.h and ~3000 slab.h inclusions. The script emitted errors for ~400 files. 2. Each error was manually checked. Some didn't need the inclusion, some needed manual addition while adding it to implementation .h or embedding .c file was more appropriate for others. This step added inclusions to around 150 files. 3. The script was run again and the output was compared to the edits from #2 to make sure no file was left behind. 4. Several build tests were done and a couple of problems were fixed. e.g. lib/decompress_*.c used malloc/free() wrappers around slab APIs requiring slab.h to be added manually. 5. The script was run on all .h files but without automatically editing them as sprinkling gfp.h and slab.h inclusions around .h files could easily lead to inclusion dependency hell. Most gfp.h inclusion directives were ignored as stuff from gfp.h was usually wildly available and often used in preprocessor macros. Each slab.h inclusion directive was examined and added manually as necessary. 6. percpu.h was updated not to include slab.h. 7. Build test were done on the following configurations and failures were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my distributed build env didn't work with gcov compiles) and a few more options had to be turned off depending on archs to make things build (like ipr on powerpc/64 which failed due to missing writeq). * x86 and x86_64 UP and SMP allmodconfig and a custom test config. * powerpc and powerpc64 SMP allmodconfig * sparc and sparc64 SMP allmodconfig * ia64 SMP allmodconfig * s390 SMP allmodconfig * alpha SMP allmodconfig * um on x86_64 SMP allmodconfig 8. percpu.h modifications were reverted so that it could be applied as a separate patch and serve as bisection point. Given the fact that I had only a couple of failures from tests on step 6, I'm fairly confident about the coverage of this conversion patch. If there is a breakage, it's likely to be something in one of the arch headers which should be easily discoverable easily on most builds of the specific arch. Signed-off-by: Tejun Heo <tj@kernel.org> Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
244 lines
6.5 KiB
C
244 lines
6.5 KiB
C
/*
|
|
* Export SMBIOS/DMI info via sysfs to userspace
|
|
*
|
|
* Copyright 2007, Lennart Poettering
|
|
*
|
|
* Licensed under GPLv2
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/init.h>
|
|
#include <linux/dmi.h>
|
|
#include <linux/device.h>
|
|
#include <linux/slab.h>
|
|
|
|
struct dmi_device_attribute{
|
|
struct device_attribute dev_attr;
|
|
int field;
|
|
};
|
|
#define to_dmi_dev_attr(_dev_attr) \
|
|
container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
|
|
|
|
static ssize_t sys_dmi_field_show(struct device *dev,
|
|
struct device_attribute *attr,
|
|
char *page)
|
|
{
|
|
int field = to_dmi_dev_attr(attr)->field;
|
|
ssize_t len;
|
|
len = scnprintf(page, PAGE_SIZE, "%s\n", dmi_get_system_info(field));
|
|
page[len-1] = '\n';
|
|
return len;
|
|
}
|
|
|
|
#define DMI_ATTR(_name, _mode, _show, _field) \
|
|
{ .dev_attr = __ATTR(_name, _mode, _show, NULL), \
|
|
.field = _field }
|
|
|
|
#define DEFINE_DMI_ATTR_WITH_SHOW(_name, _mode, _field) \
|
|
static struct dmi_device_attribute sys_dmi_##_name##_attr = \
|
|
DMI_ATTR(_name, _mode, sys_dmi_field_show, _field);
|
|
|
|
DEFINE_DMI_ATTR_WITH_SHOW(bios_vendor, 0444, DMI_BIOS_VENDOR);
|
|
DEFINE_DMI_ATTR_WITH_SHOW(bios_version, 0444, DMI_BIOS_VERSION);
|
|
DEFINE_DMI_ATTR_WITH_SHOW(bios_date, 0444, DMI_BIOS_DATE);
|
|
DEFINE_DMI_ATTR_WITH_SHOW(sys_vendor, 0444, DMI_SYS_VENDOR);
|
|
DEFINE_DMI_ATTR_WITH_SHOW(product_name, 0444, DMI_PRODUCT_NAME);
|
|
DEFINE_DMI_ATTR_WITH_SHOW(product_version, 0444, DMI_PRODUCT_VERSION);
|
|
DEFINE_DMI_ATTR_WITH_SHOW(product_serial, 0400, DMI_PRODUCT_SERIAL);
|
|
DEFINE_DMI_ATTR_WITH_SHOW(product_uuid, 0400, DMI_PRODUCT_UUID);
|
|
DEFINE_DMI_ATTR_WITH_SHOW(board_vendor, 0444, DMI_BOARD_VENDOR);
|
|
DEFINE_DMI_ATTR_WITH_SHOW(board_name, 0444, DMI_BOARD_NAME);
|
|
DEFINE_DMI_ATTR_WITH_SHOW(board_version, 0444, DMI_BOARD_VERSION);
|
|
DEFINE_DMI_ATTR_WITH_SHOW(board_serial, 0400, DMI_BOARD_SERIAL);
|
|
DEFINE_DMI_ATTR_WITH_SHOW(board_asset_tag, 0444, DMI_BOARD_ASSET_TAG);
|
|
DEFINE_DMI_ATTR_WITH_SHOW(chassis_vendor, 0444, DMI_CHASSIS_VENDOR);
|
|
DEFINE_DMI_ATTR_WITH_SHOW(chassis_type, 0444, DMI_CHASSIS_TYPE);
|
|
DEFINE_DMI_ATTR_WITH_SHOW(chassis_version, 0444, DMI_CHASSIS_VERSION);
|
|
DEFINE_DMI_ATTR_WITH_SHOW(chassis_serial, 0400, DMI_CHASSIS_SERIAL);
|
|
DEFINE_DMI_ATTR_WITH_SHOW(chassis_asset_tag, 0444, DMI_CHASSIS_ASSET_TAG);
|
|
|
|
static void ascii_filter(char *d, const char *s)
|
|
{
|
|
/* Filter out characters we don't want to see in the modalias string */
|
|
for (; *s; s++)
|
|
if (*s > ' ' && *s < 127 && *s != ':')
|
|
*(d++) = *s;
|
|
|
|
*d = 0;
|
|
}
|
|
|
|
static ssize_t get_modalias(char *buffer, size_t buffer_size)
|
|
{
|
|
static const struct mafield {
|
|
const char *prefix;
|
|
int field;
|
|
} fields[] = {
|
|
{ "bvn", DMI_BIOS_VENDOR },
|
|
{ "bvr", DMI_BIOS_VERSION },
|
|
{ "bd", DMI_BIOS_DATE },
|
|
{ "svn", DMI_SYS_VENDOR },
|
|
{ "pn", DMI_PRODUCT_NAME },
|
|
{ "pvr", DMI_PRODUCT_VERSION },
|
|
{ "rvn", DMI_BOARD_VENDOR },
|
|
{ "rn", DMI_BOARD_NAME },
|
|
{ "rvr", DMI_BOARD_VERSION },
|
|
{ "cvn", DMI_CHASSIS_VENDOR },
|
|
{ "ct", DMI_CHASSIS_TYPE },
|
|
{ "cvr", DMI_CHASSIS_VERSION },
|
|
{ NULL, DMI_NONE }
|
|
};
|
|
|
|
ssize_t l, left;
|
|
char *p;
|
|
const struct mafield *f;
|
|
|
|
strcpy(buffer, "dmi");
|
|
p = buffer + 3; left = buffer_size - 4;
|
|
|
|
for (f = fields; f->prefix && left > 0; f++) {
|
|
const char *c;
|
|
char *t;
|
|
|
|
c = dmi_get_system_info(f->field);
|
|
if (!c)
|
|
continue;
|
|
|
|
t = kmalloc(strlen(c) + 1, GFP_KERNEL);
|
|
if (!t)
|
|
break;
|
|
ascii_filter(t, c);
|
|
l = scnprintf(p, left, ":%s%s", f->prefix, t);
|
|
kfree(t);
|
|
|
|
p += l;
|
|
left -= l;
|
|
}
|
|
|
|
p[0] = ':';
|
|
p[1] = 0;
|
|
|
|
return p - buffer + 1;
|
|
}
|
|
|
|
static ssize_t sys_dmi_modalias_show(struct device *dev,
|
|
struct device_attribute *attr, char *page)
|
|
{
|
|
ssize_t r;
|
|
r = get_modalias(page, PAGE_SIZE-1);
|
|
page[r] = '\n';
|
|
page[r+1] = 0;
|
|
return r+1;
|
|
}
|
|
|
|
static struct device_attribute sys_dmi_modalias_attr =
|
|
__ATTR(modalias, 0444, sys_dmi_modalias_show, NULL);
|
|
|
|
static struct attribute *sys_dmi_attributes[DMI_STRING_MAX+2];
|
|
|
|
static struct attribute_group sys_dmi_attribute_group = {
|
|
.attrs = sys_dmi_attributes,
|
|
};
|
|
|
|
static const struct attribute_group* sys_dmi_attribute_groups[] = {
|
|
&sys_dmi_attribute_group,
|
|
NULL
|
|
};
|
|
|
|
static int dmi_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
|
|
{
|
|
ssize_t len;
|
|
|
|
if (add_uevent_var(env, "MODALIAS="))
|
|
return -ENOMEM;
|
|
len = get_modalias(&env->buf[env->buflen - 1],
|
|
sizeof(env->buf) - env->buflen);
|
|
if (len >= (sizeof(env->buf) - env->buflen))
|
|
return -ENOMEM;
|
|
env->buflen += len;
|
|
return 0;
|
|
}
|
|
|
|
static struct class dmi_class = {
|
|
.name = "dmi",
|
|
.dev_release = (void(*)(struct device *)) kfree,
|
|
.dev_uevent = dmi_dev_uevent,
|
|
};
|
|
|
|
static struct device *dmi_dev;
|
|
|
|
/* Initialization */
|
|
|
|
#define ADD_DMI_ATTR(_name, _field) \
|
|
if (dmi_get_system_info(_field)) \
|
|
sys_dmi_attributes[i++] = &sys_dmi_##_name##_attr.dev_attr.attr;
|
|
|
|
/* In a separate function to keep gcc 3.2 happy - do NOT merge this in
|
|
dmi_id_init! */
|
|
static void __init dmi_id_init_attr_table(void)
|
|
{
|
|
int i;
|
|
|
|
/* Not necessarily all DMI fields are available on all
|
|
* systems, hence let's built an attribute table of just
|
|
* what's available */
|
|
i = 0;
|
|
ADD_DMI_ATTR(bios_vendor, DMI_BIOS_VENDOR);
|
|
ADD_DMI_ATTR(bios_version, DMI_BIOS_VERSION);
|
|
ADD_DMI_ATTR(bios_date, DMI_BIOS_DATE);
|
|
ADD_DMI_ATTR(sys_vendor, DMI_SYS_VENDOR);
|
|
ADD_DMI_ATTR(product_name, DMI_PRODUCT_NAME);
|
|
ADD_DMI_ATTR(product_version, DMI_PRODUCT_VERSION);
|
|
ADD_DMI_ATTR(product_serial, DMI_PRODUCT_SERIAL);
|
|
ADD_DMI_ATTR(product_uuid, DMI_PRODUCT_UUID);
|
|
ADD_DMI_ATTR(board_vendor, DMI_BOARD_VENDOR);
|
|
ADD_DMI_ATTR(board_name, DMI_BOARD_NAME);
|
|
ADD_DMI_ATTR(board_version, DMI_BOARD_VERSION);
|
|
ADD_DMI_ATTR(board_serial, DMI_BOARD_SERIAL);
|
|
ADD_DMI_ATTR(board_asset_tag, DMI_BOARD_ASSET_TAG);
|
|
ADD_DMI_ATTR(chassis_vendor, DMI_CHASSIS_VENDOR);
|
|
ADD_DMI_ATTR(chassis_type, DMI_CHASSIS_TYPE);
|
|
ADD_DMI_ATTR(chassis_version, DMI_CHASSIS_VERSION);
|
|
ADD_DMI_ATTR(chassis_serial, DMI_CHASSIS_SERIAL);
|
|
ADD_DMI_ATTR(chassis_asset_tag, DMI_CHASSIS_ASSET_TAG);
|
|
sys_dmi_attributes[i++] = &sys_dmi_modalias_attr.attr;
|
|
}
|
|
|
|
static int __init dmi_id_init(void)
|
|
{
|
|
int ret;
|
|
|
|
if (!dmi_available)
|
|
return -ENODEV;
|
|
|
|
dmi_id_init_attr_table();
|
|
|
|
ret = class_register(&dmi_class);
|
|
if (ret)
|
|
return ret;
|
|
|
|
dmi_dev = kzalloc(sizeof(*dmi_dev), GFP_KERNEL);
|
|
if (!dmi_dev) {
|
|
ret = -ENOMEM;
|
|
goto fail_class_unregister;
|
|
}
|
|
|
|
dmi_dev->class = &dmi_class;
|
|
dev_set_name(dmi_dev, "id");
|
|
dmi_dev->groups = sys_dmi_attribute_groups;
|
|
|
|
ret = device_register(dmi_dev);
|
|
if (ret)
|
|
goto fail_class_unregister;
|
|
|
|
return 0;
|
|
|
|
fail_class_unregister:
|
|
|
|
class_unregister(&dmi_class);
|
|
|
|
return ret;
|
|
}
|
|
|
|
arch_initcall(dmi_id_init);
|