1bf21cd93STycho Nightingale /*
2bf21cd93STycho Nightingale  * This file and its contents are supplied under the terms of the
3bf21cd93STycho Nightingale  * Common Development and Distribution License ("CDDL"), version 1.0.
4bf21cd93STycho Nightingale  * You may only use this file in accordance with the terms of version
5bf21cd93STycho Nightingale  * 1.0 of the CDDL.
6bf21cd93STycho Nightingale  *
7bf21cd93STycho Nightingale  * A full copy of the text of the CDDL should have accompanied this
8bf21cd93STycho Nightingale  * source.  A copy of the CDDL is also available via the Internet at
9bf21cd93STycho Nightingale  * http://www.illumos.org/license/CDDL.
10bf21cd93STycho Nightingale  */
11bf21cd93STycho Nightingale 
12bf21cd93STycho Nightingale /*
13bf21cd93STycho Nightingale  * Copyright 2013 Pluribus Networks Inc.
144c87aefeSPatrick Mooney  * Copyright 2019 Joyent, Inc.
15bf21cd93STycho Nightingale  */
16bf21cd93STycho Nightingale 
17bf21cd93STycho Nightingale #ifndef _COMPAT_FREEBSD_AMD64_MACHINE_VMPARAM_H_
18bf21cd93STycho Nightingale #define	_COMPAT_FREEBSD_AMD64_MACHINE_VMPARAM_H_
19bf21cd93STycho Nightingale 
204c87aefeSPatrick Mooney extern caddr_t kpm_vbase;
214c87aefeSPatrick Mooney extern size_t kpm_size;
224c87aefeSPatrick Mooney 
234c87aefeSPatrick Mooney static inline uintptr_t
phys_to_dmap(uintptr_t pa)244c87aefeSPatrick Mooney phys_to_dmap(uintptr_t pa)
254c87aefeSPatrick Mooney {
264c87aefeSPatrick Mooney 	ASSERT3U(pa, <, kpm_size);
274c87aefeSPatrick Mooney 	return ((uintptr_t)kpm_vbase + pa);
284c87aefeSPatrick Mooney }
294c87aefeSPatrick Mooney 
304c87aefeSPatrick Mooney static inline uintptr_t
dmap_to_phys(uintptr_t kva)314c87aefeSPatrick Mooney dmap_to_phys(uintptr_t kva)
324c87aefeSPatrick Mooney {
334c87aefeSPatrick Mooney 	const uintptr_t base = (uintptr_t)kpm_vbase;
344c87aefeSPatrick Mooney 
354c87aefeSPatrick Mooney 	ASSERT3U(kva, >=, base);
364c87aefeSPatrick Mooney 	ASSERT3U(kva, <, base + kpm_size);
374c87aefeSPatrick Mooney 
384c87aefeSPatrick Mooney 	return (kva - base);
394c87aefeSPatrick Mooney }
404c87aefeSPatrick Mooney 
414c87aefeSPatrick Mooney #define	PHYS_TO_DMAP(x)	phys_to_dmap(x)
424c87aefeSPatrick Mooney #define	DMAP_TO_PHYS(x)	dmap_to_phys(x)
434c87aefeSPatrick Mooney 
444c87aefeSPatrick Mooney 
45bf21cd93STycho Nightingale #endif	/* _COMPAT_FREEBSD_AMD64_MACHINE_VMPARAM_H_ */
46