diff --git a/util/intelp2m/platforms/adl/macro.go b/util/intelp2m/platforms/adl/macro.go index 19e9bd20e5..63104d0ce8 100644 --- a/util/intelp2m/platforms/adl/macro.go +++ b/util/intelp2m/platforms/adl/macro.go @@ -14,6 +14,13 @@ const ( DW1Mask uint32 = 0b11111101111111111100001111111111 ) +var remapping = common.ResetSources{ + 0b00: bits.RstCfgRSMRST << bits.DW0PadRstCfg, + 0b01: bits.RstCfgDEEP << bits.DW0PadRstCfg, + 0b10: bits.RstCfgPLTRST << bits.DW0PadRstCfg, + 0b11: bits.RstCfgPWROK << bits.DW0PadRstCfg, +} + type BasePlatform struct { // based on the Cannon Lake platform cnl.BasePlatform @@ -28,30 +35,15 @@ func GetPlatform(dw0, dw1 uint32) common.PlatformIf { return &p } -// Override BasePlatform.RemapRstSrc() -func (p *BasePlatform) RemapRstSrc(m *common.Macro) { +// Override BasePlatform.RemapResetSource() +func (p *BasePlatform) RemapResetSource(m *common.Macro) { if strings.Contains(m.GetPadId(), "GPD") { // See reset map for the Alderlake GPD Group in the Community 2: // https://github.com/coreboot/coreboot/blob/master/src/soc/intel/alderlake/gpio.c#L21 // remmap is not required because it is the same as common. return } - - remapping := map[uint32]uint32{ - 0b00: bits.RstCfgRSMRST << bits.DW0PadRstCfg, - 0b01: bits.RstCfgDEEP << bits.DW0PadRstCfg, - 0b10: bits.RstCfgPLTRST << bits.DW0PadRstCfg, - 0b11: bits.RstCfgPWROK << bits.DW0PadRstCfg, + if err := p.UpdateResetSource(remapping); err != nil { + logs.Errorf("remap reset source for %s: %v", m.GetPadId(), err) } - dw0 := p.GetRegisterDW0() - source, valid := remapping[dw0.GetResetConfig()] - if valid { - dw0.Value &= 0x3fffffff - dw0.Value |= source - } else { - logs.Errorf("%s: skip re-mapping: DW0 %s: invalid reset config source value 0b%b", - m.GetPadId(), dw0, dw0.GetResetConfig()) - } - mask := bits.DW0[bits.DW0PadRstCfg] - dw0.CntrMaskFieldsClear(mask) } diff --git a/util/intelp2m/platforms/apl/macro.go b/util/intelp2m/platforms/apl/macro.go index f20acc46a3..614d0bebd6 100644 --- a/util/intelp2m/platforms/apl/macro.go +++ b/util/intelp2m/platforms/apl/macro.go @@ -25,8 +25,8 @@ func GetPlatform(dw0, dw1 uint32) common.PlatformIf { return &p } -// RemapRstSrc() remaps Pad Reset Source Config -func (p *BasePlatform) RemapRstSrc(m *common.Macro) {} +// RemapResetSource() remaps Pad Reset Source Config +func (p *BasePlatform) RemapResetSource(m *common.Macro) {} // Pull() adds The Pad Termination (TERM) parameter from PAD_CFG_DW1 to the macro func (p *BasePlatform) Pull(m *common.Macro) { diff --git a/util/intelp2m/platforms/cnl/macro.go b/util/intelp2m/platforms/cnl/macro.go index 7f5421510c..625df0aa5f 100644 --- a/util/intelp2m/platforms/cnl/macro.go +++ b/util/intelp2m/platforms/cnl/macro.go @@ -15,6 +15,12 @@ const ( DW1Mask uint32 = 0b11111101111111111100001111111111 ) +var remapping = common.ResetSources{ + 0b00: bits.RstCfgRSMRST << bits.DW0PadRstCfg, + 0b01: bits.RstCfgDEEP << bits.DW0PadRstCfg, + 0b10: bits.RstCfgPLTRST << bits.DW0PadRstCfg, +} + type BasePlatform struct { // based on the Sunrise platform snr.BasePlatform @@ -29,8 +35,8 @@ func GetPlatform(dw0, dw1 uint32) common.PlatformIf { return &p } -// Override BasePlatform.RemapRstSrc() -func (p *BasePlatform) RemapRstSrc(m *common.Macro) { +// Override BasePlatform.RemapResetSource() +func (p *BasePlatform) RemapResetSource(m *common.Macro) { if strings.Contains(m.GetPadId(), "GPP_A") || strings.Contains(m.GetPadId(), "GPP_B") || strings.Contains(m.GetPadId(), "GPP_G") { @@ -39,23 +45,9 @@ func (p *BasePlatform) RemapRstSrc(m *common.Macro) { // remmap is not required because it is the same as common. return } - - dw0 := p.GetRegisterDW0() - remapping := map[uint32]uint32{ - 0b00: bits.RstCfgRSMRST << bits.DW0PadRstCfg, - 0b01: bits.RstCfgDEEP << bits.DW0PadRstCfg, - 0b10: bits.RstCfgPLTRST << bits.DW0PadRstCfg, + if err := p.UpdateResetSource(remapping); err != nil { + logs.Errorf("remap reset source for %s: %v", m.GetPadId(), err) } - source, valid := remapping[dw0.GetResetConfig()] - if valid { - dw0.Value &= 0x3fffffff - dw0.Value |= source - } else { - logs.Errorf("%s: skip re-mapping: DW0 %s: invalid reset config source value 0b%b", - m.GetPadId(), dw0, dw0.GetResetConfig()) - } - mask := bits.DW0[bits.DW0PadRstCfg] - dw0.CntrMaskFieldsClear(mask) } // Override BasePlatform.Pull() diff --git a/util/intelp2m/platforms/common/common.go b/util/intelp2m/platforms/common/common.go index 57719842ca..9f4edce7c3 100644 --- a/util/intelp2m/platforms/common/common.go +++ b/util/intelp2m/platforms/common/common.go @@ -1,9 +1,14 @@ package common import ( + "fmt" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register/bits" ) +type ResetSources map[uint32]uint32 + type BasePlatform struct { dw0 register.DW0 dw1 register.DW1 @@ -23,3 +28,20 @@ func (p *BasePlatform) GetRegisterDW0() *register.DW0 { func (p *BasePlatform) GetRegisterDW1() *register.DW1 { return &p.dw1 } + +// UpdateResetSource() updates the Pad Reset configuration fields in the DW0 register according +// to the ResetSources{} map. Redefine this function for the corresponding platform if it has a +// difference in logic or register bits. +func (p *BasePlatform) UpdateResetSource(remapping ResetSources) error { + dw0 := p.GetRegisterDW0() + mask := bits.DW0[bits.DW0PadRstCfg] + source, valid := remapping[dw0.GetResetConfig()] + if !valid { + dw0.CntrMaskFieldsClear(mask) + return fmt.Errorf("invalid reset config source value 0b%b", dw0.GetResetConfig()) + } + dw0.Value &= ^mask + dw0.Value |= source + dw0.CntrMaskFieldsClear(mask) + return nil +} diff --git a/util/intelp2m/platforms/common/macro.go b/util/intelp2m/platforms/common/macro.go index 0f544acb08..76e76e81f5 100644 --- a/util/intelp2m/platforms/common/macro.go +++ b/util/intelp2m/platforms/common/macro.go @@ -22,7 +22,7 @@ type FieldsIf interface { } type PlatformIf interface { - RemapRstSrc(*Macro) + RemapResetSource(*Macro) Pull(*Macro) AddGpiMacro(*Macro) AddGpoMacro(*Macro) @@ -352,7 +352,7 @@ func (m *Macro) Bidirection() { // Generate() generates string of macro func (m *Macro) Generate() string { - m.Platform.RemapRstSrc(m) + m.Platform.RemapResetSource(m) if dw0 := m.Platform.GetRegisterDW0(); dw0.GetPadMode() == 0 { const txDisable uint32 = 0b01 const rxDisable uint32 = 0b10 diff --git a/util/intelp2m/platforms/ebg/macro.go b/util/intelp2m/platforms/ebg/macro.go index 771d6df6cd..f1a967ece4 100644 --- a/util/intelp2m/platforms/ebg/macro.go +++ b/util/intelp2m/platforms/ebg/macro.go @@ -12,6 +12,12 @@ const ( DW1Mask = 0b11111101111111111100001111111111 ) +var remapping = common.ResetSources{ + 0b00: bits.RstCfgRSMRST << bits.DW0PadRstCfg, + 0b01: bits.RstCfgDEEP << bits.DW0PadRstCfg, + 0b10: bits.RstCfgPLTRST << bits.DW0PadRstCfg, +} + type BasePlatform struct { // based on the Cannon Lake platform cnl.BasePlatform @@ -26,22 +32,9 @@ func GetPlatform(dw0, dw1 uint32) common.PlatformIf { return &p } -// Override BasePlatform.RemapRstSrc() -func (p *BasePlatform) RemapRstSrc(m *common.Macro) { - remapping := map[uint32]uint32{ - 0b00: bits.RstCfgRSMRST << bits.DW0PadRstCfg, - 0b01: bits.RstCfgDEEP << bits.DW0PadRstCfg, - 0b10: bits.RstCfgPLTRST << bits.DW0PadRstCfg, +// Override BasePlatform.RemapResetSource() +func (p *BasePlatform) RemapResetSource(m *common.Macro) { + if err := p.UpdateResetSource(remapping); err != nil { + logs.Errorf("remap reset source for %s: %v", m.GetPadId(), err) } - dw0 := p.GetRegisterDW0() - source, valid := remapping[dw0.GetResetConfig()] - if valid { - dw0.Value &= 0x3fffffff - dw0.Value |= source - } else { - logs.Errorf("%s: skip re-mapping: DW0 %s: invalid reset config source value 0b%b", - m.GetPadId(), dw0, dw0.GetResetConfig()) - } - mask := bits.DW0[bits.DW0PadRstCfg] - dw0.CntrMaskFieldsClear(mask) } diff --git a/util/intelp2m/platforms/jsl/macro.go b/util/intelp2m/platforms/jsl/macro.go index fa5cbedd7a..92cb66cf33 100644 --- a/util/intelp2m/platforms/jsl/macro.go +++ b/util/intelp2m/platforms/jsl/macro.go @@ -14,6 +14,12 @@ const ( DW1Mask = 0b11111101111111111100001111111111 ) +var remapping = common.ResetSources{ + 0b00: bits.RstCfgRSMRST << bits.DW0PadRstCfg, + 0b01: bits.RstCfgDEEP << bits.DW0PadRstCfg, + 0b10: bits.RstCfgPLTRST << bits.DW0PadRstCfg, +} + type BasePlatform struct { // based on the Cannon Lake platform cnl.BasePlatform @@ -28,8 +34,8 @@ func GetPlatform(dw0, dw1 uint32) common.PlatformIf { return &p } -// Override the base platform method -func (p *BasePlatform) RemapRstSrc(m *common.Macro) { +// Override BasePlatform.RemapResetSource() +func (p *BasePlatform) RemapResetSource(m *common.Macro) { if strings.Contains(m.GetPadId(), "GPP_F") || strings.Contains(m.GetPadId(), "GPP_B") || strings.Contains(m.GetPadId(), "GPP_A") || @@ -40,21 +46,7 @@ func (p *BasePlatform) RemapRstSrc(m *common.Macro) { // remmap is not required because it is the same as common. return } - - remapping := map[uint32]uint32{ - 0b00: bits.RstCfgRSMRST << bits.DW0PadRstCfg, - 0b01: bits.RstCfgDEEP << bits.DW0PadRstCfg, - 0b10: bits.RstCfgPLTRST << bits.DW0PadRstCfg, + if err := p.UpdateResetSource(remapping); err != nil { + logs.Errorf("remap reset source for %s: %v", m.GetPadId(), err) } - dw0 := p.GetRegisterDW0() - source, valid := remapping[dw0.GetResetConfig()] - if valid { - dw0.Value &= 0x3fffffff - dw0.Value |= source - } else { - logs.Errorf("%s: skip re-mapping: DW0 %s: invalid reset config source value 0b%b", - m.GetPadId(), dw0, dw0.GetResetConfig()) - } - mask := bits.DW0[bits.DW0PadRstCfg] - dw0.CntrMaskFieldsClear(mask) } diff --git a/util/intelp2m/platforms/lbg/macro.go b/util/intelp2m/platforms/lbg/macro.go index d1b53501b7..b58c8a956a 100644 --- a/util/intelp2m/platforms/lbg/macro.go +++ b/util/intelp2m/platforms/lbg/macro.go @@ -12,6 +12,12 @@ const ( DW1Mask uint32 = 0b11111101111111111100001111111111 ) +var remapping = common.ResetSources{ + 0b00: bits.RstCfgRSMRST << bits.DW0PadRstCfg, + 0b01: bits.RstCfgDEEP << bits.DW0PadRstCfg, + 0b10: bits.RstCfgPLTRST << bits.DW0PadRstCfg, +} + type BasePlatform struct { // based on the Sunrise Point platform snr.BasePlatform @@ -26,23 +32,9 @@ func GetPlatform(dw0, dw1 uint32) common.PlatformIf { return &p } -// Override the base platform method -func (p *BasePlatform) RemapRstSrc(m *common.Macro) { - dw0 := p.GetRegisterDW0() - remapping := map[uint32]uint32{ - 0b00: bits.RstCfgRSMRST << bits.DW0PadRstCfg, - 0b01: bits.RstCfgDEEP << bits.DW0PadRstCfg, - 0b10: bits.RstCfgPLTRST << bits.DW0PadRstCfg, +// Override BasePlatform.RemapResetSource() +func (p *BasePlatform) RemapResetSource(m *common.Macro) { + if err := p.UpdateResetSource(remapping); err != nil { + logs.Errorf("remap reset source for %s: %v", m.GetPadId(), err) } - source, valid := remapping[dw0.GetResetConfig()] - if valid { - // dw0.SetResetConfig(resetsrc) - dw0.Value &= 0x3fffffff - dw0.Value |= source - } else { - logs.Errorf("%s: skip re-mapping: DW0 %s: invalid reset config source value 0b%b", - m.GetPadId(), dw0, dw0.GetResetConfig()) - } - mask := bits.DW0[bits.DW0PadRstCfg] - dw0.CntrMaskFieldsClear(mask) } diff --git a/util/intelp2m/platforms/mtl/macro.go b/util/intelp2m/platforms/mtl/macro.go index 13a3f11043..8740f5f783 100644 --- a/util/intelp2m/platforms/mtl/macro.go +++ b/util/intelp2m/platforms/mtl/macro.go @@ -14,6 +14,13 @@ const ( DW1Mask = 0b11111101111111111100001111111111 ) +var remapping = common.ResetSources{ + 0b00: bits.RstCfgRSMRST << bits.DW0PadRstCfg, + 0b01: bits.RstCfgDEEP << bits.DW0PadRstCfg, + 0b10: bits.RstCfgPLTRST << bits.DW0PadRstCfg, + 0b11: bits.RstCfgPWROK << bits.RstCfgPWROK, +} + type BasePlatform struct { // based on the Cannon Lake platform cnl.BasePlatform @@ -28,30 +35,15 @@ func GetPlatform(dw0, dw1 uint32) common.PlatformIf { return &p } -// Override the base platform method -func (p *BasePlatform) RemapRstSrc(m *common.Macro) { +// Override BasePlatform.RemapResetSource() +func (p *BasePlatform) RemapResetSource(m *common.Macro) { if strings.Contains(m.GetPadId(), "GPD") { // See reset map for the MeteorLake GPD group at // https://github.com/coreboot/coreboot/blob/master/src/soc/intel/meteorlake/gpio.c#L10 // remmap is not required because it is the same as common. return } - - remapping := map[uint32]uint32{ - 0b00: bits.RstCfgRSMRST << bits.DW0PadRstCfg, - 0b01: bits.RstCfgDEEP << bits.DW0PadRstCfg, - 0b10: bits.RstCfgPLTRST << bits.DW0PadRstCfg, - 0b11: bits.RstCfgPWROK << bits.RstCfgPWROK, + if err := p.UpdateResetSource(remapping); err != nil { + logs.Errorf("remap reset source for %s: %v", m.GetPadId(), err) } - dw0 := p.GetRegisterDW0() - source, valid := remapping[dw0.GetResetConfig()] - if valid { - dw0.Value &= 0x3fffffff - dw0.Value |= source - } else { - logs.Errorf("%s: skip re-mapping: DW0 %s: invalid reset config source value 0b%b", - m.GetPadId(), dw0, dw0.GetResetConfig()) - } - mask := bits.DW0[bits.DW0PadRstCfg] - dw0.CntrMaskFieldsClear(mask) } diff --git a/util/intelp2m/platforms/snr/macro.go b/util/intelp2m/platforms/snr/macro.go index 9a4ace4753..7250608374 100644 --- a/util/intelp2m/platforms/snr/macro.go +++ b/util/intelp2m/platforms/snr/macro.go @@ -14,6 +14,12 @@ const ( DW1Mask uint32 = 0b11111101111111111100001111111111 ) +var remapping = common.ResetSources{ + 0b00: bits.RstCfgRSMRST << bits.DW0PadRstCfg, + 0b01: bits.RstCfgDEEP << bits.DW0PadRstCfg, + 0b10: bits.RstCfgPLTRST << bits.DW0PadRstCfg, +} + type BasePlatform struct { common.BasePlatform } @@ -28,29 +34,16 @@ func GetPlatform(dw0, dw1 uint32) common.PlatformIf { } // RemmapRstSrc() remaps Pad Reset Source Config -func (p *BasePlatform) RemapRstSrc(m *common.Macro) { +func (p *BasePlatform) RemapResetSource(m *common.Macro) { if strings.Contains(m.GetPadId(), "GPD") { // See reset map for the Sunrise GPD Group in the Community 2: // https://github.com/coreboot/coreboot/blob/master/src/soc/intel/skylake/gpio.c#L15 // remmap is not required because it is the same as common. return } - - dw0 := p.GetRegisterDW0() - remapping := map[uint32]uint32{ - 0b00: bits.RstCfgRSMRST << bits.DW0PadRstCfg, - 0b01: bits.RstCfgDEEP << bits.DW0PadRstCfg, - 0b10: bits.RstCfgPLTRST << bits.DW0PadRstCfg, + if err := p.UpdateResetSource(remapping); err != nil { + logs.Errorf("remap reset source for %s: %v", m.GetPadId(), err) } - - if source, valid := remapping[dw0.GetResetConfig()]; valid { - dw0.Value &= 0x3fffffff - dw0.Value |= source - } else { - logs.Errorf("%s: skip re-mapping: DW0 %s: invalid reset config source value 0b%b", - m.GetPadId(), dw0, dw0.GetResetConfig()) - } - dw0.CntrMaskFieldsClear(bits.DW0[bits.DW0PadRstCfg]) } // Pull() adds The Pad Termination (TERM) parameter from PAD_CFG_DW1 to the macro diff --git a/util/intelp2m/platforms/tgl/macro.go b/util/intelp2m/platforms/tgl/macro.go index 64ed9bb579..6e63167b2a 100644 --- a/util/intelp2m/platforms/tgl/macro.go +++ b/util/intelp2m/platforms/tgl/macro.go @@ -14,6 +14,12 @@ const ( DW1Mask = 0b11111101111111111100001111111111 ) +var remapping = common.ResetSources{ + 0b00: bits.RstCfgRSMRST << bits.DW0PadRstCfg, + 0b01: bits.RstCfgDEEP << bits.DW0PadRstCfg, + 0b10: bits.RstCfgPLTRST << bits.DW0PadRstCfg, +} + type BasePlatform struct { // based on the Cannon Lake platform cnl.BasePlatform @@ -28,29 +34,15 @@ func GetPlatform(dw0, dw1 uint32) common.PlatformIf { return &p } -// Override BasePlatform.RemapRstSrc() -func (p *BasePlatform) RemapRstSrc(m *common.Macro) { +// Override BasePlatform.RemapResetSource() +func (p *BasePlatform) RemapResetSource(m *common.Macro) { if strings.Contains(m.GetPadId(), "GPD") { // See reset map for the TigerLake Community 2: // https://github.com/coreboot/coreboot/blob/master/src/soc/intel/tigerlake/gpio.c#L21 // remmap is not required because it is the same as common. return } - - remapping := map[uint32]uint32{ - 0b00: bits.RstCfgRSMRST << bits.DW0PadRstCfg, - 0b01: bits.RstCfgDEEP << bits.DW0PadRstCfg, - 0b10: bits.RstCfgPLTRST << bits.DW0PadRstCfg, + if err := p.UpdateResetSource(remapping); err != nil { + logs.Errorf("remap reset source for %s: %v", m.GetPadId(), err) } - dw0 := p.GetRegisterDW0() - source, valid := remapping[dw0.GetResetConfig()] - if valid { - dw0.Value &= 0x3fffffff - dw0.Value |= source - } else { - logs.Errorf("%s: skip re-mapping: DW0 %s: invalid reset config source value 0b%b", - m.GetPadId(), dw0, dw0.GetResetConfig()) - } - mask := bits.DW0[bits.DW0PadRstCfg] - dw0.CntrMaskFieldsClear(mask) }