git: 7ae6593f7a64 - stable/15 - acpi_timer: Remove unneeded acpi_timer_freq global variable

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Thu, 08 Oct 2026 20:44:20 UTC
The branch stable/15 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=7ae6593f7a6436a32a17e5f81a71cfdd2d6f0610

commit 7ae6593f7a6436a32a17e5f81a71cfdd2d6f0610
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2026-09-30 16:04:59 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2026-10-08 20:42:33 +0000

    acpi_timer: Remove unneeded acpi_timer_freq global variable
    
    This was just an alias of acpi_timer_timecounter.tc_frequency.  While
    here, register the machdep.acpi_timer_freq sysctl node dynamically
    only if the driver attaches rather than making the handler fail with
    EOPNOTSUPP if the driver had not attached.
    
    Differential Revision:  https://reviews.freebsd.org/D59935
    
    (cherry picked from commit 381840e88072a90df7ffb5731c08935412edbc19)
---
 sys/dev/acpica/acpi_timer.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/sys/dev/acpica/acpi_timer.c b/sys/dev/acpica/acpi_timer.c
index b1c1d64cd171..c6d015388f2a 100644
--- a/sys/dev/acpica/acpi_timer.c
+++ b/sys/dev/acpica/acpi_timer.c
@@ -59,7 +59,7 @@ static device_t			acpi_timer_dev;
 static struct resource		*acpi_timer_reg;
 static eventhandler_tag		acpi_timer_eh;
 
-static u_int	acpi_timer_frequency = 14318182 / 4;
+#define	ACPI_TIMER_FREQUENCY	(14318182 / 4)
 
 static void	acpi_timer_identify(driver_t *driver, device_t parent);
 static int	acpi_timer_probe(device_t dev);
@@ -154,7 +154,7 @@ acpi_timer_probe(device_t dev)
 
     device_set_descf(dev, "%d-bit timer at %u.%06uMHz",
 	(AcpiGbl_FADT.Flags & ACPI_FADT_32BIT_TIMER) != 0 ? 32 : 24,
-	acpi_timer_frequency / 1000000, acpi_timer_frequency % 1000000);
+	ACPI_TIMER_FREQUENCY / 1000000, ACPI_TIMER_FREQUENCY % 1000000);
     return (0);
 }
 
@@ -191,10 +191,14 @@ acpi_timer_attach(device_t dev)
 	acpi_timer_timecounter.tc_counter_mask = 0xffffffff;
     else
 	acpi_timer_timecounter.tc_counter_mask = 0x00ffffff;
-    acpi_timer_timecounter.tc_frequency = acpi_timer_frequency;
+    acpi_timer_timecounter.tc_frequency = ACPI_TIMER_FREQUENCY;
 
     tc_init(&acpi_timer_timecounter);
 
+    SYSCTL_ADD_PROC(NULL, SYSCTL_STATIC_CHILDREN(_machdep), OID_AUTO,
+	"acpi_timer_freq", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
+	NULL, 0, acpi_timer_sysctl_freq, "I", "ACPI timer frequency");
+
     return (0);
 }
 
@@ -265,19 +269,11 @@ acpi_timer_sysctl_freq(SYSCTL_HANDLER_ARGS)
     int error;
     u_int freq;
 
-    if (acpi_timer_timecounter.tc_frequency == 0)
-	return (EOPNOTSUPP);
-    freq = acpi_timer_frequency;
+    freq = acpi_timer_timecounter.tc_frequency;
     error = sysctl_handle_int(oidp, &freq, 0, req);
     if (error == 0 && req->newptr != NULL) {
-	acpi_timer_frequency = freq;
-	acpi_timer_timecounter.tc_frequency = acpi_timer_frequency;
+	acpi_timer_timecounter.tc_frequency = freq;
     }
 
     return (error);
 }
-
-SYSCTL_PROC(_machdep, OID_AUTO, acpi_timer_freq,
-    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 0,
-    acpi_timer_sysctl_freq, "I",
-    "ACPI timer frequency");