xref: /freebsd/share/man/man9/MODULE_PNP_INFO.9 (revision 069ac184)
1.\" Copyright (c) 2018 Conrad Meyer <cem@FreeBSD.org>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.Dd May 23, 2019
26.Dt MODULE_PNP_INFO 9
27.Os
28.Sh NAME
29.Nm MODULE_PNP_INFO
30.Nd register plug and play information for device matching
31.\"
32.Sh SYNOPSIS
33.In sys/module.h
34.Fo MODULE_PNP_INFO
35.Fa "const char *descriptor_string"
36.Fa "bus"
37.Fa "module"
38.Fa "void *table"
39.Fa "size_t num_entries"
40.Fc
41.\"
42.Sh DESCRIPTION
43The
44.Fn MODULE_PNP_INFO
45macro registers a
46.Fa table
47of device-identifying data for use by
48.Xr devmatch 8 .
49Since it is built off module marking macros, it must follow a
50.Xr DRIVER_MODULE 9
51line.
52.Pp
53The macro takes a
54.Fa descriptor_string
55that describes the memory layout of table entries.
56The string is a series of members separated by semi-colons.
57Members are identified by a type and a name.
58They are encoded in the descriptor string by concatenating the type with a
59colon, followed by the name.
60(The special type
61.Vt W32
62represents two members.
63The first name is encoded like any other type.
64The second name is encoded by appending a forward slash and the second
65name after the first.)
66.Pp
67Types are one of the following:
68.Bl -tag -width U16
69.It Dq Vt U8
70.Vt uint8_t
71element.
72.It Dq Vt V8
73Same as
74.Vt U8 ,
75except that the sentinel value 0xFF matches any.
76.It Dq Vt G16
77.Vt uint16_t
78element; any value greater than or equal matches.
79.It Dq Vt L16
80.Vt uint16_t
81element; any value less than or equal matches.
82.It Dq Vt M16
83.Vt uint16_t
84element; mask of which of the following fields to use.
85.It Dq Vt U16
86.Vt uint16_t
87element.
88.It Dq Vt V16
89Same as
90.Vt U16 ,
91except that the sentinel value 0xFFFF matches any.
92.It Dq Vt U32
93.Vt uint32_t
94element.
95.It Dq Vt V32
96Same as
97.Vt U32 ,
98except that the sentinel value 0xFFFFFFFF matches any.
99.It Dq Vt W32
100Two
101.Vt uint16_t
102values; the first named member is in the least significant word and the second
103named member is in the most significant word.
104.It Dq Vt Z
105A pointer to a string to match exactly.
106.It Dq Vt D
107A pointer to a human readable description for the device.
108.It Dq Vt P
109A pointer that should be ignored.
110.It Dq Vt E
111EISA PNP Identifier.
112.It Dq Vt T
113PNP info that is true for the whole table.
114The driver code checks for these condition pragmatically before using
115this table to match devices.
116This item must come last in the list.
117.El
118.Pp
119The pseudo-name
120.Dq #
121is reserved for fields that should be ignored.
122Any member that does not match the parent device's pnpinfo output must be
123ignored.
124.Pp
125The
126.Fa bus
127parameter is an unquoted word naming the parent bus of the driver.
128For example,
129.Dq pci .
130.Pp
131The
132.Fa module
133parameter is also an unquoted word.
134It must be unique to the driver.
135Usually the driver's name is used.
136.Pp
137The
138.Fa table
139parameter points to the device matching data with entries matching the
140.Fa descriptor_string .
141.Pp
142The
143.Fa num_entries
144parameter is the number of entries in the table, i.e.,
145.Ql nitems(table) .
146Note that only valid entries should be included.
147If the table contains trailing zero or bogus values, they should not be
148included in
149.Fa num_entries .
150.\"
151.Sh EXAMPLES
152.Bl -tag -width ""
153.It Sy Example 1\&: No Using W32 for vendor/device pair
154.Pp
155The following example shows usage of
156.Vt W32
157type when vendor/device values are combined into single
158.Vt uint32_t
159value:
160.Bd -literal
161#include <sys/param.h>
162#include <sys/module.h>
163
164static struct my_pciids {
165	uint32_t devid;
166	const char *desc;
167} my_ids[] = {
168	{ 0x12345678, "Foo bar" },
169	{ 0x9abcdef0, "Baz fizz" },
170};
171
172MODULE_PNP_INFO("W32:vendor/device;D:#", pci, my_driver, my_ids,
173    nitems(my_ids));
174.Ed
175.It Sy Example 2\&: No Using T for common vendor value
176.Pp
177The following example shows usage of
178.Vt T
179type when all entries in the table have the same vendor value:
180.Bd -literal
181#include <sys/param.h>
182#include <sys/module.h>
183
184static struct my_pciids {
185	uint16_t device;
186	const char *desc;
187} my_ids[] = {
188	{ 0x9abc, "Foo bar" },
189	{ 0xdef0, "Baz fizz" },
190};
191
192MODULE_PNP_INFO("U16:device;D:#;T:vendor=0x1234", pci, my_driver,
193    my_ids, nitems(my_ids));
194.Ed
195.El
196.\"
197.Sh BUGS
198The
199.Nm
200macro must follow
201.Dv DRIVER_MODULE
202invocations due to limitations in the
203.Dv linker.hints
204file format.
205.Sh SEE ALSO
206.Xr devmatch 8 ,
207.Xr DRIVER_MODULE 9 ,
208.Xr module 9
209.Sh HISTORY
210The macro
211.Nm
212appeared in
213.Fx 11.0 .
214.Sh AUTHORS
215The PNP framework and
216.Xr devmatch 8
217utility were written by
218.An Warner Losh Aq Mt imp@FreeBSD.org .
219