From 5fde66222dc02764796983f1b52fd74c0b9ba09b Mon Sep 17 00:00:00 2001 From: kettenis Date: Sun, 21 Jan 2024 13:36:40 +0000 Subject: [PATCH] Add support for multiple matches in the component code. ok jsg@ --- sys/dev/pci/drm/drm_linux.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/sys/dev/pci/drm/drm_linux.c b/sys/dev/pci/drm/drm_linux.c index cfce2fcae1e..f89e28c1114 100644 --- a/sys/dev/pci/drm/drm_linux.c +++ b/sys/dev/pci/drm/drm_linux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: drm_linux.c,v 1.108 2024/01/16 23:37:51 jsg Exp $ */ +/* $OpenBSD: drm_linux.c,v 1.109 2024/01/21 13:36:40 kettenis Exp $ */ /* * Copyright (c) 2013 Jonathan Gray * Copyright (c) 2015, 2016 Mark Kettenis @@ -3421,23 +3421,32 @@ component_bind_all(struct device *dev, void *data) return ret; } -struct component_match { +struct component_match_entry { int (*compare)(struct device *, void *); void *data; }; +struct component_match { + struct component_match_entry match[4]; + int nmatches; +}; + int component_master_add_with_match(struct device *dev, const struct component_master_ops *ops, struct component_match *match) { struct component *component; int found = 0; - int ret; + int i, ret; SLIST_FOREACH(component, &component_list, next) { - if (match->compare(component->dev, match->data)) { - component->adev = dev; - found = 1; + for (i = 0; i < match->nmatches; i++) { + struct component_match_entry *m = &match->match[i]; + if (m->compare(component->dev, m->data)) { + component->adev = dev; + found = 1; + break; + } } } @@ -3883,15 +3892,18 @@ drm_of_component_match_add(struct device *master, int (*compare)(struct device *, void *), struct device_node *np) { - struct component_match *match; + struct component_match *match = *matchptr; - if (*matchptr == NULL) { + if (match == NULL) { match = malloc(sizeof(struct component_match), M_DEVBUF, M_WAITOK | M_ZERO); - match->compare = compare; - match->data = np; *matchptr = match; } + + KASSERT(match->nmatches < nitems(match->match)); + match->match[match->nmatches].compare = compare; + match->match[match->nmatches].data = np; + match->nmatches++; } #endif -- 2.20.1