ata.device been restructured and separated bus access code.
Would it be beneficial to implement a HIDD API for them? It would actually allow users to construct own version of ata.device, and also to add drivers at runtime.
Current code sends EXECUTE DEVICE DIAGNOSTIC separately to both master and slave (if both exists). Only if both devices are PATA hard disks. ATAPI is checked earlier so it does not matter in this case.
ATA spec says:
The devices using this interface shall be programmed by the host computer to perform commands and return status to the host at command completion. When two devices are daisychained on the interface, commands are written in parallel to both devices, and for all except the EXECUTE DEVICE DIAGNOSTIC command, only the selected device executes the command. Both devices shall execute an EXECUTE DEVICE DIAGNOSTIC command regardless of which device is selected, and Device 1 shall post its status to Device 0 via PDIAG-. When the SRST bit in the Device Control register is set to one, both devices shall perform the software reset protocol.
Code is either missing comment explaining why it does it this way or it is a bug :) Which means both devices run EXECUTE DEVICE DIAGNOSTIC twice which could cause issues in detection code. After ATA slave has finished (EXECUTE DEVICE DIAGNOSTIC done), there is nothing that re-checks status of master. It still could be executing this command if it is slower device than slave.
If I understood ATA spec correctly, master will wait for slave to finish using /PDIAG line but when slave finishes, master may still be executing diagnostics. I'd only run it once, instead of adding second test.
The bus probing code needs a little more work still -:
- Create list of legacy ports
- Enumerate PCI devices (removing used legacy ports from list)
- Add remaining legacy ports..
- Create legacy port list
- Enumerate PCI Devices (removing legacy nodes) - and check for attached units
- if no units found, add remaining legacy ports.
IDE doubler handling will be only in m68k-amiga platform files.
IDE doubler is a device that doubles number of IDE buses (two separate buses from single IDE bus, both can have master and slave) If Amiga IDE doubler is installed (even if there are no drives connected to extra IDE bus), IDE detection hangs.
IDE doublers take over 3rd (bit 2) IDE address line and uses it as a IDE bus 0/1 select line. (Who invents these kinds of hacks?) It unfortunately also means ATA Alternate Status and Device Control registers will be inaccessible. Currently ata.device requires both.
I can easily "emulate" both registers in Amiga specific code, only need some small changes in common interrupt handler but should "no altstatus/devcon" handling be in common code? I mean use alternate method if alt port == 0?
Are there any other platform(s) that used IDE doublers? It isn't Amiga specific but it seems they can be only used with legacy PIO-only hardware.
AFAIK all FastATA models come with boot rom that includes custom driver, ata.device is not needed or used. It is reported that FastATA boot rom crashes, reason unknown. (FastATA expansion or rom dump is probably needed to find the problem). Also it is too early for speed optimizations (and this one could introduce new compatibility problems). Here are the docs for FastATA 1200, 4000 and ZIV.
It unfortunately also means ATA Alternate Status and Device Control registers will be inaccessible. Currently ata.device requires both. I can easily "emulate" both registers in Amiga specific code, only > need some small changes in common interrupt handler but should "no altstatus/devcon" handling be in common code? I mean use alternate method if alt port == 0?
IDE doubler code is now in amiga specific file (it isn't even tested on real machines yet, too early to have any kind of common support). Only change in common code is small interrupt handler Status/AltStatus re-ordering.
AFAIK in this case you simply use Status instead of AltStatus. AltStatus is used in our ata.device because Status resets interrupt status, and interrupt can be lost. Happened sometimes on slow machines. So, in case of status, we could avoid that "if" using IOAlt = IOBase. Can the same be told about devcon? If yes, the problem doesn't exist at all.
Are there any other platform(s) that used IDE doublers? None is known. It isn't Amiga specific but it seems they can be only used with legacy PIO-only hardware. Yes, DMA is quite another beast. By the way, i see you override dma code in Amiga port to NOPs. Does this mean that DMA operations are bus-specific and should be moved into bus driver? Would DMA on Amiga PCI bus differ from this code? I really want to HIDDize this part. There are no Amiga IDE DMA devices, never has been, probably never will be. All are PIO-only, even newer 3rd party ones. That's why I wanted to get rid of "useless" DMA code.
Even PCI bridge boards? IIRC at least some of them are DMA-capable? Maybe but this ata.device only handles Gayle compatible PIO-IDE. Is it even possible to handle both PCI-style and custom IDE ports using same ata.device? (also technically Gayle ata.device should be called "scsi.device" but maybe no one really cares. I hope..)
I finally got an A4000 and noticed that ata.device hangs. Configuration is CF card (8G SanDisk, master) and Plextor PX-708A (slave).
For some unknown reason ATA_EXECUTE_DIAG causes an interrupt. (Yes, nIEN is set!) This shouldn't happen according to ATA specs, I checked ATA-1, ATA-2 and ATA-7 specs.. This totally hangs the machine because there is no one to clear the interrupt.
So either ata_AltControl does not work on A4000 (but on the other hand ata_AltStatus is clearly visible if I manually read the register) or either IDE device (or both) are buggy.
I can easily fix this by setting up the interrupt handler before ata_InitBus() call and let ata_HandleIRQ() to clear spurious interrupts.
Can I call bus->ab_Driver->CreateInterrupt(bus); early (in ata_RegisterBus, before ata_InitBus()) or is there some reason why it is called much later? What is the alternative fix if it breaks other platforms? Add CreateInterruptEarly() or something to ata_BusDriver structure?
This fix is also needed if IDE doubler is in use because it makes ata_AltControl inaccessible. Maybe this also fixes other reported IDE detection hangs? I remember seeing something similar on forums.