Skip to content

Commit

Permalink
acpica: integrate ACPICA into KTF
Browse files Browse the repository at this point in the history
Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Aug 30, 2021
1 parent d233de1 commit b84be73
Show file tree
Hide file tree
Showing 14 changed files with 332 additions and 18 deletions.
1 change: 1 addition & 0 deletions .config
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Size (in MB) of boot-time virtual address space coverage
CONFIG_EARLY_VIRT_MEM=8
CONFIG_LIBPFM=n
CONFIG_ACPICA=y
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ cscope.*
*.img
Makeconf.local
.DS_Store
drivers/acpi/acpica/source/
44 changes: 40 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ PFMLIB_INCLUDE :=
ifeq ($(CONFIG_LIBPFM),y)
KTF_PFMLIB_COMPILE := 1
export KTF_PFMLIB_COMPILE
TAR_CMD := tar --exclude=.git --exclude=.gitignore --strip-components=1 -xvf
TAR_CMD_PFMLIB := tar --exclude=.git --exclude=.gitignore --strip-components=1 -xvf
PFMLIB_VER := 4.10.1
PFMLIB_NAME := libpfm
PFMLIB_DIR := $(KTF_ROOT)/$(THIRD_PARTY)/$(PFMLIB_NAME)
Expand All @@ -47,6 +47,27 @@ PFMLIB_LINKER_FLAGS += -L$(PFMLIB_DIR) -lpfm
PFMLIB_INCLUDE += $(PFMLIB_DIR)/include
endif

ACPICA_DEST_DIR := $(KTF_ROOT)/drivers/acpi/acpica
ifeq ($(CONFIG_ACPICA),y)
TAR_CMD_ACPICA := tar --exclude=.git --exclude=.gitignore --strip-components=1 -C $(ACPICA_DEST_DIR) -xf
ACPICA_VER := unix-20210730
ACPICA_NAME := acpica
ACPICA_DIR := $(KTF_ROOT)/$(THIRD_PARTY)/$(ACPICA_NAME)
ACPICA_TARBALL := $(ACPICA_DIR)/$(ACPICA_NAME)-$(ACPICA_VER).tar.gz
ACPICA_PATCH := $(ACPICA_DIR)/acpica_ktf.patch
ACPICA_UNTAR_DIRS := $(ACPICA_NAME)-$(ACPICA_VER)/source/components/dispatcher
ACPICA_UNTAR_DIRS += $(ACPICA_NAME)-$(ACPICA_VER)/source/components/events
ACPICA_UNTAR_DIRS += $(ACPICA_NAME)-$(ACPICA_VER)/source/components/executer
ACPICA_UNTAR_DIRS += $(ACPICA_NAME)-$(ACPICA_VER)/source/components/hardware
ACPICA_UNTAR_DIRS += $(ACPICA_NAME)-$(ACPICA_VER)/source/components/namespace
ACPICA_UNTAR_DIRS += $(ACPICA_NAME)-$(ACPICA_VER)/source/components/parser
ACPICA_UNTAR_DIRS += $(ACPICA_NAME)-$(ACPICA_VER)/source/components/resources
ACPICA_UNTAR_DIRS += $(ACPICA_NAME)-$(ACPICA_VER)/source/components/tables
ACPICA_UNTAR_DIRS += $(ACPICA_NAME)-$(ACPICA_VER)/source/components/utilities
ACPICA_UNTAR_DIRS += $(ACPICA_NAME)-$(ACPICA_VER)/source/include
ACPICA_INCLUDE := $(ACPICA_DEST_DIR)/source/include
endif

ifeq ($(CC),cc) # overwrite on default, otherwise use whatever is in the CC env variable
CC := gcc
endif
Expand Down Expand Up @@ -75,13 +96,20 @@ COMMON_INCLUDES := -I$(KTF_ROOT)/include -I$(KTF_ROOT)/include/arch/x86
ifeq ($(CONFIG_LIBPFM),y)
COMMON_INCLUDES += -I$(PFMLIB_INCLUDE)
endif
ifeq ($(CONFIG_ACPICA),y)
COMMON_INCLUDES += -I$(ACPICA_INCLUDE)
endif

COMMON_FLAGS := $(COMMON_INCLUDES) -pipe -MP -MMD -m64 -D__x86_64__ -DEARLY_VIRT_MEM=$(CONFIG_EARLY_VIRT_MEM)
COMMON_FLAGS := $(COMMON_INCLUDES) -pipe -MP -MMD -m64 -D__x86_64__ -D__KTF__ -DEARLY_VIRT_MEM=$(CONFIG_EARLY_VIRT_MEM)

ifeq ($(CONFIG_LIBPFM),y)
COMMON_FLAGS += -DKTF_PMU
endif

ifeq ($(CONFIG_ACPICA),y)
COMMON_FLAGS += -DKTF_ACPICA
endif

