1 /******************************************************************************
3 * Module Name: oswintbl - Windows OSL for obtaining ACPI tables
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
50 #pragma warning(disable:4115) /* warning C4115: (caused by rpcasync.h) */
57 #define _COMPONENT ACPI_OS_SERVICES
58 ACPI_MODULE_NAME ("oswintbl")
60 /* Local prototypes */
63 WindowsFormatException (
68 #define LOCAL_BUFFER_SIZE 64
70 static char KeyBuffer[LOCAL_BUFFER_SIZE];
71 static char ErrorBuffer[LOCAL_BUFFER_SIZE];
74 * Tables supported in the Windows registry. SSDTs are not placed into
75 * the registry, a limitation.
77 static char *SupportedTables[] =
85 /* Max index for table above */
87 #define ACPI_OS_MAX_TABLE_INDEX 3
90 /******************************************************************************
92 * FUNCTION: WindowsFormatException
94 * PARAMETERS: WinStatus - Status from a Windows system call
96 * RETURN: Formatted (ascii) exception code. Front-end to Windows
97 * FormatMessage interface.
99 * DESCRIPTION: Decode a windows exception
101 *****************************************************************************/
104 WindowsFormatException (
109 FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, WinStatus, 0,
110 ErrorBuffer, LOCAL_BUFFER_SIZE, NULL);
112 return (ErrorBuffer);
116 /******************************************************************************
118 * FUNCTION: AcpiOsGetTableByAddress
120 * PARAMETERS: Address - Physical address of the ACPI table
121 * Table - Where a pointer to the table is returned
123 * RETURN: Status; Table buffer is returned if AE_OK.
124 * AE_NOT_FOUND: A valid table was not found at the address
126 * DESCRIPTION: Get an ACPI table via a physical memory address.
128 * NOTE: Cannot be implemented without a Windows device driver.
130 *****************************************************************************/
133 AcpiOsGetTableByAddress (
134 ACPI_PHYSICAL_ADDRESS Address,
135 ACPI_TABLE_HEADER **Table)
138 fprintf (stderr, "Get table by address is not supported on Windows\n");
143 /******************************************************************************
145 * FUNCTION: AcpiOsGetTableByIndex
147 * PARAMETERS: Index - Which table to get
148 * Table - Where a pointer to the table is returned
149 * Instance - Where a pointer to the table instance no. is
151 * Address - Where the table physical address is returned
153 * RETURN: Status; Table buffer and physical address returned if AE_OK.
154 * AE_LIMIT: Index is beyond valid limit
156 * DESCRIPTION: Get an ACPI table via an index value (0 through n). Returns
157 * AE_LIMIT when an invalid index is reached. Index is not
158 * necessarily an index into the RSDT/XSDT.
159 * Table is obtained from the Windows registry.
161 * NOTE: Cannot get the physical address from the windows registry;
162 * zero is returned instead.
164 *****************************************************************************/
167 AcpiOsGetTableByIndex (
169 ACPI_TABLE_HEADER **Table,
171 ACPI_PHYSICAL_ADDRESS *Address)
176 if (Index > ACPI_OS_MAX_TABLE_INDEX)
181 Status = AcpiOsGetTableByName (SupportedTables[Index], 0, Table, Address);
186 /******************************************************************************
188 * FUNCTION: AcpiOsGetTableByName
190 * PARAMETERS: Signature - ACPI Signature for desired table. Must be
191 * a null terminated 4-character string.
192 * Instance - For SSDTs (0...n). Use 0 otherwise.
193 * Table - Where a pointer to the table is returned
194 * Address - Where the table physical address is returned
196 * RETURN: Status; Table buffer and physical address returned if AE_OK.
197 * AE_LIMIT: Instance is beyond valid limit
198 * AE_NOT_FOUND: A table with the signature was not found
200 * DESCRIPTION: Get an ACPI table via a table signature (4 ASCII characters).
201 * Returns AE_LIMIT when an invalid instance is reached.
202 * Table is obtained from the Windows registry.
204 * NOTE: Assumes the input signature is uppercase.
205 * Cannot get the physical address from the windows registry;
206 * zero is returned instead.
208 *****************************************************************************/
211 AcpiOsGetTableByName (
214 ACPI_TABLE_HEADER **Table,
215 ACPI_PHYSICAL_ADDRESS *Address)
224 ACPI_TABLE_HEADER *ReturnTable;
225 ACPI_STATUS Status = AE_OK;
229 * Windows has no SSDTs in the registry, so multiple instances are
237 /* Get a handle to the table key */
241 ACPI_STRCPY (KeyBuffer, "HARDWARE\\ACPI\\");
242 if (AcpiUtSafeStrcat (KeyBuffer, sizeof (KeyBuffer), Signature))
244 return (AE_BUFFER_OVERFLOW);
247 WinStatus = RegOpenKeyEx (HKEY_LOCAL_MACHINE, KeyBuffer,
248 0L, KEY_READ, &Handle);
250 if (WinStatus != ERROR_SUCCESS)
253 * Somewhere along the way, MS changed the registry entry for
255 * HARDWARE/ACPI/FACP to
256 * HARDWARE/ACPI/FADT.
258 * This code allows for both.
260 if (ACPI_COMPARE_NAME (Signature, "FACP"))
264 else if (ACPI_COMPARE_NAME (Signature, "XSDT"))
271 "Could not find %s in registry at %s: %s (WinStatus=0x%X)\n",
272 Signature, KeyBuffer, WindowsFormatException (WinStatus), WinStatus);
273 return (AE_NOT_FOUND);
282 /* Actual data for the table is down a couple levels */
286 WinStatus = RegEnumKey (Handle, i, KeyBuffer, sizeof (KeyBuffer));
288 if (WinStatus == ERROR_NO_MORE_ITEMS)
293 WinStatus = RegOpenKey (Handle, KeyBuffer, &SubKey);
294 if (WinStatus != ERROR_SUCCESS)
296 fprintf (stderr, "Could not open %s entry: %s\n",
297 Signature, WindowsFormatException (WinStatus));
302 RegCloseKey (Handle);
307 /* Find the (binary) table entry */
311 NameSize = sizeof (KeyBuffer);
312 WinStatus = RegEnumValue (Handle, i, KeyBuffer, &NameSize, NULL,
314 if (WinStatus != ERROR_SUCCESS)
316 fprintf (stderr, "Could not get %s registry entry: %s\n",
317 Signature, WindowsFormatException (WinStatus));
322 if (Type == REG_BINARY)
328 /* Get the size of the table */
330 WinStatus = RegQueryValueEx (Handle, KeyBuffer, NULL, NULL,
332 if (WinStatus = ERROR_SUCCESS)
334 fprintf (stderr, "Could not read the %s table size: %s\n",
335 Signature, WindowsFormatException (WinStatus));
340 /* Allocate a new buffer for the table */
342 ReturnTable = malloc (DataSize);
345 Status = AE_NO_MEMORY;
349 /* Get the actual table from the registry */
351 WinStatus = RegQueryValueEx (Handle, KeyBuffer, NULL, NULL,
352 (UCHAR *) ReturnTable, &DataSize);
353 if (WinStatus = ERROR_SUCCESS)
355 fprintf (stderr, "Could not read %s data: %s\n",
356 Signature, WindowsFormatException (WinStatus));
362 *Table = ReturnTable;
366 RegCloseKey (Handle);
371 /* These are here for acpidump only, so we don't need to link oswinxf */
374 /******************************************************************************
376 * FUNCTION: AcpiOsMapMemory
378 * PARAMETERS: Where - Physical address of memory to be mapped
379 * Length - How much memory to map
381 * RETURN: Pointer to mapped memory. Null on error.
383 * DESCRIPTION: Map physical memory into caller's address space
385 *****************************************************************************/
389 ACPI_PHYSICAL_ADDRESS Where,
393 return (ACPI_TO_POINTER ((ACPI_SIZE) Where));
397 /******************************************************************************
399 * FUNCTION: AcpiOsUnmapMemory
401 * PARAMETERS: Where - Logical address of memory to be unmapped
402 * Length - How much memory to unmap
406 * DESCRIPTION: Delete a previously created mapping. Where and Length must
407 * correspond to a previous mapping exactly.
409 *****************************************************************************/