#!/bin/sh


pci_parity_ctrl ()
{
	local parity_cmd;
	local pdev;
	local IDS;
	local verbosity=${2:-1}


	IDS=`lspci | cut -d' ' -f1`

	if [ -z $1 ]; then
		echo "Displaying System PCI Parity Configuration";
		echo "=========================================="
		echo
		lspci -vvv | grep Parity
		echo
		echo "=========================================="
		return
	fi
	
	parity_cmd=${1:-"off"}

	if [ $parity_cmd != "on" ]; then
		parity_cmd="off";
	fi

	eval "type setpci 2> /dev/null > /dev/null"
	if [ $? -ne 0 ]; then
		echo "Parity Set Error: setpci utility not found!"
		return
	fi

	if [ $verbosity -gt 0 ]; then
		echo "Setting PCI Parity to $parity_cmd";
	fi

	for pdev in $IDS
	do
		if [ "$parity_cmd" = "on" ]; then
			eval "setpci -s $pdev 3e.b=0x7"
		else
			eval "setpci -s $pdev 3e.b=0x4"
		fi

	done

	return
}

CMD=${1:-off}
pci_parity_ctrl $1
