qemu/include/hw/acpi/aml-build.h
<<
>>
Prefs
   1#ifndef HW_ACPI_AML_BUILD_H
   2#define HW_ACPI_AML_BUILD_H
   3
   4#include "hw/acpi/acpi-defs.h"
   5#include "hw/acpi/bios-linker-loader.h"
   6
   7/* Reserve RAM space for tables: add another order of magnitude. */
   8#define ACPI_BUILD_TABLE_MAX_SIZE         0x200000
   9
  10#define ACPI_BUILD_APPNAME6 "BOCHS "
  11#define ACPI_BUILD_APPNAME4 "BXPC"
  12
  13#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
  14#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
  15#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
  16
  17#define AML_NOTIFY_METHOD "NTFY"
  18
  19typedef enum {
  20    AML_NO_OPCODE = 0,/* has only data */
  21    AML_OPCODE,       /* has opcode optionally followed by data */
  22    AML_PACKAGE,      /* has opcode and uses PkgLength for its length */
  23    AML_EXT_PACKAGE,  /* Same as AML_PACKAGE but also has 'ExOpPrefix' */
  24    AML_BUFFER,       /* data encoded as 'DefBuffer' */
  25    AML_RES_TEMPLATE, /* encoded as ResourceTemplate macro */
  26} AmlBlockFlags;
  27
  28struct Aml {
  29    GArray *buf;
  30
  31    /*< private >*/
  32    uint8_t op;
  33    AmlBlockFlags block_flags;
  34};
  35typedef struct Aml Aml;
  36
  37typedef enum {
  38    AML_COMPATIBILITY = 0,
  39    AML_TYPEA = 1,
  40    AML_TYPEB = 2,
  41    AML_TYPEF = 3,
  42} AmlDmaType;
  43
  44typedef enum {
  45    AML_NOTBUSMASTER = 0,
  46    AML_BUSMASTER = 1,
  47} AmlDmaBusMaster;
  48
  49typedef enum {
  50    AML_TRANSFER8 = 0,
  51    AML_TRANSFER8_16 = 1,
  52    AML_TRANSFER16 = 2,
  53} AmlTransferSize;
  54
  55typedef enum {
  56    AML_DECODE10 = 0,
  57    AML_DECODE16 = 1,
  58} AmlIODecode;
  59
  60typedef enum {
  61    AML_ANY_ACC = 0,
  62    AML_BYTE_ACC = 1,
  63    AML_WORD_ACC = 2,
  64    AML_DWORD_ACC = 3,
  65    AML_QWORD_ACC = 4,
  66    AML_BUFFER_ACC = 5,
  67} AmlAccessType;
  68
  69typedef enum {
  70    AML_NOLOCK = 0,
  71    AML_LOCK = 1,
  72} AmlLockRule;
  73
  74typedef enum {
  75    AML_PRESERVE = 0,
  76    AML_WRITE_AS_ONES = 1,
  77    AML_WRITE_AS_ZEROS = 2,
  78} AmlUpdateRule;
  79
  80typedef enum {
  81    AML_AS_SYSTEM_MEMORY = 0X00,
  82    AML_AS_SYSTEM_IO = 0X01,
  83    AML_AS_PCI_CONFIG = 0X02,
  84    AML_AS_EMBEDDED_CTRL = 0X03,
  85    AML_AS_SMBUS = 0X04,
  86    AML_AS_FFH = 0X7F,
  87} AmlAddressSpace;
  88
  89typedef enum {
  90    AML_SYSTEM_MEMORY = 0X00,
  91    AML_SYSTEM_IO = 0X01,
  92    AML_PCI_CONFIG = 0X02,
  93} AmlRegionSpace;
  94
  95typedef enum {
  96    AML_MEMORY_RANGE = 0,
  97    AML_IO_RANGE = 1,
  98    AML_BUS_NUMBER_RANGE = 2,
  99} AmlResourceType;
 100
 101typedef enum {
 102    AML_SUB_DECODE = 1 << 1,
 103    AML_POS_DECODE = 0
 104} AmlDecode;
 105
 106typedef enum {
 107    AML_MAX_FIXED = 1 << 3,
 108    AML_MAX_NOT_FIXED = 0,
 109} AmlMaxFixed;
 110
 111typedef enum {
 112    AML_MIN_FIXED = 1 << 2,
 113    AML_MIN_NOT_FIXED = 0
 114} AmlMinFixed;
 115
 116/*
 117 * ACPI 1.0b: Table 6-26 I/O Resource Flag (Resource Type = 1) Definitions
 118 * _RNG field definition
 119 */
 120typedef enum {
 121    AML_ISA_ONLY = 1,
 122    AML_NON_ISA_ONLY = 2,
 123    AML_ENTIRE_RANGE = 3,
 124} AmlISARanges;
 125
 126/*
 127 * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions
 128 * _MEM field definition
 129 */
 130typedef enum {
 131    AML_NON_CACHEABLE = 0,
 132    AML_CACHEABLE = 1,
 133    AML_WRITE_COMBINING = 2,
 134    AML_PREFETCHABLE = 3,
 135} AmlCacheable;
 136
 137/*
 138 * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions
 139 * _RW field definition
 140 */
 141typedef enum {
 142    AML_READ_ONLY = 0,
 143    AML_READ_WRITE = 1,
 144} AmlReadAndWrite;
 145
 146/*
 147 * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition
 148 * Interrupt Vector Flags Bits[0] Consumer/Producer
 149 */
 150typedef enum {
 151    AML_CONSUMER_PRODUCER = 0,
 152    AML_CONSUMER = 1,
 153} AmlConsumerAndProducer;
 154
 155/*
 156 * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition
 157 * _HE field definition
 158 */
 159typedef enum {
 160    AML_LEVEL = 0,
 161    AML_EDGE = 1,
 162} AmlLevelAndEdge;
 163
 164/*
 165 * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition
 166 * _LL field definition
 167 */
 168typedef enum {
 169    AML_ACTIVE_HIGH = 0,
 170    AML_ACTIVE_LOW = 1,
 171} AmlActiveHighAndLow;
 172
 173/*
 174 * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition
 175 * _SHR field definition
 176 */
 177typedef enum {
 178    AML_EXCLUSIVE = 0,
 179    AML_SHARED = 1,
 180    AML_EXCLUSIVE_AND_WAKE = 2,
 181    AML_SHARED_AND_WAKE = 3,
 182} AmlShared;
 183
 184/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: MethodFlags */
 185typedef enum {
 186    AML_NOTSERIALIZED = 0,
 187    AML_SERIALIZED = 1,
 188} AmlSerializeFlag;
 189
 190/*
 191 * ACPI 5.0: Table 6-189 GPIO Connection Descriptor Definition
 192 * GPIO Connection Type
 193 */
 194typedef enum {
 195    AML_INTERRUPT_CONNECTION = 0,
 196    AML_IO_CONNECTION = 1,
 197} AmlGpioConnectionType;
 198
 199/*
 200 * ACPI 5.0: Table 6-189 GPIO Connection Descriptor Definition
 201 * _PPI field definition
 202 */
 203typedef enum {
 204    AML_PULL_DEFAULT = 0,
 205    AML_PULL_UP = 1,
 206    AML_PULL_DOWN = 2,
 207    AML_PULL_NONE = 3,
 208} AmlPinConfig;
 209
 210typedef enum {
 211    MEM_AFFINITY_NOFLAGS      = 0,
 212    MEM_AFFINITY_ENABLED      = (1 << 0),
 213    MEM_AFFINITY_HOTPLUGGABLE = (1 << 1),
 214    MEM_AFFINITY_NON_VOLATILE = (1 << 2),
 215} MemoryAffinityFlags;
 216
 217typedef
 218struct AcpiBuildTables {
 219    GArray *table_data;
 220    GArray *rsdp;
 221    GArray *tcpalog;
 222    GArray *vmgenid;
 223    BIOSLinker *linker;
 224} AcpiBuildTables;
 225
 226/*
 227 * ACPI 5.0: 6.4.3.8.2 Serial Bus Connection Descriptors
 228 * Serial Bus Type
 229 */
 230#define AML_SERIAL_BUS_TYPE_I2C  1
 231#define AML_SERIAL_BUS_TYPE_SPI  2
 232#define AML_SERIAL_BUS_TYPE_UART 3
 233
 234/*
 235 * ACPI 5.0: 6.4.3.8.2 Serial Bus Connection Descriptors
 236 * General Flags
 237 */
 238/* Slave Mode */
 239#define AML_SERIAL_BUS_FLAG_MASTER_DEVICE       (1 << 0)
 240/* Consumer/Producer */
 241#define AML_SERIAL_BUS_FLAG_CONSUME_ONLY        (1 << 1)
 242
 243/**
 244 * init_aml_allocator:
 245 *
 246 * Called for initializing API allocator which allow to use
 247 * AML API.
 248 * Returns: toplevel container which accumulates all other
 249 * AML elements for a table.
 250 */
 251Aml *init_aml_allocator(void);
 252
 253/**
 254 * free_aml_allocator:
 255 *
 256 * Releases all elements used by AML API, frees associated memory
 257 * and invalidates AML allocator. After this call @init_aml_allocator
 258 * should be called again if AML API is to be used again.
 259 */
 260void free_aml_allocator(void);
 261
 262/**
 263 * aml_append:
 264 * @parent_ctx: context to which @child element is added
 265 * @child: element that is copied into @parent_ctx context
 266 *
 267 * Joins Aml elements together and helps to construct AML tables
 268 * Examle of usage:
 269 *   Aml *table = aml_def_block("SSDT", ...);
 270 *   Aml *sb = aml_scope("\\_SB");
 271 *   Aml *dev = aml_device("PCI0");
 272 *
 273 *   aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03")));
 274 *   aml_append(sb, dev);
 275 *   aml_append(table, sb);
 276 */
 277void aml_append(Aml *parent_ctx, Aml *child);
 278
 279/* non block AML object primitives */
 280Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 281Aml *aml_name_decl(const char *name, Aml *val);
 282Aml *aml_debug(void);
 283Aml *aml_return(Aml *val);
 284Aml *aml_int(const uint64_t val);
 285Aml *aml_arg(int pos);
 286Aml *aml_to_integer(Aml *arg);
 287Aml *aml_to_hexstring(Aml *src, Aml *dst);
 288Aml *aml_to_buffer(Aml *src, Aml *dst);
 289Aml *aml_store(Aml *val, Aml *target);
 290Aml *aml_and(Aml *arg1, Aml *arg2, Aml *dst);
 291Aml *aml_or(Aml *arg1, Aml *arg2, Aml *dst);
 292Aml *aml_lor(Aml *arg1, Aml *arg2);
 293Aml *aml_shiftleft(Aml *arg1, Aml *count);
 294Aml *aml_shiftright(Aml *arg1, Aml *count, Aml *dst);
 295Aml *aml_lless(Aml *arg1, Aml *arg2);
 296Aml *aml_add(Aml *arg1, Aml *arg2, Aml *dst);
 297Aml *aml_subtract(Aml *arg1, Aml *arg2, Aml *dst);
 298Aml *aml_increment(Aml *arg);
 299Aml *aml_decrement(Aml *arg);
 300Aml *aml_index(Aml *arg1, Aml *idx);
 301Aml *aml_notify(Aml *arg1, Aml *arg2);
 302Aml *aml_call0(const char *method);
 303Aml *aml_call1(const char *method, Aml *arg1);
 304Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2);
 305Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3);
 306Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4);
 307Aml *aml_call5(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4,
 308               Aml *arg5);
 309Aml *aml_gpio_int(AmlConsumerAndProducer con_and_pro,
 310                  AmlLevelAndEdge edge_level,
 311                  AmlActiveHighAndLow active_level, AmlShared shared,
 312                  AmlPinConfig pin_config, uint16_t debounce_timeout,
 313                  const uint32_t pin_list[], uint32_t pin_count,
 314                  const char *resource_source_name,
 315                  const uint8_t *vendor_data, uint16_t vendor_data_len);
 316Aml *aml_memory32_fixed(uint32_t addr, uint32_t size,
 317                        AmlReadAndWrite read_and_write);
 318Aml *aml_interrupt(AmlConsumerAndProducer con_and_pro,
 319                   AmlLevelAndEdge level_and_edge,
 320                   AmlActiveHighAndLow high_and_low, AmlShared shared,
 321                   uint32_t *irq_list, uint8_t irq_count);
 322Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
 323            uint8_t aln, uint8_t len);
 324Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
 325                          Aml *offset, uint32_t len);
 326Aml *aml_irq_no_flags(uint8_t irq);
 327Aml *aml_named_field(const char *name, unsigned length);
 328Aml *aml_reserved_field(unsigned length);
 329Aml *aml_local(int num);
 330Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 331Aml *aml_lnot(Aml *arg);
 332Aml *aml_equal(Aml *arg1, Aml *arg2);
 333Aml *aml_lgreater(Aml *arg1, Aml *arg2);
 334Aml *aml_lgreater_equal(Aml *arg1, Aml *arg2);
 335Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
 336                   const char *name_format, ...) GCC_FMT_ATTR(4, 5);
 337Aml *aml_eisaid(const char *str);
 338Aml *aml_word_bus_number(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
 339                         AmlDecode dec, uint16_t addr_gran,
 340                         uint16_t addr_min, uint16_t addr_max,
 341                         uint16_t addr_trans, uint16_t len);
 342Aml *aml_word_io(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
 343                 AmlDecode dec, AmlISARanges isa_ranges,
 344                 uint16_t addr_gran, uint16_t addr_min,
 345                 uint16_t addr_max, uint16_t addr_trans,
 346                 uint16_t len);
 347Aml *aml_dword_io(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
 348                 AmlDecode dec, AmlISARanges isa_ranges,
 349                 uint32_t addr_gran, uint32_t addr_min,
 350                 uint32_t addr_max, uint32_t addr_trans,
 351                 uint32_t len);
 352Aml *aml_dword_memory(AmlDecode dec, AmlMinFixed min_fixed,
 353                      AmlMaxFixed max_fixed, AmlCacheable cacheable,
 354                      AmlReadAndWrite read_and_write,
 355                      uint32_t addr_gran, uint32_t addr_min,
 356                      uint32_t addr_max, uint32_t addr_trans,
 357                      uint32_t len);
 358Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed,
 359                      AmlMaxFixed max_fixed, AmlCacheable cacheable,
 360                      AmlReadAndWrite read_and_write,
 361                      uint64_t addr_gran, uint64_t addr_min,
 362                      uint64_t addr_max, uint64_t addr_trans,
 363                      uint64_t len);
 364Aml *aml_dma(AmlDmaType typ, AmlDmaBusMaster bm, AmlTransferSize sz,
 365             uint8_t channel);
 366Aml *aml_sleep(uint64_t msec);
 367Aml *aml_i2c_serial_bus_device(uint16_t address, const char *resource_source);
 368
 369/* Block AML object primitives */
 370Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 371Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 372Aml *aml_method(const char *name, int arg_count, AmlSerializeFlag sflag);
 373Aml *aml_if(Aml *predicate);
 374Aml *aml_else(void);
 375Aml *aml_while(Aml *predicate);
 376Aml *aml_package(uint8_t num_elements);
 377Aml *aml_buffer(int buffer_size, uint8_t *byte_list);
 378Aml *aml_resource_template(void);
 379Aml *aml_field(const char *name, AmlAccessType type, AmlLockRule lock,
 380               AmlUpdateRule rule);
 381Aml *aml_mutex(const char *name, uint8_t sync_level);
 382Aml *aml_acquire(Aml *mutex, uint16_t timeout);
 383Aml *aml_release(Aml *mutex);
 384Aml *aml_alias(const char *source_object, const char *alias_object);
 385Aml *aml_create_field(Aml *srcbuf, Aml *bit_index, Aml *num_bits,
 386                      const char *name);
 387Aml *aml_create_dword_field(Aml *srcbuf, Aml *index, const char *name);
 388Aml *aml_create_qword_field(Aml *srcbuf, Aml *index, const char *name);
 389Aml *aml_varpackage(uint32_t num_elements);
 390Aml *aml_touuid(const char *uuid);
 391Aml *aml_unicode(const char *str);
 392Aml *aml_refof(Aml *arg);
 393Aml *aml_derefof(Aml *arg);
 394Aml *aml_sizeof(Aml *arg);
 395Aml *aml_concatenate(Aml *source1, Aml *source2, Aml *target);
 396Aml *aml_object_type(Aml *object);
 397
 398void build_append_int_noprefix(GArray *table, uint64_t value, int size);
 399void
 400build_header(BIOSLinker *linker, GArray *table_data,
 401             AcpiTableHeader *h, const char *sig, int len, uint8_t rev,
 402             const char *oem_id, const char *oem_table_id);
 403void *acpi_data_push(GArray *table_data, unsigned size);
 404unsigned acpi_data_len(GArray *table);
 405void acpi_add_table(GArray *table_offsets, GArray *table_data);
 406void acpi_build_tables_init(AcpiBuildTables *tables);
 407void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre);
 408void
 409build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data);
 410void
 411build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets,
 412           const char *oem_id, const char *oem_table_id);
 413void
 414build_xsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets,
 415           const char *oem_id, const char *oem_table_id);
 416
 417int
 418build_append_named_dword(GArray *array, const char *name_format, ...)
 419GCC_FMT_ATTR(2, 3);
 420
 421void build_append_gas(GArray *table, AmlAddressSpace as,
 422                      uint8_t bit_width, uint8_t bit_offset,
 423                      uint8_t access_width, uint64_t address);
 424
 425static inline void
 426build_append_gas_from_struct(GArray *table, const struct AcpiGenericAddress *s)
 427{
 428    build_append_gas(table, s->space_id, s->bit_width, s->bit_offset,
 429                     s->access_width, s->address);
 430}
 431
 432void build_srat_memory(AcpiSratMemoryAffinity *numamem, uint64_t base,
 433                       uint64_t len, int node, MemoryAffinityFlags flags);
 434
 435void build_slit(GArray *table_data, BIOSLinker *linker, MachineState *ms);
 436
 437void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f,
 438                const char *oem_id, const char *oem_table_id);
 439#endif
 440