xref: /freebsd-src/share/man/man4/proto.4 (revision ffc4f93e960d38b6f70d59409127f7562e40f916)
167fb10f3SMarcel Moolenaar.\"
215abbe51SMarcel Moolenaar.\" Copyright (c) 2014, 2015 Marcel Moolenaar
367fb10f3SMarcel Moolenaar.\" All rights reserved.
467fb10f3SMarcel Moolenaar.\"
567fb10f3SMarcel Moolenaar.\" Redistribution and use in source and binary forms, with or without
667fb10f3SMarcel Moolenaar.\" modification, are permitted provided that the following conditions
767fb10f3SMarcel Moolenaar.\" are met:
867fb10f3SMarcel Moolenaar.\"
967fb10f3SMarcel Moolenaar.\" 1. Redistributions of source code must retain the above copyright
1067fb10f3SMarcel Moolenaar.\"    notice, this list of conditions and the following disclaimer.
1167fb10f3SMarcel Moolenaar.\" 2. Redistributions in binary form must reproduce the above copyright
1267fb10f3SMarcel Moolenaar.\"    notice, this list of conditions and the following disclaimer in the
1367fb10f3SMarcel Moolenaar.\"    documentation and/or other materials provided with the distribution.
1467fb10f3SMarcel Moolenaar.\"
1567fb10f3SMarcel Moolenaar.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1667fb10f3SMarcel Moolenaar.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1767fb10f3SMarcel Moolenaar.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1867fb10f3SMarcel Moolenaar.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1967fb10f3SMarcel Moolenaar.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2067fb10f3SMarcel Moolenaar.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2167fb10f3SMarcel Moolenaar.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2267fb10f3SMarcel Moolenaar.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2367fb10f3SMarcel Moolenaar.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2467fb10f3SMarcel Moolenaar.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2567fb10f3SMarcel Moolenaar.\"
26aaa8b90cSMarcel Moolenaar.Dd August 7, 2015
2767fb10f3SMarcel Moolenaar.Dt PROTO 4
2867fb10f3SMarcel Moolenaar.Os
2967fb10f3SMarcel Moolenaar.\"
3067fb10f3SMarcel Moolenaar.Sh NAME
3167fb10f3SMarcel Moolenaar.Nm proto
3215abbe51SMarcel Moolenaar.Nd Generic prototyping and diagnostics driver
3367fb10f3SMarcel Moolenaar.\"
3467fb10f3SMarcel Moolenaar.Sh SYNOPSIS
35e418b6fdSChristian BruefferTo compile this driver into the kernel,
36e418b6fdSChristian Bruefferplace the following line in your
37e418b6fdSChristian Bruefferkernel configuration file:
38e418b6fdSChristian Brueffer.Bd -ragged -offset indent
3967fb10f3SMarcel Moolenaar.Cd "device proto"
40e418b6fdSChristian Brueffer.Ed
41e418b6fdSChristian Brueffer.Pp
42e418b6fdSChristian BruefferAlternatively, to load the driver as a
43e418b6fdSChristian Brueffermodule at boot time, place the following line in
44e418b6fdSChristian Brueffer.Xr loader.conf 5 :
45e418b6fdSChristian Brueffer.Bd -literal -offset indent
46e418b6fdSChristian Bruefferproto_load="YES"
47e418b6fdSChristian Brueffer.Ed
48be00e098SMarcel Moolenaar.Pp
49be00e098SMarcel MoolenaarTo have the driver attach to a device instead of its regular driver,
50be00e098SMarcel Moolenaarmention it in the list of devices assigned to the following loader variable:
51be00e098SMarcel Moolenaar.Bd -ragged -offset indent
52be00e098SMarcel Moolenaarhw.proto.attach="desc[,desc]"
53be00e098SMarcel Moolenaar.Ed
5467fb10f3SMarcel Moolenaar.\"
5567fb10f3SMarcel Moolenaar.Sh DESCRIPTION
5667fb10f3SMarcel MoolenaarThe
5767fb10f3SMarcel Moolenaar.Nm
5815abbe51SMarcel Moolenaardevice driver attaches to PCI or ISA devices when no other device drivers
5915abbe51SMarcel Moolenaarare present for those devices and it creates device special files for all
6015abbe51SMarcel Moolenaarresources associated with the device.
6167fb10f3SMarcel MoolenaarThe driver itself has no knowledge of the device it attaches to.
62e418b6fdSChristian BruefferPrograms can open these device special files and perform register-level
6367fb10f3SMarcel Moolenaarreads and writes.
6467fb10f3SMarcel MoolenaarAs such, the
6567fb10f3SMarcel Moolenaar.Nm
6667fb10f3SMarcel Moolenaardevice driver is nothing but a conduit or gateway between user space
6767fb10f3SMarcel Moolenaarprograms and the hardware device.
6867fb10f3SMarcel Moolenaar.Pp
6967fb10f3SMarcel MoolenaarExamples for why this is useful include hardware diagnostics and prototyping.
70e418b6fdSChristian BruefferIn both these use cases, it is far more convenient to develop and run the
7167fb10f3SMarcel Moolenaarlogic in user space.
7267fb10f3SMarcel MoolenaarEspecially hardware diagnostics requires a somewhat user-friendly interface
7367fb10f3SMarcel Moolenaarand adequate reporting.
7467fb10f3SMarcel MoolenaarNeither is done easily as kernel code.
75aaa8b90cSMarcel Moolenaar.Ss I/O port resources
76aaa8b90cSMarcel MoolenaarDevice special files created for I/O port resources allow
77aaa8b90cSMarcel Moolenaar.Xr lseek 2 ,
78aaa8b90cSMarcel Moolenaar.Xr read 2 ,
79aaa8b90cSMarcel Moolenaar.Xr write 2
80aaa8b90cSMarcel Moolenaarand
81aaa8b90cSMarcel Moolenaar.Xr ioctl 2
82aaa8b90cSMarcel Moolenaaroperations to be performed on them.
83aaa8b90cSMarcel MoolenaarThe
84aaa8b90cSMarcel Moolenaar.Xr read 2
85aaa8b90cSMarcel Moolenaarand
86aaa8b90cSMarcel Moolenaar.Xr write 2
87aaa8b90cSMarcel Moolenaarsystem calls are used to perform input and output (resp.) on the port.
88aaa8b90cSMarcel MoolenaarThe amount of data that can be read or written at any single time is either
89aaa8b90cSMarcel Moolenaar1, 2 or 4 bytes.
90aaa8b90cSMarcel MoolenaarWhile the
91aaa8b90cSMarcel Moolenaar.Nm
92aaa8b90cSMarcel Moolenaardriver does not prevent reading or writing 8 bytes at a time for some
93aaa8b90cSMarcel Moolenaararchitectures, it should not be assumed that such actually produces
94aaa8b90cSMarcel Moolenaarcorrect results.
95aaa8b90cSMarcel MoolenaarThe
96aaa8b90cSMarcel Moolenaar.Xr lseek 2
97aaa8b90cSMarcel Moolenaarsystem call is used to select the port number, relative to the I/O port
98aaa8b90cSMarcel Moolenaarregion being represented by the device special file.
99aaa8b90cSMarcel MoolenaarIf, for example, the device special file corresponds to an I/O port region
100aaa8b90cSMarcel Moolenaarfrom 0x3f8 to 0x3ff inclusive, then an offset of 4 given to lseek with a
101aaa8b90cSMarcel Moolenaarwhence value of SEEK_SET will target port 0x3fc on the next read or write
102aaa8b90cSMarcel Moolenaaroperation.
103aaa8b90cSMarcel MoolenaarThe
104aaa8b90cSMarcel Moolenaar.Xr ioctl 2
105aaa8b90cSMarcel Moolenaarsystem call can be used for the
106aaa8b90cSMarcel Moolenaar.Dv PROTO_IOC_REGION
107aaa8b90cSMarcel Moolenaarrequest.
108aaa8b90cSMarcel MoolenaarThis ioctl request returns the extend of the resource covered by this
10925972509SEdward Tomasz Napieraladevice special file.
11025972509SEdward Tomasz NapieralaThe extend is returned in the following structure:
111aaa8b90cSMarcel Moolenaar.Bd -literal
112aaa8b90cSMarcel Moolenaarstruct proto_ioc_region {
113aaa8b90cSMarcel Moolenaar        unsigned long   address;
114aaa8b90cSMarcel Moolenaar        unsigned long   size;
115aaa8b90cSMarcel Moolenaar};
116aaa8b90cSMarcel Moolenaar.Ed
117aaa8b90cSMarcel Moolenaar.Ss Memory mapped I/O resources
118aaa8b90cSMarcel MoolenaarThe device special files created for memory mapped I/O resources behave
119aaa8b90cSMarcel Moolenaarin the same way as those created for I/O port resources.
120aaa8b90cSMarcel MoolenaarAdditionally, device special files for memory mapped I/O resources allow
121aaa8b90cSMarcel Moolenaarthe memory to be mapped into the process' address space using
122aaa8b90cSMarcel Moolenaar.Xr mmap 2 .
123aaa8b90cSMarcel MoolenaarReads and writes to the memory address returned by
124aaa8b90cSMarcel Moolenaar.Xr mmap 2
125aaa8b90cSMarcel Moolenaargo directly to the hardware.
126aaa8b90cSMarcel MoolenaarAs such the use of
127aaa8b90cSMarcel Moolenaar.Xr read 2
128aaa8b90cSMarcel Moolenaarand
129aaa8b90cSMarcel Moolenaar.Xr write 2
130aaa8b90cSMarcel Moolenaarcan be avoided, reducing the access overhead significantly.
131aaa8b90cSMarcel MoolenaarAlignment and access width constraints put forth by the underlying device
132aaa8b90cSMarcel Moolenaarapply.
133aaa8b90cSMarcel MoolenaarAlso, make sure the compiler does not optimize memory accesses away or has
134aaa8b90cSMarcel Moolenaarthem coalesced into bigger accesses.
135aaa8b90cSMarcel Moolenaar.Ss DMA pseudo resource
136aaa8b90cSMarcel MoolenaarA device special file named
137aaa8b90cSMarcel Moolenaar.Pa busdma
138aaa8b90cSMarcel Moolenaaris created for the purpose of doing DMA.
139aaa8b90cSMarcel MoolenaarIt only supports
140aaa8b90cSMarcel Moolenaar.Xr ioctl 2
141aaa8b90cSMarcel Moolenaarand only for the
142aaa8b90cSMarcel Moolenaar.Dv PROTO_IOC_BUSDMA
143aaa8b90cSMarcel Moolenaarrequest.
144aaa8b90cSMarcel MoolenaarThis device special file does not support
145aaa8b90cSMarcel Moolenaar.Xr read 2
146aaa8b90cSMarcel Moolenaarnor
147aaa8b90cSMarcel Moolenaar.Xr write 2 .
148aaa8b90cSMarcel MoolenaarThe
149aaa8b90cSMarcel Moolenaar.Dv PROTO_IOC_BUSDMA
150aaa8b90cSMarcel Moolenaarrequest has an argument that is both in and out and is defined as
151aaa8b90cSMarcel Moolenaarfollows:
152aaa8b90cSMarcel Moolenaar.Bd -literal
153aaa8b90cSMarcel Moolenaarstruct proto_ioc_busdma {
154aaa8b90cSMarcel Moolenaar        unsigned int    request;
155aaa8b90cSMarcel Moolenaar        unsigned long   key;
156aaa8b90cSMarcel Moolenaar        union {
157aaa8b90cSMarcel Moolenaar                struct {
158aaa8b90cSMarcel Moolenaar                        unsigned long   align;
159aaa8b90cSMarcel Moolenaar                        unsigned long   bndry;
160aaa8b90cSMarcel Moolenaar                        unsigned long   maxaddr;
161aaa8b90cSMarcel Moolenaar                        unsigned long   maxsz;
162aaa8b90cSMarcel Moolenaar                        unsigned long   maxsegsz;
163aaa8b90cSMarcel Moolenaar                        unsigned int    nsegs;
164aaa8b90cSMarcel Moolenaar                        unsigned int    datarate;
165aaa8b90cSMarcel Moolenaar                        unsigned int    flags;
166aaa8b90cSMarcel Moolenaar                } tag;
167aaa8b90cSMarcel Moolenaar                struct {
168aaa8b90cSMarcel Moolenaar                        unsigned long   tag;
169aaa8b90cSMarcel Moolenaar                        unsigned int    flags;
170aaa8b90cSMarcel Moolenaar                        unsigned long   virt_addr;
171aaa8b90cSMarcel Moolenaar                        unsigned long   virt_size;
172aaa8b90cSMarcel Moolenaar                        unsigned int    phys_nsegs;
173aaa8b90cSMarcel Moolenaar                        unsigned long   phys_addr;
174aaa8b90cSMarcel Moolenaar                        unsigned long   bus_addr;
175aaa8b90cSMarcel Moolenaar                        unsigned int    bus_nsegs;
176aaa8b90cSMarcel Moolenaar                } md;
177aaa8b90cSMarcel Moolenaar                struct {
178aaa8b90cSMarcel Moolenaar                        unsigned int    op;
179aaa8b90cSMarcel Moolenaar                        unsigned long   base;
180aaa8b90cSMarcel Moolenaar                        unsigned long   size;
181aaa8b90cSMarcel Moolenaar                } sync;
182aaa8b90cSMarcel Moolenaar        } u;
183aaa8b90cSMarcel Moolenaar        unsigned long   result;
184aaa8b90cSMarcel Moolenaar};
185aaa8b90cSMarcel Moolenaar.Ed
186aaa8b90cSMarcel MoolenaarThe
187aaa8b90cSMarcel Moolenaar.Va request
188aaa8b90cSMarcel Moolenaarfield is used to specify which DMA operation is to be performed.
189aaa8b90cSMarcel MoolenaarThe
190aaa8b90cSMarcel Moolenaar.Va key
191aaa8b90cSMarcel Moolenaarfield is used to specify which object the operation applies to.
192aaa8b90cSMarcel MoolenaarAn object is either a tag or a memory descriptor (md).
193aaa8b90cSMarcel MoolenaarThe following DMA operations are defined:
194aaa8b90cSMarcel Moolenaar.Bl -tag -width XXXX
195aaa8b90cSMarcel Moolenaar.It PROTO_IOC_BUSDMA_TAG_CREATE
196aaa8b90cSMarcel MoolenaarCreate a root tag.
197aaa8b90cSMarcel MoolenaarThe
198aaa8b90cSMarcel Moolenaar.Va result
199aaa8b90cSMarcel Moolenaarfield is set on output with the key of the DMA tag.
200aaa8b90cSMarcel MoolenaarThe tag is created with the constraints given by the
201aaa8b90cSMarcel Moolenaar.Va tag
20225972509SEdward Tomasz Napieralasub-structure.
20325972509SEdward Tomasz NapieralaThese constraints correspond roughly to those that can be given to the
204aaa8b90cSMarcel Moolenaar.Xr bus_dma_tag_create 9
205aaa8b90cSMarcel Moolenaarfunction.
206aaa8b90cSMarcel Moolenaar.It PROTO_IOC_BUSDMA_TAG_DERIVE
207aaa8b90cSMarcel MoolenaarCreate a derived tag.
208aaa8b90cSMarcel MoolenaarThe
209aaa8b90cSMarcel Moolenaar.Va key
210aaa8b90cSMarcel Moolenaarfield is used to identify the parent tag from which to derive the new tag.
211aaa8b90cSMarcel MoolenaarThe key of the derived tag is returned in the
212aaa8b90cSMarcel Moolenaar.Va result
213aaa8b90cSMarcel Moolenaarfield.
214aaa8b90cSMarcel MoolenaarThe derived tag combines the constraints of the parent tag with those
215aaa8b90cSMarcel Moolenaargiven by the
216aaa8b90cSMarcel Moolenaar.Va tag
217aaa8b90cSMarcel Moolenaarsub-structure.
218aaa8b90cSMarcel MoolenaarThe combined constraints are written back to the
219aaa8b90cSMarcel Moolenaar.Va tag
220aaa8b90cSMarcel Moolenaarsub-structure on return.
221aaa8b90cSMarcel Moolenaar.It PROTO_IOC_BUSDMA_TAG_DESTROY
222aaa8b90cSMarcel MoolenaarDestroy a root or derived tag previously created.
223aaa8b90cSMarcel MoolenaarThe
224aaa8b90cSMarcel Moolenaar.Va key
225aaa8b90cSMarcel Moolenaarfield specifies the tag to destroy.
226aaa8b90cSMarcel MoolenaarA tag can only be destroyed when not referenced anymore.
227aaa8b90cSMarcel MoolenaarThis means that derived tags that have this tag as a parent and memory
228aaa8b90cSMarcel Moolenaardescriptors created from this tag must be destroyed first.
229aaa8b90cSMarcel Moolenaar.It PROTO_IOC_BUSDMA_MEM_ALLOC
230aaa8b90cSMarcel MoolenaarAllocate memory that satisfies the constraints put forth by the tag
231aaa8b90cSMarcel Moolenaargiven in the
232aaa8b90cSMarcel Moolenaar.Va tag
233aaa8b90cSMarcel Moolenaarfield of the
234aaa8b90cSMarcel Moolenaar.Va md
235aaa8b90cSMarcel Moolenaarsub-structure.
236aaa8b90cSMarcel MoolenaarThe key of the memory descriptor for this memory is returned in the
237aaa8b90cSMarcel Moolenaar.Va result
238aaa8b90cSMarcel Moolenaarfield.
239aaa8b90cSMarcel MoolenaarThe
240aaa8b90cSMarcel Moolenaar.Va md
241aaa8b90cSMarcel Moolenaarsub-structure is filled on return with details of the allocation.
242aaa8b90cSMarcel MoolenaarThe kernel virtual address and the size of the allocated memory are returned
243aaa8b90cSMarcel Moolenaarin the
244aaa8b90cSMarcel Moolenaar.Va virt_addr
245aaa8b90cSMarcel Moolenaarand
246aaa8b90cSMarcel Moolenaar.Va virt_size
247aaa8b90cSMarcel Moolenaarfields.
248*ffc4f93eSBenedict ReuschlingThe number of contiguous physical memory segments and the address of the first
249aaa8b90cSMarcel Moolenaarsegment are returned in the
250aaa8b90cSMarcel Moolenaar.Va phys_nsegs
251aaa8b90cSMarcel Moolenaarand
252aaa8b90cSMarcel Moolenaar.Va phys_addr
253aaa8b90cSMarcel Moolenaarfields.
254aaa8b90cSMarcel MoolenaarAllocated memory is automatically loaded and thus mapped into bus space.
255aaa8b90cSMarcel MoolenaarThe number of bus segments and the address of the first segment are returned
256aaa8b90cSMarcel Moolenaarin the
257aaa8b90cSMarcel Moolenaar.Va bus_nsegs
258aaa8b90cSMarcel Moolenaarand
259aaa8b90cSMarcel Moolenaar.Va bus_addr
260aaa8b90cSMarcel Moolenaarfields.
261aaa8b90cSMarcel MoolenaarThe behaviour of this operation banks heavily on how
262aaa8b90cSMarcel Moolenaar.Xr bus_dmamem_alloc 9
263aaa8b90cSMarcel Moolenaaris implemented, which means that memory is currently always allocated as a
264*ffc4f93eSBenedict Reuschlingsingle contiguous region of physical memory.
265*ffc4f93eSBenedict ReuschlingIn practice this also tends to give a single contiguous region in bus space.
266aaa8b90cSMarcel MoolenaarThis may change over time.
267aaa8b90cSMarcel Moolenaar.It PROTO_IOC_BUSDMA_MEM_FREE
268b1603638SGordon BerglingFree previously allocated memory and destroy the memory descriptor.
269aaa8b90cSMarcel MoolenaarThe
270aaa8b90cSMarcel Moolenaar.Nm
271aaa8b90cSMarcel Moolenaardriver is not in a position to track whether the memory has been mapped in
272aaa8b90cSMarcel Moolenaarthe process' address space, so the application is responsible for unmapping
273aaa8b90cSMarcel Moolenaarthe memory before it is freed.
274aaa8b90cSMarcel MoolenaarThe
275aaa8b90cSMarcel Moolenaar.Nm
276aaa8b90cSMarcel Moolenaardriver also cannot protect against the hardware writing to or reading from
277aaa8b90cSMarcel Moolenaarthe memory, even after it has been freed.
278aaa8b90cSMarcel MoolenaarWhen the memory is reused for other purposes it can be corrupted or cause
279aaa8b90cSMarcel Moolenaarthe hardware to behave in unpredictable ways when DMA has not stopped
280aaa8b90cSMarcel Moolenaarcompletely before freeing.
281aaa8b90cSMarcel Moolenaar.It PROTO_IOC_BUSDMA_MD_CREATE
282aaa8b90cSMarcel MoolenaarCreate an empty memory descriptor with the tag specified in the
283aaa8b90cSMarcel Moolenaar.Va tag
284aaa8b90cSMarcel Moolenaarfield of the
285aaa8b90cSMarcel Moolenaar.Va md
286aaa8b90cSMarcel Moolenaarsub-structure.
287aaa8b90cSMarcel MoolenaarThe key of the memory descriptor is returned in the
288aaa8b90cSMarcel Moolenaar.Va result
289aaa8b90cSMarcel Moolenaarfield.
290aaa8b90cSMarcel Moolenaar.It PROTO_IOC_BUSDMA_MD_DESTROY
291aaa8b90cSMarcel MoolenaarDestroy the previously created memory descriptor specified by the
292aaa8b90cSMarcel Moolenaar.Va key
293aaa8b90cSMarcel Moolenaarfield.
294aaa8b90cSMarcel MoolenaarWhen the memory descriptor is still loaded, it is unloaded first.
295aaa8b90cSMarcel Moolenaar.It PROTO_IOC_BUSDMA_MD_LOAD
296*ffc4f93eSBenedict ReuschlingLoad a contiguous region of memory in the memory descriptor specified by the
297aaa8b90cSMarcel Moolenaar.Va key
298aaa8b90cSMarcel Moolenaarfield.
299aaa8b90cSMarcel MoolenaarThe size and address in the process' virtual address space are specified
300aaa8b90cSMarcel Moolenaarby the
301aaa8b90cSMarcel Moolenaar.Va virt_size
302aaa8b90cSMarcel Moolenaarand
303aaa8b90cSMarcel Moolenaar.Va virt_addr
304aaa8b90cSMarcel Moolenaarfields.
305aaa8b90cSMarcel MoolenaarOn return, the
306aaa8b90cSMarcel Moolenaar.Va md
307aaa8b90cSMarcel Moolenaarsub-structure contains the result of the operation.
308aaa8b90cSMarcel MoolenaarThe number of physical segments and the address of the first segment is
309aaa8b90cSMarcel Moolenaarreturned in the
310aaa8b90cSMarcel Moolenaar.Va phys_nsegs
311aaa8b90cSMarcel Moolenaarand
312aaa8b90cSMarcel Moolenaar.Va phys_addr
313aaa8b90cSMarcel Moolenaarfields.
314aaa8b90cSMarcel MoolenaarThe number of bus space segments and the address of the first segment in
315aaa8b90cSMarcel Moolenaarbus space is returned in the
316aaa8b90cSMarcel Moolenaar.Va bus_nsegs
317aaa8b90cSMarcel Moolenaarand
318aaa8b90cSMarcel Moolenaar.Va bus_addr
319aaa8b90cSMarcel Moolenaarfields.
320aaa8b90cSMarcel Moolenaar.It PROTO_IOC_BUSDMA_MD_UNLOAD
321aaa8b90cSMarcel MoolenaarUnload the memory descriptor specified by the
322aaa8b90cSMarcel Moolenaar.Va key
323aaa8b90cSMarcel Moolenaarfield.
324aaa8b90cSMarcel Moolenaar.It PROTO_IOC_BUSDMA_SYNC
325aaa8b90cSMarcel MoolenaarGuarantee that all hardware components have a coherent view of the memory
326aaa8b90cSMarcel Moolenaartracked by the memory descriptor, specified by the
327aaa8b90cSMarcel Moolenaar.Va key
328aaa8b90cSMarcel Moolenaarfield.
329aaa8b90cSMarcel MoolenaarA sub-section of the memory can be targeted by specifying the relative
330aaa8b90cSMarcel Moolenaaroffset and size of the memory to make coherent.
331aaa8b90cSMarcel MoolenaarThe offset and size are given by the
332aaa8b90cSMarcel Moolenaar.Va base
333aaa8b90cSMarcel Moolenaarand
334aaa8b90cSMarcel Moolenaar.Va size
335aaa8b90cSMarcel Moolenaarfields of the
336aaa8b90cSMarcel Moolenaar.Va sync
337aaa8b90cSMarcel Moolenaarsub-structure.
338aaa8b90cSMarcel MoolenaarThe
339aaa8b90cSMarcel Moolenaar.Va op
340aaa8b90cSMarcel Moolenaarfield holds the sync operation to be performed.
341aaa8b90cSMarcel MoolenaarThis is similar to the
342aaa8b90cSMarcel Moolenaar.Xr bus_dmamap_sync 9
343aaa8b90cSMarcel Moolenaarfunction.
344aaa8b90cSMarcel Moolenaar.El
345aaa8b90cSMarcel Moolenaar.Ss PCI configuration space
346aaa8b90cSMarcel MoolenaarAccess to PCI configuration space is possible through the
347aaa8b90cSMarcel Moolenaar.Pa pcicfg
348aaa8b90cSMarcel Moolenaardevice special file.
349aaa8b90cSMarcel MoolenaarThe device special file supports
350aaa8b90cSMarcel Moolenaar.Xr lseek 2 ,
351aaa8b90cSMarcel Moolenaar.Xr read 2
352aaa8b90cSMarcel Moolenaarand
353aaa8b90cSMarcel Moolenaar.Xr write 2 .
354aaa8b90cSMarcel MoolenaarUsage is the asme as for I/O port resources.
35567fb10f3SMarcel Moolenaar.Sh FILES
35667fb10f3SMarcel MoolenaarAll device special files corresponding to a PCI device are located under
35767fb10f3SMarcel Moolenaar.Pa /dev/proto/pci<d>:<b>:<s>:<f>
35867fb10f3SMarcel Moolenaarwith
35967fb10f3SMarcel Moolenaar.Pa pci<d>:<b>:<s>:<f>
36067fb10f3SMarcel Moolenaarrepresenting the location of the PCI device in the PCI hierarchy.
36115abbe51SMarcel MoolenaarA PCI location includes:
362dd01de5cSJoel Dahl.Pp
36315abbe51SMarcel Moolenaar.Bl -tag -width XXXXXX -compact -offset indent
36467fb10f3SMarcel Moolenaar.It <d>
36567fb10f3SMarcel MoolenaarThe PCI domain number
36667fb10f3SMarcel Moolenaar.It <b>
36767fb10f3SMarcel MoolenaarThe PCI bus number
36867fb10f3SMarcel Moolenaar.It <s>
36967fb10f3SMarcel MoolenaarThe PCI slot or device number
37067fb10f3SMarcel Moolenaar.It <f>
37167fb10f3SMarcel MoolenaarThe PCI function number
37267fb10f3SMarcel Moolenaar.El
37367fb10f3SMarcel Moolenaar.Pp
37467fb10f3SMarcel MoolenaarEvery PCI device has a device special file called
37567fb10f3SMarcel Moolenaar.Pa pcicfg .
37667fb10f3SMarcel MoolenaarThis device special file gives access to the PCI configuration space.
37715abbe51SMarcel MoolenaarA device special file called
37815abbe51SMarcel Moolenaar.Pa busdma
37915abbe51SMarcel Moolenaaris also created.
38015abbe51SMarcel MoolenaarThis device special file provides the interfaces needed for doing DMA.
38167fb10f3SMarcel MoolenaarFor each valid base address register (BAR), a device special file is created
38267fb10f3SMarcel Moolenaarthat contains the BAR offset and the resource type.
38367fb10f3SMarcel MoolenaarA resource type can be either
38467fb10f3SMarcel Moolenaar.Pa io
38567fb10f3SMarcel Moolenaaror
38667fb10f3SMarcel Moolenaar.Pa mem
38767fb10f3SMarcel Moolenaarrepresenting I/O port or memory mapped I/O space (resp.)
38815abbe51SMarcel Moolenaar.Pp
38925972509SEdward Tomasz NapieralaISA devices do not have a location.
39025972509SEdward Tomasz NapieralaInstead, they are identified by the
39115abbe51SMarcel Moolenaarfirst I/O port address or first memory mapped I/O address.
39215abbe51SMarcel MoolenaarConsequently, all device special files corresponding to an ISA device are
39315abbe51SMarcel Moolenaarlocated under
39415abbe51SMarcel Moolenaar.Pa /dev/proto/isa:<addr>
39515abbe51SMarcel Moolenaarwith
39615abbe51SMarcel Moolenaar.Pa addr
39715abbe51SMarcel Moolenaarthe address in hexadecimal notation.
39815abbe51SMarcel MoolenaarFor each I/O port or memory mapped I/O address, a device special file is
39915abbe51SMarcel Moolenaarcreated that contains the resource identification used by the kernel and
40015abbe51SMarcel Moolenaarthe resource type.
40115abbe51SMarcel MoolenaarThe resource type can be either
40215abbe51SMarcel Moolenaar.Pa io
40315abbe51SMarcel Moolenaaror
40415abbe51SMarcel Moolenaar.Pa mem
40515abbe51SMarcel Moolenaarrepresenting I/O port or memory mapped I/O space (resp.)
40615abbe51SMarcel MoolenaarWhen the device has a DMA channel assigned to it, a device special file
40715abbe51SMarcel Moolenaarwith the name
40815abbe51SMarcel Moolenaar.Pa busdma
40915abbe51SMarcel Moolenaaris created as well.
41015abbe51SMarcel MoolenaarThis device special file provides the interfaces needed for doing DMA.
41115abbe51SMarcel Moolenaar.Pp
41215abbe51SMarcel MoolenaarIf the ISA device is not a Plug-and-Play device nor present in the ACPI
41315abbe51SMarcel Moolenaardevice tree, it must have the appropriate hints so that the kernel can
41415abbe51SMarcel Moolenaarreserve the resources for it.
41567fb10f3SMarcel Moolenaar.\"
41667fb10f3SMarcel Moolenaar.Sh EXAMPLES
41767fb10f3SMarcel MoolenaarA single function PCI device in domain 0, on bus 1, in slot 2 and having a
41867fb10f3SMarcel Moolenaarsingle memory mapped I/O region will have the following device special files:
419dd01de5cSJoel Dahl.Pp
42015abbe51SMarcel Moolenaar.Bl -tag -width XXXXXX -compact -offset indent
42167fb10f3SMarcel Moolenaar.It Pa /dev/proto/pci0:1:2:0/10.mem
42267fb10f3SMarcel Moolenaar.It Pa /dev/proto/pci0:1:2:0/pcicfg
42367fb10f3SMarcel Moolenaar.El
42415abbe51SMarcel Moolenaar.Pp
42515abbe51SMarcel MoolenaarA legacy floppy controller will have the following device files:
42615abbe51SMarcel Moolenaar.Pp
42715abbe51SMarcel Moolenaar.Bl -tag -width XXXXXX -compact -offset indent
42815abbe51SMarcel Moolenaar.It Pa /dev/proto/isa:0x3f0/00.io
42915abbe51SMarcel Moolenaar.It Pa /dev/proto/isa:0x3f0/01.io
43015abbe51SMarcel Moolenaar.It Pa /dev/proto/isa:0x3f0/busdma
43115abbe51SMarcel Moolenaar.El
43267fb10f3SMarcel Moolenaar.\"
433aaa8b90cSMarcel Moolenaar.Sh SEE ALSO
434aaa8b90cSMarcel Moolenaar.Xr ioctl 2 ,
435aaa8b90cSMarcel Moolenaar.Xr lseek 2 ,
436aaa8b90cSMarcel Moolenaar.Xr mmap 2 ,
437aaa8b90cSMarcel Moolenaar.Xr read 2 ,
438aaa8b90cSMarcel Moolenaar.Xr write 2 ,
439aaa8b90cSMarcel Moolenaar.Xr bus_dma_tag_create 9 ,
440aaa8b90cSMarcel Moolenaar.Xr bus_dmamap_sync 9 ,
441aaa8b90cSMarcel Moolenaar.Xr bus_dmamem_alloc 9
442aaa8b90cSMarcel Moolenaar.\"
443dd01de5cSJoel Dahl.Sh AUTHORS
444dd01de5cSJoel DahlThe
445dd01de5cSJoel Dahl.Nm
446dd01de5cSJoel Dahldevice driver and this manual page were written by
4476c899950SBaptiste Daroussin.An Marcel Moolenaar Aq Mt marcel@xcllnt.net .
44867fb10f3SMarcel Moolenaar.Sh SECURITY CONSIDERATIONS
44967fb10f3SMarcel MoolenaarBecause programs have direct access to the hardware, the
45067fb10f3SMarcel Moolenaar.Nm
45167fb10f3SMarcel Moolenaardriver is inherently insecure.
45267fb10f3SMarcel MoolenaarIt is not advisable to use this driver on a production machine.
45367fb10f3SMarcel Moolenaar.\"
45467fb10f3SMarcel Moolenaar.Sh MISSING FUNCTIONALITY
45567fb10f3SMarcel MoolenaarThe
45667fb10f3SMarcel Moolenaar.Nm
457aaa8b90cSMarcel Moolenaardriver does not fully support memory descriptors that need multiple
458aaa8b90cSMarcel Moolenaarphysical memory segments or multiple bus space segments.
459aaa8b90cSMarcel MoolenaarAt the very least, an operation is needed on the DMA pseudo resource
460aaa8b90cSMarcel Moolenaarfor the application to obtain all segments.
461aaa8b90cSMarcel Moolenaar.Pp
462aaa8b90cSMarcel MoolenaarThe
463aaa8b90cSMarcel Moolenaar.Nm
46467fb10f3SMarcel Moolenaardriver does not yet support interrupts.
46515abbe51SMarcel MoolenaarSince interrupts cannot be handled by the driver itself, they must be
46615abbe51SMarcel Moolenaarconverted into signals and delivered to the program that has registered
46715abbe51SMarcel Moolenaarfor interrupts.
46815abbe51SMarcel MoolenaarA satisfactory mechanism for keeping the interrupt masked during the
46915abbe51SMarcel Moolenaarsignal handling is still being worked out.
47067fb10f3SMarcel Moolenaar.Pp
47115abbe51SMarcel MoolenaarDMA support for devices other than busmaster devices is not present yet.
47215abbe51SMarcel MoolenaarThe details of how a program is to interact with the DMA controller still
47315abbe51SMarcel Moolenaarneed to be fleshed out.
474