@@ -1177,6 +1177,34 @@ impl CrosEc {
1177
1177
Ok ( result. valid )
1178
1178
}
1179
1179
1180
+ pub fn read_ec_gpu_chunk ( & self , addr : u16 , len : u16 ) -> EcResult < Vec < u8 > > {
1181
+ let eeprom_port = 0x05 ;
1182
+ let eeprom_addr = 0x50 ;
1183
+ let mut data: Vec < u8 > = Vec :: with_capacity ( len. into ( ) ) ;
1184
+
1185
+ while data. len ( ) < len. into ( ) {
1186
+ let remaining = len - data. len ( ) as u16 ;
1187
+ let chunk_len = std:: cmp:: min ( i2c_passthrough:: MAX_I2C_CHUNK , remaining. into ( ) ) ;
1188
+ let offset = addr + data. len ( ) as u16 ;
1189
+ let i2c_response = i2c_passthrough:: i2c_read (
1190
+ self ,
1191
+ eeprom_port,
1192
+ eeprom_addr,
1193
+ offset,
1194
+ chunk_len as u16 ,
1195
+ ) ?;
1196
+ if let Err ( EcError :: DeviceError ( err) ) = i2c_response. is_successful ( ) {
1197
+ return Err ( EcError :: DeviceError ( format ! (
1198
+ "I2C read was not successful: {:?}" ,
1199
+ err
1200
+ ) ) ) ;
1201
+ }
1202
+ data. extend ( i2c_response. data ) ;
1203
+ }
1204
+
1205
+ Ok ( data)
1206
+ }
1207
+
1180
1208
pub fn write_ec_gpu_chunk ( & self , offset : u16 , data : & [ u8 ] ) -> EcResult < ( ) > {
1181
1209
let result = i2c_passthrough:: i2c_write ( self , 5 , 0x50 , offset, data) ?;
1182
1210
result. is_successful ( )
@@ -1226,6 +1254,15 @@ impl CrosEc {
1226
1254
Ok ( ( ) )
1227
1255
}
1228
1256
1257
+ pub fn read_gpu_desc_header ( & self ) -> EcResult < GpuCfgDescriptor > {
1258
+ let bytes =
1259
+ self . read_ec_gpu_chunk ( 0x00 , core:: mem:: size_of :: < GpuCfgDescriptor > ( ) as u16 ) ?;
1260
+ let header: * const GpuCfgDescriptor = unsafe { std:: mem:: transmute ( bytes. as_ptr ( ) ) } ;
1261
+ let header = unsafe { * header } ;
1262
+
1263
+ Ok ( header)
1264
+ }
1265
+
1229
1266
/// Requests recent console output from EC and constantly asks for more
1230
1267
/// Prints the output and returns it when an error is encountered
1231
1268
pub fn console_read ( & self ) -> EcResult < ( ) > {
@@ -1633,3 +1670,28 @@ pub struct IntrusionStatus {
1633
1670
/// That means we only know if it was opened at least once, while off, not how many times.
1634
1671
pub vtr_open_count : u8 ,
1635
1672
}
1673
+
1674
+ #[ derive( Clone , Debug , Copy , PartialEq ) ]
1675
+ #[ repr( C , packed) ]
1676
+ pub struct GpuCfgDescriptor {
1677
+ /// Expansion bay card magic value that is unique
1678
+ pub magic : [ u8 ; 4 ] ,
1679
+ /// Length of header following this field
1680
+ pub length : u32 ,
1681
+ /// descriptor version, if EC max version is lower than this, ec cannot parse
1682
+ pub desc_ver_major : u16 ,
1683
+ pub desc_ver_minor : u16 ,
1684
+ /// Hardware major version
1685
+ pub hardware_version : u16 ,
1686
+ /// Hardware minor revision
1687
+ pub hardware_revision : u16 ,
1688
+ /// 18 digit Framework Serial that starts with FRA
1689
+ /// the first 10 digits must be allocated by framework
1690
+ pub serial : [ u8 ; 20 ] ,
1691
+ /// Length of descriptor following heade
1692
+ pub descriptor_length : u32 ,
1693
+ /// CRC of descriptor
1694
+ pub descriptor_crc32 : u32 ,
1695
+ /// CRC of header before this value
1696
+ pub crc32 : u32 ,
1697
+ }
0 commit comments