acpi refactoring to allow non-x86 use
binman support for bintools (binary tools)
minor tools improvements in preparation for FDT signing
various minor fixes and improvements
This commit is contained in:
Tom Rini
2022-01-27 14:14:47 -05:00
109 changed files with 4591 additions and 1013 deletions

View File

@@ -162,6 +162,9 @@ enum acpi_pm_profile {
#define ACPI_FADT_HW_REDUCED_ACPI BIT(20)
#define ACPI_FADT_LOW_PWR_IDLE_S0 BIT(21)
/* ARM boot flags */
#define ACPI_ARM_PSCI_COMPLIANT BIT(0)
enum acpi_address_space_type {
ACPI_ADDRESS_SPACE_MEMORY = 0, /* System memory */
ACPI_ADDRESS_SPACE_IO, /* System I/O */
@@ -237,6 +240,9 @@ struct __packed acpi_fadt {
struct acpi_gen_regaddr x_pm_tmr_blk;
struct acpi_gen_regaddr x_gpe0_blk;
struct acpi_gen_regaddr x_gpe1_blk;
struct acpi_gen_regaddr sleep_control_reg;
struct acpi_gen_regaddr sleep_status_reg;
u64 hyp_vendor_id;
};
/* FADT TABLE Revision values - note these do not match the ACPI revision */
@@ -302,6 +308,8 @@ enum acpi_apic_types {
ACPI_APIC_PLATFORM_IRQ_SRC, /* Platform interrupt sources */
ACPI_APIC_LX2APIC, /* Processor local x2APIC */
ACPI_APIC_LX2APIC_NMI, /* Local x2APIC NMI */
ACPI_APIC_GICC, /* Generic Interrupt Ctlr CPU i/f */
ACPI_APIC_GICD /* Generic Interrupt Ctlr Distributor */
};
/* MADT: Processor Local APIC Structure */
@@ -345,6 +353,57 @@ struct __packed acpi_madt_lapic_nmi {
u8 lint; /* Local APIC LINT# */
};
/* flags for acpi_madr_gicc flags word */
enum {
ACPI_MADRF_ENABLED = BIT(0),
ACPI_MADRF_PERF = BIT(1),
ACPI_MADRF_VGIC = BIT(2),
};
/**
* struct __packed acpi_madr_gicc - GIC CPU interface (type 0xb)
*
* This holds information about the Generic Interrupt Controller (GIC) CPU
* interface. See ACPI Spec v6.3 section 5.2.12.14
*/
struct __packed acpi_madr_gicc {
u8 type;
u8 length;
u16 reserved;
u32 cpu_if_num;
u32 processor_id;
u32 flags;
u32 parking_proto;
u32 perf_gsiv;
u64 parked_addr;
u64 phys_base;
u64 gicv;
u64 gich;
u32 vgic_maint_irq;
u64 gicr_base;
u64 mpidr;
u8 efficiency;
u8 reserved2;
u16 spi_overflow_irq;
};
/**
* struct __packed acpi_madr_gicc - GIC distributor (type 0xc)
*
* This holds information about the Generic Interrupt Controller (GIC)
* Distributor interface. See ACPI Spec v6.3 section 5.2.12.15
*/
struct __packed acpi_madr_gicd {
u8 type;
u8 length;
u16 reserved;
u32 gic_id;
u64 phys_base;
u32 reserved2;
u8 gic_version;
u8 reserved3[3];
};
/* MCFG (PCI Express MMIO config space BAR description table) */
struct acpi_mcfg {
struct acpi_table_header header;
@@ -371,6 +430,19 @@ struct acpi_csrt {
struct acpi_table_header header;
};
/**
* struct acpi_csrt_group - header for a group within the CSRT
*
* The CSRT consists of one or more groups and this is the header for each
*
* See Core System Resources Table (CSRT), March 13, 2017, Microsoft Corporation
* for details
*
* https://uefi.org/sites/default/files/resources/CSRT%20v2.pdf
*
* @shared_info_length indicates the number of shared-info bytes following this
* struct (which may be 0)
*/
struct acpi_csrt_group {
u32 length;
u32 vendor_id;
@@ -382,6 +454,25 @@ struct acpi_csrt_group {
u32 shared_info_length;
};
/**
* struct acpi_csrt_descriptor - describes the information that follows
*
* See the spec as above for details
*/
struct acpi_csrt_descriptor {
u32 length;
u16 type;
u16 subtype;
u32 uid;
};
/**
* struct acpi_csrt_shared_info - shared info for Intel tangier
*
* This provides the shared info for this particular board. Notes that the CSRT
* does not describe the format of data, so this format may not be used by any
* other board.
*/
struct acpi_csrt_shared_info {
u16 major_version;
u16 minor_version;
@@ -559,6 +650,120 @@ struct __packed acpi_spcr {
u32 reserved2;
};
/**
* struct acpi_gtdt - Generic Timer Description Table (GTDT)
*
* See ACPI Spec v6.3 section 5.2.24 for details
*/
struct __packed acpi_gtdt {
struct acpi_table_header header;
u64 cnt_ctrl_base;
u32 reserved0;
u32 sec_el1_gsiv;
u32 sec_el1_flags;
u32 el1_gsiv;
u32 el1_flags;
u32 virt_el1_gsiv;
u32 virt_el1_flags;
u32 el2_gsiv;
u32 el2_flags;
u64 cnt_read_base;
u32 plat_timer_count;
u32 plat_timer_offset;
u32 virt_el2_gsiv;
u32 virt_el2_flags;
};
/**
* struct acpi_bgrt - Boot Graphics Resource Table (BGRT)
*
* Optional table that provides a mechanism to indicate that an image was drawn
* on the screen during boot, and some information about the image.
*
* See ACPI Spec v6.3 section 5.2.22 for details
*/
struct __packed acpi_bgrt {
struct acpi_table_header header;
u16 version;
u8 status;
u8 image_type;
u64 addr;
u32 offset_x;
u32 offset_y;
};
/* Types for PPTT */
#define ACPI_PPTT_TYPE_PROC 0
#define ACPI_PPTT_TYPE_CACHE 1
/* Flags for PPTT */
#define ACPI_PPTT_PHYSICAL_PACKAGE BIT(0)
#define ACPI_PPTT_PROC_ID_VALID BIT(1)
#define ACPI_PPTT_PROC_IS_THREAD BIT(2)
#define ACPI_PPTT_NODE_IS_LEAF BIT(3)
#define ACPI_PPTT_CHILDREN_IDENTICAL BIT(4)
/**
* struct acpi_pptt_header - Processor Properties Topology Table (PPTT) header
*
* Describes the topological structure of processors and their shared resources,
* such as caches.
*
* See ACPI Spec v6.3 section 5.2.29 for details
*/
struct __packed acpi_pptt_header {
u8 type; /* ACPI_PPTT_TYPE_... */
u8 length;
u16 reserved;
};
/**
* struct acpi_pptt_proc - a processor as described by PPTT
*/
struct __packed acpi_pptt_proc {
struct acpi_pptt_header hdr;
u32 flags;
u32 parent;
u32 proc_id;
u32 num_resources;
};
/* Cache flags for acpi_pptt_cache */
#define ACPI_PPTT_SIZE_VALID BIT(0)
#define ACPI_PPTT_SETS_VALID BIT(1)
#define ACPI_PPTT_ASSOC_VALID BIT(2)
#define ACPI_PPTT_ALLOC_TYPE_VALID BIT(3)
#define ACPI_PPTT_CACHE_TYPE_VALID BIT(4)
#define ACPI_PPTT_WRITE_POLICY_VALID BIT(5)
#define ACPI_PPTT_LINE_SIZE_VALID BIT(6)
#define ACPI_PPTT_ALL_VALID 0x7f
#define ACPI_PPTT_ALL_BUT_WRITE_POL 0x5f
#define ACPI_PPTT_READ_ALLOC BIT(0)
#define ACPI_PPTT_WRITE_ALLOC BIT(1)
#define ACPI_PPTT_CACHE_TYPE_SHIFT 2
#define ACPI_PPTT_CACHE_TYPE_MASK (3 << ACPI_PPTT_CACHE_TYPE_SHIFT)
#define ACPI_PPTT_CACHE_TYPE_DATA 0
#define ACPI_PPTT_CACHE_TYPE_INSTR 1
#define ACPI_PPTT_CACHE_TYPE_UNIFIED 2
#define ACPI_PPTT_CACHE_TYPE_DATA 0
#define ACPI_PPTT_WRITE_THROUGH BIT(4)
/**
* struct acpi_pptt_cache - a cache as described by PPTT
*/
struct __packed acpi_pptt_cache {
struct acpi_pptt_header hdr;
u32 flags;
u32 next_cache_level;
u32 size;
u32 sets;
u8 assoc;
u8 attributes;
u16 line_size;
};
/* Tables defined/reserved by ACPI and generated by U-Boot */
enum acpi_tables {
ACPITAB_BERT,
@@ -678,16 +883,6 @@ void acpi_inc_align(struct acpi_ctx *ctx, uint amount);
*/
int acpi_add_table(struct acpi_ctx *ctx, void *table);
/**
* acpi_setup_base_tables() - Set up context along with RSDP, RSDT and XSDT
*
* Set up the context with the given start position. Some basic tables are
* always needed, so set them up as well.
*
* @ctx: Context to set up
*/
void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start);
/**
* acpi_write_rsdp() - Write out an RSDP indicating where the ACPI tables are
*
@@ -698,6 +893,26 @@ void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start);
void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt,
struct acpi_xsdt *xsdt);
/**
* acpi_fill_header() - Set up a table header
*
* @header: Pointer to header to set up
* @signature: 4-character signature to use (e.g. "FACS")
*/
void acpi_fill_header(struct acpi_table_header *header, char *signature);
/**
* acpi_fill_csrt() - Fill out the body of the CSRT
*
* This should write the contents of the Core System Resource Table (CSRT)
* to the context. The header (struct acpi_table_header) has already been
* written.
*
* @ctx: ACPI context to write to
* @return 0 if OK, -ve on error
*/
int acpi_fill_csrt(struct acpi_ctx *ctx);
#endif /* !__ACPI__*/
#include <asm/acpi_table.h>

View File

@@ -456,6 +456,10 @@ struct global_data {
* @acpi_ctx: ACPI context pointer
*/
struct acpi_ctx *acpi_ctx;
/**
* @acpi_start: Start address of ACPI tables
*/
ulong acpi_start;
#endif
#if CONFIG_IS_ENABLED(GENERATE_SMBIOS_TABLE)
/**
@@ -512,8 +516,12 @@ static_assert(sizeof(struct global_data) == GD_SIZE);
#ifdef CONFIG_GENERATE_ACPI_TABLE
#define gd_acpi_ctx() gd->acpi_ctx
#define gd_acpi_start() gd->acpi_start
#define gd_set_acpi_start(addr) gd->acpi_start = addr
#else
#define gd_acpi_ctx() NULL
#define gd_acpi_start() 0UL
#define gd_set_acpi_start(addr)
#endif
#if CONFIG_IS_ENABLED(MULTI_DTB_FIT)

View File

@@ -27,6 +27,8 @@
#if !defined(__ACPI__)
#include <linker_lists.h>
struct nhlt;
struct udevice;
@@ -43,10 +45,15 @@ enum acpi_dump_option {
*
* @base: Base address of ACPI tables
* @current: Current address for writing
* @tab_start: Address of start of the table being written. This is set up
* before the writer or driver method is called. It must not be changed by the
* method
* @rsdp: Pointer to the Root System Description Pointer, typically used when
* adding a new table. The RSDP holds pointers to the RSDT and XSDT.
* @rsdt: Pointer to the Root System Description Table
* @xsdt: Pointer to the Extended System Description Table
* @facs: Pointer to the Firmware ACPI Control Structure
* @dsdt: Pointer to the Differentiated System Description Table
* @nhlt: Intel Non-High-Definition-Audio Link Table (NHLT) pointer, used to
* build up information that audio codecs need to provide in the NHLT ACPI
* table
@@ -56,14 +63,65 @@ enum acpi_dump_option {
struct acpi_ctx {
void *base;
void *current;
void *tab_start;
struct acpi_rsdp *rsdp;
struct acpi_rsdt *rsdt;
struct acpi_xsdt *xsdt;
struct acpi_facs *facs;
struct acpi_table_header *dsdt;
struct nhlt *nhlt;
char *len_stack[ACPIGEN_LENSTACK_SIZE];
int ltop;
};
/**
* enum acpi_writer_flags_t - flags to use for the ACPI writers
*
* ACPIWF_ALIGN64 - align to 64 bytes after writing this one (default is 16)
*/
enum acpi_writer_flags_t {
ACPIWF_ALIGN64 = 1 << 0,
};
struct acpi_writer;
/**
* acpi_writer_func() - Function that can write an ACPI table
*
* @ctx: ACPI context to use for writing
* @entry: Linker-list entry for this writer
* @return 0 if OK, -ve on error
*/
typedef int (*acpi_writer_func)(struct acpi_ctx *ctx,
const struct acpi_writer *entry);
/**
* struct acpi_writer - an ACPI table that can be written
*
* @name: Name of the writer
* @table: Table name that is generated (e.g. "DSDT")
* @h_write: Writer function
*/
struct acpi_writer {
const char *name;
const char *table;
acpi_writer_func h_write;
int flags;
};
/* Declare a new ACPI-table writer */
#define ACPI_WRITER(_name, _table, _write, _flags) \
ll_entry_declare(struct acpi_writer, _name, acpi_writer) = { \
.name = #_name, \
.table = _table, \
.h_write = _write, \
.flags = _flags, \
}
/* Get a pointer to a given ACPI-table writer */
#define ACPI_WRITER_GET(_name) \
ll_entry_get(struct acpi_writer, _name, acpi_writer)
/**
* struct acpi_ops - ACPI operations supported by driver model
*/
@@ -204,6 +262,20 @@ int acpi_inject_dsdt(struct acpi_ctx *ctx);
*/
int acpi_setup_nhlt(struct acpi_ctx *ctx, struct nhlt *nhlt);
/**
* acpi_add_other_item() - Add a new table to the list of ACPI tables
*
* This adds an entry of type ACPIT_TYPE_OTHER
*
* @ctx: ACPI context
* @writer: Writer entry that generated the data
* @type: Table type it refers to
* @start: The start of the data (the end is obtained from ctx->current)
* @return 0 if OK, -ENOSPC if too many items, -ENOMEM if out of memory
*/
int acpi_add_other_item(struct acpi_ctx *ctx, const struct acpi_writer *writer,
void *start);
/**
* acpi_dump_items() - Dump out the collected ACPI items
*
@@ -236,6 +308,44 @@ int acpi_get_path(const struct udevice *dev, char *out_path, int maxlen);
*/
void acpi_reset_items(void);
/**
* acpi_write_one() - Call a single ACPI writer entry
*
* This handles aligning the context afterwards, if the entry flags indicate
* that.
*
* @ctx: ACPI context to use
* @entry: Entry to call
* @return 0 if OK, -ENOENT if this writer produced an empty entry, other -ve
* value on error
*/
int acpi_write_one(struct acpi_ctx *ctx, const struct acpi_writer *entry);
/**
* acpi_setup_ctx() - Set up a new ACPI context
*
* This zeros the context and sets up the base and current pointers, ensuring
* that they are aligned. Then it writes the acpi_start and acpi_ctx values in
* global_data
*
* @ctx: ACPI context to set up
* @start: Start address for ACPI table
*/
void acpi_setup_ctx(struct acpi_ctx *ctx, ulong start);
/**
* acpi_write_one() - Call a single ACPI writer entry
*
* This handles aligning the context afterwards, if the entry flags indicate
* that.
*
* @ctx: ACPI context to use
* @entry: Entry to call
* @return 0 if OK, -ENOENT if this writer produced an empty entry, other -ve
* value on error
*/
int acpi_write_one(struct acpi_ctx *ctx, const struct acpi_writer *entry);
#endif /* __ACPI__ */
#endif

View File

@@ -24,16 +24,19 @@
typedef phys_addr_t fdt_addr_t;
typedef phys_size_t fdt_size_t;
#define FDT_ADDR_T_NONE (-1U)
#define FDT_SIZE_T_NONE (-1U)
#ifdef CONFIG_PHYS_64BIT
#define FDT_ADDR_T_NONE ((ulong)(-1))
#define fdt_addr_to_cpu(reg) be64_to_cpu(reg)
#define fdt_size_to_cpu(reg) be64_to_cpu(reg)
#define cpu_to_fdt_addr(reg) cpu_to_be64(reg)
#define cpu_to_fdt_size(reg) cpu_to_be64(reg)
typedef fdt64_t fdt_val_t;
#else
#define FDT_ADDR_T_NONE (-1U)
#define fdt_addr_to_cpu(reg) be32_to_cpu(reg)
#define fdt_size_to_cpu(reg) be32_to_cpu(reg)
#define cpu_to_fdt_addr(reg) cpu_to_be32(reg)

View File

@@ -1021,17 +1021,37 @@ int fit_cipher_data(const char *keydir, void *keydest, void *fit,
const char *comment, int require_keys,
const char *engine_id, const char *cmdname);
#define NODE_MAX_NAME_LEN 80
/**
* struct image_summary - Provides information about signing info added
*
* @sig_offset: Offset of the node in the blob devicetree where the signature
* was wriiten
* @sig_path: Path to @sig_offset
* @keydest_offset: Offset of the node in the keydest devicetree where the
* public key was written (-1 if none)
* @keydest_path: Path to @keydest_offset
*/
struct image_summary {
int sig_offset;
char sig_path[NODE_MAX_NAME_LEN];
int keydest_offset;
char keydest_path[NODE_MAX_NAME_LEN];
};
/**
* fit_add_verification_data() - add verification data to FIT image nodes
*
* @keydir: Directory containing keys
* @kwydest: FDT blob to write public key information to
* @kwydest: FDT blob to write public key information to (NULL if none)
* @fit: Pointer to the FIT format image header
* @comment: Comment to add to signature nodes
* @require_keys: Mark all keys as 'required'
* @engine_id: Engine to use for signing
* @cmdname: Command name used when reporting errors
* @algo_name: Algorithm name, or NULL if to be read from FIT
* @summary: Returns information about what data was written
*
* Adds hash values for all component images in the FIT blob.
* Hashes are calculated for all component images which have hash subnodes
@@ -1046,10 +1066,22 @@ int fit_cipher_data(const char *keydir, void *keydest, void *fit,
int fit_add_verification_data(const char *keydir, const char *keyfile,
void *keydest, void *fit, const char *comment,
int require_keys, const char *engine_id,
const char *cmdname, const char *algo_name);
const char *cmdname, const char *algo_name,
struct image_summary *summary);
/**
* fit_image_verify_with_data() - Verify an image with given data
*
* @fit: Pointer to the FIT format image header
* @image_offset: Offset in @fit of image to verify
* @key_blob: FDT containing public keys
* @data: Image data to verify
* @size: Size of image data
*/
int fit_image_verify_with_data(const void *fit, int image_noffset,
const void *data, size_t size);
const void *key_blob, const void *data,
size_t size);
int fit_image_verify(const void *fit, int noffset);
int fit_config_verify(const void *fit, int conf_noffset);
int fit_all_image_verify(const void *fit);
@@ -1232,7 +1264,8 @@ struct crypto_algo {
*
* @info: Specifies key and FIT information
* @keydest: Destination FDT blob for public key data
* @return: 0, on success, -ve on error
* @return: node offset within the FDT blob where the data was written,
* or -ve on error
*/
int (*add_verify_data)(struct image_sign_info *info, void *keydest);
@@ -1297,7 +1330,7 @@ struct padding_algo *image_get_padding_algo(const char *name);
* @image_noffset: Offset of image node to check
* @data: Image data to check
* @size: Size of image data
* @sig_blob: FDT containing public keys
* @key_blob: FDT containing public keys
* @no_sigsp: Returns 1 if no signatures were required, and
* therefore nothing was checked. The caller may wish
* to fall back to other mechanisms, or refuse to
@@ -1305,7 +1338,7 @@ struct padding_algo *image_get_padding_algo(const char *name);
* Return: 0 if all verified ok, <0 on error
*/
int fit_image_verify_required_sigs(const void *fit, int image_noffset,
const char *data, size_t size, const void *sig_blob,
const char *data, size_t size, const void *key_blob,
int *no_sigsp);
/**
@@ -1315,7 +1348,8 @@ int fit_image_verify_required_sigs(const void *fit, int image_noffset,
* @noffset: Offset of signature node to check
* @data: Image data to check
* @size: Size of image data
* @required_keynode: Offset in the control FDT of the required key node,
* @keyblob: Key blob to check (typically the control FDT)
* @required_keynode: Offset in the keyblob of the required key node,
* if any. If this is given, then the image wil not
* pass verification unless that key is used. If this is
* -1 then any signature will do.
@@ -1324,7 +1358,8 @@ int fit_image_verify_required_sigs(const void *fit, int image_noffset,
* Return: 0 if all verified ok, <0 on error
*/
int fit_image_check_sig(const void *fit, int noffset, const void *data,
size_t size, int required_keynode, char **err_msgp);
size_t size, const void *key_blob, int required_keynode,
char **err_msgp);
int fit_image_decrypt_data(const void *fit,
int image_noffset, int cipher_noffset,

View File

@@ -44,8 +44,9 @@ int ecdsa_sign(struct image_sign_info *info, const struct image_region region[],
*
* @info: Specifies key and FIT information
* @keydest: Destination FDT blob for public key data
* @return: 0, on success, -ENOSPC if the keydest FDT blob ran out of space,
* other -ve value on error
* @return: node offset within the FDT blob where the data was written on
* success, -ENOSPC if the keydest FDT blob ran out of space, other -ve
* value on other error
*/
int ecdsa_add_verify_data(struct image_sign_info *info, void *keydest);

View File

@@ -61,8 +61,9 @@ int rsa_sign(struct image_sign_info *info,
*
* @info: Specifies key and FIT information
* @keydest: Destination FDT blob for public key data
* @return: 0, on success, -ENOSPC if the keydest FDT blob ran out of space,
other -ve value on error
* @return: node offset within the FDT blob where the data was written on
* success, -ENOSPC if the keydest FDT blob ran out of space, other -ve
* value on other error
*/
int rsa_add_verify_data(struct image_sign_info *info, void *keydest);