1121d0712SMarkus Armbruster #ifndef HW_ACPI_AML_BUILD_H 2121d0712SMarkus Armbruster #define HW_ACPI_AML_BUILD_H 319934e0eSIgor Mammedov 4658c2718SShannon Zhao #include "hw/acpi/acpi-defs.h" 50e9b9edaSIgor Mammedov #include "hw/acpi/bios-linker-loader.h" 6658c2718SShannon Zhao 7658c2718SShannon Zhao #define ACPI_BUILD_APPNAME6 "BOCHS " 8602b4582SMarian Postevca #define ACPI_BUILD_APPNAME8 "BXPC " 9658c2718SShannon Zhao 10658c2718SShannon Zhao #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables" 11658c2718SShannon Zhao #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp" 12658c2718SShannon Zhao #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log" 13bac78f9cSShameer Kolothum #define ACPI_BUILD_LOADER_FILE "etc/table-loader" 1419934e0eSIgor Mammedov 15f294ecbcSIgor Mammedov #define AML_NOTIFY_METHOD "NTFY" 16f294ecbcSIgor Mammedov 170f2707e4SIgor Mammedov typedef enum { 180f2707e4SIgor Mammedov AML_NO_OPCODE = 0,/* has only data */ 190f2707e4SIgor Mammedov AML_OPCODE, /* has opcode optionally followed by data */ 200f2707e4SIgor Mammedov AML_PACKAGE, /* has opcode and uses PkgLength for its length */ 2156521fb8SMichael S. Tsirkin AML_EXT_PACKAGE, /* Same as AML_PACKAGE but also has 'ExOpPrefix' */ 220f2707e4SIgor Mammedov AML_BUFFER, /* data encoded as 'DefBuffer' */ 230f2707e4SIgor Mammedov AML_RES_TEMPLATE, /* encoded as ResourceTemplate macro */ 240f2707e4SIgor Mammedov } AmlBlockFlags; 250f2707e4SIgor Mammedov 260f2707e4SIgor Mammedov struct Aml { 270f2707e4SIgor Mammedov GArray *buf; 280f2707e4SIgor Mammedov 290f2707e4SIgor Mammedov /*< private >*/ 300f2707e4SIgor Mammedov uint8_t op; 310f2707e4SIgor Mammedov AmlBlockFlags block_flags; 320f2707e4SIgor Mammedov }; 330f2707e4SIgor Mammedov 3452fa397cSIgor Mammedov typedef enum { 35a23b8872SIgor Mammedov AML_COMPATIBILITY = 0, 36a23b8872SIgor Mammedov AML_TYPEA = 1, 37a23b8872SIgor Mammedov AML_TYPEB = 2, 38a23b8872SIgor Mammedov AML_TYPEF = 3, 39a23b8872SIgor Mammedov } AmlDmaType; 40a23b8872SIgor Mammedov 41a23b8872SIgor Mammedov typedef enum { 42a23b8872SIgor Mammedov AML_NOTBUSMASTER = 0, 43a23b8872SIgor Mammedov AML_BUSMASTER = 1, 44a23b8872SIgor Mammedov } AmlDmaBusMaster; 45a23b8872SIgor Mammedov 46a23b8872SIgor Mammedov typedef enum { 47a23b8872SIgor Mammedov AML_TRANSFER8 = 0, 48a23b8872SIgor Mammedov AML_TRANSFER8_16 = 1, 49a23b8872SIgor Mammedov AML_TRANSFER16 = 2, 50a23b8872SIgor Mammedov } AmlTransferSize; 51a23b8872SIgor Mammedov 52a23b8872SIgor Mammedov typedef enum { 53ff80dc7fSShannon Zhao AML_DECODE10 = 0, 54ff80dc7fSShannon Zhao AML_DECODE16 = 1, 5552fa397cSIgor Mammedov } AmlIODecode; 5652fa397cSIgor Mammedov 5731127938SIgor Mammedov typedef enum { 58ff80dc7fSShannon Zhao AML_ANY_ACC = 0, 59ff80dc7fSShannon Zhao AML_BYTE_ACC = 1, 60ff80dc7fSShannon Zhao AML_WORD_ACC = 2, 61ff80dc7fSShannon Zhao AML_DWORD_ACC = 3, 62ff80dc7fSShannon Zhao AML_QWORD_ACC = 4, 63ff80dc7fSShannon Zhao AML_BUFFER_ACC = 5, 64af509897SZhu Guihua } AmlAccessType; 65af509897SZhu Guihua 66af509897SZhu Guihua typedef enum { 6736de884aSIgor Mammedov AML_NOLOCK = 0, 6836de884aSIgor Mammedov AML_LOCK = 1, 6936de884aSIgor Mammedov } AmlLockRule; 7036de884aSIgor Mammedov 7136de884aSIgor Mammedov typedef enum { 72ff80dc7fSShannon Zhao AML_PRESERVE = 0, 73ff80dc7fSShannon Zhao AML_WRITE_AS_ONES = 1, 74ff80dc7fSShannon Zhao AML_WRITE_AS_ZEROS = 2, 75af509897SZhu Guihua } AmlUpdateRule; 76214ae59fSIgor Mammedov 77214ae59fSIgor Mammedov typedef enum { 78d0384d90SIgor Mammedov AML_AS_SYSTEM_MEMORY = 0X00, 79d0384d90SIgor Mammedov AML_AS_SYSTEM_IO = 0X01, 80d0384d90SIgor Mammedov AML_AS_PCI_CONFIG = 0X02, 81d0384d90SIgor Mammedov AML_AS_EMBEDDED_CTRL = 0X03, 82d0384d90SIgor Mammedov AML_AS_SMBUS = 0X04, 83d0384d90SIgor Mammedov AML_AS_FFH = 0X7F, 84d0384d90SIgor Mammedov } AmlAddressSpace; 85d0384d90SIgor Mammedov 86d0384d90SIgor Mammedov typedef enum { 87ff80dc7fSShannon Zhao AML_SYSTEM_MEMORY = 0X00, 88ff80dc7fSShannon Zhao AML_SYSTEM_IO = 0X01, 89e4db2798SIgor Mammedov AML_PCI_CONFIG = 0X02, 9031127938SIgor Mammedov } AmlRegionSpace; 9131127938SIgor Mammedov 926ece7053SIgor Mammedov typedef enum { 93ff80dc7fSShannon Zhao AML_MEMORY_RANGE = 0, 94ff80dc7fSShannon Zhao AML_IO_RANGE = 1, 95ff80dc7fSShannon Zhao AML_BUS_NUMBER_RANGE = 2, 966ece7053SIgor Mammedov } AmlResourceType; 976ece7053SIgor Mammedov 986ece7053SIgor Mammedov typedef enum { 99ff80dc7fSShannon Zhao AML_SUB_DECODE = 1 << 1, 100ff80dc7fSShannon Zhao AML_POS_DECODE = 0 1016ece7053SIgor Mammedov } AmlDecode; 1026ece7053SIgor Mammedov 1036ece7053SIgor Mammedov typedef enum { 104ff80dc7fSShannon Zhao AML_MAX_FIXED = 1 << 3, 105ff80dc7fSShannon Zhao AML_MAX_NOT_FIXED = 0, 1066ece7053SIgor Mammedov } AmlMaxFixed; 1076ece7053SIgor Mammedov 1086ece7053SIgor Mammedov typedef enum { 109ff80dc7fSShannon Zhao AML_MIN_FIXED = 1 << 2, 110ff80dc7fSShannon Zhao AML_MIN_NOT_FIXED = 0 1116ece7053SIgor Mammedov } AmlMinFixed; 1126ece7053SIgor Mammedov 1136ece7053SIgor Mammedov /* 1146ece7053SIgor Mammedov * ACPI 1.0b: Table 6-26 I/O Resource Flag (Resource Type = 1) Definitions 1156ece7053SIgor Mammedov * _RNG field definition 1166ece7053SIgor Mammedov */ 1176ece7053SIgor Mammedov typedef enum { 118ff80dc7fSShannon Zhao AML_ISA_ONLY = 1, 119ff80dc7fSShannon Zhao AML_NON_ISA_ONLY = 2, 120ff80dc7fSShannon Zhao AML_ENTIRE_RANGE = 3, 1216ece7053SIgor Mammedov } AmlISARanges; 1226ece7053SIgor Mammedov 1236ece7053SIgor Mammedov /* 1246ece7053SIgor Mammedov * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions 1256ece7053SIgor Mammedov * _MEM field definition 1266ece7053SIgor Mammedov */ 1276ece7053SIgor Mammedov typedef enum { 128ff80dc7fSShannon Zhao AML_NON_CACHEABLE = 0, 129ff80dc7fSShannon Zhao AML_CACHEABLE = 1, 130ff80dc7fSShannon Zhao AML_WRITE_COMBINING = 2, 131ff80dc7fSShannon Zhao AML_PREFETCHABLE = 3, 132ff80dc7fSShannon Zhao } AmlCacheable; 1336ece7053SIgor Mammedov 1346ece7053SIgor Mammedov /* 1356ece7053SIgor Mammedov * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions 1366ece7053SIgor Mammedov * _RW field definition 1376ece7053SIgor Mammedov */ 1386ece7053SIgor Mammedov typedef enum { 139ff80dc7fSShannon Zhao AML_READ_ONLY = 0, 140ff80dc7fSShannon Zhao AML_READ_WRITE = 1, 1416ece7053SIgor Mammedov } AmlReadAndWrite; 1426ece7053SIgor Mammedov 143205d1d1cSShannon Zhao /* 144205d1d1cSShannon Zhao * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition 145205d1d1cSShannon Zhao * Interrupt Vector Flags Bits[0] Consumer/Producer 146205d1d1cSShannon Zhao */ 147205d1d1cSShannon Zhao typedef enum { 148205d1d1cSShannon Zhao AML_CONSUMER_PRODUCER = 0, 149205d1d1cSShannon Zhao AML_CONSUMER = 1, 150205d1d1cSShannon Zhao } AmlConsumerAndProducer; 151205d1d1cSShannon Zhao 152205d1d1cSShannon Zhao /* 153205d1d1cSShannon Zhao * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition 154205d1d1cSShannon Zhao * _HE field definition 155205d1d1cSShannon Zhao */ 156205d1d1cSShannon Zhao typedef enum { 157205d1d1cSShannon Zhao AML_LEVEL = 0, 158205d1d1cSShannon Zhao AML_EDGE = 1, 159205d1d1cSShannon Zhao } AmlLevelAndEdge; 160205d1d1cSShannon Zhao 161205d1d1cSShannon Zhao /* 162205d1d1cSShannon Zhao * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition 163205d1d1cSShannon Zhao * _LL field definition 164205d1d1cSShannon Zhao */ 165205d1d1cSShannon Zhao typedef enum { 166205d1d1cSShannon Zhao AML_ACTIVE_HIGH = 0, 167205d1d1cSShannon Zhao AML_ACTIVE_LOW = 1, 168205d1d1cSShannon Zhao } AmlActiveHighAndLow; 169205d1d1cSShannon Zhao 170205d1d1cSShannon Zhao /* 171205d1d1cSShannon Zhao * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition 172205d1d1cSShannon Zhao * _SHR field definition 173205d1d1cSShannon Zhao */ 174205d1d1cSShannon Zhao typedef enum { 175205d1d1cSShannon Zhao AML_EXCLUSIVE = 0, 176205d1d1cSShannon Zhao AML_SHARED = 1, 177205d1d1cSShannon Zhao AML_EXCLUSIVE_AND_WAKE = 2, 178205d1d1cSShannon Zhao AML_SHARED_AND_WAKE = 3, 179205d1d1cSShannon Zhao } AmlShared; 180205d1d1cSShannon Zhao 1814dbfc881SXiao Guangrong /* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: MethodFlags */ 1824dbfc881SXiao Guangrong typedef enum { 1834dbfc881SXiao Guangrong AML_NOTSERIALIZED = 0, 1844dbfc881SXiao Guangrong AML_SERIALIZED = 1, 1854dbfc881SXiao Guangrong } AmlSerializeFlag; 1864dbfc881SXiao Guangrong 1874ecdc746SShannon Zhao /* 1884ecdc746SShannon Zhao * ACPI 5.0: Table 6-189 GPIO Connection Descriptor Definition 1894ecdc746SShannon Zhao * GPIO Connection Type 1904ecdc746SShannon Zhao */ 1914ecdc746SShannon Zhao typedef enum { 1924ecdc746SShannon Zhao AML_INTERRUPT_CONNECTION = 0, 1934ecdc746SShannon Zhao AML_IO_CONNECTION = 1, 1944ecdc746SShannon Zhao } AmlGpioConnectionType; 1954ecdc746SShannon Zhao 1964ecdc746SShannon Zhao /* 1974ecdc746SShannon Zhao * ACPI 5.0: Table 6-189 GPIO Connection Descriptor Definition 1984ecdc746SShannon Zhao * _PPI field definition 1994ecdc746SShannon Zhao */ 2004ecdc746SShannon Zhao typedef enum { 2014ecdc746SShannon Zhao AML_PULL_DEFAULT = 0, 2024ecdc746SShannon Zhao AML_PULL_UP = 1, 2034ecdc746SShannon Zhao AML_PULL_DOWN = 2, 2044ecdc746SShannon Zhao AML_PULL_NONE = 3, 2054ecdc746SShannon Zhao } AmlPinConfig; 2064ecdc746SShannon Zhao 20764b83136SShannon Zhao typedef enum { 20864b83136SShannon Zhao MEM_AFFINITY_NOFLAGS = 0, 20964b83136SShannon Zhao MEM_AFFINITY_ENABLED = (1 << 0), 21064b83136SShannon Zhao MEM_AFFINITY_HOTPLUGGABLE = (1 << 1), 21164b83136SShannon Zhao MEM_AFFINITY_NON_VOLATILE = (1 << 2), 21264b83136SShannon Zhao } MemoryAffinityFlags; 21364b83136SShannon Zhao 214658c2718SShannon Zhao typedef 215658c2718SShannon Zhao struct AcpiBuildTables { 216658c2718SShannon Zhao GArray *table_data; 217658c2718SShannon Zhao GArray *rsdp; 218658c2718SShannon Zhao GArray *tcpalog; 219c7809e6cSBen Warren GArray *vmgenid; 220aa16508fSDongjiu Geng GArray *hardware_errors; 2210e9b9edaSIgor Mammedov BIOSLinker *linker; 222658c2718SShannon Zhao } AcpiBuildTables; 223658c2718SShannon Zhao 22437d5c0a8SYubo Miao typedef 22537d5c0a8SYubo Miao struct CrsRangeEntry { 22637d5c0a8SYubo Miao uint64_t base; 22737d5c0a8SYubo Miao uint64_t limit; 22837d5c0a8SYubo Miao } CrsRangeEntry; 22937d5c0a8SYubo Miao 23037d5c0a8SYubo Miao typedef 23137d5c0a8SYubo Miao struct CrsRangeSet { 23237d5c0a8SYubo Miao GPtrArray *io_ranges; 23337d5c0a8SYubo Miao GPtrArray *mem_ranges; 23437d5c0a8SYubo Miao GPtrArray *mem_64bit_ranges; 23537d5c0a8SYubo Miao } CrsRangeSet; 23637d5c0a8SYubo Miao 23737d5c0a8SYubo Miao 238ef48a8ceSCorey Minyard /* 239ef48a8ceSCorey Minyard * ACPI 5.0: 6.4.3.8.2 Serial Bus Connection Descriptors 240ef48a8ceSCorey Minyard * Serial Bus Type 241ef48a8ceSCorey Minyard */ 242ef48a8ceSCorey Minyard #define AML_SERIAL_BUS_TYPE_I2C 1 243ef48a8ceSCorey Minyard #define AML_SERIAL_BUS_TYPE_SPI 2 244ef48a8ceSCorey Minyard #define AML_SERIAL_BUS_TYPE_UART 3 245ef48a8ceSCorey Minyard 246ef48a8ceSCorey Minyard /* 247ef48a8ceSCorey Minyard * ACPI 5.0: 6.4.3.8.2 Serial Bus Connection Descriptors 248ef48a8ceSCorey Minyard * General Flags 249ef48a8ceSCorey Minyard */ 250ef48a8ceSCorey Minyard /* Slave Mode */ 251ef48a8ceSCorey Minyard #define AML_SERIAL_BUS_FLAG_MASTER_DEVICE (1 << 0) 252ef48a8ceSCorey Minyard /* Consumer/Producer */ 253ef48a8ceSCorey Minyard #define AML_SERIAL_BUS_FLAG_CONSUME_ONLY (1 << 1) 254ef48a8ceSCorey Minyard 2550f2707e4SIgor Mammedov /** 2560f2707e4SIgor Mammedov * init_aml_allocator: 2570f2707e4SIgor Mammedov * 2580f2707e4SIgor Mammedov * Called for initializing API allocator which allow to use 2590f2707e4SIgor Mammedov * AML API. 2600f2707e4SIgor Mammedov * Returns: toplevel container which accumulates all other 2610f2707e4SIgor Mammedov * AML elements for a table. 2620f2707e4SIgor Mammedov */ 2630f2707e4SIgor Mammedov Aml *init_aml_allocator(void); 2640f2707e4SIgor Mammedov 2650f2707e4SIgor Mammedov /** 2660f2707e4SIgor Mammedov * free_aml_allocator: 2670f2707e4SIgor Mammedov * 2680f2707e4SIgor Mammedov * Releases all elements used by AML API, frees associated memory 2690f2707e4SIgor Mammedov * and invalidates AML allocator. After this call @init_aml_allocator 2700f2707e4SIgor Mammedov * should be called again if AML API is to be used again. 2710f2707e4SIgor Mammedov */ 2720f2707e4SIgor Mammedov void free_aml_allocator(void); 2730f2707e4SIgor Mammedov 2740f2707e4SIgor Mammedov /** 2750f2707e4SIgor Mammedov * aml_append: 2760f2707e4SIgor Mammedov * @parent_ctx: context to which @child element is added 2770f2707e4SIgor Mammedov * @child: element that is copied into @parent_ctx context 2780f2707e4SIgor Mammedov * 2790f2707e4SIgor Mammedov * Joins Aml elements together and helps to construct AML tables 280a1a62cedSMichael Tokarev * Example of usage: 2810f2707e4SIgor Mammedov * Aml *table = aml_def_block("SSDT", ...); 2827824df38SGal Hammer * Aml *sb = aml_scope("\\_SB"); 2830f2707e4SIgor Mammedov * Aml *dev = aml_device("PCI0"); 2840f2707e4SIgor Mammedov * 2850f2707e4SIgor Mammedov * aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03"))); 2860f2707e4SIgor Mammedov * aml_append(sb, dev); 2870f2707e4SIgor Mammedov * aml_append(table, sb); 2880f2707e4SIgor Mammedov */ 2890f2707e4SIgor Mammedov void aml_append(Aml *parent_ctx, Aml *child); 2900f2707e4SIgor Mammedov 2913c054bd5SIgor Mammedov /* non block AML object primitives */ 2929edc6313SMarc-André Lureau Aml *aml_name(const char *name_format, ...) G_GNUC_PRINTF(1, 2); 2933c054bd5SIgor Mammedov Aml *aml_name_decl(const char *name, Aml *val); 294e8977414SIgor Mammedov Aml *aml_debug(void); 295b25af5adSIgor Mammedov Aml *aml_return(Aml *val); 296295a515dSIgor Mammedov Aml *aml_int(const uint64_t val); 2977193f3a6SIgor Mammedov Aml *aml_arg(int pos); 298f411199dSIgor Mammedov Aml *aml_to_integer(Aml *arg); 2996d5ea945SIgor Mammedov Aml *aml_to_hexstring(Aml *src, Aml *dst); 30025c1432eSIgor Mammedov Aml *aml_to_buffer(Aml *src, Aml *dst); 301910e4069SIgor Mammedov Aml *aml_to_decimalstring(Aml *src, Aml *dst); 302c263b3f7SIgor Mammedov Aml *aml_store(Aml *val, Aml *target); 3035530427fSIgor Mammedov Aml *aml_and(Aml *arg1, Aml *arg2, Aml *dst); 304ca3df95dSIgor Mammedov Aml *aml_or(Aml *arg1, Aml *arg2, Aml *dst); 3055776fa99SIgor Mammedov Aml *aml_land(Aml *arg1, Aml *arg2); 306df241999SIgor Mammedov Aml *aml_lor(Aml *arg1, Aml *arg2); 307a57dddddSMarcel Apfelbaum Aml *aml_shiftleft(Aml *arg1, Aml *count); 308c360639aSIgor Mammedov Aml *aml_shiftright(Aml *arg1, Aml *count, Aml *dst); 30996396e28SMarcel Apfelbaum Aml *aml_lless(Aml *arg1, Aml *arg2); 31020ca5208SIgor Mammedov Aml *aml_add(Aml *arg1, Aml *arg2, Aml *dst); 3117059eb42SIgor Mammedov Aml *aml_subtract(Aml *arg1, Aml *arg2, Aml *dst); 312af39d536SMarcel Apfelbaum Aml *aml_increment(Aml *arg); 3137059eb42SIgor Mammedov Aml *aml_decrement(Aml *arg); 314928b8996SMarcel Apfelbaum Aml *aml_index(Aml *arg1, Aml *idx); 31534189453SIgor Mammedov Aml *aml_notify(Aml *arg1, Aml *arg2); 3165776fa99SIgor Mammedov Aml *aml_break(void); 3177b38ba9cSIgor Mammedov Aml *aml_call0(const char *method); 3183f3992b7SIgor Mammedov Aml *aml_call1(const char *method, Aml *arg1); 3193f3992b7SIgor Mammedov Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2); 3203f3992b7SIgor Mammedov Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3); 3213f3992b7SIgor Mammedov Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4); 322052889b8SXiao Guangrong Aml *aml_call5(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4, 323052889b8SXiao Guangrong Aml *arg5); 324910e4069SIgor Mammedov Aml *aml_call6(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4, 325910e4069SIgor Mammedov Aml *arg5, Aml *arg6); 32637d0e980SShannon Zhao Aml *aml_gpio_int(AmlConsumerAndProducer con_and_pro, 32737d0e980SShannon Zhao AmlLevelAndEdge edge_level, 32837d0e980SShannon Zhao AmlActiveHighAndLow active_level, AmlShared shared, 32937d0e980SShannon Zhao AmlPinConfig pin_config, uint16_t debounce_timeout, 33037d0e980SShannon Zhao const uint32_t pin_list[], uint32_t pin_count, 33137d0e980SShannon Zhao const char *resource_source_name, 33237d0e980SShannon Zhao const uint8_t *vendor_data, uint16_t vendor_data_len); 333dc17ab1dSShannon Zhao Aml *aml_memory32_fixed(uint32_t addr, uint32_t size, 334dc17ab1dSShannon Zhao AmlReadAndWrite read_and_write); 335205d1d1cSShannon Zhao Aml *aml_interrupt(AmlConsumerAndProducer con_and_pro, 336205d1d1cSShannon Zhao AmlLevelAndEdge level_and_edge, 337205d1d1cSShannon Zhao AmlActiveHighAndLow high_and_low, AmlShared shared, 33845fcf539SIgor Mammedov uint32_t *irq_list, uint8_t irq_count); 33952fa397cSIgor Mammedov Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base, 34052fa397cSIgor Mammedov uint8_t aln, uint8_t len); 34131127938SIgor Mammedov Aml *aml_operation_region(const char *name, AmlRegionSpace rs, 3423f3009c0SXiao Guangrong Aml *offset, uint32_t len); 34370560453SIgor Mammedov Aml *aml_irq_no_flags(uint8_t irq); 344214ae59fSIgor Mammedov Aml *aml_named_field(const char *name, unsigned length); 345e2ea299bSIgor Mammedov Aml *aml_reserved_field(unsigned length); 346b8a5d689SIgor Mammedov Aml *aml_local(int num); 3479edc6313SMarc-André Lureau Aml *aml_string(const char *name_format, ...) G_GNUC_PRINTF(1, 2); 348ea7df04aSShannon Zhao Aml *aml_lnot(Aml *arg); 34915e44e56SIgor Mammedov Aml *aml_equal(Aml *arg1, Aml *arg2); 350dabad78bSIgor Mammedov Aml *aml_lgreater(Aml *arg1, Aml *arg2); 3512d3f667dSIgor Mammedov Aml *aml_lgreater_equal(Aml *arg1, Aml *arg2); 3523dd15643SIgor Mammedov Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len, 3539edc6313SMarc-André Lureau const char *name_format, ...) G_GNUC_PRINTF(4, 5); 354a7891dacSIgor Mammedov Aml *aml_eisaid(const char *str); 3556ece7053SIgor Mammedov Aml *aml_word_bus_number(AmlMinFixed min_fixed, AmlMaxFixed max_fixed, 3566ece7053SIgor Mammedov AmlDecode dec, uint16_t addr_gran, 3576ece7053SIgor Mammedov uint16_t addr_min, uint16_t addr_max, 3586ece7053SIgor Mammedov uint16_t addr_trans, uint16_t len); 3596ece7053SIgor Mammedov Aml *aml_word_io(AmlMinFixed min_fixed, AmlMaxFixed max_fixed, 3606ece7053SIgor Mammedov AmlDecode dec, AmlISARanges isa_ranges, 3616ece7053SIgor Mammedov uint16_t addr_gran, uint16_t addr_min, 3626ece7053SIgor Mammedov uint16_t addr_max, uint16_t addr_trans, 3636ece7053SIgor Mammedov uint16_t len); 364616ef329SShannon Zhao Aml *aml_dword_io(AmlMinFixed min_fixed, AmlMaxFixed max_fixed, 365616ef329SShannon Zhao AmlDecode dec, AmlISARanges isa_ranges, 366616ef329SShannon Zhao uint32_t addr_gran, uint32_t addr_min, 367616ef329SShannon Zhao uint32_t addr_max, uint32_t addr_trans, 368616ef329SShannon Zhao uint32_t len); 3696ece7053SIgor Mammedov Aml *aml_dword_memory(AmlDecode dec, AmlMinFixed min_fixed, 370ff80dc7fSShannon Zhao AmlMaxFixed max_fixed, AmlCacheable cacheable, 3716ece7053SIgor Mammedov AmlReadAndWrite read_and_write, 3726ece7053SIgor Mammedov uint32_t addr_gran, uint32_t addr_min, 3736ece7053SIgor Mammedov uint32_t addr_max, uint32_t addr_trans, 3746ece7053SIgor Mammedov uint32_t len); 3756ece7053SIgor Mammedov Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed, 376ff80dc7fSShannon Zhao AmlMaxFixed max_fixed, AmlCacheable cacheable, 3776ece7053SIgor Mammedov AmlReadAndWrite read_and_write, 3786ece7053SIgor Mammedov uint64_t addr_gran, uint64_t addr_min, 3796ece7053SIgor Mammedov uint64_t addr_max, uint64_t addr_trans, 3806ece7053SIgor Mammedov uint64_t len); 381a23b8872SIgor Mammedov Aml *aml_dma(AmlDmaType typ, AmlDmaBusMaster bm, AmlTransferSize sz, 382a23b8872SIgor Mammedov uint8_t channel); 3830073518dSIgor Mammedov Aml *aml_sleep(uint64_t msec); 384ef48a8ceSCorey Minyard Aml *aml_i2c_serial_bus_device(uint16_t address, const char *resource_source); 3853c054bd5SIgor Mammedov 3862ef7c27bSIgor Mammedov /* Block AML object primitives */ 3879edc6313SMarc-André Lureau Aml *aml_scope(const char *name_format, ...) G_GNUC_PRINTF(1, 2); 3889edc6313SMarc-André Lureau Aml *aml_device(const char *name_format, ...) G_GNUC_PRINTF(1, 2); 3894dbfc881SXiao Guangrong Aml *aml_method(const char *name, int arg_count, AmlSerializeFlag sflag); 39032acac9eSIgor Mammedov Aml *aml_if(Aml *predicate); 391467b07dfSShannon Zhao Aml *aml_else(void); 39268e6b0afSMarcel Apfelbaum Aml *aml_while(Aml *predicate); 3933bfa74a7SIgor Mammedov Aml *aml_package(uint8_t num_elements); 394ed8b5847SShannon Zhao Aml *aml_buffer(int buffer_size, uint8_t *byte_list); 395ad4a80bcSIgor Mammedov Aml *aml_resource_template(void); 39636de884aSIgor Mammedov Aml *aml_field(const char *name, AmlAccessType type, AmlLockRule lock, 39736de884aSIgor Mammedov AmlUpdateRule rule); 3986e1db3f2SXiao Guangrong Aml *aml_mutex(const char *name, uint8_t sync_level); 3996e1db3f2SXiao Guangrong Aml *aml_acquire(Aml *mutex, uint16_t timeout); 4006e1db3f2SXiao Guangrong Aml *aml_release(Aml *mutex); 40167a5c0faSIgor Mammedov Aml *aml_alias(const char *source_object, const char *alias_object); 40239b6dbd8SXiao Guangrong Aml *aml_create_field(Aml *srcbuf, Aml *bit_index, Aml *num_bits, 40339b6dbd8SXiao Guangrong const char *name); 404ed8176a3SShannon Zhao Aml *aml_create_dword_field(Aml *srcbuf, Aml *index, const char *name); 4057e192a38SIgor Mammedov Aml *aml_create_qword_field(Aml *srcbuf, Aml *index, const char *name); 406a678508eSIgor Mammedov Aml *aml_varpackage(uint32_t num_elements); 407b930fb9dSShannon Zhao Aml *aml_touuid(const char *uuid); 408e1f776c4SShannon Zhao Aml *aml_unicode(const char *str); 4097bc6fd24SIgor Mammedov Aml *aml_refof(Aml *arg); 41095cb0661SXiao Guangrong Aml *aml_derefof(Aml *arg); 41152483d14SXiao Guangrong Aml *aml_sizeof(Aml *arg); 4129815cba5SXiao Guangrong Aml *aml_concatenate(Aml *source1, Aml *source2, Aml *target); 413b265f27cSXiao Guangrong Aml *aml_object_type(Aml *object); 4142ef7c27bSIgor Mammedov 415fb9f5926SDavid Kiarie void build_append_int_noprefix(GArray *table, uint64_t value, int size); 416c151fd87SIgor Mammedov 417c151fd87SIgor Mammedov typedef struct AcpiTable { 418c151fd87SIgor Mammedov const char *sig; 419c151fd87SIgor Mammedov const uint8_t rev; 420c151fd87SIgor Mammedov const char *oem_id; 421c151fd87SIgor Mammedov const char *oem_table_id; 422c151fd87SIgor Mammedov /* private vars tracking table state */ 423c151fd87SIgor Mammedov GArray *array; 424c151fd87SIgor Mammedov unsigned table_offset; 425c151fd87SIgor Mammedov } AcpiTable; 426c151fd87SIgor Mammedov 427c151fd87SIgor Mammedov /** 428c151fd87SIgor Mammedov * acpi_table_begin: 429c151fd87SIgor Mammedov * initializes table header and keeps track of 430c151fd87SIgor Mammedov * table data/offsets 431c151fd87SIgor Mammedov * @desc: ACPI table descriptor 432c151fd87SIgor Mammedov * @array: blob where the ACPI table will be composed/stored. 433c151fd87SIgor Mammedov */ 434c151fd87SIgor Mammedov void acpi_table_begin(AcpiTable *desc, GArray *array); 435c151fd87SIgor Mammedov 436c151fd87SIgor Mammedov /** 437c151fd87SIgor Mammedov * acpi_table_end: 438c151fd87SIgor Mammedov * sets actual table length and tells bios loader 439c151fd87SIgor Mammedov * where table is for the later initialization on 440c151fd87SIgor Mammedov * guest side. 441c151fd87SIgor Mammedov * @linker: reference to BIOSLinker object to use for the table 442c151fd87SIgor Mammedov * @table: ACPI table descriptor that was used with @acpi_table_begin 443c151fd87SIgor Mammedov * counterpart 444c151fd87SIgor Mammedov */ 445c151fd87SIgor Mammedov void acpi_table_end(BIOSLinker *linker, AcpiTable *table); 446c151fd87SIgor Mammedov 447658c2718SShannon Zhao void *acpi_data_push(GArray *table_data, unsigned size); 448658c2718SShannon Zhao unsigned acpi_data_len(GArray *table); 449658c2718SShannon Zhao void acpi_add_table(GArray *table_offsets, GArray *table_data); 450658c2718SShannon Zhao void acpi_build_tables_init(AcpiBuildTables *tables); 451658c2718SShannon Zhao void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre); 452243bdb79SShannon Zhao void 453a46ce1c2SSamuel Ortiz build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data); 454a46ce1c2SSamuel Ortiz void 4550e9b9edaSIgor Mammedov build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets, 45651513558SLaszlo Ersek const char *oem_id, const char *oem_table_id); 457cb51ac2fSArd Biesheuvel void 458cb51ac2fSArd Biesheuvel build_xsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets, 459cb51ac2fSArd Biesheuvel const char *oem_id, const char *oem_table_id); 460658c2718SShannon Zhao 461f2035491SMichael S. Tsirkin int 4628d0ac88eSStefan Weil build_append_named_dword(GArray *array, const char *name_format, ...) 4639edc6313SMarc-André Lureau G_GNUC_PRINTF(2, 3); 464f2035491SMichael S. Tsirkin 465d0384d90SIgor Mammedov void build_append_gas(GArray *table, AmlAddressSpace as, 466d0384d90SIgor Mammedov uint8_t bit_width, uint8_t bit_offset, 467d0384d90SIgor Mammedov uint8_t access_width, uint64_t address); 468d0384d90SIgor Mammedov 469d0384d90SIgor Mammedov static inline void 470d0384d90SIgor Mammedov build_append_gas_from_struct(GArray *table, const struct AcpiGenericAddress *s) 471d0384d90SIgor Mammedov { 472d0384d90SIgor Mammedov build_append_gas(table, s->space_id, s->bit_width, s->bit_offset, 473d0384d90SIgor Mammedov s->access_width, s->address); 474d0384d90SIgor Mammedov } 475d0384d90SIgor Mammedov 47637d5c0a8SYubo Miao void crs_range_insert(GPtrArray *ranges, uint64_t base, uint64_t limit); 47737d5c0a8SYubo Miao void crs_replace_with_free_ranges(GPtrArray *ranges, 47837d5c0a8SYubo Miao uint64_t start, uint64_t end); 47937d5c0a8SYubo Miao void crs_range_set_init(CrsRangeSet *range_set); 48037d5c0a8SYubo Miao void crs_range_set_free(CrsRangeSet *range_set); 48137d5c0a8SYubo Miao 482e41ee855SJiahui Cen Aml *build_crs(PCIHostState *host, CrsRangeSet *range_set, uint32_t io_offset, 483e41ee855SJiahui Cen uint32_t mmio32_offset, uint64_t mmio64_offset, 484e41ee855SJiahui Cen uint16_t bus_nr_offset); 48537d5c0a8SYubo Miao 486e5b6d55aSIgor Mammedov void build_srat_memory(GArray *table_data, uint64_t base, 48764b83136SShannon Zhao uint64_t len, int node, MemoryAffinityFlags flags); 48864b83136SShannon Zhao 489602b4582SMarian Postevca void build_slit(GArray *table_data, BIOSLinker *linker, MachineState *ms, 490602b4582SMarian Postevca const char *oem_id, const char *oem_table_id); 4918612f8bdSIgor Mammedov 492099f2df2SAndrew Jones void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms, 493099f2df2SAndrew Jones const char *oem_id, const char *oem_table_id); 494099f2df2SAndrew Jones 4958612f8bdSIgor Mammedov void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f, 4968612f8bdSIgor Mammedov const char *oem_id, const char *oem_table_id); 49743384160SEric Auger 498602b4582SMarian Postevca void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog, 499602b4582SMarian Postevca const char *oem_id, const char *oem_table_id); 500*7dd0b070SSia Jee Heng 501*7dd0b070SSia Jee Heng void build_spcr(GArray *table_data, BIOSLinker *linker, 502*7dd0b070SSia Jee Heng const AcpiSpcrData *f, const uint8_t rev, 503*7dd0b070SSia Jee Heng const char *oem_id, const char *oem_table_id); 50419934e0eSIgor Mammedov #endif 505