packet.cc revision 12652
12568SN/A/* 212652Sandreas.sandberg@arm.com * Copyright (c) 2011-2018 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 538229Snate@binkert.org#include <cstring> 543260Ssaidi@eecs.umich.edu#include <iostream> 558229Snate@binkert.org 565314Sstever@gmail.com#include "base/cprintf.hh" 5712334Sgabeblack@google.com#include "base/logging.hh" 583348Sbinkertn@umich.edu#include "base/trace.hh" 5912652Sandreas.sandberg@arm.com#include "mem/packet_access.hh" 602568SN/A 615735Snate@binkert.orgusing namespace std; 625735Snate@binkert.org 634022Sstever@eecs.umich.edu// The one downside to bitsets is that static initializers can get ugly. 644022Sstever@eecs.umich.edu#define SET1(a1) (1 << (a1)) 654022Sstever@eecs.umich.edu#define SET2(a1, a2) (SET1(a1) | SET1(a2)) 664022Sstever@eecs.umich.edu#define SET3(a1, a2, a3) (SET2(a1, a2) | SET1(a3)) 674022Sstever@eecs.umich.edu#define SET4(a1, a2, a3, a4) (SET3(a1, a2, a3) | SET1(a4)) 684022Sstever@eecs.umich.edu#define SET5(a1, a2, a3, a4, a5) (SET4(a1, a2, a3, a4) | SET1(a5)) 694022Sstever@eecs.umich.edu#define SET6(a1, a2, a3, a4, a5, a6) (SET5(a1, a2, a3, a4, a5) | SET1(a6)) 7011600Sandreas.hansson@arm.com#define SET7(a1, a2, a3, a4, a5, a6, a7) (SET6(a1, a2, a3, a4, a5, a6) | \ 7111600Sandreas.hansson@arm.com SET1(a7)) 722641Sstever@eecs.umich.edu 734022Sstever@eecs.umich.educonst MemCmd::CommandInfo 744022Sstever@eecs.umich.eduMemCmd::commandInfo[] = 752641Sstever@eecs.umich.edu{ 764022Sstever@eecs.umich.edu /* InvalidCmd */ 774022Sstever@eecs.umich.edu { 0, InvalidCmd, "InvalidCmd" }, 7810885Sandreas.hansson@arm.com /* ReadReq - Read issued by a non-caching agent such as a CPU or 7910885Sandreas.hansson@arm.com * device, with no restrictions on alignment. */ 804022Sstever@eecs.umich.edu { SET3(IsRead, IsRequest, NeedsResponse), ReadResp, "ReadReq" }, 814473Sstever@eecs.umich.edu /* ReadResp */ 824473Sstever@eecs.umich.edu { SET3(IsRead, IsResponse, HasData), InvalidCmd, "ReadResp" }, 835319Sstever@gmail.com /* ReadRespWithInvalidate */ 845319Sstever@gmail.com { SET4(IsRead, IsResponse, HasData, IsInvalidate), 855319Sstever@gmail.com InvalidCmd, "ReadRespWithInvalidate" }, 864022Sstever@eecs.umich.edu /* WriteReq */ 8711284Sandreas.hansson@arm.com { SET5(IsWrite, NeedsWritable, IsRequest, NeedsResponse, HasData), 884022Sstever@eecs.umich.edu WriteResp, "WriteReq" }, 894022Sstever@eecs.umich.edu /* WriteResp */ 9011287Sandreas.hansson@arm.com { SET2(IsWrite, IsResponse), InvalidCmd, "WriteResp" }, 9111199Sandreas.hansson@arm.com /* WritebackDirty */ 9211600Sandreas.hansson@arm.com { SET5(IsWrite, IsRequest, IsEviction, HasData, FromCache), 9311199Sandreas.hansson@arm.com InvalidCmd, "WritebackDirty" }, 9411199Sandreas.hansson@arm.com /* WritebackClean - This allows the upstream cache to writeback a 9511199Sandreas.hansson@arm.com * line to the downstream cache without it being considered 9611199Sandreas.hansson@arm.com * dirty. */ 9711600Sandreas.hansson@arm.com { SET5(IsWrite, IsRequest, IsEviction, HasData, FromCache), 9811199Sandreas.hansson@arm.com InvalidCmd, "WritebackClean" }, 9912344Snikos.nikoleris@arm.com /* WriteClean - This allows a cache to write a dirty block to a memory 10012344Snikos.nikoleris@arm.com below without evicting its copy. */ 10112344Snikos.nikoleris@arm.com { SET4(IsWrite, IsRequest, HasData, FromCache), InvalidCmd, "WriteClean" }, 10210883Sali.jafri@arm.com /* CleanEvict */ 10311600Sandreas.hansson@arm.com { SET3(IsRequest, IsEviction, FromCache), InvalidCmd, "CleanEvict" }, 1044022Sstever@eecs.umich.edu /* SoftPFReq */ 1054022Sstever@eecs.umich.edu { SET4(IsRead, IsRequest, IsSWPrefetch, NeedsResponse), 1064022Sstever@eecs.umich.edu SoftPFResp, "SoftPFReq" }, 1074022Sstever@eecs.umich.edu /* HardPFReq */ 10811600Sandreas.hansson@arm.com { SET5(IsRead, IsRequest, IsHWPrefetch, NeedsResponse, FromCache), 1094022Sstever@eecs.umich.edu HardPFResp, "HardPFReq" }, 1104022Sstever@eecs.umich.edu /* SoftPFResp */ 1114022Sstever@eecs.umich.edu { SET4(IsRead, IsResponse, IsSWPrefetch, HasData), 1124022Sstever@eecs.umich.edu InvalidCmd, "SoftPFResp" }, 1134022Sstever@eecs.umich.edu /* HardPFResp */ 1144022Sstever@eecs.umich.edu { SET4(IsRead, IsResponse, IsHWPrefetch, HasData), 1154022Sstever@eecs.umich.edu InvalidCmd, "HardPFResp" }, 11610886Sandreas.hansson@arm.com /* WriteLineReq */ 11711284Sandreas.hansson@arm.com { SET5(IsWrite, NeedsWritable, IsRequest, NeedsResponse, HasData), 11810886Sandreas.hansson@arm.com WriteResp, "WriteLineReq" }, 1194022Sstever@eecs.umich.edu /* UpgradeReq */ 12011600Sandreas.hansson@arm.com { SET6(IsInvalidate, NeedsWritable, IsUpgrade, IsRequest, NeedsResponse, 12111600Sandreas.hansson@arm.com FromCache), 1224628Sstever@eecs.umich.edu UpgradeResp, "UpgradeReq" }, 1237465Ssteve.reinhardt@amd.com /* SCUpgradeReq: response could be UpgradeResp or UpgradeFailResp */ 12411600Sandreas.hansson@arm.com { SET7(IsInvalidate, NeedsWritable, IsUpgrade, IsLlsc, 12511600Sandreas.hansson@arm.com IsRequest, NeedsResponse, FromCache), 1267465Ssteve.reinhardt@amd.com UpgradeResp, "SCUpgradeReq" }, 1274628Sstever@eecs.umich.edu /* UpgradeResp */ 12811287Sandreas.hansson@arm.com { SET2(IsUpgrade, IsResponse), 1297465Ssteve.reinhardt@amd.com InvalidCmd, "UpgradeResp" }, 13010325Sgeoffrey.blake@arm.com /* SCUpgradeFailReq: generates UpgradeFailResp but still gets the data */ 13111600Sandreas.hansson@arm.com { SET7(IsRead, NeedsWritable, IsInvalidate, 13211600Sandreas.hansson@arm.com IsLlsc, IsRequest, NeedsResponse, FromCache), 1337465Ssteve.reinhardt@amd.com UpgradeFailResp, "SCUpgradeFailReq" }, 13410325Sgeoffrey.blake@arm.com /* UpgradeFailResp - Behaves like a ReadExReq, but notifies an SC 13510325Sgeoffrey.blake@arm.com * that it has failed, acquires line as Dirty*/ 13611287Sandreas.hansson@arm.com { SET3(IsRead, IsResponse, HasData), 1377465Ssteve.reinhardt@amd.com InvalidCmd, "UpgradeFailResp" }, 13810885Sandreas.hansson@arm.com /* ReadExReq - Read issues by a cache, always cache-line aligned, 13910885Sandreas.hansson@arm.com * and the response is guaranteed to be writeable (exclusive or 14010885Sandreas.hansson@arm.com * even modified) */ 14111600Sandreas.hansson@arm.com { SET6(IsRead, NeedsWritable, IsInvalidate, IsRequest, NeedsResponse, 14211600Sandreas.hansson@arm.com FromCache), 1434022Sstever@eecs.umich.edu ReadExResp, "ReadExReq" }, 14410885Sandreas.hansson@arm.com /* ReadExResp - Response matching a read exclusive, as we check 14510885Sandreas.hansson@arm.com * the need for exclusive also on responses */ 14611287Sandreas.hansson@arm.com { SET3(IsRead, IsResponse, HasData), 1474040Ssaidi@eecs.umich.edu InvalidCmd, "ReadExResp" }, 14810885Sandreas.hansson@arm.com /* ReadCleanReq - Read issued by a cache, always cache-line 14910885Sandreas.hansson@arm.com * aligned, and the response is guaranteed to not contain dirty data 15010885Sandreas.hansson@arm.com * (exclusive or shared).*/ 15111600Sandreas.hansson@arm.com { SET4(IsRead, IsRequest, NeedsResponse, FromCache), 15211600Sandreas.hansson@arm.com ReadResp, "ReadCleanReq" }, 15310885Sandreas.hansson@arm.com /* ReadSharedReq - Read issued by a cache, always cache-line 15410885Sandreas.hansson@arm.com * aligned, response is shared, possibly exclusive, owned or even 15510885Sandreas.hansson@arm.com * modified. */ 15611600Sandreas.hansson@arm.com { SET4(IsRead, IsRequest, NeedsResponse, FromCache), 15711600Sandreas.hansson@arm.com ReadResp, "ReadSharedReq" }, 1585507Sstever@gmail.com /* LoadLockedReq: note that we use plain ReadResp as response, so that 1595507Sstever@gmail.com * we can also use ReadRespWithInvalidate when needed */ 1606076Sgblack@eecs.umich.edu { SET4(IsRead, IsLlsc, IsRequest, NeedsResponse), 1615507Sstever@gmail.com ReadResp, "LoadLockedReq" }, 1624626Sstever@eecs.umich.edu /* StoreCondReq */ 16311284Sandreas.hansson@arm.com { SET6(IsWrite, NeedsWritable, IsLlsc, 1644626Sstever@eecs.umich.edu IsRequest, NeedsResponse, HasData), 1654626Sstever@eecs.umich.edu StoreCondResp, "StoreCondReq" }, 16610325Sgeoffrey.blake@arm.com /* StoreCondFailReq: generates failing StoreCondResp */ 16711284Sandreas.hansson@arm.com { SET6(IsWrite, NeedsWritable, IsLlsc, 1687669Ssteve.reinhardt@amd.com IsRequest, NeedsResponse, HasData), 1697669Ssteve.reinhardt@amd.com StoreCondResp, "StoreCondFailReq" }, 1704626Sstever@eecs.umich.edu /* StoreCondResp */ 17111287Sandreas.hansson@arm.com { SET3(IsWrite, IsLlsc, IsResponse), 1724626Sstever@eecs.umich.edu InvalidCmd, "StoreCondResp" }, 1734040Ssaidi@eecs.umich.edu /* SwapReq -- for Swap ldstub type operations */ 17411284Sandreas.hansson@arm.com { SET6(IsRead, IsWrite, NeedsWritable, IsRequest, HasData, NeedsResponse), 1754040Ssaidi@eecs.umich.edu SwapResp, "SwapReq" }, 1764040Ssaidi@eecs.umich.edu /* SwapResp -- for Swap ldstub type operations */ 17711287Sandreas.hansson@arm.com { SET4(IsRead, IsWrite, IsResponse, HasData), 1784870Sstever@eecs.umich.edu InvalidCmd, "SwapResp" }, 1795650Sgblack@eecs.umich.edu /* IntReq -- for interrupts */ 1805650Sgblack@eecs.umich.edu { SET4(IsWrite, IsRequest, NeedsResponse, HasData), 1816063Sgblack@eecs.umich.edu MessageResp, "MessageReq" }, 1825650Sgblack@eecs.umich.edu /* IntResp -- for interrupts */ 1836063Sgblack@eecs.umich.edu { SET2(IsWrite, IsResponse), InvalidCmd, "MessageResp" }, 18411256Santhony.gutierrez@amd.com /* MemFenceReq -- for synchronization requests */ 18511256Santhony.gutierrez@amd.com {SET2(IsRequest, NeedsResponse), MemFenceResp, "MemFenceReq"}, 18611256Santhony.gutierrez@amd.com /* MemFenceResp -- for synchronization responses */ 18711256Santhony.gutierrez@amd.com {SET1(IsResponse), InvalidCmd, "MemFenceResp"}, 18812347Snikos.nikoleris@arm.com /* Cache Clean Request -- Update with the latest data all existing 18912347Snikos.nikoleris@arm.com copies of the block down to the point indicated by the 19012347Snikos.nikoleris@arm.com request */ 19112347Snikos.nikoleris@arm.com { SET4(IsRequest, IsClean, NeedsResponse, FromCache), 19212347Snikos.nikoleris@arm.com CleanSharedResp, "CleanSharedReq" }, 19312347Snikos.nikoleris@arm.com /* Cache Clean Response - Indicates that all caches up to the 19412347Snikos.nikoleris@arm.com specified point of reference have a up-to-date copy of the 19512347Snikos.nikoleris@arm.com cache block or no copy at all */ 19612347Snikos.nikoleris@arm.com { SET2(IsResponse, IsClean), InvalidCmd, "CleanSharedResp" }, 19712347Snikos.nikoleris@arm.com /* Cache Clean and Invalidate Request -- Invalidate all existing 19812347Snikos.nikoleris@arm.com copies down to the point indicated by the request */ 19912347Snikos.nikoleris@arm.com { SET5(IsRequest, IsInvalidate, IsClean, NeedsResponse, FromCache), 20012347Snikos.nikoleris@arm.com CleanInvalidResp, "CleanInvalidReq" }, 20112347Snikos.nikoleris@arm.com /* Cache Clean and Invalidate Respose -- Indicates that no cache 20212347Snikos.nikoleris@arm.com above the specified point holds the block and that the block 20312347Snikos.nikoleris@arm.com was written to a memory below the specified point. */ 20412347Snikos.nikoleris@arm.com { SET3(IsResponse, IsInvalidate, IsClean), 20512347Snikos.nikoleris@arm.com InvalidCmd, "CleanInvalidResp" }, 2064870Sstever@eecs.umich.edu /* InvalidDestError -- packet dest field invalid */ 2074986Ssaidi@eecs.umich.edu { SET2(IsResponse, IsError), InvalidCmd, "InvalidDestError" }, 2084870Sstever@eecs.umich.edu /* BadAddressError -- memory address invalid */ 2095314Sstever@gmail.com { SET2(IsResponse, IsError), InvalidCmd, "BadAddressError" }, 2108436SBrad.Beckmann@amd.com /* FunctionalReadError */ 2118436SBrad.Beckmann@amd.com { SET3(IsRead, IsResponse, IsError), InvalidCmd, "FunctionalReadError" }, 2128436SBrad.Beckmann@amd.com /* FunctionalWriteError */ 2138436SBrad.Beckmann@amd.com { SET3(IsWrite, IsResponse, IsError), InvalidCmd, "FunctionalWriteError" }, 2145314Sstever@gmail.com /* PrintReq */ 2158184Ssomayeh@cs.wisc.edu { SET2(IsRequest, IsPrint), InvalidCmd, "PrintReq" }, 2168184Ssomayeh@cs.wisc.edu /* Flush Request */ 21711284Sandreas.hansson@arm.com { SET3(IsRequest, IsFlush, NeedsWritable), InvalidCmd, "FlushReq" }, 2188716Snilay@cs.wisc.edu /* Invalidation Request */ 21911600Sandreas.hansson@arm.com { SET5(IsInvalidate, IsRequest, NeedsWritable, NeedsResponse, FromCache), 22010886Sandreas.hansson@arm.com InvalidateResp, "InvalidateReq" }, 22110886Sandreas.hansson@arm.com /* Invalidation Response */ 22211287Sandreas.hansson@arm.com { SET2(IsInvalidate, IsResponse), 22310886Sandreas.hansson@arm.com InvalidCmd, "InvalidateResp" } 2244022Sstever@eecs.umich.edu}; 2252592SN/A 2263607Srdreslin@umich.edubool 22710028SGiacomo.Gabrielli@arm.comPacket::checkFunctional(Printable *obj, Addr addr, bool is_secure, int size, 22810570Sandreas.hansson@arm.com uint8_t *_data) 2292641Sstever@eecs.umich.edu{ 2304626Sstever@eecs.umich.edu Addr func_start = getAddr(); 2314626Sstever@eecs.umich.edu Addr func_end = getAddr() + getSize() - 1; 2324626Sstever@eecs.umich.edu Addr val_start = addr; 2334626Sstever@eecs.umich.edu Addr val_end = val_start + size - 1; 2343260Ssaidi@eecs.umich.edu 23510028SGiacomo.Gabrielli@arm.com if (is_secure != _isSecure || func_start > val_end || 23610028SGiacomo.Gabrielli@arm.com val_start > func_end) { 2374626Sstever@eecs.umich.edu // no intersection 2384626Sstever@eecs.umich.edu return false; 2394626Sstever@eecs.umich.edu } 2403260Ssaidi@eecs.umich.edu 2415314Sstever@gmail.com // check print first since it doesn't require data 2425314Sstever@gmail.com if (isPrint()) { 24310570Sandreas.hansson@arm.com assert(!_data); 24410376Sandreas.hansson@arm.com safe_cast<PrintReqState*>(senderState)->printObj(obj); 2455314Sstever@gmail.com return false; 2465314Sstever@gmail.com } 2475314Sstever@gmail.com 24810570Sandreas.hansson@arm.com // we allow the caller to pass NULL to signify the other packet 24910570Sandreas.hansson@arm.com // has no data 25010570Sandreas.hansson@arm.com if (!_data) { 2515314Sstever@gmail.com return false; 2525314Sstever@gmail.com } 2535314Sstever@gmail.com 2544626Sstever@eecs.umich.edu // offset of functional request into supplied value (could be 2554626Sstever@eecs.umich.edu // negative if partial overlap) 2564626Sstever@eecs.umich.edu int offset = func_start - val_start; 2573260Ssaidi@eecs.umich.edu 2584626Sstever@eecs.umich.edu if (isRead()) { 2594626Sstever@eecs.umich.edu if (func_start >= val_start && func_end <= val_end) { 26010570Sandreas.hansson@arm.com memcpy(getPtr<uint8_t>(), _data + offset, getSize()); 26110723Sandreas.hansson@arm.com if (bytesValid.empty()) 26210723Sandreas.hansson@arm.com bytesValid.resize(getSize(), true); 26310570Sandreas.hansson@arm.com // complete overlap, and as the current packet is a read 26410570Sandreas.hansson@arm.com // we are done 2654626Sstever@eecs.umich.edu return true; 2663260Ssaidi@eecs.umich.edu } else { 2678668Sgeoffrey.blake@arm.com // Offsets and sizes to copy in case of partial overlap 2688668Sgeoffrey.blake@arm.com int func_offset; 2698668Sgeoffrey.blake@arm.com int val_offset; 2708668Sgeoffrey.blake@arm.com int overlap_size; 2718668Sgeoffrey.blake@arm.com 2728668Sgeoffrey.blake@arm.com // calculate offsets and copy sizes for the two byte arrays 2738668Sgeoffrey.blake@arm.com if (val_start < func_start && val_end <= func_end) { 27410723Sandreas.hansson@arm.com // the one we are checking against starts before and 27510723Sandreas.hansson@arm.com // ends before or the same 2768668Sgeoffrey.blake@arm.com val_offset = func_start - val_start; 2778668Sgeoffrey.blake@arm.com func_offset = 0; 2788668Sgeoffrey.blake@arm.com overlap_size = val_end - func_start; 2798668Sgeoffrey.blake@arm.com } else if (val_start >= func_start && val_end > func_end) { 28010723Sandreas.hansson@arm.com // the one we are checking against starts after or the 28110723Sandreas.hansson@arm.com // same, and ends after 2828668Sgeoffrey.blake@arm.com val_offset = 0; 2838668Sgeoffrey.blake@arm.com func_offset = val_start - func_start; 2848668Sgeoffrey.blake@arm.com overlap_size = func_end - val_start; 2858668Sgeoffrey.blake@arm.com } else if (val_start >= func_start && val_end <= func_end) { 28610723Sandreas.hansson@arm.com // the one we are checking against is completely 28710723Sandreas.hansson@arm.com // subsumed in the current packet, possibly starting 28810723Sandreas.hansson@arm.com // and ending at the same address 2898668Sgeoffrey.blake@arm.com val_offset = 0; 2908668Sgeoffrey.blake@arm.com func_offset = val_start - func_start; 2918668Sgeoffrey.blake@arm.com overlap_size = size; 29210723Sandreas.hansson@arm.com } else if (val_start < func_start && val_end > func_end) { 29310723Sandreas.hansson@arm.com // the current packet is completely subsumed in the 29410723Sandreas.hansson@arm.com // one we are checking against 29510723Sandreas.hansson@arm.com val_offset = func_start - val_start; 29610723Sandreas.hansson@arm.com func_offset = 0; 29710723Sandreas.hansson@arm.com overlap_size = func_end - func_start; 2988668Sgeoffrey.blake@arm.com } else { 29910723Sandreas.hansson@arm.com panic("Missed a case for checkFunctional with " 30010723Sandreas.hansson@arm.com " %s 0x%x size %d, against 0x%x size %d\n", 30110723Sandreas.hansson@arm.com cmdString(), getAddr(), getSize(), addr, size); 3028668Sgeoffrey.blake@arm.com } 3038668Sgeoffrey.blake@arm.com 3048668Sgeoffrey.blake@arm.com // copy partial data into the packet's data array 3058668Sgeoffrey.blake@arm.com uint8_t *dest = getPtr<uint8_t>() + func_offset; 30610570Sandreas.hansson@arm.com uint8_t *src = _data + val_offset; 3078668Sgeoffrey.blake@arm.com memcpy(dest, src, overlap_size); 3088668Sgeoffrey.blake@arm.com 30910723Sandreas.hansson@arm.com // initialise the tracking of valid bytes if we have not 31010723Sandreas.hansson@arm.com // used it already 31110723Sandreas.hansson@arm.com if (bytesValid.empty()) 31210723Sandreas.hansson@arm.com bytesValid.resize(getSize(), false); 31310723Sandreas.hansson@arm.com 31410723Sandreas.hansson@arm.com // track if we are done filling the functional access 31510723Sandreas.hansson@arm.com bool all_bytes_valid = true; 31610723Sandreas.hansson@arm.com 31710723Sandreas.hansson@arm.com int i = 0; 31810723Sandreas.hansson@arm.com 31910723Sandreas.hansson@arm.com // check up to func_offset 32010723Sandreas.hansson@arm.com for (; all_bytes_valid && i < func_offset; ++i) 32110723Sandreas.hansson@arm.com all_bytes_valid &= bytesValid[i]; 32210723Sandreas.hansson@arm.com 32310723Sandreas.hansson@arm.com // update the valid bytes 32410723Sandreas.hansson@arm.com for (i = func_offset; i < func_offset + overlap_size; ++i) 32510723Sandreas.hansson@arm.com bytesValid[i] = true; 32610723Sandreas.hansson@arm.com 32710723Sandreas.hansson@arm.com // check the bit after the update we just made 32810723Sandreas.hansson@arm.com for (; all_bytes_valid && i < getSize(); ++i) 32910723Sandreas.hansson@arm.com all_bytes_valid &= bytesValid[i]; 33010723Sandreas.hansson@arm.com 33110723Sandreas.hansson@arm.com return all_bytes_valid; 3323260Ssaidi@eecs.umich.edu } 3334626Sstever@eecs.umich.edu } else if (isWrite()) { 3344626Sstever@eecs.umich.edu if (offset >= 0) { 33510570Sandreas.hansson@arm.com memcpy(_data + offset, getConstPtr<uint8_t>(), 3365735Snate@binkert.org (min(func_end, val_end) - func_start) + 1); 3375735Snate@binkert.org } else { 3385735Snate@binkert.org // val_start > func_start 33910570Sandreas.hansson@arm.com memcpy(_data, getConstPtr<uint8_t>() - offset, 3405735Snate@binkert.org (min(func_end, val_end) - val_start) + 1); 3413260Ssaidi@eecs.umich.edu } 3425314Sstever@gmail.com } else { 3434626Sstever@eecs.umich.edu panic("Don't know how to handle command %s\n", cmdString()); 3445314Sstever@gmail.com } 3455314Sstever@gmail.com 3465314Sstever@gmail.com // keep going with request by default 3475314Sstever@gmail.com return false; 3482641Sstever@eecs.umich.edu} 3493260Ssaidi@eecs.umich.edu 3505314Sstever@gmail.comvoid 3519542Sandreas.hansson@arm.comPacket::pushSenderState(Packet::SenderState *sender_state) 3529542Sandreas.hansson@arm.com{ 3539542Sandreas.hansson@arm.com assert(sender_state != NULL); 3549542Sandreas.hansson@arm.com sender_state->predecessor = senderState; 3559542Sandreas.hansson@arm.com senderState = sender_state; 3569542Sandreas.hansson@arm.com} 3579542Sandreas.hansson@arm.com 3589542Sandreas.hansson@arm.comPacket::SenderState * 3599542Sandreas.hansson@arm.comPacket::popSenderState() 3609542Sandreas.hansson@arm.com{ 3619542Sandreas.hansson@arm.com assert(senderState != NULL); 3629542Sandreas.hansson@arm.com SenderState *sender_state = senderState; 3639542Sandreas.hansson@arm.com senderState = sender_state->predecessor; 3649542Sandreas.hansson@arm.com sender_state->predecessor = NULL; 3659542Sandreas.hansson@arm.com return sender_state; 3669542Sandreas.hansson@arm.com} 3679542Sandreas.hansson@arm.com 36812652Sandreas.sandberg@arm.comuint64_t 36912652Sandreas.sandberg@arm.comPacket::getUintX(ByteOrder endian) const 37012652Sandreas.sandberg@arm.com{ 37112652Sandreas.sandberg@arm.com switch(getSize()) { 37212652Sandreas.sandberg@arm.com case 1: 37312652Sandreas.sandberg@arm.com return (uint64_t)get<uint8_t>(endian); 37412652Sandreas.sandberg@arm.com case 2: 37512652Sandreas.sandberg@arm.com return (uint64_t)get<uint16_t>(endian); 37612652Sandreas.sandberg@arm.com case 4: 37712652Sandreas.sandberg@arm.com return (uint64_t)get<uint32_t>(endian); 37812652Sandreas.sandberg@arm.com case 8: 37912652Sandreas.sandberg@arm.com return (uint64_t)get<uint64_t>(endian); 38012652Sandreas.sandberg@arm.com default: 38112652Sandreas.sandberg@arm.com panic("%i isn't a supported word size.\n", getSize()); 38212652Sandreas.sandberg@arm.com } 38312652Sandreas.sandberg@arm.com} 38412652Sandreas.sandberg@arm.com 38512652Sandreas.sandberg@arm.comvoid 38612652Sandreas.sandberg@arm.comPacket::setUintX(uint64_t w, ByteOrder endian) 38712652Sandreas.sandberg@arm.com{ 38812652Sandreas.sandberg@arm.com switch(getSize()) { 38912652Sandreas.sandberg@arm.com case 1: 39012652Sandreas.sandberg@arm.com set<uint8_t>((uint8_t)w, endian); 39112652Sandreas.sandberg@arm.com break; 39212652Sandreas.sandberg@arm.com case 2: 39312652Sandreas.sandberg@arm.com set<uint16_t>((uint16_t)w, endian); 39412652Sandreas.sandberg@arm.com break; 39512652Sandreas.sandberg@arm.com case 4: 39612652Sandreas.sandberg@arm.com set<uint32_t>((uint32_t)w, endian); 39712652Sandreas.sandberg@arm.com break; 39812652Sandreas.sandberg@arm.com case 8: 39912652Sandreas.sandberg@arm.com set<uint64_t>((uint64_t)w, endian); 40012652Sandreas.sandberg@arm.com break; 40112652Sandreas.sandberg@arm.com default: 40212652Sandreas.sandberg@arm.com panic("%i isn't a supported word size.\n", getSize()); 40312652Sandreas.sandberg@arm.com } 40412652Sandreas.sandberg@arm.com 40512652Sandreas.sandberg@arm.com} 40612652Sandreas.sandberg@arm.com 4079542Sandreas.hansson@arm.comvoid 4085735Snate@binkert.orgPacket::print(ostream &o, const int verbosity, const string &prefix) const 4093260Ssaidi@eecs.umich.edu{ 41012346Snikos.nikoleris@arm.com ccprintf(o, "%s%s [%x:%x]%s%s%s%s%s%s", prefix, cmdString(), 41111744Snikos.nikoleris@arm.com getAddr(), getAddr() + getSize() - 1, 41211744Snikos.nikoleris@arm.com req->isSecure() ? " (s)" : "", 41311744Snikos.nikoleris@arm.com req->isInstFetch() ? " IF" : "", 41411744Snikos.nikoleris@arm.com req->isUncacheable() ? " UC" : "", 41512346Snikos.nikoleris@arm.com isExpressSnoop() ? " ES" : "", 41612346Snikos.nikoleris@arm.com req->isToPOC() ? " PoC" : "", 41712346Snikos.nikoleris@arm.com req->isToPOU() ? " PoU" : ""); 4183260Ssaidi@eecs.umich.edu} 4193260Ssaidi@eecs.umich.edu 4209663Suri.wiener@arm.comstd::string 4219663Suri.wiener@arm.comPacket::print() const { 4229663Suri.wiener@arm.com ostringstream str; 4239663Suri.wiener@arm.com print(str); 4249663Suri.wiener@arm.com return str.str(); 4259663Suri.wiener@arm.com} 4269663Suri.wiener@arm.com 4275735Snate@binkert.orgPacket::PrintReqState::PrintReqState(ostream &_os, int _verbosity) 4285735Snate@binkert.org : curPrefixPtr(new string("")), os(_os), verbosity(_verbosity) 4295314Sstever@gmail.com{ 4305314Sstever@gmail.com labelStack.push_back(LabelStackEntry("", curPrefixPtr)); 4315314Sstever@gmail.com} 4325314Sstever@gmail.com 4335314Sstever@gmail.comPacket::PrintReqState::~PrintReqState() 4345314Sstever@gmail.com{ 4355314Sstever@gmail.com labelStack.pop_back(); 4365314Sstever@gmail.com assert(labelStack.empty()); 4375314Sstever@gmail.com delete curPrefixPtr; 4385314Sstever@gmail.com} 4395314Sstever@gmail.com 4405314Sstever@gmail.comPacket::PrintReqState:: 4415735Snate@binkert.orgLabelStackEntry::LabelStackEntry(const string &_label, string *_prefix) 4425314Sstever@gmail.com : label(_label), prefix(_prefix), labelPrinted(false) 4435314Sstever@gmail.com{ 4445314Sstever@gmail.com} 4455314Sstever@gmail.com 4465314Sstever@gmail.comvoid 4475735Snate@binkert.orgPacket::PrintReqState::pushLabel(const string &lbl, const string &prefix) 4485314Sstever@gmail.com{ 4495314Sstever@gmail.com labelStack.push_back(LabelStackEntry(lbl, curPrefixPtr)); 4505735Snate@binkert.org curPrefixPtr = new 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