Skip to content

Commit 6ed2876

Browse files
committed
ata.device [44.42] improved ATAPI support and System/Format improved
1 parent 717b532 commit 6ed2876

File tree

7 files changed

+118
-126
lines changed

7 files changed

+118
-126
lines changed

rom/devs/ata/ata.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,8 @@ static void cmd_GetGeometry(struct IORequest *io, LIBBASETYPEPTR LIBBASE)
644644
dg->dg_TrackSectors = unit->au_Sectors;
645645
dg->dg_BufMemType = MEMF_PUBLIC;
646646
dg->dg_DeviceType = unit->au_DevType;
647-
//if (dg->dg_DeviceType != DG_DIRECT_ACCESS)
648-
dg->dg_Flags = (unit->au_Flags & AF_Removable) ? DGF_REMOVABLE : 0;
647+
//if (dg->dg_DeviceType != DG_DIRECT_ACCESS)
648+
dg->dg_Flags = (unit->au_Flags & AF_Removable) ? DGF_REMOVABLE : 0;
649649
//else dg->dg_Flags = 0;
650650
dg->dg_Reserved = 0;
651651

@@ -1188,7 +1188,7 @@ void BusTaskCode(struct ata_Bus *bus, struct ataBase *ATABase)
11881188

11891189
struct ata_Controller *ataNode = NULL;
11901190

1191-
ata_RegisterVolume(0, 0, unit);
1191+
ata_RegisterVolume(unit->au_StartCyl, unit->au_EndCyl, unit);
11921192

11931193
//OOP_GetAttr(bus->ab_Object, aHidd_ATABus_Controller, (IPTR *)ataNode); // [WD]: This does not work, replaced buy code below
11941194

@@ -1226,7 +1226,7 @@ void BusTaskCode(struct ata_Bus *bus, struct ataBase *ATABase)
12261226
}
12271227
else
12281228
{
1229-
ata_RegisterVolume(0, unit->au_Cylinders - 1, unit);
1229+
ata_RegisterVolume(unit->au_StartCyl, unit->au_EndCyl, unit);
12301230
}
12311231
}
12321232
else
@@ -1315,7 +1315,7 @@ void BusTaskCode2(struct ata_Bus *bus, struct ataBase *ATABase)
13151315
{
13161316
struct ata_Controller *ataNode = NULL;
13171317

1318-
ata_RegisterVolume(0, 0, unit);
1318+
ata_RegisterVolume(unit->au_StartCyl, unit->au_EndCyl, unit);
13191319

13201320
//OOP_GetAttr(bus->ab_Object, aHidd_ATABus_Controller, (IPTR *)&ataNode);
13211321

@@ -1344,7 +1344,7 @@ void BusTaskCode2(struct ata_Bus *bus, struct ataBase *ATABase)
13441344
}
13451345
else
13461346
{
1347-
ata_RegisterVolume(0, unit->au_Cylinders - 1, unit);
1347+
ata_RegisterVolume(unit->au_StartCyl, unit->au_EndCyl, unit);
13481348
}
13491349
}
13501350
else

rom/devs/ata/ata.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
##begin config
22
basename ata
3-
version 44.41
3+
version 44.42
44
libbasetype struct ataBase
55
residentpri 4
66
beginio_func BeginIO

rom/devs/ata/ata.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ struct ata_Unit
331331
ULONG au_Capacity; /* Highest sector accessible through LBA28 */
332332
UQUAD au_Capacity48; /* Highest sector accessible through LBA48 */
333333
ULONG au_Cylinders;
334+
ULONG au_StartCyl; // Start Cylinder for Partition on ATAPI Devices
335+
ULONG au_EndCyl; // End Cylinder for Partition on ATAPI Devices
334336
UBYTE au_Heads;
335337
UBYTE au_Sectors;
336338
UBYTE au_Model[41];

rom/devs/ata/ata_init.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,15 @@ BOOL ata_RegisterVolume(ULONG StartCyl, ULONG EndCyl, struct ata_Unit *unit)
6969
DD(bug("[ATA>>]:-ata_RegisterVolume called on unknown devicetype\n"));
7070
}
7171

72-
if (unit->au_UnitNum < 10)
73-
dosdevname[2] += unit->au_UnitNum % 10;
74-
else
75-
dosdevname[2] = 'A' - 10 + unit->au_UnitNum;
72+
if (unit->au_UnitNum < 10) dosdevname[2] += unit->au_UnitNum % 10;
73+
else dosdevname[2] = 'A' - 10 + unit->au_UnitNum;
7674

