1726
static int is_laptop (void) {
1727
/* We only support laptops by default,
1728
* you can override this check by creating
1729
* the /etc/force-pxpress file
1704
/* Count the number of outputs connected to the card */
1705
int count_connected_outputs(int fd, drmModeResPtr res) {
1707
int connected_outputs = 0;
1708
drmModeConnectorPtr connector;
1710
for (i = 0; i < res->count_connectors; i++) {
1711
connector = drmModeGetConnector(fd, res->connectors[i]);
1714
switch (connector->connection) {
1715
case DRM_MODE_CONNECTED:
1716
fprintf(log_handle, "output %d:\n", connected_outputs);
1717
connected_outputs += 1;
1719
switch (connector->connector_type) {
1720
case DRM_MODE_CONNECTOR_Unknown:
1721
fprintf(log_handle, "\tunknown connector\n");
1723
case DRM_MODE_CONNECTOR_VGA:
1724
fprintf(log_handle, "\tVGA connector\n");
1726
case DRM_MODE_CONNECTOR_DVII:
1727
fprintf(log_handle, "\tDVII connector\n");
1729
case DRM_MODE_CONNECTOR_DVID:
1730
fprintf(log_handle, "\tDVID connector\n");
1732
case DRM_MODE_CONNECTOR_DVIA:
1733
fprintf(log_handle, "\tDVIA connector\n");
1735
case DRM_MODE_CONNECTOR_Composite:
1736
fprintf(log_handle, "\tComposite connector\n");
1738
case DRM_MODE_CONNECTOR_SVIDEO:
1739
fprintf(log_handle, "\tSVIDEO connector\n");
1741
case DRM_MODE_CONNECTOR_LVDS:
1742
fprintf(log_handle, "\tLVDS connector\n");
1744
case DRM_MODE_CONNECTOR_Component:
1745
fprintf(log_handle, "\tComponent connector\n");
1747
case DRM_MODE_CONNECTOR_9PinDIN:
1748
fprintf(log_handle, "\t9PinDIN connector\n");
1750
case DRM_MODE_CONNECTOR_DisplayPort:
1751
fprintf(log_handle, "\tDisplayPort connector\n");
1753
case DRM_MODE_CONNECTOR_HDMIA:
1754
fprintf(log_handle, "\tHDMIA connector\n");
1756
case DRM_MODE_CONNECTOR_HDMIB:
1757
fprintf(log_handle, "\tHDMIB connector\n");
1759
case DRM_MODE_CONNECTOR_TV:
1760
fprintf(log_handle, "\tTV connector\n");
1762
case DRM_MODE_CONNECTOR_eDP:
1763
fprintf(log_handle, "\teDP connector\n");
1766
case DRM_MODE_CONNECTOR_VIRTUAL:
1767
fprintf(log_handle, "VIRTUAL connector\n");
1769
case DRM_MODE_CONNECTOR_DSI:
1770
fprintf(log_handle, "DSI connector\n");
1779
case DRM_MODE_DISCONNECTED:
1784
drmModeFreeConnector(connector);
1787
return connected_outputs;
1791
/* See if the drm device created by a driver has any connected outputs. */
1792
static int has_driver_connected_outputs(const char *driver) {
1796
drmVersionPtr version;
1797
int connected_outputs = 0;
1798
int driver_match = 0;
1801
/* Keep looking until we find the device for the driver */
1802
for (it = 0; fd != -1; it++) {
1803
sprintf(path, "/dev/dri/card%d", it);
1804
fd = open(path, O_RDWR);
1806
if ((version = drmGetVersion(fd))) {
1807
/* Let's use strstr to catch the different backported
1810
if (driver && strstr(version->name, driver) != NULL) {
1811
fprintf(log_handle, "Found \"%s\", driven by \"%s\"\n",
1812
path, version->name);
1814
drmFreeVersion(version);
1818
fprintf(log_handle, "Skipping \"%s\", driven by \"%s\"\n",
1819
path, version->name);
1820
drmFreeVersion(version);
1826
fprintf(log_handle, "Error: can't open fd for %s\n", path);
1834
res = drmModeGetResources(fd);
1836
fprintf(log_handle, "Error: can't get drm resources.\n");
1842
connected_outputs = count_connected_outputs(fd, res);
1844
fprintf(log_handle, "Number of connected outputs for %s: %d\n", path, connected_outputs);
1846
drmModeFreeResources(res);
1850
return (connected_outputs > 0);
1854
/* Check if any outputs are still connected to card0.
1856
* By default we only check cards driver by i915.
1857
* If so, then claim support for RandR offloading
1859
static int requires_offloading(void) {
1861
/* Let's check only /dev/dri/card0 and look
1862
* for driver i915. We don't want to enable
1863
* offloading to any other driver, as results
1864
* may be unpredictable
1731
if (is_file(FORCE_LAPTOP)) {
1732
fprintf(log_handle, "Forcing laptop mode as per %s\n", FORCE_LAPTOP);
1736
if (! is_dir_empty("/sys/class/power_supply/") &&
1737
is_dir("/proc/acpi/button/lid"))
1866
return(has_driver_connected_outputs("i915"));
1870
/* Set permanent settings for offloading */
1871
static int set_offloading(void) {
1877
file = fopen(OFFLOADING_CONF, "w");
1879
fprintf(file, "ON\n");
2109
2253
/* These options set a flag. */
2110
2254
{"dry-run", no_argument, &dry_run, 1},
2111
{"fake-laptop", no_argument, &fake_laptop, 1},
2112
{"fake-desktop", no_argument, &fake_laptop, 0},
2255
{"fake-requires-offloading", no_argument, &fake_offloading, 1},
2256
{"fake-no-requires-offloading", no_argument, &fake_offloading, 0},
2113
2257
{"fake-lightdm", no_argument, &fake_lightdm, 1},
2114
2258
/* These options don't set a flag.
2115
2259
We distinguish them by their indices. */
2711
2865
if (boot_vga_vendor_id == INTEL) {
2712
2866
fprintf(log_handle, "Intel IGP detected\n");
2713
2867
/* AMD PowerXpress */
2714
if (laptop && intel_loaded && fglrx_loaded && !radeon_loaded) {
2868
if (offloading && intel_loaded && fglrx_loaded && !radeon_loaded) {
2715
2869
fprintf(log_handle, "PowerXpress detected\n");
2717
2871
enable_pxpress(current_devices, cards_n);
2719
2873
/* NVIDIA Optimus */
2720
else if (laptop && (intel_loaded && !nouveau_loaded &&
2874
else if (offloading && (intel_loaded && !nouveau_loaded &&
2721
2875
(alternative->nvidia_available ||
2722
2876
alternative->prime_available) &&
2723
2877
nvidia_loaded)) {
2724
fprintf(log_handle, "Intel hybrid laptop\n");
2878
fprintf(log_handle, "Intel hybrid system\n");
2726
2880
enable_prime(prime_settings, bbswitch_loaded,
2727
2881
discrete_vendor_id, alternative,
2728
2882
current_devices, cards_n);
2884
/* Write permanent settings about offloading */