MemConfig.py revision 9728
19665Sandreas.hansson@arm.com# Copyright (c) 2013 ARM Limited
29520SN/A# All rights reserved.
39520SN/A#
49520SN/A# The license below extends only to copyright in the software and shall
59520SN/A# not be construed as granting a license to any other intellectual
69520SN/A# property including but not limited to intellectual property relating
79520SN/A# to a hardware implementation of the functionality of the software
89520SN/A# licensed hereunder.  You may use the software subject to the license
99520SN/A# terms below provided that you ensure that this notice is replicated
109520SN/A# unmodified and in its entirety in all distributions of the software,
119520SN/A# modified or unmodified, in source code or in binary form.
129520SN/A#
139520SN/A# Redistribution and use in source and binary forms, with or without
149520SN/A# modification, are permitted provided that the following conditions are
159520SN/A# met: redistributions of source code must retain the above copyright
169520SN/A# notice, this list of conditions and the following disclaimer;
179520SN/A# redistributions in binary form must reproduce the above copyright
189520SN/A# notice, this list of conditions and the following disclaimer in the
199520SN/A# documentation and/or other materials provided with the distribution;
209520SN/A# neither the name of the copyright holders nor the names of its
219520SN/A# contributors may be used to endorse or promote products derived from
229520SN/A# this software without specific prior written permission.
239520SN/A#
249520SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
259520SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
269520SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
279520SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
289520SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
299520SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
309520SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
319520SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
329520SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
339520SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
349520SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
359520SN/A#
369520SN/A# Authors: Andreas Sandberg
379665Sandreas.hansson@arm.com#          Andreas Hansson
389520SN/A
399520SN/Aimport m5.objects
409520SN/Aimport inspect
419520SN/Aimport sys
429520SN/Afrom textwrap import  TextWrapper
439520SN/A
449665Sandreas.hansson@arm.com# Dictionary of mapping names of real memory controller models to
459665Sandreas.hansson@arm.com# classes.
469665Sandreas.hansson@arm.com_mem_classes = {}
479520SN/A
489665Sandreas.hansson@arm.com# Memory aliases. We make sure they exist before we add them to the
499665Sandreas.hansson@arm.com# fina; list. A target may be specified as a tuple, in which case the
509665Sandreas.hansson@arm.com# first available memory controller model in the tuple will be used.
519665Sandreas.hansson@arm.com_mem_aliases_all = [
529665Sandreas.hansson@arm.com    ("simple_mem", "SimpleMemory"),
539728Sandreas.hansson@arm.com    ("ddr3_1600_x64", "DDR3_1600_x64"),
549728Sandreas.hansson@arm.com    ("lpddr2_s4_1066_x32", "LPDDR2_S4_1066_x32"),
559728Sandreas.hansson@arm.com    ("lpddr3_1600_x32", "LPDDR3_1600_x32"),
569728Sandreas.hansson@arm.com    ("wio_200_x128", "WideIO_200_x128"),
579520SN/A    ]
589520SN/A
599665Sandreas.hansson@arm.com# Filtered list of aliases. Only aliases for existing memory
609665Sandreas.hansson@arm.com# controllers exist in this list.
619665Sandreas.hansson@arm.com_mem_aliases = {}
629520SN/A
639520SN/A
649665Sandreas.hansson@arm.comdef is_mem_class(cls):
659665Sandreas.hansson@arm.com    """Determine if a class is a memory controller that can be instantiated"""
669520SN/A
679520SN/A    # We can't use the normal inspect.isclass because the ParamFactory
689520SN/A    # and ProxyFactory classes have a tendency to confuse it.
699520SN/A    try:
709665Sandreas.hansson@arm.com        return issubclass(cls, m5.objects.AbstractMemory) and \
719665Sandreas.hansson@arm.com            not cls.abstract
729520SN/A    except TypeError:
739520SN/A        return False
749520SN/A
759520SN/Adef get(name):
769665Sandreas.hansson@arm.com    """Get a memory class from a user provided class name or alias."""
779520SN/A
789665Sandreas.hansson@arm.com    real_name = _mem_aliases.get(name, name)
799520SN/A
809520SN/A    try:
819665Sandreas.hansson@arm.com        mem_class = _mem_classes[real_name]
829665Sandreas.hansson@arm.com        return mem_class
839520SN/A    except KeyError:
849665Sandreas.hansson@arm.com        print "%s is not a valid memory controller." % (name,)
859520SN/A        sys.exit(1)
869520SN/A
879665Sandreas.hansson@arm.comdef print_mem_list():
889665Sandreas.hansson@arm.com    """Print a list of available memory classes including their aliases."""
899520SN/A
909665Sandreas.hansson@arm.com    print "Available memory classes:"
919520SN/A    doc_wrapper = TextWrapper(initial_indent="\t\t", subsequent_indent="\t\t")
929665Sandreas.hansson@arm.com    for name, cls in _mem_classes.items():
939520SN/A        print "\t%s" % name
949520SN/A
959520SN/A        # Try to extract the class documentation from the class help
969520SN/A        # string.
979520SN/A        doc = inspect.getdoc(cls)
989520SN/A        if doc:
999520SN/A            for line in doc_wrapper.wrap(doc):
1009520SN/A                print line
1019520SN/A
1029665Sandreas.hansson@arm.com    if _mem_aliases:
1039665Sandreas.hansson@arm.com        print "\nMemory aliases:"
1049665Sandreas.hansson@arm.com        for alias, target in _mem_aliases.items():
1059520SN/A            print "\t%s => %s" % (alias, target)
1069520SN/A
1079665Sandreas.hansson@arm.comdef mem_names():
1089665Sandreas.hansson@arm.com    """Return a list of valid memory names."""
1099665Sandreas.hansson@arm.com    return _mem_classes.keys() + _mem_aliases.keys()
1109520SN/A
1119665Sandreas.hansson@arm.com# Add all memory controllers in the object hierarchy.
1129665Sandreas.hansson@arm.comfor name, cls in inspect.getmembers(m5.objects, is_mem_class):
1139665Sandreas.hansson@arm.com    _mem_classes[name] = cls
1149520SN/A
1159665Sandreas.hansson@arm.comfor alias, target in _mem_aliases_all:
1169520SN/A    if isinstance(target, tuple):
1179665Sandreas.hansson@arm.com        # Some aliases contain a list of memory controller models
1189665Sandreas.hansson@arm.com        # sorted in priority order. Use the first target that's
1199665Sandreas.hansson@arm.com        # available.
1209520SN/A        for t in target:
1219665Sandreas.hansson@arm.com            if t in _mem_classes:
1229665Sandreas.hansson@arm.com                _mem_aliases[alias] = t
1239520SN/A                break
1249665Sandreas.hansson@arm.com    elif target in _mem_classes:
1259520SN/A        # Normal alias
1269665Sandreas.hansson@arm.com        _mem_aliases[alias] = target
127