Debian Codegraph @

util/intelp2m/platforms/common/fields/fsp/fsp.go

raw symbols SCIP
1 package fsp
2
3 import "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common"
4
5 type FieldCollection struct{}
6
7 // field - data structure for creating a new bitfield macro object
8 // configmap : map to select the current configuration
9 // value : the key value in the configmap
10 // override : overrides the function to generate the current bitfield macro
11 type field struct {
12 configmap map[uint32]string
13 value uint32
14 override func(configuration map[uint32]string, value uint32)
15 }
16
17 // generate() generates bitfield macro data struct
18 func generate(macro *common.Macro, fields ...*field) {
19 for _, field := range fields {
20 if field.override != nil {
21 // override if necessary
22 field.override(field.configmap, field.value)
23 continue
24 }
25
26 fieldmacro, valid := field.configmap[field.value]
27 if valid {
28 macro.Add(fieldmacro).Add(", ")
29 } else {
30 macro.Add("INVALID, ")
31 }
32 }
33 }
34
35 // DecodeDW0 - decode value of DW0 register
36 func (FieldCollection) DecodeDW0(macro *common.Macro) *common.Macro {
37 dw0 := macro.Platform.GetRegisterDW0()
38
39 ownershipStatus := func() uint32 {
40 if macro.IsOwnershipDriver() {
41 return 1
42 }
43 return 0
44 }
45
46 generate(macro,
47 &field{
48 configmap: map[uint32]string{
49 0: "GpioPadModeGpio",
50 1: "GpioPadModeNative1",
51 2: "GpioPadModeNative2",
52 3: "GpioPadModeNative3",
53 4: "GpioPadModeNative4",
54 5: "GpioPadModeNative5",
55 },
56 value: dw0.GetPadMode(),
57 },
58
59 &field{
60 configmap: map[uint32]string{
61 0: "GpioHostOwnAcpi",
62 1: "GpioHostOwnGpio",
63 },
64 value: ownershipStatus(),
65 },
66
67 &field{
68 configmap: map[uint32]string{
69 0: "GpioDirInOut",
70 1: "GpioDirIn",
71 2: "GpioDirOut",
72 3: "GpioDirNone",
73 (1 << 4): "GpioDirInInvOut",
74 (1 << 4) | 1: "GpioDirInInv",
75 },
76 value: dw0.GetRxInvert()<<4 | dw0.GetGPIORxTxDisableStatus(),
77 },
78
79 &field{
80 configmap: map[uint32]string{
81 0: "GpioOutLow",
82 1: "GpioOutHigh",
83 },
84 value: dw0.GetGPIOTXState(),
85 },
86
87 &field{
88 configmap: map[uint32]string{
89 1 << 0: "GpioIntNmi",
90 1 << 1: "GpioIntSmi",
91 1 << 2: "GpioIntSci",
92 1 << 3: "GpioIntApic",
93 },
94 override: func(configmap map[uint32]string, value uint32) {
95 mask := dw0.GetGPIOInputRouteIOxAPIC()<<3 |
96 dw0.GetGPIOInputRouteSCI()<<2 |
97 dw0.GetGPIOInputRouteSMI()<<1 |
98 dw0.GetGPIOInputRouteNMI()
99 if mask == 0 {
100 macro.Add("GpioIntDis | ")
101 return
102 }
103 for bit, fieldmacro := range configmap {
104 if mask&bit != 0 {
105 macro.Add(fieldmacro).Add(" | ")
106 }
107 }
108 },
109 },
110
111 &field{
112 configmap: map[uint32]string{
113 0: "GpioIntLevel",
114 1: "GpioIntEdge",
115 2: "GpioIntLvlEdgDis",
116 3: "GpioIntBothEdge",
117 },
118 value: dw0.GetRXLevelEdgeConfiguration(),
119 },
120
121 &field{
122 configmap: map[uint32]string{
123 0: "GpioResetPwrGood", // TODO: Has multiple values (to GPP and GPD)
124 1: "GpioHostDeepReset",
125 2: "GpioPlatformReset",
126 3: "GpioResumeReset",
127 },
128 value: dw0.GetResetConfig(),
129 },
130 )
131 return macro
132 }
133
134 // DecodeDW1() decodes DW1 register value and adds it to the macro string
135 func (FieldCollection) DecodeDW1(macro *common.Macro) *common.Macro {
136 dw1 := macro.Platform.GetRegisterDW1()
137 generate(macro,
138 &field{
139 override: func(configmap map[uint32]string, value uint32) {
140 if dw1.GetPadTol() != 0 {
141 macro.Add("GpioTolerance1v8 | ")
142 }
143 },
144 },
145 &field{
146 configmap: map[uint32]string{
147 0b0000: "GpioTermNone",
148 0b0010: "GpioTermWpd5K",
149 0b0100: "GpioTermWpd20K",
150 0b1001: "GpioTermWpu1K",
151 0b1010: "GpioTermWpu5K",
152 0b1011: "GpioTermWpu2K",
153 0b1100: "GpioTermWpu20K",
154 0b1101: "GpioTermWpu1K2K",
155 0b1111: "GpioTermNative",
156 },
157 value: dw1.GetTermination(),
158 },
159 )
160 return macro
161 }
162
163 // GenerateMacro() generates the field macro collection and adds it to the macro string
164 func (f FieldCollection) GenerateMacro(macro *common.Macro) *common.Macro {
165 macro.Add("{ GPIO_SKL_H_").Id().Add(", { ")
166 f.DecodeDW0(macro)
167 return f.DecodeDW1(macro).Add(" GpioPadConfigLock } },") // TODO: configure GpioPadConfigLock
168 }