Browse Source

Plan 9 from Bell Labs 2008-05-30

David du Colombier 12 years ago
parent
commit
06d9ce9575

+ 6 - 7
dist/replica/_plan9.db

@@ -7718,7 +7718,7 @@ sys/man/3/proc - 664 sys sys 1196638942 12062
 sys/man/3/root - 664 sys sys 1196638942 632
 sys/man/3/rtc - 664 sys sys 1196638942 667
 sys/man/3/sd - 664 sys sys 1196638942 5659
-sys/man/3/sdahci - 664 sys sys 1212016122 3212
+sys/man/3/sdahci - 664 sys sys 1212097867 3213
 sys/man/3/sdaoe - 664 sys sys 1196638942 1320
 sys/man/3/segment - 664 sys sys 1196638942 2378
 sys/man/3/srv - 664 sys sys 1196638942 1470
@@ -8190,7 +8190,7 @@ sys/src/9/pc/screen.h - 664 sys sys 1147023549 4256
 sys/src/9/pc/sd53c8xx.c - 664 sys sys 1211521147 55313
 sys/src/9/pc/sd53c8xx.n - 664 sys sys 1131290556 12657
 sys/src/9/pc/sdata.c - 664 sys sys 1211924368 53297
-sys/src/9/pc/sdiahci.c - 664 sys sys 1212010154 38901
+sys/src/9/pc/sdiahci.c - 664 sys sys 1212099695 38999
 sys/src/9/pc/sdmv50xx.c - 664 sys sys 1204232564 34031
 sys/src/9/pc/sdmylex.c - 664 sys sys 1189229947 28395
 sys/src/9/pc/sdscsi.c - 664 sys sys 1186618532 7957
@@ -8260,7 +8260,7 @@ sys/src/9/port/devpipe.c - 664 sys sys 1077055016 5825
 sys/src/9/port/devpnp.c - 664 sys sys 1088560907 13624
 sys/src/9/port/devproc.c - 664 sys sys 1210984256 28480
 sys/src/9/port/devroot.c - 664 sys sys 1146151714 4242
-sys/src/9/port/devsd.c - 664 sys sys 1186965855 31275
+sys/src/9/port/devsd.c - 664 sys sys 1212099662 31288
 sys/src/9/port/devsdp.c - 664 sys sys 1057323393 44800
 sys/src/9/port/devsegment.c - 664 sys sys 1131289891 9610
 sys/src/9/port/devsrv.c - 664 sys sys 1165810571 5711
@@ -8315,7 +8315,7 @@ sys/src/9/port/swap.c - 664 sys sys 1138028310 7019
 sys/src/9/port/sysfile.c - 664 sys sys 1188922869 22120
 sys/src/9/port/sysproc.c - 664 sys sys 1188922870 21419
 sys/src/9/port/systab.h - 664 sys sys 1161222889 3204
-sys/src/9/port/taslock.c - 664 sys sys 1204229744 4590
+sys/src/9/port/taslock.c - 664 sys sys 1212083600 4478
 sys/src/9/port/thwack.c - 664 sys sys 1057323394 7253
 sys/src/9/port/thwack.h - 664 sys sys 1015278340 1792
 sys/src/9/port/tod.c - 664 sys sys 1204228653 5445
@@ -9187,7 +9187,6 @@ sys/src/boot/pc/conf.c - 664 sys sys 1094674484 10217
 sys/src/boot/pc/console.c - 664 sys sys 1212010517 3422
 sys/src/boot/pc/dat.h - 664 sys sys 1190921443 3637
 sys/src/boot/pc/devbios.c - 664 sys sys 1212010497 9431
-sys/src/boot/pc/devbios.h - 664 sys sys 1193167027 493
 sys/src/boot/pc/devfloppy.c - 664 sys sys 1212010456 15657
 sys/src/boot/pc/devfloppy.h - 664 sys sys 1032409559 4081
 sys/src/boot/pc/devi82365.c - 664 sys sys 1144961189 15051
