RubyDirectedTester.cc revision 7632
16899SN/A/*
26899SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
37553SN/A * Copyright (c) 2009-2010 Advanced Micro Devices, Inc.
46899SN/A * All rights reserved.
56899SN/A *
66899SN/A * Redistribution and use in source and binary forms, with or without
76899SN/A * modification, are permitted provided that the following conditions are
86899SN/A * met: redistributions of source code must retain the above copyright
96899SN/A * notice, this list of conditions and the following disclaimer;
106899SN/A * redistributions in binary form must reproduce the above copyright
116899SN/A * notice, this list of conditions and the following disclaimer in the
126899SN/A * documentation and/or other materials provided with the distribution;
136899SN/A * neither the name of the copyright holders nor the names of its
146899SN/A * contributors may be used to endorse or promote products derived from
156899SN/A * this software without specific prior written permission.
166899SN/A *
176899SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186899SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196899SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206899SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216899SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226899SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236899SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246899SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256899SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266899SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276899SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286899SN/A */
296899SN/A
307632SBrad.Beckmann@amd.com#include "cpu/testers/directedtest/DirectedGenerator.hh"
317632SBrad.Beckmann@amd.com#include "cpu/testers/directedtest/RubyDirectedTester.hh"
327053SN/A#include "mem/ruby/eventqueue/RubyEventQueue.hh"
336899SN/A#include "sim/sim_exit.hh"
346899SN/A
357553SN/ARubyDirectedTester::RubyDirectedTester(const Params *p)
367553SN/A  : MemObject(p), directedStartEvent(this),
377553SN/A    m_requests_to_complete(p->requests_to_complete),
387553SN/A    generator(p->generator)
396899SN/A{
407553SN/A    m_requests_completed = 0;
416899SN/A
427053SN/A    // add the check start event to the event queue
437553SN/A    schedule(directedStartEvent, 1);
446899SN/A}
456899SN/A
467553SN/ARubyDirectedTester::~RubyDirectedTester()
476899SN/A{
487053SN/A    for (int i = 0; i < ports.size(); i++)
497053SN/A        delete ports[i];
506899SN/A}
516899SN/A
527053SN/Avoid
537553SN/ARubyDirectedTester::init()
546899SN/A{
557053SN/A    assert(ports.size() > 0);
567553SN/A    generator->setDirectedTester(this);
576899SN/A}
586899SN/A
596899SN/APort *
607553SN/ARubyDirectedTester::getPort(const std::string &if_name, int idx)
616899SN/A{
626899SN/A    if (if_name != "cpuPort") {
637553SN/A        panic("RubyDirectedTester::getPort: unknown port %s requested", if_name);
646899SN/A    }
656899SN/A
666899SN/A    if (idx >= (int)ports.size()) {
676899SN/A        ports.resize(idx + 1);
686899SN/A    }
696899SN/A
706899SN/A    if (ports[idx] != NULL) {
717553SN/A        panic("RubyDirectedTester::getPort: port %d already assigned", idx);
726899SN/A    }
736899SN/A
746899SN/A    CpuPort *port = new CpuPort(csprintf("%s-port%d", name(), idx), this, idx);
756899SN/A
766899SN/A    ports[idx] = port;
776899SN/A    return port;
786899SN/A}
796899SN/A
806899SN/ATick
817553SN/ARubyDirectedTester::CpuPort::recvAtomic(PacketPtr pkt)
826899SN/A{
837553SN/A    panic("RubyDirectedTester::CpuPort::recvAtomic() not implemented!\n");
847053SN/A    return 0;
856899SN/A}
866899SN/A
876899SN/Abool
887553SN/ARubyDirectedTester::CpuPort::recvTiming(PacketPtr pkt)
896899SN/A{
907553SN/A    tester->hitCallback(idx, pkt->getAddr());
917553SN/A
927553SN/A    //
937553SN/A    // Now that the tester has completed, delete the packet, then return
947553SN/A    //
957053SN/A    delete pkt->req;
967053SN/A    delete pkt;
977053SN/A    return true;
986899SN/A}
996899SN/A
1007053SN/APort*
1017553SN/ARubyDirectedTester::getCpuPort(int idx)
1026899SN/A{
1037053SN/A    assert(idx >= 0 && idx < ports.size());
1046899SN/A
1057053SN/A    return ports[idx];
1066899SN/A}
1076899SN/A
1087053SN/Avoid
1097553SN/ARubyDirectedTester::hitCallback(NodeID proc, Addr addr)
1106899SN/A{
1117553SN/A    DPRINTF(DirectedTest,
1127553SN/A            "completed request for proc: %d addr: 0x%x\n",
1137553SN/A            proc,
1147553SN/A            addr);
1156899SN/A
1167553SN/A    generator->performCallback(proc, addr);
1177553SN/A    schedule(directedStartEvent, curTick);
1186899SN/A}
1196899SN/A
1207053SN/Avoid
1217553SN/ARubyDirectedTester::wakeup()
1227053SN/A{
1237553SN/A    if (m_requests_completed < m_requests_to_complete) {
1247553SN/A        if (!generator->initiate()) {
1257553SN/A            schedule(directedStartEvent, curTick + 1);
1267553SN/A        }
1277053SN/A    } else {
1287553SN/A        exitSimLoop("Ruby DirectedTester completed");
1297053SN/A    }
1306899SN/A}
1316899SN/A
1327553SN/ARubyDirectedTester *
1337553SN/ARubyDirectedTesterParams::create()
1346899SN/A{
1357553SN/A    return new RubyDirectedTester(this);
1366899SN/A}
137