#!/bin/sh
#ident	"@(#)gfbinit  1.6 02/02/26 SMI"
#
# Copyright (c) 2001 by Sun Microsystems, Inc.
# All rights reserved.

# /etc/rc2.d/S91gfbinit - Solaris  initialization of GFB

PATH=/usr/bin:/bin:/usr/sbin:/sbin

#
# Find out how many GFB cards are installed on the system.
#
gfb_count=`prtconf | grep -c gfb`
if [ ${gfb_count} -eq 0 ]
then
	exit 0
fi		

# 
# Check the $devpath directory for any gfb devices
#
devpath=/dev
test -d /dev/fbs && devpath=/dev/fbs
devs=`/bin/ls $devpath | grep gfb.$`

#
# If there aren't any around, there's no need to load
# the driver, so quit.
#
if [ "$devs" = "" ]
then
        exit 0
fi

#
# We have a gfb, so modload the 32- or 64-bit driver and make sure that it
# was successful.  
# Try to locate the driver in the uname -i directory.  Otherwise look in
# uname -m.
#
isainfo=`isalist`
case "$isainfo" in
	*v9*)	drvdir="drv/sparcv9"
		;;
	*)	drvdir="drv"
		;;
esac

plat=`uname -i`
if [ ! -f /platform/$plat/kernel/$drvdir/gfb ]
then
	plat=`uname -m`
	if [ ! -f /platform/$plat/kernel/$drvdir/gfb ]
	then
		echo "gfbinit: cannot find the gfb driver module."
		exit 1
	fi
fi

err=`modload /platform/$plat/kernel/$drvdir/gfb 2>&1`
if [ $? -ne 0 ]
then
	echo "gfbinit: Problems loading GFB driver: $err"
	exit 1
fi

#
#  ucode download error flag - a non-zero flag means there was a failure
#
err_flag=0


#
#  If we can find the binary, then download the microcode to each
#  instance of the gfb device present in the system.
#
if [ -f /usr/sbin/gfbdaemon ]
then
	#
	#  Now download the microcode to each gfb. Note any failures but
	#  continue to attempt to download ucode to other gfbs.
	#
	for inst in $devs
	do
		/usr/sbin/gfbdaemon -dev /dev/fbs/${inst} >/dev/console  2>&1 &
	done
else
	err_flag=1
fi

#
#  Check to see if ucode download succeeded for all devices
#
if [ $err_flag -ne 0 ] 
then
	exit 1
fi
exit 0
