16145SN/A/*
212065Snikos.nikoleris@arm.com * Copyright (c) 2017 ARM Limited
312065Snikos.nikoleris@arm.com * All rights reserved.
412065Snikos.nikoleris@arm.com *
512065Snikos.nikoleris@arm.com * The license below extends only to copyright in the software and shall
612065Snikos.nikoleris@arm.com * not be construed as granting a license to any other intellectual
712065Snikos.nikoleris@arm.com * property including but not limited to intellectual property relating
812065Snikos.nikoleris@arm.com * to a hardware implementation of the functionality of the software
912065Snikos.nikoleris@arm.com * licensed hereunder.  You may use the software subject to the license
1012065Snikos.nikoleris@arm.com * terms below provided that you ensure that this notice is replicated
1112065Snikos.nikoleris@arm.com * unmodified and in its entirety in all distributions of the software,
1212065Snikos.nikoleris@arm.com * modified or unmodified, in source code or in binary form.
1312065Snikos.nikoleris@arm.com *
146145SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
156145SN/A * All rights reserved.
166145SN/A *
176145SN/A * Redistribution and use in source and binary forms, with or without
186145SN/A * modification, are permitted provided that the following conditions are
196145SN/A * met: redistributions of source code must retain the above copyright
206145SN/A * notice, this list of conditions and the following disclaimer;
216145SN/A * redistributions in binary form must reproduce the above copyright
226145SN/A * notice, this list of conditions and the following disclaimer in the
236145SN/A * documentation and/or other materials provided with the distribution;
246145SN/A * neither the name of the copyright holders nor the names of its
256145SN/A * contributors may be used to endorse or promote products derived from
266145SN/A * this software without specific prior written permission.
276145SN/A *
286145SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
296145SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
306145SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
316145SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
326145SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
336145SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
346145SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
356145SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
366145SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
376145SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
386145SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
396145SN/A */
406145SN/A
4110441Snilay@cs.wisc.edu#ifndef __MEM_RUBY_STRUCTURES_DIRECTORYMEMORY_HH__
4210441Snilay@cs.wisc.edu#define __MEM_RUBY_STRUCTURES_DIRECTORYMEMORY_HH__
436145SN/A
447055SN/A#include <iostream>
457055SN/A#include <string>
467055SN/A
4712065Snikos.nikoleris@arm.com#include "base/addr_range.hh"
487039SN/A#include "mem/ruby/common/Address.hh"
4914184Sgabeblack@google.com#include "mem/ruby/protocol/DirectoryRequestType.hh"
508644SN/A#include "mem/ruby/slicc_interface/AbstractEntry.hh"
517039SN/A#include "params/RubyDirectoryMemory.hh"
527039SN/A#include "sim/sim_object.hh"
536145SN/A
547039SN/Aclass DirectoryMemory : public SimObject
557039SN/A{
567039SN/A  public:
576876SN/A    typedef RubyDirectoryMemoryParams Params;
586876SN/A    DirectoryMemory(const Params *p);
597039SN/A    ~DirectoryMemory();
606145SN/A
617039SN/A    void init();
626145SN/A
6312065Snikos.nikoleris@arm.com    /**
6412065Snikos.nikoleris@arm.com     * Return the index in the directory based on an address
6512065Snikos.nikoleris@arm.com     *
6612065Snikos.nikoleris@arm.com     * This function transforms an address which belongs to a not
6712065Snikos.nikoleris@arm.com     * necessarily continuous vector of address ranges into a flat
6812065Snikos.nikoleris@arm.com     * address that we use to index in the directory
6912065Snikos.nikoleris@arm.com     *
7012065Snikos.nikoleris@arm.com     * @param an input address
7112065Snikos.nikoleris@arm.com     * @return the corresponding index in the directory
7212065Snikos.nikoleris@arm.com     *
7312065Snikos.nikoleris@arm.com     */
7411025Snilay@cs.wisc.edu    uint64_t mapAddressToLocalIdx(Addr address);
756285SN/A
7611025Snilay@cs.wisc.edu    uint64_t getSize() { return m_size_bytes; }
776285SN/A
7811025Snilay@cs.wisc.edu    bool isPresent(Addr address);
7911025Snilay@cs.wisc.edu    AbstractEntry *lookup(Addr address);
8011025Snilay@cs.wisc.edu    AbstractEntry *allocate(Addr address, AbstractEntry* new_entry);
816145SN/A
827055SN/A    void print(std::ostream& out) const;
839104SN/A    void recordRequestType(DirectoryRequestType requestType);
849104SN/A
857039SN/A  private:
867039SN/A    // Private copy constructor and assignment operator
877039SN/A    DirectoryMemory(const DirectoryMemory& obj);
887039SN/A    DirectoryMemory& operator=(const DirectoryMemory& obj);
896145SN/A
907039SN/A  private:
917055SN/A    const std::string m_name;
928644SN/A    AbstractEntry **m_entries;
937039SN/A    // int m_size;  // # of memory module blocks this directory is
947039SN/A                    // responsible for
9511025Snilay@cs.wisc.edu    uint64_t m_size_bytes;
9611025Snilay@cs.wisc.edu    uint64_t m_size_bits;
9711025Snilay@cs.wisc.edu    uint64_t m_num_entries;
986145SN/A
9912065Snikos.nikoleris@arm.com    /**
10012065Snikos.nikoleris@arm.com     * The address range for which the directory responds. Normally
10112065Snikos.nikoleris@arm.com     * this is all possible memory addresses.
10212065Snikos.nikoleris@arm.com     */
10312065Snikos.nikoleris@arm.com    const AddrRangeList addrRanges;
1046145SN/A};
1056145SN/A
1067055SN/Ainline std::ostream&
1077055SN/Aoperator<<(std::ostream& out, const DirectoryMemory& obj)
1086145SN/A{
1097039SN/A    obj.print(out);
1107055SN/A    out << std::flush;
1117039SN/A    return out;
1126145SN/A}
1136145SN/A
11410441Snilay@cs.wisc.edu#endif // __MEM_RUBY_STRUCTURES_DIRECTORYMEMORY_HH__
115