Device.py revision 12472
112472Sglenn.bergmans@arm.com# Copyright (c) 2012-2016 ARM Limited 212472Sglenn.bergmans@arm.com# All rights reserved. 312472Sglenn.bergmans@arm.com# 412472Sglenn.bergmans@arm.com# The license below extends only to copyright in the software and shall 512472Sglenn.bergmans@arm.com# not be construed as granting a license to any other intellectual 612472Sglenn.bergmans@arm.com# property including but not limited to intellectual property relating 712472Sglenn.bergmans@arm.com# to a hardware implementation of the functionality of the software 812472Sglenn.bergmans@arm.com# licensed hereunder. You may use the software subject to the license 912472Sglenn.bergmans@arm.com# terms below provided that you ensure that this notice is replicated 1012472Sglenn.bergmans@arm.com# unmodified and in its entirety in all distributions of the software, 1112472Sglenn.bergmans@arm.com# modified or unmodified, in source code or in binary form. 1212472Sglenn.bergmans@arm.com# 134486Sbinkertn@umich.edu# Copyright (c) 2005-2007 The Regents of The University of Michigan 144486Sbinkertn@umich.edu# All rights reserved. 154486Sbinkertn@umich.edu# 164486Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without 174486Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are 184486Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright 194486Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer; 204486Sbinkertn@umich.edu# redistributions in binary form must reproduce the above copyright 214486Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer in the 224486Sbinkertn@umich.edu# documentation and/or other materials provided with the distribution; 234486Sbinkertn@umich.edu# neither the name of the copyright holders nor the names of its 244486Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from 254486Sbinkertn@umich.edu# this software without specific prior written permission. 264486Sbinkertn@umich.edu# 274486Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 284486Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 294486Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 304486Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 314486Sbinkertn@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 324486Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 334486Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 344486Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 354486Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 364486Sbinkertn@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 374486Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 384486Sbinkertn@umich.edu# 394486Sbinkertn@umich.edu# Authors: Nathan Binkert 4012472Sglenn.bergmans@arm.com# Glenn Bergmans 414486Sbinkertn@umich.edu 423102SN/Afrom m5.params import * 433102SN/Afrom m5.proxy import * 4412472Sglenn.bergmans@arm.comfrom m5.util.fdthelper import * 452542SN/Afrom MemObject import MemObject 461310SN/A 472542SN/Aclass PioDevice(MemObject): 481366SN/A type = 'PioDevice' 499338SAndreas.Sandberg@arm.com cxx_header = "dev/io_device.hh" 501310SN/A abstract = True 518839Sandreas.hansson@arm.com pio = SlavePort("Programmed I/O port") 522542SN/A system = Param.System(Parent.any, "System this device is part of") 531310SN/A 5412472Sglenn.bergmans@arm.com def generateBasicPioDeviceNode(self, state, name, pio_addr, 5512472Sglenn.bergmans@arm.com size, interrupts = None): 5612472Sglenn.bergmans@arm.com node = FdtNode("%s@%x" % (name, long(pio_addr))) 5712472Sglenn.bergmans@arm.com node.append(FdtPropertyWords("reg", 5812472Sglenn.bergmans@arm.com state.addrCells(pio_addr) + 5912472Sglenn.bergmans@arm.com state.sizeCells(size) )) 6012472Sglenn.bergmans@arm.com 6112472Sglenn.bergmans@arm.com if interrupts: 6212472Sglenn.bergmans@arm.com if any([i < 32 for i in interrupts]): 6312472Sglenn.bergmans@arm.com raise(("Interrupt number smaller than 32 "+ 6412472Sglenn.bergmans@arm.com " in PioDevice %s") % name) 6512472Sglenn.bergmans@arm.com 6612472Sglenn.bergmans@arm.com # subtracting 32 because Linux assumes that SPIs start at 0, while 6712472Sglenn.bergmans@arm.com # gem5 uses the internal GIC numbering (SPIs start at 32) 6812472Sglenn.bergmans@arm.com node.append(FdtPropertyWords("interrupts", sum( 6912472Sglenn.bergmans@arm.com [[0, i - 32, 4] for i in interrupts], []) )) 7012472Sglenn.bergmans@arm.com 7112472Sglenn.bergmans@arm.com return node 7212472Sglenn.bergmans@arm.com 732542SN/Aclass BasicPioDevice(PioDevice): 742542SN/A type = 'BasicPioDevice' 759338SAndreas.Sandberg@arm.com cxx_header = "dev/io_device.hh" 761310SN/A abstract = True 772542SN/A pio_addr = Param.Addr("Device Address") 789198Sandreas.hansson@arm.com pio_latency = Param.Latency('100ns', "Programmed IO latency") 792565SN/A 802565SN/Aclass DmaDevice(PioDevice): 812565SN/A type = 'DmaDevice' 8211764Sandreas.sandberg@arm.com cxx_header = "dev/dma_device.hh" 832565SN/A abstract = True 848839Sandreas.hansson@arm.com dma = MasterPort("DMA port") 854439SN/A 863812SN/A 873812SN/Aclass IsaFake(BasicPioDevice): 883812SN/A type = 'IsaFake' 8910127SAndreas.Bardsley@arm.com cxx_header = "dev/isa_fake.hh" 903812SN/A pio_size = Param.Addr(0x8, "Size of address range") 913814SN/A ret_data8 = Param.UInt8(0xFF, "Default data to return") 923814SN/A ret_data16 = Param.UInt16(0xFFFF, "Default data to return") 933814SN/A ret_data32 = Param.UInt32(0xFFFFFFFF, "Default data to return") 943814SN/A ret_data64 = Param.UInt64(0xFFFFFFFFFFFFFFFF, "Default data to return") 953812SN/A ret_bad_addr = Param.Bool(False, "Return pkt status bad address on access") 963814SN/A update_data = Param.Bool(False, "Update the data that is returned on writes") 973814SN/A warn_access = Param.String("", "String to print when device is accessed") 988461SAli.Saidi@ARM.com fake_mem = Param.Bool(False, 998461SAli.Saidi@ARM.com "Is this device acting like a memory and thus may get a cache line sized req") 1003812SN/A 1013812SN/Aclass BadAddr(IsaFake): 1026122SSteve.Reinhardt@amd.com pio_addr = 0 1033812SN/A ret_bad_addr = Param.Bool(True, "Return pkt status bad address on access") 1043812SN/A 1053812SN/A 106