Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3002745imm; Thu, 17 May 2018 01:29:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp+U1LHQ5plgGh40mgG9arJwYpugOuckLrGkC70pSyvqhrPKlCo5ISHhu7ClLpqUVQWru3p X-Received: by 2002:a17:902:d886:: with SMTP id b6-v6mr4304668plz.361.1526545746502; Thu, 17 May 2018 01:29:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526545746; cv=none; d=google.com; s=arc-20160816; b=IxhVDrfC35cQtbZdCPNw9I7+PJ9nBevQhz3smBWgYMwqiyehI3wllckzBahgVbEdFs PGRRT/muBv2sIQSq9kRbWokVW/NH7mMWmSPunbAjZhgzphJndKEz0lTv5Am16MenN196 KW610eah3qdNYtojCt0vZX9XqZLB72lygi8CsXv9+/SMux3tsx72wCraITaC3WBlcYia CUdbCTwAtpFDiMqlq5ytJm0tKeZb9Sl1RHFZ+Vw75JH2TYJQalqr8LZBupnr+tv47Tln cEQ/S30+wsD+wMYI/PW9+dAYuV3Ni3C8rejJ/kA1LAg26H8TLxCB4XO1hkw1iAvntNsI GT3Q== 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:arc-authentication-results; bh=ybPwETFNyo0XmcjukLU8lWvEXETdo/Zbt2OJ1NytBWA=; b=JxsZ+ZP/2jUWQ6je7xPCiArsvBeEfoinTNYQBEq/B3t8Ei+22tuN917WqnQ4UZcc2+ u+LXyP9XliTIn4f96SG3+kAiyXqTUzHHxUPHIUedrph8hkiHMjgREyhpG+wp2I6Rkgta Yo5aBLhcQ9lsVyLOQga7m6iYqZUxdgmZSTbVQBCYew7lSBZpCet2NCAOwyf+lJyQtU2q YvaHCSQl3nyVW+n69jNhGV1PQ4ZZEbqBO0YL79DYC/YHjeW3p+2QNsG7WvyfhVuEBi+k rn2fDcwkMQ+yWPEV612Kw4NZu8D8BIvkewFw1pdn17+pFXt7JesxAnmrE3wHgtPSdrqM AM+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UVWioUhY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w27-v6si3649084pgc.645.2018.05.17.01.28.52; Thu, 17 May 2018 01:29:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@gmail.com header.s=20161025 header.b=UVWioUhY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752576AbeEQI0o (ORCPT + 99 others); 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-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.17.0