use servers/inet/mq.[ch] to queue messages using mq_queue() in

libdriver.  at_wini now queues messages it can't handle it receives when
waiting for an interrupt. this way it can do receive(ANY) and timeouts
should be working again (were broken for VFS, as with the advent of VFS,
at_wini could get requests from a filesystem while it was waiting for an
interrupt - as a hack, the receive() was changed to receive(HARDWARE)).

Added mq.c to libdriver, and made libdriver an actual library that
drivers link with -L../libdriver -ldriver. (So adding files, if
necessary, is easier next time.)
This commit is contained in:
Ben Gras 2007-01-12 13:33:12 +00:00
parent 8b3ddfc19f
commit b01aff70d2
13 changed files with 194 additions and 87 deletions

View file

@ -14,22 +14,18 @@ p = ../libpci
MAKE = exec make
CC = exec cc
CFLAGS = -I$i $(CPROFILE)
LDFLAGS = -i
LIBS = -lsysutil -lsys -ltimers
LDFLAGS = -i -L../libdriver
LIBS = -lsysutil -lsys -ltimers -ldriver
OBJ = at_wini.o
LIBDRIVER = $d/libdriver/driver.o $d/libdriver/drvlib.o
# build local binary
all build: $(DRIVER)
$(DRIVER): $(OBJ) $(LIBDRIVER)
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBDRIVER) $(LIBS)
$(DRIVER): $(OBJ)
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS)
install -S 32k $(DRIVER)
$(LIBDRIVER):
cd $d/libdriver && $(MAKE)
# install with other drivers
install: /sbin/$(DRIVER)
/sbin/$(DRIVER): $(DRIVER)

View file

@ -1925,28 +1925,36 @@ PRIVATE void w_intr_wait()
message m;
if (w_wn->irq != NO_IRQ) {
/* Wait for an interrupt that sets w_status to "not busy". */
/* Wait for an interrupt that sets w_status to "not busy".
* (w_timeout() also clears w_status.)
*/
while (w_wn->w_status & (STATUS_ADMBSY|STATUS_BSY)) {
int rr;
if((rr=receive(HARDWARE, &m)) != OK) { /* expect HARD_INT message */
printf("w_intr_wait: receive from ANY failed (%d)\n",
r);
continue; /* try again */
if((rr=receive(ANY, &m)) != OK)
panic("at_wini", "receive(ANY) failed", rr);
switch(m.m_type) {
case SYN_ALARM:
/* Timeout. */
w_timeout(); /* a.o. set w_status */
break;
case HARD_INT:
/* Interrupt. */
r= sys_inb(w_wn->base_cmd + REG_STATUS, &w_status);
if (r != 0)
panic("at_wini", "sys_inb failed", r);
w_wn->w_status= w_status;
ack_irqs(m.NOTIFY_ARG);
break;
case DEV_PING:
/* RS monitor ping. */
notify(m.m_source);
break;
default:
/* unhandled message.
* queue it and handle it in the libdriver loop.
*/
mq_queue(&m);
}
if (m.m_type == SYN_ALARM) { /* but check for timeout */
w_timeout(); /* a.o. set w_status */
} else if (m.m_type == HARD_INT) {
r= sys_inb(w_wn->base_cmd + REG_STATUS, &w_status);
if (r != 0)
panic("at_wini", "sys_inb failed", r);
w_wn->w_status= w_status;
ack_irqs(m.NOTIFY_ARG);
} else if (m.m_type == DEV_PING) {
notify(m.m_source);
} else {
printf("AT_WINI got unexpected message %d from %d\n",
m.m_type, m.m_source);
}
}
} else {
/* Interrupt not yet allocated; use polling. */
@ -2563,4 +2571,6 @@ PRIVATE int atapi_intr_wait()
wn->w_status |= STATUS_ADMBSY; /* Assume not done yet. */
return(r);
}
#endif /* ENABLE_ATAPI */

View file

@ -13,22 +13,17 @@ d = ..
MAKE = exec make
CC = exec cc
CFLAGS = -I$i $(CPROFILE)
LDFLAGS = -i
LIBS = -lsysutil -lsys -ltimers
LDFLAGS = -i -L../libdriver
LIBS = -lsysutil -lsys -ltimers -ldriver
OBJ = bios_wini.o
LIBDRIVER = $d/libdriver/driver.o $d/libdriver/drvlib.o
# build local binary
all build: $(DRIVER)
$(DRIVER): $(OBJ) $(LIBDRIVER)
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBDRIVER) $(LIBS)
$(DRIVER): $(OBJ)
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS)
install -S 8k $(DRIVER)
$(LIBDRIVER):
cd $d/libdriver && $(MAKE)
# install with other drivers
install: /sbin/$(DRIVER)
/sbin/$(DRIVER): $(DRIVER)

View file

