@@ -574,9 +574,12 @@ static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus,
Aml *aml_pci_device_dsm(void)
{
- Aml *method, *UUID, *ifctx, *ifctx1, *ifctx2, *ifctx3, *elsectx;
- Aml *acpi_index = aml_local(0);
+ Aml *method, *UUID, *ifctx, *ifctx1;
+ Aml *ret = aml_local(0);
+ Aml *caps = aml_local(1);
+ Aml *acpi_index = aml_local(2);
Aml *zero = aml_int(0);
+ Aml *one = aml_int(1);
Aml *bnum = aml_arg(4);
Aml *func = aml_arg(2);
Aml *rev = aml_arg(1);
@@ -584,73 +587,85 @@ Aml *aml_pci_device_dsm(void)
method = aml_method("PDSM", 6, AML_SERIALIZED);
+ /* get supported functions */
+ ifctx = aml_if(aml_equal(func, zero));
+ {
+ uint8_t byte_list[1] = { 0 }; /* nothing supported yet */
+ aml_append(ifctx, aml_store(aml_buffer(1, byte_list), ret));
+ aml_append(ifctx, aml_store(zero, caps));
+
+ /*
+ * PCI Firmware Specification 3.1
+ * 4.6. _DSM Definitions for PCI
+ */
+ UUID = aml_touuid("E5C937D0-3553-4D7A-9117-EA4D19C3434D");
+ ifctx1 = aml_if(aml_lnot(aml_equal(aml_arg(0), UUID)));
+ {
+ /* call is for unsupported UUID, bail out */
+ aml_append(ifctx1, aml_return(ret));
+ }
+ aml_append(ifctx, ifctx1);
+
+ ifctx1 = aml_if(aml_lless(rev, aml_int(2)));
+ {
+ /* call is for unsupported REV, bail out */
+ aml_append(ifctx1, aml_return(ret));
+ }
+ aml_append(ifctx, ifctx1);
+
+ aml_append(ifctx,
+ aml_store(aml_call2("AIDX", bnum, sunum), acpi_index));
+ /*
+ * advertise function 7 if device has acpi-index
+ * acpi_index values:
+ * 0: not present (default value)
+ * FFFFFFFF: not supported (old QEMU without PIDX reg)
+ * other: device's acpi-index
+ */
+ ifctx1 = aml_if(aml_lnot(
+ aml_or(aml_equal(acpi_index, zero),
+ aml_equal(acpi_index, aml_int(0xFFFFFFFF)), NULL)
+ ));
+ {
+ /* have supported functions */
+ aml_append(ifctx1, aml_or(caps, one, caps));
+ /* support for function 7 */
+ aml_append(ifctx1,
+ aml_or(caps, aml_shiftleft(one, aml_int(7)), caps));
+ }
+ aml_append(ifctx, ifctx1);
+
+ aml_append(ifctx, aml_store(caps, aml_index(ret, zero)));
+ aml_append(ifctx, aml_return(ret));
+ }
+ aml_append(method, ifctx);
+
+ /* handle specific functions requests */
/*
* PCI Firmware Specification 3.1
- * 4.6. _DSM Definitions for PCI
+ * 4.6.7. _DSM for Naming a PCI or PCI Express Device Under
+ * Operating Systems
*/
- UUID = aml_touuid("E5C937D0-3553-4D7A-9117-EA4D19C3434D");
- ifctx = aml_if(aml_equal(aml_arg(0), UUID));
+ ifctx = aml_if(aml_equal(func, aml_int(7)));
{
- aml_append(ifctx, aml_store(aml_call2("AIDX", bnum, sunum), acpi_index));
- ifctx1 = aml_if(aml_equal(func, zero));
- {
- uint8_t byte_list[1];
+ Aml *pkg = aml_package(2);
- ifctx2 = aml_if(aml_equal(rev, aml_int(2)));
- {
- /*
- * advertise function 7 if device has acpi-index
- * acpi_index values:
- * 0: not present (default value)
- * FFFFFFFF: not supported (old QEMU without PIDX reg)
- * other: device's acpi-index
- */
- ifctx3 = aml_if(aml_lnot(
- aml_or(aml_equal(acpi_index, zero),
- aml_equal(acpi_index, aml_int(0xFFFFFFFF)), NULL)
- ));
- {
- byte_list[0] =
- 1 /* have supported functions */ |
- 1 << 7 /* support for function 7 */
- ;
- aml_append(ifctx3, aml_return(aml_buffer(1, byte_list)));
- }
- aml_append(ifctx2, ifctx3);
- }
- aml_append(ifctx1, ifctx2);
-
- byte_list[0] = 0; /* nothing supported */
- aml_append(ifctx1, aml_return(aml_buffer(1, byte_list)));
- }
- aml_append(ifctx, ifctx1);
- elsectx = aml_else();
- /*
- * PCI Firmware Specification 3.1
- * 4.6.7. _DSM for Naming a PCI or PCI Express Device Under
- * Operating Systems
- */
- ifctx1 = aml_if(aml_equal(func, aml_int(7)));
- {
- Aml *pkg = aml_package(2);
- Aml *ret = aml_local(1);
-
- aml_append(pkg, zero);
- /*
- * optional, if not impl. should return null string
- */
- aml_append(pkg, aml_string("%s", ""));
- aml_append(ifctx1, aml_store(pkg, ret));
- /*
- * update acpi-index to actual value
- */
- aml_append(ifctx1, aml_store(acpi_index, aml_index(ret, zero)));
- aml_append(ifctx1, aml_return(ret));
- }
- aml_append(elsectx, ifctx1);
- aml_append(ifctx, elsectx);
+ aml_append(pkg, zero);
+ /*
+ * optional, if not impl. should return null string
+ */
+ aml_append(pkg, aml_string("%s", ""));
+ aml_append(ifctx, aml_store(pkg, ret));
+
+ aml_append(ifctx, aml_store(aml_call2("AIDX", bnum, sunum), acpi_index));
+ /*
+ * update acpi-index to actual value
+ */
+ aml_append(ifctx, aml_store(acpi_index, aml_index(ret, zero)));
}
+
aml_append(method, ifctx);
+ aml_append(method, aml_return(ret));
return method;
}
.., it will help with code readability and make easier to extend method in followup patches Signed-off-by: Igor Mammedov <imammedo@redhat.com> --- hw/i386/acpi-build.c | 139 ++++++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 62 deletions(-)