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
4211793Sbrandon.potter@amd.com#include "cpu/testers/directedtest/RubyDirectedTester.hh"
4311793Sbrandon.potter@amd.com
4411800Sbrandon.potter@amd.com#include "base/trace.hh"
457632SBrad.Beckmann@amd.com#include "cpu/testers/directedtest/DirectedGenerator.hh"
468232Snate@binkert.org#include "debug/DirectedTest.hh"
476899SN/A#include "sim/sim_exit.hh"
486899SN/A
497553SN/ARubyDirectedTester::RubyDirectedTester(const Params *p)
5013892Sgabeblack@google.com  : ClockedObject(p),
5112129Sspwilson2@wisc.edu    directedStartEvent([this]{ wakeup(); }, "Directed tick",
5212129Sspwilson2@wisc.edu                       false, Event::CPU_Tick_Pri),
537553SN/A    m_requests_to_complete(p->requests_to_complete),
547553SN/A    generator(p->generator)
556899SN/A{
567553SN/A    m_requests_completed = 0;
576899SN/A
588851Sandreas.hansson@arm.com    // create the ports
598851Sandreas.hansson@arm.com    for (int i = 0; i < p->port_cpuPort_connection_count; ++i) {
608851Sandreas.hansson@arm.com        ports.push_back(new CpuPort(csprintf("%s-port%d", name(), i),
618851Sandreas.hansson@arm.com                                    this, i));
628851Sandreas.hansson@arm.com    }
638851Sandreas.hansson@arm.com
647053SN/A    // add the check start event to the event queue
657553SN/A    schedule(directedStartEvent, 1);
666899SN/A}
676899SN/A
687553SN/ARubyDirectedTester::~RubyDirectedTester()
696899SN/A{
707053SN/A    for (int i = 0; i < ports.size(); i++)
717053SN/A        delete ports[i];
726899SN/A}
736899SN/A
747053SN/Avoid
757553SN/ARubyDirectedTester::init()
766899SN/A{
777053SN/A    assert(ports.size() > 0);
787553SN/A    generator->setDirectedTester(this);
796899SN/A}
806899SN/A
8113784Sgabeblack@google.comPort &
8213784Sgabeblack@google.comRubyDirectedTester::getPort(const std::string &if_name, PortID idx)
836899SN/A{
846899SN/A    if (if_name != "cpuPort") {
858922Swilliam.wang@arm.com        // pass it along to our super class
8613892Sgabeblack@google.com        return ClockedObject::getPort(if_name, idx);
878922Swilliam.wang@arm.com    } else {
888922Swilliam.wang@arm.com        if (idx >= static_cast<int>(ports.size())) {
8913784Sgabeblack@google.com            panic("RubyDirectedTester::getPort: unknown index %d\n", idx);
908922Swilliam.wang@arm.com        }
918922Swilliam.wang@arm.com
928922Swilliam.wang@arm.com        return *ports[idx];
936899SN/A    }
946899SN/A}
956899SN/A
966899SN/Abool
978975Sandreas.hansson@arm.comRubyDirectedTester::CpuPort::recvTimingResp(PacketPtr pkt)
986899SN/A{
998965Sandreas.hansson@arm.com    tester->hitCallback(id, pkt->getAddr());
10011320Ssteve.reinhardt@amd.com
1017553SN/A    //
1027553SN/A    // Now that the tester has completed, delete the packet, then return
1037553SN/A    //
1047053SN/A    delete pkt;
1057053SN/A    return true;
1066899SN/A}
1076899SN/A
1088922Swilliam.wang@arm.comMasterPort*
1097553SN/ARubyDirectedTester::getCpuPort(int idx)
1106899SN/A{
1117053SN/A    assert(idx >= 0 && idx < ports.size());
1126899SN/A
1137053SN/A    return ports[idx];
1146899SN/A}
1156899SN/A
1167053SN/Avoid
1177553SN/ARubyDirectedTester::hitCallback(NodeID proc, Addr addr)
1186899SN/A{
1197553SN/A    DPRINTF(DirectedTest,
1207553SN/A            "completed request for proc: %d addr: 0x%x\n",
1217553SN/A            proc,
1227553SN/A            addr);
1236899SN/A
12411320Ssteve.reinhardt@amd.com    generator->performCallback(proc, addr);
1257823Ssteve.reinhardt@amd.com    schedule(directedStartEvent, curTick());
1266899SN/A}
1276899SN/A
1287053SN/Avoid
1297553SN/ARubyDirectedTester::wakeup()
1307053SN/A{
1317553SN/A    if (m_requests_completed < m_requests_to_complete) {
1327553SN/A        if (!generator->initiate()) {
1337823Ssteve.reinhardt@amd.com            schedule(directedStartEvent, curTick() + 1);
1347553SN/A        }
1357053SN/A    } else {
1367553SN/A        exitSimLoop("Ruby DirectedTester completed");
1377053SN/A    }
1386899SN/A}
1396899SN/A
1407553SN/ARubyDirectedTester *
1417553SN/ARubyDirectedTesterParams::create()
1426899SN/A{
1437553SN/A    return new RubyDirectedTester(this);
1446899SN/A}
145