Index: sys/conf/files.x86 =================================================================== --- sys/conf/files.x86 +++ sys/conf/files.x86 @@ -324,6 +324,7 @@ x86/x86/tsc.c standard x86/x86/ucode.c standard x86/x86/delay.c standard +x86/xen/arch.c optional xenhvm x86/xen/hvm.c optional xenhvm x86/xen/xen_intr.c optional xenhvm x86/xen/xen_apic.c optional xenhvm Index: sys/dev/xen/bus/xenpv.c =================================================================== --- sys/dev/xen/bus/xenpv.c +++ sys/dev/xen/bus/xenpv.c @@ -48,22 +48,6 @@ #include "xenmem_if.h" -/* - * Allocate unused physical memory above 4GB in order to map memory - * from foreign domains. We use memory starting at 4GB in order to - * prevent clashes with MMIO/ACPI regions. - * - * Since this is not possible on i386 just use any available memory - * chunk above 1MB and hope we don't clash with anything else. - */ -#ifdef __amd64__ -#define LOW_MEM_LIMIT 0x100000000ul -#elif defined(__i386__) -#define LOW_MEM_LIMIT 0x100000ul -#else -#error "Unsupported architecture" -#endif - static devclass_t xenpv_devclass; static void @@ -119,8 +103,7 @@ void *virt_addr; int error; - res = bus_alloc_resource(child, SYS_RES_MEMORY, res_id, LOW_MEM_LIMIT, - ~0, size, RF_ACTIVE | RF_UNMAPPED); + res = xen_arch_alloc_addr(child, res_id, size); if (res == NULL) return (NULL); @@ -128,7 +111,7 @@ error = vm_phys_fictitious_reg_range(phys_addr, phys_addr + size, VM_MEMATTR_XEN); if (error) { - bus_release_resource(child, SYS_RES_MEMORY, *res_id, res); + xen_arch_release_addr(child, *res_id, res); return (NULL); } virt_addr = pmap_mapdev_attr(phys_addr, size, VM_MEMATTR_XEN); @@ -151,7 +134,7 @@ pmap_unmapdev(virt_addr, size); vm_phys_fictitious_unreg_range(phys_addr, phys_addr + size); - return (bus_release_resource(child, SYS_RES_MEMORY, res_id, res)); + return (xen_arch_release_addr(child, res_id, res)); } static device_method_t xenpv_methods[] = { Index: sys/x86/include/xen/xen-os.h =================================================================== --- sys/x86/include/xen/xen-os.h +++ sys/x86/include/xen/xen-os.h @@ -39,6 +39,12 @@ /* If non-zero, the hypervisor has been configured to use a direct vector */ extern int xen_vector_callback_enabled; +/* Function for allocating physical address resource to xenpv code */ +extern struct resource *xen_arch_alloc_addr(device_t, int *, size_t); + +/* Function for releasing physical address resource from xenpv code */ +int xen_arch_release_addr(device_t, int, struct resource *); + #endif /* !__ASSEMBLY__ */ #endif /* _MACHINE_X86_XEN_XEN_OS_H_ */ Index: sys/x86/xen/arch.c =================================================================== --- /dev/null +++ sys/x86/xen/arch.c @@ -0,0 +1,73 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2021 Elliott Mitchell + * 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. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include + +#include + +/* + * Allocate unused physical memory above 4GB in order to map memory + * from foreign domains. We use memory starting at 4GB in order to + * prevent clashes with MMIO/ACPI regions. + * + * Since this is not possible on i386 just use any available memory + * chunk above 1MB and hope we don't clash with anything else. + */ + +#ifdef __amd64__ +#define LOW_MEM_LIMIT 0x100000000ul +#elif defined(__i386__) +#define LOW_MEM_LIMIT 0x100000ul +#else +#error "Unsupported architecture" +#endif + +/* + * Function for allocating physical address resource to xenpv code + */ +struct resource *xen_arch_alloc_addr(device_t dev, int *res_id, size_t size) +{ + + return bus_alloc_resource(dev, SYS_RES_MEMORY, res_id, LOW_MEM_LIMIT, +~0, size, RF_ACTIVE | RF_UNMAPPED); +} + +/* + * Function for releasing physical address resource from xenpv code + */ +int xen_arch_release_addr(device_t dev, int res_id, struct resource *res) +{ + + return bus_release_resource(dev, SYS_RES_MEMORY, res_id, res); +}