18282SAli.Saidi@ARM.com/*
214082Stiago.muck@arm.com * Copyright (c) 2010,2019 ARM Limited
38282SAli.Saidi@ARM.com * All rights reserved
48282SAli.Saidi@ARM.com *
58282SAli.Saidi@ARM.com * The license below extends only to copyright in the software and shall
68282SAli.Saidi@ARM.com * not be construed as granting a license to any other intellectual
78282SAli.Saidi@ARM.com * property including but not limited to intellectual property relating
88282SAli.Saidi@ARM.com * to a hardware implementation of the functionality of the software
98282SAli.Saidi@ARM.com * licensed hereunder.  You may use the software subject to the license
108282SAli.Saidi@ARM.com * terms below provided that you ensure that this notice is replicated
118282SAli.Saidi@ARM.com * unmodified and in its entirety in all distributions of the software,
128282SAli.Saidi@ARM.com * modified or unmodified, in source code or in binary form.
138282SAli.Saidi@ARM.com *
148282SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without
158282SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are
168282SAli.Saidi@ARM.com * met: redistributions of source code must retain the above copyright
178282SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer;
188282SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright
198282SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer in the
208282SAli.Saidi@ARM.com * documentation and/or other materials provided with the distribution;
218282SAli.Saidi@ARM.com * neither the name of the copyright holders nor the names of its
228282SAli.Saidi@ARM.com * contributors may be used to endorse or promote products derived from
238282SAli.Saidi@ARM.com * this software without specific prior written permission.
248282SAli.Saidi@ARM.com *
258282SAli.Saidi@ARM.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
268282SAli.Saidi@ARM.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
278282SAli.Saidi@ARM.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
288282SAli.Saidi@ARM.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
298282SAli.Saidi@ARM.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
308282SAli.Saidi@ARM.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
318282SAli.Saidi@ARM.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
328282SAli.Saidi@ARM.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
338282SAli.Saidi@ARM.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
348282SAli.Saidi@ARM.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
358282SAli.Saidi@ARM.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
368282SAli.Saidi@ARM.com *
378282SAli.Saidi@ARM.com * Authors: Ali Saidi
388282SAli.Saidi@ARM.com */
398282SAli.Saidi@ARM.com
4011793Sbrandon.potter@amd.com#include "dev/arm/a9scu.hh"
4111793Sbrandon.potter@amd.com
428282SAli.Saidi@ARM.com#include "base/intmath.hh"
438282SAli.Saidi@ARM.com#include "base/trace.hh"
448282SAli.Saidi@ARM.com#include "mem/packet.hh"
458282SAli.Saidi@ARM.com#include "mem/packet_access.hh"
468282SAli.Saidi@ARM.com#include "sim/system.hh"
478282SAli.Saidi@ARM.com
488282SAli.Saidi@ARM.comA9SCU::A9SCU(Params *p)
499808Sstever@gmail.com    : BasicPioDevice(p, 0x60)
508282SAli.Saidi@ARM.com{
518282SAli.Saidi@ARM.com}
528282SAli.Saidi@ARM.com
538282SAli.Saidi@ARM.comTick
548282SAli.Saidi@ARM.comA9SCU::read(PacketPtr pkt)
558282SAli.Saidi@ARM.com{
568282SAli.Saidi@ARM.com    assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
578282SAli.Saidi@ARM.com    assert(pkt->getSize() == 4);
588282SAli.Saidi@ARM.com    Addr daddr = pkt->getAddr() - pioAddr;
598282SAli.Saidi@ARM.com
608282SAli.Saidi@ARM.com    switch(daddr) {
618282SAli.Saidi@ARM.com      case Control:
6213230Sgabeblack@google.com        pkt->setLE(1); // SCU already enabled
638282SAli.Saidi@ARM.com        break;
648282SAli.Saidi@ARM.com      case Config:
6510186Smatt.evans@arm.com        /* Without making a completely new SCU, we can use the core count field
6610186Smatt.evans@arm.com         * as 4 bits and inform the OS of up to 16 CPUs.  Although the core
6710186Smatt.evans@arm.com         * count is technically bits [1:0] only, bits [3:2] are SBZ for future
6810186Smatt.evans@arm.com         * expansion like this.
6910186Smatt.evans@arm.com         */
7010186Smatt.evans@arm.com        if (sys->numContexts() > 4) {
7110186Smatt.evans@arm.com            warn_once("A9SCU with >4 CPUs is unsupported\n");
7210186Smatt.evans@arm.com            if (sys->numContexts() > 15)
7310186Smatt.evans@arm.com                fatal("Too many CPUs (%d) for A9SCU!\n", sys->numContexts());
7410186Smatt.evans@arm.com        }
758282SAli.Saidi@ARM.com        int smp_bits, core_cnt;
7614082Stiago.muck@arm.com        smp_bits = (1 << sys->numContexts()) - 1;
778282SAli.Saidi@ARM.com        core_cnt = sys->numContexts() - 1;
7813230Sgabeblack@google.com        pkt->setLE(smp_bits << 4 | core_cnt);
798282SAli.Saidi@ARM.com        break;
808282SAli.Saidi@ARM.com      default:
818282SAli.Saidi@ARM.com        // Only configuration register is implemented
828282SAli.Saidi@ARM.com        panic("Tried to read SCU at offset %#x\n", daddr);
838282SAli.Saidi@ARM.com        break;
848282SAli.Saidi@ARM.com    }
858282SAli.Saidi@ARM.com    pkt->makeAtomicResponse();
868282SAli.Saidi@ARM.com    return pioDelay;
878282SAli.Saidi@ARM.com
888282SAli.Saidi@ARM.com}
898282SAli.Saidi@ARM.com
908282SAli.Saidi@ARM.comTick
918282SAli.Saidi@ARM.comA9SCU::write(PacketPtr pkt)
928282SAli.Saidi@ARM.com{
938282SAli.Saidi@ARM.com    assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
948282SAli.Saidi@ARM.com
958282SAli.Saidi@ARM.com    Addr daddr = pkt->getAddr() - pioAddr;
968282SAli.Saidi@ARM.com    switch (daddr) {
978282SAli.Saidi@ARM.com      default:
988282SAli.Saidi@ARM.com        // Nothing implemented at this point
9912049Sgedare@rtems.org        warn("Tried to write SCU at offset %#x\n", daddr);
1008282SAli.Saidi@ARM.com        break;
1018282SAli.Saidi@ARM.com    }
1028282SAli.Saidi@ARM.com    pkt->makeAtomicResponse();
1038282SAli.Saidi@ARM.com    return pioDelay;
1048282SAli.Saidi@ARM.com}
1058282SAli.Saidi@ARM.com
1068282SAli.Saidi@ARM.comA9SCU *
1078282SAli.Saidi@ARM.comA9SCUParams::create()
1088282SAli.Saidi@ARM.com{
1098282SAli.Saidi@ARM.com    return new A9SCU(this);
1108282SAli.Saidi@ARM.com}
111