@@ -158,13 +158,14 @@ func generateCoreCounts(sd: inout static_data) {
158158 }
159159 }
160160 }
161-
162- if model_name != " " {
163- if model_name. lowercased ( ) . contains ( " air " ) {
161+
162+ if let count = SMC . shared. getValue ( " FNum " ) {
163+ switch count {
164+ case 0.0 :
164165 sd. fan_exist = false
165- } else if model_name . lowercased ( ) . contains ( " mini " ) {
166+ case 1.0 :
166167 sd. fan_mode = 1
167- } else {
168+ default :
168169 sd. fan_mode = 2
169170 }
170171 } else {
@@ -179,27 +180,57 @@ func generateCoreCounts(sd: inout static_data) {
179180 port = kIOMasterPortDefault
180181 }
181182
182- if let service = IOServiceMatching ( " AppleARMIODevice " ) {
183+ func regAccessFailed( _ name: String ) {
184+ print ( " Failed to access \( name) service in IORegistry " )
185+ exit ( 1 )
186+ }
187+
188+ let option_bits = IOOptionBits ( kIORegistryIterateRecursively + kIORegistryIterateParents)
189+
190+ var name = " product "
191+ if let service = IOServiceNameMatching ( name) {
183192 if IOServiceGetMatchingServices ( port, service, & iter) != kIOReturnSuccess {
184- print ( " Failed to access AppleARMIODevice service in IORegistry " )
193+ regAccessFailed ( name)
194+ }
195+ } else {
196+ regAccessFailed ( name)
197+ }
198+
199+ while case let entry = IOIteratorNext ( iter) , entry != IO_OBJECT_NULL {
200+ if let productname = IORegistryEntrySearchCFProperty ( entry, kIOServicePlane, " product-name " as CFString , kCFAllocatorDefault, option_bits) {
201+ sd. marketing_name = " "
202+ let prodname = productname. bytes? . assumingMemoryBound ( to: CChar . self)
203+ for ii in 0 ... productname. length {
204+ sd. marketing_name += String ( format: " %c " , prodname![ ii] )
205+ }
206+ } else {
207+ print ( " Failed to read \" product-name \" from \( name) service in IORegistry " )
185208 exit ( 1 )
186209 }
210+ IOObjectRelease ( entry)
211+ }
212+
213+ name = " AppleARMIODevice "
214+ if let service = IOServiceMatching ( name) {
215+ if IOServiceGetMatchingServices ( port, service, & iter) != kIOReturnSuccess {
216+ regAccessFailed ( name)
217+ }
187218 } else {
188- print ( " Failed to find AppleARMIODevice service in IORegistry " )
189- exit ( 1 )
219+ regAccessFailed ( name)
190220 }
191221
192222 while case let entry = IOIteratorNext ( iter) , entry != IO_OBJECT_NULL {
193223 if IORegistryEntryCreateCFProperties ( entry, & servicedict, kCFAllocatorDefault, 0 ) != kIOReturnSuccess {
194- print ( " Failed to create CFProperties for AppleARMIODevice service in IORegistry " )
224+ print ( " Failed to create CFProperties for \( name ) service in IORegistry " )
195225 exit ( 1 )
196226 }
197227
198228 guard let serviceDict = servicedict? . takeRetainedValue ( ) as? [ String : AnyObject ] else { continue }
199229
200- if case let data = serviceDict [ " clusters " ] , data != nil {
201- let databytes = data? . bytes? . assumingMemoryBound ( to: UInt8 . self)
202- for ii in stride ( from: 0 , to: data!. length, by: 4 ) {
230+ //if case let data = serviceDict["clusters"], data != nil {
231+ if let data = serviceDict [ " clusters " ] {
232+ let databytes = data. bytes? . assumingMemoryBound ( to: UInt8 . self)
233+ for ii in stride ( from: 0 , to: data. length, by: 4 ) {
203234 let cores = UInt8 ( atoi ( String ( format: " %02x " , databytes![ ii] ) ) )
204235 sd. cluster_core_counts. append ( cores)
205236 var die_num = 1
@@ -219,29 +250,57 @@ func generateCoreCounts(sd: inout static_data) {
219250 }
220251 }
221252
222- if let service = IOServiceMatching ( " AGXAccelerator " ) {
253+ name = " AGXAccelerator "
254+ if let service = IOServiceMatching ( name) {
223255 if IOServiceGetMatchingServices ( port, service, & iter) != kIOReturnSuccess {
224- print ( " Failed to access AGXAccelerator service in IORegistry " )
225- exit ( 1 )
256+ regAccessFailed ( name)
226257 }
227258 } else {
228- print ( " Failed to find AGXAccelerator service in IORegistry " )
229- exit ( 1 )
259+ regAccessFailed ( name)
230260 }
231261
232262 while case let entry = IOIteratorNext ( iter) , entry != IO_OBJECT_NULL {
233- if let gpucorecnt = IORegistryEntrySearchCFProperty ( entry, kIOServicePlane, " gpu-core-count " as CFString , kCFAllocatorDefault, IOOptionBits ( kIORegistryIterateRecursively + kIORegistryIterateParents) ) {
263+ if IORegistryEntryCreateCFProperties ( entry, & servicedict, kCFAllocatorDefault, 0 ) != kIOReturnSuccess {
264+ print ( " Failed to create CFProperties for \( name) service in IORegistry " )
265+ exit ( 1 )
266+ }
267+
268+ guard let serviceDict = servicedict? . takeRetainedValue ( ) as? [ String : AnyObject ] else { continue }
269+
270+ if let gpucorecnt = serviceDict [ " gpu-core-count " ] {
234271 sd. gpu_core_count = gpucorecnt as? Int ?? 0
235272 IOObjectRelease ( entry)
236273 } else {
237- print ( " Failed to read \" gpu-core-count \" from AGXAccelerator service in IORegistry " )
274+ print ( " Failed to read \" gpu-core-count \" from \( name) service in IORegistry " )
275+ exit ( 1 )
276+ }
277+
278+ if let gpuname = serviceDict [ " IOClass " ] {
279+ sd. gpu_arch_name = gpuname as? String ?? " "
280+ if let range = sd. gpu_arch_name. range ( of: name) {
281+ sd. gpu_arch_name. removeSubrange ( range)
282+ }
283+ } else {
284+ print ( " Failed to read \" gpu-arch-name \" from \( name) service in IORegistry " )
238285 exit ( 1 )
239286 }
287+ IOObjectRelease ( entry)
240288 }
241289 IOObjectRelease ( iter)
242290 }
243291}
244292
293+ func getOSCode( sd: inout static_data ) {
294+ autoreleasepool {
295+ let code_file = File ( " /System/Library/CoreServices/Setup Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf " )
296+ while let code_line = code_file? . getLine ( ) {
297+ if code_line. contains ( " SOFTWARE LICENSE AGREEMENT FOR macOS " ) {
298+ sd. os_code_name = String ( code_line. split ( separator: " " ) . last ?? " " ) . replacingOccurrences ( of: " \\ \n " , with: " " )
299+ }
300+ }
301+ }
302+ }
303+
245304func generateProcessorName( sd: inout static_data ) {
246305 autoreleasepool {
247306 var size = 0
@@ -360,7 +419,7 @@ func generateMicroArchs(sd: inout static_data) {
360419 sd. extra. append ( String (
361420 format: " %s " ,
362421 ( data? . takeRetainedValue ( ) . bytes? . assumingMemoryBound ( to: UInt8 . self) ) !
363- ) )
422+ ) . replacingOccurrences ( of : " apple, " , with : " " ) . capitalized )
364423 } else {
365424 archError ( sd: & sd)
366425 }
@@ -370,7 +429,7 @@ func generateMicroArchs(sd: inout static_data) {
370429 sd. extra. append ( String (
371430 format: " %s " ,
372431 ( data? . takeRetainedValue ( ) . bytes? . assumingMemoryBound ( to: UInt8 . self) ) !
373- ) )
432+ ) . replacingOccurrences ( of : " apple, " , with : " " ) . capitalized )
374433 } else {
375434 archError ( sd: & sd)
376435 }
0 commit comments