-
Notifications
You must be signed in to change notification settings - Fork 3
/
type_07_cache.go
293 lines (257 loc) · 6.1 KB
/
type_07_cache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
package dmi
import (
"fmt"
)
type CacheOperationalMode byte
const (
CacheOperationalModeWriteThrough CacheOperationalMode = iota
CacheOperationalModeWriteBack
CacheOperationalModeVariesWithMemoryAddress
CacheOperationalModeUnknown
)
func (c CacheOperationalMode) String() string {
modes := [...]string{
"Write Through",
"Write Back",
"Varies With Memory Address",
"Unknown",
}
return modes[c]
}
type CacheLocation byte
const (
CacheLocationInternal CacheLocation = iota
CacheLocationExternal
CacheLocationReserved
CacheLocationUnknown
)
func (c CacheLocation) String() string {
locations := [...]string{
"Internal",
"External",
"Reserved",
"Unknown",
}
return locations[c]
}
type CacheLevel byte
const (
CacheLevel1 CacheLevel = iota
CacheLevel2
CacheLevel3
)
func (c CacheLevel) String() string {
levels := [...]string{
"Level1",
"Level2",
"Level3",
}
return levels[c]
}
type CacheConfiguration struct {
Mode CacheOperationalMode
Enabled bool
Location CacheLocation
Socketed bool
Level CacheLevel
}
func NewCacheConfiguration(u uint16) CacheConfiguration {
var c CacheConfiguration
c.Level = CacheLevel(byte(u & 0x7))
c.Socketed = (u&0x10 == 1)
c.Location = CacheLocation((u >> 5) & 0x3)
c.Enabled = (u&(0x1<<7) == 1)
c.Mode = CacheOperationalMode((u >> 8) & 0x7)
return c
}
func (c CacheConfiguration) String() string {
return fmt.Sprintf("Cache Configuration:\n"+
"\tLevel: %s\n"+
"\tSocketed: %v\n"+
"\tLocation: %s\n"+
"\tEnabled: %v\n"+
"\tMode:\n\t\t",
c.Level,
c.Socketed,
c.Location,
c.Enabled,
c.Mode)
}
type CacheGranularity byte
const (
CacheGranularity1K CacheGranularity = iota
CacheGranularity64K
)
func (c CacheGranularity) String() string {
grans := [...]string{
"1K",
"64K",
}
return grans[c]
}
type CacheSize struct {
Granularity CacheGranularity
Size uint16
}
func NewCacheSize(u uint16) CacheSize {
var c CacheSize
c.Granularity = CacheGranularity(u >> 15)
c.Size = u &^ (uint16(1) << 15)
return c
}
func (c CacheSize) String() string {
return fmt.Sprintf("%s * %s", c.Size, c.Granularity)
}
type CacheSRAMType uint16
const (
CacheSRAMTypeOther CacheSRAMType = 1 << iota
CacheSRAMTypeUnknown
CacheSRAMTypeNonBurst
CacheSRAMTypeBurst
CacheSRAMTypePipelineBurst
CacheSRAMTypeSynchronous
CacheSRAMTypeAsynchronous
CacheSRAMTypeReserved
)
func (c CacheSRAMType) String() string {
types := [...]string{
"Other",
"Unknown",
"Non-Burst",
"Burst",
"Pipeline Burst",
"Synchronous",
"Asynchronous",
"Reserved",
}
return types[c/2]
}
type CacheSpeed byte
type CacheErrorCorrectionType byte
const (
CacheErrorCorrectionTypeOther CacheErrorCorrectionType = 1 + iota
CacheErrorCorrectionTypeUnknown
CacheErrorCorrectionTypeNone
CacheErrorCorrectionTypeParity
CacheErrorCorrectionTypeSinglebitECC
CacheErrorCorrectionTypeMultibitECC
)
func (c CacheErrorCorrectionType) String() string {
types := [...]string{
"Other",
"Unknown",
"None",
"Parity",
"Single-bit ECC",
"Multi-bit ECC",
}
return types[c-1]
}
type CacheSystemCacheType byte
const (
CacheSystemCacheTypeOther CacheSystemCacheType = 1 + iota
CacheSystemCacheTypeUnknown
CacheSystemCacheTypeInstruction
CacheSystemCacheTypeData
CacheSystemCacheTypeUnified
)
func (c CacheSystemCacheType) String() string {
types := [...]string{
"Other",
"Unknown",
"Instruction",
"Data",
"Unified",
}
return types[c-1]
}
type CacheAssociativity byte
const (
CacheAssociativityOther CacheAssociativity = 1 + iota
CacheAssociativityUnknown
CacheAssociativityDirectMapped
CacheAssociativity2waySetAssociative
CacheAssociativity4waySetAssociative
CacheAssociativityFullyAssociative
CacheAssociativity8waySetAssociative
CacheAssociativity16waySetAssociative
CacheAssociativity12waySetAssociative
CacheAssociativity24waySetAssociative
CacheAssociativity32waySetAssociative
CacheAssociativity48waySetAssociative
CacheAssociativity64waySetAssociative
CacheAssociativity20waySetAssociative
)
func (c CacheAssociativity) String() string {
caches := [...]string{
"Other",
"Unknown",
"Direct Mapped",
"2-way Set-Associative",
"4-way Set-Associative",
"Fully Associative",
"8-way Set-Associative",
"16-way Set-Associative",
"12-way Set-Associative",
"24-way Set-Associative",
"32-way Set-Associative",
"48-way Set-Associative",
"64-way Set-Associative",
"20-way Set-Associative",
}
return caches[c]
}
type CacheInformation struct {
infoCommon
SocketDesignation string
Configuration CacheConfiguration
MaximumCacheSize CacheSize
InstalledSize CacheSize
SupportedSRAMType CacheSRAMType
CurrentSRAMType CacheSRAMType
CacheSpeed CacheSpeed
ErrorCorrectionType CacheErrorCorrectionType
SystemCacheType CacheSystemCacheType
Associativity CacheAssociativity
}
func (c CacheInformation) String() string {
return fmt.Sprintf("Cache Information\n"+
"\tSocket Designation: %s\n"+
"\tConfiguration: %s\n"+
"\tMaximum Cache Size: %s\n"+
"\tInstalled Size: %s\n"+
"\tSupportedSRAM Type: %s\n"+
"\tCurrentSRAM Type: %s\n"+
"\tCache Speed: %s\n"+
"\tError Correction Type: %s\n"+
"\tSystem Cache Type: %s\n"+
"\tAssociativity: %s",
c.SocketDesignation,
c.Configuration,
c.MaximumCacheSize,
c.InstalledSize,
c.SupportedSRAMType,
c.CurrentSRAMType,
c.CacheSpeed,
c.ErrorCorrectionType,
c.SystemCacheType,
c.Associativity)
}
func newCacheInformation(h dmiHeader) dmiTyper {
data := h.data
return &CacheInformation{
SocketDesignation: h.FieldString(int(data[0x04])),
Configuration: NewCacheConfiguration(u16(data[0x05:0x07])),
MaximumCacheSize: NewCacheSize(u16(data[0x07:0x09])),
InstalledSize: NewCacheSize(u16(data[0x09:0x0B])),
SupportedSRAMType: CacheSRAMType(u16(data[0x0B:0x0D])),
CurrentSRAMType: CacheSRAMType(u16(data[0x0D:0x0F])),
CacheSpeed: CacheSpeed(data[0x0F]),
ErrorCorrectionType: CacheErrorCorrectionType(data[0x10]),
SystemCacheType: CacheSystemCacheType(data[0x11]),
Associativity: CacheAssociativity(data[0x12]),
}
}
func init() {
addTypeFunc(SMBIOSStructureTypeCache, newCacheInformation)
}