Device.py revision 14272
14776Sgblack@eecs.umich.edu# Copyright (c) 2012-2016,2019 ARM Limited
213610Sgiacomo.gabrielli@arm.com# All rights reserved.
310665SAli.Saidi@ARM.com#
410665SAli.Saidi@ARM.com# The license below extends only to copyright in the software and shall
510665SAli.Saidi@ARM.com# not be construed as granting a license to any other intellectual
610665SAli.Saidi@ARM.com# property including but not limited to intellectual property relating
710665SAli.Saidi@ARM.com# to a hardware implementation of the functionality of the software
810665SAli.Saidi@ARM.com# licensed hereunder.  You may use the software subject to the license
910665SAli.Saidi@ARM.com# terms below provided that you ensure that this notice is replicated
1010665SAli.Saidi@ARM.com# unmodified and in its entirety in all distributions of the software,
1110665SAli.Saidi@ARM.com# modified or unmodified, in source code or in binary form.
1210665SAli.Saidi@ARM.com#
1310665SAli.Saidi@ARM.com# Copyright (c) 2005-2007 The Regents of The University of Michigan
144776Sgblack@eecs.umich.edu# All rights reserved.
154776Sgblack@eecs.umich.edu#
164776Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without
174776Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are
184776Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright
194776Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer;
204776Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright
214776Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
224776Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution;
234776Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its
244776Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from
254776Sgblack@eecs.umich.edu# this software without specific prior written permission.
264776Sgblack@eecs.umich.edu#
274776Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
284776Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
294776Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
304776Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
314776Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
324776Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
334776Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
344776Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
354776Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
364776Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
374776Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
384776Sgblack@eecs.umich.edu#
394776Sgblack@eecs.umich.edu# Authors: Nathan Binkert
404776Sgblack@eecs.umich.edu#          Glenn Bergmans
414776Sgblack@eecs.umich.edu
424776Sgblack@eecs.umich.edufrom m5.params import *
434776Sgblack@eecs.umich.edufrom m5.proxy import *
444776Sgblack@eecs.umich.edufrom m5.util.fdthelper import *
454776Sgblack@eecs.umich.edu
464776Sgblack@eecs.umich.edufrom m5.objects.ClockedObject import ClockedObject
4713610Sgiacomo.gabrielli@arm.com
4813610Sgiacomo.gabrielli@arm.comclass PioDevice(ClockedObject):
496216Snate@binkert.org    type = 'PioDevice'
5011800Sbrandon.potter@amd.com    cxx_header = "dev/io_device.hh"
514776Sgblack@eecs.umich.edu    abstract = True
524776Sgblack@eecs.umich.edu    pio = SlavePort("Programmed I/O port")
534776Sgblack@eecs.umich.edu    system = Param.System(Parent.any, "System this device is part of")
544776Sgblack@eecs.umich.edu
554776Sgblack@eecs.umich.edu    def generateBasicPioDeviceNode(self, state, name, pio_addr,
564776Sgblack@eecs.umich.edu                                   size, interrupts = None):
574776Sgblack@eecs.umich.edu        node = FdtNode("%s@%x" % (name, long(pio_addr)))
584776Sgblack@eecs.umich.edu        node.append(FdtPropertyWords("reg",
594776Sgblack@eecs.umich.edu            state.addrCells(pio_addr) +
604776Sgblack@eecs.umich.edu            state.sizeCells(size) ))
614776Sgblack@eecs.umich.edu
624776Sgblack@eecs.umich.edu        if interrupts:
634776Sgblack@eecs.umich.edu            if any([i < 32 for i in interrupts]):
644776Sgblack@eecs.umich.edu                raise(("Interrupt number smaller than 32 "+
654776Sgblack@eecs.umich.edu                       " in PioDevice %s") % name)
664776Sgblack@eecs.umich.edu
674776Sgblack@eecs.umich.edu            # subtracting 32 because Linux assumes that SPIs start at 0, while
684776Sgblack@eecs.umich.edu            # gem5 uses the internal GIC numbering (SPIs start at 32)
697720Sgblack@eecs.umich.edu            node.append(FdtPropertyWords("interrupts", sum(
705784Sgblack@eecs.umich.edu                [[0, i  - 32, 4] for i in interrupts], []) ))
714776Sgblack@eecs.umich.edu
724776Sgblack@eecs.umich.edu        return node
734776Sgblack@eecs.umich.edu
744776Sgblack@eecs.umich.educlass BasicPioDevice(PioDevice):
754776Sgblack@eecs.umich.edu    type = 'BasicPioDevice'
764776Sgblack@eecs.umich.edu    cxx_header = "dev/io_device.hh"
774776Sgblack@eecs.umich.edu    abstract = True
7810665SAli.Saidi@ARM.com    pio_addr = Param.Addr("Device Address")
7910665SAli.Saidi@ARM.com    pio_latency = Param.Latency('100ns', "Programmed IO latency")
8010665SAli.Saidi@ARM.com
8110665SAli.Saidi@ARM.comclass DmaDevice(PioDevice):
8210665SAli.Saidi@ARM.com    type = 'DmaDevice'
8310665SAli.Saidi@ARM.com    cxx_header = "dev/dma_device.hh"
8410665SAli.Saidi@ARM.com    abstract = True
8510665SAli.Saidi@ARM.com    dma = MasterPort("DMA port")
8610665SAli.Saidi@ARM.com
8710665SAli.Saidi@ARM.com    _iommu = None
8810665SAli.Saidi@ARM.com
8910665SAli.Saidi@ARM.com    sid = Param.Unsigned(0,
9010665SAli.Saidi@ARM.com        "Stream identifier used by an IOMMU to distinguish amongst "
9110665SAli.Saidi@ARM.com        "several devices attached to it")
9210665SAli.Saidi@ARM.com    ssid = Param.Unsigned(0,
9310665SAli.Saidi@ARM.com        "Substream identifier used by an IOMMU to distinguish amongst "
9410665SAli.Saidi@ARM.com        "several devices attached to it")
9510665SAli.Saidi@ARM.com
9610665SAli.Saidi@ARM.com    def addIommuProperty(self, state, node):
974776Sgblack@eecs.umich.edu        """
984776Sgblack@eecs.umich.edu        This method takes an FdtState and a FdtNode as parameters, and
994776Sgblack@eecs.umich.edu        it is appending a "iommus = <>" property in case the DmaDevice
10013610Sgiacomo.gabrielli@arm.com        is attached to an IOMMU.
10113610Sgiacomo.gabrielli@arm.com        This method is necessary for autogenerating a binding between
10213610Sgiacomo.gabrielli@arm.com        a dma device and the iommu.
1034776Sgblack@eecs.umich.edu        """
10410665SAli.Saidi@ARM.com        if self._iommu is not None:
10510665SAli.Saidi@ARM.com            node.append(FdtPropertyWords("iommus",
10610665SAli.Saidi@ARM.com                [ state.phandle(self._iommu), self.sid ]))
10710665SAli.Saidi@ARM.com
10810665SAli.Saidi@ARM.comclass IsaFake(BasicPioDevice):
10910665SAli.Saidi@ARM.com    type = 'IsaFake'
11010665SAli.Saidi@ARM.com    cxx_header = "dev/isa_fake.hh"
11110665SAli.Saidi@ARM.com    pio_size = Param.Addr(0x8, "Size of address range")
11210665SAli.Saidi@ARM.com    ret_data8 = Param.UInt8(0xFF, "Default data to return")
11310665SAli.Saidi@ARM.com    ret_data16 = Param.UInt16(0xFFFF, "Default data to return")
11410665SAli.Saidi@ARM.com    ret_data32 = Param.UInt32(0xFFFFFFFF, "Default data to return")
11510665SAli.Saidi@ARM.com    ret_data64 = Param.UInt64(0xFFFFFFFFFFFFFFFF, "Default data to return")
11610665SAli.Saidi@ARM.com    ret_bad_addr = Param.Bool(False, "Return pkt status bad address on access")
11710665SAli.Saidi@ARM.com    update_data = Param.Bool(False, "Update the data that is returned on writes")
11810665SAli.Saidi@ARM.com    warn_access = Param.String("", "String to print when device is accessed")
11910665SAli.Saidi@ARM.com    fake_mem = Param.Bool(False,
12012386Sgabeblack@google.com      "Is this device acting like a memory and thus may get a cache line sized req")
1214776Sgblack@eecs.umich.edu
1225543Ssaidi@eecs.umich.educlass BadAddr(IsaFake):
1234776Sgblack@eecs.umich.edu    pio_addr = 0
1244776Sgblack@eecs.umich.edu    ret_bad_addr = Param.Bool(True, "Return pkt status bad address on access")
1254776Sgblack@eecs.umich.edu
12613610Sgiacomo.gabrielli@arm.com
12713610Sgiacomo.gabrielli@arm.com