From 9ccae7558d41daa84240c93fd9aeec59171c3f9e Mon Sep 17 00:00:00 2001 From: Duncan Laurie Date: Mon, 9 May 2016 07:43:19 -0700 Subject: 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 Reviewed-on: https://review.coreboot.org/14792 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer Reviewed-by: Paul Menzel --- src/arch/x86/acpigen.c | 63 ++++++++++++++++++------------------- src/arch/x86/include/arch/acpigen.h | 3 ++ 2 files changed, 33 insertions(+), 33 deletions(-) (limited to 'src/arch') diff --git a/src/arch/x86/acpigen.c b/src/arch/x86/acpigen.c index 1a23bdc1a0..a612149ef2 100644 --- a/src/arch/x86/acpigen.c +++ b/src/arch/x86/acpigen.c @@ -72,6 +72,20 @@ void acpigen_emit_byte(unsigned char b) (*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 @@ void acpigen_write_byte(unsigned int data) 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 @@ void acpigen_write_processor(u8 cpuindex, u32 pblock_addr, u8 pblock_len) "\\_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_method(const char *name, int nargs) 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 @@ void acpigen_write_mem32fixed(int readwrite, u32 base, u32 size) 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 @@ void acpigen_write_register(acpi_addr_t *addr) 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) diff --git a/src/arch/x86/include/arch/acpigen.h b/src/arch/x86/include/arch/acpigen.h index 1ad021ada9..9323475dfd 100644 --- a/src/arch/x86/include/arch/acpigen.h +++ b/src/arch/x86/include/arch/acpigen.h @@ -29,9 +29,12 @@ char *acpigen_get_current(void); void acpigen_write_package(int nr_el); void acpigen_write_byte(unsigned int data); void acpigen_emit_byte(unsigned char data); +void acpigen_emit_word(unsigned int data); +void acpigen_emit_dword(unsigned int data); void acpigen_emit_stream(const char *data, int size); void acpigen_emit_namestring(const char *namepath); void acpigen_emit_eisaid(const char *eisaid); +void acpigen_write_word(unsigned int data); void acpigen_write_dword(unsigned int data); void acpigen_write_qword(uint64_t data); void acpigen_write_name(const char *name); -- cgit v1.2.3