Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / lib / csr / src / SS_BaseCsr.h
/*
* ========== Copyright Header Begin ==========================================
*
* OpenSPARC T2 Processor File: SS_BaseCsr.h
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
*
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
*
* The above named program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
* ========== Copyright Header End ============================================
*/
#ifndef SS_BASE_CSR_H
#define SS_BASE_CSR_H
/************************************************************************
**
** Copyright (C) 2006, Sun Microsystems, Inc.
**
** Sun considers its source code as an unpublished, proprietary
** trade secret and it is available only under strict license provisions.
** This copyright notice is placed here only to protect Sun in the event
** the source is deemed a published work. Disassembly, decompilation,
** or other means of reducing the object code to human readable form
** is prohibited by the license agreement under which this code is
** provided to the user or company in possession of this copy.
**
*************************************************************************/
#include "SS_CsrAttribute.h"
#include "SS_Io.h"
#include "SS_Access.h"
#include "MemoryTransaction.h"
#include "SS_Types.h"
/**
* class represents csr follow-me data
*/
class FollowMeData
{
public:
FollowMeData() : addr(0), data(0), sid(-1) { }
FollowMeData(SS_Paddr _addr, uint64_t _data, int _sid) :
addr(_addr), data(_data), sid(_sid) { }
SS_Paddr addr;
uint64_t data;
int sid;
};
class SS_BaseCsr
{
public:
enum Access_T {
// make sure there is no conflict with MemoryTransaction::Access_T
NO_FOLLOW_ME = 1 << 10 // internal access, do not pop follow-me value
};
static void access( void* obj,
uint_t sid,
SS_Access::Type,
SS_Paddr addr,
uint_t size,
uint64_t* data);
virtual int read64( SS_Paddr addr,
uint64_t* data,
int access=MemoryTransaction::READ,
int sid=-1 );
virtual int write64( SS_Paddr addr,
uint64_t data,
int access=MemoryTransaction::WRITE,
int sid=-1 );
virtual std::string toString() const
{
return std::string("SS_BaseCs::toString() not implemented");
}
/**
* common methods
*/
enum {
ENTRY_NOT_FOUND = -1
};
int64_t findAttributeEntryNdx(SS_Paddr addr,
const RegisterAttribute *const attributeTable,
int entries);
const RegisterAttribute* const
findAttributeEntry(SS_Paddr addr,
const RegisterAttribute *const attributeTable,
int entries);
void warmReset(std::vector<std::vector<RegisterValue>*>* values,
int nrAttributeEntries);
uint64_t reverseByteOrder(uint64_t value, bool littleEndian);
uint64_t forceWrite(uint64_t inputData,
const RegisterAttribute* attribute,
int access);
uint64_t normalWrite(uint64_t inputData,
uint64_t oldData,
const RegisterAttribute* attribute,
int access);
/**
* if a derived class needs to register its address range, the derived
* class should overwrite the regAddrSpace() function.
*/
virtual void regAddrSpace() { /* default, do nothing */ }
/**
* local I/O address <-> global I/O address conversion,
*/
virtual SS_Paddr local2global(SS_Paddr addr, int sid) { return addr; }
virtual SS_Paddr global2local(SS_Paddr addr) { return addr; }
virtual SS_Paddr addr_node0(SS_Paddr addr) { return addr; }
virtual bool is_global_addr(SS_Paddr addr) { return true; }
virtual int get_node_id(SS_Paddr addr) { return 0; }
protected:
SS_BaseCsr(std::string className,
const RegisterAttribute* const attributeTable,
int nrAttributeEntries) :
className_(className),
attributeTable_(attributeTable),
nrAttributeEntries_(nrAttributeEntries),
values_(new std::vector<std::vector<RegisterValue>*>[nrAttributeEntries])
{
}
virtual ~SS_BaseCsr() {}
// derived class name
const std::string className_;
// Attribute table for derived class
const RegisterAttribute* const attributeTable_;
// Nr entries in attribute table
const int nrAttributeEntries_;
void registerAddressSpace(RegisterAttribute *attributeTable,
uint_t tableSize,
const std::string &descr);
// values_ is a 3-dimention structure, the top level has an 1-to-1
// mapping with each CSR entry in the corresponding RegisterAttribute
// table, the second level has one entry for each node (i.e., cpu), the
// third level is a structure of vector<RegisterValue>, where each entry
// represents an addr entity of a (CSR,node-id,addr) triple of a particular
// CSR in the RegisterAttribute table. The reason for having a vector at
// the third level is that each CSR entry in the RegisterAttribute table
// can spawn out one or more addrs, depending on the CSR's (count,stride)
// attribute.
std::vector<std::vector<RegisterValue>*>* values_;
// the followme_ is a list of objects, each object represents a csr
// follow-me value, the objects are kept in FIFO order, once an object
// in the list is used, it should be removed from the list, as follow-me
// uses "use-once-and-discard" scheme.
std::list<FollowMeData> followme_;
private:
SS_BaseCsr() :
className_(""),
attributeTable_(NULL),
nrAttributeEntries_(0)
{}
// gaddr - global I/O address, laddr - local I/O address
int write64_notCsr( SS_Paddr gaddr, uint64_t data );
int read64_notCsr( SS_Paddr gaddr, SS_Paddr laddr, uint64_t* data );
int read_memimage( SS_Paddr gaddr, SS_Paddr laddr, uint64_t* data );
};
#endif // SS_BASE_CSR_H