19155SN/A/*
29155SN/A * Copyright (c) 2012 Advanced Micro Devices, Inc.
39155SN/A * All rights reserved.
49155SN/A *
59155SN/A * Redistribution and use in source and binary forms, with or without
69155SN/A * modification, are permitted provided that the following conditions are
79155SN/A * met: redistributions of source code must retain the above copyright
89155SN/A * notice, this list of conditions and the following disclaimer;
99155SN/A * redistributions in binary form must reproduce the above copyright
109155SN/A * notice, this list of conditions and the following disclaimer in the
119155SN/A * documentation and/or other materials provided with the distribution;
129155SN/A * neither the name of the copyright holders nor the names of its
139155SN/A * contributors may be used to endorse or promote products derived from
149155SN/A * this software without specific prior written permission.
159155SN/A *
169155SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
179155SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
189155SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
199155SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
209155SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
219155SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
229155SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
239155SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
249155SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
259155SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
269155SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
279155SN/A *
289155SN/A * Author: Brad Beckmann
299155SN/A *
309155SN/A */
319105SN/A
3210441Snilay@cs.wisc.edu#ifndef __MEM_RUBY_STRUCTURES_BANKEDARRAY_HH__
3310441Snilay@cs.wisc.edu#define __MEM_RUBY_STRUCTURES_BANKEDARRAY_HH__
349105SN/A
359105SN/A#include <vector>
369105SN/A
379105SN/A#include "mem/ruby/common/TypeDefines.hh"
3811108Sdavid.hashe@amd.com#include "mem/ruby/system/RubySystem.hh"
399297SN/A#include "sim/core.hh"
409105SN/A
419297SN/Aclass BankedArray
429105SN/A{
439297SN/A  private:
449105SN/A    unsigned int banks;
459184SN/A    Cycles accessLatency;
469105SN/A    unsigned int bankBits;
479105SN/A    unsigned int startIndexBit;
4810919Sbrandon.potter@amd.com    RubySystem *m_ruby_system;
499105SN/A
509297SN/A    class AccessRecord
519105SN/A    {
529297SN/A      public:
539297SN/A        AccessRecord() : idx(0), startAccess(0), endAccess(0) {}
5411061Snilay@cs.wisc.edu        int64_t idx;
559105SN/A        Tick startAccess;
569297SN/A        Tick endAccess;
579105SN/A    };
589105SN/A
599105SN/A    // If the tick event is scheduled then the bank is busy
609105SN/A    // otherwise, schedule the event and wait for it to complete
619297SN/A    std::vector<AccessRecord> busyBanks;
629105SN/A
6311061Snilay@cs.wisc.edu    unsigned int mapIndexToBank(int64_t idx);
649105SN/A
659297SN/A  public:
6610917Sbrandon.potter@amd.com    BankedArray(unsigned int banks, Cycles accessLatency,
6710919Sbrandon.potter@amd.com                unsigned int startIndexBit, RubySystem *rs);
689105SN/A
699105SN/A    // Note: We try the access based on the cache index, not the address
709105SN/A    // This is so we don't get aliasing on blocks being replaced
7111061Snilay@cs.wisc.edu    bool tryAccess(int64_t idx);
729105SN/A
7311061Snilay@cs.wisc.edu    void reserve(int64_t idx);
7410978Sdavid.hashe@amd.com
7510969Sdavid.hashe@amd.com    Cycles getLatency() const { return accessLatency; }
769105SN/A};
779105SN/A
789105SN/A#endif
79