From owner-FreeBSD-users-jp@jp.freebsd.org  Wed May 28 04:25:36 1997
Received: by jaz.jp.freebsd.org (8.8.5+2.7Wbeta5/8.7.3) id EAA06598
	Wed, 28 May 1997 04:25:36 +0900 (JST)
Received: by jaz.jp.freebsd.org (8.8.5+2.7Wbeta5/8.7.3) with ESMTP id EAA06592
	for <freebsd-users-jp@jp.freebsd.org>; Wed, 28 May 1997 04:25:34 +0900 (JST)
Received: from jaist.ac.jp (localhost [127.0.0.1])
	by hequil.jaist.ac.jp (8.8.5/8.8.5) with ESMTP id EAA02505;
	Wed, 28 May 1997 04:23:45 +0900 (JST)
Message-Id: <199705271923.EAA02505@hequil.jaist.ac.jp>
To: freebsd-users-jp@jp.freebsd.org
In-Reply-To: Your message of "Wed, 28 May 1997 02:49:05 +0900 (JST)"
References: <199705271749.CAA01617@jaz.jp.freebsd.org>
X-Mailer: Mew version 1.70 on Emacs 19.34.2 / Mule 2.3
X-URL: http://www.jaist.ac.jp/~shigeru/
Mime-Version: 1.0
Content-Type: Multipart/Mixed;
	boundary="--Next_Part(Wed_May_28_04:22:53_1997)--"
Content-Transfer-Encoding: 7bit
Date: Wed, 28 May 1997 04:23:45 +0900
From: Shigeru Fujiwara <shigeru@jaist.ac.jp>
Reply-To: FreeBSD-users-jp@jp.freebsd.org
Precedence: bulk
X-Distribute: distribute [version 2.1 (Alpha) patchlevel=19]
X-Sequence: FreeBSD-users-jp 13414
Subject: [FreeBSD-users-jp 13414] Re: SoundBlaster16 pnp on FreeBSD2.2.1
Errors-To: owner-FreeBSD-users-jp@jp.freebsd.org
Sender: owner-FreeBSD-users-jp@jp.freebsd.org

----Next_Part(Wed_May_28_04:22:53_1997)--
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit

digest$B$GFI$s$G$kF#86$G$9!#(B2.2-970422-RELENG$B$G$9!#(B

