diff options
author | peter <peter@FreeBSD.org> | 2001-02-07 07:05:59 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 2001-02-07 07:05:59 +0000 |
commit | d4473642637e5eadfea57b93316a31adcf33e702 (patch) | |
tree | 7daf0a32251f6c943f48831c9250eaf0e77a3776 /sys/cam | |
parent | 2b52ef3ebe9d93d57501db078ac5327c92971919 (diff) | |
download | FreeBSD-src-d4473642637e5eadfea57b93316a31adcf33e702.zip FreeBSD-src-d4473642637e5eadfea57b93316a31adcf33e702.tar.gz |
Change the peripheral driver list from a linker set to module driven
driver registration. This should allow things like da, sa, cd etc to be
in seperate KLD's to the cam core and make them preloadable.
Diffstat (limited to 'sys/cam')
-rw-r--r-- | sys/cam/cam_periph.c | 32 | ||||
-rw-r--r-- | sys/cam/cam_periph.h | 25 | ||||
-rw-r--r-- | sys/cam/cam_xpt.c | 16 | ||||
-rw-r--r-- | sys/cam/scsi/scsi_cd.c | 2 | ||||
-rw-r--r-- | sys/cam/scsi/scsi_ch.c | 2 | ||||
-rw-r--r-- | sys/cam/scsi/scsi_da.c | 2 | ||||
-rw-r--r-- | sys/cam/scsi/scsi_pass.c | 2 | ||||
-rw-r--r-- | sys/cam/scsi/scsi_pt.c | 2 | ||||
-rw-r--r-- | sys/cam/scsi/scsi_sa.c | 2 | ||||
-rw-r--r-- | sys/cam/scsi/scsi_ses.c | 2 | ||||
-rw-r--r-- | sys/cam/scsi/scsi_targ_bh.c | 2 | ||||
-rw-r--r-- | sys/cam/scsi/scsi_target.c | 2 |
12 files changed, 65 insertions, 26 deletions
diff --git a/sys/cam/cam_periph.c b/sys/cam/cam_periph.c index 675859c..eba1787 100644 --- a/sys/cam/cam_periph.c +++ b/sys/cam/cam_periph.c @@ -63,6 +63,29 @@ static void camperiphdone(struct cam_periph *periph, union ccb *done_ccb); static void camperiphfree(struct cam_periph *periph); +static int nperiph_drivers; +struct periph_driver **periph_drivers; + +void +periphdriver_register(void *data) +{ + struct periph_driver **newdrivers, **old; + int ndrivers; + + ndrivers = nperiph_drivers + 2; + newdrivers = malloc(sizeof(*newdrivers) * ndrivers, M_TEMP, M_WAITOK); + if (periph_drivers) + bcopy(periph_drivers, newdrivers, + sizeof(*newdrivers) * ndrivers); + newdrivers[nperiph_drivers] = (struct periph_driver *)data; + newdrivers[nperiph_drivers + 1] = NULL; + old = periph_drivers; + periph_drivers = newdrivers; + if (old) + free(old, M_TEMP); + nperiph_drivers++; +} + cam_status cam_periph_alloc(periph_ctor_t *periph_ctor, periph_oninv_t *periph_oninvalidate, @@ -112,8 +135,7 @@ cam_periph_alloc(periph_ctor_t *periph_ctor, init_level++; - for (p_drv = (struct periph_driver **)periphdriver_set.ls_items; - *p_drv != NULL; p_drv++) { + for (p_drv = periph_drivers; *p_drv != NULL; p_drv++) { if (strcmp((*p_drv)->driver_name, name) == 0) break; } @@ -201,8 +223,7 @@ cam_periph_find(struct cam_path *path, char *name) struct cam_periph *periph; int s; - for (p_drv = (struct periph_driver **)periphdriver_set.ls_items; - *p_drv != NULL; p_drv++) { + for (p_drv = periph_drivers; *p_drv != NULL; p_drv++) { if (name != NULL && (strcmp((*p_drv)->driver_name, name) != 0)) continue; @@ -401,8 +422,7 @@ camperiphfree(struct cam_periph *periph) int s; struct periph_driver **p_drv; - for (p_drv = (struct periph_driver **)periphdriver_set.ls_items; - *p_drv != NULL; p_drv++) { + for (p_drv = periph_drivers; *p_drv != NULL; p_drv++) { if (strcmp((*p_drv)->driver_name, periph->periph_name) == 0) break; } diff --git a/sys/cam/cam_periph.h b/sys/cam/cam_periph.h index 54c549c..ac32256 100644 --- a/sys/cam/cam_periph.h +++ b/sys/cam/cam_periph.h @@ -37,7 +37,30 @@ extern struct cam_periph *xpt_periph; -extern struct linker_set periphdriver_set; +extern struct periph_driver **periph_drivers; +void periphdriver_register(void *); + +#include <sys/module.h> +#define PERIPHDRIVER_DECLARE(name, driver) \ + static int name ## _modevent(module_t mod, int type, void *data) \ + { \ + switch (type) { \ + case MOD_LOAD: \ + periphdriver_register(data); \ + break; \ + case MOD_UNLOAD: \ + printf(#name " module unload - not possible for this module type\n"); \ + return EINVAL; \ + } \ + return 0; \ + } \ + static moduledata_t name ## _mod = { \ + #name, \ + name ## _modevent, \ + (void *)&driver \ + }; \ + DECLARE_MODULE(name, name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY); \ + MODULE_DEPEND(name, cam, 1, 1, 1) typedef void (periph_init_t)(void); /* * Callback informing the peripheral driver diff --git a/sys/cam/cam_xpt.c b/sys/cam/cam_xpt.c index 142fdf4..8e8a49b 100644 --- a/sys/cam/cam_xpt.c +++ b/sys/cam/cam_xpt.c @@ -576,8 +576,8 @@ static struct periph_driver probe_driver = TAILQ_HEAD_INITIALIZER(probe_driver.units) }; -DATA_SET(periphdriver_set, xpt_driver); -DATA_SET(periphdriver_set, probe_driver); +PERIPHDRIVER_DECLARE(xpt, xpt_driver); +PERIPHDRIVER_DECLARE(probe, probe_driver); #define XPT_CDEV_MAJOR 104 @@ -1167,8 +1167,7 @@ ptstartover: cur_generation = xsoftc.generation; /* first find our driver in the list of drivers */ - for (p_drv = (struct periph_driver **)periphdriver_set.ls_items; - *p_drv != NULL; p_drv++) + for (p_drv = periph_drivers; *p_drv != NULL; p_drv++) if (strcmp((*p_drv)->driver_name, name) == 0) break; @@ -2342,9 +2341,7 @@ xptplistperiphfunc(struct cam_periph *periph, void *arg) * peripheral driver linker set entry would cost * more in the long run than doing this quick lookup. */ - for (pdrv = - (struct periph_driver **)periphdriver_set.ls_items; - *pdrv != NULL; pdrv++) { + for (pdrv = periph_drivers; *pdrv != NULL; pdrv++) { if (strcmp((*pdrv)->driver_name, periph->periph_name) == 0) break; @@ -2546,8 +2543,7 @@ xptpdrvtraverse(struct periph_driver **start_pdrv, * change while the system is running), the list traversal should * be modified to work like the other traversal functions. */ - for (pdrv = (start_pdrv ? start_pdrv : - (struct periph_driver **)periphdriver_set.ls_items); + for (pdrv = (start_pdrv ? start_pdrv : periph_drivers); *pdrv != NULL; pdrv++) { retval = tr_func(pdrv, arg); @@ -6210,7 +6206,7 @@ xpt_finishconfig(struct cam_periph *periph, union ccb *done_ccb) if (busses_to_config == 0) { /* Register all the peripheral drivers */ /* XXX This will have to change when we have loadable modules */ - p_drv = (struct periph_driver **)periphdriver_set.ls_items; + p_drv = periph_drivers; for (i = 0; p_drv[i] != NULL; i++) { (*p_drv[i]->init)(); } diff --git a/sys/cam/scsi/scsi_cd.c b/sys/cam/scsi/scsi_cd.c index 57873bb..cf6482e 100644 --- a/sys/cam/scsi/scsi_cd.c +++ b/sys/cam/scsi/scsi_cd.c @@ -245,7 +245,7 @@ static struct periph_driver cddriver = TAILQ_HEAD_INITIALIZER(cddriver.units), /* generation */ 0 }; -DATA_SET(periphdriver_set, cddriver); +PERIPHDRIVER_DECLARE(cd, cddriver); /* For 2.2-stable support */ #ifndef D_DISK diff --git a/sys/cam/scsi/scsi_ch.c b/sys/cam/scsi/scsi_ch.c index 25f6cdd..2923ab2 100644 --- a/sys/cam/scsi/scsi_ch.c +++ b/sys/cam/scsi/scsi_ch.c @@ -209,7 +209,7 @@ static struct periph_driver chdriver = TAILQ_HEAD_INITIALIZER(chdriver.units), /* generation */ 0 }; -DATA_SET(periphdriver_set, chdriver); +PERIPHDRIVER_DECLARE(ch, chdriver); static struct cdevsw ch_cdevsw = { /* open */ chopen, diff --git a/sys/cam/scsi/scsi_da.c b/sys/cam/scsi/scsi_da.c index 70385c7..cdd70d2 100644 --- a/sys/cam/scsi/scsi_da.c +++ b/sys/cam/scsi/scsi_da.c @@ -299,7 +299,7 @@ static struct periph_driver dadriver = TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0 }; -DATA_SET(periphdriver_set, dadriver); +PERIPHDRIVER_DECLARE(da, dadriver); #define DA_CDEV_MAJOR 13 #define DA_BDEV_MAJOR 4 diff --git a/sys/cam/scsi/scsi_pass.c b/sys/cam/scsi/scsi_pass.c index d329fc5..791a71d 100644 --- a/sys/cam/scsi/scsi_pass.c +++ b/sys/cam/scsi/scsi_pass.c @@ -107,7 +107,7 @@ static struct periph_driver passdriver = TAILQ_HEAD_INITIALIZER(passdriver.units), /* generation */ 0 }; -DATA_SET(periphdriver_set, passdriver); +PERIPHDRIVER_DECLARE(pass, passdriver); static struct cdevsw pass_cdevsw = { /* open */ passopen, diff --git a/sys/cam/scsi/scsi_pt.c b/sys/cam/scsi/scsi_pt.c index 541964f..beec14d 100644 --- a/sys/cam/scsi/scsi_pt.c +++ b/sys/cam/scsi/scsi_pt.c @@ -114,7 +114,7 @@ static struct periph_driver ptdriver = TAILQ_HEAD_INITIALIZER(ptdriver.units), /* generation */ 0 }; -DATA_SET(periphdriver_set, ptdriver); +PERIPHDRIVER_DECLARE(pt, ptdriver); #define PT_CDEV_MAJOR 61 diff --git a/sys/cam/scsi/scsi_sa.c b/sys/cam/scsi/scsi_sa.c index 99b204d..0418f44 100644 --- a/sys/cam/scsi/scsi_sa.c +++ b/sys/cam/scsi/scsi_sa.c @@ -402,7 +402,7 @@ static struct periph_driver sadriver = TAILQ_HEAD_INITIALIZER(sadriver.units), /* generation */ 0 }; -DATA_SET(periphdriver_set, sadriver); +PERIPHDRIVER_DECLARE(sa, sadriver); /* For 2.2-stable support */ #ifndef D_TAPE diff --git a/sys/cam/scsi/scsi_ses.c b/sys/cam/scsi/scsi_ses.c index 6d7c4d1..d2ab63d 100644 --- a/sys/cam/scsi/scsi_ses.c +++ b/sys/cam/scsi/scsi_ses.c @@ -173,7 +173,7 @@ static struct periph_driver sesdriver = { TAILQ_HEAD_INITIALIZER(sesdriver.units), /* generation */ 0 }; -DATA_SET(periphdriver_set, sesdriver); +PERIPHDRIVER_DECLARE(ses, sesdriver); static struct cdevsw ses_cdevsw = { diff --git a/sys/cam/scsi/scsi_targ_bh.c b/sys/cam/scsi/scsi_targ_bh.c index 82a4264..95f2631 100644 --- a/sys/cam/scsi/scsi_targ_bh.c +++ b/sys/cam/scsi/scsi_targ_bh.c @@ -149,7 +149,7 @@ static struct periph_driver targbhdriver = TAILQ_HEAD_INITIALIZER(targbhdriver.units), /* generation */ 0 }; -DATA_SET(periphdriver_set, targbhdriver); +PERIPHDRIVER_DECLARE(targbh, targbhdriver); static void targbhinit(void) diff --git a/sys/cam/scsi/scsi_target.c b/sys/cam/scsi/scsi_target.c index fd3ea00..cad49a3 100644 --- a/sys/cam/scsi/scsi_target.c +++ b/sys/cam/scsi/scsi_target.c @@ -228,7 +228,7 @@ static struct periph_driver targdriver = TAILQ_HEAD_INITIALIZER(targdriver.units), /* generation */ 0 }; -DATA_SET(periphdriver_set, targdriver); +PERIPHDRIVER_DECLARE(targ, targdriver); static struct extend_array *targperiphs; static dev_t targ_ctl_dev; |