Home | History | Annotate | Line # | Download | only in lib
bootinfo_biosgeom.c revision 1.12
      1  1.12     lukem /*	$NetBSD: bootinfo_biosgeom.c,v 1.12 2003/10/08 04:25:45 lukem Exp $	*/
      2   1.1  drochner 
      3   1.1  drochner /*
      4   1.1  drochner  * Copyright (c) 1997
      5   1.1  drochner  *	Matthias Drochner.  All rights reserved.
      6   1.1  drochner  *
      7   1.1  drochner  * Redistribution and use in source and binary forms, with or without
      8   1.1  drochner  * modification, are permitted provided that the following conditions
      9   1.1  drochner  * are met:
     10   1.1  drochner  * 1. Redistributions of source code must retain the above copyright
     11   1.1  drochner  *    notice, this list of conditions and the following disclaimer.
     12   1.1  drochner  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  drochner  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  drochner  *    documentation and/or other materials provided with the distribution.
     15   1.1  drochner  * 3. All advertising materials mentioning features or use of this software
     16   1.1  drochner  *    must display the following acknowledgement:
     17   1.1  drochner  *	This product includes software developed for the NetBSD Project
     18   1.1  drochner  *	by Matthias Drochner.
     19   1.1  drochner  * 4. The name of the author may not be used to endorse or promote products
     20   1.1  drochner  *    derived from this software without specific prior written permission.
     21   1.1  drochner  *
     22   1.1  drochner  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23   1.1  drochner  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24   1.1  drochner  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25   1.1  drochner  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26   1.1  drochner  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27   1.1  drochner  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28   1.1  drochner  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29   1.1  drochner  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30   1.1  drochner  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31   1.1  drochner  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32   1.1  drochner  *
     33   1.1  drochner  */
     34   1.1  drochner 
     35   1.1  drochner #include <sys/types.h>
     36   1.1  drochner #include <machine/disklabel.h>
     37   1.6      fvdl #include <machine/cpu.h>
     38   1.1  drochner 
     39   1.1  drochner #include <lib/libkern/libkern.h>
     40   1.1  drochner #include <lib/libsa/stand.h>
     41   1.1  drochner 
     42   1.1  drochner #include "libi386.h"
     43   1.1  drochner #include "biosdisk_ll.h"
     44   1.1  drochner #include "bootinfo.h"
     45   1.1  drochner 
     46  1.11       dsl #ifdef BIOSDISK_EXT13INFO_V3
     47  1.11       dsl static struct {
     48  1.11       dsl 	char	*name;
     49  1.11       dsl 	int	flag;
     50  1.11       dsl } bus_names[] = { {"ISA", BI_GEOM_BUS_ISA},
     51  1.11       dsl 		  {"PCI", BI_GEOM_BUS_PCI},
     52  1.11       dsl 		  {NULL, BI_GEOM_BUS_OTHER} };
     53  1.11       dsl static struct {
     54  1.11       dsl 	char	*name;
     55  1.11       dsl 	int	flag;
     56  1.11       dsl } iface_names[] = { {"ATA", BI_GEOM_IFACE_ATA},
     57  1.11       dsl 		    {"ATAPI", BI_GEOM_IFACE_ATAPI},
     58  1.11       dsl 		    {"SCSI", BI_GEOM_IFACE_SCSI},
     59  1.11       dsl 		    {"USB", BI_GEOM_IFACE_USB},
     60  1.11       dsl 		    {"1394", BI_GEOM_IFACE_1394},
     61  1.11       dsl 		    {"FIBRE", BI_GEOM_IFACE_FIBRE},
     62  1.11       dsl 		    {NULL, BI_GEOM_IFACE_OTHER} };
     63  1.11       dsl #endif
     64  1.11       dsl 
     65   1.1  drochner void bi_getbiosgeom()
     66   1.1  drochner {
     67   1.1  drochner 	struct btinfo_biosgeom *bibg;
     68   1.5      fvdl 	int i, j, nvalid;
     69   1.5      fvdl 	unsigned char nhd;
     70   1.4      fvdl 	unsigned int cksum;
     71  1.11       dsl 	struct biosdisk_ll d;
     72  1.11       dsl 	struct biosdisk_ext13info ed;
     73  1.11       dsl 	char buf[BIOSDISK_SECSIZE];
     74   1.1  drochner 
     75   1.4      fvdl 	pvbcopy((void *)(0x400 + 0x75), &nhd, 1);
     76   1.4      fvdl #ifdef GEOM_DEBUG
     77   1.5      fvdl 	printf("nhd %d\n", (int)nhd);
     78   1.4      fvdl #endif
     79   1.1  drochner 
     80   1.1  drochner 	bibg = alloc(sizeof(struct btinfo_biosgeom)
     81   1.1  drochner 		     + (nhd - 1) * sizeof(struct bi_biosgeom_entry));
     82   1.4      fvdl 	if (!bibg)
     83   1.4      fvdl 		return;
     84   1.1  drochner 
     85   1.6      fvdl 	for (i = nvalid = 0; i < MAX_BIOSDISKS && nvalid < (int)nhd; i++) {
     86   1.1  drochner 
     87   1.1  drochner 		d.dev = 0x80 + i;
     88   1.4      fvdl 
     89   1.4      fvdl 		if (set_geometry(&d, &ed))
     90   1.1  drochner 			continue;
     91   1.9     perry 		memset(&bibg->disk[nvalid], 0, sizeof(bibg->disk[nvalid]));
     92   1.4      fvdl 
     93   1.4      fvdl 		bibg->disk[nvalid].sec = d.sec;
     94   1.8  drochner 		bibg->disk[nvalid].head = d.head;
     95   1.8  drochner 		bibg->disk[nvalid].cyl = d.cyl;
     96   1.4      fvdl 		bibg->disk[nvalid].dev = d.dev;
     97   1.4      fvdl 
     98   1.4      fvdl 		if (readsects(&d, 0, 1, buf, 0)) {
     99   1.4      fvdl 			bibg->disk[nvalid].flags |= BI_GEOM_INVALID;
    100   1.4      fvdl 			nvalid++;
    101   1.4      fvdl 			continue;
    102   1.4      fvdl 		}
    103   1.4      fvdl 
    104   1.4      fvdl #ifdef GEOM_DEBUG
    105   1.4      fvdl 		printf("#%d: %x: C %d H %d S %d\n", nvalid,
    106   1.4      fvdl 		    d.dev, d.cyl, d.head, d.sec);
    107  1.10       dsl 		printf("   sz %d fl %x cyl %d head %d sec %d totsec %lld sbytes %d\n",
    108  1.10       dsl 			ed.size, ed.flags, ed.cyl, ed.head, ed.sec,
    109  1.10       dsl 			ed.totsec, ed.sbytes);
    110   1.4      fvdl #endif
    111   1.4      fvdl 
    112   1.4      fvdl 		if (d.flags & BIOSDISK_EXT13) {
    113  1.10       dsl 			bibg->disk[nvalid].totsec = ed.totsec;
    114   1.4      fvdl 			bibg->disk[nvalid].flags |= BI_GEOM_EXTINT13;
    115   1.4      fvdl 		}
    116  1.11       dsl #ifdef BIOSDISK_EXT13INFO_V3
    117  1.11       dsl #ifdef GEOM_DEBUG
    118  1.11       dsl 		printf("   edd_cfg %x, sig %x, len %x, bus %s type %s\n",
    119  1.11       dsl 			ed.edd_cfg, ed.devpath_sig, ed.devpath_len,
    120  1.11       dsl 			ed.host_bus, ed.iface_type);
    121  1.11       dsl #endif
    122  1.11       dsl 
    123  1.11       dsl 		/* The v3.0 stuff will help identify the disks */
    124  1.11       dsl 		if (ed.size >= offsetof(struct biosdisk_ext13info, checksum)
    125  1.11       dsl 		    && ed.devpath_sig == EXT13_DEVPATH_SIGNATURE) {
    126  1.11       dsl 			char *cp;
    127  1.11       dsl 
    128  1.11       dsl 			for (cp = (void *)&ed.devpath_sig, cksum = 0;
    129  1.11       dsl 			    cp <= (char *)&ed.checksum; cp++) {
    130  1.11       dsl 				cksum += *cp;
    131  1.11       dsl 			}
    132  1.11       dsl 			if ((cksum & 0xff) != 0)
    133  1.11       dsl 				bibg->disk[nvalid].flags |= BI_GEOM_BADCKSUM;
    134  1.11       dsl #ifdef GEOM_DEBUG
    135  1.11       dsl 			printf("checksum %x\n", cksum & 0xff);
    136  1.11       dsl #endif
    137  1.11       dsl 			for (j = 0; ; j++) {
    138  1.11       dsl 				cp = bus_names[j].name;
    139  1.11       dsl 				if (cp == NULL)
    140  1.11       dsl 					break;
    141  1.11       dsl 				if (strncmp(cp, ed.host_bus,
    142  1.11       dsl 				    sizeof ed.host_bus) == 0)
    143  1.11       dsl 					break;
    144  1.11       dsl 			}
    145  1.11       dsl #ifdef GEOM_DEBUG
    146  1.11       dsl 			printf("bus %s (%x)\n", cp ? cp : "null",
    147  1.11       dsl 					bus_names[j].flag);
    148  1.11       dsl #endif
    149  1.11       dsl 			bibg->disk[nvalid].flags |= bus_names[j].flag;
    150  1.11       dsl 			for (j = 0; ; j++) {
    151  1.11       dsl 				cp = iface_names[j].name;
    152  1.11       dsl 				if (cp == NULL)
    153  1.11       dsl 					break;
    154  1.11       dsl 				if (strncmp(cp, ed.iface_type,
    155  1.11       dsl 				    sizeof ed.iface_type) == 0)
    156  1.11       dsl 					break;
    157  1.11       dsl 			}
    158  1.11       dsl 			bibg->disk[nvalid].flags |= iface_names[j].flag;
    159  1.11       dsl 			/* Dump raw interface path and device path */
    160  1.11       dsl 			bibg->disk[nvalid].interface_path =
    161  1.11       dsl 					ed.interface_path.ip_32[0];
    162  1.11       dsl 			bibg->disk[nvalid].device_path =
    163  1.11       dsl 					ed.device_path.dp_64[0];
    164  1.11       dsl #ifdef GEOM_DEBUG
    165  1.11       dsl 			printf("device %s (%x) interface %x path %llx\n",
    166  1.11       dsl 					cp ? cp : "null",
    167  1.11       dsl 					iface_names[j].flag,
    168  1.11       dsl 					ed.interface_path.ip_32[0],
    169  1.11       dsl 					ed.device_path.dp_64[0]);
    170  1.11       dsl #endif
    171  1.11       dsl 		}
    172  1.11       dsl #endif
    173  1.11       dsl 
    174   1.4      fvdl 		for (j = 0, cksum = 0; j < BIOSDISK_SECSIZE; j++)
    175   1.4      fvdl 			cksum += buf[j];
    176   1.4      fvdl 		bibg->disk[nvalid].cksum = cksum;
    177  1.12     lukem 		memcpy(bibg->disk[nvalid].dosparts, &buf[MBR_PART_OFFSET],
    178  1.12     lukem 		    sizeof(bibg->disk[nvalid].dosparts));
    179   1.4      fvdl 		nvalid++;
    180   1.1  drochner 	}
    181   1.1  drochner 
    182   1.4      fvdl 	bibg->num = nvalid;
    183   1.4      fvdl 
    184   1.1  drochner 	BI_ADD(bibg, BTINFO_BIOSGEOM, sizeof(struct btinfo_biosgeom)
    185   1.4      fvdl 	       + nvalid * sizeof(struct bi_biosgeom_entry));
    186   1.1  drochner }
    187