Debian Codegraph @

util/intelp2m/parser/template/template.go

raw symbols SCIP
1 package template
2
3 import (
4 "fmt"
5 "strings"
6 "unicode"
7
8 "review.coreboot.org/coreboot.git/util/intelp2m/logs"
9 "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register/bits"
10 )
11
12 func token(c rune) bool {
13 return c != '_' && c != '#' && !unicode.IsLetter(c) && !unicode.IsNumber(c)
14 }
15
16 // Apply
17 // line : string from file with pad config map
18 // return
19 // function : the string that means the pad function
20 // id : pad id string
21 // dw0 : DW0 register value
22 // dw1 : DW1 register value
23 // err : error
24 func Apply(line string) (function string, id string, dw0 uint32, dw1 uint32, err error) {
25 // 0x0520: 0x0000003c44000600 GPP_B12 SLP_S0#
26 // 0x0438: 0xffffffffffffffff GPP_C7 RESERVED
27 slices := strings.FieldsFunc(line, token)
28 number := len(slices)
29 if number >= 4 {
30 var val uint64
31 fmt.Sscanf(slices[1], "0x%x", &val)
32 dw0 = uint32(val & 0xffffffff)
33 dw1 = uint32(val >> 32)
34 id = slices[2]
35 function = slices[3]
36 // Sometimes the configuration file contains compound functions such as
37 // SUSWARN#/SUSPWRDNACK. Since the template does not take this into account,
38 // need to collect all parts of the pad function back into a single word
39 for i := 4; i < len(slices); i++ {
40 function += "/" + slices[i]
41 }
42 // clear RO Interrupt Select (INTSEL)
43 dw1 &^= bits.DW1[bits.DW1InterruptSelect]
44 return function, id, dw0, dw1, nil
45 }
46 logs.Errorf("template: more than %d elements are needed", number)
47 return "", "", 0, 0, fmt.Errorf("template error")
48 }