stand: create devinit

devinit() marches through all the devices, calling the inint routines if
any exist. Replace all the identical copies of this code.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37349
This commit is contained in:
Warner Losh 2022-11-30 15:09:29 -07:00
parent daaf594e84
commit 66012c8fc4
8 changed files with 32 additions and 27 deletions

View File

@ -991,9 +991,7 @@ main(int argc, CHAR16 *argv[])
"failures\n", i); "failures\n", i);
} }
for (i = 0; devsw[i] != NULL; i++) devinit();
if (devsw[i]->dv_init != NULL)
(devsw[i]->dv_init)();
/* /*
* Detect console settings two different ways: one via the command * Detect console settings two different ways: one via the command

View File

@ -96,8 +96,6 @@ ptov(uintptr_t x)
int int
main(void) main(void)
{ {
int i;
/* Pick up arguments */ /* Pick up arguments */
kargs = (void *)__args; kargs = (void *)__args;
initial_howto = kargs->howto; initial_howto = kargs->howto;
@ -244,12 +242,7 @@ main(void)
import_geli_boot_data(gbdata); import_geli_boot_data(gbdata);
#endif /* LOADER_GELI_SUPPORT */ #endif /* LOADER_GELI_SUPPORT */
/* devinit();
* March through the device switch probing for things.
*/
for (i = 0; devsw[i] != NULL; i++)
if (devsw[i]->dv_init != NULL)
(devsw[i]->dv_init)();
printf("BIOS %dkB/%dkB available memory\n", bios_basemem / 1024, printf("BIOS %dkB/%dkB available memory\n", bios_basemem / 1024,
bios_extmem / 1024); bios_extmem / 1024);

View File

@ -211,9 +211,7 @@ main(void)
env_setenv("currdev", EV_VOLATILE, "", i386_setcurrdev, env_setenv("currdev", EV_VOLATILE, "", i386_setcurrdev,
env_nounset); env_nounset);
for (i = 0; devsw[i] != NULL; i++) devinit();
if (devsw[i]->dv_init != NULL)
(devsw[i]->dv_init)();
/* XXX assumes this will be a disk, but it looks likely give above */ /* XXX assumes this will be a disk, but it looks likely give above */
disk_parsedev((struct devdesc **)&devdesc, boot_devname + 4, NULL); disk_parsedev((struct devdesc **)&devdesc, boot_devname + 4, NULL);

View File

@ -149,3 +149,21 @@ devparse(struct devdesc **dev, const char *devspec, const char **path)
free(idev); free(idev);
return (0); return (0);
} }
int
devinit(void)
{
int err = 0;
/*
* March through the device switch probing for things.
*/
for (int i = 0; devsw[i] != NULL; i++) {
if (devsw[i]->dv_init != NULL) {
if ((devsw[i]->dv_init)() != 0) {
err++;
}
}
}
return (err);
}

View File

@ -537,6 +537,14 @@ is non-NULL, then a pointer to the remainder of the
.Dv devdesc .Dv devdesc
string after the device specification is written. string after the device specification is written.
.It Xo .It Xo
.Ft int
.Fn devinit void
Calls all the
.Fa dv_init
routines in the
.Dv devsw
array, returning the number of routines that returned an error.
.It Xo
.Ft void .Ft void
.Fn twiddle void .Fn twiddle void
.Xc .Xc

View File

@ -188,6 +188,7 @@ struct devdesc {
char *devformat(struct devdesc *d); char *devformat(struct devdesc *d);
int devparse(struct devdesc **, const char *, const char **); int devparse(struct devdesc **, const char *, const char **);
int devinit(void);
struct open_file { struct open_file {
int f_flags; /* see F_* below */ int f_flags; /* see F_* below */

View File

@ -182,12 +182,7 @@ main(int (*openfirm)(void *))
/* Set up currdev variable to have hooks in place. */ /* Set up currdev variable to have hooks in place. */
env_setenv("currdev", EV_VOLATILE, "", ofw_setcurrdev, env_nounset); env_setenv("currdev", EV_VOLATILE, "", ofw_setcurrdev, env_nounset);
/* devinit();
* March through the device switch probing for things.
*/
for (i = 0; devsw[i] != NULL; i++)
if (devsw[i]->dv_init != NULL)
(devsw[i]->dv_init)();
printf("\n%s", bootprog_info); printf("\n%s", bootprog_info);
printf("Memory: %lldKB\n", memsize() / 1024); printf("Memory: %lldKB\n", memsize() / 1024);

View File

@ -206,13 +206,7 @@ loader_main(struct loader_callbacks *cb, void *arg, int version, int ndisks)
* Initialise the block cache. Set the upper limit. * Initialise the block cache. Set the upper limit.
*/ */
bcache_init(32768, 512); bcache_init(32768, 512);
/* devinit();
* March through the device switch probing for things.
*/
for (i = 0; devsw[i] != NULL; i++)
if (devsw[i]->dv_init != NULL)
(devsw[i]->dv_init)();
extract_currdev(); extract_currdev();
/* /*