The branch main has been updated by jhb:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=660331da7a75e897ae9710c9933962d82f0a194c

commit 660331da7a75e897ae9710c9933962d82f0a194c
Author:     Brooks Davis <bro...@freebsd.org>
AuthorDate: 2025-01-14 15:48:07 +0000
Commit:     John Baldwin <j...@freebsd.org>
CommitDate: 2025-01-14 15:48:07 +0000

    Centralize and simpify implemention of some VM macros
    
    These macros have substantially identical implementations on each
    platform.  Use roundup2/rounddown2 for round_page/trunc_page.
    
    This version standardizes on not using explicit casts and instead
    preserving the original type.  A couple of tweaks were required to
    make this work.
    
    Reviewed by:    brooks, kib, markj
    Obtained from:  CheriBSD
    Differential Revision:  https://reviews.freebsd.org/D48450
---
 sys/amd64/amd64/pmap.c         |  2 +-
 sys/amd64/include/param.h      |  7 -------
 sys/arm/arm/minidump_machdep.c |  3 ++-
 sys/arm/include/param.h        |  7 -------
 sys/arm64/include/param.h      |  8 --------
 sys/i386/include/param.h       |  7 -------
 sys/powerpc/include/param.h    |  7 -------
 sys/riscv/include/param.h      |  8 --------
 sys/sys/param.h                | 11 +++++++++++
 usr.bin/systat/sysput.c        |  3 +--
 10 files changed, 15 insertions(+), 48 deletions(-)

diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c
index 265d48e26c0b..5d31ad0dd495 100644
--- a/sys/amd64/amd64/pmap.c
+++ b/sys/amd64/amd64/pmap.c
@@ -2499,7 +2499,7 @@ pmap_init(void)
                                ret = vm_page_blacklist_add(0x40000000 +
                                    ptoa(i), false);
                                if (!ret && bootverbose)
-                                       printf("page at %#lx already used\n",
+                                       printf("page at %#x already used\n",
                                            0x40000000 + ptoa(i));
                        }
                }
diff --git a/sys/amd64/include/param.h b/sys/amd64/include/param.h
index 8ad1c0e93c6a..371128c6fe20 100644
--- a/sys/amd64/include/param.h
+++ b/sys/amd64/include/param.h
@@ -142,20 +142,13 @@
 /*
  * Mach derived conversion macros
  */
-#define        round_page(x)   ((((unsigned long)(x)) + PAGE_MASK) & 
~(PAGE_MASK))
-#define        trunc_page(x)   ((unsigned long)(x) & ~(PAGE_MASK))
 #define trunc_2mpage(x)        ((unsigned long)(x) & ~PDRMASK)
 #define round_2mpage(x)        ((((unsigned long)(x)) + PDRMASK) & ~PDRMASK)
 #define trunc_1gpage(x)        ((unsigned long)(x) & ~PDPMASK)
 
-#define        atop(x)         ((unsigned long)(x) >> PAGE_SHIFT)
-#define        ptoa(x)         ((unsigned long)(x) << PAGE_SHIFT)
-
 #define        amd64_btop(x)   ((unsigned long)(x) >> PAGE_SHIFT)
 #define        amd64_ptob(x)   ((unsigned long)(x) << PAGE_SHIFT)
 
-#define        pgtok(x)        ((unsigned long)(x) * (PAGE_SIZE / 1024))
-
 #define        INKERNEL(va) (((va) >= DMAP_MIN_ADDRESS && (va) < 
DMAP_MAX_ADDRESS) \
     || ((va) >= VM_MIN_KERNEL_ADDRESS && (va) < VM_MAX_KERNEL_ADDRESS))
 
diff --git a/sys/arm/arm/minidump_machdep.c b/sys/arm/arm/minidump_machdep.c
index 802b3184ed06..2e7fe6ebc51d 100644
--- a/sys/arm/arm/minidump_machdep.c
+++ b/sys/arm/arm/minidump_machdep.c
@@ -221,7 +221,8 @@ cpu_minidumpsys(struct dumperinfo *di, const struct 
minidumpstate *state)
        if (error != 0)
                goto fail;
 
