ia64/xen-unstable

view tools/firmware/acpi/acpi_build.c @ 6392:bca2fd76995e

Add EXT3 as built-in filesystem for x86/64 domU.
author kaf24@firebug.cl.cam.ac.uk
date Wed Aug 24 15:21:48 2005 +0000 (2005-08-24)
parents bc8bb3a26ccc
children b3a255e88810
line source
1 /*
2 * Copyright (c) 2004, Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
16 *
17 */
19 #include "acpi2_0.h"
20 #include "acpi_madt.h"
22 extern ACPI_2_0_RSDP Rsdp;
23 extern ACPI_2_0_RSDT Rsdt;
24 extern ACPI_2_0_XSDT Xsdt;
25 extern ACPI_2_0_FADT Fadt;
26 extern ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE Madt;
27 extern ACPI_2_0_FACS Facs;
28 extern unsigned char *AmlCode;
29 extern int DsdtLen;
32 typedef struct _ACPI_TABLE_ALL{
33 ACPI_2_0_RSDP *Rsdp;
34 ACPI_2_0_RSDT *Rsdt;
35 ACPI_2_0_XSDT *Xsdt;
36 ACPI_2_0_FADT *Fadt;
37 ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE *Madt;
38 ACPI_2_0_FACS *Facs;
39 unsigned char* Dsdt;
40 u32 RsdpOffset;
41 u32 RsdtOffset;
42 u32 XsdtOffset;
43 u32 FadtOffset;
44 u32 MadtOffset;
45 u32 FacsOffset;
46 u32 DsdtOffset;
47 }ACPI_TABLE_ALL;
49 static
50 void
51 MemCopy(void* src, void* dst, int len){
53 u8* src0=src;
54 u8* dst0=dst;
56 while(len--){
57 *(dst0++)=*(src0++);
58 }
59 }
61 static
62 void
63 SetCheckSum(
64 void* Table,
65 u32 ChecksumOffset,
66 u32 Length
67 )
68 /*
69 * Routine Description:
70 * Calculate Checksum and store the result in the checksum
71 * filed of the table
72 *
73 * INPUT:
74 * Table: Start pointer of table
75 * ChecksumOffset: Offset of checksum field in the table
76 * Length: Length of Table
77 */
78 {
79 u8 Sum = 0;
80 u8 *Ptr;
82 Ptr=Table;
83 Ptr[ChecksumOffset]=0;
84 while (Length--) {
85 Sum = (u8)(Sum + (*Ptr++));
86 }
88 Ptr = Table;
89 Ptr[ChecksumOffset] = (u8) (0xff - Sum + 1);
90 }
92 //
93 // FIELD_OFFSET - returns the byte offset to a field within a structure
94 //
95 #define FIELD_OFFSET(TYPE,Field) ((u32)(&(((TYPE *) 0)->Field)))
97 static
98 void
99 UpdateTable(
100 ACPI_TABLE_ALL *table
101 )
102 /*
103 * Update the ACPI table:
104 * fill in the actuall physical address of RSDT, XSDT, FADT, MADT, FACS
105 * Caculate the checksum
106 */
107 {
108 // RSDP Update
109 table->Rsdp->RsdtAddress = (u32)(ACPI_PHYSICAL_ADDRESS+
110 table->RsdtOffset);
111 table->Rsdp->XsdtAddress = (u64)(ACPI_PHYSICAL_ADDRESS+
112 table->XsdtOffset);
113 SetCheckSum(table->Rsdp,
114 FIELD_OFFSET(ACPI_1_0_RSDP, Checksum),
115 sizeof(ACPI_1_0_RSDP)
116 );
117 SetCheckSum(table->Rsdp,
118 FIELD_OFFSET(ACPI_2_0_RSDP,
119 ExtendedChecksum),
120 sizeof(ACPI_2_0_RSDP)
121 );
124 //RSDT Update
125 table->Rsdt->Entry[0] = (u32)(ACPI_PHYSICAL_ADDRESS +
126 table->FadtOffset);
127 table->Rsdt->Entry[1] = (u32)(ACPI_PHYSICAL_ADDRESS +
128 table->MadtOffset);
129 table->Rsdt->Header.Length = sizeof (ACPI_TABLE_HEADER) +
130 2*sizeof(u32);
131 SetCheckSum(table->Rsdt,
132 FIELD_OFFSET(ACPI_TABLE_HEADER, Checksum),
133 table->Rsdt->Header.Length
134 );
136 //XSDT Update
137 table->Xsdt->Entry[0] = (u64)(ACPI_PHYSICAL_ADDRESS +
138 table->FadtOffset);
139 table->Xsdt->Entry[1] = (u64)(ACPI_PHYSICAL_ADDRESS +
140 table->MadtOffset);
141 table->Xsdt->Header.Length = sizeof (ACPI_TABLE_HEADER) +
142 2*sizeof(u64);
143 SetCheckSum(table->Xsdt,
144 FIELD_OFFSET(ACPI_TABLE_HEADER, Checksum),
145 table->Xsdt->Header.Length
146 );
148 // FADT Update
149 table->Fadt->Dsdt = (u32)(ACPI_PHYSICAL_ADDRESS +
150 table->DsdtOffset);
151 table->Fadt->XDsdt = (u64)(ACPI_PHYSICAL_ADDRESS +
152 table->DsdtOffset);
153 table->Fadt->FirmwareCtrl = (u32)(ACPI_PHYSICAL_ADDRESS +
154 table->FacsOffset);
155 table->Fadt->XFirmwareCtrl = (u64)(ACPI_PHYSICAL_ADDRESS +
156 table->FacsOffset);
157 SetCheckSum(table->Fadt,
158 FIELD_OFFSET(ACPI_TABLE_HEADER, Checksum),
159 sizeof(ACPI_2_0_FADT)
160 );
162 // MADT update
163 SetCheckSum(table->Madt,
164 FIELD_OFFSET(ACPI_TABLE_HEADER, Checksum),
165 sizeof(ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE)
166 );
167 }
169 void
170 AcpiBuildTable(u8* buf)
171 /*
172 * Copy all the ACPI table to buffer
173 * Buffer Layout:
174 * FACS
175 * RSDP
176 * RSDT
177 * XSDT
178 * FADT
179 * MADT
180 * DSDT
181 *
182 */
183 {
184 ACPI_TABLE_ALL table;
185 int offset=0;
187 // FACS: should be 64-bit alignment
188 // so it is put at the start of buffer
189 // as the buffer is 64 bit alignment
190 table.FacsOffset = offset;
191 table.Facs = (ACPI_2_0_FACS*)(&buf[offset]);
192 MemCopy(&Facs, table.Facs, sizeof(ACPI_2_0_FACS));
193 offset += sizeof(ACPI_2_0_FACS);
195 // RSDP
196 table.RsdpOffset = offset;
197 table.Rsdp = (ACPI_2_0_RSDP*)(&buf[offset]);
198 MemCopy(&Rsdp, table.Rsdp, sizeof(ACPI_2_0_RSDP));
199 offset+=sizeof(ACPI_2_0_RSDP);
201 // RSDT
202 table.RsdtOffset = offset;
203 table.Rsdt = (ACPI_2_0_RSDT*)(&buf[offset]);
204 MemCopy(&Rsdt, table.Rsdt, sizeof(ACPI_2_0_RSDT));
205 offset+=sizeof(ACPI_2_0_RSDT);
207 // XSDT
208 table.XsdtOffset = offset;
209 table.Xsdt = (ACPI_2_0_XSDT*)(&buf[offset]);
210 MemCopy(&Xsdt, table.Xsdt, sizeof(ACPI_2_0_XSDT));
211 offset+=sizeof(ACPI_2_0_XSDT);
213 // FADT
214 table.FadtOffset = offset;
215 table.Fadt = (ACPI_2_0_FADT*)(&buf[offset]);
216 MemCopy(&Fadt, table.Fadt, sizeof(ACPI_2_0_FADT));
217 offset+=sizeof(ACPI_2_0_FADT);
219 // MADT
220 table.MadtOffset = offset;
221 table.Madt = (ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE*)(&buf[offset]);
222 MemCopy(&Madt, table.Madt, sizeof(ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE));
223 offset+=sizeof(ACPI_MULTIPLE_APIC_DESCRIPTION_TABLE);
225 // DSDT
226 table.DsdtOffset = offset;
227 table.Dsdt = (unsigned char*)(&buf[offset]);
228 MemCopy(&AmlCode, table.Dsdt, DsdtLen);
229 offset+=DsdtLen;
231 UpdateTable(&table);
232 }