From nobody Mon Sep 14 20:12:14 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hkGXH0T7Fz6rfYG for ; Mon, 14 Sep 2026 20:12:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hkGXG6Rpsz4fKP for ; Mon, 14 Sep 2026 20:12:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789416734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Zp+Df/Ezz9nMZqLin9mWJ6rU6wPhESyUQVSruWPsJRc=; b=PLaKtZpExYclAH/NaPWvjjFk5DxO9kw3qZWOgyk7rxtCfi686m+a/OyYRxmXU6N+5+qAdu SqYBUOUp8qOtrCzyTVcIV22ccWpy/m/qV4cQudY3BBEb8sxMyJFnzXTFZbZinitepAmOwI 6yd0ainsNkSSUz5t+yQLpXu/UhhUqWGgogEcBByZIBi1RyunxMSFzbiCTPbY1C171UzwEW QX5HP3+q3q9EuYsxHsGfq7/swhFQgETfLMI8/MP2n1LXknFO+zysVlfKoaCdCpBbcFeuER R/m2c0Nw2A5eZljDHpl698FMZQia/ZJUTIHT0QRqk3jxACMC3HGPK63Be7hoMw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1789416734; b=iv1/BAXLgmUqDbdxTgovHNBp21If0ik8OrOYgH9Pwoyg03yAXR1SBzH5jGSJUaQOSBSCIA 7JeUJBb8THrij/wBdAqsRkK/0Jln0gnrwLEet2+1u8A4zZf7KtreY9SIVRQY57cG3UD1mS 1JAlQhjWaLtjXNNLeYg8yJn7VmwLeo58CNSpDfnRgsqt1xLsUYklf9Uk3gs5QsVPnpjkOS v6bRMIRw3SyPH9505h58j8oRDpSUVfRi/dY0VvvsExl65EWTtpNleEnLnp9B9MSSUn7DwA Lx3Z8mW3Tf1EvVFHh9oKIuh8M0dLIi4jc9cE3ZDDrnUHRtCnNgwEv7TmH4owqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789416734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Zp+Df/Ezz9nMZqLin9mWJ6rU6wPhESyUQVSruWPsJRc=; b=HcKglM7rUjfk/yXN6kz5XUi15Hnt76mnMDrU3J4KPHnAHmGyDOiQy3ePeaEBifP7kGPwF7 obLtpxX0/shq1a+O+B2UIwdHGY+MDONpyUnvdGEBs68p7ZpthyM+m4WyGqNptdX746n+ZT e+uqZlBcQXUrWQ1zB5dL0OP5p5i9q+gbSOZ4T+jJKmzwdmrHVLVruFtuBAiEEqAjYke31b gnDIYPUxdzKFoNthGIIcQ8QxOEaelfPpea3vi8aJmrDlMU98vAtJE/VjJHNTGDSC9kqMAG IwEvlsWLTMZ5HwMBlUDjWL+Knzz59s5ESx23iR8KVvDUqsScPakLlLe3iANlPw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hkGXG5TrczSRV for ; Mon, 14 Sep 2026 20:12:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 312d0 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 14 Sep 2026 20:12:14 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jean-=?utf-8?Q?S=C3=A9bast?==?utf-8?Q?ien P=C3=A9?=dron Subject: git: 5fb3aea2d8c4 - main - linuxkpi: Add x86 CPU ID matching functions and macros List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dumbbell X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5fb3aea2d8c436afa87605d8d7798ae8b09d558c Auto-Submitted: auto-generated Date: Mon, 14 Sep 2026 20:12:14 +0000 Message-Id: <6aa8551e.312d0.67f8e4ac@gitrepo.freebsd.org> The branch main has been updated by dumbbell: URL: https://cgit.FreeBSD.org/src/commit/?id=5fb3aea2d8c436afa87605d8d7798ae8b09d558c commit 5fb3aea2d8c436afa87605d8d7798ae8b09d558c Author: Jean-Sébastien Pédron AuthorDate: 2026-06-17 14:01:05 +0000 Commit: Jean-Sébastien Pédron CommitDate: 2026-09-14 20:06:50 +0000 linuxkpi: Add x86 CPU ID matching functions and macros There are two parts that go together: * `X86_MATCH_VFM()` to declare a matching pattern * `x86_match_cpu()` to check if the current CPU matches one of the patterns in an array. The i915 DRM driver started to use this in Linux 6.14. Reviewed by: kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D57700 --- .../linuxkpi/common/include/asm/cpu_device_id.h | 25 +++++++++++++++ sys/compat/linuxkpi/common/include/linux/bits.h | 2 ++ .../common/include/linux/mod_devicetable.h | 17 ++++++++++ sys/compat/linuxkpi/common/src/linux_compat.c | 37 ++++++++++++++++++++++ 4 files changed, 81 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/asm/cpu_device_id.h b/sys/compat/linuxkpi/common/include/asm/cpu_device_id.h index a01d63a75a7e..5741cddd52b1 100644 --- a/sys/compat/linuxkpi/common/include/asm/cpu_device_id.h +++ b/sys/compat/linuxkpi/common/include/asm/cpu_device_id.h @@ -7,6 +7,8 @@ #ifndef _LINUXKPI_ASM_CPU_DEVICE_ID_H_ #define _LINUXKPI_ASM_CPU_DEVICE_ID_H_ +#include + #define VFM_MODEL_BIT 0 #define VFM_FAMILY_BIT 8 #define VFM_VENDOR_BIT 16 @@ -30,4 +32,27 @@ #include #include +#define X86_CPU_ID_FLAG_ENTRY_VALID BIT(0) + +#define X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE( \ + _vendor, _family, _model, _steppings, _feature) { \ + .vendor = _vendor, \ + .family = _family, \ + .model = _model, \ + .steppings = _steppings, \ + .feature = _feature, \ + .flags = X86_CPU_ID_FLAG_ENTRY_VALID, \ +} + +#define X86_MATCH_VFM(_vfm, _data) \ + X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE( \ + VFM_VENDOR(_vfm), \ + VFM_FAMILY(_vfm), \ + VFM_MODEL(_vfm), \ + X86_STEPPING_ANY, \ + X86_FEATURE_ANY) + +const struct x86_cpu_id *linuxkpi_x86_match_cpu(const struct x86_cpu_id *match_array); +#define x86_match_cpu(match_array) linuxkpi_x86_match_cpu(match_array) + #endif /* _LINUXKPI_ASM_CPU_DEVICE_ID_H_ */ diff --git a/sys/compat/linuxkpi/common/include/linux/bits.h b/sys/compat/linuxkpi/common/include/linux/bits.h index 53deb7cbbe88..f5e688cdb7c0 100644 --- a/sys/compat/linuxkpi/common/include/linux/bits.h +++ b/sys/compat/linuxkpi/common/include/linux/bits.h @@ -8,6 +8,8 @@ #ifndef _LINUXKPI_LINUX_BITS_H_ #define _LINUXKPI_LINUX_BITS_H_ +#include + #define GENMASK(h, l) (((~0UL) >> (BITS_PER_LONG - (h) - 1)) & ((~0UL) << (l))) #define GENMASK_ULL(h, l) (((~0ULL) >> (BITS_PER_LONG_LONG - (h) - 1)) & ((~0ULL) << (l))) diff --git a/sys/compat/linuxkpi/common/include/linux/mod_devicetable.h b/sys/compat/linuxkpi/common/include/linux/mod_devicetable.h index b345b98325e1..e015bde5061e 100644 --- a/sys/compat/linuxkpi/common/include/linux/mod_devicetable.h +++ b/sys/compat/linuxkpi/common/include/linux/mod_devicetable.h @@ -81,6 +81,23 @@ struct dmi_system_id { #define ACPI_ID_LEN 16 +struct x86_cpu_id { + uint16_t vendor; + uint16_t family; + uint16_t model; + uint16_t steppings; + uint16_t feature; + uint16_t flags; +}; + +#define X86_VENDOR_ANY 0xffff +#define X86_FAMILY_ANY 0 +#define X86_MODEL_ANY 0 +#define X86_STEPPING_ANY 0 +#define X86_STEP_MIN 0 +#define X86_STEP_MAX 0xf +#define X86_FEATURE_ANY 0 + /* ----------------------------------------------------------------------------- * USB */ diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c index 8fb09d5914fb..3cdeb8e2d297 100644 --- a/sys/compat/linuxkpi/common/src/linux_compat.c +++ b/sys/compat/linuxkpi/common/src/linux_compat.c @@ -100,8 +100,11 @@ #include #include #include +#include #if defined(__i386__) || defined(__amd64__) +#include +#include #include #include #endif @@ -3084,6 +3087,40 @@ linux_compat_uninit(void *arg) } SYSUNINIT(linux_compat, SI_SUB_DRIVERS, SI_ORDER_SECOND, linux_compat_uninit, NULL); +const struct x86_cpu_id * +linuxkpi_x86_match_cpu(const struct x86_cpu_id *match_array) +{ + const struct x86_cpu_id *match; + + for (match = match_array; + (match->flags & X86_CPU_ID_FLAG_ENTRY_VALID) != 0; + match++) { + if (match->vendor != X86_VENDOR_ANY && + match->vendor != boot_cpu_data.x86_vendor) + continue; + + if (match->family != X86_FAMILY_ANY && + match->family != boot_cpu_data.x86) + continue; + + if (match->model != X86_MODEL_ANY && + match->model != boot_cpu_data.x86_model) + continue; + + if (match->model != X86_STEPPING_ANY && + (match->steppings & BIT(boot_cpu_data.x86_stepping)) == 0) + continue; + + if (match->feature != X86_FEATURE_ANY && + !static_cpu_has(match->feature)) + continue; + + return (match); + } + + return (NULL); +} + /* * NOTE: Linux frequently uses "unsigned long" for pointer to integer * conversion and vice versa, where in FreeBSD "uintptr_t" would be