RubySlicc_ComponentMapping.hh revision 6285
16145Snate@binkert.org
26145Snate@binkert.org/*
36145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
46145Snate@binkert.org * All rights reserved.
56145Snate@binkert.org *
66145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
76145Snate@binkert.org * modification, are permitted provided that the following conditions are
86145Snate@binkert.org * met: redistributions of source code must retain the above copyright
96145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
106145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
116145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
126145Snate@binkert.org * documentation and/or other materials provided with the distribution;
136145Snate@binkert.org * neither the name of the copyright holders nor the names of its
146145Snate@binkert.org * contributors may be used to endorse or promote products derived from
156145Snate@binkert.org * this software without specific prior written permission.
166145Snate@binkert.org *
176145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286145Snate@binkert.org */
296145Snate@binkert.org
306145Snate@binkert.org/*
316145Snate@binkert.org * $Id$
326145Snate@binkert.org */
336145Snate@binkert.org
346145Snate@binkert.org#ifndef COMPONENTMAPPINGFNS_H
356145Snate@binkert.org#define COMPONENTMAPPINGFNS_H
366145Snate@binkert.org
376154Snate@binkert.org#include "mem/ruby/common/Global.hh"
386154Snate@binkert.org#include "mem/ruby/config/RubyConfig.hh"
396154Snate@binkert.org#include "mem/ruby/system/NodeID.hh"
406154Snate@binkert.org#include "mem/ruby/system/MachineID.hh"
416154Snate@binkert.org#include "mem/ruby/common/Address.hh"
426154Snate@binkert.org#include "mem/ruby/common/Set.hh"
436154Snate@binkert.org#include "mem/ruby/common/NetDest.hh"
446154Snate@binkert.org#include "mem/protocol/GenericMachineType.hh"
456285Snate@binkert.org#include "mem/ruby/system/DirectoryMemory.hh"
466145Snate@binkert.org
476145Snate@binkert.org#ifdef MACHINETYPE_L1Cache
486145Snate@binkert.org#define MACHINETYPE_L1CACHE_ENUM MachineType_L1Cache
496145Snate@binkert.org#else
506145Snate@binkert.org#define MACHINETYPE_L1CACHE_ENUM MachineType_NUM
516145Snate@binkert.org#endif
526145Snate@binkert.org
536145Snate@binkert.org#ifdef MACHINETYPE_L2Cache
546145Snate@binkert.org#define MACHINETYPE_L2CACHE_ENUM MachineType_L2Cache
556145Snate@binkert.org#else
566145Snate@binkert.org#define MACHINETYPE_L2CACHE_ENUM MachineType_NUM
576145Snate@binkert.org#endif
586145Snate@binkert.org
596145Snate@binkert.org#ifdef MACHINETYPE_L3Cache
606145Snate@binkert.org#define MACHINETYPE_L3CACHE_ENUM MachineType_L3Cache
616145Snate@binkert.org#else
626145Snate@binkert.org#define MACHINETYPE_L3CACHE_ENUM MachineType_NUM
636145Snate@binkert.org#endif
646145Snate@binkert.org
656285Snate@binkert.org/*
666145Snate@binkert.org#ifdef MACHINETYPE_PersistentArbiter
676145Snate@binkert.org#define MACHINETYPE_PERSISTENTARBITER_ENUM MachineType_PersistentArbiter
686145Snate@binkert.org#else
696145Snate@binkert.org#define MACHINETYPE_PERSISTENTARBITER_ENUM MachineType_NUM
706145Snate@binkert.org#endif
716285Snate@binkert.org*/
726285Snate@binkert.org/*
736285Snate@binkert.orginline MachineID map_Address_to_L2Cache(const Address & addr)
746145Snate@binkert.org{
756285Snate@binkert.org  int L2bank = 0;
766285Snate@binkert.org  MachineID mach = {MACHINETYPE_L2CACHE_ENUM, 0};
776285Snate@binkert.org  L2bank = addr.bitSelect(RubySystem::getBlockSizeBits(),
786285Snate@binkert.org                          RubySystem::getBlockSizeBits() + RubyConfig::getNumberOfCachesPerLevel(2)-1);
796285Snate@binkert.org  mach.num = L2bank;
806285Snate@binkert.org  return mach;
816145Snate@binkert.org}
826145Snate@binkert.org
836145Snate@binkert.org// input parameter is the base ruby node of the L1 cache
846145Snate@binkert.org// returns a value between 0 and total_L2_Caches_within_the_system
856145Snate@binkert.orginline
866145Snate@binkert.orgMachineID map_L1CacheMachId_to_L2Cache(const Address& addr, MachineID L1CacheMachId)
876145Snate@binkert.org{
886285Snate@binkert.org  return map_Address_to_L2Cache(addr);
896285Snate@binkert.org
906145Snate@binkert.org  int L2bank = 0;
916145Snate@binkert.org  MachineID mach = {MACHINETYPE_L2CACHE_ENUM, 0};
926145Snate@binkert.org
936145Snate@binkert.org  if (RubyConfig::L2CachePerChipBits() > 0) {
946285Snate@binkert.org    if (RubyConfig::getMAP_L2BANKS_TO_LOWEST_BITS()) {
956285Snate@binkert.org      L2bank = addr.bitSelect(RubySystem::getBlockSizeBits(),
966285Snate@binkert.org                         RubySystem::getBlockSizeBits()+RubyConfig::L2CachePerChipBits()-1);
976145Snate@binkert.org    } else {
986285Snate@binkert.org      L2bank = addr.bitSelect(RubySystem::getBlockSizeBits()+RubyConfig::getL2_CACHE_NUM_SETS_BITS(),
996285Snate@binkert.org                         RubySystem::getBlockSizeBits()+RubyConfig::getL2_CACHE_NUM_SETS_BITS()+RubyConfig::L2CachePerChipBits()-1);
1006145Snate@binkert.org    }
1016145Snate@binkert.org  }
1026145Snate@binkert.org
1036145Snate@binkert.org  assert(L2bank < RubyConfig::numberOfL2CachePerChip());
1046145Snate@binkert.org  assert(L2bank >= 0);
1056145Snate@binkert.org
1066145Snate@binkert.org  mach.num = RubyConfig::L1CacheNumToL2Base(L1CacheMachId.num)*RubyConfig::numberOfL2CachePerChip() // base #
1076145Snate@binkert.org    + L2bank;  // bank #
1086145Snate@binkert.org  assert(mach.num < RubyConfig::numberOfL2Cache());
1096145Snate@binkert.org  return mach;
1106285Snate@binkert.org
1116145Snate@binkert.org}
1126145Snate@binkert.org
1136285Snate@binkert.org
1146145Snate@binkert.org// used to determine the correct L2 bank
1156145Snate@binkert.org// input parameter is the base ruby node of the L2 cache
1166145Snate@binkert.org// returns a value between 0 and total_L2_Caches_within_the_system
1176285Snate@binkert.org
1186145Snate@binkert.orginline
1196145Snate@binkert.orgMachineID map_L2ChipId_to_L2Cache(const Address& addr, NodeID L2ChipId)
1206145Snate@binkert.org{
1216285Snate@binkert.org  return map_Address_to_L2Cache(addr);
1226285Snate@binkert.org
1236145Snate@binkert.org  assert(L2ChipId < RubyConfig::numberOfChips());
1246145Snate@binkert.org
1256145Snate@binkert.org  int L2bank = 0;
1266145Snate@binkert.org  MachineID mach = {MACHINETYPE_L2CACHE_ENUM, 0};
1276285Snate@binkert.org  L2bank = addr.bitSelect(RubySystem::getBlockSizeBits(),
1286285Snate@binkert.org                          RubySystem::getBlockSizeBits() + RubyConfig::numberOfCachesPerLevel(2)-1);
1296285Snate@binkert.org  mach.num = L2bank;
1306285Snate@binkert.org  return mach
1316145Snate@binkert.org
1326285Snate@binkert.org}
1336285Snate@binkert.org  */
1346145Snate@binkert.org
1356145Snate@binkert.org
1366145Snate@binkert.org// used to determine the home directory
1376145Snate@binkert.org// returns a value between 0 and total_directories_within_the_system
1386145Snate@binkert.orginline
1396145Snate@binkert.orgNodeID map_Address_to_DirectoryNode(const Address& addr)
1406145Snate@binkert.org{
1416285Snate@binkert.org  return DirectoryMemory::mapAddressToDirectoryVersion(addr);
1426145Snate@binkert.org}
1436145Snate@binkert.org
1446145Snate@binkert.org// used to determine the home directory
1456145Snate@binkert.org// returns a value between 0 and total_directories_within_the_system
1466145Snate@binkert.orginline
1476145Snate@binkert.orgMachineID map_Address_to_Directory(const Address &addr)
1486145Snate@binkert.org{
1496145Snate@binkert.org  MachineID mach = {MachineType_Directory, map_Address_to_DirectoryNode(addr)};
1506145Snate@binkert.org  return mach;
1516145Snate@binkert.org}
1526145Snate@binkert.org
1536145Snate@binkert.orginline
1546285Snate@binkert.orgMachineID map_Address_to_DMA(const Address & addr)
1556145Snate@binkert.org{
1566285Snate@binkert.org  MachineID dma = {MachineType_DMA, 0};
1576285Snate@binkert.org  return dma;
1586145Snate@binkert.org}
1596145Snate@binkert.org
1606285Snate@binkert.org/*
1616145Snate@binkert.orginline
1626145Snate@binkert.orgNetDest getOtherLocalL1IDs(MachineID L1)
1636145Snate@binkert.org{
1646145Snate@binkert.org  int start = (L1.num / RubyConfig::numberOfProcsPerChip()) * RubyConfig::numberOfProcsPerChip();
1656145Snate@binkert.org  NetDest ret;
1666145Snate@binkert.org
1676145Snate@binkert.org  assert(MACHINETYPE_L1CACHE_ENUM != MachineType_NUM);
1686145Snate@binkert.org
1696145Snate@binkert.org  for (int i = start; i < (start + RubyConfig::numberOfProcsPerChip()); i++) {
1706145Snate@binkert.org    if (i != L1.num) {
1716145Snate@binkert.org      MachineID mach = { MACHINETYPE_L1CACHE_ENUM, i };
1726145Snate@binkert.org      ret.add( mach );
1736145Snate@binkert.org    }
1746145Snate@binkert.org  }
1756145Snate@binkert.org
1766145Snate@binkert.org  return ret;
1776145Snate@binkert.org}
1786285Snate@binkert.org*/
1796145Snate@binkert.org
1806145Snate@binkert.orgextern inline NodeID machineIDToNodeID(MachineID machID)
1816145Snate@binkert.org{
1826145Snate@binkert.org  // return machID.num%RubyConfig::numberOfChips();
1836145Snate@binkert.org  return machID.num;
1846145Snate@binkert.org}
1856145Snate@binkert.org
1866145Snate@binkert.orgextern inline MachineType machineIDToMachineType(MachineID machID)
1876145Snate@binkert.org{
1886145Snate@binkert.org  return machID.type;
1896145Snate@binkert.org}
1906145Snate@binkert.org
1916145Snate@binkert.orgextern inline NodeID L1CacheMachIDToProcessorNum(MachineID machID)
1926145Snate@binkert.org{
1936145Snate@binkert.org  assert(machID.type == MachineType_L1Cache);
1946145Snate@binkert.org  return machID.num;
1956145Snate@binkert.org}
1966285Snate@binkert.org/*
1976145Snate@binkert.orgextern inline NodeID L2CacheMachIDToChipID(MachineID machID)
1986145Snate@binkert.org{
1996145Snate@binkert.org  assert(machID.type == MACHINETYPE_L2CACHE_ENUM);
2006285Snate@binkert.org  int L2bank = machID.num;
2016285Snate@binkert.org  int banks_seen = 0;
2026285Snate@binkert.org  for (int i=0;i<RubyConfig::getNumberOfChips();i++) {
2036285Snate@binkert.org    for (int j=0;j<RubyConfig::getNumberOfCachesPerLevelPerChip(2,i);j++) {
2046285Snate@binkert.org      if (banks_seen == L2bank)
2056285Snate@binkert.org        return i;
2066285Snate@binkert.org      banks_seen++;
2076285Snate@binkert.org    }
2086285Snate@binkert.org  }
2096285Snate@binkert.org  assert(0);
2106145Snate@binkert.org}
2116285Snate@binkert.org*/
2126145Snate@binkert.orgextern inline MachineID getL1MachineID(NodeID L1RubyNode)
2136145Snate@binkert.org{
2146145Snate@binkert.org  MachineID mach = {MACHINETYPE_L1CACHE_ENUM, L1RubyNode};
2156145Snate@binkert.org  return mach;
2166145Snate@binkert.org}
2176145Snate@binkert.org
2186145Snate@binkert.orgextern inline GenericMachineType ConvertMachToGenericMach(MachineType machType) {
2196145Snate@binkert.org  if (machType == MACHINETYPE_L1CACHE_ENUM) {
2206145Snate@binkert.org    return GenericMachineType_L1Cache;
2216145Snate@binkert.org  } else if (machType == MACHINETYPE_L2CACHE_ENUM) {
2226145Snate@binkert.org    return GenericMachineType_L2Cache;
2236145Snate@binkert.org  } else if (machType == MACHINETYPE_L3CACHE_ENUM) {
2246145Snate@binkert.org    return GenericMachineType_L3Cache;
2256145Snate@binkert.org  } else if (machType == MachineType_Directory) {
2266145Snate@binkert.org    return GenericMachineType_Directory;
2276145Snate@binkert.org  } else {
2286145Snate@binkert.org    ERROR_MSG("cannot convert to a GenericMachineType");
2296145Snate@binkert.org    return GenericMachineType_NULL;
2306145Snate@binkert.org  }
2316145Snate@binkert.org}
2326145Snate@binkert.org
2336145Snate@binkert.org
2346145Snate@binkert.org#endif  // COMPONENTMAPPINGFNS_H
235