1 /* Support for generating ACPI tables and passing them to Guests
3 * Copyright (C) 2015 Red Hat Inc
5 * Author: Michael S. Tsirkin <mst@redhat.com>
6 * Author: Igor Mammedov <imammedo@redhat.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, see <http://www.gnu.org/licenses/>.
27 #include "hw/acpi/aml-build.h"
28 #include "qemu/bswap.h"
30 static GArray
*build_alloc_array(void)
32 return g_array_new(false, true /* clear */, 1);
35 static void build_free_array(GArray
*array
)
37 g_array_free(array
, true);
40 static void build_prepend_byte(GArray
*array
, uint8_t val
)
42 g_array_prepend_val(array
, val
);
45 static void build_append_byte(GArray
*array
, uint8_t val
)
47 g_array_append_val(array
, val
);
50 static void build_append_array(GArray
*array
, GArray
*val
)
52 g_array_append_vals(array
, val
->data
, val
->len
);
55 #define ACPI_NAMESEG_LEN 4
58 build_append_nameseg(GArray
*array
, const char *seg
)
60 /* It would be nicer to use g_string_vprintf but it's only there in 2.22 */
64 assert(len
<= ACPI_NAMESEG_LEN
);
66 g_array_append_vals(array
, seg
, len
);
67 /* Pad up to ACPI_NAMESEG_LEN characters if necessary. */
68 g_array_append_vals(array
, "____", ACPI_NAMESEG_LEN
- len
);
72 build_append_namestringv(GArray
*array
, const char *format
, va_list ap
)
74 /* It would be nicer to use g_string_vprintf but it's only there in 2.22 */
83 len
= vsnprintf(NULL
, 0, format
, va_len
);
86 s
= g_new(typeof(*s
), len
);
88 len
= vsnprintf(s
, len
, format
, ap
);
90 segs
= g_strsplit(s
, ".", 0);
100 * ACPI 5.0 spec: 20.2.2 Name Objects Encoding:
101 * "SegCount can be from 1 to 255"
103 assert(seg_count
> 0 && seg_count
<= 255);
105 /* handle RootPath || PrefixPath */
107 while (*s
== '\\' || *s
== '^') {
108 build_append_byte(array
, *s
);
115 build_append_byte(array
, 0x00); /* NullName */
117 build_append_nameseg(array
, s
);
122 build_append_byte(array
, 0x2E); /* DualNamePrefix */
123 build_append_nameseg(array
, s
);
124 build_append_nameseg(array
, segs
[1]);
127 build_append_byte(array
, 0x2F); /* MultiNamePrefix */
128 build_append_byte(array
, seg_count
);
130 /* handle the 1st segment manually due to prefix/root path */
131 build_append_nameseg(array
, s
);
133 /* add the rest of segments */
134 segs_iter
= segs
+ 1;
136 build_append_nameseg(array
, *segs_iter
);
145 static void build_append_namestring(GArray
*array
, const char *format
, ...)
149 va_start(ap
, format
);
150 build_append_namestringv(array
, format
, ap
);
154 /* 5.4 Definition Block Encoding */
156 PACKAGE_LENGTH_1BYTE_SHIFT
= 6, /* Up to 63 - use extra 2 bits. */
157 PACKAGE_LENGTH_2BYTE_SHIFT
= 4,
158 PACKAGE_LENGTH_3BYTE_SHIFT
= 12,
159 PACKAGE_LENGTH_4BYTE_SHIFT
= 20,
163 build_prepend_package_length(GArray
*package
, unsigned length
, bool incl_self
)
166 unsigned length_bytes
;
168 if (length
+ 1 < (1 << PACKAGE_LENGTH_1BYTE_SHIFT
)) {
170 } else if (length
+ 2 < (1 << PACKAGE_LENGTH_3BYTE_SHIFT
)) {
172 } else if (length
+ 3 < (1 << PACKAGE_LENGTH_4BYTE_SHIFT
)) {
179 * NamedField uses PkgLength encoding but it doesn't include length
180 * of PkgLength itself.
184 * PkgLength is the length of the inclusive length of the data
185 * and PkgLength's length itself when used for terms with
188 length
+= length_bytes
;
191 switch (length_bytes
) {
194 build_prepend_byte(package
, byte
);
197 byte
= length
>> PACKAGE_LENGTH_4BYTE_SHIFT
;
198 build_prepend_byte(package
, byte
);
199 length
&= (1 << PACKAGE_LENGTH_4BYTE_SHIFT
) - 1;
202 byte
= length
>> PACKAGE_LENGTH_3BYTE_SHIFT
;
203 build_prepend_byte(package
, byte
);
204 length
&= (1 << PACKAGE_LENGTH_3BYTE_SHIFT
) - 1;
207 byte
= length
>> PACKAGE_LENGTH_2BYTE_SHIFT
;
208 build_prepend_byte(package
, byte
);
209 length
&= (1 << PACKAGE_LENGTH_2BYTE_SHIFT
) - 1;
213 * Most significant two bits of byte zero indicate how many following bytes
214 * are in PkgLength encoding.
216 byte
= ((length_bytes
- 1) << PACKAGE_LENGTH_1BYTE_SHIFT
) | length
;
217 build_prepend_byte(package
, byte
);
221 build_append_pkg_length(GArray
*array
, unsigned length
, bool incl_self
)
223 GArray
*tmp
= build_alloc_array();
225 build_prepend_package_length(tmp
, length
, incl_self
);
226 build_append_array(array
, tmp
);
227 build_free_array(tmp
);
230 static void build_package(GArray
*package
, uint8_t op
)
232 build_prepend_package_length(package
, package
->len
, true);
233 build_prepend_byte(package
, op
);
236 static void build_extop_package(GArray
*package
, uint8_t op
)
238 build_package(package
, op
);
239 build_prepend_byte(package
, 0x5B); /* ExtOpPrefix */
242 static void build_append_int_noprefix(GArray
*table
, uint64_t value
, int size
)
246 for (i
= 0; i
< size
; ++i
) {
247 build_append_byte(table
, value
& 0xFF);
252 static void build_append_int(GArray
*table
, uint64_t value
)
255 build_append_byte(table
, 0x00); /* ZeroOp */
256 } else if (value
== 0x01) {
257 build_append_byte(table
, 0x01); /* OneOp */
258 } else if (value
<= 0xFF) {
259 build_append_byte(table
, 0x0A); /* BytePrefix */
260 build_append_int_noprefix(table
, value
, 1);
261 } else if (value
<= 0xFFFF) {
262 build_append_byte(table
, 0x0B); /* WordPrefix */
263 build_append_int_noprefix(table
, value
, 2);
264 } else if (value
<= 0xFFFFFFFF) {
265 build_append_byte(table
, 0x0C); /* DWordPrefix */
266 build_append_int_noprefix(table
, value
, 4);
268 build_append_byte(table
, 0x0E); /* QWordPrefix */
269 build_append_int_noprefix(table
, value
, 8);
273 static GPtrArray
*alloc_list
;
275 static Aml
*aml_alloc(void)
277 Aml
*var
= g_new0(typeof(*var
), 1);
279 g_ptr_array_add(alloc_list
, var
);
280 var
->block_flags
= AML_NO_OPCODE
;
281 var
->buf
= build_alloc_array();
285 static Aml
*aml_opcode(uint8_t op
)
287 Aml
*var
= aml_alloc();
290 var
->block_flags
= AML_OPCODE
;
294 static Aml
*aml_bundle(uint8_t op
, AmlBlockFlags flags
)
296 Aml
*var
= aml_alloc();
299 var
->block_flags
= flags
;
303 static void aml_free(gpointer data
, gpointer user_data
)
306 build_free_array(var
->buf
);
309 Aml
*init_aml_allocator(void)
314 alloc_list
= g_ptr_array_new();
319 void free_aml_allocator(void)
321 g_ptr_array_foreach(alloc_list
, aml_free
, NULL
);
322 g_ptr_array_free(alloc_list
, true);
326 /* pack data with DefBuffer encoding */
327 static void build_buffer(GArray
*array
, uint8_t op
)
329 GArray
*data
= build_alloc_array();
331 build_append_int(data
, array
->len
);
332 g_array_prepend_vals(array
, data
->data
, data
->len
);
333 build_free_array(data
);
334 build_package(array
, op
);
337 void aml_append(Aml
*parent_ctx
, Aml
*child
)
339 GArray
*buf
= build_alloc_array();
340 build_append_array(buf
, child
->buf
);
342 switch (child
->block_flags
) {
344 build_append_byte(parent_ctx
->buf
, child
->op
);
346 case AML_EXT_PACKAGE
:
347 build_extop_package(buf
, child
->op
);
350 build_package(buf
, child
->op
);
352 case AML_RES_TEMPLATE
:
353 build_append_byte(buf
, 0x79); /* EndTag */
355 * checksum operations are treated as succeeded if checksum
356 * field is zero. [ACPI Spec 1.0b, 6.4.2.8 End Tag]
358 build_append_byte(buf
, 0);
359 /* fall through, to pack resources in buffer */
361 build_buffer(buf
, child
->op
);
369 build_append_array(parent_ctx
->buf
, buf
);
370 build_free_array(buf
);
373 /* ACPI 1.0b: 16.2.5.1 Namespace Modifier Objects Encoding: DefScope */
374 Aml
*aml_scope(const char *name_format
, ...)
377 Aml
*var
= aml_bundle(0x10 /* ScopeOp */, AML_PACKAGE
);
378 va_start(ap
, name_format
);
379 build_append_namestringv(var
->buf
, name_format
, ap
);
384 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefReturn */
385 Aml
*aml_return(Aml
*val
)
387 Aml
*var
= aml_opcode(0xA4 /* ReturnOp */);
388 aml_append(var
, val
);
393 * ACPI 1.0b: 16.2.3 Data Objects Encoding:
394 * encodes: ByteConst, WordConst, DWordConst, QWordConst, ZeroOp, OneOp
396 Aml
*aml_int(const uint64_t val
)
398 Aml
*var
= aml_alloc();
399 build_append_int(var
->buf
, val
);
404 * helper to construct NameString, which returns Aml object
405 * for using with aml_append or other aml_* terms
407 Aml
*aml_name(const char *name_format
, ...)
410 Aml
*var
= aml_alloc();
411 va_start(ap
, name_format
);
412 build_append_namestringv(var
->buf
, name_format
, ap
);
417 /* ACPI 1.0b: 16.2.5.1 Namespace Modifier Objects Encoding: DefName */
418 Aml
*aml_name_decl(const char *name
, Aml
*val
)
420 Aml
*var
= aml_opcode(0x08 /* NameOp */);
421 build_append_namestring(var
->buf
, "%s", name
);
422 aml_append(var
, val
);
426 /* ACPI 1.0b: 16.2.6.1 Arg Objects Encoding */
427 Aml
*aml_arg(int pos
)
430 uint8_t op
= 0x68 /* ARG0 op */ + pos
;
433 var
= aml_opcode(op
);
437 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefStore */
438 Aml
*aml_store(Aml
*val
, Aml
*target
)
440 Aml
*var
= aml_opcode(0x70 /* StoreOp */);
441 aml_append(var
, val
);
442 aml_append(var
, target
);
446 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefAnd */
447 Aml
*aml_and(Aml
*arg1
, Aml
*arg2
)
449 Aml
*var
= aml_opcode(0x7B /* AndOp */);
450 aml_append(var
, arg1
);
451 aml_append(var
, arg2
);
452 build_append_byte(var
->buf
, 0x00 /* NullNameOp */);
456 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefNotify */
457 Aml
*aml_notify(Aml
*arg1
, Aml
*arg2
)
459 Aml
*var
= aml_opcode(0x86 /* NotifyOp */);
460 aml_append(var
, arg1
);
461 aml_append(var
, arg2
);
465 /* helper to call method with 1 argument */
466 Aml
*aml_call1(const char *method
, Aml
*arg1
)
468 Aml
*var
= aml_alloc();
469 build_append_namestring(var
->buf
, "%s", method
);
470 aml_append(var
, arg1
);
474 /* helper to call method with 2 arguments */
475 Aml
*aml_call2(const char *method
, Aml
*arg1
, Aml
*arg2
)
477 Aml
*var
= aml_alloc();
478 build_append_namestring(var
->buf
, "%s", method
);
479 aml_append(var
, arg1
);
480 aml_append(var
, arg2
);
484 /* helper to call method with 3 arguments */
485 Aml
*aml_call3(const char *method
, Aml
*arg1
, Aml
*arg2
, Aml
*arg3
)
487 Aml
*var
= aml_alloc();
488 build_append_namestring(var
->buf
, "%s", method
);
489 aml_append(var
, arg1
);
490 aml_append(var
, arg2
);
491 aml_append(var
, arg3
);
495 /* helper to call method with 4 arguments */
496 Aml
*aml_call4(const char *method
, Aml
*arg1
, Aml
*arg2
, Aml
*arg3
, Aml
*arg4
)
498 Aml
*var
= aml_alloc();
499 build_append_namestring(var
->buf
, "%s", method
);
500 aml_append(var
, arg1
);
501 aml_append(var
, arg2
);
502 aml_append(var
, arg3
);
503 aml_append(var
, arg4
);
507 /* ACPI 1.0b: 6.4.2.5 I/O Port Descriptor */
508 Aml
*aml_io(AmlIODecode dec
, uint16_t min_base
, uint16_t max_base
,
509 uint8_t aln
, uint8_t len
)
511 Aml
*var
= aml_alloc();
512 build_append_byte(var
->buf
, 0x47); /* IO port descriptor */
513 build_append_byte(var
->buf
, dec
);
514 build_append_byte(var
->buf
, min_base
& 0xff);
515 build_append_byte(var
->buf
, (min_base
>> 8) & 0xff);
516 build_append_byte(var
->buf
, max_base
& 0xff);
517 build_append_byte(var
->buf
, (max_base
>> 8) & 0xff);
518 build_append_byte(var
->buf
, aln
);
519 build_append_byte(var
->buf
, len
);
524 * ACPI 1.0b: 6.4.2.1.1 ASL Macro for IRQ Descriptor
526 * More verbose description at:
527 * ACPI 5.0: 19.5.64 IRQNoFlags (Interrupt Resource Descriptor Macro)
528 * 6.4.2.1 IRQ Descriptor
530 Aml
*aml_irq_no_flags(uint8_t irq
)
533 Aml
*var
= aml_alloc();
536 build_append_byte(var
->buf
, 0x22); /* IRQ descriptor 2 byte form */
538 irq_mask
= 1U << irq
;
539 build_append_byte(var
->buf
, irq_mask
& 0xFF); /* IRQ mask bits[7:0] */
540 build_append_byte(var
->buf
, irq_mask
>> 8); /* IRQ mask bits[15:8] */
544 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLEqual */
545 Aml
*aml_equal(Aml
*arg1
, Aml
*arg2
)
547 Aml
*var
= aml_opcode(0x93 /* LequalOp */);
548 aml_append(var
, arg1
);
549 aml_append(var
, arg2
);
553 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
554 Aml
*aml_if(Aml
*predicate
)
556 Aml
*var
= aml_bundle(0xA0 /* IfOp */, AML_PACKAGE
);
557 aml_append(var
, predicate
);
561 /* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefMethod */
562 Aml
*aml_method(const char *name
, int arg_count
)
564 Aml
*var
= aml_bundle(0x14 /* MethodOp */, AML_PACKAGE
);
565 build_append_namestring(var
->buf
, "%s", name
);
566 build_append_byte(var
->buf
, arg_count
); /* MethodFlags: ArgCount */
570 /* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefDevice */
571 Aml
*aml_device(const char *name_format
, ...)
574 Aml
*var
= aml_bundle(0x82 /* DeviceOp */, AML_EXT_PACKAGE
);
575 va_start(ap
, name_format
);
576 build_append_namestringv(var
->buf
, name_format
, ap
);
581 /* ACPI 1.0b: 6.4.1 ASL Macros for Resource Descriptors */
582 Aml
*aml_resource_template(void)
584 /* ResourceTemplate is a buffer of Resources with EndTag at the end */
585 Aml
*var
= aml_bundle(0x11 /* BufferOp */, AML_RES_TEMPLATE
);
589 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefBuffer */
590 Aml
*aml_buffer(void)
592 Aml
*var
= aml_bundle(0x11 /* BufferOp */, AML_BUFFER
);
596 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefPackage */
597 Aml
*aml_package(uint8_t num_elements
)
599 Aml
*var
= aml_bundle(0x12 /* PackageOp */, AML_PACKAGE
);
600 build_append_byte(var
->buf
, num_elements
);
604 /* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefOpRegion */
605 Aml
*aml_operation_region(const char *name
, AmlRegionSpace rs
,
606 uint32_t offset
, uint32_t len
)
608 Aml
*var
= aml_alloc();
609 build_append_byte(var
->buf
, 0x5B); /* ExtOpPrefix */
610 build_append_byte(var
->buf
, 0x80); /* OpRegionOp */
611 build_append_namestring(var
->buf
, "%s", name
);
612 build_append_byte(var
->buf
, rs
);
613 build_append_int(var
->buf
, offset
);
614 build_append_int(var
->buf
, len
);
618 /* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: NamedField */
619 Aml
*aml_named_field(const char *name
, unsigned length
)
621 Aml
*var
= aml_alloc();
622 build_append_nameseg(var
->buf
, name
);
623 build_append_pkg_length(var
->buf
, length
, false);
627 /* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: ReservedField */
628 Aml
*aml_reserved_field(unsigned length
)
630 Aml
*var
= aml_alloc();
631 /* ReservedField := 0x00 PkgLength */
632 build_append_byte(var
->buf
, 0x00);
633 build_append_pkg_length(var
->buf
, length
, false);
637 /* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefField */
638 Aml
*aml_field(const char *name
, AmlFieldFlags flags
)
640 Aml
*var
= aml_bundle(0x81 /* FieldOp */, AML_EXT_PACKAGE
);
641 build_append_namestring(var
->buf
, "%s", name
);
642 build_append_byte(var
->buf
, flags
);
646 /* ACPI 1.0b: 16.2.3 Data Objects Encoding: String */
647 Aml
*aml_string(const char *name_format
, ...)
649 Aml
*var
= aml_opcode(0x0D /* StringPrefix */);
654 va_start(ap
, name_format
);
656 len
= vsnprintf(NULL
, 0, name_format
, va_len
);
659 s
= g_new0(typeof(*s
), len
);
661 len
= vsnprintf(s
, len
, name_format
, ap
);
664 g_array_append_vals(var
->buf
, s
, len
);
665 build_append_byte(var
->buf
, 0x0); /* NullChar */
671 /* ACPI 1.0b: 16.2.6.2 Local Objects Encoding */
672 Aml
*aml_local(int num
)
675 uint8_t op
= 0x60 /* Local0Op */ + num
;
678 var
= aml_opcode(op
);
682 /* ACPI 2.0a: 17.2.2 Data Objects Encoding: DefVarPackage */
683 Aml
*aml_varpackage(uint32_t num_elements
)
685 Aml
*var
= aml_bundle(0x13 /* VarPackageOp */, AML_PACKAGE
);
686 build_append_int(var
->buf
, num_elements
);
690 /* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefProcessor */
691 Aml
*aml_processor(uint8_t proc_id
, uint32_t pblk_addr
, uint8_t pblk_len
,
692 const char *name_format
, ...)
695 Aml
*var
= aml_bundle(0x83 /* ProcessorOp */, AML_EXT_PACKAGE
);
696 va_start(ap
, name_format
);
697 build_append_namestringv(var
->buf
, name_format
, ap
);
699 build_append_byte(var
->buf
, proc_id
); /* ProcID */
700 build_append_int_noprefix(var
->buf
, pblk_addr
, sizeof(pblk_addr
));
701 build_append_byte(var
->buf
, pblk_len
); /* PblkLen */
705 static uint8_t Hex2Digit(char c
)
714 /* ACPI 1.0b: 15.2.3.6.4.1 EISAID Macro - Convert EISA ID String To Integer */
715 Aml
*aml_eisaid(const char *str
)
717 Aml
*var
= aml_alloc();
720 g_assert(strlen(str
) == 7);
721 id
= (str
[0] - 0x40) << 26 |
722 (str
[1] - 0x40) << 21 |
723 (str
[2] - 0x40) << 16 |
724 Hex2Digit(str
[3]) << 12 |
725 Hex2Digit(str
[4]) << 8 |
726 Hex2Digit(str
[5]) << 4 |
729 build_append_byte(var
->buf
, 0x0C); /* DWordPrefix */
730 build_append_int_noprefix(var
->buf
, bswap32(id
), sizeof(id
));
734 /* ACPI 1.0b: 6.4.3.5.5 Word Address Space Descriptor: bytes 3-5 */
735 static Aml
*aml_as_desc_header(AmlResourceType type
, AmlMinFixed min_fixed
,
736 AmlMaxFixed max_fixed
, AmlDecode dec
,
739 uint8_t flags
= max_fixed
| min_fixed
| dec
;
740 Aml
*var
= aml_alloc();
742 build_append_byte(var
->buf
, type
);
743 build_append_byte(var
->buf
, flags
);
744 build_append_byte(var
->buf
, type_flags
); /* Type Specific Flags */
748 /* ACPI 1.0b: 6.4.3.5.5 Word Address Space Descriptor */
749 static Aml
*aml_word_as_desc(AmlResourceType type
, AmlMinFixed min_fixed
,
750 AmlMaxFixed max_fixed
, AmlDecode dec
,
751 uint16_t addr_gran
, uint16_t addr_min
,
752 uint16_t addr_max
, uint16_t addr_trans
,
753 uint16_t len
, uint8_t type_flags
)
755 Aml
*var
= aml_alloc();
757 build_append_byte(var
->buf
, 0x88); /* Word Address Space Descriptor */
758 /* minimum length since we do not encode optional fields */
759 build_append_byte(var
->buf
, 0x0D);
760 build_append_byte(var
->buf
, 0x0);
763 aml_as_desc_header(type
, min_fixed
, max_fixed
, dec
, type_flags
));
764 build_append_int_noprefix(var
->buf
, addr_gran
, sizeof(addr_gran
));
765 build_append_int_noprefix(var
->buf
, addr_min
, sizeof(addr_min
));
766 build_append_int_noprefix(var
->buf
, addr_max
, sizeof(addr_max
));
767 build_append_int_noprefix(var
->buf
, addr_trans
, sizeof(addr_trans
));
768 build_append_int_noprefix(var
->buf
, len
, sizeof(len
));
772 /* ACPI 1.0b: 6.4.3.5.3 DWord Address Space Descriptor */
773 static Aml
*aml_dword_as_desc(AmlResourceType type
, AmlMinFixed min_fixed
,
774 AmlMaxFixed max_fixed
, AmlDecode dec
,
775 uint32_t addr_gran
, uint32_t addr_min
,
776 uint32_t addr_max
, uint32_t addr_trans
,
777 uint32_t len
, uint8_t type_flags
)
779 Aml
*var
= aml_alloc();
781 build_append_byte(var
->buf
, 0x87); /* DWord Address Space Descriptor */
782 /* minimum length since we do not encode optional fields */
783 build_append_byte(var
->buf
, 23);
784 build_append_byte(var
->buf
, 0x0);
788 aml_as_desc_header(type
, min_fixed
, max_fixed
, dec
, type_flags
));
789 build_append_int_noprefix(var
->buf
, addr_gran
, sizeof(addr_gran
));
790 build_append_int_noprefix(var
->buf
, addr_min
, sizeof(addr_min
));
791 build_append_int_noprefix(var
->buf
, addr_max
, sizeof(addr_max
));
792 build_append_int_noprefix(var
->buf
, addr_trans
, sizeof(addr_trans
));
793 build_append_int_noprefix(var
->buf
, len
, sizeof(len
));
797 /* ACPI 1.0b: 6.4.3.5.1 QWord Address Space Descriptor */
798 static Aml
*aml_qword_as_desc(AmlResourceType type
, AmlMinFixed min_fixed
,
799 AmlMaxFixed max_fixed
, AmlDecode dec
,
800 uint64_t addr_gran
, uint64_t addr_min
,
801 uint64_t addr_max
, uint64_t addr_trans
,
802 uint64_t len
, uint8_t type_flags
)
804 Aml
*var
= aml_alloc();
806 build_append_byte(var
->buf
, 0x8A); /* QWord Address Space Descriptor */
807 /* minimum length since we do not encode optional fields */
808 build_append_byte(var
->buf
, 0x2B);
809 build_append_byte(var
->buf
, 0x0);
812 aml_as_desc_header(type
, min_fixed
, max_fixed
, dec
, type_flags
));
813 build_append_int_noprefix(var
->buf
, addr_gran
, sizeof(addr_gran
));
814 build_append_int_noprefix(var
->buf
, addr_min
, sizeof(addr_min
));
815 build_append_int_noprefix(var
->buf
, addr_max
, sizeof(addr_max
));
816 build_append_int_noprefix(var
->buf
, addr_trans
, sizeof(addr_trans
));
817 build_append_int_noprefix(var
->buf
, len
, sizeof(len
));
822 * ACPI 1.0b: 6.4.3.5.6 ASL Macros for WORD Address Descriptor
824 * More verbose description at:
825 * ACPI 5.0: 19.5.141 WordBusNumber (Word Bus Number Resource Descriptor Macro)
827 Aml
*aml_word_bus_number(AmlMinFixed min_fixed
, AmlMaxFixed max_fixed
,
828 AmlDecode dec
, uint16_t addr_gran
,
829 uint16_t addr_min
, uint16_t addr_max
,
830 uint16_t addr_trans
, uint16_t len
)
833 return aml_word_as_desc(aml_bus_number_range
, min_fixed
, max_fixed
, dec
,
834 addr_gran
, addr_min
, addr_max
, addr_trans
, len
, 0);
838 * ACPI 1.0b: 6.4.3.5.6 ASL Macros for WORD Address Descriptor
840 * More verbose description at:
841 * ACPI 5.0: 19.5.142 WordIO (Word IO Resource Descriptor Macro)
843 Aml
*aml_word_io(AmlMinFixed min_fixed
, AmlMaxFixed max_fixed
,
844 AmlDecode dec
, AmlISARanges isa_ranges
,
845 uint16_t addr_gran
, uint16_t addr_min
,
846 uint16_t addr_max
, uint16_t addr_trans
,
850 return aml_word_as_desc(aml_io_range
, min_fixed
, max_fixed
, dec
,
851 addr_gran
, addr_min
, addr_max
, addr_trans
, len
,
856 * ACPI 1.0b: 6.4.3.5.4 ASL Macros for DWORD Address Space Descriptor
858 * More verbose description at:
859 * ACPI 5.0: 19.5.34 DWordMemory (DWord Memory Resource Descriptor Macro)
861 Aml
*aml_dword_memory(AmlDecode dec
, AmlMinFixed min_fixed
,
862 AmlMaxFixed max_fixed
, AmlCacheble cacheable
,
863 AmlReadAndWrite read_and_write
,
864 uint32_t addr_gran
, uint32_t addr_min
,
865 uint32_t addr_max
, uint32_t addr_trans
,
868 uint8_t flags
= read_and_write
| (cacheable
<< 1);
870 return aml_dword_as_desc(aml_memory_range
, min_fixed
, max_fixed
,
871 dec
, addr_gran
, addr_min
, addr_max
,
872 addr_trans
, len
, flags
);
876 * ACPI 1.0b: 6.4.3.5.2 ASL Macros for QWORD Address Space Descriptor
878 * More verbose description at:
879 * ACPI 5.0: 19.5.102 QWordMemory (QWord Memory Resource Descriptor Macro)
881 Aml
*aml_qword_memory(AmlDecode dec
, AmlMinFixed min_fixed
,
882 AmlMaxFixed max_fixed
, AmlCacheble cacheable
,
883 AmlReadAndWrite read_and_write
,
884 uint64_t addr_gran
, uint64_t addr_min
,
885 uint64_t addr_max
, uint64_t addr_trans
,
888 uint8_t flags
= read_and_write
| (cacheable
<< 1);
890 return aml_qword_as_desc(aml_memory_range
, min_fixed
, max_fixed
,
891 dec
, addr_gran
, addr_min
, addr_max
,
892 addr_trans
, len
, flags
);