ACPI / video: Quirk initial backlight level 0
[linux-3.10.git] / drivers / acpi / tables.c
index 849e2c3..d67a1fe 100644 (file)
@@ -42,7 +42,9 @@ static char *mps_inti_flags_trigger[] = { "dfl", "edge", "res", "level" };
 
 static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES] __initdata;
 
-void acpi_table_print_madt_entry(struct acpi_subtable_header * header)
+static int acpi_apic_instance __initdata;
+
+void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
 {
        if (!header)
                return;
@@ -60,6 +62,18 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header * header)
                }
                break;
 
+       case ACPI_MADT_TYPE_LOCAL_X2APIC:
+               {
+                       struct acpi_madt_local_x2apic *p =
+                           (struct acpi_madt_local_x2apic *)header;
+                       printk(KERN_INFO PREFIX
+                              "X2APIC (apic_id[0x%02x] uid[0x%02x] %s)\n",
+                              p->local_apic_id, p->uid,
+                              (p->lapic_flags & ACPI_MADT_ENABLED) ?
+                              "enabled" : "disabled");
+               }
+               break;
+
        case ACPI_MADT_TYPE_IO_APIC:
                {
                        struct acpi_madt_io_apic *p =
@@ -114,6 +128,24 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header * header)
                }
                break;
 
+       case ACPI_MADT_TYPE_LOCAL_X2APIC_NMI:
+               {
+                       u16 polarity, trigger;
+                       struct acpi_madt_local_x2apic_nmi *p =
+                           (struct acpi_madt_local_x2apic_nmi *)header;
+
+                       polarity = p->inti_flags & ACPI_MADT_POLARITY_MASK;
+                       trigger = (p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
+
+                       printk(KERN_INFO PREFIX
+                              "X2APIC_NMI (uid[0x%02x] %s %s lint[0x%x])\n",
+                              p->uid,
+                              mps_inti_flags_polarity[polarity],
+                              mps_inti_flags_trigger[trigger],
+                              p->lint);
+               }
+               break;
+
        case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE:
                {
                        struct acpi_madt_local_apic_override *p =
@@ -172,19 +204,25 @@ int __init
 acpi_table_parse_entries(char *id,
                             unsigned long table_size,
                             int entry_id,
-                            acpi_table_entry_handler handler,
+                            acpi_tbl_entry_handler handler,
                             unsigned int max_entries)
 {
        struct acpi_table_header *table_header = NULL;
        struct acpi_subtable_header *entry;
        unsigned int count = 0;
        unsigned long table_end;
+       acpi_size tbl_size;
+
+       if (acpi_disabled)
+               return -ENODEV;
 
        if (!handler)
                return -EINVAL;
 
-       /* Locate the table (if exists). There should only be one. */
-       acpi_get_table(id, 0, &table_header);
+       if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
+               acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size);
+       else
+               acpi_get_table_with_size(id, 0, &table_header, &tbl_size);
 
        if (!table_header) {
                printk(KERN_WARNING PREFIX "%4.4s not present\n", id);
@@ -203,7 +241,16 @@ acpi_table_parse_entries(char *id,
                if (entry->type == entry_id
                    && (!max_entries || count++ < max_entries))
                        if (handler(entry, table_end))
-                               return -EINVAL;
+                               goto err;
+
+               /*
+                * If entry->length is 0, break from this loop to avoid
+                * infinite loop.
+                */
+               if (entry->length == 0) {
+                       pr_err(PREFIX "[%4.4s:0x%02x] Invalid zero length\n", id, entry_id);
+                       goto err;
+               }
 
                entry = (struct acpi_subtable_header *)
                    ((unsigned long)entry + entry->length);
@@ -213,12 +260,16 @@ acpi_table_parse_entries(char *id,
                       "%i found\n", id, entry_id, count - max_entries, count);
        }
 
+       early_acpi_os_unmap_memory((char *)table_header, tbl_size);
        return count;
+err:
+       early_acpi_os_unmap_memory((char *)table_header, tbl_size);
+       return -EINVAL;
 }
 
 int __init
 acpi_table_parse_madt(enum acpi_madt_type id,
-                     acpi_table_entry_handler handler, unsigned int max_entries)
+                     acpi_tbl_entry_handler handler, unsigned int max_entries)
 {
        return acpi_table_parse_entries(ACPI_SIG_MADT,
                                            sizeof(struct acpi_table_madt), id,
@@ -234,20 +285,57 @@ acpi_table_parse_madt(enum acpi_madt_type id,
  * Scan the ACPI System Descriptor Table (STD) for a table matching @id,
  * run @handler on it.  Return 0 if table found, return on if not.
  */
-int __init acpi_table_parse(char *id, acpi_table_handler handler)
+int __init acpi_table_parse(char *id, acpi_tbl_table_handler handler)
 {
        struct acpi_table_header *table = NULL;
+       acpi_size tbl_size;
+
+       if (acpi_disabled)
+               return -ENODEV;
+
        if (!handler)
                return -EINVAL;
 
-       acpi_get_table(id, 0, &table);
+       if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
+               acpi_get_table_with_size(id, acpi_apic_instance, &table, &tbl_size);
+       else
+               acpi_get_table_with_size(id, 0, &table, &tbl_size);
+
        if (table) {
                handler(table);
+               early_acpi_os_unmap_memory(table, tbl_size);
                return 0;
        } else
                return 1;
 }
 
+/* 
+ * The BIOS is supposed to supply a single APIC/MADT,
+ * but some report two.  Provide a knob to use either.
+ * (don't you wish instance 0 and 1 were not the same?)
+ */
+static void __init check_multiple_madt(void)
+{
+       struct acpi_table_header *table = NULL;
+       acpi_size tbl_size;
+
+       acpi_get_table_with_size(ACPI_SIG_MADT, 2, &table, &tbl_size);
+       if (table) {
+               printk(KERN_WARNING PREFIX
+                      "BIOS bug: multiple APIC/MADT found,"
+                      " using %d\n", acpi_apic_instance);
+               printk(KERN_WARNING PREFIX
+                      "If \"acpi_apic_instance=%d\" works better, "
+                      "notify linux-acpi@vger.kernel.org\n",
+                      acpi_apic_instance ? 0 : 2);
+               early_acpi_os_unmap_memory(table, tbl_size);
+
+       } else
+               acpi_apic_instance = 0;
+
+       return;
+}
+
 /*
  * acpi_table_init()
  *
@@ -257,9 +345,29 @@ int __init acpi_table_parse(char *id, acpi_table_handler handler)
  * result: sdt_entry[] is initialized
  */
 
-
 int __init acpi_table_init(void)
 {
-       acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
+       acpi_status status;
+
+       status = acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
+       if (ACPI_FAILURE(status))
+               return 1;
+
+       check_multiple_madt();
        return 0;
 }
+
+static int __init acpi_parse_apic_instance(char *str)
+{
+       if (!str)
+               return -EINVAL;
+
+       acpi_apic_instance = simple_strtoul(str, NULL, 0);
+
+       printk(KERN_NOTICE PREFIX "Shall use APIC/MADT table %d\n",
+              acpi_apic_instance);
+
+       return 0;
+}
+
+early_param("acpi_apic_instance", acpi_parse_apic_instance);