Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4871154ybl; Mon, 9 Dec 2019 18:43:56 -0800 (PST) X-Google-Smtp-Source: APXvYqxBlMytidExWyRvlGlrPy2uaqmhLoMWUbXz/nJjWbbESnlRd7NOCrjYjAwX/lN7Rd/D/Ch6 X-Received: by 2002:aca:f144:: with SMTP id p65mr2151447oih.131.1575945836492; Mon, 09 Dec 2019 18:43:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575945836; cv=none; d=google.com; s=arc-20160816; b=Am/elHabGvhQC00BrWzETwzbVBYJ5XZg2BqFKzrf1JZIADBR/bQ9qc4mVxyrARN1XI Z+UJUDWVIrJtNFDsXu9G6vldZjBvqLfXD4HZ/SZKjcXL78fgbg2caQER+5Yvh0kFgWuD +585ZUC1HjLEuNG8nYKZKiveGB7rETYbUfzQTZ5iz81iOynMyFu8pOAfJland5tqNXdO 4mVPOWC2xzAmoCl7JLriHOq+J7ppSkFTmS6ljeI10/0Rw7HKX0w/7h2mWyAEdQgPu6t2 mgSnL/Gk1/heyQLIQ0uAU/nwbA66TFyhuVh7kN9CEVCVqLyhYKhIM3KsDjYDzeBOjacn xSZw== 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=+pVRv0zmwM6r6qh3u7jefx+roN9IpRfJikQs29Fs7Mc=; b=hvzcOmi6f/9yLaE0uMij4Vx+j6wSZq/bYOdBqBJqbLoISxc1fowJT2C4QIHvX5XBk0 5hzhnAsqbiPeO5HI4IcaswlKIbisQ8smrXerct3vZl9TvW3xaffdzlt8Gj5T6Ld8Unfj GY/SMKKPsjlhuhMcUWjp/fPxseD2bz/g9TO1M8VvE+WIQLn3/FuwcWySWpw7QZy939l0 pwsG9XhOFj4flf5UWMeEA3IUZDsmeKSJU5HAEP+2jtJG1l2ZG8hUxJSXwosHg+Pd29rW PlQLeOdL3jALKMytd/wQV5jRKLZexFChBqXO+IAGAITsvlznRJv+KkPtNWZpgK0YSvR/ sy9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uwUf65Dt; 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 z14si1145216oth.15.2019.12.09.18.43.44; Mon, 09 Dec 2019 18:43:56 -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=uwUf65Dt; 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 S1726743AbfLJCnW (ORCPT + 99 others); Mon, 9 Dec 2019 21:43:22 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:46748 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726668AbfLJCnV (ORCPT ); Mon, 9 Dec 2019 21:43:21 -0500 Received: by mail-pf1-f196.google.com with SMTP id y14so8231057pfm.13 for ; Mon, 09 Dec 2019 18:43:21 -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=+pVRv0zmwM6r6qh3u7jefx+roN9IpRfJikQs29Fs7Mc=; b=uwUf65DtxepoaHGo4O1l3eRw7LX0FXVzucUtAwwuLkcVjQsqdGxJD9cMJLM3nuxt4J etcJjflqicP0aEqaF9T0mrVMdUzRjrsOc2W9D1SN+k2VoeOlPGsRtdsv0sKEtSjUCyX7 lbr3bTGxNh6VVe6bsLgKqdVUaqgeK2IH7WEp13jtZayc88doNqd1tyqwQn9FF71k1g8f ds1XNZVb96EMb7mSGq4cYsAA40g3HW9oHxI72pOcoR2X4xireKpY1GkZ4zSW/b0XF39r BLvCXgssR3l9lvlzi7vtpOoVHsaTGYXgbOfozM7Bh4NRkEbPnNPue9YdVQZq/PH6l+9Q O0HA== 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=+pVRv0zmwM6r6qh3u7jefx+roN9IpRfJikQs29Fs7Mc=; b=DdDW7roAyc0aOO9A/ETuJzp00Tl9D4y+nav9ADIIWCuFKHciIBau8QnZ2Sdcs8t+E8 Hqcciu/yVKoE+j7NEjmNXGk1hLiooellmXGswImLg9dln6HeELoNY2a6VZQVwrbnd5Tf esvimsVm+vQ2n4PhgaWl/9O0SaB2JhjNAzqu5gr+T29UgMOf0PXJg64MNCVsR8z+NBE5 Ko3M5Qd0vAOdHUkku3at5hbUY908v9EmuyOfuDlHLNpySrHTxI8u3ziQu3qkjMN7OjkI +hP52Voi9ziTfUJrkr2zFwQdqCxuM1Z2CaLqya7XUnaBa0D4nfKwQvZVO49LlHtHgeDI sJZA== X-Gm-Message-State: APjAAAWgtVRZAidBpLNqVbMns/sQfO7Y1fSRAw4pPv9rZQ4SCl1fg00H 7NxgxvyDlLaHuKVfcIFZ7AOJOg== X-Received: by 2002:aa7:9118:: with SMTP id 24mr34122975pfh.182.1575945800496; Mon, 09 Dec 2019 18:43:20 -0800 (PST) Received: from localhost.localdomain ([240e:362:417:e00:ed89:9d55:8cd5:6d38]) by smtp.gmail.com with ESMTPSA id r6sm826422pfh.91.2019.12.09.18.43.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Dec 2019 18:43:20 -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: [RESEND PATCH v9 1/4] uacce: Add documents for uacce Date: Tue, 10 Dec 2019 10:42:32 +0800 Message-Id: <1575945755-27380-2-git-send-email-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1575945755-27380-1-git-send-email-zhangfei.gao@linaro.org> References: <1575945755-27380-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 | 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