12400SN/A/*
28706Sandreas.hansson@arm.com * Copyright (c) 2011 ARM Limited
38706Sandreas.hansson@arm.com * All rights reserved
48706Sandreas.hansson@arm.com *
58706Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
68706Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
78706Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
88706Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
98706Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
108706Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
118706Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
128706Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
138706Sandreas.hansson@arm.com *
142400SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan
152400SN/A * All rights reserved.
162400SN/A *
172400SN/A * Redistribution and use in source and binary forms, with or without
182400SN/A * modification, are permitted provided that the following conditions are
192400SN/A * met: redistributions of source code must retain the above copyright
202400SN/A * notice, this list of conditions and the following disclaimer;
212400SN/A * redistributions in binary form must reproduce the above copyright
222400SN/A * notice, this list of conditions and the following disclaimer in the
232400SN/A * documentation and/or other materials provided with the distribution;
242400SN/A * neither the name of the copyright holders nor the names of its
252400SN/A * contributors may be used to endorse or promote products derived from
262400SN/A * this software without specific prior written permission.
272400SN/A *
282400SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292400SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302400SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312400SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322400SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332400SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342400SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352400SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362400SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372400SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382400SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392665SN/A *
402665SN/A * Authors: Ron Dreslinski
412665SN/A *          Steve Reinhardt
428706Sandreas.hansson@arm.com *          Andreas Hansson
432400SN/A */
442400SN/A
4511793Sbrandon.potter@amd.com#include "mem/se_translating_port_proxy.hh"
4611793Sbrandon.potter@amd.com
472400SN/A#include <string>
486658SN/A
498762SN/A#include "arch/isa_traits.hh"
502404SN/A#include "base/chunk_generator.hh"
516658SN/A#include "config/the_isa.hh"
528229SN/A#include "mem/page_table.hh"
534434SN/A#include "sim/process.hh"
549814Sandreas.hansson@arm.com#include "sim/system.hh"
552400SN/A
562423SN/Ausing namespace TheISA;
572423SN/A
5814196Sgabeblack@google.comSETranslatingPortProxy::SETranslatingPortProxy(
5914196Sgabeblack@google.com        SendFunctionalFunc func, Process *p, AllocType alloc)
6014196Sgabeblack@google.com    : PortProxy(func, p->system->cacheLineSize()), pTable(p->pTable),
6114196Sgabeblack@google.com      process(p), allocating(alloc)
6214196Sgabeblack@google.com{ }
6314196Sgabeblack@google.comSETranslatingPortProxy::SETranslatingPortProxy(MasterPort &port,
6414196Sgabeblack@google.com                                               Process *p, AllocType alloc)
659814Sandreas.hansson@arm.com    : PortProxy(port, p->system->cacheLineSize()), pTable(p->pTable),
669814Sandreas.hansson@arm.com      process(p), allocating(alloc)
672400SN/A{ }
682400SN/A
692445SN/Abool
7014009Sgabeblack@google.comSETranslatingPortProxy::tryReadBlob(Addr addr, void *p, int size) const
712400SN/A{
722404SN/A    int prevSize = 0;
7314009Sgabeblack@google.com    auto *bytes = static_cast<uint8_t *>(p);
742400SN/A
7510318Sandreas.hansson@arm.com    for (ChunkGenerator gen(addr, size, PageBytes); !gen.done(); gen.next()) {
768762SN/A        Addr paddr;
772400SN/A
782419SN/A        if (!pTable->translate(gen.addr(),paddr))
792445SN/A            return false;
802400SN/A
8114009Sgabeblack@google.com        PortProxy::readBlobPhys(paddr, 0, bytes + prevSize, gen.size());
822419SN/A        prevSize += gen.size();
832404SN/A    }
842400SN/A
852445SN/A    return true;
862400SN/A}
872400SN/A
882445SN/A
892445SN/Abool
9014009Sgabeblack@google.comSETranslatingPortProxy::tryWriteBlob(Addr addr, const void *p, int size) const
912445SN/A{
922404SN/A    int prevSize = 0;
9314009Sgabeblack@google.com    auto *bytes = static_cast<const uint8_t *>(p);
942400SN/A
9510318Sandreas.hansson@arm.com    for (ChunkGenerator gen(addr, size, PageBytes); !gen.done(); gen.next()) {
968762SN/A        Addr paddr;
972400SN/A
982419SN/A        if (!pTable->translate(gen.addr(), paddr)) {
994434SN/A            if (allocating == Always) {
10010318Sandreas.hansson@arm.com                process->allocateMem(roundDown(gen.addr(), PageBytes),
10110318Sandreas.hansson@arm.com                                     PageBytes);
1024434SN/A            } else if (allocating == NextPage) {
1034434SN/A                // check if we've accessed the next page on the stack
1048539SN/A                if (!process->fixupStackFault(gen.addr()))
1054434SN/A                    panic("Page table fault when accessing virtual address %#x "
1064434SN/A                            "during functional write\n", gen.addr());
1072419SN/A            } else {
1082445SN/A                return false;
1092419SN/A            }
1104434SN/A            pTable->translate(gen.addr(), paddr);
1112419SN/A        }
1122400SN/A
11314009Sgabeblack@google.com        PortProxy::writeBlobPhys(paddr, 0, bytes + prevSize, gen.size());
1142419SN/A        prevSize += gen.size();
1152404SN/A    }
1162404SN/A
1172445SN/A    return true;
1182400SN/A}
1192400SN/A
1202420SN/A
1212445SN/Abool
1228861Sandreas.hansson@arm.comSETranslatingPortProxy::tryMemsetBlob(Addr addr, uint8_t val, int size) const
1232400SN/A{
12410318Sandreas.hansson@arm.com    for (ChunkGenerator gen(addr, size, PageBytes); !gen.done(); gen.next()) {
1258762SN/A        Addr paddr;
1262400SN/A
1272420SN/A        if (!pTable->translate(gen.addr(), paddr)) {
1284434SN/A            if (allocating == Always) {
12910318Sandreas.hansson@arm.com                process->allocateMem(roundDown(gen.addr(), PageBytes),
13010318Sandreas.hansson@arm.com                                     PageBytes);
1312420SN/A                pTable->translate(gen.addr(), paddr);
1322420SN/A            } else {
1332445SN/A                return false;
1342420SN/A            }
1352420SN/A        }
1362400SN/A
13712532Sandreas.sandberg@arm.com        PortProxy::memsetBlobPhys(paddr, 0, val, gen.size());
1382404SN/A    }
1392404SN/A
1402445SN/A    return true;
1412400SN/A}
142