Skip to content

Commit

Permalink
Add PCI Bus ID detection for AMD video cards (GH-52)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lekensteyn committed Oct 5, 2012
1 parent e7626e9 commit cf2c83e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
7 changes: 7 additions & 0 deletions src/bbconfig.h
Expand Up @@ -104,6 +104,12 @@ const char *bb_pm_method_string[PM_METHODS_COUNT];
/* String buffer size */
#define BUFFER_SIZE 1024

enum card_type {
CARD_UNKNOWN,
CARD_NVIDIA,
CARD_ATI,
};

/* Structure containing the status of the application */
struct bb_status_struct {
enum verbosity_level verbosity; ///Verbosity level of messages.
Expand All @@ -115,6 +121,7 @@ struct bb_status_struct {
int x_pipe[2];//pipes for reading/writing output from X's stdout/stderr
gboolean use_syslog;
char *program_name;
enum card_type card_type;
};

/* Structure containing the configuration. */
Expand Down
55 changes: 37 additions & 18 deletions src/bumblebeed.c
Expand Up @@ -458,30 +458,49 @@ int main(int argc, char* argv[]) {
init_config();
bbconfig_parse_opts(argc, argv, PARSE_STAGE_PRECONF);

/* First look for an intel card */
struct pci_bus_id *pci_id_igd = pci_find_gfx_by_vendor(PCI_VENDOR_ID_INTEL, 0);
if (!pci_id_igd) {
/* This is no Optimus configuration. But maybe it's a
dual-nvidia configuration. Let us test that.
*/
pci_id_igd = pci_find_gfx_by_vendor(PCI_VENDOR_ID_NVIDIA, 1);
bb_log(LOG_INFO, "No Intel video card found, testing for dual-nvidia system.\n");

if (!pci_id_igd) {
/* Ok, this is not a double gpu setup supported (there is at most
one nvidia and no intel cards */
bb_log(LOG_ERR, "No integrated video card found, quitting.\n");
return (EXIT_FAILURE);
pci_bus_id_discrete = pci_find_gfx_by_vendor(PCI_VENDOR_ID_NVIDIA, 0);
if (pci_bus_id_discrete) {
bb_status.card_type = CARD_NVIDIA;
} else {
pci_bus_id_discrete = pci_find_gfx_by_vendor(PCI_VENDOR_ID_ATI, 0);
if (pci_bus_id_discrete) {
bb_status.card_type = CARD_ATI;
}
}
pci_bus_id_discrete = pci_find_gfx_by_vendor(PCI_VENDOR_ID_NVIDIA, 0);
if (!pci_bus_id_discrete) {
bb_log(LOG_ERR, "No discrete video card found, quitting\n");
bb_log(LOG_ERR, "No nVidia nor AMD/ATI graphics card found, quitting.\n");
return (EXIT_FAILURE);
}

bb_log(LOG_DEBUG, "Found card: %02x:%02x.%x (discrete)\n", pci_bus_id_discrete->bus, pci_bus_id_discrete->slot, pci_bus_id_discrete->func);
bb_log(LOG_DEBUG, "Found card: %02x:%02x.%x (integrated)\n", pci_id_igd->bus, pci_id_igd->slot, pci_id_igd->func);
struct pci_bus_id *pci_id_igd;
pci_id_igd = pci_find_gfx_by_vendor(PCI_VENDOR_ID_INTEL, 0);
if (!pci_id_igd) {
if (bb_status.card_type == CARD_ATI) {
/* assume the first AMD video card to be integrated */
pci_id_igd = pci_bus_id_discrete;
pci_bus_id_discrete = pci_find_gfx_by_vendor(PCI_VENDOR_ID_ATI, 1);
if (!pci_bus_id_discrete) {
bb_log(LOG_ERR, "No AMD Switchable Graphics detected, quitting.\n");
return (EXIT_FAILURE);
}
} else {
/* maybe it is a nvidia/nvidia setup. Assume the second card to be the
* iGPU (as is the case with MacBook Pro 2009 */
pci_id_igd = pci_find_gfx_by_vendor(PCI_VENDOR_ID_NVIDIA, 1);
if (!pci_id_igd) {
bb_log(LOG_ERR, "No hybrid Nvidia graphics detected, quitting.\n");
return (EXIT_FAILURE);
}
}
}

bb_log(LOG_DEBUG, "Found card: %02x:%02x.%x (discrete %s)\n",
pci_bus_id_discrete->bus, pci_bus_id_discrete->slot,
pci_bus_id_discrete->func,
(bb_status.card_type == CARD_NVIDIA ? "nvidia" :
(bb_status.card_type == CARD_ATI ? "amd" : "unknown")));
bb_log(LOG_DEBUG, "Found card: %02x:%02x.%x (integrated)\n", pci_id_igd->bus,
pci_id_igd->slot, pci_id_igd->func);

free(pci_id_igd);

Expand Down
1 change: 1 addition & 0 deletions src/pci.h
Expand Up @@ -21,6 +21,7 @@
#pragma once
#include <sys/types.h> /* necessary for int32_t */

#define PCI_VENDOR_ID_ATI 0x1002
#define PCI_VENDOR_ID_NVIDIA 0x10de
#define PCI_VENDOR_ID_INTEL 0x8086
#define PCI_CLASS_DISPLAY_VGA 0x0300
Expand Down

0 comments on commit cf2c83e

Please sign in to comment.