@ -13,23 +13,17 @@ d = ..
MAKE = exec make
CC = exec cc
CFLAGS = -I$i $(CPROFILE)
LDFLAGS = -i
LIBS = -lsysutil -lsys
LDFLAGS = -i -L../libdriver
LIBS = -lsysutil -lsys -ldriver
OBJ = cmos.o
LIBDRIVER = $d/libdriver/driver.o
# build local binary
all build: $(DRIVER)
$(DRIVER): $(OBJ) $(LIBDRIVER)
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBDRIVER) $(LIBS)
$(DRIVER): $(OBJ)
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS)
install -S 8k $(DRIVER)
$(LIBDRIVER):
cd $d/libdriver && $(MAKE)
# install with other drivers
install: /sbin/$(DRIVER)
/sbin/$(DRIVER): $(DRIVER)

View file

@ -13,21 +13,17 @@ d = ..
MAKE = exec make
CC = exec cc
CFLAGS = -I$i $(CPROFILE)
LDFLAGS = -i
LIBS = -lsysutil -lsys -ltimers
LDFLAGS = -i -L../libdriver
LIBS = -lsysutil -ldriver -lsys -ltimers
OBJ = floppy.o
LIBDRIVER = $d/libdriver/driver.o $d/libdriver/drvlib.o
# build local binary
all build: $(DRIVER)
$(DRIVER): $(OBJ) $(LIBDRIVER)
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBDRIVER) $(LIBS)
$(DRIVER): $(OBJ)
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS)
install -S 8k $(DRIVER)
$(LIBDRIVER):
cd $d/libdriver && $(MAKE)
# install with other drivers
install: /sbin/$(DRIVER)
/sbin/$(DRIVER): $(DRIVER)

View file

@ -12,15 +12,19 @@ CC = exec cc
CFLAGS = -I$i $(CPROFILE)
LDFLAGS = -i
LIBS = -lsysutil -lsys
LIB = libdriver.a
OBJECTS = driver.o drvlib.o
OBJECTS = driver.o drvlib.o mq.o
all build install: $(OBJECTS)
all build install: $(LIB)
$(LIB): $(OBJECTS)
ar rc $(LIB) $(OBJECTS)
# $(CC) -c $@ $(LDFLAGS) $(OBJ) $(LIBS)
clean:
rm -f *.o *.bak
rm -f *.o *.bak *.a
depend:
/usr/bin/mkdep "$(CC) -E $(CPPFLAGS)" *.c > .depend

View file

@ -39,6 +39,7 @@
#include "../drivers.h"
#include <sys/ioc_disk.h>
#include <minix/mq.h>
#include "driver.h"
#if (CHIP == INTEL)
@ -68,6 +69,7 @@ FORWARD _PROTOTYPE( int do_rdwt, (struct driver *dr, message *mp, int safe) );
FORWARD _PROTOTYPE( int do_vrdwt, (struct driver *dr, message *mp, int safe) );
int device_caller;
PRIVATE mq_t *queue_head = NULL;
/*===========================================================================*
* driver_task *
@ -80,6 +82,9 @@ struct driver *dp; /* Device dependent entry points. */
int r, proc_nr;
message mess;
/* Init MQ library. */
mq_init();
/* Get a DMA buffer. */
init_buffer();
@ -87,9 +92,19 @@ struct driver *dp; /* Device dependent entry points. */
* it out, and sends a reply.
*/
while (TRUE) {
/* Wait for a request to read or write a disk block. */
if (receive(ANY, &mess) != OK) continue;
/* Any queued messages? Oldest are at the head. */
if(queue_head) {
mq_t *mq;
mq = queue_head;
memcpy(&mess, &mq->mq_mess, sizeof(mess));
queue_head = queue_head->mq_next;
mq_free(mq);
} else {
int s;
/* Wait for a request to read or write a disk block. */
if ((s=receive(ANY, &mess)) != OK)
panic((*dp->dr_name)(),"receive() failed", s);
}
device_caller = mess.m_source;
proc_nr = mess.IO_ENDPT;
@ -427,3 +442,26 @@ int safe; /* addresses or grants? */
}
return(OK);
}
/*===========================================================================*
* mq_queue *
*===========================================================================*/
PUBLIC int mq_queue(message *m)
{
mq_t *mq, *mi;
if(!(mq = mq_get()))
panic("libdriver","mq_queue: mq_get failed", NO_NUM);
memcpy(&mq->mq_mess, m, sizeof(mq->mq_mess));
mq->mq_next = NULL;
if(!queue_head) {
queue_head = mq;
} else {
for(mi = queue_head; mi->mq_next; mi = mi->mq_next)
;
mi->mq_next = mq;
}
return OK;
}

View file

@ -74,6 +74,7 @@ _PROTOTYPE( int nop_cancel, (struct driver *dp, message *m_ptr) );
_PROTOTYPE( int nop_select, (struct driver *dp, message *m_ptr) );
_PROTOTYPE( int do_diocntl, (struct driver *dp, message *m_ptr, int safe) );
_PROTOTYPE( int nop_ioctl, (struct driver *dp, message *m_ptr, int safe) );
_PROTOTYPE( int mq_queue, (message *m_ptr) );
/* Parameters for the disk drive. */
#define SECTOR_SIZE 512 /* physical sector size in bytes */

61
drivers/libdriver/mq.c Normal file
View file

