Skip to content

Instantly share code, notes, and snippets.

@mcastelino
Last active December 23, 2021 16:47
Show Gist options
  • Save mcastelino/47c1fcec1b364d5e82d42e6f341eba78 to your computer and use it in GitHub Desktop.
Save mcastelino/47c1fcec1b364d5e82d42e6f341eba78 to your computer and use it in GitHub Desktop.
Debugging APCI using QEMU

Debugging ACPI Events in the kernel

Kernel Build

Build the kernel with ACPI debug enabled as described in https://www.kernel.org/doc/Documentation/acpi/debug.txt

tl;dr

ACPI debug output is globally enabled by CONFIG_ACPI_DEBUG.  If this config
option is turned off, the debug messages are not even built into the
kernel.

When CONFIG_ACPI_DEBUG=y, you can select the component and level of messages
you're interested in.  At boot-time, use the acpi.debug_layer and
acpi.debug_level kernel command line options.  After boot, you can use the
debug_layer and debug_level files in /sys/module/acpi/parameters/ to control
the debug messages.

The "debug_layer" is a mask that selects components of interest, e.g., a
specific driver or part of the ACPI interpreter.  To build the debug_layer
bitmask, look for the "#define _COMPONENT" in an ACPI source file.

The "debug_level" is a mask that selects different types of messages, e.g.,
those related to initialization, method execution, informational messages, etc.
To build debug_level, look at the level specified in an ACPI_DEBUG_PRINT()
statement.

The ACPI interpreter uses several different levels, but the Linux
ACPI core and ACPI drivers generally only use ACPI_LV_INFO.

Launching QEMU

#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh

VMN=${VMN:=1}

NEMU=qemu-system-x86_64

let APCI_UTILITIES=0x00000001
let APCI_HARDWARE=0x00000002
let APCI_EVENTS=0x00000004
let APCI_TABLES=0x00000008
let APCI_NAMESPACE=0x00000010
let APCI_PARSER=0x00000020
let APCI_DISPATCHER=0x00000040
let APCI_EXECUTER=0x00000080
let APCI_RESOURCES=0x00000100
let APCI_CA_DEBUGGER=0x00000200
let APCI_OS_SERVICES=0x00000400
let APCI_CA_DISASSEMBLER=0x00000800
let APCI_COMPILER=0x00001000
let APCI_TOOLS=0x00002000
let APCI_BUS_COMPONENT=0x00010000
let APCI_AC_COMPONENT=0x00020000
let APCI_BATTERY_COMPONENT=0x00040000
let APCI_BUTTON_COMPONENT=0x00080000
let APCI_SBS_COMPONENT=0x00100000
let APCI_FAN_COMPONENT=0x00200000
let APCI_PCI_COMPONENT=0x00400000
let APCI_POWER_COMPONENT=0x00800000
let APCI_CONTAINER_COMPONENT=0x01000000
let APCI_SYSTEM_COMPONENT=0x02000000
let APCI_THERMAL_COMPONENT=0x04000000
let APCI_MEMORY_DEVICE_COMPONENT=0x08000000
let APCI_VIDEO_COMPONENT=0x10000000
let APCI_PROCESSOR_COMPONENT=0x20000000

let acpi_debug_layer=$((APCI_HARDWARE|APCI_EVENTS|APCI_PCI_COMPONENT|APCI_TABLES|APCI_RESOURCES|APCI_BUS_COMPONENT|APCI_BUTTON_COMPONENT|APCI_OS_SERVICES|APCI_PROCESSOR_COMPONENT|APCI_MEMORY_DEVICE_COMPONENT|APCI_RESOURCES))

let APCI_LV_INIT=0x00000001
let APCI_LV_DEBUG_OBJECT=0x00000002
let APCI_LV_INFO=0x00000004
let APCI_LV_INIT_NAMES=0x00000020
let APCI_LV_PARSE=0x00000040
let APCI_LV_LOAD=0x00000080
let APCI_LV_DISPATCH=0x00000100
let APCI_LV_EXEC=0x00000200
let APCI_LV_NAMES=0x00000400
let APCI_LV_OPREGION=0x00000800
let APCI_LV_BFIELD=0x00001000
let APCI_LV_TABLES=0x00002000
let APCI_LV_VALUES=0x00004000
let APCI_LV_OBJECTS=0x00008000
let APCI_LV_RESOURCES=0x00010000
let APCI_LV_USER_REQUESTS=0x00020000
let APCI_LV_PACKAGE=0x00040000
let APCI_LV_ALLOCATIONS=0x00100000
let APCI_LV_FUNCTIONS=0x00200000
let APCI_LV_OPTIMIZATIONS=0x00400000
let APCI_LV_MUTEX=0x01000000
let APCI_LV_THREADS=0x02000000
let APCI_LV_IO=0x04000000
let APCI_LV_INTERRUPTS=0x08000000
let APCI_LV_AML_DISASSEMBLE=0x10000000
let APCI_LV_VERBOSE_INFO=0x20000000
let APCI_LV_FULL_TABLES=0x40000000
let APCI_LV_EVENTS=0x80000000

let apci_debug_level=$((APCI_LV_INFO|APCI_LV_DEBUG_OBJECT|APCI_LV_INTERRUPTS|APCI_LV_EVENTS|APCI_LV_IO|APCI_LV_FUNCTIONS|APCI_LV_DISPATCH|APCI_LV_OPREGION|APCI_LV_FULL_TABLES|APCI_LV_VERBOSE_INFO))

sudo $NEMU \
     -bios /mnt/fastdata/NEMU/OVMF.fd.virt \
     -enable-kvm \
     -nodefaults \
     -vga none -nographic \
     -smp sockets=1,cpus=4,cores=2,maxcpus=8 -cpu host \
     -m 512 \
     -kernel /mnt/fastdata/NEMU/linux/arch/x86_64/boot/bzImage -append 'console=hvc0 iommu=false root=/dev/vda3 rw rootfstype=ext4 data=ordered rcupdate.rcu_expedited=1 tsc=reliable no_timer_check reboot=t noapictimer acpi.debug_layer='"${acpi_debug_layer}"' acpi.debug_level='"${apci_debug_level}"' log_buf_len=1M loglevel=2' \
     -device virtio-blk-pci,drive=image -drive if=none,id=image,file=/mnt/fastdata/NEMU/clear.img,format=raw \
     -device virtio-serial-pci,id=virtio-serial0 -device virtconsole,chardev=charconsole0,id=console0 -chardev stdio,id=charconsole0 \
     -monitor telnet:127.0.0.1:55555,server,nowait \
     -netdev user,id=mynet0,hostfwd=tcp::${VMN}0022-:22 -device virtio-net-pci,netdev=mynet0,romfile="" \
     -device pci-bridge,id=pci-bridge-0,chassis_nr=1,shpc=off \
     -device pci-bridge,id=pci-bridge-1,chassis_nr=2 \
     
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment