Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp795044pxa; Wed, 19 Aug 2020 15:24:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+XE4Htjs2wdcURhLb6p+qG/ylOPSNyrDXCMKjtGNHNly1CEK17whQGytvBcJcXAvUr48c X-Received: by 2002:a17:906:f2cb:: with SMTP id gz11mr482989ejb.58.1597875870101; Wed, 19 Aug 2020 15:24:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597875870; cv=none; d=google.com; s=arc-20160816; b=lWwPoiBTcyQG7AcCZFxd+n7ZKvVkX16d2L/7B+I8DpeimphcDlu8m0YHnqq2gmlJYq pFR2Tm0Pc5idBtm+DBRyfN1XQwAoMfEAo+Iv2VTxOx4Jep5rI8wGREmhYJ+S4hvtfR21 BsZPBuYBJn2Efe7zUnwsCcuv1p0xTyCbofUYdD9gc5Zzr/dvUx9oAxZhagctaeos7489 UvWwA1jGuJH1YbrTrGzgGO+jNV0IWkbrtCEq5Z0quCy05xNNUR6gVxUP/Wn799AI804i t329Mct1+Zq1zoV6OI9fc27kUoj3DxkBwrrK9wCAAaHlYFwJ8+XKM2KWkJVmHF7DlGDm QxLQ== 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=GQQRLRSw4j8HkEfa+DKkvenAI5uYOUqQOX/jVMQ+gzs=; b=fkcUS30wYbFMu8Xb0jpA1xBK5rVzC8FtZKAFPYNyZYaiPgPjLar9t8Oazei3N2jukk xbPPUwUm69g6yJYT2MMYRTmk9ElJoND7tpzwzZvjR4p0rLMHoFvJPzyEpFU6QPoOGG/2 0JnsBDCFr5mONYiNpKb5jqqYJ/4SeKpoCwbQam2xBYp0uKbiuv/ZM+WHQOcCYWh52N0x 0t3I9zqlAsNN/z88OolNvLvCa69sKLonDNfKIo5TbQa4RYbQXdKD57X3RnOiVDoEBJqz bmVn5nFZdDr8qedq2m+lbfxav+j6YNHPdngctj6+9ykameQt1XwlC/o7Zyh1bP2WUlg/ 4XKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U+sN7pgR; 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 rl3si9344ejb.643.2020.08.19.15.24.06; Wed, 19 Aug 2020 15:24:30 -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=U+sN7pgR; 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 S1727955AbgHSWWm (ORCPT + 99 others); Wed, 19 Aug 2020 18:22:42 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:50874 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727882AbgHSWVI (ORCPT ); Wed, 19 Aug 2020 18:21:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597875667; 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=GQQRLRSw4j8HkEfa+DKkvenAI5uYOUqQOX/jVMQ+gzs=; b=U+sN7pgRbM0pDKCkUiIJafRfVKzotYYl0FoNn5jGueGf5dPWJeXlHStg3A8fOSZKW6fmpy c+b/kqFrmTkWF+pvjhUPQxbNyV18hXWkHe3bumeY77s6ADFCk3Xk661M3li9lwtJH5qOUG //szEvXSCLmhmLzmHNL0oPVfUGDi8a0= 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-274-9qBezfhxN2WzK8QymfmESA-1; Wed, 19 Aug 2020 18:21:03 -0400 X-MC-Unique: 9qBezfhxN2WzK8QymfmESA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 85F681007465; Wed, 19 Aug 2020 22:21:01 +0000 (UTC) Received: from horse.redhat.com (ovpn-115-197.rdu2.redhat.com [10.10.115.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61CA25C3E0; Wed, 19 Aug 2020 22:21:01 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id E25162256B5; Wed, 19 Aug 2020 18:20:53 -0400 (EDT) From: Vivek Goyal To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org, virtio-fs@redhat.com Cc: vgoyal@redhat.com, miklos@szeredi.hu, stefanha@redhat.com, dgilbert@redhat.com, dan.j.williams@intel.com, Sebastien Boeuf , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, "Michael S. Tsirkin" Subject: [PATCH v3 05/18] virtio: Implement get_shm_region for MMIO transport Date: Wed, 19 Aug 2020 18:19:43 -0400 Message-Id: <20200819221956.845195-6-vgoyal@redhat.com> In-Reply-To: <20200819221956.845195-1-vgoyal@redhat.com> References: <20200819221956.845195-1-vgoyal@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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: virtualization@lists.linux-foundation.org Cc: "Michael S. Tsirkin" --- drivers/virtio/virtio_mmio.c | 31 +++++++++++++++++++++++++++++++ include/uapi/linux/virtio_mmio.h | 11 +++++++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c index 627ac0487494..238383ff1064 100644 --- a/drivers/virtio/virtio_mmio.c +++ b/drivers/virtio/virtio_mmio.c @@ -498,6 +498,36 @@ 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 +540,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