From patchwork Thu Mar 2 21:44:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 9601691 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 5E0D660453 for ; Thu, 2 Mar 2017 21:50:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D8DF285F8 for ; Thu, 2 Mar 2017 21:50:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 428A6285FC; Thu, 2 Mar 2017 21:50:47 +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=-1.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_SORBS_SPAM autolearn=no version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E0EE9285FB for ; Thu, 2 Mar 2017 21:50:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=C9QKyqNoN+YVc7FYsybrdjXjd22GiJdRWUP/i230bwM=; b=g6hBOoOCutO3Iy8l8btYUwfO9a 1PT+4Y4FJypWh8xrWZ59wU0RNbH9grKHXfAJdYqfms3zsus4xdGIOTWZ/ZPeGgsmq+7AdGPoLCxrV 8RfCuZiogmjRhuSynfN9PJ2vDokO7disZ9E10Sz2wkvsWVPgvpxN79RPtFVt6Sko7b3VG3rk4dngV WCQ3IDdVO0lMhISYX0NFtu5n39zD4LhxCVvQD22g36nzYDKaYagybN7wsGsdUIC6eXouaA8JR0ORO ecH3qe3VRZ59GtYwhQsEMOLgm3Wyf7B08BnFF9BPbV10bhQuEa1KwUziKwrVSDyLvFz4VDr+w200t ntOR+0wg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cjYcY-0004du-3f; Thu, 02 Mar 2017 21:50:46 +0000 Received: from mail-qk0-f178.google.com ([209.85.220.178]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cjYXn-0007x8-N8 for linux-arm-kernel@lists.infradead.org; Thu, 02 Mar 2017 21:45:54 +0000 Received: by mail-qk0-f178.google.com with SMTP id s186so146638026qkb.1 for ; Thu, 02 Mar 2017 13:45:32 -0800 (PST) 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=tv/Xz49Wo/z/P7hX9euvhoddU2a65kcdJHe8PLZwvVA=; b=lBc4dk4icUANLJANpRNgXKS2JVDvBIemOF+QdLPzUmOrpwovFGmLZ6qFImuXxukdnU DuAR2BsNwTDa3FHOy2q3r5yM+2eEuK1Oztdwj2HTSyFt51WwGBxicXpgvmfnj9OXdu3r fTD4OMlmb+8WGs/ajZVfurkn7J4NvAl1p383rQJuiijFVeigxFXsTw+sa+X1VpnKjXOZ oa64PbhqUJknZ/8yiqX3ZHPVzkMOm7BDuhG01Raxg5IOj//gbaOReA3yyS328UCeyQr0 M0GKcQ5ojKvtGe8MrnTXjZiEmyCTpSLsArWM1/zTmqtynXGLgx8LdJ+JXqrlnGn4asX4 SooQ== X-Gm-Message-State: AMke39nL6213qKizXAI53SMAZpYUAqrS6hFU6+tbR+/YJ+eGUd9z+fH6FKzRpbAYtMdDfx+Q X-Received: by 10.200.55.57 with SMTP id o54mr20786055qtb.78.1488491131360; Thu, 02 Mar 2017 13:45:31 -0800 (PST) Received: from labbott-redhat-machine.redhat.com ([2601:602:9802:a8dc::5ce7]) by smtp.gmail.com with ESMTPSA id r10sm6261671qte.1.2017.03.02.13.45.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Mar 2017 13:45:30 -0800 (PST) From: Laura Abbott To: Sumit Semwal , Riley Andrews , arve@android.com Subject: [RFC PATCH 12/12] staging; android: ion: Enumerate all available heaps Date: Thu, 2 Mar 2017 13:44:44 -0800 Message-Id: <1488491084-17252-13-git-send-email-labbott@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488491084-17252-1-git-send-email-labbott@redhat.com> References: <1488491084-17252-1-git-send-email-labbott@redhat.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170302_134552_032364_D8156EE1 X-CRM114-Status: GOOD ( 13.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devel@driverdev.osuosl.org, romlem@google.com, Greg Kroah-Hartman , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-mm@kvack.org, Mark Brown , Benjamin Gaignard , Daniel Vetter , Laura Abbott , Brian Starkey , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Practiaclly speaking, most Ion heaps are either going to be available all the time (system heaps) or found based off of the reserved-memory node. Parse the CMA and reserved-memory nodes to assign the heaps. Signed-off-by: Laura Abbott --- drivers/staging/android/ion/Makefile | 2 +- drivers/staging/android/ion/ion_enumerate.c | 89 +++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/android/ion/ion_enumerate.c diff --git a/drivers/staging/android/ion/Makefile b/drivers/staging/android/ion/Makefile index eef022b..4ebf655 100644 --- a/drivers/staging/android/ion/Makefile +++ b/drivers/staging/android/ion/Makefile @@ -1,4 +1,4 @@ -obj-$(CONFIG_ION) += ion.o ion-ioctl.o ion_heap.o +obj-$(CONFIG_ION) += ion.o ion-ioctl.o ion_heap.o ion_enumerate.o obj-$(CONFIG_ION_SYSTEM_HEAP) += ion_system_heap.o ion_page_pool.o obj-$(CONFIG_ION_CARVEOUT_HEAP) += ion_carveout_heap.o obj-$(CONFIG_ION_CHUNK_HEAP) += ion_chunk_heap.o diff --git a/drivers/staging/android/ion/ion_enumerate.c b/drivers/staging/android/ion/ion_enumerate.c new file mode 100644 index 0000000..21344c7 --- /dev/null +++ b/drivers/staging/android/ion/ion_enumerate.c @@ -0,0 +1,89 @@ +#include +#include + +#include "ion.h" +#include "ion_priv.h" + +static struct ion_device *internal_dev; +static int heap_id = 2; + +static int ion_add_system_heap(void) +{ +#ifdef CONFIG_ION_SYSTEM_HEAP + struct ion_platform_heap pheap; + struct ion_heap *heap; + + pheap.type = ION_HEAP_TYPE_SYSTEM; + pheap.id = heap_id++; + pheap.name = "ion_system_heap"; + + heap = ion_heap_create(&pheap); + if (!heap) + return -ENODEV; + + ion_device_add_heap(internal_dev, heap); +#endif + return 0; +} + +static int ion_add_system_contig_heap(void) +{ +#ifdef CONFIG_ION_SYSTEM_HEAP + struct ion_platform_heap pheap; + struct ion_heap *heap; + + pheap.type = ION_HEAP_TYPE_SYSTEM_CONTIG; + pheap.id = heap_id++; + pheap.name = "ion_system_contig_heap"; + + heap = ion_heap_create(&pheap); + if (!heap) + return -ENODEV; + + ion_device_add_heap(internal_dev, heap); +#endif + return 0; +} + +#ifdef CONFIG_ION_CMA_HEAP +int __ion_add_cma_heaps(struct cma *cma, void *data) +{ + struct ion_heap *heap; + struct ion_platform_heap pheap; + + pheap.type = ION_HEAP_TYPE_DMA; + pheap.id = heap_id++; + pheap.name = cma_get_name(cma); + pheap.priv = cma; + + heap = ion_heap_create(&pheap); + if (!heap) + return -ENODEV; + + ion_device_add_heap(internal_dev, heap); + return 0; +} +#endif + + +static int ion_add_cma_heaps(void) +{ +#ifdef CONFIG_ION_CMA_HEAP + cma_for_each_area(__ion_add_cma_heaps, NULL); +#endif + return 0; +} + +int ion_enumerate(void) +{ + internal_dev = ion_device_create(NULL); + if (IS_ERR(internal_dev)) + return PTR_ERR(internal_dev); + + ion_add_system_heap(); + ion_add_system_contig_heap(); + + ion_add_cma_heaps(); + return 0; +} +subsys_initcall(ion_enumerate);