> FreeBSD-ISA_PnP_June8.tar.gz $B$rEv$F$F%+!<%M%k$N:F9=C[$r9T$J$C$?$N$G$9$,!"(B
> $B<!$N$h$&$J%(%i!<$,$G$F%9%H%C%W$7$F$7$^$$$^$9!#(B

$B;d$N$H$3$m$G$O%Q%C%AEv$F$b%+!<%M%k:F9=C[$bLdBj$J$/$G$-$^$7$?!#(B
$B%+!<%M%k$N%3%s%U%#%0%U%!%$%k$rE:IU$7$^$9!#(B

$B$H$3$m$G!"JX>h$7$F(BAWE64Gold$B$N@_Dj$K$D$$$F<ALd$5$;$F$$$?$@$-$?$$$N$G$9!#(B

$B;d$O:G6a(BSoundBlaster$B$N(BAWE64 Gold$B$r<j$K$$$l$?$N$G!"$=$l$rMxMQ$9$k0Y$K0J(B
$BA0(Bfj$B$KEj9F$5$l$F$$$?(BAWE64$BMQ$N@_Dj$r(B/usr/src/sys/i386/isa/pnp.c$B$K2C$($F(B
$B$_$^$7$?(B($B:G8e$KE:IU$7$^$9(B)$B!#(B

$B%5%&%s%I%U%)%s%HFI$^$;$k0Y$K(B
http://multiverse.com/~rhh/awedrv/
$B$+$i$$$?$@$$$F$-$?(Bports$B$G(Bawesfx-0.2.99c$B$r%3%s%Q%$%k$7$^$7$?!#ESCf$G(B

sfxtest.o: Undefined symbol `_AWE_SET_CHANNEL_MODE' referenced from text segment
*** Error code 1

$B$H$$$o$l$F;_$^$j$^$9$,!"(BMakefile$B$+$i(Bsfxtest$B$r30$9$HDL$k$N$G!"$=$l$G(B
$B:n$C$?(Bsfxload$B$r;H$C$F$$$^$9!#(B
# http://bahamut.mm.t.u-tokyo.ac.jp/~iwai/awedrv/index.html
# $B$K$"$k?7$7$$$b$N$O%3%s%Q%$%k$G$-$^$;$s$G$7$?!#(B

$B$3$l$G%\!<%I$KIUB0$7$F$-$?(B4GMGSMT.SF2$B$H$$$&%5%&%s%I%U%)%s%H$rFI$^$;$F(B
$B$_$?$N$G$9$,!"$I$&$bMM;R$,$*$+$7$$$N$G$9!#$C$F$$$&$H!"A4A36qBNE*$G$O$J(B
$B$$$N$G$9$,!"%I%i%`Ey$N4pK\E*$J2;$N4v$D$+$,A4A3=P$F$$$J$$$h$&$J5$$,$9$k(B
$B$N$G$9!#$J$s$+%U%K%c%U%K%c$7$?2;$NB-$j$J$$1iAU$K$J$C$F$7$^$&$N$G$9!#(B
# $B$3$l$G$bA4A36qBNE*$G$O$J$$$G$9$M!#?=$7Lu$"$j$^$;$s!#(B

$B3N$+$3$l$G$b(BAWE32$BAjEv$G;H$($k$H;W$&$N$G$9$,!"$=$l$H$b$3$&$$$&$b$N$J$N(B
$B$G$7$g$&$+!)$-$C$H4pK\E*$J4*0c$$$r$7$F$k$s$@$m$&$J$"$H$O;W$$$^$9$,!"2r(B
$B7h$N0Y$N%]%$%s%?$J$I8f;XE&$$$?$@$1$^$7$?$i9,$$$G$9!#(B

$B0J2<$K%+!<%M%k$N%3%s%U%#%0%U%!%$%k!"(B/usr/src/sys/i386/isa/pnp.c$B$rE:IU(B
$B$7$^$9!#(B

--
	Shigeru Fujiwara
	Japan Adv. Inst. of Sci. and Tech., Ishikawa, Japan
	e-mail:shigeru@jaist.ac.jp



----Next_Part(Wed_May_28_04:22:53_1997)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

#
# GENERIC -- Generic machine with WD/AHx/NCR/BTx family disks
#
# For more information read the handbook part System Administration -> 
# Configuring the FreeBSD Kernel -> The Configuration File. 
# The handbook is available in /usr/share/doc/handbook or online as
# latest version from the FreeBSD World Wide Web server 
# <URL:http://www.FreeBSD.ORG/>
#
# An exhaustive list of options and more detailed explanations of the 
# device lines is present in the ./LINT configuration file. If you are 
# in doubt as to the purpose or necessity of a line, check first in LINT.
#
#	$Id: GENERIC,v 1.77.2.4 1997/02/22 20:31:24 joerg Exp $

machine		"i386"
cpu		"I686_CPU"
ident		HEQUIL
maxusers	10

options		MAXMEM="128*1024"
options		MATH_EMULATE		#Support for x87 emulation
options		INET			#InterNETworking
options		FFS			#Berkeley Fast Filesystem
options		NFS			#Network Filesystem
options		MSDOSFS			#MSDOS Filesystem
options		"CD9660"		#ISO 9660 Filesystem
options		PROCFS			#Process filesystem
options		"COMPAT_43"		#Compatible with BSD 4.3 [KEEP THIS!]
options		SCSI_DELAY=15		#Be pessimistic about Joe SCSI device
options		BOUNCE_BUFFERS		#include support for DMA bounce buffers
options		FAILSAFE		#Be conservative
options		USERCONFIG		#boot -c editor
options		VISUAL_USERCONFIG	#visual boot -c editor

# undocumented options
options         COMPAT_LINUX
#options         DEBUG
#options         DEVFS_ROOT
options         "EXT2FS"
options         "I586_CTR_GUPROF"
options         "I586_PMC_GUPROF=0x70000"


#
# PERFMON causes the driver for Pentium/Pentium Pro performance counters
# to be compiled.  See perfmon(4) for more information.
#
options         PERFMON

# XXX - this doesn't belong here.
# Allow ordinary users to take the console - this is useful for X.
options         UCONSOLE


# These three options provide support for System V Interface
# Definition-style interprocess communication, in the form of shared
# memory, semaphores, and message queues, respectively.
#
options         SYSVSHM
options         SYSVSEM
options         SYSVMSG

#
# This option includes a MD5 routine in the kernel, this is used for
# various authentication and privacy uses.
#
options         "MD5"

config		kernel	root on sd1

controller	isa0
controller	pnp0	#need ISA_PnP patch
controller	eisa0
controller	pci0

controller	fdc0	at isa? port "IO_FD1" bio irq 6 drq 2 vector fdintr 
disk		fd0	at fdc0 drive 0

# A single entry for any of these controllers (ncr, ahb, ahc, amd) is
# sufficient for any number of installed devices.
controller	ncr0

controller	scbus0

device		sd0

device		od0	#See LINT for possible `od' options.

device		st0

device		cd0	#Only need one of these, the code dynamically grows

# syscons is the default console driver, resembling an SCO console
device		sc0	at isa? port "IO_KBD" tty irq 1 vector scintr

# Mandatory, don't remove
device		npx0	at isa? port "IO_NPX" irq 13 vector npxintr

#
# Laptop support (see LINT for more options)
#
#device		apm0    at isa?	disable	# Advanced Power Management
device		apm0	at isa?
#options		APM_BROKEN_STATCLOCK	# Workaround some buggy APM BIOS

device		sio0	at isa? port "IO_COM1" tty irq 4 vector siointr
device		sio1	at isa? port "IO_COM2" tty irq 3 vector siointr

device		lpt0	at isa? port? tty irq 7 vector lptintr

device		psm0	at isa? port "IO_KBD" conflicts tty irq 12 vector psmintr

# Sound device
controller      snd0
device          sb0     at isa? port 0x220 irq 5 drq 1 vector sbintr
device          sbxvi0  at isa? drq 5
device          sbmidi0 at isa? port 0x330
#device          opl0    at isa? port 0x388
device		awe0	at isa? port 0x620
#device         awe0    at isa? port 0xA20
#device         awe0    at isa? port 0xE20

# Order is important here due to intrusive probes, do *not* alphabetize
# this list of network interfaces until the probes have been fixed.
# Right now it appears that the ie0 must be probed before ep0. See
# revision 1.20 of this file.
device de0

pseudo-device	loop
pseudo-device	ether
pseudo-device	log
pseudo-device	sl	1
# ijppp uses tun instead of ppp device
#pseudo-device	ppp	1
pseudo-device	tun	1
pseudo-device	pty	16
pseudo-device	gzip		# Exec gzipped a.out's

# KTRACE enables the system-call tracing facility ktrace(2).
# This adds 4 KB bloat to your kernel, and slightly increases
# the costs of each syscall.
options		KTRACE		#kernel tracing


----Next_Part(Wed_May_28_04:22:53_1997)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

/*
 * Copyright (c) 1996, Sujal M. Patel
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *      $Id: pnpcfg.c,v 1.6 1996/05/06 02:08:25 smpatel Exp smpatel $
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <machine/clock.h>
#include <machine/cpufunc.h>

/* #include "pnp.h" */
#include <i386/isa/pnp.h>

#define SEND(d, r)	{ outb (ADDRESS, d); outb (WRITE_DATA, r); }


/* The READ_DATA port that we are using currently */
static int rd_port;


/*
 * Hard coded for now -- Will need to use resource information from
 * ISA, PCI, and EISA drivers to auto-configure the PnP-devices
 */
static struct cinfo cinfo[] = 
{
  /* Configuration for the Supra Express 288i PnP */
  {
    0x00008803, 		/* Serial Number */
    -1,		/* Logical Device Number */
    {
      { 15, -1 },	/* Primary IRQ Number, Type */
      { -1, -1 }	/* Second  IRQ Number, Type */
    },
    { -1, -1 },		/* DRQ Number */
    {
      0x3e8,		/* Ports 1 */
      -1,		/* Ports 2 */
      -1,		/* Ports 3 */
      -1,		/* Ports 4 */
      -1,		/* Ports 5 */
      -1,		/* Ports 6 */
      -1,		/* Ports 7 */
      -1,		/* Ports 8 */
    },
    {
      { -1, -1, -1 },	/* Memory desc0 - base, ctrl, range */
      { -1, -1, -1 },	/* Memory desc1 - base, ctrl, range */
      { -1, -1, -1 },	/* Memory desc2 - base, ctrl, range */
      { -1, -1, -1 }	/* Memory desc3 - base, ctrl, range */ 
    }
  },
  
  /* Configuration for the SMC EtherEZ */
  {
    0xb1f5acc0, 		/* Serial Number */
    -1,		/* Logical Device Number */
    {
      { 11, 1 },	/* Primary IRQ Number, Type */
      { -1, -1 }	/* Second  IRQ Number, Type */
    },
    { -1, -1 },		/* DRQ Number */
    {
      0x240,		/* Ports 1 */
      -1,		/* Ports 2 */
      -1,		/* Ports 3 */
      -1,		/* Ports 4 */
      -1,		/* Ports 5 */
      -1,		/* Ports 6 */
      -1,		/* Ports 7 */
      -1,		/* Ports 8 */
    },
    {
      { 0xd0000, 2, 0x2000 },	/* Memory desc0 - base, ctrl, range */
      { -1, -1, -1 },	/* Memory desc1 - base, ctrl, range */
      { -1, -1, -1 },	/* Memory desc2 - base, ctrl, range */
      { -1, -1, -1 }	/* Memory desc3 - base, ctrl, range */ 
    }
  },
  /* Configuration for SoundBrasterAWE64Gold */
  {
    0x01568db3,             /* Serial Number */
    2,             /* Logical Device Number */
    {
      { -1, -1 },     /* Primary IRQ Number, Type */
      { -1, -1 }      /* Second  IRQ Number, Type */
    },
    { -1, -1 },               /* DRQ Number */
    {
      0x620,          /* Ports 1 */
      0xa20,          /* Ports 2 */
      0xe20,          /* Ports 3 */
      -1,          /* Ports 4 */
      -1,          /* Ports 5 */
      -1,          /* Ports 6 */
      -1,          /* Ports 7 */
      -1,          /* Ports 8 */
    },
    {
      { -1, -1, -1 }, /* Memory desc0 - base, ctrl, range */
      { -1, -1, -1 }, /* Memory desc1 - base, ctrl, range */
      { -1, -1, -1 }, /* Memory desc2 - base, ctrl, range */
      { -1, -1, -1 }  /* Memory desc3 - base, ctrl, range */ 
    }
  }
};


int power __P((int base, int exp));
void send_Initiation_LFSR __P((void));
int get_serial __P((unsigned char *data));
void config_device __P((unsigned char *data, int csn));
int isolation_protocol __P((void));


int
power(base, exp)
	int base, exp;
{
	if (exp <= 1)
		return base;
	else
		return base * power(base, exp - 1);
}


/*
 * Send Initiation LFSR as described in "Plug and Play ISA Specification,
 * Intel May 94."
 */
void
send_Initiation_LFSR()
{
	int cur, i;

	/* Reset the LSFR */
	outb(ADDRESS, 0);
	outb(ADDRESS, 0);

	cur = 0x6a;
	outb(ADDRESS, cur);

	for (i = 1; i < 32; i++) {
		cur = (cur >> 1) | (((cur ^ (cur >> 1)) << 7) & 0xff);
		outb(ADDRESS, cur);
	}
}


/*
 * Get the device's serial number.  Returns 1 if the serial is valid.
 */
int
get_serial(data)
	unsigned char *data;
{
	int i, bit, valid = 0, sum = 0x6a;

	bzero(data, sizeof(char) * 9);

	for (i = 0; i < 72; i++) {
		bit = inb((rd_port << 2) | 0x3) == 0x55;
		DELAY(250);	/* Delay 250 usec */

		/* Can't Short Circuit the next evaluation, so 'and' is last */
		bit = (inb((rd_port << 2) | 0x3) == 0xaa) && bit;
		DELAY(250);	/* Delay 250 usec */

		valid = valid || bit;

		if (i < 64)
			sum = (sum >> 1) |
			    (((sum ^ (sum >> 1) ^ bit) << 7) & 0xff);

		data[i / 8] = (data[i / 8] >> 1) | (bit ? 0x80 : 0);
	}

	valid = valid && (data[8] == sum);

	return valid;
}


/*
 * Configure PnP devices
 */
void
config_device(data, csn)
	unsigned char *data;
	int csn;
{
	struct cinfo *ci;
	int i;

	if (bootverbose)
		printf("Card assigned CSN #%d\n", csn);

	printf("Board Vendor ID: %c%c%c%02x%02x",
	    ((data[0] & 0x7c) >> 2) + 64,
	    (((data[0] & 0x03) << 3) | ((data[1] & 0xe0) >> 5)) + 64,
	    (data[1] & 0x1f) + 64, data[2], data[3]);
	printf("     Board Serial Number: %08x\n", *(int *)&(data[4]));

	SEND(SET_CSN, csn); /* Move this out of this function XXX */
	outb(ADDRESS, STATUS);

	for (ci = cinfo; (int)ci < ((int)cinfo + sizeof (cinfo)); ci++) {
		if (ci->serial == *(int *)&(data[4])) {
			printf ("	Configuring (Logical Device %x)\n",
				ci->ldn != -1 ? ci->ldn : 0);

			if (ci->ldn > 0)
				SEND (SET_LDN, ci->ldn);

			for (i = 0; i < 8; i++)
				if (ci->port[i] > 0) {
					SEND (IO_CONFIG_BASE + i * 2,
						ci->port[i] >> 8);
					SEND (IO_CONFIG_BASE + i * 2 + 1,
						ci->port[i] & 0xff);
				}

			for (i = 0; i < 2; i++)
				if (ci->irq[i].num > 0) {
					SEND (IRQ_CONFIG + i * 2,
						ci->irq[i].num);
					if (ci->irq[i].type >= 0)
						SEND (IRQ_CONFIG + i * 2 + 1,
							ci->irq[i].type);
				}

			for (i = 0; i < 2; i++)
				if (ci->drq[i] > 0) {
					SEND (DRQ_CONFIG + i,
						ci->drq[i]);
				}

			for (i = 0; i < 4; i++)
				if (ci->mem[i].base > 0) {
					SEND (MEM_CONFIG + i * 8,
						ci->mem[i].base >> 16);
					SEND (MEM_CONFIG + i * 8 + 1,
						(ci->mem[i].base >> 8) &
						0xff);
					/*
					 * This needs to be handled better for
					 * the user's sake. XXX
					 */
					if (ci->mem[i].control >= 0) {
						SEND (MEM_CONFIG + i * 8 + 2,
							ci->mem[i].control);
					}
					SEND (MEM_CONFIG + i * 8 + 3,
						ci->mem[i].range >> 16);
					SEND (MEM_CONFIG + i * 8 + 4,
						(ci->mem[i].range >> 8) &
						0xff);
				}
			SEND (IO_RANGE_CHECK, 0);
			SEND (ACTIVATE, 1);
		}
	}
}


/*
 * Run the isolation protocol. Use rd_port as the READ_DATA port value (caller
 * should try multiple READ_DATA locations before giving up). Upon exiting,
 * all cards are aware that they should use rd_port as the READ_DATA port;
 */
int
isolation_protocol()
{
	int csn;
	unsigned char data[9];

	send_Initiation_LFSR();

	/* Reset CSN for All Cards */
	SEND(0x02, 0x04);

	for (csn = 1; (csn < MAX_CARDS); csn++) {
		/* Wake up cards without a CSN */
		SEND(WAKE, 0);
		SEND(SET_RD_DATA, rd_port);
		outb(ADDRESS, SERIAL_ISOLATION);
		DELAY(1000);	/* Delay 1 msec */

		if (get_serial(data))
			config_device(data, csn);
		else
			break;
	}
	return csn - 1;
}


void
pnp_configure()
{
	int num_pnp_devs;

	printf("Checking for Plug-n-Play devices...\n");

	/* Try various READ_DATA ports from 0x203-0x3ff */
	for (rd_port = 0x80; (rd_port < 0xff); rd_port += 0x10) {
		if (bootverbose)
			printf("Trying Read_Port at %x\n",
				(rd_port << 2) | 0x3);

		num_pnp_devs = isolation_protocol();
		if (num_pnp_devs)
			break;
	}
	if (!num_pnp_devs) {
		printf("No Plug-n-Play devices were found\n");
		return;
	}
}

----Next_Part(Wed_May_28_04:22:53_1997)----