@@ -9233,7 +9232,7 @@ sys/src/boot/pc/kbd.c - 664 sys sys 1015007952 10188
 sys/src/boot/pc/kfs.h - 664 sys sys 1032215924 861
 sys/src/boot/pc/kfsboot.c - 664 sys sys 1032215914 4788
 sys/src/boot/pc/l.s - 664 sys sys 1193167045 18213
-sys/src/boot/pc/lib.h - 664 sys sys 1200893244 2925
+sys/src/boot/pc/lib.h - 664 sys sys 1212090562 3280
 sys/src/boot/pc/load.c - 664 sys sys 1212010219 10578
 sys/src/boot/pc/mbr.s - 664 sys sys 1015007953 6234
 sys/src/boot/pc/mem.h - 664 sys sys 1190921475 3437
@@ -9254,7 +9253,7 @@ sys/src/boot/pc/sd53c8xx.i - 664 sys sys 1015007955 27245
 sys/src/boot/pc/sdaoe.c - 664 sys sys 1204324647 11381
 sys/src/boot/pc/sdata.c - 664 sys sys 1212010306 39146
 sys/src/boot/pc/sdbios.c - 664 sys sys 1212010334 3280
-sys/src/boot/pc/sdiahci.c - 664 sys sys 1212010293 28716
+sys/src/boot/pc/sdiahci.c - 664 sys sys 1212090562 28613
 sys/src/boot/pc/sdmylex.c - 664 sys sys 1171783051 28694
 sys/src/boot/pc/sdscsi.c - 664 sys sys 1144961224 7006
 sys/src/boot/pc/trap.c - 664 sys sys 1193167011 7497

+ 6 - 7
dist/replica/plan9.db

@@ -7718,7 +7718,7 @@ sys/man/3/proc - 664 sys sys 1196638942 12062
 sys/man/3/root - 664 sys sys 1196638942 632
 sys/man/3/rtc - 664 sys sys 1196638942 667
 sys/man/3/sd - 664 sys sys 1196638942 5659
-sys/man/3/sdahci - 664 sys sys 1212016122 3212
+sys/man/3/sdahci - 664 sys sys 1212097867 3213
 sys/man/3/sdaoe - 664 sys sys 1196638942 1320
 sys/man/3/segment - 664 sys sys 1196638942 2378
 sys/man/3/srv - 664 sys sys 1196638942 1470
@@ -8190,7 +8190,7 @@ sys/src/9/pc/screen.h - 664 sys sys 1147023549 4256
 sys/src/9/pc/sd53c8xx.c - 664 sys sys 1211521147 55313
 sys/src/9/pc/sd53c8xx.n - 664 sys sys 1131290556 12657
 sys/src/9/pc/sdata.c - 664 sys sys 1211924368 53297
-sys/src/9/pc/sdiahci.c - 664 sys sys 1212010154 38901
+sys/src/9/pc/sdiahci.c - 664 sys sys 1212099695 38999
 sys/src/9/pc/sdmv50xx.c - 664 sys sys 1204232564 34031
 sys/src/9/pc/sdmylex.c - 664 sys sys 1189229947 28395
 sys/src/9/pc/sdscsi.c - 664 sys sys 1186618532 7957
@@ -8260,7 +8260,7 @@ sys/src/9/port/devpipe.c - 664 sys sys 1077055016 5825
 sys/src/9/port/devpnp.c - 664 sys sys 1088560907 13624
 sys/src/9/port/devproc.c - 664 sys sys 1210984256 28480
 sys/src/9/port/devroot.c - 664 sys sys 1146151714 4242
-sys/src/9/port/devsd.c - 664 sys sys 1186965855 31275
+sys/src/9/port/devsd.c - 664 sys sys 1212099662 31288
 sys/src/9/port/devsdp.c - 664 sys sys 1057323393 44800
 sys/src/9/port/devsegment.c - 664 sys sys 1131289891 9610
 sys/src/9/port/devsrv.c - 664 sys sys 1165810571 5711
