12568SN/A/*
213732Snikos.nikoleris@arm.com * Copyright (c) 2011-2019 ARM Limited
38668Sgeoffrey.blake@arm.com * All rights reserved
48668Sgeoffrey.blake@arm.com *
58668Sgeoffrey.blake@arm.com * The license below extends only to copyright in the software and shall
68668Sgeoffrey.blake@arm.com * not be construed as granting a license to any other intellectual
78668Sgeoffrey.blake@arm.com * property including but not limited to intellectual property relating
88668Sgeoffrey.blake@arm.com * to a hardware implementation of the functionality of the software
98668Sgeoffrey.blake@arm.com * licensed hereunder.  You may use the software subject to the license
108668Sgeoffrey.blake@arm.com * terms below provided that you ensure that this notice is replicated
118668Sgeoffrey.blake@arm.com * unmodified and in its entirety in all distributions of the software,
128668Sgeoffrey.blake@arm.com * modified or unmodified, in source code or in binary form.
138668Sgeoffrey.blake@arm.com *
142568SN/A * Copyright (c) 2006 The Regents of The University of Michigan
1510975Sdavid.hashe@amd.com * Copyright (c) 2010,2015 Advanced Micro Devices, Inc.
162568SN/A * All rights reserved.
172568SN/A *
182568SN/A * Redistribution and use in source and binary forms, with or without
192568SN/A * modification, are permitted provided that the following conditions are
202568SN/A * met: redistributions of source code must retain the above copyright
212568SN/A * notice, this list of conditions and the following disclaimer;
222568SN/A * redistributions in binary form must reproduce the above copyright
232568SN/A * notice, this list of conditions and the following disclaimer in the
242568SN/A * documentation and/or other materials provided with the distribution;
252568SN/A * neither the name of the copyright holders nor the names of its
262568SN/A * contributors may be used to endorse or promote products derived from
272568SN/A * this software without specific prior written permission.
282568SN/A *
292568SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
302568SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
312568SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
322568SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
332568SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
342568SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
352568SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
362568SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
372568SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
382568SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
392568SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
402665Ssaidi@eecs.umich.edu *
412665Ssaidi@eecs.umich.edu * Authors: Ali Saidi
422665Ssaidi@eecs.umich.edu *          Steve Reinhardt
432568SN/A */
442568SN/A
452568SN/A/**
462568SN/A * @file
472568SN/A * Definition of the Packet Class, a packet is a transaction occuring
482568SN/A * between a single level of the memory heirarchy (ie L1->L2).
492568SN/A */
503260Ssaidi@eecs.umich.edu
5111793Sbrandon.potter@amd.com#include "mem/packet.hh"
5211793Sbrandon.potter@amd.com
5312821Srmk35@cl.cam.ac.uk#include <algorithm>
548229Snate@binkert.org#include <cstring>
553260Ssaidi@eecs.umich.edu#include <iostream>
5612822Srmk35@cl.cam.ac.uk#include <sstream>
5712822Srmk35@cl.cam.ac.uk#include <string>
588229Snate@binkert.org
595314Sstever@gmail.com#include "base/cprintf.hh"
6012334Sgabeblack@google.com#include "base/logging.hh"
613348Sbinkertn@umich.edu#include "base/trace.hh"
6212652Sandreas.sandberg@arm.com#include "mem/packet_access.hh"
632568SN/A
644022Sstever@eecs.umich.edu// The one downside to bitsets is that static initializers can get ugly.
654022Sstever@eecs.umich.edu#define SET1(a1)                     (1 << (a1))
664022Sstever@eecs.umich.edu#define SET2(a1, a2)                 (SET1(a1) | SET1(a2))
674022Sstever@eecs.umich.edu#define SET3(a1, a2, a3)             (SET2(a1, a2) | SET1(a3))
684022Sstever@eecs.umich.edu#define SET4(a1, a2, a3, a4)         (SET3(a1, a2, a3) | SET1(a4))
694022Sstever@eecs.umich.edu#define SET5(a1, a2, a3, a4, a5)     (SET4(a1, a2, a3, a4) | SET1(a5))
704022Sstever@eecs.umich.edu#define SET6(a1, a2, a3, a4, a5, a6) (SET5(a1, a2, a3, a4, a5) | SET1(a6))
7111600Sandreas.hansson@arm.com#define SET7(a1, a2, a3, a4, a5, a6, a7) (SET6(a1, a2, a3, a4, a5, a6) | \
7211600Sandreas.hansson@arm.com                                          SET1(a7))
732641Sstever@eecs.umich.edu
744022Sstever@eecs.umich.educonst MemCmd::CommandInfo
754022Sstever@eecs.umich.eduMemCmd::commandInfo[] =
762641Sstever@eecs.umich.edu{
774022Sstever@eecs.umich.edu    /* InvalidCmd */
784022Sstever@eecs.umich.edu    { 0, InvalidCmd, "InvalidCmd" },
7910885Sandreas.hansson@arm.com    /* ReadReq - Read issued by a non-caching agent such as a CPU or
8010885Sandreas.hansson@arm.com     * device, with no restrictions on alignment. */
814022Sstever@eecs.umich.edu    { SET3(IsRead, IsRequest, NeedsResponse), ReadResp, "ReadReq" },
824473Sstever@eecs.umich.edu    /* ReadResp */
834473Sstever@eecs.umich.edu    { SET3(IsRead, IsResponse, HasData), InvalidCmd, "ReadResp" },
845319Sstever@gmail.com    /* ReadRespWithInvalidate */
855319Sstever@gmail.com    { SET4(IsRead, IsResponse, HasData, IsInvalidate),
865319Sstever@gmail.com            InvalidCmd, "ReadRespWithInvalidate" },
874022Sstever@eecs.umich.edu    /* WriteReq */
8811284Sandreas.hansson@arm.com    { SET5(IsWrite, NeedsWritable, IsRequest, NeedsResponse, HasData),
894022Sstever@eecs.umich.edu            WriteResp, "WriteReq" },
904022Sstever@eecs.umich.edu    /* WriteResp */
9111287Sandreas.hansson@arm.com    { SET2(IsWrite, IsResponse), InvalidCmd, "WriteResp" },
9211199Sandreas.hansson@arm.com    /* WritebackDirty */
9311600Sandreas.hansson@arm.com    { SET5(IsWrite, IsRequest, IsEviction, HasData, FromCache),
9411199Sandreas.hansson@arm.com            InvalidCmd, "WritebackDirty" },
9511199Sandreas.hansson@arm.com    /* WritebackClean - This allows the upstream cache to writeback a
9611199Sandreas.hansson@arm.com     * line to the downstream cache without it being considered
9711199Sandreas.hansson@arm.com     * dirty. */
9811600Sandreas.hansson@arm.com    { SET5(IsWrite, IsRequest, IsEviction, HasData, FromCache),
9911199Sandreas.hansson@arm.com            InvalidCmd, "WritebackClean" },
10012344Snikos.nikoleris@arm.com    /* WriteClean - This allows a cache to write a dirty block to a memory
10112344Snikos.nikoleris@arm.com       below without evicting its copy. */
10212344Snikos.nikoleris@arm.com    { SET4(IsWrite, IsRequest, HasData, FromCache), InvalidCmd, "WriteClean" },
10310883Sali.jafri@arm.com    /* CleanEvict */
10411600Sandreas.hansson@arm.com    { SET3(IsRequest, IsEviction, FromCache), InvalidCmd, "CleanEvict" },
1054022Sstever@eecs.umich.edu    /* SoftPFReq */
1064022Sstever@eecs.umich.edu    { SET4(IsRead, IsRequest, IsSWPrefetch, NeedsResponse),
1074022Sstever@eecs.umich.edu            SoftPFResp, "SoftPFReq" },
10813367Syuetsu.kodama@riken.jp    /* SoftPFExReq */
10913367Syuetsu.kodama@riken.jp    { SET6(IsRead, NeedsWritable, IsInvalidate, IsRequest,
11013367Syuetsu.kodama@riken.jp           IsSWPrefetch, NeedsResponse), SoftPFResp, "SoftPFExReq" },
1114022Sstever@eecs.umich.edu    /* HardPFReq */
11211600Sandreas.hansson@arm.com    { SET5(IsRead, IsRequest, IsHWPrefetch, NeedsResponse, FromCache),
1134022Sstever@eecs.umich.edu            HardPFResp, "HardPFReq" },
1144022Sstever@eecs.umich.edu    /* SoftPFResp */
1154022Sstever@eecs.umich.edu    { SET4(IsRead, IsResponse, IsSWPrefetch, HasData),
1164022Sstever@eecs.umich.edu            InvalidCmd, "SoftPFResp" },
1174022Sstever@eecs.umich.edu    /* HardPFResp */
1184022Sstever@eecs.umich.edu    { SET4(IsRead, IsResponse, IsHWPrefetch, HasData),
1194022Sstever@eecs.umich.edu            InvalidCmd, "HardPFResp" },
12010886Sandreas.hansson@arm.com    /* WriteLineReq */
12111284Sandreas.hansson@arm.com    { SET5(IsWrite, NeedsWritable, IsRequest, NeedsResponse, HasData),
12210886Sandreas.hansson@arm.com            WriteResp, "WriteLineReq" },
1234022Sstever@eecs.umich.edu    /* UpgradeReq */
12411600Sandreas.hansson@arm.com    { SET6(IsInvalidate, NeedsWritable, IsUpgrade, IsRequest, NeedsResponse,
12511600Sandreas.hansson@arm.com            FromCache),
1264628Sstever@eecs.umich.edu            UpgradeResp, "UpgradeReq" },
1277465Ssteve.reinhardt@amd.com    /* SCUpgradeReq: response could be UpgradeResp or UpgradeFailResp */
12811600Sandreas.hansson@arm.com    { SET7(IsInvalidate, NeedsWritable, IsUpgrade, IsLlsc,
12911600Sandreas.hansson@arm.com           IsRequest, NeedsResponse, FromCache),
1307465Ssteve.reinhardt@amd.com            UpgradeResp, "SCUpgradeReq" },
1314628Sstever@eecs.umich.edu    /* UpgradeResp */
13211287Sandreas.hansson@arm.com    { SET2(IsUpgrade, IsResponse),
1337465Ssteve.reinhardt@amd.com            InvalidCmd, "UpgradeResp" },
13410325Sgeoffrey.blake@arm.com    /* SCUpgradeFailReq: generates UpgradeFailResp but still gets the data */
13511600Sandreas.hansson@arm.com    { SET7(IsRead, NeedsWritable, IsInvalidate,
13611600Sandreas.hansson@arm.com           IsLlsc, IsRequest, NeedsResponse, FromCache),
1377465Ssteve.reinhardt@amd.com            UpgradeFailResp, "SCUpgradeFailReq" },
13810325Sgeoffrey.blake@arm.com    /* UpgradeFailResp - Behaves like a ReadExReq, but notifies an SC
13910325Sgeoffrey.blake@arm.com     * that it has failed, acquires line as Dirty*/
14011287Sandreas.hansson@arm.com    { SET3(IsRead, IsResponse, HasData),
1417465Ssteve.reinhardt@amd.com            InvalidCmd, "UpgradeFailResp" },
14210885Sandreas.hansson@arm.com    /* ReadExReq - Read issues by a cache, always cache-line aligned,
14310885Sandreas.hansson@arm.com     * and the response is guaranteed to be writeable (exclusive or
14410885Sandreas.hansson@arm.com     * even modified) */
14511600Sandreas.hansson@arm.com    { SET6(IsRead, NeedsWritable, IsInvalidate, IsRequest, NeedsResponse,
14611600Sandreas.hansson@arm.com            FromCache),
1474022Sstever@eecs.umich.edu            ReadExResp, "ReadExReq" },
14810885Sandreas.hansson@arm.com    /* ReadExResp - Response matching a read exclusive, as we check
14910885Sandreas.hansson@arm.com     * the need for exclusive also on responses */
15011287Sandreas.hansson@arm.com    { SET3(IsRead, IsResponse, HasData),
1514040Ssaidi@eecs.umich.edu            InvalidCmd, "ReadExResp" },
15210885Sandreas.hansson@arm.com    /* ReadCleanReq - Read issued by a cache, always cache-line
15310885Sandreas.hansson@arm.com     * aligned, and the response is guaranteed to not contain dirty data
15410885Sandreas.hansson@arm.com     * (exclusive or shared).*/
15511600Sandreas.hansson@arm.com    { SET4(IsRead, IsRequest, NeedsResponse, FromCache),
15611600Sandreas.hansson@arm.com            ReadResp, "ReadCleanReq" },
15710885Sandreas.hansson@arm.com    /* ReadSharedReq - Read issued by a cache, always cache-line
15810885Sandreas.hansson@arm.com     * aligned, response is shared, possibly exclusive, owned or even
15910885Sandreas.hansson@arm.com     * modified. */
16011600Sandreas.hansson@arm.com    { SET4(IsRead, IsRequest, NeedsResponse, FromCache),
16111600Sandreas.hansson@arm.com            ReadResp, "ReadSharedReq" },
1625507Sstever@gmail.com    /* LoadLockedReq: note that we use plain ReadResp as response, so that
1635507Sstever@gmail.com     *                we can also use ReadRespWithInvalidate when needed */
1646076Sgblack@eecs.umich.edu    { SET4(IsRead, IsLlsc, IsRequest, NeedsResponse),
1655507Sstever@gmail.com            ReadResp, "LoadLockedReq" },
1664626Sstever@eecs.umich.edu    /* StoreCondReq */
16711284Sandreas.hansson@arm.com    { SET6(IsWrite, NeedsWritable, IsLlsc,
1684626Sstever@eecs.umich.edu           IsRequest, NeedsResponse, HasData),
1694626Sstever@eecs.umich.edu            StoreCondResp, "StoreCondReq" },
17010325Sgeoffrey.blake@arm.com    /* StoreCondFailReq: generates failing StoreCondResp */
17111284Sandreas.hansson@arm.com    { SET6(IsWrite, NeedsWritable, IsLlsc,
1727669Ssteve.reinhardt@amd.com           IsRequest, NeedsResponse, HasData),
1737669Ssteve.reinhardt@amd.com            StoreCondResp, "StoreCondFailReq" },
1744626Sstever@eecs.umich.edu    /* StoreCondResp */
17511287Sandreas.hansson@arm.com    { SET3(IsWrite, IsLlsc, IsResponse),
1764626Sstever@eecs.umich.edu            InvalidCmd, "StoreCondResp" },
1774040Ssaidi@eecs.umich.edu    /* SwapReq -- for Swap ldstub type operations */
17811284Sandreas.hansson@arm.com    { SET6(IsRead, IsWrite, NeedsWritable, IsRequest, HasData, NeedsResponse),
1794040Ssaidi@eecs.umich.edu        SwapResp, "SwapReq" },
1804040Ssaidi@eecs.umich.edu    /* SwapResp -- for Swap ldstub type operations */
18111287Sandreas.hansson@arm.com    { SET4(IsRead, IsWrite, IsResponse, HasData),
1824870Sstever@eecs.umich.edu            InvalidCmd, "SwapResp" },
1835650Sgblack@eecs.umich.edu    /* IntReq -- for interrupts */
1845650Sgblack@eecs.umich.edu    { SET4(IsWrite, IsRequest, NeedsResponse, HasData),
1856063Sgblack@eecs.umich.edu        MessageResp, "MessageReq" },
1865650Sgblack@eecs.umich.edu    /* IntResp -- for interrupts */
1876063Sgblack@eecs.umich.edu    { SET2(IsWrite, IsResponse), InvalidCmd, "MessageResp" },
18811256Santhony.gutierrez@amd.com    /* MemFenceReq -- for synchronization requests */
18911256Santhony.gutierrez@amd.com    {SET2(IsRequest, NeedsResponse), MemFenceResp, "MemFenceReq"},
19011256Santhony.gutierrez@amd.com    /* MemFenceResp -- for synchronization responses */
19111256Santhony.gutierrez@amd.com    {SET1(IsResponse), InvalidCmd, "MemFenceResp"},
19212347Snikos.nikoleris@arm.com    /* Cache Clean Request -- Update with the latest data all existing
19312347Snikos.nikoleris@arm.com       copies of the block down to the point indicated by the
19412347Snikos.nikoleris@arm.com       request */
19512347Snikos.nikoleris@arm.com    { SET4(IsRequest, IsClean, NeedsResponse, FromCache),
19612347Snikos.nikoleris@arm.com      CleanSharedResp, "CleanSharedReq" },
19712347Snikos.nikoleris@arm.com    /* Cache Clean Response - Indicates that all caches up to the
19812347Snikos.nikoleris@arm.com       specified point of reference have a up-to-date copy of the
19912347Snikos.nikoleris@arm.com       cache block or no copy at all */
20012347Snikos.nikoleris@arm.com    { SET2(IsResponse, IsClean), InvalidCmd, "CleanSharedResp" },
20112347Snikos.nikoleris@arm.com    /* Cache Clean and Invalidate Request -- Invalidate all existing
20212347Snikos.nikoleris@arm.com       copies down to the point indicated by the request */
20312347Snikos.nikoleris@arm.com    { SET5(IsRequest, IsInvalidate, IsClean, NeedsResponse, FromCache),
20412347Snikos.nikoleris@arm.com      CleanInvalidResp, "CleanInvalidReq" },
20512347Snikos.nikoleris@arm.com     /* Cache Clean and Invalidate Respose -- Indicates that no cache
20612347Snikos.nikoleris@arm.com        above the specified point holds the block and that the block
20712347Snikos.nikoleris@arm.com        was written to a memory below the specified point. */
20812347Snikos.nikoleris@arm.com    { SET3(IsResponse, IsInvalidate, IsClean),
20912347Snikos.nikoleris@arm.com      InvalidCmd, "CleanInvalidResp" },
2104870Sstever@eecs.umich.edu    /* InvalidDestError  -- packet dest field invalid */
2114986Ssaidi@eecs.umich.edu    { SET2(IsResponse, IsError), InvalidCmd, "InvalidDestError" },
2124870Sstever@eecs.umich.edu    /* BadAddressError   -- memory address invalid */
2135314Sstever@gmail.com    { SET2(IsResponse, IsError), InvalidCmd, "BadAddressError" },
2148436SBrad.Beckmann@amd.com    /* FunctionalReadError */
2158436SBrad.Beckmann@amd.com    { SET3(IsRead, IsResponse, IsError), InvalidCmd, "FunctionalReadError" },
2168436SBrad.Beckmann@amd.com    /* FunctionalWriteError */
2178436SBrad.Beckmann@amd.com    { SET3(IsWrite, IsResponse, IsError), InvalidCmd, "FunctionalWriteError" },
2185314Sstever@gmail.com    /* PrintReq */
2198184Ssomayeh@cs.wisc.edu    { SET2(IsRequest, IsPrint), InvalidCmd, "PrintReq" },
2208184Ssomayeh@cs.wisc.edu    /* Flush Request */
22111284Sandreas.hansson@arm.com    { SET3(IsRequest, IsFlush, NeedsWritable), InvalidCmd, "FlushReq" },
2228716Snilay@cs.wisc.edu    /* Invalidation Request */
22311600Sandreas.hansson@arm.com    { SET5(IsInvalidate, IsRequest, NeedsWritable, NeedsResponse, FromCache),
22410886Sandreas.hansson@arm.com      InvalidateResp, "InvalidateReq" },
22510886Sandreas.hansson@arm.com    /* Invalidation Response */
22611287Sandreas.hansson@arm.com    { SET2(IsInvalidate, IsResponse),
22710886Sandreas.hansson@arm.com      InvalidCmd, "InvalidateResp" }
2284022Sstever@eecs.umich.edu};
2292592SN/A
23013856Sodanrc@yahoo.com.brAddrRange
23113856Sodanrc@yahoo.com.brPacket::getAddrRange() const
23213856Sodanrc@yahoo.com.br{
23313856Sodanrc@yahoo.com.br    return RangeSize(getAddr(), getSize());
23413856Sodanrc@yahoo.com.br}
23513856Sodanrc@yahoo.com.br
2363607Srdreslin@umich.edubool
23712823Srmk35@cl.cam.ac.ukPacket::trySatisfyFunctional(Printable *obj, Addr addr, bool is_secure, int size,
23810570Sandreas.hansson@arm.com                        uint8_t *_data)
2392641Sstever@eecs.umich.edu{
24012821Srmk35@cl.cam.ac.uk    const Addr func_start = getAddr();
24112821Srmk35@cl.cam.ac.uk    const Addr func_end   = getAddr() + getSize() - 1;
24212821Srmk35@cl.cam.ac.uk    const Addr val_start  = addr;
24312821Srmk35@cl.cam.ac.uk    const Addr val_end    = val_start + size - 1;
2443260Ssaidi@eecs.umich.edu
24510028SGiacomo.Gabrielli@arm.com    if (is_secure != _isSecure || func_start > val_end ||
24610028SGiacomo.Gabrielli@arm.com        val_start > func_end) {
2474626Sstever@eecs.umich.edu        // no intersection
2484626Sstever@eecs.umich.edu        return false;
2494626Sstever@eecs.umich.edu    }
2503260Ssaidi@eecs.umich.edu
2515314Sstever@gmail.com    // check print first since it doesn't require data
2525314Sstever@gmail.com    if (isPrint()) {
25310570Sandreas.hansson@arm.com        assert(!_data);
25410376Sandreas.hansson@arm.com        safe_cast<PrintReqState*>(senderState)->printObj(obj);
2555314Sstever@gmail.com        return false;
2565314Sstever@gmail.com    }
2575314Sstever@gmail.com
25810570Sandreas.hansson@arm.com    // we allow the caller to pass NULL to signify the other packet
25910570Sandreas.hansson@arm.com    // has no data
26010570Sandreas.hansson@arm.com    if (!_data) {
2615314Sstever@gmail.com        return false;
2625314Sstever@gmail.com    }
2635314Sstever@gmail.com
26412821Srmk35@cl.cam.ac.uk    const Addr val_offset = func_start > val_start ?
26512821Srmk35@cl.cam.ac.uk        func_start - val_start : 0;
26612821Srmk35@cl.cam.ac.uk    const Addr func_offset = func_start < val_start ?
26712821Srmk35@cl.cam.ac.uk        val_start - func_start : 0;
26812821Srmk35@cl.cam.ac.uk    const Addr overlap_size = std::min(val_end, func_end)+1 -
26912821Srmk35@cl.cam.ac.uk        std::max(val_start, func_start);
2703260Ssaidi@eecs.umich.edu
2714626Sstever@eecs.umich.edu    if (isRead()) {
27212822Srmk35@cl.cam.ac.uk        std::memcpy(getPtr<uint8_t>() + func_offset,
27312821Srmk35@cl.cam.ac.uk               _data + val_offset,
27412821Srmk35@cl.cam.ac.uk               overlap_size);
2758668Sgeoffrey.blake@arm.com
27612821Srmk35@cl.cam.ac.uk        // initialise the tracking of valid bytes if we have not
27712821Srmk35@cl.cam.ac.uk        // used it already
27812821Srmk35@cl.cam.ac.uk        if (bytesValid.empty())
27912821Srmk35@cl.cam.ac.uk            bytesValid.resize(getSize(), false);
2808668Sgeoffrey.blake@arm.com
28112821Srmk35@cl.cam.ac.uk        // track if we are done filling the functional access
28212821Srmk35@cl.cam.ac.uk        bool all_bytes_valid = true;
2838668Sgeoffrey.blake@arm.com
28412821Srmk35@cl.cam.ac.uk        int i = 0;
28510723Sandreas.hansson@arm.com
28612821Srmk35@cl.cam.ac.uk        // check up to func_offset
28712821Srmk35@cl.cam.ac.uk        for (; all_bytes_valid && i < func_offset; ++i)
28812821Srmk35@cl.cam.ac.uk            all_bytes_valid &= bytesValid[i];
28910723Sandreas.hansson@arm.com
29012821Srmk35@cl.cam.ac.uk        // update the valid bytes
29112821Srmk35@cl.cam.ac.uk        for (i = func_offset; i < func_offset + overlap_size; ++i)
29212821Srmk35@cl.cam.ac.uk            bytesValid[i] = true;
29310723Sandreas.hansson@arm.com
29412821Srmk35@cl.cam.ac.uk        // check the bit after the update we just made
29512821Srmk35@cl.cam.ac.uk        for (; all_bytes_valid && i < getSize(); ++i)
29612821Srmk35@cl.cam.ac.uk            all_bytes_valid &= bytesValid[i];
29710723Sandreas.hansson@arm.com
29812821Srmk35@cl.cam.ac.uk        return all_bytes_valid;
2994626Sstever@eecs.umich.edu    } else if (isWrite()) {
30012822Srmk35@cl.cam.ac.uk        std::memcpy(_data + val_offset,
30112821Srmk35@cl.cam.ac.uk               getConstPtr<uint8_t>() + func_offset,
30212821Srmk35@cl.cam.ac.uk               overlap_size);
3035314Sstever@gmail.com    } else {
3044626Sstever@eecs.umich.edu        panic("Don't know how to handle command %s\n", cmdString());
3055314Sstever@gmail.com    }
3065314Sstever@gmail.com
3075314Sstever@gmail.com    // keep going with request by default
3085314Sstever@gmail.com    return false;
3092641Sstever@eecs.umich.edu}
3103260Ssaidi@eecs.umich.edu
3115314Sstever@gmail.comvoid
31213732Snikos.nikoleris@arm.comPacket::copyResponderFlags(const PacketPtr pkt)
31313732Snikos.nikoleris@arm.com{
31413732Snikos.nikoleris@arm.com    assert(isRequest());
31513732Snikos.nikoleris@arm.com    // If we have already found a responder, no other cache should
31613732Snikos.nikoleris@arm.com    // commit to responding
31713732Snikos.nikoleris@arm.com    assert(!pkt->cacheResponding() || !cacheResponding());
31813732Snikos.nikoleris@arm.com    flags.set(pkt->flags & RESPONDER_FLAGS);
31913732Snikos.nikoleris@arm.com}
32013732Snikos.nikoleris@arm.com
32113732Snikos.nikoleris@arm.comvoid
3229542Sandreas.hansson@arm.comPacket::pushSenderState(Packet::SenderState *sender_state)
3239542Sandreas.hansson@arm.com{
3249542Sandreas.hansson@arm.com    assert(sender_state != NULL);
3259542Sandreas.hansson@arm.com    sender_state->predecessor = senderState;
3269542Sandreas.hansson@arm.com    senderState = sender_state;
3279542Sandreas.hansson@arm.com}
3289542Sandreas.hansson@arm.com
3299542Sandreas.hansson@arm.comPacket::SenderState *
3309542Sandreas.hansson@arm.comPacket::popSenderState()
3319542Sandreas.hansson@arm.com{
3329542Sandreas.hansson@arm.com    assert(senderState != NULL);
3339542Sandreas.hansson@arm.com    SenderState *sender_state = senderState;
3349542Sandreas.hansson@arm.com    senderState = sender_state->predecessor;
3359542Sandreas.hansson@arm.com    sender_state->predecessor = NULL;
3369542Sandreas.hansson@arm.com    return sender_state;
3379542Sandreas.hansson@arm.com}
3389542Sandreas.hansson@arm.com
33912652Sandreas.sandberg@arm.comuint64_t
34012652Sandreas.sandberg@arm.comPacket::getUintX(ByteOrder endian) const
34112652Sandreas.sandberg@arm.com{
34212652Sandreas.sandberg@arm.com    switch(getSize()) {
34312652Sandreas.sandberg@arm.com      case 1:
34412652Sandreas.sandberg@arm.com        return (uint64_t)get<uint8_t>(endian);
34512652Sandreas.sandberg@arm.com      case 2:
34612652Sandreas.sandberg@arm.com        return (uint64_t)get<uint16_t>(endian);
34712652Sandreas.sandberg@arm.com      case 4:
34812652Sandreas.sandberg@arm.com        return (uint64_t)get<uint32_t>(endian);
34912652Sandreas.sandberg@arm.com      case 8:
35012652Sandreas.sandberg@arm.com        return (uint64_t)get<uint64_t>(endian);
35112652Sandreas.sandberg@arm.com      default:
35212652Sandreas.sandberg@arm.com        panic("%i isn't a supported word size.\n", getSize());
35312652Sandreas.sandberg@arm.com    }
35412652Sandreas.sandberg@arm.com}
35512652Sandreas.sandberg@arm.com
35612652Sandreas.sandberg@arm.comvoid
35712652Sandreas.sandberg@arm.comPacket::setUintX(uint64_t w, ByteOrder endian)
35812652Sandreas.sandberg@arm.com{
35912652Sandreas.sandberg@arm.com    switch(getSize()) {
36012652Sandreas.sandberg@arm.com      case 1:
36112652Sandreas.sandberg@arm.com        set<uint8_t>((uint8_t)w, endian);
36212652Sandreas.sandberg@arm.com        break;
36312652Sandreas.sandberg@arm.com      case 2:
36412652Sandreas.sandberg@arm.com        set<uint16_t>((uint16_t)w, endian);
36512652Sandreas.sandberg@arm.com        break;
36612652Sandreas.sandberg@arm.com      case 4:
36712652Sandreas.sandberg@arm.com        set<uint32_t>((uint32_t)w, endian);
36812652Sandreas.sandberg@arm.com        break;
36912652Sandreas.sandberg@arm.com      case 8:
37012652Sandreas.sandberg@arm.com        set<uint64_t>((uint64_t)w, endian);
37112652Sandreas.sandberg@arm.com        break;
37212652Sandreas.sandberg@arm.com      default:
37312652Sandreas.sandberg@arm.com        panic("%i isn't a supported word size.\n", getSize());
37412652Sandreas.sandberg@arm.com    }
37512652Sandreas.sandberg@arm.com
37612652Sandreas.sandberg@arm.com}
37712652Sandreas.sandberg@arm.com
3789542Sandreas.hansson@arm.comvoid
37912822Srmk35@cl.cam.ac.ukPacket::print(std::ostream &o, const int verbosity,
38012822Srmk35@cl.cam.ac.uk              const std::string &prefix) const
3813260Ssaidi@eecs.umich.edu{
38212346Snikos.nikoleris@arm.com    ccprintf(o, "%s%s [%x:%x]%s%s%s%s%s%s", prefix, cmdString(),
38311744Snikos.nikoleris@arm.com             getAddr(), getAddr() + getSize() - 1,
38411744Snikos.nikoleris@arm.com             req->isSecure() ? " (s)" : "",
38511744Snikos.nikoleris@arm.com             req->isInstFetch() ? " IF" : "",
38611744Snikos.nikoleris@arm.com             req->isUncacheable() ? " UC" : "",
38712346Snikos.nikoleris@arm.com             isExpressSnoop() ? " ES" : "",
38812346Snikos.nikoleris@arm.com             req->isToPOC() ? " PoC" : "",
38912346Snikos.nikoleris@arm.com             req->isToPOU() ? " PoU" : "");
3903260Ssaidi@eecs.umich.edu}
3913260Ssaidi@eecs.umich.edu
3929663Suri.wiener@arm.comstd::string
3939663Suri.wiener@arm.comPacket::print() const {
39412822Srmk35@cl.cam.ac.uk    std::ostringstream str;
3959663Suri.wiener@arm.com    print(str);
3969663Suri.wiener@arm.com    return str.str();
3979663Suri.wiener@arm.com}
3989663Suri.wiener@arm.com
39913860Sodanrc@yahoo.com.brbool
40013860Sodanrc@yahoo.com.brPacket::matchBlockAddr(const Addr addr, const bool is_secure,
40113860Sodanrc@yahoo.com.br                       const int blk_size) const
40213860Sodanrc@yahoo.com.br{
40313860Sodanrc@yahoo.com.br    return (getBlockAddr(blk_size) == addr) && (isSecure() == is_secure);
40413860Sodanrc@yahoo.com.br}
40513860Sodanrc@yahoo.com.br
40613860Sodanrc@yahoo.com.brbool
40713860Sodanrc@yahoo.com.brPacket::matchBlockAddr(const PacketPtr pkt, const int blk_size) const
40813860Sodanrc@yahoo.com.br{
40913860Sodanrc@yahoo.com.br    return matchBlockAddr(pkt->getBlockAddr(blk_size), pkt->isSecure(),
41013860Sodanrc@yahoo.com.br                          blk_size);
41113860Sodanrc@yahoo.com.br}
41213860Sodanrc@yahoo.com.br
41313860Sodanrc@yahoo.com.brbool
41413860Sodanrc@yahoo.com.brPacket::matchAddr(const Addr addr, const bool is_secure) const
41513860Sodanrc@yahoo.com.br{
41613860Sodanrc@yahoo.com.br    return (getAddr() == addr) && (isSecure() == is_secure);
41713860Sodanrc@yahoo.com.br}
41813860Sodanrc@yahoo.com.br
41913860Sodanrc@yahoo.com.brbool
42013860Sodanrc@yahoo.com.brPacket::matchAddr(const PacketPtr pkt) const
42113860Sodanrc@yahoo.com.br{
42213860Sodanrc@yahoo.com.br    return matchAddr(pkt->getAddr(), pkt->isSecure());
42313860Sodanrc@yahoo.com.br}
42413860Sodanrc@yahoo.com.br
42512822Srmk35@cl.cam.ac.ukPacket::PrintReqState::PrintReqState(std::ostream &_os, int _verbosity)
42612822Srmk35@cl.cam.ac.uk    : curPrefixPtr(new std::string("")), os(_os), verbosity(_verbosity)
4275314Sstever@gmail.com{
4285314Sstever@gmail.com    labelStack.push_back(LabelStackEntry("", curPrefixPtr));
4295314Sstever@gmail.com}
4305314Sstever@gmail.com
4315314Sstever@gmail.comPacket::PrintReqState::~PrintReqState()
4325314Sstever@gmail.com{
4335314Sstever@gmail.com    labelStack.pop_back();
4345314Sstever@gmail.com    assert(labelStack.empty());
4355314Sstever@gmail.com    delete curPrefixPtr;
4365314Sstever@gmail.com}
4375314Sstever@gmail.com
4385314Sstever@gmail.comPacket::PrintReqState::
43912822Srmk35@cl.cam.ac.ukLabelStackEntry::LabelStackEntry(const std::string &_label,
44012822Srmk35@cl.cam.ac.uk                                 std::string *_prefix)
4415314Sstever@gmail.com    : label(_label), prefix(_prefix), labelPrinted(false)
4425314Sstever@gmail.com{
4435314Sstever@gmail.com}
4445314Sstever@gmail.com
4455314Sstever@gmail.comvoid
44612822Srmk35@cl.cam.ac.ukPacket::PrintReqState::pushLabel(const std::string &lbl,
44712822Srmk35@cl.cam.ac.uk                                 const std::string &prefix)
4485314Sstever@gmail.com{
4495314Sstever@gmail.com    labelStack.push_back(LabelStackEntry(lbl, curPrefixPtr));
45012822Srmk35@cl.cam.ac.uk    curPrefixPtr = new std::string(*curPrefixPtr);
4515314Sstever@gmail.com    *curPrefixPtr += prefix;
4525314Sstever@gmail.com}
4535314Sstever@gmail.com
4545314Sstever@gmail.comvoid
4555314Sstever@gmail.comPacket::PrintReqState::popLabel()
4565314Sstever@gmail.com{
4575314Sstever@gmail.com    delete curPrefixPtr;
4585314Sstever@gmail.com    curPrefixPtr = labelStack.back().prefix;
4595314Sstever@gmail.com    labelStack.pop_back();
4605314Sstever@gmail.com    assert(!labelStack.empty());
4615314Sstever@gmail.com}
4625314Sstever@gmail.com
4635314Sstever@gmail.comvoid
4645314Sstever@gmail.comPacket::PrintReqState::printLabels()
4655314Sstever@gmail.com{
4665314Sstever@gmail.com    if (!labelStack.back().labelPrinted) {
4675314Sstever@gmail.com        LabelStack::iterator i = labelStack.begin();
4685314Sstever@gmail.com        LabelStack::iterator end = labelStack.end();
4695314Sstever@gmail.com        while (i != end) {
4705314Sstever@gmail.com            if (!i->labelPrinted) {
4715314Sstever@gmail.com                ccprintf(os, "%s%s\n", *(i->prefix), i->label);
4725314Sstever@gmail.com                i->labelPrinted = true;
4735314Sstever@gmail.com            }
4745314Sstever@gmail.com            i++;
4755314Sstever@gmail.com        }
4765314Sstever@gmail.com    }
4775314Sstever@gmail.com}
4785314Sstever@gmail.com
4795314Sstever@gmail.com
4805314Sstever@gmail.comvoid
4815314Sstever@gmail.comPacket::PrintReqState::printObj(Printable *obj)
4825314Sstever@gmail.com{
4835314Sstever@gmail.com    printLabels();
4845314Sstever@gmail.com    obj->print(os, verbosity, curPrefix());
4855314Sstever@gmail.com}
486