A gnot/scsibuf.c => gnot/scsibuf.c +63 -0
@@ 0,0 1,63 @@
+#include "u.h"
+#include "../port/lib.h"
+#include "mem.h"
+#include "dat.h"
+#include "fns.h"
+#include "../port/error.h"
+#include "io.h"
+
+/*
+ * The following routines
+ * scsibufreset, scsibuf, scsifree and scsialloc
+ * provide a pool of buffers used for scsi i/o.
+ * This is simplistic at best, and opportunities for
+ * deadlock abound.
+ */
+#define Nbuf 2
+
+struct {
+ Lock;
+ Scsibuf *free;
+} scsibufalloc;
+
+void
+scsibufreset(ulong datasize)
+{
+ int i;
+
+ for(i = 0; i < Nbuf; i++)
+ scsifree(scsialloc(datasize));
+ lock(&scsibufalloc);
+ unlock(&scsibufalloc);
+}
+
+/*
+ * get a scsi io buffer of DATASIZE size
+ */
+Scsibuf *
+scsibuf(void)
+{
+ Scsibuf *b;
+
+ for(;;) {
+ lock(&scsibufalloc);
+ b = scsibufalloc.free;
+ if(b != 0) {
+ scsibufalloc.free = b->next;
+ unlock(&scsibufalloc);
+ return b;
+ }
+ unlock(&scsibufalloc);
+ resrcwait(0);
+ }
+ return 0; /* not reached */
+}
+
+void
+scsifree(Scsibuf *b)
+{
+ lock(&scsibufalloc);
+ b->next = scsibufalloc.free;
+ scsibufalloc.free = b;
+ unlock(&scsibufalloc);
+}
M port/devscsi.c => port/devscsi.c +1 -42
@@ 8,15 8,10 @@
#define DPRINT if(debug)kprint
-#define Nbuf 2
#define DATASIZE (32*512)
#undef DATASIZE
#define DATASIZE (64*1024)
-struct{
- Lock;
- Scsibuf *free;
-}scsibufalloc;
static Scsi staticcmd; /* BUG: should be one per scsi device */
@@ 83,12 78,7 @@ scsigen(Chan *c, Dirtab *tab, long ntab, long s, Dir *dp)
void
scsireset(void)
{
- int i;
-
- for(i = 0; i < Nbuf; i++)
- scsifree(scsialloc(DATASIZE));
- lock(&scsibufalloc);
- unlock(&scsibufalloc);
+ scsibufreset(DATASIZE);
resetscsi();
}
@@ 543,34 533,3 @@ scsibwrite(int dev, Scsibuf *b, long n, long blocksize, long blockno)
qunlock(cmd);
return n;
}
-
-/*
- * get a scsi io buffer of DATASIZE size
- */
-Scsibuf *
-scsibuf(void)
-{
- Scsibuf *b;
-
- for(;;) {
- lock(&scsibufalloc);
- b = scsibufalloc.free;
- if(b != 0) {
- scsibufalloc.free = b->next;
- unlock(&scsibufalloc);
- return b;
- }
- unlock(&scsibufalloc);
- resrcwait(0);
- }
- return 0; /* not reached */
-}
-
-void
-scsifree(Scsibuf *b)
-{
- lock(&scsibufalloc);
- b->next = scsibufalloc.free;
- scsibufalloc.free = b;
- unlock(&scsibufalloc);
-}
M port/portfns.h => port/portfns.h +1 -0
@@ 203,6 203,7 @@ int screenbits(void);
Scsibuf* scsialloc(ulong);
int scsibread(int, Scsibuf*, long, long, long);
Scsibuf* scsibuf(void);
+void scsibufreset(ulong);
int scsibwrite(int, Scsibuf*, long, long, long);
int scsicap(int, void*);
Scsi* scsicmd(int, int, Scsibuf*, long);
M ss/main.c => ss/main.c +1 -1
@@ 420,7 420,7 @@ confinit(void)
v = mempres[i];
for(j=i+1; j<sparam->memscan && mempres[j]>v; j++)
v = mempres[j];
- npg = ((v+1)-mempres[i])*MB/BY2PG;
+ npg = (j-i)*MB/BY2PG;
if(conf.npage0 == 0){
conf.base0 = i*MB;
conf.npage0 = npg;
A ss/scsibuf.c => ss/scsibuf.c +63 -0
@@ 0,0 1,63 @@
+#include "u.h"
+#include "../port/lib.h"
+#include "mem.h"
+#include "dat.h"
+#include "fns.h"
+#include "../port/error.h"
+#include "io.h"
+
+/*
+ * The following routines
+ * scsibufreset, scsibuf, scsifree and scsialloc
+ * provide a pool of buffers used for scsi i/o.
+ * This is simplistic at best, and opportunities for
+ * deadlock abound.
+ */
+#define Nbuf 2
+
+struct {
+ Lock;
+ Scsibuf *free;
+} scsibufalloc;
+
+void
+scsibufreset(ulong datasize)
+{
+ int i;
+
+ for(i = 0; i < Nbuf; i++)
+ scsifree(scsialloc(datasize));
+ lock(&scsibufalloc);
+ unlock(&scsibufalloc);
+}
+
+/*
+ * get a scsi io buffer of DATASIZE size
+ */
+Scsibuf *
+scsibuf(void)
+{
+ Scsibuf *b;
+
+ for(;;) {
+ lock(&scsibufalloc);
+ b = scsibufalloc.free;
+ if(b != 0) {
+ scsibufalloc.free = b->next;
+ unlock(&scsibufalloc);
+ return b;
+ }
+ unlock(&scsibufalloc);
+ resrcwait(0);
+ }
+ return 0; /* not reached */
+}
+
+void
+scsifree(Scsibuf *b)
+{
+ lock(&scsibufalloc);
+ b->next = scsibufalloc.free;
+ scsibufalloc.free = b;
+ unlock(&scsibufalloc);
+}