blob: d37568c92fcf583ea66f78fce541d60c489226e8 [file] [log] [blame]
Rudolf Marek293b5f52009-02-01 18:35:15 +00001/*
2 * This file is part of the coreboot project.
3 *
Timothy Pearson83abd812015-06-08 19:35:06 -05004 * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering
Rudolf Marek293b5f52009-02-01 18:35:15 +00005 * Copyright (C) 2009 Rudolf Marek <r.marek@assembler.cz>
6 *
7 * This program is free software; you can redistribute it and/or modify
Uwe Hermannc70e9fc2010-02-15 23:10:19 +00008 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
Rudolf Marek293b5f52009-02-01 18:35:15 +000010 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Rudolf Marek293b5f52009-02-01 18:35:15 +000015 */
16
Paul Menzel0f4c0e22013-02-22 12:33:08 +010017/* How much nesting do we support? */
Rudolf Marek293b5f52009-02-01 18:35:15 +000018#define ACPIGEN_LENSTACK_SIZE 10
19
Paul Menzel0f4c0e22013-02-22 12:33:08 +010020/*
Timothy Pearson83abd812015-06-08 19:35:06 -050021 * If you need to change this, change acpigen_write_len_f and
Vladimir Serbinenko8104da72014-11-09 03:33:51 +010022 * acpigen_pop_len
Paul Menzel0f4c0e22013-02-22 12:33:08 +010023 */
Rudolf Marek293b5f52009-02-01 18:35:15 +000024
Timothy Pearson83abd812015-06-08 19:35:06 -050025#define ACPIGEN_MAXLEN 0xfffff
Rudolf Marek293b5f52009-02-01 18:35:15 +000026
Duncan Laurie3829f232016-05-09 11:08:46 -070027#include <lib.h>
Rudolf Marek293b5f52009-02-01 18:35:15 +000028#include <string.h>
29#include <arch/acpigen.h>
30#include <console/console.h>
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +000031#include <device/device.h>
Rudolf Marek293b5f52009-02-01 18:35:15 +000032
33static char *gencurrent;
34
35char *len_stack[ACPIGEN_LENSTACK_SIZE];
36int ltop = 0;
37
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010038void acpigen_write_len_f(void)
Rudolf Marek293b5f52009-02-01 18:35:15 +000039{
40 ASSERT(ltop < (ACPIGEN_LENSTACK_SIZE - 1))
Paul Menzel0f4c0e22013-02-22 12:33:08 +010041 len_stack[ltop++] = gencurrent;
Rudolf Marek293b5f52009-02-01 18:35:15 +000042 acpigen_emit_byte(0);
43 acpigen_emit_byte(0);
Timothy Pearson83abd812015-06-08 19:35:06 -050044 acpigen_emit_byte(0);
Rudolf Marek293b5f52009-02-01 18:35:15 +000045}
46
Vladimir Serbinenko430363a2014-11-02 21:51:22 +010047void acpigen_pop_len(void)
48{
49 int len;
50 ASSERT(ltop > 0)
51 char *p = len_stack[--ltop];
52 len = gencurrent - p;
53 ASSERT(len <= ACPIGEN_MAXLEN)
Timothy Pearson83abd812015-06-08 19:35:06 -050054 /* generate store length for 0xfffff max */
55 p[0] = (0x80 | (len & 0xf));
Vladimir Serbinenko430363a2014-11-02 21:51:22 +010056 p[1] = (len >> 4 & 0xff);
Timothy Pearson83abd812015-06-08 19:35:06 -050057 p[2] = (len >> 12 & 0xff);
Vladimir Serbinenko430363a2014-11-02 21:51:22 +010058
59}
60
Stefan Reinauerf96c2d92009-04-22 16:23:47 +000061void acpigen_set_current(char *curr)
62{
63 gencurrent = curr;
Rudolf Marek293b5f52009-02-01 18:35:15 +000064}
65
Stefan Reinauerf96c2d92009-04-22 16:23:47 +000066char *acpigen_get_current(void)
67{
68 return gencurrent;
Rudolf Marek293b5f52009-02-01 18:35:15 +000069}
70
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010071void acpigen_emit_byte(unsigned char b)
Rudolf Marek293b5f52009-02-01 18:35:15 +000072{
73 (*gencurrent++) = b;
Rudolf Marek293b5f52009-02-01 18:35:15 +000074}
75
Duncan Laurie9ccae752016-05-09 07:43:19 -070076void acpigen_emit_word(unsigned int data)
77{
78 acpigen_emit_byte(data & 0xff);
79 acpigen_emit_byte((data >> 8) & 0xff);
80}
81
82void acpigen_emit_dword(unsigned int data)
83{
84 acpigen_emit_byte(data & 0xff);
85 acpigen_emit_byte((data >> 8) & 0xff);
86 acpigen_emit_byte((data >> 16) & 0xff);
87 acpigen_emit_byte((data >> 24) & 0xff);
88}
89
Duncan Laurie85d80272016-07-02 19:53:54 -070090char *acpigen_write_package(int nr_el)
Rudolf Marek293b5f52009-02-01 18:35:15 +000091{
Duncan Laurie85d80272016-07-02 19:53:54 -070092 char *p;
Rudolf Marek293b5f52009-02-01 18:35:15 +000093 /* package op */
94 acpigen_emit_byte(0x12);
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010095 acpigen_write_len_f();
Duncan Laurie85d80272016-07-02 19:53:54 -070096 p = acpigen_get_current();
Rudolf Marek293b5f52009-02-01 18:35:15 +000097 acpigen_emit_byte(nr_el);
Duncan Laurie85d80272016-07-02 19:53:54 -070098 return p;
Rudolf Marek293b5f52009-02-01 18:35:15 +000099}
100
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100101void acpigen_write_byte(unsigned int data)
Rudolf Marek293b5f52009-02-01 18:35:15 +0000102{
103 /* byte op */
104 acpigen_emit_byte(0xa);
105 acpigen_emit_byte(data & 0xff);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000106}
107
Duncan Laurie9ccae752016-05-09 07:43:19 -0700108void acpigen_write_word(unsigned int data)
109{
110 /* word op */
111 acpigen_emit_byte(0xb);
112 acpigen_emit_word(data);
113}
114
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100115void acpigen_write_dword(unsigned int data)
Rudolf Marek293b5f52009-02-01 18:35:15 +0000116{
117 /* dword op */
118 acpigen_emit_byte(0xc);
Duncan Laurie9ccae752016-05-09 07:43:19 -0700119 acpigen_emit_dword(data);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000120}
121
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100122void acpigen_write_qword(uint64_t data)
Carl-Daniel Hailfingerd58671c2009-02-17 21:38:51 +0000123{
124 /* qword op */
125 acpigen_emit_byte(0xe);
Duncan Laurie9ccae752016-05-09 07:43:19 -0700126 acpigen_emit_dword(data & 0xffffffff);
127 acpigen_emit_dword((data >> 32) & 0xffffffff);
Carl-Daniel Hailfingerd58671c2009-02-17 21:38:51 +0000128}
129
Duncan Laurief7c38762016-05-09 08:20:38 -0700130void acpigen_write_zero(void)
131{
132 acpigen_emit_byte(0x00);
133}
134
135void acpigen_write_one(void)
136{
137 acpigen_emit_byte(0x01);
138}
139
140void acpigen_write_ones(void)
141{
142 acpigen_emit_byte(0xff);
143}
144
145void acpigen_write_integer(uint64_t data)
146{
147 if (data == 0)
148 acpigen_write_zero();
149 else if (data == 1)
150 acpigen_write_one();
151 else if (data <= 0xff)
152 acpigen_write_byte((unsigned char)data);
153 else if (data <= 0xffff)
154 acpigen_write_word((unsigned int)data);
155 else if (data <= 0xffffffff)
156 acpigen_write_dword((unsigned int)data);
157 else
158 acpigen_write_qword(data);
159}
160
161void acpigen_write_name_zero(const char *name)
162{
163 acpigen_write_name(name);
164 acpigen_write_one();
165}
166
167void acpigen_write_name_one(const char *name)
168{
169 acpigen_write_name(name);
170 acpigen_write_zero();
171}
172
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100173void acpigen_write_name_byte(const char *name, uint8_t val)
Stefan Reinauerf96c2d92009-04-22 16:23:47 +0000174{
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100175 acpigen_write_name(name);
176 acpigen_write_byte(val);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000177}
178
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100179void acpigen_write_name_dword(const char *name, uint32_t val)
Stefan Reinauerf96c2d92009-04-22 16:23:47 +0000180{
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100181 acpigen_write_name(name);
182 acpigen_write_dword(val);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000183}
184
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100185void acpigen_write_name_qword(const char *name, uint64_t val)
Stefan Reinauerf96c2d92009-04-22 16:23:47 +0000186{
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100187 acpigen_write_name(name);
188 acpigen_write_qword(val);
Carl-Daniel Hailfingerd58671c2009-02-17 21:38:51 +0000189}
190
Duncan Laurief7c38762016-05-09 08:20:38 -0700191void acpigen_write_name_integer(const char *name, uint64_t val)
192{
193 acpigen_write_name(name);
194 acpigen_write_integer(val);
195}
196
Duncan Laurie56b69aa2016-05-09 08:17:02 -0700197void acpigen_write_name_string(const char *name, const char *string)
198{
199 acpigen_write_name(name);
200 acpigen_write_string(string);
201}
202
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100203void acpigen_emit_stream(const char *data, int size)
Stefan Reinauerf96c2d92009-04-22 16:23:47 +0000204{
Rudolf Marek293b5f52009-02-01 18:35:15 +0000205 int i;
206 for (i = 0; i < size; i++) {
207 acpigen_emit_byte(data[i]);
208 }
Rudolf Marek293b5f52009-02-01 18:35:15 +0000209}
210
Duncan Laurie56b69aa2016-05-09 08:17:02 -0700211void acpigen_emit_string(const char *string)
212{
Jonathan Neuschäfer0ba307f2016-05-17 17:40:09 +0200213 acpigen_emit_stream(string, string ? strlen(string) : 0);
Duncan Laurie56b69aa2016-05-09 08:17:02 -0700214 acpigen_emit_byte('\0'); /* NUL */
215}
216
217void acpigen_write_string(const char *string)
218{
219 acpigen_emit_byte(0x0d);
220 acpigen_emit_string(string);
221}
222
Paul Menzel0f4c0e22013-02-22 12:33:08 +0100223/*
224 * The naming conventions for ACPI namespace names are a bit tricky as
225 * each element has to be 4 chars wide (»All names are a fixed 32 bits.«)
226 * and »By convention, when an ASL compiler pads a name shorter than 4
227 * characters, it is done so with trailing underscores (‘_’).«.
228 *
229 * Check sections 5.3, 18.2.2 and 18.4 of ACPI spec 3.0 for details.
230 */
Rudolf Marek3310d752009-06-21 20:26:13 +0000231
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100232static void acpigen_emit_simple_namestring(const char *name) {
233 int i;
Rudolf Marek3310d752009-06-21 20:26:13 +0000234 char ud[] = "____";
235 for (i = 0; i < 4; i++) {
236 if ((name[i] == '\0') || (name[i] == '.')) {
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100237 acpigen_emit_stream(ud, 4 - i);
Rudolf Marek3310d752009-06-21 20:26:13 +0000238 break;
239 } else {
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100240 acpigen_emit_byte(name[i]);
Rudolf Marek3310d752009-06-21 20:26:13 +0000241 }
242 }
Rudolf Marek3310d752009-06-21 20:26:13 +0000243}
244
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100245static void acpigen_emit_double_namestring(const char *name, int dotpos) {
Rudolf Marek3310d752009-06-21 20:26:13 +0000246 /* mark dual name prefix */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100247 acpigen_emit_byte(0x2e);
248 acpigen_emit_simple_namestring(name);
249 acpigen_emit_simple_namestring(&name[dotpos + 1]);
Rudolf Marek3310d752009-06-21 20:26:13 +0000250}
251
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100252static void acpigen_emit_multi_namestring(const char *name) {
253 int count = 0;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000254 unsigned char *pathlen;
Rudolf Marek3310d752009-06-21 20:26:13 +0000255 /* mark multi name prefix */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100256 acpigen_emit_byte(0x2f);
257 acpigen_emit_byte(0x0);
Rudolf Marek3310d752009-06-21 20:26:13 +0000258 pathlen = ((unsigned char *) acpigen_get_current()) - 1;
259
260 while (name[0] != '\0') {
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100261 acpigen_emit_simple_namestring(name);
Rudolf Marek3310d752009-06-21 20:26:13 +0000262 /* find end or next entity */
263 while ((name[0] != '.') && (name[0] != '\0'))
264 name++;
265 /* forward to next */
266 if (name[0] == '.')
267 name++;
268 count++;
269 }
270
271 pathlen[0] = count;
Rudolf Marek3310d752009-06-21 20:26:13 +0000272}
273
274
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100275void acpigen_emit_namestring(const char *namepath) {
Rudolf Marek3310d752009-06-21 20:26:13 +0000276 int dotcount = 0, i;
Myles Watson3fe6b702009-10-09 20:13:43 +0000277 int dotpos = 0;
Rudolf Marek3310d752009-06-21 20:26:13 +0000278
Ronald G. Minnichbe738eb2013-03-07 11:05:28 -0600279 /* We can start with a '\'. */
Rudolf Marek3310d752009-06-21 20:26:13 +0000280 if (namepath[0] == '\\') {
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100281 acpigen_emit_byte('\\');
Rudolf Marek3310d752009-06-21 20:26:13 +0000282 namepath++;
283 }
284
Ronald G. Minnichbe738eb2013-03-07 11:05:28 -0600285 /* And there can be any number of '^' */
Rudolf Marek3310d752009-06-21 20:26:13 +0000286 while (namepath[0] == '^') {
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100287 acpigen_emit_byte('^');
Rudolf Marek3310d752009-06-21 20:26:13 +0000288 namepath++;
289 }
290
Vladimir Serbinenkod942ed92014-08-30 20:44:37 +0200291 /* If we have only \\ or only ^...^. Then we need to put a null
292 name (0x00). */
293 if(namepath[0] == '\0') {
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100294 acpigen_emit_byte(0x00);
295 return;
Vladimir Serbinenkod942ed92014-08-30 20:44:37 +0200296 }
Rudolf Marek3310d752009-06-21 20:26:13 +0000297
298 i = 0;
299 while (namepath[i] != '\0') {
300 if (namepath[i] == '.') {
301 dotcount++;
302 dotpos = i;
303 }
304 i++;
305 }
306
307 if (dotcount == 0) {
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100308 acpigen_emit_simple_namestring(namepath);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000309 } else if (dotcount == 1) {
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100310 acpigen_emit_double_namestring(namepath, dotpos);
Rudolf Marek3310d752009-06-21 20:26:13 +0000311 } else {
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100312 acpigen_emit_multi_namestring(namepath);
Rudolf Marek3310d752009-06-21 20:26:13 +0000313 }
Rudolf Marek3310d752009-06-21 20:26:13 +0000314}
315
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100316void acpigen_write_name(const char *name)
Rudolf Marek293b5f52009-02-01 18:35:15 +0000317{
Rudolf Marek293b5f52009-02-01 18:35:15 +0000318 /* name op */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100319 acpigen_emit_byte(0x8);
320 acpigen_emit_namestring(name);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000321}
322
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100323void acpigen_write_scope(const char *name)
Rudolf Marek293b5f52009-02-01 18:35:15 +0000324{
Rudolf Marek293b5f52009-02-01 18:35:15 +0000325 /* scope op */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100326 acpigen_emit_byte(0x10);
327 acpigen_write_len_f();
328 acpigen_emit_namestring(name);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000329}
Rudolf Marekf997b552009-02-14 15:40:23 +0000330
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100331void acpigen_write_processor(u8 cpuindex, u32 pblock_addr, u8 pblock_len)
Rudolf Marekf997b552009-02-14 15:40:23 +0000332{
333/*
334 Processor (\_PR.CPUcpuindex, cpuindex, pblock_addr, pblock_len)
335 {
336*/
337 char pscope[16];
Rudolf Marekf997b552009-02-14 15:40:23 +0000338 /* processor op */
339 acpigen_emit_byte(0x5b);
340 acpigen_emit_byte(0x83);
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100341 acpigen_write_len_f();
Rudolf Marekf997b552009-02-14 15:40:23 +0000342
Vladimir Serbinenkoa37383d2013-11-26 02:41:26 +0100343 snprintf(pscope, sizeof (pscope),
Timothy Pearson033bb4b2015-02-10 22:21:39 -0600344 "\\_PR.CP%02d", (unsigned int) cpuindex);
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100345 acpigen_emit_namestring(pscope);
Rudolf Marekf997b552009-02-14 15:40:23 +0000346 acpigen_emit_byte(cpuindex);
Duncan Laurie9ccae752016-05-09 07:43:19 -0700347 acpigen_emit_dword(pblock_addr);
Rudolf Marekf997b552009-02-14 15:40:23 +0000348 acpigen_emit_byte(pblock_len);
Rudolf Marekf997b552009-02-14 15:40:23 +0000349}
350
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100351void acpigen_write_empty_PCT(void)
Rudolf Marekf997b552009-02-14 15:40:23 +0000352{
353/*
354 Name (_PCT, Package (0x02)
355 {
356 ResourceTemplate ()
357 {
358 Register (FFixedHW,
359 0x00, // Bit Width
360 0x00, // Bit Offset
361 0x0000000000000000, // Address
362 ,)
363 },
364
365 ResourceTemplate ()
366 {
367 Register (FFixedHW,
368 0x00, // Bit Width
369 0x00, // Bit Offset
370 0x0000000000000000, // Address
371 ,)
372 }
373 })
374*/
375 static char stream[] = {
376 0x08, 0x5F, 0x50, 0x43, 0x54, 0x12, 0x2C, /* 00000030 "0._PCT.," */
377 0x02, 0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, /* 00000038 "........" */
378 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00000040 "........" */
379 0x00, 0x00, 0x00, 0x00, 0x79, 0x00, 0x11, 0x14, /* 00000048 "....y..." */
380 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F, 0x00, 0x00, /* 00000050 "........" */
381 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00000058 "........" */
382 0x00, 0x79, 0x00
383 };
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100384 acpigen_emit_stream(stream, ARRAY_SIZE(stream));
Rudolf Marekf997b552009-02-14 15:40:23 +0000385}
386
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100387void acpigen_write_empty_PTC(void)
Stefan Reinauer39205c62012-04-27 21:49:28 +0200388{
389/*
390 Name (_PTC, Package (0x02)
391 {
392 ResourceTemplate ()
393 {
394 Register (FFixedHW,
395 0x00, // Bit Width
396 0x00, // Bit Offset
397 0x0000000000000000, // Address
398 ,)
399 },
400
401 ResourceTemplate ()
402 {
403 Register (FFixedHW,
404 0x00, // Bit Width
405 0x00, // Bit Offset
406 0x0000000000000000, // Address
407 ,)
408 }
409 })
410*/
Stefan Reinauer39205c62012-04-27 21:49:28 +0200411 acpi_addr_t addr = {
412 .space_id = ACPI_ADDRESS_SPACE_FIXED,
413 .bit_width = 0,
414 .bit_offset = 0,
zbaoee8a9f6c2012-05-29 14:59:38 +0800415 {
416 .resv = 0
417 },
Stefan Reinauer39205c62012-04-27 21:49:28 +0200418 .addrl = 0,
419 .addrh = 0,
420 };
421
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100422 acpigen_write_name("_PTC");
423 acpigen_write_package(2);
Stefan Reinauer39205c62012-04-27 21:49:28 +0200424
425 /* ControlRegister */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100426 acpigen_write_resourcetemplate_header();
427 acpigen_write_register(&addr);
428 acpigen_write_resourcetemplate_footer();
Stefan Reinauer39205c62012-04-27 21:49:28 +0200429
430 /* StatusRegister */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100431 acpigen_write_resourcetemplate_header();
432 acpigen_write_register(&addr);
433 acpigen_write_resourcetemplate_footer();
Stefan Reinauer39205c62012-04-27 21:49:28 +0200434
Vladimir Serbinenkoa09f4db2014-11-09 03:32:58 +0100435 acpigen_pop_len();
Stefan Reinauer39205c62012-04-27 21:49:28 +0200436}
437
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100438void acpigen_write_method(const char *name, int nargs)
Vladimir Serbinenko80fb8ed2014-11-05 10:28:28 +0100439{
Vladimir Serbinenko80fb8ed2014-11-05 10:28:28 +0100440 /* method op */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100441 acpigen_emit_byte(0x14);
442 acpigen_write_len_f();
443 acpigen_emit_namestring(name);
444 acpigen_emit_byte(nargs & 7);
Vladimir Serbinenko80fb8ed2014-11-05 10:28:28 +0100445}
446
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100447void acpigen_write_device(const char *name)
Vladimir Serbinenko663be6e2014-11-05 21:29:45 +0100448{
Duncan Laurie9ccae752016-05-09 07:43:19 -0700449 /* device op */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100450 acpigen_emit_byte(0x5b);
451 acpigen_emit_byte(0x82);
452 acpigen_write_len_f();
453 acpigen_emit_namestring(name);
Vladimir Serbinenko663be6e2014-11-05 21:29:45 +0100454}
455
Duncan Laurieabe2de82016-05-09 11:08:46 -0700456void acpigen_write_STA(uint8_t status)
457{
458 /*
459 * Method (_STA, 0, NotSerialized) { Return (status) }
460 */
461 acpigen_write_method("_STA", 0);
462 acpigen_emit_byte(0xa4);
463 acpigen_write_byte(status);
464 acpigen_pop_len();
465}
466
Paul Menzel0f4c0e22013-02-22 12:33:08 +0100467/*
468 * Generates a func with max supported P-states.
469 */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100470void acpigen_write_PPC(u8 nr)
Rudolf Marekf997b552009-02-14 15:40:23 +0000471{
472/*
473 Method (_PPC, 0, NotSerialized)
474 {
475 Return (nr)
476 }
477*/
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100478 acpigen_write_method("_PPC", 0);
Rudolf Marekf997b552009-02-14 15:40:23 +0000479 /* return */
480 acpigen_emit_byte(0xa4);
481 /* arg */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100482 acpigen_write_byte(nr);
Vladimir Serbinenkoa09f4db2014-11-09 03:32:58 +0100483 acpigen_pop_len();
Rudolf Marekf997b552009-02-14 15:40:23 +0000484}
485
Paul Menzel0f4c0e22013-02-22 12:33:08 +0100486/*
487 * Generates a func with max supported P-states saved
488 * in the variable PPCM.
489 */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100490void acpigen_write_PPC_NVS(void)
Duncan Laurie0eefa002012-07-16 12:11:53 -0700491{
492/*
493 Method (_PPC, 0, NotSerialized)
494 {
495 Return (PPCM)
496 }
497*/
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100498 acpigen_write_method("_PPC", 0);
Duncan Laurie0eefa002012-07-16 12:11:53 -0700499 /* return */
500 acpigen_emit_byte(0xa4);
501 /* arg */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100502 acpigen_emit_namestring("PPCM");
Vladimir Serbinenkoa09f4db2014-11-09 03:32:58 +0100503 acpigen_pop_len();
Duncan Laurie0eefa002012-07-16 12:11:53 -0700504}
505
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100506void acpigen_write_TPC(const char *gnvs_tpc_limit)
Stefan Reinauer39205c62012-04-27 21:49:28 +0200507{
508/*
509 // Sample _TPC method
510 Method (_TPC, 0, NotSerialized)
511 {
512 Return (\TLVL)
513 }
514 */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100515 acpigen_write_method("_TPC", 0);
516 acpigen_emit_byte(0xa4); /* ReturnOp */
517 acpigen_emit_namestring(gnvs_tpc_limit);
Vladimir Serbinenkoa09f4db2014-11-09 03:32:58 +0100518 acpigen_pop_len();
Stefan Reinauer39205c62012-04-27 21:49:28 +0200519}
520
Duncan Laurieabe2de82016-05-09 11:08:46 -0700521void acpigen_write_PRW(u32 wake, u32 level)
522{
523 /*
524 * Name (_PRW, Package () { wake, level }
525 */
526 acpigen_write_name("_PRW");
527 acpigen_write_package(2);
528 acpigen_write_integer(wake);
529 acpigen_write_integer(level);
530 acpigen_pop_len();
531}
532
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100533void acpigen_write_PSS_package(u32 coreFreq, u32 power, u32 transLat,
Stefan Reinauerf96c2d92009-04-22 16:23:47 +0000534 u32 busmLat, u32 control, u32 status)
Rudolf Marekf997b552009-02-14 15:40:23 +0000535{
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100536 acpigen_write_package(6);
537 acpigen_write_dword(coreFreq);
538 acpigen_write_dword(power);
539 acpigen_write_dword(transLat);
540 acpigen_write_dword(busmLat);
541 acpigen_write_dword(control);
542 acpigen_write_dword(status);
Vladimir Serbinenkoa09f4db2014-11-09 03:32:58 +0100543 acpigen_pop_len();
Stefan Reinauerd4bacf92012-05-02 16:38:47 -0700544
545 printk(BIOS_DEBUG, "PSS: %uMHz power %u control 0x%x status 0x%x\n",
546 coreFreq, power, control, status);
Rudolf Marekf997b552009-02-14 15:40:23 +0000547}
Patrick Georgidf444bf2009-04-21 20:34:36 +0000548
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100549void acpigen_write_PSD_package(u32 domain, u32 numprocs, PSD_coord coordtype)
Patrick Georgidf444bf2009-04-21 20:34:36 +0000550{
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100551 acpigen_write_name("_PSD");
552 acpigen_write_package(1);
553 acpigen_write_package(5);
554 acpigen_write_byte(5); // 5 values
555 acpigen_write_byte(0); // revision 0
556 acpigen_write_dword(domain);
557 acpigen_write_dword(coordtype);
558 acpigen_write_dword(numprocs);
Vladimir Serbinenkoa09f4db2014-11-09 03:32:58 +0100559 acpigen_pop_len();
Vladimir Serbinenkoa09f4db2014-11-09 03:32:58 +0100560 acpigen_pop_len();
Patrick Georgidf444bf2009-04-21 20:34:36 +0000561}
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000562
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100563void acpigen_write_CST_package_entry(acpi_cstate_t *cstate)
Sven Schnelle0b86c762011-10-21 21:46:47 +0200564{
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100565 acpigen_write_package(4);
566 acpigen_write_resourcetemplate_header();
Stefan Reinauer4cc8c702012-04-27 21:34:16 +0200567 acpigen_write_register(&cstate->resource);
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100568 acpigen_write_resourcetemplate_footer();
569 acpigen_write_dword(cstate->ctype);
570 acpigen_write_dword(cstate->latency);
571 acpigen_write_dword(cstate->power);
Vladimir Serbinenkoa09f4db2014-11-09 03:32:58 +0100572 acpigen_pop_len();
Sven Schnelle0b86c762011-10-21 21:46:47 +0200573}
574
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100575void acpigen_write_CST_package(acpi_cstate_t *cstate, int nentries)
Sven Schnelle0b86c762011-10-21 21:46:47 +0200576{
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100577 int i;
578 acpigen_write_name("_CST");
579 acpigen_write_package(nentries+1);
580 acpigen_write_dword(nentries);
Sven Schnelle0b86c762011-10-21 21:46:47 +0200581
582 for (i = 0; i < nentries; i++)
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100583 acpigen_write_CST_package_entry(cstate + i);
Sven Schnelle0b86c762011-10-21 21:46:47 +0200584
Vladimir Serbinenkoa09f4db2014-11-09 03:32:58 +0100585 acpigen_pop_len();
Sven Schnelle0b86c762011-10-21 21:46:47 +0200586}
587
Timothy Pearson83abd812015-06-08 19:35:06 -0500588void acpigen_write_CSD_package(u32 domain, u32 numprocs, CSD_coord coordtype, u32 index)
589{
590 acpigen_write_name("_CSD");
591 acpigen_write_package(1);
592 acpigen_write_package(6);
593 acpigen_write_byte(6); // 6 values
594 acpigen_write_byte(0); // revision 0
595 acpigen_write_dword(domain);
596 acpigen_write_dword(coordtype);
597 acpigen_write_dword(numprocs);
598 acpigen_write_dword(index);
599 acpigen_pop_len();
600 acpigen_pop_len();
601}
602
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100603void acpigen_write_TSS_package(int entries, acpi_tstate_t *tstate_list)
Stefan Reinauer39205c62012-04-27 21:49:28 +0200604{
605/*
606 Sample _TSS package with 100% and 50% duty cycles
607 Name (_TSS, Package (0x02)
608 {
609 Package(){100, 1000, 0, 0x00, 0)
610 Package(){50, 520, 0, 0x18, 0)
611 })
612 */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100613 int i;
Stefan Reinauer39205c62012-04-27 21:49:28 +0200614 acpi_tstate_t *tstate = tstate_list;
615
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100616 acpigen_write_name("_TSS");
617 acpigen_write_package(entries);
Stefan Reinauer39205c62012-04-27 21:49:28 +0200618
619 for (i = 0; i < entries; i++) {
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100620 acpigen_write_package(5);
621 acpigen_write_dword(tstate->percent);
622 acpigen_write_dword(tstate->power);
623 acpigen_write_dword(tstate->latency);
624 acpigen_write_dword(tstate->control);
625 acpigen_write_dword(tstate->status);
Vladimir Serbinenkoa09f4db2014-11-09 03:32:58 +0100626 acpigen_pop_len();
Stefan Reinauer39205c62012-04-27 21:49:28 +0200627 tstate++;
Stefan Reinauer39205c62012-04-27 21:49:28 +0200628 }
629
Vladimir Serbinenkoa09f4db2014-11-09 03:32:58 +0100630 acpigen_pop_len();
Stefan Reinauer39205c62012-04-27 21:49:28 +0200631}
632
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100633void acpigen_write_TSD_package(u32 domain, u32 numprocs, PSD_coord coordtype)
Stefan Reinauer39205c62012-04-27 21:49:28 +0200634{
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100635 acpigen_write_name("_TSD");
636 acpigen_write_package(1);
637 acpigen_write_package(5);
638 acpigen_write_byte(5); // 5 values
639 acpigen_write_byte(0); // revision 0
640 acpigen_write_dword(domain);
641 acpigen_write_dword(coordtype);
642 acpigen_write_dword(numprocs);
Vladimir Serbinenkoa09f4db2014-11-09 03:32:58 +0100643 acpigen_pop_len();
Vladimir Serbinenkoa09f4db2014-11-09 03:32:58 +0100644 acpigen_pop_len();
Stefan Reinauer39205c62012-04-27 21:49:28 +0200645}
646
647
648
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100649void acpigen_write_mem32fixed(int readwrite, u32 base, u32 size)
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000650{
651 /*
652 * acpi 4.0 section 6.4.3.4: 32-Bit Fixed Memory Range Descriptor
653 * Byte 0:
654 * Bit7 : 1 => big item
655 * Bit6-0: 0000110 (0x6) => 32-bit fixed memory
656 */
657 acpigen_emit_byte(0x86);
658 /* Byte 1+2: length (0x0009) */
659 acpigen_emit_byte(0x09);
660 acpigen_emit_byte(0x00);
661 /* bit1-7 are ignored */
662 acpigen_emit_byte(readwrite ? 0x01 : 0x00);
Duncan Laurie9ccae752016-05-09 07:43:19 -0700663 acpigen_emit_dword(base);
664 acpigen_emit_dword(size);
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000665}
666
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100667void acpigen_write_register(acpi_addr_t *addr)
Sven Schnelle0b86c762011-10-21 21:46:47 +0200668{
Stefan Reinauer4cc8c702012-04-27 21:34:16 +0200669 acpigen_emit_byte(0x82); /* Register Descriptor */
670 acpigen_emit_byte(0x0c); /* Register Length 7:0 */
671 acpigen_emit_byte(0x00); /* Register Length 15:8 */
672 acpigen_emit_byte(addr->space_id); /* Address Space ID */
673 acpigen_emit_byte(addr->bit_width); /* Register Bit Width */
674 acpigen_emit_byte(addr->bit_offset); /* Register Bit Offset */
675 acpigen_emit_byte(addr->resv); /* Register Access Size */
Duncan Laurie9ccae752016-05-09 07:43:19 -0700676 acpigen_emit_dword(addr->addrl); /* Register Address Low */
677 acpigen_emit_dword(addr->addrh); /* Register Address High */
Sven Schnelle0b86c762011-10-21 21:46:47 +0200678}
679
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100680void acpigen_write_irq(u16 mask)
Vladimir Serbinenko20ea0402014-02-15 18:57:17 +0100681{
682 /*
683 * acpi 3.0b section 6.4.2.1: IRQ Descriptor
684 * Byte 0:
685 * Bit7 : 0 => small item
686 * Bit6-3: 0100 (0x4) => IRQ port descriptor
687 * Bit2-0: 010 (0x2) => 2 Bytes long
688 */
689 acpigen_emit_byte(0x22);
690 acpigen_emit_byte(mask & 0xff);
691 acpigen_emit_byte((mask >> 8) & 0xff);
Vladimir Serbinenko20ea0402014-02-15 18:57:17 +0100692}
693
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100694void acpigen_write_io16(u16 min, u16 max, u8 align, u8 len, u8 decode16)
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000695{
696 /*
697 * acpi 4.0 section 6.4.2.6: I/O Port Descriptor
698 * Byte 0:
699 * Bit7 : 0 => small item
700 * Bit6-3: 1000 (0x8) => I/O port descriptor
701 * Bit2-0: 111 (0x7) => 7 Bytes long
702 */
703 acpigen_emit_byte(0x47);
Paul Menzel0f4c0e22013-02-22 12:33:08 +0100704 /* Does the device decode all 16 or just 10 bits? */
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000705 /* bit1-7 are ignored */
706 acpigen_emit_byte(decode16 ? 0x01 : 0x00);
707 /* minimum base address the device may be configured for */
708 acpigen_emit_byte(min & 0xff);
709 acpigen_emit_byte((min >> 8) & 0xff);
710 /* maximum base address the device may be configured for */
711 acpigen_emit_byte(max & 0xff);
712 acpigen_emit_byte((max >> 8) & 0xff);
713 /* alignment for min base */
714 acpigen_emit_byte(align & 0xff);
715 acpigen_emit_byte(len & 0xff);
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000716}
717
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100718void acpigen_write_resourcetemplate_header(void)
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000719{
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000720 /*
721 * A ResourceTemplate() is a Buffer() with a
722 * (Byte|Word|DWord) containing the length, followed by one or more
Paul Menzel0f4c0e22013-02-22 12:33:08 +0100723 * resource items, terminated by the end tag.
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000724 * (small item 0xf, len 1)
725 */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100726 acpigen_emit_byte(0x11); /* Buffer opcode */
727 acpigen_write_len_f();
728 acpigen_emit_byte(0x0b); /* Word opcode */
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000729 len_stack[ltop++] = acpigen_get_current();
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100730 acpigen_emit_byte(0x00);
731 acpigen_emit_byte(0x00);
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000732}
733
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100734void acpigen_write_resourcetemplate_footer(void)
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000735{
736 char *p = len_stack[--ltop];
Vladimir Serbinenko9acc1e82014-11-09 03:37:28 +0100737 int len;
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000738 /*
739 * end tag (acpi 4.0 Section 6.4.2.8)
740 * 0x79 <checksum>
741 * 0x00 is treated as a good checksum according to the spec
742 * and is what iasl generates.
743 */
Vladimir Serbinenko9acc1e82014-11-09 03:37:28 +0100744 acpigen_emit_byte(0x79);
745 acpigen_emit_byte(0x00);
746
Martin Rothe3690102016-01-06 15:21:02 -0700747 len = gencurrent - p;
Vladimir Serbinenko9acc1e82014-11-09 03:37:28 +0100748
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000749 /* patch len word */
Vladimir Serbinenko9acc1e82014-11-09 03:37:28 +0100750 p[0] = len & 0xff;
751 p[1] = (len >> 8) & 0xff;
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000752 /* patch len field */
Vladimir Serbinenkoa09f4db2014-11-09 03:32:58 +0100753 acpigen_pop_len();
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000754}
755
756static void acpigen_add_mainboard_rsvd_mem32(void *gp, struct device *dev,
757 struct resource *res)
758{
759 acpigen_write_mem32fixed(0, res->base, res->size);
760}
761
762static void acpigen_add_mainboard_rsvd_io(void *gp, struct device *dev,
763 struct resource *res)
764{
765 resource_t base = res->base;
766 resource_t size = res->size;
767 while (size > 0) {
768 resource_t sz = size > 255 ? 255 : size;
769 acpigen_write_io16(base, base, 0, sz, 1);
770 size -= sz;
771 base += sz;
772 }
773}
774
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100775void acpigen_write_mainboard_resource_template(void)
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000776{
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100777 acpigen_write_resourcetemplate_header();
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000778
Paul Menzel0f4c0e22013-02-22 12:33:08 +0100779 /* Add reserved memory ranges. */
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000780 search_global_resources(
781 IORESOURCE_MEM | IORESOURCE_RESERVE,
782 IORESOURCE_MEM | IORESOURCE_RESERVE,
783 acpigen_add_mainboard_rsvd_mem32, 0);
784
Paul Menzel0f4c0e22013-02-22 12:33:08 +0100785 /* Add reserved io ranges. */
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000786 search_global_resources(
787 IORESOURCE_IO | IORESOURCE_RESERVE,
788 IORESOURCE_IO | IORESOURCE_RESERVE,
789 acpigen_add_mainboard_rsvd_io, 0);
790
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100791 acpigen_write_resourcetemplate_footer();
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000792}
793
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100794void acpigen_write_mainboard_resources(const char *scope, const char *name)
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000795{
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100796 acpigen_write_scope(scope);
797 acpigen_write_name(name);
798 acpigen_write_mainboard_resource_template();
Vladimir Serbinenkoa09f4db2014-11-09 03:32:58 +0100799 acpigen_pop_len();
Tobias Diedrich0fe6e9a2010-11-17 16:27:06 +0000800}
Vladimir Serbinenko8ecdc9e2014-02-15 18:59:40 +0100801
802static int hex2bin(const char c)
803{
804 if (c >= 'A' && c <= 'F')
805 return c - 'A' + 10;
806 if (c >= 'a' && c <= 'f')
807 return c - 'a' + 10;
808 return c - '0';
809}
810
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100811void acpigen_emit_eisaid(const char *eisaid)
Vladimir Serbinenko8ecdc9e2014-02-15 18:59:40 +0100812{
813 u32 compact = 0;
814
815 /* Clamping individual values would be better but
816 there is a disagreement over what is a valid
817 EISA id, so accept anything and don't clamp,
818 parent code should create a valid EISAid.
819 */
820 compact |= (eisaid[0] - 'A' + 1) << 26;
821 compact |= (eisaid[1] - 'A' + 1) << 21;
822 compact |= (eisaid[2] - 'A' + 1) << 16;
823 compact |= hex2bin(eisaid[3]) << 12;
824 compact |= hex2bin(eisaid[4]) << 8;
825 compact |= hex2bin(eisaid[5]) << 4;
826 compact |= hex2bin(eisaid[6]);
827
828 acpigen_emit_byte(0xc);
829 acpigen_emit_byte((compact >> 24) & 0xff);
830 acpigen_emit_byte((compact >> 16) & 0xff);
831 acpigen_emit_byte((compact >> 8) & 0xff);
832 acpigen_emit_byte(compact & 0xff);
Vladimir Serbinenko8ecdc9e2014-02-15 18:59:40 +0100833}
Duncan Laurie3829f232016-05-09 11:08:46 -0700834
835/*
836 * ToUUID(uuid)
837 *
838 * ACPI 6.1 Section 19.6.136 table 19-385 defines a special output
839 * order for the bytes that make up a UUID Buffer object.
840 * UUID byte order for input:
841 * aabbccdd-eeff-gghh-iijj-kkllmmnnoopp
842 * UUID byte order for output:
843 * ddccbbaa-ffee-hhgg-iijj-kkllmmnnoopp
844 */
845#define UUID_LEN 16
846void acpigen_write_uuid(const char *uuid)
847{
848 uint8_t buf[UUID_LEN];
849 size_t i, order[UUID_LEN] = { 3, 2, 1, 0, 5, 4, 7, 6,
850 8, 9, 10, 11, 12, 13, 14, 15 };
851
852 /* Parse UUID string into bytes */
853 if (hexstrtobin(uuid, buf, UUID_LEN) < UUID_LEN)
854 return;
855
856 /* BufferOp */
857 acpigen_emit_byte(0x11);
858 acpigen_write_len_f();
859
860 /* Buffer length in bytes */
861 acpigen_write_word(UUID_LEN);
862
863 /* Output UUID in expected order */
864 for (i = 0; i < UUID_LEN; i++)
865 acpigen_emit_byte(buf[order[i]]);
866
867 acpigen_pop_len();
868}