RubySlicc_ComponentMapping.hh revision 6843
112855Sgabeblack@google.com
212855Sgabeblack@google.com/*
312855Sgabeblack@google.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
412855Sgabeblack@google.com * All rights reserved.
512855Sgabeblack@google.com *
612855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
712855Sgabeblack@google.com * modification, are permitted provided that the following conditions are
812855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
912855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
1012855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1112855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1212855Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1312855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1412855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1512855Sgabeblack@google.com * this software without specific prior written permission.
1612855Sgabeblack@google.com *
1712855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1812855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1912855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2012855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2112855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2212855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2312855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2412855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2512855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2612855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2712855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2812855Sgabeblack@google.com */
2912855Sgabeblack@google.com
3012855Sgabeblack@google.com/*
3112855Sgabeblack@google.com * $Id$
3212855Sgabeblack@google.com */
3312855Sgabeblack@google.com
3412855Sgabeblack@google.com#ifndef COMPONENTMAPPINGFNS_H
3512855Sgabeblack@google.com#define COMPONENTMAPPINGFNS_H
3612855Sgabeblack@google.com
3712855Sgabeblack@google.com#include "mem/ruby/common/Global.hh"
3812855Sgabeblack@google.com#include "mem/ruby/system/NodeID.hh"
3912855Sgabeblack@google.com#include "mem/ruby/system/MachineID.hh"
4012855Sgabeblack@google.com#include "mem/ruby/common/Address.hh"
4112855Sgabeblack@google.com#include "mem/ruby/common/Set.hh"
4212855Sgabeblack@google.com#include "mem/ruby/common/NetDest.hh"
4312855Sgabeblack@google.com#include "mem/protocol/GenericMachineType.hh"
4412855Sgabeblack@google.com#include "mem/ruby/system/DirectoryMemory.hh"
4512855Sgabeblack@google.com
4612855Sgabeblack@google.com#ifdef MACHINETYPE_L1Cache
4712855Sgabeblack@google.com#define MACHINETYPE_L1CACHE_ENUM MachineType_L1Cache
4812855Sgabeblack@google.com#else
4912855Sgabeblack@google.com#define MACHINETYPE_L1CACHE_ENUM MachineType_NUM
5012855Sgabeblack@google.com#endif
5112855Sgabeblack@google.com
5212855Sgabeblack@google.com#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