1.\" 2.\" Copyright (c) 2014, 2015 Marcel Moolenaar 3.\" All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25.\" 26.\" $FreeBSD$ 27.\" 28.Dd July 3, 2015 29.Dt PROTO 4 30.Os 31.\" 32.Sh NAME 33.Nm proto 34.Nd Generic prototyping and diagnostics driver 35.\" 36.Sh SYNOPSIS 37To compile this driver into the kernel, 38place the following line in your 39kernel configuration file: 40.Bd -ragged -offset indent 41.Cd "device proto" 42.Ed 43.Pp 44Alternatively, to load the driver as a 45module at boot time, place the following line in 46.Xr loader.conf 5 : 47.Bd -literal -offset indent 48proto_load="YES" 49.Ed 50.\" 51.Sh DESCRIPTION 52The 53.Nm 54device driver attaches to PCI or ISA devices when no other device drivers 55are present for those devices and it creates device special files for all 56resources associated with the device. 57The driver itself has no knowledge of the device it attaches to. 58Programs can open these device special files and perform register-level 59reads and writes. 60As such, the 61.Nm 62device driver is nothing but a conduit or gateway between user space 63programs and the hardware device. 64.Pp 65Examples for why this is useful include hardware diagnostics and prototyping. 66In both these use cases, it is far more convenient to develop and run the 67logic in user space. 68Especially hardware diagnostics requires a somewhat user-friendly interface 69and adequate reporting. 70Neither is done easily as kernel code. 71.\" 72.Sh FILES 73All device special files corresponding to a PCI device are located under 74.Pa /dev/proto/pci<d>:<b>:<s>:<f> 75with 76.Pa pci<d>:<b>:<s>:<f> 77representing the location of the PCI device in the PCI hierarchy. 78A PCI location includes: 79.Pp 80.Bl -tag -width XXXXXX -compact -offset indent 81.It <d> 82The PCI domain number 83.It <b> 84The PCI bus number 85.It <s> 86The PCI slot or device number 87.It <f> 88The PCI function number 89.El 90.Pp 91Every PCI device has a device special file called 92.Pa pcicfg . 93This device special file gives access to the PCI configuration space. 94A device special file called 95.Pa busdma 96is also created. 97This device special file provides the interfaces needed for doing DMA. 98For each valid base address register (BAR), a device special file is created 99that contains the BAR offset and the resource type. 100A resource type can be either 101.Pa io 102or 103.Pa mem 104representing I/O port or memory mapped I/O space (resp.) 105.Pp 106ISA devices do not have a location. Instead, they are identified by the 107first I/O port address or first memory mapped I/O address. 108Consequently, all device special files corresponding to an ISA device are 109located under 110.Pa /dev/proto/isa:<addr> 111with 112.Pa addr 113the address in hexadecimal notation. 114For each I/O port or memory mapped I/O address, a device special file is 115created that contains the resource identification used by the kernel and 116the resource type. 117The resource type can be either 118.Pa io 119or 120.Pa mem 121representing I/O port or memory mapped I/O space (resp.) 122When the device has a DMA channel assigned to it, a device special file 123with the name 124.Pa busdma 125is created as well. 126This device special file provides the interfaces needed for doing DMA. 127.Pp 128If the ISA device is not a Plug-and-Play device nor present in the ACPI 129device tree, it must have the appropriate hints so that the kernel can 130reserve the resources for it. 131.\" 132.Sh EXAMPLES 133A single function PCI device in domain 0, on bus 1, in slot 2 and having a 134single memory mapped I/O region will have the following device special files: 135.Pp 136.Bl -tag -width XXXXXX -compact -offset indent 137.It Pa /dev/proto/pci0:1:2:0/10.mem 138.It Pa /dev/proto/pci0:1:2:0/pcicfg 139.El 140.Pp 141A legacy floppy controller will have the following device files: 142.Pp 143.Bl -tag -width XXXXXX -compact -offset indent 144.It Pa /dev/proto/isa:0x3f0/00.io 145.It Pa /dev/proto/isa:0x3f0/01.io 146.It Pa /dev/proto/isa:0x3f0/busdma 147.El 148.\" 149.Sh AUTHORS 150The 151.Nm 152device driver and this manual page were written by 153.An Marcel Moolenaar Aq Mt marcel@xcllnt.net . 154.Sh SECURITY CONSIDERATIONS 155Because programs have direct access to the hardware, the 156.Nm 157driver is inherently insecure. 158It is not advisable to use this driver on a production machine. 159.\" 160.Sh MISSING FUNCTIONALITY 161The 162.Nm 163driver does not yet support interrupts. 164Since interrupts cannot be handled by the driver itself, they must be 165converted into signals and delivered to the program that has registered 166for interrupts. 167A satisfactory mechanism for keeping the interrupt masked during the 168signal handling is still being worked out. 169.Pp 170DMA support for devices other than busmaster devices is not present yet. 171The details of how a program is to interact with the DMA controller still 172need to be fleshed out. 173