Skip to contentSkip to conversation

tools: Remove support for qemu-trad's battery reporting

PATCH In review Alejandro Vallejo 5 participants 6 messages Mar 25, 2025 – Mar 26, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: Remove support for qemu-trad's battery reporting

The way this undocumented feature works is via qemu-trad (who nobody uses anymore), by intercepting 3 magic PIOs. 0x88 is one of them, and it's probed by hvmloader as a means of detecting support for this (so, on qemu-upstream this check always fails). If hvmloader detects the feature, it appends an SSDT with AML inherited from some laptop ~20y ago. QEMU then communicates with a userspace daemon (xenpmd) via an undocumented xenstore key ("refreshbatterystatus") in order to report battery levels.

Seeing how no one uses, mantains or cares about qemu-trad anymore, rip it all out. The hvmloader check, the SSDT generation logic and xenpmd.

---
If this feature is truly wanted, it must be implemented in qemu-upstream. Ideally in a MUCH less roundabout way. And definitely without involving xenstore.

---
 .gitignore                      |   1 -
 tools/Makefile                  |   1 -
 tools/firmware/hvmloader/util.c |   7 -
 tools/libacpi/Makefile          |   2 +-
 tools/libacpi/build.c           |   9 -
 tools/libacpi/libacpi.h         |   2 +-
 tools/libacpi/ssdt_pm.asl       | 409 -------------------------
 tools/xenpmd/Makefile           |  30 --
 tools/xenpmd/xenpmd.c           | 525 --------------------------------
 9 files changed, 2 insertions(+), 984 deletions(-)
 delete mode 100644 tools/libacpi/ssdt_pm.asl
 delete mode 100644 tools/xenpmd/Makefile
 delete mode 100644 tools/xenpmd/xenpmd.c
.gitignore +0 -1
index 53f5df000383..ea716b6dd7e0 100644
@@ -186,7 +186,6 @@ tools/xcutils/readnotes
 tools/xenmon/xentrace_setmask
 tools/xenmon/xenbaked
 tools/xenpaging/xenpaging
-tools/xenpmd/xenpmd
 tools/xentop/xentop
 tools/xentrace/xentrace_setsize
 tools/xentrace/tbctl
tools/Makefile +0 -1
index e9e1cda3053f..935ba3936dd9 100644
@@ -28,7 +28,6 @@ SUBDIRS-$(CONFIG_QEMU_TRAD) += qemu-xen-traditional-dir
 SUBDIRS-$(CONFIG_QEMU_XEN) += qemu-xen-dir
 endif
 
-SUBDIRS-y += xenpmd
 SUBDIRS-$(CONFIG_GOLANG) += golang
 SUBDIRS-y += xl
 SUBDIRS-y += helpers
tools/firmware/hvmloader/util.c +0 -7
index 2d07ce129013..0e6457994595 100644
@@ -776,11 +776,6 @@ int hpet_exists(unsigned long hpet_base)
     return ((hpet_id >> 16) == 0x8086);
 }
 
-static uint8_t battery_port_exists(void)
-{
-    return (inb(0x88) == 0x1F);
-}
-
 static unsigned long acpi_v2p(struct acpi_ctxt *ctxt, void *v)
 {
     return virt_to_phys(v);
@@ -900,8 +895,6 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
             config->pt.length = strtoll(s, NULL, 0);
     }
 
-    if ( battery_port_exists() )
-        config->table_flags |= ACPI_HAS_SSDT_PM;
     if ( !strncmp(xenstore_read("platform/acpi_s3", "1"), "1", 1)  )
         config->table_flags |= ACPI_HAS_SSDT_S3;
     if ( !strncmp(xenstore_read("platform/acpi_s4", "1"), "1", 1)  )
tools/libacpi/Makefile +1 -1
index b21a64c6b441..e57873b361f4 100644
@@ -15,7 +15,7 @@ C_SRC-$(CONFIG_X86) = dsdt_anycpu.c dsdt_15cpu.c dsdt_anycpu_qemu_xen.c dsdt_pvh
 C_SRC-$(CONFIG_ARM_64) = dsdt_anycpu_arm.c
 DSDT_FILES ?= $(C_SRC-y)
 C_SRC = $(addprefix $(ACPI_BUILD_DIR)/, $(DSDT_FILES))
