FSConfig.py revision 10118:5e1f04b4d5e4
12315SN/A# Copyright (c) 2010-2012 ARM Limited
213953Sgiacomo.gabrielli@arm.com# All rights reserved.
39920Syasuko.eckert@amd.com#
48733Sgeoffrey.blake@arm.com# The license below extends only to copyright in the software and shall
58733Sgeoffrey.blake@arm.com# not be construed as granting a license to any other intellectual
68733Sgeoffrey.blake@arm.com# property including but not limited to intellectual property relating
78733Sgeoffrey.blake@arm.com# to a hardware implementation of the functionality of the software
88733Sgeoffrey.blake@arm.com# licensed hereunder.  You may use the software subject to the license
98733Sgeoffrey.blake@arm.com# terms below provided that you ensure that this notice is replicated
108733Sgeoffrey.blake@arm.com# unmodified and in its entirety in all distributions of the software,
118733Sgeoffrey.blake@arm.com# modified or unmodified, in source code or in binary form.
128733Sgeoffrey.blake@arm.com#
138733Sgeoffrey.blake@arm.com# Copyright (c) 2010-2011 Advanced Micro Devices, Inc.
148733Sgeoffrey.blake@arm.com# Copyright (c) 2006-2008 The Regents of The University of Michigan
152332SN/A# All rights reserved.
162315SN/A#
172315SN/A# Redistribution and use in source and binary forms, with or without
182315SN/A# modification, are permitted provided that the following conditions are
192315SN/A# met: redistributions of source code must retain the above copyright
202315SN/A# notice, this list of conditions and the following disclaimer;
212315SN/A# redistributions in binary form must reproduce the above copyright
222315SN/A# notice, this list of conditions and the following disclaimer in the
232315SN/A# documentation and/or other materials provided with the distribution;
242315SN/A# neither the name of the copyright holders nor the names of its
252315SN/A# contributors may be used to endorse or promote products derived from
262315SN/A# this software without specific prior written permission.
272315SN/A#
282315SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292315SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302315SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312315SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322315SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332315SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342315SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352315SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362315SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372315SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382315SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392315SN/A#
402689Sktlim@umich.edu# Authors: Kevin Lim
412689Sktlim@umich.edu
422315SN/Afrom m5.objects import *
432315SN/Afrom Benchmarks import *
442315SN/Afrom m5.util import *
452315SN/A
462315SN/Aclass CowIdeDisk(IdeDisk):
472315SN/A    image = CowDiskImage(child=RawDiskImage(read_only=True),
488229Snate@binkert.org                         read_only=False)
492315SN/A
502315SN/A    def childImage(self, ci):
512669Sktlim@umich.edu        self.image.child.image_file = ci
522315SN/A
532315SN/Aclass MemBus(CoherentBus):
542315SN/A    badaddr_responder = BadAddr()
5510319SAndreas.Sandberg@ARM.com    default = Self.badaddr_responder.pio
5612107SRekai.GonzalezAlberquilla@arm.com
578229Snate@binkert.org
582683Sktlim@umich.edudef makeLinuxAlphaSystem(mem_mode, mdesc = None, ruby = False):
592315SN/A
608733Sgeoffrey.blake@arm.com    class BaseTsunami(Tsunami):
6111608Snikos.nikoleris@arm.com        ethernet = NSGigE(pci_bus=0, pci_dev=1, pci_func=0)
628733Sgeoffrey.blake@arm.com        ide = IdeController(disks=[Parent.disk0, Parent.disk2],
632315SN/A                            pci_func=0, pci_dev=0, pci_bus=0)
642315SN/A
6512406Sgabeblack@google.com    self = LinuxAlphaSystem()
662315SN/A    if not mdesc:
672315SN/A        # generic system
682680Sktlim@umich.edu        mdesc = SysConfig()
692669Sktlim@umich.edu    self.readfile = mdesc.script()
702315SN/A
712350SN/A    self.tsunami = BaseTsunami()
722350SN/A
732350SN/A    # Create the io bus to connect all device ports
742350SN/A    self.iobus = NoncoherentBus()
752350SN/A    self.tsunami.attachIO(self.iobus)
762350SN/A
772350SN/A    self.tsunami.ide.pio = self.iobus.master
782350SN/A    self.tsunami.ide.config = self.iobus.master
792350SN/A
802350SN/A    self.tsunami.ethernet.pio = self.iobus.master
812680Sktlim@umich.edu    self.tsunami.ethernet.config = self.iobus.master
822683Sktlim@umich.edu
832680Sktlim@umich.edu    if ruby:
842350SN/A        # Store the dma devices for later connection to dma ruby ports.
852680Sktlim@umich.edu        # Append an underscore to dma_ports to avoid the SimObjectVector check.
862350SN/A        self._dma_ports = [self.tsunami.ide.dma, self.tsunami.ethernet.dma]
8710319SAndreas.Sandberg@ARM.com    else:
882315SN/A        self.membus = MemBus()
892315SN/A
902315SN/A        # By default the bridge responds to all addresses above the I/O
9112109SRekai.GonzalezAlberquilla@arm.com        # base address (including the PCI config space)
928832SAli.Saidi@ARM.com        IO_address_space_base = 0x80000000000
938832SAli.Saidi@ARM.com        self.bridge = Bridge(delay='50ns',
948832SAli.Saidi@ARM.com                         ranges = [AddrRange(IO_address_space_base, Addr.max)])
952315SN/A        self.bridge.master = self.iobus.slave
9611169Sandreas.hansson@arm.com        self.bridge.slave = self.membus.master
972315SN/A
985529Snate@binkert.org        self.tsunami.ide.dma = self.iobus.slave
992315SN/A        self.tsunami.ethernet.dma = self.iobus.slave
1002315SN/A
1012315SN/A        self.system_port = self.membus.slave
1022315SN/A
1032315SN/A    self.mem_ranges = [AddrRange(mdesc.mem())]
1049608Sandreas.hansson@arm.com    self.disk0 = CowIdeDisk(driveID='master')
1052679Sktlim@umich.edu    self.disk2 = CowIdeDisk(driveID='master')
1069608Sandreas.hansson@arm.com    self.disk0.childImage(mdesc.disk())
1072679Sktlim@umich.edu    self.disk2.childImage(disk('linux-bigswap2.img'))
10811169Sandreas.hansson@arm.com    self.simple_disk = SimpleDisk(disk=RawDiskImage(image_file = mdesc.disk(),
1098887Sgeoffrey.blake@arm.com                                               read_only = True))
1109176Sandreas.hansson@arm.com    self.intrctrl = IntrControl()
1119176Sandreas.hansson@arm.com    self.mem_mode = mem_mode
1129176Sandreas.hansson@arm.com    self.terminal = Terminal()
1138887Sgeoffrey.blake@arm.com    self.kernel = binary('vmlinux')
1148887Sgeoffrey.blake@arm.com    self.pal = binary('ts_osfpal')
1158887Sgeoffrey.blake@arm.com    self.console = binary('console')
11611169Sandreas.hansson@arm.com    self.boot_osflags = 'root=/dev/hda1 console=ttyS0'
1178887Sgeoffrey.blake@arm.com
1189176Sandreas.hansson@arm.com    return self
1199176Sandreas.hansson@arm.com
1209176Sandreas.hansson@arm.comdef makeSparcSystem(mem_mode, mdesc = None):
1218887Sgeoffrey.blake@arm.com    # Constants from iob.cc and uart8250.cc
1228887Sgeoffrey.blake@arm.com    iob_man_addr = 0x9800000000
1232679Sktlim@umich.edu    uart_pio_size = 8
1249176Sandreas.hansson@arm.com
1259176Sandreas.hansson@arm.com    class CowMmDisk(MmDisk):
1269176Sandreas.hansson@arm.com        image = CowDiskImage(child=RawDiskImage(read_only=True),
1279176Sandreas.hansson@arm.com                             read_only=False)
1289176Sandreas.hansson@arm.com
1299176Sandreas.hansson@arm.com        def childImage(self, ci):
1309608Sandreas.hansson@arm.com            self.image.child.image_file = ci
1319608Sandreas.hansson@arm.com
1322315SN/A    self = SparcSystem()
1332680Sktlim@umich.edu    if not mdesc:
1342315SN/A        # generic system
13512406Sgabeblack@google.com        mdesc = SysConfig()
13612406Sgabeblack@google.com    self.readfile = mdesc.script()
1372315SN/A    self.iobus = NoncoherentBus()
1382315SN/A    self.membus = MemBus()
1392315SN/A    self.bridge = Bridge(delay='50ns')
1408733Sgeoffrey.blake@arm.com    self.t1000 = T1000()
1418733Sgeoffrey.blake@arm.com    self.t1000.attachOnChipIO(self.membus)
14212107SRekai.GonzalezAlberquilla@arm.com    self.t1000.attachIO(self.iobus)
1432315SN/A    self.mem_ranges = [AddrRange(Addr('1MB'), size = '64MB'),
1442315SN/A                       AddrRange(Addr('2GB'), size ='256MB')]
1458733Sgeoffrey.blake@arm.com    self.bridge.master = self.iobus.slave
1462315SN/A    self.bridge.slave = self.membus.master
1472315SN/A    self.rom.port = self.membus.master
1482315SN/A    self.nvram.port = self.membus.master
1492315SN/A    self.hypervisor_desc.port = self.membus.master
1502315SN/A    self.partition_desc.port = self.membus.master
1512315SN/A    self.intrctrl = IntrControl()
1522315SN/A    self.disk0 = CowMmDisk()
1539176Sandreas.hansson@arm.com    self.disk0.childImage(disk('disk.s10hw2'))
1549176Sandreas.hansson@arm.com    self.disk0.pio = self.iobus.master
1559176Sandreas.hansson@arm.com
1569176Sandreas.hansson@arm.com    # The puart0 and hvuart are placed on the IO bus, so create ranges
1579176Sandreas.hansson@arm.com    # for them. The remaining IO range is rather fragmented, so poke
15812406Sgabeblack@google.com    # holes for the iob and partition descriptors etc.
15912406Sgabeblack@google.com    self.bridge.ranges = \
1608733Sgeoffrey.blake@arm.com        [
16111169Sandreas.hansson@arm.com        AddrRange(self.t1000.puart0.pio_addr,
1628887Sgeoffrey.blake@arm.com                  self.t1000.puart0.pio_addr + uart_pio_size - 1),
1638887Sgeoffrey.blake@arm.com        AddrRange(self.disk0.pio_addr,
1648887Sgeoffrey.blake@arm.com                  self.t1000.fake_jbi.pio_addr +
1658887Sgeoffrey.blake@arm.com                  self.t1000.fake_jbi.pio_size - 1),
16611169Sandreas.hansson@arm.com        AddrRange(self.t1000.fake_clk.pio_addr,
1672315SN/A                  iob_man_addr - 1),
1682930Sktlim@umich.edu        AddrRange(self.t1000.fake_l2_1.pio_addr,
1692315SN/A                  self.t1000.fake_ssi.pio_addr +
1702315SN/A                  self.t1000.fake_ssi.pio_size - 1),
1712315SN/A        AddrRange(self.t1000.hvuart.pio_addr,
1722315SN/A                  self.t1000.hvuart.pio_addr + uart_pio_size - 1)
1732315SN/A        ]
1742315SN/A    self.reset_bin = binary('reset_new.bin')
17511168Sandreas.hansson@arm.com    self.hypervisor_bin = binary('q_new.bin')
17611168Sandreas.hansson@arm.com    self.openboot_bin = binary('openboot_new.bin')
1772315SN/A    self.nvram_bin = binary('nvram1')
1782315SN/A    self.hypervisor_desc_bin = binary('1up-hv.bin')
1792315SN/A    self.partition_desc_bin = binary('1up-md.bin')
1802315SN/A
1812315SN/A    self.system_port = self.membus.slave
1822315SN/A
1832315SN/A    return self
1842315SN/A
1852315SN/Adef makeArmSystem(mem_mode, machine_type, mdesc = None,
1862315SN/A                  dtb_filename = None, bare_metal=False):
1872315SN/A    assert machine_type
1882315SN/A
18913557Sgabeblack@google.com    if bare_metal:
19013557Sgabeblack@google.com        self = ArmSystem()
1912315SN/A    else:
19212106SRekai.GonzalezAlberquilla@arm.com        self = LinuxArmSystem()
19312106SRekai.GonzalezAlberquilla@arm.com
19412106SRekai.GonzalezAlberquilla@arm.com    if not mdesc:
1952315SN/A        # generic system
1962315SN/A        mdesc = SysConfig()
19713557Sgabeblack@google.com
19813557Sgabeblack@google.com    self.readfile = mdesc.script()
1992669Sktlim@umich.edu    self.iobus = NoncoherentBus()
20012106SRekai.GonzalezAlberquilla@arm.com    self.membus = MemBus()
20112106SRekai.GonzalezAlberquilla@arm.com    self.membus.badaddr_responder.warn_access = "warn"
20213611Sgabeblack@google.com    self.bridge = Bridge(delay='50ns')
2032315SN/A    self.bridge.master = self.iobus.slave
2042315SN/A    self.bridge.slave = self.membus.master
20512109SRekai.GonzalezAlberquilla@arm.com
20612109SRekai.GonzalezAlberquilla@arm.com    self.mem_mode = mem_mode
20712109SRekai.GonzalezAlberquilla@arm.com
20813557Sgabeblack@google.com    if machine_type == "RealView_PBX":
20913557Sgabeblack@google.com        self.realview = RealViewPBX()
21012109SRekai.GonzalezAlberquilla@arm.com    elif machine_type == "RealView_EB":
21112109SRekai.GonzalezAlberquilla@arm.com        self.realview = RealViewEB()
21212109SRekai.GonzalezAlberquilla@arm.com    elif machine_type == "VExpress_ELT":
21312109SRekai.GonzalezAlberquilla@arm.com        self.realview = VExpress_ELT()
21412109SRekai.GonzalezAlberquilla@arm.com    elif machine_type == "VExpress_EMM":
21512109SRekai.GonzalezAlberquilla@arm.com        self.realview = VExpress_EMM()
21612109SRekai.GonzalezAlberquilla@arm.com    elif machine_type == "VExpress_EMM64":
21712109SRekai.GonzalezAlberquilla@arm.com        self.realview = VExpress_EMM64()
21812109SRekai.GonzalezAlberquilla@arm.com    else:
21913557Sgabeblack@google.com        print "Unknown Machine Type"
22013557Sgabeblack@google.com        sys.exit(1)
22112109SRekai.GonzalezAlberquilla@arm.com
22212109SRekai.GonzalezAlberquilla@arm.com    self.cf0 = CowIdeDisk(driveID='master')
22312109SRekai.GonzalezAlberquilla@arm.com    self.cf0.childImage(mdesc.disk())
22412109SRekai.GonzalezAlberquilla@arm.com    # default to an IDE controller rather than a CF one
22512109SRekai.GonzalezAlberquilla@arm.com    # assuming we've got one; EMM64 is an exception for the moment
22612109SRekai.GonzalezAlberquilla@arm.com    if machine_type != "VExpress_EMM64":
22712109SRekai.GonzalezAlberquilla@arm.com        try:
22812109SRekai.GonzalezAlberquilla@arm.com            self.realview.ide.disks = [self.cf0]
22912109SRekai.GonzalezAlberquilla@arm.com        except:
23012109SRekai.GonzalezAlberquilla@arm.com            self.realview.cf_ctrl.disks = [self.cf0]
23113557Sgabeblack@google.com    else:
23212109SRekai.GonzalezAlberquilla@arm.com        self.realview.cf_ctrl.disks = [self.cf0]
23312109SRekai.GonzalezAlberquilla@arm.com
23412109SRekai.GonzalezAlberquilla@arm.com    if bare_metal:
23512109SRekai.GonzalezAlberquilla@arm.com        # EOT character on UART will end the simulation
23612109SRekai.GonzalezAlberquilla@arm.com        self.realview.uart.end_on_eot = True
23712109SRekai.GonzalezAlberquilla@arm.com        self.mem_ranges = [AddrRange(self.realview.mem_start_addr,
23812109SRekai.GonzalezAlberquilla@arm.com                                     size = mdesc.mem())]
23912109SRekai.GonzalezAlberquilla@arm.com    else:
24013557Sgabeblack@google.com        self.kernel = binary('vmlinux.arm.smp.fb.2.6.38.8')
24112109SRekai.GonzalezAlberquilla@arm.com        if dtb_filename:
24212109SRekai.GonzalezAlberquilla@arm.com            self.dtb_filename = binary(dtb_filename)
24312109SRekai.GonzalezAlberquilla@arm.com        self.machine_type = machine_type
24412109SRekai.GonzalezAlberquilla@arm.com        if convert.toMemorySize(mdesc.mem()) > int(self.realview.max_mem_size):
24512109SRekai.GonzalezAlberquilla@arm.com            print "The currently selected ARM platforms doesn't support"
24612109SRekai.GonzalezAlberquilla@arm.com            print " the amount of DRAM you've selected. Please try"
24712109SRekai.GonzalezAlberquilla@arm.com            print " another platform"
24812109SRekai.GonzalezAlberquilla@arm.com            sys.exit(1)
24913557Sgabeblack@google.com
25012109SRekai.GonzalezAlberquilla@arm.com        # Ensure that writes to the UART actually go out early in the boot
25112109SRekai.GonzalezAlberquilla@arm.com        boot_flags = 'earlyprintk=pl011,0x1c090000 console=ttyAMA0 ' + \
25212109SRekai.GonzalezAlberquilla@arm.com                     'lpj=19988480 norandmaps rw loglevel=8 ' + \
25312109SRekai.GonzalezAlberquilla@arm.com                     'mem=%s root=/dev/sda1' % mdesc.mem()
25412109SRekai.GonzalezAlberquilla@arm.com
25512109SRekai.GonzalezAlberquilla@arm.com        self.mem_ranges = [AddrRange(self.realview.mem_start_addr,
25612109SRekai.GonzalezAlberquilla@arm.com                                     size = mdesc.mem())]
25712109SRekai.GonzalezAlberquilla@arm.com        self.realview.setupBootLoader(self.membus, self, binary)
25813557Sgabeblack@google.com        self.gic_cpu_addr = self.realview.gic.cpu_addr
25912109SRekai.GonzalezAlberquilla@arm.com        self.flags_addr = self.realview.realview_io.pio_addr + 0x30
26012109SRekai.GonzalezAlberquilla@arm.com
26112109SRekai.GonzalezAlberquilla@arm.com        if mdesc.disk().lower().count('android'):
26212109SRekai.GonzalezAlberquilla@arm.com            boot_flags += " init=/init "
26312109SRekai.GonzalezAlberquilla@arm.com        self.boot_osflags = boot_flags
26412109SRekai.GonzalezAlberquilla@arm.com    self.realview.attachOnChipIO(self.membus, self.bridge)
26512109SRekai.GonzalezAlberquilla@arm.com    self.realview.attachIO(self.iobus)
26612109SRekai.GonzalezAlberquilla@arm.com    self.intrctrl = IntrControl()
26712109SRekai.GonzalezAlberquilla@arm.com    self.terminal = Terminal()
26812109SRekai.GonzalezAlberquilla@arm.com    self.vncserver = VncServer()
26912109SRekai.GonzalezAlberquilla@arm.com
27012109SRekai.GonzalezAlberquilla@arm.com    self.system_port = self.membus.slave
27112109SRekai.GonzalezAlberquilla@arm.com
27212109SRekai.GonzalezAlberquilla@arm.com    return self
27312109SRekai.GonzalezAlberquilla@arm.com
27412109SRekai.GonzalezAlberquilla@arm.com
27512109SRekai.GonzalezAlberquilla@arm.comdef makeLinuxMipsSystem(mem_mode, mdesc = None):
27612109SRekai.GonzalezAlberquilla@arm.com    class BaseMalta(Malta):
27712109SRekai.GonzalezAlberquilla@arm.com        ethernet = NSGigE(pci_bus=0, pci_dev=1, pci_func=0)
27812109SRekai.GonzalezAlberquilla@arm.com        ide = IdeController(disks=[Parent.disk0, Parent.disk2],
27912109SRekai.GonzalezAlberquilla@arm.com                            pci_func=0, pci_dev=0, pci_bus=0)
28012109SRekai.GonzalezAlberquilla@arm.com
28112109SRekai.GonzalezAlberquilla@arm.com    self = LinuxMipsSystem()
28212109SRekai.GonzalezAlberquilla@arm.com    if not mdesc:
28312109SRekai.GonzalezAlberquilla@arm.com        # generic system
28412109SRekai.GonzalezAlberquilla@arm.com        mdesc = SysConfig()
28512109SRekai.GonzalezAlberquilla@arm.com    self.readfile = mdesc.script()
28612109SRekai.GonzalezAlberquilla@arm.com    self.iobus = NoncoherentBus()
28712109SRekai.GonzalezAlberquilla@arm.com    self.membus = MemBus()
28812109SRekai.GonzalezAlberquilla@arm.com    self.bridge = Bridge(delay='50ns')
28912109SRekai.GonzalezAlberquilla@arm.com    self.mem_ranges = [AddrRange('1GB')]
29012109SRekai.GonzalezAlberquilla@arm.com    self.bridge.master = self.iobus.slave
29112109SRekai.GonzalezAlberquilla@arm.com    self.bridge.slave = self.membus.master
29212109SRekai.GonzalezAlberquilla@arm.com    self.disk0 = CowIdeDisk(driveID='master')
29312109SRekai.GonzalezAlberquilla@arm.com    self.disk2 = CowIdeDisk(driveID='master')
29412109SRekai.GonzalezAlberquilla@arm.com    self.disk0.childImage(mdesc.disk())
29512109SRekai.GonzalezAlberquilla@arm.com    self.disk2.childImage(disk('linux-bigswap2.img'))
29612109SRekai.GonzalezAlberquilla@arm.com    self.malta = BaseMalta()
29712109SRekai.GonzalezAlberquilla@arm.com    self.malta.attachIO(self.iobus)
29812109SRekai.GonzalezAlberquilla@arm.com    self.malta.ide.pio = self.iobus.master
29912109SRekai.GonzalezAlberquilla@arm.com    self.malta.ide.config = self.iobus.master
30013557Sgabeblack@google.com    self.malta.ide.dma = self.iobus.slave
30113557Sgabeblack@google.com    self.malta.ethernet.pio = self.iobus.master
30212109SRekai.GonzalezAlberquilla@arm.com    self.malta.ethernet.config = self.iobus.master
30312109SRekai.GonzalezAlberquilla@arm.com    self.malta.ethernet.dma = self.iobus.slave
30412109SRekai.GonzalezAlberquilla@arm.com    self.simple_disk = SimpleDisk(disk=RawDiskImage(image_file = mdesc.disk(),
30512109SRekai.GonzalezAlberquilla@arm.com                                               read_only = True))
30612109SRekai.GonzalezAlberquilla@arm.com    self.intrctrl = IntrControl()
30713610Sgiacomo.gabrielli@arm.com    self.mem_mode = mem_mode
30813610Sgiacomo.gabrielli@arm.com    self.terminal = Terminal()
30913610Sgiacomo.gabrielli@arm.com    self.kernel = binary('mips/vmlinux')
31013610Sgiacomo.gabrielli@arm.com    self.console = binary('mips/console')
31113610Sgiacomo.gabrielli@arm.com    self.boot_osflags = 'root=/dev/hda1 console=ttyS0'
31213610Sgiacomo.gabrielli@arm.com
31313610Sgiacomo.gabrielli@arm.com    self.system_port = self.membus.slave
31413610Sgiacomo.gabrielli@arm.com
31513610Sgiacomo.gabrielli@arm.com    return self
31613610Sgiacomo.gabrielli@arm.com
31713610Sgiacomo.gabrielli@arm.comdef x86IOAddress(port):
31813610Sgiacomo.gabrielli@arm.com    IO_address_space_base = 0x8000000000000000
31913610Sgiacomo.gabrielli@arm.com    return IO_address_space_base + port
32013610Sgiacomo.gabrielli@arm.com
32113610Sgiacomo.gabrielli@arm.comdef connectX86ClassicSystem(x86_sys, numCPUs):
32213610Sgiacomo.gabrielli@arm.com    # Constants similar to x86_traits.hh
32313622Sgabeblack@google.com    IO_address_space_base = 0x8000000000000000
32413557Sgabeblack@google.com    pci_config_address_space_base = 0xc000000000000000
3259920Syasuko.eckert@amd.com    interrupts_address_space_base = 0xa000000000000000
32612106SRekai.GonzalezAlberquilla@arm.com    APIC_range_size = 1 << 12;
32712106SRekai.GonzalezAlberquilla@arm.com
32812106SRekai.GonzalezAlberquilla@arm.com    x86_sys.membus = MemBus()
3299920Syasuko.eckert@amd.com
3309920Syasuko.eckert@amd.com    # North Bridge
33112107SRekai.GonzalezAlberquilla@arm.com    x86_sys.iobus = NoncoherentBus()
33213557Sgabeblack@google.com    x86_sys.bridge = Bridge(delay='50ns')
33313557Sgabeblack@google.com    x86_sys.bridge.master = x86_sys.iobus.slave
3348733Sgeoffrey.blake@arm.com    x86_sys.bridge.slave = x86_sys.membus.master
33512107SRekai.GonzalezAlberquilla@arm.com    # Allow the bridge to pass through the IO APIC (two pages),
33613557Sgabeblack@google.com    # everything in the IO address range up to the local APIC, and
3378733Sgeoffrey.blake@arm.com    # then the entire PCI address space and beyond
3388733Sgeoffrey.blake@arm.com    x86_sys.bridge.ranges = \
33912109SRekai.GonzalezAlberquilla@arm.com        [
34013557Sgabeblack@google.com        AddrRange(x86_sys.pc.south_bridge.io_apic.pio_addr,
34113557Sgabeblack@google.com                  x86_sys.pc.south_bridge.io_apic.pio_addr +
34212109SRekai.GonzalezAlberquilla@arm.com                  APIC_range_size - 1),
34312109SRekai.GonzalezAlberquilla@arm.com        AddrRange(IO_address_space_base,
34413557Sgabeblack@google.com                  interrupts_address_space_base - 1),
34512109SRekai.GonzalezAlberquilla@arm.com        AddrRange(pci_config_address_space_base,
34612109SRekai.GonzalezAlberquilla@arm.com                  Addr.max)
34712109SRekai.GonzalezAlberquilla@arm.com        ]
34813557Sgabeblack@google.com
34913557Sgabeblack@google.com    # Create a bridge from the IO bus to the memory bus to allow access to
35012109SRekai.GonzalezAlberquilla@arm.com    # the local APIC (two pages)
35112109SRekai.GonzalezAlberquilla@arm.com    x86_sys.apicbridge = Bridge(delay='50ns')
35213557Sgabeblack@google.com    x86_sys.apicbridge.slave = x86_sys.iobus.master
35312109SRekai.GonzalezAlberquilla@arm.com    x86_sys.apicbridge.master = x86_sys.membus.slave
35412109SRekai.GonzalezAlberquilla@arm.com    x86_sys.apicbridge.ranges = [AddrRange(interrupts_address_space_base,
35513610Sgiacomo.gabrielli@arm.com                                           interrupts_address_space_base +
35613610Sgiacomo.gabrielli@arm.com                                           numCPUs * APIC_range_size
35713610Sgiacomo.gabrielli@arm.com                                           - 1)]
35813610Sgiacomo.gabrielli@arm.com
35913610Sgiacomo.gabrielli@arm.com    # connect the io bus
36013610Sgiacomo.gabrielli@arm.com    x86_sys.pc.attachIO(x86_sys.iobus)
36113610Sgiacomo.gabrielli@arm.com
36213610Sgiacomo.gabrielli@arm.com    x86_sys.system_port = x86_sys.membus.slave
36313557Sgabeblack@google.com
36413557Sgabeblack@google.comdef connectX86RubySystem(x86_sys):
3652315SN/A    # North Bridge
36612106SRekai.GonzalezAlberquilla@arm.com    x86_sys.iobus = NoncoherentBus()
36712106SRekai.GonzalezAlberquilla@arm.com
36812106SRekai.GonzalezAlberquilla@arm.com    # add the ide to the list of dma devices that later need to attach to
36912107SRekai.GonzalezAlberquilla@arm.com    # dma controllers
3702315SN/A    x86_sys._dma_ports = [x86_sys.pc.south_bridge.ide.dma]
3712315SN/A    x86_sys.pc.attachIO(x86_sys.iobus, x86_sys._dma_ports)
37213557Sgabeblack@google.com
37313557Sgabeblack@google.com
3742315SN/Adef makeX86System(mem_mode, numCPUs = 1, mdesc = None, self = None,
37512106SRekai.GonzalezAlberquilla@arm.com                  Ruby = False):
37612106SRekai.GonzalezAlberquilla@arm.com    if self == None:
37713611Sgabeblack@google.com        self = X86System()
37812107SRekai.GonzalezAlberquilla@arm.com
3792315SN/A    if not mdesc:
3802315SN/A        # generic system
38113557Sgabeblack@google.com        mdesc = SysConfig()
38213622Sgabeblack@google.com    self.readfile = mdesc.script()
3839920Syasuko.eckert@amd.com
38412106SRekai.GonzalezAlberquilla@arm.com    self.mem_mode = mem_mode
38512106SRekai.GonzalezAlberquilla@arm.com
38612106SRekai.GonzalezAlberquilla@arm.com    # Physical memory
38712107SRekai.GonzalezAlberquilla@arm.com    # On the PC platform, the memory region 0xC0000000-0xFFFFFFFF is reserved
3889920Syasuko.eckert@amd.com    # for various devices.  Hence, if the physical memory size is greater than
3899920Syasuko.eckert@amd.com    # 3GB, we need to split it into two parts.
39013557Sgabeblack@google.com    excess_mem_size = \
39113557Sgabeblack@google.com        convert.toMemorySize(mdesc.mem()) - convert.toMemorySize('3GB')
39213557Sgabeblack@google.com    if excess_mem_size <= 0:
39312109SRekai.GonzalezAlberquilla@arm.com        self.mem_ranges = [AddrRange(mdesc.mem())]
39412109SRekai.GonzalezAlberquilla@arm.com    else:
39512109SRekai.GonzalezAlberquilla@arm.com        warn("Physical memory size specified is %s which is greater than " \
39612109SRekai.GonzalezAlberquilla@arm.com             "3GB.  Twice the number of memory controllers would be " \
39712109SRekai.GonzalezAlberquilla@arm.com             "created."  % (mdesc.mem()))
39812109SRekai.GonzalezAlberquilla@arm.com
39912109SRekai.GonzalezAlberquilla@arm.com        self.mem_ranges = [AddrRange('3GB'),
40013557Sgabeblack@google.com            AddrRange(Addr('4GB'), size = excess_mem_size)]
40113557Sgabeblack@google.com
40213557Sgabeblack@google.com    # Platform
40312109SRekai.GonzalezAlberquilla@arm.com    self.pc = Pc()
40412109SRekai.GonzalezAlberquilla@arm.com
40512109SRekai.GonzalezAlberquilla@arm.com    # Create and connect the busses required by each memory system
40612109SRekai.GonzalezAlberquilla@arm.com    if Ruby:
40712109SRekai.GonzalezAlberquilla@arm.com        connectX86RubySystem(self)
40812109SRekai.GonzalezAlberquilla@arm.com    else:
40912109SRekai.GonzalezAlberquilla@arm.com        connectX86ClassicSystem(self, numCPUs)
41013610Sgiacomo.gabrielli@arm.com
41113610Sgiacomo.gabrielli@arm.com    self.intrctrl = IntrControl()
41213610Sgiacomo.gabrielli@arm.com
41313610Sgiacomo.gabrielli@arm.com    # Disks
41413610Sgiacomo.gabrielli@arm.com    disk0 = CowIdeDisk(driveID='master')
41513610Sgiacomo.gabrielli@arm.com    disk2 = CowIdeDisk(driveID='master')
41613610Sgiacomo.gabrielli@arm.com    disk0.childImage(mdesc.disk())
41713610Sgiacomo.gabrielli@arm.com    disk2.childImage(disk('linux-bigswap2.img'))
41813610Sgiacomo.gabrielli@arm.com    self.pc.south_bridge.ide.disks = [disk0, disk2]
41913429Srekai.gonzalezalberquilla@arm.com
42013429Srekai.gonzalezalberquilla@arm.com    # Add in a Bios information structure.
42113557Sgabeblack@google.com    structures = [X86SMBiosBiosInformation()]
42213557Sgabeblack@google.com    self.smbios_table.structures = structures
4238733Sgeoffrey.blake@arm.com
4248733Sgeoffrey.blake@arm.com    # Set up the Intel MP table
4258733Sgeoffrey.blake@arm.com    base_entries = []
4262669Sktlim@umich.edu    ext_entries = []
42713953Sgiacomo.gabrielli@arm.com    for i in xrange(numCPUs):
42813953Sgiacomo.gabrielli@arm.com        bp = X86IntelMPProcessor(
42913953Sgiacomo.gabrielli@arm.com                local_apic_id = i,
43013953Sgiacomo.gabrielli@arm.com                local_apic_version = 0x14,
43113953Sgiacomo.gabrielli@arm.com                enable = True,
43213953Sgiacomo.gabrielli@arm.com                bootstrap = (i == 0))
43313953Sgiacomo.gabrielli@arm.com        base_entries.append(bp)
43413953Sgiacomo.gabrielli@arm.com    io_apic = X86IntelMPIOAPIC(
43513953Sgiacomo.gabrielli@arm.com            id = numCPUs,
43613953Sgiacomo.gabrielli@arm.com            version = 0x11,
43713953Sgiacomo.gabrielli@arm.com            enable = True,
43813953Sgiacomo.gabrielli@arm.com            address = 0xfec00000)
43911169Sandreas.hansson@arm.com    self.pc.south_bridge.io_apic.apic_id = io_apic.id
44013557Sgabeblack@google.com    base_entries.append(io_apic)
44113557Sgabeblack@google.com    isa_bus = X86IntelMPBus(bus_id = 0, bus_type='ISA')
4428733Sgeoffrey.blake@arm.com    base_entries.append(isa_bus)
4438733Sgeoffrey.blake@arm.com    pci_bus = X86IntelMPBus(bus_id = 1, bus_type='PCI')
4448733Sgeoffrey.blake@arm.com    base_entries.append(pci_bus)
4458733Sgeoffrey.blake@arm.com    connect_busses = X86IntelMPBusHierarchy(bus_id=0,
4468733Sgeoffrey.blake@arm.com            subtractive_decode=True, parent_bus=1)
4478733Sgeoffrey.blake@arm.com    ext_entries.append(connect_busses)
4488733Sgeoffrey.blake@arm.com    pci_dev4_inta = X86IntelMPIOIntAssignment(
4498733Sgeoffrey.blake@arm.com            interrupt_type = 'INT',
4508733Sgeoffrey.blake@arm.com            polarity = 'ConformPolarity',
4512315SN/A            trigger = 'ConformTrigger',
45213557Sgabeblack@google.com            source_bus_id = 1,
45313557Sgabeblack@google.com            source_bus_irq = 0 + (4 << 2),
4544172Ssaidi@eecs.umich.edu            dest_io_apic_id = io_apic.id,
4554172Ssaidi@eecs.umich.edu            dest_io_apic_intin = 16)
4564172Ssaidi@eecs.umich.edu    base_entries.append(pci_dev4_inta)
4574172Ssaidi@eecs.umich.edu    def assignISAInt(irq, apicPin):
45813557Sgabeblack@google.com        assign_8259_to_apic = X86IntelMPIOIntAssignment(
45913557Sgabeblack@google.com                interrupt_type = 'ExtInt',
4602315SN/A                polarity = 'ConformPolarity',
4612683Sktlim@umich.edu                trigger = 'ConformTrigger',
4622315SN/A                source_bus_id = 0,
4632315SN/A                source_bus_irq = irq,
46413557Sgabeblack@google.com                dest_io_apic_id = io_apic.id,
46513582Sgabeblack@google.com                dest_io_apic_intin = 0)
4662315SN/A        base_entries.append(assign_8259_to_apic)
46713557Sgabeblack@google.com        assign_to_apic = X86IntelMPIOIntAssignment(
46813557Sgabeblack@google.com                interrupt_type = 'INT',
4694172Ssaidi@eecs.umich.edu                polarity = 'ConformPolarity',
4704172Ssaidi@eecs.umich.edu                trigger = 'ConformTrigger',
4712315SN/A                source_bus_id = 0,
4722315SN/A                source_bus_irq = irq,
47313557Sgabeblack@google.com                dest_io_apic_id = io_apic.id,
47413582Sgabeblack@google.com                dest_io_apic_intin = apicPin)
4752315SN/A        base_entries.append(assign_to_apic)
47613557Sgabeblack@google.com    assignISAInt(0, 2)
47713557Sgabeblack@google.com    assignISAInt(1, 1)
4782315SN/A    for i in range(3, 15):
4792683Sktlim@umich.edu        assignISAInt(i, i)
4802315SN/A    self.intel_mp_table.base_entries = base_entries
4812315SN/A    self.intel_mp_table.ext_entries = ext_entries
48213557Sgabeblack@google.com
48313557Sgabeblack@google.comdef makeLinuxX86System(mem_mode, numCPUs = 1, mdesc = None,
4848733Sgeoffrey.blake@arm.com                       Ruby = False):
48512106SRekai.GonzalezAlberquilla@arm.com    self = LinuxX86System()
48612106SRekai.GonzalezAlberquilla@arm.com
48712106SRekai.GonzalezAlberquilla@arm.com    # Build up the x86 system and then specialize it for Linux
4888733Sgeoffrey.blake@arm.com    makeX86System(mem_mode, numCPUs, mdesc, self, Ruby)
4898733Sgeoffrey.blake@arm.com
49013557Sgabeblack@google.com    # We assume below that there's at least 1MB of memory. We'll require 2
49113582Sgabeblack@google.com    # just to avoid corner cases.
4928733Sgeoffrey.blake@arm.com    phys_mem_size = sum(map(lambda r: r.size(), self.mem_ranges))
49312106SRekai.GonzalezAlberquilla@arm.com    assert(phys_mem_size >= 0x200000)
49412106SRekai.GonzalezAlberquilla@arm.com    assert(len(self.mem_ranges) <= 2)
49512106SRekai.GonzalezAlberquilla@arm.com
4968733Sgeoffrey.blake@arm.com    entries = \
4978888Sgeoffrey.blake@arm.com       [
4988733Sgeoffrey.blake@arm.com        # Mark the first megabyte of memory as reserved
4998733Sgeoffrey.blake@arm.com        X86E820Entry(addr = 0, size = '639kB', range_type = 1),
50013557Sgabeblack@google.com        X86E820Entry(addr = 0x9fc00, size = '385kB', range_type = 2),
50113557Sgabeblack@google.com        # Mark the rest of physical memory as available
5028733Sgeoffrey.blake@arm.com        X86E820Entry(addr = 0x100000,
5038733Sgeoffrey.blake@arm.com                size = '%dB' % (self.mem_ranges[0].size() - 0x100000),
5048733Sgeoffrey.blake@arm.com                range_type = 1),
5058733Sgeoffrey.blake@arm.com        # Reserve the last 16kB of the 32-bit address space for the
5062315SN/A        # m5op interface
50713557Sgabeblack@google.com        X86E820Entry(addr=0xFFFF0000, size='64kB', range_type=2),
50813557Sgabeblack@google.com        ]
5095358Sgblack@eecs.umich.edu
5105358Sgblack@eecs.umich.edu    # In case the physical memory is greater than 3GB, we split it into two
5115358Sgblack@eecs.umich.edu    # parts and add a separate e820 entry for the second part.  This entry
5125358Sgblack@eecs.umich.edu    # starts at 0x100000000,  which is the first address after the space
5135358Sgblack@eecs.umich.edu    # reserved for devices.
51410529Smorr@cs.wisc.edu    if len(self.mem_ranges) == 2:
51513557Sgabeblack@google.com        entries.append(X86E820Entry(addr = 0x100000000,
51611169Sandreas.hansson@arm.com            size = '%dB' % (self.mem_ranges[1].size()), range_type = 1))
51711169Sandreas.hansson@arm.com
51811148Smitch.hayenga@arm.com    self.e820_table.entries = entries
51911169Sandreas.hansson@arm.com
52011169Sandreas.hansson@arm.com    # Command line
52110529Smorr@cs.wisc.edu    self.boot_osflags = 'earlyprintk=ttyS0 console=ttyS0 lpj=7999923 ' + \
52213557Sgabeblack@google.com                        'root=/dev/hda1'
52313557Sgabeblack@google.com    self.kernel = binary('x86_64-vmlinux-2.6.22.9')
5245358Sgblack@eecs.umich.edu    return self
5255358Sgblack@eecs.umich.edu
5265358Sgblack@eecs.umich.edu
5275358Sgblack@eecs.umich.edudef makeDualRoot(full_system, testSystem, driveSystem, dumpfile):
52813557Sgabeblack@google.com    self = Root(full_system = full_system)
52913557Sgabeblack@google.com    self.testsys = testSystem
5305358Sgblack@eecs.umich.edu    self.drivesys = driveSystem
5315358Sgblack@eecs.umich.edu    self.etherlink = EtherLink()
5325358Sgblack@eecs.umich.edu    self.etherlink.int0 = Parent.testsys.tsunami.ethernet.interface
5335358Sgblack@eecs.umich.edu    self.etherlink.int1 = Parent.drivesys.tsunami.ethernet.interface
53411169Sandreas.hansson@arm.com
53511608Snikos.nikoleris@arm.com    if hasattr(testSystem, 'realview'):
53613652Sqtt2@cornell.edu        self.etherlink.int0 = Parent.testsys.realview.ethernet.interface
53711608Snikos.nikoleris@arm.com        self.etherlink.int1 = Parent.drivesys.realview.ethernet.interface
53811608Snikos.nikoleris@arm.com    elif hasattr(testSystem, 'tsunami'):
5398733Sgeoffrey.blake@arm.com        self.etherlink.int0 = Parent.testsys.tsunami.ethernet.interface
54013652Sqtt2@cornell.edu        self.etherlink.int1 = Parent.drivesys.tsunami.ethernet.interface
54113652Sqtt2@cornell.edu    else:
54213652Sqtt2@cornell.edu        fatal("Don't know how to connect these system together")
54313652Sqtt2@cornell.edu
54413652Sqtt2@cornell.edu    if dumpfile:
54513652Sqtt2@cornell.edu        self.etherdump = EtherDump(file=dumpfile)
54613557Sgabeblack@google.com        self.etherlink.dump = Parent.etherdump
54713557Sgabeblack@google.com
54810319SAndreas.Sandberg@ARM.com    return self
54910319SAndreas.Sandberg@ARM.com