From: Laura Nao <laura.nao@collabora.com>
To: rafael@kernel.org, lenb@kernel.org, shuah@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org,
linux-kselftest@vger.kernel.org, groeck@chromium.org,
broonie@kernel.org, robh+dt@kernel.org, kernelci@lists.linux.dev,
kernel@collabora.com, Laura Nao <laura.nao@collabora.com>
Subject: [RFC PATCH 1/2] acpi: Add script to extract ACPI device ids in the kernel
Date: Mon, 25 Sep 2023 17:58:05 +0200 [thread overview]
Message-ID: <20230925155806.1812249-2-laura.nao@collabora.com> (raw)
In-Reply-To: <20230925155806.1812249-1-laura.nao@collabora.com>
Add a script to extract all the supported acpi device ids
from kernel sources.
The list of IDs returned by the script can be used as a
reference to determine if a device declared in the ACPI namespace
with certain _HID/_CID is supported by the kernel or not.
Signed-off-by: Laura Nao <laura.nao@collabora.com>
---
MAINTAINERS | 1 +
| 60 +++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+)
create mode 100755 scripts/acpi/acpi-extract-ids
diff --git a/MAINTAINERS b/MAINTAINERS
index 27751573e314..7540316d82f5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -294,6 +294,7 @@ F: drivers/pnp/pnpacpi/
F: include/acpi/
F: include/linux/acpi.h
F: include/linux/fwnode.h
+F: scripts/acpi/acpi-extract-ids
F: tools/power/acpi/
ACPI APEI
--git a/scripts/acpi/acpi-extract-ids b/scripts/acpi/acpi-extract-ids
new file mode 100755
index 000000000000..12c8e09281dd
--- /dev/null
+++ b/scripts/acpi/acpi-extract-ids
@@ -0,0 +1,60 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Heavily inspired by the scripts/dtc/dt-extract-compatibles script,
+# adapted for the ACPI use case.
+#
+
+import os
+import glob
+import re
+import argparse
+
+
+def parse_acpi_device_ids(file):
+ """ Find all device ID strings in acpi_device_id struct """
+ id_list = []
+
+ with open(file, 'r', encoding='utf-8') as f:
+ data = f.read().replace('\n', '')
+
+ for m in re.finditer(r'acpi_device_id(\s+\S+)?\s+(\S+)\[\](\s+\S+)?\s*=\s*({.*?);', data):
+ id_list += re.findall(r'\"(\S+)\"', m[4])
+
+ return id_list
+
+
+def print_acpi_device_ids(filename, id_list):
+ if not id_list:
+ return
+ if show_filename:
+ compat_str = ' '.join(id_list)
+ print(filename + ": ID(s): " + compat_str)
+ else:
+ print(*id_list, sep='\n')
+
+
+def files_to_parse(path_args):
+ for f in path_args:
+ if os.path.isdir(f):
+ for filename in glob.iglob(f + "/**/*.c", recursive=True):
+ yield filename
+ else:
+ yield f
+
+
+show_filename = False
+
+if __name__ == "__main__":
+ ap = argparse.ArgumentParser()
+ ap.add_argument("cfile", type=str, nargs='*',
+ help="C source files or directories to parse")
+ ap.add_argument('-H', '--with-filename',
+ help="Print filename with device ids", action="store_true")
+ args = ap.parse_args()
+
+ show_filename = args.with_filename
+
+ for f in files_to_parse(args.cfile):
+ id_list = parse_acpi_device_ids(f)
+ print_acpi_device_ids(f, id_list)
--
2.30.2
next prev parent reply other threads:[~2023-09-25 15:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-25 15:58 [RFC PATCH 0/2] Add a test to verify device probing on ACPI platforms Laura Nao
2023-09-25 15:58 ` Laura Nao [this message]
2023-09-25 15:58 ` [RFC PATCH 2/2] kselftest: Add test to detect unprobed devices " Laura Nao
2023-10-26 10:00 ` [RFC PATCH 0/2] Add a test to verify device probing " Laura Nao
2023-11-23 7:42 ` Dan Carpenter
2023-11-23 12:09 ` Laura Nao
2023-11-23 15:14 ` Dan Carpenter
2023-11-24 16:04 ` Laura Nao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230925155806.1812249-2-laura.nao@collabora.com \
--to=laura.nao@collabora.com \
--cc=broonie@kernel.org \
--cc=groeck@chromium.org \
--cc=kernel@collabora.com \
--cc=kernelci@lists.linux.dev \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=robh+dt@kernel.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®