firmware.h revision 256281
1272343Sngie/*-
2272343Sngie * Copyright (c) 2005, Sam Leffler <sam@errno.com>
3272343Sngie * All rights reserved.
4272343Sngie *
5272343Sngie * Redistribution and use in source and binary forms, with or without
6272343Sngie * modification, are permitted provided that the following conditions
7272343Sngie * are met:
8272343Sngie * 1. Redistributions of source code must retain the above copyright
9272343Sngie *    notice unmodified, this list of conditions, and the following
10272343Sngie *    disclaimer.
11272343Sngie * 2. Redistributions in binary form must reproduce the above copyright
12272343Sngie *    notice, this list of conditions and the following disclaimer in the
13272343Sngie *    documentation and/or other materials provided with the distribution.
14272343Sngie *
15272343Sngie * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16272343Sngie * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17272343Sngie * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18272343Sngie * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19272343Sngie * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20272343Sngie * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21272343Sngie * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22272343Sngie * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23272343Sngie * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24272343Sngie * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25272343Sngie *
26272343Sngie * $FreeBSD: stable/10/sys/sys/firmware.h 166756 2007-02-15 17:21:31Z luigi $
27272343Sngie */
28272343Sngie#ifndef _SYS_FIRMWARE_H_
29272343Sngie#define _SYS_FIRMWARE_H_
30272343Sngie/*
31272343Sngie * Loadable firmware support.
32272343Sngie *
33272343Sngie * The firmware abstraction provides an interface for loading firmware
34272343Sngie * images into the kernel and making them available to clients.
35272343Sngie *
36272343Sngie * Firmware images are usually embedded in kernel loadable modules that can
37272343Sngie * be loaded on-demand or pre-loaded as desired.  Modules may contain
38272343Sngie * one or more firmware images that are stored as opaque data arrays
39272343Sngie * and registered with a unique string name. Clients request
40272343Sngie * firmware by name, and are returned a struct firmware * below on success.
41272343Sngie * The kernel keeps track of references to firmware images to allow/prevent
42272343Sngie * module/data unload.
43272343Sngie *
44272343Sngie * When multiple images are stored in one module, the first image is
45272343Sngie * treated as the master with the other images holding references
46272343Sngie * to it.  This means that to unload the module each dependent/subimage
47272343Sngie * must first have its references removed.
48272343Sngie * In order for automatic loading to work, the master image must have
49272343Sngie * the same name as the module it is embedded into.
50272343Sngie */
51272343Sngiestruct firmware {
52272343Sngie	const char	*name;		/* system-wide name */
53272343Sngie	const void	*data;		/* location of image */
54272343Sngie	size_t		 datasize;	/* size of image in bytes */
55272343Sngie	unsigned int	 version;	/* version of the image */
56272343Sngie};
57272343Sngie
58272343Sngieconst struct firmware	*firmware_register(const char *,
59272343Sngie	const void *, size_t, unsigned int, const struct firmware *);
60272343Sngieint	 firmware_unregister(const char *);
61272343Sngieconst struct firmware *firmware_get(const char *);
62272343Sngie#define	FIRMWARE_UNLOAD		0x0001	/* unload if unreferenced */
63272343Sngievoid		 firmware_put(const struct firmware *, int);
64272343Sngie#endif /* _SYS_FIRMWARE_H_ */
65272343Sngie