blob: 6342a695722aecf42dc962c1ab2448d1260393d2 [file] [log] [blame]
Rudolf Marek293b5f52009-02-01 18:35:15 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2009 Rudolf Marek <r.marek@assembler.cz>
5 *
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.
9 *
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.
14 *
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
18 */
19
20/* how many nesting we support */
21#define ACPIGEN_LENSTACK_SIZE 10
22
23/* if you need to change this, change the acpigen_write_f and
24 acpigen_patch_len */
25
26#define ACPIGEN_MAXLEN 0xfff
27
28#include <string.h>
29#include <arch/acpigen.h>
30#include <console/console.h>
31
32static char *gencurrent;
33
34char *len_stack[ACPIGEN_LENSTACK_SIZE];
35int ltop = 0;
36
37static int acpigen_write_len_f()
38{
39 ASSERT(ltop < (ACPIGEN_LENSTACK_SIZE - 1))
40 len_stack[ltop++] = gencurrent;
41 acpigen_emit_byte(0);
42 acpigen_emit_byte(0);
43 return 2;
44}
45
46void acpigen_patch_len(int len)
47{
48 ASSERT(len <= ACPIGEN_MAXLEN)
49 ASSERT(ltop > 0)
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);
54
55}
56
57void acpigen_set_current(char *curr) {
58 gencurrent = curr;
59}
60
61char *acpigen_get_current(void) {
62 return gencurrent;
63}
64
65int acpigen_emit_byte(unsigned char b)
66{
67 (*gencurrent++) = b;
68 return 1;
69}
70
71int acpigen_write_package(int nr_el)
72{
73 int len;
74 /* package op */
75 acpigen_emit_byte(0x12);
76 len = acpigen_write_len_f();
77 acpigen_emit_byte(nr_el);
78 return len + 2;
79}
80
81int acpigen_write_byte(unsigned int data)
82{
83 /* byte op */
84 acpigen_emit_byte(0xa);
85 acpigen_emit_byte(data & 0xff);
86 return 2;
87}
88
89int acpigen_write_dword(unsigned int data)
90{
91 /* dword op */
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);
97 return 5;
98}
99
100int acpigen_write_name_byte(char *name, uint8_t val) {
101 int len;
102 len = acpigen_write_name(name);
103 len += acpigen_write_byte(val);
104 return len;
105}
106
107int acpigen_write_name_dword(char *name, uint32_t val) {
108 int len;
109 len = acpigen_write_name(name);
110 len += acpigen_write_dword(val);
111 return len;
112}
113
114int acpigen_emit_stream(char *data, int size) {
115 int i;
116 for (i = 0; i < size; i++) {
117 acpigen_emit_byte(data[i]);
118 }
119 return size;
120}
121
122int acpigen_write_name(char *name)
123{
124 int len = strlen(name);
125 /* name op */
126 acpigen_emit_byte(0x8);
127 acpigen_emit_stream(name, len);
128 return len + 1;
129}
130
131int acpigen_write_scope(char *name)
132{
133 int len;
134 /* scope op */
135 acpigen_emit_byte(0x10);
136 len = acpigen_write_len_f();
137 return len + acpigen_emit_stream(name, strlen(name)) + 1;
138}
Rudolf Marekf997b552009-02-14 15:40:23 +0000139
140int acpigen_write_processor(u8 cpuindex, u32 pblock_addr, u8 pblock_len)
141{
142/*
143 Processor (\_PR.CPUcpuindex, cpuindex, pblock_addr, pblock_len)
144 {
145*/
146 char pscope[16];
147 int len;
148 /* processor op */
149 acpigen_emit_byte(0x5b);
150 acpigen_emit_byte(0x83);
151 len = acpigen_write_len_f();
152
153 sprintf(pscope, "\\._PR_CPU%x", (unsigned int) cpuindex);
154 len += acpigen_emit_stream(pscope, strlen(pscope));
155 acpigen_emit_byte(cpuindex);
156 acpigen_emit_byte(pblock_addr & 0xff);
157 acpigen_emit_byte((pblock_addr >> 8) & 0xff);
158 acpigen_emit_byte((pblock_addr >> 16) & 0xff);
159 acpigen_emit_byte((pblock_addr >> 24) & 0xff);
160 acpigen_emit_byte(pblock_len);
161 return 6 + 2 + len;
162}
163
164int acpigen_write_empty_PCT(void)
165{
166/*
167 Name (_PCT, Package (0x02)
168 {
169 ResourceTemplate ()
170 {
171 Register (FFixedHW,
172 0x00, // Bit Width
173 0x00, // Bit Offset
174 0x0000000000000000, // Address
175 ,)
176 },
177
178 ResourceTemplate ()
179 {
180 Register (FFixedHW,
181 0x00, // Bit Width
182 0x00, // Bit Offset
183 0x0000000000000000, // Address
184 ,)
185 }
186 })
187*/
188 static char stream[] = {
189 0x08, 0x5F, 0x50, 0x43, 0x54, 0x12, 0x2C, /* 00000030 "0._PCT.," */
190 0x02, 0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, /* 00000038 "........" */
191 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00000040 "........" */
192 0x00, 0x00, 0x00, 0x00, 0x79, 0x00, 0x11, 0x14, /* 00000048 "....y..." */
193 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F, 0x00, 0x00, /* 00000050 "........" */
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00000058 "........" */
195 0x00, 0x79, 0x00
196 };
197 return acpigen_emit_stream(stream, ARRAY_SIZE(stream));
198}
199
200/* generates a func with max supported P states */
201int acpigen_write_PPC(u8 nr)
202{
203/*
204 Method (_PPC, 0, NotSerialized)
205 {
206 Return (nr)
207 }
208*/
209 int len;
210 /* method op */
211 acpigen_emit_byte(0x14);
212 len = acpigen_write_len_f();
213 len += acpigen_emit_stream("_PPC", 4);
214 /* no fnarg */
215 acpigen_emit_byte(0x00);
216 /* return */
217 acpigen_emit_byte(0xa4);
218 /* arg */
219 len += acpigen_write_byte(nr);
220 acpigen_patch_len(len - 1);
221 return len + 3;
222}
223
224int acpigen_write_PSS_package(u32 coreFreq, u32 power, u32 transLat, u32 busmLat,
225 u32 control, u32 status)
226{
227 int len;
228 len = acpigen_write_package(6);
229 len += acpigen_write_dword(coreFreq);
230 len += acpigen_write_dword(power);
231 len += acpigen_write_dword(transLat);
232 len += acpigen_write_dword(busmLat);
233 len += acpigen_write_dword(control);
234 len += acpigen_write_dword(status);
235 //pkglen without the len opcode
236 acpigen_patch_len(len - 1);
237 return len;
238}