diff mbox

[RFC,32/47] acpi: add acpi_eisaid() term

Message ID 1418954562-13716-33-git-send-email-imammedo@redhat.com
State New
Headers show

Commit Message

Igor Mammedov Dec. 19, 2014, 2:02 a.m. UTC
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/acpi/acpi_gen_utils.c         | 31 +++++++++++++++++++++++++++++++
 include/hw/acpi/acpi_gen_utils.h |  1 +
 2 files changed, 32 insertions(+)
diff mbox

Patch

diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c
index 4606d1e..68d1855 100644
--- a/hw/acpi/acpi_gen_utils.c
+++ b/hw/acpi/acpi_gen_utils.c
@@ -2,7 +2,9 @@ 
 #include <stdarg.h>
 #include <assert.h>
 #include <stdbool.h>
+#include <string.h>
 #include "hw/acpi/acpi_gen_utils.h"
+#include "qemu/bswap.h"
 
 GArray *build_alloc_array(void)
 {
@@ -633,3 +635,32 @@  acpi_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
     build_append_byte(var.buf, pblk_len); /* PblkLen */
     return var;
 }
+
+static uint8_t Hex2Digit(char c)
+{
+    if (c >= 'A') {
+        return c - 'A' + 10;
+    }
+
+    return c - '0';
+}
+
+/* ACPI 5.0: 19.5.36 EISAID (EISA ID String To Integer Conversion Macro) */
+AcpiAml acpi_eisaid(const char *str)
+{
+    AcpiAml var = aml_allocate_internal(0, NON_BLOCK);
+    uint32_t id;
+
+    g_assert(strlen(str) == 7);
+    id = (str[0] - 0x40) << 26 |
+    (str[1] - 0x40) << 21 |
+    (str[2] - 0x40) << 16 |
+    Hex2Digit(str[3]) << 12 |
+    Hex2Digit(str[4]) << 8 |
+    Hex2Digit(str[5]) << 4 |
+    Hex2Digit(str[6]);
+
+    build_append_byte(var.buf, 0x0C); /* DWordPrefix */
+    build_append_value(var.buf, bswap32(id), sizeof(id));
+    return var;
+}
diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h
index 753171f..02d5aa8 100644
--- a/include/hw/acpi/acpi_gen_utils.h
+++ b/include/hw/acpi/acpi_gen_utils.h
@@ -64,6 +64,7 @@  AcpiAml acpi_equal(AcpiAml arg1, AcpiAml arg2);
 AcpiAml GCC_FMT_ATTR(4, 5)
 acpi_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
                const char *name_format, ...);
+AcpiAml acpi_eisaid(const char *str);
 
 /* Block ASL object primitives */
 AcpiAml acpi_if(AcpiAml predicate);