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