RubyDirectedTester.cc revision 11800
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)
507553SN/A  : MemObject(p), directedStartEvent(this),
517553SN/A    m_requests_to_complete(p->requests_to_complete),
527553SN/A    generator(p->generator)
536899SN/A{
547553SN/A    m_requests_completed = 0;
556899SN/A
568851Sandreas.hansson@arm.com    // create the ports
578851Sandreas.hansson@arm.com    for (int i = 0; i < p->port_cpuPort_connection_count; ++i) {
588851Sandreas.hansson@arm.com        ports.push_back(new CpuPort(csprintf("%s-port%d", name(), i),
598851Sandreas.hansson@arm.com                                    this, i));
608851Sandreas.hansson@arm.com    }
618851Sandreas.hansson@arm.com
627053SN/A    // add the check start event to the event queue
637553SN/A    schedule(directedStartEvent, 1);
646899SN/A}
656899SN/A
667553SN/ARubyDirectedTester::~RubyDirectedTester()
676899SN/A{
687053SN/A    for (int i = 0; i < ports.size(); i++)
697053SN/A        delete ports[i];
706899SN/A}
716899SN/A
727053SN/Avoid
737553SN/ARubyDirectedTester::init()
746899SN/A{
757053SN/A    assert(ports.size() > 0);
767553SN/A    generator->setDirectedTester(this);
776899SN/A}
786899SN/A
799294Sandreas.hansson@arm.comBaseMasterPort &
809294Sandreas.hansson@arm.comRubyDirectedTester::getMasterPort(const std::string &if_name, PortID idx)
816899SN/A{
826899SN/A    if (if_name != "cpuPort") {
838922Swilliam.wang@arm.com        // pass it along to our super class
848922Swilliam.wang@arm.com        return MemObject::getMasterPort(if_name, idx);
858922Swilliam.wang@arm.com    } else {
868922Swilliam.wang@arm.com        if (idx >= static_cast<int>(ports.size())) {
878922Swilliam.wang@arm.com            panic("RubyDirectedTester::getMasterPort: unknown index %d\n", idx);
888922Swilliam.wang@arm.com        }
898922Swilliam.wang@arm.com
908922Swilliam.wang@arm.com        return *ports[idx];
916899SN/A    }
926899SN/A}
936899SN/A
946899SN/Abool
958975Sandreas.hansson@arm.comRubyDirectedTester::CpuPort::recvTimingResp(PacketPtr pkt)
966899SN/A{
978965Sandreas.hansson@arm.com    tester->hitCallback(id, pkt->getAddr());
9811320Ssteve.reinhardt@amd.com
997553SN/A    //
1007553SN/A    // Now that the tester has completed, delete the packet, then return
1017553SN/A    //
1027053SN/A    delete pkt->req;
1037053SN/A    delete pkt;
1047053SN/A    return true;
1056899SN/A}
1066899SN/A
1078922Swilliam.wang@arm.comMasterPort*
1087553SN/ARubyDirectedTester::getCpuPort(int idx)
1096899SN/A{
1107053SN/A    assert(idx >= 0 && idx < ports.size());
1116899SN/A
1127053SN/A    return ports[idx];
1136899SN/A}
1146899SN/A
1157053SN/Avoid
1167553SN/ARubyDirectedTester::hitCallback(NodeID proc, Addr addr)
1176899SN/A{
1187553SN/A    DPRINTF(DirectedTest,
1197553SN/A            "completed request for proc: %d addr: 0x%x\n",
1207553SN/A            proc,
1217553SN/A            addr);
1226899SN/A
12311320Ssteve.reinhardt@amd.com    generator->performCallback(proc, addr);
1247823Ssteve.reinhardt@amd.com    schedule(directedStartEvent, curTick());
1256899SN/A}
1266899SN/A
1277053SN/Avoid
1287553SN/ARubyDirectedTester::wakeup()
1297053SN/A{
1307553SN/A    if (m_requests_completed < m_requests_to_complete) {
1317553SN/A        if (!generator->initiate()) {
1327823Ssteve.reinhardt@amd.com            schedule(directedStartEvent, curTick() + 1);
1337553SN/A        }
1347053SN/A    } else {
1357553SN/A        exitSimLoop("Ruby DirectedTester completed");
1367053SN/A    }
1376899SN/A}
1386899SN/A
1397553SN/ARubyDirectedTester *
1407553SN/ARubyDirectedTesterParams::create()
1416899SN/A{
1427553SN/A    return new RubyDirectedTester(this);
1436899SN/A}
144