firmware.h revision 154974
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: head/sys/sys/firmware.h 154974 2006-01-29 02:52:42Z mlaier $ 27154974Smlaier */ 28154974Smlaier#ifndef _SYS_FIRMWARE_H_ 29154974Smlaier#define _SYS_FIRMWARE_H_ 30154974Smlaier/* 31154974Smlaier * Loadable firmware support. 32154974Smlaier * 33154974Smlaier * Firmware images are embedded in kernel loadable modules that can 34154974Smlaier * be loaded on-demand or pre-loaded as desired. Modules may contain 35154974Smlaier * one or more firmware images that are stored as opaque data arrays 36154974Smlaier * and registered with a unique string name. Consumers request 37154974Smlaier * firmware by name with held references counted to use in disallowing 38154974Smlaier * module/data unload. 39154974Smlaier * 40154974Smlaier * When multiple images are stored in one module the one image is 41154974Smlaier * treated as the master with the other images holding references 42154974Smlaier * to it. This means that to unload the module each dependent/subimage 43154974Smlaier * must first have its references removed. 44154974Smlaier */ 45154974Smlaierstruct firmware { 46154974Smlaier const char *name; /* system-wide name */ 47154974Smlaier const void *data; /* location of image */ 48154974Smlaier size_t datasize; /* size of image in bytes */ 49154974Smlaier unsigned int version; /* version of the image */ 50154974Smlaier int refcnt; /* held references */ 51154974Smlaier struct firmware *parent; /* not null if a subimage */ 52154974Smlaier linker_file_t file; /* loadable module */ 53154974Smlaier}; 54154974Smlaier 55154974Smlaierstruct firmware *firmware_register(const char *, const void *, size_t, 56154974Smlaier unsigned int, struct firmware *); 57154974Smlaierint firmware_unregister(const char *); 58154974Smlaierstruct firmware *firmware_get(const char *); 59154974Smlaier#define FIRMWARE_UNLOAD 0x0001 /* unload if unreferenced */ 60154974Smlaiervoid firmware_put(struct firmware *, int); 61154974Smlaier#endif /* _SYS_FIRMWARE_H_ */ 62