From bdb770bc3461df904a9d8c198c22a30eac7adcd2 Mon Sep 17 00:00:00 2001 From: fvdl Date: Wed, 10 Mar 1999 01:28:24 +0000 Subject: [PATCH] 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. --- sys/arch/i386/i386/autoconf.c | 73 ++++++++++++++++++------------ sys/arch/i386/i386/machdep.c | 12 ++++- sys/arch/i386/include/bootinfo.h | 32 +++++++++---- sys/arch/i386/include/cpu.h | 10 ++-- sys/arch/i386/stand/lib/bootinfo.h | 4 +- 5 files changed, 85 insertions(+), 46 deletions(-) diff --git a/sys/arch/i386/i386/autoconf.c b/sys/arch/i386/i386/autoconf.c index 8e5914f1af7f..c2813142c2b9 100644 --- a/sys/arch/i386/i386/autoconf.c +++ b/sys/arch/i386/i386/autoconf.c @@ -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. @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -64,11 +65,12 @@ #include static int match_harddisk __P((struct device *, struct btinfo_bootdisk *)); -#ifdef PASS_GEOM static void matchbiosdisks __P((void)); -#endif void findroot __P((struct device **, int *)); +extern struct bi_devmatch *native_disks; +extern int nnative_disks; + /* * The following several variables are related to * the configuration process, and are used in initializing @@ -116,9 +118,7 @@ cpu_rootconf() int booted_partition; findroot(&booted_device, &booted_partition); -#ifdef PASS_GEOM matchbiosdisks(); -#endif printf("boot device: %s\n", booted_device ? booted_device->dv_xname : ""); @@ -126,7 +126,10 @@ cpu_rootconf() 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 matchbiosdisks() { @@ -134,10 +137,9 @@ matchbiosdisks() struct bi_biosgeom_entry *be; struct device *dv; struct devnametobdevmaj *d; - int i, ck, error; + int i, ck, error, m, n; struct vnode *tv; - struct buf *bp; - char *mbr; + char mbr[DEV_BSIZE]; big = lookup_bootinfo(BTINFO_BIOSGEOM); @@ -146,7 +148,25 @@ matchbiosdisks() 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) { if (dv->dv_class != DV_DISK) continue; @@ -156,36 +176,40 @@ matchbiosdisks() #endif if (!strcmp(dv->dv_cfdata->cf_driver->cd_name, "sd") || !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 && strcmp(d->d_name, dv->dv_cfdata->cf_driver->cd_name); d++); if (d->d_name == NULL) return; + if (bdevvp(MAKEDISKDEV(d->d_maj, dv->dv_unit, RAW_PART), &tv)) panic("matchbiosdisks: can't alloc vnode"); + error = VOP_OPEN(tv, FREAD, NOCRED, 0); if (error) { vrele(tv); continue; } - bp = getblk(tv, 0, DEV_BSIZE, 0, 0); - bp->b_flags = B_BUSY | B_READ; - VOP_STRATEGY(bp); - if (biowait(bp)) { + error = vn_rdwr(UIO_READ, tv, mbr, DEV_BSIZE, 0, + UIO_SYSSPACE, 0, NOCRED, NULL, 0); + VOP_CLOSE(tv, FREAD, NOCRED, 0); + if (error) { #ifdef GEOM_DEBUG printf("matchbiosdisks: %s: MBR read failure\n", dv->dv_xname); #endif - brelse(bp); - vrele(tv); continue; } - VOP_CLOSE(tv, FREAD, NOCRED, 0); - mbr = (char *)bp->b_data; + for (ck = i = 0; i < DEV_BSIZE; i++) ck += mbr[i]; - for (i = 0; i < big->num; i++) { + for (m = i = 0; i < big->num; i++) { be = &big->disk[i]; #ifdef GEOM_DEBUG printf("match %s with %d\n", dv->dv_xname, i); @@ -197,25 +221,18 @@ matchbiosdisks() !memcmp(&mbr[MBR_PARTOFF], be->dosparts, NMBRPART * sizeof (struct mbr_partition))) { - sprintf(be->devname, "%s%d", - dv->dv_cfdata->cf_driver->cd_name, - dv->dv_unit); #ifdef GEOM_DEBUG printf("matched bios disk %x with %s\n", be->dev, be->devname); #endif - if (be->flags & BI_GEOM_MATCHED) - be->flags |= BI_GEOM_MULTIPLE; - else - be->flags |= BI_GEOM_MATCHED; + native_disks[n].bd_matches[m++] = i; } } - brelse(bp); + native_disks[n].bd_nmatches = m; vrele(tv); } } } -#endif u_long bootdev = 0; /* should be dev_t, but not until 32 bits */ diff --git a/sys/arch/i386/i386/machdep.c b/sys/arch/i386/i386/machdep.c index 4c41fe6ef9d9..0e8c1002c623 100644 --- a/sys/arch/i386/i386/machdep.c +++ b/sys/arch/i386/i386/machdep.c @@ -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. @@ -226,6 +226,9 @@ char machine_arch[] = "i386"; /* machine == machine_arch */ char bootinfo[BOOTINFO_MAXSIZE]; +struct bi_devmatch *native_disks = NULL; +int nnative_disks = 0; + /* * 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) return(ENOENT); /* ??? */ return (sysctl_rdstring(oldp, oldlenp, newp, bibp->bootpath)); - case CPU_BIOS_GEOM: + case CPU_BIOS_DISKS: bigp = lookup_bootinfo(BTINFO_BIOSGEOM); if (!bigp) return (ENOENT); return (sysctl_rdstruct(oldp, oldlenp, newp, bigp->disk, 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: return (EOPNOTSUPP); diff --git a/sys/arch/i386/include/bootinfo.h b/sys/arch/i386/include/bootinfo.h index 8d376908548c..5553d110af97 100644 --- a/sys/arch/i386/include/bootinfo.h +++ b/sys/arch/i386/include/bootinfo.h @@ -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 @@ -101,17 +101,18 @@ struct btinfo_memmap { #include +/* + * Structure describing disk info as seen by the BIOS. + */ struct bi_biosgeom_entry { - int sec, head, cyl; - u_int64_t totsec; - int flags, dev; + int sec, head, cyl; /* geometry */ + u_int64_t totsec; /* LBA sectors from ext int13 */ + int flags, dev; /* flags, BIOS device # */ #define BI_GEOM_INVALID 0x01 #define BI_GEOM_EXTINT13 0x02 -#define BI_GEOM_MATCHED 0x04 -#define BI_GEOM_MULTIPLE 0x08 - unsigned int cksum; - char devname[16]; - struct mbr_partition dosparts[NMBRPART]; + unsigned int cksum; /* MBR checksum */ + int res0, res1, res2, res3; /* future expansion; 0 now */ + struct mbr_partition dosparts[NMBRPART]; /* MBR itself */ }; struct btinfo_biosgeom { @@ -120,6 +121,19 @@ struct btinfo_biosgeom { 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 void *lookup_bootinfo __P((int)); #endif diff --git a/sys/arch/i386/include/cpu.h b/sys/arch/i386/include/cpu.h index 82024c9b033d..05a34e654227 100644 --- a/sys/arch/i386/include/cpu.h +++ b/sys/arch/i386/include/cpu.h @@ -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. @@ -197,8 +197,9 @@ void child_return __P((void *)); #define CPU_BIOSEXTMEM 3 /* int: bios-reported ext. mem (K) */ #define CPU_NKPDE 4 /* int: number of kernel PDEs */ #define CPU_BOOTED_KERNEL 5 /* string: booted kernel name */ -#define CPU_BIOS_GEOM 6 /* bios disk geometry information */ -#define CPU_MAXID 7 /* number of valid machdep ids */ +#define CPU_BIOS_DISKS 6 /* bios disk geometry information */ +#define CPU_NATIVE_DISKS 7 /* native disks with matching bios # */ +#define CPU_MAXID 8 /* number of valid machdep ids */ #define CTL_MACHDEP_NAMES { \ { 0, 0 }, \ @@ -207,7 +208,8 @@ void child_return __P((void *)); { "biosextmem", CTLTYPE_INT }, \ { "nkpde", CTLTYPE_INT }, \ { "booted_kernel", CTLTYPE_STRING }, \ - { "biosdiskgeom", CTLTYPE_STRUCT }, \ + { "biosdisks", CTLTYPE_STRUCT }, \ + { "nativedisks", CTLTYPE_STRUCT }, \ } #endif /* !_I386_CPU_H_ */ diff --git a/sys/arch/i386/stand/lib/bootinfo.h b/sys/arch/i386/stand/lib/bootinfo.h index 3a4606836967..1382425a2bcf 100644 --- a/sys/arch/i386/stand/lib/bootinfo.h +++ b/sys/arch/i386/stand/lib/bootinfo.h @@ -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 @@ -39,8 +39,6 @@ struct bootinfo { physaddr_t entry[1]; }; -#define BI_NHD 16 - extern struct bootinfo *bootinfo; #define BI_ALLOC(max) (bootinfo = alloc(sizeof(struct bootinfo) \