These are the compatibility headers for building bhyve on illumos. They are comprised of the shims and glue needed to use native functionality as the backing for FreeBSD interfaces. It often means heavy use of #include_next, #define renames, and forward definitions to some glue functions. For headers which would otherwise be copied verbatim from FreeBSD, the usr/src/contrib/bhyve area is the appropriate home. This allows us to carry only the bare minimum in the 'compat' headers while making updates for the 'contrib' headers easy (simply copy over the new version). /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_AMD64_MACHINE_ASMACROS_H_ #define _COMPAT_FREEBSD_AMD64_MACHINE_ASMACROS_H_ #define ENTRY(x) \ .text; .p2align 4,0x90; \ .globl x; \ .type x, @function; \ x: #define END(x) \ .size x, [.-x] #define ALIGN_TEXT \ .p2align 4,0x90; /* 16-byte alignment, nop filled */ #endif /* _COMPAT_FREEBSD_AMD64_MACHINE_ASMACROS_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2014 Pluribus Networks Inc. * Copyright 2019 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_AMD64_MACHINE_ATOMIC_H_ #define _COMPAT_FREEBSD_AMD64_MACHINE_ATOMIC_H_ static __inline u_int atomic_load_acq_short(volatile u_short *p) { u_short res; res = *p; __asm volatile("" : : : "memory"); return (res); } static __inline u_int atomic_load_acq_int(volatile u_int *p) { u_int res; res = *p; __asm volatile("" : : : "memory"); return (res); } static __inline u_long atomic_load_acq_long(volatile u_long *p) { u_long res; res = *p; __asm volatile("" : : : "memory"); return (res); } static __inline void atomic_store_rel_int(volatile u_int *p, u_int v) { __asm volatile("" : : : "memory"); *p = v; } static __inline void atomic_store_rel_long(volatile u_long *p, u_long v) { __asm volatile("" : : : "memory"); *p = v; } /* * Atomic compare and set. * * if (*dst == expect) *dst = src (all 32 bit words) * * Returns 0 on failure, non-zero on success */ static __inline int atomic_cmpset_int(volatile u_int *dst, u_int expect, u_int src) { u_char res; __asm __volatile( " lock ; " " cmpxchgl %3,%1 ; " " sete %0 ; " "# atomic_cmpset_int" : "=q" (res), /* 0 */ "+m" (*dst), /* 1 */ "+a" (expect) /* 2 */ : "r" (src) /* 3 */ : "memory", "cc"); return (res); } static __inline int atomic_cmpset_long(volatile u_long *dst, u_long expect, u_long src) { u_char res; __asm __volatile( " lock ; " " cmpxchgq %3,%1 ; " " sete %0 ; " "# atomic_cmpset_long" : "=q" (res), /* 0 */ "+m" (*dst), /* 1 */ "+a" (expect) /* 2 */ : "r" (src) /* 3 */ : "memory", "cc"); return (res); } static __inline int atomic_testandset_int(volatile u_int *p, u_int v) { u_char res; __asm __volatile( " lock ; " " btsl %2,%1 ; " " setc %0 ; " "# atomic_testandset_int" : "=q" (res), /* 0 */ "+m" (*p) /* 1 */ : "Ir" (v & 0x1f) /* 2 */ : "cc"); return (res); } /* * Atomically add the value of v to the integer pointed to by p and return * the previous value of *p. */ static __inline u_int atomic_fetchadd_int(volatile u_int *p, u_int v) { __asm __volatile( " lock ; " " xaddl %0, %1 ; " "# atomic_fetchadd_int" : "+r" (v), /* 0 (result) */ "=m" (*p) /* 1 */ : "m" (*p) /* 2 */ : "cc"); return (v); } static __inline void atomic_set_int(volatile u_int *p, u_int v) { __asm volatile( "lock ; " "orl %1,%0" : "=m" (*p) : "ir" (v), "m" (*p) : "cc"); } static __inline void atomic_clear_int(volatile u_int *p, u_int v) { __asm volatile( "lock ; " "andl %1,%0" : "=m" (*p) : "ir" (~v), "m" (*p) : "cc"); } static __inline void atomic_subtract_int(volatile u_int *p, u_int v) { __asm volatile( "lock ; " "subl %1,%0" : "=m" (*p) : "ir" (v), "m" (*p) : "cc"); } static __inline void atomic_set_long(volatile u_long *p, u_long v) { __asm volatile( "lock ; " "orq %1,%0" : "+m" (*p) : "ir" (v) : "cc"); } static __inline void atomic_clear_long(volatile u_long *p, u_long v) { __asm volatile("lock ; " "andq %1,%0" : "+m" (*p) : "ir" (~v) : "cc"); } static __inline u_int atomic_swap_int(volatile u_int *p, u_int v) { __asm __volatile( " xchgl %1,%0 ; " "# atomic_swap_int" : "+r" (v), /* 0 */ "+m" (*p)); /* 1 */ return (v); } static __inline u_long atomic_swap_long(volatile u_long *p, u_long v) { __asm __volatile( " xchgq %1,%0 ; " "# atomic_swap_long" : "+r" (v), /* 0 */ "+m" (*p)); /* 1 */ return (v); } #define atomic_store_short(p, v) \ (*(volatile u_short *)(p) = (u_short)(v)) #define atomic_store_int(p, v) \ (*(volatile u_int *)(p) = (u_int)(v)) #define atomic_load_32(p) (*(volatile uint32_t *)(p)) #define atomic_load_64(p) (*(volatile uint64_t *)(p)) #define atomic_readandclear_int(p) atomic_swap_int(p, 0) #define atomic_readandclear_long(p) atomic_swap_long(p, 0) /* Operations on 32-bit double words. */ #define atomic_load_acq_32 atomic_load_acq_int #define atomic_store_rel_32 atomic_store_rel_int #define atomic_cmpset_32 atomic_cmpset_int /* Operations on 64-bit quad words. */ #define atomic_cmpset_64 atomic_cmpset_long #define atomic_readandclear_64 atomic_readandclear_long /* Operations on pointers. */ #define atomic_cmpset_ptr atomic_cmpset_long /* Needed for the membar functions */ #include_next static __inline void atomic_thread_fence_rel(void) { /* Equivalent to their __compiler_membar() */ __asm __volatile(" " : : : "memory"); } static __inline void atomic_thread_fence_seq_cst(void) { /* Equivalent to their !KERNEL storeload_barrer() */ __asm __volatile("lock; addl $0,-8(%%rsp)" : : : "memory", "cc"); } #define mb() membar_enter() #define rmb() membar_consumer() #define wmb() membar_producer() #endif /* _COMPAT_FREEBSD_AMD64_MACHINE_ATOMIC_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_AMD64_MACHINE_CLOCK_H_ #define _COMPAT_FREEBSD_AMD64_MACHINE_CLOCK_H_ extern uint64_t cpu_freq_hz; #define tsc_freq cpu_freq_hz #endif /* _COMPAT_FREEBSD_AMD64_MACHINE_CLOCK_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2017 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_AMD64_MACHINE_CPU_H #define _COMPAT_FREEBSD_AMD64_MACHINE_CPU_H #include #define cpu_spinwait() SMT_PAUSE() #endif /* _COMPAT_FREEBSD_AMD64_MACHINE_CPU_H */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2014 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_AMD64_MACHINE_CPUFUNC_H_ #define _COMPAT_FREEBSD_AMD64_MACHINE_CPUFUNC_H_ #include static __inline u_long bsfq(u_long mask) { u_long result; __asm __volatile("bsfq %1,%0" : "=r" (result) : "rm" (mask)); return (result); } static __inline u_int bsrl(u_int mask) { u_int result; __asm __volatile("bsrl %1,%0" : "=r" (result) : "rm" (mask)); return (result); } static __inline u_long bsrq(u_long mask) { u_long result; __asm __volatile("bsrq %1,%0" : "=r" (result) : "rm" (mask)); return (result); } static __inline void clts(void) { __asm __volatile("clts"); } static __inline void do_cpuid(u_int ax, u_int *p) { __asm __volatile("cpuid" : "=a" (p[0]), "=b" (p[1]), "=c" (p[2]), "=d" (p[3]) : "0" (ax)); } static __inline void cpuid_count(u_int ax, u_int cx, u_int *p) { __asm __volatile("cpuid" : "=a" (p[0]), "=b" (p[1]), "=c" (p[2]), "=d" (p[3]) : "0" (ax), "c" (cx)); } static __inline void disable_intr(void) { __asm __volatile("cli"); } static __inline void enable_intr(void) { __asm __volatile("sti"); } static __inline int ffsl(long mask) { return (mask == 0 ? mask : (int)bsfq((u_long)mask) + 1); } static __inline int fls(int mask) { return (mask == 0 ? mask : (int)bsrl((u_int)mask) + 1); } static __inline int flsl(long mask) { return (mask == 0 ? mask : (int)bsrq((u_long)mask) + 1); } static __inline int flsll(long long mask) { return (flsl((long)mask)); } static __inline u_long read_rflags(void) { u_long rf; __asm __volatile("pushfq; popq %0" : "=r" (rf)); return (rf); } /* Equivalent to the FreeBSD rdtsc(), but with any necessary per-cpu offset */ uint64_t rdtsc_offset(void); static __inline uint64_t rdmsr(u_int msr) { uint32_t low, high; __asm __volatile("rdmsr" : "=a" (low), "=d" (high) : "c" (msr)); return (low | ((uint64_t)high << 32)); } static __inline void wrmsr(u_int msr, uint64_t newval) { uint32_t low, high; low = newval; high = newval >> 32; __asm __volatile("wrmsr" : : "a" (low), "d" (high), "c" (msr)); } static __inline void load_cr0(u_long data) { __asm __volatile("movq %0,%%cr0" : : "r" (data)); } static __inline u_long rcr0(void) { u_long data; __asm __volatile("movq %%cr0,%0" : "=r" (data)); return (data); } static __inline u_long rcr3(void) { u_long data; __asm __volatile("movq %%cr3,%0" : "=r" (data)); return (data); } static __inline void load_cr4(u_long data) { __asm __volatile("movq %0,%%cr4" : : "r" (data)); } static __inline u_long rcr4(void) { u_long data; __asm __volatile("movq %%cr4,%0" : "=r" (data)); return (data); } static __inline u_long rxcr(u_int reg) { u_int low, high; __asm __volatile("xgetbv" : "=a" (low), "=d" (high) : "c" (reg)); return (low | ((uint64_t)high << 32)); } static __inline void load_xcr(u_int reg, u_long val) { u_int low, high; low = val; high = val >> 32; __asm __volatile("xsetbv" : : "c" (reg), "a" (low), "d" (high)); } static __inline void write_rflags(u_long rf) { __asm __volatile("pushq %0; popfq" : : "r" (rf)); } static __inline uint64_t rdr0(void) { uint64_t data; __asm __volatile("movq %%dr0,%0" : "=r" (data)); return (data); } static __inline void load_dr0(uint64_t dr0) { __asm __volatile("movq %0,%%dr0" : : "r" (dr0)); } static __inline uint64_t rdr1(void) { uint64_t data; __asm __volatile("movq %%dr1,%0" : "=r" (data)); return (data); } static __inline void load_dr1(uint64_t dr1) { __asm __volatile("movq %0,%%dr1" : : "r" (dr1)); } static __inline uint64_t rdr2(void) { uint64_t data; __asm __volatile("movq %%dr2,%0" : "=r" (data)); return (data); } static __inline void load_dr2(uint64_t dr2) { __asm __volatile("movq %0,%%dr2" : : "r" (dr2)); } static __inline uint64_t rdr3(void) { uint64_t data; __asm __volatile("movq %%dr3,%0" : "=r" (data)); return (data); } static __inline void load_dr3(uint64_t dr3) { __asm __volatile("movq %0,%%dr3" : : "r" (dr3)); } static __inline uint64_t rdr6(void) { uint64_t data; __asm __volatile("movq %%dr6,%0" : "=r" (data)); return (data); } static __inline void load_dr6(uint64_t dr6) { __asm __volatile("movq %0,%%dr6" : : "r" (dr6)); } static __inline uint64_t rdr7(void) { uint64_t data; __asm __volatile("movq %%dr7,%0" : "=r" (data)); return (data); } static __inline void load_dr7(uint64_t dr7) { __asm __volatile("movq %0,%%dr7" : : "r" (dr7)); } #ifdef _KERNEL /* * Including the native sys/segments.h in userspace seriously conflicts with * the FreeBSD compat/contrib headers. */ #include static __inline void lldt(u_short sel) { wr_ldtr(sel); } static __inline u_short sldt() { return (rd_ldtr()); } #endif /* _KERNEL */ #endif /* _COMPAT_FREEBSD_AMD64_MACHINE_CPUFUNC_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2017 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_AMD64_MACHINE_IODEV_H #define _COMPAT_FREEBSD_AMD64_MACHINE_IODEV_H #endif /* _COMPAT_FREEBSD_AMD64_MACHINE_IODEV_H */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_AMD64_MACHINE_MD_VAR_H_ #define _COMPAT_FREEBSD_AMD64_MACHINE_MD_VAR_H_ extern u_int cpu_high; /* Highest arg to CPUID */ extern u_int cpu_exthigh; /* Highest arg to extended CPUID */ extern u_int cpu_id; /* Stepping ID */ extern char cpu_vendor[]; /* CPU Origin code */ #include #endif /* _COMPAT_FREEBSD_AMD64_MACHINE_MD_VAR_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_AMD64_MACHINE_PARAM_H_ #define _COMPAT_FREEBSD_AMD64_MACHINE_PARAM_H_ #ifdef _KERNEL #define MAXCPU NCPU #endif /* _KERNEL */ #define PAGE_SHIFT 12 /* LOG2(PAGE_SIZE) */ #define PAGE_SIZE (1< #endif /* _COMPAT_FREEBSD_AMD64_MACHINE_SEGMENTS_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2019 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_AMD64_MACHINE_SPECIALREG_H_ #define _COMPAT_FREEBSD_AMD64_MACHINE_SPECIALREG_H_ #ifdef _SYS_X86_ARCHEXT_H /* Our x86_archext conflicts with BSD header for the XFEATURE_ defines */ #undef XFEATURE_AVX #undef XFEATURE_MPX #undef XFEATURE_AVX512 #endif #ifdef _SYS_CONTROLREGS_H /* Our CR4 defines conflict with BSD header */ #undef CR4_VME #undef CR4_PVI #undef CR4_TSD #undef CR4_DE #undef CR4_PSE #undef CR4_PAE #undef CR4_MCE #undef CR4_PGE #undef CR4_PCE #undef CR4_VMXE #undef CR4_SMEP #undef CR4_SMAP #undef CR4_PKE #undef CR4_FSGSBASE #undef CR4_PCIDE #undef CR4_UMIP #undef CR4_LA57 #endif /* _SYS_CONTROLREGS_H */ #ifdef _SYS_X86_ARCHEXT_H /* Our IA32 speculation-related defines conflict with BSD header */ #undef IA32_ARCH_CAP_RDCL_NO #undef IA32_ARCH_CAP_IBRS_ALL #undef IA32_ARCH_CAP_RSBA #undef IA32_ARCH_CAP_SKIP_L1DFL_VMENTRY #undef IA32_ARCH_CAP_SSB_NO #undef IA32_ARCH_CAP_MDS_NO #undef IA32_ARCH_CAP_IF_PSCHANGE_MC_NO #undef IA32_ARCH_CAP_TSX_CTRL #undef IA32_ARCH_CAP_TAA_NO #undef IA32_FLUSH_CMD_L1D #undef IA32_SPEC_CTRL_IBRS #undef IA32_SPEC_CTRL_STIBP #undef IA32_SPEC_CTRL_SSBD #undef IA32_TSX_CTRL_RTM_DISABLE #undef IA32_TSX_CTRL_TSX_CPUID_CLEAR #undef MSR_IA32_SPEC_CTRL #undef MSR_IA32_PRED_CMD #endif /* _SYS_X86_ARCHEXT_H */ #include #endif /* _COMPAT_FREEBSD_AMD64_MACHINE_SPECIALREG_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. * Copyright 2017 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_AMD64_MACHINE_VMM_H_ #define _COMPAT_FREEBSD_AMD64_MACHINE_VMM_H_ #include #ifdef _KERNEL #include #include #endif #endif /* _COMPAT_FREEBSD_AMD64_MACHINE_VMM_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_AMD64_MACHINE_VMM_DEV_H_ #define _COMPAT_FREEBSD_AMD64_MACHINE_VMM_DEV_H_ #include #endif /* _COMPAT_FREEBSD_AMD64_MACHINE_VMM_DEV_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_AMD64_MACHINE_VMM_INSTRUCTION_EMUL_H_ #define _COMPAT_FREEBSD_AMD64_MACHINE_VMM_INSTRUCTION_EMUL_H_ #include #endif /* _COMPAT_FREEBSD_AMD64_MACHINE_VMM_INSTRUCTION_EMUL_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. * Copyright 2019 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_AMD64_MACHINE_VMPARAM_H_ #define _COMPAT_FREEBSD_AMD64_MACHINE_VMPARAM_H_ extern caddr_t kpm_vbase; extern size_t kpm_size; static inline uintptr_t phys_to_dmap(uintptr_t pa) { ASSERT3U(pa, <, kpm_size); return ((uintptr_t)kpm_vbase + pa); } static inline uintptr_t dmap_to_phys(uintptr_t kva) { const uintptr_t base = (uintptr_t)kpm_vbase; ASSERT3U(kva, >=, base); ASSERT3U(kva, <, base + kpm_size); return (kva - base); } #define PHYS_TO_DMAP(x) phys_to_dmap(x) #define DMAP_TO_PHYS(x) dmap_to_phys(x) #endif /* _COMPAT_FREEBSD_AMD64_MACHINE_VMPARAM_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2017 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_CONTRIB_DEV_ACPICA_INCLUDE_ACPI_H #define _COMPAT_FREEBSD_CONTRIB_DEV_ACPICA_INCLUDE_ACPI_H #include #endif /* _COMPAT_FREEBSD_CONTRIB_DEV_ACPICA_INCLUDE_ACPI_H */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2018 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_DEV_PCI_PCIVAR_H #define _COMPAT_FREEBSD_DEV_PCI_PCIVAR_H #include #include #include #include #include #include static inline pcie_req_id_t pci_get_bdf(device_t dev) { pcie_req_id_t bdf; VERIFY(pcie_get_bdf_from_dip(dev, &bdf) == DDI_SUCCESS); return (bdf); } #define pci_get_rid(dev) (pci_get_bdf(dev)) #endif /* _COMPAT_FREEBSD_DEV_PCI_PCIVAR_H */ /*- * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2013 Chris Torek * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* This file is dual-licensed; see usr/src/contrib/bhyve/LICENSE */ /* * Copyright 2025 Oxide Computer Company */ #ifndef _BHYVE_COMPAT_VIRTIO_H_ #define _BHYVE_COMPAT_VIRTIO_H_ #include #define VIRTIO_PCI_DEVICEID_MODERN_MIN 0x1040 #define VRING_DESC_F_NEXT (1 << 0) #define VRING_DESC_F_WRITE (1 << 1) #define VRING_DESC_F_INDIRECT (1 << 2) struct vring_desc { uint64_t addr; /* guest physical address */ uint32_t len; /* length of scatter/gather seg */ uint16_t flags; /* VRING_F_DESC_* */ uint16_t next; /* next desc if F_NEXT */ } __packed; struct vring_used_elem { uint32_t id; /* head of used descriptor chain */ uint32_t len; /* length written-to */ } __packed; #define VRING_AVAIL_F_NO_INTERRUPT 1 struct vring_avail { uint16_t flags; /* VRING_AVAIL_F_* */ uint16_t idx; /* counts to 65535, then cycles */ uint16_t ring[]; /* size N, reported in QNUM value */ /* uint16_t used_event; -- after N ring entries */ } __packed; #define VRING_USED_F_NO_NOTIFY 1 struct vring_used { uint16_t flags; /* VRING_USED_F_* */ uint16_t idx; /* counts to 65535, then cycles */ struct vring_used_elem ring[]; /* size N */ /* uint16_t avail_event; -- after N ring entries */ } __packed; /* * Virtio device types */ #define VIRTIO_ID_NETWORK 1 #define VIRTIO_ID_BLOCK 2 #define VIRTIO_ID_CONSOLE 3 #define VIRTIO_ID_ENTROPY 4 #define VIRTIO_ID_BALLOON 5 #define VIRTIO_ID_IOMEMORY 6 #define VIRTIO_ID_RPMSG 7 #define VIRTIO_ID_SCSI 8 #define VIRTIO_ID_9P 9 /* experimental IDs start at 65535 and work down */ /* * PCI config space constants. * * If MSI-X is enabled, the ISR register is generally not used, * and the configuration vector and queue vector appear at offsets * 20 and 22 with the remaining configuration registers at 24. * If MSI-X is not enabled, those two registers disappear and * the remaining configuration registers start at offset 20. */ #define VIRTIO_PCI_HOST_FEATURES 0 #define VIRTIO_PCI_GUEST_FEATURES 4 #define VIRTIO_PCI_QUEUE_PFN 8 #define VIRTIO_PCI_QUEUE_NUM 12 #define VIRTIO_PCI_QUEUE_SEL 14 #define VIRTIO_PCI_QUEUE_NOTIFY 16 #define VIRTIO_PCI_STATUS 18 #define VIRTIO_PCI_ISR 19 #define VIRTIO_MSI_CONFIG_VECTOR 20 #define VIRTIO_MSI_QUEUE_VECTOR 22 #define VIRTIO_PCI_CONFIG_OFF(msix_enabled) ((msix_enabled) ? 24 : 20) /* * Bits in VTCFG_R_STATUS. Guests need not actually set any of these, * but a guest writing 0 to this register means "please reset". */ #define VTCFG_STATUS_ACK 0x01 /* guest OS has acknowledged dev */ #define VTCFG_STATUS_DRIVER 0x02 /* guest OS driver is loaded */ #define VTCFG_STATUS_DRIVER_OK 0x04 /* guest OS driver ready */ #define VTCFG_STATUS_FEAT_OK 0x08 /* driver finished cfg features */ #define VTCFG_STATUS_NEEDS_RST 0x40 /* device needs reset */ #define VTCFG_STATUS_FAILED 0x80 /* guest has given up on this dev */ #define VIRTIO_CONFIG_STATUS_DRIVER_OK VTCFG_STATUS_DRIVER_OK #define VIRTIO_CONFIG_S_FEATURES_OK VTCFG_STATUS_FEAT_OK /* * Bits in VTCFG_R_ISR. These apply only if not using MSI-X. */ /* The bit of the ISR which indicates a device has an interrupt. */ #define VIRTIO_PCI_ISR_INTR 0x01 /* The bit of the ISR which indicates a device configuration change. */ #define VIRTIO_PCI_ISR_CONFIG 0x02 #define VIRTIO_MSI_NO_VECTOR 0xFFFF /* * Feature flags. * Note: bits 0 through 23 are reserved to each device type. */ #define VIRTIO_F_NOTIFY_ON_EMPTY (1ULL << 24) #define VIRTIO_F_ANY_LAYOUT (1ULL << 27) #define VIRTIO_RING_F_INDIRECT_DESC (1ULL << 28) #define VIRTIO_RING_F_EVENT_IDX (1ULL << 29) #define VIRTIO_F_BAD_FEATURE (1ULL << 30) #define VIRTIO_F_VERSION_1 (1ULL << 32) static inline int vring_size(unsigned int num, unsigned long align) { int size; size = num * sizeof(struct vring_desc); size += sizeof(struct vring_avail) + (num * sizeof(uint16_t)) + sizeof(uint16_t); size = (size + align - 1) & ~(align - 1); size += sizeof(struct vring_used) + (num * sizeof(struct vring_used_elem)) + sizeof(uint16_t); return (size); } #define VIRTIO_PCI_CAP_COMMON_CFG 1 #define VIRTIO_PCI_CAP_NOTIFY_CFG 2 #define VIRTIO_PCI_CAP_ISR_CFG 3 #define VIRTIO_PCI_CAP_DEVICE_CFG 4 #define VIRTIO_PCI_CAP_PCI_CFG 5 #define VIRTIO_PCI_CAP_MAX VIRTIO_PCI_CAP_PCI_CFG /* * Alignment requirements for the BAR regions pointed to by each capability. * Note that some have multiple alignment requirements based on negotiated * features and for those we choose the larger value. There are no alignment * requirements for VIRTIO_PCI_CAP_PCI_CFG as it does not point to a fixed BAR * area. */ #define VIRTIO_PCI_CAP_COMMON_CFG_ALIGN 4 #define VIRTIO_PCI_CAP_NOTIFY_CFG_ALIGN 4 #define VIRTIO_PCI_CAP_ISR_CFG_ALIGN 1 #define VIRTIO_PCI_CAP_DEVICE_CFG_ALIGN 4 /* This is the PCI capability header: */ typedef struct virtio_pci_cap { uint8_t cap_vndr; uint8_t cap_next; uint8_t cap_len; uint8_t cfg_type; uint8_t bar; uint8_t id; uint8_t padding[2]; uint32_t offset; uint32_t length; } virtio_pci_cap_t; typedef struct virtio_pci_notify_cap { struct virtio_pci_cap cap; uint32_t notify_off_multiplier; } virtio_pci_notify_cap_t; /* Fields in VIRTIO_PCI_CAP_COMMON_CFG: */ typedef struct virtio_pci_common_cfg { /* About the whole device. */ uint32_t device_feature_select; /* read-write */ uint32_t device_feature; /* read-only */ uint32_t driver_feature_select; /* read-write */ uint32_t driver_feature; /* read-write */ uint16_t msix_config; /* read-write */ uint16_t num_queues; /* read-only */ uint8_t device_status; /* read-write */ uint8_t config_generation; /* read-only */ /* About a specific virtqueue. */ uint16_t queue_select; /* read-write */ uint16_t queue_size; /* read-write */ uint16_t queue_msix_vector; /* read-write */ uint16_t queue_enable; /* read-write */ uint16_t queue_notify_off; /* read-only */ uint32_t queue_desc_lo; /* read-write */ uint32_t queue_desc_hi; /* read-write */ uint32_t queue_avail_lo; /* read-write */ uint32_t queue_avail_hi; /* read-write */ uint32_t queue_used_lo; /* read-write */ uint32_t queue_used_hi; /* read-write */ } virtio_pci_common_cfg_t; /* Fields in VIRTIO_PCI_CAP_PCI_CFG: */ typedef struct virtio_pci_cfg_cap { struct virtio_pci_cap cap; uint8_t pci_cfg_data[4]; /* Data for BAR access. */ } virtio_pci_cfg_cap_t; /* Macro versions of offsets */ #define __VPCO(x) offsetof(virtio_pci_cap_t, x) #define VIRTIO_PCI_CAP_VNDR __VPCO(cap_vndr) #define VIRTIO_PCI_CAP_NEXT __VPCO(cap_next) #define VIRTIO_PCI_CAP_LEN __VPCO(cap_len) #define VIRTIO_PCI_CAP_CFG_TYPE __VPCO(cfg_type) #define VIRTIO_PCI_CAP_BAR __VPCO(bar) #define VIRTIO_PCI_CAP_ID __VPCO(id) #define VIRTIO_PCI_CAP_OFFSET __VPCO(offset) #define VIRTIO_PCI_CAP_LENGTH __VPCO(length) #define V__VPNCO(x) offsetof(virtio_pci_notify_cap_t, x) #define VIRTIO_PCI_NOTIFY_CAP_MULT V__VPNCO(notify_off_multiplier) #define __VPCCO(x) offsetof(virtio_pci_common_cfg_t, x) #define VIRTIO_PCI_COMMON_DFSELECT __VPCCO(device_feature_select) #define VIRTIO_PCI_COMMON_DF __VPCCO(device_feature) #define VIRTIO_PCI_COMMON_GFSELECT __VPCCO(driver_feature_select) #define VIRTIO_PCI_COMMON_GF __VPCCO(driver_feature) #define VIRTIO_PCI_COMMON_MSIX __VPCCO(msix_config) #define VIRTIO_PCI_COMMON_NUMQ __VPCCO(num_queues) #define VIRTIO_PCI_COMMON_STATUS __VPCCO(device_status) #define VIRTIO_PCI_COMMON_CFGGENERATION __VPCCO(config_generation) #define VIRTIO_PCI_COMMON_Q_SELECT __VPCCO(queue_select) #define VIRTIO_PCI_COMMON_Q_SIZE __VPCCO(queue_size) #define VIRTIO_PCI_COMMON_Q_MSIX __VPCCO(queue_msix_vector) #define VIRTIO_PCI_COMMON_Q_ENABLE __VPCCO(queue_enable) #define VIRTIO_PCI_COMMON_Q_NOFF __VPCCO(queue_notify_off) #define VIRTIO_PCI_COMMON_Q_DESCLO __VPCCO(queue_desc_lo) #define VIRTIO_PCI_COMMON_Q_DESCHI __VPCCO(queue_desc_hi) #define VIRTIO_PCI_COMMON_Q_AVAILLO __VPCCO(queue_avail_lo) #define VIRTIO_PCI_COMMON_Q_AVAILHI __VPCCO(queue_avail_hi) #define VIRTIO_PCI_COMMON_Q_USEDLO __VPCCO(queue_used_lo) #define VIRTIO_PCI_COMMON_Q_USEDHI __VPCCO(queue_used_hi) #endif /* _BHYVE_COMPAT_VIRTIO_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_LIBUTIL_H_ #define _COMPAT_FREEBSD_LIBUTIL_H_ int expand_number(const char *_buf, uint64_t *_num); int humanize_number(char *_buf, size_t _len, int64_t _number, const char *_suffix, int _scale, int _flags); /* Values for humanize_number(3)'s flags parameter. */ #define HN_DECIMAL 0x01 #define HN_NOSPACE 0x02 #define HN_B 0x04 #define HN_DIVISOR_1000 0x08 #define HN_IEC_PREFIXES 0x10 /* Values for humanize_number(3)'s scale parameter. */ #define HN_GETSCALE 0x10 #define HN_AUTOSCALE 0x20 #endif /* _COMPAT_FREEBSD_LIBUTIL_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. * Copyright 2017 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_SYS_NET_ETHERNET_H_ #define _COMPAT_FREEBSD_SYS_NET_ETHERNET_H_ #define ether_addr_octet octet #include /* * Some basic Ethernet constants. */ #define ETHER_ADDR_LEN 6 /* length of an Ethernet address */ #define ETHER_CRC_LEN 4 /* length of the Ethernet CRC */ #define ETHER_MIN_LEN 64 /* minimum frame len, including CRC */ #define ETHER_VLAN_ENCAP_LEN 4 /* len of 802.1Q VLAN encapsulation */ #define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */ #endif /* _COMPAT_FREEBSD_SYS_NET_ETHERNET_H_ */ /* - * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2013 The FreeBSD Foundation * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * Author: George V. Neville-Neil * */ /* Organizationally Unique Identifier assigned by IEEE 14 Nov 2013 */ #define OUI_FREEBSD_BASE 0x589cfc000000 #define OUI_FREEBSD(nic) (OUI_FREEBSD_BASE | (nic)) /* * OUIs are most often used to uniquely identify network interfaces * and occupy the first 3 bytes of both destination and source MAC * addresses. The following allocations exist so that various * software systems associated with FreeBSD can have unique IDs in the * absence of hardware. The use of OUIs for this purpose is not fully * fleshed out but is now in common use in virtualization technology. * * Allocations from this range are expected to be made using COMMON * SENSE by developers. Do NOT take a large range just because * they're currently wide open. Take the smallest useful range for * your system. We have (2^24 - 2) available addresses (see Reserved * Values below) but that is far from infinite. * * In the event of a conflict arbitration of allocation in this file * is subject to core@ approval. * * Applications are differentiated based on the high order bit(s) of * the remaining three bytes. Our first allocation has all 0s, the * next allocation has the highest bit set. Allocating in this way * gives us 254 allocations of 64K addresses. Address blocks can be * concatenated if necessary. * * Reserved Values: 0x000000 and 0xffffff are reserved and MUST NOT BE * allocated for any reason. */ /* Allocate 20 bits to bhyve */ #define OUI_FREEBSD_BHYVE_LOW OUI_FREEBSD(0x000001) #define OUI_FREEBSD_BHYVE_HIGH OUI_FREEBSD(0x0fffff) /* * Allocate 16 bits for a pool to give to various interfaces that need a * generated address, but don't quite need to slice off a whole section of * the OUI (e.g. cloned interfaces, one-off NICs of various vendors). * * ether_gen_addr should be used to generate an address from this pool. */ #define OUI_FREEBSD_GENERATED_MASK 0x10ffff #define OUI_FREEBSD_GENERATED_LOW OUI_FREEBSD(0x100000) #define OUI_FREEBSD_GENERATED_HIGH OUI_FREEBSD(OUI_FREEBSD_GENERATED_MASK) /* Allocate 16 bits for emulated NVMe devices */ #define OUI_FREEBSD_NVME_MASK 0x20ffff #define OUI_FREEBSD_NVME_LOW OUI_FREEBSD(0x200000) #define OUI_FREEBSD_NVME_HIGH OUI_FREEBSD(OUI_FREEBSD_NVME_MASK) /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_PATHS_H_ #define _COMPAT_FREEBSD_PATHS_H_ #define _PATH_TMP "/tmp/" #endif /* _COMPAT_FREEBSD_PATHS_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2022 OmniOS Community Edition (OmniOSce) Association. */ #ifndef _COMPAT_FREEBSD_PTHREAD_H_ #define _COMPAT_FREEBSD_PTHREAD_H_ #include #include_next /* * Mutexes on FreeBSD are error-checking by default. Wrap pthread_mutex_*() * to deliver the same, and check for errors. */ #undef PTHREAD_MUTEX_INITIALIZER #define PTHREAD_MUTEX_INITIALIZER PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP static __inline int checked_pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict cattr) { if (cattr != NULL) { VERIFY0(pthread_mutex_init(mutex, cattr)); } else { pthread_mutexattr_t attr = { 0 }; VERIFY0(pthread_mutexattr_init(&attr)); VERIFY0(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK)); VERIFY0(pthread_mutex_init(mutex, &attr)); VERIFY0(pthread_mutexattr_destroy(&attr)); } return (0); } static __inline int checked_pthread_mutex_destroy(pthread_mutex_t *mutex) { VERIFY0(pthread_mutex_destroy(mutex)); return (0); } #define pthread_mutex_init(m, a) checked_pthread_mutex_init(m, a) #define pthread_mutex_destroy(m) checked_pthread_mutex_destroy(m) #define pthread_mutex_lock(m) pthread_mutex_enter_np(m) #define pthread_mutex_unlock(m) pthread_mutex_exit_np(m) #endif /* _COMPAT_FREEBSD_PTHREAD_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2014 Pluribus Networks Inc. * Copyright 2018 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_PTHREAD_NP_H_ #define _COMPAT_FREEBSD_PTHREAD_NP_H_ #include #include #include #include #define pthread_set_name_np pthread_setname_np #define pthread_mutex_isowned_np(x) _mutex_held(x) #endif /* _COMPAT_FREEBSD_PTHREAD_NP_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2020 OmniOS Community Edition (OmniOSce) Association. */ #ifndef _COMPAT_FREEBSD_STDATOMIC_H_ #define _COMPAT_FREEBSD_STDATOMIC_H_ #include /* * For now, this is just enough to support the usage in usr/src/cmd/bhyve/rfb.c * which uses these functions with atomic_bool/bool arguments. */ #define atomic_bool volatile u_int #define atomic_compare_exchange_strong(p, ovalp, nval) \ atomic_cmpset_int((p), *(ovalp), (nval)) #define atomic_exchange(p, nval) atomic_swap_int((p), (nval)) #endif /* _COMPAT_FREEBSD_STDATOMIC_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_STRING_H_ #define _COMPAT_FREEBSD_STRING_H_ /* * This is quite a hack; blame bcopy/bcmp/bzero and memcpy/memcmp/memset. */ #include #include_next #endif /* _COMPAT_FREEBSD_STRING_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2014 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_STRINGS_H_ #define _COMPAT_FREEBSD_STRINGS_H_ #include #include_next #endif /* _COMPAT_FREEBSD_STRINGS_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2017 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_SYS__CPUSET_H_ #define _COMPAT_FREEBSD_SYS__CPUSET_H_ #ifdef _KERNEL /* * The sys/_cpuset.h header is used to communicate the layout of cpuset_t while * sys/cpuset.h contains the manipulation routines. * * The explicit guard definition below is necessary as other contrib headers * change their behavior based on its presence. */ #define _SYS__CPUSET_H_ #include #endif /* _KERNEL */ #endif /* _COMPAT_FREEBSD_SYS__CPUSET_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2015 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_SYS__IOVEC_H_ #define _COMPAT_FREEBSD_SYS__IOVEC_H_ struct iovec { void *iov_base; /* Base address. */ size_t iov_len; /* Length. */ }; #endif /* _COMPAT_FREEBSD_SYS__IOVEC_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2014 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_SYS__PTHREADTYPES_H_ #define _COMPAT_FREEBSD_SYS__PTHREADTYPES_H_ #endif /* _COMPAT_FREEBSD_SYS__PTHREADTYPES_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_SYS__TYPES_H_ #define _COMPAT_FREEBSD_SYS__TYPES_H_ #include #include #endif /* _COMPAT_FREEBSD_SYS__TYPES_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2017 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_SYS_BUS_H #define _COMPAT_FREEBSD_SYS_BUS_H #define device_get_softc(dev) ddi_get_driver_private(dev) #endif /* _COMPAT_FREEBSD_SYS_BUS_H */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2014 Pluribus Networks Inc. * Copyright 2018 Joyent, Inc. * Copyright 2020 Oxide Computer Company */ #ifndef _COMPAT_FREEBSD_SYS_CALLOUT_H_ #define _COMPAT_FREEBSD_SYS_CALLOUT_H_ #include struct callout { cyclic_id_t c_cyc_id; hrtime_t c_target; hrtime_t c_fired; void (*c_func)(void *); void *c_arg; }; #define C_ABSOLUTE 0x0200 /* event time is absolute. */ /* Callout considered active if t_target has not been zeroed */ #define callout_active(c) ((c)->c_target != 0) #define callout_deactivate(c) ((c)->c_target = 0) /* * If a callout is rescheduled (into the future) while its handler is running, * it will be able to detect the pending invocation by the target time being * greater than the time at which the handler was fired. * * This is only valid when checked from the callout handler, which is the only * place where it is used by bhyve today. */ #define callout_pending(c) ((c)->c_target > (c)->c_fired) void vmm_glue_callout_init(struct callout *c, int mpsafe); void vmm_glue_callout_stop(struct callout *c); void vmm_glue_callout_drain(struct callout *c); /* illumos-custom function for resource locality optimization */ void vmm_glue_callout_localize(struct callout *c); static __inline void callout_init(struct callout *c, int mpsafe) { vmm_glue_callout_init(c, mpsafe); } static __inline void callout_stop(struct callout *c) { vmm_glue_callout_stop(c); } static __inline void callout_drain(struct callout *c) { vmm_glue_callout_drain(c); } void callout_reset_hrtime(struct callout *c, hrtime_t target, void (*func)(void *), void *arg, int flags); uint64_t hrt_freq_count(hrtime_t interval, uint32_t freq); hrtime_t hrt_freq_interval(uint32_t freq, uint64_t count); #endif /* _COMPAT_FREEBSD_SYS_CALLOUT_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. * Copyright 2017 Joyent, Inc. * Copyright 2021 OmniOS Community Edition (OmniOSce) Association. */ #ifndef _COMPAT_FREEBSD_SYS_CDEFS_H_ #define _COMPAT_FREEBSD_SYS_CDEFS_H_ /* * Testing against Clang-specific extensions. */ #ifndef __has_extension #define __has_extension __has_feature #endif #ifndef __has_feature #define __has_feature(x) 0 #endif /* * Macro to test if we're using a specific version of gcc or later. */ #if defined(__GNUC__) && !defined(__INTEL_COMPILER) #define __GNUC_PREREQ__(ma, mi) \ (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)) #else #define __GNUC_PREREQ__(ma, mi) 0 #endif #ifdef __GNUC__ #define asm __asm #define inline __inline #define __GNUCLIKE___SECTION 1 #define __dead2 __attribute__((__noreturn__)) #define __used __attribute__((__used__)) #define __packed __attribute__((__packed__)) #define __aligned(x) __attribute__((__aligned__(x))) #define __section(x) __attribute__((__section__(x))) #define __weak_symbol __attribute__((__weak__)) #endif #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || defined(lint) #if defined(__cplusplus) && __cplusplus >= 201103L #define _Alignof(x) alignof(x) #else #define _Alignof(x) __alignof(x) #endif #if defined(__cplusplus) && __cplusplus >= 201103L #define _Noreturn [[noreturn]] #else #define _Noreturn __dead2 #endif #if !__has_extension(c_static_assert) #if (defined(__cplusplus) && __cplusplus >= 201103L) || \ __has_extension(cxx_static_assert) #define _Static_assert(x, y) static_assert(x, y) #elif __GNUC_PREREQ__(4,6) /* Nothing, gcc 4.6 and higher has _Static_assert built-in */ #elif defined(__COUNTER__) #define _Static_assert(x, y) __Static_assert(x, __COUNTER__) #define __Static_assert(x, y) ___Static_assert(x, y) #define ___Static_assert(x, y) typedef char __assert_ ## y[(x) ? 1 : -1] \ __unused #else #define _Static_assert(x, y) struct __hack #endif #endif #define static_assert(x, y) _Static_assert(x, y) #endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */ #if __GNUC_PREREQ__(4, 1) #define __offsetof(type, field) __builtin_offsetof(type, field) #else #ifndef __cplusplus #define __offsetof(type, field) \ ((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field)) #else #define __offsetof(type, field) \ (__offsetof__ (reinterpret_cast <__size_t> \ (&reinterpret_cast \ (static_cast (0)->field)))) #endif #endif #ifndef __DECONST #define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) #endif #endif /* _COMPAT_FREEBSD_SYS_CDEFS_H_ */ /*- * Copyright (c) 1996 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Gordon W. Ross * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $NetBSD: clock_subr.h,v 1.7 2000/10/03 13:41:07 tsutsui Exp $ * * * This file is the central clearing-house for calendrical issues. * * In general the kernel does not know about minutes, hours, days, timezones, * daylight savings time, leap-years and such. All that is theoretically a * matter for userland only. * * Parts of kernel code does however care: badly designed filesystems store * timestamps in local time and RTC chips sometimes track time in a local * timezone instead of UTC and so on. * * All that code should go here for service. */ #ifndef _COMPAT_FREEBSD_SYS_CLOCK_H_ #define _COMPAT_FREEBSD_SYS_CLOCK_H_ #include_next #ifdef _KERNEL /* No user serviceable parts */ /* * Structure to hold the values typically reported by time-of-day clocks. * This can be passed to the generic conversion functions to be converted * to a struct timespec. */ struct clocktime { int year; /* year (4 digit year) */ int mon; /* month (1 - 12) */ int day; /* day (1 - 31) */ int hour; /* hour (0 - 23) */ int min; /* minute (0 - 59) */ int sec; /* second (0 - 59) */ int dow; /* day of week (0 - 6; 0 = Sunday) */ long nsec; /* nano seconds */ }; int clock_ct_to_ts(struct clocktime *, struct timespec *); void clock_ts_to_ct(struct timespec *, struct clocktime *); /* Some handy constants. */ #define SECDAY (24 * 60 * 60) #define SECYR (SECDAY * 365) /* Traditional POSIX base year */ #define POSIX_BASE_YEAR 1970 void timespec2fattime(struct timespec *tsp, int utc, u_int16_t *ddp, u_int16_t *dtp, u_int8_t *dhp); void fattime2timespec(unsigned dd, unsigned dt, unsigned dh, int utc, struct timespec *tsp); #endif /* _KERNEL */ #endif /* _COMPAT_FREEBSD_SYS_CLOCK_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2014 Pluribus Networks Inc. * Copyright 2019 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_SYS_CPUSET_H_ #define _COMPAT_FREEBSD_SYS_CPUSET_H_ #define NOCPU -1 #ifdef _KERNEL #include #define CPU_SET(cpu, set) cpuset_add((set), (cpu)) #define CPU_SETOF(cpu, set) cpuset_only((set), (cpu)) #define CPU_ZERO(set) cpuset_zero((cpuset_t *)(set)) #define CPU_CLR(cpu, set) cpuset_del((set), (cpu)) #define CPU_EMPTY(set) cpuset_isnull((set)) #define CPU_FFS(set) cpusetobj_ffs(set) #define CPU_ISSET(cpu, set) cpu_in_set((cpuset_t *)(set), (cpu)) #define CPU_AND(dst, src) cpuset_and( \ (cpuset_t *)(dst), \ (cpuset_t *)(src)) #define CPU_OR(dst, src) cpuset_or( \ (cpuset_t *)(dst), \ (cpuset_t *)(src)) #define CPU_CMP(set1, set2) (cpuset_isequal( \ (cpuset_t *)(set1), \ (cpuset_t *)(set2)) == 0) #define CPU_SET_ATOMIC(cpu, set) cpuset_atomic_add( \ (cpuset_t *)(set), \ (cpu)) #define CPU_CLR_ATOMIC(cpu, set) cpuset_atomic_del( \ (cpuset_t *)(set), \ (cpu)) #define CPU_SET_ATOMIC_ACQ(cpu, set) cpuset_atomic_add((set), (cpu)) int cpusetobj_ffs(const cpuset_t *set); #else #include #include #include /* For now, assume NCPU of 256 */ #define CPU_SETSIZE (256) typedef struct { ulong_t _bits[BT_BITOUL(CPU_SETSIZE)]; } cpuset_t; static __inline int cpuset_isempty(const cpuset_t *set) { uint_t i; for (i = 0; i < BT_BITOUL(CPU_SETSIZE); i++) { if (set->_bits[i] != 0) return (0); } return (1); } static __inline void cpuset_zero(cpuset_t *dst) { uint_t i; for (i = 0; i < BT_BITOUL(CPU_SETSIZE); i++) { dst->_bits[i] = 0; } } static __inline int cpuset_isequal(cpuset_t *s1, cpuset_t *s2) { uint_t i; for (i = 0; i < BT_BITOUL(CPU_SETSIZE); i++) { if (s1->_bits[i] != s2->_bits[i]) return (0); } return (1); } static __inline uint_t cpusetobj_ffs(const cpuset_t *set) { uint_t i, cbit; cbit = 0; for (i = 0; i < BT_BITOUL(CPU_SETSIZE); i++) { if (set->_bits[i] != 0) { cbit = ffsl(set->_bits[i]); cbit += i * sizeof (set->_bits[0]); break; } } return (cbit); } #define CPU_SET(cpu, setp) BT_SET((setp)->_bits, cpu) #define CPU_CLR(cpu, setp) BT_CLEAR((setp)->_bits, cpu) #define CPU_ZERO(setp) cpuset_zero((setp)) #define CPU_CMP(set1, set2) (cpuset_isequal( \ (cpuset_t *)(set1), \ (cpuset_t *)(set2)) == 0) #define CPU_FFS(set) cpusetobj_ffs(set) #define CPU_ISSET(cpu, setp) BT_TEST((setp)->_bits, cpu) #define CPU_EMPTY(setp) cpuset_isempty((setp)) #define CPU_SET_ATOMIC(cpu, setp) \ atomic_set_long(&(BT_WIM((setp)->_bits, cpu)), BT_BIW(cpu)) #define CPU_CLR_ATOMIC(cpu, setp) \ atomic_clear_long(&(BT_WIM((setp)->_bits, cpu)), BT_BIW(cpu)) #endif #endif /* _COMPAT_FREEBSD_SYS_CPUSET_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_SYS_DISK_H_ #define _COMPAT_FREEBSD_SYS_DISK_H_ #endif /* _COMPAT_FREEBSD_SYS_DISK_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2014 Pluribus Networks Inc. * Copyright 2018 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_SYS_ENDIAN_H_ #define _COMPAT_FREEBSD_SYS_ENDIAN_H_ static __inline uint16_t be16dec(const void *pp) { uint8_t const *p = (uint8_t const *)pp; return ((p[0] << 8) | p[1]); } static __inline uint32_t be32dec(const void *pp) { uint8_t const *p = (uint8_t const *)pp; return (((unsigned)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); } static __inline uint64_t be64dec(const void *pp) { uint8_t const *p = (uint8_t const *)pp; return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4)); } static __inline uint16_t le16dec(const void *pp) { uint8_t const *p = (uint8_t const *)pp; return ((p[1] << 8) | p[0]); } static __inline uint32_t le32dec(const void *pp) { uint8_t const *p = (uint8_t const *)pp; return (((unsigned)p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]); } static __inline uint64_t le64dec(const void *pp) { uint8_t const *p = (uint8_t const *)pp; return (((uint64_t)le32dec(p + 4) << 32) | le32dec(p)); } static __inline void be16enc(void *pp, uint16_t u) { uint8_t *p = (uint8_t *)pp; p[0] = (u >> 8) & 0xff; p[1] = u & 0xff; } static __inline void be32enc(void *pp, uint32_t u) { uint8_t *p = (uint8_t *)pp; p[0] = (u >> 24) & 0xff; p[1] = (u >> 16) & 0xff; p[2] = (u >> 8) & 0xff; p[3] = u & 0xff; } static __inline void be64enc(void *pp, uint64_t u) { uint8_t *p = (uint8_t *)pp; be32enc(p, (uint32_t)(u >> 32)); be32enc(p + 4, (uint32_t)(u & 0xffffffffU)); } static __inline void le16enc(void *pp, uint16_t u) { uint8_t *p = (uint8_t *)pp; p[0] = u & 0xff; p[1] = (u >> 8) & 0xff; } static __inline void le32enc(void *pp, uint32_t u) { uint8_t *p = (uint8_t *)pp; p[0] = u & 0xff; p[1] = (u >> 8) & 0xff; p[2] = (u >> 16) & 0xff; p[3] = (u >> 24) & 0xff; } static __inline void le64enc(void *pp, uint64_t u) { uint8_t *p = (uint8_t *)pp; le32enc(p, (uint32_t)(u & 0xffffffffU)); le32enc(p + 4, (uint32_t)(u >> 32)); } #ifdef _LITTLE_ENDIAN #define htole16(x) ((uint16_t)(x)) #define htole32(x) ((uint32_t)(x)) #define htole64(x) ((uint64_t)(x)) #define le16toh(x) ((uint16_t)(x)) #define le32toh(x) ((uint32_t)(x)) #define le64toh(x) ((uint64_t)(x)) #endif #endif /* _COMPAT_FREEBSD_SYS_ENDIAN_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_SYS_ERRNO_H_ #define _COMPAT_FREEBSD_SYS_ERRNO_H_ #ifndef _KERNEL extern int *___errno(); #define errno (*(___errno())) #endif #include_next #endif /* _COMPAT_FREEBSD_SYS_ERRNO_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2019 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_SYS_EVENTHANDLER_H_ #define _COMPAT_FREEBSD_SYS_EVENTHANDLER_H_ #endif /* _COMPAT_FREEBSD_SYS_EVENTHANDLER_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_SYS_FCNTL_H_ #define _COMPAT_FREEBSD_SYS_FCNTL_H_ #include_next #endif /* _COMPAT_FREEBSD_SYS_FCNTL_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_SYS_IOCTL_H_ #define _COMPAT_FREEBSD_SYS_IOCTL_H_ #include /* Get BSD compatibility from the ioctl header */ #define BSD_COMP #include_next #endif /* _COMPAT_FREEBSD_SYS_IOCTL_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. * Copyright 2018 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_SYS_KERNEL_H_ #define _COMPAT_FREEBSD_SYS_KERNEL_H_ #define TUNABLE_INT_FETCH(path, var) #include typedef void (*sysinit_func_t)(const void *); struct sysinit { const sysinit_func_t func; const void *data; }; #define SYSINIT(uniquifier, subsystem, order, func, ident) \ static struct sysinit uniquifier ## _sys_init = { \ (const sysinit_func_t)func, \ (const void *)&(ident) \ }; \ DATA_SET(sysinit_set, uniquifier ## _sys_init); extern void sysinit(void); #define ticks ddi_get_lbolt() #endif /* _COMPAT_FREEBSD_SYS_KERNEL_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_SYS_LIBKERN_H_ #define _COMPAT_FREEBSD_SYS_LIBKERN_H_ #include #ifndef min static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); } #endif #endif /* _COMPAT_FREEBSD_SYS_LIBKERN_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. * Copyright 2017 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_SYS_LIMITS_H_ #define _COMPAT_FREEBSD_SYS_LIMITS_H_ #include_next #define OFF_MAX ((off_t)-1) #define SIZE_T_MAX SIZE_MAX #endif /* _COMPAT_FREEBSD_SYS_LIMITS_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2020 Oxide Computer Company */ #ifndef _COMPAT_FREEBSD_SYS_MMAN_H_ #define _COMPAT_FREEBSD_SYS_MMAN_H_ #include_next #define _PROT_ALL (PROT_READ | PROT_WRITE | PROT_EXEC) #endif /* _COMPAT_FREEBSD_SYS_MMAN_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_SYS_MODULE_H_ #define _COMPAT_FREEBSD_SYS_MODULE_H_ #endif /* _COMPAT_FREEBSD_SYS_MODULE_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2021 OmniOS Community Edition (OmniOSce) Association. */ #ifndef _COMPAT_FREEBSD_SYS_NV_H_ #define _COMPAT_FREEBSD_SYS_NV_H_ #include #include #define NV_TYPE_NVLIST DATA_TYPE_NVLIST #define NV_TYPE_STRING DATA_TYPE_STRING static inline const char * nvlist_next(const nvlist_t *nvl, int *type, void **cookie) { nvpair_t *nvp = *cookie; nvp = nvlist_next_nvpair((nvlist_t *)nvl, nvp); if (nvp == NULL) return (NULL); *cookie = nvp; *type = nvpair_type(nvp); return (nvpair_name(nvp)); } static inline nvlist_t * nvlist_create(int flag) { nvlist_t *nvl; /* * We only emulate this with flag == 0, which is equivalent to the * illumos NV_UNIQUE_NAME. */ assert(flag == 0); if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) return (NULL); return (nvl); } static inline bool nvlist_exists_nvlist(const nvlist_t *nvl, const char *name) { nvlist_t *snvl; return (nvlist_lookup_nvlist((nvlist_t *)nvl, name, &snvl) == 0); } static inline nvlist_t * nvlist_get_nvlist(const nvlist_t *nvl, const char *name) { nvlist_t *snvl; if (nvlist_lookup_nvlist((nvlist_t *)nvl, name, &snvl) == 0) return (snvl); return (NULL); } static inline bool nvlist_exists_string(const nvlist_t *nvl, const char *name) { char *str; return (nvlist_lookup_string((nvlist_t *)nvl, name, &str) == 0); } static inline char * nvlist_get_string(const nvlist_t *nvl, const char *name) { char *str; if (nvlist_lookup_string((nvlist_t *)nvl, name, &str) == 0) return (str); return (NULL); } #define nvlist_free_string(nvl, name) nvlist_remove_all((nvl), (name)) #endif /* _COMPAT_FREEBSD_SYS_NV_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2014 Pluribus Networks Inc. * Copyright 2017 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_SYS_PARAM_H_ #define _COMPAT_FREEBSD_SYS_PARAM_H_ #ifndef _KERNEL #define MAXCOMLEN 16 /* default value of the kernel tunable 'maxphys' in i86pc */ #define MAXPHYS (56 * 1024) #endif #define MAXHOSTNAMELEN 256 #define SPECNAMELEN 255 #ifdef _KERNEL #include #ifndef FALSE #define FALSE 0 #endif #ifndef TRUE #define TRUE 1 #endif #endif #include #define nitems(x) (sizeof((x)) / sizeof((x)[0])) #define rounddown(x,y) (((x)/(y))*(y)) #define rounddown2(x, y) ((x)&(~((y)-1))) /* if y is power of two */ #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */ #define roundup2(x,y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */ #define powerof2(x) ((((x)-1)&(x))==0) /* Macros for min/max. */ #define MIN(a,b) (((a)<(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b)) #define trunc_page(x) ((unsigned long)(x) & ~(PAGE_MASK)) #define ptoa(x) ((unsigned long)(x) << PAGE_SHIFT) #include_next #endif /* _COMPAT_FREEBSD_SYS_PARAM_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_SYS_PCPU_H_ #define _COMPAT_FREEBSD_SYS_PCPU_H_ #define curcpu (CPU->cpu_id) #define get_pcpu() CPU #endif /* _COMPAT_FREEBSD_SYS_PCPU_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_SYS_SCHED_H_ #define _COMPAT_FREEBSD_SYS_SCHED_H_ #endif /* _COMPAT_FREEBSD_SYS_SCHED_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2018 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_SYS_SDT_H_ #define _COMPAT_FREEBSD_SYS_SDT_H_ /* Empty macros to cover FreeBSD's SDT linker tricks */ #define SDT_PROVIDER_DECLARE(mod) #define SDT_PROVIDER_DEFINE(mod) #define SDT_PROBE_DEFINE1(...) #define SDT_PROBE_DEFINE2(...) #define SDT_PROBE_DEFINE3(...) #define SDT_PROBE_DEFINE4(...) #define SDT_PROBE_DEFINE5(...) #define SDT_PROBE1(...) #define SDT_PROBE2(...) #define SDT_PROBE3(...) #define SDT_PROBE4(...) #define SDT_PROBE5(...) #include_next #endif /* _COMPAT_FREEBSD_SYS_SDT_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2014 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_SYS_MODULE_H_ #define _COMPAT_FREEBSD_SYS_MODULE_H_ void *memset(void *s, int c, size_t n); #include_next #endif /* _COMPAT_FREEBSD_SYS_MODULE_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2017 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_SYS_SGLIST_H_ #define _COMPAT_FREEBSD_SYS_SGLIST_H_ #ifdef _KERNEL struct sglist; struct sglist *sglist_alloc(int, int); void sglist_free(struct sglist *); int sglist_append_phys(struct sglist *, vm_paddr_t, size_t); #endif /* _KERNEL */ #endif /* _COMPAT_FREEBSD_SYS_SGLIST_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2017 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_SYS_SOCKET_H #define _COMPAT_FREEBSD_SYS_SOCKET_H #include_next #define SO_NOSIGPIPE 0 #endif /* _COMPAT_FREEBSD_SYS_SOCKET_H */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2014 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_SYS_SYSCTL_H_ #define _COMPAT_FREEBSD_SYS_SYSCTL_H_ #define SYSCTL_DECL(name) #define SYSCTL_NODE(parent, nbr, name, access, handler, descr) #define SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) #define SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr) #define SYSCTL_ULONG(parent, nbr, name, access, ptr, val, descr) #endif /* _COMPAT_FREEBSD_SYS_SYSCTL_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2014 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_SYS_SYSTM_H_ #define _COMPAT_FREEBSD_SYS_SYSTM_H_ #include #include #include #include struct mtx; #define KASSERT(exp,msg) do { \ if (!(exp)) \ panic msg; \ } while (0) void critical_enter(void); void critical_exit(void); struct unrhdr *new_unrhdr(int low, int high, struct mtx *mutex); void delete_unrhdr(struct unrhdr *uh); int alloc_unr(struct unrhdr *uh); void free_unr(struct unrhdr *uh, u_int item); #include #include_next #include #endif /* _COMPAT_FREEBSD_SYS_SYSTM_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2014 Pluribus Networks Inc. * Copyright 2018 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_SYS_TYPES_H_ #define _COMPAT_FREEBSD_SYS_TYPES_H_ #include typedef __uint8_t u_int8_t; /* unsigned integrals (deprecated) */ typedef __uint16_t u_int16_t; typedef __uint32_t u_int32_t; typedef __uint64_t u_int64_t; #ifndef __REGISTER_T_DEFINED #define __REGISTER_T_DEFINED typedef __register_t register_t; #endif #ifndef __VM_MEMATTR_T_DEFINED #define __VM_MEMATTR_T_DEFINED typedef char vm_memattr_t; #endif #ifndef __VM_OFFSET_T_DEFINED #define __VM_OFFSET_T_DEFINED typedef __vm_offset_t vm_offset_t; #endif #ifndef __VM_OOFFSET_T_DEFINED #define __VM_OOFFSET_T_DEFINED typedef __vm_ooffset_t vm_ooffset_t; #endif #ifndef __VM_PADDR_T_DEFINED #define __VM_PADDR_T_DEFINED typedef __vm_paddr_t vm_paddr_t; #endif #ifndef __VM_PINDEX_T_DEFINED #define __VM_PINDEX_T_DEFINED typedef __uint64_t vm_pindex_t; #endif #ifndef __VM_SIZE_T_DEFINED #define __VM_SIZE_T_DEFINED typedef __vm_size_t vm_size_t; #endif #ifndef __VM_MEMATTR_T_DEFINED #define __VM_MEMATTR_T_DEFINED typedef char vm_memattr_t; #endif #ifndef __bool_true_false_are_defined #define __bool_true_false_are_defined 1 #define false 0 #define true 1 typedef _Bool bool; #endif #if defined(_KERNEL) typedef struct __dev_info **device_t; #endif #include_next #endif /* _COMPAT_FREEBSD_SYS_TYPES_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_SYS_UIO_H_ #define _COMPAT_FREEBSD_SYS_UIO_H_ #include_next #ifndef _KERNEL ssize_t preadv(int, const struct iovec *, int, off_t); ssize_t pwritev(int, const struct iovec *, int, off_t); #endif #endif /* _COMPAT_FREEBSD_SYS_UIO_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_TERMIOS_H_ #define _COMPAT_FREEBSD_TERMIOS_H_ #include_next void cfmakeraw(struct termios *); #endif /* _COMPAT_FREEBSD_TERMIOS_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2017 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_UNISTD_H #define _COMPAT_FREEBSD_UNISTD_H #define setproctitle(fmt, ...) #include_next #endif /* _COMPAT_FREEBSD_UNISTD_H */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2014 Pluribus Networks Inc. */ #ifndef _COMPAT_FREEBSD_UUID_H_ #define _COMPAT_FREEBSD_UUID_H_ #include #include /* Status codes returned by the functions. */ #define uuid_s_ok 0 #define uuid_s_bad_version 1 #define uuid_s_invalid_string_uuid 2 static __inline void uuid_from_string(const char *str, uuid_t *uuidp, uint32_t *status) { if (uuid_parse((char *)str, *uuidp) == 0) { *status = uuid_s_ok; } else { *status = uuid_s_invalid_string_uuid; } } static __inline void uuid_enc_le(void *buf, uuid_t *uuidp) { uchar_t *p; int i; p = buf; be32enc(p, ((struct uuid *)uuidp)->time_low); be16enc(p + 4, ((struct uuid *)uuidp)->time_mid); be16enc(p + 6, ((struct uuid *)uuidp)->time_hi_and_version); p[8] = ((struct uuid *)uuidp)->clock_seq_hi_and_reserved; p[9] = ((struct uuid *)uuidp)->clock_seq_low; for (i = 0; i < 6; i++) p[10 + i] = ((struct uuid *)uuidp)->node_addr[i]; } #endif /* _COMPAT_FREEBSD_UUID_H_ */ #ifndef _COMPAT_FREEBSD_VM_VM_PARAM_H_ #define _COMPAT_FREEBSD_VM_VM_PARAM_H_ #include #define KERN_SUCCESS 0 /* Not a direct correlation, but the primary necessity is being non-zero */ #define KERN_RESOURCE_SHORTAGE ENOMEM /* * The VM_MAXUSER_ADDRESS is used to determine the upper limit size limit of a * vmspace, their 'struct as' equivalent. The compat value is sized well below * our native userlimit, even halving the available space below the VA hole. * This is to avoid Intel EPT limits and leave room available in the usabe VA * range for other mmap tricks. */ #define VM_MAXUSER_ADDRESS 0x00003ffffffffffful #endif /* _COMPAT_FREEBSD_VM_VM_PARAM_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2013 Pluribus Networks Inc. */ #ifndef _FREEBSD_X86__TYPES_H_ #define _FREEBSD_X86__TYPES_H_ /* * Basic types upon which most other types are built. */ typedef signed char __int8_t; typedef unsigned char __uint8_t; typedef short __int16_t; typedef unsigned short __uint16_t; typedef int __int32_t; typedef unsigned int __uint32_t; #ifdef _LP64 typedef long __int64_t; typedef unsigned long __uint64_t; #else typedef long long __int64_t; typedef unsigned long long __uint64_t; #endif /* * Standard type definitions. */ #ifdef _LP64 typedef __int64_t __register_t; typedef __uint64_t __vm_offset_t; typedef __uint64_t __vm_paddr_t; typedef __int64_t __vm_ooffset_t; typedef __uint64_t __vm_size_t; #else typedef __int32_t __register_t; typedef __uint32_t __vm_paddr_t; typedef __uint32_t __vm_size_t; #endif #endif /* _FREEBSD_X86__TYPES_H_ */ /* * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. */ /* * Copyright 2015 Pluribus Networks Inc. * Copyright 2017 Joyent, Inc. */ #ifndef _COMPAT_FREEBSD_X86_SEGMENTS_H #define _COMPAT_FREEBSD_X86_SEGMENTS_H #if defined(_COMPAT_FREEBSD_AMD64_MACHINE_VMM_H_) || defined(_KERNEL) #define IDT_BP 3 /* #BP: Breakpoint */ #define IDT_UD 6 /* #UD: Undefined/Invalid Opcode */ #define IDT_SS 12 /* #SS: Stack Segment Fault */ #define IDT_GP 13 /* #GP: General Protection Fault */ #define IDT_AC 17 /* #AC: Alignment Check */ #else #include_next #endif #endif /* _COMPAT_FREEBSD_X86_SEGMENTS_H */