Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: dev_registry.h | |
5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
7 | * | |
8 | * The above named program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public | |
10 | * License version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * The above named program is distributed in the hope that it will be | |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public | |
18 | * License along with this work; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | * | |
21 | * ========== Copyright Header End ============================================ | |
22 | */ | |
23 | #ifndef _DEV_REGISTRY_H_ | |
24 | #define _DEV_REGISTRY_H_ | |
25 | ||
26 | ||
27 | // Implement a simple device registry. A device registers itself through | |
28 | // its Module pointer. This will allow getting information about the | |
29 | // device such as its Name and also allow for future expansions. | |
30 | // The function registerDev will return a unique handle that the device can use | |
31 | // to identify itself in traces. The handle will be unique in a particular setup | |
32 | // ie, as long as sysconf file does not change. | |
33 | ||
34 | ||
35 | ||
36 | // Note: samId is a 32 bit unique handle to identify a leaf device in a trace | |
37 | // record for dma/interrupt/ld/st. For interrupts/dma it percolates towards the | |
38 | // upstream bridge. The storage is allocated/initialized by leaf. The call | |
39 | // originates at the leaf device itself. For ld/st, the storage is | |
40 | // allocated by host bridge ( or main entry point for ld/st ) and the id is | |
41 | // filled in by the leaf device. The call originates at the host bridge. | |
42 | ||
43 | ||
44 | ||
45 | #include "types.h" | |
46 | #include "mmi.h" | |
47 | #include <map> | |
48 | #include <pthread.h> | |
49 | ||
50 | class Module; | |
51 | ||
52 | class devRegistry{ | |
53 | ||
54 | typedef std::map <SAM_DeviceId , Module * > samDevRegistry; | |
55 | typedef std::map <SAM_DeviceId , Module * >::iterator samDevRegistryIter; | |
56 | ||
57 | samDevRegistry r; | |
58 | samDevRegistryIter ri; | |
59 | ||
60 | SAM_DeviceId handle; | |
61 | // make it threadsafe | |
62 | pthread_mutex_t handleMutex; | |
63 | ||
64 | public: | |
65 | ||
66 | // device ids start from 1 instead of 0. 0 is the default | |
67 | // value that occurs in traces created before this feature | |
68 | // was added. | |
69 | static const int devid_first = 1; | |
70 | ||
71 | devRegistry(); | |
72 | ~devRegistry(); | |
73 | ||
74 | // register the device with SAM and return a unique system level handle. | |
75 | SAM_DeviceId devRegistry::registerDev (Module * dev){ | |
76 | SAM_DeviceId ret; | |
77 | pthread_mutex_lock(&handleMutex); | |
78 | // check if there are multple registrations of the same device | |
79 | for( ri = r.begin(); ri != r.end(); ri++) | |
80 | if(ri->second == dev){ | |
81 | printf("Error %s already registered\n"); | |
82 | assert(0); | |
83 | } | |
84 | ret = handle++; | |
85 | r[ret] = dev; | |
86 | pthread_mutex_unlock(&handleMutex); | |
87 | return ret; | |
88 | } | |
89 | // get the name of the device with id 'handle' | |
90 | const char * getName (SAM_DeviceId handle); | |
91 | ||
92 | // dump the device name<->trace handle mapping into file FP. | |
93 | // FP can be stderr. Can be used by UI or trace dump functions. | |
94 | void dump(FILE * fp); | |
95 | }; | |
96 | ||
97 | ||
98 | #endif // _DEV_REGISTRY_H_ | |
99 | ||
100 |