tsunami_io.cc (4762:c94e103c83ad) tsunami_io.cc (4870:fcc39d001154)
1/*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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;

--- 26 unchanged lines hidden (view full) ---

35 */
36
37#include <sys/time.h>
38
39#include <deque>
40#include <string>
41#include <vector>
42
1/*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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;

--- 26 unchanged lines hidden (view full) ---

35 */
36
37#include <sys/time.h>
38
39#include <deque>
40#include <string>
41#include <vector>
42
43#include "base/time.hh"
44#include "base/trace.hh"
45#include "dev/pitreg.h"
46#include "dev/rtcreg.h"
47#include "dev/alpha/tsunami_cchip.hh"
48#include "dev/alpha/tsunami.hh"
49#include "dev/alpha/tsunami_io.hh"
50#include "dev/alpha/tsunamireg.h"
51#include "mem/packet.hh"
52#include "mem/packet_access.hh"
53#include "mem/port.hh"
43#include "base/trace.hh"
44#include "dev/pitreg.h"
45#include "dev/rtcreg.h"
46#include "dev/alpha/tsunami_cchip.hh"
47#include "dev/alpha/tsunami.hh"
48#include "dev/alpha/tsunami_io.hh"
49#include "dev/alpha/tsunamireg.h"
50#include "mem/packet.hh"
51#include "mem/packet_access.hh"
52#include "mem/port.hh"
53#include "sim/builder.hh"
54#include "sim/system.hh"
55
56using namespace std;
57//Should this be AlphaISA?
58using namespace TheISA;
59
54#include "sim/system.hh"
55
56using namespace std;
57//Should this be AlphaISA?
58using namespace TheISA;
59
60TsunamiIO::RTC::RTC(const string &n, Tsunami* tsunami,
61 const TsunamiIO::Params *p)
62 : _name(n), event(tsunami, p->frequency), addr(0)
60TsunamiIO::RTC::RTC(const string &n, Tsunami* tsunami, const vector<int> &t,
61 bool bcd, Tick i)
62 : _name(n), event(tsunami, i), addr(0), year_is_bcd(bcd)
63{
64 memset(clock_data, 0, sizeof(clock_data));
65 stat_regA = RTCA_32768HZ | RTCA_1024HZ;
66 stat_regB = RTCB_PRDC_IE |RTCB_BIN | RTCB_24HR;
67
63{
64 memset(clock_data, 0, sizeof(clock_data));
65 stat_regA = RTCA_32768HZ | RTCA_1024HZ;
66 stat_regB = RTCB_PRDC_IE |RTCB_BIN | RTCB_24HR;
67
68 year = p->time.tm_year;
68 struct tm tm;
69 parseTime(t, &tm);
69
70
70 if (p->year_is_bcd) {
71 year = tm.tm_year;
72
73 if (year_is_bcd) {
71 // The datasheet says that the year field can be either BCD or
72 // years since 1900. Linux seems to be happy with years since
73 // 1900.
74 year = year % 100;
75 int tens = year / 10;
76 int ones = year % 10;
77 year = (tens << 4) + ones;
78 }
79
80 // Unix is 0-11 for month, data seet says start at 1
74 // The datasheet says that the year field can be either BCD or
75 // years since 1900. Linux seems to be happy with years since
76 // 1900.
77 year = year % 100;
78 int tens = year / 10;
79 int ones = year % 10;
80 year = (tens << 4) + ones;
81 }
82
83 // Unix is 0-11 for month, data seet says start at 1
81 mon = p->time.tm_mon + 1;
82 mday = p->time.tm_mday;
83 hour = p->time.tm_hour;
84 min = p->time.tm_min;
85 sec = p->time.tm_sec;
84 mon = tm.tm_mon + 1;
85 mday = tm.tm_mday;
86 hour = tm.tm_hour;
87 min = tm.tm_min;
88 sec = tm.tm_sec;
86
87 // Datasheet says 1 is sunday
89
90 // Datasheet says 1 is sunday
88 wday = p->time.tm_wday + 1;
91 wday = tm.tm_wday + 1;
89
92
90 DPRINTFN("Real-time clock set to %s", asctime(&p->time));
93 DPRINTFN("Real-time clock set to %s", asctime(&tm));
91}
92
93void
94TsunamiIO::RTC::writeAddr(const uint8_t data)
95{
96 if (data <= RTC_STAT_REGD)
97 addr = data;
98 else

--- 330 unchanged lines hidden (view full) ---

429}
430
431const char *
432TsunamiIO::PITimer::Counter::CounterEvent::description()
433{
434 return "tsunami 8254 Interval timer";
435}
436
94}
95
96void
97TsunamiIO::RTC::writeAddr(const uint8_t data)
98{
99 if (data <= RTC_STAT_REGD)
100 addr = data;
101 else

--- 330 unchanged lines hidden (view full) ---

432}
433
434const char *
435TsunamiIO::PITimer::Counter::CounterEvent::description()
436{
437 return "tsunami 8254 Interval timer";
438}
439
437TsunamiIO::TsunamiIO(const Params *p)
440TsunamiIO::TsunamiIO(Params *p)
438 : BasicPioDevice(p), tsunami(p->tsunami), pitimer(p->name + "pitimer"),
441 : BasicPioDevice(p), tsunami(p->tsunami), pitimer(p->name + "pitimer"),
439 rtc(p->name + ".rtc", p->tsunami, p)
442 rtc(p->name + ".rtc", p->tsunami, p->init_time, p->year_is_bcd,
443 p->frequency)
440{
441 pioSize = 0x100;
442
443 // set the back pointer from tsunami to myself
444 tsunami->io = this;
445
446 timerData = 0;
447 picr = 0;

--- 4 unchanged lines hidden (view full) ---

452TsunamiIO::frequency() const
453{
454 return Clock::Frequency / params()->frequency;
455}
456
457Tick
458TsunamiIO::read(PacketPtr pkt)
459{
444{
445 pioSize = 0x100;
446
447 // set the back pointer from tsunami to myself
448 tsunami->io = this;
449
450 timerData = 0;
451 picr = 0;

--- 4 unchanged lines hidden (view full) ---

456TsunamiIO::frequency() const
457{
458 return Clock::Frequency / params()->frequency;
459}
460
461Tick
462TsunamiIO::read(PacketPtr pkt)
463{
460 assert(pkt->result == Packet::Unknown);
461 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
462
463 Addr daddr = pkt->getAddr() - pioAddr;
464
465 DPRINTF(Tsunami, "io read va=%#x size=%d IOPorrt=%#x\n", pkt->getAddr(),
466 pkt->getSize(), daddr);
467
468 pkt->allocate();

--- 42 unchanged lines hidden (view full) ---

511 if (daddr == TSDEV_PIC1_ISR)
512 pkt->set<uint64_t>(picr);
513 else
514 panic("I/O Read - invalid addr - va %#x size %d\n",
515 pkt->getAddr(), pkt->getSize());
516 } else {
517 panic("I/O Read - invalid size - va %#x size %d\n", pkt->getAddr(), pkt->getSize());
518 }
464 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
465
466 Addr daddr = pkt->getAddr() - pioAddr;
467
468 DPRINTF(Tsunami, "io read va=%#x size=%d IOPorrt=%#x\n", pkt->getAddr(),
469 pkt->getSize(), daddr);
470
471 pkt->allocate();

--- 42 unchanged lines hidden (view full) ---

514 if (daddr == TSDEV_PIC1_ISR)
515 pkt->set<uint64_t>(picr);
516 else
517 panic("I/O Read - invalid addr - va %#x size %d\n",
518 pkt->getAddr(), pkt->getSize());
519 } else {
520 panic("I/O Read - invalid size - va %#x size %d\n", pkt->getAddr(), pkt->getSize());
521 }
519 pkt->result = Packet::Success;
522 pkt->makeAtomicResponse();
520 return pioDelay;
521}
522
523Tick
524TsunamiIO::write(PacketPtr pkt)
525{
523 return pioDelay;
524}
525
526Tick
527TsunamiIO::write(PacketPtr pkt)
528{
526 assert(pkt->result == Packet::Unknown);
527 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
528 Addr daddr = pkt->getAddr() - pioAddr;
529
530 DPRINTF(Tsunami, "io write - va=%#x size=%d IOPort=%#x Data=%#x\n",
531 pkt->getAddr(), pkt->getSize(), pkt->getAddr() & 0xfff, (uint32_t)pkt->get<uint8_t>());
532
533 assert(pkt->getSize() == sizeof(uint8_t));
534

--- 56 unchanged lines hidden (view full) ---

591 case TSDEV_DMA1_MASK:
592 case TSDEV_DMA2_MASK:
593 case TSDEV_CTRL_PORTB:
594 break;
595 default:
596 panic("I/O Write - va%#x size %d data %#x\n", pkt->getAddr(), pkt->getSize(), pkt->get<uint8_t>());
597 }
598
529 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
530 Addr daddr = pkt->getAddr() - pioAddr;
531
532 DPRINTF(Tsunami, "io write - va=%#x size=%d IOPort=%#x Data=%#x\n",
533 pkt->getAddr(), pkt->getSize(), pkt->getAddr() & 0xfff, (uint32_t)pkt->get<uint8_t>());
534
535 assert(pkt->getSize() == sizeof(uint8_t));
536

--- 56 unchanged lines hidden (view full) ---

593 case TSDEV_DMA1_MASK:
594 case TSDEV_DMA2_MASK:
595 case TSDEV_CTRL_PORTB:
596 break;
597 default:
598 panic("I/O Write - va%#x size %d data %#x\n", pkt->getAddr(), pkt->getSize(), pkt->get<uint8_t>());
599 }
600
599 pkt->result = Packet::Success;
601 pkt->makeAtomicResponse();
600 return pioDelay;
601}
602
603void
604TsunamiIO::postPIC(uint8_t bitvector)
605{
606 //PIC2 Is not implemented, because nothing of interest there
607 picr |= bitvector;

--- 41 unchanged lines hidden (view full) ---

649 UNSERIALIZE_SCALAR(picr);
650 UNSERIALIZE_SCALAR(picInterrupting);
651
652 // Unserialize the timers
653 pitimer.unserialize("pitimer", cp, section);
654 rtc.unserialize("rtc", cp, section);
655}
656
602 return pioDelay;
603}
604
605void
606TsunamiIO::postPIC(uint8_t bitvector)
607{
608 //PIC2 Is not implemented, because nothing of interest there
609 picr |= bitvector;

--- 41 unchanged lines hidden (view full) ---

651 UNSERIALIZE_SCALAR(picr);
652 UNSERIALIZE_SCALAR(picInterrupting);
653
654 // Unserialize the timers
655 pitimer.unserialize("pitimer", cp, section);
656 rtc.unserialize("rtc", cp, section);
657}
658
657TsunamiIO *
658TsunamiIOParams::create()
659BEGIN_DECLARE_SIM_OBJECT_PARAMS(TsunamiIO)
660
661 Param<Addr> pio_addr;
662 Param<Tick> pio_latency;
663 Param<Tick> frequency;
664 SimObjectParam<Platform *> platform;
665 SimObjectParam<System *> system;
666 VectorParam<int> time;
667 Param<bool> year_is_bcd;
668 SimObjectParam<Tsunami *> tsunami;
669
670END_DECLARE_SIM_OBJECT_PARAMS(TsunamiIO)
671
672BEGIN_INIT_SIM_OBJECT_PARAMS(TsunamiIO)
673
674 INIT_PARAM(pio_addr, "Device Address"),
675 INIT_PARAM(pio_latency, "Programmed IO latency"),
676 INIT_PARAM(frequency, "clock interrupt frequency"),
677 INIT_PARAM(platform, "platform"),
678 INIT_PARAM(system, "system object"),
679 INIT_PARAM(time, "System time to use (0 for actual time"),
680 INIT_PARAM(year_is_bcd, ""),
681 INIT_PARAM(tsunami, "Tsunami")
682
683END_INIT_SIM_OBJECT_PARAMS(TsunamiIO)
684
685CREATE_SIM_OBJECT(TsunamiIO)
659{
686{
660 return new TsunamiIO(this);
687 TsunamiIO::Params *p = new TsunamiIO::Params;
688 p->frequency = frequency;
689 p->name = getInstanceName();
690 p->pio_addr = pio_addr;
691 p->pio_delay = pio_latency;
692 p->platform = platform;
693 p->system = system;
694 p->init_time = time;
695 p->year_is_bcd = year_is_bcd;
696 p->tsunami = tsunami;
697 return new TsunamiIO(p);
661}
698}
699
700REGISTER_SIM_OBJECT("TsunamiIO", TsunamiIO)