Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Module Name: hwacpi - ACPI Hardware Initialization/Mode Interface |
| 5 | * |
Bob Moore | da6f832 | 2018-01-04 10:06:38 -0800 | [diff] [blame] | 6 | * Copyright (C) 2000 - 2018, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 8 | *****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 11 | #include "accommon.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #define _COMPONENT ACPI_HARDWARE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 14 | ACPI_MODULE_NAME("hwacpi") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 16 | #if (!ACPI_REDUCED_HARDWARE) /* Entire module */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | /****************************************************************************** |
| 18 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * FUNCTION: acpi_hw_set_mode |
| 20 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 21 | * PARAMETERS: mode - SYS_MODE_ACPI or SYS_MODE_LEGACY |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | * |
| 23 | * RETURN: Status |
| 24 | * |
| 25 | * DESCRIPTION: Transitions the system into the requested mode. |
| 26 | * |
| 27 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 28 | acpi_status acpi_hw_set_mode(u32 mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | { |
| 30 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 31 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 33 | ACPI_FUNCTION_TRACE(hw_set_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Bob Moore | c39660b | 2013-03-08 09:22:14 +0000 | [diff] [blame] | 35 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | /* |
| 42 | * ACPI 2.0 clarified that if SMI_CMD in FADT is zero, |
| 43 | * system does not support mode transition. |
| 44 | */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 45 | if (!acpi_gbl_FADT.smi_command) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 46 | ACPI_ERROR((AE_INFO, |
| 47 | "No SMI_CMD in FADT, mode transition failed")); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 48 | return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
| 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 Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 58 | if (!acpi_gbl_FADT.acpi_enable && !acpi_gbl_FADT.acpi_disable) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 59 | ACPI_ERROR((AE_INFO, |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 60 | "No ACPI mode transition supported in this system " |
| 61 | "(enable/disable both zero)")); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 62 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | switch (mode) { |
| 66 | case ACPI_SYS_MODE_ACPI: |
| 67 | |
| 68 | /* BIOS should have disabled ALL fixed and GP events */ |
| 69 | |
Bob Moore | 7f07190 | 2009-03-19 09:37:47 +0800 | [diff] [blame] | 70 | status = acpi_hw_write_port(acpi_gbl_FADT.smi_command, |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 71 | (u32) acpi_gbl_FADT.acpi_enable, 8); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 72 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 73 | "Attempting to enable ACPI mode\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | break; |
| 75 | |
| 76 | case ACPI_SYS_MODE_LEGACY: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | /* |
| 78 | * BIOS should clear all fixed status bits and restore fixed event |
| 79 | * enable bits to default |
| 80 | */ |
Bob Moore | 7f07190 | 2009-03-19 09:37:47 +0800 | [diff] [blame] | 81 | status = acpi_hw_write_port(acpi_gbl_FADT.smi_command, |
Lv Zheng | 3e8214e | 2012-12-19 05:37:15 +0000 | [diff] [blame] | 82 | (u32)acpi_gbl_FADT.acpi_disable, 8); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 83 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 84 | "Attempting to enable Legacy (non-ACPI) mode\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | break; |
| 86 | |
| 87 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 88 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 89 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 92 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 93 | ACPI_EXCEPTION((AE_INFO, status, |
| 94 | "Could not write ACPI mode change")); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 95 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Len Brown | b430acb | 2010-05-06 17:41:08 -0400 | [diff] [blame] | 98 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 101 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | * |
| 103 | * FUNCTION: acpi_hw_get_mode |
| 104 | * |
| 105 | * PARAMETERS: none |
| 106 | * |
| 107 | * RETURN: SYS_MODE_ACPI or SYS_MODE_LEGACY |
| 108 | * |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 109 | * DESCRIPTION: Return current operating state of system. Determined by |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | * querying the SCI_EN bit. |
| 111 | * |
| 112 | ******************************************************************************/ |
| 113 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 114 | u32 acpi_hw_get_mode(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 116 | acpi_status status; |
| 117 | u32 value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 119 | ACPI_FUNCTION_TRACE(hw_get_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
Bob Moore | c39660b | 2013-03-08 09:22:14 +0000 | [diff] [blame] | 121 | /* If the Hardware Reduced flag is set, machine is always in acpi mode */ |
| 122 | |
| 123 | if (acpi_gbl_reduced_hardware) { |
Bob Moore | fd1af71 | 2013-03-08 09:22:23 +0000 | [diff] [blame] | 124 | return_UINT32(ACPI_SYS_MODE_ACPI); |
Bob Moore | c39660b | 2013-03-08 09:22:14 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | /* |
| 128 | * ACPI 2.0 clarified that if SMI_CMD in FADT is zero, |
| 129 | * system does not support mode transition. |
| 130 | */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 131 | if (!acpi_gbl_FADT.smi_command) { |
Bob Moore | fd1af71 | 2013-03-08 09:22:23 +0000 | [diff] [blame] | 132 | return_UINT32(ACPI_SYS_MODE_ACPI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Bob Moore | 50ffba1 | 2009-02-23 15:02:07 +0800 | [diff] [blame] | 135 | status = acpi_read_bit_register(ACPI_BITREG_SCI_ENABLE, &value); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 136 | if (ACPI_FAILURE(status)) { |
Bob Moore | fd1af71 | 2013-03-08 09:22:23 +0000 | [diff] [blame] | 137 | return_UINT32(ACPI_SYS_MODE_LEGACY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | if (value) { |
Bob Moore | fd1af71 | 2013-03-08 09:22:23 +0000 | [diff] [blame] | 141 | return_UINT32(ACPI_SYS_MODE_ACPI); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 142 | } else { |
Bob Moore | fd1af71 | 2013-03-08 09:22:23 +0000 | [diff] [blame] | 143 | return_UINT32(ACPI_SYS_MODE_LEGACY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | } |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 146 | |
| 147 | #endif /* !ACPI_REDUCED_HARDWARE */ |