Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6531365ybl; Wed, 15 Jan 2020 06:14:30 -0800 (PST) X-Google-Smtp-Source: APXvYqxDLv2z0qJ3dDm+Jq4MfrHc9AHgXgnv8rSwRL1nIN+NTKxWENiVBat0hnYWC+bmzmWpyCMn X-Received: by 2002:a05:6808:181:: with SMTP id w1mr21750013oic.176.1579097669830; Wed, 15 Jan 2020 06:14:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579097669; cv=none; d=google.com; s=arc-20160816; b=sVAv/G/TBtcR5Eb7qTp53RIr0iE5AStiQPvRK6vedsH7SSlhPRaF4SCWXQl3eeyVvi +tovOtAn5LNQbsCq1xHvcmk5zd1ENqkGBgidSPaYL2LeLeGPrYiYJ7Ky85Z/aKAjm6Jk Hx+hX1DyuUp6/2WZUzDQouYtQH2yORLRnjwkvFuAIXgAlQ6knE8lWOSyD+/UsDG8VYy9 dq2y38DQexvqHjMFlb833kijZAt6sQVuoZgRd4kWUHwn9sOc2da9n4hvk2WxLOebmiug ivp4mXy256ScDkrxuJW9g9psWN3j6LmWnzasTkkX8cppN0OJDeYimG/LQM7ySoRnna1n Poww== 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=Src2nBsw9fEQNe6R1XRh63qOf6PvwHbP1eF/87qT/L8=; b=cY7yqfSVlGCGmlIIRwVZ233pJII0yv19B/BilXfj5iM0Vo+dYYYoEOKwNFKA7FmjEz dAh/o07kqWeA9z3IqLcGxUrjLuZlljcg8Rt96bKqGBMt90zFeHPPclIOd5X2AGZq1qhT dwh3tXMi0jIZjZWorpgMdoxTdJWUDJQMqh9JShVcU6wBO7VCFfk5/WRWMIHkOSOYFdUL fUer7VC6HLY0qukCQW5RSn+U1y7R0g3fqYlkzbMJ+zKDyEh/jACoNaGxgqSr6Dj0Twvx xn+frGEsialjOn1/k5mZSCQDC70dimYcAMeIz8tk5qYITiRoRL3w4UGN0ZRL3iSLv1wd 8D6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="o6X/nqdF"; 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 v14si11396276oth.181.2020.01.15.06.14.15; Wed, 15 Jan 2020 06:14:29 -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="o6X/nqdF"; 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 S1728988AbgAOONh (ORCPT + 99 others); Wed, 15 Jan 2020 09:13:37 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:41856 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730398AbgAOONc (ORCPT ); Wed, 15 Jan 2020 09:13:32 -0500 Received: by mail-pg1-f194.google.com with SMTP id x8so8269124pgk.8 for ; Wed, 15 Jan 2020 06:13:32 -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=Src2nBsw9fEQNe6R1XRh63qOf6PvwHbP1eF/87qT/L8=; b=o6X/nqdFlkZP5IwKgGBT/IcaPAebM8FGb0PVIqEcdL2L8VmRMZh0Xrtfqf8LzRhcOX nHuQZj8X9SbuPZfeTRcBm1MScioFj409Xm3HqAUI9LYp5X2sB+nWaWN8Ivo8NfEc3vui a7a8fqJGWG3n2dsXwgNOC4Slz2B9/SACrUabygcmHTK90Rr/l5txCtH7UQkDF1fcFtos Zfy00UgZSMuR4p7IFOIqJhQD4j5idbWvdGAeagJC5TzNZvGizttwUhU9JQ+j+dM3TuFp dlp46BYaGJb6ojmMzXo9qYcL29nmp6uEJwC9Latw9iDd5ATDzVPN9HvxHDv94CMIKXm0 ZjUw== 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=Src2nBsw9fEQNe6R1XRh63qOf6PvwHbP1eF/87qT/L8=; b=ZlXwDAF+s0wqJZ+j774bWEgfI+BEBq2w2dHTNm2KVzTyrH4aeQrnhnk/A927ZGkNSm tz3WnCX1px+/5/eOKp2TAM3UJa8ohqcXVHI26UwcwL+smsDfnfn6RWeR4EZNZCZT0lxI uz52DarM2pLSoP0hGqE82HJ5ZlqSP0xbC43bnRDdXPIGQ2K1Bcjx04pQBFttYSzZ3BGV MsrIGj5Bad3cWpb+rjZQiY+neJ5ChZ0MUBA0of0fvg+eKrujs3nVBDqCoYYMiE9ueVRR 1YdHK8SA0YSwJop1b45xsFDT+1YBvgZdu1hIo/6QAadzdyJwNv5UZLr0LWpxFUZIAnZK 8Wjw== X-Gm-Message-State: APjAAAWORmR9jhLRDOLR8ZHd+TfS6BEuESTWkkzI8J6U4Q3ZRkU2cEu+ fEBz2mMysKHCA+v9+4yaojm+zg== X-Received: by 2002:aa7:9edd:: with SMTP id r29mr30849280pfq.14.1579097611989; Wed, 15 Jan 2020 06:13:31 -0800 (PST) Received: from localhost.localdomain ([104.238.63.136]) by smtp.gmail.com with ESMTPSA id a15sm22591980pfh.169.2020.01.15.06.13.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Jan 2020 06:13:31 -0800 (PST) From: Zhangfei Gao To: Greg Kroah-Hartman , Arnd Bergmann , Herbert Xu , jonathan.cameron@huawei.com, dave.jiang@intel.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 v12 1/4] uacce: Add documents for uacce Date: Wed, 15 Jan 2020 22:12:45 +0800 Message-Id: <1579097568-17542-2-git-send-email-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1579097568-17542-1-git-send-email-zhangfei.gao@linaro.org> References: <1579097568-17542-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. Reviewed-by: Jonathan Cameron 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 | 176 +++++++++++++++++++++++++++++++++++ 1 file changed, 176 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..1db412e --- /dev/null +++ b/Documentation/misc-devices/uacce.rst @@ -0,0 +1,176 @@ +.. 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_alloc(struct device *parent, + struct uacce_interface *interface); + int uacce_register(struct uacce_device *uacce); + void uacce_remove(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