2 * This file is part of the coreboot project.
4 * Copyright (C) 2009 Rudolf Marek <r.marek@assembler.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License v2 as published by
8 * the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 /* how many nesting we support */
21 #define ACPIGEN_LENSTACK_SIZE 10
23 /* if you need to change this, change the acpigen_write_f and
26 #define ACPIGEN_MAXLEN 0xfff
29 #include <arch/acpigen.h>
30 #include <console/console.h>
32 static char *gencurrent;
34 char *len_stack[ACPIGEN_LENSTACK_SIZE];
37 static int acpigen_write_len_f()
39 ASSERT(ltop < (ACPIGEN_LENSTACK_SIZE - 1))
40 len_stack[ltop++] = gencurrent;
46 void acpigen_patch_len(int len)
48 ASSERT(len <= ACPIGEN_MAXLEN)
50 char *p = len_stack[--ltop];
51 /* generate store length for 0xfff max */
52 p[0] = (0x40 | (len & 0xf));
53 p[1] = (len >> 4 & 0xff);
57 void acpigen_set_current(char *curr) {
61 char *acpigen_get_current(void) {
65 int acpigen_emit_byte(unsigned char b)
71 int acpigen_write_package(int nr_el)
75 acpigen_emit_byte(0x12);
76 len = acpigen_write_len_f();
77 acpigen_emit_byte(nr_el);
81 int acpigen_write_byte(unsigned int data)
84 acpigen_emit_byte(0xa);
85 acpigen_emit_byte(data & 0xff);
89 int acpigen_write_dword(unsigned int data)
92 acpigen_emit_byte(0xc);
93 acpigen_emit_byte(data & 0xff);
94 acpigen_emit_byte((data >> 8) & 0xff);
95 acpigen_emit_byte((data >> 16) & 0xff);
96 acpigen_emit_byte((data >> 24) & 0xff);
100 int acpigen_write_qword(uint64_t data)
103 acpigen_emit_byte(0xe);
104 acpigen_emit_byte(data & 0xff);
105 acpigen_emit_byte((data >> 8) & 0xff);
106 acpigen_emit_byte((data >> 16) & 0xff);
107 acpigen_emit_byte((data >> 24) & 0xff);
108 acpigen_emit_byte((data >> 32) & 0xff);
109 acpigen_emit_byte((data >> 40) & 0xff);
110 acpigen_emit_byte((data >> 48) & 0xff);
111 acpigen_emit_byte((data >> 56) & 0xff);
115 int acpigen_write_name_byte(char *name, uint8_t val) {
117 len = acpigen_write_name(name);
118 len += acpigen_write_byte(val);
122 int acpigen_write_name_dword(char *name, uint32_t val) {
124 len = acpigen_write_name(name);
125 len += acpigen_write_dword(val);
129 int acpigen_write_name_qword(char *name, uint64_t val) {
131 len = acpigen_write_name(name);
132 len += acpigen_write_qword(val);
136 int acpigen_emit_stream(char *data, int size) {
138 for (i = 0; i < size; i++) {
139 acpigen_emit_byte(data[i]);
144 int acpigen_write_name(char *name)
146 int len = strlen(name);
148 acpigen_emit_byte(0x8);
149 acpigen_emit_stream(name, len);
153 int acpigen_write_scope(char *name)
157 acpigen_emit_byte(0x10);
158 len = acpigen_write_len_f();
159 return len + acpigen_emit_stream(name, strlen(name)) + 1;
162 int acpigen_write_processor(u8 cpuindex, u32 pblock_addr, u8 pblock_len)
165 Processor (\_PR.CPUcpuindex, cpuindex, pblock_addr, pblock_len)
171 acpigen_emit_byte(0x5b);
172 acpigen_emit_byte(0x83);
173 len = acpigen_write_len_f();
175 sprintf(pscope, "\\._PR_CPU%x", (unsigned int) cpuindex);
176 len += acpigen_emit_stream(pscope, strlen(pscope));
177 acpigen_emit_byte(cpuindex);
178 acpigen_emit_byte(pblock_addr & 0xff);
179 acpigen_emit_byte((pblock_addr >> 8) & 0xff);
180 acpigen_emit_byte((pblock_addr >> 16) & 0xff);
181 acpigen_emit_byte((pblock_addr >> 24) & 0xff);
182 acpigen_emit_byte(pblock_len);
186 int acpigen_write_empty_PCT(void)
189 Name (_PCT, Package (0x02)
196 0x0000000000000000, // Address
205 0x0000000000000000, // Address
210 static char stream[] = {
211 0x08, 0x5F, 0x50, 0x43, 0x54, 0x12, 0x2C, /* 00000030 "0._PCT.," */
212 0x02, 0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, /* 00000038 "........" */
213 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00000040 "........" */
214 0x00, 0x00, 0x00, 0x00, 0x79, 0x00, 0x11, 0x14, /* 00000048 "....y..." */
215 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F, 0x00, 0x00, /* 00000050 "........" */
216 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00000058 "........" */
219 return acpigen_emit_stream(stream, ARRAY_SIZE(stream));
222 /* generates a func with max supported P states */
223 int acpigen_write_PPC(u8 nr)
226 Method (_PPC, 0, NotSerialized)
233 acpigen_emit_byte(0x14);
234 len = acpigen_write_len_f();
235 len += acpigen_emit_stream("_PPC", 4);
237 acpigen_emit_byte(0x00);
239 acpigen_emit_byte(0xa4);
241 len += acpigen_write_byte(nr);
242 /* add all single bytes */
244 acpigen_patch_len(len - 1);
248 int acpigen_write_PSS_package(u32 coreFreq, u32 power, u32 transLat, u32 busmLat,
249 u32 control, u32 status)
252 len = acpigen_write_package(6);
253 len += acpigen_write_dword(coreFreq);
254 len += acpigen_write_dword(power);
255 len += acpigen_write_dword(transLat);
256 len += acpigen_write_dword(busmLat);
257 len += acpigen_write_dword(control);
258 len += acpigen_write_dword(status);
259 //pkglen without the len opcode
260 acpigen_patch_len(len - 1);
264 int acpigen_write_PSD_package(u32 domain, u32 numprocs, PSD_coord coordtype)
267 lenh = acpigen_write_name("_PSD");
268 lenp = acpigen_write_package(1);
269 len = acpigen_write_package(5);
270 len += acpigen_write_byte(5); // 5 values
271 len += acpigen_write_byte(0); // revision 0
272 len += acpigen_write_dword(domain);
273 len += acpigen_write_dword(coordtype);
274 len += acpigen_write_dword(numprocs);
275 acpigen_patch_len(len-1);
277 acpigen_patch_len(len-1);