Lines Matching +full:boot +full:- +full:blks

1 /*-
33 * - NetBSD libi386/biosdisk.c
34 * - FreeBSD biosboot/disk.c
197 if (dev->dv_type == DEVT_DISK) in bd_get_bdinfo_list()
199 if (dev->dv_type == DEVT_CD) in bd_get_bdinfo_list()
201 if (dev->dv_type == DEVT_FD) in bd_get_bdinfo_list()
214 bdi = bd_get_bdinfo_list(dev->d_dev); in bd_get_bdinfo()
220 if (unit == dev->d_unit) in bd_get_bdinfo()
241 if (bd->bd_unit == biosdev) { in bd_bios2unit()
243 bd->bd_unit); in bd_bios2unit()
249 return (-1); in bd_bios2unit()
259 bdi = bd_get_bdinfo_list(dev->dd.d_dev); in bd_unit2bios()
261 return (-1); in bd_unit2bios()
265 if (unit == dev->dd.d_unit) in bd_unit2bios()
266 return (bd->bd_unit); in bd_unit2bios()
269 return (-1); in bd_unit2bios()
273 * Use INT13 AH=15 - Read Drive Type.
313 bd->bd_sectorsize = BIOSDISK_SECSIZE; in fd_init()
314 bd->bd_flags = BD_FLOPPY; in fd_init()
315 bd->bd_unit = unit; in fd_init()
322 if (bd->bd_sectors == 0) in fd_init()
323 bd->bd_flags |= BD_NO_MEDIA; in fd_init()
350 bd->bd_unit = base + unit; in bd_init()
379 * Information from bootable CD-ROM.
385 int ret = -1; in bd_get_diskinfo_cd()
389 bc_sp.sp_size = sizeof (bc_sp) - sizeof (bc_sp.sp_dummy); in bd_get_diskinfo_cd()
394 v86.edx = bd->bd_unit; in bd_get_diskinfo_cd()
400 bc_sp.sp_drive == bd->bd_unit) { in bd_get_diskinfo_cd()
401 bd->bd_cyl = ((bc_sp.sp_cylsec & 0xc0) << 2) + in bd_get_diskinfo_cd()
403 bd->bd_sec = bc_sp.sp_cylsec & 0x3f; in bd_get_diskinfo_cd()
404 bd->bd_hds = bc_sp.sp_head + 1; in bd_get_diskinfo_cd()
405 bd->bd_sectors = (uint64_t)bd->bd_cyl * bd->bd_hds * bd->bd_sec; in bd_get_diskinfo_cd()
408 /* Floppy or hard-disk emulation */ in bd_get_diskinfo_cd()
409 bd->bd_sectorsize = BIOSDISK_SECSIZE; in bd_get_diskinfo_cd()
410 return (-1); in bd_get_diskinfo_cd()
412 bd->bd_sectorsize = 2048; in bd_get_diskinfo_cd()
413 bd->bd_flags = BD_MODEEDD | BD_CDROM; in bd_get_diskinfo_cd()
419 * If this is the boot_drive, default to non-emulation bootable CD-ROM. in bd_get_diskinfo_cd()
421 if (ret != 0 && bd->bd_unit >= 0x88) { in bd_get_diskinfo_cd()
422 bd->bd_cyl = 0; in bd_get_diskinfo_cd()
423 bd->bd_hds = 1; in bd_get_diskinfo_cd()
424 bd->bd_sec = 15; in bd_get_diskinfo_cd()
425 bd->bd_sectorsize = 2048; in bd_get_diskinfo_cd()
426 bd->bd_flags = BD_MODEEDD | BD_CDROM; in bd_get_diskinfo_cd()
427 bd->bd_sectors = 0; in bd_get_diskinfo_cd()
433 * here - some systems do get hung with those. in bd_get_diskinfo_cd()
440 if (bd->bd_sectors == 0) in bd_get_diskinfo_cd()
441 bd->bd_sectors = 4173824; in bd_get_diskinfo_cd()
453 return (-1); in bc_add()
456 return (-1); in bc_add()
458 bd->bd_unit = biosdev; in bc_add()
461 return (-1); in bc_add()
493 /* extended disk access functions (AH=42h-44h,47h,48h) supported */ in bd_check_extensions()
521 v86.edx = bd->bd_unit; in bd_get_diskinfo_std()
531 bd->bd_cyl = ((v86.ecx & 0xc0) << 2) + ((v86.ecx & 0xff00) >> 8) + 1; in bd_get_diskinfo_std()
532 /* Convert max head # -> # of heads */ in bd_get_diskinfo_std()
533 bd->bd_hds = ((v86.edx & 0xff00) >> 8) + 1; in bd_get_diskinfo_std()
534 bd->bd_sec = v86.ecx & 0x3f; in bd_get_diskinfo_std()
535 bd->bd_type = v86.ebx; in bd_get_diskinfo_std()
536 bd->bd_sectors = (uint64_t)bd->bd_cyl * bd->bd_hds * bd->bd_sec; in bd_get_diskinfo_std()
562 params->len = sizeof(struct edd_params_v3); in bd_get_diskinfo_ext()
566 v86.edx = bd->bd_unit; in bd_get_diskinfo_ext()
580 if (params->sector_size >= 512 && in bd_get_diskinfo_ext()
581 params->sector_size <= 16384 && in bd_get_diskinfo_ext()
582 (params->sector_size % BIOSDISK_SECSIZE) == 0) in bd_get_diskinfo_ext()
583 bd->bd_sectorsize = params->sector_size; in bd_get_diskinfo_ext()
585 bd->bd_cyl = params->cylinders; in bd_get_diskinfo_ext()
586 bd->bd_hds = params->heads; in bd_get_diskinfo_ext()
587 bd->bd_sec = params->sectors_per_track; in bd_get_diskinfo_ext()
589 if (params->sectors != 0) { in bd_get_diskinfo_ext()
590 total = params->sectors; in bd_get_diskinfo_ext()
592 total = (uint64_t)params->cylinders * in bd_get_diskinfo_ext()
593 params->heads * params->sectors_per_track; in bd_get_diskinfo_ext()
595 bd->bd_sectors = total; in bd_get_diskinfo_ext()
608 bd->bd_flags &= ~BD_NO_MEDIA; in bd_int13probe()
610 if ((bd->bd_flags & BD_CDROM) != 0) { in bd_int13probe()
614 edd = bd_check_extensions(bd->bd_unit); in bd_int13probe()
616 bd->bd_flags |= BD_MODEINT13; in bd_int13probe()
618 bd->bd_flags |= BD_MODEEDD1; in bd_int13probe()
620 bd->bd_flags |= BD_MODEEDD3; in bd_int13probe()
623 if (bd->bd_sectorsize == 0) in bd_int13probe()
624 bd->bd_sectorsize = BIOSDISK_SECSIZE; in bd_int13probe()
630 if (bd->bd_unit < 0x80) { in bd_int13probe()
632 bd_reset_disk(bd->bd_unit); in bd_int13probe()
638 v86.edx = bd->bd_unit; in bd_int13probe()
647 if (ret != 0 || bd->bd_sectors == 0) in bd_int13probe()
650 if (ret != 0 && bd->bd_unit < 0x80) { in bd_int13probe()
652 bd->bd_cyl = 80; in bd_int13probe()
653 bd->bd_hds = 2; in bd_int13probe()
654 bd->bd_sec = 18; in bd_int13probe()
655 bd->bd_sectors = 2880; in bd_int13probe()
657 bd->bd_flags |= BD_NO_MEDIA; in bd_int13probe()
662 if (bd->bd_sectors != 0 && edd != 0) { in bd_int13probe()
663 bd->bd_sec = 63; in bd_int13probe()
664 bd->bd_hds = 255; in bd_int13probe()
665 bd->bd_cyl = in bd_int13probe()
666 (bd->bd_sectors + bd->bd_sec * bd->bd_hds - 1) / in bd_int13probe()
667 bd->bd_sec * bd->bd_hds; in bd_int13probe()
671 if ((bd->bd_flags & BD_FLOPPY) != 0) in bd_int13probe()
677 dv_name, bd->bd_unit); in bd_int13probe()
682 if (bd->bd_sec == 0) in bd_int13probe()
683 bd->bd_sec = 63; in bd_int13probe()
684 if (bd->bd_hds == 0) in bd_int13probe()
685 bd->bd_hds = 255; in bd_int13probe()
687 if (bd->bd_sectors == 0) in bd_int13probe()
688 bd->bd_sectors = (uint64_t)bd->bd_cyl * bd->bd_hds * bd->bd_sec; in bd_int13probe()
690 DPRINTF("unit 0x%x geometry %d/%d/%d\n", bd->bd_unit, bd->bd_cyl, in bd_int13probe()
691 bd->bd_hds, bd->bd_sec); in bd_int13probe()
723 printf("%s devices:", dev->dv_name); in bd_print_common()
727 i = -1; in bd_print_common()
731 switch (dev->dv_type) { in bd_print_common()
745 dev->dv_name, i, drive + i, in bd_print_common()
746 (bd->bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA ? in bd_print_common()
748 (uintmax_t)bd->bd_sectors, in bd_print_common()
749 bd->bd_sectorsize); in bd_print_common()
753 if ((bd->bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA) in bd_print_common()
756 if (dev->dv_type != DEVT_DISK) in bd_print_common()
764 bd->bd_sectorsize * bd->bd_sectors, in bd_print_common()
765 bd->bd_sectorsize) == 0) { in bd_print_common()
767 dev->dv_name, i); in bd_print_common()
809 bd = bd_get_bdinfo(&dev->dd); in bd_disk_get_sectors()
813 disk.dd.d_dev = dev->dd.d_dev; in bd_disk_get_sectors()
814 disk.dd.d_unit = dev->dd.d_unit; in bd_disk_get_sectors()
819 size = bd->bd_sectors * bd->bd_sectorsize; in bd_disk_get_sectors()
820 if (disk_open(&disk, size, bd->bd_sectorsize) == 0) { in bd_disk_get_sectors()
824 return (size / bd->bd_sectorsize); in bd_disk_get_sectors()
834 * sliced - are they after the first BSD slice, or the DOS
851 bd = bd_get_bdinfo(&dev->dd); in bd_open()
855 if ((bd->bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA) { in bd_open()
858 if ((bd->bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA) in bd_open()
861 if (bd->bd_bcache == NULL) in bd_open()
862 bd->bd_bcache = bcache_allocate(); in bd_open()
864 if (bd->bd_open == 0) in bd_open()
865 bd->bd_sectors = bd_disk_get_sectors(dev); in bd_open()
866 bd->bd_open++; in bd_open()
869 if (dev->dd.d_dev->dv_type == DEVT_DISK) { in bd_open()
870 rc = disk_open(dev, bd->bd_sectors * bd->bd_sectorsize, in bd_open()
871 bd->bd_sectorsize); in bd_open()
873 bd->bd_open--; in bd_open()
874 if (bd->bd_open == 0) { in bd_open()
875 bcache_free(bd->bd_bcache); in bd_open()
876 bd->bd_bcache = NULL; in bd_open()
891 dev = (struct disk_devdesc *)f->f_devdata; in bd_close()
892 bd = bd_get_bdinfo(&dev->dd); in bd_close()
896 bd->bd_open--; in bd_close()
897 if (bd->bd_open == 0) { in bd_close()
898 bcache_free(bd->bd_bcache); in bd_close()
899 bd->bd_bcache = NULL; in bd_close()
901 if (dev->dd.d_dev->dv_type == DEVT_DISK) in bd_close()
913 dev = (struct disk_devdesc *)f->f_devdata; in bd_ioctl()
914 bd = bd_get_bdinfo(&dev->dd); in bd_ioctl()
918 if (dev->dd.d_dev->dv_type == DEVT_DISK) { in bd_ioctl()
926 *(uint32_t *)data = bd->bd_sectorsize; in bd_ioctl()
929 *(uint64_t *)data = bd->bd_sectors * bd->bd_sectorsize; in bd_ioctl()
947 bd = bd_get_bdinfo(&dev->dd); in bd_strategy()
953 bcd.dv_cache = bd->bd_bcache; in bd_strategy()
956 if (dev->dd.d_dev->dv_type == DEVT_DISK) { in bd_strategy()
958 offset = dev->d_offset * bd->bd_sectorsize; in bd_strategy()
972 size_t blks, blkoff, bsize, bio_size, rest; in bd_realstrategy() local
976 bd = bd_get_bdinfo(&dev->dd); in bd_realstrategy()
977 if (bd == NULL || (bd->bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA) in bd_realstrategy()
995 dblk = offset / bd->bd_sectorsize; in bd_realstrategy()
996 blkoff = offset % bd->bd_sectorsize; in bd_realstrategy()
1009 blks = size / bd->bd_sectorsize; in bd_realstrategy()
1010 if (blks == 0 || (size % bd->bd_sectorsize) != 0) in bd_realstrategy()
1011 blks++; in bd_realstrategy()
1013 if (dblk > dblk + blks) in bd_realstrategy()
1025 if (dev->dd.d_dev->dv_type == DEVT_DISK) { in bd_realstrategy()
1028 disk_blocks /= bd->bd_sectorsize; in bd_realstrategy()
1030 d_offset = dev->d_offset; in bd_realstrategy()
1033 disk_blocks = bd->bd_sectors * (bd->bd_sectorsize / in bd_realstrategy()
1034 BIOSDISK_SECSIZE) - d_offset; in bd_realstrategy()
1043 if (dblk + blks >= d_offset + disk_blocks) { in bd_realstrategy()
1044 blks = d_offset + disk_blocks - dblk; in bd_realstrategy()
1045 size = blks * bd->bd_sectorsize; in bd_realstrategy()
1046 DPRINTF("short I/O %d", blks); in bd_realstrategy()
1050 while (bio_size > bd->bd_sectorsize) { in bd_realstrategy()
1054 bio_size -= bd->bd_sectorsize; in bd_realstrategy()
1058 if (bio_size / bd->bd_sectorsize == 0) in bd_realstrategy()
1066 while (blks > 0) { in bd_realstrategy()
1067 int x = min(blks, bio_size / bd->bd_sectorsize); in bd_realstrategy()
1072 bsize = bd->bd_sectorsize * x - blkoff; in bd_realstrategy()
1091 bsize = bd->bd_sectorsize - blkoff; in bd_realstrategy()
1094 } else if (rest < bd->bd_sectorsize) { in bd_realstrategy()
1104 bsize = bd->bd_sectorsize * x; in bd_realstrategy()
1125 rest -= bsize; in bd_realstrategy()
1126 blks -= x; in bd_realstrategy()
1139 bd_edd_io(bdinfo_t *bd, daddr_t dblk, int blks, caddr_t dest, in bd_edd_io() argument
1147 packet.count = blks; in bd_edd_io()
1157 v86.edx = bd->bd_unit; in bd_edd_io()
1169 bd_chs_io(bdinfo_t *bd, daddr_t dblk, int blks, caddr_t dest, in bd_chs_io() argument
1176 bpc = bd->bd_sec * bd->bd_hds; /* blocks per cylinder */ in bd_chs_io()
1180 hd = x / bd->bd_sec; /* offset / blocks per track */ in bd_chs_io()
1181 sec = x % bd->bd_sec; /* offset into track */ in bd_chs_io()
1183 /* correct sector number for 1-based BIOS numbering */ in bd_chs_io()
1194 v86.eax = CMD_WRITE_CHS | blks; in bd_chs_io()
1196 v86.eax = CMD_READ_CHS | blks; in bd_chs_io()
1198 v86.edx = (hd << 8) | bd->bd_unit; in bd_chs_io()
1217 bd_io(struct disk_devdesc *dev, bdinfo_t *bd, daddr_t dblk, int blks, in bd_io() argument
1224 /* Just in case some idiot actually tries to read/write -1 blocks... */ in bd_io()
1225 if (blks < 0) in bd_io()
1226 return (-1); in bd_io()
1230 * out the boot disk after installation. hrs and kuriyama discovered in bd_io()
1242 if (bd->bd_flags & BD_MODEEDD) in bd_io()
1243 result = bd_edd_io(bd, dblk, blks, dest, dowrite); in bd_io()
1245 result = bd_chs_io(bd, dblk, blks, dest, dowrite); in bd_io()
1248 if (bd->bd_flags & BD_NO_MEDIA) in bd_io()
1249 bd->bd_flags &= ~BD_NO_MEDIA; in bd_io()
1253 bd_reset_disk(bd->bd_unit); in bd_io()
1263 bd->bd_flags |= BD_NO_MEDIA; in bd_io()
1268 if (result != 0 && (bd->bd_flags & BD_NO_MEDIA) == 0) { in bd_io()
1271 "to %lld: 0x%x\n", dev->dd.d_dev->dv_name, in bd_io()
1272 dev->dd.d_unit, blks, dest, VTOP(dest), dblk, in bd_io()
1276 "(0x%x): 0x%x\n", dev->dd.d_dev->dv_name, in bd_io()
1277 dev->dd.d_unit, blks, dblk, dest, VTOP(dest), in bd_io()
1309 bd = bd_get_bdinfo(&dev->dd); in bd_getdev()
1311 return (-1); in bd_getdev()
1314 DPRINTF("unit %d BIOS device %d", dev->dd.d_unit, biosdev); in bd_getdev()
1315 if (biosdev == -1) /* not a BIOS device */ in bd_getdev()
1316 return (-1); in bd_getdev()
1318 if (dev->dd.d_dev->dv_type == DEVT_DISK) { in bd_getdev()
1319 if (disk_open(dev, bd->bd_sectors * bd->bd_sectorsize, in bd_getdev()
1320 bd->bd_sectorsize) != 0) /* oops, not a viable device */ in bd_getdev()
1321 return (-1); in bd_getdev()
1324 slice = dev->d_slice + 1; in bd_getdev()
1325 partition = dev->d_partition; in bd_getdev()
1330 if (bd->bd_type == DT_ATAPI) { in bd_getdev()
1344 if (dev->dd.d_dev->dv_type == DEVT_CD) { in bd_getdev()
1352 * we pass -C to the boot args if we are the boot device. in bd_getdev()