From patchwork Tue Sep 18 14:57:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 971149 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="LTtqlT3z"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42F5hY2H86z9s9N for ; Wed, 19 Sep 2018 00:58:05 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729873AbeIRUbB (ORCPT ); Tue, 18 Sep 2018 16:31:01 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:37427 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728631AbeIRUbB (ORCPT ); Tue, 18 Sep 2018 16:31:01 -0400 Received: by mail-wr1-f65.google.com with SMTP id u12-v6so2462395wrr.4 for ; Tue, 18 Sep 2018 07:58:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id; bh=tWAJ5ehl8dkATEE7czTzScLiB0dlXRdfPp0umosaGuU=; b=LTtqlT3zxcMbaZVUVo+4e5FE8E1TZmQ+zakuBP0B0iahmtRMMrEEvZf72jLmUtzuz6 C5qkjIlsbDVtHz1zN7J2EviJe2f/v4nPZ/VxxRODKKxgbcI6G4dsqKHVQEKJR2+uDDhQ W1PjEJaE2qyBtYotawrs/MLY0VMsjTWy6gCKpx4iqwyTDlz3/pzoKv8f/Lu4rs9GlBMZ cHSHUamBDCeBet/T8LhcCNN9Vdr/B1N+Z5UoeIm1mxDlbJsroh0qyhv5JQeclkOMQDnf PzGk5DV40GBtzE0nWgy3NgZc5y/eYnY/KT+7GK0QqKu4ddEWUCMeZIMwvEPydMLAWMKP 4gaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=tWAJ5ehl8dkATEE7czTzScLiB0dlXRdfPp0umosaGuU=; b=iGL9fomkpWec00lcTdby6+EbhwcO/JIYp6pe1jT6sTdYAse28N6qqovMo8WZ3ZTO1r 2i4XT1fsJaN1NkhW2hV9mq4MitGbyVGgLMfGtWITDEu92cJxLFa6PYLkh8KiD8vibRCH I3T9uuGVmIh19qXRysTfcR1yIKjWNl36RvhUW/gr3LoS4uVEmA2QF0sJVqX/iI60xwON PzGKgOVR/MLjAKixqnEnbPNCIOR1aHX+Jrek3Az3BwZKyQXthUns+s8XbqLbXts3cgKL GH4/9trq7XRUjRQJRurea2JoBLg6iXFxKxq03xe+3K1CNqSLdVoR14Um7XliMnBndY3N 03yw== X-Gm-Message-State: APzg51Cn8zG4Uq3NIkTHyQD3ZmNybsKtekHN+A6eQww7tmM1pJ6hGDUZ /t2uIKuCBBlrdSjdmkLb2Qd0TQ== X-Google-Smtp-Source: ANB0VdayaGVHKUd0YtC4fHViLEpEZOcYtHFbCxycH/Vx1YZ6zVE2QwHPLgmj3udFpoW81M7lJHJiCQ== X-Received: by 2002:a5d:448d:: with SMTP id j13-v6mr24210017wrq.236.1537282680986; Tue, 18 Sep 2018 07:58:00 -0700 (PDT) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id o14-v6sm12697973wrp.57.2018.09.18.07.58.00 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 18 Sep 2018 07:58:00 -0700 (PDT) From: Michal Simek To: linux-kernel@vger.kernel.org, monstr@monstr.eu Cc: devicetree@vger.kernel.org, Rob Herring , Frank Rowand Subject: [PATCH v3 1/2] of: base: Introduce of_alias_get_alias_list() to check alias IDs Date: Tue, 18 Sep 2018 16:57:58 +0200 Message-Id: X-Mailer: git-send-email 1.9.1 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The function travels the lookup table to record alias ids for the given device match structures and alias stem. This function will be used by serial drivers to check if requested alias is allocated or free to use. Signed-off-by: Michal Simek Reviewed-by: Rob Herring --- Changes in v3: - Fix subject s/of_alias_check_id/of_alias_get_alias_list/ - And also fix commit message description to match of_alias_get_alias_list() - mark empty function with inline Changes in v2: - Add empty function for !CONFIG_OF case - Add return to that function - Add Rob's Reviewed-by tag Based on discussion with Rob https://lkml.org/lkml/2018/4/27/397 nbits is passed to the function not to limit only to 32/64bit fields. Greg: Please apply this together with serial: uartps: Change uart ID port allocation. Rob is fine with that (link above) --- drivers/of/base.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 10 ++++++++++ 2 files changed, 62 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index 74eaedd5b860..33011b88ed3f 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -16,6 +16,7 @@ #define pr_fmt(fmt) "OF: " fmt +#include #include #include #include @@ -1943,6 +1944,57 @@ int of_alias_get_id(struct device_node *np, const char *stem) EXPORT_SYMBOL_GPL(of_alias_get_id); /** + * of_alias_get_alias_list - Get alias list for the given device driver + * @matches: Array of OF device match structures to search in + * @stem: Alias stem of the given device_node + * @bitmap: Bitmap field pointer + * @nbits: Maximum number of alias ID which can be recorded it bitmap + * + * The function travels the lookup table to record alias ids for the given + * device match structures and alias stem. + * + * Return: 0 or -ENOSYS when !CONFIG_OF + */ +int of_alias_get_alias_list(const struct of_device_id *matches, + const char *stem, unsigned long *bitmap, + unsigned int nbits) +{ + struct alias_prop *app; + + /* Zero bitmap field to make sure that all the time it is clean */ + bitmap_zero(bitmap, nbits); + + mutex_lock(&of_mutex); + pr_debug("%s: Looking for stem: %s\n", __func__, stem); + list_for_each_entry(app, &aliases_lookup, link) { + pr_debug("%s: stem: %s, id: %d\n", + __func__, app->stem, app->id); + + if (strcmp(app->stem, stem) != 0) { + pr_debug("%s: stem comparison doesn't passed %s\n", + __func__, app->stem); + continue; + } + + if (app->id >= nbits) { + pr_debug("%s: ID %d greater then bitmap field %d\n", + __func__, app->id, nbits); + continue; + } + + if (of_match_node(matches, app->np)) { + pr_debug("%s: Allocated ID %d\n", __func__, app->id); + set_bit(app->id, bitmap); + } + /* Alias exist but it not compatible with matches */ + } + mutex_unlock(&of_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(of_alias_get_alias_list); + +/** * of_alias_get_highest_id - Get highest alias id for the given stem * @stem: Alias stem to be examined * diff --git a/include/linux/of.h b/include/linux/of.h index 99b0ebf49632..d51457b40725 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -392,6 +392,9 @@ extern int of_phandle_iterator_args(struct of_phandle_iterator *it, extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)); extern int of_alias_get_id(struct device_node *np, const char *stem); extern int of_alias_get_highest_id(const char *stem); +extern int of_alias_get_alias_list(const struct of_device_id *matches, + const char *stem, unsigned long *bitmap, + unsigned int nbits); extern int of_machine_is_compatible(const char *compat); @@ -893,6 +896,13 @@ static inline int of_alias_get_highest_id(const char *stem) return -ENOSYS; } +static inline int of_alias_get_alias_list(const struct of_device_id *matches, + const char *stem, unsigned long *bitmap, + unsigned int nbits) +{ + return -ENOSYS; +} + static inline int of_machine_is_compatible(const char *compat) { return 0;