Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp2453603ybx; Fri, 8 Nov 2019 04:38:13 -0800 (PST) X-Google-Smtp-Source: APXvYqwsuzHiY50B9zMilhdXLLStbCC6fVvmDON51iZ/gvSXHvP/1zJi+7epYg33hqjU2M0bZXE1 X-Received: by 2002:aa7:db82:: with SMTP id u2mr9775951edt.256.1573216693406; Fri, 08 Nov 2019 04:38:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573216693; cv=none; d=google.com; s=arc-20160816; b=tPKyuSYwTwhxvlwGlOHAOsBc+XzmNG/mIovBqvGagHc09EO0KXU+x3sf7Vk46nW8DJ DR3H3tKK+qDTaWoMMv8erW5VsoBIgafEyuwLCX8t229VEY0Q+3cE17GAzzzTNM/8Pq2h oKaKcp6w26gA2xKffhSEE+43EHBw8SAezGHmjFyYVdwqkKpo0jt8tlFs8MV++7clvtVa lISu4cpuyWtXAKqpvV4L3kkZOtnvW+gSA+nBEyF13izj2/RrsO9GyMGOldYKdaWp0n8V sTG2Uy21XshRvdUVYcyXSOiuNstyrq9sTGpv6g2FGM7/q1yy/eTgySNfdjkSU9w6kqAQ k07g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=cfpg9lXoO3GI47l6Tfb34t3Cc2krZOv/mwnJIDHcsuU=; b=hUShSYG2i+QSMlGrLLlaoPnuqIppsJZnZVLlp64neb4P6Wn8+nreq/DHFtwncFkVG/ HKseCRYSo/R1Q17LbuZ2GMcfRfITX1+GsU5eum/3aAbZC/zfswhv3uprPnqTDGJ7093u xiKds7S4uLlslnHonjdyX/kIIhaiu9nhCnlnIO7S4J7wv5u0N+ctqF7LnMT5nirhta1K BamYW3MAPO5cI7LjAkxakltLdmbQL2dHc3PYWwMsyDg3azT2i2J2yYaB5ThgAEUrI2kT eEztlIWDjq6+fMby47aYwZI6nsclSMXV1fSQzQejY+ObVhM80piYFecHf3qzbYCcpM+w DlXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q6J0UhsH; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k24si3579596ejv.111.2019.11.08.04.37.49; Fri, 08 Nov 2019 04:38:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q6J0UhsH; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726587AbfKHMfP (ORCPT + 99 others); Fri, 8 Nov 2019 07:35:15 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:36490 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726576AbfKHMfO (ORCPT ); Fri, 8 Nov 2019 07:35:14 -0500 Received: by mail-pl1-f194.google.com with SMTP id d7so2141686pls.3 for ; Fri, 08 Nov 2019 04:35:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cfpg9lXoO3GI47l6Tfb34t3Cc2krZOv/mwnJIDHcsuU=; b=q6J0UhsHUCZNx6jwmJG5PInMVhNBssW4rIAHr0KRNeNDsp8tpTt44b2qlhw7hO/1r/ j/TAMrjzNzXm3yShUR/cqctRTlfru++ql49sjjVGa51dVEluhRfXzbJL7nIreYJ3gsvc CHwEv3RQfC7JW3TgKLkQ4HyB2qVrZXxB+Sv/r+k82Bor7Qy6NZMyyWIbkk0hIncpMSg/ mkF0zeyKjnx0Oll0b1S+u2laymPbkKwvIaYxWwC20NGUi98TDQbzHKqaTb8iH0xzeI1W mkQH2QUzg+PNZ40eVdcb8i6kyDuVGytVZ6HH2iHubeLyTuGU+1SPElUW19tWSoULGWac oVRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cfpg9lXoO3GI47l6Tfb34t3Cc2krZOv/mwnJIDHcsuU=; b=G5g5POj9nigdSc5jxK+myGk9PCeHzEEdctt095uxSo+6OI9CKvEPZAOUigAGnyawmV 2FyH983GMqxiUUknuZQZhVTxf+fR4aWCecx4hgi65sfM/B8p+DmJRrI9hFqZNvUOz0r7 n+my2rckvyPqlsvMdJMcy+uLlNgsJ5E49Pkqq2jNdZIlPS9zskvPPuHjyJVeaaB9yhv1 33rvpF8cQ7w0TUUZGIe8W9YvOMwEU+emIhpA4olNeAhl7pXWeqP0K64vAkhHB2EGZM/i RWXk2/zd/adW+micXw8Adj5CQ12iI4YZSs3vVXUFqVpkrrxRHI9p2Rjpd8t/Xkiv/fns 1rTw== X-Gm-Message-State: APjAAAVASvXteDNty6Tm8StFUKy7YVeGAgnCvhfaLR7MrK5Hk7tQ+ei/ pH02UWanSeQdednMOB8vx9CWYg== X-Received: by 2002:a17:902:aa86:: with SMTP id d6mr10604159plr.268.1573216513795; Fri, 08 Nov 2019 04:35:13 -0800 (PST) Received: from localhost.localdomain ([240e:362:48f:8f00:79bd:a8a7:1834:2d1a]) by smtp.gmail.com with ESMTPSA id q34sm5430926pjb.15.2019.11.08.04.34.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 08 Nov 2019 04:35:13 -0800 (PST) From: Zhangfei Gao To: Greg Kroah-Hartman , Arnd Bergmann , Herbert Xu , jonathan.cameron@huawei.com, grant.likely@arm.com, jean-philippe , Jerome Glisse , ilias.apalodimas@linaro.org, francois.ozog@linaro.org, kenneth-lee-2012@foxmail.com, Wangzhou , "haojian . zhuang" , guodong.xu@linaro.org Cc: linux-accelerators@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, iommu@lists.linux-foundation.org, Kenneth Lee , Zaibo Xu , Zhangfei Gao Subject: [PATCH v8 1/3] uacce: Add documents for uacce Date: Fri, 8 Nov 2019 20:34:26 +0800 Message-Id: <1573216468-10379-2-git-send-email-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1573216468-10379-1-git-send-email-zhangfei.gao@linaro.org> References: <1573216468-10379-1-git-send-email-zhangfei.gao@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Kenneth Lee Uacce (Unified/User-space-access-intended Accelerator Framework) is a kernel module targets to provide Shared Virtual Addressing (SVA) between the accelerator and process. This patch add document to explain how it works. Signed-off-by: Kenneth Lee Signed-off-by: Zaibo Xu Signed-off-by: Zhou Wang Signed-off-by: Zhangfei Gao --- Documentation/misc-devices/uacce.rst | 159 +++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 Documentation/misc-devices/uacce.rst diff --git a/Documentation/misc-devices/uacce.rst b/Documentation/misc-devices/uacce.rst new file mode 100644 index 0000000..733521a --- /dev/null +++ b/Documentation/misc-devices/uacce.rst @@ -0,0 +1,159 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Introduction of Uacce +--------------------- + +Uacce (Unified/User-space-access-intended Accelerator Framework) targets to +provide Shared Virtual Addressing (SVA) between accelerators and processes. +So accelerator can access any data structure of the main cpu. +This differs from the data sharing between cpu and io device, which share +only data content rather than address. +Because of the unified address, hardware and user space of process can +share the same virtual address in the communication. +Uacce takes the hardware accelerator as a heterogeneous processor, while +IOMMU share the same CPU page tables and as a result the same translation +from va to pa. + + __________________________ __________________________ + | | | | + | User application (CPU) | | Hardware Accelerator | + |__________________________| |__________________________| + + | | + | va | va + V V + __________ __________ + | | | | + | MMU | | IOMMU | + |__________| |__________| + | | + | | + V pa V pa + _______________________________________ + | | + | Memory | + |_______________________________________| + + + +Architecture +------------ + +Uacce is the kernel module, taking charge of iommu and address sharing. +The user drivers and libraries are called WarpDrive. + +The uacce device, built around the IOMMU SVA API, can access multiple +address spaces, including the one without PASID. + +A virtual concept, queue, is used for the communication. It provides a +FIFO-like interface. And it maintains a unified address space between the +application and all involved hardware. + + ___________________ ________________ + | | user API | | + | WarpDrive library | ------------> | user driver | + |___________________| |________________| + | | + | | + | queue fd | + | | + | | + v | + ___________________ _________ | + | | | | | mmap memory + | Other framework | | uacce | | r/w interface + | crypto/nic/others | |_________| | + |___________________| | + | | | + | register | register | + | | | + | | | + | _________________ __________ | + | | | | | | + ------------- | Device Driver | | IOMMU | | + |_________________| |__________| | + | | + | V + | ___________________ + | | | + -------------------------- | Device(Hardware) | + |___________________| + + +How does it work +---------------- + +Uacce uses mmap and IOMMU to play the trick. + +Uacce creates a chrdev for every device registered to it. New queue is +created when user application open the chrdev. The file descriptor is used +as the user handle of the queue. +The accelerator device present itself as an Uacce object, which exports as +a chrdev to the user space. The user application communicates with the +hardware by ioctl (as control path) or share memory (as data path). + +The control path to the hardware is via file operation, while data path is +via mmap space of the queue fd. + +The queue file address space: +/** + * enum uacce_qfrt: qfrt type + * @UACCE_QFRT_MMIO: device mmio region + * @UACCE_QFRT_DUS: device user share region + */ +enum uacce_qfrt { + UACCE_QFRT_MMIO = 0, + UACCE_QFRT_DUS = 1, +}; + +All regions are optional and differ from device type to type. +Each region can be mmapped only once, otherwise -EEXIST returns. + +The device mmio region is mapped to the hardware mmio space. It is generally +used for doorbell or other notification to the hardware. It is not fast enough +as data channel. + +The device user share region is used for share data buffer between user process +and device. + + +The Uacce register API +---------------------- + +The register API is defined in uacce.h. + + struct uacce_interface { + char name[UACCE_MAX_NAME_SIZE]; + unsigned int flags; + const struct uacce_ops *ops; + }; + +According to the IOMMU capability, uacce_interface flags can be: + +/** + * UACCE Device flags: + * UACCE_DEV_SVA: Shared Virtual Addresses + * Support PASID + * Support device page faults (PCI PRI or SMMU Stall) + */ +#define UACCE_DEV_SVA BIT(0) + +struct uacce_device *uacce_register(struct device *parent, + struct uacce_interface *interface); +void uacce_unregister(struct uacce_device *uacce); + +uacce_register results can be: +a. If uacce module is not compiled, ERR_PTR(-ENODEV) +b. Succeed with the desired flags +c. Succeed with the negotiated flags, for example + uacce_interface.flags = UACCE_DEV_SVA but uacce->flags = ~UACCE_DEV_SVA +So user driver need check return value as well as the negotiated uacce->flags. + + +The user driver +--------------- + +The queue file mmap space will need a user driver to wrap the communication +protocol. Uacce provides some attributes in sysfs for the user driver to +match the right accelerator accordingly. +More details in Documentation/ABI/testing/sysfs-driver-uacce. -- 2.7.4