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.
30 * Device model implementation for an IDE disk
38 #include "base/chunk_generator.hh"
39 #include "base/cprintf.hh" // csprintf
40 #include "base/trace.hh"
41 #include "dev/disk_image.hh"
42 #include "dev/ide_disk.hh"
43 #include "dev/ide_ctrl.hh"
44 #include "dev/tsunami.hh"
45 #include "dev/tsunami_pchip.hh"
46 #include "sim/builder.hh"
47 #include "sim/sim_object.hh"
48 #include "sim/root.hh"
49 #include "arch/isa_traits.hh"
52 using namespace TheISA
;
54 IdeDisk::IdeDisk(const string
&name
, DiskImage
*img
,
56 : SimObject(name
), ctrl(NULL
), image(img
), diskDelay(delay
),
57 dmaTransferEvent(this), dmaReadCG(NULL
), dmaReadWaitEvent(this),
58 dmaWriteCG(NULL
), dmaWriteWaitEvent(this), dmaPrdReadEvent(this),
59 dmaReadEvent(this), dmaWriteEvent(this)
61 // Reset the device state
64 // fill out the drive ID structure
65 memset(&driveID
, 0, sizeof(struct ataparams
));
67 // Calculate LBA and C/H/S values
72 uint32_t lba_size
= image
->size();
73 if (lba_size
>= 16383*16*63) {
83 if ((lba_size
/ sectors
) >= 16)
86 heads
= (lba_size
/ sectors
);
88 cylinders
= lba_size
/ (heads
* sectors
);
91 // Setup the model name
92 strncpy((char *)driveID
.atap_model
, "5MI EDD si k",
93 sizeof(driveID
.atap_model
));
94 // Set the maximum multisector transfer size
95 driveID
.atap_multi
= MAX_MULTSECT
;
96 // IORDY supported, IORDY disabled, LBA enabled, DMA enabled
97 driveID
.atap_capabilities1
= 0x7;
98 // UDMA support, EIDE support
99 driveID
.atap_extensions
= 0x6;
100 // Setup default C/H/S settings
101 driveID
.atap_cylinders
= cylinders
;
102 driveID
.atap_sectors
= sectors
;
103 driveID
.atap_heads
= heads
;
104 // Setup the current multisector transfer size
105 driveID
.atap_curmulti
= MAX_MULTSECT
;
106 driveID
.atap_curmulti_valid
= 0x1;
107 // Number of sectors on disk
108 driveID
.atap_capacity
= lba_size
;
109 // Multiword DMA mode 2 and below supported
110 driveID
.atap_dmamode_supp
= 0x400;
111 // Set PIO mode 4 and 3 supported
112 driveID
.atap_piomode_supp
= 0x3;
113 // Set DMA mode 4 and below supported
114 driveID
.atap_udmamode_supp
= 0x1f;
115 // Statically set hardware config word
116 driveID
.atap_hwreset_res
= 0x4001;
118 //arbitrary for now...
119 driveID
.atap_ata_major
= WDC_VER_ATA7
;
124 // destroy the data buffer
125 delete [] dataBuffer
;
129 IdeDisk::reset(int id
)
131 // initialize the data buffer and shadow registers
132 dataBuffer
= new uint8_t[MAX_DMA_SIZE
];
134 memset(dataBuffer
, 0, MAX_DMA_SIZE
);
135 memset(&cmdReg
, 0, sizeof(CommandReg_t
));
136 memset(&curPrd
.entry
, 0, sizeof(PrdEntry_t
));
146 // set the device state to idle
150 devState
= Device_Idle_S
;
152 } else if (id
== DEV1
) {
153 devState
= Device_Idle_NS
;
156 panic("Invalid device ID: %#x\n", id
);
159 // set the device ready bit
160 status
= STATUS_DRDY_BIT
;
162 /* The error register must be set to 0x1 on start-up to
163 indicate that no diagnostic error was detected */
172 IdeDisk::isDEVSelect()
174 return ctrl
->isDiskSelected(this);
178 IdeDisk::pciToDma(Addr pciAddr
)
181 return ctrl
->plat
->pciToDma(pciAddr
);
183 panic("Access to unset controller!\n");
187 // Device registers read/write
191 IdeDisk::read(const Addr
&offset
, IdeRegType reg_type
, uint8_t *data
)
193 DevAction_t action
= ACT_NONE
;
198 // Data transfers occur two bytes at a time
200 *(uint16_t*)data
= cmdReg
.data
;
201 action
= ACT_DATA_READ_SHORT
;
204 *data
= cmdReg
.error
;
207 *data
= cmdReg
.sec_count
;
210 *data
= cmdReg
.sec_num
;
213 *data
= cmdReg
.cyl_low
;
216 *data
= cmdReg
.cyl_high
;
219 *data
= cmdReg
.drive
;
223 action
= ACT_STAT_READ
;
226 panic("Invalid IDE command register offset: %#x\n", offset
);
230 if (offset
== ALTSTAT_OFFSET
)
233 panic("Invalid IDE control register offset: %#x\n", offset
);
236 panic("Unknown register block!\n");
238 DPRINTF(IdeDisk
, "Read to disk at offset: %#x data %#x\n", offset
,
241 if (action
!= ACT_NONE
)
246 IdeDisk::write(const Addr
&offset
, IdeRegType reg_type
, const uint8_t *data
)
248 DevAction_t action
= ACT_NONE
;
254 cmdReg
.data
= *(uint16_t*)data
;
255 action
= ACT_DATA_WRITE_SHORT
;
257 case FEATURES_OFFSET
:
260 cmdReg
.sec_count
= *data
;
263 cmdReg
.sec_num
= *data
;
266 cmdReg
.cyl_low
= *data
;
269 cmdReg
.cyl_high
= *data
;
272 cmdReg
.drive
= *data
;
273 action
= ACT_SELECT_WRITE
;
276 cmdReg
.command
= *data
;
277 action
= ACT_CMD_WRITE
;
280 panic("Invalid IDE command register offset: %#x\n", offset
);
284 if (offset
== CONTROL_OFFSET
) {
285 if (*data
& CONTROL_RST_BIT
) {
286 // force the device into the reset state
287 devState
= Device_Srst
;
288 action
= ACT_SRST_SET
;
289 } else if (devState
== Device_Srst
&& !(*data
& CONTROL_RST_BIT
))
290 action
= ACT_SRST_CLEAR
;
292 nIENBit
= (*data
& CONTROL_IEN_BIT
) ? true : false;
295 panic("Invalid IDE control register offset: %#x\n", offset
);
298 panic("Unknown register block!\n");
301 DPRINTF(IdeDisk
, "Write to disk at offset: %#x data %#x\n", offset
,
303 if (action
!= ACT_NONE
)
308 // Perform DMA transactions
312 IdeDisk::doDmaTransfer()
314 if (dmaState
!= Dma_Transfer
|| devState
!= Transfer_Data_Dma
)
315 panic("Inconsistent DMA transfer state: dmaState = %d devState = %d\n",
318 if (ctrl
->dmaPending()) {
319 dmaTransferEvent
.schedule(curTick
+ DMA_BACKOFF_PERIOD
);
322 ctrl
->dmaRead(curPrdAddr
, sizeof(PrdEntry_t
), &dmaPrdReadEvent
,
323 (uint8_t*)&curPrd
.entry
);
327 IdeDisk::dmaPrdReadDone()
330 "PRD: baseAddr:%#x (%#x) byteCount:%d (%d) eot:%#x sector:%d\n",
331 curPrd
.getBaseAddr(), pciToDma(curPrd
.getBaseAddr()),
332 curPrd
.getByteCount(), (cmdBytesLeft
/SectorSize
),
333 curPrd
.getEOT(), curSector
);
335 // the prd pointer has already been translated, so just do an increment
336 curPrdAddr
= curPrdAddr
+ sizeof(PrdEntry_t
);
345 IdeDisk::doDmaDataRead()
347 /** @todo we need to figure out what the delay actually will be */
348 Tick totalDiskDelay
= diskDelay
+ (curPrd
.getByteCount() / SectorSize
);
350 DPRINTF(IdeDisk
, "doDmaRead, diskDelay: %d totalDiskDelay: %d\n",
351 diskDelay
, totalDiskDelay
);
353 dmaReadWaitEvent
.schedule(curTick
+ totalDiskDelay
);
359 using namespace Stats
;
361 .name(name() + ".dma_read_full_pages")
362 .desc("Number of full page size DMA reads (not PRD).")
365 .name(name() + ".dma_read_bytes")
366 .desc("Number of bytes transfered via DMA reads (not PRD).")
369 .name(name() + ".dma_read_txs")
370 .desc("Number of DMA read transactions (not PRD).")
374 .name(name() + ".dma_write_full_pages")
375 .desc("Number of full page size DMA writes.")
378 .name(name() + ".dma_write_bytes")
379 .desc("Number of bytes transfered via DMA writes.")
382 .name(name() + ".dma_write_txs")
383 .desc("Number of DMA write transactions.")
392 // clear out the data buffer
393 memset(dataBuffer
, 0, MAX_DMA_SIZE
);
394 dmaReadCG
= new ChunkGenerator(curPrd
.getBaseAddr(),
395 curPrd
.getByteCount(), TheISA::PageBytes
);
398 if (ctrl
->dmaPending()) {
399 panic("shouldn't be reentant??");
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()) {
475 panic("shouldn't be reentant??");
476 dmaWriteWaitEvent
.schedule(curTick
+ DMA_BACKOFF_PERIOD
);
478 } else if (!dmaWriteCG
->done()) {
479 assert(dmaWriteCG
->complete() < MAX_DMA_SIZE
);
480 ctrl
->dmaWrite(pciToDma(dmaWriteCG
->addr()), dmaWriteCG
->size(),
481 &dmaWriteWaitEvent
, dataBuffer
+ dmaWriteCG
->complete());
482 dmaWriteBytes
+= dmaWriteCG
->size();
484 if (dmaWriteCG
->size() == TheISA::PageBytes
)
488 assert(dmaWriteCG
->done());
496 IdeDisk::dmaWriteDone()
499 if (curPrd
.getEOT()) {
500 assert(cmdBytesLeft
== 0);
502 updateState(ACT_DMA_DONE
);
509 // Disk utility routines
513 IdeDisk::readDisk(uint32_t sector
, uint8_t *data
)
515 uint32_t bytesRead
= image
->read(data
, sector
);
517 if (bytesRead
!= SectorSize
)
518 panic("Can't read from %s. Only %d of %d read. errno=%d\n",
519 name(), bytesRead
, SectorSize
, errno
);
523 IdeDisk::writeDisk(uint32_t sector
, uint8_t *data
)
525 uint32_t bytesWritten
= image
->write(data
, sector
);
527 if (bytesWritten
!= SectorSize
)
528 panic("Can't write to %s. Only %d of %d written. errno=%d\n",
529 name(), bytesWritten
, SectorSize
, errno
);
533 // Setup and handle commands
537 IdeDisk::startDma(const uint32_t &prdTableBase
)
539 if (dmaState
!= Dma_Start
)
540 panic("Inconsistent DMA state, should be in Dma_Start!\n");
542 if (devState
!= Transfer_Data_Dma
)
543 panic("Inconsistent device state for DMA start!\n");
545 // PRD base address is given by bits 31:2
546 curPrdAddr
= pciToDma((Addr
)(prdTableBase
& ~ULL(0x3)));
548 dmaState
= Dma_Transfer
;
550 // schedule dma transfer (doDmaTransfer)
551 dmaTransferEvent
.schedule(curTick
+ 1);
557 if (dmaState
== Dma_Idle
)
558 panic("Inconsistent DMA state, should be Start or Transfer!");
560 if (devState
!= Transfer_Data_Dma
&& devState
!= Prepare_Data_Dma
)
561 panic("Inconsistent device state, should be Transfer or Prepare!\n");
563 updateState(ACT_CMD_ERROR
);
567 IdeDisk::startCommand()
569 DevAction_t action
= ACT_NONE
;
574 switch (cmdReg
.command
) {
575 // Supported non-data commands
576 case WDSF_READ_NATIVE_MAX
:
577 size
= image
->size() - 1;
578 cmdReg
.sec_num
= (size
& 0xff);
579 cmdReg
.cyl_low
= ((size
& 0xff00) >> 8);
580 cmdReg
.cyl_high
= ((size
& 0xff0000) >> 16);
581 cmdReg
.head
= ((size
& 0xf000000) >> 24);
583 devState
= Command_Execution
;
584 action
= ACT_CMD_COMPLETE
;
589 case WDCC_STANDBY_IMMED
:
590 case WDCC_FLUSHCACHE
:
595 devState
= Command_Execution
;
596 action
= ACT_CMD_COMPLETE
;
599 // Supported PIO data-in commands
601 cmdBytes
= cmdBytesLeft
= sizeof(struct ataparams
);
602 devState
= Prepare_Data_In
;
603 action
= ACT_DATA_READY
;
608 if (!(cmdReg
.drive
& DRIVE_LBA_BIT
))
609 panic("Attempt to perform CHS access, only supports LBA\n");
611 if (cmdReg
.sec_count
== 0)
612 cmdBytes
= cmdBytesLeft
= (256 * SectorSize
);
614 cmdBytes
= cmdBytesLeft
= (cmdReg
.sec_count
* SectorSize
);
616 curSector
= getLBABase();
618 /** @todo make this a scheduled event to simulate disk delay */
619 devState
= Prepare_Data_In
;
620 action
= ACT_DATA_READY
;
623 // Supported PIO data-out commands
624 case WDCC_WRITEMULTI
:
626 if (!(cmdReg
.drive
& DRIVE_LBA_BIT
))
627 panic("Attempt to perform CHS access, only supports LBA\n");
629 if (cmdReg
.sec_count
== 0)
630 cmdBytes
= cmdBytesLeft
= (256 * SectorSize
);
632 cmdBytes
= cmdBytesLeft
= (cmdReg
.sec_count
* SectorSize
);
634 curSector
= getLBABase();
636 devState
= Prepare_Data_Out
;
637 action
= ACT_DATA_READY
;
640 // Supported DMA commands
642 dmaRead
= true; // a write to the disk is a DMA read from memory
644 if (!(cmdReg
.drive
& DRIVE_LBA_BIT
))
645 panic("Attempt to perform CHS access, only supports LBA\n");
647 if (cmdReg
.sec_count
== 0)
648 cmdBytes
= cmdBytesLeft
= (256 * SectorSize
);
650 cmdBytes
= cmdBytesLeft
= (cmdReg
.sec_count
* SectorSize
);
652 curSector
= getLBABase();
654 devState
= Prepare_Data_Dma
;
655 action
= ACT_DMA_READY
;
659 panic("Unsupported ATA command: %#x\n", cmdReg
.command
);
662 if (action
!= ACT_NONE
) {
664 status
|= STATUS_BSY_BIT
;
666 status
&= ~STATUS_DRQ_BIT
;
668 status
&= ~STATUS_DF_BIT
;
675 // Handle setting and clearing interrupts
681 DPRINTF(IdeDisk
, "Posting Interrupt\n");
683 panic("Attempt to post an interrupt with one pending\n");
687 // talk to controller to set interrupt
689 ctrl
->bmi_regs
.bmis0
|= IDEINTS
;
697 DPRINTF(IdeDisk
, "Clearing Interrupt\n");
699 panic("Attempt to clear a non-pending interrupt\n");
703 // talk to controller to clear interrupt
709 // Manage the device internal state machine
713 IdeDisk::updateState(DevAction_t action
)
717 if (action
== ACT_SRST_SET
) {
719 status
|= STATUS_BSY_BIT
;
720 } else if (action
== ACT_SRST_CLEAR
) {
722 status
&= ~STATUS_BSY_BIT
;
724 // reset the device state
730 if (action
== ACT_SELECT_WRITE
&& !isDEVSelect()) {
731 devState
= Device_Idle_NS
;
732 } else if (action
== ACT_CMD_WRITE
) {
739 if (action
== ACT_SELECT_WRITE
&& !isDEVSelect()) {
740 devState
= Device_Idle_NS
;
742 } else if (action
== ACT_STAT_READ
|| isIENSet()) {
743 devState
= Device_Idle_S
;
745 } else if (action
== ACT_CMD_WRITE
) {
753 if (action
== ACT_SELECT_WRITE
&& isDEVSelect()) {
754 if (!isIENSet() && intrPending
) {
755 devState
= Device_Idle_SI
;
758 if (isIENSet() || !intrPending
) {
759 devState
= Device_Idle_S
;
764 case Command_Execution
:
765 if (action
== ACT_CMD_COMPLETE
) {
770 devState
= Device_Idle_SI
;
773 devState
= Device_Idle_S
;
778 case Prepare_Data_In
:
779 if (action
== ACT_CMD_ERROR
) {
784 devState
= Device_Idle_SI
;
787 devState
= Device_Idle_S
;
789 } else if (action
== ACT_DATA_READY
) {
791 status
&= ~STATUS_BSY_BIT
;
793 status
|= STATUS_DRQ_BIT
;
795 // copy the data into the data buffer
796 if (cmdReg
.command
== WDCC_IDENTIFY
) {
797 // Reset the drqBytes for this block
798 drqBytesLeft
= sizeof(struct ataparams
);
800 memcpy((void *)dataBuffer
, (void *)&driveID
,
801 sizeof(struct ataparams
));
803 // Reset the drqBytes for this block
804 drqBytesLeft
= SectorSize
;
806 readDisk(curSector
++, dataBuffer
);
809 // put the first two bytes into the data register
810 memcpy((void *)&cmdReg
.data
, (void *)dataBuffer
,
814 devState
= Data_Ready_INTRQ_In
;
817 devState
= Transfer_Data_In
;
822 case Data_Ready_INTRQ_In
:
823 if (action
== ACT_STAT_READ
) {
824 devState
= Transfer_Data_In
;
829 case Transfer_Data_In
:
830 if (action
== ACT_DATA_READ_BYTE
|| action
== ACT_DATA_READ_SHORT
) {
831 if (action
== ACT_DATA_READ_BYTE
) {
832 panic("DEBUG: READING DATA ONE BYTE AT A TIME!\n");
837 // copy next short into data registers
839 memcpy((void *)&cmdReg
.data
,
840 (void *)&dataBuffer
[SectorSize
- drqBytesLeft
],
844 if (drqBytesLeft
== 0) {
845 if (cmdBytesLeft
== 0) {
848 devState
= Device_Idle_S
;
850 devState
= Prepare_Data_In
;
852 status
|= STATUS_BSY_BIT
;
854 status
&= ~STATUS_DRQ_BIT
;
856 /** @todo change this to a scheduled event to simulate
858 updateState(ACT_DATA_READY
);
864 case Prepare_Data_Out
:
865 if (action
== ACT_CMD_ERROR
|| cmdBytesLeft
== 0) {
870 devState
= Device_Idle_SI
;
873 devState
= Device_Idle_S
;
875 } else if (action
== ACT_DATA_READY
&& cmdBytesLeft
!= 0) {
877 status
&= ~STATUS_BSY_BIT
;
879 status
|= STATUS_DRQ_BIT
;
881 // clear the data buffer to get it ready for writes
882 memset(dataBuffer
, 0, MAX_DMA_SIZE
);
884 // reset the drqBytes for this block
885 drqBytesLeft
= SectorSize
;
887 if (cmdBytesLeft
== cmdBytes
|| isIENSet()) {
888 devState
= Transfer_Data_Out
;
890 devState
= Data_Ready_INTRQ_Out
;
896 case Data_Ready_INTRQ_Out
:
897 if (action
== ACT_STAT_READ
) {
898 devState
= Transfer_Data_Out
;
903 case Transfer_Data_Out
:
904 if (action
== ACT_DATA_WRITE_BYTE
||
905 action
== ACT_DATA_WRITE_SHORT
) {
907 if (action
== ACT_DATA_READ_BYTE
) {
908 panic("DEBUG: WRITING DATA ONE BYTE AT A TIME!\n");
910 // copy the latest short into the data buffer
911 memcpy((void *)&dataBuffer
[SectorSize
- drqBytesLeft
],
912 (void *)&cmdReg
.data
,
919 if (drqBytesLeft
== 0) {
920 // copy the block to the disk
921 writeDisk(curSector
++, dataBuffer
);
924 status
|= STATUS_BSY_BIT
;
926 status
|= STATUS_SEEK_BIT
;
928 status
&= ~STATUS_DRQ_BIT
;
930 devState
= Prepare_Data_Out
;
932 /** @todo change this to a scheduled event to simulate
934 updateState(ACT_DATA_READY
);
939 case Prepare_Data_Dma
:
940 if (action
== ACT_CMD_ERROR
) {
945 devState
= Device_Idle_SI
;
948 devState
= Device_Idle_S
;
950 } else if (action
== ACT_DMA_READY
) {
952 status
&= ~STATUS_BSY_BIT
;
954 status
|= STATUS_DRQ_BIT
;
956 devState
= Transfer_Data_Dma
;
958 if (dmaState
!= Dma_Idle
)
959 panic("Inconsistent DMA state, should be Dma_Idle\n");
961 dmaState
= Dma_Start
;
962 // wait for the write to the DMA start bit
966 case Transfer_Data_Dma
:
967 if (action
== ACT_CMD_ERROR
|| action
== ACT_DMA_DONE
) {
971 status
|= STATUS_SEEK_BIT
;
972 // clear the controller state for DMA transfer
973 ctrl
->setDmaComplete(this);
976 devState
= Device_Idle_SI
;
979 devState
= Device_Idle_S
;
985 panic("Unknown IDE device state: %#x\n", devState
);
990 IdeDisk::serialize(ostream
&os
)
992 // Check all outstanding events to see if they are scheduled
993 // these are all mutually exclusive
995 Events_t event
= None
;
999 if (dmaTransferEvent
.scheduled()) {
1000 reschedule
= dmaTransferEvent
.when();
1004 if (dmaReadWaitEvent
.scheduled()) {
1005 reschedule
= dmaReadWaitEvent
.when();
1009 if (dmaWriteWaitEvent
.scheduled()) {
1010 reschedule
= dmaWriteWaitEvent
.when();
1014 if (dmaPrdReadEvent
.scheduled()) {
1015 reschedule
= dmaPrdReadEvent
.when();
1019 if (dmaReadEvent
.scheduled()) {
1020 reschedule
= dmaReadEvent
.when();
1024 if (dmaWriteEvent
.scheduled()) {
1025 reschedule
= dmaWriteEvent
.when();
1030 assert(eventCount
<= 1);
1032 SERIALIZE_SCALAR(reschedule
);
1033 SERIALIZE_ENUM(event
);
1035 // Serialize device registers
1036 SERIALIZE_SCALAR(cmdReg
.data
);
1037 SERIALIZE_SCALAR(cmdReg
.sec_count
);
1038 SERIALIZE_SCALAR(cmdReg
.sec_num
);
1039 SERIALIZE_SCALAR(cmdReg
.cyl_low
);
1040 SERIALIZE_SCALAR(cmdReg
.cyl_high
);
1041 SERIALIZE_SCALAR(cmdReg
.drive
);
1042 SERIALIZE_SCALAR(cmdReg
.command
);
1043 SERIALIZE_SCALAR(status
);
1044 SERIALIZE_SCALAR(nIENBit
);
1045 SERIALIZE_SCALAR(devID
);
1047 // Serialize the PRD related information
1048 SERIALIZE_SCALAR(curPrd
.entry
.baseAddr
);
1049 SERIALIZE_SCALAR(curPrd
.entry
.byteCount
);
1050 SERIALIZE_SCALAR(curPrd
.entry
.endOfTable
);
1051 SERIALIZE_SCALAR(curPrdAddr
);
1053 /** @todo need to serialized chunk generator stuff!! */
1054 // Serialize current transfer related information
1055 SERIALIZE_SCALAR(cmdBytesLeft
);
1056 SERIALIZE_SCALAR(cmdBytes
);
1057 SERIALIZE_SCALAR(drqBytesLeft
);
1058 SERIALIZE_SCALAR(curSector
);
1059 SERIALIZE_SCALAR(dmaRead
);
1060 SERIALIZE_SCALAR(intrPending
);
1061 SERIALIZE_ENUM(devState
);
1062 SERIALIZE_ENUM(dmaState
);
1063 SERIALIZE_ARRAY(dataBuffer
, MAX_DMA_SIZE
);
1067 IdeDisk::unserialize(Checkpoint
*cp
, const string
§ion
)
1069 // Reschedule events that were outstanding
1070 // these are all mutually exclusive
1071 Tick reschedule
= 0;
1072 Events_t event
= None
;
1074 UNSERIALIZE_SCALAR(reschedule
);
1075 UNSERIALIZE_ENUM(event
);
1079 case Transfer
: dmaTransferEvent
.schedule(reschedule
); break;
1080 case ReadWait
: dmaReadWaitEvent
.schedule(reschedule
); break;
1081 case WriteWait
: dmaWriteWaitEvent
.schedule(reschedule
); break;
1082 case PrdRead
: dmaPrdReadEvent
.schedule(reschedule
); break;
1083 case DmaRead
: dmaReadEvent
.schedule(reschedule
); break;
1084 case DmaWrite
: dmaWriteEvent
.schedule(reschedule
); break;
1087 // Unserialize device registers
1088 UNSERIALIZE_SCALAR(cmdReg
.data
);
1089 UNSERIALIZE_SCALAR(cmdReg
.sec_count
);
1090 UNSERIALIZE_SCALAR(cmdReg
.sec_num
);
1091 UNSERIALIZE_SCALAR(cmdReg
.cyl_low
);
1092 UNSERIALIZE_SCALAR(cmdReg
.cyl_high
);
1093 UNSERIALIZE_SCALAR(cmdReg
.drive
);
1094 UNSERIALIZE_SCALAR(cmdReg
.command
);
1095 UNSERIALIZE_SCALAR(status
);
1096 UNSERIALIZE_SCALAR(nIENBit
);
1097 UNSERIALIZE_SCALAR(devID
);
1099 // Unserialize the PRD related information
1100 UNSERIALIZE_SCALAR(curPrd
.entry
.baseAddr
);
1101 UNSERIALIZE_SCALAR(curPrd
.entry
.byteCount
);
1102 UNSERIALIZE_SCALAR(curPrd
.entry
.endOfTable
);
1103 UNSERIALIZE_SCALAR(curPrdAddr
);
1105 /** @todo need to serialized chunk generator stuff!! */
1106 // Unserialize current transfer related information
1107 UNSERIALIZE_SCALAR(cmdBytes
);
1108 UNSERIALIZE_SCALAR(cmdBytesLeft
);
1109 UNSERIALIZE_SCALAR(drqBytesLeft
);
1110 UNSERIALIZE_SCALAR(curSector
);
1111 UNSERIALIZE_SCALAR(dmaRead
);
1112 UNSERIALIZE_SCALAR(intrPending
);
1113 UNSERIALIZE_ENUM(devState
);
1114 UNSERIALIZE_ENUM(dmaState
);
1115 UNSERIALIZE_ARRAY(dataBuffer
, MAX_DMA_SIZE
);
1118 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1120 enum DriveID
{ master
, slave
};
1121 static const char *DriveID_strings
[] = { "master", "slave" };
1122 BEGIN_DECLARE_SIM_OBJECT_PARAMS(IdeDisk
)
1124 SimObjectParam
<DiskImage
*> image
;
1125 SimpleEnumParam
<DriveID
> driveID
;
1128 END_DECLARE_SIM_OBJECT_PARAMS(IdeDisk
)
1130 BEGIN_INIT_SIM_OBJECT_PARAMS(IdeDisk
)
1132 INIT_PARAM(image
, "Disk image"),
1133 INIT_ENUM_PARAM(driveID
, "Drive ID (0=master 1=slave)", DriveID_strings
),
1134 INIT_PARAM_DFLT(delay
, "Fixed disk delay in microseconds", 1)
1136 END_INIT_SIM_OBJECT_PARAMS(IdeDisk
)
1139 CREATE_SIM_OBJECT(IdeDisk
)
1141 return new IdeDisk(getInstanceName(), image
, driveID
, delay
);
1144 REGISTER_SIM_OBJECT("IdeDisk", IdeDisk
)
1146 #endif //DOXYGEN_SHOULD_SKIP_THIS