Clean up the BIOS disk matching code a bit (better naming, one structure

and sysctl to export to userland). Also, only use total number of sectors
given in the extended parameters if the physical chs geometry is
marked invalid. Hopefully fixes a problem where BIOSs would not correctly
fill in this field.
This commit is contained in:
fvdl 1999-03-12 01:01:41 +00:00
parent 988bdf8e19
commit 8371eb7a88
6 changed files with 86 additions and 50 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: autoconf.c,v 1.34 1999/03/10 01:28:24 fvdl Exp $ */
/* $NetBSD: autoconf.c,v 1.35 1999/03/12 01:01:41 fvdl Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@ -68,8 +68,8 @@ static int match_harddisk __P((struct device *, struct btinfo_bootdisk *));
static void matchbiosdisks __P((void));
void findroot __P((struct device **, int *));
extern struct bi_devmatch *native_disks;
extern int nnative_disks;
extern struct disklist *i386_alldisks;
extern int i386_ndisks;
/*
* The following several variables are related to
@ -155,14 +155,29 @@ matchbiosdisks()
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++;
i386_ndisks++;
if (i386_ndisks == 0)
return;
/* XXX M_TEMP is wrong */
native_disks = malloc(nnative_disks * sizeof (struct bi_devmatch),
M_TEMP, M_NOWAIT);
if (native_disks == NULL)
i386_alldisks = malloc(sizeof (struct disklist) + (i386_ndisks - 1) *
sizeof (struct nativedisk_info),
M_TEMP, M_NOWAIT);
if (i386_alldisks == NULL)
return;
i386_alldisks->dl_nnativedisks = i386_ndisks;
i386_alldisks->dl_nbiosdisks = big->num;
for (i = 0; i < big->num; i++) {
i386_alldisks->dl_biosdisks[i].bi_dev = big->disk[i].dev;
i386_alldisks->dl_biosdisks[i].bi_sec = big->disk[i].sec;
i386_alldisks->dl_biosdisks[i].bi_head = big->disk[i].head;
i386_alldisks->dl_biosdisks[i].bi_cyl = big->disk[i].cyl;
i386_alldisks->dl_biosdisks[i].bi_lbasecs = big->disk[i].totsec;
i386_alldisks->dl_biosdisks[i].bi_flags = big->disk[i].flags;
}
/*
* XXX code duplication from findroot()
*/
@ -177,8 +192,8 @@ matchbiosdisks()
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,
sprintf(i386_alldisks->dl_nativedisks[n].ni_devname,
"%s%d", dv->dv_cfdata->cf_driver->cd_name,
dv->dv_unit);
for (d = i386_nam2blk; d->d_name &&
@ -225,10 +240,11 @@ matchbiosdisks()
printf("matched bios disk %x with %s\n",
be->dev, be->devname);
#endif
native_disks[n].bd_matches[m++] = i;
i386_alldisks->dl_nativedisks[n].
ni_biosmatches[m++] = i;
}
}
native_disks[n].bd_nmatches = m;
i386_alldisks->dl_nativedisks[n].ni_nmatches = m;
vrele(tv);
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.342 1999/03/10 01:28:24 fvdl Exp $ */
/* $NetBSD: machdep.c,v 1.343 1999/03/12 01:01:41 fvdl Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@ -226,8 +226,8 @@ char machine_arch[] = "i386"; /* machine == machine_arch */
char bootinfo[BOOTINFO_MAXSIZE];
struct bi_devmatch *native_disks = NULL;
int nnative_disks = 0;
struct bi_devmatch *i386_alldisks = NULL;
int i386_ndisks = 0;
/*
* Declare these as initialized data so we can patch them.
@ -1132,7 +1132,6 @@ cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
{
dev_t consdev;
struct btinfo_bootpath *bibp;
struct btinfo_biosgeom *bigp;
/* all sysctl names at this level are terminal */
if (namelen != 1)
@ -1161,18 +1160,12 @@ cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
if(!bibp)
return(ENOENT); /* ??? */
return (sysctl_rdstring(oldp, oldlenp, newp, bibp->bootpath));
case CPU_BIOS_DISKS:
bigp = lookup_bootinfo(BTINFO_BIOSGEOM);
if (!bigp)
case CPU_DISKINFO:
if (i386_alldisks == NULL)
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)));
return (sysctl_rdstruct(oldp, oldlenp, newp, i386_alldisks,
sizeof (struct disklist) +
(i386_ndisks - 1) * sizeof (struct nativedisk_info)));
default:
return (EOPNOTSUPP);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: bootinfo.h,v 1.6 1999/03/10 01:28:25 fvdl Exp $ */
/* $NetBSD: bootinfo.h,v 1.7 1999/03/12 01:01:42 fvdl Exp $ */
/*
* Copyright (c) 1997
@ -121,19 +121,6 @@ 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

View File

@ -1,4 +1,4 @@
/* $NetBSD: cpu.h,v 1.51 1999/03/10 01:28:25 fvdl Exp $ */
/* $NetBSD: cpu.h,v 1.52 1999/03/12 01:01:42 fvdl Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@ -197,9 +197,8 @@ 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_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 CPU_DISKINFO 6 /* disk geometry information */
#define CPU_MAXID 7 /* number of valid machdep ids */
#define CTL_MACHDEP_NAMES { \
{ 0, 0 }, \
@ -208,8 +207,35 @@ void child_return __P((void *));
{ "biosextmem", CTLTYPE_INT }, \
{ "nkpde", CTLTYPE_INT }, \
{ "booted_kernel", CTLTYPE_STRING }, \
{ "biosdisks", CTLTYPE_STRUCT }, \
{ "nativedisks", CTLTYPE_STRUCT }, \
{ "diskinfo", CTLTYPE_STRUCT }, \
}
/*
* Structure for CPU_DISKINFO sysctl call.
* XXX this should be somewhere else.
*/
#define MAX_BIOSDISKS 16
struct disklist {
int dl_nbiosdisks; /* number of bios disks */
struct biosdisk_info {
int bi_dev; /* BIOS device # (0x80 ..) */
int bi_cyl; /* cylinders on disk */
int bi_head; /* heads per track */
int bi_sec; /* sectors per track */
u_int64_t bi_lbasecs; /* total sec. (iff ext13) */
#define BIFLAG_INVALID 0x01
#define BIFLAG_EXTINT13 0x02
int bi_flags;
} dl_biosdisks[MAX_BIOSDISKS];
int dl_nnativedisks; /* number of native disks */
struct nativedisk_info {
char ni_devname[16]; /* native device name */
int ni_nmatches; /* # of matches w/ BIOS */
int ni_biosmatches[MAX_BIOSDISKS]; /* indices in dl_biosdisks */
} dl_nativedisks[1]; /* actually longer */
};
#endif /* !_I386_CPU_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: biosdisk_ll.h,v 1.4 1999/03/08 00:09:25 fvdl Exp $ */
/* $NetBSD: biosdisk_ll.h,v 1.5 1999/03/12 01:01:42 fvdl Exp $ */
/*
* Copyright (c) 1996
@ -70,6 +70,14 @@ struct biosdisk_ext13info {
u_int16_t sbytes; /* # of bytes per sector */
} __attribute__((packed));
#define EXT13_DMA_TRANS 0x0001 /* transparent DMA boundary errors */
#define EXT13_GEOM_VALID 0x0002 /* geometry in c/h/s in struct valid */
#define EXT13_REMOVABLE 0x0004 /* removable device */
#define EXT13_WRITEVERF 0x0008 /* supports write with verify */
#define EXT13_CHANGELINE 0x0010 /* changeline support */
#define EXT13_LOCKABLE 0x0020 /* device is lockable */
#define EXT13_MAXGEOM 0x0040 /* geometry set to max; no media */
#if __GNUC__ == 2 && __GNUC_MINOR__ < 7
#pragma pack(4)
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: bootinfo_biosgeom.c,v 1.5 1999/03/11 12:34:36 fvdl Exp $ */
/* $NetBSD: bootinfo_biosgeom.c,v 1.6 1999/03/12 01:01:42 fvdl Exp $ */
/*
* Copyright (c) 1997
@ -34,6 +34,7 @@
#include <sys/types.h>
#include <machine/disklabel.h>
#include <machine/cpu.h>
#include <lib/libkern/libkern.h>
#include <lib/libsa/stand.h>
@ -59,7 +60,7 @@ void bi_getbiosgeom()
if (!bibg)
return;
for (i = nvalid = 0; i < BI_NHD && nvalid < (int)nhd; i++) {
for (i = nvalid = 0; i < MAX_BIOSDISKS && nvalid < (int)nhd; i++) {
struct biosdisk_ll d;
struct biosdisk_ext13info ed;
char buf[BIOSDISK_SECSIZE];
@ -87,7 +88,12 @@ void bi_getbiosgeom()
#endif
if (d.flags & BIOSDISK_EXT13) {
bibg->disk[nvalid].totsec = ed.totsec;
if (ed.flags & EXT13_GEOM_VALID)
bibg->disk[nvalid].totsec =
(u_int64_t)ed.sec * (u_int64_t)ed.head *
(u_int64_t)ed.cyl;
else
bibg->disk[nvalid].totsec = ed.totsec;
bibg->disk[nvalid].flags |= BI_GEOM_EXTINT13;
}
for (j = 0, cksum = 0; j < BIOSDISK_SECSIZE; j++)