RubyDirectedTester.cc revision 8851
16899SN/A/*
28851Sandreas.hansson@arm.com * Copyright (c) 2012 ARM Limited
38851Sandreas.hansson@arm.com * All rights reserved
48851Sandreas.hansson@arm.com *
58851Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
68851Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
78851Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
88851Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
98851Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
108851Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
118851Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
128851Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
138851Sandreas.hansson@arm.com *
146899SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
157553SN/A * Copyright (c) 2009-2010 Advanced Micro Devices, Inc.
166899SN/A * All rights reserved.
176899SN/A *
186899SN/A * Redistribution and use in source and binary forms, with or without
196899SN/A * modification, are permitted provided that the following conditions are
206899SN/A * met: redistributions of source code must retain the above copyright
216899SN/A * notice, this list of conditions and the following disclaimer;
226899SN/A * redistributions in binary form must reproduce the above copyright
236899SN/A * notice, this list of conditions and the following disclaimer in the
246899SN/A * documentation and/or other materials provided with the distribution;
256899SN/A * neither the name of the copyright holders nor the names of its
266899SN/A * contributors may be used to endorse or promote products derived from
276899SN/A * this software without specific prior written permission.
286899SN/A *
296899SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
306899SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
316899SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
326899SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
336899SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
346899SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
356899SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
366899SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
376899SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
386899SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
396899SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
406899SN/A */
416899SN/A
427632SBrad.Beckmann@amd.com#include "cpu/testers/directedtest/DirectedGenerator.hh"
437632SBrad.Beckmann@amd.com#include "cpu/testers/directedtest/RubyDirectedTester.hh"
448232Snate@binkert.org#include "debug/DirectedTest.hh"
457053SN/A#include "mem/ruby/eventqueue/RubyEventQueue.hh"
466899SN/A#include "sim/sim_exit.hh"
476899SN/A
487553SN/ARubyDirectedTester::RubyDirectedTester(const Params *p)
497553SN/A  : MemObject(p), directedStartEvent(this),
507553SN/A    m_requests_to_complete(p->requests_to_complete),
517553SN/A    generator(p->generator)
526899SN/A{
537553SN/A    m_requests_completed = 0;
546899SN/A
558851Sandreas.hansson@arm.com    // create the ports
568851Sandreas.hansson@arm.com    for (int i = 0; i < p->port_cpuPort_connection_count; ++i) {
578851Sandreas.hansson@arm.com        ports.push_back(new CpuPort(csprintf("%s-port%d", name(), i),
588851Sandreas.hansson@arm.com                                    this, i));
598851Sandreas.hansson@arm.com    }
608851Sandreas.hansson@arm.com
617053SN/A    // add the check start event to the event queue
627553SN/A    schedule(directedStartEvent, 1);
636899SN/A}
646899SN/A
657553SN/ARubyDirectedTester::~RubyDirectedTester()
666899SN/A{
677053SN/A    for (int i = 0; i < ports.size(); i++)
687053SN/A        delete ports[i];
696899SN/A}
706899SN/A
717053SN/Avoid
727553SN/ARubyDirectedTester::init()
736899SN/A{
747053SN/A    assert(ports.size() > 0);
757553SN/A    generator->setDirectedTester(this);
766899SN/A}
776899SN/A
786899SN/APort *
797553SN/ARubyDirectedTester::getPort(const std::string &if_name, int idx)
806899SN/A{
816899SN/A    if (if_name != "cpuPort") {
828851Sandreas.hansson@arm.com        panic("RubyDirectedTester::getPort: unknown port %s requested",
838851Sandreas.hansson@arm.com              if_name);
846899SN/A    }
856899SN/A
868851Sandreas.hansson@arm.com    if (idx >= static_cast<int>(ports.size())) {
878851Sandreas.hansson@arm.com        panic("RubyDirectedTester::getPort: unknown index %d requested\n", idx);
886899SN/A    }
896899SN/A
908851Sandreas.hansson@arm.com    return ports[idx];
916899SN/A}
926899SN/A
936899SN/ATick
947553SN/ARubyDirectedTester::CpuPort::recvAtomic(PacketPtr pkt)
956899SN/A{
967553SN/A    panic("RubyDirectedTester::CpuPort::recvAtomic() not implemented!\n");
977053SN/A    return 0;
986899SN/A}
996899SN/A
1006899SN/Abool
1017553SN/ARubyDirectedTester::CpuPort::recvTiming(PacketPtr pkt)
1026899SN/A{
1037553SN/A    tester->hitCallback(idx, pkt->getAddr());
1047553SN/A
1057553SN/A    //
1067553SN/A    // Now that the tester has completed, delete the packet, then return
1077553SN/A    //
1087053SN/A    delete pkt->req;
1097053SN/A    delete pkt;
1107053SN/A    return true;
1116899SN/A}
1126899SN/A
1137053SN/APort*
1147553SN/ARubyDirectedTester::getCpuPort(int idx)
1156899SN/A{
1167053SN/A    assert(idx >= 0 && idx < ports.size());
1176899SN/A
1187053SN/A    return ports[idx];
1196899SN/A}
1206899SN/A
1217053SN/Avoid
1227553SN/ARubyDirectedTester::hitCallback(NodeID proc, Addr addr)
1236899SN/A{
1247553SN/A    DPRINTF(DirectedTest,
1257553SN/A            "completed request for proc: %d addr: 0x%x\n",
1267553SN/A            proc,
1277553SN/A            addr);
1286899SN/A
1297553SN/A    generator->performCallback(proc, addr);
1307823Ssteve.reinhardt@amd.com    schedule(directedStartEvent, curTick());
1316899SN/A}
1326899SN/A
1337053SN/Avoid
1347553SN/ARubyDirectedTester::wakeup()
1357053SN/A{
1367553SN/A    if (m_requests_completed < m_requests_to_complete) {
1377553SN/A        if (!generator->initiate()) {
1387823Ssteve.reinhardt@amd.com            schedule(directedStartEvent, curTick() + 1);
1397553SN/A        }
1407053SN/A    } else {
1417553SN/A        exitSimLoop("Ruby DirectedTester completed");
1427053SN/A    }
1436899SN/A}
1446899SN/A
1457553SN/ARubyDirectedTester *
1467553SN/ARubyDirectedTesterParams::create()
1476899SN/A{
1487553SN/A    return new RubyDirectedTester(this);
1496899SN/A}
150