Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2510979pxa; Fri, 7 Aug 2020 13:00:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFp2n1M2+bl+aHjQrJnmtFvZYvIkJc9VNfiSe3GbvryRX6CABUaYEBmJVwWwa92U2NoZqT X-Received: by 2002:a05:6402:17c2:: with SMTP id s2mr10189447edy.188.1596830443487; Fri, 07 Aug 2020 13:00:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596830443; cv=none; d=google.com; s=arc-20160816; b=UFh/k2L3DkA5aiT4AV8WnR9kqpYAfaRw0VvtHaxe+dJKmwvdaDYgEmUnYqa7BGdzSR ICFGIplREtVVz2xViMkcsJrQhxRtinefXBVj1RUcdEP3oSEuSVE3X5HQvsd/de0NjLaA OPMU+1F889D3KB5ESZVkz7Ngx69L/a7VpZXl6NjsQ97vWBdyZ/IuRjDdS8ZUy7472A+j MKF9VGQHYi4IEfxPgAnOFAraA3B1R6tpqoweDq83KhjMS34w8Q6T15RnSVM+qlzu6vay 0kWQ6f14JFdePIoGRYm9SUeDxsgU6uqrYWINX7FONp05rjUsGCMMJoXWOYK+sgXckmPI jlPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=a11wJbhnzYwxb2Lcb6PDBA6q2DERVu1PinNtBvs2loo=; b=UokBpYw6cKX5BbttTwXIEN5VBsgSAaz/L8AqSVlINiXhP7fpL5i94FUtahuqngLh5l DyXttQXcy557+QuAJaZsPj4XhazPkd3gwTnHqgGJcAPc8okx4g+Koz88qmpkkBsDcn5a U/bdHAdmYRdSZ98xhW8rrfU4znecDlpKtCkNsd3zDu71N4imEGBWtWmDM3/tnN4U7zo/ nNpYHB39fKEjwSz3h2zWhzdSEQwYrMervOStP6Cpeab3epmqaJLPvOYwerGu5YeMJ7XF DZ397uU0l3vTXrwqJt5uQqtDOZTK816Gj1PxmtlzIKlb75lm/2KzUXD+RgvNro/2N8oG CwQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=e4GzilC4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e1si5833313edn.361.2020.08.07.13.00.19; Fri, 07 Aug 2020 13:00:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=e4GzilC4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727897AbgHGT4x (ORCPT + 99 others); Fri, 7 Aug 2020 15:56:53 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:59678 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726916AbgHGTzz (ORCPT ); Fri, 7 Aug 2020 15:55:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596830153; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a11wJbhnzYwxb2Lcb6PDBA6q2DERVu1PinNtBvs2loo=; b=e4GzilC4mZgZktkDcm92SfIrN7ZJQkRc1f9CRoX1Md02k0DGojAaANADh/0/YsgouXOPhI XmVESo7nzoqN4ckp5TZ7ls7Y9NWCKXWHDAivkI6zozAD4JRqrZvMWfrzAE8Okl8AvX3BgJ GFY2OV7O3SjRp1RKrNbt9iy/kpN7pFE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-214-j7cTREl9MMqQBbypohLXfg-1; Fri, 07 Aug 2020 15:55:49 -0400 X-MC-Unique: j7cTREl9MMqQBbypohLXfg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5972C8014C1; Fri, 7 Aug 2020 19:55:48 +0000 (UTC) Received: from horse.redhat.com (ovpn-113-142.rdu2.redhat.com [10.10.113.142]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F20B10027A6; Fri, 7 Aug 2020 19:55:45 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id BAF7F222E49; Fri, 7 Aug 2020 15:55:38 -0400 (EDT) From: Vivek Goyal To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, virtio-fs@redhat.com Cc: vgoyal@redhat.com, miklos@szeredi.hu, stefanha@redhat.com, dgilbert@redhat.com, Sebastien Boeuf , kvm@vger.kernel.org, "Michael S. Tsirkin" Subject: [PATCH v2 05/20] virtio: Implement get_shm_region for MMIO transport Date: Fri, 7 Aug 2020 15:55:11 -0400 Message-Id: <20200807195526.426056-6-vgoyal@redhat.com> In-Reply-To: <20200807195526.426056-1-vgoyal@redhat.com> References: <20200807195526.426056-1-vgoyal@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sebastien Boeuf On MMIO a new set of registers is defined for finding SHM regions. Add their definitions and use them to find the region. Signed-off-by: Sebastien Boeuf Cc: kvm@vger.kernel.org Cc: "Michael S. Tsirkin" --- drivers/virtio/virtio_mmio.c | 32 ++++++++++++++++++++++++++++++++ include/uapi/linux/virtio_mmio.h | 11 +++++++++++ 2 files changed, 43 insertions(+) diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c index 627ac0487494..2697c492cf78 100644 --- a/drivers/virtio/virtio_mmio.c +++ b/drivers/virtio/virtio_mmio.c @@ -498,6 +498,37 @@ static const char *vm_bus_name(struct virtio_device *vdev) return vm_dev->pdev->name; } +static bool vm_get_shm_region(struct virtio_device *vdev, + struct virtio_shm_region *region, u8 id) +{ + struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev); + u64 len, addr; + + /* Select the region we're interested in */ + writel(id, vm_dev->base + VIRTIO_MMIO_SHM_SEL); + + /* Read the region size */ + len = (u64) readl(vm_dev->base + VIRTIO_MMIO_SHM_LEN_LOW); + len |= (u64) readl(vm_dev->base + VIRTIO_MMIO_SHM_LEN_HIGH) << 32; + + region->len = len; + + /* Check if region length is -1. If that's the case, the shared memory + * region does not exist and there is no need to proceed further. + */ + if (len == ~(u64)0) { + return false; + } + + /* Read the region base address */ + addr = (u64) readl(vm_dev->base + VIRTIO_MMIO_SHM_BASE_LOW); + addr |= (u64) readl(vm_dev->base + VIRTIO_MMIO_SHM_BASE_HIGH) << 32; + + region->addr = addr; + + return true; +} + static const struct virtio_config_ops virtio_mmio_config_ops = { .get = vm_get, .set = vm_set, @@ -510,6 +541,7 @@ static const struct virtio_config_ops virtio_mmio_config_ops = { .get_features = vm_get_features, .finalize_features = vm_finalize_features, .bus_name = vm_bus_name, + .get_shm_region = vm_get_shm_region, }; diff --git a/include/uapi/linux/virtio_mmio.h b/include/uapi/linux/virtio_mmio.h index c4b09689ab64..0650f91bea6c 100644 --- a/include/uapi/linux/virtio_mmio.h +++ b/include/uapi/linux/virtio_mmio.h @@ -122,6 +122,17 @@ #define VIRTIO_MMIO_QUEUE_USED_LOW 0x0a0 #define VIRTIO_MMIO_QUEUE_USED_HIGH 0x0a4 +/* Shared memory region id */ +#define VIRTIO_MMIO_SHM_SEL 0x0ac + +/* Shared memory region length, 64 bits in two halves */ +#define VIRTIO_MMIO_SHM_LEN_LOW 0x0b0 +#define VIRTIO_MMIO_SHM_LEN_HIGH 0x0b4 + +/* Shared memory region base address, 64 bits in two halves */ +#define VIRTIO_MMIO_SHM_BASE_LOW 0x0b8 +#define VIRTIO_MMIO_SHM_BASE_HIGH 0x0bc + /* Configuration atomicity value */ #define VIRTIO_MMIO_CONFIG_GENERATION 0x0fc -- 2.25.4