Skip to content

Commit

Permalink
ooga
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkFire01 committed Dec 27, 2024
1 parent e43a1f6 commit f35784b
Show file tree
Hide file tree
Showing 50 changed files with 4,420 additions and 1,562 deletions.
127 changes: 126 additions & 1 deletion drivers/bus/acpi_new/include/uacpi/acpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define ACPI_SSDT_SIGNATURE "SSDT"
#define ACPI_PSDT_SIGNATURE "PSDT"
#define ACPI_ECDT_SIGNATURE "ECDT"
#define ACPI_RHCT_SIGNATURE "RHCT"

#define ACPI_AS_ID_SYS_MEM 0x00
#define ACPI_AS_ID_SYS_IO 0x01
Expand Down Expand Up @@ -130,7 +131,11 @@ enum acpi_madt_entry_type {
ACPI_MADT_ENTRY_TYPE_MSI_PIC = 0x15,
ACPI_MADT_ENTRY_TYPE_BIO_PIC = 0x16,
ACPI_MADT_ENTRY_TYPE_LPC_PIC = 0x17,
ACPI_MADT_ENTRY_TYPE_RESERVED = 0x18, // 0x18..0x7F
ACPI_MADT_ENTRY_TYPE_RINTC = 0x18,
ACPI_MADT_ENTRY_TYPE_IMSIC = 0x19,
ACPI_MADT_ENTRY_TYPE_APLIC = 0x1A,
ACPI_MADT_ENTRY_TYPE_PLIC = 0x1B,
ACPI_MADT_ENTRY_TYPE_RESERVED = 0x1C, // 0x1C..0x7F
ACPI_MADT_ENTRY_TYPE_OEM = 0x80, // 0x80..0xFF
};

Expand Down Expand Up @@ -418,6 +423,62 @@ UACPI_PACKED(struct acpi_madt_lpc_pic {
})
UACPI_EXPECT_SIZEOF(struct acpi_madt_lpc_pic, 15);

UACPI_PACKED(struct acpi_madt_rintc {
struct acpi_entry_hdr hdr;
uacpi_u8 version;
uacpi_u8 rsvd;
uacpi_u32 flags;
uacpi_u64 hart_id;
uacpi_u32 uid;
uacpi_u32 ext_intc_id;
uacpi_u64 address;
uacpi_u32 size;
})
UACPI_EXPECT_SIZEOF(struct acpi_madt_rintc, 36);

UACPI_PACKED(struct acpi_madt_imsic {
struct acpi_entry_hdr hdr;
uacpi_u8 version;
uacpi_u8 rsvd;
uacpi_u32 flags;
uacpi_u16 num_ids;
uacpi_u16 num_guest_ids;
uacpi_u8 guest_index_bits;
uacpi_u8 hart_index_bits;
uacpi_u8 group_index_bits;
uacpi_u8 group_index_shift;
})
UACPI_EXPECT_SIZEOF(struct acpi_madt_imsic, 16);

UACPI_PACKED(struct acpi_madt_aplic {
struct acpi_entry_hdr hdr;
uacpi_u8 version;
uacpi_u8 id;
uacpi_u32 flags;
uacpi_u64 hardware_id;
uacpi_u16 idc_count;
uacpi_u16 sources_count;
uacpi_u32 gsi_base;
uacpi_u64 address;
uacpi_u32 size;
})
UACPI_EXPECT_SIZEOF(struct acpi_madt_aplic, 36);

UACPI_PACKED(struct acpi_madt_plic {
struct acpi_entry_hdr hdr;
uacpi_u8 version;
uacpi_u8 id;
uacpi_u64 hardware_id;
uacpi_u16 sources_count;
uacpi_u16 max_priority;
uacpi_u32 flags;
uacpi_u32 size;
uacpi_u64 address;
uacpi_u32 gsi_base;

})
UACPI_EXPECT_SIZEOF(struct acpi_madt_plic, 36);

