Commit efedfdce authored by Robert Sprowson's avatar Robert Sprowson
Browse files

Adapt the capacity calculation based on reported sector size

Read the sector size from ATA Identify, so that the capacity reported is right when the sector size != 512B.
Increase the COMRESET recovery time a bit more to account for long spin up mechanical drives - the timeout's only used if a drive is present, so is harmless on fast (eg. SSD) drives which recover well before the timeout.

Tested on Titanium with an assortment of manufacturer drives, capacities, and sector sizes.

Version 0.05. Tagged as 'SATADriver-0_05'
parent 404dada8
/* (0.04)
/* (0.05)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 0.04
#define Module_MajorVersion_CMHG 0.05
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 09 Dec 2016
#define Module_Date_CMHG 16 Jun 2017
#define Module_MajorVersion "0.04"
#define Module_Version 4
#define Module_MajorVersion "0.05"
#define Module_Version 5
#define Module_MinorVersion ""
#define Module_Date "09 Dec 2016"
#define Module_Date "16 Jun 2017"
#define Module_ApplicationDate "09-Dec-16"
#define Module_ApplicationDate "16-Jun-17"
#define Module_ComponentName "SATADriver"
#define Module_ComponentPath "cddl/RiscOS/Sources/HWSupport/ATA/SATADriver"
#define Module_FullVersion "0.04"
#define Module_HelpVersion "0.04 (09 Dec 2016)"
#define Module_LibraryVersionInfo "0:4"
#define Module_FullVersion "0.05"
#define Module_HelpVersion "0.05 (16 Jun 2017)"
#define Module_LibraryVersionInfo "0:5"
......@@ -38,8 +38,6 @@
#include "message.h"
#include "op.h"
#define SECTOR_SIZE (512) // for now
#define RETRIES (4)
#define OFFSET_MODEL_NUMBER (27)
......@@ -47,11 +45,20 @@
#define OFFSET_MAX_LBA (60)
#define OFFSET_COMMAND_SET (83)
#define OFFSET_MAX_LBA48 (100)
#define OFFSET_PHY_LOG_SSZ (106)
#define OFFSET_SSZ_LO (117)
#define OFFSET_SSZ_HI (118)
#define COMMAND_SET_MBZ (1u<<15)
#define COMMAND_SET_MBO (1u<<14)
#define COMMAND_SET_LBA48 (1u<<10)
#define PHY_LOG_SSZ_MBZ (1u<<15)
#define PHY_LOG_SSZ_MBO (1u<<14)
#define PHY_LOG_SSZ_GT1_LOG_PER_PHY (1u<<13)
#define PHY_LOG_SSZ_SIZE_NOT_512 (1u<<12) /* In which case see 117-118 */
#define PHY_LOG_SSZ_COUNT_SHIFT 0
#define PHY_LOG_SSZ_COUNT_MASK (0xF<<PHY_LOG_SSZ_COUNT_SHIFT)
static void extract_model_number(const uint16_t *restrict identify_block, char *restrict buffer)
{
......@@ -128,10 +135,18 @@ _kernel_oserror *command_satadevices(void)
bool lba48 = (identify_block[OFFSET_COMMAND_SET] &
(COMMAND_SET_MBZ | COMMAND_SET_MBO | COMMAND_SET_LBA48)) ==
(COMMAND_SET_MBO | COMMAND_SET_LBA48);
uint64_t capacity = lba48 ?
SECTOR_SIZE * *(uint64_t *)&identify_block[OFFSET_MAX_LBA48] :
SECTOR_SIZE * (uint64_t) *(uint32_t *)&identify_block[OFFSET_MAX_LBA];
char capacity_string[12] = "";
size_t sector_size = 256;
if ((identify_block[OFFSET_PHY_LOG_SSZ] &
(PHY_LOG_SSZ_MBZ | PHY_LOG_SSZ_MBO | PHY_LOG_SSZ_SIZE_NOT_512)) ==
(PHY_LOG_SSZ_MBO | PHY_LOG_SSZ_SIZE_NOT_512))
{
sector_size = identify_block[OFFSET_SSZ_LO] | (identify_block[OFFSET_SSZ_HI] << 16);
}
sector_size = sector_size << 1; /* Expressed in 16b words */
uint64_t capacity = lba48 ?
sector_size * *(uint64_t *)&identify_block[OFFSET_MAX_LBA48] :
sector_size * (uint64_t) *(uint32_t *)&identify_block[OFFSET_MAX_LBA];
_swix(OS_ConvertVariform, _INR(0,4), &capacity, capacity_string, sizeof capacity_string, 8, 8);
printf("%s %s %s\n", message_lookup_direct("SATATypeATA"), name, capacity_string);
}
......
......@@ -43,7 +43,7 @@
/* Timeouts are in cs */
#define PORT_IDLE_TIMEOUT (50) // AHCI spec 10.1.2 advocates half-second wait for PxCMD.CR to clear after deasserting PxCMD.ST
#define COMRESET_ASSERT_TIME (5) // AHCI spec only advocates 1 millisecond, though
#define COMRESET_RECOVERY_TIME (75)
#define COMRESET_RECOVERY_TIME (250)
#define PM_PSCR_TIMEOUT (50)
#define DEVICE_CONTROL_OP_TIMEOUT (50)
#define SOFTWARE_RESET_ASSERT_TIME (1) /* really only needs 5us */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment