summaryrefslogtreecommitdiffstats
path: root/lib/Xconfig/proprietary.pm
blob: 3fb43cc438688544f6e1ab3dd1c5274cc286bb8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package Xconfig::proprietary; # $Id: proprietary.pm 269741 2010-06-02 09:25:33Z cfergeau $

use diagnostics;
use strict;

use lib qw(/usr/lib/libDrakX); # for perl_checker
use common;
use Xconfig::card;
# perl_checker: require MDK::Common

my $lib = arch() =~ /x86_64/ ? "lib64" : "lib";
my $libdir = "/usr/$lib";

sub install_matrox_hal {
    my ($prefix) = @_;
    my $tmpdir = "$prefix/root/tmp";

    my $tar = "mgadrivers-2.0.tgz";
    my $dir_in_tar = "mgadrivers";
    my $dest_dir = "$prefix/usr/lib/xorg/modules/drivers";

    #- already installed
    return if -e "$dest_dir/mga_hal_drv.o" || $::testing;

    system("wget -O $tmpdir/$tar ftp://ftp.matrox.com/pub/mga/archive/linux/2002/$tar") if !-e "$tmpdir/$tar";
    system("tar xzC $tmpdir -f $tmpdir/$tar");

    my $src_dir = "$tmpdir/$dir_in_tar/xfree86/4.2.1/drivers";
    foreach (all($src_dir)) {
	my $src = "$src_dir/$_";
	my $dest = "$dest_dir/$_";
	rename $dest, "$dest.non_hal";
	cp_af($src, $dest_dir);
    }
    rm_rf("$tmpdir/$tar");
    rm_rf("$tmpdir/$dir_in_tar");
}

sub handle_DRIVER2_NO_SSE {
    my ($card) = @_;

    $card->{DRIVER2_NO_SSE} || $card->{DRIVER2_NEEDS_SSE} or return;

    require detect_devices;
    if (!detect_devices::has_cpu_flag('sse')) {
	my $driver = $card->{DRIVER2_NEEDS_SSE} ? $card->{DRIVER} : $card->{DRIVER2_NO_SSE};
	log::l("$card->{Driver2} need a processor featuring SSE, switching back to $driver");
	$card->{Driver2} = $driver;
    }
}

sub handle_FIRMWARE {
    my ($do_pkgs, $card, $o_in) = @_;

    my $pkg = $card->{FIRMWARE} or return;

    $do_pkgs->is_installed($pkg) || ($do_pkgs->is_available($pkg) && $do_pkgs->install($pkg)) and return;

    if ($card->{DRIVER_NO_FIRMWARE}) {
	log::l("$card->{Driver} need a firmware to work, switching back to $card->{DRIVER_NO_FIRMWARE}");

        # do not show warning if the user selected the proprietary driver
        !$card->{Driver2} and $o_in and $o_in->ask_warn('', N("The free '%s' driver for your graphics card requires a proprietary firmware package '%s' to be installed, but it was not available on the enabled media.\n\nThe basic non-accelerated '%s' driver will be configured instead.\n\nTo enable full graphics support later, enable the 'nonfree' repository section at \"Install and remove software\" and reconfigure the graphics driver by going to \"Set up the graphical server\" at Mageia Control Center and re-selecting your graphics card.", $card->{Driver}, $card->{FIRMWARE}, $card->{DRIVER_NO_FIRMWARE}));

	$card->{Driver} = $card->{DRIVER_NO_FIRMWARE};

    } else {
	log::l("$card->{Driver} needs a firmware to work smoothly/better (eg: 3D, KMS) but will still work");

        # do not show warning if the user selected the proprietary driver
        !$card->{Driver2} and $o_in and $o_in->ask_warn('', N("The free '%s' driver for your graphics card requires a proprietary firmware package '%s' to be installed in order for all features (including 3D acceleration) to work properly, but that package was not available in the enabled media.\n\nTo enable all graphics card features later, enable the 'nonfree' repository section at \"Install and remove software\" and install the firmware package manually or reconfigure your graphics card.", $card->{Driver}, $card->{FIRMWARE}));
    }
}


sub pkgs_for_Driver2 {
    my ($Driver2, $do_pkgs) = @_;

    my ($pkg, $base_name) = $Driver2 =~ /^fglrx|^nvidia/ ?
                            ("x11-driver-video-$Driver2", $Driver2) : () or return;

    $do_pkgs->is_installed($pkg) || $do_pkgs->is_available($pkg) or
      log::l("proprietary package $pkg not available"), return;

    my $module_pkgs = $do_pkgs->check_kernel_module_packages($base_name) or
      log::l("$pkg available, but no kernel module package (for installed kernels, and no dkms)"), return;

    ($pkg, @$module_pkgs);
}

sub may_use_Driver2 {
    my ($card) = @_;

    my $modules_dir = Xconfig::card::modules_dir();
    #- make sure everything is correct at this point, packages have really been installed
    #- and driver and GLX extension is present.

    my $check_drv = sub {
	my ($drv, $o_subdir) = @_;
	my @l = (if_($o_subdir, "$modules_dir/drivers/$o_subdir/$drv.so",
		 "$libdir/$o_subdir/xorg/$drv.so"),
		 "$modules_dir/drivers/$drv.so",
		 "$modules_dir/drivers/$drv.o");
	my $has = find { -e "$::prefix$_" } @l;
	$has or log::l("proprietary $drv driver missing (we searched for: @l)");
	$has;
    };

    my $card2 = { 
	%$card,
	$card->{Driver2} =~ /^(fglrx|nvidia)(.*)/ ?
	  (Driver => $1, DriverVersion => $2) :
	  (Driver => $card->{Driver2}),
    };

    if ($card2->{Driver} eq 'nvidia') {
	$check_drv->('nvidia_drv', "nvidia$card2->{DriverVersion}") or return;

	my $libglx_path = "$libdir/nvidia$card2->{DriverVersion}/xorg";
	-e "$::prefix$libglx_path/libglx.so" or log::l("special NVIDIA libglx missing"), return;

	log::explanations("Using specific NVIDIA driver and GLX extensions");
	$card2->{DRI_GLX_SPECIAL} = 1;
	$card2->{Options}{IgnoreEDID} = 1 if $card2->{DriverVersion} eq "71xx";
	$card2->{Options}{UseEDID} = 0 if $card2->{DriverVersion} eq "96xx";
	$card2;
    } elsif ($card2->{Driver} eq 'fglrx') {
	$check_drv->('fglrx_drv', "fglrx$card2->{DriverVersion}") or return;
        find { -e "$::prefix/$_/dri/fglrx_dri.so" } (
            "$libdir/fglrx$card2->{DriverVersion}", $modules_dir, $libdir) or
	  log::l("proprietary fglrx_dri.so missing"), return;

	log::explanations("Using specific ATI fglrx and DRI drivers");
	$card2->{DRI_GLX} = 1;
	$card2;
    } else {
	undef;
    }
}

1;