Changeset 57 for trunk/src/os2ahci/ahci.c
- Timestamp:
- Dec 14, 2010, 9:35:35 PM (15 years ago)
- File:
-
- 1 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
Note:
See TracChangeset
for help on using the changeset viewer.