From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753087AbcLSBLK (ORCPT ); Sun, 18 Dec 2016 20:11:10 -0500 Received: from mout.gmx.net ([212.227.15.19]:49362 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752088AbcLSBLH (ORCPT ); Sun, 18 Dec 2016 20:11:07 -0500 From: Heinrich Schuchardt To: Rob Herring , Mark Rutland , Frank Rowand Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Heinrich Schuchardt Subject: [PATCH 1/3] of/overlay: add API function to count and pop last Date: Mon, 19 Dec 2016 02:10:33 +0100 Message-Id: <1482109835-9000-2-git-send-email-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1482109835-9000-1-git-send-email-xypron.glpk@gmx.de> References: <1482109835-9000-1-git-send-email-xypron.glpk@gmx.de> X-Provags-ID: V03:K0:gXToCWCM3bmcqsJf4hVI56Y1F6MJkgyleoiknsIc4Av0tBr4DYI diViY6J1Smx3ju8hSWClXG95YRpG4cWG4c6/NF9UD+1NlDmdEWeHVpZlhM4hKo3nOuQbh+e BkjEy3ZQ8DObkqGQP7tjw5xpuhHavB7Dmcs+h570CZxJV+SEyn8jHtmpHOyb46twiX0EDGe khtQQVIwWQ6tciyNz7x3g== X-UI-Out-Filterresults: notjunk:1;V01:K0:Impuz+3vdEk=:74FkCm7Nw1HiqkgQuUBQM8 EBK9lI3Icshqpm3yYcet4nF4SzVnljdIWngndIjFS4xcDKrUiWNAE4uCLrQwDS2zCrNun/NyS ggPrXeVj3gNVESv00enYQ9NaLFJRx5o+63kEJurPu6i60A1z1xm4KAYafip3R0a1yxFSA8Bas VS8f19VsJf7SaJa5Xgp4K1S3ZhrQOgnPePb3mvwpfQGn5bSfN3vQW9RuTrjQfpd7paldfi8aY Xj1iw8pvgJuDKqLs9I67wKT7mV8dSzfGI7MQh3QJfPt4YRn4lmPfWibDcF8oIBZbM0DWx/TX8 iYIzaCVA6FANclyOsUxHKNtKxmY+MtnqkXyvL1iMmG7K2OVqpf2GVvj7qLwxPIFm2L6nuKvnw V9kNNOrbHQo7B05NHUeeXZZOBiCSask3WnYy5KboOweObB2pi0nxv5WVB0eucp9Kworuz/ypV A3n5LEZxZknU7T+qeoL8Il394cS7phW0G4M2C8io0c3b5OEpsaTuSPkx5iynbpej/jJCirHYy aXSSM+zDZycbh/GSPW1tm9gzlQOLo/Ow2GBHQnDwHsaaPJAxCDsLg9j6BJQ71SGN6SibmCP1b jCQuXy/cSHBoGAe9NoA8W4IEDl1E4v3EGMLnIVU/viGJfJkHDKkzYfUz0lO3Vac7re3k0y1J7 Vc/ZZtCmj6UaLdAcQ0NUNNQNYecGyA9wOBT+EgC7Q/syArSndh3nKCayBG1QqeCIpr78/IbZc j+xvx9ocvaWhDjvtMeHvex1DvppwDj/qkyuoJNPdeOgTonGadKmGzJNocqY= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To allow building interfaces which are not id based two new functions are added to the device tree overlay API: of_overlay_count - counts the loaded overlays of_overlay_destroy_last - removes the last overlay loaded Signed-off-by: Heinrich Schuchardt --- Documentation/devicetree/overlay-notes.txt | 7 +++-- drivers/of/overlay.c | 50 ++++++++++++++++++++++++++++++ include/linux/of.h | 12 +++++++ 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/overlay-notes.txt b/Documentation/devicetree/overlay-notes.txt index d418a6ce9812..7c8099c81e91 100644 --- a/Documentation/devicetree/overlay-notes.txt +++ b/Documentation/devicetree/overlay-notes.txt @@ -89,17 +89,20 @@ Overlay in-kernel API The API is quite easy to use. -1. Call of_overlay_create() to create and apply an overlay. The return value +Call of_overlay_create() to create and apply an overlay. The return value is a cookie identifying this overlay. -2. Call of_overlay_destroy() to remove and cleanup the overlay previously +Call of_overlay_destroy() to remove and cleanup the overlay previously created via the call to of_overlay_create(). Removal of an overlay that is stacked by another will not be permitted. +Or call of_overlay_destroy_last() to remove the most recent overlay. Finally, if you need to remove all overlays in one-go, just call of_overlay_destroy_all() which will remove every single one in the correct order. +Call of_overlay_count() to determine the number of loaded overlays. + Overlay DTS Format ------------------ diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 0d4cda7050e0..bd30253b26f9 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -587,3 +587,53 @@ int of_overlay_destroy_all(void) return 0; } EXPORT_SYMBOL_GPL(of_overlay_destroy_all); + +/** + * of_overlay_destroy_last() - Removes the last overlay from the system + * + * It is allways possible to delete the last overlay. + * + * Returns 0 on success, or a negative error number + */ +int of_overlay_destroy_last(void) +{ + struct of_overlay *ov, *ovn; + int id; + + mutex_lock(&of_mutex); + + list_for_each_entry_safe_reverse(ov, ovn, &ov_list, node) { + id = ov->id; + mutex_unlock(&of_mutex); + return of_overlay_destroy(id); + } + + mutex_unlock(&of_mutex); + + pr_info("destroy: No overlay to destroy"); + + return -ENODEV; +} +EXPORT_SYMBOL_GPL(of_overlay_destroy_last); + +/** + * of_overlay_count - Counts number of loaded overlays + * + * Returns number of loaded overlays + */ +int of_overlay_count(void) +{ + struct of_overlay *ov, *ovn; + int count = 0; + + mutex_lock(&of_mutex); + + list_for_each_entry_safe(ov, ovn, &ov_list, node) { + ++count; + } + + mutex_unlock(&of_mutex); + + return count; +} +EXPORT_SYMBOL_GPL(of_overlay_count); diff --git a/include/linux/of.h b/include/linux/of.h index d72f01009297..73c8826c543b 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1281,15 +1281,22 @@ struct of_overlay_notify_data { #ifdef CONFIG_OF_OVERLAY /* ID based overlays; the API for external users */ +int of_overlay_count(void); int of_overlay_create(struct device_node *tree); int of_overlay_destroy(int id); int of_overlay_destroy_all(void); +int of_overlay_destroy_last(void); int of_overlay_notifier_register(struct notifier_block *nb); int of_overlay_notifier_unregister(struct notifier_block *nb); #else +static int of_overlay_count(void) +{ + return -ENOTSUPP; +} + static inline int of_overlay_create(struct device_node *tree) { return -ENOTSUPP; @@ -1305,6 +1312,11 @@ static inline int of_overlay_destroy_all(void) return -ENOTSUPP; } +static inline int of_overlay_destroy_last(void) +{ + return -ENOTSUPP; +} + static inline int of_overlay_notifier_register(struct notifier_block *nb) { return 0; -- 2.11.0