Maxim Polyakov has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/71167 )
Change subject: util/intelp2m: Rework platform packages ......................................................................
util/intelp2m: Rework platform packages
Tests: - make test = PASS - gpio.h for Apollo Lake before and after the patch is the same
Change-Id: I2e0aa56efa2430ac6524c6977f8b6fd13113edf9 Signed-off-by: Maxim Polyakov max.senia.poliak@gmail.com --- M util/intelp2m/fields/cb/cb.go M util/intelp2m/fields/fields.go M util/intelp2m/fields/fsp/fsp.go M util/intelp2m/fields/raw/raw.go M util/intelp2m/fields/test/suite.go M util/intelp2m/parser/parser.go D util/intelp2m/platforms/adl/macro.go D util/intelp2m/platforms/adl/template.go A util/intelp2m/platforms/alder/alder.go D util/intelp2m/platforms/apl/macro.go D util/intelp2m/platforms/apl/template.go A util/intelp2m/platforms/apollo/apollo.go R util/intelp2m/platforms/apollo/apollo_test.go A util/intelp2m/platforms/cannon/cannon.go D util/intelp2m/platforms/cnl/macro.go D util/intelp2m/platforms/cnl/template.go D util/intelp2m/platforms/common/macro.go A util/intelp2m/platforms/common/macros/macros.go M util/intelp2m/platforms/common/register/helper.go M util/intelp2m/platforms/interfaces.go A util/intelp2m/platforms/interfaces/interfaces.go D util/intelp2m/platforms/lbg/macro.go D util/intelp2m/platforms/lbg/template.go A util/intelp2m/platforms/lewisburg/lewisburg.go R util/intelp2m/platforms/lewisburg/lewisburg_test.go D util/intelp2m/platforms/snr/macro.go D util/intelp2m/platforms/snr/template.go A util/intelp2m/platforms/sunrise/sunrise.go R util/intelp2m/platforms/sunrise/sunrise_test.go M util/intelp2m/platforms/test/suite.go 30 files changed, 1,645 insertions(+), 1,688 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/67/71167/1
diff --git a/util/intelp2m/fields/cb/cb.go b/util/intelp2m/fields/cb/cb.go index 031c83a..8547423 100644 --- a/util/intelp2m/fields/cb/cb.go +++ b/util/intelp2m/fields/cb/cb.go @@ -2,7 +2,7 @@
import ( "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/macros" )
type FieldMacros struct{} @@ -23,7 +23,7 @@ // generate - wrapper for generating bitfield macros string // fields : field structure func generate(fields ...*field) { - macro := common.GetMacro() + macro := macros.GetInstance() var allhidden bool = true for _, field := range fields { if field.unhide { @@ -49,8 +49,8 @@
// DecodeDW0 - decode value of DW0 register func (FieldMacros) DecodeDW0() { - macro := common.GetMacro() - dw0 := macro.GetRegisterDW0() + macro := macros.GetInstance() + dw0 := macro.Platform.GetRegisterDW0() generate( &field{ prefix: "PAD_FUNC", @@ -132,8 +132,8 @@
// DecodeDW1 - decode value of DW1 register func (FieldMacros) DecodeDW1() { - macro := common.GetMacro() - dw1 := macro.GetRegisterDW1() + macro := macros.GetInstance() + dw1 := macro.Platform.GetRegisterDW1() generate( &field{ name: "PAD_CFG1_TOL_1V8", @@ -166,9 +166,9 @@ ) }
-// GenerateString - generates the entire string of bitfield macros. -func (bitfields FieldMacros) GenerateString() { - macro := common.GetMacro() +// GenerateMacro generates the field macro collection +func (bitfields FieldMacros) GenerateMacro() { + macro := macros.GetInstance() macro.Add("_PAD_CFG_STRUCT(").Id().Add(", ") bitfields.DecodeDW0() macro.Add(", ") diff --git a/util/intelp2m/fields/fields.go b/util/intelp2m/fields/fields.go index bcb6221..d3de950 100644 --- a/util/intelp2m/fields/fields.go +++ b/util/intelp2m/fields/fields.go @@ -5,17 +5,18 @@ "review.coreboot.org/coreboot.git/util/intelp2m/fields/cb" "review.coreboot.org/coreboot.git/util/intelp2m/fields/fsp" "review.coreboot.org/coreboot.git/util/intelp2m/fields/raw" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/macros" )
// InterfaceSet - set the interface for decoding configuration // registers DW0 and DW1. -func InterfaceGet() common.Fields { - var fldstylemap = map[p2m.FieldType]common.Fields{ +func InterfaceGet() macros.FieldsIf { + var fldstylemap = map[p2m.FieldType]macros.FieldsIf{ p2m.NoFlds: cb.FieldMacros{}, // analyze fields using cb macros p2m.CbFlds: cb.FieldMacros{}, p2m.FspFlds: fsp.FieldMacros{}, p2m.RawFlds: raw.FieldMacros{}, } - return fldstylemap[p2m.SettingsGet().Field] + config := p2m.SettingsGet() + return fldstylemap[config.Field] } diff --git a/util/intelp2m/fields/fsp/fsp.go b/util/intelp2m/fields/fsp/fsp.go index db6b4ad..c4b2387 100644 --- a/util/intelp2m/fields/fsp/fsp.go +++ b/util/intelp2m/fields/fsp/fsp.go @@ -1,6 +1,8 @@ package fsp
-import "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" +import ( + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/macros" +)
type FieldMacros struct{}
@@ -17,7 +19,7 @@ // generate - wrapper for generating bitfield macros string // fields : field structure func generate(fields ...*field) { - macro := common.GetMacro() + macro := macros.GetInstance() for _, field := range fields { if field.override != nil { // override if necessary @@ -36,8 +38,8 @@
// DecodeDW0 - decode value of DW0 register func (FieldMacros) DecodeDW0() { - macro := common.GetMacro() - dw0 := macro.GetRegisterDW0() + macro := macros.GetInstance() + dw0 := macro.Platform.GetRegisterDW0()
ownershipStatus := func() uint32 { if macro.IsOwnershipDriver() { @@ -135,8 +137,8 @@
// DecodeDW1 - decode value of DW1 register func (FieldMacros) DecodeDW1() { - macro := common.GetMacro() - dw1 := macro.GetRegisterDW1() + macro := macros.GetInstance() + dw1 := macro.Platform.GetRegisterDW1() generate( &field{ override: func(configmap map[uint32]string, value uint32) { @@ -163,9 +165,9 @@ ) }
-// GenerateString - generates the entire string of bitfield macros. -func (bitfields FieldMacros) GenerateString() { - macro := common.GetMacro() +// GenerateMacro generates the field macro collection +func (bitfields FieldMacros) GenerateMacro() { + macro := macros.GetInstance() macro.Add("{ GPIO_SKL_H_").Id().Add(", { ") bitfields.DecodeDW0() bitfields.DecodeDW1() diff --git a/util/intelp2m/fields/raw/raw.go b/util/intelp2m/fields/raw/raw.go index 4efccd5..2c27913 100644 --- a/util/intelp2m/fields/raw/raw.go +++ b/util/intelp2m/fields/raw/raw.go @@ -1,26 +1,26 @@ package raw
import ( - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/macros" )
type FieldMacros struct{}
func (FieldMacros) DecodeDW0() { - macro := common.GetMacro() - dw0 := macro.GetRegisterDW0() + macro := macros.GetInstance() + dw0 := macro.Platform.GetRegisterDW0() macro.Add(dw0.String()) }
func (FieldMacros) DecodeDW1() { - macro := common.GetMacro() - dw1 := macro.GetRegisterDW1() + macro := macros.GetInstance() + dw1 := macro.Platform.GetRegisterDW1() macro.Add(dw1.String()) }
-// GenerateString - generates the entire string of bitfield macros. -func (bitfields FieldMacros) GenerateString() { - macro := common.GetMacro() +// GenerateMacro generates the field macro collection +func (bitfields FieldMacros) GenerateMacro() { + macro := macros.GetInstance() macro.Add("_PAD_CFG_STRUCT(").Id().Add(", ") bitfields.DecodeDW0() macro.Add(", ") diff --git a/util/intelp2m/fields/test/suite.go b/util/intelp2m/fields/test/suite.go index 3041de2..0b9f317 100644 --- a/util/intelp2m/fields/test/suite.go +++ b/util/intelp2m/fields/test/suite.go @@ -4,8 +4,9 @@ "fmt" "testing"
- "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/snr" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/macros" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/sunrise" )
type TestCase struct { @@ -16,7 +17,7 @@
func (tc TestCase) Check(actuallyMacro string) error { if actuallyMacro != tc.Reference { - return fmt.Errorf(`TestCase: DW0 = %d, DW1 = %d, Ownership = %d: + return fmt.Errorf(`TestCase: DW0 = 0x%x, DW1 = 0x%x, Ownership = %d: Expects: '%s' Actually: '%s'`, tc.DW0, tc.DW1, tc.Ownership, tc.Reference, actuallyMacro) } @@ -25,19 +26,19 @@
type Suite []TestCase
-func (suite Suite) Run(t *testing.T, label string, decoderIf common.Fields) { +func (suite Suite) Run(t *testing.T, label string, decoderIf macros.FieldsIf) { t.Run(label, func(t *testing.T) { - platform := snr.PlatformSpecific{} - macro := common.GetInstanceMacro(platform, decoderIf) - dw0 := macro.GetRegisterDW0() - dw1 := macro.GetRegisterDW1() for _, tc := range suite { - macro.Clear() - macro.PadIdSet("").SetPadOwnership(tc.Ownership) - dw0.Value = tc.DW0 - dw1.Value = tc.DW1 - macro.Fields.GenerateString() - if err := tc.Check(macro.Get()); err != nil { + platrorm := sunrise.InitBasePlatform( + "", + tc.Ownership == 1, + register.ValDW0(tc.DW0, sunrise.DW0Mask), + register.ValDW1(tc.DW1, sunrise.DW1Mask), + ) + macro := platrorm.GetMacro() + macro.Fields = decoderIf + macro.Fields.GenerateMacro() + if err := tc.Check(macro.String()); err != nil { t.Errorf("Test failed: %v", err) } } diff --git a/util/intelp2m/parser/parser.go b/util/intelp2m/parser/parser.go index 805b127..eccff44 100644 --- a/util/intelp2m/parser/parser.go +++ b/util/intelp2m/parser/parser.go @@ -11,6 +11,7 @@ "review.coreboot.org/coreboot.git/util/intelp2m/parser/template" "review.coreboot.org/coreboot.git/util/intelp2m/platforms" "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/macros" "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register/bits" )
@@ -35,12 +36,16 @@ Function string DW0 uint32 DW1 uint32 - Ownership uint8 + Ownership bool }
func (e *Entry) ToMacro() []string { - platform := platforms.GetSpecificInterface() - line := platform.GenMacro(e.ID, e.DW0, e.DW1, e.Ownership) + generate := platforms.GetMacroAction() + if generate == nil { + logs.Errorf("error converting to macro") + return nil + } + line := generate(e.ID, e.DW0, e.DW1, e.Ownership) slices := strings.Split(line, "\n") return slices } @@ -59,7 +64,7 @@ ID: id, DW0: dw0, DW1: dw1, - Ownership: 0, + Ownership: macros.Acpi, }
if dw0 == bits.All32 { @@ -79,12 +84,13 @@ }
// Extract() extracts pad information from a string -func Extract(line string, platform platforms.SpecificIf) Entry { +func Extract(line string) Entry { if included, _ := common.KeywordsCheck(line, "GPIO Community", "GPIO Group"); included { return extractGroup(line) }
- if platform.KeywordCheck(line) { + checkKeyword := platforms.GetKeywordChekingAction() + if checkKeyword(line) { pad, err := extractPad(line) if err != nil { logs.Errorf("extract pad info from %s: %v", line, err) @@ -101,11 +107,6 @@ entries := make([]Entry, 0) config := p2m.SettingsGet()
- platform := platforms.GetSpecificInterface() - if platform == nil { - return nil, fmt.Errorf("unknown platform") - } - file, err := os.Open(config.InputPath) if err != nil { err = fmt.Errorf("input file error: %v", err) @@ -118,7 +119,7 @@ scanner := bufio.NewScanner(file) for scanner.Scan() { line := scanner.Text() - entry := Extract(line, platform) + entry := Extract(line) if entry.EType != EntryEmpty { entries = append(entries, entry) } diff --git a/util/intelp2m/platforms/adl/macro.go b/util/intelp2m/platforms/adl/macro.go deleted file mode 100644 index 7c4f435..0000000 --- a/util/intelp2m/platforms/adl/macro.go +++ /dev/null @@ -1,113 +0,0 @@ -package adl - -import ( - "fmt" - "strings" - - "review.coreboot.org/coreboot.git/util/intelp2m/fields" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/cnl" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register/bits" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/snr" -) - -const ( - PAD_CFG_DW0_RO_FIELDS = (0x1 << 27) | (0x1 << 24) | (0x3 << 21) | (0xf << 16) | 0xfc - PAD_CFG_DW1_RO_FIELDS = 0xfdffc3ff -) - -type InheritanceMacro interface { - Pull() - GpiMacroAdd() - GpoMacroAdd() - NativeFunctionMacroAdd() - NoConnMacroAdd() -} - -type PlatformSpecific struct { - InheritanceMacro -} - -// RemmapRstSrc - remmap Pad Reset Source Config -func (PlatformSpecific) RemmapRstSrc() { - macro := common.GetMacro() - if strings.Contains(macro.PadIdGet(), "GPD") { - // See reset map for the Alderlake GPD Group in the Community 2: - // https://github.com/coreboot/coreboot/blob/master/src/soc/intel/alderlake/gpi... - // remmap is not required because it is the same as common. - return - } - - dw0 := macro.GetRegisterDW0() - remapping := map[uint32]uint32{ - 0: (bits.RstCfgRSMRST << bits.DW0PadRstCfg), - 1: (bits.RstCfgDEEP << bits.DW0PadRstCfg), - 2: (bits.RstCfgPLTRST << bits.DW0PadRstCfg), - 3: (bits.RstCfgPWROK << bits.DW0PadRstCfg), - } - resetsrc, valid := remapping[dw0.GetResetConfig()] - if valid { - // dw0.SetResetConfig(resetsrc) - ResetConfigFieldVal := (dw0.Value & 0x3fffffff) | remapping[dw0.GetResetConfig()] - dw0.Value = ResetConfigFieldVal - } else { - fmt.Println("Invalid Pad Reset Config [ 0x", resetsrc, " ] for ", macro.PadIdGet()) - } - dw0.CntrMaskFieldsClear(0b11 << bits.DW0PadRstCfg) -} - -// Adds The Pad Termination (TERM) parameter from PAD_CFG_DW1 to the macro -// as a new argument -func (platform PlatformSpecific) Pull() { - platform.InheritanceMacro.Pull() -} - -// Adds PAD_CFG_GPI macro with arguments -func (platform PlatformSpecific) GpiMacroAdd() { - platform.InheritanceMacro.GpiMacroAdd() -} - -// Adds PAD_CFG_GPO macro with arguments -func (platform PlatformSpecific) GpoMacroAdd() { - platform.InheritanceMacro.GpoMacroAdd() -} - -// Adds PAD_CFG_NF macro with arguments -func (platform PlatformSpecific) NativeFunctionMacroAdd() { - platform.InheritanceMacro.NativeFunctionMacroAdd() -} - -// Adds PAD_NC macro -func (platform PlatformSpecific) NoConnMacroAdd() { - platform.InheritanceMacro.NoConnMacroAdd() -} - -// GenMacro - generate pad macro -// dw0Val : DW0 config register value -// dw1Val : DW1 config register value -// return: string of macro -// error -func (PlatformSpecific) GenMacro(id string, dw0Val uint32, dw1Val uint32, ownership uint8) string { - macro := common.GetInstanceMacro( - PlatformSpecific{ - InheritanceMacro: cnl.PlatformSpecific{ - InheritanceMacro: snr.PlatformSpecific{}, - }, - }, - fields.InterfaceGet(), - ) - macro.Clear() - dw0 := macro.GetRegisterDW0() - dw0.CntrMaskFieldsClear(bits.All32) - - dw1 := macro.GetRegisterDW1() - dw1.CntrMaskFieldsClear(bits.All32) - - dw0.Value = dw0Val - dw1.Value = dw1Val - - dw0.ReadOnly = PAD_CFG_DW0_RO_FIELDS - dw1.ReadOnly = PAD_CFG_DW1_RO_FIELDS - macro.PadIdSet(id).SetPadOwnership(ownership) - return macro.Generate() -} diff --git a/util/intelp2m/platforms/adl/template.go b/util/intelp2m/platforms/adl/template.go deleted file mode 100644 index b6bfe5d..0000000 --- a/util/intelp2m/platforms/adl/template.go +++ /dev/null @@ -1,17 +0,0 @@ -package adl - -import "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" - -// Group : "GPP_A", "GPP_B", "GPP_C", "GPP_D", "GPP_E", "GPP_F", "GPP_G", -// "GPP_H", "GPP_I", "GPP_J", "GPP_K", "GPP_R", "GPP_S", "GPP_T", -// "GPD", "VGPIO_USB", "VGPIO_PCIE" - -// KeywordCheck - This function is used to filter parsed lines of the configuration file and -// -// returns true if the keyword is contained in the line. -// -// line : string from the configuration file -func (PlatformSpecific) KeywordCheck(line string) bool { - isIncluded, _ := common.KeywordsCheck(line, "GPP_", "GPD", "VGPIO") - return isIncluded -} diff --git a/util/intelp2m/platforms/alder/alder.go b/util/intelp2m/platforms/alder/alder.go new file mode 100644 index 0000000..af6ce6a --- /dev/null +++ b/util/intelp2m/platforms/alder/alder.go @@ -0,0 +1,104 @@ +package alder + +import ( + "strings" + + "review.coreboot.org/coreboot.git/util/intelp2m/logs" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/cannon" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register/bits" +) + +const ( + dw0Mask uint32 = (0x1 << 27) | (0x1 << 24) | (0x3 << 21) | (0xf << 16) | 0xfc + dw1Mask uint32 = 0xfdffc3ff +) + +type BasePlatform struct { + // based on the Sunrise platform + cannon.BasePlatform +} + +func InitBasePlatform(id string, owner bool, dw0 register.DW0, dw1 register.DW1) BasePlatform { + return BasePlatform{ + BasePlatform: cannon.InitBasePlatform(id, owner, dw0, dw1), + } +} + +// RemapRstSrc() remaps Pad Reset Source Config +func (p *BasePlatform) RemmapRstSrc() { + macro := p.GetMacro() + if strings.Contains(macro.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/gpi... + // remmap is not required because it is the same as common. + return + } + + remapping := map[uint32]uint32{ + 0: (bits.RstCfgRSMRST << bits.DW0PadRstCfg), + 1: (bits.RstCfgDEEP << bits.DW0PadRstCfg), + 2: (bits.RstCfgPLTRST << bits.DW0PadRstCfg), + 3: (bits.RstCfgPWROK << bits.DW0PadRstCfg), + } + 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", + macro.GetPadId(), dw0, dw0.GetResetConfig()) + } + mask := bits.DW0[bits.DW0PadRstCfg] + dw0.CntrMaskFieldsClear(mask) +} + +// Adds The Pad Termination (TERM) parameter from PAD_CFG_DW1 to the macro +// as a new argument +func (p *BasePlatform) Pull() { + p.BasePlatform.Pull() +} + +// Adds PAD_CFG_GPI macro with arguments +func (p *BasePlatform) AddGpiMacro() { + p.BasePlatform.AddGpiMacro() +} + +// Adds PAD_CFG_GPO macro with arguments +func (p *BasePlatform) AddGpoMacro() { + p.BasePlatform.AddGpoMacro() +} + +// Adds PAD_CFG_NF macro with arguments +func (p *BasePlatform) AddNativeFunctionMacro() { + p.BasePlatform.AddNativeFunctionMacro() +} + +// Adds PAD_NC macro +func (p *BasePlatform) AddNoConnMacro() { + p.BasePlatform.AddNoConnMacro() +} + +// GenerateMacro() generates pad macro +func GenerateMacro(id string, dw0 uint32, dw1 uint32, owner bool) string { + platrorm := InitBasePlatform( + id, + owner, + register.ValDW0(dw0, dw0Mask), + register.ValDW1(dw1, dw1Mask), + ) + macro := platrorm.GetMacro() + return macro.Generate() +} + +// CheckKeyword() parses lines of the configuration file and returns true if the keyword is +// contained in the line +// "GPP_A", "GPP_B", "GPP_C", "GPP_D", "GPP_E", "GPP_F", "GPP_G", +// "GPP_H", "GPP_I", "GPP_J", "GPP_K", "GPP_R", "GPP_S", "GPP_T", +// "GPD", "VGPIO_USB", "VGPIO_PCIE" +func CheckKeyword(line string) bool { + isIncluded, _ := common.KeywordsCheck(line, "GPP_", "GPD", "VGPIO") + return isIncluded +} diff --git a/util/intelp2m/platforms/apl/macro.go b/util/intelp2m/platforms/apl/macro.go deleted file mode 100644 index 7b2ce63..0000000 --- a/util/intelp2m/platforms/apl/macro.go +++ /dev/null @@ -1,303 +0,0 @@ -package apl - -import ( - "fmt" - "strconv" - - "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" - "review.coreboot.org/coreboot.git/util/intelp2m/fields" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register/bits" -) - -const ( - PAD_CFG_DW0_RO_FIELDS = (0x1 << 27) | (0x1 << 24) | (0x3 << 21) | (0xf << 16) | 0xfc - PAD_CFG_DW1_RO_FIELDS = 0xfffc00ff -) - -const ( - PULL_NONE = 0x0 // 0 000: none - PULL_DN_5K = 0x2 // 0 010: 5k wpd (Only available on SMBus GPIOs) - PULL_DN_20K = 0x4 // 0 100: 20k wpd - // PULL_NONE = 0x8 // 1 000: none - PULL_UP_1K = 0x9 // 1 001: 1k wpu (Only available on I2C GPIOs) - PULL_UP_2K = 0xb // 1 011: 2k wpu (Only available on I2C GPIOs) - PULL_UP_20K = 0xc // 1 100: 20k wpu - PULL_UP_667 = 0xd // 1 101: 1k & 2k wpu (Only available on I2C GPIOs) - PULL_NATIVE = 0xf // 1 111: (optional) Native controller selected by Pad Mode -) - -type PlatformSpecific struct{} - -// RemmapRstSrc - remmap Pad Reset Source Config -// remmap is not required because it is the same as common. -func (PlatformSpecific) RemmapRstSrc() {} - -// Adds The Pad Termination (TERM) parameter from DW1 to the macro as a new argument -// return: macro -func (PlatformSpecific) Pull() { - macro := common.GetMacro() - dw1 := macro.GetRegisterDW1() - var pull = map[uint32]string{ - PULL_NONE: "NONE", - PULL_DN_5K: "DN_5K", - PULL_DN_20K: "DN_20K", - PULL_UP_1K: "UP_1K", - PULL_UP_2K: "UP_2K", - PULL_UP_20K: "UP_20K", - PULL_UP_667: "UP_667", - PULL_NATIVE: "NATIVE", - } - str, exist := pull[dw1.GetTermination()] - if !exist { - str = strconv.Itoa(int(dw1.GetTermination())) - fmt.Println("Error", macro.PadIdGet(), " invalid TERM value = ", str) - } - macro.Separator().Add(str) -} - -// Generate macro to cause peripheral IRQ when configured in GPIO input mode -func ioApicRoute() bool { - macro := common.GetMacro() - dw0 := macro.GetRegisterDW0() - dw1 := macro.GetRegisterDW1() - if dw0.GetGPIOInputRouteIOxAPIC() == 0 { - return false - } - macro.Add("_APIC") - if dw1.GetIOStandbyState() != 0 || dw1.GetIOStandbyTermination() != 0 { - // e.g. H1_PCH_INT_ODL - // PAD_CFG_GPI_APIC_IOS(GPIO_63, NONE, DEEP, LEVEL, INVERT, TxDRxE, DISPUPD), - macro.Add("_IOS(").Id().Pull().Rstsrc().Trig().Invert().IOSstate().IOTerm() - } else { - // PAD_CFG_GPI_APIC(pad, pull, rst, trig, inv) - macro.Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") - } - macro.Add("),") - return true -} - -// Generate macro to cause NMI when configured in GPIO input mode -func nmiRoute() bool { - macro := common.GetMacro() - if macro.GetRegisterDW0().GetGPIOInputRouteNMI() == 0 { - return false - } - // e.g. PAD_CFG_GPI_NMI(GPIO_24, UP_20K, DEEP, LEVEL, INVERT), - macro.Add("_NMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") - return true -} - -// Generate macro to cause SCI when configured in GPIO input mode -func sciRoute() bool { - macro := common.GetMacro() - dw0 := macro.GetRegisterDW0() - dw1 := macro.GetRegisterDW1() - if dw0.GetGPIOInputRouteSCI() == 0 { - return false - } - if dw1.GetIOStandbyState() != 0 || dw1.GetIOStandbyTermination() != 0 { - // PAD_CFG_GPI_SCI_IOS(GPIO_141, NONE, DEEP, EDGE_SINGLE, INVERT, IGNORE, DISPUPD), - macro.Add("_SCI_IOS") - macro.Add("(").Id().Pull().Rstsrc().Trig().Invert().IOSstate().IOTerm() - } else if dw0.GetRXLevelEdgeConfiguration()&0x1 != 0 { - // e.g. PAD_CFG_GPI_ACPI_SCI(GPP_G2, NONE, DEEP, YES), - macro.Add("_ACPI_SCI").Add("(").Id().Pull().Rstsrc().Invert() - } else { - // e.g. PAD_CFG_GPI_SCI(GPP_B18, UP_20K, PLTRST, LEVEL, INVERT), - macro.Add("_SCI").Add("(").Id().Pull().Rstsrc().Trig().Invert() - } - macro.Add("),") - return true -} - -// Generate macro to cause SMI when configured in GPIO input mode -func smiRoute() bool { - macro := common.GetMacro() - dw0 := macro.GetRegisterDW0() - dw1 := macro.GetRegisterDW1() - if dw0.GetGPIOInputRouteSMI() == 0 { - return false - } - if dw1.GetIOStandbyState() != 0 || dw1.GetIOStandbyTermination() != 0 { - // PAD_CFG_GPI_SMI_IOS(GPIO_41, UP_20K, DEEP, EDGE_SINGLE, NONE, IGNORE, SAME), - macro.Add("_SMI_IOS") - macro.Add("(").Id().Pull().Rstsrc().Trig().Invert().IOSstate().IOTerm() - } else if dw0.GetRXLevelEdgeConfiguration()&0x1 != 0 { - // e.g. PAD_CFG_GPI_ACPI_SMI(GPP_I3, NONE, DEEP, YES), - macro.Add("_ACPI_SMI").Add("(").Id().Pull().Rstsrc().Invert() - } else { - // e.g. PAD_CFG_GPI_SMI(GPP_E3, NONE, PLTRST, EDGE_SINGLE, NONE), - macro.Add("_SMI").Add("(").Id().Pull().Rstsrc().Trig().Invert() - } - macro.Add("),") - return true -} - -// Generate macro for GPI port -func (PlatformSpecific) GpiMacroAdd() { - var ids []string - - macro := common.GetMacro() - macro.Set("PAD_CFG_GPI") - for routeid, isRoute := range map[string]func() bool{ - "IOAPIC": ioApicRoute, - "SCI": sciRoute, - "SMI": smiRoute, - "NMI": nmiRoute, - } { - if isRoute() { - ids = append(ids, routeid) - } - } - - switch config, argc := p2m.SettingsGet(), len(ids); argc { - case 0: - dw1 := macro.GetRegisterDW1() - isIOStandbyStateUsed := dw1.GetIOStandbyState() != 0 - isIOStandbyTerminationUsed := dw1.GetIOStandbyTermination() != 0 - if isIOStandbyStateUsed && !isIOStandbyTerminationUsed { - macro.Add("_TRIG_IOSSTATE_OWN(") - // PAD_CFG_GPI_TRIG_IOSSTATE_OWN(pad, pull, rst, trig, iosstate, own) - macro.Id().Pull().Rstsrc().Trig().IOSstate().Own().Add("),") - } else if isIOStandbyTerminationUsed { - macro.Add("_TRIG_IOS_OWN(") - // PAD_CFG_GPI_TRIG_IOS_OWN(pad, pull, rst, trig, iosstate, iosterm, own) - macro.Id().Pull().Rstsrc().Trig().IOSstate().IOTerm().Own().Add("),") - } else { - // PAD_CFG_GPI_TRIG_OWN(pad, pull, rst, trig, own) - macro.Add("_TRIG_OWN(").Id().Pull().Rstsrc().Trig().Own().Add("),") - } - case 1: - // GPI with IRQ route - if config.IgnoredFields { - macro.SetPadOwnership(common.PAD_OWN_ACPI) - } - case 2: - // PAD_CFG_GPI_DUAL_ROUTE(pad, pull, rst, trig, inv, route1, route2) - macro.Set("PAD_CFG_GPI_DUAL_ROUTE(").Id().Pull().Rstsrc().Trig().Invert() - macro.Add(", " + ids[0] + ", " + ids[1] + "),") - if config.IgnoredFields { - macro.SetPadOwnership(common.PAD_OWN_ACPI) - } - default: - // Clear the control mask so that the check fails and "Advanced" macro is - // generated - macro.GetRegisterDW0().CntrMaskFieldsClear(bits.All32) - } -} - -// Adds PAD_CFG_GPO macro with arguments -func (PlatformSpecific) GpoMacroAdd() { - macro := common.GetMacro() - dw0 := macro.GetRegisterDW0() - dw1 := macro.GetRegisterDW1() - term := dw1.GetTermination() - - macro.Set("PAD_CFG") - if dw1.GetIOStandbyState() != 0 || dw1.GetIOStandbyTermination() != 0 { - // PAD_CFG_GPO_IOSSTATE_IOSTERM(GPIO_91, 0, DEEP, NONE, Tx0RxDCRx0, DISPUPD), - // PAD_CFG_GPO_IOSSTATE_IOSTERM(pad, val, rst, pull, iosstate, ioterm) - macro.Add("_GPO_IOSSTATE_IOSTERM(").Id().Val().Rstsrc().Pull().IOSstate().IOTerm() - } else { - if term != 0 { - // e.g. PAD_CFG_TERM_GPO(GPP_B23, 1, DN_20K, DEEP), - // PAD_CFG_TERM_GPO(pad, val, pull, rst) - macro.Add("_TERM") - } - macro.Add("_GPO(").Id().Val() - if term != 0 { - macro.Pull() - } - macro.Rstsrc() - } - macro.Add("),") - - if dw0.GetRXLevelEdgeConfiguration() != bits.TrigOFF { - // ignore if trig = OFF is not set - dw0.CntrMaskFieldsClear(bits.DW0[bits.DW0RxLevelEdgeConfiguration]) - } -} - -// Adds PAD_CFG_NF macro with arguments -func (PlatformSpecific) NativeFunctionMacroAdd() { - macro := common.GetMacro() - dw1 := macro.GetRegisterDW1() - isIOStandbyStateUsed := dw1.GetIOStandbyState() != 0 - isIOStandbyTerminationUsed := dw1.GetIOStandbyTermination() != 0 - - macro.Set("PAD_CFG_NF") - if !isIOStandbyTerminationUsed && isIOStandbyStateUsed { - if dw1.GetIOStandbyState() == bits.IOStateStandbyIgnore { - // PAD_CFG_NF_IOSTANDBY_IGNORE(PMU_SLP_S0_B, NONE, DEEP, NF1), - macro.Add("_IOSTANDBY_IGNORE(").Id().Pull().Rstsrc().Padfn() - } else { - // PAD_CFG_NF_IOSSTATE(GPIO_22, UP_20K, DEEP, NF2, TxDRxE), - macro.Add("_IOSSTATE(").Id().Pull().Rstsrc().Padfn().IOSstate() - } - } else if isIOStandbyTerminationUsed { - // PAD_CFG_NF_IOSSTATE_IOSTERM(GPIO_103, NATIVE, DEEP, NF1, MASK, SAME), - macro.Add("_IOSSTATE_IOSTERM(").Id().Pull().Rstsrc().Padfn().IOSstate().IOTerm() - } else { - // e.g. PAD_CFG_NF(GPP_D23, NONE, DEEP, NF1) - macro.Add("(").Id().Pull().Rstsrc().Padfn() - } - macro.Add("),") - - if dw0 := macro.GetRegisterDW0(); dw0.GetGPIORxTxDisableStatus() != 0 { - // Since the bufbis parameter will be ignored for NF, we should clear - // the corresponding bits in the control mask. - dw0.CntrMaskFieldsClear(bits.DW0[bits.DW0RxTxBufDisable]) - } -} - -// Adds PAD_NC macro -func (PlatformSpecific) NoConnMacroAdd() { - macro := common.GetMacro() - - dw0, dw1 := macro.GetRegisterDW0(), macro.GetRegisterDW1() - if dw1.GetIOStandbyState() == bits.IOStateTxDRxE { - - // See comments in sunrise/macro.go : NoConnMacroAdd() - if dw0.GetRXLevelEdgeConfiguration() != bits.TrigOFF { - dw0.CntrMaskFieldsClear(bits.DW0[bits.DW0RxLevelEdgeConfiguration]) - } - if dw0.GetResetConfig() != 1 { // 1 = RST_DEEP - dw0.CntrMaskFieldsClear(bits.DW0[bits.DW0PadRstCfg]) - } - - // PAD_NC(OSC_CLK_OUT_1, DN_20K) - macro.Set("PAD_NC").Add("(").Id().Pull().Add("),") - return - } - // PAD_CFG_GPIO_HI_Z(GPIO_81, UP_20K, DEEP, HIZCRx0, DISPUPD), - macro.Set("PAD_CFG_GPIO_") - if macro.IsOwnershipDriver() { - // PAD_CFG_GPIO_DRIVER_HI_Z(GPIO_55, UP_20K, DEEP, HIZCRx1, ENPU), - macro.Add("DRIVER_") - } - macro.Add("HI_Z(").Id().Pull().Rstsrc().IOSstate().IOTerm().Add("),") -} - -// GenMacro - generate pad macro -// dw0Val : DW0 config register value -// dw1Val : DW1 config register value -// return: string of macro -// error -func (PlatformSpecific) GenMacro(id string, dw0Val uint32, dw1Val uint32, ownership uint8) string { - macro := common.GetInstanceMacro(PlatformSpecific{}, fields.InterfaceGet()) - macro.Clear() - dw0 := macro.GetRegisterDW0() - dw0.CntrMaskFieldsClear(bits.All32) - - dw1 := macro.GetRegisterDW1() - dw1.CntrMaskFieldsClear(bits.All32) - - dw0.Value = dw0Val - dw1.Value = dw1Val - - dw0.ReadOnly = PAD_CFG_DW0_RO_FIELDS - dw1.ReadOnly = PAD_CFG_DW1_RO_FIELDS - macro.PadIdSet(id).SetPadOwnership(ownership) - return macro.Generate() -} diff --git a/util/intelp2m/platforms/apl/template.go b/util/intelp2m/platforms/apl/template.go deleted file mode 100644 index 36040ca..0000000 --- a/util/intelp2m/platforms/apl/template.go +++ /dev/null @@ -1,20 +0,0 @@ -package apl - -import "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" - -// KeywordCheck - This function is used to filter parsed lines of the configuration file and -// returns true if the keyword is contained in the line. -// line : string from the configuration file -func (PlatformSpecific) KeywordCheck(line string) bool { - isIncluded, _ := common.KeywordsCheck(line, - "GPIO_", "TCK", "TRST_B", "TMS", "TDI", "CX_PMODE", "CX_PREQ_B", "JTAGX", "CX_PRDY_B", - "TDO", "CNV_BRI_DT", "CNV_BRI_RSP", "CNV_RGI_DT", "CNV_RGI_RSP", "SVID0_ALERT_B", - "SVID0_DATA", "SVID0_CLK", "PMC_SPI_FS", "PMC_SPI_RXD", "PMC_SPI_TXD", "PMC_SPI_CLK", - "PMIC_PWRGOOD", "PMIC_RESET_B", "PMIC_THERMTRIP_B", "PMIC_STDBY", "PROCHOT_B", - "PMIC_I2C_SCL", "PMIC_I2C_SDA", "FST_SPI_CLK_FB", "OSC_CLK_OUT_", "PMU_AC_PRESENT", - "PMU_BATLOW_B", "PMU_PLTRST_B", "PMU_PWRBTN_B", "PMU_RESETBUTTON_B", "PMU_SLP_S0_B", - "PMU_SLP_S3_B", "PMU_SLP_S4_B", "PMU_SUSCLK", "PMU_WAKE_B", "SUS_STAT_B", "SUSPWRDNACK", - "SMB_ALERTB", "SMB_CLK", "SMB_DATA", "LPC_ILB_SERIRQ", "LPC_CLKOUT", "LPC_AD", "LPC_CLKRUNB", - "LPC_FRAMEB") - return isIncluded -} diff --git a/util/intelp2m/platforms/apollo/apollo.go b/util/intelp2m/platforms/apollo/apollo.go new file mode 100644 index 0000000..85c51ad --- /dev/null +++ b/util/intelp2m/platforms/apollo/apollo.go @@ -0,0 +1,324 @@ +package apollo + +import ( + "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" + "review.coreboot.org/coreboot.git/util/intelp2m/fields" + "review.coreboot.org/coreboot.git/util/intelp2m/logs" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/macros" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register/bits" +) + +const ( + dw0Mask uint32 = (0x1 << 27) | (0x1 << 24) | (0x3 << 21) | (0xf << 16) | 0xfc + dw1Mask uint32 = 0xfffc00ff +) + +type BasePlatform struct { + macro *macros.Macro + dw0 register.DW0 + dw1 register.DW1 +} + +func InitBasePlatform(id string, owner bool, dw0 register.DW0, dw1 register.DW1) BasePlatform { + platforms := BasePlatform{dw0: dw0, dw1: dw1} + fieldsDecodeIf := fields.InterfaceGet() + platforms.macro = macros.Update(id, owner, &platforms, fieldsDecodeIf) + return platforms +} + +func (p *BasePlatform) GetRegisterDW0() *register.DW0 { + return &p.dw0 +} + +func (p *BasePlatform) GetRegisterDW1() *register.DW1 { + return &p.dw1 +} + +func (p *BasePlatform) GetMacro() *macros.Macro { + return p.macro +} + +// RemapRstSrc() remaps Pad Reset Source Config +func (p *BasePlatform) RemapRstSrc() {} + +// Pull() adds The Pad Termination (TERM) parameter from PAD_CFG_DW1 to the macro +func (p *BasePlatform) Pull() { + const ( + PULL_NONE = 0x0 // 0 000: none + PULL_DN_5K = 0x2 // 0 010: 5k wpd (Only available on SMBus GPIOs) + PULL_DN_20K = 0x4 // 0 100: 20k wpd + // PULL_NONE = 0x8 // 1 000: none + PULL_UP_1K = 0x9 // 1 001: 1k wpu (Only available on I2C GPIOs) + PULL_UP_2K = 0xb // 1 011: 2k wpu (Only available on I2C GPIOs) + PULL_UP_20K = 0xc // 1 100: 20k wpu + PULL_UP_667 = 0xd // 1 101: 1k & 2k wpu (Only available on I2C GPIOs) + PULL_NATIVE = 0xf // 1 111: (optional) Native controller selected by Pad Mode + ) + + var pull = map[uint32]string{ + PULL_NONE: "NONE", + PULL_DN_5K: "DN_5K", + PULL_DN_20K: "DN_20K", + PULL_UP_1K: "UP_1K", + PULL_UP_2K: "UP_2K", + PULL_UP_20K: "UP_20K", + PULL_UP_667: "UP_667", + PULL_NATIVE: "NATIVE", + } + dw1 := p.GetRegisterDW1() + macro := p.GetMacro() + term, exist := pull[dw1.GetTermination()] + if !exist { + term = "INVALID" + logs.Errorf("%s: DW1 %s: invalid termination value 0b%b", + dw1, macro.GetPadId(), dw1.GetTermination()) + } + macro.Separator().Add(term) +} + +// Generate macro to cause peripheral IRQ when configured in GPIO input mode +func ioApicRoute(p *BasePlatform) bool { + if dw0 := p.GetRegisterDW0(); dw0.GetGPIOInputRouteIOxAPIC() == 0 { + return false + } + macro := p.GetMacro() + macro.Add("_APIC") + dw1 := p.GetRegisterDW1() + if dw1.GetIOStandbyState() != 0 || dw1.GetIOStandbyTermination() != 0 { + // e.g. H1_PCH_INT_ODL + // PAD_CFG_GPI_APIC_IOS(GPIO_63, NONE, DEEP, LEVEL, INVERT, TxDRxE, DISPUPD), + macro.Add("_IOS(").Id().Pull().Rstsrc().Trig().Invert().IOSstate().IOTerm() + } else { + // PAD_CFG_GPI_APIC(pad, pull, rst, trig, inv) + macro.Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") + } + macro.Add("),") + return true +} + +// Generate macro to cause NMI when configured in GPIO input mode +func nmiRoute(p *BasePlatform) bool { + if dw0 := p.GetRegisterDW0(); dw0.GetGPIOInputRouteNMI() == 0 { + return false + } + macro := p.GetMacro() + // e.g. PAD_CFG_GPI_NMI(GPIO_24, UP_20K, DEEP, LEVEL, INVERT), + macro.Add("_NMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") + return true +} + +// Generate macro to cause SCI when configured in GPIO input mode +func sciRoute(p *BasePlatform) bool { + dw0 := p.GetRegisterDW0() + if dw0.GetGPIOInputRouteSCI() == 0 { + return false + } + + macro := p.GetMacro() + dw1 := p.GetRegisterDW1() + if dw1.GetIOStandbyState() != 0 || dw1.GetIOStandbyTermination() != 0 { + // PAD_CFG_GPI_SCI_IOS(GPIO_141, NONE, DEEP, EDGE_SINGLE, INVERT, IGNORE, DISPUPD), + macro.Add("_SCI_IOS") + macro.Add("(").Id().Pull().Rstsrc().Trig().Invert().IOSstate().IOTerm() + } else if dw0.GetRXLevelEdgeConfiguration()&0x1 != 0 { + // e.g. PAD_CFG_GPI_ACPI_SCI(GPP_G2, NONE, DEEP, YES), + macro.Add("_ACPI_SCI").Add("(").Id().Pull().Rstsrc().Invert() + } else { + // e.g. PAD_CFG_GPI_SCI(GPP_B18, UP_20K, PLTRST, LEVEL, INVERT), + macro.Add("_SCI").Add("(").Id().Pull().Rstsrc().Trig().Invert() + } + macro.Add("),") + return true +} + +// Generate macro to cause SMI when configured in GPIO input mode +func smiRoute(p *BasePlatform) bool { + macro := p.GetMacro() + dw0 := p.GetRegisterDW0() + if dw0.GetGPIOInputRouteSMI() == 0 { + return false + } + dw1 := p.GetRegisterDW1() + if dw1.GetIOStandbyState() != 0 || dw1.GetIOStandbyTermination() != 0 { + // PAD_CFG_GPI_SMI_IOS(GPIO_41, UP_20K, DEEP, EDGE_SINGLE, NONE, IGNORE, SAME), + macro.Add("_SMI_IOS") + macro.Add("(").Id().Pull().Rstsrc().Trig().Invert().IOSstate().IOTerm() + } else if dw0.GetRXLevelEdgeConfiguration()&0x1 != 0 { + // e.g. PAD_CFG_GPI_ACPI_SMI(GPP_I3, NONE, DEEP, YES), + macro.Add("_ACPI_SMI").Add("(").Id().Pull().Rstsrc().Invert() + } else { + // e.g. PAD_CFG_GPI_SMI(GPP_E3, NONE, PLTRST, EDGE_SINGLE, NONE), + macro.Add("_SMI").Add("(").Id().Pull().Rstsrc().Trig().Invert() + } + macro.Add("),") + return true +} + +// AddGpiMacro() adds PAD_CFG_GPI macro with arguments +func (p *BasePlatform) AddGpiMacro() { + var ids []string + + macro := p.GetMacro() + macro.Set("PAD_CFG_GPI") + for routeid, isRoute := range map[string]func(p *BasePlatform) bool{ + "IOAPIC": ioApicRoute, + "SCI": sciRoute, + "SMI": smiRoute, + "NMI": nmiRoute, + } { + if isRoute(p) { + ids = append(ids, routeid) + } + } + + switch config, argc := p2m.SettingsGet(), len(ids); argc { + case 0: + dw1 := p.GetRegisterDW1() + isIOStandbyStateUsed := dw1.GetIOStandbyState() != 0 + isIOStandbyTerminationUsed := dw1.GetIOStandbyTermination() != 0 + if isIOStandbyStateUsed && !isIOStandbyTerminationUsed { + macro.Add("_TRIG_IOSSTATE_OWN(") + // PAD_CFG_GPI_TRIG_IOSSTATE_OWN(pad, pull, rst, trig, iosstate, own) + macro.Id().Pull().Rstsrc().Trig().IOSstate().Own().Add("),") + } else if isIOStandbyTerminationUsed { + macro.Add("_TRIG_IOS_OWN(") + // PAD_CFG_GPI_TRIG_IOS_OWN(pad, pull, rst, trig, iosstate, iosterm, own) + macro.Id().Pull().Rstsrc().Trig().IOSstate().IOTerm().Own().Add("),") + } else { + // PAD_CFG_GPI_TRIG_OWN(pad, pull, rst, trig, own) + macro.Add("_TRIG_OWN(").Id().Pull().Rstsrc().Trig().Own().Add("),") + } + case 1: + // GPI with IRQ route + if config.IgnoredFields { + macro.SetOwnershipAcpi() + } + case 2: + // PAD_CFG_GPI_DUAL_ROUTE(pad, pull, rst, trig, inv, route1, route2) + macro.Set("PAD_CFG_GPI_DUAL_ROUTE(").Id().Pull().Rstsrc().Trig().Invert() + macro.Add(", " + ids[0] + ", " + ids[1] + "),") + if config.IgnoredFields { + macro.SetOwnershipAcpi() + } + default: + // Clear the control mask so that the check fails and "Advanced" macro is + // generated + dw0 := p.GetRegisterDW0() + dw0.CntrMaskFieldsClear(bits.All32) + } +} + +// AddGpoMacro() adds PAD_CFG_GPO macro with arguments +func (p *BasePlatform) AddGpoMacro() { + macro := p.GetMacro() + macro.Set("PAD_CFG") + dw1 := p.GetRegisterDW1() + if dw1.GetIOStandbyState() != 0 || dw1.GetIOStandbyTermination() != 0 { + // PAD_CFG_GPO_IOSSTATE_IOSTERM(GPIO_91, 0, DEEP, NONE, Tx0RxDCRx0, DISPUPD), + // PAD_CFG_GPO_IOSSTATE_IOSTERM(pad, val, rst, pull, iosstate, ioterm) + macro.Add("_GPO_IOSSTATE_IOSTERM(").Id().Val().Rstsrc().Pull().IOSstate().IOTerm() + } else { + term := dw1.GetTermination() + if term != 0 { + // e.g. PAD_CFG_TERM_GPO(GPP_B23, 1, DN_20K, DEEP), + // PAD_CFG_TERM_GPO(pad, val, pull, rst) + macro.Add("_TERM") + } + macro.Add("_GPO(").Id().Val() + if term != 0 { + macro.Pull() + } + macro.Rstsrc() + } + macro.Add("),") + + if dw0 := p.GetRegisterDW0(); dw0.GetRXLevelEdgeConfiguration() != bits.TrigOFF { + // ignore if trig = OFF is not set + dw0.CntrMaskFieldsClear(bits.DW0[bits.DW0RxLevelEdgeConfiguration]) + } +} + +// AddNativeFunctionMacro() adds PAD_CFG_NF macro with arguments +func (p *BasePlatform) AddNativeFunctionMacro() { + macro := p.GetMacro() + macro.Set("PAD_CFG_NF") + dw1 := p.GetRegisterDW1() + isIOStandbyStateUsed := dw1.GetIOStandbyState() != 0 + isIOStandbyTerminationUsed := dw1.GetIOStandbyTermination() != 0 + if !isIOStandbyTerminationUsed && isIOStandbyStateUsed { + if dw1.GetIOStandbyState() == bits.IOStateStandbyIgnore { + // PAD_CFG_NF_IOSTANDBY_IGNORE(PMU_SLP_S0_B, NONE, DEEP, NF1), + macro.Add("_IOSTANDBY_IGNORE(").Id().Pull().Rstsrc().Padfn() + } else { + // PAD_CFG_NF_IOSSTATE(GPIO_22, UP_20K, DEEP, NF2, TxDRxE), + macro.Add("_IOSSTATE(").Id().Pull().Rstsrc().Padfn().IOSstate() + } + } else if isIOStandbyTerminationUsed { + // PAD_CFG_NF_IOSSTATE_IOSTERM(GPIO_103, NATIVE, DEEP, NF1, MASK, SAME), + macro.Add("_IOSSTATE_IOSTERM(").Id().Pull().Rstsrc().Padfn().IOSstate().IOTerm() + } else { + // e.g. PAD_CFG_NF(GPP_D23, NONE, DEEP, NF1) + macro.Add("(").Id().Pull().Rstsrc().Padfn() + } + macro.Add("),") + + if dw0 := p.GetRegisterDW0(); dw0.GetGPIORxTxDisableStatus() != 0 { + // Since the bufbis parameter will be ignored for NF, we should clear + // the corresponding bits in the control mask. + dw0.CntrMaskFieldsClear(bits.DW0[bits.DW0RxTxBufDisable]) + } +} + +// AddNoConnMacro() adds PAD_NC macro +func (p *BasePlatform) AddNoConnMacro() { + macro := p.GetMacro() + if dw1 := p.GetRegisterDW1(); dw1.GetIOStandbyState() == bits.IOStateTxDRxE { + dw0 := p.GetRegisterDW0() + // See comments in sunrise/macro.go : AddNoConnMacro() + if dw0.GetRXLevelEdgeConfiguration() != bits.TrigOFF { + dw0.CntrMaskFieldsClear(bits.DW0[bits.DW0RxLevelEdgeConfiguration]) + } + if dw0.GetResetConfig() != 1 { // 1 = RST_DEEP + dw0.CntrMaskFieldsClear(bits.DW0[bits.DW0PadRstCfg]) + } + // PAD_NC(OSC_CLK_OUT_1, DN_20K) + macro.Set("PAD_NC").Add("(").Id().Pull().Add("),") + return + } + // PAD_CFG_GPIO_HI_Z(GPIO_81, UP_20K, DEEP, HIZCRx0, DISPUPD), + if macro.Set("PAD_CFG_GPIO_"); macro.IsOwnershipDriver() { + // PAD_CFG_GPIO_DRIVER_HI_Z(GPIO_55, UP_20K, DEEP, HIZCRx1, ENPU), + macro.Add("DRIVER_") + } + macro.Add("HI_Z(").Id().Pull().Rstsrc().IOSstate().IOTerm().Add("),") +} + +// GenerateMacro() generates pad macro +func GenerateMacro(id string, dw0 uint32, dw1 uint32, owner bool) string { + platrorm := InitBasePlatform( + id, + owner, + register.ValDW0(dw0, dw0Mask), + register.ValDW1(dw1, dw1Mask), + ) + macro := platrorm.GetMacro() + return macro.Generate() +} + +// CheckKeyword() parses lines of the configuration file and returns true if the keyword is +// contained in the line +func CheckKeyword(line string) bool { + isIncluded, _ := common.KeywordsCheck(line, + "GPIO_", "TCK", "TRST_B", "TMS", "TDI", "CX_PMODE", "CX_PREQ_B", "JTAGX", "CX_PRDY_B", + "TDO", "CNV_BRI_DT", "CNV_BRI_RSP", "CNV_RGI_DT", "CNV_RGI_RSP", "SVID0_ALERT_B", + "SVID0_DATA", "SVID0_CLK", "PMC_SPI_FS", "PMC_SPI_RXD", "PMC_SPI_TXD", "PMC_SPI_CLK", + "PMIC_PWRGOOD", "PMIC_RESET_B", "PMIC_THERMTRIP_B", "PMIC_STDBY", "PROCHOT_B", + "PMIC_I2C_SCL", "PMIC_I2C_SDA", "FST_SPI_CLK_FB", "OSC_CLK_OUT_", "PMU_AC_PRESENT", + "PMU_BATLOW_B", "PMU_PLTRST_B", "PMU_PWRBTN_B", "PMU_RESETBUTTON_B", "PMU_SLP_S0_B", + "PMU_SLP_S3_B", "PMU_SLP_S4_B", "PMU_SUSCLK", "PMU_WAKE_B", "SUS_STAT_B", "SUSPWRDNACK", + "SMB_ALERTB", "SMB_CLK", "SMB_DATA", "LPC_ILB_SERIRQ", "LPC_CLKOUT", "LPC_AD", "LPC_CLKRUNB", + "LPC_FRAMEB") + return isIncluded +} diff --git a/util/intelp2m/platforms/apl/apl_test.go b/util/intelp2m/platforms/apollo/apollo_test.go similarity index 88% rename from util/intelp2m/platforms/apl/apl_test.go rename to util/intelp2m/platforms/apollo/apollo_test.go index 42d15ba4..1bb8fd2 100644 --- a/util/intelp2m/platforms/apl/apl_test.go +++ b/util/intelp2m/platforms/apollo/apollo_test.go @@ -1,167 +1,170 @@ -package apl_test +package apollo_test
import ( "testing"
- "review.coreboot.org/coreboot.git/util/intelp2m/platforms/apl" + "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/macros" "review.coreboot.org/coreboot.git/util/intelp2m/platforms/test" )
func TestGenMacro(t *testing.T) { - apollolake := apl.PlatformSpecific{} + config := p2m.SettingsGet() + config.Platform = p2m.Apollo + p2m.SettingsUpdate(config) test.Suite{ { /* GPIO_0 - GPIO */ - Pad: test.Pad{ID: "GPIO_0", DW0: 0x44000300, DW1: 0x1003d000, Ownership: 0}, + Pad: test.Pad{ID: "GPIO_0", DW0: 0x44000300, DW1: 0x1003d000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPIO_HI_Z(GPIO_0, DN_20K, DEEP, IGNORE, SAME),", Long: "_PAD_CFG_STRUCT(GPIO_0, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | PAD_BUF(TX_RX_DISABLE), PAD_PULL(DN_20K) | PAD_IOSSTATE(IGNORE)),", }, }, { /* GPIO_15 - GPIO */ - Pad: test.Pad{ID: "GPIO_15", DW0: 0x44000000, DW1: 0x10001000, Ownership: 0}, + Pad: test.Pad{ID: "GPIO_15", DW0: 0x44000000, DW1: 0x10001000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPIO_BIDIRECT(GPIO_15, 0, DN_20K, DEEP, OFF, ACPI),", Long: "_PAD_CFG_STRUCT(GPIO_15, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_PULL(DN_20K)),", }, }, { /* GPIO_16 - GPIO */ - Pad: test.Pad{ID: "GPIO_16", DW0: 0x44000003, DW1: 0x10003000, Ownership: 0}, + Pad: test.Pad{ID: "GPIO_16", DW0: 0x44000003, DW1: 0x10003000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPIO_BIDIRECT(GPIO_16, 1, UP_20K, DEEP, OFF, ACPI),", Long: "_PAD_CFG_STRUCT(GPIO_16, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | (1 << 1) | 1, PAD_PULL(UP_20K)),", }, }, { /* GPIO_18 - GPIO */ - Pad: test.Pad{ID: "GPIO_18", DW0: 0x44000102, DW1: 0x10003000, Ownership: 0}, + Pad: test.Pad{ID: "GPIO_18", DW0: 0x44000102, DW1: 0x10003000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_TRIG_OWN(GPIO_18, UP_20K, DEEP, OFF, ACPI),", Long: "_PAD_CFG_STRUCT(GPIO_18, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | PAD_BUF(TX_DISABLE) | (1 << 1), PAD_PULL(UP_20K)),", }, }, { /* GPIO_21 - GPIO */ - Pad: test.Pad{ID: "GPIO_21", DW0: 0x44000102, DW1: 0x10027000, Ownership: 0}, + Pad: test.Pad{ID: "GPIO_21", DW0: 0x44000102, DW1: 0x10027000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_TRIG_IOSSTATE_OWN(GPIO_21, UP_20K, DEEP, OFF, TxDRxE, ACPI),", Long: "_PAD_CFG_STRUCT(GPIO_21, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | PAD_BUF(TX_DISABLE) | (1 << 1), PAD_PULL(UP_20K) | PAD_IOSSTATE(TxDRxE)),", }, }, { /* GPIO_22 - GPIO */ - Pad: test.Pad{ID: "GPIO_22", DW0: 0x44800102, DW1: 0x10024100, Ownership: 1}, + Pad: test.Pad{ID: "GPIO_22", DW0: 0x44800102, DW1: 0x10024100, Ownership: macros.Driver}, Macro: test.Macro{ Short: "PAD_CFG_GPI_TRIG_IOS_OWN(GPIO_22, NONE, DEEP, OFF, TxDRxE, DISPUPD, DRIVER),", Long: "_PAD_CFG_STRUCT(GPIO_22, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | PAD_RX_POL(INVERT) | PAD_BUF(TX_DISABLE) | (1 << 1), PAD_IOSSTATE(TxDRxE) | PAD_IOSTERM(DISPUPD) | PAD_CFG_OWN_GPIO(DRIVER)),", }, }, { /* GPIO_25 - GPIO */ - Pad: test.Pad{ID: "GPIO_25", DW0: 0x40880102, DW1: 0x00027100, Ownership: 0}, + Pad: test.Pad{ID: "GPIO_25", DW0: 0x40880102, DW1: 0x00027100, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_SCI_IOS(GPIO_25, UP_20K, DEEP, LEVEL, INVERT, TxDRxE, DISPUPD),", Long: "_PAD_CFG_STRUCT(GPIO_25, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_IRQ_ROUTE(SCI) | PAD_RX_POL(INVERT) | PAD_BUF(TX_DISABLE) | (1 << 1), PAD_PULL(UP_20K) | PAD_IOSSTATE(TxDRxE) | PAD_IOSTERM(DISPUPD)),", }, }, { /* GPIO_26 - SATA_LEDN */ - Pad: test.Pad{ID: "GPIO_26", DW0: 0x44001400, DW1: 0x00003c00, Ownership: 1}, + Pad: test.Pad{ID: "GPIO_26", DW0: 0x44001400, DW1: 0x00003c00, Ownership: macros.Driver}, Macro: test.Macro{ Short: "PAD_CFG_NF(GPIO_26, NATIVE, DEEP, NF5),", Long: "_PAD_CFG_STRUCT(GPIO_26, PAD_FUNC(NF5) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_PULL(NATIVE) | PAD_CFG_OWN_GPIO(DRIVER)),", }, }, { /* GPIO_27 - GPIO */ - Pad: test.Pad{ID: "GPIO_27", DW0: 0x42880102, DW1: 0x00024100, Ownership: 0}, + Pad: test.Pad{ID: "GPIO_27", DW0: 0x42880102, DW1: 0x00024100, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_SCI_IOS(GPIO_27, NONE, DEEP, EDGE_SINGLE, INVERT, TxDRxE, DISPUPD),", Long: "_PAD_CFG_STRUCT(GPIO_27, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(EDGE_SINGLE) | PAD_IRQ_ROUTE(SCI) | PAD_RX_POL(INVERT) | PAD_BUF(TX_DISABLE) | (1 << 1), PAD_IOSSTATE(TxDRxE) | PAD_IOSTERM(DISPUPD)),", }, }, { /* TDI - JTAG_TDI */ - Pad: test.Pad{ID: "TDI", DW0: 0x44000700, DW1: 0x00c00000, Ownership: 0}, + Pad: test.Pad{ID: "TDI", DW0: 0x44000700, DW1: 0x00c00000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF(TDI, NONE, DEEP, NF1),", Long: "_PAD_CFG_STRUCT(TDI, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | PAD_BUF(TX_RX_DISABLE), 0),", }, }, { /* CNV_BRI_DT - GPIO */ - Pad: test.Pad{ID: "CNV_BRI_DT", DW0: 0x44000100, DW1: 0x1003d000, Ownership: 0}, + Pad: test.Pad{ID: "CNV_BRI_DT", DW0: 0x44000100, DW1: 0x1003d000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_TRIG_IOSSTATE_OWN(CNV_BRI_DT, DN_20K, DEEP, OFF, IGNORE, ACPI),", Long: "_PAD_CFG_STRUCT(CNV_BRI_DT, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | PAD_BUF(TX_DISABLE), PAD_PULL(DN_20K) | PAD_IOSSTATE(IGNORE)),", }, }, { /* CNV_BRI_RSP - GPIO */ - Pad: test.Pad{ID: "CNV_BRI_RSP", DW0: 0x44000201, DW1: 0x10003000, Ownership: 0}, + Pad: test.Pad{ID: "CNV_BRI_RSP", DW0: 0x44000201, DW1: 0x10003000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_TERM_GPO(CNV_BRI_RSP, 1, UP_20K, DEEP),", Long: "_PAD_CFG_STRUCT(CNV_BRI_RSP, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | PAD_BUF(RX_DISABLE) | 1, PAD_PULL(UP_20K)),", }, }, { /* GPIO_188 - DDI0_DDC_SCL */ - Pad: test.Pad{ID: "GPIO_188", DW0: 0x44000400, DW1: 0x0003fc00, Ownership: 0}, + Pad: test.Pad{ID: "GPIO_188", DW0: 0x44000400, DW1: 0x0003fc00, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF_IOSTANDBY_IGNORE(GPIO_188, NATIVE, DEEP, NF1),", Long: "_PAD_CFG_STRUCT(GPIO_188, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_PULL(NATIVE) | PAD_IOSSTATE(IGNORE)),", }, }, { /* GPIO_172 - SDCARD_CLK */ - Pad: test.Pad{ID: "GPIO_172", DW0: 0x44000400, DW1: 0x00021100, Ownership: 0}, + Pad: test.Pad{ID: "GPIO_172", DW0: 0x44000400, DW1: 0x00021100, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF_IOSSTATE_IOSTERM(GPIO_172, DN_20K, DEEP, NF1, HIZCRx1, DISPUPD),", Long: "_PAD_CFG_STRUCT(GPIO_172, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_PULL(DN_20K) | PAD_IOSSTATE(HIZCRx1) | PAD_IOSTERM(DISPUPD)),", }, }, { /* GPIO_176 - SDCARD_D3 */ - Pad: test.Pad{ID: "GPIO_176", DW0: 0x44000400, DW1: 0x00021000, Ownership: 0}, + Pad: test.Pad{ID: "GPIO_176", DW0: 0x44000400, DW1: 0x00021000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF_IOSSTATE(GPIO_176, DN_20K, DEEP, NF1, HIZCRx1),", Long: "_PAD_CFG_STRUCT(GPIO_176, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_PULL(DN_20K) | PAD_IOSSTATE(HIZCRx1)),", }, }, { /* GPIO_177 - GPIO */ - Pad: test.Pad{ID: "GPIO_177", DW0: 0x46000102, DW1: 0x10027000, Ownership: 1}, + Pad: test.Pad{ID: "GPIO_177", DW0: 0x46000102, DW1: 0x10027000, Ownership: macros.Driver}, Macro: test.Macro{ Short: "PAD_CFG_GPI_TRIG_IOSSTATE_OWN(GPIO_177, UP_20K, DEEP, EDGE_BOTH, TxDRxE, DRIVER),", Long: "_PAD_CFG_STRUCT(GPIO_177, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(EDGE_BOTH) | PAD_BUF(TX_DISABLE) | (1 << 1), PAD_PULL(UP_20K) | PAD_IOSSTATE(TxDRxE) | PAD_CFG_OWN_GPIO(DRIVER)),", }, }, { /* GPIO_186 - SDCARD_LVL_WP */ - Pad: test.Pad{ID: "GPIO_186", DW0: 0x44000402, DW1: 0x00003000, Ownership: 0}, + Pad: test.Pad{ID: "GPIO_186", DW0: 0x44000402, DW1: 0x00003000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF(GPIO_186, UP_20K, DEEP, NF1),", Long: "_PAD_CFG_STRUCT(GPIO_186, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | (1 << 1), PAD_PULL(UP_20K)),", }, }, { /* GPIO_182 - EMMC_RCLK */ - Pad: test.Pad{ID: "GPIO_182", DW0: 0x44000400, DW1: 0x0001d000, Ownership: 0}, + Pad: test.Pad{ID: "GPIO_182", DW0: 0x44000400, DW1: 0x0001d000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF_IOSSTATE(GPIO_182, DN_20K, DEEP, NF1, HIZCRx0),", Long: "_PAD_CFG_STRUCT(GPIO_182, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_PULL(DN_20K) | PAD_IOSSTATE(HIZCRx0)),", }, }, { /* LPC_CLKOUT0 - LPC_CLKOUT0 */ - Pad: test.Pad{ID: "LPC_CLKOUT0", DW0: 0x44000400, DW1: 0x00020100, Ownership: 0}, + Pad: test.Pad{ID: "LPC_CLKOUT0", DW0: 0x44000400, DW1: 0x00020100, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF_IOSSTATE_IOSTERM(LPC_CLKOUT0, NONE, DEEP, NF1, HIZCRx1, DISPUPD),", Long: "_PAD_CFG_STRUCT(LPC_CLKOUT0, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_IOSSTATE(HIZCRx1) | PAD_IOSTERM(DISPUPD)),", }, }, - }.Run(t, "INTEL-APOLLO-PCH/PAD-MAP", apollolake) + }.Run(t, "INTEL-APOLLO-PCH/PAD-MAP")
test.Suite{ { - Pad: test.Pad{ID: "GPP_1xx", DW0: 0xBFFFFFFF, DW1: 0xFFFFFFFF, Ownership: 1}, + Pad: test.Pad{ID: "GPP_1xx", DW0: 0xBFFFFFFF, DW1: 0xFFFFFFFF, Ownership: macros.Driver}, Macro: test.Macro{ Short: "PAD_CFG_NF_IOSSTATE_IOSTERM(GPP_1xx, NATIVE, PLTRST, NF7, IGNORE, ENPU),", Long: "_PAD_CFG_STRUCT(GPP_1xx, PAD_FUNC(NF7) | PAD_RESET(PLTRST) | PAD_TRIG(EDGE_BOTH) | PAD_IRQ_ROUTE(IOAPIC) | PAD_IRQ_ROUTE(SCI) | PAD_IRQ_ROUTE(SMI) | PAD_IRQ_ROUTE(NMI) | PAD_RX_POL(INVERT) | PAD_BUF(TX_RX_DISABLE) | (1 << 29) | (1 << 28) | (1 << 1) | 1, PAD_CFG1_TOL_1V8PAD_PULL(NATIVE) | PAD_IOSSTATE(IGNORE) | PAD_IOSTERM(ENPU) | PAD_CFG_OWN_GPIO(DRIVER)),", }, }, - }.Run(t, "INTEL-APOLLO-PCH/MASK", apollolake) + }.Run(t, "INTEL-APOLLO-PCH/MASK")
test.Suite{ { - Pad: test.Pad{ID: "GPP_2xx", DW0: 0x00000000, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_2xx", DW0: 0x00000000, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPIO_BIDIRECT(GPP_2xx, 0, NONE, PWROK, LEVEL, ACPI),", Long: "_PAD_CFG_STRUCT(GPP_2xx, PAD_FUNC(GPIO), 0),", }, }, - }.Run(t, "INTEL-APOLLO-PCH/EMRTY", apollolake) + }.Run(t, "INTEL-APOLLO-PCH/EMRTY") } diff --git a/util/intelp2m/platforms/cannon/cannon.go b/util/intelp2m/platforms/cannon/cannon.go new file mode 100644 index 0000000..830d77b --- /dev/null +++ b/util/intelp2m/platforms/cannon/cannon.go @@ -0,0 +1,207 @@ +package cannon + +import ( + "strings" + + "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" + "review.coreboot.org/coreboot.git/util/intelp2m/logs" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register/bits" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/sunrise" +) + +const ( + dw0Mask uint32 = (0x1 << 27) | (0x1 << 24) | (0x3 << 21) | (0xf << 16) | 0xfc + dw1Mask uint32 = 0xfdffc3ff +) + +type BasePlatform struct { + // based on the Sunrise platform + sunrise.BasePlatform +} + +func InitBasePlatform(id string, owner bool, dw0 register.DW0, dw1 register.DW1) BasePlatform { + return BasePlatform{ + BasePlatform: sunrise.InitBasePlatform(id, owner, dw0, dw1), + } +} + +// RemapRstSrc() remaps Pad Reset Source Config +func (p *BasePlatform) RemapRstSrc() { + macro := p.GetMacro() + if strings.Contains(macro.GetPadId(), "GPP_A") || + strings.Contains(macro.GetPadId(), "GPP_B") || + strings.Contains(macro.GetPadId(), "GPP_G") { + // See reset map for the Cannonlake Groups the Community 0: + // https://github.com/coreboot/coreboot/blob/master/src/soc/intel/cannonlake/gp... + // remmap is not required because it is the same as common. + return + } + + dw0 := p.GetRegisterDW0() + var remapping = map[uint32]uint32{ + 0: bits.RstCfgRSMRST << bits.DW0PadRstCfg, + 1: bits.RstCfgDEEP << bits.DW0PadRstCfg, + 2: bits.RstCfgPLTRST << bits.DW0PadRstCfg, + } + 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", + macro.GetPadId(), dw0, dw0.GetResetConfig()) + } + mask := bits.DW0[bits.DW0PadRstCfg] + dw0.CntrMaskFieldsClear(mask) +} + +// Pull() adds The Pad Termination (TERM) parameter from PAD_CFG_DW1 to the macro +func (p *BasePlatform) Pull() { + dw1 := p.GetRegisterDW1() + var pull = map[uint32]string{ + 0x0: "NONE", + 0x2: "DN_5K", + 0x4: "DN_20K", + 0x9: "UP_1K", + 0xa: "UP_5K", + 0xb: "UP_2K", + 0xc: "UP_20K", + 0xd: "UP_667", + 0xf: "NATIVE", + } + term, valid := pull[dw1.GetTermination()] + macro := p.GetMacro() + if !valid { + term = "INVALID" + logs.Errorf("%s: DW1 %s: invalid termination value 0b%b", + dw1, macro.GetPadId(), dw1.GetTermination()) + } + macro.Separator().Add(term) +} + +// ioApicRoute() generate macro to cause peripheral IRQ when configured in GPIO input mode +func ioApicRoute(p *BasePlatform) bool { + macro := p.GetMacro() + dw0 := p.GetRegisterDW0() + if dw0.GetGPIOInputRouteIOxAPIC() == 0 { + return false + } + + macro.Add("_APIC") + // PAD_CFG_GPI_APIC(pad, pull, rst, trig, inv) + macro.Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") + return true +} + +// nmiRoute() generate macro to cause NMI when configured in GPIO input mode +func nmiRoute(p *BasePlatform) bool { + if dw0 := p.GetRegisterDW0(); dw0.GetGPIOInputRouteNMI() == 0 { + return false + } + macro := p.GetMacro() + // PAD_CFG_GPI_NMI(GPIO_24, UP_20K, DEEP, LEVEL, INVERT), + macro.Add("_NMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") + return true +} + +// sciRoute() generate macro to cause SCI when configured in GPIO input mode +func sciRoute(p *BasePlatform) bool { + macro := p.GetMacro() + if dw0 := p.GetRegisterDW0(); dw0.GetGPIOInputRouteSCI() == 0 { + return false + } + // PAD_CFG_GPI_SCI(pad, pull, rst, trig, inv) + macro.Add("_SCI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") + return true +} + +// smiRoute() generates macro to cause SMI when configured in GPIO input mode +func smiRoute(p *BasePlatform) bool { + if dw0 := p.GetRegisterDW0(); dw0.GetGPIOInputRouteSMI() == 0 { + return false + } + macro := p.GetMacro() + // PAD_CFG_GPI_SMI(pad, pull, rst, trig, inv) + macro.Add("_SMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") + return true +} + +// AddGpiMacro() adds PAD_CFG_GPI macro with arguments +func (p *BasePlatform) AddGpiMacro() { + var ids []string + macro := p.GetMacro() + macro.Set("PAD_CFG_GPI") + for routeid, isRoute := range map[string]func(p *BasePlatform) bool{ + "IOAPIC": ioApicRoute, + "SCI": sciRoute, + "SMI": smiRoute, + "NMI": nmiRoute, + } { + if isRoute(p) { + ids = append(ids, routeid) + } + } + + switch config, argc := p2m.SettingsGet(), len(ids); argc { + case 0: + // e.g. PAD_CFG_GPI_TRIG_OWN(pad, pull, rst, trig, own) + macro.Add("_TRIG_OWN").Add("(").Id().Pull().Rstsrc().Trig().Own().Add("),") + case 1: + // GPI with IRQ route + if config.IgnoredFields { + // Set Host Software Ownership to ACPI mode + macro.SetOwnershipAcpi() + } + + case 2: + // PAD_CFG_GPI_DUAL_ROUTE(pad, pull, rst, trig, inv, route1, route2) + macro.Set("PAD_CFG_GPI_DUAL_ROUTE(").Id().Pull().Rstsrc().Trig().Invert() + macro.Add(", " + ids[0] + ", " + ids[1] + "),") + if config.IgnoredFields { + // Set Host Software Ownership to ACPI mode + macro.SetOwnershipAcpi() + } + default: + // Clear the control mask so that the check fails and "Advanced" macro is + // generated + dw0 := p.GetRegisterDW0() + dw0.CntrMaskFieldsClear(bits.All32) + } +} + +// Adds PAD_CFG_GPO macro with arguments +func (p *BasePlatform) AddGpoMacro() { + p.BasePlatform.AddGpoMacro() +} + +// Adds PAD_CFG_NF macro with arguments +func (p *BasePlatform) AddNativeFunctionMacro() { + p.BasePlatform.AddNativeFunctionMacro() +} + +// Adds PAD_NC macro +func (p *BasePlatform) AddNoConnMacro() { + p.BasePlatform.AddNoConnMacro() +} + +// GenerateMacro() generates pad macro +func GenerateMacro(id string, dw0 uint32, dw1 uint32, owner bool) string { + platrorm := InitBasePlatform( + id, + owner, + register.ValDW0(dw0, dw0Mask), + register.ValDW1(dw1, dw1Mask), + ) + macro := platrorm.GetMacro() + return macro.Generate() +} + +// CheckKeyword() parses lines of the configuration file and returns true if the keyword is +// contained in the line +// "GPP_A", "GPP_B", "GPP_G", "GPP_D", "GPP_F", "GPP_H", "GPD", "GPP_C", "GPP_E" +func CheckKeyword(line string) bool { + included, _ := common.KeywordsCheck(line, "GPP_", "GPD") + return included +} diff --git a/util/intelp2m/platforms/cnl/macro.go b/util/intelp2m/platforms/cnl/macro.go deleted file mode 100644 index 0d2ba46..0000000 --- a/util/intelp2m/platforms/cnl/macro.go +++ /dev/null @@ -1,218 +0,0 @@ -package cnl - -import ( - "fmt" - "strings" - - "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" - "review.coreboot.org/coreboot.git/util/intelp2m/fields" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register/bits" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/snr" -) - -const ( - PAD_CFG_DW0_RO_FIELDS = (0x1 << 27) | (0x1 << 24) | (0x3 << 21) | (0xf << 16) | 0xfc - PAD_CFG_DW1_RO_FIELDS = 0xfdffc3ff -) - -type InheritanceMacro interface { - GpoMacroAdd() - NativeFunctionMacroAdd() - NoConnMacroAdd() -} - -type PlatformSpecific struct { - InheritanceMacro - InheritanceTemplate -} - -// RemmapRstSrc - remmap Pad Reset Source Config -func (PlatformSpecific) RemmapRstSrc() { - macro := common.GetMacro() - if strings.Contains(macro.PadIdGet(), "GPP_A") || - strings.Contains(macro.PadIdGet(), "GPP_B") || - strings.Contains(macro.PadIdGet(), "GPP_G") { - // See reset map for the Cannonlake Groups the Community 0: - // https://github.com/coreboot/coreboot/blob/master/src/soc/intel/cannonlake/gp... - // remmap is not required because it is the same as common. - return - } - - dw0 := macro.GetRegisterDW0() - var remapping = map[uint32]uint32{ - 0: bits.RstCfgRSMRST << bits.DW0PadRstCfg, - 1: bits.RstCfgDEEP << bits.DW0PadRstCfg, - 2: bits.RstCfgPLTRST << bits.DW0PadRstCfg, - } - resetsrc, valid := remapping[dw0.GetResetConfig()] - if valid { - // dw0.SetResetConfig(resetsrc) - ResetConfigFieldVal := (dw0.Value & 0x3fffffff) | remapping[dw0.GetResetConfig()] - dw0.Value = ResetConfigFieldVal - } else { - fmt.Println("Invalid Pad Reset Config [ 0x", resetsrc, " ] for ", macro.PadIdGet()) - } - mask := bits.DW0[bits.DW0PadRstCfg] - dw0.CntrMaskFieldsClear(mask) -} - -// Adds The Pad Termination (TERM) parameter from PAD_CFG_DW1 to the macro -// as a new argument -func (PlatformSpecific) Pull() { - macro := common.GetMacro() - dw1 := macro.GetRegisterDW1() - var pull = map[uint32]string{ - 0x0: "NONE", - 0x2: "DN_5K", - 0x4: "DN_20K", - 0x9: "UP_1K", - 0xa: "UP_5K", - 0xb: "UP_2K", - 0xc: "UP_20K", - 0xd: "UP_667", - 0xf: "NATIVE", - } - str, valid := pull[dw1.GetTermination()] - if !valid { - str = "INVALID" - fmt.Println("Error", - macro.PadIdGet(), - " invalid TERM value = ", - int(dw1.GetTermination())) - } - macro.Separator().Add(str) -} - -// Generate macro to cause peripheral IRQ when configured in GPIO input mode -func ioApicRoute() bool { - macro := common.GetMacro() - dw0 := macro.GetRegisterDW0() - if dw0.GetGPIOInputRouteIOxAPIC() == 0 { - return false - } - - macro.Add("_APIC") - // PAD_CFG_GPI_APIC(pad, pull, rst, trig, inv) - macro.Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") - return true -} - -// Generate macro to cause NMI when configured in GPIO input mode -func nmiRoute() bool { - macro := common.GetMacro() - if macro.GetRegisterDW0().GetGPIOInputRouteNMI() == 0 { - return false - } - // PAD_CFG_GPI_NMI(GPIO_24, UP_20K, DEEP, LEVEL, INVERT), - macro.Add("_NMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") - return true -} - -// Generate macro to cause SCI when configured in GPIO input mode -func sciRoute() bool { - macro := common.GetMacro() - if macro.GetRegisterDW0().GetGPIOInputRouteSCI() == 0 { - return false - } - // PAD_CFG_GPI_SCI(pad, pull, rst, trig, inv) - macro.Add("_SCI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") - return true -} - -// Generate macro to cause SMI when configured in GPIO input mode -func smiRoute() bool { - macro := common.GetMacro() - - if macro.GetRegisterDW0().GetGPIOInputRouteSMI() == 0 { - return false - } - // PAD_CFG_GPI_SMI(pad, pull, rst, trig, inv) - macro.Add("_SMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") - return true -} - -// Adds PAD_CFG_GPI macro with arguments -func (PlatformSpecific) GpiMacroAdd() { - macro := common.GetMacro() - var ids []string - macro.Set("PAD_CFG_GPI") - for routeid, isRoute := range map[string]func() bool{ - "IOAPIC": ioApicRoute, - "SCI": sciRoute, - "SMI": smiRoute, - "NMI": nmiRoute, - } { - if isRoute() { - ids = append(ids, routeid) - } - } - - switch config, argc := p2m.SettingsGet(), len(ids); argc { - case 0: - // e.g. PAD_CFG_GPI_TRIG_OWN(pad, pull, rst, trig, own) - macro.Add("_TRIG_OWN").Add("(").Id().Pull().Rstsrc().Trig().Own().Add("),") - case 1: - // GPI with IRQ route - if config.IgnoredFields { - // Set Host Software Ownership to ACPI mode - macro.SetPadOwnership(common.PAD_OWN_ACPI) - } - - case 2: - // PAD_CFG_GPI_DUAL_ROUTE(pad, pull, rst, trig, inv, route1, route2) - macro.Set("PAD_CFG_GPI_DUAL_ROUTE(").Id().Pull().Rstsrc().Trig().Invert() - macro.Add(", " + ids[0] + ", " + ids[1] + "),") - if config.IgnoredFields { - // Set Host Software Ownership to ACPI mode - macro.SetPadOwnership(common.PAD_OWN_ACPI) - } - default: - // Clear the control mask so that the check fails and "Advanced" macro is - // generated - macro.GetRegisterDW0().CntrMaskFieldsClear(bits.All32) - } -} - -// Adds PAD_CFG_GPO macro with arguments -func (platform PlatformSpecific) GpoMacroAdd() { - platform.InheritanceMacro.GpoMacroAdd() -} - -// Adds PAD_CFG_NF macro with arguments -func (platform PlatformSpecific) NativeFunctionMacroAdd() { - platform.InheritanceMacro.NativeFunctionMacroAdd() -} - -// Adds PAD_NC macro -func (platform PlatformSpecific) NoConnMacroAdd() { - platform.InheritanceMacro.NoConnMacroAdd() -} - -// GenMacro - generate pad macro -// dw0Val : DW0 config register value -// dw1Val : DW1 config register value -// return: string of macro -// error -func (PlatformSpecific) GenMacro(id string, dw0Val uint32, dw1Val uint32, ownership uint8) string { - macro := common.GetInstanceMacro( - PlatformSpecific{ - InheritanceMacro: snr.PlatformSpecific{}, - }, - fields.InterfaceGet(), - ) - macro.Clear() - dw0 := macro.GetRegisterDW0() - dw0.CntrMaskFieldsClear(bits.All32) - - dw1 := macro.GetRegisterDW1() - dw1.CntrMaskFieldsClear(bits.All32) - - dw0.Value = dw0Val - dw1.Value = dw1Val - - dw0.ReadOnly = PAD_CFG_DW0_RO_FIELDS - dw1.ReadOnly = PAD_CFG_DW1_RO_FIELDS - macro.PadIdSet(id).SetPadOwnership(ownership) - return macro.Generate() -} diff --git a/util/intelp2m/platforms/cnl/template.go b/util/intelp2m/platforms/cnl/template.go deleted file mode 100644 index 886a59a..0000000 --- a/util/intelp2m/platforms/cnl/template.go +++ /dev/null @@ -1,14 +0,0 @@ -package cnl - -type InheritanceTemplate interface { - KeywordCheck(line string) bool -} - -// Group: "GPP_A", "GPP_B", "GPP_G", "GPP_D", "GPP_F", "GPP_H", "GPD", "GPP_C", "GPP_E" - -// KeywordCheck - This function is used to filter parsed lines of the configuration file and -// returns true if the keyword is contained in the line. -// line : string from the configuration file -func (platform PlatformSpecific) KeywordCheck(line string) bool { - return platform.InheritanceTemplate.KeywordCheck(line) -} diff --git a/util/intelp2m/platforms/common/macro.go b/util/intelp2m/platforms/common/macro.go deleted file mode 100644 index 534d76f..0000000 --- a/util/intelp2m/platforms/common/macro.go +++ /dev/null @@ -1,423 +0,0 @@ -package common - -import ( - "fmt" - "strconv" - "sync" - - "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register/bits" -) - -type Fields interface { - DecodeDW0() - DecodeDW1() - GenerateString() -} - -const ( - PAD_OWN_ACPI = 0 - PAD_OWN_DRIVER = 1 -) - -// PlatformSpecific - platform-specific interface -type PlatformSpecific interface { - RemmapRstSrc() - Pull() - GpiMacroAdd() - GpoMacroAdd() - NativeFunctionMacroAdd() - NoConnMacroAdd() -} - -// Macro - contains macro information and methods -// Platform : platform-specific interface -// padID : pad ID string -// str : macro string entirely -// Reg : structure of configuration register values and their masks -type Macro struct { - Platform PlatformSpecific - DW0 register.DW0 - DW1 register.DW1 - padID string - str string - ownership uint8 - Fields -} - -var instanceMacro *Macro -var once sync.Once - -// GetInstance returns singleton -func GetInstanceMacro(p PlatformSpecific, f Fields) *Macro { - once.Do(func() { - instanceMacro = &Macro{Platform: p, Fields: f} - }) - return instanceMacro -} - -func GetMacro() *Macro { - return GetInstanceMacro(nil, nil) -} - -func (macro *Macro) PadIdGet() string { - return macro.padID -} - -func (macro *Macro) PadIdSet(padid string) *Macro { - macro.padID = padid - return macro -} - -func (macro *Macro) SetPadOwnership(own uint8) *Macro { - macro.ownership = own - return macro -} - -func (macro *Macro) IsOwnershipDriver() bool { - return macro.ownership == PAD_OWN_DRIVER -} - -func (macro *Macro) GetRegisterDW0() *register.DW0 { - return ¯o.DW0 -} - -func (macro *Macro) GetRegisterDW1() *register.DW1 { - return ¯o.DW1 -} - -// add a string to macro -func (macro *Macro) Add(str string) *Macro { - macro.str += str - return macro -} - -// set a string in a macro instead of its previous contents -func (macro *Macro) Set(str string) *Macro { - macro.str = str - return macro -} - -// get macro string -func (macro *Macro) Get() string { - return macro.str -} - -// set a string in a macro instead of its previous contents -func (macro *Macro) Clear() *Macro { - macro.Set("") - return macro -} - -// Adds PAD Id to the macro as a new argument -// return: Macro -func (macro *Macro) Id() *Macro { - return macro.Add(macro.padID) -} - -// Add Separator to macro if needed -func (macro *Macro) Separator() *Macro { - str := macro.Get() - c := str[len(str)-1] - if c != '(' && c != '_' { - macro.Add(", ") - } - return macro -} - -// Adds the PADRSTCFG parameter from DW0 to the macro as a new argument -// return: Macro -func (macro *Macro) Rstsrc() *Macro { - dw0 := macro.GetRegisterDW0() - resetsrc := map[uint32]string{ - 0b00: "PWROK", - 0b01: "DEEP", - 0b10: "PLTRST", - 0b11: "RSMRST", - } - source, exist := resetsrc[dw0.GetResetConfig()] - if !exist { - source = "ERROR" - } - return macro.Separator().Add(source) -} - -// Adds The Pad Termination (TERM) parameter from DW1 to the macro as a new argument -// return: Macro -func (macro *Macro) Pull() *Macro { - macro.Platform.Pull() - return macro -} - -// Adds Pad GPO value to macro string as a new argument -// return: Macro -func (macro *Macro) Val() *Macro { - dw0 := macro.GetRegisterDW0() - return macro.Separator().Add(strconv.Itoa(int(dw0.GetGPIOTXState()))) -} - -// Adds Pad GPO value to macro string as a new argument -// return: Macro -func (macro *Macro) Trig() *Macro { - dw0 := macro.GetRegisterDW0() - trig := map[uint32]string{ - 0b00: "LEVEL", - 0b01: "EDGE_SINGLE", - 0b10: "OFF", - 0b11: "EDGE_BOTH", - } - level, exist := trig[dw0.GetRXLevelEdgeConfiguration()] - if !exist { - level = "ERROR" - } - return macro.Separator().Add(level) -} - -// Adds Pad Polarity Inversion Stage (RXINV) to macro string as a new argument -// return: Macro -func (macro *Macro) Invert() *Macro { - if macro.GetRegisterDW0().GetRxInvert() != 0 { - return macro.Separator().Add("INVERT") - } - return macro.Separator().Add("NONE") -} - -// Adds input/output buffer state -// return: Macro -func (macro *Macro) Bufdis() *Macro { - dw0 := macro.GetRegisterDW0() - states := map[uint32]string{ - 0b00: "NO_DISABLE", // both buffers are enabled - 0b01: "TX_DISABLE", // output buffer is disabled - 0b10: "RX_DISABLE", // input buffer is disabled - 0b11: "TX_RX_DISABLE", // both buffers are disabled - } - state, exist := states[dw0.GetGPIORxTxDisableStatus()] - if !exist { - state = "ERROR" - } - return macro.Separator().Add(state) -} - -// Adds macro to set the host software ownership -// return: Macro -func (macro *Macro) Own() *Macro { - if macro.IsOwnershipDriver() { - return macro.Separator().Add("DRIVER") - } - return macro.Separator().Add("ACPI") -} - -// Adds pad native function (PMODE) as a new argument -// return: Macro -func (macro *Macro) Padfn() *Macro { - dw0 := macro.GetRegisterDW0() - if number := dw0.GetPadMode(); number != 0 { - return macro.Separator().Add(fmt.Sprintf("NF%d", number)) - } - // GPIO used only for PAD_FUNC(x) macro - return macro.Add("GPIO") -} - -// Add a line to the macro that defines IO Standby State -// return: macro -func (macro *Macro) IOSstate() *Macro { - states := map[uint32]string{ - bits.IOStateTxLASTRxE: "TxLASTRxE", - bits.IOStateTx0RxDCRx0: "Tx0RxDCRx0", - bits.IOStateTx0RxDCRx1: "Tx0RxDCRx1", - bits.IOStateTx1RxDCRx0: "Tx1RxDCRx0", - bits.IOStateTx1RxDCRx1: "Tx1RxDCRx1", - bits.IOStateTx0RxE: "Tx0RxE", - bits.IOStateTx1RxE: "Tx1RxE", - bits.IOStateHIZCRx0: "HIZCRx0", - bits.IOStateHIZCRx1: "HIZCRx1", - bits.IOStateTxDRxE: "TxDRxE", - bits.IOStateStandbyIgnore: "IGNORE", - } - dw1 := macro.GetRegisterDW1() - state, exist := states[dw1.GetIOStandbyState()] - if !exist { - // ignore setting for incorrect value - state = "ERROR" - } - return macro.Separator().Add(state) -} - -// Add a line to the macro that defines IO Standby Termination -// return: macro -func (macro *Macro) IOTerm() *Macro { - dw1 := macro.GetRegisterDW1() - terminations := map[uint32]string{ - bits.IOTermSAME: "SAME", - bits.IOTermDISPUPD: "DISPUPD", - bits.IOTermENPD: "ENPD", - bits.IOTermENPU: "ENPU", - } - termination, exist := terminations[dw1.GetIOStandbyTermination()] - if !exist { - termination = "ERROR" - } - return macro.Separator().Add(termination) -} - -// Check created macro -func (macro *Macro) check() *Macro { - dw0 := macro.GetRegisterDW0() - if !dw0.MaskCheck() { - return macro.GenerateFields() - } - return macro -} - -// or - Set " | " if its needed -func (macro *Macro) Or() *Macro { - if str := macro.Get(); str[len(str)-1] == ')' { - macro.Add(" | ") - } - return macro -} - -func (macro *Macro) DecodeIgnoredFieldsDW0() *Macro { - if p2m.SettingsGet().Field == p2m.FspFlds { - return macro - } - dw0 := macro.GetRegisterDW0() - if ignored := dw0.IgnoredFieldsGet(); ignored != 0 { - saved := dw0.Value - dw0.Value = ignored - macro.Add("/* DW0: ") - macro.Fields.DecodeDW0() - macro.Add(" - IGNORED */\n") - dw0.Value = saved - } - return macro -} - -func (macro *Macro) DecodeIgnoredFieldsDW1() *Macro { - if p2m.SettingsGet().Field == p2m.FspFlds { - return macro - } - dw1 := macro.GetRegisterDW1() - if ignored := dw1.IgnoredFieldsGet(); ignored != 0 { - saved := dw1.Value - dw1.Value = ignored - macro.Add("/* DW0: ") - macro.DecodeDW1() - macro.Add(" - IGNORED */\n") - dw1.Value = saved - } - return macro -} - -// GenerateFields - generate bitfield macros -func (macro *Macro) GenerateFields() *Macro { - dw0 := macro.GetRegisterDW0() - dw1 := macro.GetRegisterDW1() - - // Get mask of ignored bit fields. - dw0Ignored := dw0.IgnoredFieldsGet() - dw1Ignored := dw1.IgnoredFieldsGet() - - config := p2m.SettingsGet() - if config.GenLevel != 4 { - macro.Clear() - } - if config.GenLevel >= 3 { - // Add string of reference macro as a comment - reference := macro.Get() - macro.Clear() - /* DW0 : PAD_TRIG(OFF) | PAD_BUF(RX_DISABLE) | 1 - IGNORED */ - macro.DecodeIgnoredFieldsDW0() - macro.DecodeIgnoredFieldsDW1() - if config.GenLevel >= 4 { - /* PAD_CFG_NF(GPP_B23, 20K_PD, PLTRST, NF2), */ - macro.Add("/* ").Add(reference).Add(" */\n") - } - } - if config.IgnoredFields { - // Consider bit fields that should be ignored when regenerating - // advansed macros - tempVal := dw0.Value & ^dw0Ignored - dw0.Value = tempVal - - tempVal = dw1.Value & ^dw1Ignored - dw1.Value = tempVal - } - - macro.Fields.GenerateString() - return macro -} - -// Generate macro for bi-directional GPIO port -func (macro *Macro) Bidirection() { - dw1 := macro.GetRegisterDW1() - ios := dw1.GetIOStandbyState() != 0 || dw1.GetIOStandbyTermination() != 0 - macro.Set("PAD_CFG_GPIO_BIDIRECT") - if ios { - macro.Add("_IOS") - } - // PAD_CFG_GPIO_BIDIRECT(pad, val, pull, rst, trig, own) - macro.Add("(").Id().Val().Pull().Rstsrc().Trig() - if ios { - // PAD_CFG_GPIO_BIDIRECT_IOS(pad, val, pull, rst, trig, iosstate, iosterm, own) - macro.IOSstate().IOTerm() - } - macro.Own().Add("),") -} - -// Gets base string of current macro -// return: string of macro -func (macro *Macro) Generate() string { - const rxDisable uint32 = 0x2 - const txDisable uint32 = 0x1 - - macro.Platform.RemmapRstSrc() - macro.Set("PAD_CFG") - if dw0 := macro.GetRegisterDW0(); dw0.GetPadMode() == 0 { - // GPIO - switch dw0.GetGPIORxTxDisableStatus() { - case txDisable: - macro.Platform.GpiMacroAdd() // GPI - - case rxDisable: - macro.Platform.GpoMacroAdd() // GPO - - case rxDisable | txDisable: - macro.Platform.NoConnMacroAdd() // NC - - default: - macro.Bidirection() - } - } else { - macro.Platform.NativeFunctionMacroAdd() - } - - config := p2m.SettingsGet() - - if config.Field != p2m.NoFlds { - // Clear control mask to generate advanced macro only - return macro.GenerateFields().Get() - } - - if !config.AutoCheck { - body := macro.Get() - if config.GenLevel >= 3 { - macro.Clear() - macro.DecodeIgnoredFieldsDW0() - macro.DecodeIgnoredFieldsDW1() - comment := macro.Get() - if config.GenLevel >= 4 { - macro.Clear().Add("/* ") - macro.Fields.GenerateString() - macro.Add(" */\n") - comment += macro.Get() - } - return comment + body - } - return body - } - - return macro.check().Get() -} diff --git a/util/intelp2m/platforms/common/macros/macros.go b/util/intelp2m/platforms/common/macros/macros.go new file mode 100644 index 0000000..eaf0d93 --- /dev/null +++ b/util/intelp2m/platforms/common/macros/macros.go @@ -0,0 +1,394 @@ +package macros + +import ( + "fmt" + "strconv" + + "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" + "review.coreboot.org/coreboot.git/util/intelp2m/logs" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register/bits" +) + +const ( + Driver bool = true + Acpi bool = false +) + +type FieldsIf interface { + DecodeDW0() + DecodeDW1() + GenerateMacro() +} + +type PlatformIf interface { + RemapRstSrc() + Pull() + AddGpiMacro() + AddGpoMacro() + AddNativeFunctionMacro() + AddNoConnMacro() + GetRegisterDW0() *register.DW0 + GetRegisterDW1() *register.DW1 +} + +type Macro struct { + line string + id string + ownership bool + Fields FieldsIf + Platform PlatformIf +} + +var instance Macro + +func Update(id string, owner bool, platform PlatformIf, fields FieldsIf) *Macro { + instance = Macro{id: id, ownership: owner, Platform: platform, Fields: fields} + return &instance +} + +func GetInstance() *Macro { + return &instance +} + +func (m *Macro) String() string { + return m.line +} + +func (m *Macro) GetPadId() string { + return m.id +} + +func (m Macro) IsOwnershipDriver() bool { + return m.ownership +} + +func (m *Macro) SetOwnershipAcpi() { + m.ownership = Acpi +} + +func (m *Macro) SetOwnershipDriver() { + m.ownership = Driver +} + +func (m *Macro) Add(str string) *Macro { + m.line += str + return m +} + +func (m *Macro) Set(str string) *Macro { + m.line = str + return m +} + +func (m *Macro) Clear() *Macro { + m.line = "" + return m +} + +// Id() adds Pad Id to the macro string +func (m *Macro) Id() *Macro { + return m.Add(m.id) +} + +// Separator() adds separator ", " to macro if needed +func (m *Macro) Separator() *Macro { + line := m.line + c := line[len(line)-1] + if c != '(' && c != '_' { + m.Add(", ") + } + return m +} + +// or - Set " | " if its needed +func (m *Macro) Or() *Macro { + if str := m.line; str[len(str)-1] == ')' { + m.Add(" | ") + } + return m +} + +// Rstsrc() adds PADRSTCFG parameter +func (m *Macro) Rstsrc() *Macro { + dw0 := m.Platform.GetRegisterDW0() + resetsrc := map[uint32]string{ + 0b00: "PWROK", + 0b01: "DEEP", + 0b10: "PLTRST", + 0b11: "RSMRST", + } + source, exist := resetsrc[dw0.GetResetConfig()] + if !exist { + logs.Errorf("%s: ResetConfig error: map does not contain %d", + m.id, dw0.GetResetConfig()) + source = "ERROR" + } + return m.Separator().Add(source) +} + +// Pull() adds Pad Termination TERM parameter +func (m *Macro) Pull() *Macro { + m.Platform.Pull() + return m +} + +// Val() adds pad GPO value to macro string +func (m *Macro) Val() *Macro { + dw0 := m.Platform.GetRegisterDW0() + return m.Separator().Add(strconv.Itoa(int(dw0.GetGPIOTXState()))) +} + +// Trig() adds Pad GPO value to macro string +func (m *Macro) Trig() *Macro { + dw0 := m.Platform.GetRegisterDW0() + trig := map[uint32]string{ + 0b00: "LEVEL", + 0b01: "EDGE_SINGLE", + 0b10: "OFF", + 0b11: "EDGE_BOTH", + } + level, exist := trig[dw0.GetRXLevelEdgeConfiguration()] + if !exist { + logs.Errorf("%s: RXLevelEdgeConfig error: map does not contain %d", + m.id, dw0.GetRXLevelEdgeConfiguration()) + level = "ERROR" + } + return m.Separator().Add(level) +} + +// Invert() adds Pad Polarity Inversion Stage (RXINV) to macro string +func (m *Macro) Invert() *Macro { + if dw0 := m.Platform.GetRegisterDW0(); dw0.GetRxInvert() != 0 { + return m.Separator().Add("INVERT") + } + return m.Separator().Add("NONE") +} + +// Bufdis() adds input/output buffer state +func (m *Macro) Bufdis() *Macro { + dw0 := m.Platform.GetRegisterDW0() + states := map[uint32]string{ + 0b00: "NO_DISABLE", // both buffers are enabled + 0b01: "TX_DISABLE", // output buffer is disabled + 0b10: "RX_DISABLE", // input buffer is disabled + 0b11: "TX_RX_DISABLE", // both buffers are disabled + } + state, exist := states[dw0.GetGPIORxTxDisableStatus()] + if !exist { + logs.Errorf("%s: GPIORxTxDisableStatus error: map does not contain %d", + m.id, dw0.GetGPIORxTxDisableStatus()) + state = "ERROR" + } + return m.Separator().Add(state) +} + +// Own() adds macro to set the host software ownership +func (m *Macro) Own() *Macro { + if m.IsOwnershipDriver() { + return m.Separator().Add("DRIVER") + } + return m.Separator().Add("ACPI") +} + +// Padfn() adds pad native function (PMODE) +func (m *Macro) Padfn() *Macro { + dw0 := m.Platform.GetRegisterDW0() + if number := dw0.GetPadMode(); number != 0 { + return m.Separator().Add(fmt.Sprintf("NF%d", number)) + } + // GPIO used only for PAD_FUNC(x) macro + return m.Add("GPIO") +} + +// IOSstate() adds a line to the macro that defines IO Standby State +func (m *Macro) IOSstate() *Macro { + states := map[uint32]string{ + bits.IOStateTxLASTRxE: "TxLASTRxE", + bits.IOStateTx0RxDCRx0: "Tx0RxDCRx0", + bits.IOStateTx0RxDCRx1: "Tx0RxDCRx1", + bits.IOStateTx1RxDCRx0: "Tx1RxDCRx0", + bits.IOStateTx1RxDCRx1: "Tx1RxDCRx1", + bits.IOStateTx0RxE: "Tx0RxE", + bits.IOStateTx1RxE: "Tx1RxE", + bits.IOStateHIZCRx0: "HIZCRx0", + bits.IOStateHIZCRx1: "HIZCRx1", + bits.IOStateTxDRxE: "TxDRxE", + bits.IOStateStandbyIgnore: "IGNORE", + } + dw1 := m.Platform.GetRegisterDW1() + state, exist := states[dw1.GetIOStandbyState()] + if !exist { + logs.Errorf("%s: IOStandbyState error: map does not contain %d", + m.id, dw1.GetIOStandbyState()) + state = "ERROR" + } + return m.Separator().Add(state) +} + +// IOTerm() add a line to the macro that defines IO Standby Termination +func (m *Macro) IOTerm() *Macro { + dw1 := m.Platform.GetRegisterDW1() + terminations := map[uint32]string{ + bits.IOTermSAME: "SAME", + bits.IOTermDISPUPD: "DISPUPD", + bits.IOTermENPD: "ENPD", + bits.IOTermENPU: "ENPU", + } + termination, exist := terminations[dw1.GetIOStandbyTermination()] + if !exist { + logs.Errorf("%s: IOStandbyTermination error: map does not contain %d", + m.id, dw1.GetIOStandbyTermination()) + termination = "ERROR" + } + return m.Separator().Add(termination) +} + +// Check created macro +func (m *Macro) Check() *Macro { + dw0 := m.Platform.GetRegisterDW0() + if !dw0.MaskCheck() { + return m.GenerateFields() + } + return m +} + +func (m *Macro) DecodeIgnoredFieldsDW0() *Macro { + if p2m.SettingsGet().Field == p2m.FspFlds { + logs.Infof("%s: decoding of extracted fields is not applied for fsp", m.id) + return m + } + dw0 := m.Platform.GetRegisterDW0() + if ignored := dw0.IgnoredFieldsGet(); ignored != 0 { + saved := dw0.Value + dw0.Value = ignored + m.Add("/* DW0: ") + m.Fields.DecodeDW0() + m.Add(" - IGNORED */\n") + dw0.Value = saved + } + return m +} + +func (m *Macro) DecodeIgnoredFieldsDW1() *Macro { + if p2m.SettingsGet().Field == p2m.FspFlds { + return m + } + dw1 := m.Platform.GetRegisterDW1() + if ignored := dw1.IgnoredFieldsGet(); ignored != 0 { + saved := dw1.Value + dw1.Value = ignored + m.Add("/* DW0: ") + m.Fields.DecodeDW1() + m.Add(" - IGNORED */\n") + dw1.Value = saved + } + return m +} + +// GenerateFields() generates bitfield macros +func (m *Macro) GenerateFields() *Macro { + dw0 := m.Platform.GetRegisterDW0() + dw1 := m.Platform.GetRegisterDW1() + + // Get mask of ignored bit fields. + dw0Ignored := dw0.IgnoredFieldsGet() + dw1Ignored := dw1.IgnoredFieldsGet() + + config := p2m.SettingsGet() + if config.GenLevel != 4 { + m.Clear() + } + if config.GenLevel >= 3 { + // Add string of reference m as a comment + reference := m.line + m.Clear() + /* DW0 : PAD_TRIG(OFF) | PAD_BUF(RX_DISABLE) | 1 - IGNORED */ + m.DecodeIgnoredFieldsDW0() + m.DecodeIgnoredFieldsDW1() + if config.GenLevel >= 4 { + /* PAD_CFG_NF(GPP_B23, 20K_PD, PLTRST, NF2), */ + m.Add("/* ").Add(reference).Add(" */\n") + } + } + if config.IgnoredFields { + // Consider bit fields that should be ignored when regenerating + // advansed ms + tempVal := dw0.Value & ^dw0Ignored + dw0.Value = tempVal + + tempVal = dw1.Value & ^dw1Ignored + dw1.Value = tempVal + } + + m.Fields.GenerateMacro() + return m +} + +// Bidirection() generates macro for bi-directional GPIO port +func (m *Macro) Bidirection() { + dw1 := m.Platform.GetRegisterDW1() + ios := dw1.GetIOStandbyState() != 0 || dw1.GetIOStandbyTermination() != 0 + m.Set("PAD_CFG_GPIO_BIDIRECT") + if ios { + m.Add("_IOS") + } + // PAD_CFG_GPIO_BIDIRECT(pad, val, pull, rst, trig, own) + m.Add("(").Id().Val().Pull().Rstsrc().Trig() + if ios { + // PAD_CFG_GPIO_BIDIRECT_IOS(pad, val, pull, rst, trig, iosstate, iosterm, own) + m.IOSstate().IOTerm() + } + m.Own().Add("),") +} + +// Generate() generates string of macro +func (m *Macro) Generate() string { + m.Platform.RemapRstSrc() + if dw0 := m.Platform.GetRegisterDW0(); dw0.GetPadMode() == 0 { + const txDisable uint32 = 0b01 + const rxDisable uint32 = 0b10 + switch m.Set("PAD_CFG"); dw0.GetGPIORxTxDisableStatus() { + case txDisable: + m.Platform.AddGpiMacro() // GPI + + case rxDisable: + m.Platform.AddGpoMacro() // GPO + + case rxDisable | txDisable: + m.Platform.AddNoConnMacro() // NC + + default: + m.Bidirection() + } + } else { + m.Platform.AddNativeFunctionMacro() + } + + config := p2m.SettingsGet() + + if config.Field != p2m.NoFlds { + // clear control mask to generate field collection macro + return m.GenerateFields().line + } + + if !config.AutoCheck { + body := m.line + if config.GenLevel >= 3 { + m.Clear() + m.DecodeIgnoredFieldsDW0() + m.DecodeIgnoredFieldsDW1() + comment := m.line + if config.GenLevel >= 4 { + m.Clear().Add("/* ") + m.Fields.GenerateMacro() + m.Add(" */\n") + comment += m.line + } + return comment + body + } + return body + } + + return m.Check().line +} diff --git a/util/intelp2m/platforms/common/register/helper.go b/util/intelp2m/platforms/common/register/helper.go index f6850da..b0da102 100644 --- a/util/intelp2m/platforms/common/register/helper.go +++ b/util/intelp2m/platforms/common/register/helper.go @@ -7,3 +7,11 @@ func ValueDW1(value uint32) DW1 { return DW1{Register: Register{Value: value}} } + +func ValDW0(value uint32, ro uint32) DW0 { + return DW0{Register: Register{Value: value, ReadOnly: ro}} +} + +func ValDW1(value uint32, ro uint32) DW1 { + return DW1{Register: Register{Value: value, ReadOnly: ro}} +} diff --git a/util/intelp2m/platforms/interfaces.go b/util/intelp2m/platforms/interfaces.go index d3e0a2d..65af90d 100644 --- a/util/intelp2m/platforms/interfaces.go +++ b/util/intelp2m/platforms/interfaces.go @@ -3,37 +3,47 @@ import ( "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" "review.coreboot.org/coreboot.git/util/intelp2m/logs" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/adl" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/apl" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/cnl" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/lbg" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/snr" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/alder" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/apollo" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/cannon" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/lewisburg" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/sunrise" )
-type SpecificIf interface { - GenMacro(id string, dw0 uint32, dw1 uint32, ownership uint8) string - KeywordCheck(line string) bool -} +type KeywordAction func(line string) bool
-func GetSpecificInterface() SpecificIf { - platforms := map[p2m.PlatformType]SpecificIf{ - p2m.Alder: adl.PlatformSpecific{}, - p2m.Apollo: apl.PlatformSpecific{}, - p2m.Sunrise: snr.PlatformSpecific{}, - p2m.Cannon: cnl.PlatformSpecific{ - InheritanceTemplate: snr.PlatformSpecific{}, - InheritanceMacro: snr.PlatformSpecific{}, - }, - p2m.Lewisburg: lbg.PlatformSpecific{ - InheritanceTemplate: snr.PlatformSpecific{}, - InheritanceMacro: snr.PlatformSpecific{}, - }, +func GetKeywordChekingAction() KeywordAction { + actions := map[p2m.PlatformType]KeywordAction{ + p2m.Alder: alder.CheckKeyword, + p2m.Apollo: apollo.CheckKeyword, + p2m.Cannon: cannon.CheckKeyword, + p2m.Sunrise: sunrise.CheckKeyword, + p2m.Lewisburg: lewisburg.CheckKeyword, } - platformType := p2m.SettingsGet().Platform - platform, exist := platforms[platformType] + config := p2m.SettingsGet() + action, exist := actions[config.Platform] if !exist { - logs.Errorf("unknown platform type %d", int(platformType)) + logs.Errorf("unregistered platform type %d", config.Platform) return nil } - return platform + return action +} + +type MacroAction func(id string, dw0 uint32, dw1 uint32, ownership bool) string + +func GetMacroAction() MacroAction { + actions := map[p2m.PlatformType]MacroAction{ + p2m.Alder: alder.GenerateMacro, + p2m.Apollo: apollo.GenerateMacro, + p2m.Cannon: cannon.GenerateMacro, + p2m.Sunrise: sunrise.GenerateMacro, + p2m.Lewisburg: lewisburg.GenerateMacro, + } + config := p2m.SettingsGet() + action, exist := actions[config.Platform] + if !exist { + logs.Errorf("unregistered platform type %d", config.Platform) + return nil + } + return action } diff --git a/util/intelp2m/platforms/interfaces/interfaces.go b/util/intelp2m/platforms/interfaces/interfaces.go new file mode 100644 index 0000000..ce5c1db --- /dev/null +++ b/util/intelp2m/platforms/interfaces/interfaces.go @@ -0,0 +1,12 @@ +package interfaces + +import ( + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/macros" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register" +) + +type PlatformIf interface { + GetRegisterDW0() *register.DW0 + GetRegisterDW1() *register.DW1 + GetMacro() *macros.Macro +} diff --git a/util/intelp2m/platforms/lbg/macro.go b/util/intelp2m/platforms/lbg/macro.go deleted file mode 100644 index 63b7d2b..0000000 --- a/util/intelp2m/platforms/lbg/macro.go +++ /dev/null @@ -1,101 +0,0 @@ -package lbg - -import ( - "fmt" - - "review.coreboot.org/coreboot.git/util/intelp2m/fields" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register/bits" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/snr" -) - -const ( - PAD_CFG_DW0_RO_FIELDS = (0x1 << 27) | (0x1 << 24) | (0x3 << 21) | (0xf << 16) | 0xfc - PAD_CFG_DW1_RO_FIELDS = 0xfdffc3ff -) - -type InheritanceMacro interface { - Pull() - GpiMacroAdd() - GpoMacroAdd() - NativeFunctionMacroAdd() - NoConnMacroAdd() -} - -type PlatformSpecific struct { - InheritanceMacro - InheritanceTemplate -} - -// RemmapRstSrc - remmap Pad Reset Source Config -func (PlatformSpecific) RemmapRstSrc() { - macro := common.GetMacro() - dw0 := macro.GetRegisterDW0() - remapping := map[uint32]uint32{ - 0: (bits.RstCfgRSMRST << bits.DW0PadRstCfg), - 1: (bits.RstCfgDEEP << bits.DW0PadRstCfg), - 2: (bits.RstCfgPLTRST << bits.DW0PadRstCfg), - } - resetsrc, valid := remapping[dw0.GetResetConfig()] - if valid { - // dw0.SetResetConfig(resetsrc) - ResetConfigFieldVal := (dw0.Value & 0x3fffffff) | remapping[dw0.GetResetConfig()] - dw0.Value = ResetConfigFieldVal - } else { - fmt.Println("Invalid Pad Reset Config [ 0x", resetsrc, " ] for ", macro.PadIdGet()) - } - mask := bits.DW0[bits.DW0PadRstCfg] - dw0.CntrMaskFieldsClear(mask) -} - -// Adds The Pad Termination (TERM) parameter from PAD_CFG_DW1 to the macro -// as a new argument -func (platform PlatformSpecific) Pull() { - platform.InheritanceMacro.Pull() -} - -// Adds PAD_CFG_GPI macro with arguments -func (platform PlatformSpecific) GpiMacroAdd() { - platform.InheritanceMacro.GpiMacroAdd() -} - -// Adds PAD_CFG_GPO macro with arguments -func (platform PlatformSpecific) GpoMacroAdd() { - platform.InheritanceMacro.GpoMacroAdd() -} - -// Adds PAD_CFG_NF macro with arguments -func (platform PlatformSpecific) NativeFunctionMacroAdd() { - platform.InheritanceMacro.NativeFunctionMacroAdd() -} - -// Adds PAD_NC macro -func (platform PlatformSpecific) NoConnMacroAdd() { - platform.InheritanceMacro.NoConnMacroAdd() -} - -// GenMacro - generate pad macro -// dw0val : DW0 config register value -// dw1val : DW1 config register value -// return: string of macro -// error -func (platform PlatformSpecific) GenMacro(id string, dw0Val uint32, dw1Val uint32, ownership uint8) string { - // The GPIO controller architecture in Lewisburg and Sunrise are very similar, - // so we will inherit some platform-dependent functions from Sunrise. - macro := common.GetInstanceMacro(PlatformSpecific{InheritanceMacro: snr.PlatformSpecific{}}, - fields.InterfaceGet()) - macro.Clear() - dw0 := macro.GetRegisterDW0() - dw0.CntrMaskFieldsClear(bits.All32) - - dw1 := macro.GetRegisterDW1() - dw1.CntrMaskFieldsClear(bits.All32) - - dw0.Value = dw0Val - dw1.Value = dw1Val - - dw0.ReadOnly = PAD_CFG_DW0_RO_FIELDS - dw1.ReadOnly = PAD_CFG_DW1_RO_FIELDS - macro.PadIdSet(id).SetPadOwnership(ownership) - return macro.Generate() -} diff --git a/util/intelp2m/platforms/lbg/template.go b/util/intelp2m/platforms/lbg/template.go deleted file mode 100644 index d76f2cd..0000000 --- a/util/intelp2m/platforms/lbg/template.go +++ /dev/null @@ -1,15 +0,0 @@ -package lbg - -type InheritanceTemplate interface { - KeywordCheck(line string) bool -} - -// Group: "GPP_A", "GPP_B", "GPP_F", "GPP_C", "GPP_D", "GPP_E", "GPD", "GPP_I", "GPP_J", -// "GPP_K", "GPP_G", "GPP_H", "GPP_L" - -// KeywordCheck - This function is used to filter parsed lines of the configuration file and -// returns true if the keyword is contained in the line. -// line : string from the configuration file -func (platform PlatformSpecific) KeywordCheck(line string) bool { - return platform.InheritanceTemplate.KeywordCheck(line) -} diff --git a/util/intelp2m/platforms/lewisburg/lewisburg.go b/util/intelp2m/platforms/lewisburg/lewisburg.go new file mode 100644 index 0000000..c83dd9e --- /dev/null +++ b/util/intelp2m/platforms/lewisburg/lewisburg.go @@ -0,0 +1,93 @@ +package lewisburg + +import ( + "review.coreboot.org/coreboot.git/util/intelp2m/logs" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register/bits" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/sunrise" +) + +const ( + dw0Mask uint32 = (0x1 << 27) | (0x1 << 24) | (0x3 << 21) | (0xf << 16) | 0xfc + dw1Mask uint32 = 0xfdffc3ff +) + +type BasePlatform struct { + // Lewisburg and Sunrise are very similar, so inherit the basic Sunrise platform + sunrise.BasePlatform +} + +func InitBasePlatform(id string, owner bool, dw0 register.DW0, dw1 register.DW1) BasePlatform { + return BasePlatform{ + BasePlatform: sunrise.InitBasePlatform(id, owner, dw0, dw1), + } +} + +// RemapRstSrc() remaps Pad Reset Source Config +func (p *BasePlatform) RemapRstSrc() { + dw0 := p.GetRegisterDW0() + remapping := map[uint32]uint32{ + 0: (bits.RstCfgRSMRST << bits.DW0PadRstCfg), + 1: (bits.RstCfgDEEP << bits.DW0PadRstCfg), + 2: (bits.RstCfgPLTRST << bits.DW0PadRstCfg), + } + source, valid := remapping[dw0.GetResetConfig()] + if valid { + // dw0.SetResetConfig(resetsrc) + dw0.Value &= 0x3fffffff + dw0.Value |= source + } else { + macro := p.GetMacro() + logs.Errorf("%s: skip re-mapping: DW0 %s: invalid reset config source value 0b%b", + macro.GetPadId(), dw0, dw0.GetResetConfig()) + } + mask := bits.DW0[bits.DW0PadRstCfg] + dw0.CntrMaskFieldsClear(mask) +} + +// Pull() adds The Pad Termination (TERM) parameter from PAD_CFG_DW1 to the macro +func (p *BasePlatform) Pull() { + p.BasePlatform.Pull() +} + +// AddGpiMacro() adds PAD_CFG_GPI macro with arguments +func (p *BasePlatform) AddGpiMacro() { + p.BasePlatform.AddGpiMacro() +} + +// AddGpoMacro() adds PAD_CFG_GPO macro with arguments +func (p *BasePlatform) AddGpoMacro() { + p.BasePlatform.AddGpoMacro() +} + +// AddNativeFunctionMacro() adds PAD_CFG_NF macro with arguments +func (p *BasePlatform) AddNativeFunctionMacro() { + p.BasePlatform.AddNativeFunctionMacro() +} + +// AddNoConnMacro() adds PAD_NC macro +func (p *BasePlatform) AddNoConnMacro() { + p.BasePlatform.AddNoConnMacro() +} + +// GenerateMacro() generates pad macro +func GenerateMacro(id string, dw0 uint32, dw1 uint32, owner bool) string { + platrorm := InitBasePlatform( + id, + owner, + register.ValDW0(dw0, dw0Mask), + register.ValDW1(dw1, dw1Mask), + ) + macro := platrorm.GetMacro() + return macro.Generate() +} + +// CheckKeyword() parses lines of the configuration file and returns true if the keyword is +// contained in the line +// "GPP_A", "GPP_B", "GPP_F", "GPP_C", "GPP_D", "GPP_E", "GPD", "GPP_I", "GPP_J", +// "GPP_K", "GPP_G", "GPP_H", "GPP_L" +func CheckKeyword(line string) bool { + included, _ := common.KeywordsCheck(line, "GPP_", "GPD") + return included +} diff --git a/util/intelp2m/platforms/lbg/lbg_test.go b/util/intelp2m/platforms/lewisburg/lewisburg_test.go similarity index 87% rename from util/intelp2m/platforms/lbg/lbg_test.go rename to util/intelp2m/platforms/lewisburg/lewisburg_test.go index 62eba804..5b235c9 100644 --- a/util/intelp2m/platforms/lbg/lbg_test.go +++ b/util/intelp2m/platforms/lewisburg/lewisburg_test.go @@ -1,175 +1,177 @@ -package lbg_test +package lewisburg_test
import ( "testing"
- "review.coreboot.org/coreboot.git/util/intelp2m/platforms/lbg" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/snr" + "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/macros" "review.coreboot.org/coreboot.git/util/intelp2m/platforms/test" )
func TestGenMacro(t *testing.T) { - lewisburg := lbg.PlatformSpecific{InheritanceMacro: snr.PlatformSpecific{}} + config := p2m.SettingsGet() + config.Platform = p2m.Lewisburg + p2m.SettingsUpdate(config) test.Suite{ { /* GPP_A1 - ESPI_ALERT1# */ - Pad: test.Pad{ID: "GPP_A1", DW0: 0x44000c00, DW1: 0x00003000, Ownership: 1}, + Pad: test.Pad{ID: "GPP_A1", DW0: 0x44000c00, DW1: 0x00003000, Ownership: macros.Driver}, Macro: test.Macro{ Short: "PAD_CFG_NF(GPP_A1, UP_20K, DEEP, NF3),", Long: "_PAD_CFG_STRUCT(GPP_A1, PAD_FUNC(NF3) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_PULL(UP_20K) | PAD_CFG_OWN_GPIO(DRIVER)),", }, }, { /* GPP_A12 - LFRAME# */ - Pad: test.Pad{ID: "GPP_A12", DW0: 0x80880102, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_A12", DW0: 0x80880102, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_SCI(GPP_A12, NONE, PLTRST, LEVEL, INVERT),", Long: "_PAD_CFG_STRUCT(GPP_A12, PAD_FUNC(GPIO) | PAD_RESET(PLTRST) | PAD_IRQ_ROUTE(SCI) | PAD_RX_POL(INVERT) | PAD_BUF(TX_DISABLE) | (1 << 1), 0),", }, }, { /* GPP_A16 - GPIO */ - Pad: test.Pad{ID: "GPP_A16", DW0: 0x44000201, DW1: 0x00000000, Ownership: 1}, + Pad: test.Pad{ID: "GPP_A16", DW0: 0x44000201, DW1: 0x00000000, Ownership: macros.Driver}, Macro: test.Macro{ Short: "PAD_CFG_GPO_GPIO_DRIVER(GPP_A16, 1, DEEP, NONE),", Long: "_PAD_CFG_STRUCT(GPP_A16, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | PAD_BUF(RX_DISABLE) | 1, PAD_CFG_OWN_GPIO(DRIVER)),", }, }, { /* GPP_A20 - GPIO */ - Pad: test.Pad{ID: "GPP_A20", DW0: 0x04000100, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_A20", DW0: 0x04000100, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_TRIG_OWN(GPP_A20, NONE, RSMRST, OFF, ACPI),", Long: "_PAD_CFG_STRUCT(GPP_A20, PAD_FUNC(GPIO) | PAD_RESET(RSMRST) | PAD_TRIG(OFF) | PAD_BUF(TX_DISABLE), 0),", }, }, { /* GPP_B10 - GPIO */ - Pad: test.Pad{ID: "GPP_B10", DW0: 0x04000102, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_B10", DW0: 0x04000102, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_TRIG_OWN(GPP_B10, NONE, RSMRST, OFF, ACPI),", Long: "_PAD_CFG_STRUCT(GPP_B10, PAD_FUNC(GPIO) | PAD_RESET(RSMRST) | PAD_TRIG(OFF) | PAD_BUF(TX_DISABLE) | (1 << 1), 0),", }, }, { /* GPP_B20 - GPIO */ - Pad: test.Pad{ID: "GPP_B20", DW0: 0x04000200, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_B20", DW0: 0x04000200, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPO(GPP_B20, 0, RSMRST),", Long: "_PAD_CFG_STRUCT(GPP_B20, PAD_FUNC(GPIO) | PAD_RESET(RSMRST) | PAD_TRIG(OFF) | PAD_BUF(RX_DISABLE), 0),", }, }, { /* GPP_B23 - PCHHOT# */ - Pad: test.Pad{ID: "GPP_B23", DW0: 0x04000a00, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_B23", DW0: 0x04000a00, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF(GPP_B23, NONE, RSMRST, NF2),", Long: "_PAD_CFG_STRUCT(GPP_B23, PAD_FUNC(NF2) | PAD_RESET(RSMRST) | PAD_TRIG(OFF) | PAD_BUF(RX_DISABLE), 0),", }, }, { /* GPP_F0 - SATAXPCIE3 */ - Pad: test.Pad{ID: "GPP_F0", DW0: 0x04000502, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_F0", DW0: 0x04000502, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF(GPP_F0, NONE, RSMRST, NF1),", Long: "_PAD_CFG_STRUCT(GPP_F0, PAD_FUNC(NF1) | PAD_RESET(RSMRST) | PAD_TRIG(OFF) | PAD_BUF(TX_DISABLE) | (1 << 1), 0),", }, }, { /* GPP_C10 - GPIO */ - Pad: test.Pad{ID: "GPP_C10", DW0: 0x04000000, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_C10", DW0: 0x04000000, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPIO_BIDIRECT(GPP_C10, 0, NONE, RSMRST, OFF, ACPI),", Long: "_PAD_CFG_STRUCT(GPP_C10, PAD_FUNC(GPIO) | PAD_RESET(RSMRST) | PAD_TRIG(OFF), 0),", }, }, { /* GPP_C23 - GPIO */ - Pad: test.Pad{ID: "GPP_C23", DW0: 0x40880102, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_C23", DW0: 0x40880102, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_SCI(GPP_C23, NONE, DEEP, LEVEL, INVERT),", Long: "_PAD_CFG_STRUCT(GPP_C23, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_IRQ_ROUTE(SCI) | PAD_RX_POL(INVERT) | PAD_BUF(TX_DISABLE) | (1 << 1), 0),", }, }, { /* GPP_D1 - GPIO */ - Pad: test.Pad{ID: "GPP_D1", DW0: 0x04000200, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_D1", DW0: 0x04000200, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPO(GPP_D1, 0, RSMRST),", Long: "_PAD_CFG_STRUCT(GPP_D1, PAD_FUNC(GPIO) | PAD_RESET(RSMRST) | PAD_TRIG(OFF) | PAD_BUF(RX_DISABLE), 0),", }, }, { /* GPP_D16 - GPIO */ - Pad: test.Pad{ID: "GPP_D16", DW0: 0x84000100, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_D16", DW0: 0x84000100, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_TRIG_OWN(GPP_D16, NONE, PLTRST, OFF, ACPI),", Long: "_PAD_CFG_STRUCT(GPP_D16, PAD_FUNC(GPIO) | PAD_RESET(PLTRST) | PAD_TRIG(OFF) | PAD_BUF(TX_DISABLE), 0),", }, }, { /* GPP_E0 - SATAXPCIE0 */ - Pad: test.Pad{ID: "GPP_E0", DW0: 0x04000502, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_E0", DW0: 0x04000502, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF(GPP_E0, NONE, RSMRST, NF1),", Long: "_PAD_CFG_STRUCT(GPP_E0, PAD_FUNC(NF1) | PAD_RESET(RSMRST) | PAD_TRIG(OFF) | PAD_BUF(TX_DISABLE) | (1 << 1), 0),", }, }, { /* GPP_E7 - GPIO */ - Pad: test.Pad{ID: "GPP_E7", DW0: 0x40840102, DW1: 0x00000000, Ownership: 1}, + Pad: test.Pad{ID: "GPP_E7", DW0: 0x40840102, DW1: 0x00000000, Ownership: macros.Driver}, Macro: test.Macro{ Short: "PAD_CFG_GPI_SMI(GPP_E7, NONE, DEEP, LEVEL, INVERT),", Long: "_PAD_CFG_STRUCT(GPP_E7, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_IRQ_ROUTE(SMI) | PAD_RX_POL(INVERT) | PAD_BUF(TX_DISABLE) | (1 << 1), PAD_CFG_OWN_GPIO(DRIVER)),", }, }, { /* GPP_F2 - GPIO */ - Pad: test.Pad{ID: "GPP_F2", DW0: 0x44000300, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_F2", DW0: 0x44000300, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_NC(GPP_F2, NONE),", Long: "_PAD_CFG_STRUCT(GPP_F2, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | PAD_BUF(TX_RX_DISABLE), 0),", }, }, { /* GPP_F12 - GPIO */ - Pad: test.Pad{ID: "GPP_F12", DW0: 0x80900102, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_F12", DW0: 0x80900102, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_APIC_LOW(GPP_F12, NONE, PLTRST),", Long: "_PAD_CFG_STRUCT(GPP_F12, PAD_FUNC(GPIO) | PAD_RESET(PLTRST) | PAD_IRQ_ROUTE(IOAPIC) | PAD_RX_POL(INVERT) | PAD_BUF(TX_DISABLE) | (1 << 1), 0),", }, }, { /* GPP_F13 - GPIO */ - Pad: test.Pad{ID: "GPP_F13", DW0: 0x80100102, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_F13", DW0: 0x80100102, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_APIC_HIGH(GPP_F13, NONE, PLTRST),", Long: "_PAD_CFG_STRUCT(GPP_F13, PAD_FUNC(GPIO) | PAD_RESET(PLTRST) | PAD_IRQ_ROUTE(IOAPIC) | PAD_BUF(TX_DISABLE) | (1 << 1), 0),", }, }, { /* GPP_H10 - NC */ - Pad: test.Pad{ID: "GPP_H10", DW0: 0x44000300, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_H10", DW0: 0x44000300, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_NC(GPP_H10, NONE),", Long: "_PAD_CFG_STRUCT(GPP_H10, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | PAD_BUF(TX_RX_DISABLE), 0),", }, }, { /* GPP_L1 - CSME_INTR_OUT */ - Pad: test.Pad{ID: "GPP_L1", DW0: 0x44000700, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_L1", DW0: 0x44000700, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF(GPP_L1, NONE, DEEP, NF1),", Long: "_PAD_CFG_STRUCT(GPP_L1, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | PAD_BUF(TX_RX_DISABLE), 0),", }, }, { /* GPP_L19 - TESTCH1_CLK */ - Pad: test.Pad{ID: "GPP_L19", DW0: 0x04000600, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_L19", DW0: 0x04000600, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF(GPP_L19, NONE, RSMRST, NF1),", Long: "_PAD_CFG_STRUCT(GPP_L19, PAD_FUNC(NF1) | PAD_RESET(RSMRST) | PAD_TRIG(OFF) | PAD_BUF(RX_DISABLE), 0),", }, }, - }.Run(t, "INTEL-LEWISBURG-PCH/PAD-MAP", lewisburg) + }.Run(t, "INTEL-LEWISBURG-PCH/PAD-MAP")
test.Suite{ { - Pad: test.Pad{ID: "GPP_Axx", DW0: 0xBFFFFFFF, DW1: 0xFFFFFFFF, Ownership: 1}, + Pad: test.Pad{ID: "GPP_Axx", DW0: 0xBFFFFFFF, DW1: 0xFFFFFFFF, Ownership: macros.Driver}, Macro: test.Macro{ Short: "PAD_CFG_NF_1V8(GPP_Axx, NATIVE, PLTRST, NF7),", Long: "_PAD_CFG_STRUCT(GPP_Axx, PAD_FUNC(NF7) | PAD_RESET(PLTRST) | PAD_TRIG(EDGE_BOTH) | PAD_IRQ_ROUTE(IOAPIC) | PAD_IRQ_ROUTE(SCI) | PAD_IRQ_ROUTE(SMI) | PAD_IRQ_ROUTE(NMI) | PAD_RX_POL(INVERT) | PAD_BUF(TX_RX_DISABLE) | (1 << 29) | (1 << 28) | (1 << 1) | 1, PAD_CFG1_TOL_1V8PAD_PULL(NATIVE) | PAD_IOSSTATE(IGNORE) | PAD_IOSTERM(ENPU) | PAD_CFG_OWN_GPIO(DRIVER)),", }, }, - }.Run(t, "INTEL-LEWISBURG-PCH/MASK", lewisburg) + }.Run(t, "INTEL-LEWISBURG-PCH/MASK")
test.Suite{ { - Pad: test.Pad{ID: "GPP_Bxx", DW0: 0x00000000, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_Bxx", DW0: 0x00000000, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPIO_BIDIRECT(GPP_Bxx, 0, NONE, RSMRST, LEVEL, ACPI),", Long: "_PAD_CFG_STRUCT(GPP_Bxx, PAD_FUNC(GPIO) | PAD_RESET(RSMRST), 0),", }, }, - }.Run(t, "INTEL-LEWISBURG-PCH/EMRTY", lewisburg) + }.Run(t, "INTEL-LEWISBURG-PCH/EMRTY") } diff --git a/util/intelp2m/platforms/snr/macro.go b/util/intelp2m/platforms/snr/macro.go deleted file mode 100644 index f1d05e7..0000000 --- a/util/intelp2m/platforms/snr/macro.go +++ /dev/null @@ -1,265 +0,0 @@ -package snr - -import ( - "fmt" - "strings" - - "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" - "review.coreboot.org/coreboot.git/util/intelp2m/fields" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register/bits" -) - -const ( - PAD_CFG_DW0_RO_FIELDS = (0x1 << 27) | (0x1 << 24) | (0x3 << 21) | (0xf << 16) | 0xfc - PAD_CFG_DW1_RO_FIELDS = 0xfdffc3ff -) - -type PlatformSpecific struct{} - -// RemmapRstSrc - remmap Pad Reset Source Config -func (PlatformSpecific) RemmapRstSrc() { - macro := common.GetMacro() - if strings.Contains(macro.PadIdGet(), "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.... - // remmap is not required because it is the same as common. - return - } - - dw0 := macro.GetRegisterDW0() - remapping := map[uint32]uint32{ - 0: bits.RstCfgRSMRST << bits.DW0PadRstCfg, - 1: bits.RstCfgDEEP << bits.DW0PadRstCfg, - 2: bits.RstCfgPLTRST << bits.DW0PadRstCfg, - } - resetsrc, valid := remapping[dw0.GetResetConfig()] - if valid { - // dw0.SetResetConfig(resetsrc) - ResetConfigFieldVal := (dw0.Value & 0x3fffffff) | remapping[dw0.GetResetConfig()] - dw0.Value = ResetConfigFieldVal - } else { - fmt.Println("Invalid Pad Reset Config [ 0x", resetsrc, " ] for ", macro.PadIdGet()) - } - mask := bits.DW0[bits.DW0PadRstCfg] - dw0.CntrMaskFieldsClear(mask) -} - -// Adds The Pad Termination (TERM) parameter from PAD_CFG_DW1 to the macro -// as a new argument -func (PlatformSpecific) Pull() { - macro := common.GetMacro() - dw1 := macro.GetRegisterDW1() - var pull = map[uint32]string{ - 0x0: "NONE", - 0x2: "DN_5K", - 0x4: "DN_20K", - 0x9: "UP_1K", - 0xa: "UP_5K", - 0xb: "UP_2K", - 0xc: "UP_20K", - 0xd: "UP_667", - 0xf: "NATIVE", - } - str, valid := pull[dw1.GetTermination()] - if !valid { - str = "INVALID" - fmt.Println("Error", - macro.PadIdGet(), - " invalid TERM value = ", - int(dw1.GetTermination())) - } - macro.Separator().Add(str) -} - -// Generate macro to cause peripheral IRQ when configured in GPIO input mode -func ioApicRoute() bool { - macro := common.GetMacro() - dw0 := macro.GetRegisterDW0() - if dw0.GetGPIOInputRouteIOxAPIC() == 0 { - return false - } - - macro.Add("_APIC") - if dw0.GetRXLevelEdgeConfiguration() == bits.TrigLEVEL { - if dw0.GetRxInvert() != 0 { - // PAD_CFG_GPI_APIC_LOW(pad, pull, rst) - macro.Add("_LOW") - } else { - // PAD_CFG_GPI_APIC_HIGH(pad, pull, rst) - macro.Add("_HIGH") - } - macro.Add("(").Id().Pull().Rstsrc().Add("),") - return true - } - - // e.g. PAD_CFG_GPI_APIC_IOS(pad, pull, rst, trig, inv, iosstate, iosterm) - macro.Add("_IOS(").Id().Pull().Rstsrc().Trig().Invert().Add(", TxLASTRxE, SAME),") - return true -} - -// Generate macro to cause NMI when configured in GPIO input mode -func nmiRoute() bool { - macro := common.GetMacro() - if macro.GetRegisterDW0().GetGPIOInputRouteNMI() == 0 { - return false - } - // PAD_CFG_GPI_NMI(GPIO_24, UP_20K, DEEP, LEVEL, INVERT), - macro.Add("_NMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") - return true -} - -// Generate macro to cause SCI when configured in GPIO input mode -func sciRoute() bool { - macro := common.GetMacro() - dw0 := macro.GetRegisterDW0() - if dw0.GetGPIOInputRouteSCI() == 0 { - return false - } - // PAD_CFG_GPI_SCI(GPP_B18, UP_20K, PLTRST, LEVEL, INVERT), - macro.Add("_SCI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") - return true -} - -// Generate macro to cause SMI when configured in GPIO input mode -func smiRoute() bool { - macro := common.GetMacro() - dw0 := macro.GetRegisterDW0() - if dw0.GetGPIOInputRouteSMI() == 0 { - return false - } - // PAD_CFG_GPI_SMI(GPP_E7, NONE, DEEP, LEVEL, NONE), - macro.Add("_SMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") - return true -} - -// Adds PAD_CFG_GPI macro with arguments -func (PlatformSpecific) GpiMacroAdd() { - macro := common.GetMacro() - var ids []string - macro.Set("PAD_CFG_GPI") - for routeid, isRoute := range map[string]func() bool{ - "IOAPIC": ioApicRoute, - "SCI": sciRoute, - "SMI": smiRoute, - "NMI": nmiRoute, - } { - if isRoute() { - ids = append(ids, routeid) - } - } - - switch config, argc := p2m.SettingsGet(), len(ids); argc { - case 0: - // e.g. PAD_CFG_GPI_TRIG_OWN(pad, pull, rst, trig, own) - macro.Add("_TRIG_OWN").Add("(").Id().Pull().Rstsrc().Trig().Own().Add("),") - case 1: - // GPI with IRQ route - if config.IgnoredFields { - // Set Host Software Ownership to ACPI mode - macro.SetPadOwnership(common.PAD_OWN_ACPI) - } - - case 2: - // PAD_CFG_GPI_DUAL_ROUTE(pad, pull, rst, trig, inv, route1, route2) - macro.Set("PAD_CFG_GPI_DUAL_ROUTE(").Id().Pull().Rstsrc().Trig().Invert() - macro.Add(", " + ids[0] + ", " + ids[1] + "),") - if config.IgnoredFields { - // Set Host Software Ownership to ACPI mode - macro.SetPadOwnership(common.PAD_OWN_ACPI) - } - default: - // Clear the control mask so that the check fails and "Advanced" macro is - // generated - macro.GetRegisterDW0().CntrMaskFieldsClear(bits.All32) - } -} - -// Adds PAD_CFG_GPO macro with arguments -func (PlatformSpecific) GpoMacroAdd() { - macro := common.GetMacro() - dw0 := macro.GetRegisterDW0() - term := macro.GetRegisterDW1().GetTermination() - - // #define PAD_CFG_GPO(pad, val, rst) \ - // _PAD_CFG_STRUCT(pad, \ - // PAD_FUNC(GPIO) | PAD_RESET(rst) | \ - // PAD_TRIG(OFF) | PAD_BUF(RX_DISABLE) | !!val, \ - // PAD_PULL(NONE) | PAD_IOSSTATE(TxLASTRxE)) - if dw0.GetRXLevelEdgeConfiguration() != bits.TrigOFF { - mask := bits.DW0[bits.DW0RxLevelEdgeConfiguration] - dw0.CntrMaskFieldsClear(mask) - } - macro.Set("PAD_CFG") - if macro.IsOwnershipDriver() { - // PAD_CFG_GPO_GPIO_DRIVER(pad, val, rst, pull) - macro.Add("_GPO_GPIO_DRIVER").Add("(").Id().Val().Rstsrc().Pull().Add("),") - return - } - if term != 0 { - // e.g. PAD_CFG_TERM_GPO(GPP_B23, 1, DN_20K, DEEP), - macro.Add("_TERM") - } - macro.Add("_GPO").Add("(").Id().Val() - if term != 0 { - macro.Pull() - } - macro.Rstsrc().Add("),") -} - -// Adds PAD_CFG_NF macro with arguments -func (PlatformSpecific) NativeFunctionMacroAdd() { - macro := common.GetMacro() - // e.g. PAD_CFG_NF(GPP_D23, NONE, DEEP, NF1) - macro.Set("PAD_CFG_NF") - if macro.GetRegisterDW1().GetPadTol() != 0 { - macro.Add("_1V8") - } - macro.Add("(").Id().Pull().Rstsrc().Padfn().Add("),") -} - -// Adds PAD_NC macro -func (PlatformSpecific) NoConnMacroAdd() { - macro := common.GetMacro() - // #define PAD_NC(pad, pull) - // _PAD_CFG_STRUCT(pad, - // PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | PAD_BUF(TX_RX_DISABLE), - // PAD_PULL(pull) | PAD_IOSSTATE(TxDRxE)), - dw0 := macro.GetRegisterDW0() - - // Some fields of the configuration registers are hidden inside the macros, - // we should check them to update the corresponding bits in the control mask. - if dw0.GetRXLevelEdgeConfiguration() != bits.TrigOFF { - mask := bits.DW0[bits.DW0RxLevelEdgeConfiguration] - dw0.CntrMaskFieldsClear(mask) - } - if dw0.GetResetConfig() != 1 { // 1 = RST_DEEP - mask := bits.DW0[bits.DW0PadRstCfg] - dw0.CntrMaskFieldsClear(mask) - } - - macro.Set("PAD_NC").Add("(").Id().Pull().Add("),") -} - -// GenMacro - generate pad macro -// dw0Val : DW0 config register value -// dw1Val : DW1 config register value -// return: string of macro -// error -func (PlatformSpecific) GenMacro(id string, dw0Val uint32, dw1Val uint32, ownership uint8) string { - macro := common.GetInstanceMacro(PlatformSpecific{}, fields.InterfaceGet()) - macro.Clear() - dw0 := macro.GetRegisterDW0() - dw0.CntrMaskFieldsClear(bits.All32) - - dw1 := macro.GetRegisterDW1() - dw1.CntrMaskFieldsClear(bits.All32) - - dw0.Value = dw0Val - dw1.Value = dw1Val - - dw0.ReadOnly = PAD_CFG_DW0_RO_FIELDS - dw1.ReadOnly = PAD_CFG_DW1_RO_FIELDS - macro.PadIdSet(id).SetPadOwnership(ownership) - return macro.Generate() -} diff --git a/util/intelp2m/platforms/snr/template.go b/util/intelp2m/platforms/snr/template.go deleted file mode 100644 index 4d02743..0000000 --- a/util/intelp2m/platforms/snr/template.go +++ /dev/null @@ -1,15 +0,0 @@ -package snr - -import "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" - -// Group: "GPP_A", "GPP_B", "GPP_F", "GPP_C", "GPP_D", "GPP_E", "GPD", "GPP_I", "GPP_J", -// "GPP_K", "GPP_G", "GPP_H", "GPP_L" - -// KeywordCheck - This function is used to filter parsed lines of the configuration file and -// returns true if the keyword is contained in the line. -// line : string from the configuration file -// Returns false if no word was found, or true otherwise -func (PlatformSpecific) KeywordCheck(line string) bool { - included, _ := common.KeywordsCheck(line, "GPP_", "GPD") - return included -} diff --git a/util/intelp2m/platforms/sunrise/sunrise.go b/util/intelp2m/platforms/sunrise/sunrise.go new file mode 100644 index 0000000..d33f65d --- /dev/null +++ b/util/intelp2m/platforms/sunrise/sunrise.go @@ -0,0 +1,282 @@ +package sunrise + +import ( + "strings" + + "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" + "review.coreboot.org/coreboot.git/util/intelp2m/fields" + "review.coreboot.org/coreboot.git/util/intelp2m/logs" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/macros" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register/bits" +) + +const ( + DW0Mask uint32 = (0b1 << 27) | (0b1 << 24) | (0b11 << 21) | (0b1111 << 16) | 0b11111100 + DW1Mask uint32 = 0xfdffc3ff +) + +type BasePlatform struct { + dw0 register.DW0 + dw1 register.DW1 + macro *macros.Macro +} + +func InitBasePlatform(id string, owner bool, dw0 register.DW0, dw1 register.DW1) BasePlatform { + platforms := BasePlatform{dw0: dw0, dw1: dw1} + platforms.macro = macros.Update(id, owner, &platforms, fields.InterfaceGet()) + return platforms +} + +func (p *BasePlatform) GetRegisterDW0() *register.DW0 { + return &p.dw0 +} + +func (p *BasePlatform) GetRegisterDW1() *register.DW1 { + return &p.dw1 +} + +func (p *BasePlatform) GetMacro() *macros.Macro { + return p.macro +} + +// RemmapRstSrc() remaps Pad Reset Source Config +func (p *BasePlatform) RemapRstSrc() { + if strings.Contains(p.macro.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.... + // 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 source, valid := remapping[dw0.GetResetConfig()]; valid { + dw0.Value &= 0x3fffffff + dw0.Value |= source + } else { + macro := p.GetMacro() + logs.Errorf("%s: skip re-mapping: DW0 %s: invalid reset config source value 0b%b", + macro.GetPadId(), dw0, dw0.GetResetConfig()) + } + dw0.CntrMaskFieldsClear(bits.DW0[bits.DW0PadRstCfg]) +} + +// Pull() adds The Pad Termination (TERM) parameter from PAD_CFG_DW1 to the macro +func (p *BasePlatform) Pull() { + dw1 := p.GetRegisterDW1() + var pull = map[uint32]string{ + 0x0: "NONE", + 0x2: "DN_5K", + 0x4: "DN_20K", + 0x9: "UP_1K", + 0xa: "UP_5K", + 0xb: "UP_2K", + 0xc: "UP_20K", + 0xd: "UP_667", + 0xf: "NATIVE", + } + term, valid := pull[dw1.GetTermination()] + macro := p.GetMacro() + if !valid { + term = "INVALID" + logs.Errorf("%s: DW1 %s: invalid termination value 0b%b", + dw1, macro.GetPadId(), dw1.GetTermination()) + } + macro.Separator().Add(term) +} + +// ioApicRoute() generate macro to cause peripheral IRQ when configured in GPIO input mode +func ioApicRoute(p *BasePlatform) bool { + dw0 := p.GetRegisterDW0() + if dw0.GetGPIOInputRouteIOxAPIC() == 0 { + return false + } + + macro := p.GetMacro() + macro.Add("_APIC") + if dw0.GetRXLevelEdgeConfiguration() == bits.TrigLEVEL { + if dw0.GetRxInvert() != 0 { + // PAD_CFG_GPI_APIC_LOW(pad, pull, rst) + p.macro.Add("_LOW") + } else { + // PAD_CFG_GPI_APIC_HIGH(pad, pull, rst) + p.macro.Add("_HIGH") + } + p.macro.Add("(").Id().Pull().Rstsrc().Add("),") + return true + } + + // e.g. PAD_CFG_GPI_APIC_IOS(pad, pull, rst, trig, inv, iosstate, iosterm) + macro.Add("_IOS(").Id().Pull().Rstsrc().Trig().Invert().Add(", TxLASTRxE, SAME),") + return true +} + +// nmiRoute() generate macro to cause NMI when configured in GPIO input mode +func nmiRoute(p *BasePlatform) bool { + if p.GetRegisterDW0().GetGPIOInputRouteNMI() == 0 { + return false + } + macro := p.GetMacro() + // PAD_CFG_GPI_NMI(GPIO_24, UP_20K, DEEP, LEVEL, INVERT), + macro.Add("_NMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") + return true +} + +// sciRoute() generate macro to cause SCI when configured in GPIO input mode +func sciRoute(p *BasePlatform) bool { + dw0 := p.GetRegisterDW0() + if dw0.GetGPIOInputRouteSCI() == 0 { + return false + } + macro := p.GetMacro() + // PAD_CFG_GPI_SCI(GPP_B18, UP_20K, PLTRST, LEVEL, INVERT), + macro.Add("_SCI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") + return true +} + +// smiRoute() generates macro to cause SMI when configured in GPIO input mode +func smiRoute(p *BasePlatform) bool { + dw0 := p.GetRegisterDW0() + if dw0.GetGPIOInputRouteSMI() == 0 { + return false + } + macro := p.GetMacro() + // PAD_CFG_GPI_SMI(GPP_E7, NONE, DEEP, LEVEL, NONE), + macro.Add("_SMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") + return true +} + +// AddGpiMacro() adds PAD_CFG_GPI macro with arguments +func (p *BasePlatform) AddGpiMacro() { + var ids []string + macro := p.GetMacro() + macro.Set("PAD_CFG_GPI") + for routeid, isRoute := range map[string]func(p *BasePlatform) bool{ + "IOAPIC": ioApicRoute, + "SCI": sciRoute, + "SMI": smiRoute, + "NMI": nmiRoute, + } { + if isRoute(p) { + ids = append(ids, routeid) + } + } + + switch config, argc := p2m.SettingsGet(), len(ids); argc { + case 0: + // e.g. PAD_CFG_GPI_TRIG_OWN(pad, pull, rst, trig, own) + macro.Add("_TRIG_OWN").Add("(").Id().Pull().Rstsrc().Trig().Own().Add("),") + case 1: + // GPI with IRQ route + if config.IgnoredFields { + // Set Host Software Ownership to ACPI mode + macro.SetOwnershipAcpi() + } + + case 2: + // PAD_CFG_GPI_DUAL_ROUTE(pad, pull, rst, trig, inv, route1, route2) + macro.Set("PAD_CFG_GPI_DUAL_ROUTE(").Id().Pull().Rstsrc().Trig().Invert() + macro.Add(", " + ids[0] + ", " + ids[1] + "),") + if config.IgnoredFields { + // Set Host Software Ownership to ACPI mode + macro.SetOwnershipAcpi() + } + default: + // Clear the control mask so that the check fails and "Advanced" macro is + // generated + dw0 := p.GetRegisterDW0() + dw0.CntrMaskFieldsClear(bits.All32) + } +} + +// AddGpoMacro() adds PAD_CFG_GPO macro with arguments +func (p *BasePlatform) AddGpoMacro() { + macro := p.GetMacro() + // #define PAD_CFG_GPO(pad, val, rst) \ + // _PAD_CFG_STRUCT(pad, \ + // PAD_FUNC(GPIO) | PAD_RESET(rst) | \ + // PAD_TRIG(OFF) | PAD_BUF(RX_DISABLE) | !!val, \ + // PAD_PULL(NONE) | PAD_IOSSTATE(TxLASTRxE)) + if dw0 := p.GetRegisterDW0(); dw0.GetRXLevelEdgeConfiguration() != bits.TrigOFF { + mask := bits.DW0[bits.DW0RxLevelEdgeConfiguration] + dw0.CntrMaskFieldsClear(mask) + } + macro.Set("PAD_CFG") + if macro.IsOwnershipDriver() { + // PAD_CFG_GPO_GPIO_DRIVER(pad, val, rst, pull) + macro.Add("_GPO_GPIO_DRIVER").Add("(").Id().Val().Rstsrc().Pull().Add("),") + return + } + dw1 := p.GetRegisterDW1() + term := dw1.GetTermination() + if term != 0 { + // e.g. PAD_CFG_TERM_GPO(GPP_B23, 1, DN_20K, DEEP), + macro.Add("_TERM") + } + macro.Add("_GPO").Add("(").Id().Val() + if term != 0 { + macro.Pull() + } + macro.Rstsrc().Add("),") +} + +// AddNativeFunctionMacro() adds PAD_CFG_NF macro with arguments +func (p *BasePlatform) AddNativeFunctionMacro() { + // e.g. PAD_CFG_NF(GPP_D23, NONE, DEEP, NF1) + macro := p.GetMacro() + macro.Set("PAD_CFG_NF") + if p.GetRegisterDW1().GetPadTol() != 0 { + macro.Add("_1V8") + } + macro.Add("(").Id().Pull().Rstsrc().Padfn().Add("),") +} + +// AddNoConnMacro() adds PAD_NC macro +func (p *BasePlatform) AddNoConnMacro() { + // #define PAD_NC(pad, pull) + // _PAD_CFG_STRUCT(pad, + // PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | PAD_BUF(TX_RX_DISABLE), + // PAD_PULL(pull) | PAD_IOSSTATE(TxDRxE)), + dw0 := p.GetRegisterDW0() + + // Some fields of the configuration registers are hidden inside the macros, + // we should check them to update the corresponding bits in the control mask. + if dw0.GetRXLevelEdgeConfiguration() != bits.TrigOFF { + mask := bits.DW0[bits.DW0RxLevelEdgeConfiguration] + dw0.CntrMaskFieldsClear(mask) + } + if dw0.GetResetConfig() != 1 { // 1 = RST_DEEP + mask := bits.DW0[bits.DW0PadRstCfg] + dw0.CntrMaskFieldsClear(mask) + } + macro := p.GetMacro() + macro.Set("PAD_NC").Add("(").Id().Pull().Add("),") +} + +// GenerateMacro() generates pad macro +func GenerateMacro(id string, dw0 uint32, dw1 uint32, owner bool) string { + platrorm := InitBasePlatform( + id, + owner, + register.ValDW0(dw0, DW0Mask), + register.ValDW1(dw1, DW1Mask), + ) + macro := platrorm.GetMacro() + return macro.Generate() +} + +// CheckKeyword() parses lines of the configuration file and returns true if the keyword is +// contained in the line +// "GPP_A", "GPP_B", "GPP_F", "GPP_C", "GPP_D", "GPP_E", "GPD", "GPP_I", "GPP_J", +// "GPP_K", "GPP_G", "GPP_H", "GPP_L" +func CheckKeyword(line string) bool { + included, _ := common.KeywordsCheck(line, "GPP_", "GPD") + return included +} diff --git a/util/intelp2m/platforms/snr/snr_test.go b/util/intelp2m/platforms/sunrise/sunrise_test.go similarity index 88% rename from util/intelp2m/platforms/snr/snr_test.go rename to util/intelp2m/platforms/sunrise/sunrise_test.go index 8a52396..7eafd9d 100644 --- a/util/intelp2m/platforms/snr/snr_test.go +++ b/util/intelp2m/platforms/sunrise/sunrise_test.go @@ -1,209 +1,212 @@ -package snr_test +package sunrise_test
import ( "testing"
- "review.coreboot.org/coreboot.git/util/intelp2m/platforms/snr" + "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/macros" "review.coreboot.org/coreboot.git/util/intelp2m/platforms/test" )
func TestGenMacro(t *testing.T) { - sunrise := snr.PlatformSpecific{} + config := p2m.SettingsGet() + config.Platform = p2m.Sunrise + p2m.SettingsUpdate(config) test.Suite{ { /* GPP_A1 - LAD0 */ - Pad: test.Pad{ID: "GPP_A1", DW0: 0x84000402, DW1: 0x00003000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_A1", DW0: 0x84000402, DW1: 0x00003000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF(GPP_A1, UP_20K, PLTRST, NF1),", Long: "_PAD_CFG_STRUCT(GPP_A1, PAD_FUNC(NF1) | PAD_RESET(PLTRST) | PAD_TRIG(OFF) | (1 << 1), PAD_PULL(UP_20K)),", }, }, { /* GPP_A5 - LFRAME# */ - Pad: test.Pad{ID: "GPP_A5", DW0: 0x84000600, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_A5", DW0: 0x84000600, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF(GPP_A5, NONE, PLTRST, NF1),", Long: "_PAD_CFG_STRUCT(GPP_A5, PAD_FUNC(NF1) | PAD_RESET(PLTRST) | PAD_TRIG(OFF) | PAD_BUF(RX_DISABLE), 0),", }, }, { /* GPP_A22 - GPIO */ - Pad: test.Pad{ID: "GPP_A22", DW0: 0x84000102, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_A22", DW0: 0x84000102, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_TRIG_OWN(GPP_A22, NONE, PLTRST, OFF, ACPI),", Long: "_PAD_CFG_STRUCT(GPP_A22, PAD_FUNC(GPIO) | PAD_RESET(PLTRST) | PAD_TRIG(OFF) | PAD_BUF(TX_DISABLE) | (1 << 1), 0),", }, }, { /* GPP_B3 - GPIO */ - Pad: test.Pad{ID: "GPP_B3", DW0: 0x44000201, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_B3", DW0: 0x44000201, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPO(GPP_B3, 1, DEEP),", Long: "_PAD_CFG_STRUCT(GPP_B3, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | PAD_BUF(RX_DISABLE) | 1, 0),", }, }, { /* GPP_B5 - GPIO */ - Pad: test.Pad{ID: "GPP_B5", DW0: 0x84000100, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_B5", DW0: 0x84000100, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_TRIG_OWN(GPP_B5, NONE, PLTRST, OFF, ACPI),", Long: "_PAD_CFG_STRUCT(GPP_B5, PAD_FUNC(GPIO) | PAD_RESET(PLTRST) | PAD_TRIG(OFF) | PAD_BUF(TX_DISABLE), 0),", }, }, { /* GPP_B8 - NC */ - Pad: test.Pad{ID: "GPP_B8", DW0: 0x44000300, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_B8", DW0: 0x44000300, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_NC(GPP_B8, NONE),", Long: "_PAD_CFG_STRUCT(GPP_B8, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | PAD_BUF(TX_RX_DISABLE), 0),", }, }, { /* GPP_C2 - GPIO */ - Pad: test.Pad{ID: "GPP_C2", DW0: 0x44000201, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_C2", DW0: 0x44000201, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPO(GPP_C2, 1, DEEP),", Long: "_PAD_CFG_STRUCT(GPP_C2, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | PAD_BUF(RX_DISABLE) | 1, 0),", }, }, { /* GPP_C10 - GPIO */ - Pad: test.Pad{ID: "GPP_C10", DW0: 0x04000000, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_C10", DW0: 0x04000000, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPIO_BIDIRECT(GPP_C10, 0, NONE, RSMRST, OFF, ACPI),", Long: "_PAD_CFG_STRUCT(GPP_C10, PAD_FUNC(GPIO) | PAD_RESET(RSMRST) | PAD_TRIG(OFF), 0),", }, }, { /* GPP_C22 - UART2_RTS# */ - Pad: test.Pad{ID: "GPP_C22", DW0: 0x84000600, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_C22", DW0: 0x84000600, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF(GPP_C22, NONE, PLTRST, NF1),", Long: "_PAD_CFG_STRUCT(GPP_C22, PAD_FUNC(NF1) | PAD_RESET(PLTRST) | PAD_TRIG(OFF) | PAD_BUF(RX_DISABLE), 0),", }, }, { /* GPP_C23 - GPIO */ - Pad: test.Pad{ID: "GPP_C23", DW0: 0x40880102, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_C23", DW0: 0x40880102, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_SCI(GPP_C23, NONE, DEEP, LEVEL, INVERT),", Long: "_PAD_CFG_STRUCT(GPP_C23, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_IRQ_ROUTE(SCI) | PAD_RX_POL(INVERT) | PAD_BUF(TX_DISABLE) | (1 << 1), 0),", }, }, { /* GPP_D0 - GPIO */ - Pad: test.Pad{ID: "GPP_D0", DW0: 0x84000200, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_D0", DW0: 0x84000200, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPO(GPP_D0, 0, PLTRST),", Long: "_PAD_CFG_STRUCT(GPP_D0, PAD_FUNC(GPIO) | PAD_RESET(PLTRST) | PAD_TRIG(OFF) | PAD_BUF(RX_DISABLE), 0),", }, }, { /* GPP_D16 - GPIO */ - Pad: test.Pad{ID: "GPP_D16", DW0: 0x84000100, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_D16", DW0: 0x84000100, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_TRIG_OWN(GPP_D16, NONE, PLTRST, OFF, ACPI),", Long: "_PAD_CFG_STRUCT(GPP_D16, PAD_FUNC(GPIO) | PAD_RESET(PLTRST) | PAD_TRIG(OFF) | PAD_BUF(TX_DISABLE), 0),", }, }, { /* GPP_E0 - SATAXPCIE0 */ - Pad: test.Pad{ID: "GPP_E0", DW0: 0x84000502, DW1: 0x00003000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_E0", DW0: 0x84000502, DW1: 0x00003000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF(GPP_E0, UP_20K, PLTRST, NF1),", Long: "_PAD_CFG_STRUCT(GPP_E0, PAD_FUNC(NF1) | PAD_RESET(PLTRST) | PAD_TRIG(OFF) | PAD_BUF(TX_DISABLE) | (1 << 1), PAD_PULL(UP_20K)),", }, }, { /* GPP_E7 - GPIO */ - Pad: test.Pad{ID: "GPP_E7", DW0: 0x84000102, DW1: 0x00000000, Ownership: 1}, + Pad: test.Pad{ID: "GPP_E7", DW0: 0x84000102, DW1: 0x00000000, Ownership: macros.Driver}, Macro: test.Macro{ Short: "PAD_CFG_GPI_TRIG_OWN(GPP_E7, NONE, PLTRST, OFF, DRIVER),", Long: "_PAD_CFG_STRUCT(GPP_E7, PAD_FUNC(GPIO) | PAD_RESET(PLTRST) | PAD_TRIG(OFF) | PAD_BUF(TX_DISABLE) | (1 << 1), PAD_CFG_OWN_GPIO(DRIVER)),", }, }, { /* GPP_F2 - GPIO */ - Pad: test.Pad{ID: "GPP_F2", DW0: 0x44000300, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_F2", DW0: 0x44000300, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_NC(GPP_F2, NONE),", Long: "_PAD_CFG_STRUCT(GPP_F2, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | PAD_BUF(TX_RX_DISABLE), 0),", }, }, { /* GPP_F12 - GPIO */ - Pad: test.Pad{ID: "GPP_F12", DW0: 0x80900102, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_F12", DW0: 0x80900102, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_APIC_LOW(GPP_F12, NONE, PLTRST),", Long: "_PAD_CFG_STRUCT(GPP_F12, PAD_FUNC(GPIO) | PAD_RESET(PLTRST) | PAD_IRQ_ROUTE(IOAPIC) | PAD_RX_POL(INVERT) | PAD_BUF(TX_DISABLE) | (1 << 1), 0),", }, }, { /* GPP_F13 - GPIO */ - Pad: test.Pad{ID: "GPP_F13", DW0: 0x80100102, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_F13", DW0: 0x80100102, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_APIC_HIGH(GPP_F13, NONE, PLTRST),", Long: "_PAD_CFG_STRUCT(GPP_F13, PAD_FUNC(GPIO) | PAD_RESET(PLTRST) | PAD_IRQ_ROUTE(IOAPIC) | PAD_BUF(TX_DISABLE) | (1 << 1), 0),", }, }, { /* GPP_F14 - GPIO */ - Pad: test.Pad{ID: "GPP_F14", DW0: 0x40900102, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_F14", DW0: 0x40900102, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_APIC_LOW(GPP_F14, NONE, DEEP),", Long: "_PAD_CFG_STRUCT(GPP_F14, PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_IRQ_ROUTE(IOAPIC) | PAD_RX_POL(INVERT) | PAD_BUF(TX_DISABLE) | (1 << 1), 0),", }, }, { /* GPP_H13 - GPIO */ - Pad: test.Pad{ID: "GPP_H13", DW0: 0x80100102, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_H13", DW0: 0x80100102, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_APIC_HIGH(GPP_H13, NONE, PLTRST),", Long: "_PAD_CFG_STRUCT(GPP_H13, PAD_FUNC(GPIO) | PAD_RESET(PLTRST) | PAD_IRQ_ROUTE(IOAPIC) | PAD_BUF(TX_DISABLE) | (1 << 1), 0),", }, }, { /* GPD1 - GPIO */ - Pad: test.Pad{ID: "GPD1", DW0: 0x04000200, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPD1", DW0: 0x04000200, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPO(GPD1, 0, PWROK),", Long: "_PAD_CFG_STRUCT(GPD1, PAD_FUNC(GPIO) | PAD_TRIG(OFF) | PAD_BUF(RX_DISABLE), 0),", }, }, { /* GPD2 - LAN_WAKE# */ - Pad: test.Pad{ID: "GPD2", DW0: 0x00080602, DW1: 0x00003c00, Ownership: 0}, + Pad: test.Pad{ID: "GPD2", DW0: 0x00080602, DW1: 0x00003c00, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF(GPD2, NATIVE, PWROK, NF1),", Long: "_PAD_CFG_STRUCT(GPD2, PAD_FUNC(NF1) | PAD_IRQ_ROUTE(SCI) | PAD_BUF(RX_DISABLE) | (1 << 1), PAD_PULL(NATIVE)),", }, }, { /* GPD3 - PWRBTN# */ - Pad: test.Pad{ID: "GPD3", DW0: 0x04000502, DW1: 0x00003000, Ownership: 0}, + Pad: test.Pad{ID: "GPD3", DW0: 0x04000502, DW1: 0x00003000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF(GPD3, UP_20K, PWROK, NF1),", Long: "_PAD_CFG_STRUCT(GPD3, PAD_FUNC(NF1) | PAD_TRIG(OFF) | PAD_BUF(TX_DISABLE) | (1 << 1), PAD_PULL(UP_20K)),", }, }, { /* GPD7 - GPIO */ - Pad: test.Pad{ID: "GPD7", DW0: 0x84000103, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPD7", DW0: 0x84000103, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPI_TRIG_OWN(GPD7, NONE, PLTRST, OFF, ACPI),", Long: "_PAD_CFG_STRUCT(GPD7, PAD_FUNC(GPIO) | PAD_RESET(PLTRST) | PAD_TRIG(OFF) | PAD_BUF(TX_DISABLE) | (1 << 1) | 1, 0),", }, }, { /* GPP_I1 - DDPC_HPD1 */ - Pad: test.Pad{ID: "GPP_I1", DW0: 0x84000502, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_I1", DW0: 0x84000502, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF(GPP_I1, NONE, PLTRST, NF1),", Long: "_PAD_CFG_STRUCT(GPP_I1, PAD_FUNC(NF1) | PAD_RESET(PLTRST) | PAD_TRIG(OFF) | PAD_BUF(TX_DISABLE) | (1 << 1), 0),", }, }, { /* GPP_I8 - DDPC_CTRLDATA */ - Pad: test.Pad{ID: "GPP_I8", DW0: 0x84000500, DW1: 0x00001000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_I8", DW0: 0x84000500, DW1: 0x00001000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_NF(GPP_I8, DN_20K, PLTRST, NF1),", Long: "_PAD_CFG_STRUCT(GPP_I8, PAD_FUNC(NF1) | PAD_RESET(PLTRST) | PAD_TRIG(OFF) | PAD_BUF(TX_DISABLE), PAD_PULL(DN_20K)),", }, }, - }.Run(t, "INTEL-SUNRISE-PCH/PAD-MAP", sunrise) + }.Run(t, "INTEL-SUNRISE-PCH/PAD-MAP")
test.Suite{ { - Pad: test.Pad{ID: "GPP_Axx", DW0: 0xBFFFFFFF, DW1: 0xFFFFFFFF, Ownership: 1}, + Pad: test.Pad{ID: "GPP_Axx", DW0: 0xBFFFFFFF, DW1: 0xFFFFFFFF, Ownership: macros.Driver}, Macro: test.Macro{ Short: "PAD_CFG_NF_1V8(GPP_Axx, NATIVE, PLTRST, NF7),", Long: "_PAD_CFG_STRUCT(GPP_Axx, PAD_FUNC(NF7) | PAD_RESET(PLTRST) | PAD_TRIG(EDGE_BOTH) | PAD_IRQ_ROUTE(IOAPIC) | PAD_IRQ_ROUTE(SCI) | PAD_IRQ_ROUTE(SMI) | PAD_IRQ_ROUTE(NMI) | PAD_RX_POL(INVERT) | PAD_BUF(TX_RX_DISABLE) | (1 << 29) | (1 << 28) | (1 << 1) | 1, PAD_CFG1_TOL_1V8PAD_PULL(NATIVE) | PAD_IOSSTATE(IGNORE) | PAD_IOSTERM(ENPU) | PAD_CFG_OWN_GPIO(DRIVER)),", }, }, - }.Run(t, "INTEL-SUNRISE-PCH/MASK", sunrise) + }.Run(t, "INTEL-SUNRISE-PCH/MASK")
test.Suite{ { - Pad: test.Pad{ID: "GPP_Bxx", DW0: 0x00000000, DW1: 0x00000000, Ownership: 0}, + Pad: test.Pad{ID: "GPP_Bxx", DW0: 0x00000000, DW1: 0x00000000, Ownership: macros.Acpi}, Macro: test.Macro{ Short: "PAD_CFG_GPIO_BIDIRECT(GPP_Bxx, 0, NONE, RSMRST, LEVEL, ACPI),", Long: "_PAD_CFG_STRUCT(GPP_Bxx, PAD_FUNC(GPIO) | PAD_RESET(RSMRST), 0),", }, }, - }.Run(t, "INTEL-SUNRISE-PCH/EMRTY", sunrise) + }.Run(t, "INTEL-SUNRISE-PCH/EMRTY") } diff --git a/util/intelp2m/platforms/test/suite.go b/util/intelp2m/platforms/test/suite.go index 314315c..ee7a887 100644 --- a/util/intelp2m/platforms/test/suite.go +++ b/util/intelp2m/platforms/test/suite.go @@ -5,6 +5,7 @@ "testing"
"review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" + "review.coreboot.org/coreboot.git/util/intelp2m/platforms" )
type ( @@ -12,7 +13,7 @@ ID string DW0 uint32 DW1 uint32 - Ownership uint8 + Ownership bool } Macro struct { Short string @@ -22,38 +23,37 @@ Pad Macro } - PlatformSpecificIf interface { - GenMacro(string, uint32, uint32, uint8) string - } Suite []TestCase )
-func (p Pad) toShortMacro(platform PlatformSpecificIf) string { +func (p Pad) toShortMacro() string { config := p2m.SettingsGet() if err := config.SetFieldType("none"); err != nil { panic(err) } config.AutoCheck = false p2m.SettingsUpdate(config) - return platform.GenMacro(p.ID, p.DW0, p.DW1, p.Ownership) + do := platforms.GetMacroAction() + return do(p.ID, p.DW0, p.DW1, p.Ownership) }
-func (p Pad) toLongMacro(platform PlatformSpecificIf) string { +func (p Pad) toLongMacro() string { config := p2m.SettingsGet() if err := config.SetFieldType("cb"); err != nil { panic(err) } config.AutoCheck = true p2m.SettingsUpdate(config) - return platform.GenMacro(p.ID, p.DW0, p.DW1, p.Ownership) + do := platforms.GetMacroAction() + return do(p.ID, p.DW0, p.DW1, p.Ownership) }
-func (m *Macro) checkFor(platform PlatformSpecificIf, pad Pad) error { +func (m *Macro) check(pad Pad) error { var format string = "%s macro\nExpects: '%s'\nActually: '%s'\n\n" var err error - if actually := pad.toLongMacro(platform); m.Long != "" && m.Long != actually { + if actually := pad.toLongMacro(); m.Long != "" && m.Long != actually { err = fmt.Errorf(format, "LONG", m.Long, actually) - } else if actually := pad.toShortMacro(platform); m.Short != "" && m.Short != actually { + } else if actually := pad.toShortMacro(); m.Short != "" && m.Short != actually { err = fmt.Errorf(format, "SHORT", m.Short, actually) } else { return nil @@ -61,10 +61,10 @@ return err }
-func (suite Suite) Run(t *testing.T, label string, platform PlatformSpecificIf) { +func (suite Suite) Run(t *testing.T, label string) { t.Run(label, func(t *testing.T) { for _, testcase := range suite { - if err := testcase.Macro.checkFor(platform, testcase.Pad); err != nil { + if err := testcase.Macro.check(testcase.Pad); err != nil { t.Errorf("Test failed for pad %s\n%v", testcase.Pad.ID, err) } }