diff mbox

Small fix for qemu APIC for Mac OS X support

Message ID 20101126124016.GF14105@valinux.co.jp
State New
Headers show

Commit Message

Isaku Yamahata Nov. 26, 2010, 12:40 p.m. UTC
On Thu, Nov 25, 2010 at 08:18:45PM +0000, adq wrote:
> On 25 November 2010 11:28, Isaku Yamahata <yamahata@valinux.co.jp> wrote:
> > On Wed, Nov 24, 2010 at 02:08:16PM +0000, adq wrote:
> >> > Interesting. I was also thinking that maybe we can leverage overriding mechanisms that are already available. Maybe it's possible to squeeze the HPET node into an SSDT. Maybe we need to override the whole DSDT from the command line.
> >>
> >> We'll definitely need to override the DSDT for the applesmc device. I
> >> was thinking something along the lines of an additional DSDT binary
> >> supplied with QEMU for use when emulating apple hardware as you
> >> suggest.
> >
> > The patches for qemu and seabios have been floating around.
> > I wrote them for Q35 chipset support, but no one has gotten interested in it.
> > But now, you are there. I'm willing to rebase/resend them.
> 
> I'd definitely be interested to see those!

Here is seabios part.

From 7a6e97b74bc0d25aca42a43cabcc68836edaf6c0 Mon Sep 17 00:00:00 2001
Message-Id: <7a6e97b74bc0d25aca42a43cabcc68836edaf6c0.1290774988.git.yamahata@valinux.co.jp>
In-Reply-To: <cover.1290774988.git.yamahata@valinux.co.jp>
References: <cover.1290774988.git.yamahata@valinux.co.jp>
From: Isaku Yamahata <yamahata@valinux.co.jp>
Date: Tue, 15 Jun 2010 12:41:13 +0900
Subject: [PATCH 1/1] seabios: acpi: allow qemu to load dsdt as external acpi table.

allow qemu to load dsdt as external acpi table.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>

---
changes v1 -> v2.
- load qemu table first and they try default dsdt table if
  qemu doesn't supply dsdt.
  Thus unnecessary malloc_high()/free() is avoided.
---
 src/acpi.c |   44 ++++++++++++++++++++++++++++++++++++--------
 1 files changed, 36 insertions(+), 8 deletions(-)

Comments

