mirror of
https://github.com/apache/nuttx.git
synced 2026-05-21 13:13:08 +08:00
arch/x86_64: add simple ACPI parser
add simple ACPI parser for intel64. For now RSDP signature can be found in BIOS legacy region or can be provided by multiboot2 Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
This commit is contained in:
committed by
Xiang Xiao
parent
0aac7d929d
commit
30226901c0
@@ -0,0 +1,304 @@
|
||||
/****************************************************************************
|
||||
* arch/x86_64/include/acpi.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_X86_64_INCLUDE_ACPI_H
|
||||
#define __ARCH_X86_64_INCLUDE_ACPI_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define ACPI_SIG_RSDP "RSD PTR " /* Root System Description Pointer */
|
||||
|
||||
/* Tables defined by ACPI spec */
|
||||
|
||||
#define ACPI_SIG_APIC "APIC" /* Multiple APIC Description Table (MADT) */
|
||||
#define ACPI_SIG_BERT "BERT"
|
||||
#define ACPI_SIG_BGRT "BGRT"
|
||||
#define ACPI_SIG_CCEL "CCEL"
|
||||
#define ACPI_SIG_CPEP "CPEP"
|
||||
#define ACPI_SIG_DSDT "DSDT"
|
||||
#define ACPI_SIG_ECDT "ECDT"
|
||||
#define ACPI_SIG_EINJ "EINJ"
|
||||
#define ACPI_SIG_ERST "ERST"
|
||||
#define ACPI_SIG_FACP "FACP"
|
||||
#define ACPI_SIG_FACS "FACS"
|
||||
#define ACPI_SIG_FPDT "FPDT"
|
||||
#define ACPI_SIG_GTDT "GTDT"
|
||||
#define ACPI_SIG_HEST "HEST"
|
||||
#define ACPI_SIG_MISC "MISC"
|
||||
#define ACPI_SIG_MSCT "MSCT"
|
||||
#define ACPI_SIG_MPST "MPST"
|
||||
#define ACPI_SIG_NFIT "NFIT"
|
||||
#define ACPI_SIG_OEMx "OEMx"
|
||||
#define ACPI_SIG_PCCT "PCCT"
|
||||
#define ACPI_SIG_PHAT "PHAT"
|
||||
#define ACPI_SIG_PMTT "PMTT"
|
||||
#define ACPI_SIG_PPTT "PPTT"
|
||||
#define ACPI_SIG_PSDT "PSDT"
|
||||
#define ACPI_SIG_RASF "RASF"
|
||||
#define ACPI_SIG_RAS2 "RAS2"
|
||||
#define ACPI_SIG_RSDT "RSDT"
|
||||
#define ACPI_SIG_SBST "SBST"
|
||||
#define ACPI_SIG_SDEV "SDEV"
|
||||
#define ACPI_SIG_SLIT "SLIT"
|
||||
#define ACPI_SIG_SRAT "SRAT"
|
||||
#define ACPI_SIG_SSDT "SSDT"
|
||||
#define ACPI_SIG_SVKL "SVKL"
|
||||
#define ACPI_SIG_XSDT "XSDT"
|
||||
|
||||
/* Tables not defined by ACPI spec */
|
||||
|
||||
#define ACPI_SIG_AEST "AEST"
|
||||
#define ACPI_SIG_AGDI "AGDI"
|
||||
#define ACPI_SIG_APMT "APMT"
|
||||
#define ACPI_SIG_BDAT "BDAT"
|
||||
#define ACPI_SIG_BOOT "BOOT"
|
||||
#define ACPI_SIG_CEDT "CEDT"
|
||||
#define ACPI_SIG_CSRT "CSRT"
|
||||
#define ACPI_SIG_DBGT "DBGT"
|
||||
#define ACPI_SIG_DBG2 "DBG2"
|
||||
#define ACPI_SIG_DMAR "DMAR"
|
||||
#define ACPI_SIG_DRTM "DRTM"
|
||||
#define ACPI_SIG_DTPR "DTPR"
|
||||
#define ACPI_SIG_ETDT "ETDT"
|
||||
#define ACPI_SIG_HPET "HPET"
|
||||
#define ACPI_SIG_IBFT "IBFT"
|
||||
#define ACPI_SIG_IERS "IERS"
|
||||
#define ACPI_SIG_IORT "IORT"
|
||||
#define ACPI_SIG_IVRS "IVRS"
|
||||
#define ACPI_SIG_KEYP "KEYP"
|
||||
#define ACPI_SIG_LPIT "LPIT"
|
||||
#define ACPI_SIG_MCFG "MCFG" /* PCI Express Memory-mapped Configuration table */
|
||||
#define ACPI_SIG_MCHI "MCHI"
|
||||
#define ACPI_SIG_MHSP "MHSP"
|
||||
#define ACPI_SIG_MPAM "MPAM"
|
||||
#define ACPI_SIG_MSDM "MSDM"
|
||||
#define ACPI_SIG_NBFT "NBFT"
|
||||
#define ACPI_SIG_PRMT "PRMT"
|
||||
#define ACPI_SIG_RGRT "RGRT"
|
||||
#define ACPI_SIG_SDEI "SDEI"
|
||||
#define ACPI_SIG_SLIC "SLIC"
|
||||
#define ACPI_SIG_SPCR "SPCR"
|
||||
#define ACPI_SIG_SPMI "SPMI"
|
||||
#define ACPI_SIG_STAO "STAO"
|
||||
#define ACPI_SIG_SWFT "SWFT"
|
||||
#define ACPI_SIG_TCPA "TCPA"
|
||||
#define ACPI_SIG_TPM2 "TPM2"
|
||||
#define ACPI_SIG_UEFI "UEFI"
|
||||
#define ACPI_SIG_WAET "WAET"
|
||||
#define ACPI_SIG_WDAT "WDAT"
|
||||
#define ACPI_SIG_WDDT "WDDT"
|
||||
#define ACPI_SIG_WDRT "WDRT"
|
||||
#define ACPI_SIG_WPBT "WPBT"
|
||||
#define ACPI_SIG_WSMT "WSMT"
|
||||
#define ACPI_SIG_XENV "XENV"
|
||||
|
||||
/* MADT Interrupt Controller Structure types */
|
||||
|
||||
#define ACPI_MADT_TYPE_LOCAL_APIC (0)
|
||||
#define ACPI_MADT_TYPE_IO_APIC (1)
|
||||
#define ACPI_MADT_TYPE_LOCAL_APIC64 (5)
|
||||
#define ACPI_MADT_TYPE_LOCAL_X2APIC (9)
|
||||
|
||||
/* Local APIC Flags */
|
||||
|
||||
#define ACPI_LAPIC_FLAGS_ENABLED (1 << 0)
|
||||
#define ACPI_LAPIC_FLAGS_ONLINECAP (1 << 1)
|
||||
#define ACPI_LAPIC_FLAGS_RESERVED (0xfffffffc)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* Root System Description Pointer (RSDP) Structure */
|
||||
|
||||
begin_packed_struct struct acpi_rsdp_s
|
||||
{
|
||||
char signature[8]; /* "RSD PTR " sugnature */
|
||||
uint8_t checksum; /* ACPI 1.0 checksum */
|
||||
char oem_id[6]; /* An OEM-supplied string */
|
||||
uint8_t revision; /* The revision of this structure */
|
||||
uint32_t rsdt_addr; /* 32 bit physical address of the RSDT */
|
||||
uint32_t length; /* The length of the table */
|
||||
uint64_t xsdt_addr; /* 64 bit physical address of the XSDT */
|
||||
uint8_t ext_checksum; /* Extended checksum */
|
||||
uint8_t reserved[3]; /* Reserved field */
|
||||
} end_packed_struct;
|
||||
|
||||
/* System Description Table Header */
|
||||
|
||||
begin_packed_struct struct acpi_sdt_s
|
||||
{
|
||||
char signature[4]; /* Table ASCII identifier */
|
||||
uint32_t length; /* The length of the table in bytes */
|
||||
uint8_t revision; /* The revision of the structure */
|
||||
uint8_t checksum; /* The entire table checksum */
|
||||
char oem_id[6]; /* An OEM identification string */
|
||||
char oem_table_id[8]; /* An OEM data table string */
|
||||
uint32_t oem_revision; /* An OEM revision number */
|
||||
uint32_t creator_id; /* Vendor ID */
|
||||
uint32_t creator_revision; /* Vendor revision */
|
||||
} end_packed_struct;
|
||||
|
||||
/* Root System Description Table */
|
||||
|
||||
begin_packed_struct struct acpi_rsdt_s
|
||||
{
|
||||
struct acpi_sdt_s sdt;
|
||||
uint32_t table_ptrs;
|
||||
} end_packed_struct;
|
||||
|
||||
/* Extended System Descriptior Table */
|
||||
|
||||
begin_packed_struct struct acpi_xsdt_s
|
||||
{
|
||||
struct acpi_sdt_s sdt;
|
||||
uint64_t table_ptrs;
|
||||
} end_packed_struct;
|
||||
|
||||
/* Common structure for tables entry */
|
||||
|
||||
begin_packed_struct struct acpi_entry_s
|
||||
{
|
||||
uint8_t type;
|
||||
uint8_t length;
|
||||
} end_packed_struct;
|
||||
|
||||
/* Multiple APIC Description Table */
|
||||
|
||||
begin_packed_struct struct acpi_madt_s
|
||||
{
|
||||
struct acpi_sdt_s sdt;
|
||||
uint32_t loapic;
|
||||
uint32_t flags;
|
||||
struct acpi_entry_s entries;
|
||||
} end_packed_struct;
|
||||
|
||||
/* Multiple APIC Description Table */
|
||||
|
||||
begin_packed_struct struct acpi_lapic_s
|
||||
{
|
||||
struct acpi_entry_s entry;
|
||||
uint8_t acpi_id;
|
||||
uint8_t apic_id;
|
||||
uint8_t flags;
|
||||
} end_packed_struct;
|
||||
|
||||
/* Configuration space base address allocation structure */
|
||||
|
||||
begin_packed_struct struct acpi_pciseg_s
|
||||
{
|
||||
uint64_t base_addr; /* Base address */
|
||||
uint16_t seg_group_num; /* PCI Segment Group Number */
|
||||
uint8_t start_bus; /* Strt PCI bus number */
|
||||
uint8_t end_bus; /* End PCI bus number */
|
||||
uint32_t reserved; /* Reserved */
|
||||
} end_packed_struct;
|
||||
|
||||
/* PCI Express Memory-mapped Configuration Table */
|
||||
|
||||
begin_packed_struct struct acpi_mcfg_s
|
||||
{
|
||||
struct acpi_sdt_s sdt; /* Header */
|
||||
uint64_t reserved; /* Reserved */
|
||||
struct acpi_pciseg_s segs; /* Configuration space base addresses */
|
||||
} end_packed_struct;
|
||||
|
||||
/****************************************************************************
|
||||
* Inline Functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: acpi_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize ACPI parser.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int acpi_init(uintptr_t rsdp);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: acpi_madt_get
|
||||
*
|
||||
* Description:
|
||||
* Find the n'th occurence of a MADT entry with a given type.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int acpi_madt_get(int type, int n, struct acpi_entry_s **entry);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: acpi_lapi_get
|
||||
*
|
||||
* Description:
|
||||
* Get Local APIC entry for a given CPU.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int acpi_lapic_get(int cpu, struct acpi_lapic_s **lapic);
|
||||
|
||||
#ifdef CONFIG_ARCH_X86_64_ACPI_DUMP
|
||||
/****************************************************************************
|
||||
* Name: acpi_dump
|
||||
*
|
||||
* Description:
|
||||
* Dump ACPI tables.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void acpi_dump(void);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __ARCH_X86_64_INCLUDE_ACPI_H */
|
||||
@@ -37,4 +37,8 @@ if(CONFIG_PCI)
|
||||
list(APPEND SRCS x86_64_pci.c)
|
||||
endif()
|
||||
|
||||
if(CONFIG_ARCH_X86_64_ACPI)
|
||||
list(APPEND SRCS x86_64_acpi.c)
|
||||
endif()
|
||||
|
||||
target_sources(arch PRIVATE ${SRCS})
|
||||
|
||||
@@ -6,6 +6,28 @@
|
||||
if ARCH_X86_64
|
||||
comment "Common Configuration Options"
|
||||
|
||||
config ARCH_X86_64_ACPI
|
||||
bool "ACPI support"
|
||||
default y
|
||||
---help---
|
||||
Select to enable ACPI parser.
|
||||
|
||||
if ARCH_X86_64_ACPI
|
||||
|
||||
config ARCH_X86_64_ACPI_DUMP
|
||||
bool "ACPI dump"
|
||||
default DEBUG_FEATURES
|
||||
---help---
|
||||
Select to dump ACPI tables.
|
||||
|
||||
config ARCH_X86_64_ACPI_BIOS
|
||||
bool "Look for ACPI RSDP in BIOS legacy region"
|
||||
default y
|
||||
---help---
|
||||
Look for RSDP in BIOS legacy region (0x000e0000-0x000fffff).
|
||||
|
||||
endif # ARCH_X86_64_ACPI
|
||||
|
||||
config ARCH_X86_64_MMX
|
||||
bool "MMX support"
|
||||
depends on ARCH_HAVE_MMX
|
||||
|
||||
@@ -28,3 +28,7 @@ CMN_CSRCS += x86_64_nputs.c x86_64_switchcontext.c x86_64_udelay.c
|
||||
ifeq ($(CONFIG_PCI),y)
|
||||
CMN_CSRCS += x86_64_pci.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ARCH_X86_64_ACPI),y)
|
||||
CMN_CSRCS += x86_64_acpi.c
|
||||
endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -30,6 +30,8 @@
|
||||
# include <nuttx/drivers/addrenv.h>
|
||||
#endif
|
||||
|
||||
#include <arch/acpi.h>
|
||||
|
||||
#include "x86_64_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
@@ -136,5 +138,11 @@ void up_initialize(void)
|
||||
|
||||
x86_64_usbinitialize();
|
||||
|
||||
#ifdef CONFIG_ARCH_X86_64_ACPI_DUMP
|
||||
/* Dump ACPI tables */
|
||||
|
||||
acpi_dump();
|
||||
#endif
|
||||
|
||||
board_autoled_on(LED_IRQSENABLED);
|
||||
}
|
||||
|
||||
@@ -87,9 +87,11 @@ header_start:
|
||||
|
||||
.short MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST
|
||||
.short 0 /* flags, none set */
|
||||
.long 16 /* size, including itself (short + short + long) */
|
||||
.long 24 /* size, including itself (short + short + long) */
|
||||
.long MULTIBOOT_TAG_TYPE_EFI64
|
||||
.long MULTIBOOT_TAG_TYPE_FRAMEBUFFER
|
||||
.long MULTIBOOT_TAG_TYPE_ACPI_OLD
|
||||
.long MULTIBOOT_TAG_TYPE_ACPI_NEW
|
||||
|
||||
.short MULTIBOOT_HEADER_TAG_END
|
||||
.short 0 /* flags, none set */
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include <arch/board/board.h>
|
||||
#include <arch/multiboot2.h>
|
||||
|
||||
#include <arch/acpi.h>
|
||||
|
||||
#include "x86_64_internal.h"
|
||||
|
||||
#include "intel64_lowsetup.h"
|
||||
@@ -41,6 +43,7 @@
|
||||
|
||||
uint32_t g_mb_magic __attribute__((section(".loader.bss")));
|
||||
uint32_t g_mb_info_struct __attribute__((section(".loader.bss")));
|
||||
uintptr_t g_acpi_rsdp = 0;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
@@ -78,6 +81,22 @@ static void x86_64_mb2_config(void)
|
||||
break;
|
||||
}
|
||||
|
||||
case MULTIBOOT_TAG_TYPE_ACPI_OLD:
|
||||
{
|
||||
struct multiboot_tag_old_acpi *acpi
|
||||
= (struct multiboot_tag_old_acpi *)tag;
|
||||
g_acpi_rsdp = (uintptr_t)acpi->rsdp;
|
||||
break;
|
||||
}
|
||||
|
||||
case MULTIBOOT_TAG_TYPE_ACPI_NEW:
|
||||
{
|
||||
struct multiboot_tag_new_acpi *acpi =
|
||||
(struct multiboot_tag_new_acpi *)tag;
|
||||
g_acpi_rsdp = (uintptr_t)acpi->rsdp;
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MULTBOOT2_FB_TERM
|
||||
case MULTIBOOT_TAG_TYPE_FRAMEBUFFER:
|
||||
{
|
||||
@@ -136,6 +155,12 @@ void __nxstart(void)
|
||||
|
||||
intel64_lowsetup();
|
||||
|
||||
#ifdef CONFIG_ARCH_X86_64_ACPI
|
||||
/* Initialize ACPI */
|
||||
|
||||
acpi_init(g_acpi_rsdp);
|
||||
#endif
|
||||
|
||||
/* perform board-specific initializations */
|
||||
|
||||
x86_64_boardinitialize();
|
||||
|
||||
Reference in New Issue
Block a user