2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Andrew Schultz
33 * Device model implementation for an IDE disk
41 #include "base/chunk_generator.hh"
42 #include "base/cprintf.hh" // csprintf
43 #include "base/trace.hh"
44 #include "dev/disk_image.hh"
45 #include "dev/ide_disk.hh"
46 #include "dev/ide_ctrl.hh"
47 #include "dev/tsunami.hh"
48 #include "dev/tsunami_pchip.hh"
49 #include "sim/builder.hh"
50 #include "sim/sim_object.hh"
51 #include "sim/root.hh"
52 #include "arch/isa_traits.hh"
55 using namespace TheISA
;
57 IdeDisk::IdeDisk(const string
&name
, DiskImage
*img
,
59 : SimObject(name
), ctrl(NULL
), image(img
), diskDelay(delay
),
60 dmaTransferEvent(this), dmaReadCG(NULL
), dmaReadWaitEvent(this),
61 dmaWriteCG(NULL
), dmaWriteWaitEvent(this), dmaPrdReadEvent(this),
62 dmaReadEvent(this), dmaWriteEvent(this)
64 // Reset the device state
67 // fill out the drive ID structure
68 memset(&driveID
, 0, sizeof(struct ataparams
));
70 // Calculate LBA and C/H/S values
75 uint32_t lba_size
= image
->size();
76 if (lba_size
>= 16383*16*63) {
86 if ((lba_size
/ sectors
) >= 16)
89 heads
= (lba_size
/ sectors
);
91 cylinders
= lba_size
/ (heads
* sectors
);
94 // Setup the model name
95 strncpy((char *)driveID
.atap_model
, "5MI EDD si k",
96 sizeof(driveID
.atap_model
));
97 // Set the maximum multisector transfer size
98 driveID
.atap_multi
= MAX_MULTSECT
;
99 // IORDY supported, IORDY disabled, LBA enabled, DMA enabled
100 driveID
.atap_capabilities1
= 0x7;
101 // UDMA support, EIDE support
102 driveID
.atap_extensions
= 0x6;
103 // Setup default C/H/S settings
104 driveID
.atap_cylinders
= cylinders
;
105 driveID
.atap_sectors
= sectors
;
106 driveID
.atap_heads
= heads
;
107 // Setup the current multisector transfer size
108 driveID
.atap_curmulti
= MAX_MULTSECT
;
109 driveID
.atap_curmulti_valid
= 0x1;
110 // Number of sectors on disk
111 driveID
.atap_capacity
= lba_size
;
112 // Multiword DMA mode 2 and below supported
113 driveID
.atap_dmamode_supp
= 0x400;
114 // Set PIO mode 4 and 3 supported
115 driveID
.atap_piomode_supp
= 0x3;
116 // Set DMA mode 4 and below supported
117 driveID
.atap_udmamode_supp
= 0x1f;
118 // Statically set hardware config word
119 driveID
.atap_hwreset_res
= 0x4001;
121 //arbitrary for now...
122 driveID
.atap_ata_major
= WDC_VER_ATA7
;
127 // destroy the data buffer
128 delete [] dataBuffer
;
132 IdeDisk::reset(int id
)
134 // initialize the data buffer and shadow registers
135 dataBuffer
= new uint8_t[MAX_DMA_SIZE
];
137 memset(dataBuffer
, 0, MAX_DMA_SIZE
);
138 memset(&cmdReg
, 0, sizeof(CommandReg_t
));
139 memset(&curPrd
.entry
, 0, sizeof(PrdEntry_t
));
149 // set the device state to idle
153 devState
= Device_Idle_S
;
155 } else if (id
== DEV1
) {
156 devState
= Device_Idle_NS
;
159 panic("Invalid device ID: %#x\n", id
);
162 // set the device ready bit
163 status
= STATUS_DRDY_BIT
;
165 /* The error register must be set to 0x1 on start-up to
166 indicate that no diagnostic error was detected */
175 IdeDisk::isDEVSelect()
177 return ctrl
->isDiskSelected(this);
181 IdeDisk::pciToDma(Addr pciAddr
)
184 return ctrl
->plat
->pciToDma(pciAddr
);
186 panic("Access to unset controller!\n");
190 // Device registers read/write
194 IdeDisk::read(const Addr
&offset
, IdeRegType reg_type
, uint8_t *data
)
196 DevAction_t action
= ACT_NONE
;
201 // Data transfers occur two bytes at a time
203 *(uint16_t*)data
= cmdReg
.data
;
204 action
= ACT_DATA_READ_SHORT
;
207 *data
= cmdReg
.error
;
210 *data
= cmdReg
.sec_count
;
213 *data
= cmdReg
.sec_num
;
216 *data
= cmdReg
.cyl_low
;
219 *data
= cmdReg
.cyl_high
;
222 *data
= cmdReg
.drive
;
226 action
= ACT_STAT_READ
;
229 panic("Invalid IDE command register offset: %#x\n", offset
);
233 if (offset
== ALTSTAT_OFFSET
)
236 panic("Invalid IDE control register offset: %#x\n", offset
);
239 panic("Unknown register block!\n");
241 DPRINTF(IdeDisk
, "Read to disk at offset: %#x data %#x\n", offset
,
244 if (action
!= ACT_NONE
)
249 IdeDisk::write(const Addr
&offset
, IdeRegType reg_type
, const uint8_t *data
)
251 DevAction_t action
= ACT_NONE
;
257 cmdReg
.data
= *(uint16_t*)data
;
258 action
= ACT_DATA_WRITE_SHORT
;
260 case FEATURES_OFFSET
:
263 cmdReg
.sec_count
= *data
;
266 cmdReg
.sec_num
= *data
;
269 cmdReg
.cyl_low
= *data
;
272 cmdReg
.cyl_high
= *data
;
275 cmdReg
.drive
= *data
;
276 action
= ACT_SELECT_WRITE
;
279 cmdReg
.command
= *data
;
280 action
= ACT_CMD_WRITE
;
283 panic("Invalid IDE command register offset: %#x\n", offset
);
287 if (offset
== CONTROL_OFFSET
) {
288 if (*data
& CONTROL_RST_BIT
) {
289 // force the device into the reset state
290 devState
= Device_Srst
;
291 action
= ACT_SRST_SET
;
292 } else if (devState
== Device_Srst
&& !(*data
& CONTROL_RST_BIT
))
293 action
= ACT_SRST_CLEAR
;
295 nIENBit
= (*data
& CONTROL_IEN_BIT
) ? true : false;
298 panic("Invalid IDE control register offset: %#x\n", offset
);
301 panic("Unknown register block!\n");
304 DPRINTF(IdeDisk
, "Write to disk at offset: %#x data %#x\n", offset
,
306 if (action
!= ACT_NONE
)
311 // Perform DMA transactions
315 IdeDisk::doDmaTransfer()
317 if (dmaState
!= Dma_Transfer
|| devState
!= Transfer_Data_Dma
)
318 panic("Inconsistent DMA transfer state: dmaState = %d devState = %d\n",
321 if (ctrl
->dmaPending()) {
322 dmaTransferEvent
.schedule(curTick
+ DMA_BACKOFF_PERIOD
);
325 ctrl
->dmaRead(curPrdAddr
, sizeof(PrdEntry_t
), &dmaPrdReadEvent
,
326 (uint8_t*)&curPrd
.entry
);
330 IdeDisk::dmaPrdReadDone()
333 "PRD: baseAddr:%#x (%#x) byteCount:%d (%d) eot:%#x sector:%d\n",
334 curPrd
.getBaseAddr(), pciToDma(curPrd
.getBaseAddr()),
335 curPrd
.getByteCount(), (cmdBytesLeft
/SectorSize
),
336 curPrd
.getEOT(), curSector
);
338 // the prd pointer has already been translated, so just do an increment
339 curPrdAddr
= curPrdAddr
+ sizeof(PrdEntry_t
);
348 IdeDisk::doDmaDataRead()
350 /** @todo we need to figure out what the delay actually will be */
351 Tick totalDiskDelay
= diskDelay
+ (curPrd
.getByteCount() / SectorSize
);
353 DPRINTF(IdeDisk
, "doDmaRead, diskDelay: %d totalDiskDelay: %d\n",
354 diskDelay
, totalDiskDelay
);
356 dmaReadWaitEvent
.schedule(curTick
+ totalDiskDelay
);
362 using namespace Stats
;
364 .name(name() + ".dma_read_full_pages")
365 .desc("Number of full page size DMA reads (not PRD).")
368 .name(name() + ".dma_read_bytes")
369 .desc("Number of bytes transfered via DMA reads (not PRD).")
372 .name(name() + ".dma_read_txs")
373 .desc("Number of DMA read transactions (not PRD).")
377 .name(name() + ".dma_write_full_pages")
378 .desc("Number of full page size DMA writes.")
381 .name(name() + ".dma_write_bytes")
382 .desc("Number of bytes transfered via DMA writes.")
385 .name(name() + ".dma_write_txs")
386 .desc("Number of DMA write transactions.")
395 // clear out the data buffer
396 memset(dataBuffer
, 0, MAX_DMA_SIZE
);
397 dmaReadCG
= new ChunkGenerator(curPrd
.getBaseAddr(),
398 curPrd
.getByteCount(), TheISA::PageBytes
);
401 if (ctrl
->dmaPending()) {
402 panic("shouldn't be reentant??");
403 dmaReadWaitEvent
.schedule(curTick
+ DMA_BACKOFF_PERIOD
);
405 } else if (!dmaReadCG
->done()) {
406 assert(dmaReadCG
->complete() < MAX_DMA_SIZE
);
407 ctrl
->dmaRead(pciToDma(dmaReadCG
->addr()), dmaReadCG
->size(),
408 &dmaReadWaitEvent
, dataBuffer
+ dmaReadCG
->complete());
409 dmaReadBytes
+= dmaReadCG
->size();
411 if (dmaReadCG
->size() == TheISA::PageBytes
)
415 assert(dmaReadCG
->done());
423 IdeDisk::dmaReadDone()
426 uint32_t bytesWritten
= 0;
429 // write the data to the disk image
430 for (bytesWritten
= 0; bytesWritten
< curPrd
.getByteCount();
431 bytesWritten
+= SectorSize
) {
433 cmdBytesLeft
-= SectorSize
;
434 writeDisk(curSector
++, (uint8_t *)(dataBuffer
+ bytesWritten
));
438 if (curPrd
.getEOT()) {
439 assert(cmdBytesLeft
== 0);
441 updateState(ACT_DMA_DONE
);
448 IdeDisk::doDmaDataWrite()
450 /** @todo we need to figure out what the delay actually will be */
451 Tick totalDiskDelay
= diskDelay
+ (curPrd
.getByteCount() / SectorSize
);
452 uint32_t bytesRead
= 0;
454 DPRINTF(IdeDisk
, "doDmaWrite, diskDelay: %d totalDiskDelay: %d\n",
455 diskDelay
, totalDiskDelay
);
457 memset(dataBuffer
, 0, MAX_DMA_SIZE
);
458 assert(cmdBytesLeft
<= MAX_DMA_SIZE
);
459 while (bytesRead
< curPrd
.getByteCount()) {
460 readDisk(curSector
++, (uint8_t *)(dataBuffer
+ bytesRead
));
461 bytesRead
+= SectorSize
;
462 cmdBytesLeft
-= SectorSize
;
465 dmaWriteWaitEvent
.schedule(curTick
+ totalDiskDelay
);
469 IdeDisk::doDmaWrite()
473 // clear out the data buffer
474 dmaWriteCG
= new ChunkGenerator(curPrd
.getBaseAddr(),
475 curPrd
.getByteCount(), TheISA::PageBytes
);
477 if (ctrl
->dmaPending()) {
478 panic("shouldn't be reentant??");
479 dmaWriteWaitEvent
.schedule(curTick
+ DMA_BACKOFF_PERIOD
);
481 } else if (!dmaWriteCG
->done()) {
482 assert(dmaWriteCG
->complete() < MAX_DMA_SIZE
);
483 ctrl
->dmaWrite(pciToDma(dmaWriteCG
->addr()), dmaWriteCG
->size(),
484 &dmaWriteWaitEvent
, dataBuffer
+ dmaWriteCG
->complete());
485 dmaWriteBytes
+= dmaWriteCG
->size();
487 if (dmaWriteCG
->size() == TheISA::PageBytes
)
491 assert(dmaWriteCG
->done());
499 IdeDisk::dmaWriteDone()
502 if (curPrd
.getEOT()) {
503 assert(cmdBytesLeft
== 0);
505 updateState(ACT_DMA_DONE
);
512 // Disk utility routines
516 IdeDisk::readDisk(uint32_t sector
, uint8_t *data
)
518 uint32_t bytesRead
= image
->read(data
, sector
);
520 if (bytesRead
!= SectorSize
)
521 panic("Can't read from %s. Only %d of %d read. errno=%d\n",
522 name(), bytesRead
, SectorSize
, errno
);
526 IdeDisk::writeDisk(uint32_t sector
, uint8_t *data
)
528 uint32_t bytesWritten
= image
->write(data
, sector
);
530 if (bytesWritten
!= SectorSize
)
531 panic("Can't write to %s. Only %d of %d written. errno=%d\n",
532 name(), bytesWritten
, SectorSize
, errno
);
536 // Setup and handle commands
540 IdeDisk::startDma(const uint32_t &prdTableBase
)
542 if (dmaState
!= Dma_Start
)
543 panic("Inconsistent DMA state, should be in Dma_Start!\n");
545 if (devState
!= Transfer_Data_Dma
)
546 panic("Inconsistent device state for DMA start!\n");
548 // PRD base address is given by bits 31:2
549 curPrdAddr
= pciToDma((Addr
)(prdTableBase
& ~ULL(0x3)));
551 dmaState
= Dma_Transfer
;
553 // schedule dma transfer (doDmaTransfer)
554 dmaTransferEvent
.schedule(curTick
+ 1);
560 if (dmaState
== Dma_Idle
)
561 panic("Inconsistent DMA state, should be Start or Transfer!");
563 if (devState
!= Transfer_Data_Dma
&& devState
!= Prepare_Data_Dma
)
564 panic("Inconsistent device state, should be Transfer or Prepare!\n");
566 updateState(ACT_CMD_ERROR
);
570 IdeDisk::startCommand()
572 DevAction_t action
= ACT_NONE
;
577 switch (cmdReg
.command
) {
578 // Supported non-data commands
579 case WDSF_READ_NATIVE_MAX
:
580 size
= image
->size() - 1;
581 cmdReg
.sec_num
= (size
& 0xff);
582 cmdReg
.cyl_low
= ((size
& 0xff00) >> 8);
583 cmdReg
.cyl_high
= ((size
& 0xff0000) >> 16);
584 cmdReg
.head
= ((size
& 0xf000000) >> 24);
586 devState
= Command_Execution
;
587 action
= ACT_CMD_COMPLETE
;
592 case WDCC_STANDBY_IMMED
:
593 case WDCC_FLUSHCACHE
:
598 devState
= Command_Execution
;
599 action
= ACT_CMD_COMPLETE
;
602 // Supported PIO data-in commands
604 cmdBytes
= cmdBytesLeft
= sizeof(struct ataparams
);
605 devState
= Prepare_Data_In
;
606 action
= ACT_DATA_READY
;
611 if (!(cmdReg
.drive
& DRIVE_LBA_BIT
))
612 panic("Attempt to perform CHS access, only supports LBA\n");
614 if (cmdReg
.sec_count
== 0)
615 cmdBytes
= cmdBytesLeft
= (256 * SectorSize
);
617 cmdBytes
= cmdBytesLeft
= (cmdReg
.sec_count
* SectorSize
);
619 curSector
= getLBABase();
621 /** @todo make this a scheduled event to simulate disk delay */
622 devState
= Prepare_Data_In
;
623 action
= ACT_DATA_READY
;
626 // Supported PIO data-out commands
627 case WDCC_WRITEMULTI
:
629 if (!(cmdReg
.drive
& DRIVE_LBA_BIT
))
630 panic("Attempt to perform CHS access, only supports LBA\n");
632 if (cmdReg
.sec_count
== 0)
633 cmdBytes
= cmdBytesLeft
= (256 * SectorSize
);
635 cmdBytes
= cmdBytesLeft
= (cmdReg
.sec_count
* SectorSize
);
637 curSector
= getLBABase();
639 devState
= Prepare_Data_Out
;
640 action
= ACT_DATA_READY
;
643 // Supported DMA commands
645 dmaRead
= true; // a write to the disk is a DMA read from memory
647 if (!(cmdReg
.drive
& DRIVE_LBA_BIT
))
648 panic("Attempt to perform CHS access, only supports LBA\n");
650 if (cmdReg
.sec_count
== 0)
651 cmdBytes
= cmdBytesLeft
= (256 * SectorSize
);
653 cmdBytes
= cmdBytesLeft
= (cmdReg
.sec_count
* SectorSize
);
655 curSector
= getLBABase();
657 devState
= Prepare_Data_Dma
;
658 action
= ACT_DMA_READY
;
662 panic("Unsupported ATA command: %#x\n", cmdReg
.command
);
665 if (action
!= ACT_NONE
) {
667 status
|= STATUS_BSY_BIT
;
669 status
&= ~STATUS_DRQ_BIT
;
671 status
&= ~STATUS_DF_BIT
;
678 // Handle setting and clearing interrupts
684 DPRINTF(IdeDisk
, "Posting Interrupt\n");
686 panic("Attempt to post an interrupt with one pending\n");
690 // talk to controller to set interrupt
692 ctrl
->bmi_regs
.bmis0
|= IDEINTS
;
700 DPRINTF(IdeDisk
, "Clearing Interrupt\n");
702 panic("Attempt to clear a non-pending interrupt\n");
706 // talk to controller to clear interrupt
712 // Manage the device internal state machine
716 IdeDisk::updateState(DevAction_t action
)
720 if (action
== ACT_SRST_SET
) {
722 status
|= STATUS_BSY_BIT
;
723 } else if (action
== ACT_SRST_CLEAR
) {
725 status
&= ~STATUS_BSY_BIT
;
727 // reset the device state
733 if (action
== ACT_SELECT_WRITE
&& !isDEVSelect()) {
734 devState
= Device_Idle_NS
;
735 } else if (action
== ACT_CMD_WRITE
) {
742 if (action
== ACT_SELECT_WRITE
&& !isDEVSelect()) {
743 devState
= Device_Idle_NS
;
745 } else if (action
== ACT_STAT_READ
|| isIENSet()) {
746 devState
= Device_Idle_S
;
748 } else if (action
== ACT_CMD_WRITE
) {
756 if (action
== ACT_SELECT_WRITE
&& isDEVSelect()) {
757 if (!isIENSet() && intrPending
) {
758 devState
= Device_Idle_SI
;
761 if (isIENSet() || !intrPending
) {
762 devState
= Device_Idle_S
;
767 case Command_Execution
:
768 if (action
== ACT_CMD_COMPLETE
) {
773 devState
= Device_Idle_SI
;
776 devState
= Device_Idle_S
;
781 case Prepare_Data_In
:
782 if (action
== ACT_CMD_ERROR
) {
787 devState
= Device_Idle_SI
;
790 devState
= Device_Idle_S
;
792 } else if (action
== ACT_DATA_READY
) {
794 status
&= ~STATUS_BSY_BIT
;
796 status
|= STATUS_DRQ_BIT
;
798 // copy the data into the data buffer
799 if (cmdReg
.command
== WDCC_IDENTIFY
) {
800 // Reset the drqBytes for this block
801 drqBytesLeft
= sizeof(struct ataparams
);
803 memcpy((void *)dataBuffer
, (void *)&driveID
,
804 sizeof(struct ataparams
));
806 // Reset the drqBytes for this block
807 drqBytesLeft
= SectorSize
;
809 readDisk(curSector
++, dataBuffer
);
812 // put the first two bytes into the data register
813 memcpy((void *)&cmdReg
.data
, (void *)dataBuffer
,
817 devState
= Data_Ready_INTRQ_In
;
820 devState
= Transfer_Data_In
;
825 case Data_Ready_INTRQ_In
:
826 if (action
== ACT_STAT_READ
) {
827 devState
= Transfer_Data_In
;
832 case Transfer_Data_In
:
833 if (action
== ACT_DATA_READ_BYTE
|| action
== ACT_DATA_READ_SHORT
) {
834 if (action
== ACT_DATA_READ_BYTE
) {
835 panic("DEBUG: READING DATA ONE BYTE AT A TIME!\n");
840 // copy next short into data registers
842 memcpy((void *)&cmdReg
.data
,
843 (void *)&dataBuffer
[SectorSize
- drqBytesLeft
],
847 if (drqBytesLeft
== 0) {
848 if (cmdBytesLeft
== 0) {
851 devState
= Device_Idle_S
;
853 devState
= Prepare_Data_In
;
855 status
|= STATUS_BSY_BIT
;
857 status
&= ~STATUS_DRQ_BIT
;
859 /** @todo change this to a scheduled event to simulate
861 updateState(ACT_DATA_READY
);
867 case Prepare_Data_Out
:
868 if (action
== ACT_CMD_ERROR
|| cmdBytesLeft
== 0) {
873 devState
= Device_Idle_SI
;
876 devState
= Device_Idle_S
;
878 } else if (action
== ACT_DATA_READY
&& cmdBytesLeft
!= 0) {
880 status
&= ~STATUS_BSY_BIT
;
882 status
|= STATUS_DRQ_BIT
;
884 // clear the data buffer to get it ready for writes
885 memset(dataBuffer
, 0, MAX_DMA_SIZE
);
887 // reset the drqBytes for this block
888 drqBytesLeft
= SectorSize
;
890 if (cmdBytesLeft
== cmdBytes
|| isIENSet()) {
891 devState
= Transfer_Data_Out
;
893 devState
= Data_Ready_INTRQ_Out
;
899 case Data_Ready_INTRQ_Out
:
900 if (action
== ACT_STAT_READ
) {
901 devState
= Transfer_Data_Out
;
906 case Transfer_Data_Out
:
907 if (action
== ACT_DATA_WRITE_BYTE
||
908 action
== ACT_DATA_WRITE_SHORT
) {
910 if (action
== ACT_DATA_READ_BYTE
) {
911 panic("DEBUG: WRITING DATA ONE BYTE AT A TIME!\n");
913 // copy the latest short into the data buffer
914 memcpy((void *)&dataBuffer
[SectorSize
- drqBytesLeft
],
915 (void *)&cmdReg
.data
,
922 if (drqBytesLeft
== 0) {
923 // copy the block to the disk
924 writeDisk(curSector
++, dataBuffer
);
927 status
|= STATUS_BSY_BIT
;
929 status
|= STATUS_SEEK_BIT
;
931 status
&= ~STATUS_DRQ_BIT
;
933 devState
= Prepare_Data_Out
;
935 /** @todo change this to a scheduled event to simulate
937 updateState(ACT_DATA_READY
);
942 case Prepare_Data_Dma
:
943 if (action
== ACT_CMD_ERROR
) {
948 devState
= Device_Idle_SI
;
951 devState
= Device_Idle_S
;
953 } else if (action
== ACT_DMA_READY
) {
955 status
&= ~STATUS_BSY_BIT
;
957 status
|= STATUS_DRQ_BIT
;
959 devState
= Transfer_Data_Dma
;
961 if (dmaState
!= Dma_Idle
)
962 panic("Inconsistent DMA state, should be Dma_Idle\n");
964 dmaState
= Dma_Start
;
965 // wait for the write to the DMA start bit
969 case Transfer_Data_Dma
:
970 if (action
== ACT_CMD_ERROR
|| action
== ACT_DMA_DONE
) {
974 status
|= STATUS_SEEK_BIT
;
975 // clear the controller state for DMA transfer
976 ctrl
->setDmaComplete(this);
979 devState
= Device_Idle_SI
;
982 devState
= Device_Idle_S
;
988 panic("Unknown IDE device state: %#x\n", devState
);
993 IdeDisk::serialize(ostream
&os
)
995 // Check all outstanding events to see if they are scheduled
996 // these are all mutually exclusive
998 Events_t event
= None
;
1002 if (dmaTransferEvent
.scheduled()) {
1003 reschedule
= dmaTransferEvent
.when();
1007 if (dmaReadWaitEvent
.scheduled()) {
1008 reschedule
= dmaReadWaitEvent
.when();
1012 if (dmaWriteWaitEvent
.scheduled()) {
1013 reschedule
= dmaWriteWaitEvent
.when();
1017 if (dmaPrdReadEvent
.scheduled()) {
1018 reschedule
= dmaPrdReadEvent
.when();
1022 if (dmaReadEvent
.scheduled()) {
1023 reschedule
= dmaReadEvent
.when();
1027 if (dmaWriteEvent
.scheduled()) {
1028 reschedule
= dmaWriteEvent
.when();
1033 assert(eventCount
<= 1);
1035 SERIALIZE_SCALAR(reschedule
);
1036 SERIALIZE_ENUM(event
);
1038 // Serialize device registers
1039 SERIALIZE_SCALAR(cmdReg
.data
);
1040 SERIALIZE_SCALAR(cmdReg
.sec_count
);
1041 SERIALIZE_SCALAR(cmdReg
.sec_num
);
1042 SERIALIZE_SCALAR(cmdReg
.cyl_low
);
1043 SERIALIZE_SCALAR(cmdReg
.cyl_high
);
1044 SERIALIZE_SCALAR(cmdReg
.drive
);
1045 SERIALIZE_SCALAR(cmdReg
.command
);
1046 SERIALIZE_SCALAR(status
);
1047 SERIALIZE_SCALAR(nIENBit
);
1048 SERIALIZE_SCALAR(devID
);
1050 // Serialize the PRD related information
1051 SERIALIZE_SCALAR(curPrd
.entry
.baseAddr
);
1052 SERIALIZE_SCALAR(curPrd
.entry
.byteCount
);
1053 SERIALIZE_SCALAR(curPrd
.entry
.endOfTable
);
1054 SERIALIZE_SCALAR(curPrdAddr
);
1056 /** @todo need to serialized chunk generator stuff!! */
1057 // Serialize current transfer related information
1058 SERIALIZE_SCALAR(cmdBytesLeft
);
1059 SERIALIZE_SCALAR(cmdBytes
);
1060 SERIALIZE_SCALAR(drqBytesLeft
);
1061 SERIALIZE_SCALAR(curSector
);
1062 SERIALIZE_SCALAR(dmaRead
);
1063 SERIALIZE_SCALAR(intrPending
);
1064 SERIALIZE_ENUM(devState
);
1065 SERIALIZE_ENUM(dmaState
);
1066 SERIALIZE_ARRAY(dataBuffer
, MAX_DMA_SIZE
);
1070 IdeDisk::unserialize(Checkpoint
*cp
, const string
§ion
)
1072 // Reschedule events that were outstanding
1073 // these are all mutually exclusive
1074 Tick reschedule
= 0;
1075 Events_t event
= None
;
1077 UNSERIALIZE_SCALAR(reschedule
);
1078 UNSERIALIZE_ENUM(event
);
1082 case Transfer
: dmaTransferEvent
.schedule(reschedule
); break;
1083 case ReadWait
: dmaReadWaitEvent
.schedule(reschedule
); break;
1084 case WriteWait
: dmaWriteWaitEvent
.schedule(reschedule
); break;
1085 case PrdRead
: dmaPrdReadEvent
.schedule(reschedule
); break;
1086 case DmaRead
: dmaReadEvent
.schedule(reschedule
); break;
1087 case DmaWrite
: dmaWriteEvent
.schedule(reschedule
); break;
1090 // Unserialize device registers
1091 UNSERIALIZE_SCALAR(cmdReg
.data
);
1092 UNSERIALIZE_SCALAR(cmdReg
.sec_count
);
1093 UNSERIALIZE_SCALAR(cmdReg
.sec_num
);
1094 UNSERIALIZE_SCALAR(cmdReg
.cyl_low
);
1095 UNSERIALIZE_SCALAR(cmdReg
.cyl_high
);
1096 UNSERIALIZE_SCALAR(cmdReg
.drive
);
1097 UNSERIALIZE_SCALAR(cmdReg
.command
);
1098 UNSERIALIZE_SCALAR(status
);
1099 UNSERIALIZE_SCALAR(nIENBit
);
1100 UNSERIALIZE_SCALAR(devID
);
1102 // Unserialize the PRD related information
1103 UNSERIALIZE_SCALAR(curPrd
.entry
.baseAddr
);
1104 UNSERIALIZE_SCALAR(curPrd
.entry
.byteCount
);
1105 UNSERIALIZE_SCALAR(curPrd
.entry
.endOfTable
);
1106 UNSERIALIZE_SCALAR(curPrdAddr
);
1108 /** @todo need to serialized chunk generator stuff!! */
1109 // Unserialize current transfer related information
1110 UNSERIALIZE_SCALAR(cmdBytes
);
1111 UNSERIALIZE_SCALAR(cmdBytesLeft
);
1112 UNSERIALIZE_SCALAR(drqBytesLeft
);
1113 UNSERIALIZE_SCALAR(curSector
);
1114 UNSERIALIZE_SCALAR(dmaRead
);
1115 UNSERIALIZE_SCALAR(intrPending
);
1116 UNSERIALIZE_ENUM(devState
);
1117 UNSERIALIZE_ENUM(dmaState
);
1118 UNSERIALIZE_ARRAY(dataBuffer
, MAX_DMA_SIZE
);
1121 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1123 enum DriveID
{ master
, slave
};
1124 static const char *DriveID_strings
[] = { "master", "slave" };
1125 BEGIN_DECLARE_SIM_OBJECT_PARAMS(IdeDisk
)
1127 SimObjectParam
<DiskImage
*> image
;
1128 SimpleEnumParam
<DriveID
> driveID
;
1131 END_DECLARE_SIM_OBJECT_PARAMS(IdeDisk
)
1133 BEGIN_INIT_SIM_OBJECT_PARAMS(IdeDisk
)
1135 INIT_PARAM(image
, "Disk image"),
1136 INIT_ENUM_PARAM(driveID
, "Drive ID (0=master 1=slave)", DriveID_strings
),
1137 INIT_PARAM_DFLT(delay
, "Fixed disk delay in microseconds", 1)
1139 END_INIT_SIM_OBJECT_PARAMS(IdeDisk
)
1142 CREATE_SIM_OBJECT(IdeDisk
)
1144 return new IdeDisk(getInstanceName(), image
, driveID
, delay
);
1147 REGISTER_SIM_OBJECT("IdeDisk", IdeDisk
)
1149 #endif //DOXYGEN_SHOULD_SKIP_THIS