fwupd/plugins/thunderbolt/fu-plugin-thunderbolt.c
Richard Hughes e87fc05ab9 Speed up the daemon startup by ~2% by doing dlsym much less
We were calling g_module_symbol() 2703 times, which is actually more
expensive than you'd think.

It also means the plugins are actually what we tell people they are:
A set of vfuncs that get run. The reality before that they were dlsym'd
functions that get called at pretty random times.
2021-11-09 12:02:07 +00:00

79 lines
2.4 KiB
C

/*
* Copyright (C) 2017 Christian J. Kellner <christian@kellner.me>
*
* SPDX-License-Identifier: LGPL-2.1+
*/
#include "config.h"
#include <fwupdplugin.h>
#include "fu-thunderbolt-device.h"
#include "fu-thunderbolt-firmware-update.h"
#include "fu-thunderbolt-firmware.h"
static gboolean
fu_plugin_thunderbolt_safe_kernel(FuPlugin *plugin, GError **error)
{
g_autofree gchar *minimum_kernel = NULL;
minimum_kernel = fu_plugin_get_config_value(plugin, "MinimumKernelVersion");
if (minimum_kernel == NULL) {
g_debug("Ignoring kernel safety checks");
return TRUE;
}
return fu_common_check_kernel_version(minimum_kernel, error);
}
static gboolean
fu_plugin_thunderbolt_device_created(FuPlugin *plugin, FuDevice *dev, GError **error)
{
FuContext *ctx = fu_plugin_get_context(plugin);
fu_plugin_add_rule(plugin,
FU_PLUGIN_RULE_INHIBITS_IDLE,
"thunderbolt requires device wakeup");
fu_device_set_context(dev, ctx);
return TRUE;
}
static void
fu_plugin_thunderbolt_device_registered(FuPlugin *plugin, FuDevice *device)
{
if (g_strcmp0(fu_device_get_plugin(device), "thunderbolt") != 0)
return;
/* Operating system will handle finishing updates later */
if (fu_plugin_get_config_value_boolean(plugin, "DelayedActivation") &&
!fu_device_has_flag(device, FWUPD_DEVICE_FLAG_USABLE_DURING_UPDATE)) {
g_debug("Turning on delayed activation for %s", fu_device_get_name(device));
fu_device_add_flag(device, FWUPD_DEVICE_FLAG_USABLE_DURING_UPDATE);
fu_device_add_flag(device, FWUPD_DEVICE_FLAG_SKIPS_RESTART);
fu_device_remove_internal_flag(device, FU_DEVICE_INTERNAL_FLAG_REPLUG_MATCH_GUID);
}
}
static void
fu_plugin_thunderbolt_init(FuPlugin *plugin)
{
fu_plugin_add_udev_subsystem(plugin, "thunderbolt");
fu_plugin_add_device_gtype(plugin, FU_TYPE_THUNDERBOLT_DEVICE);
fu_plugin_add_firmware_gtype(plugin, NULL, FU_TYPE_THUNDERBOLT_FIRMWARE);
fu_plugin_add_firmware_gtype(plugin, NULL, FU_TYPE_THUNDERBOLT_FIRMWARE_UPDATE);
}
static gboolean
fu_plugin_thunderbolt_startup(FuPlugin *plugin, GError **error)
{
return fu_plugin_thunderbolt_safe_kernel(plugin, error);
}
void
fu_plugin_init_vfuncs(FuPluginVfuncs *vfuncs)
{
vfuncs->build_hash = FU_BUILD_HASH;
vfuncs->init = fu_plugin_thunderbolt_init;
vfuncs->startup = fu_plugin_thunderbolt_startup;
vfuncs->device_registered = fu_plugin_thunderbolt_device_registered;
vfuncs->device_created = fu_plugin_thunderbolt_device_created;
}