acpigen: Add an abstracted integer output method

In order to produce smaller AML and not rely on the caller to size the
output type appropriately add a helper function that will output an
appropriately sized integer.

To complete this also add helper functions for outputting the single
OpCode for Zero and One and Ones.

And finally add "name" variants of the helpers that will output a
complete sequence like "Name (_UID, Zero)".

Change-Id: I7ee4bc0a6347d15b8d49df357845a8bc2e517407
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14794
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
diff --git a/src/arch/x86/acpigen.c b/src/arch/x86/acpigen.c
index f274ea2..e051c82 100644
--- a/src/arch/x86/acpigen.c
+++ b/src/arch/x86/acpigen.c
@@ -123,6 +123,49 @@
 	acpigen_emit_dword((data >> 32) & 0xffffffff);
 }
 
+void acpigen_write_zero(void)
+{
+	acpigen_emit_byte(0x00);
+}
+
+void acpigen_write_one(void)
+{
+	acpigen_emit_byte(0x01);
+}
+
+void acpigen_write_ones(void)
+{
+	acpigen_emit_byte(0xff);
+}
+
+void acpigen_write_integer(uint64_t data)
+{
+	if (data == 0)
+		acpigen_write_zero();
+	else if (data == 1)
+		acpigen_write_one();
+	else if (data <= 0xff)
+		acpigen_write_byte((unsigned char)data);
+	else if (data <= 0xffff)
+		acpigen_write_word((unsigned int)data);
+	else if (data <= 0xffffffff)
+		acpigen_write_dword((unsigned int)data);
+	else
+		acpigen_write_qword(data);
+}
+
+void acpigen_write_name_zero(const char *name)
+{
+	acpigen_write_name(name);
+	acpigen_write_one();
+}
+
+void acpigen_write_name_one(const char *name)
+{
+	acpigen_write_name(name);
+	acpigen_write_zero();
+}
+
 void acpigen_write_name_byte(const char *name, uint8_t val)
 {
 	acpigen_write_name(name);
@@ -141,6 +184,12 @@
 	acpigen_write_qword(val);
 }
 
+void acpigen_write_name_integer(const char *name, uint64_t val)
+{
+	acpigen_write_name(name);
+	acpigen_write_integer(val);
+}
+
 void acpigen_write_name_string(const char *name, const char *string)
 {
 	acpigen_write_name(name);