Maxim Polyakov has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/70308 )
Change subject: intelp2m: Rework configuration package ......................................................................
intelp2m: Rework configuration package
- Reduce the number of methods for updating settings and redefine types to make the code cleaner and more readable. - Move the configuration to the p2m package to add settings from new utilities based on the intelp2m code. - Make some code style fixes.
Change-Id: Ia1b19ae3122bcf6ec740ae4683d62f31570670b1 Signed-off-by: Maxim Polyakov max.senia.poliak@gmail.com --- D util/intelp2m/config/config.go A util/intelp2m/config/p2m/config.go M util/intelp2m/fields/cb/cb.go M util/intelp2m/fields/fields.go M util/intelp2m/main.go M util/intelp2m/parser/parser.go M util/intelp2m/parser/parser_test.go M util/intelp2m/platforms/apl/macro.go M util/intelp2m/platforms/cnl/macro.go M util/intelp2m/platforms/common/macro.go M util/intelp2m/platforms/snr/macro.go M util/intelp2m/platforms/test/suite.go 12 files changed, 315 insertions(+), 328 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/70308/1
diff --git a/util/intelp2m/config/config.go b/util/intelp2m/config/config.go deleted file mode 100644 index 0444ddf..0000000 --- a/util/intelp2m/config/config.go +++ /dev/null @@ -1,117 +0,0 @@ -package config - -import "os" - -const ( - SunriseType uint8 = 0 - LewisburgType uint8 = 1 - ApolloType uint8 = 2 - CannonType uint8 = 3 - AlderType uint8 = 4 -) - -var key uint8 = SunriseType - -var platform = map[string]uint8{ - "snr": SunriseType, - "lbg": LewisburgType, - "apl": ApolloType, - "cnl": CannonType, - "adl": AlderType} - -func PlatformSet(name string) int { - if platformType, valid := platform[name]; valid { - key = platformType - return 0 - } - return -1 -} -func PlatformGet() uint8 { - return key -} -func IsPlatform(platformType uint8) bool { - return platformType == key -} -func IsPlatformApollo() bool { - return IsPlatform(ApolloType) -} -func IsPlatformSunrise() bool { - return IsPlatform(SunriseType) -} -func IsPlatformLewisburg() bool { - return IsPlatform(LewisburgType) -} -func IsPlatformCannonLake() bool { - return IsPlatform(CannonType) -} -func IsPlatformAlderLakeH() bool { - return IsPlatform(AlderType) -} - -var InputRegDumpFile *os.File = nil -var OutputGenFile *os.File = nil - -var ignoredFieldsFormat bool = false - -func IgnoredFieldsFlagSet(flag bool) { - ignoredFieldsFormat = flag -} -func AreFieldsIgnored() bool { - return ignoredFieldsFormat -} - -var nonCheckingFlag bool = false - -func NonCheckingFlagSet(flag bool) { - nonCheckingFlag = flag -} -func IsNonCheckingFlagUsed() bool { - return nonCheckingFlag -} - -var infolevel int = 0 - -func InfoLevelSet(lvl int) { - infolevel = lvl -} -func InfoLevelGet() int { - return infolevel -} - -var fldstyle uint8 = CbFlds - -const ( - NoFlds uint8 = 0 - CbFlds uint8 = 1 // coreboot style - FspFlds uint8 = 2 // FSP/edk2 style - RawFlds uint8 = 3 // raw DW0/1 values -) - -var fldstylemap = map[string]uint8{ - "none": NoFlds, - "cb": CbFlds, - "fsp": FspFlds, - "raw": RawFlds} - -func FldStyleSet(name string) int { - if style, valid := fldstylemap[name]; valid { - fldstyle = style - return 0 - } - return -1 -} -func FldStyleGet() uint8 { - return fldstyle -} -func IsFieldsMacroUsed() bool { - return FldStyleGet() != NoFlds -} -func IsCbStyleMacro() bool { - return FldStyleGet() == CbFlds -} -func IsFspStyleMacro() bool { - return FldStyleGet() == FspFlds -} -func IsRawFields() bool { - return FldStyleGet() == RawFlds -} diff --git a/util/intelp2m/config/p2m/config.go b/util/intelp2m/config/p2m/config.go new file mode 100644 index 0000000..43f8226 --- /dev/null +++ b/util/intelp2m/config/p2m/config.go @@ -0,0 +1,83 @@ +package p2m + +import ( + "fmt" + "os" +) + +type PlatformType int +type FieldType int + +const ( + Sunrise PlatformType = iota + Lewisburg + Apollo + Cannon + Alder +) + +const ( + NoFlds FieldType = iota + CbFlds // coreboot style + FspFlds // FSP/edk2 style + RawFlds // raw DW0/1 values +) + +var platforms = map[string]PlatformType{ + "snr": Sunrise, + "lbg": Lewisburg, + "apl": Apollo, + "cnl": Cannon, + "adl": Alder, +} + +var fields = map[string]FieldType{ + "none": NoFlds, + "cb": CbFlds, + "fsp": FspFlds, + "raw": RawFlds, +} + +type Settings struct { + Version string + Platform PlatformType + Field FieldType + InputFile *os.File + OutputFile *os.File + IgnoredFields bool + AutoCheck bool + GenLevel int +} + +var p2mConfig = Settings{ + Version: "unknown", + Platform: Sunrise, + Field: CbFlds, + IgnoredFields: false, + AutoCheck: true, + GenLevel: 0, +} + +func SettingsUpdate(settings Settings) { + p2mConfig = settings +} + +func SettingsGet() Settings { + return p2mConfig +} + +func (s *Settings) SetPlatformType(format string) error { + if _, exist := platforms[format]; !exist { + return fmt.Errorf("unknown platform type %s", format) + } + s.Platform = platforms[format] + return nil +} + +func (s *Settings) SetFieldType(format string) error { + if _, exist := fields[format]; !exist { + return fmt.Errorf("unknown field type %s", format) + } + s.Field = fields[format] + return nil +} diff --git a/util/intelp2m/fields/cb/cb.go b/util/intelp2m/fields/cb/cb.go index a70b2a6..0c8988eb 100644 --- a/util/intelp2m/fields/cb/cb.go +++ b/util/intelp2m/fields/cb/cb.go @@ -1,11 +1,11 @@ package cb
import ( - "review.coreboot.org/coreboot.git/util/intelp2m/config" + "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" )
-type FieldMacros struct {} +type FieldMacros struct{}
// field - data structure for creating a new bitfield macro object // PAD_FUNC(NF3) @@ -42,7 +42,9 @@ } } } - if allhidden { macro.Add("0") } + if allhidden { + macro.Add("0") + } }
// DecodeDW0 - decode value of DW0 register @@ -50,80 +52,80 @@ macro := common.GetMacro() dw0 := macro.Register(common.PAD_CFG_DW0) generate( - &field { - prefix : "PAD_FUNC", + &field{ + prefix: "PAD_FUNC", // TODO: Find another way to hide PAD_FUNC(GPIO) in the comment with // ignored fields - unhide : config.InfoLevelGet() < 3 || dw0.GetPadMode() != 0, - configurator : func() { macro.Padfn() }, + unhide: p2m.SettingsGet().GenLevel < 3 || dw0.GetPadMode() != 0, + configurator: func() { macro.Padfn() }, },
- &field { - prefix : "PAD_RESET", - unhide : dw0.GetResetConfig() != 0, - configurator : func() { macro.Rstsrc() }, + &field{ + prefix: "PAD_RESET", + unhide: dw0.GetResetConfig() != 0, + configurator: func() { macro.Rstsrc() }, },
- &field { - prefix : "PAD_TRIG", - unhide : dw0.GetRXLevelEdgeConfiguration() != 0, - configurator : func() { macro.Trig() }, + &field{ + prefix: "PAD_TRIG", + unhide: dw0.GetRXLevelEdgeConfiguration() != 0, + configurator: func() { macro.Trig() }, },
- &field { - prefix : "PAD_IRQ_ROUTE", - name : "IOAPIC", - unhide : dw0.GetGPIOInputRouteIOxAPIC() != 0, + &field{ + prefix: "PAD_IRQ_ROUTE", + name: "IOAPIC", + unhide: dw0.GetGPIOInputRouteIOxAPIC() != 0, },
- &field { - prefix : "PAD_IRQ_ROUTE", - name : "SCI", - unhide : dw0.GetGPIOInputRouteSCI() != 0, + &field{ + prefix: "PAD_IRQ_ROUTE", + name: "SCI", + unhide: dw0.GetGPIOInputRouteSCI() != 0, },
- &field { - prefix : "PAD_IRQ_ROUTE", - name : "SMI", - unhide : dw0.GetGPIOInputRouteSMI() != 0, + &field{ + prefix: "PAD_IRQ_ROUTE", + name: "SMI", + unhide: dw0.GetGPIOInputRouteSMI() != 0, },
- &field { - prefix : "PAD_IRQ_ROUTE", - name : "NMI", - unhide : dw0.GetGPIOInputRouteNMI() != 0, + &field{ + prefix: "PAD_IRQ_ROUTE", + name: "NMI", + unhide: dw0.GetGPIOInputRouteNMI() != 0, },
- &field { - prefix : "PAD_RX_POL", - unhide : dw0.GetRxInvert() != 0, - configurator : func() { macro.Invert() }, + &field{ + prefix: "PAD_RX_POL", + unhide: dw0.GetRxInvert() != 0, + configurator: func() { macro.Invert() }, },
- &field { - prefix : "PAD_BUF", - unhide : dw0.GetGPIORxTxDisableStatus() != 0, - configurator : func() { macro.Bufdis() }, + &field{ + prefix: "PAD_BUF", + unhide: dw0.GetGPIORxTxDisableStatus() != 0, + configurator: func() { macro.Bufdis() }, },
- &field { - name : "(1 << 29)", - unhide : dw0.GetRXPadStateSelect() != 0, + &field{ + name: "(1 << 29)", + unhide: dw0.GetRXPadStateSelect() != 0, },
- &field { - name : "(1 << 28)", - unhide : dw0.GetRXRawOverrideStatus() != 0, + &field{ + name: "(1 << 28)", + unhide: dw0.GetRXRawOverrideStatus() != 0, },
- &field { - name : "(1 << 1)", - unhide : dw0.GetGPIORXState() != 0, + &field{ + name: "(1 << 1)", + unhide: dw0.GetGPIORXState() != 0, },
- &field { - name : "1", - unhide : dw0.GetGPIOTXState() != 0, + &field{ + name: "1", + unhide: dw0.GetGPIOTXState() != 0, }, ) } @@ -133,33 +135,33 @@ macro := common.GetMacro() dw1 := macro.Register(common.PAD_CFG_DW1) generate( - &field { - name : "PAD_CFG1_TOL_1V8", - unhide : dw1.GetPadTol() != 0, + &field{ + name: "PAD_CFG1_TOL_1V8", + unhide: dw1.GetPadTol() != 0, },
- &field { - prefix : "PAD_PULL", - unhide : dw1.GetTermination() != 0, - configurator : func() { macro.Pull() }, + &field{ + prefix: "PAD_PULL", + unhide: dw1.GetTermination() != 0, + configurator: func() { macro.Pull() }, },
- &field { - prefix : "PAD_IOSSTATE", - unhide : dw1.GetIOStandbyState() != 0, - configurator : func() { macro.IOSstate() }, + &field{ + prefix: "PAD_IOSSTATE", + unhide: dw1.GetIOStandbyState() != 0, + configurator: func() { macro.IOSstate() }, },
- &field { - prefix : "PAD_IOSTERM", - unhide : dw1.GetIOStandbyTermination() != 0, - configurator : func() { macro.IOTerm() }, + &field{ + prefix: "PAD_IOSTERM", + unhide: dw1.GetIOStandbyTermination() != 0, + configurator: func() { macro.IOTerm() }, },
- &field { - prefix : "PAD_CFG_OWN_GPIO", - unhide : macro.IsOwnershipDriver(), - configurator : func() { macro.Own() }, + &field{ + prefix: "PAD_CFG_OWN_GPIO", + unhide: macro.IsOwnershipDriver(), + configurator: func() { macro.Own() }, }, ) } diff --git a/util/intelp2m/fields/fields.go b/util/intelp2m/fields/fields.go index 4f14c81..bcb6221 100644 --- a/util/intelp2m/fields/fields.go +++ b/util/intelp2m/fields/fields.go @@ -1,21 +1,21 @@ package fields
import ( - "review.coreboot.org/coreboot.git/util/intelp2m/config" - "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" - "review.coreboot.org/coreboot.git/util/intelp2m/fields/fsp" + "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" "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" )
// InterfaceSet - set the interface for decoding configuration // registers DW0 and DW1. func InterfaceGet() common.Fields { - var fldstylemap = map[uint8]common.Fields{ - config.NoFlds : cb.FieldMacros{}, // analyze fields using cb macros - config.CbFlds : cb.FieldMacros{}, - config.FspFlds : fsp.FieldMacros{}, - config.RawFlds : raw.FieldMacros{}, + var fldstylemap = map[p2m.FieldType]common.Fields{ + p2m.NoFlds: cb.FieldMacros{}, // analyze fields using cb macros + p2m.CbFlds: cb.FieldMacros{}, + p2m.FspFlds: fsp.FieldMacros{}, + p2m.RawFlds: raw.FieldMacros{}, } - return fldstylemap[config.FldStyleGet()] + return fldstylemap[p2m.SettingsGet().Field] } diff --git a/util/intelp2m/main.go b/util/intelp2m/main.go index e1a51c8..0b0c9d5 100644 --- a/util/intelp2m/main.go +++ b/util/intelp2m/main.go @@ -4,22 +4,23 @@ "flag" "fmt" "os" + "path/filepath"
- "review.coreboot.org/coreboot.git/util/intelp2m/config" + "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" "review.coreboot.org/coreboot.git/util/intelp2m/parser" )
type Printer struct{}
func (Printer) Linef(lvl int, format string, args ...interface{}) { - if config.InfoLevelGet() >= lvl { - fmt.Fprintf(config.OutputGenFile, format, args...) + if config := p2m.SettingsGet(); config.GenLevel >= lvl { + fmt.Fprintf(config.OutputFile, format, args...) } }
func (Printer) Line(lvl int, str string) { - if config.InfoLevelGet() >= lvl { - fmt.Fprint(config.OutputGenFile, str) + if config := p2m.SettingsGet(); config.GenLevel >= lvl { + fmt.Fprint(config.OutputFile, str) } }
@@ -36,25 +37,22 @@ // main func main() { // Command line arguments - inputFileName := flag.String("file", - "inteltool.log", + inputFilePath := flag.String("file", "inteltool.log", "the path to the inteltool log file\n")
- outputFileName := flag.String("o", + outputFilePath := flag.String("o", "generate/gpio.h", "the path to the generated file with GPIO configuration\n")
- ignFlag := flag.Bool("ign", - false, + ignored := flag.Bool("ign", false, "exclude fields that should be ignored from advanced macros\n")
- nonCheckFlag := flag.Bool("n", - false, + unchecking := flag.Bool("n", false, "Generate macros without checking.\n"+ "\tIn this case, some fields of the configuration registers\n"+ "\tDW0 will be ignored.\n")
- infoLevels := []*bool{ + levels := []*bool{ flag.Bool("i", false, "Show pads function in the comments"), flag.Bool("ii", false, "Show DW0/DW1 value in the comments"), flag.Bool("iii", false, "Show ignored bit fields in the comments"), @@ -68,63 +66,58 @@ "\tcnl - CannonLake-LP or Whiskeylake/Coffeelake/Cometlake-U SoC\n"+ "\tadl - AlderLake PCH\n")
- fieldstyle := flag.String("fld", "none", "set fields macros style:\n"+ + field := flag.String("fld", "none", "set fields macros style:\n"+ "\tcb - use coreboot style for bit fields macros\n"+ "\tfsp - use fsp style\n"+ "\traw - do not convert, print as is\n")
- printVersion() flag.Parse() + printVersion()
- config.IgnoredFieldsFlagSet(*ignFlag) - config.NonCheckingFlagSet(*nonCheckFlag) - - for level, flag := range infoLevels { - if *flag { - config.InfoLevelSet(level + 1) + // settings + config := p2m.SettingsGet() + config.Version = Version + config.IgnoredFields = *ignored + config.AutoCheck = !(*unchecking) + for level, set := range levels { + if *set { + config.GenLevel = level + 1 fmt.Printf("Info level: Use level %d!\n", level+1) break } }
- if valid := config.PlatformSet(*platform); valid != 0 { - fmt.Printf("Error: invalid platform -%s!\n", *platform) + if err := config.SetPlatformType(*platform); err != nil { + fmt.Printf("Error: %v\n", err) os.Exit(1) }
- fmt.Println("Log file:", *inputFileName) - fmt.Println("Output generated file:", *outputFileName) - - inputRegDumpFile, err := os.Open(*inputFileName) - if err != nil { - fmt.Printf("Error: inteltool log file was not found!\n") + if err := config.SetFieldType(*field); err != nil { + fmt.Printf("Error: %v\n", err) os.Exit(1) }
- if config.FldStyleSet(*fieldstyle) != 0 { - fmt.Printf("Error! Unknown bit fields style option -%s!\n", *fieldstyle) + if file, err := os.Open(*inputFilePath); err != nil { + fmt.Printf("input file error: %v", err) + os.Exit(1) + } else { + config.InputFile = file + } + defer config.InputFile.Close() + + if err := os.MkdirAll(filepath.Dir(*outputFilePath), os.ModePerm); err != nil { + fmt.Printf("failed to create output directory: %v", err) os.Exit(1) } - - // create dir for output files - err = os.MkdirAll("generate", os.ModePerm) - if err != nil { - fmt.Printf("Error! Can not create a directory for the generated files!\n") + if file, err := os.Create(*outputFilePath); err != nil { + fmt.Printf("failed to create output file: %v", err) os.Exit(1) + } else { + config.OutputFile = file } + defer config.OutputFile.Close()
- // create empty gpio.h file - outputGenFile, err := os.Create(*outputFileName) - if err != nil { - fmt.Printf("Error: unable to generate GPIO config file!\n") - os.Exit(1) - } - - defer inputRegDumpFile.Close() - defer outputGenFile.Close() - - config.OutputGenFile = outputGenFile - config.InputRegDumpFile = inputRegDumpFile + p2m.SettingsUpdate(config)
prs := parser.ParserData{} prs.Parse() @@ -142,15 +135,16 @@
/* Pad configuration was generated automatically using intelp2m %s */ static const struct pad_config gpio_table[] = {`, Version) - config.OutputGenFile.WriteString(header + "\n") + config.OutputFile.WriteString(header + "\n") // Add the pads map
if err := generator.Run(); err != nil { fmt.Printf("Error: %v", err) os.Exit(1) } - config.OutputGenFile.WriteString(`}; + config.OutputFile.WriteString(`};
#endif /* CFG_GPIO_H */ `) + os.Exit(0) } diff --git a/util/intelp2m/parser/parser.go b/util/intelp2m/parser/parser.go index e411534..8b772b6 100644 --- a/util/intelp2m/parser/parser.go +++ b/util/intelp2m/parser/parser.go @@ -7,7 +7,7 @@ "strconv" "strings"
- "review.coreboot.org/coreboot.git/util/intelp2m/config" + "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" "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" @@ -92,19 +92,19 @@ // PlatformSpecificInterfaceSet - specific interface for the platform selected // in the configuration func (parser *ParserData) PlatformSpecificInterfaceSet() { - var platform = map[uint8]PlatformSpecific{ - config.SunriseType: snr.PlatformSpecific{}, + platform := map[p2m.PlatformType]PlatformSpecific{ + p2m.Sunrise: snr.PlatformSpecific{}, // See platforms/lbg/macro.go - config.LewisburgType: lbg.PlatformSpecific{ + p2m.Lewisburg: lbg.PlatformSpecific{ InheritanceTemplate: snr.PlatformSpecific{}, }, - config.ApolloType: apl.PlatformSpecific{}, - config.CannonType: cnl.PlatformSpecific{ + p2m.Apollo: apl.PlatformSpecific{}, + p2m.Cannon: cnl.PlatformSpecific{ InheritanceTemplate: snr.PlatformSpecific{}, }, - config.AlderType: adl.PlatformSpecific{}, + p2m.Alder: adl.PlatformSpecific{}, } - parser.platform = platform[config.PlatformGet()] + parser.platform = platform[p2m.SettingsGet().Platform] }
// Register - read specific platform registers (32 bits) @@ -148,8 +148,7 @@ // padConfigurationExtract - reads GPIO configuration registers and returns true if the // information from the inteltool log was successfully parsed. func (parser *ParserData) padConfigurationExtract() bool { - // Only for Sunrise or CannonLake, and only for inteltool.log file template - if config.IsPlatformApollo() { + if p2m.SettingsGet().Platform == p2m.Apollo { return false } return parser.padOwnershipExtract() @@ -167,7 +166,8 @@ // map of thepad ownership registers for the GPIO controller parser.ownership = make(map[string]uint32)
- scanner := bufio.NewScanner(config.InputRegDumpFile) + file := p2m.SettingsGet().InputFile + scanner := bufio.NewScanner(file) for scanner.Scan() { parser.line = scanner.Text() isIncluded, _ := common.KeywordsCheck(parser.line, "GPIO Community", "GPIO Group") @@ -218,7 +218,7 @@ g.Linef(2, "\n\t/* %s - %s */\n\t/* DW0: 0x%0.8x, DW1: 0x%0.8x */\n", pad.id, pad.function, pad.dw0, pad.dw1) g.Linef(0, "\t%s", macro) - if config.InfoLevelGet() == 1 { + if p2m.SettingsGet().GenLevel == 1 { g.Linef(1, "\t/* %s */", pad.function) } g.Line(0, "\n") diff --git a/util/intelp2m/parser/parser_test.go b/util/intelp2m/parser/parser_test.go index 4f0e452..9e6f021 100644 --- a/util/intelp2m/parser/parser_test.go +++ b/util/intelp2m/parser/parser_test.go @@ -5,7 +5,7 @@ "os" "testing"
- "review.coreboot.org/coreboot.git/util/intelp2m/config" + "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" "review.coreboot.org/coreboot.git/util/intelp2m/parser" )
@@ -16,19 +16,20 @@ }
func (p *Printer) Linef(lvl int, format string, args ...interface{}) { - if config.InfoLevelGet() >= lvl { + if p2m.SettingsGet().GenLevel >= lvl { p.lines = append(p.lines, fmt.Sprintf(format, args...)) } }
func (p *Printer) Line(lvl int, str string) { - if config.InfoLevelGet() >= lvl { + if p2m.SettingsGet().GenLevel >= lvl { p.lines = append(p.lines, str) } }
func TestParser(t *testing.T) { t.Run("PARSER/PARSE-INTELTOOL-FILE", func(t *testing.T) { + var err error reference := []string{ "\n\t/* ------- GPIO Community 0 ------- */\n", "\n\t/* ------- GPIO Group GPP_A ------- */\n", @@ -62,18 +63,17 @@ "\tPAD_CFG_NF(GPP_I1, NONE, PLTRST, NF1),", "\t/* DDPC_HPD1 */", "\n", "\tPAD_CFG_NF(GPP_I2, NONE, PLTRST, NF1),", "\t/* DDPD_HPD2 */", "\n", } - - input, err := os.Open(testLogFilePath) - if err != nil { + config := p2m.SettingsGet() + if config.InputFile, err = os.Open(testLogFilePath); err != nil { t.Errorf("Something is wrong with the test file - %s!\n", testLogFilePath) os.Exit(1) } - defer input.Close() + defer config.InputFile.Close()
- config.InputRegDumpFile = input - config.FldStyleSet("none") - config.NonCheckingFlagSet(true) - config.InfoLevelSet(1) + config.AutoCheck = false + config.Field = p2m.NoFlds + config.GenLevel = 1 + p2m.SettingsUpdate(config)
prs := parser.ParserData{} prs.Parse() diff --git a/util/intelp2m/platforms/apl/macro.go b/util/intelp2m/platforms/apl/macro.go index 2098c57..6ed1eec 100644 --- a/util/intelp2m/platforms/apl/macro.go +++ b/util/intelp2m/platforms/apl/macro.go @@ -4,9 +4,9 @@ "fmt" "strconv"
- "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" - "review.coreboot.org/coreboot.git/util/intelp2m/config" + "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" )
const ( @@ -21,18 +21,18 @@ )
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 = 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 + 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 {} +type PlatformSpecific struct{}
// RemmapRstSrc - remmap Pad Reset Source Config // remmap is not required because it is the same as common. @@ -52,7 +52,6 @@ PULL_UP_20K: "UP_20K", PULL_UP_667: "UP_667", PULL_NATIVE: "NATIVE", - } terminationFieldValue := dw1.GetTermination() str, valid := pull[terminationFieldValue] @@ -107,7 +106,7 @@ // 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 { + } 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 { @@ -130,7 +129,7 @@ // 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 { + } 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 { @@ -143,10 +142,11 @@
// Generate macro for GPI port func (PlatformSpecific) GpiMacroAdd() { - macro := common.GetMacro() var ids []string + + macro := common.GetMacro() macro.Set("PAD_CFG_GPI") - for routeid, isRoute := range map[string]func() (bool) { + for routeid, isRoute := range map[string]func() bool{ "IOAPIC": ioApicRoute, "SCI": sciRoute, "SMI": smiRoute, @@ -157,7 +157,7 @@ } }
- switch argc := len(ids); argc { + switch config, argc := p2m.SettingsGet(), len(ids); argc { case 0: dw1 := macro.Register(PAD_CFG_DW1) isIOStandbyStateUsed := dw1.GetIOStandbyState() != 0 @@ -176,14 +176,14 @@ } case 1: // GPI with IRQ route - if config.AreFieldsIgnored() { + 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.AreFieldsIgnored() { + if config.IgnoredFields { macro.SetPadOwnership(common.PAD_OWN_ACPI) } default: @@ -193,12 +193,11 @@ } }
- // Adds PAD_CFG_GPO macro with arguments func (PlatformSpecific) GpoMacroAdd() { macro := common.GetMacro() - dw0 := macro.Register(PAD_CFG_DW0) - dw1 := macro.Register(PAD_CFG_DW1) + dw0 := macro.Register(PAD_CFG_DW0) + dw1 := macro.Register(PAD_CFG_DW1) term := dw1.GetTermination()
macro.Set("PAD_CFG") diff --git a/util/intelp2m/platforms/cnl/macro.go b/util/intelp2m/platforms/cnl/macro.go index 02c47eb..08574de 100644 --- a/util/intelp2m/platforms/cnl/macro.go +++ b/util/intelp2m/platforms/cnl/macro.go @@ -4,7 +4,7 @@ "fmt" "strings"
- "review.coreboot.org/coreboot.git/util/intelp2m/config" + "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/snr" @@ -153,13 +153,13 @@ } }
- switch argc := len(ids); argc { + 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.AreFieldsIgnored() { + if config.IgnoredFields { // Set Host Software Ownership to ACPI mode macro.SetPadOwnership(common.PAD_OWN_ACPI) } @@ -168,7 +168,7 @@ // 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.AreFieldsIgnored() { + if config.IgnoredFields { // Set Host Software Ownership to ACPI mode macro.SetPadOwnership(common.PAD_OWN_ACPI) } diff --git a/util/intelp2m/platforms/common/macro.go b/util/intelp2m/platforms/common/macro.go index ddb612a..02cbed9 100644 --- a/util/intelp2m/platforms/common/macro.go +++ b/util/intelp2m/platforms/common/macro.go @@ -4,7 +4,7 @@ "strconv" "sync"
- "review.coreboot.org/coreboot.git/util/intelp2m/config" + "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" )
type Fields interface { @@ -33,9 +33,9 @@ )
const ( - IOSTERM_SAME = 0x0 - IOSTERM_DISPUPD = 0x1 - IOSTERM_ENPD = 0x2 + IOSTERM_SAME = 0x0 + IOSTERM_DISPUPD = 0x1 + IOSTERM_ENPD = 0x2 IOSTERM_ENPU = 0x3 )
@@ -77,13 +77,13 @@ Fields }
-var instanceMacro *Macro -var once sync.Once +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 } + instanceMacro = &Macro{Platform: p, Fields: f} }) return instanceMacro } @@ -159,7 +159,7 @@ // return: Macro func (macro *Macro) Rstsrc() *Macro { dw0 := macro.Register(PAD_CFG_DW0) - var resetsrc = map[uint8]string { + var resetsrc = map[uint8]string{ 0: "PWROK", 1: "DEEP", 2: "PLTRST", @@ -199,7 +199,7 @@ // return: Macro func (macro *Macro) Invert() *Macro { macro.Separator() - if macro.Register(PAD_CFG_DW0).GetRxInvert() !=0 { + if macro.Register(PAD_CFG_DW0).GetRxInvert() != 0 { return macro.Add("INVERT") } return macro.Add("NONE") @@ -287,22 +287,21 @@
// or - Set " | " if its needed func (macro *Macro) Or() *Macro { - - if str := macro.Get(); str[len(str) - 1] == ')' { - macro.Add(" | ") - } - return macro + if str := macro.Get(); str[len(str)-1] == ')' { + macro.Add(" | ") + } + return macro }
// DecodeIgnored - Add info about ignored field mask // reg : PAD_CFG_DW0 or PAD_CFG_DW1 register func (macro *Macro) DecodeIgnored(reg uint8) *Macro { - var decode = map[uint8]func() { + var decode = map[uint8]func(){ PAD_CFG_DW0: macro.Fields.DecodeDW0, PAD_CFG_DW1: macro.Fields.DecodeDW1, } decodefn, valid := decode[reg] - if !valid || config.IsFspStyleMacro() { + if !valid || p2m.SettingsGet().Field == p2m.FspFlds { return macro } dw := macro.Register(reg) @@ -328,21 +327,22 @@ dw0Ignored := dw0.IgnoredFieldsGet() dw1Ignored := dw1.IgnoredFieldsGet()
- if config.InfoLevelGet() != 4 { + config := p2m.SettingsGet() + if config.GenLevel != 4 { macro.Clear() } - if config.InfoLevelGet() >= 3 { + 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.DecodeIgnored(PAD_CFG_DW0).DecodeIgnored(PAD_CFG_DW1) - if config.InfoLevelGet() >= 4 { + if config.GenLevel >= 4 { /* PAD_CFG_NF(GPP_B23, 20K_PD, PLTRST, NF2), */ macro.Add("/* ").Add(reference).Add(" */\n\t") } } - if config.AreFieldsIgnored() { + if config.IgnoredFields { // Consider bit fields that should be ignored when regenerating // advansed macros var tempVal uint32 = dw0.ValueGet() & ^dw0Ignored @@ -404,17 +404,19 @@ macro.Platform.NativeFunctionMacroAdd() }
- if config.IsFieldsMacroUsed() { + config := p2m.SettingsGet() + + if config.Field != p2m.NoFlds { // Clear control mask to generate advanced macro only return macro.GenerateFields().Get() }
- if config.IsNonCheckingFlagUsed() { + if !config.AutoCheck { body := macro.Get() - if config.InfoLevelGet() >= 3 { + if config.GenLevel >= 3 { macro.Clear().DecodeIgnored(PAD_CFG_DW0).DecodeIgnored(PAD_CFG_DW1) comment := macro.Get() - if config.InfoLevelGet() >= 4 { + if config.GenLevel >= 4 { macro.Clear().Add("/* ") macro.Fields.GenerateString() macro.Add(" */\n\t") diff --git a/util/intelp2m/platforms/snr/macro.go b/util/intelp2m/platforms/snr/macro.go index 5958b9f..5ead7e9 100644 --- a/util/intelp2m/platforms/snr/macro.go +++ b/util/intelp2m/platforms/snr/macro.go @@ -4,7 +4,7 @@ "fmt" "strings"
- "review.coreboot.org/coreboot.git/util/intelp2m/config" + "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" ) @@ -153,13 +153,13 @@ } }
- switch argc := len(ids); argc { + 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.AreFieldsIgnored() { + if config.IgnoredFields { // Set Host Software Ownership to ACPI mode macro.SetPadOwnership(common.PAD_OWN_ACPI) } @@ -168,7 +168,7 @@ // 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.AreFieldsIgnored() { + if config.IgnoredFields { // Set Host Software Ownership to ACPI mode macro.SetPadOwnership(common.PAD_OWN_ACPI) } diff --git a/util/intelp2m/platforms/test/suite.go b/util/intelp2m/platforms/test/suite.go index b161ca4..314315c 100644 --- a/util/intelp2m/platforms/test/suite.go +++ b/util/intelp2m/platforms/test/suite.go @@ -4,7 +4,7 @@ "fmt" "testing"
- "review.coreboot.org/coreboot.git/util/intelp2m/config" + "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m" )
type ( @@ -29,14 +29,22 @@ )
func (p Pad) toShortMacro(platform PlatformSpecificIf) string { - config.FldStyleSet("none") - config.NonCheckingFlagSet(true) + 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) }
func (p Pad) toLongMacro(platform PlatformSpecificIf) string { - config.FldStyleSet("cb") - config.NonCheckingFlagSet(false) + 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) }