aml-build.h 5.8 KB
Newer Older
1 2 3 4 5 6 7
#ifndef HW_ACPI_GEN_UTILS_H
#define HW_ACPI_GEN_UTILS_H

#include <stdint.h>
#include <glib.h>
#include "qemu/compiler.h"

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
typedef enum {
    AML_NO_OPCODE = 0,/* has only data */
    AML_OPCODE,       /* has opcode optionally followed by data */
    AML_PACKAGE,      /* has opcode and uses PkgLength for its length */
    AML_EXT_PACKAGE,  /* ame as AML_PACKAGE but also has 'ExOpPrefix' */
    AML_BUFFER,       /* data encoded as 'DefBuffer' */
    AML_RES_TEMPLATE, /* encoded as ResourceTemplate macro */
} AmlBlockFlags;

struct Aml {
    GArray *buf;

    /*< private >*/
    uint8_t op;
    AmlBlockFlags block_flags;
};
typedef struct Aml Aml;

I
Igor Mammedov 已提交
26 27 28 29 30
typedef enum {
    aml_decode10 = 0,
    aml_decode16 = 1,
} AmlIODecode;

31
typedef enum {
32
    aml_any_acc = 0,
33
    aml_byte_acc = 1,
34 35 36 37
    aml_word_acc = 2,
    aml_dword_acc = 3,
    aml_qword_acc = 4,
    aml_buffer_acc = 5,
38 39
} AmlFieldFlags;

40 41 42 43 44
typedef enum {
    aml_system_memory = 0x00,
    aml_system_io = 0x01,
} AmlRegionSpace;

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
typedef enum {
    aml_memory_range = 0,
    aml_io_range = 1,
    aml_bus_number_range = 2,
} AmlResourceType;

typedef enum {
    aml_sub_decode = 1 << 1,
    aml_pos_decode = 0
} AmlDecode;

typedef enum {
    aml_max_fixed = 1 << 3,
    aml_max_not_fixed = 0,
} AmlMaxFixed;

typedef enum {
    aml_min_fixed = 1 << 2,
    aml_min_not_fixed = 0
} AmlMinFixed;

/*
 * ACPI 1.0b: Table 6-26 I/O Resource Flag (Resource Type = 1) Definitions
 * _RNG field definition
 */
typedef enum {
    aml_isa_only = 1,
    aml_non_isa_only = 2,
    aml_entire_range = 3,
} AmlISARanges;

/*
 * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions
 * _MEM field definition
 */
typedef enum {
    aml_non_cacheable = 0,
    aml_cacheable = 1,
    aml_write_combining = 2,
    aml_prefetchable = 3,
} AmlCacheble;

/*
 * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions
 * _RW field definition
 */
typedef enum {
    aml_ReadOnly = 0,
    aml_ReadWrite = 1,
} AmlReadAndWrite;

96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
/**
 * init_aml_allocator:
 *
 * Called for initializing API allocator which allow to use
 * AML API.
 * Returns: toplevel container which accumulates all other
 * AML elements for a table.
 */
Aml *init_aml_allocator(void);

/**
 * free_aml_allocator:
 *
 * Releases all elements used by AML API, frees associated memory
 * and invalidates AML allocator. After this call @init_aml_allocator
 * should be called again if AML API is to be used again.
 */
void free_aml_allocator(void);

/**
 * aml_append:
 * @parent_ctx: context to which @child element is added
 * @child: element that is copied into @parent_ctx context
 *
 * Joins Aml elements together and helps to construct AML tables
 * Examle of usage:
 *   Aml *table = aml_def_block("SSDT", ...);
 *   Aml *sb = aml_scope("\_SB");
 *   Aml *dev = aml_device("PCI0");
 *
 *   aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03")));
 *   aml_append(sb, dev);
 *   aml_append(table, sb);
 */
void aml_append(Aml *parent_ctx, Aml *child);

132 133 134
/* non block AML object primitives */
Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
Aml *aml_name_decl(const char *name, Aml *val);
I
Igor Mammedov 已提交
135
Aml *aml_return(Aml *val);
I
Igor Mammedov 已提交
136
Aml *aml_int(const uint64_t val);
I
Igor Mammedov 已提交
137
Aml *aml_arg(int pos);
I
Igor Mammedov 已提交
138
Aml *aml_store(Aml *val, Aml *target);
I
Igor Mammedov 已提交
139
Aml *aml_and(Aml *arg1, Aml *arg2);
I
Igor Mammedov 已提交
140
Aml *aml_notify(Aml *arg1, Aml *arg2);
141 142 143 144
Aml *aml_call1(const char *method, Aml *arg1);
Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2);
Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3);
Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4);
I
Igor Mammedov 已提交
145 146
Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
            uint8_t aln, uint8_t len);
147 148
Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
                          uint32_t offset, uint32_t len);
149
Aml *aml_irq_no_flags(uint8_t irq);
150
Aml *aml_named_field(const char *name, unsigned length);
151
Aml *aml_reserved_field(unsigned length);
I
Igor Mammedov 已提交
152
Aml *aml_local(int num);
I
Igor Mammedov 已提交
153
Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
I
Igor Mammedov 已提交
154
Aml *aml_equal(Aml *arg1, Aml *arg2);
I
Igor Mammedov 已提交
155 156
Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
                   const char *name_format, ...) GCC_FMT_ATTR(4, 5);
I
Igor Mammedov 已提交
157
Aml *aml_eisaid(const char *str);
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
Aml *aml_word_bus_number(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
                         AmlDecode dec, uint16_t addr_gran,
                         uint16_t addr_min, uint16_t addr_max,
                         uint16_t addr_trans, uint16_t len);
Aml *aml_word_io(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
                 AmlDecode dec, AmlISARanges isa_ranges,
                 uint16_t addr_gran, uint16_t addr_min,
                 uint16_t addr_max, uint16_t addr_trans,
                 uint16_t len);
Aml *aml_dword_memory(AmlDecode dec, AmlMinFixed min_fixed,
                      AmlMaxFixed max_fixed, AmlCacheble cacheable,
                      AmlReadAndWrite read_and_write,
                      uint32_t addr_gran, uint32_t addr_min,
                      uint32_t addr_max, uint32_t addr_trans,
                      uint32_t len);
Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed,
                      AmlMaxFixed max_fixed, AmlCacheble cacheable,
                      AmlReadAndWrite read_and_write,
                      uint64_t addr_gran, uint64_t addr_min,
                      uint64_t addr_max, uint64_t addr_trans,
                      uint64_t len);
179

I
Igor Mammedov 已提交
180 181
/* Block AML object primitives */
Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
I
Igor Mammedov 已提交
182
Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
I
Igor Mammedov 已提交
183
Aml *aml_method(const char *name, int arg_count);
I
Igor Mammedov 已提交
184
Aml *aml_if(Aml *predicate);
I
Igor Mammedov 已提交
185
Aml *aml_package(uint8_t num_elements);
I
Igor Mammedov 已提交
186
Aml *aml_buffer(void);
187
Aml *aml_resource_template(void);
188
Aml *aml_field(const char *name, AmlFieldFlags flags);
I
Igor Mammedov 已提交
189
Aml *aml_varpackage(uint32_t num_elements);
I
Igor Mammedov 已提交
190

191
#endif