RubyDirectedTester.cc revision 11320
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"
456899SN/A#include "sim/sim_exit.hh"
466899SN/A
477553SN/ARubyDirectedTester::RubyDirectedTester(const Params *p)
487553SN/A  : MemObject(p), directedStartEvent(this),
497553SN/A    m_requests_to_complete(p->requests_to_complete),
507553SN/A    generator(p->generator)
516899SN/A{
527553SN/A    m_requests_completed = 0;
536899SN/A
548851Sandreas.hansson@arm.com    // create the ports
558851Sandreas.hansson@arm.com    for (int i = 0; i < p->port_cpuPort_connection_count; ++i) {
568851Sandreas.hansson@arm.com        ports.push_back(new CpuPort(csprintf("%s-port%d", name(), i),
578851Sandreas.hansson@arm.com                                    this, i));
588851Sandreas.hansson@arm.com    }
598851Sandreas.hansson@arm.com
607053SN/A    // add the check start event to the event queue
617553SN/A    schedule(directedStartEvent, 1);
626899SN/A}
636899SN/A
647553SN/ARubyDirectedTester::~RubyDirectedTester()
656899SN/A{
667053SN/A    for (int i = 0; i < ports.size(); i++)
677053SN/A        delete ports[i];
686899SN/A}
696899SN/A
707053SN/Avoid
717553SN/ARubyDirectedTester::init()
726899SN/A{
737053SN/A    assert(ports.size() > 0);
747553SN/A    generator->setDirectedTester(this);
756899SN/A}
766899SN/A
779294Sandreas.hansson@arm.comBaseMasterPort &
789294Sandreas.hansson@arm.comRubyDirectedTester::getMasterPort(const std::string &if_name, PortID idx)
796899SN/A{
806899SN/A    if (if_name != "cpuPort") {
818922Swilliam.wang@arm.com        // pass it along to our super class
828922Swilliam.wang@arm.com        return MemObject::getMasterPort(if_name, idx);
838922Swilliam.wang@arm.com    } else {
848922Swilliam.wang@arm.com        if (idx >= static_cast<int>(ports.size())) {
858922Swilliam.wang@arm.com            panic("RubyDirectedTester::getMasterPort: unknown index %d\n", idx);
868922Swilliam.wang@arm.com        }
878922Swilliam.wang@arm.com
888922Swilliam.wang@arm.com        return *ports[idx];
896899SN/A    }
906899SN/A}
916899SN/A
926899SN/Abool
938975Sandreas.hansson@arm.comRubyDirectedTester::CpuPort::recvTimingResp(PacketPtr pkt)
946899SN/A{
958965Sandreas.hansson@arm.com    tester->hitCallback(id, pkt->getAddr());
9611320Ssteve.reinhardt@amd.com
977553SN/A    //
987553SN/A    // Now that the tester has completed, delete the packet, then return
997553SN/A    //
1007053SN/A    delete pkt->req;
1017053SN/A    delete pkt;
1027053SN/A    return true;
1036899SN/A}
1046899SN/A
1058922Swilliam.wang@arm.comMasterPort*
1067553SN/ARubyDirectedTester::getCpuPort(int idx)
1076899SN/A{
1087053SN/A    assert(idx >= 0 && idx < ports.size());
1096899SN/A
1107053SN/A    return ports[idx];
1116899SN/A}
1126899SN/A
1137053SN/Avoid
1147553SN/ARubyDirectedTester::hitCallback(NodeID proc, Addr addr)
1156899SN/A{
1167553SN/A    DPRINTF(DirectedTest,
1177553SN/A            "completed request for proc: %d addr: 0x%x\n",
1187553SN/A            proc,
1197553SN/A            addr);
1206899SN/A
12111320Ssteve.reinhardt@amd.com    generator->performCallback(proc, addr);
1227823Ssteve.reinhardt@amd.com    schedule(directedStartEvent, curTick());
1236899SN/A}
1246899SN/A
1257053SN/Avoid
1267553SN/ARubyDirectedTester::wakeup()
1277053SN/A{
1287553SN/A    if (m_requests_completed < m_requests_to_complete) {
1297553SN/A        if (!generator->initiate()) {
1307823Ssteve.reinhardt@amd.com            schedule(directedStartEvent, curTick() + 1);
1317553SN/A        }
1327053SN/A    } else {
1337553SN/A        exitSimLoop("Ruby DirectedTester completed");
1347053SN/A    }
1356899SN/A}
1366899SN/A
1377553SN/ARubyDirectedTester *
1387553SN/ARubyDirectedTesterParams::create()
1396899SN/A{
1407553SN/A    return new RubyDirectedTester(this);
1416899SN/A}
142