1 /* $NetBSD: bootinfo_biosgeom.c,v 1.22 2013/05/16 19:06:44 christos Exp $ */
5 * Matthias Drochner. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
29 #include <sys/types.h>
30 #include <machine/disklabel.h>
31 #include <machine/cpu.h>
33 #include <lib/libkern/libkern.h>
34 #include <lib/libsa/stand.h>
37 #include "biosdisk_ll.h"
40 #ifdef BIOSDISK_EXTINFO_V3
44 } bus_names
[] = { {"ISA", BI_GEOM_BUS_ISA
},
45 {"PCI", BI_GEOM_BUS_PCI
},
46 {NULL
, BI_GEOM_BUS_OTHER
} };
50 } iface_names
[] = { {"ATA", BI_GEOM_IFACE_ATA
},
51 {"ATAPI", BI_GEOM_IFACE_ATAPI
},
52 {"SCSI", BI_GEOM_IFACE_SCSI
},
53 {"USB", BI_GEOM_IFACE_USB
},
54 {"1394", BI_GEOM_IFACE_1394
},
55 {"FIBRE", BI_GEOM_IFACE_FIBRE
},
56 {NULL
, BI_GEOM_IFACE_OTHER
} };
62 struct btinfo_biosgeom
*bibg
;
67 struct biosdisk_extinfo ed
;
68 char buf
[BIOSDISK_DEFAULT_SECSIZE
];
70 nhd
= get_harddrives();
72 printf("nhd %d\n", nhd
);
75 bibg
= alloc(sizeof(struct btinfo_biosgeom
)
76 + (nhd
- 1) * sizeof(struct bi_biosgeom_entry
));
80 for (i
= nvalid
= 0; i
< MAX_BIOSDISKS
&& nvalid
< nhd
; i
++) {
84 if (set_geometry(&d
, &ed
))
86 memset(&bibg
->disk
[nvalid
], 0, sizeof(bibg
->disk
[nvalid
]));
88 bibg
->disk
[nvalid
].sec
= d
.sec
;
89 bibg
->disk
[nvalid
].head
= d
.head
;
90 bibg
->disk
[nvalid
].cyl
= d
.cyl
;
91 bibg
->disk
[nvalid
].dev
= d
.dev
;
93 if (readsects(&d
, 0, 1, buf
, 0)) {
94 bibg
->disk
[nvalid
].flags
|= BI_GEOM_INVALID
;
100 printf("#%d: %x: C %d H %d S %d\n", nvalid
,
101 d
.dev
, d
.cyl
, d
.head
, d
.sec
);
102 printf(" sz %d fl %x cyl %d head %d sec %d totsec %"PRId64
" sbytes %d\n",
103 ed
.size
, ed
.flags
, ed
.cyl
, ed
.head
, ed
.sec
,
104 ed
.totsec
, ed
.sbytes
);
107 if (d
.flags
& BIOSDISK_INT13EXT
) {
108 bibg
->disk
[nvalid
].totsec
= ed
.totsec
;
109 bibg
->disk
[nvalid
].flags
|= BI_GEOM_EXTINT13
;
111 #ifdef BIOSDISK_EXTINFO_V3
113 printf(" edd_cfg %x, sig %x, len %x, bus %s type %s\n",
114 ed
.edd_cfg
, ed
.devpath_sig
, ed
.devpath_len
,
115 ed
.host_bus
, ed
.iface_type
);
118 /* The v3.0 stuff will help identify the disks */
119 if (ed
.size
>= offsetof(struct biosdisk_ext13info
, checksum
)
120 && ed
.devpath_sig
== EXTINFO_DEVPATH_SIGNATURE
) {
123 for (cp
= (void *)&ed
.devpath_sig
, cksum
= 0;
124 cp
<= (char *)&ed
.checksum
; cp
++) {
127 if ((cksum
& 0xff) != 0)
128 bibg
->disk
[nvalid
].flags
|= BI_GEOM_BADCKSUM
;
130 printf("checksum %x\n", cksum
& 0xff);
133 cp
= bus_names
[j
].name
;
136 if (strncmp(cp
, ed
.host_bus
,
137 sizeof(ed
.host_bus
)) == 0)
141 printf("bus %s (%x)\n", cp
? cp
: "null",
144 bibg
->disk
[nvalid
].flags
|= bus_names
[j
].flag
;
146 cp
= iface_names
[j
].name
;
149 if (strncmp(cp
, ed
.iface_type
,
150 sizeof(ed
.iface_type
)) == 0)
153 bibg
->disk
[nvalid
].flags
|= iface_names
[j
].flag
;
154 /* Dump raw interface path and device path */
155 bibg
->disk
[nvalid
].interface_path
=
156 ed
.interface_path
.ip_32
[0];
157 bibg
->disk
[nvalid
].device_path
=
158 ed
.device_path
.dp_64
[0];
160 printf("device %s (%x) interface %x path %llx\n",
163 ed
.interface_path
.ip_32
[0],
164 ed
.device_path
.dp_64
[0]);
169 for (j
= 0, cksum
= 0; j
< BIOSDISK_DEFAULT_SECSIZE
; j
++)
171 bibg
->disk
[nvalid
].cksum
= cksum
;
172 memcpy(bibg
->disk
[nvalid
].mbrparts
, &buf
[MBR_PART_OFFSET
],
173 sizeof(bibg
->disk
[nvalid
].mbrparts
));
179 BI_ADD(bibg
, BTINFO_BIOSGEOM
, sizeof(struct btinfo_biosgeom
)
180 + nvalid
* sizeof(struct bi_biosgeom_entry
));