2005-04-21 16:53:53 +02:00
|
|
|
/* This file contains the table with device <-> driver mappings. It also
|
|
|
|
* contains some routines to dynamically add and/ or remove device drivers
|
2012-02-13 16:28:04 +01:00
|
|
|
* or change mappings.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fs.h"
|
|
|
|
#include <string.h>
|
2005-08-03 18:06:35 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
2005-06-02 14:43:21 +02:00
|
|
|
#include <unistd.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include <minix/com.h>
|
2007-08-07 14:52:47 +02:00
|
|
|
#include <minix/ds.h>
|
2012-02-13 16:28:04 +01:00
|
|
|
#include "fproc.h"
|
|
|
|
#include "dmap.h"
|
2005-08-02 17:29:17 +02:00
|
|
|
#include "param.h"
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2010-04-09 23:56:44 +02:00
|
|
|
/* The order of the entries in the table determines the mapping between major
|
|
|
|
* device numbers and device drivers. Character and block devices
|
|
|
|
* can be intermixed at random. The ordering determines the device numbers in
|
2012-02-13 16:28:04 +01:00
|
|
|
* /dev. Note that the major device numbers used in /dev are NOT the same as
|
2010-04-09 23:56:44 +02:00
|
|
|
* the process numbers of the device drivers. See <minix/dmap.h> for mappings.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2010-04-09 23:56:44 +02:00
|
|
|
|
|
|
|
struct dmap dmap[NR_DEVICES];
|
|
|
|
|
|
|
|
#define DT_EMPTY { no_dev, no_dev_io, NONE, "", 0, STYLE_NDEV, NULL }
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2007-08-07 14:52:47 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_mapdriver *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_mapdriver()
|
2007-08-07 14:52:47 +02:00
|
|
|
{
|
2012-02-13 16:28:04 +01:00
|
|
|
/* Create a device->driver mapping. RS will tell us which major is driven by
|
|
|
|
* this driver, what type of device it is (regular, TTY, asynchronous, clone,
|
|
|
|
* etc), and its label. This label is registered with DS, and allows us to
|
|
|
|
* retrieve the driver's endpoint.
|
|
|
|
*/
|
2012-04-13 14:50:38 +02:00
|
|
|
int r, flags, major, style;
|
2012-02-13 16:28:04 +01:00
|
|
|
endpoint_t endpoint;
|
|
|
|
vir_bytes label_vir;
|
|
|
|
size_t label_len;
|
|
|
|
char label[LABEL_MAX];
|
2007-08-07 14:52:47 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
/* Only RS can map drivers. */
|
|
|
|
if (who_e != RS_PROC_NR) return(EPERM);
|
2007-08-07 14:52:47 +02:00
|
|
|
|
2012-04-13 14:50:38 +02:00
|
|
|
label_vir = (vir_bytes) job_m_in.md_label;
|
|
|
|
label_len = (size_t) job_m_in.md_label_len;
|
|
|
|
major = job_m_in.md_major;
|
|
|
|
flags = job_m_in.md_flags;
|
|
|
|
style = job_m_in.md_style;
|
2007-08-07 14:52:47 +02:00
|
|
|
|
2012-04-13 14:50:38 +02:00
|
|
|
/* Get the label */
|
2012-02-13 16:28:04 +01:00
|
|
|
if (label_len+1 > sizeof(label)) { /* Can we store this label? */
|
|
|
|
printf("VFS: do_mapdriver: label too long\n");
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
r = sys_vircopy(who_e, D, label_vir, SELF, D, (vir_bytes) label, label_len);
|
|
|
|
if (r != OK) {
|
|
|
|
printf("VFS: do_mapdriver: sys_vircopy failed: %d\n", r);
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
label[label_len] = '\0'; /* Terminate label */
|
2007-08-07 14:52:47 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
/* Now we know how the driver is called, fetch its endpoint */
|
|
|
|
r = ds_retrieve_label_endpt(label, &endpoint);
|
|
|
|
if (r != OK) {
|
|
|
|
printf("VFS: do_mapdriver: label '%s' unknown\n", label);
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
2007-08-07 14:52:47 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
/* Try to update device mapping. */
|
2012-04-13 14:50:38 +02:00
|
|
|
return map_driver(label, major, endpoint, style, flags);
|
2007-08-07 14:52:47 +02:00
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* map_driver *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int map_driver(label, major, proc_nr_e, style, flags)
|
2010-04-13 12:58:41 +02:00
|
|
|
const char *label; /* name of the driver */
|
2007-08-07 14:52:47 +02:00
|
|
|
int major; /* major number of the device */
|
|
|
|
endpoint_t proc_nr_e; /* process number of the driver */
|
|
|
|
int style; /* style of the device */
|
2010-04-09 23:56:44 +02:00
|
|
|
int flags; /* device flags */
|
2007-08-07 14:52:47 +02:00
|
|
|
{
|
2012-02-13 16:28:04 +01:00
|
|
|
/* Add a new device driver mapping in the dmap table. If the proc_nr is set to
|
|
|
|
* NONE, we're supposed to unmap it.
|
2007-08-07 14:52:47 +02:00
|
|
|
*/
|
2012-02-13 16:28:04 +01:00
|
|
|
|
2012-04-02 17:20:05 +02:00
|
|
|
int slot, s;
|
2007-08-07 14:52:47 +02:00
|
|
|
size_t len;
|
|
|
|
struct dmap *dp;
|
2012-04-02 17:20:05 +02:00
|
|
|
struct fproc *rfp;
|
2007-08-07 14:52:47 +02:00
|
|
|
|
|
|
|
/* Get pointer to device entry in the dmap table. */
|
|
|
|
if (major < 0 || major >= NR_DEVICES) return(ENODEV);
|
2012-02-13 16:28:04 +01:00
|
|
|
dp = &dmap[major];
|
2007-08-07 14:52:47 +02:00
|
|
|
|
2010-04-09 23:56:44 +02:00
|
|
|
/* Check if we're supposed to unmap it. */
|
2012-02-13 16:28:04 +01:00
|
|
|
if (proc_nr_e == NONE) {
|
2007-08-07 14:52:47 +02:00
|
|
|
dp->dmap_opcl = no_dev;
|
|
|
|
dp->dmap_io = no_dev_io;
|
|
|
|
dp->dmap_driver = NONE;
|
2010-04-09 23:56:44 +02:00
|
|
|
dp->dmap_flags = flags;
|
2007-08-07 14:52:47 +02:00
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
/* Check process number of new driver if it was alive before mapping */
|
2012-04-02 17:20:05 +02:00
|
|
|
s = isokendpt(proc_nr_e, &slot);
|
|
|
|
if (s != OK) {
|
|
|
|
/* This is not a problem only when we force this driver mapping */
|
|
|
|
if (! (flags & DRV_FORCED))
|
2007-08-07 14:52:47 +02:00
|
|
|
return(EINVAL);
|
2012-04-02 17:20:05 +02:00
|
|
|
} else {
|
2012-02-13 16:28:04 +01:00
|
|
|
rfp = &fproc[slot];
|
|
|
|
rfp->fp_flags |= FP_SYS_PROC; /* Process is a driver */
|
2007-08-07 14:52:47 +02:00
|
|
|
}
|
|
|
|
|
2010-01-05 20:39:27 +01:00
|
|
|
if (label != NULL) {
|
2012-02-13 16:28:04 +01:00
|
|
|
len = strlen(label);
|
2010-01-05 20:39:27 +01:00
|
|
|
if (len+1 > sizeof(dp->dmap_label))
|
2012-02-13 16:28:04 +01:00
|
|
|
panic("VFS: map_driver: label too long: %d", len);
|
2010-01-05 20:39:27 +01:00
|
|
|
strcpy(dp->dmap_label, label);
|
|
|
|
}
|
2007-08-07 14:52:47 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
/* Store driver I/O routines based on type of device */
|
2007-08-07 14:52:47 +02:00
|
|
|
switch (style) {
|
2012-02-13 16:28:04 +01:00
|
|
|
case STYLE_DEV:
|
2010-04-09 23:56:44 +02:00
|
|
|
dp->dmap_opcl = gen_opcl;
|
|
|
|
dp->dmap_io = gen_io;
|
|
|
|
break;
|
2012-02-13 16:28:04 +01:00
|
|
|
case STYLE_DEVA:
|
2010-04-09 23:56:44 +02:00
|
|
|
dp->dmap_opcl = gen_opcl;
|
|
|
|
dp->dmap_io = asyn_io;
|
|
|
|
break;
|
2012-02-13 16:28:04 +01:00
|
|
|
case STYLE_TTY:
|
2010-04-09 23:56:44 +02:00
|
|
|
dp->dmap_opcl = tty_opcl;
|
|
|
|
dp->dmap_io = gen_io;
|
|
|
|
break;
|
2012-02-13 16:28:04 +01:00
|
|
|
case STYLE_CTTY:
|
2010-04-09 23:56:44 +02:00
|
|
|
dp->dmap_opcl = ctty_opcl;
|
|
|
|
dp->dmap_io = ctty_io;
|
|
|
|
break;
|
2012-02-13 16:28:04 +01:00
|
|
|
case STYLE_CLONE:
|
2010-04-09 23:56:44 +02:00
|
|
|
dp->dmap_opcl = clone_opcl;
|
|
|
|
dp->dmap_io = gen_io;
|
|
|
|
break;
|
2012-02-13 16:28:04 +01:00
|
|
|
case STYLE_CLONE_A:
|
|
|
|
dp->dmap_opcl = clone_opcl;
|
|
|
|
dp->dmap_io = asyn_io;
|
|
|
|
break;
|
|
|
|
default:
|
2010-04-09 23:56:44 +02:00
|
|
|
return(EINVAL);
|
2007-08-07 14:52:47 +02:00
|
|
|
}
|
2012-02-13 16:28:04 +01:00
|
|
|
|
2007-08-07 14:52:47 +02:00
|
|
|
dp->dmap_driver = proc_nr_e;
|
2010-04-09 23:56:44 +02:00
|
|
|
dp->dmap_flags = flags;
|
|
|
|
dp->dmap_style = style;
|
2008-02-22 16:01:00 +01:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
return(OK);
|
2007-08-07 14:52:47 +02:00
|
|
|
}
|
|
|
|
|
2005-10-05 17:38:15 +02:00
|
|
|
/*===========================================================================*
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
* dmap_unmap_by_endpt *
|
2005-10-05 17:38:15 +02:00
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
void dmap_unmap_by_endpt(endpoint_t proc_e)
|
2005-10-05 17:38:15 +02:00
|
|
|
{
|
2012-02-13 16:28:04 +01:00
|
|
|
/* Lookup driver in dmap table by endpoint and unmap it */
|
|
|
|
int major, r;
|
|
|
|
|
|
|
|
for (major = 0; major < NR_DEVICES; major++) {
|
|
|
|
if (dmap_driver_match(proc_e, major)) {
|
|
|
|
/* Found driver; overwrite it with a NULL entry */
|
|
|
|
if ((r = map_driver(NULL, major, NONE, 0, 0)) != OK) {
|
|
|
|
printf("VFS: unmapping driver %d for major %d failed:"
|
|
|
|
" %d\n", proc_e, major, r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-10-05 17:38:15 +02:00
|
|
|
}
|
|
|
|
|
2010-04-09 23:56:44 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* map_service *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int map_service(struct rprocpub *rpub)
|
2010-04-09 23:56:44 +02:00
|
|
|
{
|
|
|
|
/* Map a new service by storing its device driver properties. */
|
|
|
|
int r;
|
|
|
|
|
|
|
|
/* Not a driver, nothing more to do. */
|
2012-02-13 16:28:04 +01:00
|
|
|
if(rpub->dev_nr == NO_DEV) return(OK);
|
2010-04-09 23:56:44 +02:00
|
|
|
|
|
|
|
/* Map driver. */
|
2012-02-13 16:28:04 +01:00
|
|
|
r = map_driver(rpub->label, rpub->dev_nr, rpub->endpoint, rpub->dev_style,
|
|
|
|
rpub->dev_flags);
|
|
|
|
if(r != OK) return(r);
|
2010-04-09 23:56:44 +02:00
|
|
|
|
|
|
|
/* If driver has two major numbers associated, also map the other one. */
|
|
|
|
if(rpub->dev_style2 != STYLE_NDEV) {
|
|
|
|
r = map_driver(rpub->label, rpub->dev_nr+1, rpub->endpoint,
|
2012-02-13 16:28:04 +01:00
|
|
|
rpub->dev_style2, rpub->dev_flags);
|
|
|
|
if(r != OK) return(r);
|
2010-04-09 23:56:44 +02:00
|
|
|
}
|
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
return(OK);
|
2010-04-09 23:56:44 +02:00
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
2012-02-13 16:28:04 +01:00
|
|
|
* init_dmap *
|
2005-04-21 16:53:53 +02:00
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
void init_dmap()
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2010-04-09 23:56:44 +02:00
|
|
|
/* Initialize the table with empty device <-> driver mappings. */
|
2006-03-15 16:34:12 +01:00
|
|
|
int i;
|
2010-04-09 23:56:44 +02:00
|
|
|
struct dmap dmap_default = DT_EMPTY;
|
2005-08-05 20:57:20 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
for (i = 0; i < NR_DEVICES; i++)
|
2010-04-09 23:56:44 +02:00
|
|
|
dmap[i] = dmap_default;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2005-10-20 21:39:32 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* dmap_driver_match *
|
2012-02-13 16:28:04 +01:00
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int dmap_driver_match(endpoint_t proc, int major)
|
2005-10-20 21:39:32 +02:00
|
|
|
{
|
2012-02-13 16:28:04 +01:00
|
|
|
if (major < 0 || major >= NR_DEVICES) return(0);
|
|
|
|
if (dmap[major].dmap_driver != NONE && dmap[major].dmap_driver == proc)
|
|
|
|
return(1);
|
|
|
|
|
|
|
|
return(0);
|
2005-10-20 21:39:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
* dmap_endpt_up *
|
2012-02-13 16:28:04 +01:00
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
void dmap_endpt_up(endpoint_t proc_e, int is_blk)
|
2005-10-20 21:39:32 +02:00
|
|
|
{
|
2012-02-13 16:28:04 +01:00
|
|
|
/* A device driver with endpoint proc_e has been restarted. Go tell everyone
|
|
|
|
* that might be blocking on it that this device is 'up'.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int major;
|
|
|
|
for (major = 0; major < NR_DEVICES; major++) {
|
|
|
|
if (dmap_driver_match(proc_e, major)) {
|
|
|
|
if (is_blk)
|
|
|
|
bdev_up(major);
|
|
|
|
else
|
|
|
|
cdev_up(major);
|
2005-10-20 21:39:32 +02:00
|
|
|
}
|
2012-02-13 16:28:04 +01:00
|
|
|
}
|
2005-10-20 21:39:32 +02:00
|
|
|
}
|
2011-04-13 15:25:34 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* get_dmap *
|
2012-02-13 16:28:04 +01:00
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
struct dmap *get_dmap(endpoint_t proc_e)
|
2011-04-13 15:25:34 +02:00
|
|
|
{
|
|
|
|
/* See if 'proc_e' endpoint belongs to a valid dmap entry. If so, return a
|
|
|
|
* pointer */
|
|
|
|
|
|
|
|
int major;
|
|
|
|
for (major = 0; major < NR_DEVICES; major++)
|
2012-02-13 16:28:04 +01:00
|
|
|
if (dmap_driver_match(proc_e, major))
|
|
|
|
return(&dmap[major]);
|
2011-04-13 15:25:34 +02:00
|
|
|
|
|
|
|
return(NULL);
|
|
|
|
}
|