blob: e112fe814cd4b08a9a2dff48b64a4400a3798e61 [file] [log] [blame]
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001/*
2 *****************************************************************************
3 *
4 * Copyright (c) 2011, Advanced Micro Devices, Inc.
5 * All rights reserved.
Edward O'Callaghanef5981b2014-07-06 19:20:52 +10006 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +00007 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
Edward O'Callaghanef5981b2014-07-06 19:20:52 +100014 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
15 * its contributors may be used to endorse or promote products derived
Frank Vibrans2b4c8312011-02-14 18:30:54 +000016 * from this software without specific prior written permission.
Edward O'Callaghanef5981b2014-07-06 19:20:52 +100017 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +000018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Edward O'Callaghanef5981b2014-07-06 19:20:52 +100028 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +000029 * ***************************************************************************
30 *
31 */
32
33#include "SBPLATFORM.h"
34#include "cbtypes.h"
35
36//
37//
38// Routine Description:
39//
40// Locate ACPI table
41//
42// Arguments:
43//
44// Signature - table signature
45//
46//Returns:
47//
48// pointer to ACPI table
49//
50//
51VOID*
52ACPI_LocateTable (
53 IN UINT32 Signature
54 )
55{
56 UINT32 i;
57 UINT32* RsdPtr;
58 UINT32* Rsdt;
59 UINTN tableOffset;
60 DESCRIPTION_HEADER* CurrentTable;
61
62 RsdPtr = (UINT32*) (UINTN)0xe0000;
63 Rsdt = NULL;
64 do {
65 if ( *RsdPtr == Int32FromChar('R', 'S', 'D', ' ') && *(RsdPtr + 1) == Int32FromChar('P', 'T', 'R', ' ')) {
Marc Jonesf2592f92018-08-23 10:33:29 -060066 Rsdt = (UINT32*) (UINTN) ((RSDP_HEADER*)RsdPtr)->RsdtAddress;
Frank Vibrans2b4c8312011-02-14 18:30:54 +000067 break;
68 }
69 RsdPtr += 4;
70 } while ( RsdPtr <= (UINT32*) (UINTN)0xffff0 );
71 if ( Rsdt != NULL && ACPI_GetTableChecksum (Rsdt) == 0 ) {
72 for ( i = 0; i < (((DESCRIPTION_HEADER*)Rsdt)->Length - sizeof (DESCRIPTION_HEADER)) / 4; i++ ) {
73 tableOffset = *(UINTN*) ((UINT8*)Rsdt + sizeof (DESCRIPTION_HEADER) + i * 4);
74 CurrentTable = (DESCRIPTION_HEADER*)tableOffset;
75 if ( CurrentTable->Signature == Signature ) {
76 return CurrentTable;
77 }
78 }
79 }
80 return NULL;
81}
82
83//
84//
85// Routine Description:
86//
87// Update table checksum
88//
89// Arguments:
90//
91// TablePtr - table pointer
92//
93// Returns:
94//
95// none
96//
97//
98VOID
99ACPI_SetTableChecksum (
100 IN VOID* TablePtr
101 )
102{
103 UINT8 Checksum;
104 Checksum = 0;
105 ((DESCRIPTION_HEADER*)TablePtr)->Checksum = 0;
106 Checksum = ACPI_GetTableChecksum (TablePtr);
107 ((DESCRIPTION_HEADER*)TablePtr)->Checksum = (UINT8)(0x100 - Checksum);
108}
109
110//
111//
112// Routine Description:
113//
114// Get table checksum
115//
116// Arguments:
117//
118// TablePtr - table pointer
119//
120// Returns:
121//
122// none
123//
124//
125UINT8
126ACPI_GetTableChecksum (
127 IN VOID* TablePtr
128 )
129{
130 return GetByteSum (TablePtr, ((DESCRIPTION_HEADER*)TablePtr)->Length);
131}
132
133
134UINT8
135GetByteSum (
136 IN VOID* pData,
137 IN UINT32 Length
138 )
139{
140 UINT32 i;
141 UINT8 Checksum;
142 Checksum = 0;
143 for ( i = 0; i < Length; i++ ) {
144 Checksum = Checksum + (*((UINT8*)pData + i));
145 }
146 return Checksum;
147}
148VOID
149GetSbAcpiMmioBase (
150 OUT UINT32* AcpiMmioBase
151 )
152{
153 UINT32 Value16;
154
155 ReadPMIO (SB_PMIOA_REG24 + 2, AccWidthUint16, &Value16);
156 *AcpiMmioBase = Value16 << 16;
157}
158
159VOID
160GetSbAcpiPmBase (
161 OUT UINT16* AcpiPmBase
162 )
163{
164 ReadPMIO (SB_PMIOA_REG60, AccWidthUint16, AcpiPmBase);
165}
166