Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / include / dev_registry.h
/*
* ========== Copyright Header Begin ==========================================
*
* OpenSPARC T2 Processor File: dev_registry.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 _DEV_REGISTRY_H_
#define _DEV_REGISTRY_H_
// Implement a simple device registry. A device registers itself through
// its Module pointer. This will allow getting information about the
// device such as its Name and also allow for future expansions.
// The function registerDev will return a unique handle that the device can use
// to identify itself in traces. The handle will be unique in a particular setup
// ie, as long as sysconf file does not change.
// Note: samId is a 32 bit unique handle to identify a leaf device in a trace
// record for dma/interrupt/ld/st. For interrupts/dma it percolates towards the
// upstream bridge. The storage is allocated/initialized by leaf. The call
// originates at the leaf device itself. For ld/st, the storage is
// allocated by host bridge ( or main entry point for ld/st ) and the id is
// filled in by the leaf device. The call originates at the host bridge.
#include "types.h"
#include "mmi.h"
#include <map>
#include <pthread.h>
class Module;
class devRegistry{
typedef std::map <SAM_DeviceId , Module * > samDevRegistry;
typedef std::map <SAM_DeviceId , Module * >::iterator samDevRegistryIter;
samDevRegistry r;
samDevRegistryIter ri;
SAM_DeviceId handle;
// make it threadsafe
pthread_mutex_t handleMutex;
public:
// device ids start from 1 instead of 0. 0 is the default
// value that occurs in traces created before this feature
// was added.
static const int devid_first = 1;
devRegistry();
~devRegistry();
// register the device with SAM and return a unique system level handle.
SAM_DeviceId devRegistry::registerDev (Module * dev){
SAM_DeviceId ret;
pthread_mutex_lock(&handleMutex);
// check if there are multple registrations of the same device
for( ri = r.begin(); ri != r.end(); ri++)
if(ri->second == dev){
printf("Error %s already registered\n");
assert(0);
}
ret = handle++;
r[ret] = dev;
pthread_mutex_unlock(&handleMutex);
return ret;
}
// get the name of the device with id 'handle'
const char * getName (SAM_DeviceId handle);
// dump the device name<->trace handle mapping into file FP.
// FP can be stderr. Can be used by UI or trace dump functions.
void dump(FILE * fp);
};
#endif // _DEV_REGISTRY_H_