Changeset 57
- Timestamp:
- Dec 14, 2010, 9:35:35 PM (15 years ago)
- Location:
- trunk/src/os2ahci
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/os2ahci/ahci.c
r55 r57 33 33 34 34 35 /* #define LBATEST36 * uncomment to perform sector mapping test of first drive */37 38 #define LBATEST_SECTORS_PER_READ 6439 #define LBATEST_SECTOR_SIZE 51240 41 42 35 /* ------------------------ typedefs and structures ------------------------ */ 43 36 … … 46 39 static void ahci_setup_device (AD_INFO *ai, int p, int d, u16 *id_buf); 47 40 static void _cdecl _far timeout_callback (ULONG timer_handle, ULONG p1, ULONG p2); 48 49 #ifdef LBATEST50 static void lba_test (AD_INFO *ai, int p, int d, u16 *id_buf);51 #endif52 41 53 42 /* ------------------------ global/static variables ------------------------ */ … … 1517 1506 } 1518 1507 1519 #ifdef LBATEST1520 /* if LBATEST is defined, we perform a sector mapping test1521 * for the first HD attached to the first adapter.1522 * The purose of this test is to determine if the sector1523 * mapping is correct throughout the entire disk.1524 */1525 if (total_dev_cnt == 1) {1526 lba_test(ai, p, 0, id_buf);1527 }1528 #endif1529 1530 1508 1531 1509 } … … 1574 1552 1575 1553 1576 /*******************************************************************************1577 * Perform LBA to CHS mapping test.1578 * The purpose of this test is to find out if the driver's CHS to LBA mapping1579 * is correct throughout the entire physical hard disk.1580 *1581 * To perform the test, attach the test HD to a Linux box and run lbatest1582 * to write each sector's LBA to its first 4 bytes, then compile/install1583 * the driver with LBATEST defined.1584 */1585 #ifdef LBATEST1586 static void lba_test(AD_INFO *ai, int p, int d, u16 *id_buf)1587 {1588 u32 total_sectors = 0;1589 u32 sector;1590 int i;1591 unsigned char _far *buf;1592 u32 err_cnt = 0;1593 int rc;1594 u16 cbt = LBATEST_SECTOR_SIZE * LBATEST_SECTORS_PER_READ;1595 u32 phys_addr;1596 1597 /* determine number of sectors of this HD */1598 if (id_buf[ATA_ID_CFS_ENABLE_2] & 0x400) {1599 /* 48-bit LBA supported */1600 if (ATA_CAPACITY48_H(id_buf) != 0) {1601 /* more than 32 bits for number of sectors */1602 total_sectors = 0xffffffffUL;1603 } else {1604 total_sectors = ATA_CAPACITY48_L(id_buf);1605 }1606 } else {1607 /* 28-bit LBA */1608 total_sectors = ATA_CAPACITY(id_buf) & 0x0fffffffUL;1609 }1610 1611 /* allocate buffer */1612 spin_lock(drv_lock);1613 if (DevHelp_AllocPhys(cbt, 1, &phys_addr)) {1614 printf("Failed to allocate %ld bytes phys memory for lbatest\n");1615 spin_unlock(drv_lock);1616 return;1617 }1618 if (DevHelp_PhysToVirt(phys_addr, (USHORT) cbt, (PVOID) &buf, &i)) {1619 printf("Failed to convert phys addr to virt\n");1620 DevHelp_FreePhys(phys_addr);1621 spin_unlock(drv_lock);1622 return;1623 }1624 spin_unlock(drv_lock);1625 1626 /* go... */1627 memset(buf, 0x00, sizeof(buf));1628 for (sector = 0; sector < total_sectors; sector += LBATEST_SECTORS_PER_READ) {1629 1630 /* write progress to serial terminal */1631 if (sector % 1000 == 0) {1632 printf("lbatest: read %ldk sectors\n", sector / 1000);1633 }1634 1635 /* read appropriate number of sectors */1636 rc = ahci_exec_polled_cmd(ai, p, 0, 500, ATA_CMD_READ_EXT,1637 AP_SECTOR_48, sector, (u16) 0,1638 AP_VADDR, (void _far *) buf, cbt,1639 AP_COUNT, (u16) LBATEST_SECTORS_PER_READ,1640 AP_DEVICE, 0x4000,1641 AP_END);1642 1643 /* verify lba numbers */1644 for (i = 0; i < LBATEST_SECTORS_PER_READ; i++) {1645 if (*((u32 _far*)(buf + i * LBATEST_SECTOR_SIZE)) != sector + i) {1646 printf("lbatest: read LBA 0x%08lx from sector 0x%08lx\n",1647 *((u32 _far*) buf), sector + i);1648 err_cnt++;1649 }1650 1651 }1652 }1653 1654 printf("lbatest: passed with %ld errors\n", err_cnt);1655 1656 cleanup_lbatest:1657 DevHelp_FreePhys(phys_addr);1658 1659 LBA test compiled?1660 1661 }1662 #endif -
trunk/src/os2ahci/ata.c
r56 r57 118 118 /* 28-bit sector address */ 119 119 ata_cmd.lba_l = va_arg(va, u32); 120 dprintf("LBA28: 0x%08lx\n", ata_cmd.lba_l); 120 121 if (ata_cmd.lba_l & 0xf0000000UL) { 121 122 dprintf("error: LBA-28 address %ld has more than 28 bits\n", ata_cmd.lba_l); 122 123 return(-1); 123 124 } 124 dprintf("LBA28: 0x%08lx\n", ata_cmd.lba_l); 125 /* add upper 4 bits to device field */ 126 ata_cmd.device |= (ata_cmd.lba_l >> 24) & 0x0fU; 127 /* only lower 24 bits come into _debug lba_l */ 128 ata_cmd.lba_l &= 0x00ffffffUL; 125 129 break; 126 130 … … 133 137 134 138 case AP_DEVICE: 135 /* ATA device byte */ 136 ata_cmd.device = va_arg(va, u16) >> 8; 139 /* ATA device byte; note that this byte contains the highest 140 * 4 bits of LBA-28 address; we have to leave them alone here. */ 141 ata_cmd.device |= (va_arg(va, u16) & 0xf000U) >> 8; 137 142 break; 138 143 … … 313 318 fis[12] = (u8) ata_cmd->count; 314 319 fis[13] = (u8) (ata_cmd->count >> 8); 315 316 phex(fis, 14, "FIS:\n");317 320 } 318 321 -
trunk/src/os2ahci/ata.h
r39 r57 434 434 u16 features; /* feature bits */ 435 435 u16 count; /* count register (e.g. number of sectors) */ 436 u32 lba_l; /* low 2 8 bits of LBA(32 bits for 48-bit devices) */436 u32 lba_l; /* low 24 bits of LBA-28 (32 bits for 48-bit devices) */ 437 437 u16 lba_h; /* high 16 bits of LBA for 48-bit devices */ 438 438 u8 cmd; /* ATA command field */ 439 u8 device; /* ATA device field */439 u8 device; /* ATA device field and upper 4 bits of LBA-28 */ 440 440 } ATA_CMD; 441 441
Note:
See TracChangeset
for help on using the changeset viewer.