-       printf("Physical memory: %u MB\n", ptoa((uintmax_t)physmem) / 1048576);
+       printf("Physical memory: %ju MB\n",
+           ptoa((uintmax_t)physmem) / 1048576);
        printf("Dumping %llu MB:", (long long)dumpsize >> 20);
 
        /* Dump my header */
diff --git a/sys/arm/include/param.h b/sys/arm/include/param.h
index 3e1503e17709..03131ebcb436 100644
--- a/sys/arm/include/param.h
+++ b/sys/arm/include/param.h
@@ -123,17 +123,10 @@
 /*
  * Mach derived conversion macros
  */
-#define        trunc_page(x)           ((x) & ~PAGE_MASK)
-#define        round_page(x)           (((x) + PAGE_MASK) & ~PAGE_MASK)
 #define        trunc_1mpage(x)         ((unsigned)(x) & ~PDRMASK)
 #define        round_1mpage(x)         ((((unsigned)(x)) + PDRMASK) & ~PDRMASK)
 
-#define        atop(x)                 ((unsigned)(x) >> PAGE_SHIFT)
-#define        ptoa(x)                 ((unsigned)(x) << PAGE_SHIFT)
-
 #define        arm32_btop(x)           ((unsigned)(x) >> PAGE_SHIFT)
 #define        arm32_ptob(x)           ((unsigned)(x) << PAGE_SHIFT)
 
-#define        pgtok(x)                ((x) * (PAGE_SIZE / 1024))
-
 #endif /* !_ARM_INCLUDE_PARAM_H_ */
diff --git a/sys/arm64/include/param.h b/sys/arm64/include/param.h
index 6eb58a69dba1..c3f6990db79b 100644
--- a/sys/arm64/include/param.h
+++ b/sys/arm64/include/param.h
@@ -119,17 +119,9 @@
 /*
  * Mach derived conversion macros
  */
-#define        round_page(x)           (((unsigned long)(x) + PAGE_MASK) & 
~PAGE_MASK)
-#define        trunc_page(x)           ((unsigned long)(x) & ~PAGE_MASK)
-
-#define        atop(x)                 ((unsigned long)(x) >> PAGE_SHIFT)
-#define        ptoa(x)                 ((unsigned long)(x) << PAGE_SHIFT)
-
 #define        arm64_btop(x)           ((unsigned long)(x) >> PAGE_SHIFT)
 #define        arm64_ptob(x)           ((unsigned long)(x) << PAGE_SHIFT)
 
-#define        pgtok(x)                ((unsigned long)(x) * (PAGE_SIZE / 
1024))
-
 #endif /* !_MACHINE_PARAM_H_ */
 
 #endif /* !__arm__ */
diff --git a/sys/i386/include/param.h b/sys/i386/include/param.h
index 2b9982324d19..79b6eee9db69 100644
--- a/sys/i386/include/param.h
+++ b/sys/i386/include/param.h
@@ -144,19 +144,12 @@
 /*
  * Mach derived conversion macros
  */
-#define trunc_page(x)          ((x) & ~PAGE_MASK)
-#define round_page(x)          (((x) + PAGE_MASK) & ~PAGE_MASK)
 #define trunc_4mpage(x)                ((x) & ~PDRMASK)
 #define round_4mpage(x)                ((((x)) + PDRMASK) & ~PDRMASK)
 
-#define atop(x)                        ((x) >> PAGE_SHIFT)
-#define ptoa(x)                        ((x) << PAGE_SHIFT)
-
 #define i386_btop(x)           ((x) >> PAGE_SHIFT)
 #define i386_ptob(x)           ((x) << PAGE_SHIFT)
 
-#define        pgtok(x)                ((x) * (PAGE_SIZE / 1024))
-
 #define INKERNEL(va)           (TRUE)
 
 #endif /* !_I386_INCLUDE_PARAM_H_ */
