diff mbox

[16/21] HPET support.

Message ID 1255017566-26220-17-git-send-email-gleb@redhat.com
State Not Applicable
Headers show

Commit Message

Gleb Natapov Oct. 8, 2009, 3:59 p.m. UTC
Part of qemu pcbios commit e04da91178f0e11febbbd61d9795e49cc27e9ad4

Signed-off-by: Gleb Natapov <gleb@redhat.com>
---
 src/acpi-dsdt.dsl |   19 +++++++++++++++++++
 src/acpi.c        |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/src/acpi-dsdt.dsl b/src/acpi-dsdt.dsl
index 4cd6f6a..c7e6547 100644
--- a/src/acpi-dsdt.dsl
+++ b/src/acpi-dsdt.dsl
@@ -165,6 +165,25 @@  DefinitionBlock (
                     ,, , AddressRangeMemory, TypeStatic)
             })
         }
+
+        Device(HPET) {
+            Name(_HID,  EISAID("PNP0103"))
+            Name(_UID, 0)
+            Method (_STA, 0, NotSerialized) {
+                    Return(0x0F)
+            }
+            Name(_CRS, ResourceTemplate() {
+                DWordMemory(
+                    ResourceConsumer, PosDecode, MinFixed, MaxFixed,
+                    NonCacheable, ReadWrite,
+                    0x00000000,
+                    0xFED00000,
+                    0xFED003FF,
+                    0x00000000,
+                    0x00000400 /* 1K memory: FED00000 - FED003FF */
+                )
+            })
+        }
     }
 
     Scope(\_SB.PCI0) {
diff --git a/src/acpi.c b/src/acpi.c
index 7c96427..3e7efc8 100644
--- a/src/acpi.c
+++ b/src/acpi.c
@@ -206,6 +206,30 @@  struct madt_intsrcovr {
     u16 flags;
 } PACKED;
 
+/*
+ * ACPI 2.0 Generic Address Space definition.
+ */
+struct acpi_20_generic_address {
+    u8  address_space_id;
+    u8  register_bit_width;
+    u8  register_bit_offset;
+    u8  reserved;
+    u64 address;
+} PACKED;
+
+/*
+ * HPET Description Table
+ */
+struct acpi_20_hpet {
+    ACPI_TABLE_HEADER_DEF                    /* ACPI common table header */
+    u32           timer_block_id;
+    struct acpi_20_generic_address addr;
+    u8            hpet_number;
+    u16           min_tick;
+    u8            page_protect;
+} PACKED;
+#define ACPI_HPET_ADDRESS 0xFED00000UL
+
 #include "acpi-dsdt.hex"
 
 static inline u16 cpu_to_le16(u16 x)
@@ -402,6 +426,27 @@  build_ssdt(void)
     return ssdt;
 }
 
+#define HPET_SIGNATURE 0x54455048 //HPET
+static void*
+build_hpet(void)
+{
+    struct acpi_20_hpet *hpet = malloc_high(sizeof(*hpet));
+    if (!hpet) {
+        dprintf(1, "Not enough memory for hpet!\n");
+        return NULL;
+    }
+
+    memset(hpet, 0, sizeof(*hpet));
+    /* Note timer_block_id value must be kept in sync with value advertised by
+     * emulated hpet
+     */
+    hpet->timer_block_id = cpu_to_le32(0x8086a201);
+    hpet->addr.address = cpu_to_le32(ACPI_HPET_ADDRESS);
+    build_header((void*)hpet, HPET_SIGNATURE, sizeof(*hpet), 1);
+
+    return hpet;
+}
+
 struct rsdp_descriptor *RsdpAddr;
 
 #define MAX_ACPI_TABLES 20
@@ -440,6 +485,7 @@  acpi_bios_init(void)
     ACPI_INIT_TABLE(build_fadt(bdf));
     ACPI_INIT_TABLE(build_ssdt());
     ACPI_INIT_TABLE(build_madt());
+    ACPI_INIT_TABLE(build_hpet());
 
     u16 i, external_tables = qemu_cfg_acpi_additional_tables();