From nobody Tue Apr 16 05:47:01 2024 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