@ -0,0 +1,61 @@
/*
inet/mq.c
Created: Jan 3, 1992 by Philip Homburg
Copyright 1995 Philip Homburg
*/
#include <ansi.h>
#include <assert.h>
#include <minix/config.h>
#include <minix/const.h>
#include <minix/type.h>
#include <minix/ipc.h>
#include <minix/mq.h>
#define MQ_SIZE 128
PRIVATE mq_t mq_list[MQ_SIZE];
PRIVATE mq_t *mq_freelist;
void mq_init()
{
int i;
mq_freelist= NULL;
for (i= 0; i<MQ_SIZE; i++)
{
mq_list[i].mq_next= mq_freelist;
mq_freelist= &mq_list[i];
mq_list[i].mq_allocated= 0;
}
}
mq_t *mq_get()
{
mq_t *mq;
mq= mq_freelist;
assert(mq != NULL);
mq_freelist= mq->mq_next;
mq->mq_next= NULL;
assert(mq->mq_allocated == 0);
mq->mq_allocated= 1;
return mq;
}
void mq_free(mq)
mq_t *mq;
{
mq->mq_next= mq_freelist;
mq_freelist= mq;
assert(mq->mq_allocated == 1);
mq->mq_allocated= 0;
}
/*
* $PchId: mq.c,v 1.7 1998/10/23 20:10:47 philip Exp $
*/

View file

@ -12,22 +12,17 @@ d = ..
MAKE = exec make
CC = exec cc
CFLAGS = -I$i $(CPROFILE)
LDFLAGS = -i
LIBS = -lsysutil -lsys
LDFLAGS = -i -L../libdriver
LIBS = -lsysutil -ldriver -lsys
OBJ = log.o diag.o kputc.o
LIBDRIVER = $d/libdriver/driver.o
# build local binary
all build: $(DRIVER)
$(DRIVER): $(OBJ) $(LIBDRIVER)
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBDRIVER) $(LIBS)
$(DRIVER): $(OBJ)
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS)
install -S 16kb $(DRIVER)
$(LIBDRIVER):
cd $d/libdriver && $(MAKE)
# install with other drivers
install: $(DRIVER)
install -o root -cs $? /sbin/$(DRIVER)

View file

@ -13,8 +13,8 @@ d = ..
MAKE = exec make
CC = exec cc
CFLAGS = -I$i
LDFLAGS = -i
LIBS = -lsysutil -lsys
LDFLAGS = -i -L../libdriver
LIBS = -lsysutil -ldriver -lsys
# imgrd_s.s is the ACK assembler version of the ramdisk. For more portability,
# use the C version imgrd.c. However, the C compiler takes too much memory
@ -23,14 +23,12 @@ IMGRD=imgrd_s.o
#IMGRD=imgrd.c
OBJ = memory.o allocmem.o $(IMGRD)
LIBDRIVER = $d/libdriver/driver.o
# build local binary
all build: $(DRIVER)
$(DRIVER): ramdisk_image $(OBJ) $(LIBDRIVER)
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBDRIVER) $(LIBS)
$(DRIVER): ramdisk_image $(OBJ)
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS)
install -S 8k $(DRIVER)
imgrd.o: ramdisk/image.c
@ -38,9 +36,6 @@ imgrd.o: ramdisk/image.c
imgrd_s.o: ramdisk/image.s
TMPDIR=/usr/tmp $(CC) -T /usr/tmp -c imgrd_s.s
$(LIBDRIVER):
cd $d/libdriver && $(MAKE)
ramdisk_image:
cd ramdisk && make

View file

@ -13,22 +13,17 @@ d = ..
MAKE = exec make
CC = exec cc
CFLAGS = -I$i $(CPROFILE)
LDFLAGS = -i
LIBS = -lsysutil -lsys
LDFLAGS = -i -L../libdriver
LIBS = -lsysutil -ldriver -lsys
OBJ = main.o random.o sha2.o aes/rijndael_api.o aes/rijndael_alg.o
LIBDRIVER = $d/libdriver/driver.o
# build local binary
all build: $(DRIVER)
$(DRIVER): $(OBJ) $(LIBDRIVER)
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBDRIVER) $(LIBS)
$(DRIVER): $(OBJ)
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS)
install -S 8k $(DRIVER)
$(LIBDRIVER):
cd $d/libdriver && $(MAKE)
aes/rijndael_api.o:
$(CC) -c -o $@ aes/rijndael_api.c

27
include/minix/mq.h Normal file
View file

@ -0,0 +1,27 @@
/*
inet/mq.h
Created: Jan 3, 1992 by Philip Homburg
Copyright 1995 Philip Homburg
*/
#ifndef INET__MQ_H
#define INET__MQ_H
typedef struct mq
{
message mq_mess;
struct mq *mq_next;
int mq_allocated;
} mq_t;
_PROTOTYPE( mq_t *mq_get, (void) );
_PROTOTYPE( void mq_free, (mq_t *mq) );
_PROTOTYPE( void mq_init, (void) );
#endif /* INET__MQ_H */
/*
* $PchId: mq.h,v 1.4 1995/11/21 06:40:30 philip Exp $
*/