xref: /netbsd-src/share/man/man4/intro.4 (revision 9045582bde361c7d5d2021a437d8f3504369d1a7)
1*9045582bSwiz.\" $NetBSD: intro.4,v 1.3 2017/12/20 09:58:36 wiz Exp $
2189d838aSchristos.\"
3189d838aSchristos.\" Copyright (c) 1996 David E. O'Brien, Joerg Wunsch
4189d838aSchristos.\"
5189d838aSchristos.\" All rights reserved.
6189d838aSchristos.\"
7189d838aSchristos.\" Redistribution and use in source and binary forms, with or without
8189d838aSchristos.\" modification, are permitted provided that the following conditions
9189d838aSchristos.\" are met:
10189d838aSchristos.\" 1. Redistributions of source code must retain the above copyright
11189d838aSchristos.\"    notice, this list of conditions and the following disclaimer.
12189d838aSchristos.\" 2. Redistributions in binary form must reproduce the above copyright
13189d838aSchristos.\"    notice, this list of conditions and the following disclaimer in the
14189d838aSchristos.\"    documentation and/or other materials provided with the distribution.
15189d838aSchristos.\"
16189d838aSchristos.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
17189d838aSchristos.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18189d838aSchristos.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19189d838aSchristos.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
20189d838aSchristos.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21189d838aSchristos.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22189d838aSchristos.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23189d838aSchristos.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24189d838aSchristos.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25189d838aSchristos.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26189d838aSchristos.\"
27189d838aSchristos.\" $FreeBSD: head/share/man/man4/intro.4 131530 2004-07-03 18:29:24Z ru $
28189d838aSchristos.\"
29a560478dSchristos.Dd December 18, 2017
30189d838aSchristos.Dt INTRO 4
31189d838aSchristos.Os
32189d838aSchristos.Sh NAME
33189d838aSchristos.Nm intro
34189d838aSchristos.Nd introduction to devices and device drivers
35189d838aSchristos.Sh DESCRIPTION
36189d838aSchristosThis section contains information related to devices, device drivers
37189d838aSchristosand miscellaneous hardware.
38189d838aSchristos.Ss The device abstraction
39189d838aSchristosDevice is a term used mostly for hardware-related stuff that belongs
40189d838aSchristosto the system, like disks, printers, or a graphics display with its
41189d838aSchristoskeyboard.
42189d838aSchristosThere are also so-called
43189d838aSchristos.Em pseudo-devices
44189d838aSchristoswhere a device driver emulates the behaviour of a device in software
45189d838aSchristoswithout any particular underlying hardware.
46189d838aSchristosA typical example for
47189d838aSchristosthe latter class is
48189d838aSchristos.Pa /dev/mem ,
49189d838aSchristosa loophole where the physical memory can be accessed using the regular
50189d838aSchristosfile access semantics.
51189d838aSchristos.Pp
52189d838aSchristosThe device abstraction generally provides a common set of system calls
53189d838aSchristoslayered on top of them, which are dispatched to the corresponding
54189d838aSchristosdevice driver by the upper layers of the kernel.
55189d838aSchristosThe set of system
56189d838aSchristoscalls available for devices is chosen from
57189d838aSchristos.Xr open 2 ,
58189d838aSchristos.Xr close 2 ,
59189d838aSchristos.Xr read 2 ,
60189d838aSchristos.Xr write 2 ,
61189d838aSchristos.Xr ioctl 2 ,
62189d838aSchristos.Xr select 2 ,
63189d838aSchristosand
64189d838aSchristos.Xr mmap 2 .
65189d838aSchristosNot all drivers implement all system calls, for example, calling
66189d838aSchristos.Xr mmap 2
67189d838aSchristoson terminal devices is likely to be not useful at all.
68189d838aSchristos.Ss Accessing Devices
69189d838aSchristosMost of the devices in a
70189d838aSchristos.Ux Ns
71189d838aSchristos-like operating system are accessed
72189d838aSchristosthrough so-called
73189d838aSchristos.Em device nodes ,
74189d838aSchristossometimes also called
75189d838aSchristos.Em special files .
76189d838aSchristosThey are usually located under the directory
77189d838aSchristos.Pa /dev
78189d838aSchristosin the file system hierarchy
79189d838aSchristos(see also
80189d838aSchristos.Xr hier 7 ) .
81189d838aSchristos.Pp
82189d838aSchristosNote that this could lead to an inconsistent state, where either there
83189d838aSchristosare device nodes that do not have a configured driver associated with
84189d838aSchristosthem, or there may be drivers that have successfully probed for their
85189d838aSchristosdevices, but cannot be accessed since the corresponding device node is
86189d838aSchristosstill missing.
87189d838aSchristosIn the first case, any attempt to reference the device
88189d838aSchristosthrough the device node will result in an error, returned by the upper
89189d838aSchristoslayers of the kernel, usually
90189d838aSchristos.Er ENXIO .
91189d838aSchristosIn the second case, the device node needs to be created before the
92189d838aSchristosdriver and its device will be usable.
93189d838aSchristos.Pp
94189d838aSchristosSome devices come in two flavors:
95189d838aSchristos.Em block
96189d838aSchristosand
97189d838aSchristos.Em character
98189d838aSchristosdevices, or to use better terms, buffered and unbuffered
99189d838aSchristos(raw)
100189d838aSchristosdevices.
101189d838aSchristosThe traditional names are reflected by the letters
102189d838aSchristos.Ql b
103189d838aSchristosand
104189d838aSchristos.Ql c
105189d838aSchristosas the file type identification in the output of
106189d838aSchristos.Ql ls -l .
107189d838aSchristosBuffered devices are being accessed through the buffer cache of the
108189d838aSchristosoperating system, and they are solely intended to layer a file system
109189d838aSchristoson top of them.
110189d838aSchristosThey are normally implemented for disks and disk-like
111189d838aSchristosdevices only and, for historical reasons, for tape devices.
112189d838aSchristos.Pp
113189d838aSchristosRaw devices are available for all drivers, including those that also
114189d838aSchristosimplement a buffered device.
115189d838aSchristosFor the latter group of devices, the
116189d838aSchristosdifferentiation is conventionally done by prepending the letter
117189d838aSchristos.Ql r
118189d838aSchristosto the path name of the device node, for example
119a560478dSchristos.Pa /dev/rsd0[cd]
120189d838aSchristosdenotes the raw device for the first SCSI disk, while
121a560478dSchristos.Pa /dev/sd0[cd]
122189d838aSchristosis the corresponding device node for the buffered device.
123189d838aSchristos.Pp
124189d838aSchristosUnbuffered devices should be used for all actions that are not related
125189d838aSchristosto file system operations, even if the device in question is a disk
126189d838aSchristosdevice.
127189d838aSchristosThis includes making backups of entire disk partitions, or
128189d838aSchristosto
129189d838aSchristos.Em raw
130189d838aSchristosfloppy disks
131189d838aSchristos(i.e., those used like tapes).
132189d838aSchristos.Pp
133189d838aSchristosAccess restrictions to device nodes are usually subject to the regular
134189d838aSchristosfile permissions of the device node entry, instead of being enforced
135189d838aSchristosdirectly by the drivers in the kernel.
136189d838aSchristos.Ss Drivers without device nodes
137189d838aSchristosDrivers for network devices do not use device nodes in order to be
138189d838aSchristosaccessed.
139189d838aSchristosTheir selection is based on other decisions inside the
140189d838aSchristoskernel, and instead of calling
141189d838aSchristos.Xr open 2 ,
142189d838aSchristosuse of a network device is generally introduced by using the system
143189d838aSchristoscall
144189d838aSchristos.Xr socket 2 .
145189d838aSchristos.Ss Configuring a driver into the kernel
146189d838aSchristosFor each kernel, there is a configuration file that is used as a base
147189d838aSchristosto select the facilities and drivers for that kernel, and to tune
148189d838aSchristosseveral options.
149189d838aSchristosSee
150*9045582bSwiz.Xr config 1
151189d838aSchristosfor a detailed description of the files involved.
152189d838aSchristosThe individual manual pages in this section provide a sample line for the
153189d838aSchristosconfiguration file in their synopsis portion.
154189d838aSchristosSee also the sample config file
155a560478dSchristos.Pa /usr/src/sys/arch/i386/conf/GENERIC
156189d838aSchristos(for the
157189d838aSchristos.Em i386
158189d838aSchristosarchitecture).
159189d838aSchristos.Sh SEE ALSO
160a560478dSchristos.Xr config 1 ,
161189d838aSchristos.Xr close 2 ,
162189d838aSchristos.Xr ioctl 2 ,
163189d838aSchristos.Xr mmap 2 ,
164189d838aSchristos.Xr open 2 ,
165189d838aSchristos.Xr read 2 ,
166189d838aSchristos.Xr select 2 ,
167189d838aSchristos.Xr socket 2 ,
168189d838aSchristos.Xr write 2 ,
169a560478dSchristos.\" .Xr devfs 5 ,
170*9045582bSwiz.Xr hier 7
171189d838aSchristos.Sh HISTORY
172189d838aSchristosThis manual page first appeared in
173a560478dSchristos.Fx 2.1
174a560478dSchristosand
175a560478dSchristos.Nx 9 .
176189d838aSchristos.Sh AUTHORS
177189d838aSchristos.An -nosplit
178189d838aSchristosThis man page has been written by
179189d838aSchristos.An J\(:org Wunsch
180189d838aSchristoswith initial input by
181189d838aSchristos.An David E. O'Brien .
182