Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux...
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 28 May 2010 21:42:18 +0000 (14:42 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 28 May 2010 21:42:18 +0000 (14:42 -0700)
* 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux-acpi-2.6: (27 commits)
  ACPI: Don't let acpi_pad needlessly mark TSC unstable
  drivers/acpi/sleep.h: Checkpatch cleanup
  ACPI: Minor cleanup eliminating redundant PMTIMER_TICKS to NS conversion
  ACPI: delete unused c-state promotion/demotion data strucutures
  ACPI: video: fix acpi_backlight=video
  ACPI: EC: Use kmemdup
  drivers/acpi: use kasprintf
  ACPI, APEI, EINJ injection parameters support
  Add x64 support to debugfs
  ACPI, APEI, Use ERST for persistent storage of MCE
  ACPI, APEI, Error Record Serialization Table (ERST) support
  ACPI, APEI, Generic Hardware Error Source memory error support
  ACPI, APEI, UEFI Common Platform Error Record (CPER) header
  Unified UUID/GUID definition
  ACPI Hardware Error Device (PNP0C33) support
  ACPI, APEI, PCIE AER, use general HEST table parsing in AER firmware_first setup
  ACPI, APEI, Document for APEI
  ACPI, APEI, EINJ support
  ACPI, APEI, HEST table parsing
  ACPI, APEI, APEI supporting infrastructure
  ...

1  2 
Documentation/kernel-parameters.txt
arch/x86/kernel/acpi/boot.c
arch/x86/kernel/cpu/mcheck/mce.c
drivers/acpi/acpica/evxfevnt.c
drivers/acpi/processor_idle.c
drivers/pci/pcie/aer/aerdrv.h
drivers/pci/pcie/aer/aerdrv_core.c
include/linux/acpi.h
include/linux/pci.h
lib/Makefile

@@@ -58,7 -58,6 +58,7 @@@ parameter is applicable
        ISAPNP  ISA PnP code is enabled.
        ISDN    Appropriate ISDN support is enabled.
        JOY     Appropriate joystick support is enabled.
 +      KGDB    Kernel debugger support is enabled.
        KVM     Kernel Virtual Machine support is enabled.
        LIBATA  Libata driver is enabled
        LP      Printer support is enabled.
        SWSUSP  Software suspend (hibernation) is enabled.
        SUSPEND System suspend states are enabled.
        FTRACE  Function tracing enabled.
 +      TPM     TPM drivers are enabled.
        TS      Appropriate touchscreen support is enabled.
        UMS     USB Mass Storage support is enabled.
        USB     USB support is enabled.
@@@ -145,15 -143,13 +145,14 @@@ and is between 256 and 4096 characters
  
        acpi=           [HW,ACPI,X86]
                        Advanced Configuration and Power Interface
-                       Format: { force | off | ht | strict | noirq | rsdt }
+                       Format: { force | off | strict | noirq | rsdt }
                        force -- enable ACPI if default was off
                        off -- disable ACPI if default was on
                        noirq -- do not use ACPI for IRQ routing
                        strict -- Be less tolerant of platforms that are not
                                strictly ACPI specification compliant.
                        rsdt -- prefer RSDT over (default) XSDT
 +                      copy_dsdt -- copy DSDT to memory
  
                        See also Documentation/power/pm.txt, pci=noacpi
  
        advansys=       [HW,SCSI]
                        See header of drivers/scsi/advansys.c.
  
 -      advwdt=         [HW,WDT] Advantech WDT
 -                      Format: <iostart>,<iostop>
 -
        aedsp16=        [HW,OSS] Audio Excel DSP 16
                        Format: <io>,<irq>,<dma>,<mss_io>,<mpu_io>,<mpu_irq>
                        See also header of sound/oss/aedsp16.c.
                                    they are unmapped. Otherwise they are
                                    flushed before they will be reused, which
                                    is a lot of faster
 +                      off       - do not initialize any AMD IOMMU found in
 +                                  the system
  
        amijoy.map=     [HW,JOY] Amiga joystick support
                        Map of devices attached to JOY0DAT and JOY1DAT
                        The VGA output is eventually overwritten by the real
                        console.
  
 +      ekgdboc=        [X86,KGDB] Allow early kernel console debugging
 +                      ekgdboc=kbd
 +
 +                      This is desgined to be used in conjunction with
 +                      the boot argument: earlyprintk=vga
 +
        eata=           [HW,SCSI]
  
        edd=            [EDD]
                        Default value is 0.
                        Value can be changed at runtime via /selinux/enforce.
  
+       erst_disable    [ACPI]
+                       Disable Error Record Serialization Table (ERST)
+                       support.
        ether=          [HW,NET] Ethernet cards parameters
                        This option is obsoleted by the "netdev=" option, which
                        has equivalent usage. See its documentation for details.
  
 -      eurwdt=         [HW,WDT] Eurotech CPU-1220/1410 onboard watchdog.
 -                      Format: <io>[,<irq>]
 -
        failslab=
        fail_page_alloc=
        fail_make_request=[KNL]
                        as early as possible in order to facilitate early
                        boot debugging.
  
 -      ftrace_dump_on_oops
 +      ftrace_dump_on_oops[=orig_cpu]
                        [FTRACE] will dump the trace buffers on oops.
 +                      If no parameter is passed, ftrace will dump
 +                      buffers of all CPUs, but if you pass orig_cpu, it will
 +                      dump only the buffer of the CPU that triggered the
 +                      oops.
  
        ftrace_filter=[function-list]
                        [FTRACE] Limit the functions traced by the function
        hd=             [EIDE] (E)IDE hard drive subsystem geometry
                        Format: <cyl>,<head>,<sect>
  
+       hest_disable    [ACPI]
+                       Disable Hardware Error Source Table (HEST) support;
+                       corresponding firmware-first mode error processing
+                       logic will be disabled.
        highmem=nn[KMG] [KNL,BOOT] forces the highmem zone to have an exact
                        size of <nn>. This works even on boxes that have no
                        highmem otherwise. This also works to reduce highmem
                        use the HighMem zone if it exists, and the Normal
                        zone if it does not.
  
 -      kgdboc=         [HW] kgdb over consoles.
 -                      Requires a tty driver that supports console polling.
 -                      (only serial supported for now)
 -                      Format: <serial_device>[,baud]
 +      kgdbdbgp=       [KGDB,HW] kgdb over EHCI usb debug port.
 +                      Format: <Controller#>[,poll interval]
 +                      The controller # is the number of the ehci usb debug
 +                      port as it is probed via PCI.  The poll interval is
 +                      optional and is the number seconds in between
 +                      each poll cycle to the debug port in case you need
 +                      the functionality for interrupting the kernel with
 +                      gdb or control-c on the dbgp connection.  When
 +                      not using this parameter you use sysrq-g to break into
 +                      the kernel debugger.
 +
 +      kgdboc=         [KGDB,HW] kgdb over consoles.
 +                      Requires a tty driver that supports console polling,
 +                      or a supported polling keyboard driver (non-usb).
 +                      Serial only format: <serial_device>[,baud]
 +                      keyboard only format: kbd
 +                      keyboard and serial format: kbd,<serial_device>[,baud]
 +
 +      kgdbwait        [KGDB] Stop kernel execution and enter the
 +                      kernel debugger at the earliest opportunity.
  
        kmac=           [MIPS] korina ethernet MAC address.
                        Configure the RouterBoard 532 series on-chip
                        * nohrst, nosrst, norst: suppress hard, soft
                            and both resets.
  
 +                      * dump_id: dump IDENTIFY data.
 +
                        If there are multiple matching configurations changing
                        the same attribute, the last one is used.
  
  
        sched_debug     [KNL] Enables verbose scheduler debug messages.
  
 -      sc1200wdt=      [HW,WDT] SC1200 WDT (watchdog) driver
 -                      Format: <io>[,<timeout>[,<isapnp>]]
 -
        scsi_debug_*=   [SCSI]
                        See drivers/scsi/scsi_debug.c.
  
  
        tp720=          [HW,PS2]
  
 +      tpm_suspend_pcr=[HW,TPM]
 +                      Format: integer pcr id
 +                      Specify that at suspend time, the tpm driver
 +                      should extend the specified pcr with zeros,
 +                      as a workaround for some chips which fail to
 +                      flush the last written pcr on TPM_SaveState.
 +                      This will guarantee that all the other pcrs
 +                      are saved.
 +
        trace_buf_size=nn[KMG]
                        [FTRACE] will set tracing buffer size.
  
        wd7000=         [HW,SCSI]
                        See header of drivers/scsi/wd7000.c.
  
 -      wdt=            [WDT] Watchdog
 -                      See Documentation/watchdog/wdt.txt.
 +      watchdog timers [HW,WDT] For information on watchdog timers,
 +                      see Documentation/watchdog/watchdog-parameters.txt
 +                      or other driver-specific files in the
 +                      Documentation/watchdog/ directory.
  
        x2apic_phys     [X86-64,APIC] Use x2apic physical mode instead of
                        default x2apic cluster mode on platforms
@@@ -63,7 -63,6 +63,6 @@@ EXPORT_SYMBOL(acpi_disabled)
  int acpi_noirq;                               /* skip ACPI IRQ initialization */
  int acpi_pci_disabled;                /* skip ACPI PCI scan and IRQ initialization */
  EXPORT_SYMBOL(acpi_pci_disabled);
- int acpi_ht __initdata = 1;   /* enable HT */
  
  int acpi_lapic;
  int acpi_ioapic;
@@@ -94,53 -93,6 +93,53 @@@ enum acpi_irq_model_id acpi_irq_model 
  
  
  /*
 + * ISA irqs by default are the first 16 gsis but can be
 + * any gsi as specified by an interrupt source override.
 + */
 +static u32 isa_irq_to_gsi[NR_IRQS_LEGACY] __read_mostly = {
 +      0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
 +};
 +
 +static unsigned int gsi_to_irq(unsigned int gsi)
 +{
 +      unsigned int irq = gsi + NR_IRQS_LEGACY;
 +      unsigned int i;
 +
 +      for (i = 0; i < NR_IRQS_LEGACY; i++) {
 +              if (isa_irq_to_gsi[i] == gsi) {
 +                      return i;
 +              }
 +      }
 +
 +      /* Provide an identity mapping of gsi == irq
 +       * except on truly weird platforms that have
 +       * non isa irqs in the first 16 gsis.
 +       */
 +      if (gsi >= NR_IRQS_LEGACY)
 +              irq = gsi;
 +      else
 +              irq = gsi_end + 1 + gsi;
 +
 +      return irq;
 +}
 +
 +static u32 irq_to_gsi(int irq)
 +{
 +      unsigned int gsi;
 +
 +      if (irq < NR_IRQS_LEGACY)
 +              gsi = isa_irq_to_gsi[irq];
 +      else if (irq <= gsi_end)
 +              gsi = irq;
 +      else if (irq <= (gsi_end + NR_IRQS_LEGACY))
 +              gsi = irq - gsi_end;
 +      else
 +              gsi = 0xffffffff;
 +
 +      return gsi;
 +}
 +
 +/*
   * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
   * to map the target physical address. The problem is that set_fixmap()
   * provides a single page, and it is possible that the page is not
@@@ -360,7 -312,7 +359,7 @@@ acpi_parse_ioapic(struct acpi_subtable_
  /*
   * Parse Interrupt Source Override for the ACPI SCI
   */
 -static void __init acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
 +static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger, u32 gsi)
  {
        if (trigger == 0)       /* compatible SCI trigger is level */
                trigger = 3;
         * If GSI is < 16, this will update its flags,
         * else it will create a new mp_irqs[] entry.
         */
 -      mp_override_legacy_irq(gsi, polarity, trigger, gsi);
 +      mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
  
        /*
         * stash over-ride to indicate we've been here
@@@ -404,10 -356,9 +403,10 @@@ acpi_parse_int_src_ovr(struct acpi_subt
        acpi_table_print_madt_entry(header);
  
        if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
 -              acpi_sci_ioapic_setup(intsrc->global_irq,
 +              acpi_sci_ioapic_setup(intsrc->source_irq,
                                      intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
 -                                    (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
 +                                    (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
 +                                    intsrc->global_irq);
                return 0;
        }
  
@@@ -496,7 -447,7 +495,7 @@@ void __init acpi_pic_sci_set_trigger(un
  
  int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
  {
 -      *irq = gsi;
 +      *irq = gsi_to_irq(gsi);
  
  #ifdef CONFIG_X86_IO_APIC
        if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
        return 0;
  }
  
 +int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi)
 +{
 +      if (isa_irq >= 16)
 +              return -1;
 +      *gsi = irq_to_gsi(isa_irq);
 +      return 0;
 +}
 +
  /*
   * success: return IRQ number (>=0)
   * failure: return < 0
@@@ -538,7 -481,7 +537,7 @@@ int acpi_register_gsi(struct device *de
                plat_gsi = mp_register_gsi(dev, gsi, trigger, polarity);
        }
  #endif
 -      irq = plat_gsi;
 +      irq = gsi_to_irq(plat_gsi);
  
        return irq;
  }
@@@ -923,6 -866,29 +922,6 @@@ static int __init acpi_parse_madt_lapic
  extern int es7000_plat;
  #endif
  
 -int __init acpi_probe_gsi(void)
 -{
 -      int idx;
 -      int gsi;
 -      int max_gsi = 0;
 -
 -      if (acpi_disabled)
 -              return 0;
 -
 -      if (!acpi_ioapic)
 -              return 0;
 -
 -      max_gsi = 0;
 -      for (idx = 0; idx < nr_ioapics; idx++) {
 -              gsi = mp_gsi_routing[idx].gsi_end;
 -
 -              if (gsi > max_gsi)
 -                      max_gsi = gsi;
 -      }
 -
 -      return max_gsi + 1;
 -}
 -
  static void assign_to_mp_irq(struct mpc_intsrc *m,
                                    struct mpc_intsrc *mp_irq)
  {
@@@ -980,13 -946,13 +979,13 @@@ void __init mp_override_legacy_irq(u8 b
        mp_irq.dstirq = pin;    /* INTIN# */
  
        save_mp_irq(&mp_irq);
 +
 +      isa_irq_to_gsi[bus_irq] = gsi;
  }
  
  void __init mp_config_acpi_legacy_irqs(void)
  {
        int i;
 -      int ioapic;
 -      unsigned int dstapic;
        struct mpc_intsrc mp_irq;
  
  #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
  #endif
  
        /*
 -       * Locate the IOAPIC that manages the ISA IRQs (0-15).
 -       */
 -      ioapic = mp_find_ioapic(0);
 -      if (ioapic < 0)
 -              return;
 -      dstapic = mp_ioapics[ioapic].apicid;
 -
 -      /*
         * Use the default configuration for the IRQs 0-15.  Unless
         * overridden by (MADT) interrupt source override entries.
         */
        for (i = 0; i < 16; i++) {
 +              int ioapic, pin;
 +              unsigned int dstapic;
                int idx;
 +              u32 gsi;
 +
 +              /* Locate the gsi that irq i maps to. */
 +              if (acpi_isa_irq_to_gsi(i, &gsi))
 +                      continue;
 +
 +              /*
 +               * Locate the IOAPIC that manages the ISA IRQ.
 +               */
 +              ioapic = mp_find_ioapic(gsi);
 +              if (ioapic < 0)
 +                      continue;
 +              pin = mp_find_ioapic_pin(ioapic, gsi);
 +              dstapic = mp_ioapics[ioapic].apicid;
  
                for (idx = 0; idx < mp_irq_entries; idx++) {
                        struct mpc_intsrc *irq = mp_irqs + idx;
                                break;
  
                        /* Do we already have a mapping for this IOAPIC pin */
 -                      if (irq->dstapic == dstapic && irq->dstirq == i)
 +                      if (irq->dstapic == dstapic && irq->dstirq == pin)
                                break;
                }
  
                mp_irq.dstapic = dstapic;
                mp_irq.irqtype = mp_INT;
                mp_irq.srcbusirq = i; /* Identity mapped */
 -              mp_irq.dstirq = i;
 +              mp_irq.dstirq = pin;
  
                save_mp_irq(&mp_irq);
        }
@@@ -1117,6 -1075,11 +1116,6 @@@ int mp_register_gsi(struct device *dev
  
        ioapic_pin = mp_find_ioapic_pin(ioapic, gsi);
  
 -#ifdef CONFIG_X86_32
 -      if (ioapic_renumber_irq)
 -              gsi = ioapic_renumber_irq(ioapic, gsi);
 -#endif
 -
        if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
                printk(KERN_ERR "Invalid reference to IOAPIC pin "
                       "%d-%d\n", mp_ioapics[ioapic].apicid,
        set_io_apic_irq_attr(&irq_attr, ioapic, ioapic_pin,
                             trigger == ACPI_EDGE_SENSITIVE ? 0 : 1,
                             polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
 -      io_apic_set_pci_routing(dev, gsi, &irq_attr);
 +      io_apic_set_pci_routing(dev, gsi_to_irq(gsi), &irq_attr);
  
        return gsi;
  }
@@@ -1190,8 -1153,7 +1189,8 @@@ static int __init acpi_parse_madt_ioapi
         * pretend we got one so we can set the SCI flags.
         */
        if (!acpi_sci_override_gsi)
 -              acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0);
 +              acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0,
 +                                    acpi_gbl_FADT.sci_interrupt);
  
        /* Fill in identity legacy mappings where no override */
        mp_config_acpi_legacy_irqs();
@@@ -1501,9 -1463,8 +1500,8 @@@ void __init acpi_boot_table_init(void
  
        /*
         * If acpi_disabled, bail out
-        * One exception: acpi=ht continues far enough to enumerate LAPICs
         */
-       if (acpi_disabled && !acpi_ht)
+       if (acpi_disabled)
                return; 
  
        /*
@@@ -1534,9 -1495,8 +1532,8 @@@ int __init early_acpi_boot_init(void
  {
        /*
         * If acpi_disabled, bail out
-        * One exception: acpi=ht continues far enough to enumerate LAPICs
         */
-       if (acpi_disabled && !acpi_ht)
+       if (acpi_disabled)
                return 1;
  
        /*
@@@ -1554,9 -1514,8 +1551,8 @@@ int __init acpi_boot_init(void
  
        /*
         * If acpi_disabled, bail out
-        * One exception: acpi=ht continues far enough to enumerate LAPICs
         */
-       if (acpi_disabled && !acpi_ht)
+       if (acpi_disabled)
                return 1;
  
        acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
@@@ -1591,21 -1550,12 +1587,12 @@@ static int __init parse_acpi(char *arg
        /* acpi=force to over-ride black-list */
        else if (strcmp(arg, "force") == 0) {
                acpi_force = 1;
-               acpi_ht = 1;
                acpi_disabled = 0;
        }
        /* acpi=strict disables out-of-spec workarounds */
        else if (strcmp(arg, "strict") == 0) {
                acpi_strict = 1;
        }
-       /* Limit ACPI just to boot-time to enable HT */
-       else if (strcmp(arg, "ht") == 0) {
-               if (!acpi_force) {
-                       printk(KERN_WARNING "acpi=ht will be removed in Linux-2.6.35\n");
-                       disable_acpi();
-               }
-               acpi_ht = 1;
-       }
        /* acpi=rsdt use RSDT instead of XSDT */
        else if (strcmp(arg, "rsdt") == 0) {
                acpi_rsdt_forced = 1;
        /* "acpi=noirq" disables ACPI interrupt routing */
        else if (strcmp(arg, "noirq") == 0) {
                acpi_noirq_set();
 +      }
 +      /* "acpi=copy_dsdt" copys DSDT */
 +      else if (strcmp(arg, "copy_dsdt") == 0) {
 +              acpi_gbl_copy_dsdt_locally = 1;
        } else {
                /* Core will printk when we return error. */
                return -EINVAL;
@@@ -264,7 -264,7 +264,7 @@@ static void wait_for_panic(void
  
  static void mce_panic(char *msg, struct mce *final, char *exp)
  {
-       int i;
+       int i, apei_err = 0;
  
        if (!fake_panic) {
                /*
                struct mce *m = &mcelog.entry[i];
                if (!(m->status & MCI_STATUS_VAL))
                        continue;
-               if (!(m->status & MCI_STATUS_UC))
+               if (!(m->status & MCI_STATUS_UC)) {
                        print_mce(m);
+                       if (!apei_err)
+                               apei_err = apei_write_mce(m);
+               }
        }
        /* Now print uncorrected but with the final one last */
        for (i = 0; i < MCE_LOG_LEN; i++) {
                        continue;
                if (!(m->status & MCI_STATUS_UC))
                        continue;
-               if (!final || memcmp(m, final, sizeof(struct mce)))
+               if (!final || memcmp(m, final, sizeof(struct mce))) {
                        print_mce(m);
+                       if (!apei_err)
+                               apei_err = apei_write_mce(m);
+               }
        }
-       if (final)
+       if (final) {
                print_mce(final);
+               if (!apei_err)
+                       apei_err = apei_write_mce(final);
+       }
        if (cpu_missing)
                printk(KERN_EMERG "Some CPUs didn't answer in synchronization\n");
        print_mce_tail();
@@@ -539,7 -548,7 +548,7 @@@ void machine_check_poll(enum mcp_flags 
        struct mce m;
        int i;
  
 -      __get_cpu_var(mce_poll_count)++;
 +      percpu_inc(mce_poll_count);
  
        mce_setup(&m);
  
@@@ -934,7 -943,7 +943,7 @@@ void do_machine_check(struct pt_regs *r
  
        atomic_inc(&mce_entry);
  
 -      __get_cpu_var(mce_exception_count)++;
 +      percpu_inc(mce_exception_count);
  
        if (notify_die(DIE_NMI, "machine check", regs, error_code,
                           18, SIGKILL) == NOTIFY_STOP)
@@@ -1493,6 -1502,43 +1502,43 @@@ static void collect_tscs(void *data
        rdtscll(cpu_tsc[smp_processor_id()]);
  }
  
+ static int mce_apei_read_done;
+ /* Collect MCE record of previous boot in persistent storage via APEI ERST. */
+ static int __mce_read_apei(char __user **ubuf, size_t usize)
+ {
+       int rc;
+       u64 record_id;
+       struct mce m;
+       if (usize < sizeof(struct mce))
+               return -EINVAL;
+       rc = apei_read_mce(&m, &record_id);
+       /* Error or no more MCE record */
+       if (rc <= 0) {
+               mce_apei_read_done = 1;
+               return rc;
+       }
+       rc = -EFAULT;
+       if (copy_to_user(*ubuf, &m, sizeof(struct mce)))
+               return rc;
+       /*
+        * In fact, we should have cleared the record after that has
+        * been flushed to the disk or sent to network in
+        * /sbin/mcelog, but we have no interface to support that now,
+        * so just clear it to avoid duplication.
+        */
+       rc = apei_clear_mce(record_id);
+       if (rc) {
+               mce_apei_read_done = 1;
+               return rc;
+       }
+       *ubuf += sizeof(struct mce);
+       return 0;
+ }
  static ssize_t mce_read(struct file *filp, char __user *ubuf, size_t usize,
                        loff_t *off)
  {
                return -ENOMEM;
  
        mutex_lock(&mce_read_mutex);
+       if (!mce_apei_read_done) {
+               err = __mce_read_apei(&buf, usize);
+               if (err || buf != ubuf)
+                       goto out;
+       }
        next = rcu_dereference_check_mce(mcelog.next);
  
        /* Only supports full reads right now */
-       if (*off != 0 || usize < MCE_LOG_LEN*sizeof(struct mce)) {
-               mutex_unlock(&mce_read_mutex);
-               kfree(cpu_tsc);
-               return -EINVAL;
-       }
+       err = -EINVAL;
+       if (*off != 0 || usize < MCE_LOG_LEN*sizeof(struct mce))
+               goto out;
  
        err = 0;
        prev = 0;
@@@ -1562,10 -1612,15 +1612,15 @@@ timeout
                        memset(&mcelog.entry[i], 0, sizeof(struct mce));
                }
        }
+       if (err)
+               err = -EFAULT;
+ out:
        mutex_unlock(&mce_read_mutex);
        kfree(cpu_tsc);
  
-       return err ? -EFAULT : buf - ubuf;
+       return err ? err : buf - ubuf;
  }
  
  static unsigned int mce_poll(struct file *file, poll_table *wait)
        poll_wait(file, &mce_wait, wait);
        if (rcu_dereference_check_mce(mcelog.next))
                return POLLIN | POLLRDNORM;
+       if (!mce_apei_read_done && apei_check_mce())
+               return POLLIN | POLLRDNORM;
        return 0;
  }
  
@@@ -69,7 -69,7 +69,7 @@@ acpi_ev_get_gpe_device(struct acpi_gpe_
  
  acpi_status acpi_enable(void)
  {
-       acpi_status status = AE_OK;
+       acpi_status status;
  
        ACPI_FUNCTION_TRACE(acpi_enable);
  
        if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
                ACPI_DEBUG_PRINT((ACPI_DB_INIT,
                                  "System is already in ACPI mode\n"));
-       } else {
-               /* Transition to ACPI mode */
+               return_ACPI_STATUS(AE_OK);
+       }
  
-               status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
-               if (ACPI_FAILURE(status)) {
-                       ACPI_ERROR((AE_INFO,
-                                   "Could not transition to ACPI mode"));
-                       return_ACPI_STATUS(status);
-               }
+       /* Transition to ACPI mode */
  
-               ACPI_DEBUG_PRINT((ACPI_DB_INIT,
-                                 "Transition to ACPI mode successful\n"));
+       status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
+       if (ACPI_FAILURE(status)) {
+               ACPI_ERROR((AE_INFO,
+                           "Could not transition to ACPI mode"));
+               return_ACPI_STATUS(status);
+       }
+       /* Sanity check that transition succeeded */
+       if (acpi_hw_get_mode() != ACPI_SYS_MODE_ACPI) {
+               ACPI_ERROR((AE_INFO,
+                           "Hardware did not enter ACPI mode"));
+               return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
        }
  
-       return_ACPI_STATUS(status);
+       ACPI_DEBUG_PRINT((ACPI_DB_INIT,
+                         "Transition to ACPI mode successful\n"));
+       return_ACPI_STATUS(AE_OK);
  }
  
  ACPI_EXPORT_SYMBOL(acpi_enable)
@@@ -203,26 -212,21 +212,26 @@@ ACPI_EXPORT_SYMBOL(acpi_enable_event
   *
   * FUNCTION:    acpi_set_gpe
   *
 - * PARAMETERS:  gpe_device      - Parent GPE Device
 + * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
   *              gpe_number      - GPE level within the GPE block
 - *              action          - Enable or disable
 - *                                Called from ISR or not
 + *              action          - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
   *
   * RETURN:      Status
   *
 - * DESCRIPTION: Enable or disable an ACPI event (general purpose)
 + * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
 + *              the reference count mechanism used in the acpi_enable_gpe and
 + *              acpi_disable_gpe interfaces -- and should be used with care.
 + *
 + * Note: Typically used to disable a runtime GPE for short period of time,
 + * then re-enable it, without disturbing the existing reference counts. This
 + * is useful, for example, in the Embedded Controller (EC) driver.
   *
   ******************************************************************************/
  acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
  {
 -      acpi_status status = AE_OK;
 -      acpi_cpu_flags flags;
        struct acpi_gpe_event_info *gpe_event_info;
 +      acpi_status status;
 +      acpi_cpu_flags flags;
  
        ACPI_FUNCTION_TRACE(acpi_set_gpe);
  
                break;
  
        default:
 -              ACPI_ERROR((AE_INFO, "Invalid action\n"));
                status = AE_BAD_PARAMETER;
                break;
        }
@@@ -263,31 -268,25 +272,31 @@@ ACPI_EXPORT_SYMBOL(acpi_set_gpe
   *
   * FUNCTION:    acpi_enable_gpe
   *
 - * PARAMETERS:  gpe_device      - Parent GPE Device
 + * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
   *              gpe_number      - GPE level within the GPE block
 - *              type            - Purpose the GPE will be used for
 + *              gpe_type        - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
 + *                                or both
   *
   * RETURN:      Status
   *
 - * DESCRIPTION: Take a reference to a GPE and enable it if necessary
 + * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
 + *              hardware-enabled (for runtime GPEs), or the GPE register mask
 + *              is updated (for wake GPEs).
   *
   ******************************************************************************/
 -acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type)
 +acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
  {
        acpi_status status = AE_OK;
 -      acpi_cpu_flags flags;
        struct acpi_gpe_event_info *gpe_event_info;
 +      acpi_cpu_flags flags;
  
        ACPI_FUNCTION_TRACE(acpi_enable_gpe);
  
 -      if (type & ~ACPI_GPE_TYPE_WAKE_RUN)
 +      /* Parameter validation */
 +
 +      if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
                return_ACPI_STATUS(AE_BAD_PARAMETER);
 +      }
  
        flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  
                goto unlock_and_exit;
        }
  
 -      if (type & ACPI_GPE_TYPE_RUNTIME) {
 -              if (++gpe_event_info->runtime_count == 1) {
 +      if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
 +              if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
 +                      status = AE_LIMIT;      /* Too many references */
 +                      goto unlock_and_exit;
 +              }
 +
 +              gpe_event_info->runtime_count++;
 +              if (gpe_event_info->runtime_count == 1) {
                        status = acpi_ev_enable_gpe(gpe_event_info);
 -                      if (ACPI_FAILURE(status))
 +                      if (ACPI_FAILURE(status)) {
                                gpe_event_info->runtime_count--;
 +                              goto unlock_and_exit;
 +                      }
                }
        }
  
 -      if (type & ACPI_GPE_TYPE_WAKE) {
 +      if (gpe_type & ACPI_GPE_TYPE_WAKE) {
 +              /* The GPE must have the ability to wake the system */
 +
                if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
 -                      status = AE_BAD_PARAMETER;
 +                      status = AE_TYPE;
 +                      goto unlock_and_exit;
 +              }
 +
 +              if (gpe_event_info->wakeup_count == ACPI_UINT8_MAX) {
 +                      status = AE_LIMIT;      /* Too many references */
                        goto unlock_and_exit;
                }
  
                /*
 -               * Wake-up GPEs are only enabled right prior to putting the
 -               * system into a sleep state.
 +               * Update the enable mask on the first wakeup reference. Wake GPEs
 +               * are only hardware-enabled just before sleeping.
                 */
 -              if (++gpe_event_info->wakeup_count == 1)
 -                      acpi_ev_update_gpe_enable_masks(gpe_event_info);
 +              gpe_event_info->wakeup_count++;
 +              if (gpe_event_info->wakeup_count == 1) {
 +                      (void)acpi_ev_update_gpe_enable_masks(gpe_event_info);
 +              }
        }
  
  unlock_and_exit:
@@@ -348,34 -330,27 +357,34 @@@ ACPI_EXPORT_SYMBOL(acpi_enable_gpe
   *
   * FUNCTION:    acpi_disable_gpe
   *
 - * PARAMETERS:  gpe_device      - Parent GPE Device
 + * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
   *              gpe_number      - GPE level within the GPE block
 - *              type            - Purpose the GPE won't be used for any more
 + *              gpe_type        - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
 + *                                or both
   *
   * RETURN:      Status
   *
 - * DESCRIPTION: Release a reference to a GPE and disable it if necessary
 + * DESCRIPTION: Remove a reference to a GPE. When the last reference is
 + *              removed, only then is the GPE disabled (for runtime GPEs), or
 + *              the GPE mask bit disabled (for wake GPEs)
   *
   ******************************************************************************/
 -acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type)
 +acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
  {
        acpi_status status = AE_OK;
 -      acpi_cpu_flags flags;
        struct acpi_gpe_event_info *gpe_event_info;
 +      acpi_cpu_flags flags;
  
        ACPI_FUNCTION_TRACE(acpi_disable_gpe);
  
 -      if (type & ~ACPI_GPE_TYPE_WAKE_RUN)
 +      /* Parameter validation */
 +
 +      if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
                return_ACPI_STATUS(AE_BAD_PARAMETER);
 +      }
  
        flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
 +
        /* Ensure that we have a valid GPE number */
  
        gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
                goto unlock_and_exit;
        }
  
 -      if ((type & ACPI_GPE_TYPE_RUNTIME) && gpe_event_info->runtime_count) {
 -              if (--gpe_event_info->runtime_count == 0)
 +      /* Hardware-disable a runtime GPE on removal of the last reference */
 +
 +      if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
 +              if (!gpe_event_info->runtime_count) {
 +                      status = AE_LIMIT;      /* There are no references to remove */
 +                      goto unlock_and_exit;
 +              }
 +
 +              gpe_event_info->runtime_count--;
 +              if (!gpe_event_info->runtime_count) {
                        status = acpi_ev_disable_gpe(gpe_event_info);
 +                      if (ACPI_FAILURE(status)) {
 +                              gpe_event_info->runtime_count++;
 +                              goto unlock_and_exit;
 +                      }
 +              }
        }
  
 -      if ((type & ACPI_GPE_TYPE_WAKE) && gpe_event_info->wakeup_count) {
 -              /*
 -               * Wake-up GPEs are not enabled after leaving system sleep
 -               * states, so we don't need to disable them here.
 -               */
 -              if (--gpe_event_info->wakeup_count == 0)
 -                      acpi_ev_update_gpe_enable_masks(gpe_event_info);
 +      /*
 +       * Update masks for wake GPE on removal of the last reference.
 +       * No need to hardware-disable wake GPEs here, they are not currently
 +       * enabled.
 +       */
 +      if (gpe_type & ACPI_GPE_TYPE_WAKE) {
 +              if (!gpe_event_info->wakeup_count) {
 +                      status = AE_LIMIT;      /* There are no references to remove */
 +                      goto unlock_and_exit;
 +              }
 +
 +              gpe_event_info->wakeup_count--;
 +              if (!gpe_event_info->wakeup_count) {
 +                      (void)acpi_ev_update_gpe_enable_masks(gpe_event_info);
 +              }
        }
  
  unlock_and_exit:
@@@ -520,23 -474,30 +529,23 @@@ ACPI_EXPORT_SYMBOL(acpi_clear_event
   *
   * FUNCTION:    acpi_clear_gpe
   *
 - * PARAMETERS:  gpe_device      - Parent GPE Device
 + * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
   *              gpe_number      - GPE level within the GPE block
 - *              Flags           - Called from an ISR or not
   *
   * RETURN:      Status
   *
   * DESCRIPTION: Clear an ACPI event (general purpose)
   *
   ******************************************************************************/
 -acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
 +acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
  {
        acpi_status status = AE_OK;
        struct acpi_gpe_event_info *gpe_event_info;
 +      acpi_cpu_flags flags;
  
        ACPI_FUNCTION_TRACE(acpi_clear_gpe);
  
 -      /* Use semaphore lock if not executing at interrupt level */
 -
 -      if (flags & ACPI_NOT_ISR) {
 -              status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
 -              if (ACPI_FAILURE(status)) {
 -                      return_ACPI_STATUS(status);
 -              }
 -      }
 +      flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  
        /* Ensure that we have a valid GPE number */
  
        status = acpi_hw_clear_gpe(gpe_event_info);
  
        unlock_and_exit:
 -      if (flags & ACPI_NOT_ISR) {
 -              (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
 -      }
 +      acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
        return_ACPI_STATUS(status);
  }
  
@@@ -615,8 -578,9 +624,8 @@@ ACPI_EXPORT_SYMBOL(acpi_get_event_statu
   *
   * FUNCTION:    acpi_get_gpe_status
   *
 - * PARAMETERS:  gpe_device      - Parent GPE Device
 + * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
   *              gpe_number      - GPE level within the GPE block
 - *              Flags           - Called from an ISR or not
   *              event_status    - Where the current status of the event will
   *                                be returned
   *
   ******************************************************************************/
  acpi_status
  acpi_get_gpe_status(acpi_handle gpe_device,
 -                  u32 gpe_number, u32 flags, acpi_event_status * event_status)
 +                  u32 gpe_number, acpi_event_status *event_status)
  {
        acpi_status status = AE_OK;
        struct acpi_gpe_event_info *gpe_event_info;
 +      acpi_cpu_flags flags;
  
        ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
  
 -      /* Use semaphore lock if not executing at interrupt level */
 -
 -      if (flags & ACPI_NOT_ISR) {
 -              status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
 -              if (ACPI_FAILURE(status)) {
 -                      return_ACPI_STATUS(status);
 -              }
 -      }
 +      flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
  
        /* Ensure that we have a valid GPE number */
  
                *event_status |= ACPI_EVENT_FLAG_HANDLE;
  
        unlock_and_exit:
 -      if (flags & ACPI_NOT_ISR) {
 -              (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
 -      }
 +      acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
        return_ACPI_STATUS(status);
  }
  
@@@ -710,15 -682,20 +719,15 @@@ acpi_install_gpe_block(acpi_handle gpe_
                goto unlock_and_exit;
        }
  
 -      /* Run the _PRW methods and enable the GPEs */
 -
 -      status = acpi_ev_initialize_gpe_block(node, gpe_block);
 -      if (ACPI_FAILURE(status)) {
 -              goto unlock_and_exit;
 -      }
 -
 -      /* Get the device_object attached to the node */
 +      /* Install block in the device_object attached to the node */
  
        obj_desc = acpi_ns_get_attached_object(node);
        if (!obj_desc) {
  
 -              /* No object, create a new one */
 -
 +              /*
 +               * No object, create a new one (Device nodes do not always have
 +               * an attached object)
 +               */
                obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
                if (!obj_desc) {
                        status = AE_NO_MEMORY;
                }
        }
  
 -      /* Install the GPE block in the device_object */
 +      /* Now install the GPE block in the device_object */
  
        obj_desc->device.gpe_block = gpe_block;
  
 +      /* Run the _PRW methods and enable the runtime GPEs in the new block */
 +
 +      status = acpi_ev_initialize_gpe_block(node, gpe_block);
 +
        unlock_and_exit:
        (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
        return_ACPI_STATUS(status);
@@@ -875,7 -848,8 +884,7 @@@ acpi_ev_get_gpe_device(struct acpi_gpe_
  
        /* Increment Index by the number of GPEs in this block */
  
 -      info->next_block_base_index +=
 -          (gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH);
 +      info->next_block_base_index += gpe_block->gpe_count;
  
        if (info->index < info->next_block_base_index) {
                /*
@@@ -698,7 -698,7 +698,7 @@@ static int acpi_processor_power_seq_sho
                   "max_cstate:              C%d\n"
                   "maximum allowed latency: %d usec\n",
                   pr->power.state ? pr->power.state - pr->power.states : 0,
 -                 max_cstate, pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY));
 +                 max_cstate, pm_qos_request(PM_QOS_CPU_DMA_LATENCY));
  
        seq_puts(seq, "states:\n");
  
                        break;
                }
  
-               if (pr->power.states[i].promotion.state)
-                       seq_printf(seq, "promotion[C%zd] ",
-                                  (pr->power.states[i].promotion.state -
-                                   pr->power.states));
-               else
-                       seq_puts(seq, "promotion[--] ");
-               if (pr->power.states[i].demotion.state)
-                       seq_printf(seq, "demotion[C%zd] ",
-                                  (pr->power.states[i].demotion.state -
-                                   pr->power.states));
-               else
-                       seq_puts(seq, "demotion[--] ");
+               seq_puts(seq, "promotion[--] ");
+               seq_puts(seq, "demotion[--] ");
  
                seq_printf(seq, "latency[%03d] usage[%08d] duration[%020llu]\n",
                           pr->power.states[i].latency,
@@@ -869,6 -859,7 +859,7 @@@ static int acpi_idle_enter_simple(struc
        struct acpi_processor *pr;
        struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
        ktime_t  kt1, kt2;
+       s64 idle_time_ns;
        s64 idle_time;
        s64 sleep_ticks = 0;
  
        sched_clock_idle_sleep_event();
        acpi_idle_do_entry(cx);
        kt2 = ktime_get_real();
-       idle_time =  ktime_to_us(ktime_sub(kt2, kt1));
+       idle_time_ns = ktime_to_ns(ktime_sub(kt2, kt1));
+       idle_time = idle_time_ns;
+       do_div(idle_time, NSEC_PER_USEC);
  
        sleep_ticks = us_to_pm_timer_ticks(idle_time);
  
        /* Tell the scheduler how much we idled: */
-       sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
+       sched_clock_idle_wakeup_event(idle_time_ns);
  
        local_irq_enable();
        current_thread_info()->status |= TS_POLLING;
@@@ -943,6 -936,7 +936,7 @@@ static int acpi_idle_enter_bm(struct cp
        struct acpi_processor *pr;
        struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
        ktime_t  kt1, kt2;
+       s64 idle_time_ns;
        s64 idle_time;
        s64 sleep_ticks = 0;
  
                spin_unlock(&c3_lock);
        }
        kt2 = ktime_get_real();
-       idle_time =  ktime_to_us(ktime_sub(kt2, kt1));
+       idle_time_ns = ktime_to_us(ktime_sub(kt2, kt1));
+       idle_time = idle_time_ns;
+       do_div(idle_time, NSEC_PER_USEC);
  
        sleep_ticks = us_to_pm_timer_ticks(idle_time);
        /* Tell the scheduler how much we idled: */
-       sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
+       sched_clock_idle_wakeup_event(idle_time_ns);
  
        local_irq_enable();
        current_thread_info()->status |= TS_POLLING;
@@@ -17,6 -17,9 +17,6 @@@
  #define AER_FATAL                     1
  #define AER_CORRECTABLE                       2
  
 -/* Root Error Status Register Bits */
 -#define ROOT_ERR_STATUS_MASKS         0x0f
 -
  #define SYSTEM_ERROR_INTR_ON_MESG_MASK        (PCI_EXP_RTCTL_SECEE|   \
                                        PCI_EXP_RTCTL_SENFEE|   \
                                        PCI_EXP_RTCTL_SEFEE)
@@@ -114,7 -117,8 +114,7 @@@ static inline pci_ers_result_t merge_re
  }
  
  extern struct bus_type pcie_port_bus_type;
 -extern void aer_enable_rootport(struct aer_rpc *rpc);
 -extern void aer_delete_rootport(struct aer_rpc *rpc);
 +extern void aer_do_secondary_bus_reset(struct pci_dev *dev);
  extern int aer_init(struct pcie_device *dev);
  extern void aer_isr(struct work_struct *work);
  extern void aer_print_error(struct pci_dev *dev, struct aer_err_info *info);
@@@ -130,4 -134,21 +130,21 @@@ static inline int aer_osc_setup(struct 
  }
  #endif
  
+ #ifdef CONFIG_ACPI_APEI
+ extern int pcie_aer_get_firmware_first(struct pci_dev *pci_dev);
+ #else
+ static inline int pcie_aer_get_firmware_first(struct pci_dev *pci_dev)
+ {
+       if (pci_dev->__aer_firmware_first_valid)
+               return pci_dev->__aer_firmware_first;
+       return 0;
+ }
+ #endif
+ static inline void pcie_aer_force_firmware_first(struct pci_dev *pci_dev,
+                                                int enable)
+ {
+       pci_dev->__aer_firmware_first = !!enable;
+       pci_dev->__aer_firmware_first_valid = 1;
+ }
  #endif /* _AERDRV_H_ */
@@@ -36,7 -36,7 +36,7 @@@ int pci_enable_pcie_error_reporting(str
        u16 reg16 = 0;
        int pos;
  
-       if (dev->aer_firmware_first)
+       if (pcie_aer_get_firmware_first(dev))
                return -EIO;
  
        pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
        if (!pos)
                return -EIO;
  
 -      pci_read_config_word(dev, pos+PCI_EXP_DEVCTL, &reg16);
 -      reg16 = reg16 |
 -              PCI_EXP_DEVCTL_CERE |
 +      pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &reg16);
 +      reg16 |= (PCI_EXP_DEVCTL_CERE |
                PCI_EXP_DEVCTL_NFERE |
                PCI_EXP_DEVCTL_FERE |
 -              PCI_EXP_DEVCTL_URRE;
 -      pci_write_config_word(dev, pos+PCI_EXP_DEVCTL, reg16);
 +              PCI_EXP_DEVCTL_URRE);
 +      pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, reg16);
  
        return 0;
  }
@@@ -63,19 -64,19 +63,19 @@@ int pci_disable_pcie_error_reporting(st
        u16 reg16 = 0;
        int pos;
  
-       if (dev->aer_firmware_first)
+       if (pcie_aer_get_firmware_first(dev))
                return -EIO;
  
        pos = pci_pcie_cap(dev);
        if (!pos)
                return -EIO;
  
 -      pci_read_config_word(dev, pos+PCI_EXP_DEVCTL, &reg16);
 -      reg16 = reg16 & ~(PCI_EXP_DEVCTL_CERE |
 -                      PCI_EXP_DEVCTL_NFERE |
 -                      PCI_EXP_DEVCTL_FERE |
 -                      PCI_EXP_DEVCTL_URRE);
 -      pci_write_config_word(dev, pos+PCI_EXP_DEVCTL, reg16);
 +      pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &reg16);
 +      reg16 &= ~(PCI_EXP_DEVCTL_CERE |
 +              PCI_EXP_DEVCTL_NFERE |
 +              PCI_EXP_DEVCTL_FERE |
 +              PCI_EXP_DEVCTL_URRE);
 +      pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, reg16);
  
        return 0;
  }
@@@ -98,46 -99,99 +98,46 @@@ int pci_cleanup_aer_uncorrect_error_sta
  }
  EXPORT_SYMBOL_GPL(pci_cleanup_aer_uncorrect_error_status);
  
 -static int set_device_error_reporting(struct pci_dev *dev, void *data)
 -{
 -      bool enable = *((bool *)data);
 -
 -      if ((dev->pcie_type == PCI_EXP_TYPE_ROOT_PORT) ||
 -          (dev->pcie_type == PCI_EXP_TYPE_UPSTREAM) ||
 -          (dev->pcie_type == PCI_EXP_TYPE_DOWNSTREAM)) {
 -              if (enable)
 -                      pci_enable_pcie_error_reporting(dev);
 -              else
 -                      pci_disable_pcie_error_reporting(dev);
 -      }
 -
 -      if (enable)
 -              pcie_set_ecrc_checking(dev);
 -
 -      return 0;
 -}
 -
  /**
 - * set_downstream_devices_error_reporting - enable/disable the error reporting  bits on the root port and its downstream ports.
 - * @dev: pointer to root port's pci_dev data structure
 - * @enable: true = enable error reporting, false = disable error reporting.
 + * add_error_device - list device to be handled
 + * @e_info: pointer to error info
 + * @dev: pointer to pci_dev to be added
   */
 -static void set_downstream_devices_error_reporting(struct pci_dev *dev,
 -                                                 bool enable)
 -{
 -      set_device_error_reporting(dev, &enable);
 -
 -      if (!dev->subordinate)
 -              return;
 -      pci_walk_bus(dev->subordinate, set_device_error_reporting, &enable);
 -}
 -
 -static inline int compare_device_id(struct pci_dev *dev,
 -                      struct aer_err_info *e_info)
 -{
 -      if (e_info->id == ((dev->bus->number << 8) | dev->devfn)) {
 -              /*
 -               * Device ID match
 -               */
 -              return 1;
 -      }
 -
 -      return 0;
 -}
 -
  static int add_error_device(struct aer_err_info *e_info, struct pci_dev *dev)
  {
        if (e_info->error_dev_num < AER_MAX_MULTI_ERR_DEVICES) {
                e_info->dev[e_info->error_dev_num] = dev;
                e_info->error_dev_num++;
 -              return 1;
 +              return 0;
        }
 -
 -      return 0;
 +      return -ENOSPC;
  }
  
 -
  #define       PCI_BUS(x)      (((x) >> 8) & 0xff)
  
 -static int find_device_iter(struct pci_dev *dev, void *data)
 +/**
 + * is_error_source - check whether the device is source of reported error
 + * @dev: pointer to pci_dev to be checked
 + * @e_info: pointer to reported error info
 + */
 +static bool is_error_source(struct pci_dev *dev, struct aer_err_info *e_info)
  {
        int pos;
 -      u32 status;
 -      u32 mask;
 +      u32 status, mask;
        u16 reg16;
 -      int result;
 -      struct aer_err_info *e_info = (struct aer_err_info *)data;
  
        /*
         * When bus id is equal to 0, it might be a bad id
         * reported by root port.
         */
        if (!nosourceid && (PCI_BUS(e_info->id) != 0)) {
 -              result = compare_device_id(dev, e_info);
 -              if (result)
 -                      add_error_device(e_info, dev);
 +              /* Device ID match? */
 +              if (e_info->id == ((dev->bus->number << 8) | dev->devfn))
 +                      return true;
  
 -              /*
 -               * If there is no multiple error, we stop
 -               * or continue based on the id comparing.
 -               */
 +              /* Continue id comparing if there is no multiple error */
                if (!e_info->multi_error_valid)
 -                      return result;
 -
 -              /*
 -               * If there are multiple errors and id does match,
 -               * We need continue to search other devices under
 -               * the root port. Return 0 means that.
 -               */
 -              if (result)
 -                      return 0;
 +                      return false;
        }
  
        /*
         *      2) bus id is equal to 0. Some ports might lose the bus
         *              id of error source id;
         *      3) There are multiple errors and prior id comparing fails;
 -       * We check AER status registers to find the initial reporter.
 +       * We check AER status registers to find possible reporter.
         */
        if (atomic_read(&dev->enable_cnt) == 0)
 -              return 0;
 +              return false;
        pos = pci_pcie_cap(dev);
        if (!pos)
 -              return 0;
 +              return false;
 +
        /* Check if AER is enabled */
 -      pci_read_config_word(dev, pos+PCI_EXP_DEVCTL, &reg16);
 +      pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &reg16);
        if (!(reg16 & (
                PCI_EXP_DEVCTL_CERE |
                PCI_EXP_DEVCTL_NFERE |
                PCI_EXP_DEVCTL_FERE |
                PCI_EXP_DEVCTL_URRE)))
 -              return 0;
 +              return false;
        pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
        if (!pos)
 -              return 0;
 +              return false;
  
 -      status = 0;
 -      mask = 0;
 +      /* Check if error is recorded */
        if (e_info->severity == AER_CORRECTABLE) {
                pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, &status);
                pci_read_config_dword(dev, pos + PCI_ERR_COR_MASK, &mask);
        } else {
                pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
                pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, &mask);
 -              if (status & ~mask) {
 -                      add_error_device(e_info, dev);
 -                      goto added;
 -              }
        }
 +      if (status & ~mask)
 +              return true;
  
 -      return 0;
 +      return false;
 +}
  
 -added:
 -      if (e_info->multi_error_valid)
 -              return 0;
 -      else
 -              return 1;
 +static int find_device_iter(struct pci_dev *dev, void *data)
 +{
 +      struct aer_err_info *e_info = (struct aer_err_info *)data;
 +
 +      if (is_error_source(dev, e_info)) {
 +              /* List this device */
 +              if (add_error_device(e_info, dev)) {
 +                      /* We cannot handle more... Stop iteration */
 +                      /* TODO: Should print error message here? */
 +                      return 1;
 +              }
 +
 +              /* If there is only a single error, stop iteration */
 +              if (!e_info->multi_error_valid)
 +                      return 1;
 +      }
 +      return 0;
  }
  
  /**
   * find_source_device - search through device hierarchy for source device
   * @parent: pointer to Root Port pci_dev data structure
 - * @err_info: including detailed error information such like id
 + * @e_info: including detailed error information such like id
   *
 - * Invoked when error is detected at the Root Port.
 + * Return true if found.
 + *
 + * Invoked by DPC when error is detected at the Root Port.
 + * Caller of this function must set id, severity, and multi_error_valid of
 + * struct aer_err_info pointed by @e_info properly.  This function must fill
 + * e_info->error_dev_num and e_info->dev[], based on the given information.
   */
 -static void find_source_device(struct pci_dev *parent,
 +static bool find_source_device(struct pci_dev *parent,
                struct aer_err_info *e_info)
  {
        struct pci_dev *dev = parent;
        int result;
  
 +      /* Must reset in this function */
 +      e_info->error_dev_num = 0;
 +
        /* Is Root Port an agent that sends error message? */
        result = find_device_iter(dev, e_info);
        if (result)
 -              return;
 +              return true;
  
        pci_walk_bus(parent->subordinate, find_device_iter, e_info);
 +
 +      if (!e_info->error_dev_num) {
 +              dev_printk(KERN_DEBUG, &parent->dev,
 +                              "can't find device of ID%04x\n",
 +                              e_info->id);
 +              return false;
 +      }
 +      return true;
  }
  
  static int report_error_detected(struct pci_dev *dev, void *data)
@@@ -372,77 -403,43 +372,77 @@@ static pci_ers_result_t broadcast_error
        return result_data.result;
  }
  
 -struct find_aer_service_data {
 -      struct pcie_port_service_driver *aer_driver;
 -      int is_downstream;
 -};
 -
 -static int find_aer_service_iter(struct device *device, void *data)
 +/**
 + * aer_do_secondary_bus_reset - perform secondary bus reset
 + * @dev: pointer to bridge's pci_dev data structure
 + *
 + * Invoked when performing link reset at Root Port or Downstream Port.
 + */
 +void aer_do_secondary_bus_reset(struct pci_dev *dev)
  {
 -      struct device_driver *driver;
 -      struct pcie_port_service_driver *service_driver;
 -      struct find_aer_service_data *result;
 +      u16 p2p_ctrl;
 +
 +      /* Assert Secondary Bus Reset */
 +      pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &p2p_ctrl);
 +      p2p_ctrl |= PCI_BRIDGE_CTL_BUS_RESET;
 +      pci_write_config_word(dev, PCI_BRIDGE_CONTROL, p2p_ctrl);
 +
 +      /*
 +       * we should send hot reset message for 2ms to allow it time to
 +       * propagate to all downstream ports
 +       */
 +      msleep(2);
 +
 +      /* De-assert Secondary Bus Reset */
 +      p2p_ctrl &= ~PCI_BRIDGE_CTL_BUS_RESET;
 +      pci_write_config_word(dev, PCI_BRIDGE_CONTROL, p2p_ctrl);
 +
 +      /*
 +       * System software must wait for at least 100ms from the end
 +       * of a reset of one or more device before it is permitted
 +       * to issue Configuration Requests to those devices.
 +       */
 +      msleep(200);
 +}
  
 -      result = (struct find_aer_service_data *) data;
 +/**
 + * default_downstream_reset_link - default reset function for Downstream Port
 + * @dev: pointer to downstream port's pci_dev data structure
 + *
 + * Invoked when performing link reset at Downstream Port w/ no aer driver.
 + */
 +static pci_ers_result_t default_downstream_reset_link(struct pci_dev *dev)
 +{
 +      aer_do_secondary_bus_reset(dev);
 +      dev_printk(KERN_DEBUG, &dev->dev,
 +              "Downstream Port link has been reset\n");
 +      return PCI_ERS_RESULT_RECOVERED;
 +}
  
 -      if (device->bus == &pcie_port_bus_type) {
 -              struct pcie_device *pcie = to_pcie_device(device);
 +static int find_aer_service_iter(struct device *device, void *data)
 +{
 +      struct pcie_port_service_driver *service_driver, **drv;
  
 -              if (pcie->port->pcie_type == PCI_EXP_TYPE_DOWNSTREAM)
 -                      result->is_downstream = 1;
 +      drv = (struct pcie_port_service_driver **) data;
  
 -              driver = device->driver;
 -              if (driver) {
 -                      service_driver = to_service_driver(driver);
 -                      if (service_driver->service == PCIE_PORT_SERVICE_AER) {
 -                              result->aer_driver = service_driver;
 -                              return 1;
 -                      }
 +      if (device->bus == &pcie_port_bus_type && device->driver) {
 +              service_driver = to_service_driver(device->driver);
 +              if (service_driver->service == PCIE_PORT_SERVICE_AER) {
 +                      *drv = service_driver;
 +                      return 1;
                }
        }
  
        return 0;
  }
  
 -static void find_aer_service(struct pci_dev *dev,
 -              struct find_aer_service_data *data)
 +static struct pcie_port_service_driver *find_aer_service(struct pci_dev *dev)
  {
 -      int retval;
 -      retval = device_for_each_child(&dev->dev, data, find_aer_service_iter);
 +      struct pcie_port_service_driver *drv = NULL;
 +
 +      device_for_each_child(&dev->dev, &drv, find_aer_service_iter);
 +
 +      return drv;
  }
  
  static pci_ers_result_t reset_link(struct pcie_device *aerdev,
  {
        struct pci_dev *udev;
        pci_ers_result_t status;
 -      struct find_aer_service_data data;
 +      struct pcie_port_service_driver *driver;
  
 -      if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE)
 +      if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE) {
 +              /* Reset this port for all subordinates */
                udev = dev;
 -      else
 +      } else {
 +              /* Reset the upstream component (likely downstream port) */
                udev = dev->bus->self;
 +      }
  
 -      data.is_downstream = 0;
 -      data.aer_driver = NULL;
 -      find_aer_service(udev, &data);
 +      /* Use the aer driver of the component firstly */
 +      driver = find_aer_service(udev);
  
 -      /*
 -       * Use the aer driver of the error agent firstly.
 -       * If it hasn't the aer driver, use the root port's
 -       */
 -      if (!data.aer_driver || !data.aer_driver->reset_link) {
 -              if (data.is_downstream &&
 -                      aerdev->device.driver &&
 -                      to_service_driver(aerdev->device.driver)->reset_link) {
 -                      data.aer_driver =
 -                              to_service_driver(aerdev->device.driver);
 -              } else {
 -                      dev_printk(KERN_DEBUG, &dev->dev, "no link-reset "
 -                                 "support\n");
 -                      return PCI_ERS_RESULT_DISCONNECT;
 -              }
 +      if (driver && driver->reset_link) {
 +              status = driver->reset_link(udev);
 +      } else if (udev->pcie_type == PCI_EXP_TYPE_DOWNSTREAM) {
 +              status = default_downstream_reset_link(udev);
 +      } else {
 +              dev_printk(KERN_DEBUG, &dev->dev,
 +                      "no link-reset support at upstream device %s\n",
 +                      pci_name(udev));
 +              return PCI_ERS_RESULT_DISCONNECT;
        }
  
 -      status = data.aer_driver->reset_link(udev);
        if (status != PCI_ERS_RESULT_RECOVERED) {
 -              dev_printk(KERN_DEBUG, &dev->dev, "link reset at upstream "
 -                         "device %s failed\n", pci_name(udev));
 +              dev_printk(KERN_DEBUG, &dev->dev,
 +                      "link reset at upstream device %s failed\n",
 +                      pci_name(udev));
                return PCI_ERS_RESULT_DISCONNECT;
        }
  
   * error detected message to all downstream drivers within a hierarchy in
   * question and return the returned code.
   */
 -static pci_ers_result_t do_recovery(struct pcie_device *aerdev,
 -              struct pci_dev *dev,
 +static void do_recovery(struct pcie_device *aerdev, struct pci_dev *dev,
                int severity)
  {
        pci_ers_result_t status, result = PCI_ERS_RESULT_RECOVERED;
  
        if (severity == AER_FATAL) {
                result = reset_link(aerdev, dev);
 -              if (result != PCI_ERS_RESULT_RECOVERED) {
 -                      /* TODO: Should panic here? */
 -                      return result;
 -              }
 +              if (result != PCI_ERS_RESULT_RECOVERED)
 +                      goto failed;
        }
  
        if (status == PCI_ERS_RESULT_CAN_RECOVER)
                                report_slot_reset);
        }
  
 -      if (status == PCI_ERS_RESULT_RECOVERED)
 -              broadcast_error_message(dev,
 +      if (status != PCI_ERS_RESULT_RECOVERED)
 +              goto failed;
 +
 +      broadcast_error_message(dev,
                                state,
                                "resume",
                                report_resume);
  
 -      return status;
 +      dev_printk(KERN_DEBUG, &dev->dev,
 +              "AER driver successfully recovered\n");
 +      return;
 +
 +failed:
 +      /* TODO: Should kernel panic here? */
 +      dev_printk(KERN_DEBUG, &dev->dev,
 +              "AER driver didn't recover\n");
  }
  
  /**
@@@ -564,6 -559,7 +564,6 @@@ static void handle_error_source(struct 
        struct pci_dev *dev,
        struct aer_err_info *info)
  {
 -      pci_ers_result_t status = 0;
        int pos;
  
        if (info->severity == AER_CORRECTABLE) {
                if (pos)
                        pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS,
                                        info->status);
 -      } else {
 -              status = do_recovery(aerdev, dev, info->severity);
 -              if (status == PCI_ERS_RESULT_RECOVERED) {
 -                      dev_printk(KERN_DEBUG, &dev->dev, "AER driver "
 -                                 "successfully recovered\n");
 -              } else {
 -                      /* TODO: Should kernel panic here? */
 -                      dev_printk(KERN_DEBUG, &dev->dev, "AER driver didn't "
 -                                 "recover\n");
 -              }
 -      }
 -}
 -
 -/**
 - * aer_enable_rootport - enable Root Port's interrupts when receiving messages
 - * @rpc: pointer to a Root Port data structure
 - *
 - * Invoked when PCIe bus loads AER service driver.
 - */
 -void aer_enable_rootport(struct aer_rpc *rpc)
 -{
 -      struct pci_dev *pdev = rpc->rpd->port;
 -      int pos, aer_pos;
 -      u16 reg16;
 -      u32 reg32;
 -
 -      pos = pci_pcie_cap(pdev);
 -      /* Clear PCIe Capability's Device Status */
 -      pci_read_config_word(pdev, pos+PCI_EXP_DEVSTA, &reg16);
 -      pci_write_config_word(pdev, pos+PCI_EXP_DEVSTA, reg16);
 -
 -      /* Disable system error generation in response to error messages */
 -      pci_read_config_word(pdev, pos + PCI_EXP_RTCTL, &reg16);
 -      reg16 &= ~(SYSTEM_ERROR_INTR_ON_MESG_MASK);
 -      pci_write_config_word(pdev, pos + PCI_EXP_RTCTL, reg16);
 -
 -      aer_pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR);
 -      /* Clear error status */
 -      pci_read_config_dword(pdev, aer_pos + PCI_ERR_ROOT_STATUS, &reg32);
 -      pci_write_config_dword(pdev, aer_pos + PCI_ERR_ROOT_STATUS, reg32);
 -      pci_read_config_dword(pdev, aer_pos + PCI_ERR_COR_STATUS, &reg32);
 -      pci_write_config_dword(pdev, aer_pos + PCI_ERR_COR_STATUS, reg32);
 -      pci_read_config_dword(pdev, aer_pos + PCI_ERR_UNCOR_STATUS, &reg32);
 -      pci_write_config_dword(pdev, aer_pos + PCI_ERR_UNCOR_STATUS, reg32);
 -
 -      /*
 -       * Enable error reporting for the root port device and downstream port
 -       * devices.
 -       */
 -      set_downstream_devices_error_reporting(pdev, true);
 -
 -      /* Enable Root Port's interrupt in response to error messages */
 -      pci_write_config_dword(pdev,
 -              aer_pos + PCI_ERR_ROOT_COMMAND,
 -              ROOT_PORT_INTR_ON_MESG_MASK);
 -}
 -
 -/**
 - * disable_root_aer - disable Root Port's interrupts when receiving messages
 - * @rpc: pointer to a Root Port data structure
 - *
 - * Invoked when PCIe bus unloads AER service driver.
 - */
 -static void disable_root_aer(struct aer_rpc *rpc)
 -{
 -      struct pci_dev *pdev = rpc->rpd->port;
 -      u32 reg32;
 -      int pos;
 -
 -      /*
 -       * Disable error reporting for the root port device and downstream port
 -       * devices.
 -       */
 -      set_downstream_devices_error_reporting(pdev, false);
 -
 -      pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR);
 -      /* Disable Root's interrupt in response to error messages */
 -      pci_write_config_dword(pdev, pos + PCI_ERR_ROOT_COMMAND, 0);
 -
 -      /* Clear Root's error status reg */
 -      pci_read_config_dword(pdev, pos + PCI_ERR_ROOT_STATUS, &reg32);
 -      pci_write_config_dword(pdev, pos + PCI_ERR_ROOT_STATUS, reg32);
 -}
 -
 -/**
 - * get_e_source - retrieve an error source
 - * @rpc: pointer to the root port which holds an error
 - *
 - * Invoked by DPC handler to consume an error.
 - */
 -static struct aer_err_source *get_e_source(struct aer_rpc *rpc)
 -{
 -      struct aer_err_source *e_source;
 -      unsigned long flags;
 -
 -      /* Lock access to Root error producer/consumer index */
 -      spin_lock_irqsave(&rpc->e_lock, flags);
 -      if (rpc->prod_idx == rpc->cons_idx) {
 -              spin_unlock_irqrestore(&rpc->e_lock, flags);
 -              return NULL;
 -      }
 -      e_source = &rpc->e_sources[rpc->cons_idx];
 -      rpc->cons_idx++;
 -      if (rpc->cons_idx == AER_ERROR_SOURCES_MAX)
 -              rpc->cons_idx = 0;
 -      spin_unlock_irqrestore(&rpc->e_lock, flags);
 -
 -      return e_source;
 +      } else
 +              do_recovery(aerdev, dev, info->severity);
  }
  
  /**
   * @info: pointer to structure to store the error record
   *
   * Return 1 on success, 0 on error.
 + *
 + * Note that @info is reused among all error devices. Clear fields properly.
   */
  static int get_device_error_info(struct pci_dev *dev, struct aer_err_info *info)
  {
        int pos, temp;
  
 +      /* Must reset in this function */
        info->status = 0;
        info->tlp_header_valid = 0;
  
@@@ -645,6 -744,12 +645,6 @@@ static inline void aer_process_err_devi
  {
        int i;
  
 -      if (!e_info->dev[0]) {
 -              dev_printk(KERN_DEBUG, &p_device->port->dev,
 -                              "can't find device of ID%04x\n",
 -                              e_info->id);
 -      }
 -
        /* Report all before handle them, not to lost records by reset etc. */
        for (i = 0; i < e_info->error_dev_num && e_info->dev[i]; i++) {
                if (get_device_error_info(e_info->dev[i], e_info))
@@@ -665,10 -770,11 +665,10 @@@ static void aer_isr_one_error(struct pc
                struct aer_err_source *e_src)
  {
        struct aer_err_info *e_info;
  
        /* struct aer_err_info might be big, so we allocate it with slab */
        e_info = kmalloc(sizeof(struct aer_err_info), GFP_KERNEL);
 -      if (e_info == NULL) {
 +      if (!e_info) {
                dev_printk(KERN_DEBUG, &p_device->port->dev,
                        "Can't allocate mem when processing AER errors\n");
                return;
         * There is a possibility that both correctable error and
         * uncorrectable error being logged. Report correctable error first.
         */
 -      for (i = 1; i & ROOT_ERR_STATUS_MASKS ; i <<= 2) {
 -              if (i > 4)
 -                      break;
 -              if (!(e_src->status & i))
 -                      continue;
 -
 -              memset(e_info, 0, sizeof(struct aer_err_info));
 -
 -              /* Init comprehensive error information */
 -              if (i & PCI_ERR_ROOT_COR_RCV) {
 -                      e_info->id = ERR_COR_ID(e_src->id);
 -                      e_info->severity = AER_CORRECTABLE;
 -              } else {
 -                      e_info->id = ERR_UNCOR_ID(e_src->id);
 -                      e_info->severity = ((e_src->status >> 6) & 1);
 -              }
 -              if (e_src->status &
 -                      (PCI_ERR_ROOT_MULTI_COR_RCV |
 -                       PCI_ERR_ROOT_MULTI_UNCOR_RCV))
 +      if (e_src->status & PCI_ERR_ROOT_COR_RCV) {
 +              e_info->id = ERR_COR_ID(e_src->id);
 +              e_info->severity = AER_CORRECTABLE;
 +
 +              if (e_src->status & PCI_ERR_ROOT_MULTI_COR_RCV)
                        e_info->multi_error_valid = 1;
 +              else
 +                      e_info->multi_error_valid = 0;
 +
 +              aer_print_port_info(p_device->port, e_info);
 +
 +              if (find_source_device(p_device->port, e_info))
 +                      aer_process_err_devices(p_device, e_info);
 +      }
 +
 +      if (e_src->status & PCI_ERR_ROOT_UNCOR_RCV) {
 +              e_info->id = ERR_UNCOR_ID(e_src->id);
 +
 +              if (e_src->status & PCI_ERR_ROOT_FATAL_RCV)
 +                      e_info->severity = AER_FATAL;
 +              else
 +                      e_info->severity = AER_NONFATAL;
 +
 +              if (e_src->status & PCI_ERR_ROOT_MULTI_UNCOR_RCV)
 +                      e_info->multi_error_valid = 1;
 +              else
 +                      e_info->multi_error_valid = 0;
  
                aer_print_port_info(p_device->port, e_info);
  
 -              find_source_device(p_device->port, e_info);
 -              aer_process_err_devices(p_device, e_info);
 +              if (find_source_device(p_device->port, e_info))
 +                      aer_process_err_devices(p_device, e_info);
        }
  
        kfree(e_info);
  }
  
  /**
 + * get_e_source - retrieve an error source
 + * @rpc: pointer to the root port which holds an error
 + * @e_src: pointer to store retrieved error source
 + *
 + * Return 1 if an error source is retrieved, otherwise 0.
 + *
 + * Invoked by DPC handler to consume an error.
 + */
 +static int get_e_source(struct aer_rpc *rpc, struct aer_err_source *e_src)
 +{
 +      unsigned long flags;
 +      int ret = 0;
 +
 +      /* Lock access to Root error producer/consumer index */
 +      spin_lock_irqsave(&rpc->e_lock, flags);
 +      if (rpc->prod_idx != rpc->cons_idx) {
 +              *e_src = rpc->e_sources[rpc->cons_idx];
 +              rpc->cons_idx++;
 +              if (rpc->cons_idx == AER_ERROR_SOURCES_MAX)
 +                      rpc->cons_idx = 0;
 +              ret = 1;
 +      }
 +      spin_unlock_irqrestore(&rpc->e_lock, flags);
 +
 +      return ret;
 +}
 +
 +/**
   * aer_isr - consume errors detected by root port
   * @work: definition of this work item
   *
@@@ -753,17 -824,34 +753,17 @@@ void aer_isr(struct work_struct *work
  {
        struct aer_rpc *rpc = container_of(work, struct aer_rpc, dpc_handler);
        struct pcie_device *p_device = rpc->rpd;
 -      struct aer_err_source *e_src;
 +      struct aer_err_source e_src;
  
        mutex_lock(&rpc->rpc_mutex);
 -      e_src = get_e_source(rpc);
 -      while (e_src) {
 -              aer_isr_one_error(p_device, e_src);
 -              e_src = get_e_source(rpc);
 -      }
 +      while (get_e_source(rpc, &e_src))
 +              aer_isr_one_error(p_device, &e_src);
        mutex_unlock(&rpc->rpc_mutex);
  
        wake_up(&rpc->wait_release);
  }
  
  /**
 - * aer_delete_rootport - disable root port aer and delete service data
 - * @rpc: pointer to a root port device being deleted
 - *
 - * Invoked when AER service unloaded on a specific Root Port
 - */
 -void aer_delete_rootport(struct aer_rpc *rpc)
 -{
 -      /* Disable root port AER itself */
 -      disable_root_aer(rpc);
 -
 -      kfree(rpc);
 -}
 -
 -/**
   * aer_init - provide AER initialization
   * @dev: pointer to AER pcie device
   *
   */
  int aer_init(struct pcie_device *dev)
  {
-       if (dev->port->aer_firmware_first) {
+       if (pcie_aer_get_firmware_first(dev->port)) {
                dev_printk(KERN_DEBUG, &dev->device,
                           "PCIe errors handled by platform firmware.\n");
                goto out;
@@@ -785,7 -873,7 +785,7 @@@ out
        if (forceload) {
                dev_printk(KERN_DEBUG, &dev->device,
                           "aerdrv forceload requested.\n");
-               dev->port->aer_firmware_first = 0;
+               pcie_aer_force_firmware_first(dev->port, 0);
                return 0;
        }
        return -ENXIO;
diff --combined include/linux/acpi.h
@@@ -116,12 -116,11 +116,12 @@@ extern unsigned long acpi_realmode_flag
  
  int acpi_register_gsi (struct device *dev, u32 gsi, int triggering, int polarity);
  int acpi_gsi_to_irq (u32 gsi, unsigned int *irq);
 +int acpi_isa_irq_to_gsi (unsigned isa_irq, u32 *gsi);
  
  #ifdef CONFIG_X86_IO_APIC
 -extern int acpi_get_override_irq(int bus_irq, int *trigger, int *polarity);
 +extern int acpi_get_override_irq(u32 gsi, int *trigger, int *polarity);
  #else
 -#define acpi_get_override_irq(bus, trigger, polarity) (-1)
 +#define acpi_get_override_irq(gsi, trigger, polarity) (-1)
  #endif
  /*
   * This function undoes the effect of one call to acpi_register_gsi().
@@@ -248,13 -247,10 +248,12 @@@ int acpi_check_region(resource_size_t s
  int acpi_check_mem_region(resource_size_t start, resource_size_t n,
                      const char *name);
  
 +int acpi_resources_are_enforced(void);
 +
  #ifdef CONFIG_PM_SLEEP
  void __init acpi_no_s4_hw_signature(void);
  void __init acpi_old_suspend_ordering(void);
  void __init acpi_s4_no_nvs(void);
- void __init acpi_set_sci_en_on_resume(void);
  #endif /* CONFIG_PM_SLEEP */
  
  struct acpi_osc_context {
diff --combined include/linux/pci.h
@@@ -311,7 -311,8 +311,8 @@@ struct pci_dev 
        unsigned int    is_virtfn:1;
        unsigned int    reset_fn:1;
        unsigned int    is_hotplug_bridge:1;
-       unsigned int    aer_firmware_first:1;
+       unsigned int    __aer_firmware_first_valid:1;
+       unsigned int    __aer_firmware_first:1;
        pci_dev_flags_t dev_flags;
        atomic_t        enable_cnt;     /* pci_enable_device has been called */
  
  #endif
  };
  
 +static inline struct pci_dev *pci_physfn(struct pci_dev *dev)
 +{
 +#ifdef CONFIG_PCI_IOV
 +      if (dev->is_virtfn)
 +              dev = dev->physfn;
 +#endif
 +
 +      return dev;
 +}
 +
  extern struct pci_dev *alloc_pci_dev(void);
  
  #define pci_dev_b(n) list_entry(n, struct pci_dev, bus_list)
diff --combined lib/Makefile
@@@ -21,7 -21,7 +21,7 @@@ lib-y += kobject.o kref.o klist.
  
  obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
         bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \
-        string_helpers.o gcd.o lcm.o list_sort.o
+        string_helpers.o gcd.o lcm.o list_sort.o uuid.o
  
  ifeq ($(CONFIG_DEBUG_KOBJECT),y)
  CFLAGS_kobject.o += -DDEBUG
@@@ -39,10 -39,7 +39,10 @@@ lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) +
  lib-$(CONFIG_GENERIC_FIND_FIRST_BIT) += find_next_bit.o
  lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o
  obj-$(CONFIG_GENERIC_FIND_LAST_BIT) += find_last_bit.o
 +
 +CFLAGS_hweight.o = $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
  obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
 +
  obj-$(CONFIG_LOCK_KERNEL) += kernel_lock.o
  obj-$(CONFIG_BTREE) += btree.o
  obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
@@@ -85,7 -82,6 +85,7 @@@ obj-$(CONFIG_AUDIT_GENERIC) += audit.
  obj-$(CONFIG_SWIOTLB) += swiotlb.o
  obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o
  obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o
 +obj-$(CONFIG_CPU_NOTIFIER_ERROR_INJECT) += cpu-notifier-error-inject.o
  
  lib-$(CONFIG_GENERIC_BUG) += bug.o
  
@@@ -105,8 -101,6 +105,8 @@@ obj-$(CONFIG_GENERIC_CSUM) += checksum.
  
  obj-$(CONFIG_GENERIC_ATOMIC64) += atomic64.o
  
 +obj-$(CONFIG_ATOMIC64_SELFTEST) += atomic64_test.o
 +
  hostprogs-y   := gen_crc32table
  clean-files   := crc32table.h