1154974Smlaier/*-
2154974Smlaier * Copyright (c) 2005, Sam Leffler <sam@errno.com>
3154974Smlaier * All rights reserved.
4154974Smlaier *
5154974Smlaier * Redistribution and use in source and binary forms, with or without
6154974Smlaier * modification, are permitted provided that the following conditions
7154974Smlaier * are met:
8154974Smlaier * 1. Redistributions of source code must retain the above copyright
9154974Smlaier *    notice unmodified, this list of conditions, and the following
10154974Smlaier *    disclaimer.
11154974Smlaier * 2. Redistributions in binary form must reproduce the above copyright
12154974Smlaier *    notice, this list of conditions and the following disclaimer in the
13154974Smlaier *    documentation and/or other materials provided with the distribution.
14154974Smlaier *
15154974Smlaier * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16154974Smlaier * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17154974Smlaier * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18154974Smlaier * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19154974Smlaier * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20154974Smlaier * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21154974Smlaier * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22154974Smlaier * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23154974Smlaier * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24154974Smlaier * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25154974Smlaier *
26154974Smlaier * $FreeBSD$
27154974Smlaier */
28154974Smlaier#ifndef _SYS_FIRMWARE_H_
29154974Smlaier#define _SYS_FIRMWARE_H_
30154974Smlaier/*
31154974Smlaier * Loadable firmware support.
32154974Smlaier *
33166756Sluigi * The firmware abstraction provides an interface for loading firmware
34166756Sluigi * images into the kernel and making them available to clients.
35166756Sluigi *
36166756Sluigi * Firmware images are usually embedded in kernel loadable modules that can
37154974Smlaier * be loaded on-demand or pre-loaded as desired.  Modules may contain
38154974Smlaier * one or more firmware images that are stored as opaque data arrays
39166756Sluigi * and registered with a unique string name. Clients request
40166756Sluigi * firmware by name, and are returned a struct firmware * below on success.
41166756Sluigi * The kernel keeps track of references to firmware images to allow/prevent
42154974Smlaier * module/data unload.
43154974Smlaier *
44166756Sluigi * When multiple images are stored in one module, the first image is
45154974Smlaier * treated as the master with the other images holding references
46154974Smlaier * to it.  This means that to unload the module each dependent/subimage
47154974Smlaier * must first have its references removed.
48166756Sluigi * In order for automatic loading to work, the master image must have
49166756Sluigi * the same name as the module it is embedded into.
50154974Smlaier */
51154974Smlaierstruct firmware {
52154974Smlaier	const char	*name;		/* system-wide name */
53154974Smlaier	const void	*data;		/* location of image */
54154974Smlaier	size_t		 datasize;	/* size of image in bytes */
55154974Smlaier	unsigned int	 version;	/* version of the image */
56154974Smlaier};
57154974Smlaier
58166756Sluigiconst struct firmware	*firmware_register(const char *,
59166756Sluigi	const void *, size_t, unsigned int, const struct firmware *);
60166756Sluigiint	 firmware_unregister(const char *);
61166756Sluigiconst struct firmware *firmware_get(const char *);
62154974Smlaier#define	FIRMWARE_UNLOAD		0x0001	/* unload if unreferenced */
63166756Sluigivoid		 firmware_put(const struct firmware *, int);
64154974Smlaier#endif /* _SYS_FIRMWARE_H_ */
65