acpigen: Add helpers for word/dword output

Add helpers for writing word and dword values in acpigen and use them
throughout the file to clean things up:

acpigen_emit_word - write raw word
acpigen_emit_dword - write raw dword
acpigen_write_word - write word opcode and value

Change-Id: Ia758d4dd25d0ae5b31be7d51b33866dddd96a473
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14792
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
diff --git a/src/arch/x86/acpigen.c b/src/arch/x86/acpigen.c
index 1a23bdc..a612149 100644
--- a/src/arch/x86/acpigen.c
+++ b/src/arch/x86/acpigen.c
@@ -72,6 +72,20 @@
 	(*gencurrent++) = b;
 }
 
+void acpigen_emit_word(unsigned int data)
+{
+	acpigen_emit_byte(data & 0xff);
+	acpigen_emit_byte((data >> 8) & 0xff);
+}
+
+void acpigen_emit_dword(unsigned int data)
+{
+	acpigen_emit_byte(data & 0xff);
+	acpigen_emit_byte((data >> 8) & 0xff);
+	acpigen_emit_byte((data >> 16) & 0xff);
+	acpigen_emit_byte((data >> 24) & 0xff);
+}
+
 void acpigen_write_package(int nr_el)
 {
 	/* package op */
@@ -87,28 +101,26 @@
 	acpigen_emit_byte(data & 0xff);
 }
 
+void acpigen_write_word(unsigned int data)
+{
+	/* word op */
+	acpigen_emit_byte(0xb);
+	acpigen_emit_word(data);
+}
+
 void acpigen_write_dword(unsigned int data)
 {
 	/* dword op */
 	acpigen_emit_byte(0xc);
-	acpigen_emit_byte(data & 0xff);
-	acpigen_emit_byte((data >> 8) & 0xff);
-	acpigen_emit_byte((data >> 16) & 0xff);
-	acpigen_emit_byte((data >> 24) & 0xff);
+	acpigen_emit_dword(data);
 }
 
 void acpigen_write_qword(uint64_t data)
 {
 	/* qword op */
 	acpigen_emit_byte(0xe);
-	acpigen_emit_byte(data & 0xff);
-	acpigen_emit_byte((data >> 8) & 0xff);
-	acpigen_emit_byte((data >> 16) & 0xff);
-	acpigen_emit_byte((data >> 24) & 0xff);
-	acpigen_emit_byte((data >> 32) & 0xff);
-	acpigen_emit_byte((data >> 40) & 0xff);
-	acpigen_emit_byte((data >> 48) & 0xff);
-	acpigen_emit_byte((data >> 56) & 0xff);
+	acpigen_emit_dword(data & 0xffffffff);
+	acpigen_emit_dword((data >> 32) & 0xffffffff);
 }
 
 void acpigen_write_name_byte(const char *name, uint8_t val)
@@ -261,10 +273,7 @@
 		 "\\_PR.CP%02d", (unsigned int) cpuindex);
 	acpigen_emit_namestring(pscope);
 	acpigen_emit_byte(cpuindex);
-	acpigen_emit_byte(pblock_addr & 0xff);
-	acpigen_emit_byte((pblock_addr >> 8) & 0xff);
-	acpigen_emit_byte((pblock_addr >> 16) & 0xff);
-	acpigen_emit_byte((pblock_addr >> 24) & 0xff);
+	acpigen_emit_dword(pblock_addr);
 	acpigen_emit_byte(pblock_len);
 }
 
@@ -366,7 +375,7 @@
 
 void acpigen_write_device(const char *name)
 {
-	/* method op */
+	/* device op */
 	acpigen_emit_byte(0x5b);
 	acpigen_emit_byte(0x82);
 	acpigen_write_len_f();
@@ -557,14 +566,8 @@
 	acpigen_emit_byte(0x00);
 	/* bit1-7 are ignored */
 	acpigen_emit_byte(readwrite ? 0x01 : 0x00);
-	acpigen_emit_byte(base & 0xff);
-	acpigen_emit_byte((base >> 8) & 0xff);
-	acpigen_emit_byte((base >> 16) & 0xff);
-	acpigen_emit_byte((base >> 24) & 0xff);
-	acpigen_emit_byte(size & 0xff);
-	acpigen_emit_byte((size >> 8) & 0xff);
-	acpigen_emit_byte((size >> 16) & 0xff);
-	acpigen_emit_byte((size >> 24) & 0xff);
+	acpigen_emit_dword(base);
+	acpigen_emit_dword(size);
 }
 
 void acpigen_write_register(acpi_addr_t *addr)
@@ -576,14 +579,8 @@
 	acpigen_emit_byte(addr->bit_width);	/* Register Bit Width */
 	acpigen_emit_byte(addr->bit_offset);	/* Register Bit Offset */
 	acpigen_emit_byte(addr->resv);		/* Register Access Size */
-	acpigen_emit_byte(addr->addrl & 0xff);	/* Register Address Low */
-	acpigen_emit_byte((addr->addrl >> 8) & 0xff);
-	acpigen_emit_byte((addr->addrl >> 16) & 0xff);
-	acpigen_emit_byte((addr->addrl >> 24) & 0xff);
-	acpigen_emit_byte(addr->addrh & 0xff);	/* Register Address High */
-	acpigen_emit_byte((addr->addrh >> 8) & 0xff);
-	acpigen_emit_byte((addr->addrh >> 16) & 0xff);
-	acpigen_emit_byte((addr->addrh >> 24) & 0xff);
+	acpigen_emit_dword(addr->addrl);	/* Register Address Low */
+	acpigen_emit_dword(addr->addrh);	/* Register Address High */
 }
 
 void acpigen_write_irq(u16 mask)