From 71fc47a9adf8ee89e5c96a47222915c5485ac437 Mon Sep 17 00:00:00 2001 From: Markus Gaugusch Date: Tue, 5 Feb 2008 00:04:06 +0100 Subject: ACPI: basic initramfs DSDT override support The basics of DSDT from initramfs. In case this option is selected, populate_rootfs() is called a bit earlier to have the initramfs content available during ACPI initialization. This is a very similar path to the one available at http://gaugusch.at/kernel.shtml but with some update in the documentation, default set to No and the change of populate_rootfs() the "Jeff Mahony way" (which avoids reading the initramfs twice). Signed-off-by: Thomas Renninger Signed-off-by: Eric Piel Signed-off-by: Len Brown --- drivers/acpi/osl.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 4 deletions(-) (limited to 'drivers/acpi/osl.c') diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c index e53fb516f9d..131936e7ff1 100644 --- a/drivers/acpi/osl.c +++ b/drivers/acpi/osl.c @@ -312,6 +312,66 @@ acpi_os_predefined_override(const struct acpi_predefined_names *init_val, return AE_OK; } +#ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD +struct acpi_table_header *acpi_find_dsdt_initrd(void) +{ + struct file *firmware_file; + mm_segment_t oldfs; + unsigned long len, len2; + struct acpi_table_header *dsdt_buffer, *ret = NULL; + struct kstat stat; + char *ramfs_dsdt_name = "/DSDT.aml"; + + printk(KERN_INFO PREFIX "Looking for DSDT in initramfs... "); + + /* + * Never do this at home, only the user-space is allowed to open a file. + * The clean way would be to use the firmware loader. But this code must be run + * before there is any userspace available. So we need a static/init firmware + * infrastructure, which doesn't exist yet... + */ + if (vfs_stat(ramfs_dsdt_name, &stat) < 0) { + printk("not found.\n"); + return ret; + } + + len = stat.size; + /* check especially against empty files */ + if (len <= 4) { + printk("error, file is too small: only %lu bytes.\n", len); + return ret; + } + + firmware_file = filp_open(ramfs_dsdt_name, O_RDONLY, 0); + if (IS_ERR(firmware_file)) { + printk("error, could not open file %s.\n", ramfs_dsdt_name); + return ret; + } + + dsdt_buffer = ACPI_ALLOCATE(len); + if (!dsdt_buffer) { + printk("error when allocating %lu bytes of memory.\n", len); + goto err; + } + + oldfs = get_fs(); + set_fs(KERNEL_DS); + len2 = vfs_read(firmware_file, (char __user *)dsdt_buffer, len, &firmware_file->f_pos); + set_fs(oldfs); + if (len2 < len) { + printk("error trying to read %lu bytes from %s.\n", len, ramfs_dsdt_name); + ACPI_FREE(dsdt_buffer); + goto err; + } + + printk("successfully read %lu bytes from %s.\n", len, ramfs_dsdt_name); + ret = dsdt_buffer; +err: + filp_close(firmware_file, NULL); + return ret; +} +#endif + acpi_status acpi_os_table_override(struct acpi_table_header * existing_table, struct acpi_table_header ** new_table) @@ -319,13 +379,18 @@ acpi_os_table_override(struct acpi_table_header * existing_table, if (!existing_table || !new_table) return AE_BAD_PARAMETER; + *new_table = NULL; + #ifdef CONFIG_ACPI_CUSTOM_DSDT if (strncmp(existing_table->signature, "DSDT", 4) == 0) *new_table = (struct acpi_table_header *)AmlCode; - else - *new_table = NULL; -#else - *new_table = NULL; +#endif +#ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD + if (strncmp(existing_table->signature, "DSDT", 4) == 0) { + struct acpi_table_header *initrd_table = acpi_find_dsdt_initrd(); + if (initrd_table) + *new_table = initrd_table; + } #endif return AE_OK; } -- cgit v1.2.3 From 6ed31e92e94830c138fbd470486383380710069a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Piel?= Date: Tue, 5 Feb 2008 00:04:50 +0100 Subject: ACPI: Taint kernel on ACPI table override (format corrected) When an ACPI table is overridden (for now this can happen only for DSDT) display a big warning and taint the kernel with flag A. Signed-off-by: Eric Piel Signed-off-by: Len Brown --- drivers/acpi/osl.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'drivers/acpi/osl.c') diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c index 131936e7ff1..bbd8360bfb2 100644 --- a/drivers/acpi/osl.c +++ b/drivers/acpi/osl.c @@ -392,6 +392,13 @@ acpi_os_table_override(struct acpi_table_header * existing_table, *new_table = initrd_table; } #endif + if (*new_table != NULL) { + printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], " + "this is unsafe: tainting kernel\n", + existing_table->signature, + existing_table->oem_table_id); + add_taint(TAINT_OVERRIDDEN_ACPI_TABLE); + } return AE_OK; } -- cgit v1.2.3 From 9cbc7960288d28aec95257af59854e1d14ba23b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Piel?= Date: Tue, 5 Feb 2008 00:04:58 +0100 Subject: ACPI: Add "acpi_no_initrd_override" kernel parameter The acpi_no_initrd_override parameter permits to disable the load of an ACPI table from the initramfs. Signed-off-by: Eric Piel Signed-off-by: Len Brown --- drivers/acpi/osl.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'drivers/acpi/osl.c') diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c index bbd8360bfb2..2b41bdddbeb 100644 --- a/drivers/acpi/osl.c +++ b/drivers/acpi/osl.c @@ -77,6 +77,10 @@ static struct workqueue_struct *kacpi_notify_wq; #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */ static char osi_additional_string[OSI_STRING_LENGTH_MAX]; +#ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD +static int acpi_no_initrd_override; +#endif + /* * "Ode to _OSI(Linux)" * @@ -386,7 +390,8 @@ acpi_os_table_override(struct acpi_table_header * existing_table, *new_table = (struct acpi_table_header *)AmlCode; #endif #ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD - if (strncmp(existing_table->signature, "DSDT", 4) == 0) { + if ((strncmp(existing_table->signature, "DSDT", 4) == 0) && + !acpi_no_initrd_override) { struct acpi_table_header *initrd_table = acpi_find_dsdt_initrd(); if (initrd_table) *new_table = initrd_table; @@ -402,6 +407,15 @@ acpi_os_table_override(struct acpi_table_header * existing_table, return AE_OK; } +#ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD +int __init acpi_no_initrd_override_setup(char *s) +{ + acpi_no_initrd_override = 1; + return 1; +} +__setup("acpi_no_initrd_override", acpi_no_initrd_override_setup); +#endif + static irqreturn_t acpi_irq(int irq, void *dev_id) { return (*acpi_irq_handler) (acpi_irq_context) ? IRQ_HANDLED : IRQ_NONE; -- cgit v1.2.3 From 04d94886b47b5133915021dcfb1108a8576f6ea7 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Wed, 6 Feb 2008 19:49:54 -0500 Subject: ACPI: update intrd DSDT override console messages also, address some checkpatch.pl violations Signed-off-by: Len Brown --- drivers/acpi/osl.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'drivers/acpi/osl.c') diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c index 2b41bdddbeb..2a400e08e74 100644 --- a/drivers/acpi/osl.c +++ b/drivers/acpi/osl.c @@ -326,49 +326,50 @@ struct acpi_table_header *acpi_find_dsdt_initrd(void) struct kstat stat; char *ramfs_dsdt_name = "/DSDT.aml"; - printk(KERN_INFO PREFIX "Looking for DSDT in initramfs... "); + printk(KERN_INFO PREFIX "Checking initramfs for custom DSDT"); /* * Never do this at home, only the user-space is allowed to open a file. - * The clean way would be to use the firmware loader. But this code must be run - * before there is any userspace available. So we need a static/init firmware - * infrastructure, which doesn't exist yet... + * The clean way would be to use the firmware loader. + * But this code must be run before there is any userspace available. + * A static/init firmware infrastructure doesn't exist yet... */ - if (vfs_stat(ramfs_dsdt_name, &stat) < 0) { - printk("not found.\n"); + if (vfs_stat(ramfs_dsdt_name, &stat) < 0) return ret; - } len = stat.size; /* check especially against empty files */ if (len <= 4) { - printk("error, file is too small: only %lu bytes.\n", len); + printk(KERN_ERR PREFIX "Failed: DSDT only %lu bytes.\n", len); return ret; } firmware_file = filp_open(ramfs_dsdt_name, O_RDONLY, 0); if (IS_ERR(firmware_file)) { - printk("error, could not open file %s.\n", ramfs_dsdt_name); + printk(KERN_ERR PREFIX "Failed to open %s.\n", ramfs_dsdt_name); return ret; } - dsdt_buffer = ACPI_ALLOCATE(len); + dsdt_buffer = kmalloc(len, GFP_ATOMIC); if (!dsdt_buffer) { - printk("error when allocating %lu bytes of memory.\n", len); + printk(KERN_ERR PREFIX "Failed to allocate %lu bytes.\n", len); goto err; } oldfs = get_fs(); set_fs(KERNEL_DS); - len2 = vfs_read(firmware_file, (char __user *)dsdt_buffer, len, &firmware_file->f_pos); + len2 = vfs_read(firmware_file, (char __user *)dsdt_buffer, len, + &firmware_file->f_pos); set_fs(oldfs); if (len2 < len) { - printk("error trying to read %lu bytes from %s.\n", len, ramfs_dsdt_name); + printk(KERN_ERR PREFIX "Failed to read %lu bytes from %s.\n", + len, ramfs_dsdt_name); ACPI_FREE(dsdt_buffer); goto err; } - printk("successfully read %lu bytes from %s.\n", len, ramfs_dsdt_name); + printk(KERN_INFO PREFIX "Found %lu byte DSDT in %s.\n", + len, ramfs_dsdt_name); ret = dsdt_buffer; err: filp_close(firmware_file, NULL); @@ -392,7 +393,9 @@ acpi_os_table_override(struct acpi_table_header * existing_table, #ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD if ((strncmp(existing_table->signature, "DSDT", 4) == 0) && !acpi_no_initrd_override) { - struct acpi_table_header *initrd_table = acpi_find_dsdt_initrd(); + struct acpi_table_header *initrd_table; + + initrd_table = acpi_find_dsdt_initrd(); if (initrd_table) *new_table = initrd_table; } -- cgit v1.2.3