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