ACPICA: Implement simplified Table Manager

The Table Manager component has been completely
redesigned and reimplemented. The new design is much
simpler, and reduces the overall code and data size of
the kernel-resident ACPICA by approximately 5%. Also,
it is now possible to obtain the ACPI tables very early
during kernel initialization, even before dynamic memory
management is initialized.

Signed-off-by: Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
diff --git a/drivers/acpi/hardware/hwsleep.c b/drivers/acpi/hardware/hwsleep.c
index 8bb43ca..6faa76b 100644
--- a/drivers/acpi/hardware/hwsleep.c
+++ b/drivers/acpi/hardware/hwsleep.c
@@ -43,6 +43,7 @@
  */
 
 #include <acpi/acpi.h>
+#include <acpi/actables.h>
 
 #define _COMPONENT          ACPI_HARDWARE
 ACPI_MODULE_NAME("hwsleep")
@@ -62,17 +63,32 @@
 acpi_status
 acpi_set_firmware_waking_vector(acpi_physical_address physical_address)
 {
+	struct acpi_table_facs *facs;
+	acpi_status status;
 
 	ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector);
 
+	/* Get the FACS */
+
+	status =
+	    acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
+				    (struct acpi_table_header **)&facs);
+	if (ACPI_FAILURE(status)) {
+		return_ACPI_STATUS(status);
+	}
+
 	/* Set the vector */
 
-	if (acpi_gbl_common_fACS.vector_width == 32) {
-		*(ACPI_CAST_PTR
-		  (u32, acpi_gbl_common_fACS.firmware_waking_vector))
-		    = (u32) physical_address;
+	if ((facs->length < 32) || (!(facs->xfirmware_waking_vector))) {
+		/*
+		 * ACPI 1.0 FACS or short table or optional X_ field is zero
+		 */
+		facs->firmware_waking_vector = (u32) physical_address;
 	} else {
-		*acpi_gbl_common_fACS.firmware_waking_vector = physical_address;
+		/*
+		 * ACPI 2.0 FACS with valid X_ field
+		 */
+		facs->xfirmware_waking_vector = physical_address;
 	}
 
 	return_ACPI_STATUS(AE_OK);
@@ -97,6 +113,8 @@
 acpi_status
 acpi_get_firmware_waking_vector(acpi_physical_address * physical_address)
 {
+	struct acpi_table_facs *facs;
+	acpi_status status;
 
 	ACPI_FUNCTION_TRACE(acpi_get_firmware_waking_vector);
 
@@ -104,16 +122,29 @@
 		return_ACPI_STATUS(AE_BAD_PARAMETER);
 	}
 
+	/* Get the FACS */
+
+	status =
+	    acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
+				    (struct acpi_table_header **)&facs);
+	if (ACPI_FAILURE(status)) {
+		return_ACPI_STATUS(status);
+	}
+
 	/* Get the vector */
 
-	if (acpi_gbl_common_fACS.vector_width == 32) {
-		*physical_address = (acpi_physical_address)
-		    *
-		    (ACPI_CAST_PTR
-		     (u32, acpi_gbl_common_fACS.firmware_waking_vector));
-	} else {
+	if ((facs->length < 32) || (!(facs->xfirmware_waking_vector))) {
+		/*
+		 * ACPI 1.0 FACS or short table or optional X_ field is zero
+		 */
 		*physical_address =
-		    *acpi_gbl_common_fACS.firmware_waking_vector;
+		    (acpi_physical_address) facs->firmware_waking_vector;
+	} else {
+		/*
+		 * ACPI 2.0 FACS with valid X_ field
+		 */
+		*physical_address =
+		    (acpi_physical_address) facs->xfirmware_waking_vector;
 	}
 
 	return_ACPI_STATUS(AE_OK);
@@ -429,8 +460,8 @@
 
 	ACPI_FLUSH_CPU_CACHE();
 
-	status = acpi_os_write_port(acpi_gbl_FADT->smi_cmd,
-				    (u32) acpi_gbl_FADT->S4bios_req, 8);
+	status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
+				    (u32) acpi_gbl_FADT.S4bios_request, 8);
 
 	do {
 		acpi_os_stall(1000);