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