@@ -8315,7 +8315,7 @@ sys/src/9/port/swap.c - 664 sys sys 1138028310 7019
 sys/src/9/port/sysfile.c - 664 sys sys 1188922869 22120
 sys/src/9/port/sysproc.c - 664 sys sys 1188922870 21419
 sys/src/9/port/systab.h - 664 sys sys 1161222889 3204
-sys/src/9/port/taslock.c - 664 sys sys 1204229744 4590
+sys/src/9/port/taslock.c - 664 sys sys 1212083600 4478
 sys/src/9/port/thwack.c - 664 sys sys 1057323394 7253
 sys/src/9/port/thwack.h - 664 sys sys 1015278340 1792
 sys/src/9/port/tod.c - 664 sys sys 1204228653 5445
@@ -9187,7 +9187,6 @@ sys/src/boot/pc/conf.c - 664 sys sys 1094674484 10217
 sys/src/boot/pc/console.c - 664 sys sys 1212010517 3422
 sys/src/boot/pc/dat.h - 664 sys sys 1190921443 3637
 sys/src/boot/pc/devbios.c - 664 sys sys 1212010497 9431
-sys/src/boot/pc/devbios.h - 664 sys sys 1193167027 493
 sys/src/boot/pc/devfloppy.c - 664 sys sys 1212010456 15657
 sys/src/boot/pc/devfloppy.h - 664 sys sys 1032409559 4081
 sys/src/boot/pc/devi82365.c - 664 sys sys 1144961189 15051
@@ -9233,7 +9232,7 @@ sys/src/boot/pc/kbd.c - 664 sys sys 1015007952 10188
 sys/src/boot/pc/kfs.h - 664 sys sys 1032215924 861
 sys/src/boot/pc/kfsboot.c - 664 sys sys 1032215914 4788
 sys/src/boot/pc/l.s - 664 sys sys 1193167045 18213
-sys/src/boot/pc/lib.h - 664 sys sys 1200893244 2925
+sys/src/boot/pc/lib.h - 664 sys sys 1212090562 3280
 sys/src/boot/pc/load.c - 664 sys sys 1212010219 10578
 sys/src/boot/pc/mbr.s - 664 sys sys 1015007953 6234
 sys/src/boot/pc/mem.h - 664 sys sys 1190921475 3437
@@ -9254,7 +9253,7 @@ sys/src/boot/pc/sd53c8xx.i - 664 sys sys 1015007955 27245
 sys/src/boot/pc/sdaoe.c - 664 sys sys 1204324647 11381
 sys/src/boot/pc/sdata.c - 664 sys sys 1212010306 39146
 sys/src/boot/pc/sdbios.c - 664 sys sys 1212010334 3280
-sys/src/boot/pc/sdiahci.c - 664 sys sys 1212010293 28716
+sys/src/boot/pc/sdiahci.c - 664 sys sys 1212090562 28613
 sys/src/boot/pc/sdmylex.c - 664 sys sys 1171783051 28694
 sys/src/boot/pc/sdscsi.c - 664 sys sys 1144961224 7006
 sys/src/boot/pc/trap.c - 664 sys sys 1193167011 7497

+ 7 - 0
dist/replica/plan9.log

@@ -19760,3 +19760,10 @@
 1212012004 21 c sys/src/boot/pc/devbios.c - 664 sys sys 1212010497 9431
 1212012004 22 c sys/src/boot/pc/sdbios.c - 664 sys sys 1212010334 3280
 1212017405 0 c sys/man/3/sdahci - 664 sys sys 1212016122 3212
+1212084006 0 c sys/src/9/port/taslock.c - 664 sys sys 1212083600 4478
+1212091204 0 c sys/src/boot/pc/lib.h - 664 sys sys 1212090562 3280
+1212091204 1 c sys/src/boot/pc/sdiahci.c - 664 sys sys 1212090562 28613
+1212098403 0 c sys/man/3/sdahci - 664 sys sys 1212097867 3213
+1212100207 0 c sys/src/9/pc/sdiahci.c - 664 sys sys 1212099695 38999
+1212100207 1 c sys/src/9/port/devsd.c - 664 sys sys 1212099662 31288
+1212100207 2 d sys/src/boot/pc/devbios.h - 664 sys sys 1193167027 0

