Create a list of native disks too, and make it retrievable. It contains

all matching BIOS disks per entry, so that we have complete match info.
Enable the matching code.
This commit is contained in:
fvdl 1999-03-10 01:28:24 +00:00
parent 2c952176c1
commit bdb770bc34
5 changed files with 85 additions and 46 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: autoconf.c,v 1.33 1999/03/08 01:26:00 fvdl Exp $ */ /* $NetBSD: autoconf.c,v 1.34 1999/03/10 01:28:24 fvdl Exp $ */
/*- /*-
* Copyright (c) 1990 The Regents of the University of California. * Copyright (c) 1990 The Regents of the University of California.
@ -55,6 +55,7 @@
#include <sys/dmap.h> #include <sys/dmap.h>
#include <sys/reboot.h> #include <sys/reboot.h>
#include <sys/device.h> #include <sys/device.h>
#include <sys/malloc.h>
#include <sys/vnode.h> #include <sys/vnode.h>
#include <sys/fcntl.h> #include <sys/fcntl.h>
#include <sys/dkio.h> #include <sys/dkio.h>
@ -64,11 +65,12 @@
#include <machine/bootinfo.h> #include <machine/bootinfo.h>
static int match_harddisk __P((struct device *, struct btinfo_bootdisk *)); static int match_harddisk __P((struct device *, struct btinfo_bootdisk *));
#ifdef PASS_GEOM
static void matchbiosdisks __P((void)); static void matchbiosdisks __P((void));
#endif
void findroot __P((struct device **, int *)); void findroot __P((struct device **, int *));
extern struct bi_devmatch *native_disks;
extern int nnative_disks;
/* /*
* The following several variables are related to * The following several variables are related to
* the configuration process, and are used in initializing * the configuration process, and are used in initializing
@ -116,9 +118,7 @@ cpu_rootconf()
int booted_partition; int booted_partition;
findroot(&booted_device, &booted_partition); findroot(&booted_device, &booted_partition);
#ifdef PASS_GEOM
matchbiosdisks(); matchbiosdisks();
#endif
printf("boot device: %s\n", printf("boot device: %s\n",
booted_device ? booted_device->dv_xname : "<unknown>"); booted_device ? booted_device->dv_xname : "<unknown>");
@ -126,7 +126,10 @@ cpu_rootconf()
setroot(booted_device, booted_partition, i386_nam2blk); setroot(booted_device, booted_partition, i386_nam2blk);
} }
#ifdef PASS_GEOM /*
* XXX ugly bit of code. But, this is the only safe time that the
* match between BIOS disks and native disks can be done.
*/
static void static void
matchbiosdisks() matchbiosdisks()
{ {
@ -134,10 +137,9 @@ matchbiosdisks()
struct bi_biosgeom_entry *be; struct bi_biosgeom_entry *be;
struct device *dv; struct device *dv;
struct devnametobdevmaj *d; struct devnametobdevmaj *d;
int i, ck, error; int i, ck, error, m, n;
struct vnode *tv; struct vnode *tv;
struct buf *bp; char mbr[DEV_BSIZE];
char *mbr;
big = lookup_bootinfo(BTINFO_BIOSGEOM); big = lookup_bootinfo(BTINFO_BIOSGEOM);
@ -146,7 +148,25 @@ matchbiosdisks()
return; return;
} }
/* XXX code duplication from findroot() */ /*
* First, count all native disks
*/
for (dv = alldevs.tqh_first; dv != NULL; dv = dv->dv_list.tqe_next)
if (dv->dv_class == DV_DISK &&
(!strcmp(dv->dv_cfdata->cf_driver->cd_name, "sd") ||
!strcmp(dv->dv_cfdata->cf_driver->cd_name, "wd")))
nnative_disks++;
/* XXX M_TEMP is wrong */
native_disks = malloc(nnative_disks * sizeof (struct bi_devmatch),
M_TEMP, M_NOWAIT);
if (native_disks == NULL)
return;
/*
* XXX code duplication from findroot()
*/
n = -1;
for (dv = alldevs.tqh_first; dv != NULL; dv = dv->dv_list.tqe_next) { for (dv = alldevs.tqh_first; dv != NULL; dv = dv->dv_list.tqe_next) {
if (dv->dv_class != DV_DISK) if (dv->dv_class != DV_DISK)
continue; continue;
@ -156,36 +176,40 @@ matchbiosdisks()
#endif #endif
if (!strcmp(dv->dv_cfdata->cf_driver->cd_name, "sd") || if (!strcmp(dv->dv_cfdata->cf_driver->cd_name, "sd") ||
!strcmp(dv->dv_cfdata->cf_driver->cd_name, "wd")) { !strcmp(dv->dv_cfdata->cf_driver->cd_name, "wd")) {
n++;
sprintf(native_disks[n].bd_devname, "%s%d",
dv->dv_cfdata->cf_driver->cd_name,
dv->dv_unit);
for (d = i386_nam2blk; d->d_name && for (d = i386_nam2blk; d->d_name &&
strcmp(d->d_name, dv->dv_cfdata->cf_driver->cd_name); strcmp(d->d_name, dv->dv_cfdata->cf_driver->cd_name);
d++); d++);
if (d->d_name == NULL) if (d->d_name == NULL)
return; return;
if (bdevvp(MAKEDISKDEV(d->d_maj, dv->dv_unit, RAW_PART), if (bdevvp(MAKEDISKDEV(d->d_maj, dv->dv_unit, RAW_PART),
&tv)) &tv))
panic("matchbiosdisks: can't alloc vnode"); panic("matchbiosdisks: can't alloc vnode");
error = VOP_OPEN(tv, FREAD, NOCRED, 0); error = VOP_OPEN(tv, FREAD, NOCRED, 0);
if (error) { if (error) {
vrele(tv); vrele(tv);
continue; continue;
} }
bp = getblk(tv, 0, DEV_BSIZE, 0, 0); error = vn_rdwr(UIO_READ, tv, mbr, DEV_BSIZE, 0,
bp->b_flags = B_BUSY | B_READ; UIO_SYSSPACE, 0, NOCRED, NULL, 0);
VOP_STRATEGY(bp); VOP_CLOSE(tv, FREAD, NOCRED, 0);
if (biowait(bp)) { if (error) {
#ifdef GEOM_DEBUG #ifdef GEOM_DEBUG
printf("matchbiosdisks: %s: MBR read failure\n", printf("matchbiosdisks: %s: MBR read failure\n",
dv->dv_xname); dv->dv_xname);
#endif #endif
brelse(bp);
vrele(tv);
continue; continue;
} }
VOP_CLOSE(tv, FREAD, NOCRED, 0);
mbr = (char *)bp->b_data;
for (ck = i = 0; i < DEV_BSIZE; i++) for (ck = i = 0; i < DEV_BSIZE; i++)
ck += mbr[i]; ck += mbr[i];
for (i = 0; i < big->num; i++) { for (m = i = 0; i < big->num; i++) {
be = &big->disk[i]; be = &big->disk[i];
#ifdef GEOM_DEBUG #ifdef GEOM_DEBUG
printf("match %s with %d\n", dv->dv_xname, i); printf("match %s with %d\n", dv->dv_xname, i);
@ -197,25 +221,18 @@ matchbiosdisks()
!memcmp(&mbr[MBR_PARTOFF], be->dosparts, !memcmp(&mbr[MBR_PARTOFF], be->dosparts,
NMBRPART * NMBRPART *
sizeof (struct mbr_partition))) { sizeof (struct mbr_partition))) {
sprintf(be->devname, "%s%d",
dv->dv_cfdata->cf_driver->cd_name,
dv->dv_unit);
#ifdef GEOM_DEBUG #ifdef GEOM_DEBUG
printf("matched bios disk %x with %s\n", printf("matched bios disk %x with %s\n",
be->dev, be->devname); be->dev, be->devname);
#endif #endif
if (be->flags & BI_GEOM_MATCHED) native_disks[n].bd_matches[m++] = i;
be->flags |= BI_GEOM_MULTIPLE;
else
be->flags |= BI_GEOM_MATCHED;
} }
} }
brelse(bp); native_disks[n].bd_nmatches = m;
vrele(tv); vrele(tv);
} }
} }
} }
#endif
u_long bootdev = 0; /* should be dev_t, but not until 32 bits */ u_long bootdev = 0; /* should be dev_t, but not until 32 bits */

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.341 1999/03/09 16:05:34 fvdl Exp $ */ /* $NetBSD: machdep.c,v 1.342 1999/03/10 01:28:24 fvdl Exp $ */
/*- /*-
* Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@ -226,6 +226,9 @@ char machine_arch[] = "i386"; /* machine == machine_arch */
char bootinfo[BOOTINFO_MAXSIZE]; char bootinfo[BOOTINFO_MAXSIZE];
struct bi_devmatch *native_disks = NULL;
int nnative_disks = 0;
/* /*
* Declare these as initialized data so we can patch them. * Declare these as initialized data so we can patch them.
*/ */
@ -1158,12 +1161,17 @@ cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
if(!bibp) if(!bibp)
return(ENOENT); /* ??? */ return(ENOENT); /* ??? */
return (sysctl_rdstring(oldp, oldlenp, newp, bibp->bootpath)); return (sysctl_rdstring(oldp, oldlenp, newp, bibp->bootpath));
case CPU_BIOS_GEOM: case CPU_BIOS_DISKS:
bigp = lookup_bootinfo(BTINFO_BIOSGEOM); bigp = lookup_bootinfo(BTINFO_BIOSGEOM);
if (!bigp) if (!bigp)
return (ENOENT); return (ENOENT);
return (sysctl_rdstruct(oldp, oldlenp, newp, bigp->disk, return (sysctl_rdstruct(oldp, oldlenp, newp, bigp->disk,
bigp->num * sizeof (struct bi_biosgeom_entry))); bigp->num * sizeof (struct bi_biosgeom_entry)));
case CPU_NATIVE_DISKS:
if (native_disks == NULL)
return (ENOENT);
return (sysctl_rdstruct(oldp, oldlenp, newp, native_disks,
nnative_disks * sizeof (struct bi_devmatch)));
default: default:
return (EOPNOTSUPP); return (EOPNOTSUPP);

