kvleonhardt
unread,May 14, 2012, 4:41:15 AM5/14/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to minix3
To visualize the problem please look at following test code (for minix
3.1.8):
Please look at the open command in the vga_transfer function and the
output listed below.
File: vga.c
[code]
#include <minix/drivers.h>
#include <minix/driver.h>
#include <minix/sysutil.h>
#include <minix/safecopies.h>
#include <minix/ds.h>
#include <minix/dmap.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
/*
* Function prototypes for the vga driver.
*/
_PROTOTYPE( PRIVATE char * vga_name, (void) );
_PROTOTYPE( PRIVATE int vga_open, (struct driver *d, message
*m) );
_PROTOTYPE( PRIVATE int vga_close, (struct driver *d, message
*m) );
_PROTOTYPE( PRIVATE struct device * vga_prepare, (int device) );
_PROTOTYPE( PRIVATE int vga_transfer, (int procnr, int opcode, u64_t
position, iovec_t *iov, unsigned nr_req) );
_PROTOTYPE( PRIVATE void vga_geometry, (struct partition *entry) );
/* SEF functions and variables. */
_PROTOTYPE( PRIVATE void sef_local_startup, (void) );
_PROTOTYPE( PRIVATE int sef_cb_init_fresh, (int type, sef_init_info_t
*info) );
_PROTOTYPE( PRIVATE int sef_cb_lu_state_save, (int) );
/* Entry points to the vga driver. */
PRIVATE struct driver vga_tab =
{
vga_name,
vga_open,
vga_close,
nop_ioctl,
vga_prepare,
vga_transfer,
nop_cleanup,
vga_geometry,
nop_alarm,
nop_cancel,
nop_select,
nop_ioctl,
do_nop,
};
PRIVATE struct device vga_device;
/
*===========================================================================*
*
vga_name
*
*===========================================================================*/
PRIVATE char * vga_name(void)
{
printf("vga_name()\n");
return "vga";
}
/
*===========================================================================*
*
vga_open
*
*===========================================================================*/
PRIVATE int vga_open(d, m)
struct driver *d;
message *m;
{
printf("vga_open()\n");
return OK;
}
/
*===========================================================================*
*
vga_close
*
*===========================================================================*/
PRIVATE int vga_close(d, m)
struct driver *d;
message *m;
{
printf("vga_close()\n");
return OK;
}
/
*===========================================================================*
* vga_prepare *
*===========================================================================*/
PRIVATE struct device * vga_prepare(dev)
int dev;
{
vga_device.dv_base.lo = 0;
vga_device.dv_base.hi = 0;
vga_device.dv_size.lo = 0;
vga_device.dv_size.hi = 0;
return &vga_device;
}
/
*===========================================================================*
* vga_transfer *
*===========================================================================*/
PRIVATE int vga_transfer(proc_nr, opcode, position, iov, nr_req)
int proc_nr;
int opcode;
u64_t position;
iovec_t *iov;
unsigned nr_req;
{
static char toggle = 0;
int bytes, ret;
printf("vga_transfer()\n");
switch (opcode)
{
case DEV_GATHER_S:
break;
case DEV_SCATTER_S:
{
int fp;
if ((fp = open("/usr/src/drivers/vga/Farver.bmp", O_RDONLY)) <=
0)
{
printf("Can't open file. (%d)\n", fp);
return 0;
}
}
break;
default:
return EINVAL;
}
return ret;
}
/
*===========================================================================*
*
vga_geometry
*
*===========================================================================*/
PRIVATE void vga_geometry(entry)
struct partition *entry;
{
printf("vga_geometry()\n");
entry->cylinders = 0;
entry->heads = 0;
entry->sectors = 0;
}
/*************************************************************
*
* Function sef_cb_lu_state_save
*
* Descriptions:
* Handler for device driver
*
* Returns: OK
*
*************************************************************/
PRIVATE int sef_cb_lu_state_save(int state)
{
return OK;
}
/*************************************************************
*
* Function lu_state_restore
*
* Descriptions:
* Handler for device driver
*
* Returns: OK
*
*************************************************************/
PRIVATE int lu_state_restore(void)
{
return OK;
}
/
*===========================================================================*
*
sef_local_startup
*
*===========================================================================*/
PRIVATE void sef_local_startup(void)
{
/* Register init callbacks. */
sef_setcb_init_fresh(sef_cb_init_fresh);
sef_setcb_init_lu(sef_cb_init_fresh); /* treat live updates
as fresh inits */
sef_setcb_init_restart(sef_cb_init_fresh); /* treat restarts as
fresh inits */
/* Register live update callbacks. */
sef_setcb_lu_prepare(sef_cb_lu_prepare_always_ready); /*
agree to update immediately when a LU request is received in a
supported state */
sef_setcb_lu_state_isvalid(sef_cb_lu_state_isvalid_standard); /*
support live update starting from any standard state */
/* - Register a custom routine to save the state. */
sef_setcb_lu_state_save(sef_cb_lu_state_save);
/* Let SEF perform startup. */
sef_startup();
}
/
*===========================================================================*
*
sef_cb_init_fresh
*
*===========================================================================*/
PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info)
{
int do_announce_driver = TRUE;
open_counter = 0;
/* Initialize the vga driver. */
switch(type)
{
case SEF_INIT_FRESH:
printf("%s", VGA_MESSAGE);
break;
case SEF_INIT_LU:
lu_state_restore();
do_announce_driver = FALSE;
printf("%sHey, I'm a new version!\n", VGA_MESSAGE);
break;
case SEF_INIT_RESTART:
printf("%sHey, I've just been restarted!\n", VGA_MESSAGE);
break;
}
if(do_announce_driver)
driver_announce();
/* Initialization completed successfully. */
return(OK);
}
/
*===========================================================================*
*
main
*
*===========================================================================*/
PUBLIC int main(int argc, char **argv)
{
/*
* Perform initialization.
*/
sef_local_startup();
/*
* Run the main loop.
*/
driver_task(&vga_tab, DRIVER_STD);
return OK;
}
To test the driver i just send new line to the device handle
echo "" > /dev/vga
and the output is:
May 14 10:36:56 minix kernel: vga_transfer()
May 14 10:36:56 minix kernel: VFS: only the PFS device can make nested
VFS calls
May 14 10:36:56 minix kernel: Can't open file. (-1)
May 14 10:36:56 minix kernel: vga_close()