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: 9601629 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 2789660453 for ; Thu, 2 Mar 2017 21:45:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17A012841C for ; Thu, 2 Mar 2017 21:45:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C028285EF; Thu, 2 Mar 2017 21:45:57 +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=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 713532841C for ; Thu, 2 Mar 2017 21:45:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E1D456EC64; Thu, 2 Mar 2017 21:45:33 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk0-f180.google.com (mail-qk0-f180.google.com [209.85.220.180]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3CBEF6EC65 for ; Thu, 2 Mar 2017 21:45:32 +0000 (UTC) Received: by mail-qk0-f180.google.com with SMTP id s186so146638016qkb.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=HV/pm+fMDa00lfTVKrsXI3PBpFLSq5VlbMtrlnO6lBIJGLrYzYfeH9DaGqKqE9fddw lnqyjVcy/1p4foX9j8FMN5k8CmaW1qDNhpNsSnSdnb5dPnIFzcUld1C2puDzfRxuQYAo Dxc6Dkul6TwgOs8pQksqzlCrjDz7I/vMY7v13ZjAxJbl2S34KcLyxQPFSQbM5+Q/MZZb FQSy6cgFnRi8nPdPwxQLOwGT0a4SpDo8eYWIk2yHYLpb01VPFuECL0b2K2lurgQd/Yh3 UKX0Ag8pOp3j82NPUFdOYAUw7wLu1i0ZcLDvmbwAyhfPdB0C2jU3ulTYBo6cPkR8GaG0 ReLQ== X-Gm-Message-State: AMke39nl8GXnznem1D+Etj0XxSkEPkibqk1dCLwf1/r17rlNz9KJE8uKOWYPyyAtNlpNd/LI 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> 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 , Daniel Vetter , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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);