From patchwork Thu May 17 08:26:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 10405863 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A80A060230 for ; Thu, 17 May 2018 08:27:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95093289A6 for ; Thu, 17 May 2018 08:27:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8865B289A9; Thu, 17 May 2018 08:27:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07A36289A6 for ; Thu, 17 May 2018 08:27:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752501AbeEQI0o (ORCPT ); Thu, 17 May 2018 04:26:44 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:33922 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752380AbeEQI0Q (ORCPT ); Thu, 17 May 2018 04:26:16 -0400 Received: by mail-lf0-f66.google.com with SMTP id r25-v6so7478218lfd.1; Thu, 17 May 2018 01:26:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ybPwETFNyo0XmcjukLU8lWvEXETdo/Zbt2OJ1NytBWA=; b=UVWioUhYWaV8o+SO0r+N2rLJ0V2dmx62Ac69JiPgFS5CFu59PMYQNDjcBY9MuzQwIl Vn6nU9VGedJNufYSk3hWXsm/vmnRvgKKskltEh+d0UUwiGM0Lxt6KQ0rmBVkCRdRm+hP 62akpZQ8u5R7siFNwd6eg128CmqjYIVzMbrWo/F1K/KNeeuB5LxAvykQOcIXvMjn71ZD ZzGsP3RxhjRYw8H8uu3fU5+QlWwdosxGu4aZAm0fG1zoKDa1Bh579+CP1qnilDjgBYxQ ITkI8MfxibIYYuooJHs2sZEuvBaPxGFsVOwnb6vGO+9gBhR7cfJutRmPwR/3LqmvUXfO is/Q== 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=ybPwETFNyo0XmcjukLU8lWvEXETdo/Zbt2OJ1NytBWA=; b=erarcuqlwH0czrGnQQ19qvq+FdOj3rYrlp1vvyxXp/sGGGHthCP4rAdGChoVT7qx/B BBVZrqnW3hNjCinV+Zfln7wB53aIAxjEYIIa+hmXA5ZeH+GvibI2z8D5KRPMZN3pnJgS kD1KomVyZjoCzVJ6EJLC4l4GvtltMfn6GJitd8/3SUbOykg0FO9NBeF2T6099RqADFQr adZq8KoJa1BCgJM6NFfO5koSfEkDaxA59ohj64O0rtK6WBQeqdPhnyOZ4KzqymaVZaPk 517L2JyPccdcyrHIysBloCBAYgUbsptt7d9yIVLBrokGzoXAdgGudPZG5g2YtGGhov6S xBqw== X-Gm-Message-State: ALKqPwcUVVcLWZ2+BbLnUi4Rt5vMN9kSy+GtIRcEG9ErJpU5A9enqx4o mHYm0VmmRe0C6gfuKlI80Xc= X-Google-Smtp-Source: AB8JxZo+Iuea9FcPU2N+thucNgE4w5FUWTF2enbNPbn5XFC7Fo0SAXgPwLixJDM+5lHjq0rr5gTQrw== X-Received: by 2002:a2e:95d6:: with SMTP id y22-v6mr2368466ljh.90.1526545575151; Thu, 17 May 2018 01:26:15 -0700 (PDT) Received: from a2k-HP-ProDesk-600-G2-SFF.kyiv.epam.com (ll-52.209.223.85.sovam.net.ua. [85.223.209.52]) by smtp.gmail.com with ESMTPSA id y1-v6sm1102381lfg.10.2018.05.17.01.26.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 May 2018 01:26:14 -0700 (PDT) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, jgross@suse.com, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com Cc: daniel.vetter@intel.com, andr2000@gmail.com, dongwon.kim@intel.com, matthew.d.roper@intel.com, Oleksandr Andrushchenko Subject: [Xen-devel][RFC 2/3] xen/grant-table: Extend API to work with DMA buffers Date: Thu, 17 May 2018 11:26:03 +0300 Message-Id: <20180517082604.14828-3-andr2000@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180517082604.14828-1-andr2000@gmail.com> References: <20180517082604.14828-1-andr2000@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Andrushchenko Signed-off-by: Oleksandr Andrushchenko --- drivers/xen/grant-table.c | 49 +++++++++++++++++++++++++++++++++++++++ include/xen/grant_table.h | 7 ++++++ 2 files changed, 56 insertions(+) diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c index bb36b1e1dbcc..c27bcc420575 100644 --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c @@ -729,6 +729,55 @@ void gnttab_free_pages(int nr_pages, struct page **pages) } EXPORT_SYMBOL(gnttab_free_pages); +int gnttab_dma_alloc_pages(struct device *dev, bool coherent, + int nr_pages, struct page **pages, + void **vaddr, dma_addr_t *dev_bus_addr) +{ + int i; + int ret; + + ret = alloc_dma_xenballooned_pages(dev, coherent, nr_pages, pages, + vaddr, dev_bus_addr); + if (ret < 0) + return ret; + + for (i = 0; i < nr_pages; i++) { +#if BITS_PER_LONG < 64 + struct xen_page_foreign *foreign; + + foreign = kzalloc(sizeof(*foreign), GFP_KERNEL); + if (!foreign) { + gnttab_dma_free_pages(dev, flags, nr_pages, pages, + *vaddr, *dev_bus_addr); + return -ENOMEM; + } + set_page_private(pages[i], (unsigned long)foreign); +#endif + SetPagePrivate(pages[i]); + } + return 0; +} +EXPORT_SYMBOL(gnttab_dma_alloc_pages); + +void gnttab_dma_free_pages(struct device *dev, bool coherent, + int nr_pages, struct page **pages, + void *vaddr, dma_addr_t dev_bus_addr) +{ + int i; + + for (i = 0; i < nr_pages; i++) { + if (PagePrivate(pages[i])) { +#if BITS_PER_LONG < 64 + kfree((void *)page_private(pages[i])); +#endif + ClearPagePrivate(pages[i]); + } + } + free_dma_xenballooned_pages(dev, coherent, nr_pages, pages, + vaddr, dev_bus_addr); +} +EXPORT_SYMBOL(gnttab_dma_free_pages); + /* Handling of paged out grant targets (GNTST_eagain) */ #define MAX_DELAY 256 static inline void diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h index 34b1379f9777..20ee2b5ba965 100644 --- a/include/xen/grant_table.h +++ b/include/xen/grant_table.h @@ -195,6 +195,13 @@ void gnttab_free_auto_xlat_frames(void); int gnttab_alloc_pages(int nr_pages, struct page **pages); void gnttab_free_pages(int nr_pages, struct page **pages); +int gnttab_dma_alloc_pages(struct device *dev, bool coherent, + int nr_pages, struct page **pages, + void **vaddr, dma_addr_t *dev_bus_addr); +void gnttab_dma_free_pages(struct device *dev, bool coherent, + int nr_pages, struct page **pages, + void *vaddr, dma_addr_t dev_bus_addr); + int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, struct gnttab_map_grant_ref *kmap_ops, struct page **pages, unsigned int count);