From owner-svn-src-head@freebsd.org Fri Dec 11 05:27:55 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 31A099D681D; Fri, 11 Dec 2015 05:27:55 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0D5A31F19; Fri, 11 Dec 2015 05:27:54 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tBB5RsBd011879; Fri, 11 Dec 2015 05:27:54 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tBB5Rs8u011875; Fri, 11 Dec 2015 05:27:54 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201512110527.tBB5Rs8u011875@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Fri, 11 Dec 2015 05:27:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r292077 - in head/sys: kern sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Dec 2015 05:27:55 -0000 Author: imp Date: Fri Dec 11 05:27:53 2015 New Revision: 292077 URL: https://svnweb.freebsd.org/changeset/base/292077 Log: Create the MDT_PNP_INFO metadata record to communicate PNP info about modules. External agents may use this data to automatically load those modules. Differential Review: https://reviews.freebsd.org/D3461 Modified: head/sys/kern/kern_linker.c head/sys/sys/module.h Modified: head/sys/kern/kern_linker.c ============================================================================== --- head/sys/kern/kern_linker.c Fri Dec 11 05:26:46 2015 (r292076) +++ head/sys/kern/kern_linker.c Fri Dec 11 05:27:53 2015 (r292077) @@ -1409,7 +1409,7 @@ linker_addmodules(linker_file_t lf, stru if (mp->md_type != MDT_VERSION) continue; modname = mp->md_cval; - ver = ((struct mod_version *)mp->md_data)->mv_version; + ver = ((const struct mod_version *)mp->md_data)->mv_version; if (modlist_lookup(modname, ver) != NULL) { printf("module %s already present!\n", modname); /* XXX what can we do? this is a build error. :-( */ @@ -1530,7 +1530,7 @@ restart: if (mp->md_type != MDT_VERSION) continue; modname = mp->md_cval; - nver = ((struct mod_version *) + nver = ((const struct mod_version *) mp->md_data)->mv_version; if (modlist_lookup(modname, nver) != NULL) { @@ -2056,7 +2056,7 @@ linker_load_dependencies(linker_file_t l if (mp->md_type != MDT_VERSION) continue; modname = mp->md_cval; - ver = ((struct mod_version *)mp->md_data)->mv_version; + ver = ((const struct mod_version *)mp->md_data)->mv_version; mod = modlist_lookup(modname, ver); if (mod != NULL) { printf("interface %s.%d already present in the KLD" Modified: head/sys/sys/module.h ============================================================================== --- head/sys/sys/module.h Fri Dec 11 05:26:46 2015 (r292076) +++ head/sys/sys/module.h Fri Dec 11 05:27:53 2015 (r292077) @@ -89,10 +89,19 @@ struct mod_version { struct mod_metadata { int md_version; /* structure version MDTV_* */ int md_type; /* type of entry MDT_* */ - void *md_data; /* specific data */ + const void *md_data; /* specific data */ const char *md_cval; /* common string label */ }; +struct mod_pnp_match_info +{ + const char *descr; /* Description of the table */ + const char *bus; /* Name of the bus for this table */ + const void *table; /* Pointer to pnp table */ + int entry_len; /* Length of each entry in the table (may be */ + /* logner than descr descriebs). */ + int num_entry; /* Number of entries in the table */ +}; #ifdef _KERNEL #include @@ -155,6 +164,44 @@ struct mod_metadata { MODULE_METADATA(_##module##_version, MDT_VERSION, \ &_##module##_version, #module) +/** + * Generic macros to create pnp info hints that modules may export + * to allow external tools to parse their intenral device tables + * to make an informed guess about what driver(s) to load. + */ +#define MODULE_PNP_INFO(d, b, unique, t, l, n) \ + static const struct mod_pnp_match_info _module_pnp_##b##_##unique = { \ + .descr = d, \ + .bus = #b, \ + .table = t, \ + .entry_len = l, \ + .num_entry = n \ + }; \ + MODULE_METADATA(_md_##b##_pnpinfo_##unique, MDT_PNP_INFO, \ + &_module_pnp_##b##_##unique, #b); +/** + * descr is a string that describes each entry in the table. The general + * form is (TYPE:pnp_name[/pnp_name];)* + * where TYPE is one of the following: + * U8 uint8_t element + * V8 like U8 and 0xff means match any + * G16 uint16_t element, any value >= matches + * L16 uint16_t element, any value <= matches + * M16 uint16_t element, mask of which of the following fields to use. + * U16 uint16_t element + * V16 like U16 and 0xffff means match any + * U32 uint32_t element + * V32 like U32 and 0xffffffff means match any + * W32 Two 16-bit values with first pnp_name in LSW and second in MSW. + * Z pointer to a string to match exactly + * D like Z, but is the string passed to device_set_descr() + * P A pointer that should be ignored + * E EISA PNP Identifier (in binary, but bus publishes string) + * K Key for whole table. pnp_name=value. must be last, if present. + * + * The pnp_name "#" is reserved for other fields that should be ignored. + */ + extern struct sx modules_sx; #define MOD_XLOCK sx_xlock(&modules_sx)