[PATCH 1/4] acpi: Add aml_generic_register

2020-02-12 Thread Ying Fang
The generic register descriptor describes the localtion of a
fixed width register within any of the ACPI-defined address space.

This is needed to declare the ACPI CPPC registers.

Signed-off-by: Heyi Guo 
Signed-off-by: Ying Fang 
---
 hw/acpi/aml-build.c | 22 ++
 include/hw/acpi/aml-build.h |  3 +++
 2 files changed, 25 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 2c3702b882..79b1431f07 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -1370,6 +1370,28 @@ Aml *aml_sleep(uint64_t msec)
 return var;
 }
 
+/* ACPI 5.0b: 6.4.3.7 Generic Register Descriptor */
+Aml *aml_generic_register(AmlRegionSpace rs, uint8_t reg_width,
+  uint8_t reg_offset, AmlAccessType type, uint64_t 
addr)
+{
+int i;
+Aml *var = aml_alloc();
+build_append_byte(var->buf, 0x82); /* Generic Register Descriptor */
+build_append_byte(var->buf, 0x0C); /* Length, bits[7:0] value = 0x0C */
+build_append_byte(var->buf, 0);/* Length, bits[15:8] value = 0 */
+build_append_byte(var->buf, rs);   /* Address Space ID */
+build_append_byte(var->buf, reg_width);   /* Register Bit Width */
+build_append_byte(var->buf, reg_offset);  /* Register Bit Offset */
+build_append_byte(var->buf, type);/* Access Size */
+
+/* Register address */
+for (i = 0; i < 8; i++) {
+build_append_byte(var->buf, extract64(addr, i * 8, 8));
+}
+
+return var;
+}
+
 static uint8_t Hex2Byte(const char *src)
 {
 int hi, lo;
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index de4a406568..37a047b156 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -364,6 +364,9 @@ Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed,
 Aml *aml_dma(AmlDmaType typ, AmlDmaBusMaster bm, AmlTransferSize sz,
  uint8_t channel);
 Aml *aml_sleep(uint64_t msec);
+Aml *aml_generic_register(AmlRegionSpace rs, uint8_t reg_width,
+  uint8_t reg_offset, AmlAccessType type,
+  uint64_t addr);
 Aml *aml_i2c_serial_bus_device(uint16_t address, const char *resource_source);
 
 /* Block AML object primitives */
-- 
2.19.1





[PATCH 1/4] acpi: Add aml_generic_register

2020-02-12 Thread fangying1
From: Ying Fang 

The generic register descriptor describes the localtion of a
fixed width register within any of the ACPI-defined address space.

This is needed to declare the ACPI CPPC registers.

Signed-off-by: Heyi Guo 
Signed-off-by: Ying Fang 
---
 hw/acpi/aml-build.c | 22 ++
 include/hw/acpi/aml-build.h |  3 +++
 2 files changed, 25 insertions(+)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 2c3702b882..79b1431f07 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -1370,6 +1370,28 @@ Aml *aml_sleep(uint64_t msec)
 return var;
 }
 
+/* ACPI 5.0b: 6.4.3.7 Generic Register Descriptor */
+Aml *aml_generic_register(AmlRegionSpace rs, uint8_t reg_width,
+  uint8_t reg_offset, AmlAccessType type, uint64_t 
addr)
+{
+int i;
+Aml *var = aml_alloc();
+build_append_byte(var->buf, 0x82); /* Generic Register Descriptor */
+build_append_byte(var->buf, 0x0C); /* Length, bits[7:0] value = 0x0C */
+build_append_byte(var->buf, 0);/* Length, bits[15:8] value = 0 */
+build_append_byte(var->buf, rs);   /* Address Space ID */
+build_append_byte(var->buf, reg_width);   /* Register Bit Width */
+build_append_byte(var->buf, reg_offset);  /* Register Bit Offset */
+build_append_byte(var->buf, type);/* Access Size */
+
+/* Register address */
+for (i = 0; i < 8; i++) {
+build_append_byte(var->buf, extract64(addr, i * 8, 8));
+}
+
+return var;
+}
+
 static uint8_t Hex2Byte(const char *src)
 {
 int hi, lo;
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index de4a406568..37a047b156 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -364,6 +364,9 @@ Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed,
 Aml *aml_dma(AmlDmaType typ, AmlDmaBusMaster bm, AmlTransferSize sz,
  uint8_t channel);
 Aml *aml_sleep(uint64_t msec);
+Aml *aml_generic_register(AmlRegionSpace rs, uint8_t reg_width,
+  uint8_t reg_offset, AmlAccessType type,
+  uint64_t addr);
 Aml *aml_i2c_serial_bus_device(uint16_t address, const char *resource_source);
 
 /* Block AML object primitives */
-- 
2.19.1