From owner-svn-src-all@FreeBSD.ORG Fri Dec 13 17:23:48 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8F42DCD2; Fri, 13 Dec 2013 17:23:48 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 612F91B05; Fri, 13 Dec 2013 17:23:48 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBDHNm1v041881; Fri, 13 Dec 2013 17:23:48 GMT (envelope-from ian@svn.freebsd.org) Received: (from ian@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBDHNm6B041879; Fri, 13 Dec 2013 17:23:48 GMT (envelope-from ian@svn.freebsd.org) Message-Id: <201312131723.rBDHNm6B041879@svn.freebsd.org> From: Ian Lepore Date: Fri, 13 Dec 2013 17:23:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r259316 - stable/10/sys/dev/ofw X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Dec 2013 17:23:48 -0000 Author: ian Date: Fri Dec 13 17:23:47 2013 New Revision: 259316 URL: http://svnweb.freebsd.org/changeset/base/259316 Log: MFC r257130: Add a helper routine to search for a compat string in a table that associates compat strings with arbitrary values that mean something to the driver. This is handy for drivers that support several variations of similar hardware and need to know which one matched. Modified: stable/10/sys/dev/ofw/ofw_bus_subr.c stable/10/sys/dev/ofw/ofw_bus_subr.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/ofw/ofw_bus_subr.c ============================================================================== --- stable/10/sys/dev/ofw/ofw_bus_subr.c Fri Dec 13 17:10:23 2013 (r259315) +++ stable/10/sys/dev/ofw/ofw_bus_subr.c Fri Dec 13 17:23:47 2013 (r259316) @@ -197,6 +197,21 @@ ofw_bus_is_compatible_strict(device_t de return (0); } +const struct ofw_compat_data * +ofw_bus_search_compatible(device_t dev, const struct ofw_compat_data *compat) +{ + + if (compat == NULL) + return NULL; + + for (; compat->ocd_str != NULL; ++compat) { + if (ofw_bus_is_compatible(dev, compat->ocd_str)) + break; + } + + return (compat); +} + int ofw_bus_has_prop(device_t dev, const char *propname) { Modified: stable/10/sys/dev/ofw/ofw_bus_subr.h ============================================================================== --- stable/10/sys/dev/ofw/ofw_bus_subr.h Fri Dec 13 17:10:23 2013 (r259315) +++ stable/10/sys/dev/ofw/ofw_bus_subr.h Fri Dec 13 17:23:47 2013 (r259316) @@ -47,6 +47,11 @@ struct ofw_bus_iinfo { pcell_t opi_addrc; }; +struct ofw_compat_data { + const char *ocd_str; + uintptr_t ocd_data; +}; + /* Generic implementation of ofw_bus_if.m methods and helper routines */ int ofw_bus_gen_setup_devinfo(struct ofw_bus_devinfo *, phandle_t); void ofw_bus_gen_destroy_devinfo(struct ofw_bus_devinfo *); @@ -74,6 +79,16 @@ void ofw_bus_find_iparent(phandle_t); int ofw_bus_is_compatible(device_t, const char *); int ofw_bus_is_compatible_strict(device_t, const char *); +/* + * Helper routine to search a list of compat properties. The table is + * terminated by an entry with a NULL compat-string pointer; a pointer to that + * table entry is returned if none of the compat strings match for the device, + * giving you control over the not-found value. Will not return NULL unless the + * provided table pointer is NULL. + */ +const struct ofw_compat_data * + ofw_bus_search_compatible(device_t, const struct ofw_compat_data *); + /* Helper routine for checking existence of a prop */ int ofw_bus_has_prop(device_t, const char *);