The HPET is a 64-bit counter. The spec permits both 32-bit and 64-bit
aligned access. We should use bus_space_read_8() in acpihpet_r()
where it is available to improve the accuracy of acpihpet_delay().
The math is obvious: one read is faster than two.
Switching acpihpet_w() to bus_space_read_write_8() is not strictly
necessary, but it does shrink the object file a bit and also keeps the
two functions symmetrical.
-current:
-rw-r--r-- 1 ssc wobj 53512 Aug 25 13:28 obj/acpihpet.o
patched:
-rw-r--r-- 1 ssc wobj 50040 Aug 25 13:29 obj/acpihpet.o
So we shave 3472 bytes off the module on amd64.
As suggested by jsg@ in the big ACPI delay thread, I am using __LP64__
to decide between 4-byte and 8-byte bus access.
ok?
Index: acpihpet.c
===================================================================
RCS file: /cvs/src/sys/dev/acpi/acpihpet.c,v
retrieving revision 1.28
diff -u -p -r1.28 acpihpet.c
--- acpihpet.c 25 Aug 2022 18:01:54 -0000 1.28
+++ acpihpet.c 25 Aug 2022 18:34:11 -0000
@@ -86,20 +86,28 @@ struct cfdriver acpihpet_cd = {
uint64_t
acpihpet_r(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t ioa)
{
+#if defined(__LP64__)
+ return bus_space_read_8(iot, ioh, ioa);
+#else
uint64_t val;
val = bus_space_read_4(iot, ioh, ioa + 4);
val = val << 32;
val |= bus_space_read_4(iot, ioh, ioa);
return (val);
+#endif
}
void
acpihpet_w(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t ioa,
uint64_t val)
{
+#if defined(__LP64__)
+ bus_space_write_8(iot, ioh, ioa, val);
+#else
bus_space_write_4(iot, ioh, ioa + 4, val >> 32);
bus_space_write_4(iot, ioh, ioa, val & 0xffffffff);
+#endif
}
int