RubySlicc_ComponentMapping.hh revision 6843:de4b394c6792
1 2/* 3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer; 10 * redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution; 13 * neither the name of the copyright holders nor the names of its 14 * contributors may be used to endorse or promote products derived from 15 * this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30/* 31 * $Id$ 32 */ 33 34#ifndef COMPONENTMAPPINGFNS_H 35#define COMPONENTMAPPINGFNS_H 36 37#include "mem/ruby/common/Global.hh" 38#include "mem/ruby/system/NodeID.hh" 39#include "mem/ruby/system/MachineID.hh" 40#include "mem/ruby/common/Address.hh" 41#include "mem/ruby/common/Set.hh" 42#include "mem/ruby/common/NetDest.hh" 43#include "mem/protocol/GenericMachineType.hh" 44#include "mem/ruby/system/DirectoryMemory.hh" 45 46#ifdef MACHINETYPE_L1Cache 47#define MACHINETYPE_L1CACHE_ENUM MachineType_L1Cache 48#else 49#define MACHINETYPE_L1CACHE_ENUM MachineType_NUM 50#endif 51 52#ifdef MACHINETYPE_L2Cache 53#define MACHINETYPE_L2CACHE_ENUM MachineType_L2Cache 54#else 55#define MACHINETYPE_L2CACHE_ENUM MachineType_NUM 56#endif 57 58#ifdef MACHINETYPE_L3Cache 59#define MACHINETYPE_L3CACHE_ENUM MachineType_L3Cache 60#else 61#define MACHINETYPE_L3CACHE_ENUM MachineType_NUM 62#endif 63 64// used to determine the home directory 65// returns a value between 0 and total_directories_within_the_system 66inline 67NodeID map_Address_to_DirectoryNode(const Address& addr) 68{ 69 return DirectoryMemory::mapAddressToDirectoryVersion(addr); 70} 71 72// used to determine the home directory 73// returns a value between 0 and total_directories_within_the_system 74inline 75MachineID map_Address_to_Directory(const Address &addr) 76{ 77 MachineID mach = {MachineType_Directory, map_Address_to_DirectoryNode(addr)}; 78 return mach; 79} 80 81inline 82MachineID map_Address_to_DMA(const Address & addr) 83{ 84 MachineID dma = {MachineType_DMA, 0}; 85 return dma; 86} 87 88inline 89NetDest broadcast(MachineType type) 90{ 91 NetDest dest; 92 for (int i=0; i<MachineType_base_count(type); i++) { 93 MachineID mach = {type, i}; 94 dest.add(mach); 95 } 96 return dest; 97} 98 99inline 100MachineID mapAddressToRange(const Address & addr, MachineType type, int low_bit, int num_bits) 101{ 102 MachineID mach = {type, 0}; 103 if (num_bits == 0) 104 return mach; 105 mach.num = addr.bitSelect(low_bit, low_bit+num_bits-1); 106 return mach; 107} 108 109extern inline NodeID machineIDToNodeID(MachineID machID) 110{ 111 return machID.num; 112} 113 114extern inline MachineType machineIDToMachineType(MachineID machID) 115{ 116 return machID.type; 117} 118 119extern inline NodeID L1CacheMachIDToProcessorNum(MachineID machID) 120{ 121 assert(machID.type == MachineType_L1Cache); 122 return machID.num; 123} 124 125extern inline MachineID getL1MachineID(NodeID L1RubyNode) 126{ 127 MachineID mach = {MACHINETYPE_L1CACHE_ENUM, L1RubyNode}; 128 return mach; 129} 130 131extern inline GenericMachineType ConvertMachToGenericMach(MachineType machType) { 132 if (machType == MACHINETYPE_L1CACHE_ENUM) { 133 return GenericMachineType_L1Cache; 134 } else if (machType == MACHINETYPE_L2CACHE_ENUM) { 135 return GenericMachineType_L2Cache; 136 } else if (machType == MACHINETYPE_L3CACHE_ENUM) { 137 return GenericMachineType_L3Cache; 138 } else if (machType == MachineType_Directory) { 139 return GenericMachineType_Directory; 140 } else { 141 ERROR_MSG("cannot convert to a GenericMachineType"); 142 return GenericMachineType_NULL; 143 } 144} 145 146 147#endif // COMPONENTMAPPINGFNS_H 148