From patchwork Thu Sep 20 11:41:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 972352 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="AAccMnEq"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42GFFP47WGz9s4V for ; Thu, 20 Sep 2018 21:42:01 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731343AbeITRZF (ORCPT ); Thu, 20 Sep 2018 13:25:05 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:38770 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727633AbeITRZF (ORCPT ); Thu, 20 Sep 2018 13:25:05 -0400 Received: by mail-wr1-f65.google.com with SMTP id j8-v6so5318719wrw.5 for ; Thu, 20 Sep 2018 04:41:58 -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=AAccMnEqkcz1NsXexuSF0XvjqOMbwGBxvEo9DIuGP9IOjPQcCQ0dBxg6ZysEQb/bPe PUrIv6VQPfDmWNXdXq2lYLvYIwg0Ev7WOUG4DXgmemGdJ9ExdRRCSZdgk8B5lg7LAwjc KB3tTZw/fW62e0z4iW2e0ON5xPb5ROdi0OWzcGo+PacYx16ujGmlv+KScFw7s1dYUPbd F+e1Yq2ggbgZ8WsMyGrsbNrWR0j/b+z+rfd3ST54lk9cQr0VSVTXgyqq3TSbQLAIOVT6 xg0l538gTL2t5D2VSi7q3+Ey/aQ8TgT2eR0qSF3DLPqsSQhu+8rY9Fy/DYFacBuee9lg o57g== 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=MzAJT/FteAzl2mtQH1sA/IsUHYYdlKgsTcLMOACt2xGFT/SZFHvD+pl+9d+Bzu/I4f CmMVyQgABYL98KCHUGYKoAsjtAACCjQuFCAXb0KcsgCoTLpvibUG10pLf3ob+LvYKs8q MPwa9qih3P4nwO/TtOWC/TQzG6VhKlRpJ2FS9cop+LS7owsocUd/Ge9+l+VnG+S3vRi+ +tmP2SDpi+d0YE7e1rf7AyGyuoBcrxksdMlVN96s+WBenZtlDKmzVqC5T+yAXx4EdHCC 5AU06b9eF/TeN5qCpDlc0MP1L9xtMgAJpatOoJCsD0c/eKAV778n2AiggZ13kDK/SNJ+ hq8A== X-Gm-Message-State: ABuFfoj6RznmOhs7I0c+jOU3+gx4u4ZcL5JFkv+epOzmIdcktL5KVUmy SllrS+3nnPOVTreuiX2O+Uvwdw== X-Google-Smtp-Source: ACcGV617W84x3aQchGF7w9Rj3B6wbcqEFJr6yfkNyr7VsTY/8d8peAg0xp3Ww+tZgXsfv1GrqHzHVQ== X-Received: by 2002:adf:e643:: with SMTP id b3-v6mr1769421wrn.254.1537443717763; Thu, 20 Sep 2018 04:41:57 -0700 (PDT) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id e14-v6sm16888807wrv.44.2018.09.20.04.41.56 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 20 Sep 2018 04:41:57 -0700 (PDT) From: Michal Simek To: linux-kernel@vger.kernel.org, monstr@monstr.eu, gregkh@linuxfoundation.org Cc: devicetree@vger.kernel.org, Rob Herring , Frank Rowand Subject: [RESEND PATCH v3 1/2] of: base: Introduce of_alias_get_alias_list() to check alias IDs Date: Thu, 20 Sep 2018 13:41:52 +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;