From nobody Tue Jun 20 08:52:16 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QlgPD6rnvz4gTH0; Tue, 20 Jun 2023 08:52:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QlgPD5jbhz3xdp; Tue, 20 Jun 2023 08:52:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687251136; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FEjO9iP16dpVfDrnmJz/Bb2nKnUHobWdbIkHoxFxs08=; b=kM1tzkJQOZUlgtNJdglGRY+L3Lwlhabs7escol2Cz5Hc6YTK4osJz0OALBzJBbk9LQwWq0 xBfCqjpEgezGs6S9ABgAKs+89vPNOQr/5YROl8yjXoVkzAP+HI3HWpsF2KPmvQKtuHXtkL C4CaN6aH6r9nXPjTWOt+LT0pBeDEuwqu72JCo9sU3ASMgC7G/1pYmY/iW2q3CsWPocsBl0 xLjSC/t2lX4x+94yx26yS23NdfI1ixYIrHVY6xBygv1sBZ1g17JZrX1voJobYpc7+HPBEM HnoihFZgd5xq08sXiMxxrGaLdnUKjpgegsajEv+54rfepaFluwR75fhnCGP51w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687251136; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FEjO9iP16dpVfDrnmJz/Bb2nKnUHobWdbIkHoxFxs08=; b=IkmQyg5nj81swoQ1g5vbeBre1tTCMH1llOU6KycyTc8r5A71lB6tLBR5ivrNhds78SBgEc 2uN5RLAKI/r+UtC/eLrpMFeXle9vONs5nFKM3H98fslShR6AJU2p2w0xFZ8YfqydG3GlG3 F2a4JQUmWACxvE4Tg7Y5e6/aRMJB0OF7tVLrvPSmGoJTvIoN1XCWRhKpwIPJcfagnEcEdG eYdL02id3IfL0WY8AZAb/7sFvo+HMnfUCGFMuCC4ctnnxjTm88NdhnGbRUHV1y/+ropADv Wtuu8Ihi9aPwPo9SetNZkOz2k537KCFWGbeyiO2jpDY8e4TkPrSWaRKT4EJvRQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1687251136; a=rsa-sha256; cv=none; b=qCKtCWqe+DxVaXm+dh0cPZzd/0onji5T4JZIPaAfkFo3qUA4I2XPJvuYra8fvaiIzekAHQ 1kRf904CiVgIN9OUJCTYpK21bAqZ2MRrQJx/LUKURio2cCWjVyej7AYAghD10LzjWs5gXV Rl5KMmw3vmKDe/gBxhR/IrQsDBWU6HMpQooczvHfisb/BvNCZVawFMuP2HEHQaHBZa2C9X XSnvjPYuWRTC6Jr1nb7mGq+j/Fyb5P8bfx+SeBKHGe21HR+XRZpDYWGGESVBvtwf+DjxgG 8rFZD1rm90bUQ/W7DFuhOYGGkyFhubBLw5tovozvURmS3vP9mW/E62TAJok/3A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QlgPD4nPLzsjM; Tue, 20 Jun 2023 08:52:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 35K8qGGR094965; Tue, 20 Jun 2023 08:52:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35K8qGwO094949; Tue, 20 Jun 2023 08:52:16 GMT (envelope-from git) Date: Tue, 20 Jun 2023 08:52:16 GMT Message-Id: <202306200852.35K8qGwO094949@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Corvin=20K=C3=B6hne?= Subject: git: 6632a0a4e3ab - main - bhyve: add helper to create a bootorder List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: corvink X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6632a0a4e3ab68b0e31b612e8aeca14de3fc8159 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=6632a0a4e3ab68b0e31b612e8aeca14de3fc8159 commit 6632a0a4e3ab68b0e31b612e8aeca14de3fc8159 Author: Corvin Köhne AuthorDate: 2021-08-16 07:47:53 +0000 Commit: Corvin Köhne CommitDate: 2023-06-20 08:51:54 +0000 bhyve: add helper to create a bootorder Qemu's fwcfg allows to define a bootorder. Therefore, the hypervisor has to create a fwcfg item named bootorder, which has a newline seperated list of boot entries. Qemu's OVMF will pick up the bootorder and applies it. Add the moment, bhyve's OVMF doesn't support a custom bootorder by qemu's fwcfg. However, in the future bhyve will gain support for qemu's OVMF. Additonally, we can port relevant parts from qemu's to bhyve's OVMF implementation. Reviewed by: jhb, markj MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D39284 --- usr.sbin/bhyve/pci_emul.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++ usr.sbin/bhyve/pci_emul.h | 2 ++ 2 files changed, 78 insertions(+) diff --git a/usr.sbin/bhyve/pci_emul.c b/usr.sbin/bhyve/pci_emul.c index cb92ea9edb09..ad6180c79470 100644 --- a/usr.sbin/bhyve/pci_emul.c +++ b/usr.sbin/bhyve/pci_emul.c @@ -62,6 +62,7 @@ __FBSDID("$FreeBSD$"); #include "pci_irq.h" #include "pci_lpc.h" #include "pci_passthru.h" +#include "qemu_fwcfg.h" #define CONF1_ADDR_PORT 0x0cf8 #define CONF1_DATA_PORT 0x0cfc @@ -121,6 +122,14 @@ struct pci_bar_allocation { static TAILQ_HEAD(pci_bar_list, pci_bar_allocation) pci_bars = TAILQ_HEAD_INITIALIZER(pci_bars); +struct boot_device { + TAILQ_ENTRY(boot_device) boot_device_chain; + struct pci_devinst *pdi; + int bootindex; +}; +static TAILQ_HEAD(boot_list, boot_device) boot_devices = TAILQ_HEAD_INITIALIZER( + boot_devices); + #define PCI_EMUL_IOBASE 0x2000 #define PCI_EMUL_IOLIMIT 0x10000 @@ -955,6 +964,45 @@ pci_emul_alloc_rom(struct pci_devinst *const pdi, const uint64_t size, return (0); } +int +pci_emul_add_boot_device(struct pci_devinst *pi, int bootindex) +{ + struct boot_device *new_device, *device; + + /* don't permit a negative bootindex */ + if (bootindex < 0) { + errx(4, "Invalid bootindex %d for %s", bootindex, pi->pi_name); + } + + /* alloc new boot device */ + new_device = calloc(1, sizeof(struct boot_device)); + if (new_device == NULL) { + return (ENOMEM); + } + new_device->pdi = pi; + new_device->bootindex = bootindex; + + /* search for boot device with higher boot index */ + TAILQ_FOREACH(device, &boot_devices, boot_device_chain) { + if (device->bootindex == bootindex) { + errx(4, + "Could not set bootindex %d for %s. Bootindex already occupied by %s", + bootindex, pi->pi_name, device->pdi->pi_name); + } else if (device->bootindex > bootindex) { + break; + } + } + + /* add boot device to queue */ + if (device == NULL) { + TAILQ_INSERT_TAIL(&boot_devices, new_device, boot_device_chain); + } else { + TAILQ_INSERT_BEFORE(device, new_device, boot_device_chain); + } + + return (0); +} + #define CAP_START_OFFSET 0x40 static int pci_emul_add_capability(struct pci_devinst *pi, u_char *capdata, int caplen) @@ -1362,6 +1410,27 @@ pci_ecfg_base(void) return (PCI_EMUL_ECFG_BASE); } +static int +init_bootorder(void) +{ + struct boot_device *device; + FILE *fp; + char *bootorder; + size_t bootorder_len; + + if (TAILQ_EMPTY(&boot_devices)) + return (0); + + fp = open_memstream(&bootorder, &bootorder_len); + TAILQ_FOREACH(device, &boot_devices, boot_device_chain) { + fprintf(fp, "/pci@i0cf8/pci@%d,%d\n", + device->pdi->pi_slot, device->pdi->pi_func); + } + fclose(fp); + + return (qemu_fwcfg_add_file("bootorder", bootorder_len, bootorder)); +} + #define BUSIO_ROUNDUP 32 #define BUSMEM32_ROUNDUP (1024 * 1024) #define BUSMEM64_ROUNDUP (512 * 1024 * 1024) @@ -1391,6 +1460,8 @@ init_pci(struct vmctx *ctx) pci_emul_membase64 = roundup2(pci_emul_membase64, PCI_EMUL_MEMSIZE64); pci_emul_memlim64 = pci_emul_membase64 + PCI_EMUL_MEMSIZE64; + TAILQ_INIT(&boot_devices); + for (bus = 0; bus < MAXBUSES; bus++) { snprintf(node_name, sizeof(node_name), "pci.%d", bus); nvl = find_config_node(node_name); @@ -1498,6 +1569,11 @@ init_pci(struct vmctx *ctx) } lpc_pirq_routed(); + if ((error = init_bootorder()) != 0) { + warnx("%s: Unable to init bootorder", __func__); + return (error); + } + /* * The guest physical memory map looks like the following: * [0, lowmem) guest system memory diff --git a/usr.sbin/bhyve/pci_emul.h b/usr.sbin/bhyve/pci_emul.h index d68920524398..945d32d7bdcd 100644 --- a/usr.sbin/bhyve/pci_emul.h +++ b/usr.sbin/bhyve/pci_emul.h @@ -234,6 +234,8 @@ int pci_emul_alloc_bar(struct pci_devinst *pdi, int idx, enum pcibar_type type, uint64_t size); int pci_emul_alloc_rom(struct pci_devinst *const pdi, const uint64_t size, void **const addr); +int pci_emul_add_boot_device(struct pci_devinst *const pi, + const int bootindex); int pci_emul_add_msicap(struct pci_devinst *pi, int msgnum); int pci_emul_add_pciecap(struct pci_devinst *pi, int pcie_device_type); void pci_emul_capwrite(struct pci_devinst *pi, int offset, int bytes,