adq Dec. 5, 2010, 2:36 p.m. UTC | #1
On 26 November 2010 12:40, Isaku Yamahata <yamahata@valinux.co.jp> wrote:
> On Thu, Nov 25, 2010 at 08:18:45PM +0000, adq wrote:
>> On 25 November 2010 11:28, Isaku Yamahata <yamahata@valinux.co.jp> wrote:
>> > On Wed, Nov 24, 2010 at 02:08:16PM +0000, adq wrote:
>> >> > Interesting. I was also thinking that maybe we can leverage overriding mechanisms that are already available. Maybe it's possible to squeeze the HPET node into an SSDT. Maybe we need to override the whole DSDT from the command line.
>> >>
>> >> We'll definitely need to override the DSDT for the applesmc device. I
>> >> was thinking something along the lines of an additional DSDT binary
>> >> supplied with QEMU for use when emulating apple hardware as you
>> >> suggest.
>> >
>> > The patches for qemu and seabios have been floating around.
>> > I wrote them for Q35 chipset support, but no one has gotten interested in it.
>> > But now, you are there. I'm willing to rebase/resend them.
>>
>> I'd definitely be interested to see those!
>
> Here is seabios part.
>
> From 7a6e97b74bc0d25aca42a43cabcc68836edaf6c0 Mon Sep 17 00:00:00 2001
> Message-Id: <7a6e97b74bc0d25aca42a43cabcc68836edaf6c0.1290774988.git.yamahata@valinux.co.jp>
> In-Reply-To: <cover.1290774988.git.yamahata@valinux.co.jp>
> References: <cover.1290774988.git.yamahata@valinux.co.jp>
> From: Isaku Yamahata <yamahata@valinux.co.jp>
> Date: Tue, 15 Jun 2010 12:41:13 +0900
> Subject: [PATCH 1/1] seabios: acpi: allow qemu to load dsdt as external acpi table.
>
> allow qemu to load dsdt as external acpi table.
>
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
>
> ---
> changes v1 -> v2.
> - load qemu table first and they try default dsdt table if
>  qemu doesn't supply dsdt.
>  Thus unnecessary malloc_high()/free() is avoided.
> ---
>  src/acpi.c |   44 ++++++++++++++++++++++++++++++++++++--------
>  1 files changed, 36 insertions(+), 8 deletions(-)
>
> diff --git a/src/acpi.c b/src/acpi.c
> index 18830dc..f4e0780 100644
> --- a/src/acpi.c
> +++ b/src/acpi.c
> @@ -54,6 +54,11 @@ struct facs_descriptor_rev1
>
>
>  /*
> + * Differentiated System Descrition Table (DSDT)
> + */
> +#define DSDT_SIGNATURE 0x54445344 // DSDT
> +
> +/*
>  * MADT values and structures
>  */
>
> @@ -221,14 +226,20 @@ static const struct pci_device_id fadt_init_tbl[] = {
>     PCI_DEVICE_END
>  };
>
> +static void fill_dsdt(struct fadt_descriptor_rev1 *fadt, void *dsdt)
> +{
> +    fadt->dsdt = cpu_to_le32((u32)dsdt);
> +    fadt->checksum -= checksum(fadt, sizeof(*fadt));
> +    dprintf(1, "ACPI DSDT=%p\n", dsdt);
> +}
> +
>  static void*
>  build_fadt(int bdf)
>  {
>     struct fadt_descriptor_rev1 *fadt = malloc_high(sizeof(*fadt));
>     struct facs_descriptor_rev1 *facs = memalign_high(64, sizeof(*facs));
> -    void *dsdt = malloc_high(sizeof(AmlCode));
>
> -    if (!fadt || !facs || !dsdt) {
> +    if (!fadt || !facs) {
>         warn_noalloc();
>         return NULL;
>     }
> @@ -238,13 +249,11 @@ build_fadt(int bdf)
>     facs->signature = FACS_SIGNATURE;
>     facs->length = cpu_to_le32(sizeof(*facs));
>
> -    /* DSDT */
> -    memcpy(dsdt, AmlCode, sizeof(AmlCode));
> -
>     /* FADT */
>     memset(fadt, 0, sizeof(*fadt));
>     fadt->firmware_ctrl = cpu_to_le32((u32)facs);
> -    fadt->dsdt = cpu_to_le32((u32)dsdt);
> +    fadt->dsdt = 0;  /* dsdt will be filled later in acpi_bios_init()
> +                        by fill_dsdt() */
>     fadt->model = 1;
>     fadt->reserved1 = 0;
>     int pm_sci_int = pci_config_readb(bdf, PCI_INTERRUPT_LINE);
> @@ -620,7 +629,8 @@ acpi_bios_init(void)
>     } while(0)
>
>     // Add tables
> -    ACPI_INIT_TABLE(build_fadt(bdf));
> +    struct fadt_descriptor_rev1 *fadt = build_fadt(bdf);
> +    ACPI_INIT_TABLE(fadt);
>     ACPI_INIT_TABLE(build_ssdt());
>     ACPI_INIT_TABLE(build_madt());
>     ACPI_INIT_TABLE(build_hpet());
> @@ -635,12 +645,30 @@ acpi_bios_init(void)
>             warn_noalloc();
>             continue;
>         }
> -        ACPI_INIT_TABLE(qemu_cfg_next_acpi_table_load(addr, len));
> +        struct acpi_table_header *header =
> +            qemu_cfg_next_acpi_table_load(addr, len);
> +        if (header->signature == DSDT_SIGNATURE) {
> +            if (fadt) {
> +                fill_dsdt(fadt, addr);
> +            }
> +        } else {
> +            ACPI_INIT_TABLE(header);
> +        }
>         if (tbl_idx == MAX_ACPI_TABLES) {
>             warn_noalloc();
>             break;
>         }
>     }
> +    if (fadt && !fadt->dsdt) {
> +        /* default DSDT */
> +        void *dsdt = malloc_high(sizeof(AmlCode));
> +        if (!dsdt) {
> +            warn_noalloc();
> +            return;
> +        }
> +        memcpy(dsdt, AmlCode, sizeof(AmlCode));
> +        fill_dsdt(fadt, dsdt);
> +    }
>
>     struct rsdt_descriptor_rev1 *rsdt;
>     size_t rsdt_len = sizeof(*rsdt) + sizeof(u32) * tbl_idx;

