InvalidateGenerator.cc revision 7632
16145SN/A/*
26386SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
37553SN/A * Copyright (c) 2009-2010 Advanced Micro Devices, Inc.
46386SN/A * All rights reserved.
56386SN/A *
66386SN/A * Redistribution and use in source and binary forms, with or without
76386SN/A * modification, are permitted provided that the following conditions are
86386SN/A * met: redistributions of source code must retain the above copyright
96386SN/A * notice, this list of conditions and the following disclaimer;
106386SN/A * redistributions in binary form must reproduce the above copyright
116386SN/A * notice, this list of conditions and the following disclaimer in the
126386SN/A * documentation and/or other materials provided with the distribution;
136386SN/A * neither the name of the copyright holders nor the names of its
146386SN/A * contributors may be used to endorse or promote products derived from
156386SN/A * this software without specific prior written permission.
166386SN/A *
176386SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186386SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196386SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206386SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216386SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226386SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236386SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246386SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256386SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266386SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276386SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286386SN/A */
296145SN/A
307632SBrad.Beckmann@amd.com#include "cpu/testers/directedtest/RubyDirectedTester.hh"
317632SBrad.Beckmann@amd.com#include "cpu/testers/directedtest/DirectedGenerator.hh"
327632SBrad.Beckmann@amd.com#include "cpu/testers/directedtest/InvalidateGenerator.hh"
336145SN/A
347553SN/AInvalidateGenerator::InvalidateGenerator(const Params *p)
357553SN/A    : DirectedGenerator(p)
366145SN/A{
377553SN/A    //
387553SN/A    // First, issue loads to bring the block into S state
397553SN/A    //
407553SN/A    m_status = InvalidateGeneratorStatus_Load_Waiting;
417553SN/A    m_active_read_node = 0;
427553SN/A    m_active_inv_node = 0;
437553SN/A    m_address = 0x0;
447553SN/A    m_addr_increment_size = p->addr_increment_size;
456145SN/A}
466145SN/A
477553SN/AInvalidateGenerator::~InvalidateGenerator()
486145SN/A{
496145SN/A}
506145SN/A
517553SN/Abool
527553SN/AInvalidateGenerator::initiate()
536145SN/A{
547553SN/A    RubyDirectedTester::CpuPort* port;
557553SN/A    Request::Flags flags;
567553SN/A    PacketPtr pkt;
577553SN/A    Packet::Command cmd;
586145SN/A
597553SN/A    // For simplicity, requests are assumed to be 1 byte-sized
607553SN/A    Request *req = new Request(m_address, 1, flags);
617553SN/A
627553SN/A    //
637553SN/A    // Based on the current state, issue a load or a store
647553SN/A    //
657553SN/A    if (m_status == InvalidateGeneratorStatus_Load_Waiting) {
667553SN/A        DPRINTF(DirectedTest, "initiating read\n");
677553SN/A        cmd = MemCmd::ReadReq;
687553SN/A        port = safe_cast<RubyDirectedTester::CpuPort*>(m_directed_tester->
697553SN/A                                               getCpuPort(m_active_read_node));
707553SN/A        pkt = new Packet(req, cmd, m_active_read_node);
717553SN/A    } else if (m_status == InvalidateGeneratorStatus_Inv_Waiting) {
727553SN/A        DPRINTF(DirectedTest, "initiating invalidating write\n");
737553SN/A        cmd = MemCmd::WriteReq;
747553SN/A        port = safe_cast<RubyDirectedTester::CpuPort*>(m_directed_tester->
757553SN/A                                               getCpuPort(m_active_inv_node));
767553SN/A        pkt = new Packet(req, cmd, m_active_inv_node);
777553SN/A    } else {
787553SN/A        panic("initiate was unexpectedly called\n");
796145SN/A    }
807553SN/A    uint8_t* dummyData = new uint8_t;
817553SN/A    *dummyData = 0;
827553SN/A    pkt->dataDynamic(dummyData);
836145SN/A
847553SN/A    if (port->sendTiming(pkt)) {
857553SN/A        DPRINTF(DirectedTest, "initiating request - successful\n");
867553SN/A        if (m_status == InvalidateGeneratorStatus_Load_Waiting) {
877553SN/A            m_status = InvalidateGeneratorStatus_Load_Pending;
887553SN/A        } else {
897553SN/A            m_status = InvalidateGeneratorStatus_Inv_Pending;
907553SN/A        }
917553SN/A        return true;
927553SN/A    } else {
937553SN/A        // If the packet did not issue, must delete
947553SN/A        // Note: No need to delete the data, the packet destructor
957553SN/A        // will delete it
967553SN/A        delete pkt->req;
977553SN/A        delete pkt;
987553SN/A
997553SN/A        DPRINTF(DirectedTest, "failed to issue request - sequencer not ready\n");
1007553SN/A        return false;
1017553SN/A    }
1026145SN/A}
1036145SN/A
1047553SN/Avoid
1057553SN/AInvalidateGenerator::performCallback(uint proc, Addr address)
1066145SN/A{
1077553SN/A    assert(m_address == address);
1086145SN/A
1097553SN/A    if (m_status == InvalidateGeneratorStatus_Load_Pending) {
1107553SN/A        assert(m_active_read_node == proc);
1117553SN/A        m_active_read_node++;
1127553SN/A        //
1137553SN/A        // Once all cpus have the block in S state, issue the invalidate
1147553SN/A        //
1157553SN/A        if (m_active_read_node == m_num_cpus) {
1167553SN/A            m_status = InvalidateGeneratorStatus_Inv_Waiting;
1177553SN/A            m_active_read_node = 0;
1187553SN/A        } else {
1197553SN/A            m_status = InvalidateGeneratorStatus_Load_Waiting;
1207553SN/A        }
1217553SN/A    } else if (m_status == InvalidateGeneratorStatus_Inv_Pending) {
1227553SN/A        assert(m_active_inv_node == proc);
1237553SN/A        m_active_inv_node++;
1247553SN/A        if (m_active_inv_node == m_num_cpus) {
1257553SN/A            m_address += m_addr_increment_size;
1267553SN/A            m_active_inv_node = 0;
1277553SN/A        }
1287553SN/A        //
1297553SN/A        // Invalidate completed, send that info to the tester and restart
1307553SN/A        // the cycle
1317553SN/A        //
1327553SN/A        m_directed_tester->incrementCycleCompletions();
1337553SN/A        m_status = InvalidateGeneratorStatus_Load_Waiting;
1346357SN/A    }
1357553SN/A
1366145SN/A}
1376145SN/A
1387553SN/AInvalidateGenerator *
1397553SN/AInvalidateGeneratorParams::create()
1406145SN/A{
1417553SN/A    return new InvalidateGenerator(this);
1426145SN/A}
143