Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/pci Introduce autoconfiguration helpers based around...
details: https://anonhg.NetBSD.org/src/rev/194011975d6e
branches: trunk
changeset: 980210:194011975d6e
user: thorpej <thorpej%NetBSD.org@localhost>
date: Wed Jan 27 05:00:15 2021 +0000
description:
Introduce autoconfiguration helpers based around device_compatible_entry:
- pci_compatible_match(): matches against the PCI ID.
- pci_compatible_match_subsys(): matches against PCI SUBSYS ID.
- pci_compatible_lookup(): look up entry by PCI ID.
- pci_compatible_lookup_subsys(): look up entry by PCI SUBSYS ID.
- pci_compatible_lookup_id(): look up entry by an arbitrary ID using the
PCI ID code conventions.
- Define PCI_COMPAT_EOL as a compat data array sentinel.
diffstat:
sys/dev/pci/pci_subr.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
sys/dev/pci/pcivar.h | 20 ++++++++++++++++++--
2 files changed, 64 insertions(+), 4 deletions(-)
diffs (110 lines):
diff -r b90131462468 -r 194011975d6e sys/dev/pci/pci_subr.c
--- a/sys/dev/pci/pci_subr.c Wed Jan 27 04:55:42 2021 +0000
+++ b/sys/dev/pci/pci_subr.c Wed Jan 27 05:00:15 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_subr.c,v 1.224 2020/05/30 10:43:46 jdolecek Exp $ */
+/* $NetBSD: pci_subr.c,v 1.225 2021/01/27 05:00:15 thorpej Exp $ */
/*
* Copyright (c) 1997 Zubin D. Dittia. All rights reserved.
@@ -40,7 +40,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.224 2020/05/30 10:43:46 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.225 2021/01/27 05:00:15 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "opt_pci.h"
@@ -84,6 +84,50 @@
static void pci_conf_print_pcie_power(uint8_t, unsigned int);
#define PCIREG_SHIFTOUT(a, b) ((pcireg_t)__SHIFTOUT((a), (b)))
+#ifdef _KERNEL
+/*
+ * Common routines used to match a compatible device by its PCI ID code.
+ */
+
+const struct device_compatible_entry *
+pci_compatible_lookup_id(pcireg_t const id,
+ const struct device_compatible_entry *dce)
+{
+ return device_compatible_lookup_id(id, PCI_COMPAT_EOL_VALUE, dce);
+}
+
+const struct device_compatible_entry *
+pci_compatible_lookup(const struct pci_attach_args * const pa,
+ const struct device_compatible_entry * const dce)
+{
+ return pci_compatible_lookup_id(pa->pa_id, dce);
+}
+
+const struct device_compatible_entry *
+pci_compatible_lookup_subsys(const struct pci_attach_args * const pa,
+ const struct device_compatible_entry * const dce)
+{
+ const pcireg_t subsysid =
+ pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
+
+ return pci_compatible_lookup_id(subsysid, dce);
+}
+
+int
+pci_compatible_match(const struct pci_attach_args * const pa,
+ const struct device_compatible_entry * const dce)
+{
+ return pci_compatible_lookup(pa, dce) != NULL;
+}
+
+int
+pci_compatible_match_subsys(const struct pci_attach_args * const pa,
+ const struct device_compatible_entry * const dce)
+{
+ return pci_compatible_lookup_subsys(pa, dce) != NULL;
+}
+#endif /* _KERNEL */
+
/*
* Descriptions of known PCI classes and subclasses.
*
diff -r b90131462468 -r 194011975d6e sys/dev/pci/pcivar.h
--- a/sys/dev/pci/pcivar.h Wed Jan 27 04:55:42 2021 +0000
+++ b/sys/dev/pci/pcivar.h Wed Jan 27 05:00:15 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pcivar.h,v 1.113 2018/12/01 01:23:24 msaitoh Exp $ */
+/* $NetBSD: pcivar.h,v 1.114 2021/01/27 05:00:16 thorpej Exp $ */
/*
* Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.
@@ -298,7 +298,6 @@
bus_size_t, bus_size_t, bus_space_tag_t *, bus_space_handle_t *,
bus_addr_t *, bus_size_t *);
-
int pci_find_rom(const struct pci_attach_args *, bus_space_tag_t,
bus_space_handle_t, bus_size_t,
int, bus_space_handle_t *, bus_size_t *);
@@ -315,6 +314,23 @@
/*
* Helper functions for autoconfiguration.
*/
+
+#define PCI_COMPAT_EOL_VALUE (0xffffffffU)
+#define PCI_COMPAT_EOL { .id = PCI_COMPAT_EOL_VALUE }
+
+const struct device_compatible_entry *
+ pci_compatible_lookup_id(pcireg_t,
+ const struct device_compatible_entry *);
+const struct device_compatible_entry *
+ pci_compatible_lookup(const struct pci_attach_args *,
+ const struct device_compatible_entry *);
+int pci_compatible_match(const struct pci_attach_args *,
+ const struct device_compatible_entry *);
+const struct device_compatible_entry *
+ pci_compatible_lookup_subsys(const struct pci_attach_args *,
+ const struct device_compatible_entry *);
+int pci_compatible_match_subsys(const struct pci_attach_args *,
+ const struct device_compatible_entry *);
#ifndef PCI_MACHDEP_ENUMERATE_BUS
int pci_enumerate_bus(struct pci_softc *, const int *,
int (*)(const struct pci_attach_args *), struct pci_attach_args *);
Home |
Main Index |
Thread Index |
Old Index