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 19, 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.Pp 51To have the driver attach to a device instead of its regular driver, 52mention it in the list of devices assigned to the following loader variable: 53.Bd -ragged -offset indent 54hw.proto.attach="desc[,desc]" 55.Ed 56.\" 57.Sh DESCRIPTION 58The 59.Nm 60device driver attaches to PCI or ISA devices when no other device drivers 61are present for those devices and it creates device special files for all 62resources associated with the device. 63The driver itself has no knowledge of the device it attaches to. 64Programs can open these device special files and perform register-level 65reads and writes. 66As such, the 67.Nm 68device driver is nothing but a conduit or gateway between user space 69programs and the hardware device. 70.Pp 71Examples for why this is useful include hardware diagnostics and prototyping. 72In both these use cases, it is far more convenient to develop and run the 73logic in user space. 74Especially hardware diagnostics requires a somewhat user-friendly interface 75and adequate reporting. 76Neither is done easily as kernel code. 77.\" 78.Sh FILES 79All device special files corresponding to a PCI device are located under 80.Pa /dev/proto/pci<d>:<b>:<s>:<f> 81with 82.Pa pci<d>:<b>:<s>:<f> 83representing the location of the PCI device in the PCI hierarchy. 84A PCI location includes: 85.Pp 86.Bl -tag -width XXXXXX -compact -offset indent 87.It <d> 88The PCI domain number 89.It <b> 90The PCI bus number 91.It <s> 92The PCI slot or device number 93.It <f> 94The PCI function number 95.El 96.Pp 97Every PCI device has a device special file called 98.Pa pcicfg . 99This device special file gives access to the PCI configuration space. 100A device special file called 101.Pa busdma 102is also created. 103This device special file provides the interfaces needed for doing DMA. 104For each valid base address register (BAR), a device special file is created 105that contains the BAR offset and the resource type. 106A resource type can be either 107.Pa io 108or 109.Pa mem 110representing I/O port or memory mapped I/O space (resp.) 111.Pp 112ISA devices do not have a location. Instead, they are identified by the 113first I/O port address or first memory mapped I/O address. 114Consequently, all device special files corresponding to an ISA device are 115located under 116.Pa /dev/proto/isa:<addr> 117with 118.Pa addr 119the address in hexadecimal notation. 120For each I/O port or memory mapped I/O address, a device special file is 121created that contains the resource identification used by the kernel and 122the resource type. 123The resource type can be either 124.Pa io 125or 126.Pa mem 127representing I/O port or memory mapped I/O space (resp.) 128When the device has a DMA channel assigned to it, a device special file 129with the name 130.Pa busdma 131is created as well. 132This device special file provides the interfaces needed for doing DMA. 133.Pp 134If the ISA device is not a Plug-and-Play device nor present in the ACPI 135device tree, it must have the appropriate hints so that the kernel can 136reserve the resources for it. 137.\" 138.Sh EXAMPLES 139A single function PCI device in domain 0, on bus 1, in slot 2 and having a 140single memory mapped I/O region will have the following device special files: 141.Pp 142.Bl -tag -width XXXXXX -compact -offset indent 143.It Pa /dev/proto/pci0:1:2:0/10.mem 144.It Pa /dev/proto/pci0:1:2:0/pcicfg 145.El 146.Pp 147A legacy floppy controller will have the following device files: 148.Pp 149.Bl -tag -width XXXXXX -compact -offset indent 150.It Pa /dev/proto/isa:0x3f0/00.io 151.It Pa /dev/proto/isa:0x3f0/01.io 152.It Pa /dev/proto/isa:0x3f0/busdma 153.El 154.\" 155.Sh AUTHORS 156The 157.Nm 158device driver and this manual page were written by 159.An Marcel Moolenaar Aq Mt marcel@xcllnt.net . 160.Sh SECURITY CONSIDERATIONS 161Because programs have direct access to the hardware, the 162.Nm 163driver is inherently insecure. 164It is not advisable to use this driver on a production machine. 165.\" 166.Sh MISSING FUNCTIONALITY 167The 168.Nm 169driver does not yet support interrupts. 170Since interrupts cannot be handled by the driver itself, they must be 171converted into signals and delivered to the program that has registered 172for interrupts. 173A satisfactory mechanism for keeping the interrupt masked during the 174signal handling is still being worked out. 175.Pp 176DMA support for devices other than busmaster devices is not present yet. 177The details of how a program is to interact with the DMA controller still 178need to be fleshed out. 179