Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp658164rdg; Thu, 10 Aug 2023 15:21:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFBFvUMA2zxKj3AJ6I5fYVT8tjE7assYzXc62Rd7lQ5ZCl+YZqFZMRTIhdpbvWNuNxRg+l4 X-Received: by 2002:a17:90b:e0b:b0:268:38f5:86ac with SMTP id ge11-20020a17090b0e0b00b0026838f586acmr2855541pjb.24.1691706089731; Thu, 10 Aug 2023 15:21:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691706089; cv=none; d=google.com; s=arc-20160816; b=Qfn7DQukBjP4SOaqM8aKjvWkX6jP7b+/tn6KDiLWr7Z/wncJHFTsiFGVNyA3kdhWdI 6vTR4Sx1HY8qiowAmyDUISkL7icGSheuM7iIj9LNHN4DWeIEiwFlUPo64Lz5RMpg/vWy iNA4T0pF/XjDVjjIDMwkMXdRqprQcnwkiNxysMKtZw+kGMlqvrQo9+juhIcmZvXFssev 6ImYO9nB4Mv+3TeWLZJT3bMqj7dQjq5a3LD5BoTYsVKKkGaeg8RTHrEmc9wZUzudN3lF bESh7bS0zXlGq8oRRQCG7TAeOKhcaEJvLkgs7sojyCB31JItwcbpfuMUQM8+yq6i1X4k 7x1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/CxwV4zT6xTijPhn1y007FdQODJxJi2+tT6U1GjyDx8=; fh=aH+FGj6Ok9jgSQ7w+jHOT279iMAIvJYaV85EeY+whZk=; b=pVNVQRMaqLoHmhdxda993tF2V7WhcEEusKdiYG0Uh+Xbu+sLmSaf3QCUXLaTluNUfk UXXLlOIa3zJ5dKjHZg7OpCnu9dGDft3O70yhWge4iSGpBW7DBLz0ychfRCJT3sNHDFH1 CEaadljZdqRDUDWv1rALKDKsjB/xIKHG6pN91WeueHyzIbVaRhu85eZqnYsgekMF7/X3 sZCZrdwBN7YlvKto+mQ64hir1sokq6KicqL39IDp21NzKft9Xt1fGUET2AdmYxwQHfIX hSB9T55s89w2xuwGPoFSP3mvUi87En/TRUZ27uD+42VDZ8/iHCp5izJ6AQvEeaT13yLK 7lNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=YgLtGBpW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o4-20020a17090a5b0400b00268093d0a8csi2205602pji.155.2023.08.10.15.21.16; Thu, 10 Aug 2023 15:21:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=YgLtGBpW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235756AbjHJUY1 (ORCPT + 99 others); Thu, 10 Aug 2023 16:24:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230304AbjHJUY0 (ORCPT ); Thu, 10 Aug 2023 16:24:26 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D21032710; Thu, 10 Aug 2023 13:24:24 -0700 (PDT) Received: from notapiano.myfiosgateway.com (zone.collabora.co.uk [167.235.23.81]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: nfraprado) by madras.collabora.co.uk (Postfix) with ESMTPSA id 723476607236; Thu, 10 Aug 2023 21:24:21 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1691699063; bh=CWAkbpMFXFQs1T6gDBqCxpIcKwmIAlhfHzW4mUk9Ib8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YgLtGBpWpeULzTa9f9Omhj15XDPiT7VJ+uX1qfW2e8LRP6KgwNCiCD+h2oLZloxuf JSp1ov1/ODjCKt+qGYhCWd8C41+87eDRkzIfQxp7CqJ/foOQrHP0SDTcJ9+qXmLz2k p/sm5GcLtd9XpIynb19abDI1+H7FZ78Ak9JjW5aKB6jOH33T6iUaMR8fUit6EK96pe 0ITNp/CeQoBJFFsNTiPuUpfB+hBnklhaT0uftRHvsY2jQPekLy9piABYakLqCZ7G1b DF686k73+pTKJP11J0HaaU/iBD1MVjJ675plGFnSa5uK8/ue6JrgbzsfSku2uCBv2P /9suWEGDqdNPg== From: =?UTF-8?q?N=C3=ADcolas=20F=2E=20R=2E=20A=2E=20Prado?= To: Rob Herring , Frank Rowand , Shuah Khan Cc: cocci@inria.fr, Mark Brown , Nicolas Palix , kernelci@lists.linux.dev, Julia Lawall , Bjorn Andersson , kernel@collabora.com, Guenter Roeck , =?UTF-8?q?N=C3=ADcolas=20F=2E=20R=2E=20A=2E=20Prado?= , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/2] scripts/dtc: Add script to extract matchable DT compatibles Date: Thu, 10 Aug 2023 16:23:50 -0400 Message-ID: <20230810202413.1780286-2-nfraprado@collabora.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230810202413.1780286-1-nfraprado@collabora.com> References: <20230810202413.1780286-1-nfraprado@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce a script to extract all compatibles that can match a device described on the Devicetree to a driver. The compatible extraction is done by running Coccinelle with a newly introduced Coccinelle file that detects compatibles listed inside a of_device_id table which is referenced by the of_match_table of a driver struct. Signed-off-by: NĂ­colas F. R. A. Prado --- scripts/dtc/extract-matchable-dt-compatibles | 33 +++++++++++ scripts/dtc/matchable_dt_compatibles.cocci | 58 ++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100755 scripts/dtc/extract-matchable-dt-compatibles create mode 100644 scripts/dtc/matchable_dt_compatibles.cocci diff --git a/scripts/dtc/extract-matchable-dt-compatibles b/scripts/dtc/extract-matchable-dt-compatibles new file mode 100755 index 000000000000..b5e96c7ba42e --- /dev/null +++ b/scripts/dtc/extract-matchable-dt-compatibles @@ -0,0 +1,33 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (c) 2023 Collabora Ltd +# +# Based on coccicheck script. +# +# This script uses Coccinelle to extract all compatibles that can be matched by +# Devicetree devices from the kernel source. + +DIR="$(dirname $(readlink -f $0))" +SPATCH=`which ${SPATCH:=spatch}` +COCCI_FILE=$DIR/matchable_dt_compatibles.cocci + +if [ ! -x "$SPATCH" ]; then + echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/' + exit 1 +fi + +# Use only one thread per core by default if hyperthreading is enabled +THREADS_PER_CORE=$(LANG=C lscpu | grep "Thread(s) per core: " | tr -cd "[:digit:]") +if [ -z "$J" ]; then + NPROC=$(getconf _NPROCESSORS_ONLN) + if [ $THREADS_PER_CORE -gt 1 -a $NPROC -gt 4 ] ; then + NPROC=$((NPROC/2)) + fi +else + NPROC="$J" +fi + +"$SPATCH" --cocci-file "$COCCI_FILE" --dir . --jobs "$NPROC" --chunksize 1 \ + --no-show-diff --no-includes --include-headers --very-quiet \ + | grep '"' | sed -e 's/"//g;s/^ *\([^ ]*\) *$/\1/' diff --git a/scripts/dtc/matchable_dt_compatibles.cocci b/scripts/dtc/matchable_dt_compatibles.cocci new file mode 100644 index 000000000000..ecd3705681aa --- /dev/null +++ b/scripts/dtc/matchable_dt_compatibles.cocci @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright: (C) 2023 Collabora Ltd +@rule1@ +identifier table; +type drv; +identifier drvname; +identifier drvfield; +identifier drvfield1; +identifier drvfield2; +@@ + +( +drv drvname = { + .drvfield = { + .of_match_table = table, + }, +}; +| +drv drvname = { + .drvfield = { + .of_match_table = of_match_ptr(table), + }, +}; +| +// Accounts for mdio and spimem drivers +drv drvname = { + .drvfield1 = { + .drvfield2 = { + .of_match_table = table, + }, + }, +}; +| +drv drvname = { + .drvfield1 = { + .drvfield2 = { + .of_match_table = of_match_ptr(table), + }, + }, +}; +) + +@rule2@ +identifier rule1.table; +expression compat; +@@ + +struct of_device_id table[] = { +..., +{ .compatible = compat, }, +... +}; + +@script:python@ +compat << rule2.compat; +@@ + +print("%s" % compat) -- 2.41.0