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 "arch/isa_traits.hh"
42 #include "base/chunk_generator.hh"
43 #include "base/cprintf.hh" // csprintf
44 #include "base/trace.hh"
45 #include "dev/disk_image.hh"
46 #include "dev/ide_ctrl.hh"
47 #include "dev/ide_disk.hh"
48 #include "params/IdeDisk.hh"
49 #include "sim/core.hh"
50 #include "sim/sim_object.hh"
53 using namespace TheISA
;
55 IdeDisk::IdeDisk(const string
&name
, DiskImage
*img
,
57 : SimObject(name
), ctrl(NULL
), image(img
), diskDelay(delay
),
58 dmaTransferEvent(this), dmaReadCG(NULL
), dmaReadWaitEvent(this),
59 dmaWriteCG(NULL
), dmaWriteWaitEvent(this), dmaPrdReadEvent(this),
60 dmaReadEvent(this), dmaWriteEvent(this)
62 // Reset the device state
65 // fill out the drive ID structure
66 memset(&driveID
, 0, sizeof(struct ataparams
));
68 // Calculate LBA and C/H/S values
73 uint32_t lba_size
= image
->size();
74 if (lba_size
>= 16383*16*63) {
84 if ((lba_size
/ sectors
) >= 16)
87 heads
= (lba_size
/ sectors
);
89 cylinders
= lba_size
/ (heads
* sectors
);
92 // Setup the model name
93 strncpy((char *)driveID
.atap_model
, "5MI EDD si k",
94 sizeof(driveID
.atap_model
));
95 // Set the maximum multisector transfer size
96 driveID
.atap_multi
= MAX_MULTSECT
;
97 // IORDY supported, IORDY disabled, LBA enabled, DMA enabled
98 driveID
.atap_capabilities1
= 0x7;
99 // UDMA support, EIDE support
100 driveID
.atap_extensions
= 0x6;
101 // Setup default C/H/S settings
102 driveID
.atap_cylinders
= cylinders
;
103 driveID
.atap_sectors
= sectors
;
104 driveID
.atap_heads
= heads
;
105 // Setup the current multisector transfer size
106 driveID
.atap_curmulti
= MAX_MULTSECT
;
107 driveID
.atap_curmulti_valid
= 0x1;
108 // Number of sectors on disk
109 driveID
.atap_capacity
= lba_size
;
110 // Multiword DMA mode 2 and below supported
111 driveID
.atap_dmamode_supp
= 0x4;
112 // Set PIO mode 4 and 3 supported
113 driveID
.atap_piomode_supp
= 0x3;
114 // Set DMA mode 4 and below supported
115 driveID
.atap_udmamode_supp
= 0x1f;
116 // Statically set hardware config word
117 driveID
.atap_hwreset_res
= 0x4001;
119 //arbitrary for now...
120 driveID
.atap_ata_major
= WDC_VER_ATA7
;
125 // destroy the data buffer
126 delete [] dataBuffer
;
130 IdeDisk::reset(int id
)
132 // initialize the data buffer and shadow registers
133 dataBuffer
= new uint8_t[MAX_DMA_SIZE
];
135 memset(dataBuffer
, 0, MAX_DMA_SIZE
);
136 memset(&cmdReg
, 0, sizeof(CommandReg_t
));
137 memset(&curPrd
.entry
, 0, sizeof(PrdEntry_t
));
147 // set the device state to idle
151 devState
= Device_Idle_S
;
153 } else if (id
== DEV1
) {
154 devState
= Device_Idle_NS
;
157 panic("Invalid device ID: %#x\n", id
);
160 // set the device ready bit
161 status
= STATUS_DRDY_BIT
;
163 /* The error register must be set to 0x1 on start-up to
164 indicate that no diagnostic error was detected */
173 IdeDisk::isDEVSelect()
175 return ctrl
->isDiskSelected(this);
179 IdeDisk::pciToDma(Addr pciAddr
)
182 return ctrl
->plat
->pciToDma(pciAddr
);
184 panic("Access to unset controller!\n");
188 // Device registers read/write
192 IdeDisk::read(const Addr
&offset
, IdeRegType reg_type
, uint8_t *data
)
194 DevAction_t action
= ACT_NONE
;
199 // Data transfers occur two bytes at a time
201 *(uint16_t*)data
= cmdReg
.data
;
202 action
= ACT_DATA_READ_SHORT
;
205 *data
= cmdReg
.error
;
208 *data
= cmdReg
.sec_count
;
211 *data
= cmdReg
.sec_num
;
214 *data
= cmdReg
.cyl_low
;
217 *data
= cmdReg
.cyl_high
;
220 *data
= cmdReg
.drive
;
224 action
= ACT_STAT_READ
;
227 panic("Invalid IDE command register offset: %#x\n", offset
);
231 if (offset
== ALTSTAT_OFFSET
)
234 panic("Invalid IDE control register offset: %#x\n", offset
);
237 panic("Unknown register block!\n");
239 DPRINTF(IdeDisk
, "Read to disk at offset: %#x data %#x\n", offset
,
242 if (action
!= ACT_NONE
)
247 IdeDisk::write(const Addr
&offset
, IdeRegType reg_type
, const uint8_t *data
)
249 DevAction_t action
= ACT_NONE
;
255 cmdReg
.data
= *(uint16_t*)data
;
256 action
= ACT_DATA_WRITE_SHORT
;
258 case FEATURES_OFFSET
:
261 cmdReg
.sec_count
= *data
;
264 cmdReg
.sec_num
= *data
;
267 cmdReg
.cyl_low
= *data
;
270 cmdReg
.cyl_high
= *data
;
273 cmdReg
.drive
= *data
;
274 action
= ACT_SELECT_WRITE
;
277 cmdReg
.command
= *data
;
278 action
= ACT_CMD_WRITE
;
281 panic("Invalid IDE command register offset: %#x\n", offset
);
285 if (offset
== CONTROL_OFFSET
) {
286 if (*data
& CONTROL_RST_BIT
) {
287 // force the device into the reset state
288 devState
= Device_Srst
;
289 action
= ACT_SRST_SET
;
290 } else if (devState
== Device_Srst
&& !(*data
& CONTROL_RST_BIT
))
291 action
= ACT_SRST_CLEAR
;
293 nIENBit
= (*data
& CONTROL_IEN_BIT
) ? true : false;
296 panic("Invalid IDE control register offset: %#x\n", offset
);
299 panic("Unknown register block!\n");
302 DPRINTF(IdeDisk
, "Write to disk at offset: %#x data %#x\n", offset
,
304 if (action
!= ACT_NONE
)
309 // Perform DMA transactions
313 IdeDisk::doDmaTransfer()
315 if (dmaState
!= Dma_Transfer
|| devState
!= Transfer_Data_Dma
)
316 panic("Inconsistent DMA transfer state: dmaState = %d devState = %d\n",
319 if (ctrl
->dmaPending() || ctrl
->getState() != SimObject::Running
) {
320 dmaTransferEvent
.schedule(curTick
+ DMA_BACKOFF_PERIOD
);
323 ctrl
->dmaRead(curPrdAddr
, sizeof(PrdEntry_t
), &dmaPrdReadEvent
,
324 (uint8_t*)&curPrd
.entry
);
328 IdeDisk::dmaPrdReadDone()
331 "PRD: baseAddr:%#x (%#x) byteCount:%d (%d) eot:%#x sector:%d\n",
332 curPrd
.getBaseAddr(), pciToDma(curPrd
.getBaseAddr()),
333 curPrd
.getByteCount(), (cmdBytesLeft
/SectorSize
),
334 curPrd
.getEOT(), curSector
);
336 // the prd pointer has already been translated, so just do an increment
337 curPrdAddr
= curPrdAddr
+ sizeof(PrdEntry_t
);
346 IdeDisk::doDmaDataRead()
348 /** @todo we need to figure out what the delay actually will be */
349 Tick totalDiskDelay
= diskDelay
+ (curPrd
.getByteCount() / SectorSize
);
351 DPRINTF(IdeDisk
, "doDmaRead, diskDelay: %d totalDiskDelay: %d\n",
352 diskDelay
, totalDiskDelay
);
354 dmaReadWaitEvent
.schedule(curTick
+ totalDiskDelay
);
360 using namespace Stats
;
362 .name(name() + ".dma_read_full_pages")
363 .desc("Number of full page size DMA reads (not PRD).")
366 .name(name() + ".dma_read_bytes")
367 .desc("Number of bytes transfered via DMA reads (not PRD).")
370 .name(name() + ".dma_read_txs")
371 .desc("Number of DMA read transactions (not PRD).")
375 .name(name() + ".dma_write_full_pages")
376 .desc("Number of full page size DMA writes.")
379 .name(name() + ".dma_write_bytes")
380 .desc("Number of bytes transfered via DMA writes.")
383 .name(name() + ".dma_write_txs")
384 .desc("Number of DMA write transactions.")
393 // clear out the data buffer
394 memset(dataBuffer
, 0, MAX_DMA_SIZE
);
395 dmaReadCG
= new ChunkGenerator(curPrd
.getBaseAddr(),
396 curPrd
.getByteCount(), TheISA::PageBytes
);
399 if (ctrl
->dmaPending() || ctrl
->getState() != SimObject::Running
) {
400 dmaReadWaitEvent
.schedule(curTick
+ DMA_BACKOFF_PERIOD
);
402 } else if (!dmaReadCG
->done()) {
403 assert(dmaReadCG
->complete() < MAX_DMA_SIZE
);
404 ctrl
->dmaRead(pciToDma(dmaReadCG
->addr()), dmaReadCG
->size(),
405 &dmaReadWaitEvent
, dataBuffer
+ dmaReadCG
->complete());
406 dmaReadBytes
+= dmaReadCG
->size();
408 if (dmaReadCG
->size() == TheISA::PageBytes
)
412 assert(dmaReadCG
->done());
420 IdeDisk::dmaReadDone()
423 uint32_t bytesWritten
= 0;
426 // write the data to the disk image
427 for (bytesWritten
= 0; bytesWritten
< curPrd
.getByteCount();
428 bytesWritten
+= SectorSize
) {
430 cmdBytesLeft
-= SectorSize
;
431 writeDisk(curSector
++, (uint8_t *)(dataBuffer
+ bytesWritten
));
435 if (curPrd
.getEOT()) {
436 assert(cmdBytesLeft
== 0);
438 updateState(ACT_DMA_DONE
);
445 IdeDisk::doDmaDataWrite()
447 /** @todo we need to figure out what the delay actually will be */
448 Tick totalDiskDelay
= diskDelay
+ (curPrd
.getByteCount() / SectorSize
);
449 uint32_t bytesRead
= 0;
451 DPRINTF(IdeDisk
, "doDmaWrite, diskDelay: %d totalDiskDelay: %d\n",
452 diskDelay
, totalDiskDelay
);
454 memset(dataBuffer
, 0, MAX_DMA_SIZE
);
455 assert(cmdBytesLeft
<= MAX_DMA_SIZE
);
456 while (bytesRead
< curPrd
.getByteCount()) {
457 readDisk(curSector
++, (uint8_t *)(dataBuffer
+ bytesRead
));
458 bytesRead
+= SectorSize
;
459 cmdBytesLeft
-= SectorSize
;
462 dmaWriteWaitEvent
.schedule(curTick
+ totalDiskDelay
);
466 IdeDisk::doDmaWrite()
470 // clear out the data buffer
471 dmaWriteCG
= new ChunkGenerator(curPrd
.getBaseAddr(),
472 curPrd
.getByteCount(), TheISA::PageBytes
);
474 if (ctrl
->dmaPending() || ctrl
->getState() != SimObject::Running
) {
475 dmaWriteWaitEvent
.schedule(curTick
+ DMA_BACKOFF_PERIOD
);
477 } else if (!dmaWriteCG
->done()) {
478 assert(dmaWriteCG
->complete() < MAX_DMA_SIZE
);
479 ctrl
->dmaWrite(pciToDma(dmaWriteCG
->addr()), dmaWriteCG
->size(),
480 &dmaWriteWaitEvent
, dataBuffer
+ dmaWriteCG
->complete());
481 dmaWriteBytes
+= dmaWriteCG
->size();
483 if (dmaWriteCG
->size() == TheISA::PageBytes
)
487 assert(dmaWriteCG
->done());
495 IdeDisk::dmaWriteDone()
498 if (curPrd
.getEOT()) {
499 assert(cmdBytesLeft
== 0);
501 updateState(ACT_DMA_DONE
);
508 // Disk utility routines
512 IdeDisk::readDisk(uint32_t sector
, uint8_t *data
)
514 uint32_t bytesRead
= image
->read(data
, sector
);
516 if (bytesRead
!= SectorSize
)
517 panic("Can't read from %s. Only %d of %d read. errno=%d\n",
518 name(), bytesRead
, SectorSize
, errno
);
522 IdeDisk::writeDisk(uint32_t sector
, uint8_t *data
)
524 uint32_t bytesWritten
= image
->write(data
, sector
);
526 if (bytesWritten
!= SectorSize
)
527 panic("Can't write to %s. Only %d of %d written. errno=%d\n",
528 name(), bytesWritten
, SectorSize
, errno
);
532 // Setup and handle commands
536 IdeDisk::startDma(const uint32_t &prdTableBase
)
538 if (dmaState
!= Dma_Start
)
539 panic("Inconsistent DMA state, should be in Dma_Start!\n");
541 if (devState
!= Transfer_Data_Dma
)
542 panic("Inconsistent device state for DMA start!\n");
544 // PRD base address is given by bits 31:2
545 curPrdAddr
= pciToDma((Addr
)(prdTableBase
& ~ULL(0x3)));
547 dmaState
= Dma_Transfer
;
549 // schedule dma transfer (doDmaTransfer)
550 dmaTransferEvent
.schedule(curTick
+ 1);
556 if (dmaState
== Dma_Idle
)
557 panic("Inconsistent DMA state, should be Start or Transfer!");
559 if (devState
!= Transfer_Data_Dma
&& devState
!= Prepare_Data_Dma
)
560 panic("Inconsistent device state, should be Transfer or Prepare!\n");
562 updateState(ACT_CMD_ERROR
);
566 IdeDisk::startCommand()
568 DevAction_t action
= ACT_NONE
;
573 switch (cmdReg
.command
) {
574 // Supported non-data commands
575 case WDSF_READ_NATIVE_MAX
:
576 size
= image
->size() - 1;
577 cmdReg
.sec_num
= (size
& 0xff);
578 cmdReg
.cyl_low
= ((size
& 0xff00) >> 8);
579 cmdReg
.cyl_high
= ((size
& 0xff0000) >> 16);
580 cmdReg
.head
= ((size
& 0xf000000) >> 24);
582 devState
= Command_Execution
;
583 action
= ACT_CMD_COMPLETE
;
588 case WDCC_STANDBY_IMMED
:
589 case WDCC_FLUSHCACHE
:
594 devState
= Command_Execution
;
595 action
= ACT_CMD_COMPLETE
;
598 // Supported PIO data-in commands
600 cmdBytes
= cmdBytesLeft
= sizeof(struct ataparams
);
601 devState
= Prepare_Data_In
;
602 action
= ACT_DATA_READY
;
607 if (!(cmdReg
.drive
& DRIVE_LBA_BIT
))
608 panic("Attempt to perform CHS access, only supports LBA\n");
610 if (cmdReg
.sec_count
== 0)
611 cmdBytes
= cmdBytesLeft
= (256 * SectorSize
);
613 cmdBytes
= cmdBytesLeft
= (cmdReg
.sec_count
* SectorSize
);
615 curSector
= getLBABase();
617 /** @todo make this a scheduled event to simulate disk delay */
618 devState
= Prepare_Data_In
;
619 action
= ACT_DATA_READY
;
622 // Supported PIO data-out commands
623 case WDCC_WRITEMULTI
:
625 if (!(cmdReg
.drive
& DRIVE_LBA_BIT
))
626 panic("Attempt to perform CHS access, only supports LBA\n");
628 if (cmdReg
.sec_count
== 0)
629 cmdBytes
= cmdBytesLeft
= (256 * SectorSize
);
631 cmdBytes
= cmdBytesLeft
= (cmdReg
.sec_count
* SectorSize
);
633 curSector
= getLBABase();
635 devState
= Prepare_Data_Out
;
636 action
= ACT_DATA_READY
;
639 // Supported DMA commands
641 dmaRead
= true; // a write to the disk is a DMA read from memory
643 if (!(cmdReg
.drive
& DRIVE_LBA_BIT
))
644 panic("Attempt to perform CHS access, only supports LBA\n");
646 if (cmdReg
.sec_count
== 0)
647 cmdBytes
= cmdBytesLeft
= (256 * SectorSize
);
649 cmdBytes
= cmdBytesLeft
= (cmdReg
.sec_count
* SectorSize
);
651 curSector
= getLBABase();
653 devState
= Prepare_Data_Dma
;
654 action
= ACT_DMA_READY
;
658 panic("Unsupported ATA command: %#x\n", cmdReg
.command
);
661 if (action
!= ACT_NONE
) {
663 status
|= STATUS_BSY_BIT
;
665 status
&= ~STATUS_DRQ_BIT
;
667 status
&= ~STATUS_DF_BIT
;
674 // Handle setting and clearing interrupts
680 DPRINTF(IdeDisk
, "Posting Interrupt\n");
682 panic("Attempt to post an interrupt with one pending\n");
686 // talk to controller to set interrupt
688 ctrl
->bmi_regs
.bmis0
|= IDEINTS
;
696 DPRINTF(IdeDisk
, "Clearing Interrupt\n");
698 panic("Attempt to clear a non-pending interrupt\n");
702 // talk to controller to clear interrupt
708 // Manage the device internal state machine
712 IdeDisk::updateState(DevAction_t action
)
716 if (action
== ACT_SRST_SET
) {
718 status
|= STATUS_BSY_BIT
;
719 } else if (action
== ACT_SRST_CLEAR
) {
721 status
&= ~STATUS_BSY_BIT
;
723 // reset the device state
729 if (action
== ACT_SELECT_WRITE
&& !isDEVSelect()) {
730 devState
= Device_Idle_NS
;
731 } else if (action
== ACT_CMD_WRITE
) {
738 if (action
== ACT_SELECT_WRITE
&& !isDEVSelect()) {
739 devState
= Device_Idle_NS
;
741 } else if (action
== ACT_STAT_READ
|| isIENSet()) {
742 devState
= Device_Idle_S
;
744 } else if (action
== ACT_CMD_WRITE
) {
752 if (action
== ACT_SELECT_WRITE
&& isDEVSelect()) {
753 if (!isIENSet() && intrPending
) {
754 devState
= Device_Idle_SI
;
757 if (isIENSet() || !intrPending
) {
758 devState
= Device_Idle_S
;
763 case Command_Execution
:
764 if (action
== ACT_CMD_COMPLETE
) {
769 devState
= Device_Idle_SI
;
772 devState
= Device_Idle_S
;
777 case Prepare_Data_In
:
778 if (action
== ACT_CMD_ERROR
) {
783 devState
= Device_Idle_SI
;
786 devState
= Device_Idle_S
;
788 } else if (action
== ACT_DATA_READY
) {
790 status
&= ~STATUS_BSY_BIT
;
792 status
|= STATUS_DRQ_BIT
;
794 // copy the data into the data buffer
795 if (cmdReg
.command
== WDCC_IDENTIFY
) {
796 // Reset the drqBytes for this block
797 drqBytesLeft
= sizeof(struct ataparams
);
799 memcpy((void *)dataBuffer
, (void *)&driveID
,
800 sizeof(struct ataparams
));
802 // Reset the drqBytes for this block
803 drqBytesLeft
= SectorSize
;
805 readDisk(curSector
++, dataBuffer
);
808 // put the first two bytes into the data register
809 memcpy((void *)&cmdReg
.data
, (void *)dataBuffer
,
813 devState
= Data_Ready_INTRQ_In
;
816 devState
= Transfer_Data_In
;
821 case Data_Ready_INTRQ_In
:
822 if (action
== ACT_STAT_READ
) {
823 devState
= Transfer_Data_In
;
828 case Transfer_Data_In
:
829 if (action
== ACT_DATA_READ_BYTE
|| action
== ACT_DATA_READ_SHORT
) {
830 if (action
== ACT_DATA_READ_BYTE
) {
831 panic("DEBUG: READING DATA ONE BYTE AT A TIME!\n");
836 // copy next short into data registers
838 memcpy((void *)&cmdReg
.data
,
839 (void *)&dataBuffer
[SectorSize
- drqBytesLeft
],
843 if (drqBytesLeft
== 0) {
844 if (cmdBytesLeft
== 0) {
847 devState
= Device_Idle_S
;
849 devState
= Prepare_Data_In
;
851 status
|= STATUS_BSY_BIT
;
853 status
&= ~STATUS_DRQ_BIT
;
855 /** @todo change this to a scheduled event to simulate
857 updateState(ACT_DATA_READY
);
863 case Prepare_Data_Out
:
864 if (action
== ACT_CMD_ERROR
|| cmdBytesLeft
== 0) {
869 devState
= Device_Idle_SI
;
872 devState
= Device_Idle_S
;
874 } else if (action
== ACT_DATA_READY
&& cmdBytesLeft
!= 0) {
876 status
&= ~STATUS_BSY_BIT
;
878 status
|= STATUS_DRQ_BIT
;
880 // clear the data buffer to get it ready for writes
881 memset(dataBuffer
, 0, MAX_DMA_SIZE
);
883 // reset the drqBytes for this block
884 drqBytesLeft
= SectorSize
;
886 if (cmdBytesLeft
== cmdBytes
|| isIENSet()) {
887 devState
= Transfer_Data_Out
;
889 devState
= Data_Ready_INTRQ_Out
;
895 case Data_Ready_INTRQ_Out
:
896 if (action
== ACT_STAT_READ
) {
897 devState
= Transfer_Data_Out
;
902 case Transfer_Data_Out
:
903 if (action
== ACT_DATA_WRITE_BYTE
||
904 action
== ACT_DATA_WRITE_SHORT
) {
906 if (action
== ACT_DATA_READ_BYTE
) {
907 panic("DEBUG: WRITING DATA ONE BYTE AT A TIME!\n");
909 // copy the latest short into the data buffer
910 memcpy((void *)&dataBuffer
[SectorSize
- drqBytesLeft
],
911 (void *)&cmdReg
.data
,
918 if (drqBytesLeft
== 0) {
919 // copy the block to the disk
920 writeDisk(curSector
++, dataBuffer
);
923 status
|= STATUS_BSY_BIT
;
925 status
|= STATUS_SEEK_BIT
;
927 status
&= ~STATUS_DRQ_BIT
;
929 devState
= Prepare_Data_Out
;
931 /** @todo change this to a scheduled event to simulate
933 updateState(ACT_DATA_READY
);
938 case Prepare_Data_Dma
:
939 if (action
== ACT_CMD_ERROR
) {
944 devState
= Device_Idle_SI
;
947 devState
= Device_Idle_S
;
949 } else if (action
== ACT_DMA_READY
) {
951 status
&= ~STATUS_BSY_BIT
;
953 status
|= STATUS_DRQ_BIT
;
955 devState
= Transfer_Data_Dma
;
957 if (dmaState
!= Dma_Idle
)
958 panic("Inconsistent DMA state, should be Dma_Idle\n");
960 dmaState
= Dma_Start
;
961 // wait for the write to the DMA start bit
965 case Transfer_Data_Dma
:
966 if (action
== ACT_CMD_ERROR
|| action
== ACT_DMA_DONE
) {
970 status
|= STATUS_SEEK_BIT
;
971 // clear the controller state for DMA transfer
972 ctrl
->setDmaComplete(this);
975 devState
= Device_Idle_SI
;
978 devState
= Device_Idle_S
;
984 panic("Unknown IDE device state: %#x\n", devState
);
989 IdeDisk::serialize(ostream
&os
)
991 // Check all outstanding events to see if they are scheduled
992 // these are all mutually exclusive
994 Events_t event
= None
;
998 if (dmaTransferEvent
.scheduled()) {
999 reschedule
= dmaTransferEvent
.when();
1003 if (dmaReadWaitEvent
.scheduled()) {
1004 reschedule
= dmaReadWaitEvent
.when();
1008 if (dmaWriteWaitEvent
.scheduled()) {
1009 reschedule
= dmaWriteWaitEvent
.when();
1013 if (dmaPrdReadEvent
.scheduled()) {
1014 reschedule
= dmaPrdReadEvent
.when();
1018 if (dmaReadEvent
.scheduled()) {
1019 reschedule
= dmaReadEvent
.when();
1023 if (dmaWriteEvent
.scheduled()) {
1024 reschedule
= dmaWriteEvent
.when();
1029 assert(eventCount
<= 1);
1031 SERIALIZE_SCALAR(reschedule
);
1032 SERIALIZE_ENUM(event
);
1034 // Serialize device registers
1035 SERIALIZE_SCALAR(cmdReg
.data
);
1036 SERIALIZE_SCALAR(cmdReg
.sec_count
);
1037 SERIALIZE_SCALAR(cmdReg
.sec_num
);
1038 SERIALIZE_SCALAR(cmdReg
.cyl_low
);
1039 SERIALIZE_SCALAR(cmdReg
.cyl_high
);
1040 SERIALIZE_SCALAR(cmdReg
.drive
);
1041 SERIALIZE_SCALAR(cmdReg
.command
);
1042 SERIALIZE_SCALAR(status
);
1043 SERIALIZE_SCALAR(nIENBit
);
1044 SERIALIZE_SCALAR(devID
);
1046 // Serialize the PRD related information
1047 SERIALIZE_SCALAR(curPrd
.entry
.baseAddr
);
1048 SERIALIZE_SCALAR(curPrd
.entry
.byteCount
);
1049 SERIALIZE_SCALAR(curPrd
.entry
.endOfTable
);
1050 SERIALIZE_SCALAR(curPrdAddr
);
1052 /** @todo need to serialized chunk generator stuff!! */
1053 // Serialize current transfer related information
1054 SERIALIZE_SCALAR(cmdBytesLeft
);
1055 SERIALIZE_SCALAR(cmdBytes
);
1056 SERIALIZE_SCALAR(drqBytesLeft
);
1057 SERIALIZE_SCALAR(curSector
);
1058 SERIALIZE_SCALAR(dmaRead
);
1059 SERIALIZE_SCALAR(intrPending
);
1060 SERIALIZE_ENUM(devState
);
1061 SERIALIZE_ENUM(dmaState
);
1062 SERIALIZE_ARRAY(dataBuffer
, MAX_DMA_SIZE
);
1066 IdeDisk::unserialize(Checkpoint
*cp
, const string
§ion
)
1068 // Reschedule events that were outstanding
1069 // these are all mutually exclusive
1070 Tick reschedule
= 0;
1071 Events_t event
= None
;
1073 UNSERIALIZE_SCALAR(reschedule
);
1074 UNSERIALIZE_ENUM(event
);
1078 case Transfer
: dmaTransferEvent
.schedule(reschedule
); break;
1079 case ReadWait
: dmaReadWaitEvent
.schedule(reschedule
); break;
1080 case WriteWait
: dmaWriteWaitEvent
.schedule(reschedule
); break;
1081 case PrdRead
: dmaPrdReadEvent
.schedule(reschedule
); break;
1082 case DmaRead
: dmaReadEvent
.schedule(reschedule
); break;
1083 case DmaWrite
: dmaWriteEvent
.schedule(reschedule
); break;
1086 // Unserialize device registers
1087 UNSERIALIZE_SCALAR(cmdReg
.data
);
1088 UNSERIALIZE_SCALAR(cmdReg
.sec_count
);
1089 UNSERIALIZE_SCALAR(cmdReg
.sec_num
);
1090 UNSERIALIZE_SCALAR(cmdReg
.cyl_low
);
1091 UNSERIALIZE_SCALAR(cmdReg
.cyl_high
);
1092 UNSERIALIZE_SCALAR(cmdReg
.drive
);
1093 UNSERIALIZE_SCALAR(cmdReg
.command
);
1094 UNSERIALIZE_SCALAR(status
);
1095 UNSERIALIZE_SCALAR(nIENBit
);
1096 UNSERIALIZE_SCALAR(devID
);
1098 // Unserialize the PRD related information
1099 UNSERIALIZE_SCALAR(curPrd
.entry
.baseAddr
);
1100 UNSERIALIZE_SCALAR(curPrd
.entry
.byteCount
);
1101 UNSERIALIZE_SCALAR(curPrd
.entry
.endOfTable
);
1102 UNSERIALIZE_SCALAR(curPrdAddr
);
1104 /** @todo need to serialized chunk generator stuff!! */
1105 // Unserialize current transfer related information
1106 UNSERIALIZE_SCALAR(cmdBytes
);
1107 UNSERIALIZE_SCALAR(cmdBytesLeft
);
1108 UNSERIALIZE_SCALAR(drqBytesLeft
);
1109 UNSERIALIZE_SCALAR(curSector
);
1110 UNSERIALIZE_SCALAR(dmaRead
);
1111 UNSERIALIZE_SCALAR(intrPending
);
1112 UNSERIALIZE_ENUM(devState
);
1113 UNSERIALIZE_ENUM(dmaState
);
1114 UNSERIALIZE_ARRAY(dataBuffer
, MAX_DMA_SIZE
);
1118 IdeDiskParams::create()
1120 return new IdeDisk(name
, image
, driveID
, delay
);