From nobody Sun Feb 8 15:10:15 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584604012; cv=none; d=zohomail.com; s=zohoarc; b=Szjfzk08rjQcI5N3pUSpO3/PLXiZWO1kEWXFoC85O9ol5+JmqP9/RFbBxqQsHPtSocrkjEJZqcBFDYug1nnLuleyL6hZCI1yEwDoEafFGUWiABZlmXup02X1opr2Rj9qmvXekT/ouh1tVTkl0eHcqeodPUI1Yq77fNnbVF2fSfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584604012; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Subject:To; bh=tmSZtOLMkXQutNmduEtdi2c08u33Nu3eh8iVlwx3r68=; b=gaaMS7G1GyZWlORwMS/QWMbbOELvl6tKvEixnXxLdR6wRnH02x9b7vqNvjiOz6UCBBz9phQESfDKTbuHJRzTFzfV62DyB0opZPfSK8vkfPj0A8M9OLiQ73CVsr7vOI0wt/Nt46emNwEFlo3sAA0KmtrE/WUFs+DvjuOnCh9itj4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1584604012049882.7338621121011; Thu, 19 Mar 2020 00:46:52 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 917F3B01B19; Thu, 19 Mar 2020 07:46:48 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 5AAD1B01B18 for ; Thu, 19 Mar 2020 07:46:05 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-426-lQLH7k4yPzqkjrq0uz0YZg-1; Thu, 19 Mar 2020 03:39:44 -0400 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 24DF08010EA for ; Thu, 19 Mar 2020 07:39:44 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA707BBBC0; Thu, 19 Mar 2020 07:39:43 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) id F333E31EAC; Thu, 19 Mar 2020 08:39:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584603964; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Jzyp5ggFwZpOWJyyVGsk/UabhlIjk3Jp3yEqTx9z3t4=; b=cl9jaImX+DOVLC7Qsan1vZbYxEwkuWzE3OFJbuSOM5zrsnvVNn47EzJwtlEdy2Xz4N/F9S WI2aCHYsndPpKhjg/ZhmQvH913T1vNeOUO09dkIQrfBY+JUXs4f6ipydcNclGk1ZMAoRB1 9iJi+Gx67X16VLsbMCOST+N9AGo2fjc= X-MC-Unique: lQLH7k4yPzqkjrq0uz0YZg-1 From: Gerd Hoffmann To: seabios@seabios.org Date: Thu, 19 Mar 2020 08:39:32 +0100 Message-Id: <20200319073937.5561-2-kraxel@redhat.com> In-Reply-To: <20200319073937.5561-1-kraxel@redhat.com> References: <20200319073937.5561-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: TWFNIE7XHIEUAOXGNFZZWTNLMXNXHQVX X-Message-ID-Hash: TWFNIE7XHIEUAOXGNFZZWTNLMXNXHQVX X-MailFrom: kraxel@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Gerd Hoffmann X-Mailman-Version: 3.3.1 Precedence: list Subject: [SeaBIOS] [PATCH 1/6] string: add strtol() implementation List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: ++++ X-Spam-Level: **** Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Gerd Hoffmann --- src/string.h | 1 + src/string.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/string.h b/src/string.h index d069989db4b4..17ef3c6a1e89 100644 --- a/src/string.h +++ b/src/string.h @@ -27,5 +27,6 @@ void *memmove(void *d, const void *s, size_t len); char *strtcpy(char *dest, const char *src, size_t len); char *strchr(const char *s, int c); char *nullTrailingSpace(char *buf); +u64 strtol(const char *ptr, int base); =20 #endif // string.h diff --git a/src/string.c b/src/string.c index adb8198f84f4..ec8cf6108561 100644 --- a/src/string.c +++ b/src/string.c @@ -249,3 +249,28 @@ nullTrailingSpace(char *buf) buf++; return buf; } + +u64 strtol(const char *ptr, int base) +{ + u64 digit, val =3D 0; + + for (;;) { + switch (*ptr) { + case '0' ... '9': + digit =3D *ptr - '0'; + break; + case 'a' ... 'f': + digit =3D *ptr - 'a' + 10; + break; + case 'A' ... 'F': + digit =3D *ptr - 'A' + 10; + break; + default: + return val; + } + if (digit >=3D base) + return val; + val =3D val * base + digit; + ptr++; + } +} --=20 2.18.2 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org From nobody Sun Feb 8 15:10:15 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584604061; cv=none; d=zohomail.com; s=zohoarc; b=X/FtesJNMy8mxDYeE9niscm2sbnppoPboBWG/PsyTbGrE2Pry1GW2E/wbFBGOguZNJAZuZe0oFPefDoSmE0/EAXEBcPW4GejtbLlA0X5odmAp2kLR3JJIscaYuR/895fvO+cd3aov87YMR61kZrvV5gRpbVH6BqrEn45lS3XN/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584604061; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Subject:To; bh=pMRMVEQ9O7v/yExDKowNWz4UO2Lj9x6r0NzW3X18+5E=; b=Q49moRI5qMoDT5CQXBbTrvrrVp2vDWwDrQ6hEAaCBWNWR0uztNZI5gIWSqA+OF3XOSWAmiNoUBLnbFYsMleMOwao7lJRw6H0HqaDX4N5Z/MNywgJp5rmwsEOMkH9cnbJy1StI0/F14X2UkwpFoexIZYiNAyY+xILQcK+h1t/joM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1584604061284623.9017845528194; Thu, 19 Mar 2020 00:47:41 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 14AA1B01B48; Thu, 19 Mar 2020 07:47:37 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 98519B01B2A for ; Thu, 19 Mar 2020 07:46:08 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-385-3yxMaEeGPHaNvZt_BL5iXg-1; Thu, 19 Mar 2020 03:39:44 -0400 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4AF86107ACC4 for ; Thu, 19 Mar 2020 07:39:43 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6D6462673; Thu, 19 Mar 2020 07:39:40 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) id 011E031F24; Thu, 19 Mar 2020 08:39:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584603967; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nwCMvnfD2vvjf58AakGhK1xD4pi3sQOMgItIdE+Du34=; b=a4w1iWYBOrgthySA7GRVfen6/Kl34rBQHNtTcVmwuDoFKogP5+pXv7L2+A0WFLJG/nMOoL IoR1M5UIaDwFM3VC3n19PKCkD33A6lCNAPdr2zqTSdYWa98WGrZLm8SoqvKpOU5VBf02we 2qxu6qClklNGmU/rtAZenViYLRdeJMI= X-MC-Unique: 3yxMaEeGPHaNvZt_BL5iXg-1 From: Gerd Hoffmann To: seabios@seabios.org Date: Thu, 19 Mar 2020 08:39:33 +0100 Message-Id: <20200319073937.5561-3-kraxel@redhat.com> In-Reply-To: <20200319073937.5561-1-kraxel@redhat.com> References: <20200319073937.5561-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Level: ***** Message-ID-Hash: QO7LKOELXOBA5TJADIPG243BBN77IJUC X-Message-ID-Hash: QO7LKOELXOBA5TJADIPG243BBN77IJUC X-MailFrom: kraxel@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Gerd Hoffmann X-Mailman-Version: 3.3.1 Precedence: list Subject: [SeaBIOS] [PATCH 2/6] paravirt/qemu: virtio-mmio device discovery List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: / X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Use bootorder fw_cfg file to find bootable virtio-mmio devices. Also add a new virtio-mmio.c source file, providing a function to register virtio-mmio devices. Signed-off-by: Gerd Hoffmann --- Makefile | 2 +- src/hw/virtio-mmio.h | 6 ++++++ src/fw/paravirt.c | 24 ++++++++++++++++++++++++ src/hw/virtio-mmio.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/hw/virtio-mmio.h create mode 100644 src/hw/virtio-mmio.c diff --git a/Makefile b/Makefile index 5f7d5370198a..985ef591a13b 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ SRC32FLAT=3D$(SRCBOTH) post.c e820map.c malloc.c romfile.= c x86.c optionroms.c \ fw/coreboot.c fw/lzmadecode.c fw/multiboot.c fw/csm.c fw/biostables.c \ fw/paravirt.c fw/shadow.c fw/pciinit.c fw/smm.c fw/smp.c fw/mtrr.c fw/= xen.c \ fw/acpi.c fw/mptable.c fw/pirtable.c fw/smbios.c fw/romfile_loader.c \ - hw/virtio-ring.c hw/virtio-pci.c hw/virtio-blk.c hw/virtio-scsi.c \ + hw/virtio-ring.c hw/virtio-pci.c hw/virtio-mmio.c hw/virtio-blk.c hw/v= irtio-scsi.c \ hw/tpm_drivers.c hw/nvme.c SRC32SEG=3Dstring.c output.c pcibios.c apm.c stacks.c hw/pci.c hw/serialio= .c DIRS=3Dsrc src/hw src/fw vgasrc diff --git a/src/hw/virtio-mmio.h b/src/hw/virtio-mmio.h new file mode 100644 index 000000000000..751984241f49 --- /dev/null +++ b/src/hw/virtio-mmio.h @@ -0,0 +1,6 @@ +#ifndef _VIRTIO_MMIO_H +#define _VIRTIO_MMIO_H + +void virtio_mmio_register(u64 mmio); + +#endif /* _VIRTIO_MMIO_H */ diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index 119280c574fd..aaaf8b8dad31 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -15,6 +15,7 @@ #include "hw/pcidevice.h" // pci_probe_devices #include "hw/pci_regs.h" // PCI_DEVICE_ID #include "hw/serialio.h" // PORT_SERIAL1 +#include "hw/virtio-mmio.h" // virtio_mmio_register #include "hw/rtc.h" // CMOS_* #include "malloc.h" // malloc_tmp #include "output.h" // dprintf @@ -192,6 +193,27 @@ static void msr_feature_control_setup(void) wrmsr_smp(MSR_IA32_FEATURE_CONTROL, feature_control_bits); } =20 +static void qemu_probe_virtio_mmio(void) +{ + char *data, *next; + int size; + u64 mmio; + + data =3D romfile_loadfile("bootorder", &size); + while (data) { + next =3D strchr(data, '\n'); + if (next) { + *next =3D '\0'; + next++; + } + if (memcmp("/virtio-mmio@", data, 13) =3D=3D 0) { + mmio =3D strtol(data+13, 16); + virtio_mmio_register(mmio); + } + data =3D next; + } +} + void qemu_platform_setup(void) { @@ -217,6 +239,8 @@ qemu_platform_setup(void) msr_feature_control_setup(); smp_setup(); =20 + qemu_probe_virtio_mmio(); + // Create bios tables if (MaxCountCPUs <=3D 255) { pirtable_setup(); diff --git a/src/hw/virtio-mmio.c b/src/hw/virtio-mmio.c new file mode 100644 index 000000000000..0f320921df30 --- /dev/null +++ b/src/hw/virtio-mmio.c @@ -0,0 +1,30 @@ +#include "config.h" // CONFIG_DEBUG_LEVEL +#include "malloc.h" // free +#include "output.h" // dprintf +#include "virtio-pci.h" +#include "virtio-ring.h" + +/* qemu microvm supports 8 virtio-mmio devices */ +static u64 devs[8]; + +void virtio_mmio_register(u64 mmio) +{ + int i; + + for (i =3D 0; i < ARRAY_SIZE(devs); i++) { + if (devs[i] =3D=3D mmio) { + /* + * This can happen in case we have multiple scsi devices + * attached to a single virtio-scsi controller + */ + dprintf(3, "virtio-mmio: duplicate device at 0x%llx, ignoring\= n", mmio); + return; + } + if (devs[i] =3D=3D 0) { + dprintf(1, "virtio-mmio: device at 0x%llx\n", mmio); + devs[i] =3D mmio; + return; + } + } + dprintf(1, "virtio-mmio: device list full\n"); +} --=20 2.18.2 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org From nobody Sun Feb 8 15:10:15 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584603999; cv=none; d=zohomail.com; s=zohoarc; b=ZIDGHx2gELQXWY71yAhuUeqzYOB0DqUmZ8B/5hgK+Uf5IKkzWmzLC44YbQZ5WR90epigdN8Sy0RezCro5arTLVBoEgc2sZAFjzv+Y79KiE3RUtOLXWx6yWRjXby6LDb+dCi1PZK18K18YmjPGJwdEc+75juegbemXXYfQwo94hY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584603999; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Subject:To; bh=/mRx7wW4psBHsxJr5VOZOpLin3Xhbykg47zqrHTcYyI=; b=YMf5Zc7Vu6ZjfDTnchwT/zKhBC89Nk3Jk8kAAqiCZHNxGkcoI0NW/O+q2UPFf+5kml/EAdPEMSd4QBCBkul4erB24AdDBtnJoaPcJhhfNnTuCw61z2idPwgdAL8mDaXmvt+HybKqKmKhYjXi1ZchF+HjN448w3X8BLjkPfFVZ4s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1584603999880468.0136441632101; Thu, 19 Mar 2020 00:46:39 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 57B75B01B19; Thu, 19 Mar 2020 07:46:36 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 59842B01B03 for ; Thu, 19 Mar 2020 07:46:05 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-200-BoXNttlENjCtfQUagcMU9Q-1; Thu, 19 Mar 2020 03:39:43 -0400 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 68643189F760 for ; Thu, 19 Mar 2020 07:39:42 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.corp.redhat.com (Postfix) with ESMTP id C48D15D9E2; Thu, 19 Mar 2020 07:39:39 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) id 0357C31F2D; Thu, 19 Mar 2020 08:39:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584603964; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T2MEu7iZUUh4P9FnvWteTD+PFFquxVdzbx/C2/SHUvw=; b=fkfPMNgHp6zJ8BTqnYtYW7Jk/4wbNZCHSHfpoYcuWKJvQG8j9UU9HSXni1C+RFzkfQjBRW AO4f+T5qTzOOL6dQ06+k2eKIxdq9FdPL2blLmSr6QBT9uVpmA35m/SRrXs8nVX1vaG6dCZ K1B0nwVHs6HJyTCYTd94iKvMspvlOWw= X-MC-Unique: BoXNttlENjCtfQUagcMU9Q-1 From: Gerd Hoffmann To: seabios@seabios.org Date: Thu, 19 Mar 2020 08:39:34 +0100 Message-Id: <20200319073937.5561-4-kraxel@redhat.com> In-Reply-To: <20200319073937.5561-1-kraxel@redhat.com> References: <20200319073937.5561-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: MPBVQY7JKDJ76GG3RQ5FBVJ5O6WS7VM3 X-Message-ID-Hash: MPBVQY7JKDJ76GG3RQ5FBVJ5O6WS7VM3 X-MailFrom: kraxel@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Gerd Hoffmann X-Mailman-Version: 3.3.1 Precedence: list Subject: [SeaBIOS] [PATCH 3/6] virtio-mmio: device probing and initialization. List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: ++++ X-Spam-Level: **** Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add virtio_mmio_setup() to probe virtio mmio devices. Add vp_init_mmio() to initialize device struct. Because virtio-pci and virtio-mmio are quite simliar we reuse the infrastructure we already have for virtio-pci and just setup struct vp_cap for virtio-mmio. Signed-off-by: Gerd Hoffmann --- src/hw/virtio-mmio.h | 71 ++++++++++++++++++++++++++++++++++++++++++++ src/hw/virtio-pci.h | 1 + src/block.c | 2 ++ src/hw/virtio-mmio.c | 49 ++++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+) diff --git a/src/hw/virtio-mmio.h b/src/hw/virtio-mmio.h index 751984241f49..5e24f692c1ae 100644 --- a/src/hw/virtio-mmio.h +++ b/src/hw/virtio-mmio.h @@ -1,6 +1,77 @@ #ifndef _VIRTIO_MMIO_H #define _VIRTIO_MMIO_H =20 +struct vp_device; + +typedef struct virtio_mmio_cfg { + u32 magic; + u32 version; + u32 device_id; + u32 vendor_id; + + u32 device_feature; + u32 device_feature_select; + u32 res_18; + u32 res_1c; + + u32 guest_feature; + u32 guest_feature_select; + u32 legacy_guest_page_size; + u32 res_2c; + + u32 queue_select; + u32 queue_num_max; + u32 queue_num; + u32 legacy_queue_align; + + u32 legacy_queue_pfn; + u32 queue_ready; + u32 res_48; + u32 res_4c; + + u32 queue_notify; + u32 res_54; + u32 res_58; + u32 res_5c; + + u32 irq_status; + u32 irq_ack; + u32 res_68; + u32 res_6c; + + u32 device_status; + u32 res_74; + u32 res_78; + u32 res_7c; + + u32 queue_desc_lo; + u32 queue_desc_hi; + u32 res_88; + u32 res_8c; + + u32 queue_driver_lo; + u32 queue_driver_hi; + u32 res_98; + u32 res_9c; + + u32 queue_device_lo; + u32 queue_device_hi; + u32 res_a8; + u32 shm_sel; + + u32 shmem_len_lo; + u32 shmem_len_hi; + u32 shmem_base_lo; + u32 shmem_base_hi; + + u32 res_c0_f7[14]; + + u32 res_f8; + u32 config_generation; +} virtio_mmio_cfg; + void virtio_mmio_register(u64 mmio); +void virtio_mmio_setup(void); +void vp_init_mmio(struct vp_device *vp, void *mmio); =20 #endif /* _VIRTIO_MMIO_H */ diff --git a/src/hw/virtio-pci.h b/src/hw/virtio-pci.h index 492e5c7c9166..269626448558 100644 --- a/src/hw/virtio-pci.h +++ b/src/hw/virtio-pci.h @@ -111,6 +111,7 @@ struct vp_device { struct vp_cap common, notify, isr, device, legacy; u32 notify_off_multiplier; u8 use_modern; + u8 use_mmio; }; =20 u64 _vp_read(struct vp_cap *cap, u32 offset, u8 size); diff --git a/src/block.c b/src/block.c index 1f600b85391b..9ef607610c40 100644 --- a/src/block.c +++ b/src/block.c @@ -20,6 +20,7 @@ #include "hw/usb-uas.h" // uas_process_op #include "hw/virtio-blk.h" // process_virtio_blk_op #include "hw/virtio-scsi.h" // virtio_scsi_process_op +#include "hw/virtio-mmio.h" // virtio_mmio_setup #include "hw/nvme.h" // nvme_process_op #include "malloc.h" // malloc_low #include "output.h" // dprintf @@ -514,6 +515,7 @@ block_setup(void) ramdisk_setup(); virtio_blk_setup(); virtio_scsi_setup(); + virtio_mmio_setup(); lsi_scsi_setup(); esp_scsi_setup(); megasas_setup(); diff --git a/src/hw/virtio-mmio.c b/src/hw/virtio-mmio.c index 0f320921df30..d9068c7c035b 100644 --- a/src/hw/virtio-mmio.c +++ b/src/hw/virtio-mmio.c @@ -1,8 +1,11 @@ #include "config.h" // CONFIG_DEBUG_LEVEL #include "malloc.h" // free #include "output.h" // dprintf +#include "stacks.h" // run_thread +#include "string.h" // memset #include "virtio-pci.h" #include "virtio-ring.h" +#include "virtio-mmio.h" =20 /* qemu microvm supports 8 virtio-mmio devices */ static u64 devs[8]; @@ -28,3 +31,49 @@ void virtio_mmio_register(u64 mmio) } dprintf(1, "virtio-mmio: device list full\n"); } + +void virtio_mmio_setup(void) +{ + u32 magic, version, devid; + void *mmio; + int i; + + for (i =3D 0; i < ARRAY_SIZE(devs); i++) { + if (devs[i] =3D=3D 0) + return; + mmio =3D (void*)(u32)(devs[i]); + magic =3D readl(mmio); + if (magic !=3D 0x74726976) + continue; + version =3D readl(mmio+4); + if (version !=3D 1 /* legacy */ && + version !=3D 2 /* 1.0 */) + continue; + devid =3D readl(mmio+8); + dprintf(1, "virtio-mmio: %llx: device id %x%s\n", + devs[i], devid, version =3D=3D 1 ? " (legacy)" : ""); + switch (devid) { + case 2: /* blk */ + /* TODO */ + break; + case 8: /* scsi */ + /* TODO */ + break; + default: + break; + } + } +} + +void vp_init_mmio(struct vp_device *vp, void *mmio) +{ + memset(vp, 0, sizeof(*vp)); + vp->use_mmio =3D 1; + vp->common.mode =3D VP_ACCESS_MMIO; + vp->common.memaddr =3D mmio; + vp->device.mode =3D VP_ACCESS_MMIO; + vp->device.memaddr =3D mmio + 0x100; + vp_reset(vp); + vp_set_status(vp, VIRTIO_CONFIG_S_ACKNOWLEDGE | + VIRTIO_CONFIG_S_DRIVER); +} --=20 2.18.2 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org From nobody Sun Feb 8 15:10:15 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584603988; cv=none; d=zohomail.com; s=zohoarc; b=fZjPKP2it9Lp+0Ej5yj1dX6gCZ3R97shxjtSxgmMXTvE8zbAxtwYIK4WlWslBQBfKyvsryzYFv5RbSMy6YEzYpRTwjLS94PGaWtPX0pSTwZuuhsQ3zLYJlsR/ugXw09TJhcl5SojJx9DRlRb1K5OolOnzsE6Ha75TanfoVUTLtc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584603988; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Subject:To; bh=MwloAa4u7F70S2fySVnpIK0AFwQM2MUj7p3G5hbkr1w=; b=Oasl1/Sb38mivyCkZ5DZz2sLI7LhHmzI3CXQMtmKYvlKa7Wb7Z9kZrIxgf+t3Hgb5z+OuhIJ1+pOh6jxjeiTgtal/ONvWv0zsh8FnHJhJ0dMXaQ+/Q7KNzbeEWCvv5kFvEI0ttkSyeXgSODIV3JPS3uBNrck2iBcCICy5QhFQPE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1584603988114122.60940591542578; Thu, 19 Mar 2020 00:46:28 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 15DC3B01B19; Thu, 19 Mar 2020 07:46:23 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 5AF1DB01B19 for ; Thu, 19 Mar 2020 07:46:05 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-375-4sq_ZwWlNTSzkdyPBxDFug-1; Thu, 19 Mar 2020 03:39:43 -0400 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9FE73800D50 for ; Thu, 19 Mar 2020 07:39:42 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.corp.redhat.com (Postfix) with ESMTP id C505860BEE; Thu, 19 Mar 2020 07:39:39 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) id 059D231F3B; Thu, 19 Mar 2020 08:39:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584603964; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MOkgIlEw0GKmYZABAz6WoX9ib6y5sw03PWFACNKSNWs=; b=MAnqa4Bh+6RP7X1YC1mV6DK3pbYD5+Rj/biMnkVlUJSZ6DKZIH3smbhNd0ZMGFFNBbculF bv4XAfSJY5om/blS/9swjStilcr7D7sJyR/y/BnazE0Jle45zNX/OOuFPTCdaEUousumOm tOrr84kgtEqKX31JFHoRCGUAvyGOQqQ= X-MC-Unique: 4sq_ZwWlNTSzkdyPBxDFug-1 From: Gerd Hoffmann To: seabios@seabios.org Date: Thu, 19 Mar 2020 08:39:35 +0100 Message-Id: <20200319073937.5561-5-kraxel@redhat.com> In-Reply-To: <20200319073937.5561-1-kraxel@redhat.com> References: <20200319073937.5561-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: WELFO5WACUJBXICL7WK5Z4NDIUMTNHNA X-Message-ID-Hash: WELFO5WACUJBXICL7WK5Z4NDIUMTNHNA X-MailFrom: kraxel@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Gerd Hoffmann X-Mailman-Version: 3.3.1 Precedence: list Subject: [SeaBIOS] [PATCH 4/6] virtio-mmio: add support to vp_*() functions List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: ++++ X-Spam-Level: **** Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add support for virtio-mmio to the vp_*() helper functions. Both legacy and 1.0 virto-mmio versions are supported. They are very simliar anyway, only the virtqueue initialization is slightly different. Signed-off-by: Gerd Hoffmann --- src/hw/virtio-pci.c | 68 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 11 deletions(-) diff --git a/src/hw/virtio-pci.c b/src/hw/virtio-pci.c index d5435218fb0a..213c49777c40 100644 --- a/src/hw/virtio-pci.c +++ b/src/hw/virtio-pci.c @@ -23,6 +23,7 @@ #include "pci_regs.h" // PCI_BASE_ADDRESS_0 #include "string.h" // memset #include "virtio-pci.h" +#include "virtio-mmio.h" #include "virtio-ring.h" =20 u64 _vp_read(struct vp_cap *cap, u32 offset, u8 size) @@ -189,7 +190,11 @@ u64 vp_get_features(struct vp_device *vp) { u32 f0, f1; =20 - if (vp->use_modern) { + if (vp->use_mmio) { + vp_write(&vp->common, virtio_mmio_cfg, device_feature_select, 0); + f0 =3D vp_read(&vp->common, virtio_mmio_cfg, device_feature); + f1 =3D 0; + } else if (vp->use_modern) { vp_write(&vp->common, virtio_pci_common_cfg, device_feature_select= , 0); f0 =3D vp_read(&vp->common, virtio_pci_common_cfg, device_feature); vp_write(&vp->common, virtio_pci_common_cfg, device_feature_select= , 1); @@ -208,7 +213,10 @@ void vp_set_features(struct vp_device *vp, u64 feature= s) f0 =3D features; f1 =3D features >> 32; =20 - if (vp->use_modern) { + if (vp->use_mmio) { + vp_write(&vp->common, virtio_mmio_cfg, guest_feature_select, f0); + vp_write(&vp->common, virtio_mmio_cfg, guest_feature, f0); + } else if (vp->use_modern) { vp_write(&vp->common, virtio_pci_common_cfg, guest_feature_select,= 0); vp_write(&vp->common, virtio_pci_common_cfg, guest_feature, f0); vp_write(&vp->common, virtio_pci_common_cfg, guest_feature_select,= 1); @@ -220,7 +228,9 @@ void vp_set_features(struct vp_device *vp, u64 features) =20 u8 vp_get_status(struct vp_device *vp) { - if (vp->use_modern) { + if (vp->use_mmio) { + return vp_read(&vp->common, virtio_mmio_cfg, device_status); + } else if (vp->use_modern) { return vp_read(&vp->common, virtio_pci_common_cfg, device_status); } else { return vp_read(&vp->legacy, virtio_pci_legacy, status); @@ -231,7 +241,9 @@ void vp_set_status(struct vp_device *vp, u8 status) { if (status =3D=3D 0) /* reset */ return; - if (vp->use_modern) { + if (vp->use_mmio) { + vp_write(&vp->common, virtio_mmio_cfg, device_status, status); + } else if (vp->use_modern) { vp_write(&vp->common, virtio_pci_common_cfg, device_status, status= ); } else { vp_write(&vp->legacy, virtio_pci_legacy, status, status); @@ -240,7 +252,9 @@ void vp_set_status(struct vp_device *vp, u8 status) =20 u8 vp_get_isr(struct vp_device *vp) { - if (vp->use_modern) { + if (vp->use_mmio) { + return vp_read(&vp->common, virtio_mmio_cfg, irq_status); + } else if (vp->use_modern) { return vp_read(&vp->isr, virtio_pci_isr, isr); } else { return vp_read(&vp->legacy, virtio_pci_legacy, isr); @@ -249,7 +263,10 @@ u8 vp_get_isr(struct vp_device *vp) =20 void vp_reset(struct vp_device *vp) { - if (vp->use_modern) { + if (vp->use_mmio) { + vp_write(&vp->common, virtio_mmio_cfg, device_status, 0); + vp_read(&vp->common, virtio_mmio_cfg, irq_status); + } else if (vp->use_modern) { vp_write(&vp->common, virtio_pci_common_cfg, device_status, 0); vp_read(&vp->isr, virtio_pci_isr, isr); } else { @@ -260,7 +277,9 @@ void vp_reset(struct vp_device *vp) =20 void vp_notify(struct vp_device *vp, struct vring_virtqueue *vq) { - if (vp->use_modern) { + if (vp->use_mmio) { + vp_write(&vp->common, virtio_mmio_cfg, queue_notify, vq->queue_ind= ex); + } else if (vp->use_modern) { u32 offset =3D vq->queue_notify_off * vp->notify_off_multiplier; switch (vp->notify.mode) { case VP_ACCESS_IO: @@ -305,14 +324,21 @@ int vp_find_vq(struct vp_device *vp, int queue_index, =20 =20 /* select the queue */ - if (vp->use_modern) { + if (vp->use_mmio) { + vp_write(&vp->common, virtio_mmio_cfg, queue_select, queue_index); + } else if (vp->use_modern) { vp_write(&vp->common, virtio_pci_common_cfg, queue_select, queue_in= dex); } else { vp_write(&vp->legacy, virtio_pci_legacy, queue_sel, queue_index); } =20 /* check if the queue is available */ - if (vp->use_modern) { + if (vp->use_mmio) { + num =3D vp_read(&vp->common, virtio_mmio_cfg, queue_num_max); + if (num > MAX_QUEUE_NUM) + num =3D MAX_QUEUE_NUM; + vp_write(&vp->common, virtio_mmio_cfg, queue_num, num); + } else if (vp->use_modern) { num =3D vp_read(&vp->common, virtio_pci_common_cfg, queue_size); if (num > MAX_QUEUE_NUM) { vp_write(&vp->common, virtio_pci_common_cfg, queue_size, @@ -332,7 +358,9 @@ int vp_find_vq(struct vp_device *vp, int queue_index, } =20 /* check if the queue is already active */ - if (vp->use_modern) { + if (vp->use_mmio) { + /* TODO */; + } else if (vp->use_modern) { if (vp_read(&vp->common, virtio_pci_common_cfg, queue_enable)) { dprintf(1, "ERROR: queue already active\n"); goto fail; @@ -354,7 +382,25 @@ int vp_find_vq(struct vp_device *vp, int queue_index, * NOTE: vr->desc is initialized by vring_init() */ =20 - if (vp->use_modern) { + if (vp->use_mmio) { + if (vp_read(&vp->common, virtio_mmio_cfg, version) =3D=3D 2) { + vp_write(&vp->common, virtio_mmio_cfg, queue_desc_lo, + (unsigned long)virt_to_phys(vr->desc)); + vp_write(&vp->common, virtio_mmio_cfg, queue_desc_hi, 0); + vp_write(&vp->common, virtio_mmio_cfg, queue_driver_lo, + (unsigned long)virt_to_phys(vr->avail)); + vp_write(&vp->common, virtio_mmio_cfg, queue_driver_hi, 0); + vp_write(&vp->common, virtio_mmio_cfg, queue_device_lo, + (unsigned long)virt_to_phys(vr->used)); + vp_write(&vp->common, virtio_mmio_cfg, queue_device_hi, 0); + vp_write(&vp->common, virtio_mmio_cfg, queue_ready, 1); + } else { + vp_write(&vp->common, virtio_mmio_cfg, legacy_guest_page_size, + (unsigned long)1 << PAGE_SHIFT); + vp_write(&vp->common, virtio_mmio_cfg, legacy_queue_pfn, + (unsigned long)virt_to_phys(vr->desc) >> PAGE_SHIFT); + } + } else if (vp->use_modern) { vp_write(&vp->common, virtio_pci_common_cfg, queue_desc_lo, (unsigned long)virt_to_phys(vr->desc)); vp_write(&vp->common, virtio_pci_common_cfg, queue_desc_hi, 0); --=20 2.18.2 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org From nobody Sun Feb 8 15:10:15 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584604047; cv=none; d=zohomail.com; s=zohoarc; b=gornUiG94PXoVgLnepQlzkGbU0DPn5coKDpPF/RroQ+mgBiAHMFbnyqBLhDCY4SbDUjykBWjIhOoZKwA7J+6FskIBdr794LJOE3bPyUjEiiheNKbkTXDpmppWCQ0wi8cvOKvIlZUIX2VFvvq1FTzwasyDG36O6ZSheuZABemhfM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584604047; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Subject:To; bh=TX84ivDe8LJOOsazFaV+haiWZ9IeF8WrkAhSr/t7n30=; b=iF4QTh2ynsAvl0VhprS4rq2t1Fsms8f8PVISXVv+P2JGT6RJNlBfwQyq4m6tOay44LweODeXg1RNSWjSKf2GNrsAf1wVrLnbzXhQF8rnNd5OVfgQYU1YVzizz/dQVny3gNuKPR/MgK77c/m7q7rP3QYhHx8q+k+W8ynQ32Qq6Kg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1584604047146989.8007761174881; Thu, 19 Mar 2020 00:47:27 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id A24EFB01B48; Thu, 19 Mar 2020 07:47:23 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 80F8CB01B28 for ; Thu, 19 Mar 2020 07:46:08 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-477-521kT_QWN5Osvuzqi1rU-w-1; Thu, 19 Mar 2020 03:39:47 -0400 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A607A107ACC7 for ; Thu, 19 Mar 2020 07:39:46 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.corp.redhat.com (Postfix) with ESMTP id 116041001925; Thu, 19 Mar 2020 07:39:43 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) id 07F5831F48; Thu, 19 Mar 2020 08:39:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584603967; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eSDLR41ghJVIyMikH/ufEMBYxDSLY+N00b75Axxqxlw=; b=ivhZheHKZgtL5wBNh1iv6J61H5On47OarjxMuEHxtvR5sZtfhVMsVZwBo5pq0W3t2Cxsns 4+UWneC7FzmxLzrk1RCBDKIFa3qSoRVKdKGOYbjlLdMtLVkjPB8Wu4GERedzwbmx1bojZv +SVk+jybrYn672YM52240obgTZOUflc= X-MC-Unique: 521kT_QWN5Osvuzqi1rU-w-1 From: Gerd Hoffmann To: seabios@seabios.org Date: Thu, 19 Mar 2020 08:39:36 +0100 Message-Id: <20200319073937.5561-6-kraxel@redhat.com> In-Reply-To: <20200319073937.5561-1-kraxel@redhat.com> References: <20200319073937.5561-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Level: ***** Message-ID-Hash: ZEFTOGTYJX7GWLFC5SIOOECKU6JP6WCU X-Message-ID-Hash: ZEFTOGTYJX7GWLFC5SIOOECKU6JP6WCU X-MailFrom: kraxel@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Gerd Hoffmann X-Mailman-Version: 3.3.1 Precedence: list Subject: [SeaBIOS] [PATCH 5/6] virtio-mmio: add support for scsi devices. List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: / X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add new fields to struct virtio_lun_s for mmio support, add mmio parameter to virtio_scsi_init_lun(), so both pci and mmio devices can be handled. Add and use bootprio_find_scsi_mmio_device() to figure boot priority of devices connected to a virtio-mmio scsi controller. Finally add init_virtio_scsi_mmio() to initialize one virtio-mmio scsi controller. Signed-off-by: Gerd Hoffmann --- src/hw/virtio-scsi.h | 1 + src/util.h | 1 + src/boot.c | 10 ++++++ src/hw/virtio-mmio.c | 3 +- src/hw/virtio-scsi.c | 73 +++++++++++++++++++++++++++++++++++++------- 5 files changed, 76 insertions(+), 12 deletions(-) diff --git a/src/hw/virtio-scsi.h b/src/hw/virtio-scsi.h index 7532cc98e56e..8f01de4cba99 100644 --- a/src/hw/virtio-scsi.h +++ b/src/hw/virtio-scsi.h @@ -43,5 +43,6 @@ struct virtio_scsi_resp_cmd { struct disk_op_s; int virtio_scsi_process_op(struct disk_op_s *op); void virtio_scsi_setup(void); +void init_virtio_scsi_mmio(void *data); =20 #endif /* _VIRTIO_SCSI_H */ diff --git a/src/util.h b/src/util.h index 94592a2d2e8d..1c82e09ed87b 100644 --- a/src/util.h +++ b/src/util.h @@ -31,6 +31,7 @@ u8 is_bootprio_strict(void); struct pci_device; int bootprio_find_pci_device(struct pci_device *pci); int bootprio_find_scsi_device(struct pci_device *pci, int target, int lun); +int bootprio_find_scsi_mmio_device(void *mmio, int target, int lun); int bootprio_find_ata_device(struct pci_device *pci, int chanid, int slave= ); int bootprio_find_fdc_device(struct pci_device *pci, int port, int fdid); int bootprio_find_pci_rom(struct pci_device *pci, int instance); diff --git a/src/boot.c b/src/boot.c index 4f12988f687c..f2f084bea843 100644 --- a/src/boot.c +++ b/src/boot.c @@ -328,6 +328,16 @@ int bootprio_find_scsi_device(struct pci_device *pci, = int target, int lun) return find_prio(desc); } =20 +int bootprio_find_scsi_mmio_device(void *mmio, int target, int lun) +{ + if (!CONFIG_BOOTORDER) + return -1; + char desc[256]; + snprintf(desc, sizeof(desc), "/virtio-mmio@%016x/*@0/*@%x,%x", + (u32)mmio, target, lun); + return find_prio(desc); +} + int bootprio_find_ata_device(struct pci_device *pci, int chanid, int slave) { if (CONFIG_CSM) diff --git a/src/hw/virtio-mmio.c b/src/hw/virtio-mmio.c index d9068c7c035b..3b514d944a9d 100644 --- a/src/hw/virtio-mmio.c +++ b/src/hw/virtio-mmio.c @@ -4,6 +4,7 @@ #include "stacks.h" // run_thread #include "string.h" // memset #include "virtio-pci.h" +#include "virtio-scsi.h" #include "virtio-ring.h" #include "virtio-mmio.h" =20 @@ -57,7 +58,7 @@ void virtio_mmio_setup(void) /* TODO */ break; case 8: /* scsi */ - /* TODO */ + run_thread(init_virtio_scsi_mmio, mmio); break; default: break; diff --git a/src/hw/virtio-scsi.c b/src/hw/virtio-scsi.c index a5332848b8c8..59f1c654d76b 100644 --- a/src/hw/virtio-scsi.c +++ b/src/hw/virtio-scsi.c @@ -22,10 +22,13 @@ #include "virtio-pci.h" #include "virtio-ring.h" #include "virtio-scsi.h" +#include "virtio-mmio.h" =20 struct virtio_lun_s { struct drive_s drive; struct pci_device *pci; + void *mmio; + char name[16]; struct vring_virtqueue *vq; struct vp_device *vp; u16 target; @@ -94,7 +97,8 @@ virtio_scsi_process_op(struct disk_op_s *op) } =20 static void -virtio_scsi_init_lun(struct virtio_lun_s *vlun, struct pci_device *pci, +virtio_scsi_init_lun(struct virtio_lun_s *vlun, + struct pci_device *pci, void *mmio, struct vp_device *vp, struct vring_virtqueue *vq, u16 target, u16 lun) { @@ -102,10 +106,15 @@ virtio_scsi_init_lun(struct virtio_lun_s *vlun, struc= t pci_device *pci, vlun->drive.type =3D DTYPE_VIRTIO_SCSI; vlun->drive.cntl_id =3D pci->bdf; vlun->pci =3D pci; + vlun->mmio =3D mmio; vlun->vp =3D vp; vlun->vq =3D vq; vlun->target =3D target; vlun->lun =3D lun; + if (vlun->pci) + snprintf(vlun->name, sizeof(vlun->name), "pci:%pP", vlun->pci); + if (vlun->mmio) + snprintf(vlun->name, sizeof(vlun->name), "mmio:%08x", (u32)vlun->m= mio); } =20 static int @@ -114,12 +123,17 @@ virtio_scsi_add_lun(u32 lun, struct drive_s *tmpl_drv) u8 skip_nonbootable =3D is_bootprio_strict(); struct virtio_lun_s *tmpl_vlun =3D container_of(tmpl_drv, struct virtio_lun_s, drive); - int prio =3D bootprio_find_scsi_device(tmpl_vlun->pci, tmpl_vlun->targ= et, tmpl_vlun->lun); + int prio =3D -1; + + if (tmpl_vlun->pci) + prio =3D bootprio_find_scsi_device(tmpl_vlun->pci, tmpl_vlun->targ= et, tmpl_vlun->lun); + if (tmpl_vlun->mmio) + prio =3D bootprio_find_scsi_mmio_device(tmpl_vlun->mmio, tmpl_vlun= ->target, tmpl_vlun->lun); =20 if (skip_nonbootable && prio < 0) { - dprintf(1, "skipping init of a non-bootable virtio-scsi dev at %pP= ," + dprintf(1, "skipping init of a non-bootable virtio-scsi dev at %s," " target %d, lun %d\n", - tmpl_vlun->pci, tmpl_vlun->target, tmpl_vlun->lun); + tmpl_vlun->name, tmpl_vlun->target, tmpl_vlun->lun); return -1; } =20 @@ -128,11 +142,12 @@ virtio_scsi_add_lun(u32 lun, struct drive_s *tmpl_drv) warn_noalloc(); return -1; } - virtio_scsi_init_lun(vlun, tmpl_vlun->pci, tmpl_vlun->vp, tmpl_vlun->v= q, - tmpl_vlun->target, lun); + virtio_scsi_init_lun(vlun, tmpl_vlun->pci, tmpl_vlun->mmio,tmpl_vlun->= vp, + tmpl_vlun->vq, tmpl_vlun->target, lun); =20 - boot_lchs_find_scsi_device(vlun->pci, vlun->target, vlun->lun, - &(vlun->drive.lchs)); + if (vlun->pci) + boot_lchs_find_scsi_device(vlun->pci, vlun->target, vlun->lun, + &(vlun->drive.lchs)); int ret =3D scsi_drive_setup(&vlun->drive, "virtio-scsi", prio); if (ret) goto fail; @@ -144,13 +159,13 @@ fail: } =20 static int -virtio_scsi_scan_target(struct pci_device *pci, struct vp_device *vp, +virtio_scsi_scan_target(struct pci_device *pci, void *mmio, struct vp_devi= ce *vp, struct vring_virtqueue *vq, u16 target) { =20 struct virtio_lun_s vlun0; =20 - virtio_scsi_init_lun(&vlun0, pci, vp, vq, target, 0); + virtio_scsi_init_lun(&vlun0, pci, mmio, vp, vq, target, 0); =20 int ret =3D scsi_rep_luns_scan(&vlun0.drive, virtio_scsi_add_lun); return ret < 0 ? 0 : ret; @@ -198,7 +213,43 @@ init_virtio_scsi(void *data) =20 int i, tot; for (tot =3D 0, i =3D 0; i < 256; i++) - tot +=3D virtio_scsi_scan_target(pci, vp, vq, i); + tot +=3D virtio_scsi_scan_target(pci, NULL, vp, vq, i); + + if (!tot) + goto fail; + + return; + +fail: + vp_reset(vp); + free(vp); + free(vq); +} + +void +init_virtio_scsi_mmio(void *mmio) +{ + dprintf(1, "found virtio-scsi-mmio at %p\n", mmio); + struct vring_virtqueue *vq =3D NULL; + struct vp_device *vp =3D malloc_high(sizeof(*vp)); + if (!vp) { + warn_noalloc(); + return; + } + vp_init_mmio(vp, mmio); + u8 status =3D VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER; + + if (vp_find_vq(vp, 2, &vq) < 0 ) { + dprintf(1, "fail to find vq for virtio-scsi-mmio %p\n", mmio); + goto fail; + } + + status |=3D VIRTIO_CONFIG_S_DRIVER_OK; + vp_set_status(vp, status); + + int i, tot; + for (tot =3D 0, i =3D 0; i < 256; i++) + tot +=3D virtio_scsi_scan_target(NULL, mmio, vp, vq, i); =20 if (!tot) goto fail; --=20 2.18.2 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org From nobody Sun Feb 8 15:10:15 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584604023; cv=none; d=zohomail.com; s=zohoarc; b=I0++hlDiAYXccW4zSfl/C2SI50EIgelQaEgvdyXzv4aw89Ddp69Pxx+m7vsBAF2WNNV387kPRZ5N9kTOgL0IEs1//lR1EJZyo7MAYu2hWhN5OdloNSOkpFiK2VjM5U3NDQyzCSNWPaQsj3G3dLnftAzPzAH/o3yDRGzejUHIOFw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584604023; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Subject:To; bh=/k28EW02i3+5VnTlGpbC758aVA9HIVYjwCGdQEvoRYU=; b=Okt0FZqGKp/VxfOhIgPOAkbJtqxSJgvJURdjRmq0AsRtYsPTl8GA+90QAZtFHsCDAiSKVYyo/iunR/WNlJQMMxGa5cxksTpxm4IxhFDMRTAfQgmuy86aSKxyKmwVWhKyU73Hfd3xNYRnD5ljXRf56nwzz40f0r0vqildTw9EV3s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1584604023382888.8420576271352; Thu, 19 Mar 2020 00:47:03 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 27974B01B39; Thu, 19 Mar 2020 07:46:59 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id CD92BB01B1D for ; Thu, 19 Mar 2020 07:46:05 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-117-ex4H4wT8MkqRv--eLKaeQA-1; Thu, 19 Mar 2020 03:39:47 -0400 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 842C0477 for ; Thu, 19 Mar 2020 07:39:46 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.corp.redhat.com (Postfix) with ESMTP id 101D460BEC; Thu, 19 Mar 2020 07:39:43 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) id 0A41B31F62; Thu, 19 Mar 2020 08:39:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584603964; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aJ0txXlREWwiNzo0dvRa2ifPwdBS9ecPZI37bu/QjUM=; b=MuUZcV1Jx6Zvlnrt45aFt6VEbmUNlh8hr4K/b3kfJVsOSUgmJWfjdfG405hxb3GA3Y+hS+ zEZCjmGwkofEL8+xwB1nwgtqcVQh3wy84WqIPNrcG8EvtTrIN9gqAyYq8Rcji4F0nKBCAo ey0oMQDjfxkreB3k68DjF4PBNoQ7cik= X-MC-Unique: ex4H4wT8MkqRv--eLKaeQA-1 From: Gerd Hoffmann To: seabios@seabios.org Date: Thu, 19 Mar 2020 08:39:37 +0100 Message-Id: <20200319073937.5561-7-kraxel@redhat.com> In-Reply-To: <20200319073937.5561-1-kraxel@redhat.com> References: <20200319073937.5561-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: YHRDSMDMRDB4FA4L2FNY7PTJFKS6PU4M X-Message-ID-Hash: YHRDSMDMRDB4FA4L2FNY7PTJFKS6PU4M X-MailFrom: kraxel@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Gerd Hoffmann X-Mailman-Version: 3.3.1 Precedence: list Subject: [SeaBIOS] [PATCH 6/6] virtio-mmio: add support for block devices. List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: ++++ X-Spam-Level: **** Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add and use bootprio_find_mmio_device() to figure the boot priority of virtio-mmio block devices. Add init_virtio_blk_mmio to initialize one virtio-mmio block device. Signed-off-by: Gerd Hoffmann --- src/hw/virtio-blk.h | 1 + src/util.h | 1 + src/boot.c | 9 ++++++ src/hw/virtio-blk.c | 71 ++++++++++++++++++++++++++++++++++++++++++++ src/hw/virtio-mmio.c | 3 +- 5 files changed, 84 insertions(+), 1 deletion(-) diff --git a/src/hw/virtio-blk.h b/src/hw/virtio-blk.h index 157bed62744a..d20461a2a3b2 100644 --- a/src/hw/virtio-blk.h +++ b/src/hw/virtio-blk.h @@ -39,5 +39,6 @@ struct virtio_blk_outhdr { struct disk_op_s; int virtio_blk_process_op(struct disk_op_s *op); void virtio_blk_setup(void); +void init_virtio_blk_mmio(void *mmio); =20 #endif /* _VIRTIO_BLK_H */ diff --git a/src/util.h b/src/util.h index 1c82e09ed87b..4f27fc307439 100644 --- a/src/util.h +++ b/src/util.h @@ -30,6 +30,7 @@ void bcv_prepboot(void); u8 is_bootprio_strict(void); struct pci_device; int bootprio_find_pci_device(struct pci_device *pci); +int bootprio_find_mmio_device(void *mmio); int bootprio_find_scsi_device(struct pci_device *pci, int target, int lun); int bootprio_find_scsi_mmio_device(void *mmio, int target, int lun); int bootprio_find_ata_device(struct pci_device *pci, int chanid, int slave= ); diff --git a/src/boot.c b/src/boot.c index f2f084bea843..cc87b1d98476 100644 --- a/src/boot.c +++ b/src/boot.c @@ -316,6 +316,15 @@ int bootprio_find_pci_device(struct pci_device *pci) return find_prio(desc); } =20 +int bootprio_find_mmio_device(void *mmio) +{ + if (!CONFIG_BOOTORDER) + return -1; + char desc[256]; + snprintf(desc, sizeof(desc), "/virtio-mmio@%016x/*", (u32)mmio); + return find_prio(desc); +} + int bootprio_find_scsi_device(struct pci_device *pci, int target, int lun) { if (!CONFIG_BOOTORDER) diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index a5e28fc858b1..3b198965c8ba 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -20,6 +20,7 @@ #include "string.h" // memset #include "util.h" // usleep, bootprio_find_pci_device, is_bootprio_strict #include "virtio-pci.h" +#include "virtio-mmio.h" #include "virtio-ring.h" #include "virtio-blk.h" =20 @@ -193,6 +194,76 @@ fail: free(vdrive); } =20 +void +init_virtio_blk_mmio(void *mmio) +{ + u8 status =3D VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER; + dprintf(1, "found virtio-blk-mmio at %p\n", mmio); + struct virtiodrive_s *vdrive =3D malloc_low(sizeof(*vdrive)); + if (!vdrive) { + warn_noalloc(); + return; + } + memset(vdrive, 0, sizeof(*vdrive)); + vdrive->drive.type =3D DTYPE_VIRTIO_BLK; + vdrive->drive.cntl_id =3D (u32)mmio; + + vp_init_mmio(&vdrive->vp, mmio); + if (vp_find_vq(&vdrive->vp, 0, &vdrive->vq) < 0 ) { + dprintf(1, "fail to find vq for virtio-blk-mmio %p\n", mmio); + goto fail; + } + + struct vp_device *vp =3D &vdrive->vp; + u64 features =3D vp_get_features(vp); + u64 version1 =3D 1ull << VIRTIO_F_VERSION_1; + u64 blk_size =3D 1ull << VIRTIO_BLK_F_BLK_SIZE; + + features =3D features & (version1 | blk_size); + vp_set_features(vp, features); + status |=3D VIRTIO_CONFIG_S_FEATURES_OK; + vp_set_status(vp, status); + if (!(vp_get_status(vp) & VIRTIO_CONFIG_S_FEATURES_OK)) { + dprintf(1, "device didn't accept features: %p\n", mmio); + goto fail; + } + + vdrive->drive.sectors =3D + vp_read(&vp->device, struct virtio_blk_config, capacity); + if (features & blk_size) { + vdrive->drive.blksize =3D + vp_read(&vp->device, struct virtio_blk_config, blk_size); + } else { + vdrive->drive.blksize =3D DISK_SECTOR_SIZE; + } + if (vdrive->drive.blksize !=3D DISK_SECTOR_SIZE) { + dprintf(1, "virtio-blk-mmio %p block size %d is unsupported\n", + mmio, vdrive->drive.blksize); + goto fail; + } + dprintf(1, "virtio-blk-mmio %p blksize=3D%d sectors=3D%u\n", + mmio, vdrive->drive.blksize, (u32)vdrive->drive.sectors); + + vdrive->drive.pchs.cylinder =3D + vp_read(&vp->device, struct virtio_blk_config, cylinders); + vdrive->drive.pchs.head =3D + vp_read(&vp->device, struct virtio_blk_config, heads); + vdrive->drive.pchs.sector =3D + vp_read(&vp->device, struct virtio_blk_config, sectors); + + char *desc =3D znprintf(MAXDESCSIZE, "Virtio disk mmio:%p", mmio); + boot_add_hd(&vdrive->drive, desc, bootprio_find_mmio_device(mmio)); + + status |=3D VIRTIO_CONFIG_S_DRIVER_OK; + vp_set_status(&vdrive->vp, status); + return; + +fail: + vp_reset(&vdrive->vp); + free(vdrive->vq); + free(vdrive); +} + void virtio_blk_setup(void) { diff --git a/src/hw/virtio-mmio.c b/src/hw/virtio-mmio.c index 3b514d944a9d..30834ee372b1 100644 --- a/src/hw/virtio-mmio.c +++ b/src/hw/virtio-mmio.c @@ -4,6 +4,7 @@ #include "stacks.h" // run_thread #include "string.h" // memset #include "virtio-pci.h" +#include "virtio-blk.h" #include "virtio-scsi.h" #include "virtio-ring.h" #include "virtio-mmio.h" @@ -55,7 +56,7 @@ void virtio_mmio_setup(void) devs[i], devid, version =3D=3D 1 ? " (legacy)" : ""); switch (devid) { case 2: /* blk */ - /* TODO */ + run_thread(init_virtio_blk_mmio, mmio); break; case 8: /* scsi */ run_thread(init_virtio_scsi_mmio, mmio); --=20 2.18.2 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org