+ 5 - 5
sys/man/3/sdahci

@@ -42,23 +42,23 @@ The top level control file,
 .BR /dev/sdctl ,
 supports the following control messages for
 .IR sdahci :
-.TF "\fLahci idprint "
+.TF "\fLiahci idprint"
 .TP
-.B ahci debug
+.B iahci debug
 Toggle debug messages.  Default is off.
 .TP
-.B ahci idprint
+.B iahci idprint
 Toggle printing of drive identification messages.  Default is on.
 Prints short messages when a drive is identified or removed.
 .TP
-.B ahci aprint
+.B iahci aprint
 Print verbose ATAPI debugging messages.  Default is off.
 .PD
 .PP
 The device-level
 .B ctl
 file supports:
-.TF "\fLsmartdisable"
+.TF \fLsmartdisable
 .TP
 .B flushcache
 Send the ATA/ATAPI

+ 7 - 1
sys/src/9/pc/sdiahci.c

@@ -154,6 +154,7 @@ static	int	niactlr;
 static	Drive	*iadrive[NDrive];
 static	int	niadrive;
 
+/* these are fiddled in iawtopctl() */
 static	int	debug;
 static	int	prid = 1;
 static	int	datapi;
@@ -2219,6 +2220,8 @@ iawtopctl(SDev *, Cmdbuf *cmd)
 	f = cmd->f;
 	v = 0;
 
+	if (f[0] == nil)
+		return 0;
 	if(strcmp(f[0], "debug") == 0)
 		v = &debug;
 	else if(strcmp(f[0], "idprint") == 0)
@@ -2235,7 +2238,10 @@ iawtopctl(SDev *, Cmdbuf *cmd)
 		*v ^= 1;
 		break;
 	case 2:
-		*v = (strcmp(f[1], "on") == 0);
+		if(f[1])
+			*v = strcmp(f[1], "on") == 0;
+		else
+			*v ^= 1;
 		break;
 	}
 	return 0;

+ 2 - 1
sys/src/9/port/devsd.c

@@ -1250,7 +1250,8 @@ sdwrite(Chan* c, void* a, long n, vlong off)
 			error(Ebadctl);
 		poperror();
 		poperror();
-		decref(&sdev->r);
+		if (sdev)
+			decref(&sdev->r);
 		free(cb);
 		break;
 

+ 4 - 9
sys/src/9/port/taslock.c

@@ -100,7 +100,7 @@ lock(Lock *l)
 				 */
 				print("inversion 0x%lux pc 0x%lux proc %lud held by pc 0x%lux proc %lud\n",
 					l, pc, up ? up->pid : 0, l->pc, l->p ? l->p->pid : 0);
