qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Marcel Apfelbaum <marcel.a@redhat.com>
Cc: ghammer@redhat.com, seabios@seabios.org, qemu-devel@nongnu.org,
	kevin@koconnor.net, kraxel@redhat.com, lersek@redhat.com
Subject: Re: [Qemu-devel] [Seabios] [PATCH v2] seabios: restore piix pm config registers after resume
Date: Wed, 15 Jan 2014 17:08:07 +0200	[thread overview]
Message-ID: <20140115150807.GA5862@redhat.com> (raw)
In-Reply-To: <1389788406-13333-1-git-send-email-marcel.a@redhat.com>

On Wed, Jan 15, 2014 at 02:20:06PM +0200, Marcel Apfelbaum wrote:
> On resume, the OS queries the power management event that
> caused it. In order to complete this task, it executes some
> reads to the piix pm io space. This all happens before the
> OS has a chance to restore the PCI config space for devices,
> so it is bios's responsibility to make sure the pm IO space
> is configured correctly. (During suspend, the piix pm
> configuration space is lost).
> 
> Note: For 'ordinary' pci devices the config space is
> saved by the OS on sleep and restored on resume.
> 
> Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>

Acked-by: Michael S. Tsirkin <mst@redhat.com>

> ---
> v1 -> v2:
>  Addressed Kevin O'Connor comments
>  - Simplified patch by remembering PM device bdf
> 
> Notes:
>  - Without this patch the OS gets stuck because it tries repeatedly
>    to read/write to pm io space, but the
>    memory region is not enabled, so -1 is returned.
>  - After resume the OS does not actually use the pm base address
>    configured by the bios to get the IO ports, but uses
>    the value from the ACPI FADT table actually. However, as a side effect
>    of the configuration, the pm-io space is enabled by Qemu and
>    the OS can continue the the boot sequence.
>  - Bioses used for hardware like coreboot have the same init
>    sequence for piix, see enable_pm from src/southbridge/intel/i82371eb/early_pm.c.
> 
> 
>  src/fw/pciinit.c | 24 +++++++++++++++++++++---
>  src/hw/pci.h     |  1 +
>  src/resume.c     |  2 ++
>  src/util.h       |  1 +
>  4 files changed, 25 insertions(+), 3 deletions(-)
> 
> diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c
> index a24b8ff..11c92ae 100644
> --- a/src/fw/pciinit.c
> +++ b/src/fw/pciinit.c
> @@ -230,10 +230,8 @@ static void apple_macio_setup(struct pci_device *pci, void *arg)
>      pci_set_io_region_addr(pci, 0, 0x80800000, 0);
>  }
>  
> -/* PIIX4 Power Management device (for ACPI) */
> -static void piix4_pm_setup(struct pci_device *pci, void *arg)
> +static void piix4_pm_config_setup(u16 bdf)
>  {
> -    u16 bdf = pci->bdf;
>      // acpi sci is hardwired to 9
>      pci_config_writeb(bdf, PCI_INTERRUPT_LINE, 9);
>  
> @@ -241,6 +239,15 @@ static void piix4_pm_setup(struct pci_device *pci, void *arg)
>      pci_config_writeb(bdf, 0x80, 0x01); /* enable PM io space */
>      pci_config_writel(bdf, 0x90, PORT_SMB_BASE | 1);
>      pci_config_writeb(bdf, 0xd2, 0x09); /* enable SMBus io space */
> +}
> +
> +static int PiixPmBDF = -1;
> +
> +/* PIIX4 Power Management device (for ACPI) */
> +static void piix4_pm_setup(struct pci_device *pci, void *arg)
> +{
> +    PiixPmBDF = pci->bdf;
> +    piix4_pm_config_setup(pci->bdf);
>  
>      acpi_pm1a_cnt = PORT_ACPI_PM_BASE + 0x04;
>      pmtimer_setup(PORT_ACPI_PM_BASE + 0x08);
> @@ -295,6 +302,17 @@ static const struct pci_device_id pci_device_tbl[] = {
>      PCI_DEVICE_END,
>  };
>  
> +void pci_resume(void)
> +{
> +    if (!CONFIG_QEMU) {
> +        return;
> +    }
> +
> +    if (PiixPmBDF >= 0) {
> +        piix4_pm_config_setup(PiixPmBDF);
> +    }
> +}
> +
>  static void pci_bios_init_device(struct pci_device *pci)
>  {
>      u16 bdf = pci->bdf;
> diff --git a/src/hw/pci.h b/src/hw/pci.h
> index 9c7351d..17689a8 100644
> --- a/src/hw/pci.h
> +++ b/src/hw/pci.h
> @@ -66,6 +66,7 @@ extern u64 pcimem64_start, pcimem64_end;
>  extern struct hlist_head PCIDevices;
>  extern int MaxPCIBus;
>  int pci_probe_host(void);
> +void pci_resume(void);
>  void pci_probe_devices(void);
>  static inline u32 pci_classprog(struct pci_device *pci) {
>      return (pci->class << 8) | pci->prog_if;
> diff --git a/src/resume.c b/src/resume.c
> index d69429c..9ad2e4f 100644
> --- a/src/resume.c
> +++ b/src/resume.c
> @@ -101,6 +101,8 @@ s3_resume(void)
>      pic_setup();
>      smm_setup();
>  
> +    pci_resume();
> +
>      s3_resume_vga();
>  
>      make_bios_readonly();
> diff --git a/src/util.h b/src/util.h
> index 1b7d525..3f53f4d 100644
> --- a/src/util.h
> +++ b/src/util.h
> @@ -28,6 +28,7 @@ void boot_add_cbfs(void *data, const char *desc, int prio);
>  void interactive_bootmenu(void);
>  void bcv_prepboot(void);
>  struct pci_device;
> +void pci_resume(void);
>  int bootprio_find_pci_device(struct pci_device *pci);
>  int bootprio_find_scsi_device(struct pci_device *pci, int target, int lun);
>  int bootprio_find_ata_device(struct pci_device *pci, int chanid, int slave);
> -- 
> 1.8.3.1

      parent reply	other threads:[~2014-01-15 15:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-15 12:20 [Qemu-devel] [Seabios] [PATCH v2] seabios: restore piix pm config registers after resume Marcel Apfelbaum
2014-01-15 12:24 ` Marcel Apfelbaum
2014-01-15 16:04   ` Kevin O'Connor
2014-01-15 15:08 ` Michael S. Tsirkin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140115150807.GA5862@redhat.com \
    --to=mst@redhat.com \
    --cc=ghammer@redhat.com \
    --cc=kevin@koconnor.net \
    --cc=kraxel@redhat.com \
    --cc=lersek@redhat.com \
    --cc=marcel.a@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=seabios@seabios.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).