PatchworkOS
Loading...
Searching...
No Matches
acpi.c
Go to the documentation of this file.
1#include <kernel/acpi/acpi.h>
2
6#include <kernel/fs/mount.h>
7#include <kernel/log/log.h>
8#include <kernel/log/panic.h>
9#include <kernel/mem/pmm.h>
10
11#include <boot/boot_info.h>
12#include <string.h>
13
14static bool mountInitialzed = false;
15static mount_t* mount = NULL;
16
17bool acpi_is_checksum_valid(void* table, uint64_t length)
18{
19 uint8_t sum = 0;
20 for (uint64_t i = 0; i < length; i++)
21 {
22 sum += ((uint8_t*)table)[i];
23 }
24
25 return sum == 0;
26}
27
29{
30 if (!mountInitialzed)
31 {
32 mount = sysfs_mount_new(NULL, "acpi", NULL, NULL);
33 if (mount == NULL)
34 {
35 panic(NULL, "failed to initialize ACPI sysfs group");
36 }
37
38 mountInitialzed = true;
39 }
40
41 return REF(mount->root);
42}
43
45{
46 for (uint64_t i = 0; i < map->length; i++)
47 {
48 const EFI_MEMORY_DESCRIPTOR* desc = BOOT_MEMORY_MAP_GET_DESCRIPTOR(map, i);
49
50 if (desc->Type == EfiACPIReclaimMemory)
51 {
52 pmm_free_region((void*)PML_LOWER_TO_HIGHER(desc->PhysicalStart), desc->NumberOfPages);
53 LOG_INFO("reclaim memory [0x%016lx-0x%016lx]\n", desc->PhysicalStart,
54 ((uintptr_t)desc->PhysicalStart) + desc->NumberOfPages * PAGE_SIZE);
55 }
56 }
57}
static bool mountInitialzed
Definition acpi.c:14
static mount_t * mount
Definition acpi.c:15
#define BOOT_MEMORY_MAP_GET_DESCRIPTOR(map, index)
Definition boot_info.h:41
dentry_t * acpi_get_sysfs_root(void)
Retrieve the sysfs root directory for ACPI.
Definition acpi.c:28
bool acpi_is_checksum_valid(void *table, uint64_t length)
Check if the sum of all bytes in a table is 0.
Definition acpi.c:17
void acpi_reclaim_memory(const boot_memory_map_t *map)
Reclaim ACPI memory regions.
Definition acpi.c:44
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
Definition panic.c:362
#define LOG_INFO(format,...)
Definition log.h:87
#define PML_LOWER_TO_HIGHER(addr)
Converts an address from the lower half to the higher half.
void pmm_free_region(void *address, uint64_t count)
Frees a contiguous region of physical pages.
Definition pmm.c:226
#define REF(ptr)
Increment reference count.
Definition ref.h:65
#define PAGE_SIZE
Memory page size.
Definition proc.h:140
#define NULL
Pointer error value.
Definition NULL.h:23
boot_memory_map_t * map
Definition mem.c:19
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:43
uint64_t length
Definition boot_info.h:47
Directory entry structure.
Definition dentry.h:83
Mount structure.
Definition mount.h:36
dentry_t * root
The root dentry of the mounted filesystem.
Definition mount.h:42
mount_t * sysfs_mount_new(const path_t *parent, const char *name, namespace_t *ns, const superblock_ops_t *superblockOps)
Mount a new instance of SysFS.
Definition sysfs.c:100