-H_SRC = $(addprefix $(ACPI_BUILD_DIR)/, ssdt_s3.h ssdt_s4.h ssdt_pm.h)
+H_SRC = $(addprefix $(ACPI_BUILD_DIR)/, ssdt_s3.h ssdt_s4.h)
 H_SRC += $(addprefix $(ACPI_BUILD_DIR)/, ssdt_tpm.h ssdt_tpm2.h ssdt_laptop_slate.h)
 
 MKDSDT_CFLAGS-$(CONFIG_ARM_64) = -DCONFIG_ARM_64
tools/libacpi/build.c +0 -9
index 2f29863db154..f91b9a22e95e 100644
@@ -11,7 +11,6 @@
 #include "ssdt_s4.h"
 #include "ssdt_tpm.h"
 #include "ssdt_tpm2.h"
-#include "ssdt_pm.h"
 #include "ssdt_laptop_slate.h"
 #include <xen/hvm/hvm_info_table.h>
 #include <xen/hvm/hvm_xs_strings.h>
@@ -371,14 +370,6 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt,
         table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, waet);
     }
 
-    if ( config->table_flags & ACPI_HAS_SSDT_PM )
-    {
-        ssdt = ctxt->mem_ops.alloc(ctxt, sizeof(ssdt_pm), 16);
-        if (!ssdt) return -1;
-        memcpy(ssdt, ssdt_pm, sizeof(ssdt_pm));
-        table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, ssdt);
-    }
-
     if ( config->table_flags & ACPI_HAS_SSDT_S3 )
     {
         ssdt = ctxt->mem_ops.alloc(ctxt, sizeof(ssdt_s3), 16);
tools/libacpi/libacpi.h +1 -1
index deda39e5dbc4..79298beccf9e 100644
@@ -15,7 +15,7 @@
 #define ACPI_HAS_COM2              (1<<1)
 #define ACPI_HAS_LPT1              (1<<2)
 #define ACPI_HAS_HPET              (1<<3)
-#define ACPI_HAS_SSDT_PM           (1<<4)
+/* (1<<4) deprecated */
 #define ACPI_HAS_SSDT_S3           (1<<5)
 #define ACPI_HAS_SSDT_S4           (1<<6)
 #define ACPI_HAS_TPM               (1<<7)
tools/libacpi/ssdt_pm.asl deleted +0 -409

409 lines not on this page · raw message

tools/xenpmd/Makefile deleted +0 -30
deleted file mode 100644
index 8da20510b54a..000000000000
@@ -1,30 +0,0 @@
-XEN_ROOT=$(CURDIR)/../..
-include $(XEN_ROOT)/tools/Rules.mk
-
-CFLAGS += $(CFLAGS_libxenstore)
-
-LDLIBS += $(LDLIBS_libxenstore)
-
-.PHONY: all
-all: xenpmd
-
-.PHONY: install
-install: all
-	$(INSTALL_DIR) $(DESTDIR)$(sbindir)
-	$(INSTALL_PROG) xenpmd $(DESTDIR)$(sbindir)
-
-.PHONY: clean
-clean:
-	$(RM) -f xenpmd xenpmd.o $(DEPS_RM)
-
-.PHONY: distclean
-distclean: clean
-
-.PHONY: uninstall
-uninstall:
-	rm -f $(DESTDIR)$(sbindir)/xenpmd
-
-xenpmd: xenpmd.o Makefile
-	$(CC) $(LDFLAGS) $< -o $@ $(LDLIBS) $(APPEND_LDFLAGS)
-
--include $(DEPS_INCLUDE)
tools/xenpmd/xenpmd.c deleted +0 -525

525 lines not on this page · raw message

Signature · 1 line
2.48.1
#1 lore raw
Quoted 11 lines · Alejandro Vallejo

The way this undocumented feature works is via qemu-trad (who nobody uses anymore), by intercepting 3 magic PIOs. 0x88 is one of them, and it's probed by hvmloader as a means of detecting support for this (so, on qemu-upstream this check always fails). If hvmloader detects the feature, it appends an SSDT with AML inherited from some laptop ~20y ago. QEMU then communicates with a userspace daemon (xenpmd) via an undocumented xenstore key ("refreshbatterystatus") in order to report battery levels.

Seeing how no one uses, mantains or cares about qemu-trad anymore, rip it all out. The hvmloader check, the SSDT generation logic and xenpmd.

Oh, I didn't know something like this existed!
We needed a feature like this, and solved it via extra kernel module + PV-like interface to feed it with data from dom0:
https://github.com/QubesOS/qubes-dummy-psu/

I guess it doesn't make much sense for me to resurrect the old interface and bring it to QEMU upstream, as I need the battery info in PVH too. So, I'm fine with removing it as is.

Quoted 5 lines

---
If this feature is truly wanted, it must be implemented in qemu-upstream. Ideally in a MUCH less roundabout way. And definitely without involving xenstore.

Signature · 3 lines
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
#4 lore raw
In reply to Alejandro Vallejo
Quoted 8 lines · Alejandro Vallejo

The way this undocumented feature works is via qemu-trad (who nobody uses anymore), by intercepting 3 magic PIOs. 0x88 is one of them, and it's probed by hvmloader as a means of detecting support for this (so, on qemu-upstream this check always fails). If hvmloader detects the feature, it appends an SSDT with AML inherited from some laptop ~20y ago. QEMU then communicates with a userspace daemon (xenpmd) via an undocumented xenstore key ("refreshbatterystatus") in order to report battery levels.

Any chance we can make this less undocumented, even if it is a note saying "removed now" ?

Quoted 9 lines

Seeing how no one uses, mantains or cares about qemu-trad anymore, rip it all out. The hvmloader check, the SSDT generation logic and xenpmd.

---
If this feature is truly wanted, it must be implemented in qemu-upstream. Ideally in a MUCH less roundabout way. And definitely without involving xenstore.

Quoted 14 lines
---
 .gitignore                      |   1 -
 tools/Makefile                  |   1 -
 tools/firmware/hvmloader/util.c |   7 -
 tools/libacpi/Makefile          |   2 +-
 tools/libacpi/build.c           |   9 -
 tools/libacpi/libacpi.h         |   2 +-
 tools/libacpi/ssdt_pm.asl       | 409 -------------------------
 tools/xenpmd/Makefile           |  30 --
 tools/xenpmd/xenpmd.c           | 525 --------------------------------
 9 files changed, 2 insertions(+), 984 deletions(-)
 delete mode 100644 tools/libacpi/ssdt_pm.asl
 delete mode 100644 tools/xenpmd/Makefile
 delete mode 100644 tools/xenpmd/xenpmd.c

I'm tempted to summarily ack this based on diffstat alone.

Juergen has expressed an interest in finally purging qemu-trad in this release cycle, which I agree with.

If we're going to do this, then I suggest we delete qemu-trad first. Otherwise we are technically breaking something that someone might be using.

~Andrew

#5 lore raw
Quoted 37 lines · Andrew Cooper
Quoted 8 lines · Alejandro Vallejo

The way this undocumented feature works is via qemu-trad (who nobody uses anymore), by intercepting 3 magic PIOs. 0x88 is one of them, and it's probed by hvmloader as a means of detecting support for this (so, on qemu-upstream this check always fails). If hvmloader detects the feature, it appends an SSDT with AML inherited from some laptop ~20y ago. QEMU then communicates with a userspace daemon (xenpmd) via an undocumented xenstore key ("refreshbatterystatus") in order to report battery levels.

Any chance we can make this less undocumented, even if it is a note saying "removed now" ?

Quoted 20 lines

Seeing how no one uses, mantains or cares about qemu-trad anymore, rip it all out. The hvmloader check, the SSDT generation logic and xenpmd.

---
If this feature is truly wanted, it must be implemented in qemu-upstream. Ideally in a MUCH less roundabout way. And definitely without involving xenstore.

---
  .gitignore                      |   1 -
  tools/Makefile                  |   1 -
  tools/firmware/hvmloader/util.c |   7 -
  tools/libacpi/Makefile          |   2 +-
  tools/libacpi/build.c           |   9 -
  tools/libacpi/libacpi.h         |   2 +-
  tools/libacpi/ssdt_pm.asl       | 409 -------------------------
  tools/xenpmd/Makefile           |  30 --
  tools/xenpmd/xenpmd.c           | 525 --------------------------------
  9 files changed, 2 insertions(+), 984 deletions(-)
Quoted 3 lines

delete mode 100644 tools/libacpi/ssdt_pm.asl
delete mode 100644 tools/xenpmd/Makefile
delete mode 100644 tools/xenpmd/xenpmd.c

Quoted 7 lines

I'm tempted to summarily ack this based on diffstat alone.

Juergen has expressed an interest in finally purging qemu-trad in this release cycle, which I agree with.

If we're going to do this, then I suggest we delete qemu-trad first. Otherwise we are technically breaking something that someone might be using.

I'm working on the patches right now.

Juergen

#2 lore raw
In reply to Marek Marczykowski-Górecki
Quoted 10 lines · Marek Marczykowski-Górecki
Quoted 9 lines · Alejandro Vallejo

The way this undocumented feature works is via qemu-trad (who nobody uses anymore), by intercepting 3 magic PIOs. 0x88 is one of them, and it's probed by hvmloader as a means of detecting support for this (so, on qemu-upstream this check always fails). If hvmloader detects the feature, it appends an SSDT with AML inherited from some laptop ~20y ago. QEMU then communicates with a userspace daemon (xenpmd) via an undocumented xenstore key ("refreshbatterystatus") in order to report battery levels.

Quoted 4 lines
Quoted 2 lines

Seeing how no one uses, mantains or cares about qemu-trad anymore, rip it all out. The hvmloader check, the SSDT generation logic and xenpmd.

Oh, I didn't know something like this existed!

In retrospect, it might've been for the best. I really dislike the way it's put together. Using xenstore feels really pointless.

Quoted 3 lines

We needed a feature like this, and solved it via extra kernel module + PV-like interface to feed it with data from dom0:
https://github.com/QubesOS/qubes-dummy-psu/

I did wonder (after learning how this all works) how you guys did it without qemu-trad. I guess that explains it. FWIW, it's not hard to do this properly on QEMU upstream. We could create a new field under a BAR of the Xen platform device and instruct some (much, much, much simpler) AML to read the battery level from there. Then QEMU can ask the real system what the battery level is and Bob's your uncle.

But...

Quoted 4 lines

I guess it doesn't make much sense for me to resurrect the old interface and bring it to QEMU upstream, as I need the battery info in PVH too. So, I'm fine with removing it as is.

... in principle I'd say QubesOS and OpenXT are the two only plausible users of this feature. So it's a tad pointless if you've since developed a working solution many years ago.

Cheers,
Alejandro

#3 lore raw
Quoted 23 lines · Alejandro Vallejo
Quoted 10 lines · Marek Marczykowski-Górecki
Quoted 9 lines · Alejandro Vallejo

The way this undocumented feature works is via qemu-trad (who nobody uses anymore), by intercepting 3 magic PIOs. 0x88 is one of them, and it's probed by hvmloader as a means of detecting support for this (so, on qemu-upstream this check always fails). If hvmloader detects the feature, it appends an SSDT with AML inherited from some laptop ~20y ago. QEMU then communicates with a userspace daemon (xenpmd) via an undocumented xenstore key ("refreshbatterystatus") in order to report battery levels.

Quoted 4 lines
Quoted 2 lines

Seeing how no one uses, mantains or cares about qemu-trad anymore, rip it all out. The hvmloader check, the SSDT generation logic and xenpmd.

Oh, I didn't know something like this existed!

In retrospect, it might've been for the best. I really dislike the way it's put together. Using xenstore feels really pointless.

Quoted 3 lines

We needed a feature like this, and solved it via extra kernel module + PV-like interface to feed it with data from dom0:
https://github.com/QubesOS/qubes-dummy-psu/

Quoted 6 lines

I did wonder (after learning how this all works) how you guys did it without qemu-trad. I guess that explains it. FWIW, it's not hard to do this properly on QEMU upstream. We could create a new field under a BAR of the Xen platform device and instruct some (much, much, much simpler) AML to read the battery level from there. Then QEMU can ask the real system what the battery level is and Bob's your uncle.

I think some OSes (Linux? Possibly Windows?) like to use the xenpci device BAR to put the grant table and as scratch space to map grants, so we need to be careful with putting real registers there, as older guests might not know about them.

Also that would mean adding QEMU (even if just for a limited usage) if we want the feature for PVH guests.

It might be safer to place those registers in a physmap reserved region, but not correlated with any device BAR. Otherwise if the guest decides to turn memory decoding off (which it shouldn't do in the first place), the related AML will stop working properly.

I wonder if we could find a way to do this nicely from ACPI (so not using a side band PV interface) and not have to involve QEMU.

Thanks, Roger.