9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Russ Cox" <rsc@swtch.com>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] sb16
Date: Sat, 26 Jan 2008 09:28:15 -0500	[thread overview]
Message-ID: <20080126142810.BF8C71E8C22@holo.morphisms.net> (raw)
In-Reply-To: <789304.87596.qm@web56206.mail.re3.yahoo.com>

> So, I added the line
>         audio0=type=sb16 port=0x220 irq=5 dma=1
> to plan9.ini and 'bind #A' to termrc, but I got the error

If the driver says the card isn't responding, making it
continue on blindly isn't likely to change the situation.
Luckily, the card you have should work, as long as it 
is what Win98 says it is.

On the sb16 plug-and-play, the important field is port=.
The irq= and dma= actually get programmed into the
card (or read from it, if you don't specify them), but
the driver needs a correct port= to find the card in the
first place.

Below is a very old throwaway program I wrote called tsb.c.
I haven't used it in 7+ years, but it looks like it should
still work.  It probes a given port to see if it finds a sb16 there.
If it prints sensible numbers, then it did.

	8c tsb.c
	8l tsb.8
	for(i in 0x220 0x240 0x260 0x280)
		echo -n 'port='$i && 8.out $i >[2]/dev/null

For example, here's a run on a machine without a sb16.

	% for(i in 0x220 0x240 0x260 0x280)
		echo -n 'port='$i && 8.out >[2]/dev/null
	port=0x220 irq:#ff:10 dma:#ff:0 1 3 5 6 7 
	port=0x240 irq:#ff:10 dma:#ff:0 1 3 5 6 7 
	port=0x260 irq:#ff:10 dma:#ff:0 1 3 5 6 7 
	port=0x280 irq:#ff:10 dma:#ff:0 1 3 5 6 7 
	% 

On a machine with a sb16, one of those lines should have hex
numbers other than #ff.  Use that port number.

If you run it without the >[2]/dev/null you'll get more 
debugging info than you could want to see.

Russ


--- tsb.c
#include <u.h>
#include <libc.h>

int iobfd = -1;

uchar
inportb(long port)
{
	uchar data;
	if(iobfd == -1)
		iobfd = open("#P/iob", ORDWR);
	seek(iobfd, port, 0);
	if(read(iobfd, &data, sizeof(data)) != sizeof(data))
		fprint(2, "inportb(0x%4.4x): %r\n", port);
	return data;
}

void
outportb(long port, uchar b)
{
	if(iobfd == -1)
		iobfd = open("#P/iob", ORDWR);
	seek(iobfd, port, 0);
	if(write(iobfd, &b, sizeof(b)) != sizeof(b))
		fprint(2, "outportb(0x%4.4x, %#x): %r\n", port);
	
}
	
int mixaddr, mixdata, rstatus, bread, bwrite, wstatus, reset;

int sbread(void)
{	int i;
	int s;
	for(i=0;i<16;i++) {
		s=inportb(rstatus);
		fprint(2,"(rstat %#x)", s);
		if(s & 0x80) {
			return inportb(bread);
		}
	}
	return 0xbb;
}

int sbwrite(int d)
{
int i, s;
	for(i=0; i<16; i++) {
		s=inportb(rstatus);
		fprint(2,"(rstat %#x)", s);
		if((s & 0x80) == 0) {
			outportb(bwrite, d);
			return 0;
		}
	}
	return 1;
}
	
void
main(int argc, char **argv)
{
	int i, j, irq, dma;
	int base;

	base = argc > 1 ? atoi(argv[1]) : 0x220;
fprint(2, "base 0x%x\n", base);
	mixaddr = base + 4;
	mixdata = base + 5;
	reset = base + 6;
	wstatus = base + 0xc;
	bread = base  + 0xa;
	bwrite = base + 0xc;
	rstatus = base + 0xe;
	
	fprint(2, "testing...\n");
	fprint(2, "reset...");
	outportb(reset, 1);
	sleep(1);
	outportb(reset, 0);
	sleep(2);
	fprint(2, "read...");
	fprint(2, "%#x...", inportb(bread));
	fprint(2, "%#x...", inportb(bread));
	fprint(2, "%#x...", inportb(bread));
	fprint(2, "%#x...", inportb(bread));

	fprint(2, "write e1...");
	fprint(2, "%d...", sbwrite(0xe1));

	fprint(2, "read...");
	fprint(2, "%#x...", sbread());
	fprint(2, "read...");
	fprint(2, "%#x...", sbread());

	fprint(2, "0x80: ");
	outportb(mixaddr, 0x80);
	fprint(2, "%#2.2x...", i=inportb(mixdata));
	irq = 0;
	print(" irq:#%2.2x", i);
	if(i & 1) irq = 2;
	if(i & 2) irq = 5;
	if(i & 4) irq = 7;
	if(i & 8) irq = 10;
	print(":%d ", irq);

	fprint(2, "0x81: ");
	outportb(mixaddr, 0x81);
	fprint(2, "%#2.2x...", i=inportb(mixdata));
	dma = 0;
	print("dma:#%2.2x:", i);
	for(j=0; j<8; j++) {
		if(i & (1 << j) && j != 2 && j != 4) {
			print("%d ", j);
			dma = j;
		}
	}

	fprint(2, "0x82: ");
	outportb(mixaddr, 0x82);
	fprint(2, "%#2.2x...", inportb(mixdata));

	fprint(2, "\n");
	print("\n");	
}


  parent reply	other threads:[~2008-01-26 14:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-26  0:01 gas
2008-01-26  0:07 ` Pietro Gagliardi
2008-01-26  0:25   ` gas
2008-01-26  0:40     ` Tharaneedharan Vilwanathan
2008-01-26 14:28 ` Russ Cox [this message]
2008-01-26 16:16   ` gas
  -- strict thread matches above, loose matches on Subject: below --
2001-11-02 15:22 [9fans] SB16 Richard Miller
2001-11-01  3:42 Carlos Eduardo Lenz
2001-11-01  2:57 okamoto
2001-11-01 13:31 ` plan9
2001-11-02  3:54   ` Carlos Eduardo Lenz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080126142810.BF8C71E8C22@holo.morphisms.net \
    --to=rsc@swtch.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).