xref: /freebsd/share/man/man4/intro.4 (revision 1a720cbec513210fa2e85c3882741ef2f6dc5f35)
1f00e21baSJoerg Wunsch.\"
2f00e21baSJoerg Wunsch.\" Copyright (c) 1996 David E. O'Brien, Joerg Wunsch
300ef9f43SGuangyuan Yang.\" Copyright (c) 2019 Andrew Gierth
4f00e21baSJoerg Wunsch.\"
5f00e21baSJoerg Wunsch.\" All rights reserved.
6f00e21baSJoerg Wunsch.\"
7f00e21baSJoerg Wunsch.\" Redistribution and use in source and binary forms, with or without
8f00e21baSJoerg Wunsch.\" modification, are permitted provided that the following conditions
9f00e21baSJoerg Wunsch.\" are met:
10f00e21baSJoerg Wunsch.\" 1. Redistributions of source code must retain the above copyright
11f00e21baSJoerg Wunsch.\"    notice, this list of conditions and the following disclaimer.
12f00e21baSJoerg Wunsch.\" 2. Redistributions in binary form must reproduce the above copyright
13f00e21baSJoerg Wunsch.\"    notice, this list of conditions and the following disclaimer in the
14f00e21baSJoerg Wunsch.\"    documentation and/or other materials provided with the distribution.
15f00e21baSJoerg Wunsch.\"
16f00e21baSJoerg Wunsch.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
17f00e21baSJoerg Wunsch.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18f00e21baSJoerg Wunsch.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19f00e21baSJoerg Wunsch.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
20f00e21baSJoerg Wunsch.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21f00e21baSJoerg Wunsch.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22f00e21baSJoerg Wunsch.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23f00e21baSJoerg Wunsch.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24f00e21baSJoerg Wunsch.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25f00e21baSJoerg Wunsch.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26f00e21baSJoerg Wunsch.\"
2700ef9f43SGuangyuan Yang.Dd April 3, 2019
28f00e21baSJoerg Wunsch.Dt INTRO 4
293d45e180SRuslan Ermilov.Os
30f00e21baSJoerg Wunsch.Sh NAME
31f00e21baSJoerg Wunsch.Nm intro
32f00e21baSJoerg Wunsch.Nd introduction to devices and device drivers
33f00e21baSJoerg Wunsch.Sh DESCRIPTION
344057c9f0SDima DorfmanThis section contains information related to devices, device drivers
35f00e21baSJoerg Wunschand miscellaneous hardware.
36f00e21baSJoerg Wunsch.Ss The device abstraction
37f00e21baSJoerg WunschDevice is a term used mostly for hardware-related stuff that belongs
38f00e21baSJoerg Wunschto the system, like disks, printers, or a graphics display with its
39b5e7e999SRuslan Ermilovkeyboard.
40b5e7e999SRuslan ErmilovThere are also so-called
41f00e21baSJoerg Wunsch.Em pseudo-devices
42f00e21baSJoerg Wunschwhere a device driver emulates the behaviour of a device in software
43b5e7e999SRuslan Ermilovwithout any particular underlying hardware.
44b5e7e999SRuslan ErmilovA typical example for
45f00e21baSJoerg Wunschthe latter class is
46f00e21baSJoerg Wunsch.Pa /dev/mem ,
4700ef9f43SGuangyuan Yanga mechanism whereby the physical memory can be accessed using file
4800ef9f43SGuangyuan Yangaccess semantics.
49f00e21baSJoerg Wunsch.Pp
5000ef9f43SGuangyuan YangThe device abstraction generally provides a common set of system
5100ef9f43SGuangyuan Yangcalls, which are dispatched to the corresponding device driver by the
5200ef9f43SGuangyuan Yangupper layers of the kernel.
5300ef9f43SGuangyuan YangThe set of system calls available for devices is chosen from
54f00e21baSJoerg Wunsch.Xr open 2 ,
55f00e21baSJoerg Wunsch.Xr close 2 ,
56f00e21baSJoerg Wunsch.Xr read 2 ,
57f00e21baSJoerg Wunsch.Xr write 2 ,
58f00e21baSJoerg Wunsch.Xr ioctl 2 ,
59f00e21baSJoerg Wunsch.Xr select 2 ,
60f00e21baSJoerg Wunschand
61f00e21baSJoerg Wunsch.Xr mmap 2 .
6200ef9f43SGuangyuan YangNot all drivers implement all system calls; for example, calling
63f00e21baSJoerg Wunsch.Xr mmap 2
6400ef9f43SGuangyuan Yangon a keyboard device is not likely to be useful.
6500ef9f43SGuangyuan Yang.Pp
6600ef9f43SGuangyuan YangAspects of the device abstraction have changed significantly in
6700ef9f43SGuangyuan Yang.Fx
6800ef9f43SGuangyuan Yangover the past two decades.
6900ef9f43SGuangyuan YangThe section
7000ef9f43SGuangyuan Yang.Sx Historical Notes
7100ef9f43SGuangyuan Yangdescribes some of the more important differences.
72f00e21baSJoerg Wunsch.Ss Accessing Devices
7300ef9f43SGuangyuan YangMost of the devices in
7400ef9f43SGuangyuan Yang.Fx
7500ef9f43SGuangyuan Yangare accessed through
76f00e21baSJoerg Wunsch.Em device nodes ,
77f00e21baSJoerg Wunschsometimes also called
78f00e21baSJoerg Wunsch.Em special files .
7900ef9f43SGuangyuan YangThey are located within instances of the
80*1a720cbeSAlexander Ziaee.Xr devfs 4
8100ef9f43SGuangyuan Yangfilesystem, which is conventionally mounted on the directory
82f00e21baSJoerg Wunsch.Pa /dev
83f00e21baSJoerg Wunschin the file system hierarchy
84c4d9468eSRuslan Ermilov(see also
85c4d9468eSRuslan Ermilov.Xr hier 7 ) .
86f00e21baSJoerg Wunsch.Pp
8700ef9f43SGuangyuan YangThe
88*1a720cbeSAlexander Ziaee.Xr devfs 4
8900ef9f43SGuangyuan Yangfilesystem creates or removes device nodes automatically according to
9000ef9f43SGuangyuan Yangthe physical hardware recognized as present at any given time.
9100ef9f43SGuangyuan YangFor pseudo-devices, device nodes may be created and removed dynamically
9200ef9f43SGuangyuan Yangas required, depending on the nature of the device.
93f00e21baSJoerg Wunsch.Pp
944057c9f0SDima DorfmanAccess restrictions to device nodes are usually subject to the regular
954057c9f0SDima Dorfmanfile permissions of the device node entry, instead of being enforced
96f00e21baSJoerg Wunschdirectly by the drivers in the kernel.
9700ef9f43SGuangyuan YangBut since device nodes are not stored persistently between reboots,
9800ef9f43SGuangyuan Yangthose file permissions are set at boot time from rules specified in
9900ef9f43SGuangyuan Yang.Xr devfs.conf 5 ,
10000ef9f43SGuangyuan Yangor dynamically according to rules defined in
10100ef9f43SGuangyuan Yang.Xr devfs.rules 5
10200ef9f43SGuangyuan Yangor set using the
10300ef9f43SGuangyuan Yang.Xr devfs 8
10400ef9f43SGuangyuan Yangcommand.
10500ef9f43SGuangyuan YangIn the latter case, different rules may be used to make different sets
10600ef9f43SGuangyuan Yangof devices visible within different instances of the
107*1a720cbeSAlexander Ziaee.Xr devfs 4
10800ef9f43SGuangyuan Yangfilesystem, which may be used, for example, to prevent jailed
10900ef9f43SGuangyuan Yangsubsystems from accessing unsafe devices.
11000ef9f43SGuangyuan YangManual changes to device
11100ef9f43SGuangyuan Yangnode permissions may still be made, but will not persist.
112f00e21baSJoerg Wunsch.Ss Drivers without device nodes
113f00e21baSJoerg WunschDrivers for network devices do not use device nodes in order to be
114b5e7e999SRuslan Ermilovaccessed.
115b5e7e999SRuslan ErmilovTheir selection is based on other decisions inside the
116f00e21baSJoerg Wunschkernel, and instead of calling
117f00e21baSJoerg Wunsch.Xr open 2 ,
118f00e21baSJoerg Wunschuse of a network device is generally introduced by using the system
119f00e21baSJoerg Wunschcall
120f00e21baSJoerg Wunsch.Xr socket 2 .
121f00e21baSJoerg Wunsch.Ss Configuring a driver into the kernel
122f00e21baSJoerg WunschFor each kernel, there is a configuration file that is used as a base
123f00e21baSJoerg Wunschto select the facilities and drivers for that kernel, and to tune
124b5e7e999SRuslan Ermilovseveral options.
125b5e7e999SRuslan ErmilovSee
126f00e21baSJoerg Wunsch.Xr config 8
127b5e7e999SRuslan Ermilovfor a detailed description of the files involved.
128b5e7e999SRuslan ErmilovThe individual manual pages in this section provide a sample line for the
12900ef9f43SGuangyuan Yangconfiguration file in their synopsis portions.
13000ef9f43SGuangyuan YangSee also the files
13100ef9f43SGuangyuan Yang.Pa /usr/src/sys/conf/NOTES
13200ef9f43SGuangyuan Yangand
13300ef9f43SGuangyuan Yang.Pa /usr/src/sys/${ARCH}/conf/NOTES .
13400ef9f43SGuangyuan Yang.Pp
13500ef9f43SGuangyuan YangDrivers need not be statically compiled into the kernel; they may also be
13600ef9f43SGuangyuan Yangloaded as modules, in which case any device nodes they provide will appear
13700ef9f43SGuangyuan Yangonly after the module is loaded (and has attached to suitable hardware,
13800ef9f43SGuangyuan Yangif applicable).
13900ef9f43SGuangyuan Yang.Ss Historical Notes
14000ef9f43SGuangyuan YangPrior to
14100ef9f43SGuangyuan Yang.Fx 6.0 ,
14200ef9f43SGuangyuan Yangdevice nodes could be created in the traditional way as persistent
14300ef9f43SGuangyuan Yangentries in the file system.
14400ef9f43SGuangyuan YangWhile such entries can still be created, they no longer function to
14500ef9f43SGuangyuan Yangaccess devices.
14600ef9f43SGuangyuan Yang.Pp
14700ef9f43SGuangyuan YangPrior to
14800ef9f43SGuangyuan Yang.Fx 5.0 ,
14900ef9f43SGuangyuan Yangdevices for disk and tape drives existed in two variants, known as
15000ef9f43SGuangyuan Yang.Em block
15100ef9f43SGuangyuan Yangand
15200ef9f43SGuangyuan Yang.Em character
15300ef9f43SGuangyuan Yangdevices, or to use better terms, buffered and unbuffered
15400ef9f43SGuangyuan Yang(raw)
15500ef9f43SGuangyuan Yangdevices.
15600ef9f43SGuangyuan YangThe traditional names are reflected by the letters
15700ef9f43SGuangyuan Yang.Dq Li b
15800ef9f43SGuangyuan Yangand
15900ef9f43SGuangyuan Yang.Dq Li c
16000ef9f43SGuangyuan Yangas the file type identification in the output of
16100ef9f43SGuangyuan Yang.Dq Li ls -l .
16200ef9f43SGuangyuan YangRaw devices were traditionally named with a prefix of
16300ef9f43SGuangyuan Yang.Dq Li r ,
16400ef9f43SGuangyuan Yangfor example
16500ef9f43SGuangyuan Yang.Pa /dev/rda0
16600ef9f43SGuangyuan Yangwould denote the raw version of the disk whose buffered device was
16700ef9f43SGuangyuan Yang.Pa /dev/da0 .
16800ef9f43SGuangyuan Yang.Em This is no longer the case ;
16900ef9f43SGuangyuan Yangall disk devices are now
17000ef9f43SGuangyuan Yang.Dq raw
17100ef9f43SGuangyuan Yangin the traditional sense, even though they are not given
17200ef9f43SGuangyuan Yang.Dq Li r
17300ef9f43SGuangyuan Yangprefixes, and
17400ef9f43SGuangyuan Yang.Dq buffered
17500ef9f43SGuangyuan Yangdevices no longer exist at all.
17600ef9f43SGuangyuan Yang.Pp
17700ef9f43SGuangyuan YangBuffered devices were accessed through a buffer cache maintained by
17800ef9f43SGuangyuan Yangthe operating system; historically this was the system's primary disk
17900ef9f43SGuangyuan Yangcache, but in
18000ef9f43SGuangyuan Yang.Fx
18100ef9f43SGuangyuan Yangthis was rendered obsolete by the introduction of unified virtual
18200ef9f43SGuangyuan Yangmemory management.
18300ef9f43SGuangyuan YangBuffered devices could be read or written at any
18400ef9f43SGuangyuan Yangbyte position, with the buffer mechanism handling the reading and
18500ef9f43SGuangyuan Yangwriting of disk blocks.
18600ef9f43SGuangyuan YangIn contrast, raw disk devices can be read or
18700ef9f43SGuangyuan Yangwritten only at positions and lengths that are multiples of the
18800ef9f43SGuangyuan Yangunderlying device block size, and
18900ef9f43SGuangyuan Yang.Xr write 2
19000ef9f43SGuangyuan Yangcalls are
19100ef9f43SGuangyuan Yang.Em synchronous ,
19200ef9f43SGuangyuan Yangnot returning to the caller until the data has been handed off to the
19300ef9f43SGuangyuan Yangdevice.
194f00e21baSJoerg Wunsch.Sh SEE ALSO
195f00e21baSJoerg Wunsch.Xr close 2 ,
196f00e21baSJoerg Wunsch.Xr ioctl 2 ,
197f00e21baSJoerg Wunsch.Xr mmap 2 ,
1980b992c1dSWolfram Schneider.Xr open 2 ,
1990b992c1dSWolfram Schneider.Xr read 2 ,
2000b992c1dSWolfram Schneider.Xr select 2 ,
201f00e21baSJoerg Wunsch.Xr socket 2 ,
2020b992c1dSWolfram Schneider.Xr write 2 ,
203*1a720cbeSAlexander Ziaee.Xr devfs 4 ,
204f00e21baSJoerg Wunsch.Xr hier 7 ,
205494a5dabSGiorgos Keramidas.Xr config 8
206b5e7e999SRuslan Ermilov.Sh HISTORY
207b5e7e999SRuslan ErmilovThis manual page first appeared in
208b5e7e999SRuslan Ermilov.Fx 2.1 .
209f00e21baSJoerg Wunsch.Sh AUTHORS
210f4d874a1SRuslan Ermilov.An -nosplit
21100ef9f43SGuangyuan YangThis man page has been rewritten by
21200ef9f43SGuangyuan Yang.An Andrew Gierth
21300ef9f43SGuangyuan Yangfrom an earlier version written by
214726b61abSRuslan Ermilov.An J\(:org Wunsch
215aaf1f16eSPhilippe Charnierwith initial input by
216aaf1f16eSPhilippe Charnier.An David E. O'Brien .
217