2006-01-29 02:52:42 +00:00
|
|
|
/*-
|
2023-05-10 15:40:58 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2017-11-27 15:20:12 +00:00
|
|
|
*
|
2008-04-09 19:07:48 +00:00
|
|
|
* Copyright (c) 2005-2008, Sam Leffler <sam@errno.com>
|
2006-01-29 02:52:42 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice unmodified, this list of conditions, and the following
|
|
|
|
* disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2024-02-05 03:12:37 +00:00
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/eventhandler.h>
|
2024-02-29 16:36:20 +00:00
|
|
|
#include <sys/fcntl.h>
|
2024-02-05 03:12:37 +00:00
|
|
|
#include <sys/firmware.h>
|
2006-01-29 02:52:42 +00:00
|
|
|
#include <sys/kernel.h>
|
2024-02-05 03:12:37 +00:00
|
|
|
#include <sys/linker.h>
|
2006-01-29 02:52:42 +00:00
|
|
|
#include <sys/lock.h>
|
2024-02-05 03:12:37 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/module.h>
|
2006-01-29 02:52:42 +00:00
|
|
|
#include <sys/mutex.h>
|
2024-02-29 16:36:20 +00:00
|
|
|
#include <sys/namei.h>
|
2006-11-06 13:42:10 +00:00
|
|
|
#include <sys/priv.h>
|
2006-01-29 02:52:42 +00:00
|
|
|
#include <sys/proc.h>
|
2024-02-05 03:12:37 +00:00
|
|
|
#include <sys/queue.h>
|
2024-02-29 16:36:20 +00:00
|
|
|
#include <sys/sbuf.h>
|
|
|
|
#include <sys/sysctl.h>
|
2024-02-05 03:12:37 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/taskqueue.h>
|
2008-04-09 19:07:48 +00:00
|
|
|
|
|
|
|
#include <sys/filedesc.h>
|
|
|
|
#include <sys/vnode.h>
|
2006-01-29 02:52:42 +00:00
|
|
|
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
/*
|
|
|
|
* Loadable firmware support. See sys/sys/firmware.h and firmware(9)
|
|
|
|
* form more details on the subsystem.
|
|
|
|
*
|
|
|
|
* 'struct firmware' is the user-visible part of the firmware table.
|
2020-06-10 23:52:29 +00:00
|
|
|
* Additional internal information is stored in a 'struct priv_fw',
|
|
|
|
* which embeds the public firmware structure.
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fw.name != NULL when an image is registered; file != NULL for
|
|
|
|
* autoloaded images whose handling has not been completed.
|
|
|
|
*
|
|
|
|
* The state of a slot evolves as follows:
|
|
|
|
* firmware_register --> fw.name = image_name
|
|
|
|
* (autoloaded image) --> file = module reference
|
|
|
|
* firmware_unregister --> fw.name = NULL
|
|
|
|
* (unloadentry complete) --> file = NULL
|
|
|
|
*
|
|
|
|
* In order for the above to work, the 'file' field must remain
|
|
|
|
* unchanged in firmware_unregister().
|
|
|
|
*
|
|
|
|
* Images residing in the same module are linked to each other
|
|
|
|
* through the 'parent' argument of firmware_register().
|
|
|
|
* One image (typically, one with the same name as the module to let
|
|
|
|
* the autoloading mechanism work) is considered the parent image for
|
|
|
|
* all other images in the same module. Children affect the refcount
|
|
|
|
* on the parent image preventing improper unloading of the image itself.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct priv_fw {
|
|
|
|
int refcnt; /* reference count */
|
2020-06-10 23:52:29 +00:00
|
|
|
LIST_ENTRY(priv_fw) link; /* table linkage */
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* parent entry, see above. Set on firmware_register(),
|
|
|
|
* cleared on firmware_unregister().
|
|
|
|
*/
|
|
|
|
struct priv_fw *parent;
|
|
|
|
|
2024-02-29 16:36:20 +00:00
|
|
|
int flags;
|
|
|
|
#define FW_BINARY 0x080 /* Firmware directly loaded, file == NULL */
|
|
|
|
#define FW_UNLOAD 0x100 /* record FIRMWARE_UNLOAD requests */
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 'file' is private info managed by the autoload/unload code.
|
|
|
|
* Set at the end of firmware_get(), cleared only in the
|
2008-04-09 19:07:48 +00:00
|
|
|
* firmware_unload_task, so the latter can depend on its value even
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
* while the lock is not held.
|
|
|
|
*/
|
|
|
|
linker_file_t file; /* module file, if autoloaded */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 'fw' is the externally visible image information.
|
|
|
|
* We do not make it the first field in priv_fw, to avoid the
|
|
|
|
* temptation of casting pointers to each other.
|
|
|
|
* Use PRIV_FW(fw) to get a pointer to the cointainer of fw.
|
|
|
|
* Beware, PRIV_FW does not work for a NULL pointer.
|
|
|
|
*/
|
|
|
|
struct firmware fw; /* externally visible information */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PRIV_FW returns the pointer to the container of struct firmware *x.
|
|
|
|
* Cast to intptr_t to override the 'const' attribute of x
|
|
|
|
*/
|
|
|
|
#define PRIV_FW(x) ((struct priv_fw *) \
|
|
|
|
((intptr_t)(x) - offsetof(struct priv_fw, fw)) )
|
|
|
|
|
|
|
|
/*
|
2020-06-10 23:52:29 +00:00
|
|
|
* Global firmware image registry.
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
*/
|
2020-06-10 23:52:29 +00:00
|
|
|
static LIST_HEAD(, priv_fw) firmware_table;
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
|
|
|
|
/*
|
2008-04-09 19:07:48 +00:00
|
|
|
* Firmware module operations are handled in a separate task as they
|
2024-02-29 16:36:20 +00:00
|
|
|
* might sleep and they require directory context to do i/o. We also
|
|
|
|
* use this when loading binaries directly.
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
*/
|
2008-04-09 19:07:48 +00:00
|
|
|
static struct taskqueue *firmware_tq;
|
|
|
|
static struct task firmware_unload_task;
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This mutex protects accesses to the firmware table.
|
|
|
|
*/
|
2008-04-09 19:07:48 +00:00
|
|
|
static struct mtx firmware_mtx;
|
2006-01-29 02:52:42 +00:00
|
|
|
MTX_SYSINIT(firmware, &firmware_mtx, "firmware table", MTX_DEF);
|
|
|
|
|
2020-06-10 23:52:29 +00:00
|
|
|
static MALLOC_DEFINE(M_FIRMWARE, "firmware", "device firmware images");
|
|
|
|
|
2024-02-29 16:36:20 +00:00
|
|
|
static uint64_t firmware_max_size = 8u << 20; /* Default to 8MB cap */
|
|
|
|
SYSCTL_U64(_debug, OID_AUTO, firmware_max_size,
|
|
|
|
CTLFLAG_RWTUN, &firmware_max_size, 0,
|
|
|
|
"Max size permitted for a firmware file.");
|
|
|
|
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
/*
|
|
|
|
* Helper function to lookup a name.
|
|
|
|
* As a side effect, it sets the pointer to a free slot, if any.
|
|
|
|
* This way we can concentrate most of the registry scanning in
|
|
|
|
* this function, which makes it easier to replace the registry
|
|
|
|
* with some other data structure.
|
|
|
|
*/
|
|
|
|
static struct priv_fw *
|
2020-06-10 23:52:29 +00:00
|
|
|
lookup(const char *name)
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
{
|
2020-06-10 23:52:29 +00:00
|
|
|
struct priv_fw *fp;
|
|
|
|
|
|
|
|
mtx_assert(&firmware_mtx, MA_OWNED);
|
|
|
|
|
|
|
|
LIST_FOREACH(fp, &firmware_table, link) {
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
if (fp->fw.name != NULL && strcasecmp(name, fp->fw.name) == 0)
|
|
|
|
break;
|
2024-02-29 16:36:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the name looks like an absolute path, also try to match
|
|
|
|
* the last part of the string to the requested firmware if it
|
|
|
|
* matches the trailing components. This allows us to load
|
|
|
|
* /boot/firmware/abc/bca2233_fw.bin and match it against
|
|
|
|
* requests for bca2233_fw.bin or abc/bca2233_fw.bin.
|
|
|
|
*/
|
|
|
|
if (*fp->fw.name == '/' && strlen(fp->fw.name) > strlen(name)) {
|
|
|
|
const char *p = fp->fw.name + strlen(fp->fw.name) - strlen(name);
|
|
|
|
if (p[-1] == '/' && strcasecmp(name, p) == 0)
|
|
|
|
break;
|
|
|
|
}
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
}
|
2020-06-10 23:52:29 +00:00
|
|
|
return (fp);
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
}
|
|
|
|
|
2006-01-29 02:52:42 +00:00
|
|
|
/*
|
|
|
|
* Register a firmware image with the specified name. The
|
|
|
|
* image name must not already be registered. If this is a
|
|
|
|
* subimage then parent refers to a previously registered
|
|
|
|
* image that this should be associated with.
|
|
|
|
*/
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
const struct firmware *
|
2006-01-29 02:52:42 +00:00
|
|
|
firmware_register(const char *imagename, const void *data, size_t datasize,
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
unsigned int version, const struct firmware *parent)
|
2006-01-29 02:52:42 +00:00
|
|
|
{
|
2020-06-10 23:52:29 +00:00
|
|
|
struct priv_fw *frp;
|
|
|
|
char *name;
|
2006-01-29 02:52:42 +00:00
|
|
|
|
|
|
|
mtx_lock(&firmware_mtx);
|
2020-06-10 23:52:29 +00:00
|
|
|
frp = lookup(imagename);
|
|
|
|
if (frp != NULL) {
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
mtx_unlock(&firmware_mtx);
|
|
|
|
printf("%s: image %s already registered!\n",
|
2020-06-10 23:52:29 +00:00
|
|
|
__func__, imagename);
|
|
|
|
return (NULL);
|
2006-01-29 02:52:42 +00:00
|
|
|
}
|
2020-06-10 23:52:29 +00:00
|
|
|
mtx_unlock(&firmware_mtx);
|
|
|
|
|
|
|
|
frp = malloc(sizeof(*frp), M_FIRMWARE, M_WAITOK | M_ZERO);
|
|
|
|
name = strdup(imagename, M_FIRMWARE);
|
|
|
|
|
|
|
|
mtx_lock(&firmware_mtx);
|
|
|
|
if (lookup(imagename) != NULL) {
|
|
|
|
/* We lost a race. */
|
2006-01-29 02:52:42 +00:00
|
|
|
mtx_unlock(&firmware_mtx);
|
2020-06-10 23:52:29 +00:00
|
|
|
free(name, M_FIRMWARE);
|
|
|
|
free(frp, M_FIRMWARE);
|
|
|
|
return (NULL);
|
2006-01-29 02:52:42 +00:00
|
|
|
}
|
2020-06-10 23:52:29 +00:00
|
|
|
frp->fw.name = name;
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
frp->fw.data = data;
|
|
|
|
frp->fw.datasize = datasize;
|
|
|
|
frp->fw.version = version;
|
2011-11-19 00:20:28 +00:00
|
|
|
if (parent != NULL)
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
frp->parent = PRIV_FW(parent);
|
2020-06-10 23:52:29 +00:00
|
|
|
LIST_INSERT_HEAD(&firmware_table, frp, link);
|
2006-01-29 02:52:42 +00:00
|
|
|
mtx_unlock(&firmware_mtx);
|
2007-02-03 16:01:46 +00:00
|
|
|
if (bootverbose)
|
|
|
|
printf("firmware: '%s' version %u: %zu bytes loaded at %p\n",
|
|
|
|
imagename, version, datasize, data);
|
2020-06-10 23:52:29 +00:00
|
|
|
return (&frp->fw);
|
2006-01-29 02:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unregister/remove a firmware image. If there are outstanding
|
|
|
|
* references an error is returned and the image is not removed
|
|
|
|
* from the registry.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
firmware_unregister(const char *imagename)
|
|
|
|
{
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
struct priv_fw *fp;
|
|
|
|
int err;
|
2006-01-29 02:52:42 +00:00
|
|
|
|
|
|
|
mtx_lock(&firmware_mtx);
|
2020-06-10 23:52:29 +00:00
|
|
|
fp = lookup(imagename);
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
if (fp == NULL) {
|
|
|
|
/*
|
|
|
|
* It is ok for the lookup to fail; this can happen
|
|
|
|
* when a module is unloaded on last reference and the
|
2016-11-08 23:59:41 +00:00
|
|
|
* module unload handler unregister's each of its
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
* firmware images.
|
|
|
|
*/
|
|
|
|
err = 0;
|
|
|
|
} else if (fp->refcnt != 0) { /* cannot unregister */
|
|
|
|
err = EBUSY;
|
2012-04-13 04:22:42 +00:00
|
|
|
} else {
|
2020-06-10 23:52:29 +00:00
|
|
|
LIST_REMOVE(fp, link);
|
|
|
|
free(__DECONST(char *, fp->fw.name), M_FIRMWARE);
|
|
|
|
free(fp, M_FIRMWARE);
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
err = 0;
|
2006-01-29 02:52:42 +00:00
|
|
|
}
|
|
|
|
mtx_unlock(&firmware_mtx);
|
2020-06-10 23:52:29 +00:00
|
|
|
return (err);
|
2006-01-29 02:52:42 +00:00
|
|
|
}
|
|
|
|
|
2021-01-25 22:41:50 +00:00
|
|
|
struct fw_loadimage {
|
|
|
|
const char *imagename;
|
|
|
|
uint32_t flags;
|
|
|
|
};
|
|
|
|
|
2024-02-29 16:36:20 +00:00
|
|
|
static const char *fw_path = "/boot/firmware/";
|
|
|
|
|
|
|
|
static void
|
|
|
|
try_binary_file(const char *imagename, uint32_t flags)
|
|
|
|
{
|
|
|
|
struct nameidata nd;
|
|
|
|
struct thread *td = curthread;
|
|
|
|
struct ucred *cred = td ? td->td_ucred : NULL;
|
|
|
|
struct sbuf *sb;
|
|
|
|
struct priv_fw *fp;
|
|
|
|
const char *fn;
|
|
|
|
struct vattr vattr;
|
|
|
|
void *data = NULL;
|
|
|
|
const struct firmware *fw;
|
2024-02-29 17:53:05 +00:00
|
|
|
int oflags;
|
2024-02-29 16:36:20 +00:00
|
|
|
size_t resid;
|
|
|
|
int error;
|
|
|
|
bool warn = flags & FIRMWARE_GET_NOWARN;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX TODO: Loop over some path instead of a single element path.
|
|
|
|
* and fetch this path from the 'firmware_path' kenv the loader sets.
|
|
|
|
*/
|
|
|
|
sb = sbuf_new_auto();
|
|
|
|
sbuf_printf(sb, "%s%s", fw_path, imagename);
|
|
|
|
sbuf_finish(sb);
|
|
|
|
fn = sbuf_data(sb);
|
|
|
|
if (bootverbose)
|
|
|
|
printf("Trying to load binary firmware from %s\n", fn);
|
|
|
|
|
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, fn);
|
2024-02-29 17:53:05 +00:00
|
|
|
oflags = FREAD;
|
|
|
|
error = vn_open(&nd, &oflags, 0, NULL);
|
2024-02-29 16:36:20 +00:00
|
|
|
if (error)
|
|
|
|
goto err;
|
|
|
|
NDFREE_PNBUF(&nd);
|
|
|
|
if (nd.ni_vp->v_type != VREG)
|
|
|
|
goto err2;
|
|
|
|
error = VOP_GETATTR(nd.ni_vp, &vattr, cred);
|
|
|
|
if (error)
|
|
|
|
goto err2;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Limit this to something sane, 8MB by default.
|
|
|
|
*/
|
|
|
|
if (vattr.va_size > firmware_max_size) {
|
2024-02-29 17:53:05 +00:00
|
|
|
printf("Firmware %s is too big: %lld bytes, %ld bytes max.\n",
|
|
|
|
fn, (long long)vattr.va_size, (long)firmware_max_size);
|
2024-02-29 16:36:20 +00:00
|
|
|
goto err2;
|
|
|
|
}
|
|
|
|
data = malloc(vattr.va_size, M_FIRMWARE, M_WAITOK);
|
|
|
|
error = vn_rdwr(UIO_READ, nd.ni_vp, (caddr_t)data, vattr.va_size, 0,
|
|
|
|
UIO_SYSSPACE, IO_NODELOCKED, cred, NOCRED, &resid, td);
|
|
|
|
/* XXX make data read only? */
|
|
|
|
VOP_UNLOCK(nd.ni_vp);
|
|
|
|
vn_close(nd.ni_vp, FREAD, cred, td);
|
|
|
|
nd.ni_vp = NULL;
|
|
|
|
if (error != 0 || resid != 0)
|
|
|
|
goto err;
|
|
|
|
fw = firmware_register(fn, data, vattr.va_size, 0, NULL);
|
|
|
|
if (fw == NULL)
|
|
|
|
goto err;
|
|
|
|
fp = PRIV_FW(fw);
|
|
|
|
fp->flags |= FW_BINARY;
|
|
|
|
if (bootverbose)
|
|
|
|
printf("%s: Loaded binary firmware using %s\n", imagename, fn);
|
|
|
|
sbuf_delete(sb);
|
|
|
|
return;
|
|
|
|
|
|
|
|
err2: /* cleanup in vn_open through vn_close */
|
|
|
|
VOP_UNLOCK(nd.ni_vp);
|
|
|
|
vn_close(nd.ni_vp, FREAD, cred, td);
|
|
|
|
err:
|
|
|
|
free(data, M_FIRMWARE);
|
|
|
|
if (bootverbose || warn)
|
|
|
|
printf("%s: could not load binary firmware %s either\n", imagename, fn);
|
|
|
|
sbuf_delete(sb);
|
|
|
|
}
|
|
|
|
|
2008-04-09 19:07:48 +00:00
|
|
|
static void
|
2021-01-25 22:41:50 +00:00
|
|
|
loadimage(void *arg, int npending __unused)
|
2008-04-09 19:07:48 +00:00
|
|
|
{
|
2021-01-25 22:41:50 +00:00
|
|
|
struct fw_loadimage *fwli = arg;
|
2008-04-09 19:07:48 +00:00
|
|
|
struct priv_fw *fp;
|
|
|
|
linker_file_t result;
|
|
|
|
int error;
|
|
|
|
|
2021-01-25 22:41:50 +00:00
|
|
|
error = linker_reference_module(fwli->imagename, NULL, &result);
|
2008-04-09 19:07:48 +00:00
|
|
|
if (error != 0) {
|
2021-01-25 22:41:50 +00:00
|
|
|
if (bootverbose || (fwli->flags & FIRMWARE_GET_NOWARN) == 0)
|
|
|
|
printf("%s: could not load firmware image, error %d\n",
|
|
|
|
fwli->imagename, error);
|
2024-02-29 16:36:20 +00:00
|
|
|
try_binary_file(fwli->imagename, fwli->flags);
|
2020-06-10 23:52:29 +00:00
|
|
|
mtx_lock(&firmware_mtx);
|
2008-04-09 19:07:48 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
mtx_lock(&firmware_mtx);
|
2021-01-25 22:41:50 +00:00
|
|
|
fp = lookup(fwli->imagename);
|
2008-04-09 19:07:48 +00:00
|
|
|
if (fp == NULL || fp->file != NULL) {
|
|
|
|
mtx_unlock(&firmware_mtx);
|
|
|
|
if (fp == NULL)
|
|
|
|
printf("%s: firmware image loaded, "
|
2021-01-25 22:41:50 +00:00
|
|
|
"but did not register\n", fwli->imagename);
|
|
|
|
(void) linker_release_module(fwli->imagename, NULL, NULL);
|
2020-06-10 23:52:29 +00:00
|
|
|
mtx_lock(&firmware_mtx);
|
2008-04-09 19:07:48 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
fp->file = result; /* record the module identity */
|
|
|
|
done:
|
2021-01-25 22:41:50 +00:00
|
|
|
wakeup_one(arg);
|
2020-06-10 23:52:29 +00:00
|
|
|
mtx_unlock(&firmware_mtx);
|
2008-04-09 19:07:48 +00:00
|
|
|
}
|
|
|
|
|
2006-01-29 02:52:42 +00:00
|
|
|
/*
|
|
|
|
* Lookup and potentially load the specified firmware image.
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
* If the firmware is not found in the registry, try to load a kernel
|
|
|
|
* module named as the image name.
|
|
|
|
* If the firmware is located, a reference is returned. The caller must
|
|
|
|
* release this reference for the image to be eligible for removal/unload.
|
2006-01-29 02:52:42 +00:00
|
|
|
*/
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
const struct firmware *
|
2021-01-25 22:41:50 +00:00
|
|
|
firmware_get_flags(const char *imagename, uint32_t flags)
|
2006-01-29 02:52:42 +00:00
|
|
|
{
|
2008-04-09 19:07:48 +00:00
|
|
|
struct task fwload_task;
|
2006-01-29 02:52:42 +00:00
|
|
|
struct thread *td;
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
struct priv_fw *fp;
|
2006-01-29 02:52:42 +00:00
|
|
|
|
|
|
|
mtx_lock(&firmware_mtx);
|
2020-06-10 23:52:29 +00:00
|
|
|
fp = lookup(imagename);
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
if (fp != NULL)
|
|
|
|
goto found;
|
2006-01-29 02:52:42 +00:00
|
|
|
/*
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
* Image not present, try to load the module holding it.
|
2006-01-29 02:52:42 +00:00
|
|
|
*/
|
|
|
|
td = curthread;
|
2006-11-06 13:42:10 +00:00
|
|
|
if (priv_check(td, PRIV_FIRMWARE_LOAD) != 0 ||
|
|
|
|
securelevel_gt(td->td_ucred, 0) != 0) {
|
2008-04-09 19:07:48 +00:00
|
|
|
mtx_unlock(&firmware_mtx);
|
2006-01-29 02:52:42 +00:00
|
|
|
printf("%s: insufficient privileges to "
|
|
|
|
"load firmware image %s\n", __func__, imagename);
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-06-10 23:52:29 +00:00
|
|
|
/*
|
2008-04-09 19:07:48 +00:00
|
|
|
* Defer load to a thread with known context. linker_reference_module
|
|
|
|
* may do filesystem i/o which requires root & current dirs, etc.
|
|
|
|
* Also we must not hold any mtx's over this call which is problematic.
|
|
|
|
*/
|
2008-11-11 12:25:08 +00:00
|
|
|
if (!cold) {
|
2021-01-25 22:41:50 +00:00
|
|
|
struct fw_loadimage fwli;
|
|
|
|
|
|
|
|
fwli.imagename = imagename;
|
|
|
|
fwli.flags = flags;
|
|
|
|
TASK_INIT(&fwload_task, 0, loadimage, (void *)&fwli);
|
2008-11-11 12:25:08 +00:00
|
|
|
taskqueue_enqueue(firmware_tq, &fwload_task);
|
2021-01-25 22:41:50 +00:00
|
|
|
PHOLD(curproc);
|
|
|
|
msleep((void *)&fwli, &firmware_mtx, 0, "fwload", 0);
|
|
|
|
PRELE(curproc);
|
2008-11-11 12:25:08 +00:00
|
|
|
}
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
/*
|
2008-04-09 19:07:48 +00:00
|
|
|
* After attempting to load the module, see if the image is registered.
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
*/
|
2020-06-10 23:52:29 +00:00
|
|
|
fp = lookup(imagename);
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
if (fp == NULL) {
|
2006-01-29 02:52:42 +00:00
|
|
|
mtx_unlock(&firmware_mtx);
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
return NULL;
|
2006-01-29 02:52:42 +00:00
|
|
|
}
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
found: /* common exit point on success */
|
2011-11-19 00:20:28 +00:00
|
|
|
if (fp->refcnt == 0 && fp->parent != NULL)
|
|
|
|
fp->parent->refcnt++;
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
fp->refcnt++;
|
2006-01-29 02:52:42 +00:00
|
|
|
mtx_unlock(&firmware_mtx);
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
return &fp->fw;
|
2006-01-29 02:52:42 +00:00
|
|
|
}
|
|
|
|
|
2021-01-25 22:41:50 +00:00
|
|
|
const struct firmware *
|
|
|
|
firmware_get(const char *imagename)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (firmware_get_flags(imagename, 0));
|
|
|
|
}
|
|
|
|
|
2006-01-29 02:52:42 +00:00
|
|
|
/*
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
* Release a reference to a firmware image returned by firmware_get.
|
|
|
|
* The caller may specify, with the FIRMWARE_UNLOAD flag, its desire
|
|
|
|
* to release the resource, but the flag is only advisory.
|
|
|
|
*
|
|
|
|
* If this is the last reference to the firmware image, and this is an
|
2008-04-09 19:07:48 +00:00
|
|
|
* autoloaded module, wake up the firmware_unload_task to figure out
|
|
|
|
* what to do with the associated module.
|
2006-01-29 02:52:42 +00:00
|
|
|
*/
|
|
|
|
void
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
firmware_put(const struct firmware *p, int flags)
|
2006-01-29 02:52:42 +00:00
|
|
|
{
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
struct priv_fw *fp = PRIV_FW(p);
|
|
|
|
|
2006-01-29 02:52:42 +00:00
|
|
|
mtx_lock(&firmware_mtx);
|
|
|
|
fp->refcnt--;
|
2006-06-10 17:04:07 +00:00
|
|
|
if (fp->refcnt == 0) {
|
2011-11-19 00:20:28 +00:00
|
|
|
if (fp->parent != NULL)
|
|
|
|
fp->parent->refcnt--;
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
if (flags & FIRMWARE_UNLOAD)
|
|
|
|
fp->flags |= FW_UNLOAD;
|
|
|
|
if (fp->file)
|
2008-04-09 19:07:48 +00:00
|
|
|
taskqueue_enqueue(firmware_tq, &firmware_unload_task);
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
}
|
|
|
|
mtx_unlock(&firmware_mtx);
|
|
|
|
}
|
|
|
|
|
2008-04-09 19:07:48 +00:00
|
|
|
/*
|
|
|
|
* Setup directory state for the firmware_tq thread so we can do i/o.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_rootvnode(void *arg, int npending)
|
|
|
|
{
|
|
|
|
|
2015-07-11 16:22:48 +00:00
|
|
|
pwd_ensure_dirs();
|
2008-10-04 23:58:02 +00:00
|
|
|
free(arg, M_TEMP);
|
2008-04-09 19:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Event handler called on mounting of /; bounce a task
|
|
|
|
* into the task queue thread to setup it's directories.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
firmware_mountroot(void *arg)
|
|
|
|
{
|
2008-10-04 23:58:02 +00:00
|
|
|
struct task *setroot_task;
|
|
|
|
|
|
|
|
setroot_task = malloc(sizeof(struct task), M_TEMP, M_NOWAIT);
|
|
|
|
if (setroot_task != NULL) {
|
|
|
|
TASK_INIT(setroot_task, 0, set_rootvnode, setroot_task);
|
|
|
|
taskqueue_enqueue(firmware_tq, setroot_task);
|
|
|
|
} else
|
|
|
|
printf("%s: no memory for task!\n", __func__);
|
2008-04-09 19:07:48 +00:00
|
|
|
}
|
|
|
|
EVENTHANDLER_DEFINE(mountroot, firmware_mountroot, NULL, 0);
|
|
|
|
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
/*
|
|
|
|
* The body of the task in charge of unloading autoloaded modules
|
|
|
|
* that are not needed anymore.
|
|
|
|
* Images can be cross-linked so we may need to make multiple passes,
|
|
|
|
* but the time we spend in the loop is bounded because we clear entries
|
|
|
|
* as we touch them.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
unloadentry(void *unused1, int unused2)
|
|
|
|
{
|
2024-02-29 16:36:20 +00:00
|
|
|
struct priv_fw *fp, *tmp;
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
|
|
|
|
mtx_lock(&firmware_mtx);
|
2020-06-10 23:52:29 +00:00
|
|
|
restart:
|
2024-02-29 16:36:20 +00:00
|
|
|
LIST_FOREACH_SAFE(fp, &firmware_table, link, tmp) {
|
|
|
|
if (((fp->flags & FW_BINARY) == 0 && fp->file == NULL) ||
|
|
|
|
fp->refcnt != 0 || (fp->flags & FW_UNLOAD) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we directly loaded the firmware, then we just need to
|
|
|
|
* remove the entry from the list and free the entry and go to
|
|
|
|
* the next one. There's no need for the indirection of the kld
|
|
|
|
* module case, we free memory and go to the next one.
|
|
|
|
*/
|
|
|
|
if ((fp->flags & FW_BINARY) != 0) {
|
|
|
|
LIST_REMOVE(fp, link);
|
|
|
|
free(__DECONST(char *, fp->fw.data), M_FIRMWARE);
|
|
|
|
free(__DECONST(char *, fp->fw.name), M_FIRMWARE);
|
|
|
|
free(fp, M_FIRMWARE);
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
continue;
|
2024-02-29 16:36:20 +00:00
|
|
|
}
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
|
|
|
|
/*
|
2024-02-29 16:36:20 +00:00
|
|
|
* Found an entry. This is the kld case, so we have a more
|
|
|
|
* complex dance. Now:
|
2020-06-10 23:52:29 +00:00
|
|
|
* 1. make sure we scan the table again
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
* 2. clear FW_UNLOAD so we don't try this entry again.
|
|
|
|
* 3. release the lock while trying to unload the module.
|
|
|
|
*/
|
|
|
|
fp->flags &= ~FW_UNLOAD; /* do not try again */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We rely on the module to call firmware_unregister()
|
2020-06-10 23:52:29 +00:00
|
|
|
* on unload to actually free the entry.
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
*/
|
2020-06-10 23:52:29 +00:00
|
|
|
mtx_unlock(&firmware_mtx);
|
2021-10-21 17:40:24 +00:00
|
|
|
(void)linker_release_module(NULL, NULL, fp->file);
|
2020-06-10 23:52:29 +00:00
|
|
|
mtx_lock(&firmware_mtx);
|
2020-06-29 21:35:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* When we dropped the lock, another thread could have
|
|
|
|
* removed an element, so we must restart the scan.
|
|
|
|
*/
|
2020-06-10 23:52:29 +00:00
|
|
|
goto restart;
|
2006-06-10 17:04:07 +00:00
|
|
|
}
|
2006-01-29 02:52:42 +00:00
|
|
|
mtx_unlock(&firmware_mtx);
|
|
|
|
}
|
|
|
|
|
2024-02-29 16:36:31 +00:00
|
|
|
/*
|
|
|
|
* Find all the binary firmware that was loaded in the boot loader via load -t
|
|
|
|
* firmware foo. There is only one firmware per file, it's the whole file, and
|
|
|
|
* there's no meaningful version passed in, so pass 0 for that. If version is
|
|
|
|
* needed by the consumer (and not just arbitrarily defined), the .ko version
|
|
|
|
* must be used instead.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
firmware_binary_files(void)
|
|
|
|
{
|
|
|
|
caddr_t file;
|
|
|
|
char *name;
|
|
|
|
const char *type;
|
|
|
|
const void *addr;
|
|
|
|
size_t size;
|
|
|
|
unsigned int version = 0;
|
|
|
|
const struct firmware *fw;
|
|
|
|
struct priv_fw *fp;
|
|
|
|
|
|
|
|
file = 0;
|
|
|
|
for (;;) {
|
|
|
|
file = preload_search_next_name(file);
|
|
|
|
if (file == 0)
|
|
|
|
break;
|
|
|
|
type = (const char *)preload_search_info(file, MODINFO_TYPE);
|
|
|
|
if (type == NULL || strcmp(type, "firmware") != 0)
|
|
|
|
continue;
|
|
|
|
name = preload_search_info(file, MODINFO_NAME);
|
|
|
|
addr = preload_fetch_addr(file);
|
|
|
|
size = preload_fetch_size(file);
|
|
|
|
fw = firmware_register(name, addr, size, version, NULL);
|
|
|
|
fp = PRIV_FW(fw);
|
|
|
|
fp->refcnt++; /* Hold an extra reference so we never unload */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-29 02:52:42 +00:00
|
|
|
/*
|
|
|
|
* Module glue.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
firmware_modevent(module_t mod, int type, void *unused)
|
|
|
|
{
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
struct priv_fw *fp;
|
2020-06-10 23:52:29 +00:00
|
|
|
int err;
|
2006-06-10 17:04:07 +00:00
|
|
|
|
2020-06-10 23:52:29 +00:00
|
|
|
err = 0;
|
2006-01-29 02:52:42 +00:00
|
|
|
switch (type) {
|
|
|
|
case MOD_LOAD:
|
2008-04-09 19:07:48 +00:00
|
|
|
TASK_INIT(&firmware_unload_task, 0, unloadentry, NULL);
|
|
|
|
firmware_tq = taskqueue_create("taskqueue_firmware", M_WAITOK,
|
|
|
|
taskqueue_thread_enqueue, &firmware_tq);
|
|
|
|
/* NB: use our own loop routine that sets up context */
|
|
|
|
(void) taskqueue_start_threads(&firmware_tq, 1, PWAIT,
|
|
|
|
"firmware taskq");
|
2024-02-29 16:36:31 +00:00
|
|
|
firmware_binary_files();
|
2008-04-09 19:07:48 +00:00
|
|
|
if (rootvnode != NULL) {
|
2020-06-10 23:52:29 +00:00
|
|
|
/*
|
2008-04-09 19:07:48 +00:00
|
|
|
* Root is already mounted so we won't get an event;
|
|
|
|
* simulate one here.
|
|
|
|
*/
|
|
|
|
firmware_mountroot(NULL);
|
|
|
|
}
|
2020-06-10 23:52:29 +00:00
|
|
|
break;
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
|
2006-01-29 02:52:42 +00:00
|
|
|
case MOD_UNLOAD:
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
/* request all autoloaded modules to be released */
|
|
|
|
mtx_lock(&firmware_mtx);
|
2020-06-10 23:52:29 +00:00
|
|
|
LIST_FOREACH(fp, &firmware_table, link)
|
2010-01-07 21:01:37 +00:00
|
|
|
fp->flags |= FW_UNLOAD;
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
mtx_unlock(&firmware_mtx);
|
2008-04-09 19:07:48 +00:00
|
|
|
taskqueue_enqueue(firmware_tq, &firmware_unload_task);
|
|
|
|
taskqueue_drain(firmware_tq, &firmware_unload_task);
|
2020-06-10 23:52:29 +00:00
|
|
|
|
|
|
|
LIST_FOREACH(fp, &firmware_table, link) {
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
if (fp->fw.name != NULL) {
|
2020-06-10 23:52:29 +00:00
|
|
|
printf("%s: image %s still active, %d refs\n",
|
|
|
|
__func__, fp->fw.name, fp->refcnt);
|
Cleanup and document the implementation of firmware(9) based on
a version that i posted earlier on the -current mailing list,
and subsequent feedback received.
The core of the change is just in sys/firmware.h and kern/subr_firmware.c,
while other files are just adaptation of the clients to the ABI change
(const-ification of some parameters and hiding of internal info,
so this is fully compatible at the binary level).
In detail:
- reduce the amount of information exported to clients in struct firmware,
and constify the pointer;
- internally, document and simplify the implementation of the various
functions, and make sure error conditions are dealt with properly.
The diffs are large, but the code is really straightforward now (i hope).
Note also that there is a subtle issue with the implementation of
firmware_register(): currently, as in the previous version, we just
store a reference to the 'imagename' argument, but we should rather
copy it because there is no guarantee that this is a static string.
I realised this while testing this code, but i prefer to fix it in
a later commit -- there is no regression with respect to the past.
Note, too, that the version in RELENG_6 has various bugs including
missing locks around the module release calls, mishandling of modules
loaded by /boot/loader, and so on, so an MFC is absolutely necessary
there. I was just postponing it until this cleanup to avoid doing
things twice.
MFC after: 1 week
2007-02-15 17:21:31 +00:00
|
|
|
err = EINVAL;
|
|
|
|
}
|
|
|
|
}
|
2008-04-09 19:07:48 +00:00
|
|
|
if (err == 0)
|
|
|
|
taskqueue_free(firmware_tq);
|
2020-06-10 23:52:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
err = EOPNOTSUPP;
|
|
|
|
break;
|
2006-01-29 02:52:42 +00:00
|
|
|
}
|
2020-06-10 23:52:29 +00:00
|
|
|
return (err);
|
2006-01-29 02:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static moduledata_t firmware_mod = {
|
|
|
|
"firmware",
|
|
|
|
firmware_modevent,
|
2009-02-03 07:51:11 +00:00
|
|
|
NULL
|
2006-01-29 02:52:42 +00:00
|
|
|
};
|
|
|
|
DECLARE_MODULE(firmware, firmware_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
|
|
|
|
MODULE_VERSION(firmware, 1);
|