1228022Smarius/*- 2228022Smarius * Copyright (c) 2011 Marius Strobl <marius@FreeBSD.org> 3228022Smarius * All rights reserved. 4228022Smarius * 5228022Smarius * Redistribution and use in source and binary forms, with or without 6228022Smarius * modification, are permitted provided that the following conditions 7228022Smarius * are met: 8228022Smarius * 1. Redistributions of source code must retain the above copyright 9228022Smarius * notice, this list of conditions and the following disclaimer. 10228022Smarius * 2. Redistributions in binary form must reproduce the above copyright 11228022Smarius * notice, this list of conditions and the following disclaimer in the 12228022Smarius * documentation and/or other materials provided with the distribution. 13228022Smarius * 14228022Smarius * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15228022Smarius * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16228022Smarius * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17228022Smarius * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18228022Smarius * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19228022Smarius * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20228022Smarius * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21228022Smarius * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22228022Smarius * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23228022Smarius * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24228022Smarius * SUCH DAMAGE. 25228022Smarius */ 26228022Smarius 27228022Smarius#include <sys/cdefs.h> 28228022Smarius__FBSDID("$FreeBSD$"); 29228022Smarius 30228022Smarius#include <sys/param.h> 31228022Smarius#include <sys/systm.h> 32228022Smarius 33228022Smarius#include <cam/cam.h> 34228022Smarius#include <cam/cam_ccb.h> 35228022Smarius 36228022Smarius#include <machine/md_var.h> 37228022Smarius 38228022Smariusint 39228022Smariusscsi_da_bios_params(struct ccb_calc_geometry *ccg) 40228022Smarius{ 41228022Smarius uint32_t secs_per_cylinder, size_mb; 42228022Smarius 43228022Smarius /* 44228022Smarius * The VTOC8 disk label only uses 16-bit fields for cylinders, heads 45228022Smarius * and sectors so the geometry of large disks has to be adjusted. 46228022Smarius * We generally use the sizing used by cam_calc_geometry(9), except 47228022Smarius * when it would overflow the cylinders, in which case we use 255 48228022Smarius * heads and sectors. This allows disks up to the 2TB limit of the 49228022Smarius * extended VTOC8. 50228022Smarius * XXX this doesn't match the sizing used by OpenSolaris, as that 51228022Smarius * would exceed the 8-bit ccg->heads and ccg->secs_per_track. 52228022Smarius */ 53228022Smarius if (ccg->block_size == 0) 54228022Smarius return (0); 55228022Smarius size_mb = (1024L * 1024L) / ccg->block_size; 56228022Smarius if (size_mb == 0) 57228022Smarius return (0); 58228022Smarius size_mb = ccg->volume_size / size_mb; 59228022Smarius if (ccg->volume_size > (uint64_t)65535 * 255 * 63) { 60228022Smarius ccg->heads = 255; 61228022Smarius ccg->secs_per_track = 255; 62228022Smarius } else if (size_mb > 1024) { 63228022Smarius ccg->heads = 255; 64228022Smarius ccg->secs_per_track = 63; 65228022Smarius } else { 66228022Smarius ccg->heads = 64; 67228022Smarius ccg->secs_per_track = 32; 68228022Smarius } 69228022Smarius secs_per_cylinder = ccg->heads * ccg->secs_per_track; 70228022Smarius if (secs_per_cylinder == 0) 71228022Smarius return (0); 72228022Smarius ccg->cylinders = ccg->volume_size / secs_per_cylinder; 73228022Smarius return (1); 74228022Smarius} 75