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>
This commit is contained in:
Duncan Laurie 2016-05-09 07:43:19 -07:00 committed by Duncan Laurie
parent 4650f5baff
commit 9ccae7558d
2 changed files with 33 additions and 33 deletions

View File

@ -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)

View File

@ -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);