Hi, looks great, sorry for the delay in answering, I got caught up
with other things.

I'm currently figuring out why the e1000 doesn't work; I suspect
something is slightly wrong with qemu/macosx's microwire bitbanging
implementation (and I've verified macosx is using microwire) causing
eeprom reads to fail.
Andreas Färber Dec. 5, 2010, 6:40 p.m. UTC | #2
Am 26.11.2010 um 13:40 schrieb Isaku Yamahata:

> On Thu, Nov 25, 2010 at 08:18:45PM +0000, adq wrote:
>> On 25 November 2010 11:28, Isaku Yamahata <yamahata@valinux.co.jp>  
>> wrote:
>>> On Wed, Nov 24, 2010 at 02:08:16PM +0000, adq wrote:
>>>>> Interesting. I was also thinking that maybe we can leverage  
>>>>> overriding mechanisms that are already available. Maybe it's  
>>>>> possible to squeeze the HPET node into an SSDT. Maybe we need to  
>>>>> override the whole DSDT from the command line.
>>>>
>>>> We'll definitely need to override the DSDT for the applesmc  
>>>> device. I
>>>> was thinking something along the lines of an additional DSDT binary
>>>> supplied with QEMU for use when emulating apple hardware as you
>>>> suggest.
>>>
>>> The patches for qemu and seabios have been floating around.
>>> I wrote them for Q35 chipset support, but no one has gotten  
>>> interested in it.
>>> But now, you are there. I'm willing to rebase/resend them.
>>
>> I'd definitely be interested to see those!
>
> Here is seabios part.
>
> From 7a6e97b74bc0d25aca42a43cabcc68836edaf6c0 Mon Sep 17 00:00:00 2001
> Message-Id: <7a6e97b74bc0d25aca42a43cabcc68836edaf6c0.1290774988.git.yamahata@valinux.co.jp 
> >
> In-Reply-To: <cover.1290774988.git.yamahata@valinux.co.jp>
> References: <cover.1290774988.git.yamahata@valinux.co.jp>
> From: Isaku Yamahata <yamahata@valinux.co.jp>
> Date: Tue, 15 Jun 2010 12:41:13 +0900
> Subject: [PATCH 1/1] seabios: acpi: allow qemu to load dsdt as  
> external acpi table.
>
> allow qemu to load dsdt as external acpi table.
>
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
>
> ---
> changes v1 -> v2.
> - load qemu table first and they try default dsdt table if
>  qemu doesn't supply dsdt.
>  Thus unnecessary malloc_high()/free() is avoided.
> ---
> src/acpi.c |   44 ++++++++++++++++++++++++++++++++++++--------
> 1 files changed, 36 insertions(+), 8 deletions(-)
>
> diff --git a/src/acpi.c b/src/acpi.c
> index 18830dc..f4e0780 100644
> --- a/src/acpi.c
> +++ b/src/acpi.c
> @@ -54,6 +54,11 @@ struct facs_descriptor_rev1
>
>
> /*
> + * Differentiated System Descrition Table (DSDT)

Typo: Description

Andreas
diff mbox

Patch

diff --git a/src/acpi.c b/src/acpi.c
index 18830dc..f4e0780 100644
--- a/src/acpi.c
+++ b/src/acpi.c
@@ -54,6 +54,11 @@  struct facs_descriptor_rev1
 
 
 /*
+ * Differentiated System Descrition Table (DSDT)
+ */
+#define DSDT_SIGNATURE 0x54445344 // DSDT
+
+/*
  * MADT values and structures
  */
 
@@ -221,14 +226,20 @@  static const struct pci_device_id fadt_init_tbl[] = {
     PCI_DEVICE_END
 };
 
+static void fill_dsdt(struct fadt_descriptor_rev1 *fadt, void *dsdt)
+{
+    fadt->dsdt = cpu_to_le32((u32)dsdt);
+    fadt->checksum -= checksum(fadt, sizeof(*fadt));
+    dprintf(1, "ACPI DSDT=%p\n", dsdt);
+}
+
 static void*
 build_fadt(int bdf)
 {
     struct fadt_descriptor_rev1 *fadt = malloc_high(sizeof(*fadt));
     struct facs_descriptor_rev1 *facs = memalign_high(64, sizeof(*facs));
-    void *dsdt = malloc_high(sizeof(AmlCode));
 
-    if (!fadt || !facs || !dsdt) {
+    if (!fadt || !facs) {
         warn_noalloc();
         return NULL;
     }
@@ -238,13 +249,11 @@  build_fadt(int bdf)
     facs->signature = FACS_SIGNATURE;
     facs->length = cpu_to_le32(sizeof(*facs));
 
-    /* DSDT */
-    memcpy(dsdt, AmlCode, sizeof(AmlCode));
-
     /* FADT */
     memset(fadt, 0, sizeof(*fadt));
     fadt->firmware_ctrl = cpu_to_le32((u32)facs);
-    fadt->dsdt = cpu_to_le32((u32)dsdt);
+    fadt->dsdt = 0;  /* dsdt will be filled later in acpi_bios_init()
+                        by fill_dsdt() */
     fadt->model = 1;
     fadt->reserved1 = 0;
     int pm_sci_int = pci_config_readb(bdf, PCI_INTERRUPT_LINE);
@@ -620,7 +629,8 @@  acpi_bios_init(void)
     } while(0)
 
     // Add tables
-    ACPI_INIT_TABLE(build_fadt(bdf));
+    struct fadt_descriptor_rev1 *fadt = build_fadt(bdf);
+    ACPI_INIT_TABLE(fadt);
     ACPI_INIT_TABLE(build_ssdt());
     ACPI_INIT_TABLE(build_madt());
     ACPI_INIT_TABLE(build_hpet());
@@ -635,12 +645,30 @@  acpi_bios_init(void)
             warn_noalloc();
             continue;
         }
-        ACPI_INIT_TABLE(qemu_cfg_next_acpi_table_load(addr, len));
+        struct acpi_table_header *header =
+            qemu_cfg_next_acpi_table_load(addr, len);
+        if (header->signature == DSDT_SIGNATURE) {
+            if (fadt) {
+                fill_dsdt(fadt, addr);
+            }
+        } else {
+            ACPI_INIT_TABLE(header);
+        }
         if (tbl_idx == MAX_ACPI_TABLES) {
             warn_noalloc();
             break;
         }
     }
+    if (fadt && !fadt->dsdt) {
+        /* default DSDT */
+        void *dsdt = malloc_high(sizeof(AmlCode));
+        if (!dsdt) {
+            warn_noalloc();
+            return;
+        }
+        memcpy(dsdt, AmlCode, sizeof(AmlCode));
+        fill_dsdt(fadt, dsdt);
+    }
 
     struct rsdt_descriptor_rev1 *rsdt;
     size_t rsdt_len = sizeof(*rsdt) + sizeof(u32) * tbl_idx;