Changeset 58724 in vbox
- Timestamp:
- Nov 17, 2015 3:32:43 PM (9 years ago)
- Location:
- trunk/src/VBox/Devices
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/PC/BIOS/ahci.c
r58044 r58724 360 360 361 361 ahci->abCmd[8] = (bios_dsk->drqp.lba >> 24) & 0xff; 362 ahci->abCmd[9] = 0;363 ahci->abCmd[10] = 0;362 ahci->abCmd[9] = (bios_dsk->drqp.lba >> 32) & 0xff; 363 ahci->abCmd[10] = (bios_dsk->drqp.lba >> 40) & 0xff; 364 364 ahci->abCmd[11] = 0; 365 365 … … 525 525 BX_PANIC("%s: device_id out of range %d\n", __func__, device_id); 526 526 527 DBG_AHCI("%s: %u sectors @ LBA %lu, device %d, port %d\n", __func__,528 bios_dsk->drqp.nsect, bios_dsk->drqp.lba, device_id,529 bios_dsk->ahcidev[device_id].port);527 DBG_AHCI("%s: %u sectors @ LBA 0x%llx, device %d, port %d\n", __func__, 528 bios_dsk->drqp.nsect, bios_dsk->drqp.lba, 529 device_id, bios_dsk->ahcidev[device_id].port); 530 530 531 531 high_bits_save(bios_dsk->ahci_seg :> 0); … … 557 557 BX_PANIC("%s: device_id out of range %d\n", __func__, device_id); 558 558 559 DBG_AHCI("%s: %u sectors @ LBA %lu, device %d, port %d\n", __func__,559 DBG_AHCI("%s: %u sectors @ LBA 0x%llx, device %d, port %d\n", __func__, 560 560 bios_dsk->drqp.nsect, bios_dsk->drqp.lba, device_id, 561 561 bios_dsk->ahcidev[device_id].port); … … 602 602 bios_dsk->drqp.nsect, bios_dsk->drqp.sect_sz); 603 603 604 bios_dsk->drqp.lba = (uint32_t)length << 8; //@todo: xfer length limit604 bios_dsk->drqp.lba = length << 8; //@todo: xfer length limit 605 605 bios_dsk->drqp.buffer = buffer; 606 606 bios_dsk->drqp.nsect = length / bios_dsk->drqp.sect_sz; … … 690 690 if (val == 0x101) 691 691 { 692 uint 32_t sectors;692 uint64_t sectors; 693 693 uint16_t cylinders, heads, spt; 694 694 chs_t lgeo; … … 713 713 sectors = *(uint32_t *)(abBuffer+(60*2)); // word 60 and word 61 714 714 715 /** @todo update sectors to be a 64 bit number (also lba...). */716 715 if (sectors == 0x0FFFFFFF) /* For disks bigger than ~128GB */ 717 sectors = *(uint 32_t *)(abBuffer+(100*2)); // words 100 to 103 (someday)718 719 DBG_AHCI("AHCI: %ldsectors\n", sectors);716 sectors = *(uint64_t *)(abBuffer+(100*2)); // words 100 to 103 717 718 DBG_AHCI("AHCI: 0x%llx sectors\n", sectors); 720 719 721 720 bios_dsk->ahcidev[devcount_ahci].port = u8Port; … … 759 758 set_geom_lba(&lgeo, sectors); /* Default EDD-style translated LBA geometry. */ 760 759 761 BX_INFO("AHCI %d-P#%d: PCHS=%u/%u/%u LCHS=%u/%u/%u %lu sectors\n", devcount_ahci, 762 u8Port, cylinders, heads, spt, lgeo.cylinders, lgeo.heads, lgeo.spt, sectors); 760 BX_INFO("AHCI %d-P#%d: PCHS=%u/%u/%u LCHS=%u/%u/%u 0x%llx sectors\n", devcount_ahci, 761 u8Port, cylinders, heads, spt, lgeo.cylinders, lgeo.heads, lgeo.spt, 762 sectors); 763 763 764 764 bios_dsk->devices[hd_index].lchs = lgeo; -
trunk/src/VBox/Devices/PC/BIOS/ata.c
r56292 r58724 109 109 bios_dsk->devices[device].pchs.cylinders = 0; 110 110 bios_dsk->devices[device].pchs.spt = 0; 111 bios_dsk->devices[device].sectors = 0;111 bios_dsk->devices[device].sectors = 0; 112 112 } 113 113 … … 207 207 uint16_t ata_cmd_data_in(bio_dsk_t __far *bios_dsk, uint16_t command, uint16_t count) 208 208 { 209 uint 32_t lba;209 uint64_t lba; 210 210 uint16_t iobase1, iobase2, blksize, mult_blk_cnt; 211 211 uint16_t cylinder; … … 256 256 if (lba + count >= 268435456) 257 257 { 258 sector = (lba & 0xff000000L) >> 24;259 cylinder = 0; /* The parameter lba is just a 32 bit value. */258 sector = (lba >> 24) & 0x00ff; 259 cylinder = (lba >> 32) & 0xffff; 260 260 outb(iobase1 + ATA_CB_SC, (count & 0xff00) >> 8); 261 261 outb(iobase1 + ATA_CB_SN, sector); … … 460 460 // Now we send a IDENTIFY command to ATA device 461 461 if (type == DSK_TYPE_ATA) { 462 uint 32_t sectors;462 uint64_t sectors; 463 463 uint16_t cylinders, heads, spt, blksize; 464 464 chs_t lgeo; … … 484 484 485 485 sectors = *(uint32_t *)(buffer+(60*2)); // word 60 and word 61 486 /** @todo update sectors to be a 64 bit number (also lba...). */487 486 if (sectors == 0x0FFFFFFF) /* For disks bigger than ~128GB */ 488 sectors = *(uint 32_t *)(buffer+(100*2)); // words 100 to 103 (someday)487 sectors = *(uint64_t *)(buffer+(100*2)); // words 100 to 103 489 488 switch (device) 490 489 { … … 595 594 switch (type) { 596 595 case DSK_TYPE_ATA: 597 sizeinmb = bios_dsk->devices[device].sectors; 598 sizeinmb >>= 11; 596 sizeinmb = (bios_dsk->devices[device].sectors >> 11); 599 597 case DSK_TYPE_ATAPI: 600 598 // Read ATA/ATAPI version … … 683 681 uint16_t ata_cmd_data_out(bio_dsk_t __far *bios_dsk, uint16_t command, uint16_t count) 684 682 { 685 uint 32_t lba;683 uint64_t lba; 686 684 char __far *buffer; 687 685 uint16_t iobase1, iobase2, blksize; … … 724 722 if (lba + count >= 268435456) 725 723 { 726 sector = (lba & 0xff000000L) >> 24;727 cylinder = 0; /* The parameter lba is just a 32 bit value. */724 sector = (lba >> 24) & 0x00ff; 725 cylinder = (lba >> 32) & 0xffff; 728 726 outb(iobase1 + ATA_CB_SC, (count & 0xff00) >> 8); 729 727 outb(iobase1 + ATA_CB_SN, sector); … … 837 835 /* CHS addressing. */ 838 836 bios_dsk->devices[device_id].blksize = n_sect * 0x200; 837 BX_DEBUG_ATA("%s: reading %u sectors (CHS)\n", __func__, n_sect); 839 838 status = ata_cmd_data_in(bios_dsk, ATA_CMD_READ_MULTIPLE, n_sect); 840 839 bios_dsk->devices[device_id].blksize = 0x200; 841 840 } else { 842 841 /* LBA addressing. */ 843 if (bios_dsk->drqp.lba + n_sect >= 268435456) 842 if (bios_dsk->drqp.lba + n_sect >= 268435456) { 843 BX_DEBUG_ATA("%s: reading %u sector (LBA,EXT)\n", __func__, n_sect); 844 844 status = ata_cmd_data_in(bios_dsk, ATA_CMD_READ_SECTORS_EXT, n_sect); 845 else {845 } else { 846 846 bios_dsk->devices[device_id].blksize = n_sect * 0x200; 847 BX_DEBUG_ATA("%s: reading %u sector (LBA,MULT)\n", __func__, n_sect); 847 848 status = ata_cmd_data_in(bios_dsk, ATA_CMD_READ_MULTIPLE, n_sect); 848 849 bios_dsk->devices[device_id].blksize = 0x200; -
trunk/src/VBox/Devices/PC/BIOS/disk.c
r56292 r58724 99 99 * geometry in case none was provided in CMOS. 100 100 */ 101 void set_geom_lba(chs_t __far *lgeo, uint 32_t nsectors)101 void set_geom_lba(chs_t __far *lgeo, uint64_t nsectors64) 102 102 { 103 103 uint32_t limit = 8257536; /* 1024 * 128 * 63 */ 104 uint32_t nsectors; 104 105 unsigned heads = 255; 105 106 int i; 106 107 108 nsectors = (nsectors64 >> 32) ? 0xFFFFFFFFL : (uint32_t)nsectors64; 107 109 /* Start with ~4GB limit, go down to 504MB. */ 108 110 for (i = 0; i < 4; ++i) { … … 331 333 void BIOSCALL int13_harddisk_ext(disk_regs_t r) 332 334 { 333 uint 32_t lba;335 uint64_t lba; 334 336 uint16_t ebda_seg = read_word(0x0040,0x000E); 335 337 uint16_t segment, offset; … … 384 386 offset = i13_ext->offset; 385 387 386 BX_DEBUG_INT13_HD("%s: %d sectors from lba %lu @ %04x:%04x\n", __func__, 387 count, i13_ext->lba1, segment, offset); 388 389 // Can't use 64 bits lba 388 // Get 64 bits lba and check 390 389 lba = i13_ext->lba2; 391 if (lba != 0L) { 392 BX_PANIC("%s: function %02x. Can't use 64bits lba\n", __func__, GET_AH()); 393 goto int13x_fail; 394 } 395 396 // Get 32 bits lba and check 397 lba = i13_ext->lba1; 390 lba <<= 32; 391 lba |= i13_ext->lba1; 392 393 BX_DEBUG_INT13_HD("%s: %d sectors from LBA 0x%llx @ %04x:%04x\n", __func__, 394 count, lba, segment, offset); 398 395 399 396 type = bios_dsk->devices[device].type; … … 467 464 dpt->spt = npspt; 468 465 dpt->blksize = blksize; 469 dpt->sector_count1 = lba; // FIXME should be Bit64470 dpt->sector_count2 = 0;466 dpt->sector_count1 = lba; 467 dpt->sector_count2 = lba >> 32; 471 468 } 472 469 -
trunk/src/VBox/Devices/PC/BIOS/ebda.h
r56292 r58724 193 193 chs_t lchs; /* Logical CHS geometry. */ 194 194 chs_t pchs; /* Physical CHS geometry. */ 195 uint 32_t sectors; /* Total sector count. */195 uint64_t sectors; /* Total sector count. */ 196 196 } disk_dev_t; 197 197 … … 201 201 */ 202 202 typedef struct { 203 uint 32_t lba; /* Starting LBA. */203 uint64_t lba; /* Starting LBA. */ 204 204 void __far *buffer; /* Read/write data buffer pointer. */ 205 205 uint8_t dev_id; /* Device ID; index into devices array. */ … … 318 318 int __fastcall ahci_write_sectors(bio_dsk_t __far *bios_dsk); 319 319 320 extern void set_geom_lba(chs_t __far *lgeo, uint 32_t nsectors);320 extern void set_geom_lba(chs_t __far *lgeo, uint64_t nsectors); 321 321 322 322 // @todo: put this elsewhere (and change/eliminate?) -
trunk/src/VBox/Devices/PC/BIOS/print.c
r56292 r58724 145 145 // Supports %[format_width][length]format 146 146 // where format can be x,X,u,d,s,S,c 147 // and the optional length modifier is l (ell) 147 // and the optional length modifier is l (ell, long 32-bit) or ll 148 // (long long, 64-bit). 149 // Only x,X work with ll 148 150 //-------------------------------------------------------------------------- 149 151 void bios_printf(uint16_t action, const char *s, ...) … … 190 192 put_uint(action, arg, format_width, 0); 191 193 } 194 else if (c == 'l' && s[1] == 'l') { 195 uint64_t llval; 196 uint16_t *cp16; 197 198 s += 2; 199 c = *s; 200 cp16 = (uint16_t *)&llval; 201 cp16[0] = arg; 202 cp16[1] = va_arg( args, uint16_t ); 203 cp16[2] = va_arg( args, uint16_t ); 204 cp16[3] = va_arg( args, uint16_t ); 205 if (c == 'x' || c == 'X') { 206 if (format_width == 0) 207 format_width = 16; 208 if (c == 'x') 209 hexadd = 'a'; 210 else 211 hexadd = 'A'; 212 for (i=format_width-1; i>=0; i--) { 213 nibble = (llval >> (i * 4)) & 0x000f; 214 send (action, (nibble<=9)? (nibble+'0') : (nibble-10+hexadd)); 215 } 216 } else { 217 BX_PANIC("bios_printf: unknown %ll format\n"); 218 } 219 } 192 220 else if (c == 'l') { 193 221 s++; -
trunk/src/VBox/Devices/PC/BIOS/scsi.c
r56292 r58724 49 49 50 50 /* Command opcodes. */ 51 #define SCSI_SERVICE_ACT 0x9e 51 52 #define SCSI_INQUIRY 0x12 52 #define SCSI_READ_CAP ACITY0x2553 #define SCSI_READ_CAP_10 0x25 53 54 #define SCSI_READ_10 0x28 54 55 #define SCSI_WRITE_10 0x2a 56 #define SCSI_READ_CAP_16 0x10 /* Not an opcode by itself, sub-action for the "Service Action" */ 57 #define SCSI_READ_16 0x88 58 #define SCSI_WRITE_16 0x8a 55 59 56 60 /* Data transfer direction. */ … … 69 73 } cdb_rw10; 70 74 75 /* READ_16/WRITE_16 CDB layout. */ 76 typedef struct { 77 uint16_t command; /* Command. */ 78 uint64_t lba; /* LBA, MSB first! */ 79 uint32_t nsect32; /* Sector count, MSB first! */ 80 uint8_t pad1; /* Unused. */ 81 uint8_t pad2; /* Unused. */ 82 } cdb_rw16; 83 71 84 #pragma pack() 72 85 73 86 ct_assert(sizeof(cdb_rw10) == 10); 74 87 ct_assert(sizeof(cdb_rw16) == 16); 75 88 76 89 void insb_discard(unsigned nbytes, unsigned port); … … 94 107 while (status & VBSCSI_BUSY); 95 108 96 97 sizes = ((length >> 12) & 0xF0) | cbCDB; 109 sizes = ((length >> 12) & 0xF0) | (cbCDB == 16) ? 0 : cbCDB; 98 110 outb(io_base + VBSCSI_REGISTER_COMMAND, target_id); /* Write the target ID. */ 99 111 outb(io_base + VBSCSI_REGISTER_COMMAND, SCSI_TXDIR_FROM_DEVICE); /* Write the transfer direction. */ … … 146 158 147 159 148 sizes = ((length >> 12) & 0xF0) | cbCDB;160 sizes = ((length >> 12) & 0xF0) | (cbCDB == 16) ? 0 : cbCDB; 149 161 outb(io_base + VBSCSI_REGISTER_COMMAND, target_id); /* Write the target ID. */ 150 162 outb(io_base + VBSCSI_REGISTER_COMMAND, SCSI_TXDIR_TO_DEVICE); /* Write the transfer direction. */ … … 185 197 } 186 198 199 static uint64_t swap_64(uint64_t val) 200 { 201 uint64_t rval; 202 203 rval = swap_32(val & 0xffffffff); 204 rval <<= 32; 205 rval |= swap_32(val >> 32); 206 207 return rval; 208 } 209 187 210 /** 188 211 * Read sectors from an attached SCSI device. … … 195 218 { 196 219 uint8_t rc; 197 cdb_rw1 0cdb;198 uint 16_t count;220 cdb_rw16 cdb; 221 uint32_t count; 199 222 uint16_t io_base; 200 223 uint8_t target_id; … … 208 231 209 232 /* Prepare a CDB. */ 210 cdb.command = SCSI_READ_1 0;211 cdb.lba = swap_ 32(bios_dsk->drqp.lba);233 cdb.command = SCSI_READ_16; 234 cdb.lba = swap_64(bios_dsk->drqp.lba); 212 235 cdb.pad1 = 0; 213 cdb.nsect = swap_16(count);236 cdb.nsect32 = swap_32(count); 214 237 cdb.pad2 = 0; 215 238 … … 221 244 count, device_id, bios_dsk->scsidev[device_id].target_id); 222 245 223 rc = scsi_cmd_data_in(io_base, target_id, (void __far *)&cdb, 1 0,246 rc = scsi_cmd_data_in(io_base, target_id, (void __far *)&cdb, 16, 224 247 bios_dsk->drqp.buffer, (count * 512L)); 225 248 … … 244 267 { 245 268 uint8_t rc; 246 cdb_rw1 0cdb;247 uint 16_t count;269 cdb_rw16 cdb; 270 uint32_t count; 248 271 uint16_t io_base; 249 272 uint8_t target_id; … … 257 280 258 281 /* Prepare a CDB. */ 259 cdb.command = SCSI_WRITE_1 0;260 cdb.lba = swap_ 32(bios_dsk->drqp.lba);282 cdb.command = SCSI_WRITE_16; 283 cdb.lba = swap_64(bios_dsk->drqp.lba); 261 284 cdb.pad1 = 0; 262 cdb.nsect = swap_16(count);285 cdb.nsect32 = swap_32(count); 263 286 cdb.pad2 = 0; 264 287 … … 269 292 count, device_id, bios_dsk->scsidev[device_id].target_id); 270 293 271 rc = scsi_cmd_data_out(io_base, target_id, (void __far *)&cdb, 1 0,294 rc = scsi_cmd_data_out(io_base, target_id, (void __far *)&cdb, 16, 272 295 bios_dsk->drqp.buffer, (count * 512L)); 273 296 … … 403 426 { 404 427 uint8_t rc; 405 uint8_t aCDB[1 0];428 uint8_t aCDB[16]; 406 429 uint8_t hd_index, devcount_scsi; 407 430 … … 428 451 if (devcount_scsi < BX_MAX_SCSI_DEVICES) 429 452 { 430 uint32_t sectors, sector_size, cylinders; 453 uint64_t sectors, t; 454 uint32_t sector_size, cylinders; 431 455 uint16_t heads, sectors_per_track; 432 456 uint8_t hdcount; … … 435 459 /* Issue a read capacity command now. */ 436 460 _fmemset(aCDB, 0, sizeof(aCDB)); 437 aCDB[0] = SCSI_READ_CAPACITY; 438 439 rc = scsi_cmd_data_in(io_base, i, aCDB, 10, buffer, 8); 461 aCDB[0] = SCSI_SERVICE_ACT; 462 aCDB[1] = SCSI_READ_CAP_16; 463 aCDB[13] = 32; /* Allocation length. */ 464 465 rc = scsi_cmd_data_in(io_base, i, aCDB, 16, buffer, 32); 440 466 if (rc != 0) 441 467 BX_PANIC("%s: SCSI_READ_CAPACITY failed\n", __func__); 442 468 443 /* Build sector number and size from the buffer. */ 444 //@todo: byte swapping for dword sized items should be farmed out... 445 sectors = ((uint32_t)buffer[0] << 24) 446 | ((uint32_t)buffer[1] << 16) 447 | ((uint32_t)buffer[2] << 8) 448 | ((uint32_t)buffer[3]); 449 ++sectors; /* Returned value is the last LBA, zero-based. */ 450 451 sector_size = ((uint32_t)buffer[4] << 24) 452 | ((uint32_t)buffer[5] << 16) 453 | ((uint32_t)buffer[6] << 8) 454 | ((uint32_t)buffer[7]); 469 /* The value returned is the last addressable LBA, not 470 * the size, which what "+ 1" is for. 471 */ 472 sectors = swap_64(*(uint64_t *)buffer) + 1; 473 474 sector_size = ((uint32_t)buffer[8] << 24) 475 | ((uint32_t)buffer[9] << 16) 476 | ((uint32_t)buffer[10] << 8) 477 | ((uint32_t)buffer[11]); 455 478 456 479 /* We only support the disk if sector size is 512 bytes. */ … … 497 520 heads = 255; 498 521 sectors_per_track = 63; 522 /* Approximate x / (255 * 63) using shifts */ 523 t = (sectors >> 6) + (sectors >> 12); 524 cylinders = (t >> 8) + (t >> 16); 499 525 } 500 526 else if (sectors >= (uint32_t)2 * 1024 * 1024) … … 502 528 heads = 128; 503 529 sectors_per_track = 32; 530 cylinders = sectors >> 12; 504 531 } 505 532 else … … 507 534 heads = 64; 508 535 sectors_per_track = 32; 536 cylinders = sectors >> 11; 509 537 } 510 cylinders = (uint32_t)(sectors / (heads * sectors_per_track));511 538 } 512 539 … … 523 550 bios_dsk->devices[hd_index].translation = GEO_TRANSLATION_LBA; 524 551 525 /* Write LCHS values. */552 /* Write LCHS/PCHS values. */ 526 553 bios_dsk->devices[hd_index].lchs.heads = heads; 527 554 bios_dsk->devices[hd_index].lchs.spt = sectors_per_track; 528 if (cylinders > 1024)529 bios_dsk->devices[hd_index].lchs.cylinders = 1024;530 else531 bios_dsk->devices[hd_index].lchs.cylinders = (uint16_t)cylinders;532 533 BX_INFO("SCSI %d-ID#%d: LCHS=%u/%u/%u %lu sectors\n", devcount_scsi,534 i, (uint16_t)cylinders, heads, sectors_per_track, sectors);535 536 /* Write PCHS values. */537 555 bios_dsk->devices[hd_index].pchs.heads = heads; 538 556 bios_dsk->devices[hd_index].pchs.spt = sectors_per_track; 539 if (cylinders > 1024) 557 558 if (cylinders > 1024) { 559 bios_dsk->devices[hd_index].lchs.cylinders = 1024; 540 560 bios_dsk->devices[hd_index].pchs.cylinders = 1024; 541 else 561 } else { 562 bios_dsk->devices[hd_index].lchs.cylinders = (uint16_t)cylinders; 542 563 bios_dsk->devices[hd_index].pchs.cylinders = (uint16_t)cylinders; 564 } 565 566 BX_INFO("SCSI %d-ID#%d: LCHS=%lu/%u/%u 0x%llx sectors\n", devcount_scsi, 567 i, (uint32_t)cylinders, heads, sectors_per_track, sectors); 543 568 544 569 bios_dsk->devices[hd_index].sectors = sectors; -
trunk/src/VBox/Devices/Storage/VBoxSCSI.cpp
r57358 r58724 176 176 { 177 177 uint8_t cbCDB = uVal & 0x0F; 178 179 if (cbCDB == 0) 180 cbCDB = 16; 178 181 if (cbCDB > VBOXSCSI_CDB_SIZE_MAX) 179 182 vboxscsiReset(pVBoxSCSI, true /*fEverything*/); -
trunk/src/VBox/Devices/Storage/VBoxSCSI.h
r56427 r58724 88 88 89 89 /** Maximum CDB size the BIOS driver sends. */ 90 #define VBOXSCSI_CDB_SIZE_MAX 1 090 #define VBOXSCSI_CDB_SIZE_MAX 16 91 91 92 92 typedef struct VBOXSCSI … … 101 101 uint8_t cbCDB; 102 102 /** The command to issue. */ 103 uint8_t abCDB[ 12];103 uint8_t abCDB[VBOXSCSI_CDB_SIZE_MAX + 4]; 104 104 /** Current position in the array. */ 105 105 uint8_t iCDB;
Note:
See TracChangeset
for help on using the changeset viewer.