diff options
author | Maxim Polyakov <max.senia.poliak@gmail.com> | 2020-04-26 22:12:01 +0300 |
---|---|---|
committer | Felix Held <felix-coreboot@felixheld.de> | 2020-07-28 22:06:02 +0000 |
commit | 82ec61e9d7a39a11c9b8ed68eb90bd29905439bc (patch) | |
tree | ff68be99e8bf9d92c4adfbadd457c317a2414418 /util/intelp2m/parser | |
parent | 8079c5c1c2b76ebd01cfcddcef4b5398ee860403 (diff) |
util/intelp2m: Add Intel Pad to Macro utility
This patch adds a new utility for converting a pad configuration from
the inteltool dump to the PAD_CFG_*() macros [1] for coreboot and GPIO
config data structures for FSP/sdk2-platforms/slimbootloader [2,3].
Mirror: https://github.com/maxpoliak/pch-pads-parser.git
[1] src/soc/intel/common/block/include/intelblocks/gpio_defs.h
[2] https://slimbootloader.github.io/tools/index.html#gpio-tool
[3] 3rdparty/fsp/CometLakeFspBinPkg/CometLake1/Include/GpioSampleDef.h
Change-Id: If3e3b523c4f63dc2f91e9ccd16934e3a1b6e21fa
Signed-off-by: Maxim Polyakov <max.senia.poliak@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/35643
Reviewed-by: Andrey Petrov <andrey.petrov@gmail.com>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'util/intelp2m/parser')
-rw-r--r-- | util/intelp2m/parser/parser.go | 232 | ||||
-rw-r--r-- | util/intelp2m/parser/template.go | 132 |
2 files changed, 364 insertions, 0 deletions
diff --git a/util/intelp2m/parser/parser.go b/util/intelp2m/parser/parser.go new file mode 100644 index 0000000000..f002cc9064 --- /dev/null +++ b/util/intelp2m/parser/parser.go @@ -0,0 +1,232 @@ +package parser + +import ( + "bufio" + "fmt" + "strings" + "strconv" +) + +import "../platforms/snr" +import "../platforms/lbg" +import "../platforms/apl" +import "../config" + +// PlatformSpecific - platform-specific interface +type PlatformSpecific interface { + GenMacro(id string, dw0 uint32, dw1 uint32, ownership uint8) string + GroupNameExtract(line string) (bool, string) + KeywordCheck(line string) bool +} + +// padInfo - information about pad +// id : pad id string +// offset : the offset of the register address relative to the base +// function : the string that means the pad function +// dw0 : DW0 register value +// dw1 : DW1 register value +// ownership : host software ownership +type padInfo struct { + id string + offset uint16 + function string + dw0 uint32 + dw1 uint32 + ownership uint8 +} + +// generate - wrapper for Fprintf(). Writes text to the file specified +// in config.OutputGenFile +func (info *padInfo) generate(lvl uint8, line string, a ...interface{}) { + if config.InfoLevelGet() >= lvl { + fmt.Fprintf(config.OutputGenFile, line, a...) + } +} + +// titleFprint - print GPIO group title to file +// /* ------- GPIO Group GPP_L ------- */ +func (info *padInfo) titleFprint() { + info.generate(0, "\n\t/* %s */\n", info.function) +} + +// reservedFprint - print reserved GPIO to file as comment +// /* GPP_H17 - RESERVED */ +func (info *padInfo) reservedFprint() { + info.generate(2, "\n") + // small comment about reserved port + info.generate(0, "\t/* %s - %s */\n", info.id, info.function) +} + +// padInfoMacroFprint - print information about current pad to file using +// special macros: +// PAD_CFG_NF(GPP_F1, 20K_PU, PLTRST, NF1), /* SATAXPCIE4 */ +// gpio : gpio.c file descriptor +// macro : string of the generated macro +func (info *padInfo) padInfoMacroFprint(macro string) { + info.generate(2, "\n") + info.generate(1, "\t/* %s - %s ", info.id, info.function) + info.generate(2, "DW0: 0x%0.8x, DW1: 0x%0.8x ", info.dw0, info.dw1) + info.generate(1, "*/\n") + info.generate(0, "\t%s", macro) + if config.InfoLevelGet() == 0 { + info.generate(0, "\t/* %s */", info.function) + } + info.generate(0, "\n") +} + +// ParserData - global data +// line : string from the configuration file +// padmap : pad info map +// RawFmt : flag for generating pads config file with DW0/1 reg raw values +// Template : structure template type of ConfigFile +type ParserData struct { + platform PlatformSpecific + line string + padmap []padInfo + ownership map[string]uint32 +} + +// hostOwnershipGet - get the host software ownership value for the corresponding +// pad ID +// id : pad ID string +// return the host software ownership form the parser struct +func (parser *ParserData) hostOwnershipGet(id string) uint8 { + var ownership uint8 = 0 + status, group := parser.platform.GroupNameExtract(id) + if config.TemplateGet() == config.TempInteltool && status { + numder, _ := strconv.Atoi(strings.TrimLeft(id, group)) + if (parser.ownership[group] & (1 << uint8(numder))) != 0 { + ownership = 1 + } + } + return ownership +} + +// padInfoExtract - adds a new entry to pad info map +// return error status +func (parser *ParserData) padInfoExtract() int { + var function, id string + var dw0, dw1 uint32 + var template = map[int]template{ + config.TempInteltool: useInteltoolLogTemplate, + config.TempGpioh : useGpioHTemplate, + config.TempSpec : useYourTemplate, + } + if template[config.TemplateGet()](parser.line, &function, &id, &dw0, &dw1) == 0 { + pad := padInfo{id: id, + function: function, + dw0: dw0, + dw1: dw1, + ownership: parser.hostOwnershipGet(id)} + parser.padmap = append(parser.padmap, pad) + return 0 + } + fmt.Printf("This template (%d) does not match!\n", config.TemplateGet()) + return -1 +} + +// communityGroupExtract +func (parser *ParserData) communityGroupExtract() { + pad := padInfo{function: parser.line} + parser.padmap = append(parser.padmap, pad) +} + +// PlatformSpecificInterfaceSet - specific interface for the platform selected +// in the configuration +func (parser *ParserData) PlatformSpecificInterfaceSet() { + var platform = map[uint8]PlatformSpecific { + config.SunriseType : snr.PlatformSpecific{}, + // See platforms/lbg/macro.go + config.LewisburgType : lbg.PlatformSpecific{ + InheritanceTemplate : snr.PlatformSpecific{}, + }, + config.ApolloType : apl.PlatformSpecific{}, + } + parser.platform = platform[config.PlatformGet()] +} + +// PadMapFprint - print pad info map to file +func (parser *ParserData) PadMapFprint() { + for _, pad := range parser.padmap { + switch pad.dw0 { + case 0: + pad.titleFprint() + case 0xffffffff: + pad.reservedFprint() + default: + str := parser.platform.GenMacro(pad.id, pad.dw0, pad.dw1, pad.ownership) + pad.padInfoMacroFprint(str) + } + } +} + +// Register - read specific platform registers (32 bits) +// line : string from file with pad config map +// nameTemplate : register name femplate to filter parsed lines +// return +// valid : true if the dump of the register in intertool.log is set in accordance +// with the template +// name : full register name +// offset : register offset relative to the base address +// value : register value +func (parser *ParserData) Register(nameTemplate string) ( + valid bool, name string, offset uint32, value uint32) { + if strings.Contains(parser.line, nameTemplate) && + config.TemplateGet() == config.TempInteltool { + if registerInfoTemplate(parser.line, &name, &offset, &value) == 0 { + fmt.Printf("\n\t/* %s : 0x%x : 0x%x */\n", name, offset, value) + return true, name, offset, value + } + } + return false, "ERROR", 0, 0 +} + +// padOwnershipExtract - extract Host Software Pad Ownership from inteltool dump +// return true if success +func (parser *ParserData) padOwnershipExtract() bool { + var group string + status, name, offset, value := parser.Register("HOSTSW_OWN_GPP_") + if status { + _, group = parser.platform.GroupNameExtract(parser.line) + parser.ownership[group] = value + fmt.Printf("\n\t/* padOwnershipExtract: [offset 0x%x] %s = 0x%x */\n", + offset, name, parser.ownership[group]) + } + return status +} + +// 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 PCH and only for inteltool.log file template + if config.TemplateGet() != config.TempInteltool || config.IsPlatformApollo() { + return false + } + return parser.padOwnershipExtract() +} + +// Parse pads groupe information in the inteltool log file +// ConfigFile : name of inteltool log file +func (parser *ParserData) Parse() { + // Read all lines from inteltool log file + fmt.Println("Parse IntelTool Log File...") + + // determine the platform type and set the interface for it + parser.PlatformSpecificInterfaceSet() + + // map of thepad ownership registers for the GPIO controller + parser.ownership = make(map[string]uint32) + + scanner := bufio.NewScanner(config.InputRegDumpFile) + for scanner.Scan() { + parser.line = scanner.Text() + if strings.Contains(parser.line, "GPIO Community") || strings.Contains(parser.line, "GPIO Group") { + parser.communityGroupExtract() + } else if !parser.padConfigurationExtract() && parser.platform.KeywordCheck(parser.line) { + if parser.padInfoExtract() != 0 { + fmt.Println("...error!") + } + } + } + fmt.Println("...done!") +} diff --git a/util/intelp2m/parser/template.go b/util/intelp2m/parser/template.go new file mode 100644 index 0000000000..bc7d702928 --- /dev/null +++ b/util/intelp2m/parser/template.go @@ -0,0 +1,132 @@ +package parser + +import ( + "fmt" + "strings" + "unicode" +) + +type template func(string, *string, *string, *uint32, *uint32) int + +// extractPadFuncFromComment +// line : string from file with pad config map +// return : pad function string +func extractPadFuncFromComment(line string) string { + if !strings.Contains(line, "/*") && !strings.Contains(line, "*/") { + return "" + } + + fields := strings.Fields(line) + for i, field := range fields { + if field == "/*" && len(fields) >= i+2 { + return fields[i+1] + } + } + return "" +} + +// tokenCheck +func tokenCheck(c rune) bool { + return c != '_' && c != '#' && !unicode.IsLetter(c) && !unicode.IsNumber(c) +} + +// useGpioHTemplate +// line : string from file with pad config map +// *function : the string that means the pad function +// *id : pad id string +// *dw0 : DW0 register value +// *dw1 : DW1 register value +// return +// error status +func useInteltoolLogTemplate(line string, function *string, + id *string, dw0 *uint32, dw1 *uint32) int { + + var val uint64 + // 0x0520: 0x0000003c44000600 GPP_B12 SLP_S0# + // 0x0438: 0xffffffffffffffff GPP_C7 RESERVED + if fields := strings.FieldsFunc(line, tokenCheck); len(fields) >= 4 { + fmt.Sscanf(fields[1], "0x%x", &val) + *dw0 = uint32(val & 0xffffffff) + *dw1 = uint32(val >> 32) + *id = fields[2] + *function = fields[3] + // Sometimes the configuration file contains compound functions such as + // SUSWARN#/SUSPWRDNACK. Since the template does not take this into account, + // need to collect all parts of the pad function back into a single word + for i := 4; i < len(fields); i++ { + *function += "/" + fields[i] + } + // clear RO Interrupt Select (INTSEL) + *dw1 &= 0xffffff00 + } + return 0 +} + +// useGpioHTemplate +// line : string from file with pad config map +// *function : the string that means the pad function +// *id : pad id string +// *dw0 : DW0 register value +// *dw1 : DW1 register value +// return +// error status +func useGpioHTemplate(line string, function *string, + id *string, dw0 *uint32, dw1 *uint32) int { + + // /* RCIN# */ _PAD_CFG_STRUCT(GPP_A0, 0x44000702, 0x00000000), + // _PAD_CFG_STRUCT(GPP_A0, 0x44000702, 0x00000000), /* RCIN# */ + // _PAD_CFG_STRUCT(GPP_A0, 0x44000702, 0x00000000) + fields := strings.FieldsFunc(line, tokenCheck) + for i, field := range fields { + if field == "_PAD_CFG_STRUCT" { + if len(fields) < 4 { + /* the number of definitions does not match the format */ + return -1 + } + + if !strings.Contains(fields[i+2], "0x") || !strings.Contains(fields[i+3], "0x") { + /* definitions inside the macro do not match the pattern */ + return -1 + } + *id = fields[i+1] + fmt.Sscanf(fields[i+2], "0x%x", dw0) + fmt.Sscanf(fields[i+3], "0x%x", dw1) + *function = extractPadFuncFromComment(line) + return 0 + } + } + return -1 +} + +// useYourTemplate +func useYourTemplate(line string, function *string, + id *string, dw0 *uint32, dw1 *uint32) int { + + // ADD YOUR TEMPLATE HERE + *function = "" + *id = "" + *dw0 = 0 + *dw1 = 0 + + fmt.Printf("ADD YOUR TEMPLATE!\n") + return -1 +} + +// registerInfoTemplate +// line : (in) string from file with pad config map +// *name : (out) register name +// *offset : (out) offset name +// *value : (out) register value +// return +// error status +func registerInfoTemplate(line string, name *string, offset *uint32, value *uint32) int { + // 0x0088: 0x00ffffff (HOSTSW_OWN_GPP_F) + // 0x0100: 0x00000000 (GPI_IS_GPP_A) + if fields := strings.FieldsFunc(line, tokenCheck); len(fields) == 3 { + *name = fields[2] + fmt.Sscanf(fields[1], "0x%x", value) + fmt.Sscanf(fields[0], "0x%x", offset) + return 0 + } + return -1 +} |