-				up->edf->d = todget(nil);	/* yield to process with lock */ 
+				up->edf->d = todget(nil);	/* yield to process with lock */
 			}
 			if(i++ > 100000000){
 				i = 0;
@@ -138,15 +138,10 @@ ilock(Lock *l)
 	if(tas(&l->key) != 0){
 		lockstats.glare++;
 		/*
-		 * Cannot also check l->pc and l->m here because
-		 * they might just not be set yet, or the lock might 
-		 * even have been let go.
+		 * Cannot also check l->pc, l->m, or l->isilock here
+		 * because they might just not be set yet, or
+		 * (for pc and m) the lock might have just been unlocked.
 		 */
-		if(!l->isilock){
-			dumplockmem("ilock:", l);
-			panic("corrupt ilock %p pc=%luX m=%p isilock=%d", 
-				l, l->pc, l->m, l->isilock);
-		}
 		for(;;){
 			lockstats.inglare++;
 			splx(x);

+ 0 - 22
sys/src/boot/pc/devbios.h

@@ -1,22 +0,0 @@
-typedef uvlong Devbytes, Devsects;
-
-typedef struct Biosdrive Biosdrive;	/* 1 drive -> ndevs */
-typedef struct Biosdev Biosdev;
-
-struct Biosdrive {
-	int	ndevs;
-};
-struct Biosdev {
-	Devbytes size;
-	Devbytes offset;
-	uchar	id;
-	char	type;
-};
-
-int	biosboot(int dev, char *file, Boot *b);
-void*	biosgetfspart(int i, char *name, int chatty);
-void	biosinitdev(int i, char *name);
-int	biosinit(void);
-void	biosprintbootdevs(int dev);
-void	biosprintdevs(int i);
-long	biosread(Fs *fs, void *a, long n);

+ 16 - 4
sys/src/boot/pc/lib.h

@@ -59,24 +59,31 @@ extern	int	fmtinstall(int, int (*)(Fmt*));
 #pragma	varargck	argpos	seprint		3
 #pragma	varargck	argpos	snprint		3
 #pragma	varargck	argpos	sprint		2
-#pragma varargck	type	"H" void*
 
+#pragma varargck	type	"lux"	void*
+#pragma	varargck	type	"E"	uchar*	/* eipfmt */
+
+/* from /sys/include/libc.h */
 #pragma	varargck	type	"lld"	vlong
 #pragma	varargck	type	"llx"	vlong
 #pragma	varargck	type	"lld"	uvlong
 #pragma	varargck	type	"llx"	uvlong
 #pragma	varargck	type	"ld"	long
 #pragma	varargck	type	"lx"	long
+#pragma	varargck	type	"lb"	long
 #pragma	varargck	type	"ld"	ulong
 #pragma	varargck	type	"lx"	ulong
+#pragma	varargck	type	"lb"	ulong
 #pragma	varargck	type	"d"	int
 #pragma	varargck	type	"x"	int
 #pragma	varargck	type	"c"	int
 #pragma	varargck	type	"C"	int
+#pragma	varargck	type	"b"	int
 #pragma	varargck	type	"d"	uint
 #pragma	varargck	type	"x"	uint
 #pragma	varargck	type	"c"	uint
 #pragma	varargck	type	"C"	uint
+#pragma	varargck	type	"b"	uint
 #pragma	varargck	type	"f"	double
 #pragma	varargck	type	"e"	double
 #pragma	varargck	type	"g"	double
@@ -86,10 +93,15 @@ extern	int	fmtinstall(int, int (*)(Fmt*));
 #pragma	varargck	type	"Q"	Rune*
 #pragma	varargck	type	"r"	void
 #pragma	varargck	type	"%"	void
-#pragma	varargck	type	"|"	int
+#pragma	varargck	type	"n"	int*
+#pragma	varargck	type	"p"	uintptr
 #pragma	varargck	type	"p"	void*
-#pragma varargck	type	"lux"	void*
-#pragma	varargck	type	"E"	uchar*
+#pragma	varargck	flag	','
+#pragma	varargck	flag	'h'
+#pragma varargck	type	"<"	void*
+#pragma varargck	type	"["	void*
+#pragma varargck	type	"H"	void*
+#pragma varargck	type	"lH"	void*
 
 #define PRINTSIZE	256
 

+ 48 - 35
sys/src/boot/pc/sdiahci.c

@@ -38,14 +38,16 @@ enum {
 	Tesb,
 	Tich,
 	Tsb600,
+	Tunk,
 };
 
-#define Intel(x)	((x) == Tesb  || (x) == Tich)
+#define Intel(x)	((x)->pci->vid == 0x8086)
 
 static char *tname[] = {
 	"63xxesb",
 	"ich",
 	"sb600",
+	"unk",
 };
 
 enum {
@@ -131,6 +133,7 @@ struct Ctlr {
 	Drive	rawdrive[NCtlrdrv];
 	Drive*	drive[NCtlrdrv];
 	int	ndrive;
+	int	mport;
 };
 
 static	Ctlr	iactlr[NCtlr];
@@ -571,7 +574,7 @@ ahciconfigdrive(Ahba *h, Aportc *c, int mode)
 	}
 
 	if(p->sstatus & 3 && h->cap & Hsss){
-		dprint("configdrive:  spinning up ... [%lux]\n", p->sstatus);
+		dprint("configdrive: spinning up ... [%lux]\n", p->sstatus);
 		p->cmd |= Apod|Asud;
 		asleep(1400);
 	}
@@ -707,8 +710,7 @@ identify(Drive *d)
 	u->inquiry[4] = sizeof u->inquiry - 4;
 	memmove(u->inquiry+8, d->model, 40);
 
-	if((osectors == 0 || osectors != s) &&
-	    memcmp(oserial, d->serial, sizeof oserial) != 0){
+	if(osectors != s || memcmp(oserial, d->serial, sizeof oserial)){
 		d->mediachange = 1;
 		u->sectors = 0;
 	}
@@ -753,8 +755,8 @@ updatedrive(Drive *d)
 		dprint("Fatal\n");
 	}
 	if(cause & Adhrs){
-		if(p->task & (32|1)){
-			dprint("Adhrs cause = %lux; serr = %lux; task=%lux\n",
+		if(p->task & (1<<5|1)){
+			dprint("Adhrs cause %lux serr %lux task %lux\n",
 				cause, serr, p->task);
 			d->portm.flag |= Ferror;
 			ewake = 1;
@@ -810,8 +812,7 @@ pstatus(Drive *d, ulong s)
 	case 0:
 		d->state = Dmissing;
 		break;
-	case 2:			/* should this be missing?  need testcase. */
-		dprint("pstatus 2\n");
+	case 2:
 	case 3:
 		d->wait = 0;
 		d->state = Dnew;
@@ -904,10 +905,8 @@ newdrive(Drive *d)
 	}
 	if(m->feat & Dpower && setfeatures(c, 0x85) == -1){
 		m->feat &= ~Dpower;
-		if(ahcirecover(c) == -1) {
-			dprint("%s: ahcirecover failed\n", name);
+		if(ahcirecover(c) == -1)
 			goto lose;
-		}
 	}
 	if (d->sectors == 0) {
 		idprint("%s: no sectors\n", d->unit->name);
@@ -923,7 +922,7 @@ newdrive(Drive *d)
 	s = "";
 	if(m->feat & Dllba)
 		s = "L";
-	idprint("%s: %sLBA %lld sectors\n", d->unit->name, s, d->sectors);
+	idprint("%s: %sLBA %,llud sectors\n", d->unit->name, s, d->sectors);
 	idprint("  %s %s %s %s\n", d->model, d->firmware, d->serial,
 		d->mediachange? "[mediachange]": "");
 
@@ -1005,7 +1004,7 @@ checkdrive(Drive *d, int i)
 reset:
 			if(++d->mode > DMsataii)
 				d->mode = 0;
-			if(d->mode == DMsatai){	/* we tried everything */
+			if(d->mode == DMsatai){
 				d->state = Dportreset;
 				goto portreset;
 			}
@@ -1072,9 +1071,8 @@ iainterrupt(Ureg*, void *a)
 
 	c = a;
 	ilock(c);
-	/* check drive here! */
 	cause = c->hba->isr;
-	for(i = 0; i < c->ndrive; i++){
+	for(i = 0; i < c->mport; i++){
 		m = 1 << i;
 		if((cause & m) == 0)
 			continue;
@@ -1106,7 +1104,7 @@ iaverify(SDunit *u)
 		checkdrive(d, d->driveno);
 		switch(d->state){
 		case Dmissing:
-			if(i < 4 || d->port->sstatus & 0x733)
+			if(d->port->sstatus & 0x733)
 				break;
 			/* fall through */
 		case Dnull:
@@ -1377,7 +1375,7 @@ retry:
 	iunlock(d);
 
 	if(task & (Efatal<<8) || task & (ASbsy|ASdrq) && d->state == Dready){
-		d->port->ci = 0;		/* @? */
+		d->port->ci = 0;
 		ahcirecover(&d->portc);
 		task = d->port->task;
 	}
@@ -1480,7 +1478,7 @@ iario(SDreq *r)
 
 		if(task & (Efatal<<8) ||
 		    task & (ASbsy|ASdrq) && d->state == Dready){
-			d->port->ci = 0;		/* @? */
+			d->port->ci = 0;
 			ahcirecover(&d->portc);
 			task = d->port->task;
 		}
@@ -1528,6 +1526,32 @@ iasetupahci(Ctlr *c)
 	pcicfgw8(c->pci, 0x90, 1<<6 | 1<<5);
 }
 
+static int
+didtype(Pcidev *p)
+{
+	switch(p->vid){
+	case 0x8086:
+		if((p->did & 0xfffc) == 0x2680)
+			return Tesb;
+		/*
+		 * 0x27c4 is the intel 82801 in compatibility (not sata) mode.
+		 * ich7 is 82801g[bh]m?.
+		 */
+		if ((p->did & 0xfeff) == 0x2829 ||		/* ich8 */
+		    (p->did & 0xfffe) == 0x2922 ||		/* ich9 */
+		    (p->did & 0xfffe) == 0x27c4 || p->did == 0x27c0) /* ich7 */
+			return Tich;
+		break;
+	case 0x1002:
+		if(p->did == 0x4380)
+			return Tsb600;
+		break;
+	}
+	if(p->ccrb == Pcibcstore && p->ccru == 6 && p->ccrp == 1)
+		return Tunk;
+	return -1;
+}
+
 static SDev*
 iapnp(void)
 {
@@ -1542,30 +1566,19 @@ iapnp(void)
 	if (done || getconf("*noahciload") != nil)
 		return nil;
 	done = 1;
+	memset(olds, 0xff, sizeof olds);
 	p = nil;
 	head = tail = nil;
 loop:
 	while((p = pcimatch(p, 0, 0)) != nil){
-		/* 0x27c4 is the intel 82801 in compatibility (not sata) mode */
-		if(p->vid == 0x8086 && (p->did & 0xfffc) == 0x2680)
-			type = Tesb;
-		else if(p->vid == 0x8086 &&
-		    (p->did == 0x27c5 || p->did == 0x27c0))
-			type = Tich;	/* 82801g[bh]m?; compat mode fails */
-		else if(p->vid == 0x8086 && (p->did & 0xfeff) == 0x2829)
-			type = Tich;		/* ich8 */
-		else if(p->vid == 0x8086 && (p->did & 0xfffe) == 0x2922)
-			type = Tich;		/* ich8 */
-		else if(p->vid == 0x1002 && p->did == 0x4380)
-			type = Tsb600;
-		else
+		if((type = didtype(p)) == -1)
 			continue;
 		if(niactlr == NCtlr){
 			print("iapnp: %s: too many controllers\n", tname[type]);
 			break;
 		}
 		c = iactlr + niactlr;
-		s = sdevs  + niactlr;
+		s = sdevs + niactlr;
 		memset(c, 0, sizeof *c);
 		memset(s, 0, sizeof *s);
 		c->pci = p;
@@ -1592,11 +1605,11 @@ loop:
 
 		c->mmio = KADDR(io);
 		c->lmmio = (ulong*)c->mmio;
-		if(Intel(c->type) && p->did != 0x2681)
+		if(Intel(c) && p->did != 0x2681)
 			iasetupahci(c);
 		nunit = ahciconf(c);
 //		ahcihbareset((Ahba*)c->mmio);
-		if(Intel(c->type) && iaahcimode(p) == -1)
+		if(Intel(c) && iaahcimode(p) == -1)
 			break;
 		if(nunit < 1){
 //			vunmap(c->mmio, p->mem[Abar].size);
@@ -1612,6 +1625,7 @@ loop:
 		s->idno = 'E';
 		c->sdev = s;
 		c->ndrive = nunit;
+		c->mport = c->hba->cap & 0x1f;
 
 		/* map the drives -- they don't all need to be enabled. */
 		memset(c->rawdrive, 0, sizeof c->rawdrive);
@@ -1624,7 +1638,6 @@ loop:
 			d->ctlr = c;
 			if((c->hba->pi & (1<<i)) == 0)
 				continue;
-//			d->state = Dnew;
 			d->port = (Aport*)(c->mmio + 0x80*i + 0x100);
 			d->portc.p = d->port;
 			d->portc.m = &d->portm;