git: ace666bd21a2 - main - linuxkpi: Define `PCI_POSSIBLE_ERROR()` macro

From: Jean-Sébastien Pédron <dumbbell_at_FreeBSD.org>
Date: Mon, 05 Jan 2026 20:09:23 UTC
The branch main has been updated by dumbbell:

URL: https://cgit.FreeBSD.org/src/commit/?id=ace666bd21a204c62807f2c899402a7dc9ab161a

commit ace666bd21a204c62807f2c899402a7dc9ab161a
Author:     Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
AuthorDate: 2025-08-09 16:14:05 +0000
Commit:     Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
CommitDate: 2026-01-05 19:32:44 +0000

    linuxkpi: Define `PCI_POSSIBLE_ERROR()` macro
    
    It comes with `PCI_ERROR_RESPONSE` and `PCI_SET_ERROR_RESPONSE()` but we
    don't use them so far. Therefore `PCI_POSSIBLE_ERROR()` will always
    reture false.
    
    As written in the comment, this macro is a bit weird given the Linux
    `pci_read_*() functions can return an error code separately from the
    read value.
    
    The `PCI_POSSIBLE_ERROR()` macro started to be used by the amdgpu DRM
    driver in Linux 6.10.
    
    Reviewed by:    emaste
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D54487
---
 sys/compat/linuxkpi/common/include/linux/pci.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h
index 06336bf963d6..8fe09554aed2 100644
--- a/sys/compat/linuxkpi/common/include/linux/pci.h
+++ b/sys/compat/linuxkpi/common/include/linux/pci.h
@@ -253,6 +253,20 @@ extern const char *pci_power_names[6];
 #define	PCI_IRQ_LEGACY			PCI_IRQ_INTX
 #endif
 
+/*
+ * Linux PCI code uses `PCI_SET_ERROR_RESPONSE()` to indicate to the caller of
+ * a `pci_read_*()` function that the read failed. An example of failure is
+ * whether the device was disconnected. It is a bit weird because Linux
+ * `pci_read_*()` can return an error value, as the read value is stored in a
+ * integer passed by pointer.
+ *
+ * We don't set PCI_ERROR_RESPONSE anywhere as of this commit, but the DRM
+ * drivers started to use `PCI_POSSIBLE_ERROR()`.
+ */
+#define	PCI_ERROR_RESPONSE		(~0ULL)
+#define	PCI_SET_ERROR_RESPONSE(val)	(*(val) = ((typeof(*(val))) PCI_ERROR_RESPONSE))
+#define	PCI_POSSIBLE_ERROR(val)		((val) == ((typeof(val)) PCI_ERROR_RESPONSE))
+
 struct pci_dev;
 
 struct pci_driver {