* ========== 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 ============================================
// 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.
typedef std::map
<SAM_DeviceId
, Module
* > samDevRegistry
;
typedef std::map
<SAM_DeviceId
, Module
* >::iterator samDevRegistryIter
;
pthread_mutex_t handleMutex
;
// device ids start from 1 instead of 0. 0 is the default
// value that occurs in traces created before this feature
static const int devid_first
= 1;
// register the device with SAM and return a unique system level handle.
SAM_DeviceId
devRegistry::registerDev (Module
* dev
){
pthread_mutex_lock(&handleMutex
);
// check if there are multple registrations of the same device
for( ri
= r
.begin(); ri
!= r
.end(); ri
++)
printf("Error %s already registered\n");
pthread_mutex_unlock(&handleMutex
);
// 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.
#endif // _DEV_REGISTRY_H_