git: 90d4da622592 - main - amd64: provide PHYS_IN_DMAP() and VIRT_IN_DMAP()

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Fri, 19 Nov 2021 19:06:04 UTC
The branch main has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=90d4da62259299a8d91fed1121be97ac5b7b6b3c

commit 90d4da62259299a8d91fed1121be97ac5b7b6b3c
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2021-11-17 15:29:02 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2021-11-19 19:05:52 +0000

    amd64: provide PHYS_IN_DMAP() and VIRT_IN_DMAP()
    
    It is useful for quickly checking an address against the DMAP region.
    These definitions exist already on arm64 and riscv.
    
    Reviewed by:    kib, markj
    MFC after:      3 days
    Sponsored by:   Juniper Networks, Inc.
    Sponsored by:   Klara, Inc.
    Differential Revision:  https://reviews.freebsd.org/D32962
---
 sys/amd64/include/vmparam.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/sys/amd64/include/vmparam.h b/sys/amd64/include/vmparam.h
index 6cb8b3f0071a..c841cc41f17b 100644
--- a/sys/amd64/include/vmparam.h
+++ b/sys/amd64/include/vmparam.h
@@ -239,16 +239,19 @@
  * because the result is not actually accessed until later, but the early
  * vt fb startup needs to be reworked.
  */
+#define	PHYS_IN_DMAP(pa)	(dmaplimit == 0 || (pa) < dmaplimit)
+#define	VIRT_IN_DMAP(va)	((va) >= DMAP_MIN_ADDRESS &&		\
+    (va) < (DMAP_MIN_ADDRESS + dmaplimit))
+
 #define	PMAP_HAS_DMAP	1
 #define	PHYS_TO_DMAP(x)	({						\
-	KASSERT(dmaplimit == 0 || (x) < dmaplimit,			\
+	KASSERT(PHYS_IN_DMAP(x),					\
 	    ("physical address %#jx not covered by the DMAP",		\
 	    (uintmax_t)x));						\
 	(x) | DMAP_MIN_ADDRESS; })
 
 #define	DMAP_TO_PHYS(x)	({						\
-	KASSERT((x) < (DMAP_MIN_ADDRESS + dmaplimit) &&			\
-	    (x) >= DMAP_MIN_ADDRESS,					\
+	KASSERT(VIRT_IN_DMAP(x),					\
 	    ("virtual address %#jx not covered by the DMAP",		\
 	    (uintmax_t)x));						\
 	(x) & ~DMAP_MIN_ADDRESS; })