Skip to content

Commit

Permalink
Report and test
Browse files Browse the repository at this point in the history
  • Loading branch information
phaubertin committed Jan 25, 2025
1 parent 29706ed commit 71d76d3
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 8 deletions.
7 changes: 6 additions & 1 deletion include/kernel/infrastructure/acpi/asm/tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@
#ifndef JINUE_KERNEL_INFRASTRUCTURE_ACPI_ASM_TABLES_H
#define JINUE_KERNEL_INFRASTRUCTURE_ACPI_ASM_TABLES_H


#define ACPI_FADT_SIGNATURE "FACP"

#define ACPI_FADT_NAME "FADT"

#define ACPI_HPET_SIGNATURE "HPET"

#define ACPI_HPET_NAME ACPI_HPET_SIGNATURE

#define ACPI_MADT_SIGNATURE "APIC"

#define ACPI_MADT_NAME "MADT"

#define ACPI_RSDP_SIGNATURE "RSD PTR "

#define ACPI_RSDT_SIGNATURE "RSDT"
Expand Down
1 change: 1 addition & 0 deletions include/kernel/infrastructure/acpi/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef struct {
} acpi_addr_range_t;

typedef struct {
const char *name;
const char *signature;
const void **ptr;
} acpi_table_def_t;
Expand Down
2 changes: 2 additions & 0 deletions include/kernel/infrastructure/i686/firmware/acpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ void find_acpi_rsdp(void);

void init_acpi(void);

void report_acpi_tables(void);

kern_paddr_t acpi_get_rsdp_paddr(void);

#endif
33 changes: 29 additions & 4 deletions kernel/infrastructure/i686/firmware/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <kernel/domain/services/logging.h>
#include <kernel/infrastructure/acpi/acpi.h>
#include <kernel/infrastructure/acpi/tables.h>
#include <kernel/infrastructure/acpi/types.h>
Expand All @@ -51,10 +52,22 @@ static struct {
} acpi_tables;

static const acpi_table_def_t table_defs[] = {
{ .signature = ACPI_FADT_SIGNATURE, .ptr = (const void **)&acpi_tables.fadt },
{ .signature = ACPI_MADT_SIGNATURE, .ptr = (const void **)&acpi_tables.madt },
{ .signature = ACPI_HPET_SIGNATURE, .ptr = (const void **)&acpi_tables.hpet },
{ .signature = NULL, .ptr = NULL },
{
.name = ACPI_FADT_NAME,
.signature = ACPI_FADT_SIGNATURE,
.ptr = (const void **)&acpi_tables.fadt
},
{
.name = ACPI_MADT_NAME,
.signature = ACPI_MADT_SIGNATURE,
.ptr = (const void **)&acpi_tables.madt
},
{
.name = ACPI_HPET_NAME,
.signature = ACPI_HPET_SIGNATURE,
.ptr = (const void **)&acpi_tables.hpet
},
{ .signature = NULL },
};

/**
Expand Down Expand Up @@ -128,6 +141,18 @@ void init_acpi(void) {
map_acpi_tables(rsdp_paddr, table_defs);
}

void report_acpi_tables(void) {
info("ACPI:");

for(int idx = 0; table_defs[idx].signature != NULL; ++idx) {
const acpi_table_def_t *def = &table_defs[idx];

if(*def->ptr != NULL) {
info(" Found %s table", def->name);
}
}
}

/**
* Get the physical address of the ACPI RSDP
*
Expand Down
3 changes: 3 additions & 0 deletions kernel/infrastructure/i686/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ void machine_init(const config_t *config) {
initialize_page_allocator(&boot_alloc);

init_acpi();

report_acpi_tables();

init_mp();

/* create slab cache to allocate PDPTs
Expand Down
3 changes: 2 additions & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ run_log = run-test.log
deps = $(kernel_img) $(testapp_initrd)

tests = \
test_detect_qemu \
test_acpi \
test_boot_nopae \
test_boot_pae \
test_detect_qemu \
test_mp \
test_ipc

Expand Down
46 changes: 46 additions & 0 deletions tests/test_acpi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
# Copyright (C) 2025 Philippe Aubertin.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the author nor the names of other contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

run

check_kernel_start

# If check_no_panic, check_no_error would also fail, but check_no_panic provides
# more relevant context in the log.
check_no_panic

check_no_error

for t in FADT HPET MADT; do
echo "* Check $t table was found"
grep -E "Found $t table" $LOG || fail
done

check_reboot
4 changes: 2 additions & 2 deletions tests/test_mp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ check_no_panic
check_no_error

echo "* Check floating pointer structure was found"
grep -E "Floating pointer structure found at address 0x[1-9a-f][0-9a-f]{4}" $LOG || fail
grep -E "Floating pointer structure found at address 0x[1-9a-f][0-9a-f]{4}$" $LOG || fail

echo "* Check configuration table was found and mapped"
grep -E "Configuration table version 1.[14] at address 0x[1-9a-f][0-9a-f]{4}" $LOG || fail
grep -E "Configuration table version 1.[14] at address 0x[1-9a-f][0-9a-f]{4}$" $LOG || fail

check_reboot

0 comments on commit 71d76d3

Please sign in to comment.