@@ -5,15 +5,15 @@ use alloc::string::String;
55use core:: char;
66use coreboot_fs:: Rom ;
77use ecflash:: EcFlash ;
8- use intel_spi:: { HsfStsCtl , Spi , SpiKbl , SpiCnl } ;
8+ use intel_spi:: { HsfStsCtl , Spi , SpiDev } ;
99use plain:: Plain ;
1010use std:: fs:: { find, load} ;
1111use std:: ptr;
1212use std:: vars:: { get_boot_item, get_boot_order, set_boot_item, set_boot_order} ;
1313use std:: uefi:: reset:: ResetType ;
1414use std:: uefi:: status:: { Error , Result , Status } ;
1515
16- use super :: { FIRMWARECAP , FIRMWAREDIR , FIRMWARENSH , FIRMWAREROM , H2OFFT , IFLASHV , UEFIFLASH , shell, Component } ;
16+ use super :: { FIRMWARECAP , FIRMWAREDIR , FIRMWARENSH , FIRMWAREROM , H2OFFT , IFLASHV , UEFIFLASH , shell, Component , pci_mcfg , UefiMapper } ;
1717
1818fn copy_region ( region : intelflash:: RegionKind , old_data : & [ u8 ] , new_data : & mut [ u8 ] ) -> core:: result:: Result < bool , String > {
1919 let old_opt = intelflash:: Rom :: new ( old_data) ?. get_region_base_limit ( region) ?;
@@ -102,44 +102,54 @@ impl BiosComponent {
102102 }
103103 }
104104
105- pub fn spi ( & self ) -> Option < ( & ' static mut dyn Spi , HsfStsCtl ) > {
105+ pub fn spi ( & self ) -> Option < ( SpiDev < ' static , UefiMapper > , HsfStsCtl ) > {
106+ static mut UEFI_MAPPER : UefiMapper = UefiMapper ;
107+
106108 match self . bios_vendor . as_str ( ) {
107109 "coreboot" => match self . system_version . as_str ( ) {
108- "galp2" |
109- "galp3" |
110- "galp3-b" => {
111- let spi_kbl = unsafe {
112- & mut * ( SpiKbl :: address ( ) as * mut SpiKbl )
113- } ;
114- let hsfsts_ctl = spi_kbl. hsfsts_ctl ( ) ;
115- Some ( ( spi_kbl as & mut dyn Spi , hsfsts_ctl) )
116- } ,
117110 "addw1" |
118111 "addw2" |
119112 "bonw14" |
120113 "darp5" |
121114 "darp6" |
122- "darp7" | // Technically TGL-U but protocol is the same
115+ "darp7" |
116+ "galp2" |
117+ "galp3" |
118+ "galp3-b" |
123119 "galp3-c" |
124120 "galp4" |
125- "galp5" | // Technically TGL-U but protocol is the same
121+ "galp5" |
126122 "gaze14" |
127123 "gaze15" |
128- "gaze16-3050" | // Technically TGL-H but protocol is the same
129- "gaze16-3060" | // Technically TGL-H but protocol is the same
130- "gaze16-3060-b" | // Technically TGL-H but protocol is the same
124+ "gaze16-3050" |
125+ "gaze16-3060" |
126+ "gaze16-3060-b" |
127+ "gaze17-3050" |
128+ "gaze17-3060" |
129+ "gaze17-3060-b" |
131130 "lemp9" |
132- "lemp10" | // Technically TGL-U but protocol is the same
131+ "lemp10" |
133132 "oryp5" |
134133 "oryp6" |
135134 "oryp7" |
136- "oryp8" // Technically TGL-H but protocol is the same
135+ "oryp8"
137136 => {
138- let spi_cnl = unsafe {
139- & mut * ( SpiCnl :: address ( ) as * mut SpiCnl )
137+ let mcfg = match pci_mcfg ( ) {
138+ Some ( some) => some,
139+ None => {
140+ println ! ( "failed to get MCFG table" ) ;
141+ return None ;
142+ }
143+ } ;
144+ let spi = match unsafe { SpiDev :: new ( mcfg, & mut UEFI_MAPPER ) } {
145+ Ok ( ok) => ok,
146+ Err ( err) => {
147+ println ! ( "failed to get SPI device: {}" , err) ;
148+ return None ;
149+ }
140150 } ;
141- let hsfsts_ctl = spi_cnl . hsfsts_ctl ( ) ;
142- Some ( ( spi_cnl as & mut dyn Spi , hsfsts_ctl) )
151+ let hsfsts_ctl = spi . regs . hsfsts_ctl ( ) ;
152+ Some ( ( spi , hsfsts_ctl) )
143153 } ,
144154 _ => None ,
145155 } ,
@@ -200,7 +210,7 @@ impl Component for BiosComponent {
200210
201211 fn validate ( & self ) -> Result < bool > {
202212 let data = load ( self . path ( ) ) ?;
203- if let Some ( ( spi, _hsfsts_ctl) ) = self . spi ( ) {
213+ if let Some ( ( mut spi, _hsfsts_ctl) ) = self . spi ( ) {
204214 // if hsfsts_ctl.contains(HsfStsCtl::FDOPSS) {
205215 // println!("SPI currently locked, attempting to unlock");
206216 // Self::spi_unlock();
@@ -224,7 +234,7 @@ impl Component for BiosComponent {
224234 }
225235
226236 fn flash ( & self ) -> Result < ( ) > {
227- if let Some ( ( spi, _hsfsts_ctl) ) = self . spi ( ) {
237+ if let Some ( ( mut spi, _hsfsts_ctl) ) = self . spi ( ) {
228238 // Read new data
229239 let mut new;
230240 {
0 commit comments