1.\" $NetBSD: firmload.9,v 1.3 2006/01/21 23:33:21 wiz Exp $ 2.\" 3.\" Copyright (c) 2006 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by Jason R. Thorpe. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. All advertising materials mentioning features or use of this software 18.\" must display the following acknowledgement: 19.\" This product includes software developed by the NetBSD 20.\" Foundation, Inc. and its contributors. 21.\" 4. Neither the name of The NetBSD Foundation nor the names of its 22.\" contributors may be used to endorse or promote products derived 23.\" from this software without specific prior written permission. 24.\" 25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35.\" POSSIBILITY OF SUCH DAMAGE. 36.\" 37.Dd January 17, 2006 38.Dt FIRMLOAD 9 39.Os 40.Sh NAME 41.Nm firmload 42.Nd Firmware loader API for device drivers 43.Sh SYNOPSIS 44.In dev/firmload.h 45.\" 46.Ft int 47.Fn "firmware_open" "const char *drvname" "const char *imgname" \ 48"firmware_handle_t *fhp" 49.\" 50.Ft int 51.Fn "firmware_close" "firmware_handle_t fh" 52.\" 53.Ft off_t 54.Fn "firmware_get_size" "firmware_handle_t fh" 55.\" 56.Ft int 57.Fn "firmware_read" "firmware_handle_t fh" "off_t offset" "void *buf" \ 58"size_t size" 59.\" 60.Ft void * 61.Fn "firmware_malloc" "size_t size" 62.\" 63.Ft void 64.Fn "firmware_free" "void *buf" "size_t size" 65.Sh DESCRIPTION 66.Nm 67provides a simple and convenient API for device drivers to load firmware 68images from files residing in the file system that are necessary for the 69devices that they control. 70Firmware images reside in sub-directories, one for each driver, of a series 71of colon-separated path prefixes specified the sysctl variable 72.Dv hw.firmware.path . 73.Pp 74The following functions are provided by the 75.Nm 76API: 77.Bl -tag -width indent 78.It int Fn "firmware_open" "const char *drvname" "const char *imgname" \ 79"firmware_handle_t *fhp" 80.Pp 81Open then firmware image 82.Fa imgname 83for the driver 84.Fa drvname . 85The path to the firmware image file is constructed by appending the string 86.Dq "/drvname/imgname" 87to each configured path prefix until opening the firmware image file succeeds. 88Upon success, 89.Fn firmware_open 90returns 0 and stores a firmware image handle in the location pointed to by 91.Fa fhp . 92Otherwise, an error code is returned to indicate the reason for failure. 93.It int Fn "firmware_close" "firmware_handle_t fh" 94.Pp 95Close the firmware image file associated with the firmware handle 96.Fa fh . 97Returns 0 upon success or an error code to indicate the reason for failure. 98.It off_t Fn "firmware_get_size" "firmware_handle_t fh" 99.Pp 100Returns the size of the image file associated with the firmware handle 101.Fa fh . 102.It int Fn "firmware_read" "firmware_handle_t fh" "off_t offset" "void *buf" \ 103"size_t size" 104.Pp 105Reads from the image file associated with the firmware handle 106.Fa fh 107beginning at offset 108.Fa offset 109for length 110.Fa size . 111The firmware image data is placed into the buffer specified by 112.Fa buf . 113Returns 0 upon success or an error code to indicate the reason for failure. 114.It void * Ns Fn "firmware_malloc" "size_t size" 115.Pp 116Allocates a region of wired kernel memory of size 117.Fa size . 118Note: 119.Fn firmware_malloc 120may block. 121.It void Fn "firmware_free" "void *buf" "size_t size" 122.Pp 123Frees a region of memory previously allocated by 124.Fn firmware_malloc . 125.El 126.Sh SEE ALSO 127.Xr autoconf 9 , 128.Xr malloc 9 , 129.Xr vnsubr 9 130.Sh HISTORY 131The 132.Nm 133framework first appeared in 134.Nx 4.0 . 135.Sh AUTHORS 136.An Jason Thorpe Aq thorpej@NetBSD.org 137