AFLAGS := $(COMMON_FLAGS) -D__ASSEMBLY__ -nostdlib -nostdinc
CFLAGS := $(COMMON_FLAGS) -std=gnu99 -O3 -g -Wall -Wextra -ffreestanding -nostdlib -nostdinc
CFLAGS += -mno-red-zone -mno-mmx -mno-sse -mno-sse2
Expand All @@ -96,6 +124,13 @@ endif

-include Makeconf.local

ifeq ($(CONFIG_ACPICA),y)
ACPICA_INSTALL := $(shell [ -d $(ACPICA_DEST_DIR)/source ] || \
$(TAR_CMD_ACPICA) $(ACPICA_TARBALL) $(ACPICA_UNTAR_DIRS) && \
$(PATCH) -p0 < $(ACPICA_PATCH) && \
$(SYMLINK) $(ACPICA_DEST_DIR)/acktf.h $(ACPICA_DEST_DIR)/source/include/platform/acktf.h)
endif

SOURCES := $(shell find . -name \*.c)
HEADERS := $(shell find . -name \*.h)
ASM_SOURCES := $(shell find . -name \*.S)
Expand Down Expand Up @@ -139,7 +174,7 @@ $(PFMLIB_ARCHIVE): $(PFMLIB_TARBALL)
@echo "UNTAR pfmlib"
# untar tarball and apply the patch
cd $(PFMLIB_DIR) &&\
$(TAR_CMD) $(PFMLIB_TARBALL) $(PFMLIB_UNTAR_FILES) -C ./ &&\
$(TAR_CMD_PFMLIB) $(PFMLIB_TARBALL) $(PFMLIB_UNTAR_FILES) -C ./ &&\
$(PATCH) -p1 < $(PFMLIB_PATCH_FILE) &&\
cd -
# invoke libpfm build
Expand Down Expand Up @@ -171,6 +206,7 @@ ifeq ($(CONFIG_LIBPFM),y)
$(MAKE) -C $(PFMLIB_DIR) cleanlib
$(VERBOSE) find $(PFMLIB_DIR) -mindepth 1 ! -name $(PFMLIB_NAME)-$(PFMLIB_VER).tar.gz -delete
endif
$(VERBOSE) $(RM) -rf $(ACPICA_DEST_DIR)/source

# Check whether we can use kvm for qemu
ifeq ($(SYSTEM),LINUX)
Expand Down Expand Up @@ -265,7 +301,7 @@ dockerimage:
.PHONY: docker%
docker%: dockerimage
@echo "running target '$(strip $(subst :,, $*))' in docker"
$(VERBOSE) docker run -t $(DOCKERUSERFLAGS) -e UNITTEST=$(UNITTEST) -e CONFIG_LIBPFM=$(CONFIG_LIBPFM) -v $(PWD):$(PWD)$(DOCKER_MOUNT_OPTS) -w $(PWD) $(DOCKERIMAGE) bash -c "make -j $(strip $(subst :,, $*))"
$(VERBOSE) docker run -t $(DOCKERUSERFLAGS) -e UNITTEST=$(UNITTEST) -e CONFIG_LIBPFM=$(CONFIG_LIBPFM) -e CONFIG_ACPICA=$(CONFIG_ACPICA) -v $(PWD):$(PWD)$(DOCKER_MOUNT_OPTS) -w $(PWD) $(DOCKERIMAGE) bash -c "make -j $(strip $(subst :,, $*))"

.PHONY: onelinescan
onelinescan:
Expand Down
37 changes: 37 additions & 0 deletions THIRD-PARTY-LICENSES
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,40 @@ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIG
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

----------------

** ACPI Component Architecture (ACPICA) -- https://acpica.org/
1. Copyright Notice

Some or all of this work - Copyright (c) 1999 - 2021, Intel Corp.
All rights reserved.

2. License

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,
without modification.
2. Redistributions in binary form must reproduce at minimum a disclaimer
substantially similar to the "NO WARRANTY" disclaimer below
("Disclaimer") and any redistribution must be conditioned upon
including a substantially similar Disclaimer requirement for further
binary redistribution.
3. Neither the names of the above-listed copyright holders nor the names
of any contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
OWNER 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.
75 changes: 74 additions & 1 deletion common/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <acpi.h>
#ifndef KTF_ACPICA
#include <acpi_ktf.h>
#include <errno.h>
#include <ioapic.h>
#include <ktf.h>
Expand Down Expand Up @@ -439,3 +440,75 @@ int init_acpi(unsigned bsp_cpu_id) {

return process_madt_entries(bsp_cpu_id);
}
#else /* KTF_ACPICA */
#include <acpi_ktf.h>
#include <ioapic.h>
#include <ktf.h>
#include <percpu.h>

#include "acpi.h"

static unsigned nr_cpus;

/* ACPI initialization and termination functions */

