Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An option to unload the driver even without active PM method #983

Merged
merged 1 commit into from
Dec 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/bbconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,10 @@ void bbconfig_parse_conf_driver(GKeyFile *bbcfg, char *driver) {
g_free(module_name);
}
}
key = "AlwaysUnloadKernelDriver";
if (g_key_file_has_key(bbcfg, section, key, NULL)) {
bb_config.force_driver_unload = g_key_file_get_boolean(bbcfg, section, key, NULL);
}
key = "LibraryPath";
if (g_key_file_has_key(bbcfg, section, key, NULL)) {
free_and_set_value(&bb_config.ld_path, g_key_file_get_string(bbcfg, section, key, NULL));
Expand Down
1 change: 1 addition & 0 deletions src/bbconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ struct bb_config_struct {
char * module_name; /* Kernel module to be loaded for the driver.
* If empty, driver will be used. This is
* for Ubuntu which uses nvidia-current */
int force_driver_unload; /* Force driver unload, even without active PM method */
int card_shutdown_state;
#ifdef WITH_PIDFILE
char *pid_file; /* pid file for storing the daemons PID */
Expand Down
27 changes: 17 additions & 10 deletions src/bbsecondary.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,24 +225,31 @@ bool start_secondary(bool need_secondary) {
static void switch_and_unload(void)
{
char driver[BUFFER_SIZE];
int unload_driver = 0;

if (bb_config.pm_method == PM_DISABLED && bb_status.runmode != BB_RUN_EXIT) {
if (bb_config.pm_method == PM_DISABLED && !bb_config.force_driver_unload && bb_status.runmode != BB_RUN_EXIT) {
/* do not disable the card if PM is disabled unless exiting */
return;
}

//if card is on and can be switched, switch it off
if (switcher && switcher->need_driver_unloaded) {
/* do not unload the drivers nor disable the card if the card is not on */
if (switcher->status() != SWITCH_ON) {
return;
}
unload_driver = 1;
}

if (unload_driver || bb_config.force_driver_unload) {
/* unload the driver loaded by the graphica card */
if (pci_get_driver(driver, pci_bus_id_discrete, sizeof driver)) {
module_unload(driver);
}
}

if (switcher) {
if (switcher->need_driver_unloaded) {
/* do not unload the drivers nor disable the card if the card is not on */
if (switcher->status() != SWITCH_ON) {
return;
}
/* unload the driver loaded by the graphica card */
if (pci_get_driver(driver, pci_bus_id_discrete, sizeof driver)) {
module_unload(driver);
}

//only turn card off if no drivers are loaded
if (pci_get_driver(NULL, pci_bus_id_discrete, 0)) {
bb_log(LOG_DEBUG, "Drivers are still loaded, unable to disable card\n");
Expand Down