1108983Simp# $FreeBSD$
2108983Simp#
3108983Simp# Refer to devd.conf(5) and devd(8) man pages for the details on how to
4108983Simp# run and configure devd.
5108983Simp#
6108983Simp
7108983Simp# NB: All regular expressions have an implicit ^$ around them.
8108983Simp# NB: device-name is shorthand for 'match device-name'
9108983Simp
10108983Simpoptions {
11227994Swblock	# Each "directory" directive adds a directory to the list of
12227994Swblock	# directories that we scan for files.  Files are loaded in the order
13227994Swblock	# that they are returned from readdir(3).  The rule-sets are combined
14227994Swblock	# to create a DFA that's used to match events to actions.
15108983Simp	directory "/etc/devd";
16108983Simp	directory "/usr/local/etc/devd";
17108983Simp	pid-file "/var/run/devd.pid";
18108983Simp
19108983Simp	# Setup some shorthand for regex that we use later in the file.
20148471Simp	#XXX Yes, these are gross -- imp
21108983Simp	set scsi-controller-regex
22139027Sbrueffer		"(aac|adv|adw|aha|ahb|ahc|ahd|aic|amd|amr|asr|bt|ciss|ct|dpt|\
23146969Smarius		esp|ida|iir|ips|isp|mlx|mly|mpt|ncr|ncv|nsp|stg|sym|trm|wds)\
24139027Sbrueffer		[0-9]+";
25108983Simp};
26108983Simp
27108983Simp# Note that the attach/detach with the highest value wins, so that one can
28108983Simp# override these general rules.
29108983Simp
30108983Simp#
31159126Sthompsa# Configure the interface on attach.  Due to a historical accident, this
32159126Sthompsa# script is called pccard_ether.
33108983Simp#
34187743Ssam# NB: DETACH events are ignored; the kernel should handle all cleanup
35227994Swblock#     (routes, arp cache).  Beware of races against immediate create
36227994Swblock#     of a device with the same name; e.g.
37187743Ssam#	ifconfig bridge0 destroy; ifconfig bridge0 create
38187743Ssam#
39159126Sthompsanotify 0 {
40159126Sthompsa	match "system"		"IFNET";
41247767Shrs	match "subsystem"	"!usbus[0-9]+";
42159126Sthompsa	match "type"		"ATTACH";
43159126Sthompsa	action "/etc/pccard_ether $subsystem start";
44108983Simp};
45108983Simp
46147088Sbrooks#
47227994Swblock# Try to start dhclient on Ethernet-like interfaces when the link comes
48147088Sbrooks# up.  Only devices that are configured to support DHCP will actually
49216983Sjpaetzel# run it.  No link down rule exists because dhclient automatically exits
50147088Sbrooks# when the link goes down.
51147088Sbrooks#
52147088Sbrooksnotify 0 {
53147088Sbrooks	match "system"		"IFNET";
54147088Sbrooks	match "type"		"LINK_UP";
55148642Ssam	media-type		"ethernet";
56175683Smtm	action "/etc/rc.d/dhclient quietstart $subsystem";
57147088Sbrooks};
58147088Sbrooks
59148642Ssam#
60148642Ssam# Like Ethernet devices, but separate because
61148642Ssam# they have a different media type.  We may want
62148642Ssam# to exploit this later.
63148642Ssam#
64148642Ssamdetach 0 {
65148642Ssam	media-type "802.11";
66148642Ssam	action "/etc/pccard_ether $device-name stop";
67148642Ssam};
68148642Ssamattach 0 {
69148642Ssam	media-type "802.11";
70148642Ssam	action "/etc/pccard_ether $device-name start";
71148642Ssam};
72148642Ssamnotify 0 {
73148642Ssam	match "system"		"IFNET";
74148642Ssam	match "type"		"LINK_UP";
75148642Ssam	media-type		"802.11";
76175683Smtm	action "/etc/rc.d/dhclient quietstart $subsystem";
77148642Ssam};
78148642Ssam
79108983Simp# An entry like this might be in a different file, but is included here
80108983Simp# as an example of how to override things.  Normally 'ed50' would match
81108983Simp# the above attach/detach stuff, but the value of 100 makes it
82139281Sbrueffer# hard wired to 1.2.3.4.
83108983Simpattach 100 {
84108983Simp	device-name "ed50";
85108983Simp	action "ifconfig $device-name inet 1.2.3.4 netmask 0xffff0000";
86108983Simp};
87108983Simpdetach 100 {
88108983Simp	device-name "ed50";
89108983Simp};
90108983Simp
91227994Swblock# When a USB Bluetooth dongle appears, activate it
92152326Semaxattach 100 {
93152326Semax	device-name "ubt[0-9]+";
94175683Smtm	action "/etc/rc.d/bluetooth quietstart $device-name";
95152326Semax};
96152326Semaxdetach 100 {
97152326Semax	device-name "ubt[0-9]+";
98175683Smtm	action "/etc/rc.d/bluetooth quietstop $device-name";
99152326Semax};
100152326Semax
101215195Semax# Firmware downloader for Atheros AR3011 based USB Bluetooth devices
102215195Semax#attach 100 {
103215195Semax#	match "vendor" "0x0cf3";
104215195Semax#	match "product" "0x3000";
105215195Semax#	action "sleep 2 && /usr/sbin/ath3kfw -d $device-name -f /usr/local/etc/ath3k-1.fw";
106215195Semax#};
107215195Semax
108139281Sbrueffer# When a USB keyboard arrives, attach it as the console keyboard.
109134584Sbrooksattach 100 {
110134584Sbrooks	device-name "ukbd0";
111156782Semax	action "/etc/rc.d/syscons setkeyboard /dev/ukbd0";
112134584Sbrooks};
113134584Sbrooksdetach 100 {
114134584Sbrooks	device-name "ukbd0";
115156331Semax	action "/etc/rc.d/syscons setkeyboard /dev/kbd0";
116134584Sbrooks};
117134584Sbrooks
118241084Shselaskynotify 100 {
119241084Shselasky	match "system" "DEVFS";
120241084Shselasky	match "subsystem" "CDEV";
121241084Shselasky	match "type" "CREATE";
122261510Shselasky	match "cdev" "atp[0-9]+";
123261510Shselasky
124261510Shselasky	action "/etc/rc.d/moused quietstart $cdev";
125261510Shselasky};
126261510Shselasky
127261510Shselaskynotify 100 {
128261510Shselasky	match "system" "DEVFS";
129261510Shselasky	match "subsystem" "CDEV";
130261510Shselasky	match "type" "CREATE";
131241084Shselasky	match "cdev" "ums[0-9]+";
132241084Shselasky
133241084Shselasky	action "/etc/rc.d/moused quietstart $cdev";
134138175Siedowse};
135138175Siedowse
136241084Shselaskynotify 100 {
137241084Shselasky	match "system" "DEVFS";
138241084Shselasky	match "subsystem" "CDEV";
139261510Shselasky	match "type" "CREATE";
140261510Shselasky	match "cdev" "wsp[0-9]+";
141261510Shselasky
142261510Shselasky	action "/etc/rc.d/moused quietstart $cdev";
143261510Shselasky};
144261510Shselasky
145261510Shselaskynotify 100 {
146261510Shselasky	match "system" "DEVFS";
147261510Shselasky	match "subsystem" "CDEV";
148241084Shselasky	match "type" "DESTROY";
149241084Shselasky	match "cdev" "ums[0-9]+";
150241084Shselasky
151241084Shselasky	action "/etc/rc.d/moused stop $cdev";
152208060Sdougb};
153179804Skmacy
154153300Siedowse# Firmware download into the ActiveWire board. After the firmware download is
155227994Swblock# done, the device detaches and reappears as something new and shiny
156153300Siedowse# automatically.
157153300Siedowseattach 100 {
158153300Siedowse	match "vendor"	"0x0854";
159153300Siedowse	match "product"	"0x0100";
160153300Siedowse	match "release"	"0x0000";
161153300Siedowse	action "/usr/local/bin/ezdownload -f /usr/local/share/usb/firmware/0854.0100.0_01.hex $device-name";
162153300Siedowse};
163153300Siedowse
164153300Siedowse# Firmware download for Entrega Serial DB25 adapter.
165153300Siedowseattach 100 {
166153300Siedowse	match "vendor"	"0x1645";
167153300Siedowse	match "product"	"0x8001";
168153300Siedowse	match "release"	"0x0101";
169192198Smaxim	action "if ! kldstat -n usio > /dev/null 2>&1 ; then kldload usio; fi; /usr/sbin/ezdownload -v -f /usr/share/usb/firmware/1645.8001.0101 /dev/$device-name";
170153300Siedowse};
171153300Siedowse
172153300Siedowse# This entry starts the ColdSync tool in daemon mode. Make sure you have an up
173153300Siedowse# to date /usr/local/etc/palms. We override the 'listen' settings for port and
174153300Siedowse# type in /usr/local/etc/coldsync.conf.
175207020Sthompsanotify 100 {
176207020Sthompsa	match "system"		"USB";
177207020Sthompsa	match "subsystem"	"DEVICE";
178207020Sthompsa	match "type"		"ATTACH";
179207020Sthompsa	match "vendor"		"0x082d";
180207020Sthompsa	match "product"		"0x0100";
181207020Sthompsa	match "release"		"0x0100";
182207020Sthompsa	action "/usr/local/bin/coldsync -md -p /dev/$cdev -t usb";
183153300Siedowse};
184153300Siedowse
185108983Simp#
186148471Simp# Rescan scsi device-names on attach, but not detach.  However, it is
187148471Simp# disabled by default due to reports of problems.
188108983Simp#
189108983Simpattach 0 {
190108983Simp	device-name "$scsi-controller-regex";
191131646Simp//	action "camcontrol rescan all";
192108983Simp};
193108983Simp
194108983Simp# Don't even try to second guess what to do about drivers that don't
195114799Simp# match here.  Instead, pass it off to syslog.  Commented out for the
196166754Simp# moment, as the pnpinfo variable isn't set in devd yet.  Individual
197166754Simp# variables within the bus supplied pnpinfo are set.
198119254Simpnomatch 0 {
199114852Simp#	action "logger Unknown device: $pnpinfo $location $bus";
200119254Simp};
201108983Simp
202166701Sjoerg# Various logging of unknown devices.
203166701Sjoergnomatch 10 {
204166701Sjoerg	match "bus" "uhub[0-9]+";
205166701Sjoerg	action "logger Unknown USB device: vendor $vendor product $product \
206166701Sjoerg		bus $bus";
207166701Sjoerg};
208166701Sjoerg
209166701Sjoerg# Some PC-CARDs don't offer numerical manufacturer/product IDs, just
210166701Sjoerg# show the CIS info there.
211166701Sjoergnomatch 20 {
212166701Sjoerg	match "bus" "pccard[0-9]+";
213166701Sjoerg	match "manufacturer" "0xffffffff";
214166701Sjoerg	match "product" "0xffffffff";
215166701Sjoerg	action "logger Unknown PCCARD device: CISproduct $cisproduct \
216166701Sjoerg		CIS-vendor $cisvendor bus $bus";
217166701Sjoerg};
218166701Sjoerg
219166701Sjoergnomatch 10 {
220166701Sjoerg	match "bus" "pccard[0-9]+";
221166701Sjoerg	action "logger Unknown PCCARD device: manufacturer $manufacturer \
222166701Sjoerg		product $product CISproduct $cisproduct CIS-vendor \
223166701Sjoerg		$cisvendor bus $bus";
224166701Sjoerg};
225166701Sjoerg
226166701Sjoergnomatch 10 {
227166701Sjoerg	match "bus" "cardbus[0-9]+";
228166701Sjoerg	action "logger Unknown Cardbus device: device $device class $class \
229166701Sjoerg		vendor $vendor bus $bus";
230166701Sjoerg};
231166701Sjoerg
232139281Sbrueffer# Switch power profiles when the AC line state changes.
233123626Snjlnotify 10 {
234123626Snjl	match "system"		"ACPI";
235123626Snjl	match "subsystem"	"ACAD";
236125366Snjl	action "/etc/rc.d/power_profile $notify";
237123626Snjl};
238123626Snjl
239125366Snjl# Notify all users before beginning emergency shutdown when we get
240125366Snjl# a _CRT or _HOT thermal event and we're going to power down the system
241125366Snjl# very soon.
242125366Snjlnotify 10 {
243125366Snjl	match "system"		"ACPI";
244125366Snjl	match "subsystem"	"Thermal";
245125366Snjl	match "notify"		"0xcc";
246125366Snjl	action "logger -p kern.emerg 'WARNING: system temperature too high, shutting down soon!'";
247125366Snjl};
248125366Snjl
249168495Spjd# Sample ZFS problem reports handling.
250168495Spjdnotify 10 {
251168495Spjd	match "system"		"ZFS";
252168495Spjd	match "type"		"zpool";
253168495Spjd	action "logger -p kern.err 'ZFS: failed to load zpool $pool'";
254168495Spjd};
255168495Spjd
256168495Spjdnotify 10 {
257168495Spjd	match "system"		"ZFS";
258168495Spjd	match "type"		"vdev";
259168497Spjd	action "logger -p kern.err 'ZFS: vdev failure, zpool=$pool type=$type'";
260168495Spjd};
261168495Spjd
262168495Spjdnotify 10 {
263168495Spjd	match "system"		"ZFS";
264168495Spjd	match "type"		"data";
265168495Spjd	action "logger -p kern.warn 'ZFS: zpool I/O failure, zpool=$pool error=$zio_err'";
266168495Spjd};
267168495Spjd
268168495Spjdnotify 10 {
269168495Spjd	match "system"		"ZFS";
270168495Spjd	match "type"		"io";
271168495Spjd	action "logger -p kern.warn 'ZFS: vdev I/O failure, zpool=$pool path=$vdev_path offset=$zio_offset size=$zio_size error=$zio_err'";
272168495Spjd};
273168495Spjd
274168495Spjdnotify 10 {
275168495Spjd	match "system"		"ZFS";
276168495Spjd	match "type"		"checksum";
277168495Spjd	action "logger -p kern.warn 'ZFS: checksum mismatch, zpool=$pool path=$vdev_path offset=$zio_offset size=$zio_size'";
278168495Spjd};
279168495Spjd
280170976Snjl# User requested suspend, so perform preparation steps and then execute
281170976Snjl# the actual suspend process.
282170976Snjlnotify 10 {
283170976Snjl	match "system"		"ACPI";
284170976Snjl	match "subsystem"	"Suspend";
285170976Snjl	action "/etc/rc.suspend acpi $notify";
286170976Snjl};
287170976Snjlnotify 10 {
288170976Snjl	match "system"		"ACPI";
289170976Snjl	match "subsystem"	"Resume";
290170976Snjl	action "/etc/rc.resume acpi $notify";
291170976Snjl};
292170976Snjl
293108983Simp/* EXAMPLES TO END OF FILE
294108983Simp
295227994Swblock# An example of something that a vendor might install if you were to
296227994Swblock# add their device.  This might reside in /usr/local/etc/devd/deqna.conf.
297227994Swblock# A deqna is, in this hypothetical example, a pccard ethernet-like device.
298227994Swblock# Students of history may know other devices by this name, and will get
299227994Swblock# the in-jokes in this entry.
300108983Simpnomatch 10 {
301108983Simp	match "bus" "pccard[0-9]+";
302108983Simp	match "manufacturer" "0x1234";
303108983Simp	match "product" "0x2323";
304108983Simp	action "kldload if_deqna";
305108983Simp};
306108983Simpattach 10 {
307108983Simp	device-name "deqna[0-9]+";
308108983Simp	action "/etc/pccard_ether $device-name start";
309108983Simp};
310108983Simpdetach 10 {
311108983Simp	device-name "deqna[0-9]+";
312108983Simp	action "/etc/pccard_ether $device-name stop";
313108983Simp};
314108983Simp
315121493Snjl# Examples of notify hooks.  A notify is a generic way for a kernel
316121493Snjl# subsystem to send event notification to userland.
317227994Swblock
318121493Snjl# Here are some examples of ACPI notify handlers.  ACPI subsystems that
319121493Snjl# generate notifies include the AC adapter, power/sleep buttons,
320121493Snjl# control method batteries, lid switch, and thermal zones.
321121493Snjl#
322121493Snjl# Information returned is not always the same as the ACPI notify
323121493Snjl# events.  See the ACPI specification for more information about
324121493Snjl# notifies.  Here is the information returned for each subsystem:
325121493Snjl#
326121493Snjl# ACAD:		AC line state (0 is offline, 1 is online)
327121493Snjl# Button:	Button pressed (0 for power, 1 for sleep)
328121493Snjl# CMBAT:	ACPI battery events
329121493Snjl# Lid:		Lid state (0 is closed, 1 is open)
330220168Strasz# RCTL:		Resource limits
331170976Snjl# Suspend, Resume: Suspend and resume notification
332121493Snjl# Thermal:	ACPI thermal zone events
333121493Snjl#
334121493Snjl# This example calls a script when the AC state changes, passing the
335121493Snjl# notify value as the first argument.  If the state is 0x00, it might
336121493Snjl# call some sysctls to implement economy mode.  If 0x01, it might set
337121493Snjl# the mode to performance.
338121493Snjlnotify 10 {
339121493Snjl	match "system"		"ACPI";
340121493Snjl	match "subsystem"	"ACAD";
341121493Snjl	action			"/etc/acpi_ac $notify";
342121493Snjl};
343220168Strasz
344220168Strasz# This example works around a memory leak in PostgreSQL, restarting
345227994Swblock# it when the "user:pgsql:swap:devctl=1G" rctl(8) rule gets triggered.
346220168Strasznotify 0 {
347220168Strasz	match "system"		"RCTL";
348220168Strasz	match "rule"		"user:70:swap:.*";
349220168Strasz	action			"/usr/local/etc/rc.d/postgresql restart"
350220168Strasz};
351220168Strasz
352108983Simp*/
353