View File

@ -1,4 +1,4 @@
/* $NetBSD: bootinfo.h,v 1.5 1999/03/08 21:42:48 drochner Exp $ */ /* $NetBSD: bootinfo.h,v 1.6 1999/03/10 01:28:25 fvdl Exp $ */
/* /*
* Copyright (c) 1997 * Copyright (c) 1997
@ -101,17 +101,18 @@ struct btinfo_memmap {
#include <sys/disklabel_mbr.h> #include <sys/disklabel_mbr.h>
/*
* Structure describing disk info as seen by the BIOS.
*/
struct bi_biosgeom_entry { struct bi_biosgeom_entry {
int sec, head, cyl; int sec, head, cyl; /* geometry */
u_int64_t totsec; u_int64_t totsec; /* LBA sectors from ext int13 */
int flags, dev; int flags, dev; /* flags, BIOS device # */
#define BI_GEOM_INVALID 0x01 #define BI_GEOM_INVALID 0x01
#define BI_GEOM_EXTINT13 0x02 #define BI_GEOM_EXTINT13 0x02
#define BI_GEOM_MATCHED 0x04 unsigned int cksum; /* MBR checksum */
#define BI_GEOM_MULTIPLE 0x08 int res0, res1, res2, res3; /* future expansion; 0 now */
unsigned int cksum; struct mbr_partition dosparts[NMBRPART]; /* MBR itself */
char devname[16];
struct mbr_partition dosparts[NMBRPART];
}; };
struct btinfo_biosgeom { struct btinfo_biosgeom {
@ -120,6 +121,19 @@ struct btinfo_biosgeom {
struct bi_biosgeom_entry disk[1]; /* var len */ struct bi_biosgeom_entry disk[1]; /* var len */
}; };
#define BI_NHD 16
/*
* Structure containing a disk device name and possible matching BIOS
* disks (indices in the bi_biosgeom_entry array)
* XXX shouldn't really be here.
*/
struct bi_devmatch {
char bd_devname[16];
int bd_nmatches;
int bd_matches[BI_NHD];
};
#ifdef _KERNEL #ifdef _KERNEL
void *lookup_bootinfo __P((int)); void *lookup_bootinfo __P((int));
#endif #endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: cpu.h,v 1.50 1999/03/08 00:10:42 fvdl Exp $ */ /* $NetBSD: cpu.h,v 1.51 1999/03/10 01:28:25 fvdl Exp $ */
/*- /*-
* Copyright (c) 1990 The Regents of the University of California. * Copyright (c) 1990 The Regents of the University of California.
@ -197,8 +197,9 @@ void child_return __P((void *));
#define CPU_BIOSEXTMEM 3 /* int: bios-reported ext. mem (K) */ #define CPU_BIOSEXTMEM 3 /* int: bios-reported ext. mem (K) */
#define CPU_NKPDE 4 /* int: number of kernel PDEs */ #define CPU_NKPDE 4 /* int: number of kernel PDEs */
#define CPU_BOOTED_KERNEL 5 /* string: booted kernel name */ #define CPU_BOOTED_KERNEL 5 /* string: booted kernel name */
#define CPU_BIOS_GEOM 6 /* bios disk geometry information */ #define CPU_BIOS_DISKS 6 /* bios disk geometry information */
#define CPU_MAXID 7 /* number of valid machdep ids */ #define CPU_NATIVE_DISKS 7 /* native disks with matching bios # */
#define CPU_MAXID 8 /* number of valid machdep ids */
#define CTL_MACHDEP_NAMES { \ #define CTL_MACHDEP_NAMES { \
{ 0, 0 }, \ { 0, 0 }, \
@ -207,7 +208,8 @@ void child_return __P((void *));
{ "biosextmem", CTLTYPE_INT }, \ { "biosextmem", CTLTYPE_INT }, \
{ "nkpde", CTLTYPE_INT }, \ { "nkpde", CTLTYPE_INT }, \
{ "booted_kernel", CTLTYPE_STRING }, \ { "booted_kernel", CTLTYPE_STRING }, \
{ "biosdiskgeom", CTLTYPE_STRUCT }, \ { "biosdisks", CTLTYPE_STRUCT }, \
{ "nativedisks", CTLTYPE_STRUCT }, \
} }
#endif /* !_I386_CPU_H_ */ #endif /* !_I386_CPU_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: bootinfo.h,v 1.4 1999/03/08 21:44:48 drochner Exp $ */ /* $NetBSD: bootinfo.h,v 1.5 1999/03/10 01:28:25 fvdl Exp $ */
/* /*
* Copyright (c) 1997 * Copyright (c) 1997
@ -39,8 +39,6 @@ struct bootinfo {
physaddr_t entry[1]; physaddr_t entry[1];
}; };
#define BI_NHD 16
extern struct bootinfo *bootinfo; extern struct bootinfo *bootinfo;
#define BI_ALLOC(max) (bootinfo = alloc(sizeof(struct bootinfo) \ #define BI_ALLOC(max) (bootinfo = alloc(sizeof(struct bootinfo) \