static ACPI_STATUS InitializeFullAcpi(void) {
ACPI_STATUS status;

/* Initialize the ACPICA subsystem */
status = AcpiInitializeSubsystem();
if (ACPI_FAILURE(status))
return status;

/* Initialize the ACPICA Table Manager and get all ACPI tables */
status = AcpiInitializeTables(NULL, 16, true);
if (ACPI_FAILURE(status))
return status;

/* Create the ACPI namespace from ACPI tables */
status = AcpiLoadTables();
if (ACPI_FAILURE(status))
return status;

/* Note: Local handlers should be installed here */
/* Initialize the ACPI hardware */
status = AcpiEnableSubsystem(ACPI_FULL_INITIALIZATION);
if (ACPI_FAILURE(status))
return status;

/* Complete the ACPI namespace object initialization */
status = AcpiInitializeObjects(ACPI_FULL_INITIALIZATION);
if (ACPI_FAILURE(status))
return status;

return AE_OK;
}

unsigned acpi_get_nr_cpus(void) { return nr_cpus; }

void *acpi_find_table(char *signature) {
ACPI_TABLE_HEADER *hdr;

AcpiGetTable(signature, 1, &hdr);
return hdr;
}

void acpi_walk_subtables(ACPI_SUBTABLE_HEADER *entry, uint32_t length,
acpi_subtable_parser_t parser, void *arg) {
ACPI_SUBTABLE_HEADER *stop = (void *) entry + length;

while (entry < stop && entry->Length >= sizeof(*entry)) {
parser(entry, arg);
entry = ACPI_ADD_PTR(ACPI_SUBTABLE_HEADER, entry, entry->Length);
}
}

ACPI_STATUS init_acpi(unsigned bsp_cpu_id) {
ACPI_STATUS status;

printk("Initializing ACPI support\n");

status = InitializeFullAcpi();
return status;
}
#endif /* KTF_ACPICA */
13 changes: 10 additions & 3 deletions common/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <acpi.h>
#include <acpi_ktf.h>
#include <apic.h>
#include <cmdline.h>
#include <console.h>
Expand Down Expand Up @@ -262,8 +262,15 @@ void __noreturn __text_init kernel_start(uint32_t multiboot_magic,

init_slab();

if (init_acpi(get_bsp_cpu_id()) < 0 && init_mptables() < 0) {
BUG();
/* Try to initialize ACPI (and MADT) */
#ifndef KTF_ACPICA
if (init_acpi(get_bsp_cpu_id()) < 0) {
#else
if (ACPI_FAILURE(init_acpi(get_bsp_cpu_id()))) {
#endif
/* Fallback to MP tables when no ACPI */
if (init_mptables() < 0)
BUG();
}

init_vga_console();
Expand Down
101 changes: 101 additions & 0 deletions drivers/acpi/acpica/acktf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/******************************************************************************
*
* Name: acktf.h - OS specific defines, etc. for KTF
*
*****************************************************************************/

/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2021, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 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,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
* OWNER 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.
*
*****************************************************************************/

#ifdef KTF_ACPICA

#ifndef __ACKTF_H__
#define __ACKTF_H__

/* Common (in-kernel/user-space) ACPICA configuration */

#define ACPI_USE_SYSTEM_CLIBRARY
#define ACPI_USE_DO_WHILE_0
#define ACPI_USE_LOCAL_CACHE

/* Kernel specific ACPICA configuration */

#define ACPI_DEBUG_OUTPUT

#include <spinlock.h>
#include <string.h>

#include "acenv.h"

#define ACPI_INIT_FUNCTION
#define ACPI_CACHE_T ACPI_MEMORY_LIST

/* Host-dependent types and defines for in-kernel ACPICA */

#define ACPI_EXPORT_SYMBOL(symbol)

#define ACPI_SPINLOCK spinlock_t *
#define ACPI_CPU_FLAGS unsigned long

#define ACPI_MSG_ERROR "ACPI Error: "
#define ACPI_MSG_EXCEPTION "ACPI Exception: "
#define ACPI_MSG_WARNING "ACPI Warning: "
#define ACPI_MSG_INFO "ACPI: "

#define ACPI_MSG_BIOS_ERROR "ACPI BIOS Error (bug): "
#define ACPI_MSG_BIOS_WARNING "ACPI BIOS Warning (bug): "

#ifndef __init
#define __init
#endif
#ifndef __iomem
#define __iomem
#endif

#if defined(__x86_64__)
#define ACPI_MACHINE_WIDTH 64
#define COMPILER_DEPENDENT_INT64 long
#define COMPILER_DEPENDENT_UINT64 unsigned long
#else
#define ACPI_MACHINE_WIDTH 32
#define COMPILER_DEPENDENT_INT64 long long
#define COMPILER_DEPENDENT_UINT64 unsigned long long
#endif

#endif /* __ACKTF_H__ */
#endif /* KTF_ACPICA */
Loading

0 comments on commit b84be73

Please sign in to comment.