From a4052f0f2ce65d0f836241f4aa965b0baf29081f Mon Sep 17 00:00:00 2001 From: dv Date: Wed, 2 Oct 2024 17:05:56 +0000 Subject: [PATCH] Move some PCI MMIO defines from vmm(4) kernel headers to userland. vmm(4) doesn't need this information anymore. vmd(8) is the only consumer of this information. ok mlarkin@ --- sys/arch/amd64/include/vmmvar.h | 5 +---- usr.sbin/vmd/pci.c | 6 +++--- usr.sbin/vmd/pci.h | 5 ++++- usr.sbin/vmd/x86_vm.c | 16 ++++++++-------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/sys/arch/amd64/include/vmmvar.h b/sys/arch/amd64/include/vmmvar.h index 6bc63d5ae3f..a2c9d5db449 100644 --- a/sys/arch/amd64/include/vmmvar.h +++ b/sys/arch/amd64/include/vmmvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vmmvar.h,v 1.107 2024/09/26 13:18:25 dv Exp $ */ +/* $OpenBSD: vmmvar.h,v 1.108 2024/10/02 17:05:56 dv Exp $ */ /* * Copyright (c) 2014 Mike Larkin * @@ -23,9 +23,6 @@ #define VMM_HV_SIGNATURE "OpenBSDVMM58" -#define VMM_PCI_MMIO_BAR_BASE 0xF0000000ULL -#define VMM_PCI_MMIO_BAR_END 0xFFDFFFFFULL /* 2 MiB below 4 GiB */ - /* VMX: Basic Exit Reasons */ #define VMX_EXIT_NMI 0 #define VMX_EXIT_EXTINT 1 diff --git a/usr.sbin/vmd/pci.c b/usr.sbin/vmd/pci.c index b159977f464..f606d913536 100644 --- a/usr.sbin/vmd/pci.c +++ b/usr.sbin/vmd/pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pci.c,v 1.34 2024/09/26 01:45:13 jsg Exp $ */ +/* $OpenBSD: pci.c,v 1.35 2024/10/02 17:05:56 dv Exp $ */ /* * Copyright (c) 2015 Mike Larkin @@ -73,7 +73,7 @@ pci_add_bar(uint8_t id, uint32_t type, void *barfn, void *cookie) /* Compute BAR address and add */ bar_reg_idx = (PCI_MAPREG_START + (bar_ct * 4)) / 4; if (type == PCI_MAPREG_TYPE_MEM) { - if (pci.pci_next_mmio_bar >= VMM_PCI_MMIO_BAR_END) + if (pci.pci_next_mmio_bar >= PCI_MMIO_BAR_END) return (1); pci.pci_devices[id].pd_cfg_space[bar_reg_idx] = @@ -216,7 +216,7 @@ pci_init(void) uint8_t id; memset(&pci, 0, sizeof(pci)); - pci.pci_next_mmio_bar = VMM_PCI_MMIO_BAR_BASE; + pci.pci_next_mmio_bar = PCI_MMIO_BAR_BASE; #ifdef __amd64__ pci.pci_next_io_bar = VM_PCI_IO_BAR_BASE; diff --git a/usr.sbin/vmd/pci.h b/usr.sbin/vmd/pci.h index 0b05a9298d1..8e36759aafd 100644 --- a/usr.sbin/vmd/pci.h +++ b/usr.sbin/vmd/pci.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pci.h,v 1.11 2024/07/10 09:27:33 dv Exp $ */ +/* $OpenBSD: pci.h,v 1.12 2024/10/02 17:05:56 dv Exp $ */ /* * Copyright (c) 2015 Mike Larkin @@ -34,6 +34,9 @@ #define PCI_BAR_TYPE_IO 0x0 #define PCI_BAR_TYPE_MMIO 0x1 +#define PCI_MMIO_BAR_BASE 0xF0000000ULL +#define PCI_MMIO_BAR_END 0xFFDFFFFFULL /* 2 MiB below 4 GiB */ + #define PCI_MAX_PIC_IRQS 10 typedef int (*pci_cs_fn_t)(int dir, uint8_t reg, uint32_t *data); diff --git a/usr.sbin/vmd/x86_vm.c b/usr.sbin/vmd/x86_vm.c index 729e0c5f9bd..aa64ddb02e8 100644 --- a/usr.sbin/vmd/x86_vm.c +++ b/usr.sbin/vmd/x86_vm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x86_vm.c,v 1.4 2024/09/26 01:45:13 jsg Exp $ */ +/* $OpenBSD: x86_vm.c,v 1.5 2024/10/02 17:05:56 dv Exp $ */ /* * Copyright (c) 2015 Mike Larkin * @@ -192,7 +192,7 @@ create_memory_map(struct vm_create_params *vcp) /* If we have less than 2MB remaining, still create a 2nd BIOS area. */ if (mem_bytes <= MB(2)) { - vcp->vcp_memranges[2].vmr_gpa = VMM_PCI_MMIO_BAR_END; + vcp->vcp_memranges[2].vmr_gpa = PCI_MMIO_BAR_END; vcp->vcp_memranges[2].vmr_size = MB(2); vcp->vcp_memranges[2].vmr_type = VM_MEM_RESERVED; vcp->vcp_nmemranges = 3; @@ -204,8 +204,8 @@ create_memory_map(struct vm_create_params *vcp) * boundary while making sure we do not place physical memory into * MMIO ranges. */ - if (mem_bytes > VMM_PCI_MMIO_BAR_BASE - MB(1)) { - above_1m = VMM_PCI_MMIO_BAR_BASE - MB(1); + if (mem_bytes > PCI_MMIO_BAR_BASE - MB(1)) { + above_1m = PCI_MMIO_BAR_BASE - MB(1); above_4g = mem_bytes - above_1m; } else { above_1m = mem_bytes; @@ -218,13 +218,13 @@ create_memory_map(struct vm_create_params *vcp) vcp->vcp_memranges[2].vmr_type = VM_MEM_RAM; /* Fourth region: PCI MMIO range */ - vcp->vcp_memranges[3].vmr_gpa = VMM_PCI_MMIO_BAR_BASE; - vcp->vcp_memranges[3].vmr_size = VMM_PCI_MMIO_BAR_END - - VMM_PCI_MMIO_BAR_BASE + 1; + vcp->vcp_memranges[3].vmr_gpa = PCI_MMIO_BAR_BASE; + vcp->vcp_memranges[3].vmr_size = PCI_MMIO_BAR_END - + PCI_MMIO_BAR_BASE + 1; vcp->vcp_memranges[3].vmr_type = VM_MEM_MMIO; /* Fifth region: 2nd copy of BIOS above MMIO ending at 4GB */ - vcp->vcp_memranges[4].vmr_gpa = VMM_PCI_MMIO_BAR_END + 1; + vcp->vcp_memranges[4].vmr_gpa = PCI_MMIO_BAR_END + 1; vcp->vcp_memranges[4].vmr_size = MB(2); vcp->vcp_memranges[4].vmr_type = VM_MEM_RESERVED; -- 2.20.1