From nobody Tue Feb 10 04:29:48 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=1588168404; cv=none; d=zohomail.com; s=zohoarc; b=ZtSHKVJYrekGzjW+b6+hK4XBKO+12diwMoaRMtuyzsbObcny2591H7YtPnq6fHlS9KcmPTHGLMFeemWGGm/YuJXLKb7VfmFN42OOPGcmYjMHfcczW10VNBKdTz9Kr9BUYSWiyDPje9EDV/YaTnofk4TdCCvNN/AheMmOuA8bsPE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588168404; 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=tryiyeWosPOrgs0V9GQ1exOpDQMeYhuFem5aIEYlaaE=; b=nb6WCgcXqQ5PqYfidmvfoRvjIGP+jU68eyyHljr/wdYILOfxorgq3oZU6MthliSI5lWaAA/4RMT7mtmb3EvCiSnRw4ewBDAV5qBr8/BOmr08TeUNEc5WNWs9Y2fFQvhlr+ADCH2WKngK5AI9QO7kwQmaqMo+XDnikHkI3XcqYAc= 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 1588168404947753.6826669497767; Wed, 29 Apr 2020 06:53:24 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 8EF8710C195B; Wed, 29 Apr 2020 13:53:20 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 51A2E10C1955 for ; Wed, 29 Apr 2020 13:53: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-403-9m7jrC2gPtOVB2Ff3fjqTg-1; Wed, 29 Apr 2020 09:46:58 -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 2D95245F for ; Wed, 29 Apr 2020 13:46:57 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7AC9560BF4; Wed, 29 Apr 2020 13:46:53 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) id 18C199D99; Wed, 29 Apr 2020 15:46:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588168387; 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=o1ac3GcktkeUPN5aoWYqkesehQO3xXcBazmEkVXGXB8=; b=DW7KlvtLk9jUVGSbYvSfcI0GvDZz7p0E6wDdZhWpwnRVihLqO4tF1lq8vlCAJGE9ywXWbz mqDz+pICpu+/u3uUQzi3ftpp91+WQi/iJtPk4mj3nkYEO/kOvJwgvGSrOwWee9rWvgiks7 kzTGEs84oFE3JmsZFarFnJzLlrEPvbU= X-MC-Unique: 9m7jrC2gPtOVB2Ff3fjqTg-1 From: Gerd Hoffmann To: seabios@seabios.org Date: Wed, 29 Apr 2020 15:46:35 +0200 Message-Id: <20200429134643.2001-2-kraxel@redhat.com> In-Reply-To: <20200429134643.2001-1-kraxel@redhat.com> References: <20200429134643.2001-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: KVZUCCKAVYCEHB3M5O3QXLB3PII4FMTM X-Message-ID-Hash: KVZUCCKAVYCEHB3M5O3QXLB3PII4FMTM 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 v3 1/9] 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-Spam: Yes X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add virtio_mmio_setup_one() to setup 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 --- Makefile | 2 +- src/hw/virtio-mmio.h | 76 ++++++++++++++++++++++++++++++++++++++++++++ src/hw/virtio-pci.h | 1 + src/hw/virtio-mmio.c | 58 +++++++++++++++++++++++++++++++++ 4 files changed, 136 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..9e0dae421009 --- /dev/null +++ b/src/hw/virtio-mmio.h @@ -0,0 +1,76 @@ +#ifndef _VIRTIO_MMIO_H +#define _VIRTIO_MMIO_H + +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_setup_one(u64 mmio); +void vp_init_mmio(struct vp_device *vp, void *mmio); + +#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/hw/virtio-mmio.c b/src/hw/virtio-mmio.c new file mode 100644 index 000000000000..0d6ef6e2f19d --- /dev/null +++ b/src/hw/virtio-mmio.c @@ -0,0 +1,58 @@ +#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" + +void virtio_mmio_setup_one(u64 addr) +{ + u32 magic, version, devid; + void *mmio; + + if (addr >=3D 0x100000000) { + dprintf(1, "virtio-mmio: %llx: above 4G\n", addr); + return; + } + + mmio =3D (void*)(u32)(addr); + magic =3D readl(mmio); + if (magic !=3D 0x74726976) { + dprintf(1, "virtio-mmio: %llx: magic mismatch\n", addr); + return; + } + version =3D readl(mmio+4); + if (version !=3D 1 /* legacy */ && + version !=3D 2 /* 1.0 */) { + dprintf(1, "virtio-mmio: %llx: unknown version %d\n", addr, versio= n); + return; + } + devid =3D readl(mmio+8); + dprintf(1, "virtio-mmio: %llx: device id %x%s\n", + addr, 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