15390SN/A# Copyright (c) 2008 The Regents of The University of Michigan
25390SN/A# All rights reserved.
35390SN/A#
45390SN/A# Redistribution and use in source and binary forms, with or without
55390SN/A# modification, are permitted provided that the following conditions are
65390SN/A# met: redistributions of source code must retain the above copyright
75390SN/A# notice, this list of conditions and the following disclaimer;
85390SN/A# redistributions in binary form must reproduce the above copyright
95390SN/A# notice, this list of conditions and the following disclaimer in the
105390SN/A# documentation and/or other materials provided with the distribution;
115390SN/A# neither the name of the copyright holders nor the names of its
125390SN/A# contributors may be used to endorse or promote products derived from
135390SN/A# this software without specific prior written permission.
145390SN/A#
155390SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
165390SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
175390SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
185390SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
195390SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
205390SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
215390SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
225390SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
235390SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
245390SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
255390SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
265390SN/A#
275390SN/A# Authors: Gabe Black
285390SN/A
295390SN/Afrom m5.params import *
305390SN/Afrom m5.proxy import *
3113665Sandreas.sandberg@arm.comfrom m5.objects.Cmos import Cmos
3213665Sandreas.sandberg@arm.comfrom m5.objects.I8042 import I8042
3313665Sandreas.sandberg@arm.comfrom m5.objects.I82094AA import I82094AA
3413665Sandreas.sandberg@arm.comfrom m5.objects.I8237 import I8237
3513665Sandreas.sandberg@arm.comfrom m5.objects.I8254 import I8254
3613665Sandreas.sandberg@arm.comfrom m5.objects.I8259 import I8259
3713665Sandreas.sandberg@arm.comfrom m5.objects.Ide import IdeController
3813665Sandreas.sandberg@arm.comfrom m5.objects.PcSpeaker import PcSpeaker
395636SN/Afrom m5.SimObject import SimObject
405390SN/A
415636SN/Adef x86IOAddress(port):
425636SN/A    IO_address_space_base = 0x8000000000000000
435636SN/A    return IO_address_space_base + port;
445636SN/A
455636SN/Aclass SouthBridge(SimObject):
465390SN/A    type = 'SouthBridge'
479338SAndreas.Sandberg@arm.com    cxx_header = "dev/x86/south_bridge.hh"
485636SN/A    platform = Param.Platform(Parent.any, "Platform this device is part of")
495636SN/A
505636SN/A    _pic1 = I8259(pio_addr=x86IOAddress(0x20), mode='I8259Master')
515636SN/A    _pic2 = I8259(pio_addr=x86IOAddress(0xA0), mode='I8259Slave')
525636SN/A    _cmos = Cmos(pio_addr=x86IOAddress(0x70))
535818Sgblack@eecs.umich.edu    _dma1 = I8237(pio_addr=x86IOAddress(0x0))
545831Sgblack@eecs.umich.edu    _keyboard = I8042(data_port=x86IOAddress(0x60), \
555831Sgblack@eecs.umich.edu            command_port=x86IOAddress(0x64))
565636SN/A    _pit = I8254(pio_addr=x86IOAddress(0x40))
575636SN/A    _speaker = PcSpeaker(pio_addr=x86IOAddress(0x61))
585643Sgblack@eecs.umich.edu    _io_apic = I82094AA(pio_addr=0xFEC00000)
595636SN/A
605636SN/A    pic1 = Param.I8259(_pic1, "Master PIC")
615636SN/A    pic2 = Param.I8259(_pic2, "Slave PIC")
625636SN/A    cmos = Param.Cmos(_cmos, "CMOS memory and real time clock device")
635818Sgblack@eecs.umich.edu    dma1 = Param.I8237(_dma1, "The first dma controller")
645831Sgblack@eecs.umich.edu    keyboard = Param.I8042(_keyboard, "The keyboard controller")
655636SN/A    pit = Param.I8254(_pit, "Programmable interval timer")
665636SN/A    speaker = Param.PcSpeaker(_speaker, "PC speaker")
675643Sgblack@eecs.umich.edu    io_apic = Param.I82094AA(_io_apic, "I/O APIC")
685636SN/A
695833Sgblack@eecs.umich.edu    # IDE controller
705833Sgblack@eecs.umich.edu    ide = IdeController(disks=[], pci_func=0, pci_dev=4, pci_bus=0)
715833Sgblack@eecs.umich.edu    ide.BAR0 = 0x1f0
725833Sgblack@eecs.umich.edu    ide.BAR0LegacyIO = True
735833Sgblack@eecs.umich.edu    ide.BAR1 = 0x3f4
745833Sgblack@eecs.umich.edu    ide.BAR1Size = '3B'
755833Sgblack@eecs.umich.edu    ide.BAR1LegacyIO = True
765833Sgblack@eecs.umich.edu    ide.BAR2 = 0x170
775833Sgblack@eecs.umich.edu    ide.BAR2LegacyIO = True
785833Sgblack@eecs.umich.edu    ide.BAR3 = 0x374
795833Sgblack@eecs.umich.edu    ide.BAR3Size = '3B'
805833Sgblack@eecs.umich.edu    ide.BAR3LegacyIO = True
815833Sgblack@eecs.umich.edu    ide.BAR4 = 1
826432Sgblack@eecs.umich.edu    ide.Command = 0
836432Sgblack@eecs.umich.edu    ide.ProgIF = 0x80
845843Sgblack@eecs.umich.edu    ide.InterruptLine = 14
855843Sgblack@eecs.umich.edu    ide.InterruptPin = 1
8610359SAli.Saidi@ARM.com    ide.LegacyIOBase = x86IOAddress(0)
875833Sgblack@eecs.umich.edu
888929Snilay@cs.wisc.edu    def attachIO(self, bus, dma_ports):
8914290Sgabeblack@google.com        # Route interrupt signals
9014290Sgabeblack@google.com        self.pic1.output = self.io_apic.inputs[0]
9114290Sgabeblack@google.com        self.pic2.output = self.pic1.inputs[2]
9214290Sgabeblack@google.com        self.cmos.int_pin = self.pic2.inputs[0]
9314290Sgabeblack@google.com        self.pit.int_pin = self.pic1.inputs[0]
9414290Sgabeblack@google.com        self.pit.int_pin = self.io_apic.inputs[2]
9514290Sgabeblack@google.com        self.keyboard.keyboard_int_pin = self.io_apic.inputs[1]
9614290Sgabeblack@google.com        self.keyboard.mouse_int_pin = self.io_apic.inputs[12]
975827Sgblack@eecs.umich.edu        # Tell the devices about each other
985827Sgblack@eecs.umich.edu        self.pic1.slave = self.pic2
995636SN/A        self.speaker.i8254 = self.pit
1005827Sgblack@eecs.umich.edu        self.io_apic.external_int_pic = self.pic1
1015636SN/A        # Connect to the bus
1028839Sandreas.hansson@arm.com        self.cmos.pio = bus.master
1038839Sandreas.hansson@arm.com        self.dma1.pio = bus.master
1048839Sandreas.hansson@arm.com        self.ide.pio = bus.master
1058929Snilay@cs.wisc.edu        if dma_ports.count(self.ide.dma) == 0:
1068929Snilay@cs.wisc.edu                self.ide.dma = bus.slave
1078839Sandreas.hansson@arm.com        self.keyboard.pio = bus.master
1088839Sandreas.hansson@arm.com        self.pic1.pio = bus.master
1098839Sandreas.hansson@arm.com        self.pic2.pio = bus.master
1108839Sandreas.hansson@arm.com        self.pit.pio = bus.master
1118839Sandreas.hansson@arm.com        self.speaker.pio = bus.master
1128839Sandreas.hansson@arm.com        self.io_apic.pio = bus.master
1138839Sandreas.hansson@arm.com        self.io_apic.int_master = bus.slave
114