Skip to content

Commit

Permalink
Introduce early table access
Browse files Browse the repository at this point in the history
This adds a new uacpi_setup_early_table_access() API, which allows the
kernel to bring up the table subsystem without utilizing the kernel heap
or any other kernel API besides logging and map/unmap callbacks. This
may be utilized by the host to detect NUMA topology or any other
platform information, which subsystems like memory management or
scheduling depend on.

This commit also makes table checksumming lazy, with the ability to
make it proactive by using UACPI_FLAG_PROACTIVE_TBL_CSUM. The flag is
also toggleable via uacpi_context_set_proactive_table_checksum().

Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
  • Loading branch information
d-tatianin committed Sep 24, 2024
1 parent 68b3288 commit 8ccabaf
Show file tree
Hide file tree
Showing 6 changed files with 489 additions and 268 deletions.
2 changes: 2 additions & 0 deletions include/uacpi/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void uacpi_context_set_max_call_stack_depth(uacpi_u32 depth);

uacpi_u32 uacpi_context_get_loop_timeout(void);

void uacpi_context_set_proactive_table_checksum(uacpi_bool);

#ifdef __cplusplus
}
#endif
11 changes: 5 additions & 6 deletions include/uacpi/internal/tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,23 @@ enum uacpi_table_origin {
};

struct uacpi_installed_table {
uacpi_object_name signature;
uacpi_phys_addr phys_addr;
union {
void *ptr;
struct acpi_sdt_hdr *hdr;
};
uacpi_u32 length;
struct acpi_sdt_hdr hdr;
void *ptr;

uacpi_u16 reference_count;

#define UACPI_TABLE_LOADED (1 << 0)
#define UACPI_TABLE_CSUM_VERIFIED (1 << 1)
#define UACPI_TABLE_INVALID (1 << 2)
uacpi_u8 flags;
uacpi_u8 origin;
};

uacpi_status uacpi_initialize_tables(void);
void uacpi_deinitialize_tables(void);

uacpi_bool uacpi_signatures_match(const void *const lhs, const void *const rhs);
uacpi_status uacpi_check_table_signature(void *table, const uacpi_char *expect);
uacpi_status uacpi_verify_table_checksum(void *table, uacpi_size size);

Expand Down
34 changes: 29 additions & 5 deletions include/uacpi/uacpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,60 @@
extern "C" {
#endif

/*
* Set up early access to the table subsystem. What this means is:
* - uacpi_table_find() and similar API becomes usable before the call to
* uacpi_initialize().
* - No kernel API besides logging and map/unmap will be invoked at this stage,
* allowing for heap and scheduling to still be fully offline.
* - The provided 'temporary_buffer' will be used as a temporary storage for the
* internal metadata about the tables (list, reference count, addresses,
* sizes, etc).
* - The 'temporary_buffer' is replaced with a normal heap buffer allocated via
* uacpi_kernel_alloc() after the call to uacpi_initialize() and can therefore
* be reclaimed by the kernel.
*/
uacpi_status uacpi_setup_early_table_access(
void *temporary_buffer, uacpi_size buffer_size
);

/*
* Bad table checksum should be considered a fatal error
* (table load is fully aborted in this case)
*/
#define UACPI_FLAG_BAD_CSUM_FATAL (1 << 0)
#define UACPI_FLAG_BAD_CSUM_FATAL (1ull << 0)

/*
* Unexpected table signature should be considered a fatal error
* (table load is fully aborted in this case)
*/
#define UACPI_FLAG_BAD_TBL_SIGNATURE_FATAL (1 << 1)
#define UACPI_FLAG_BAD_TBL_SIGNATURE_FATAL (1ull << 1)

/*
* Force uACPI to use RSDT even for later revisions
*/
#define UACPI_FLAG_BAD_XSDT (1 << 2)
#define UACPI_FLAG_BAD_XSDT (1ull << 2)

/*
* If this is set, ACPI mode is not entered during the call to
* uacpi_initialize. The caller is expected to enter it later at their own
* discretion by using uacpi_enter_acpi_mode().
*/
#define UACPI_FLAG_NO_ACPI_MODE (1 << 3)
#define UACPI_FLAG_NO_ACPI_MODE (1ull << 3)

/*
* Don't create the \_OSI method when building the namespace.
* Only enable this if you're certain that having this method breaks your AML
* blob, a more atomic/granular interface management is available via osi.h
*/
#define UACPI_FLAG_NO_OSI (1 << 4)
#define UACPI_FLAG_NO_OSI (1ull << 4)

/*
* Validate table checksums at installation time instead of first use.
* Note that this makes uACPI map the entire table at once, which not all
* hosts are able to handle at early init.
*/
#define UACPI_FLAG_PROACTIVE_TBL_CSUM (1ull << 5)

/*
* Initializes the uACPI subsystem, iterates & records all relevant RSDT/XSDT
Expand Down
Loading

0 comments on commit 8ccabaf

Please sign in to comment.