diff --git a/sys/powerpc/include/param.h b/sys/powerpc/include/param.h
index 56a7308a21b3..b40ada24ad11 100644
--- a/sys/powerpc/include/param.h
+++ b/sys/powerpc/include/param.h
@@ -141,20 +141,13 @@
 /*
  * Mach derived conversion macros
  */
-#define        trunc_page(x)           ((x) & ~(PAGE_MASK))
-#define        round_page(x)           (((x) + PAGE_MASK) & ~PAGE_MASK)
 #define        trunc_2mpage(x)         ((unsigned long)(x) & ~L3_PAGE_MASK)
 #define        round_2mpage(x)         ((((unsigned long)(x)) + L3_PAGE_MASK) 
& ~L3_PAGE_MASK)
 #define        trunc_1gpage(x)         ((unsigned long)(x) & ~L2_PAGE_MASK)
 
-#define        atop(x)                 ((x) >> PAGE_SHIFT)
-#define        ptoa(x)                 ((x) << PAGE_SHIFT)
-
 #define        powerpc_btop(x)         ((x) >> PAGE_SHIFT)
 #define        powerpc_ptob(x)         ((x) << PAGE_SHIFT)
 
-#define        pgtok(x)                ((x) * (PAGE_SIZE / 1024UL))
-
 #define btoc(x)                        
((vm_offset_t)(((x)+PAGE_MASK)>>PAGE_SHIFT))
 
 #endif /* !_POWERPC_INCLUDE_PARAM_H_ */
diff --git a/sys/riscv/include/param.h b/sys/riscv/include/param.h
index d06bd0663bac..ca9c91f3f981 100644
--- a/sys/riscv/include/param.h
+++ b/sys/riscv/include/param.h
@@ -93,15 +93,7 @@
 /*
  * Mach derived conversion macros
  */
-#define        round_page(x)           (((unsigned long)(x) + PAGE_MASK) & 
~PAGE_MASK)
-#define        trunc_page(x)           ((unsigned long)(x) & ~PAGE_MASK)
-
-#define        atop(x)                 ((unsigned long)(x) >> PAGE_SHIFT)
-#define        ptoa(x)                 ((unsigned long)(x) << PAGE_SHIFT)
-
 #define        riscv_btop(x)           ((unsigned long)(x) >> PAGE_SHIFT)
 #define        riscv_ptob(x)           ((unsigned long)(x) << PAGE_SHIFT)
 
-#define        pgtok(x)                ((unsigned long)(x) * (PAGE_SIZE / 
1024))
-
 #endif /* !_MACHINE_PARAM_H_ */
diff --git a/sys/sys/param.h b/sys/sys/param.h
index d2aad1ff98a1..6d611f251add 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -200,6 +200,17 @@
 #define        MJUM9BYTES      (9 * 1024)      /* jumbo cluster 9k */
 #define        MJUM16BYTES     (16 * 1024)     /* jumbo cluster 16k */
 
+/*
+ * Mach derived conversion macros
+ */
+#define        round_page(x)   roundup2(x, PAGE_SIZE)
+#define        trunc_page(x)   rounddown2(x, PAGE_SIZE)
+
+#define        atop(x)         ((x) >> PAGE_SHIFT)
+#define        ptoa(x)         ((x) << PAGE_SHIFT)
+
+#define        pgtok(x)        ((x) * (PAGE_SIZE / 1024))
+
 /*
  * Some macros for units conversion
  */
diff --git a/usr.bin/systat/sysput.c b/usr.bin/systat/sysput.c
index 4053037236f4..6ae0075bb54d 100644
--- a/usr.bin/systat/sysput.c
+++ b/usr.bin/systat/sysput.c
@@ -25,13 +25,12 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/sysctl.h>
 
 #include <err.h>
 #include <inttypes.h>
 #include <libutil.h>
-#include <machine/param.h>
 #include <string.h>
 
 #include "systat.h"

Reply via email to