gitlab.com/apertussolutions/u-root@v7.0.0+incompatible/pkg/smbios/type7_cache_information.go (about) 1 // Copyright 2016-2019 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package smbios 6 7 import ( 8 "errors" 9 "fmt" 10 "strings" 11 ) 12 13 // Much of this is auto-generated. If adding a new type, see README for instructions. 14 15 // CacheInfo is defined in DSP0134 7.8. 16 type CacheInfo struct { 17 Table 18 SocketDesignation string // 04h 19 Configuration uint16 // 05h 20 MaximumSize uint16 // 07h 21 InstalledSize uint16 // 09h 22 SupportedSRAMType CacheSRAMType // 0Bh 23 CurrentSRAMType CacheSRAMType // 0Dh 24 Speed uint8 // 0Fh 25 ErrorCorrectionType CacheErrorCorrectionType // 10h 26 SystemType CacheSystemType // 11h 27 Associativity CacheAssociativity // 12h 28 MaximumSize2 uint32 // 13h 29 InstalledSize2 uint32 // 17h 30 } 31 32 // ParseCacheInfo parses a generic Table into CacheInfo. 33 func ParseCacheInfo(t *Table) (*CacheInfo, error) { 34 if t.Type != TableTypeCacheInfo { 35 return nil, fmt.Errorf("invalid table type %d", t.Type) 36 } 37 if t.Len() < 0xf { 38 return nil, errors.New("required fields missing") 39 } 40 ci := &CacheInfo{Table: *t} 41 _, err := parseStruct(t, 0 /* off */, false /* complete */, ci) 42 if err != nil { 43 return nil, err 44 } 45 return ci, nil 46 } 47 48 func cacheSizeBytes2Or1(size1 uint16, size2 uint32) uint64 { 49 mul2 := uint64(1024) 50 if size2&0x80000000 != 0 { 51 mul2 *= 64 52 } 53 if size2Bytes := uint64(size2&0x7fffffff) * mul2; size2Bytes != 0 { 54 return size2Bytes 55 } 56 mul1 := uint64(1024) 57 if size1&0x8000 != 0 { 58 mul1 *= 64 59 } 60 return uint64(size1&0x7fff) * mul1 61 } 62 63 // GetMaxSizeBytes returns the maximum size of the cache that can be installed, in bytes. 64 func (ci *CacheInfo) GetMaxSizeBytes() uint64 { 65 return cacheSizeBytes2Or1(ci.MaximumSize, ci.MaximumSize2) 66 } 67 68 // GetInstalledSizeBytes returns the currently installed cache size, in bytes. 69 func (ci *CacheInfo) GetInstalledSizeBytes() uint64 { 70 return cacheSizeBytes2Or1(ci.InstalledSize, ci.InstalledSize2) 71 } 72 73 func (ci *CacheInfo) String() string { 74 enDis := "Disabled" 75 if ci.Configuration&0x80 != 0 { 76 enDis = "Enabled" 77 } 78 sock := "Not Socketed" 79 if ci.Configuration&0x8 != 0 { 80 sock = "Socketed" 81 } 82 83 om := "" 84 switch (ci.Configuration >> 8) & 3 { 85 case 0: 86 om = "Write Through" 87 case 1: 88 om = "Write Back" 89 case 2: 90 om = "Varies With Memory Address" 91 case 3: 92 om = "Unknown" 93 } 94 95 loc := "" 96 switch (ci.Configuration >> 5) & 3 { 97 case 0: 98 loc = "Internal" 99 case 1: 100 loc = "External" 101 case 2: 102 loc = "Reserved" 103 case 3: 104 loc = "Unknown" 105 } 106 107 speedStr := "Unknown" 108 if ci.Speed > 0 { 109 speedStr = fmt.Sprintf("%d ns", ci.Speed) 110 } 111 112 lines := []string{ 113 ci.Header.String(), 114 fmt.Sprintf("Socket Designation: %s", ci.SocketDesignation), 115 fmt.Sprintf("Configuration: %s, %s, Level %d", enDis, sock, (ci.Configuration&7)+1), 116 fmt.Sprintf("Operational Mode: %s", om), 117 fmt.Sprintf("Location: %s", loc), 118 fmt.Sprintf("Installed Size: %s", kmgt(ci.GetInstalledSizeBytes())), 119 fmt.Sprintf("Maximum Size: %s", kmgt(ci.GetMaxSizeBytes())), 120 fmt.Sprintf("Supported SRAM Types:\n%s", ci.SupportedSRAMType), 121 fmt.Sprintf("Installed SRAM Type: %s", strings.TrimSpace(ci.CurrentSRAMType.String())), 122 } 123 if ci.Len() > 0xf { 124 lines = append(lines, 125 fmt.Sprintf("Speed: %s", speedStr), 126 fmt.Sprintf("Error Correction Type: %s", ci.ErrorCorrectionType), 127 fmt.Sprintf("System Type: %s", ci.SystemType), 128 fmt.Sprintf("Associativity: %s", ci.Associativity), 129 ) 130 } 131 return strings.Join(lines, "\n\t") 132 } 133 134 // CacheSRAMType is defined in DSP0134 7.8.2. 135 type CacheSRAMType uint16 136 137 // CacheSRAMType fields are defined in DSP0134 7.8.2 138 const ( 139 CacheSRAMTypeOther CacheSRAMType = 1 << 0 // Other 140 CacheSRAMTypeUnknown CacheSRAMType = 1 << 1 // Unknown 141 CacheSRAMTypeNonBurst CacheSRAMType = 1 << 2 // Non-Burst 142 CacheSRAMTypeBurst CacheSRAMType = 1 << 3 // Burst 143 CacheSRAMTypePipelineBurst CacheSRAMType = 1 << 4 // Pipeline Burst 144 CacheSRAMTypeSynchronous CacheSRAMType = 1 << 5 // Synchronous 145 CacheSRAMTypeAsynchronous CacheSRAMType = 1 << 6 // Asynchronous 146 ) 147 148 func (v CacheSRAMType) String() string { 149 var lines []string 150 if v&CacheSRAMTypeOther != 0 { 151 lines = append(lines, "Other") 152 } 153 if v&CacheSRAMTypeUnknown != 0 { 154 lines = append(lines, "Unknown") 155 } 156 if v&CacheSRAMTypeNonBurst != 0 { 157 lines = append(lines, "Non-Burst") 158 } 159 if v&CacheSRAMTypeBurst != 0 { 160 lines = append(lines, "Burst") 161 } 162 if v&CacheSRAMTypePipelineBurst != 0 { 163 lines = append(lines, "Pipeline Burst") 164 } 165 if v&CacheSRAMTypeSynchronous != 0 { 166 lines = append(lines, "Synchronous") 167 } 168 if v&CacheSRAMTypeAsynchronous != 0 { 169 lines = append(lines, "Asynchronous") 170 } 171 return "\t\t" + strings.Join(lines, "\n\t\t") 172 } 173 174 // CacheErrorCorrectionType is defined in DSP0134 7.8.3. 175 type CacheErrorCorrectionType uint8 176 177 // CacheErrorCorrectionType values are defined in DSP0134 7.8.3. 178 const ( 179 CacheErrorCorrectionTypeOther CacheErrorCorrectionType = 0x01 // Other 180 CacheErrorCorrectionTypeUnknown CacheErrorCorrectionType = 0x02 // Unknown 181 CacheErrorCorrectionTypeNone CacheErrorCorrectionType = 0x03 // None 182 CacheErrorCorrectionTypeParity CacheErrorCorrectionType = 0x04 // Parity 183 CacheErrorCorrectionTypeSinglebitECC CacheErrorCorrectionType = 0x05 // Single-bit ECC 184 CacheErrorCorrectionTypeMultibitECC CacheErrorCorrectionType = 0x06 // Multi-bit ECC 185 ) 186 187 func (v CacheErrorCorrectionType) String() string { 188 names := map[CacheErrorCorrectionType]string{ 189 CacheErrorCorrectionTypeOther: "Other", 190 CacheErrorCorrectionTypeUnknown: "Unknown", 191 CacheErrorCorrectionTypeNone: "None", 192 CacheErrorCorrectionTypeParity: "Parity", 193 CacheErrorCorrectionTypeSinglebitECC: "Single-bit ECC", 194 CacheErrorCorrectionTypeMultibitECC: "Multi-bit ECC", 195 } 196 if name, ok := names[v]; ok { 197 return name 198 } 199 return fmt.Sprintf("%#x", uint8(v)) 200 } 201 202 // CacheSystemType is defined in DSP0134 7.8.4. 203 type CacheSystemType uint8 204 205 // CacheSystemType values are defined in DSP0134 7.8.4. 206 const ( 207 CacheSystemTypeOther CacheSystemType = 0x01 // Other 208 CacheSystemTypeUnknown CacheSystemType = 0x02 // Unknown 209 CacheSystemTypeInstruction CacheSystemType = 0x03 // Instruction 210 CacheSystemTypeData CacheSystemType = 0x04 // Data 211 CacheSystemTypeUnified CacheSystemType = 0x05 // Unified 212 ) 213 214 func (v CacheSystemType) String() string { 215 names := map[CacheSystemType]string{ 216 CacheSystemTypeOther: "Other", 217 CacheSystemTypeUnknown: "Unknown", 218 CacheSystemTypeInstruction: "Instruction", 219 CacheSystemTypeData: "Data", 220 CacheSystemTypeUnified: "Unified", 221 } 222 if name, ok := names[v]; ok { 223 return name 224 } 225 return fmt.Sprintf("%#x", uint8(v)) 226 } 227 228 // CacheAssociativity is defined in DSP0134 7.8.5. 229 type CacheAssociativity uint8 230 231 // CacheAssociativity values are defined in DSP0134 7.8.5. 232 const ( 233 CacheAssociativityOther CacheAssociativity = 0x01 // Other 234 CacheAssociativityUnknown CacheAssociativity = 0x02 // Unknown 235 CacheAssociativityDirectMapped CacheAssociativity = 0x03 // Direct Mapped 236 CacheAssociativity2waySetAssociative CacheAssociativity = 0x04 // 2-way Set-associative 237 CacheAssociativity4waySetAssociative CacheAssociativity = 0x05 // 4-way Set-associative 238 CacheAssociativityFullyAssociative CacheAssociativity = 0x06 // Fully Associative 239 CacheAssociativity8waySetAssociative CacheAssociativity = 0x07 // 8-way Set-associative 240 CacheAssociativity16waySetAssociative CacheAssociativity = 0x08 // 16-way Set-associative 241 CacheAssociativity12waySetAssociative CacheAssociativity = 0x09 // 12-way Set-associative 242 CacheAssociativity24waySetAssociative CacheAssociativity = 0x0a // 24-way Set-associative 243 CacheAssociativity32waySetAssociative CacheAssociativity = 0x0b // 32-way Set-associative 244 CacheAssociativity48waySetAssociative CacheAssociativity = 0x0c // 48-way Set-associative 245 CacheAssociativity64waySetAssociative CacheAssociativity = 0x0d // 64-way Set-associative 246 CacheAssociativity20waySetAssociative CacheAssociativity = 0x0e // 20-way Set-associative 247 ) 248 249 func (v CacheAssociativity) String() string { 250 names := map[CacheAssociativity]string{ 251 CacheAssociativityOther: "Other", 252 CacheAssociativityUnknown: "Unknown", 253 CacheAssociativityDirectMapped: "Direct Mapped", 254 CacheAssociativity2waySetAssociative: "2-way Set-associative", 255 CacheAssociativity4waySetAssociative: "4-way Set-associative", 256 CacheAssociativityFullyAssociative: "Fully Associative", 257 CacheAssociativity8waySetAssociative: "8-way Set-associative", 258 CacheAssociativity16waySetAssociative: "16-way Set-associative", 259 CacheAssociativity12waySetAssociative: "12-way Set-associative", 260 CacheAssociativity24waySetAssociative: "24-way Set-associative", 261 CacheAssociativity32waySetAssociative: "32-way Set-associative", 262 CacheAssociativity48waySetAssociative: "48-way Set-associative", 263 CacheAssociativity64waySetAssociative: "64-way Set-associative", 264 CacheAssociativity20waySetAssociative: "20-way Set-associative", 265 } 266 if name, ok := names[v]; ok { 267 return name 268 } 269 return fmt.Sprintf("%#x", uint8(v)) 270 }