blob: 525e6ea5c11491cf7aa27084bf2a29b0f3564a8d [file] [log] [blame]
Erik Schmauss95857632018-03-14 16:13:07 -07001// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/******************************************************************************
3 *
4 * Module Name: hwacpi - ACPI Hardware Initialization/Mode Interface
5 *
Bob Mooreda6f8322018-01-04 10:06:38 -08006 * Copyright (C) 2000 - 2018, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
Erik Schmauss95857632018-03-14 16:13:07 -07008 *****************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050011#include "accommon.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#define _COMPONENT ACPI_HARDWARE
Len Brown4be44fc2005-08-05 00:44:28 -040014ACPI_MODULE_NAME("hwacpi")
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Bob Moore33620c52012-02-14 18:14:27 +080016#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
Linus Torvalds1da177e2005-04-16 15:20:36 -070017/******************************************************************************
18 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * FUNCTION: acpi_hw_set_mode
20 *
Bob Mooreba494be2012-07-12 09:40:10 +080021 * PARAMETERS: mode - SYS_MODE_ACPI or SYS_MODE_LEGACY
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 *
23 * RETURN: Status
24 *
25 * DESCRIPTION: Transitions the system into the requested mode.
26 *
27 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040028acpi_status acpi_hw_set_mode(u32 mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029{
30
Len Brown4be44fc2005-08-05 00:44:28 -040031 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Bob Mooreb229cf92006-04-21 17:15:00 -040033 ACPI_FUNCTION_TRACE(hw_set_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Bob Moorec39660b2013-03-08 09:22:14 +000035 /* If the Hardware Reduced flag is set, machine is always in acpi mode */
36
37 if (acpi_gbl_reduced_hardware) {
38 return_ACPI_STATUS(AE_OK);
39 }
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 /*
42 * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
43 * system does not support mode transition.
44 */
Bob Mooref3d2e782007-02-02 19:48:18 +030045 if (!acpi_gbl_FADT.smi_command) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050046 ACPI_ERROR((AE_INFO,
47 "No SMI_CMD in FADT, mode transition failed"));
Len Brown4be44fc2005-08-05 00:44:28 -040048 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 }
50
51 /*
52 * ACPI 2.0 clarified the meaning of ACPI_ENABLE and ACPI_DISABLE
53 * in FADT: If it is zero, enabling or disabling is not supported.
54 * As old systems may have used zero for mode transition,
55 * we make sure both the numbers are zero to determine these
56 * transitions are not supported.
57 */
Bob Mooref3d2e782007-02-02 19:48:18 +030058 if (!acpi_gbl_FADT.acpi_enable && !acpi_gbl_FADT.acpi_disable) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050059 ACPI_ERROR((AE_INFO,
Bob Moored4913dc2009-03-06 10:05:18 +080060 "No ACPI mode transition supported in this system "
61 "(enable/disable both zero)"));
Len Brown4be44fc2005-08-05 00:44:28 -040062 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 }
64
65 switch (mode) {
66 case ACPI_SYS_MODE_ACPI:
67
68 /* BIOS should have disabled ALL fixed and GP events */
69
Bob Moore7f071902009-03-19 09:37:47 +080070 status = acpi_hw_write_port(acpi_gbl_FADT.smi_command,
Bob Mooref3d2e782007-02-02 19:48:18 +030071 (u32) acpi_gbl_FADT.acpi_enable, 8);
Len Brown4be44fc2005-08-05 00:44:28 -040072 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
73 "Attempting to enable ACPI mode\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 break;
75
76 case ACPI_SYS_MODE_LEGACY:
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 /*
78 * BIOS should clear all fixed status bits and restore fixed event
79 * enable bits to default
80 */
Bob Moore7f071902009-03-19 09:37:47 +080081 status = acpi_hw_write_port(acpi_gbl_FADT.smi_command,
Lv Zheng3e8214e2012-12-19 05:37:15 +000082 (u32)acpi_gbl_FADT.acpi_disable, 8);
Len Brown4be44fc2005-08-05 00:44:28 -040083 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
84 "Attempting to enable Legacy (non-ACPI) mode\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 break;
86
87 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +000088
Len Brown4be44fc2005-08-05 00:44:28 -040089 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 }
91
Len Brown4be44fc2005-08-05 00:44:28 -040092 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050093 ACPI_EXCEPTION((AE_INFO, status,
94 "Could not write ACPI mode change"));
Len Brown4be44fc2005-08-05 00:44:28 -040095 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 }
97
Len Brownb430acb2010-05-06 17:41:08 -040098 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}
100
Robert Moore44f6c012005-04-18 22:49:35 -0400101/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 *
103 * FUNCTION: acpi_hw_get_mode
104 *
105 * PARAMETERS: none
106 *
107 * RETURN: SYS_MODE_ACPI or SYS_MODE_LEGACY
108 *
Bob Moore73a30902012-10-31 02:26:55 +0000109 * DESCRIPTION: Return current operating state of system. Determined by
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 * querying the SCI_EN bit.
111 *
112 ******************************************************************************/
113
Len Brown4be44fc2005-08-05 00:44:28 -0400114u32 acpi_hw_get_mode(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
Len Brown4be44fc2005-08-05 00:44:28 -0400116 acpi_status status;
117 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Bob Mooreb229cf92006-04-21 17:15:00 -0400119 ACPI_FUNCTION_TRACE(hw_get_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Bob Moorec39660b2013-03-08 09:22:14 +0000121 /* If the Hardware Reduced flag is set, machine is always in acpi mode */
122
123 if (acpi_gbl_reduced_hardware) {
Bob Moorefd1af712013-03-08 09:22:23 +0000124 return_UINT32(ACPI_SYS_MODE_ACPI);
Bob Moorec39660b2013-03-08 09:22:14 +0000125 }
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 /*
128 * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
129 * system does not support mode transition.
130 */
Bob Mooref3d2e782007-02-02 19:48:18 +0300131 if (!acpi_gbl_FADT.smi_command) {
Bob Moorefd1af712013-03-08 09:22:23 +0000132 return_UINT32(ACPI_SYS_MODE_ACPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 }
134
Bob Moore50ffba12009-02-23 15:02:07 +0800135 status = acpi_read_bit_register(ACPI_BITREG_SCI_ENABLE, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400136 if (ACPI_FAILURE(status)) {
Bob Moorefd1af712013-03-08 09:22:23 +0000137 return_UINT32(ACPI_SYS_MODE_LEGACY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 }
139
140 if (value) {
Bob Moorefd1af712013-03-08 09:22:23 +0000141 return_UINT32(ACPI_SYS_MODE_ACPI);
Len Brown4be44fc2005-08-05 00:44:28 -0400142 } else {
Bob Moorefd1af712013-03-08 09:22:23 +0000143 return_UINT32(ACPI_SYS_MODE_LEGACY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 }
145}
Bob Moore33620c52012-02-14 18:14:27 +0800146
147#endif /* !ACPI_REDUCED_HARDWARE */