enum acpi_srat_entry_type {
ACPI_SRAT_ENTRY_TYPE_PROCESSOR_AFFINITY = 0,
ACPI_SRAT_ENTRY_TYPE_MEMORY_AFFINITY = 1,
Expand Down Expand Up @@ -942,6 +1003,70 @@ UACPI_PACKED(struct acpi_ecdt {
})
UACPI_EXPECT_SIZEOF(struct acpi_ecdt, 65);

UACPI_PACKED(struct acpi_rhct_hdr {
uacpi_u16 type;
uacpi_u16 length;
uacpi_u16 revision;
})
UACPI_EXPECT_SIZEOF(struct acpi_rhct_hdr, 6);

// acpi_rhct->flags
#define ACPI_TIMER_CANNOT_WAKE_CPU (1 << 0)

UACPI_PACKED(struct acpi_rhct {
struct acpi_sdt_hdr hdr;
uacpi_u32 flags;
uacpi_u64 timebase_frequency;
uacpi_u32 node_count;
uacpi_u32 nodes_offset;
struct acpi_rhct_hdr entries[];
})
UACPI_EXPECT_SIZEOF(struct acpi_rhct, 56);

enum acpi_rhct_entry_type {
ACPI_RHCT_ENTRY_TYPE_ISA_STRING = 0,
ACPI_RHCT_ENTRY_TYPE_CMO = 1,
ACPI_RHCT_ENTRY_TYPE_MMU = 2,
ACPI_RHCT_ENTRY_TYPE_HART_INFO = 65535,
};

UACPI_PACKED(struct acpi_rhct_isa_string {
struct acpi_rhct_hdr hdr;
uacpi_u16 length;
uacpi_u8 isa[];
})
UACPI_EXPECT_SIZEOF(struct acpi_rhct_isa_string, 8);

UACPI_PACKED(struct acpi_rhct_cmo {
struct acpi_rhct_hdr hdr;
uacpi_u8 rsvd;
uacpi_u8 cbom_size;
uacpi_u8 cbop_size;
uacpi_u8 cboz_size;
})
UACPI_EXPECT_SIZEOF(struct acpi_rhct_cmo, 10);

enum acpi_rhct_mmu_type {
ACPI_RHCT_MMU_TYPE_SV39 = 0,
ACPI_RHCT_MMU_TYPE_SV48 = 1,
ACPI_RHCT_MMU_TYPE_SV57 = 2,
};

UACPI_PACKED(struct acpi_rhct_mmu {
struct acpi_rhct_hdr hdr;
uacpi_u8 rsvd;
uacpi_u8 type;
})
UACPI_EXPECT_SIZEOF(struct acpi_rhct_mmu, 8);

UACPI_PACKED(struct acpi_rhct_hart_info {
struct acpi_rhct_hdr hdr;
uacpi_u16 offset_count;
uacpi_u32 uid;
uacpi_u32 offsets[];
})
UACPI_EXPECT_SIZEOF(struct acpi_rhct_hart_info, 12);

#define ACPI_LARGE_ITEM (1 << 7)

#define ACPI_SMALL_ITEM_NAME_IDX 3
Expand Down
7 changes: 0 additions & 7 deletions drivers/bus/acpi_new/include/uacpi/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

#include <uacpi/types.h>

#ifndef UACPI_DEFAULT_LOG_LEVEL
#define UACPI_DEFAULT_LOG_LEVEL UACPI_LOG_INFO
#endif

#define UACPI_DEFAULT_LOOP_TIMEOUT_SECONDS 30
#define UACPI_DEFAULT_MAX_CALL_STACK_DEPTH 256

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
11 changes: 5 additions & 6 deletions drivers/bus/acpi_new/include/uacpi/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ uacpi_status uacpi_fixed_event_info(

UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
uacpi_status uacpi_gpe_info(
uacpi_namespace_node *gpe_devicem, uacpi_u16 idx,
uacpi_namespace_node *gpe_device, uacpi_u16 idx,
uacpi_event_info *out_info
))

Expand Down Expand Up @@ -111,7 +111,7 @@ uacpi_status uacpi_install_gpe_handler(
* NOTE: 'gpe_device' may be null for GPEs managed by \_GPE
*/
UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
uacpi_status uacpi_install_gpe_handler_raw(
uacpi_status uacpi_install_gpe_handler_raw(
uacpi_namespace_node *gpe_device, uacpi_u16 idx,
uacpi_gpe_triggering triggering, uacpi_gpe_handler handler, uacpi_handle ctx
))
Expand All @@ -129,7 +129,7 @@ uacpi_status uacpi_uninstall_gpe_handler(
* NOTE: 'gpe_device' may be null for GPEs managed by \_GPE
*/
UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
uacpi_status uacpi_gpe_setup_for_wake(
uacpi_status uacpi_setup_gpe_for_wake(
uacpi_namespace_node *gpe_device, uacpi_u16 idx,
uacpi_namespace_node *wake_device
))
Expand All @@ -143,15 +143,14 @@ uacpi_status uacpi_gpe_setup_for_wake(
* NOTE: 'gpe_device' may be null for GPEs managed by \_GPE
*/
UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
uacpi_status uacpi_gpe_enable_for_wake(
uacpi_status uacpi_enable_gpe_for_wake(
uacpi_namespace_node *gpe_device, uacpi_u16 idx
))
UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
uacpi_status uacpi_gpe_disable_for_wake(
uacpi_status uacpi_disable_gpe_for_wake(
uacpi_namespace_node *gpe_device, uacpi_u16 idx
))


/*
* Finalize GPE initialization by enabling all GPEs not configured for wake and
* having a matching AML handler detected.
Expand Down
2 changes: 1 addition & 1 deletion drivers/bus/acpi_new/include/uacpi/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define UACPI_STATIC_ASSERT _Static_assert
#endif

#define UACPI_BUILD_BUG_ON_WITH_MSG(expr, msg) UACPI_STATIC_ASSERT(!(expr), msg)
#define UACPI_BUILD_BUG_ON_WITH_MSG(expr, msg) //UACPI_STATIC_ASSERT(!(expr), msg)

#define UACPI_BUILD_BUG_ON(expr) \
UACPI_BUILD_BUG_ON_WITH_MSG(expr, "BUILD BUG: " #expr " evaluated to true")
Expand Down
11 changes: 10 additions & 1 deletion drivers/bus/acpi_new/include/uacpi/internal/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,20 @@ struct uacpi_runtime_context {
uacpi_bool has_global_lock;
uacpi_handle sci_handle;
#endif
uacpi_u64 opcodes_executed;

uacpi_u32 loop_timeout_seconds;
uacpi_u32 max_call_stack_depth;

uacpi_u32 global_lock_seq_num;
uacpi_handle *global_lock_mutex;

/*
* These are stored here to protect against stuff like:
* - CopyObject(JUNK, \)
* - CopyObject(JUNK, \_GL)
*/
uacpi_mutex *global_lock_mutex;
uacpi_object *root_object;

#ifndef UACPI_REDUCED_HARDWARE
uacpi_handle *global_lock_event;
Expand Down
8 changes: 6 additions & 2 deletions drivers/bus/acpi_new/include/uacpi/internal/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
// This fixed event is internal-only, and we don't expose it in the enum
#define UACPI_FIXED_EVENT_GLOBAL_LOCK 0

UACPI_ALWAYS_OK_FOR_REDUCED_HARDWARE(
uacpi_status uacpi_initialize_events_early(void)
)

UACPI_ALWAYS_OK_FOR_REDUCED_HARDWARE(
uacpi_status uacpi_initialize_events(void)
)
UACPI_STUB_IF_REDUCED_HARDWARE(
void uacpi_deinitialize_events(void)
)

UACPI_ALWAYS_OK_FOR_REDUCED_HARDWARE(
uacpi_status uacpi_events_match_post_dynamic_table_load(void)
UACPI_STUB_IF_REDUCED_HARDWARE(
void uacpi_events_match_post_dynamic_table_load(void)
)

UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
Expand Down
2 changes: 1 addition & 1 deletion drivers/bus/acpi_new/include/uacpi/internal/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ uacpi_status uacpi_osi(uacpi_handle handle, uacpi_object *retval);

uacpi_status uacpi_execute_control_method(
uacpi_namespace_node *scope, uacpi_control_method *method,
const uacpi_args *args, uacpi_object **ret
const uacpi_object_array *args, uacpi_object **ret
);
12 changes: 11 additions & 1 deletion drivers/bus/acpi_new/include/uacpi/internal/io.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <uacpi/types.h>
#include <uacpi/internal/types.h>
#include <uacpi/acpi.h>
#include <uacpi/io.h>

Expand All @@ -19,3 +19,13 @@ uacpi_status uacpi_read_field_unit(
uacpi_status uacpi_write_field_unit(
uacpi_field_unit *field, const void *src, uacpi_size size
);

uacpi_status uacpi_system_io_read(
uacpi_io_addr address, uacpi_u8 width, uacpi_u64 *out
);
uacpi_status uacpi_system_io_write(
uacpi_io_addr address, uacpi_u8 width, uacpi_u64 in
);

uacpi_status uacpi_system_memory_read(void *ptr, uacpi_u8 width, uacpi_u64 *out);
uacpi_status uacpi_system_memory_write(void *ptr, uacpi_u8 width, uacpi_u64 in);
2 changes: 2 additions & 0 deletions drivers/bus/acpi_new/include/uacpi/internal/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ void uacpi_log(uacpi_log_level, const uacpi_char*, ...);
#define uacpi_info(...) uacpi_log_lvl(UACPI_LOG_INFO, __VA_ARGS__)
#define uacpi_warn(...) uacpi_log_lvl(UACPI_LOG_WARN, __VA_ARGS__)
#define uacpi_error(...) uacpi_log_lvl(UACPI_LOG_ERROR, __VA_ARGS__)

void uacpi_logger_initialize(void);
76 changes: 73 additions & 3 deletions drivers/bus/acpi_new/include/uacpi/internal/mutex.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,78 @@
#pragma once

#include <uacpi/types.h>
#include <uacpi/internal/types.h>
#include <uacpi/kernel_api.h>

uacpi_bool uacpi_this_thread_owns_aml_mutex(uacpi_mutex*);

uacpi_bool uacpi_acquire_aml_mutex(uacpi_mutex*, uacpi_u16 timeout);
void uacpi_release_aml_mutex(uacpi_mutex*);
uacpi_status uacpi_acquire_aml_mutex(uacpi_mutex*, uacpi_u16 timeout);
uacpi_status uacpi_release_aml_mutex(uacpi_mutex*);

static inline uacpi_status uacpi_acquire_native_mutex(uacpi_handle mtx)
{
if (uacpi_unlikely(mtx == UACPI_NULL))
return UACPI_STATUS_INVALID_ARGUMENT;

return uacpi_kernel_acquire_mutex(mtx, 0xFFFF);
}

uacpi_status uacpi_acquire_native_mutex_with_timeout(
uacpi_handle mtx, uacpi_u16 timeout
);

static inline uacpi_status uacpi_release_native_mutex(uacpi_handle mtx)
{
if (uacpi_unlikely(mtx == UACPI_NULL))
return UACPI_STATUS_INVALID_ARGUMENT;

uacpi_kernel_release_mutex(mtx);
return UACPI_STATUS_OK;
}

static inline uacpi_status uacpi_acquire_native_mutex_may_be_null(
uacpi_handle mtx
)
{
if (mtx == UACPI_NULL)
return UACPI_STATUS_OK;

return uacpi_kernel_acquire_mutex(mtx, 0xFFFF);
}

static inline uacpi_status uacpi_release_native_mutex_may_be_null(
uacpi_handle mtx
)
{
if (mtx == UACPI_NULL)
return UACPI_STATUS_OK;

uacpi_kernel_release_mutex(mtx);
return UACPI_STATUS_OK;
}

struct uacpi_recursive_lock {
uacpi_handle mutex;
uacpi_size depth;
uacpi_thread_id owner;
};

uacpi_status uacpi_recursive_lock_init(struct uacpi_recursive_lock *lock);
uacpi_status uacpi_recursive_lock_deinit(struct uacpi_recursive_lock *lock);

uacpi_status uacpi_recursive_lock_acquire(struct uacpi_recursive_lock *lock);
uacpi_status uacpi_recursive_lock_release(struct uacpi_recursive_lock *lock);

struct uacpi_rw_lock {
uacpi_handle read_mutex;
uacpi_handle write_mutex;
uacpi_size num_readers;
};

uacpi_status uacpi_rw_lock_init(struct uacpi_rw_lock *lock);
uacpi_status uacpi_rw_lock_deinit(struct uacpi_rw_lock *lock);

uacpi_status uacpi_rw_lock_read(struct uacpi_rw_lock *lock);
uacpi_status uacpi_rw_unlock_read(struct uacpi_rw_lock *lock);

uacpi_status uacpi_rw_lock_write(struct uacpi_rw_lock *lock);
uacpi_status uacpi_rw_unlock_write(struct uacpi_rw_lock *lock);
Loading

0 comments on commit f35784b

Please sign in to comment.