#!/usr/bin/perl -w # # Copyright 2003 John Robertson # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # Version 1.0: 2003-04-03 John Robertson # First public release. # # ENABLES BUS MASTERING FOR ALL VIDEO CARDS THAT HAVE IT DISABLED # # The Direct Rendering Infrastructure (DRI) needs bus mastering enabled # to function properly. Unfortunately, this was not being done on my VAIO # laptop, causing the X Server to fail. To solve this problem, this script # was born. # # Thanks to Jean Delvare for his suggestions and help with perl. # use strict; use Text::ParseWords; # From linux/pci.h use constant PCI_COMMAND_MASTER => 0x4; # From linux/pci_ids.h use constant PCI_BASE_CLASS_DISPLAY => 0x3; # Pathnames for pciutils use constant CMD_LSPCI => '/sbin/lspci'; use constant CMD_SETPCI => '/sbin/setpci'; my $pci_bus = `@{[CMD_LSPCI]} -n`; while ($pci_bus =~ /^([\da-f]+:[\da-f]+\.[\da-f]+) Class ([\da-f]+):/mg) { next unless ((hex $2) >> 8) == PCI_BASE_CLASS_DISPLAY; my $dev_name = (shellwords (`@{[CMD_LSPCI]} -s $1 -m`))[3]; chomp (my $cmd_reg = `@{[CMD_SETPCI]} -s $1 command`); $cmd_reg = hex $cmd_reg; if ($cmd_reg & PCI_COMMAND_MASTER) { print "Bus mastering already enabled for $dev_name in slot $1.\n"; } else { print "Enabling bus mastering for $dev_name in slot $1..."; $cmd_reg = sprintf '%04X', $cmd_reg | PCI_COMMAND_MASTER; `@{[CMD_SETPCI]} -s $1 command=$cmd_reg`; print " done.\n"; } }