tlb.hh revision 13892
14997SN/A/*
27944SN/A * Copyright (c) 2011 ARM Limited
37944SN/A * All rights reserved.
47944SN/A *
57944SN/A * The license below extends only to copyright in the software and shall
67944SN/A * not be construed as granting a license to any other intellectual
77944SN/A * property including but not limited to intellectual property relating
87944SN/A * to a hardware implementation of the functionality of the software
97944SN/A * licensed hereunder.  You may use the software subject to the license
107944SN/A * terms below provided that you ensure that this notice is replicated
117944SN/A * unmodified and in its entirety in all distributions of the software,
127944SN/A * modified or unmodified, in source code or in binary form.
137944SN/A *
144997SN/A * Copyright (c) 2006 The Regents of The University of Michigan
154997SN/A * All rights reserved.
164997SN/A *
174997SN/A * Redistribution and use in source and binary forms, with or without
184997SN/A * modification, are permitted provided that the following conditions are
194997SN/A * met: redistributions of source code must retain the above copyright
204997SN/A * notice, this list of conditions and the following disclaimer;
214997SN/A * redistributions in binary form must reproduce the above copyright
224997SN/A * notice, this list of conditions and the following disclaimer in the
234997SN/A * documentation and/or other materials provided with the distribution;
244997SN/A * neither the name of the copyright holders nor the names of its
254997SN/A * contributors may be used to endorse or promote products derived from
264997SN/A * this software without specific prior written permission.
274997SN/A *
284997SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
294997SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
304997SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
314997SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
324997SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
334997SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
344997SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
354997SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
364997SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
374997SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
384997SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
394997SN/A *
404997SN/A * Authors: Gabe Black
414997SN/A */
424997SN/A
4310687SAndreas.Sandberg@ARM.com#ifndef __ARCH_GENERIC_TLB_HH__
4410687SAndreas.Sandberg@ARM.com#define __ARCH_GENERIC_TLB_HH__
454997SN/A
4612334Sgabeblack@google.com#include "base/logging.hh"
474997SN/A#include "mem/request.hh"
4813892Sgabeblack@google.com#include "sim/sim_object.hh"
494997SN/A
504997SN/Aclass ThreadContext;
519294SN/Aclass BaseMasterPort;
524997SN/A
5313892Sgabeblack@google.comclass BaseTLB : public SimObject
545004SN/A{
555004SN/A  protected:
5613892Sgabeblack@google.com    BaseTLB(const Params *p) : SimObject(p) {}
575004SN/A
584997SN/A  public:
5913741SAndrea.Mondelli@ucf.edu
606023SN/A    enum Mode { Read, Write, Execute };
616023SN/A
625894SN/A    class Translation
635894SN/A    {
645894SN/A      public:
655894SN/A        virtual ~Translation()
665894SN/A        {}
675894SN/A
687944SN/A        /**
697944SN/A         * Signal that the translation has been delayed due to a hw page table
707944SN/A         * walk.
717944SN/A         */
727944SN/A        virtual void markDelayed() = 0;
737944SN/A
745894SN/A        /*
755894SN/A         * The memory for this object may be dynamically allocated, and it may
765894SN/A         * be responsible for cleaning itself up which will happen in this
775894SN/A         * function. Once it's called, the object is no longer valid.
785894SN/A         */
7912749Sgiacomo.travaglini@arm.com        virtual void finish(const Fault &fault, const RequestPtr &req,
8010379SN/A                            ThreadContext *tc, Mode mode) = 0;
819258SN/A
829258SN/A        /** This function is used by the page table walker to determine if it
839258SN/A         * should translate the a pending request or if the underlying request
849258SN/A         * has been squashed.
859258SN/A         * @ return Is the instruction that requested this translation squashed?
869258SN/A         */
879258SN/A        virtual bool squashed() const { return false; }
885894SN/A    };
895358SN/A
905358SN/A  public:
9112406Sgabeblack@google.com    virtual void demapPage(Addr vaddr, uint64_t asn) = 0;
925358SN/A
9312406Sgabeblack@google.com    virtual Fault translateAtomic(
9412749Sgiacomo.travaglini@arm.com            const RequestPtr &req, ThreadContext *tc, Mode mode) = 0;
9512406Sgabeblack@google.com    virtual void translateTiming(
9612749Sgiacomo.travaglini@arm.com            const RequestPtr &req, ThreadContext *tc,
9712406Sgabeblack@google.com            Translation *translation, Mode mode) = 0;
9812406Sgabeblack@google.com    virtual Fault
9912749Sgiacomo.travaglini@arm.com    translateFunctional(const RequestPtr &req, ThreadContext *tc, Mode mode)
10012406Sgabeblack@google.com    {
10112406Sgabeblack@google.com        panic("Not implemented.\n");
10212406Sgabeblack@google.com    }
1039738SN/A
1049738SN/A    /**
1059738SN/A     * Do post-translation physical address finalization.
1069738SN/A     *
1079738SN/A     * This method is used by some architectures that need
1089738SN/A     * post-translation massaging of physical addresses. For example,
1099738SN/A     * X86 uses this to remap physical addresses in the APIC range to
1109738SN/A     * a range of physical memory not normally available to real x86
1119738SN/A     * implementations.
1129738SN/A     *
1139738SN/A     * @param req Request to updated in-place.
1149738SN/A     * @param tc Thread context that created the request.
1159738SN/A     * @param mode Request type (read/write/execute).
1169738SN/A     * @return A fault on failure, NoFault otherwise.
1179738SN/A     */
11812406Sgabeblack@google.com    virtual Fault finalizePhysical(
11912749Sgiacomo.travaglini@arm.com            const RequestPtr &req, ThreadContext *tc, Mode mode) const = 0;
12012406Sgabeblack@google.com
12112406Sgabeblack@google.com    /**
12212406Sgabeblack@google.com     * Remove all entries from the TLB
12312406Sgabeblack@google.com     */
12412406Sgabeblack@google.com    virtual void flushAll() = 0;
12512406Sgabeblack@google.com
12612406Sgabeblack@google.com    /**
12712406Sgabeblack@google.com     * Take over from an old tlb context
12812406Sgabeblack@google.com     */
12912406Sgabeblack@google.com    virtual void takeOverFrom(BaseTLB *otlb) = 0;
13012406Sgabeblack@google.com
13112406Sgabeblack@google.com    /**
13213784Sgabeblack@google.com     * Get the table walker port if present. This is used for
13312406Sgabeblack@google.com     * migrating port connections during a CPU takeOverFrom()
13412406Sgabeblack@google.com     * call. For architectures that do not have a table walker, NULL
13512406Sgabeblack@google.com     * is returned, hence the use of a pointer rather than a
13612406Sgabeblack@google.com     * reference.
13712406Sgabeblack@google.com     *
13813784Sgabeblack@google.com     * @return A pointer to the walker port or NULL if not present
13912406Sgabeblack@google.com     */
14013784Sgabeblack@google.com    virtual Port* getTableWalkerPort() { return NULL; }
14112406Sgabeblack@google.com
14212406Sgabeblack@google.com    void memInvalidate() { flushAll(); }
14312406Sgabeblack@google.com};
14412406Sgabeblack@google.com
14512406Sgabeblack@google.comclass GenericTLB : public BaseTLB
14612406Sgabeblack@google.com{
14712406Sgabeblack@google.com  protected:
14812406Sgabeblack@google.com    GenericTLB(const Params *p)
14912406Sgabeblack@google.com        : BaseTLB(p)
15012406Sgabeblack@google.com    {}
15112406Sgabeblack@google.com
15212406Sgabeblack@google.com  public:
15312406Sgabeblack@google.com    void demapPage(Addr vaddr, uint64_t asn) override;
15412406Sgabeblack@google.com
15512406Sgabeblack@google.com    Fault translateAtomic(
15612749Sgiacomo.travaglini@arm.com        const RequestPtr &req, ThreadContext *tc, Mode mode) override;
15712406Sgabeblack@google.com    void translateTiming(
15812749Sgiacomo.travaglini@arm.com        const RequestPtr &req, ThreadContext *tc,
15912406Sgabeblack@google.com        Translation *translation, Mode mode) override;
16012406Sgabeblack@google.com
16112406Sgabeblack@google.com    Fault finalizePhysical(
16212749Sgiacomo.travaglini@arm.com        const RequestPtr &req, ThreadContext *tc, Mode mode) const override;
1634997SN/A};
1644997SN/A
16510687SAndreas.Sandberg@ARM.com#endif // __ARCH_GENERIC_TLB_HH__
166