Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937312AbcLTTGR (ORCPT ); Tue, 20 Dec 2016 14:06:17 -0500 Received: from mout.gmx.net ([212.227.15.18]:51544 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936223AbcLTTFw (ORCPT ); Tue, 20 Dec 2016 14:05:52 -0500 From: Heinrich Schuchardt To: Pantelis Antoniou , Rob Herring , Mark Rutland , Frank Rowand Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Heinrich Schuchardt Subject: [PATCH 1/4 v2] of/overlay: add API function to count and pop last Date: Tue, 20 Dec 2016 20:04:52 +0100 Message-Id: <20161220190455.25115-2-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161220190455.25115-1-xypron.glpk@gmx.de> References: <20161220190455.25115-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K0:CNJPV/sybbCc6sgZ8iZH9OU79Tatp9FGQ9W8JCKr8FIRHD+dFFr VZbSFT2CF5slyVqUSj8yFKzKIeWHMZpyO/lTRkFLs8a6viKnUimP5tmrQJ1xrfdYfWi8MeU 3sw8J2xoPY7J3ZdnVrpKEBowPryeTY3lxzfO1loScObo1lgb5hAe8JbComA0ac5C3QZDYgB aUYXU8GXhdc3Vw8+EXj8A== X-UI-Out-Filterresults: notjunk:1;V01:K0:Bpm1KrVG3Vs=:D1Npv1P7+uABjKY+UhHaKv 42t8CcwbJVBJw4mQRHwlM2wmJPJQhLI/hsTJg9a8Z4TlvgYn6lIlbV+i8TsFUQ52TCqa04J9k xvt96YgB01nU1AnJG8FPpnEUPYb8fo+PVdxrmUzB9fsItlwY2Xkb6j+dTzqToaxyZf8PJdLxn rLiCbsEgd1HNi6Ey6JSLXZOFN9Otttzr78aqp7Tl/d1irUikMr0Bcm0Fjq/Obps3pQgyj874+ xCvoZhyu4yq1aAg0SH5IQRSk7IqsBmmGkUGx0sclREFiI4Ml8G/1xYgyh0qjCt0CFpI/D74NQ QXqvq2XlUxeSElYDh2J1GhEWNWBWy6LtA0+3/nReQ9DzHwJnmOK9hknw0SH56zEyXKxRL33E1 8fA+toOQZWnAtrqoM00jEpMtu+7sCGb4aBXjwkhX7GTQUGp8+FHj2WmQWjik5mftBY+MczqCG gG+NHNv32wQDLA/jtkcy3XZZYHdbDK5z2ygTI/1sBGKMVncJ77UJ5p1CD7ln2ZIozwWEKnWmQ 5/TQIb7Rc1jzvewmENtl7CyJ7z3i1c7Uy8cqX0xJ8FmGhOuQpUAc8UyMlEndxRQC+/jcyS516 1GsJuYdM3xUCzrc6Nt8gm/88TEDCpdAU0s2YxpQF77AMW4Ceb82AEPRNzSnnUyyOLL8UlavOx HeuKvKnpmktzo5gNUnd23ml2f/2bUPya3RqlSEOJJLAKJk3zpox0928Z9jc/816VgV0hI6fAw b2AcTPrIQQRqCbbmnG7RYnxpbFytewTGBH5F2ejfT6vSqqcSou7HY3mzN44= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3938 Lines: 144 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 --- v2: Add missing inline attribute for ov_overlay_count. 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 d418a6c..7c8099c 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 0d4cda7..bd30253 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 d72f010..5ca3523 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 inline 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.10.2