shithub: riscv

Download patch

ref: e1400c2d5b429f3baa2a5f8227494e80367f7ee0
parent: f5b15ebcd3edfa52a4c8eaa1ef2dd88a60196285
author: cinap_lenrek <cinap_lenrek@localhost>
date: Thu May 19 13:00:58 EDT 2011

ac97: fix probe code

--- a/sys/src/9/pc/audioac97.c
+++ b/sys/src/9/pc/audioac97.c
@@ -70,6 +70,10 @@
 	int hardrate;
 
 	int attachok;
+
+	/* for probe */
+	Pcidev *pcidev;
+	Ctlr *next;
 };
 
 #define iorl(c, r)	(inl((c)->port+(r)))
@@ -483,20 +487,34 @@
 static int
 ac97reset(Audio *adev)
 {
-	static int ncards = 1;
-	int i, irq, tbdf;
+	static Ctlr *cards = nil;
 	Pcidev *p;
+	int i, irq, tbdf;
 	Ctlr *ctlr;
 	ulong ctl, stat = 0;
 
-	p = nil;
-	for(i = 0; i < ncards; i++)
-		if((p = ac97match(p)) == nil)
-			return -1;
-	ncards++;
+	/* make a list of all ac97 cards if not already done */
+	if(cards == nil){
+		p = nil;
+		while(p = ac97match(p)){
+			ctlr = xspanalloc(sizeof(Ctlr), 8, 0);
+			memset(ctlr, 0, sizeof(Ctlr));
+			ctlr->pcidev = p;
+			ctlr->next = cards;
+			cards = ctlr;
+		}
+	}
 
-	ctlr = xspanalloc(sizeof(Ctlr), 8, 0);
-	memset(ctlr, 0, sizeof(Ctlr));
+	/* pick a card from the list */
+	for(ctlr = cards; ctlr; ctlr = ctlr->next){
+		if(p = ctlr->pcidev){
+			ctlr->pcidev = nil;
+			goto Found;
+		}
+	}
+	return -1;
+
+Found:
 	adev->ctlr = ctlr;
 	ctlr->targetrate = 44100;
 	ctlr->hardrate = 44100;