/* $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 */

#ident	"$Header: consmem.c 1.12 90/05/03 $"

/*
 * consmem.c 
 *	Logical memory driver for system controllers.
 *	Provides a dynamic indirect interface to 
 *	the memory driver of either the SSM or SCED 
 *	connected to the front panel.
 */

/* $Log:	consmem.c,v $
 */

#include "sys/types.h"
#include "sys/devsw.h"
#include "sys/param.h"
#include "sys/debug.h"
#include "sys/cmn_err.h"
#include "sys/sysmacros.h"
#include "sys/signal.h"
#include "sys/user.h"
#include "sys/conf.h"
#include "sys/uio.h"
#include "sys/devsw.h"
#include "sys/systm.h"
#include "sys/cfg.h"
#include "sys/errno.h"
#include "sys/arch.h"

static struct dev *devp;

/*ARGSUSED*/
void
consmem_init(ndevs)
	int ndevs; 
{
	register struct dev *dp;
	extern dev_t smem_devnum;
	extern int consmem_c_major;
	extern struct devops consmemdevops;

	/*
	 * Disallow on hardware known to not support SSM.
	 */

	if (arch_type == SYSTYP_S1)
		return;

	dp = (struct dev *)calloc(sizeof(struct dev));
	dp->d_dev = makedev(consmem_c_major, CTLR_MINOR);
	dp->d_ops = &consmemdevops;
	dp->d_flags = 0;
	if (devsw_add(dp) < 0)
		CPRINTF("consmem: devsw_add() failed\n");
	if (smem_devnum != -1)
		devp = dev_ref(smem_devnum);
}
	
/*
 * consmemopen()	
 *	Verify that the minor device number is
 *	the special control device value and then
 *	call the device dependent routine.
 */
consmemopen(dp, flag, type)
	struct dev *dp;
	int flag;
	int type;
{
	if (minor(dp->d_dev) != CTLR_MINOR || devp == NULL)
		return(ENXIO);
	return DEV_OPEN(devp, flag, type);
}

/*
 * consmemwrite()
 *	Invoke the device dependent write-to-RAM function.
 */
/*ARGSUSED*/
consmemwrite(dp, uio, flag)
	struct dev *dp;
	struct uio *uio;
	int	flag;
{
	return DEV_WRITE(devp, uio, flag);
}

/*
 * consmemread()
 *	Invoke the device dependent read-from-RAM function.
 */
/*ARGSUSED*/
consmemread(dp, uio, flag)
	struct dev *dp;
	struct uio *uio;
	int	flag;
{
	return DEV_READ(devp, uio, flag);
}

/*
 * consmemioctl()
 *	Invoke the device dependent ioctl function.
 */
/*ARGSUSED*/
consmemioctl(dp, cmd, addr, flag)
	struct dev *dp;
	int	cmd;
	caddr_t	addr;
	int	flag;
{
	return DEV_IOCTL(devp, cmd, addr, flag);
}