77-
pp[0] = (IPTR)dosdevname;
78-
pp[1] = (IPTR)MOD_NAME_STRING;
79-
pp[2] = unit->au_UnitNum;
75+
pp[0] = (IPTR)dosdevname;
76+
pp[1] = (IPTR)MOD_NAME_STRING;
77+
pp[2] = unit->au_UnitNum;
8078
pp[DE_TABLESIZE + 4] = DE_BOOTBLOCKS;
81-
pp[DE_SIZEBLOCK + 4] = 1 << (unit->au_SectorShift - 2);
79+
80+
pp[DE_SIZEBLOCK + 4] = 1 << (unit->au_SectorShift - 2); // LONG (32-bit) per Sector = (#Bytes/Sector)/4 = SectorSift-2
8281
pp[DE_NUMHEADS + 4] = unit->au_Heads;
8382
pp[DE_SECSPERBLOCK + 4] = 1;
8483
pp[DE_BLKSPERTRACK + 4] = unit->au_Sectors;
@@ -98,9 +97,10 @@ BOOL ata_RegisterVolume(ULONG StartCyl, ULONG EndCyl, struct ata_Unit *unit)
9897

9998
if (devnode)
10099
{
101-
DD(bug("[ATA>>]:-ata_RegisterVolume=%b, type=0x%08lx | StartCyl=%d | EndCyl=%d .. ", devnode->dn_Name, pp[DE_DOSTYPE + 4], StartCyl, EndCyl));
100+
DD(bug("[ATA>>]:-ata_RegisterVolume=%b, DosType=0x%08lx | LowCyl=%d | HighCyl=%d | Heads=%d | Blocksize=%d | BlockPerTrack=%d .. ",
101+
devnode->dn_Name, pp[DE_DOSTYPE + 4], StartCyl, EndCyl, unit->au_Heads, 1 << unit->au_SectorShift, unit->au_Sectors));
102102

103-
if (unit->au_DevType == DG_DIRECT_ACCESS)
103+
if (unit->au_DevType == DG_DIRECT_ACCESS) // && ((unit->au_Flags & AF_Removable) == 0))
104104
{
105105
AddBootNode(pp[DE_BOOTPRI + 4], ADNF_STARTPROC, devnode, NULL);
106106
DD(bug("BootNode (Direct Access Medium)\n"));

rom/devs/ata/lowlevel.c

Lines changed: 46 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static void ata_IRQPIOReadAtapi(struct ata_Unit *unit, UBYTE status)
211211

212212
AGAIN:
213213
retry_busy = 5000000;
214-
retry_datareq = 500;
214+
retry_datareq = 5000;
215215

216216
WAITBUSY:
217217
status = PIO_In(unit->au_Bus, ata_Status);
@@ -244,7 +244,7 @@ static void ata_IRQPIOReadAtapi(struct ata_Unit *unit, UBYTE status)
244244
{
245245
ata_IRQSetHandler(unit, &ata_IRQNoData, NULL, 0, 0);
246246
unit->au_cmd_error = HFERR_BadStatus;
247-
DERROR(bug("[ATAPI] ata_IRQPIOReadAtapi: ERROR = RetryCount (500) reached ZERO on ATAF_DATAREQ SET\n"));
247+
DERROR(bug("[ATAPI] ata_IRQPIOReadAtapi: ERROR = RetryCount (5000) reached ZERO on ATAF_DATAREQ SET\n"));
248248
return;
249249
}
250250

@@ -281,13 +281,13 @@ static void ata_IRQPIOReadAtapi(struct ata_Unit *unit, UBYTE status)
281281
DERROR(status = PIO_In(unit->au_Bus, ata_Status));
282282
DERROR(if (status & ATAF_ERROR) bug("\n[ATAPI] *** ERROR: ata_IRQPIOReadAtapi - ATAF_ERROR"));
283283

284-
retry_busy = 0;
284+
retry_busy = 5000000;
285285
do
286286
{
287287
status = PIO_In(bus, atapi_Status);
288288
ata_WaitNano(400, bus->ab_Base);
289-
retry_busy++;
290-
if (retry_busy == 5000000)
289+
retry_busy--;
290+
if (retry_busy == 0)
291291
{
292292
DERROR(bug("[ATAPI] *** ERROR: ata_IRQPIOReadAtapi - ATAF_BUSY not cleared!\n"));
293293
break;
@@ -303,7 +303,7 @@ static void ata_IRQPIOWriteAtapi(struct ata_Unit *unit, UBYTE status)
303303

304304
AGAINW:
305305
retry_busy = 5000000;
306-
retry_datareq = 500;
306+
retry_datareq = 5000;
307307

308308
WAITBUSYW:
309309
status = PIO_In(unit->au_Bus, ata_Status);
@@ -335,7 +335,7 @@ static void ata_IRQPIOWriteAtapi(struct ata_Unit *unit, UBYTE status)
335335
{
336336
ata_IRQSetHandler(unit, &ata_IRQNoData, NULL, 0, 0);
337337
unit->au_cmd_error = HFERR_BadStatus;
338-
DERROR(bug("\n[ATAPI] *** ERROR: ata_IRQPIOWriteAtapi: ERROR = RetryCount (500) reached ZERO on ATAF_DATAREQ SET\n"));
338+
DERROR(bug("\n[ATAPI] *** ERROR: ata_IRQPIOWriteAtapi: ERROR = RetryCount (5000) reached ZERO on ATAF_DATAREQ SET\n"));
339339
return;
340340
}
341341

@@ -372,13 +372,13 @@ static void ata_IRQPIOWriteAtapi(struct ata_Unit *unit, UBYTE status)
372372
DERROR(status = PIO_In(unit->au_Bus, ata_Status));
373373
DERROR(if (status & ATAF_ERROR) bug("\n[ATAPI] *** ERROR: ata_IRQPIOWriteAtapi - ATAF_ERROR"));
374374

375-
retry_busy = 0;
375+
retry_busy = 5000000;
376376
do
377377
{
378378
status = PIO_In(bus, atapi_Status);
379379
ata_WaitNano(400, bus->ab_Base);
380-
retry_busy++;
381-
if (retry_busy == 5000000)
380+
retry_busy--;
381+
if (retry_busy == 0)
382382
{
383383
DERROR(bug("[ATAPI] *** ERROR: ata_IRQPIOWriteAtapi - ATAF_BUSY not cleared!\n"));
384384
break;
@@ -579,7 +579,7 @@ static BYTE atapi_SendPacket(struct ata_Unit *unit, APTR packet, APTR data, LONG
579579
UBYTE status;
580580

581581
ULONG retry_busy = 200000;
582-
ULONG retry_datareq = 500;
582+
ULONG retry_datareq = 5000;
583583

584584
UBYTE cmd[12] = {0};
585585
register int t=5,l=0;
@@ -625,7 +625,7 @@ static BYTE atapi_SendPacket(struct ata_Unit *unit, APTR packet, APTR data, LONG
625625
{
626626
DDD(bug("\n"));
627627
DERROR(bug("[ATAPI] atapi_SendPacket - ERROR: ATAF_BUSY | ATAF_DATAREQ not cleared, status = %u\n", status));
628-
break;
628+
return HFERR_BadStatus;
629629
}
630630
} while ((status & (ATAF_BUSY | ATAF_DATAREQ)) != 0); // Wait for BSY and DRQ to CLEAR
631631
DDD(bug("\n"));
@@ -650,7 +650,7 @@ static BYTE atapi_SendPacket(struct ata_Unit *unit, APTR packet, APTR data, LONG
650650
{
651651
DDD(bug("\n"));
652652
DERROR(bug("[ATAPI] atapi_SendPacket - ERROR: ATAF_DATAREQ not set!"));
653-
break;
653+
return HFERR_BadStatus;
654654
}
655655
} while ((status & ATAF_DATAREQ) != ATAF_DATAREQ); // Wait for DRQ to SET
656656
DDD(bug("\n"));
@@ -1183,25 +1183,38 @@ static BYTE ata_Identify(struct ata_Unit *unit)
11831183
unit->au_Heads = 1;
11841184
unit->au_Sectors = 75;
11851185
unit->au_Cylinders = 4440;
1186+
unit->au_StartCyl = 0; // Handled by CD Filesystem
1187+
unit->au_EndCyl = 0; // Handled by CD Filesystem
1188+
unit->au_Capacity = unit->au_Heads * unit->au_Sectors * unit->au_Cylinders;
1189+
unit->au_Capacity48 = unit->au_Capacity;
11861190
break;
11871191

11881192
case DG_DIRECT_ACCESS:
1189-
unit->au_SectorShift = 9;
1190-
/*if (!strcmp("LS-120", &unit->au_Model[0])) // CHANGE: HARDCODED SUCKS
1193+
//DINIT(bug("[ATA:%02ld] ata_Identify: MODEL[0]=%s | MODEL[8]=%s | STRCMP = %u\n", unit->au_UnitNum, &unit->au_Model[0], &unit->au_Model[8], strcmp("ZIP 100", &unit->au_Model[8]) ));
1194+
1195+
/*if (strcmp("LS-120", &unit->au_Model[0]) == 0) // CHANGE: HARDCODED SUCKS
11911196
{
11921197
unit->au_Heads = 2;
11931198
unit->au_Sectors = 18;
11941199
unit->au_Cylinders = 6848;
11951200
}
1196-
else if (!strcmp("ZIP 100 ", &unit->au_Model[8])) // CHANGE: HARDCODED SUCKS
1197-
{
1198-
unit->au_Heads = 1;
1199-
unit->au_Sectors = 64;
1200-
unit->au_Cylinders = 3072;
1201-
}*/
1201+
else if (strcmp("ZIP 100", &unit->au_Model[8]) == 0) // CHANGE: HARDCODED SUCKS
1202+
{*/
1203+
unit->au_SectorShift = 9;
1204+
unit->au_Heads = 16;
1205+
unit->au_Sectors = 63;
1206+
unit->au_Cylinders = 195;
1207+
unit->au_StartCyl = 4; // First partition starts on Cylinder 4
1208+
unit->au_EndCyl = unit->au_Cylinders - 1; // Partition covers full disk
1209+
unit->au_Capacity = unit->au_Heads * unit->au_Sectors * unit->au_Cylinders;
1210+
unit->au_Capacity48 = unit->au_Capacity;
1211+
1212+
//}
12021213
break;
12031214
}
12041215

1216+
DINIT(bug("[ATA:%02ld] ata_Identify: HARDCODE = Cap28=%u | Cap48=%llu | CHS=%u/%u/%u\n", unit->au_UnitNum, unit->au_Capacity, unit->au_Capacity48, unit->au_Cylinders, unit->au_Heads, unit->au_Sectors);)
1217+
12051218
ULONG retry_test = 10;
12061219
while(!(atapi_TestUnitOK(unit)) || (retry_test > 5))
12071220
{
@@ -1213,19 +1226,9 @@ static BYTE ata_Identify(struct ata_Unit *unit)
12131226
}
12141227

12151228
} else {
1216-
/*
1217-
For drive capacities > 8.3GB assume maximal possible layout.
1218-
It really doesn't matter here, as BIOS will not handle them in
1219-
CHS way anyway :)
1220-
i guess this just solves that weirdo div-by-zero crash, if nothing
1221-
else...
1222-
*/
12231229
if (supportLBA && ((unit->au_Drive->id_LBA48Sectors > (63 * 255 * 1024)) || (unit->au_Drive->id_LBASectors > (63 * 255 * 1024))))
12241230
{
12251231
ULONG div = 1;
1226-
/*
1227-
* TODO: this shouldn't be casted down here.
1228-
*/
12291232
ULONG sec = unit->au_Capacity48;
12301233

12311234
if (sec < unit->au_Capacity48)
@@ -1236,9 +1239,6 @@ static BYTE ata_Identify(struct ata_Unit *unit)
12361239

12371240
unit->au_Sectors = 63;
12381241
sec /= 63;
1239-
/*
1240-
* keep dividing by 2
1241-
*/
12421242
do
12431243
{
12441244
if (((sec >> 1) << 1) != sec)
@@ -1267,6 +1267,10 @@ static BYTE ata_Identify(struct ata_Unit *unit)
12671267
unit->au_Cylinders = unit->au_Drive->id_OldLCylinders;
12681268
unit->au_Heads = unit->au_Drive->id_OldLHeads;
12691269
unit->au_Sectors = unit->au_Drive->id_OldLSectors;
1270+
1271+
unit->au_StartCyl = 0; // RDB starts on Cylinder 0
1272+
unit->au_EndCyl = unit->au_Cylinders - 1; // Full disk
1273+
12701274
if (!supportLBA) {
12711275
unit->au_Capacity = unit->au_Cylinders * unit->au_Heads * unit->au_Sectors;
12721276
unit->au_Capacity48 = unit->au_Capacity;
@@ -1580,6 +1584,9 @@ BOOL atapi_TestUnitOK(struct ata_Unit *unit)
15801584

15811585
result = unit->au_DirectSCSI(unit, &sc);
15821586

1587+
DINIT(bug("[ATA:%02ld] atapi_TestUnitOK: DETECTED = LBA = %u | Block = %u\n",
1588+
unit->au_UnitNum, capacity.logicalsectors, capacity.blocksize));
1589+
15831590
if ( (unit->au_cmd_error) == HFERR_BadStatus )
15841591
{
15851592
DINIT(bug("[ATA:%02ld] unit->au_cmd_error == HFERR_BadStatus\n", unit->au_UnitNum));
@@ -1590,20 +1597,13 @@ BOOL atapi_TestUnitOK(struct ata_Unit *unit)
15901597
unit->au_Flags |= AF_DiscChanged; // Set AF_DiscChanged
15911598
}
15921599

1593-
/*unit->au_Capacity = 196575;
1594-
unit->au_Capacity48 = 0;
1595-
unit->au_Heads = 16;
1596-
unit->au_Cylinders = 195;
1597-
unit->au_Sectors = 63;
1598-
capacity.blocksize = 512;*/
1599-
1600-
DINIT(bug("[ATA:%02ld] atapi_TestUnitOK: LBA = %u | Block = %u | Cylinders = %u | Heads = %u | Sectors = %u |",
1600+
DINIT(bug("[ATA:%02ld] atapi_TestUnitOK: REGISTERED = LBA = %u | Block = %u | Cylinders = %u | Heads = %u | Sectors = %u |",
16011601
unit->au_UnitNum, unit->au_Capacity, 1<<unit->au_SectorShift , unit->au_Cylinders, unit->au_Heads, unit->au_Sectors));
16021602

16031603
DINIT(bug("Result = %d | Media = %s | Change = %s\n",
16041604
result, unit->au_Flags & AF_DiscPresent ? "YES" : "NO", unit->au_Flags & AF_DiscChanged ? "YES" : "NO"));
16051605

1606-
if (result == 0)
1606+
if (result == 0 || result == 29)
16071607
{
16081608
return(TRUE); // No Media but valid Device
16091609
} else {
@@ -1616,9 +1616,10 @@ BOOL atapi_TestUnitOK(struct ata_Unit *unit)
16161616
unit->au_Flags |= AF_DiscChanged; // Set AF_DiscChanged
16171617
}
16181618

1619-
if ((unit->au_DevType) == DG_DIRECT_ACCESS)
1619+
if ( ((unit->au_DevType) == DG_DIRECT_ACCESS) && ((unit->au_Flags & AF_Removable) == 0) )
16201620
{
16211621
unit->au_Capacity = capacity.logicalsectors;
1622+
unit->au_Capacity48 = capacity.logicalsectors;
16221623

16231624
#define HEADS_PER_CYLINDER 16
16241625
#define SECTORS_PER_TRACK 63
@@ -1630,7 +1631,7 @@ BOOL atapi_TestUnitOK(struct ata_Unit *unit)
16301631
unit->au_Sectors = (UBYTE)SECTORS_PER_TRACK;
16311632
}
16321633

1633-
DINIT(bug("[ATA:%02ld] atapi_TestUnitOK: LBA = %u | Block = %u | Cylinders = %u | Heads = %u | Sectors = %u | ",
1634+
DINIT(bug("[ATA:%02ld] atapi_TestUnitOK: REGISTERED = LBA = %u | Block = %u | Cylinders = %u | Heads = %u | Sectors = %u | ",
16341635
unit->au_UnitNum, unit->au_Capacity, capacity.blocksize, unit->au_Cylinders, unit->au_Heads, unit->au_Sectors));
16351636

16361637
DINIT(bug("Result = %d | Media = %s | Change = %s\n",
@@ -1940,16 +1941,6 @@ static BYTE atapi_EndCmd(struct ata_Unit *unit)
19401941
error = PIO_In(bus, atapi_Error);
19411942
DERROR(bug("[ATA:%02ld] atapi_EndCmd: ERROR code 0x%lx\n", unit->au_UnitNum, error));
19421943

1943-
/*if (error != 0x60)
1944-
{
1945-
ULONG sense_lenght = 18;
1946-
UBYTE* sense_data = AllocMem(sense_lenght, MEMF_ANY|MEMF_PUBLIC);
1947-
1948-
atapi_RequestSense(unit, sense_data, sense_lenght);
1949-
1950-
FreeMem(sense_data,sense_lenght);
1951-
}*/
1952-
19531944
return ErrorMap[error >> 4];
19541945
}
19551946
}

0 commit comments

Comments
 (0)