Debian Codegraph @

util/intelp2m/platforms/snr/snr.go

raw symbols SCIP
1 package snr
2
3 import (
4 "strings"
5
6 "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m"
7 "review.coreboot.org/coreboot.git/util/intelp2m/logs"
8 "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common"
9 "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register/bits"
10 )
11
12 const (
13 DW0Mask uint32 = (0b1 << 27) | (0b1 << 24) | (0b11 << 21) | (0b1111 << 16) | 0b11111100
14 DW1Mask uint32 = 0b11111101111111111100001111111111
15 )
16
17 // "GPP_A", "GPP_B", "GPP_F", "GPP_C", "GPP_D", "GPP_E", "GPD", "GPP_I", "GPP_J", "GPP_G",
18 // "GPP_H", "GPP_L"
19 var GPPGroups = []string{"GPP_", "GPD"}
20
21 var remapping = common.ResetSources{
22 0b00: bits.RstCfgRSMRST << bits.DW0PadRstCfg,
23 0b01: bits.RstCfgDEEP << bits.DW0PadRstCfg,
24 0b10: bits.RstCfgPLTRST << bits.DW0PadRstCfg,
25 }
26
27 type BasePlatform struct {
28 common.BasePlatform
29 }
30
31 func InitBasePlatform(dw0, dw0mask uint32, dw1, dw1mask uint32) BasePlatform {
32 return BasePlatform{common.InitBasePlatform(dw0, dw0mask, dw1, dw1mask)}
33 }
34
35 func GetPlatform(dw0, dw1 uint32) common.PlatformIf {
36 p := InitBasePlatform(dw0, DW0Mask, dw1, DW1Mask)
37 return &p
38 }
39
40 // RemmapRstSrc() remaps Pad Reset Source Config
41 func (p *BasePlatform) RemapResetSource(m *common.Macro) {
42 if strings.Contains(m.GetPadId(), "GPD") {
43 // See reset map for the Sunrise GPD Group in the Community 2:
44 // https://github.com/coreboot/coreboot/blob/master/src/soc/intel/skylake/gpio.c#L15
45 // remmap is not required because it is the same as common.
46 return
47 }
48 if err := p.UpdateResetSource(remapping); err != nil {
49 logs.Errorf("remap reset source for %s: %v", m.GetPadId(), err)
50 }
51 }
52
53 // Pull() adds The Pad Termination (TERM) parameter from PAD_CFG_DW1 to the macro
54 func (p *BasePlatform) Pull(m *common.Macro) {
55 dw1 := p.GetRegisterDW1()
56 var pull = map[uint32]string{
57 0b0000: "NONE",
58 0b0010: "DN_5K",
59 0b0100: "DN_20K",
60 0b1001: "UP_1K",
61 0b1010: "UP_5K",
62 0b1011: "UP_2K",
63 0b1100: "UP_20K",
64 0b1101: "UP_667",
65 0b1111: "NATIVE",
66 }
67 term, valid := pull[dw1.GetTermination()]
68 if !valid {
69 term = "INVALID"
70 logs.Errorf("%s: DW1 %s: invalid termination value 0b%b",
71 dw1, m.GetPadId(), dw1.GetTermination())
72 }
73 m.Separator().Add(term)
74 }
75
76 // ioApicRoute() generate macro to cause peripheral IRQ when configured in GPIO input mode
77 func ioApicRoute(p *BasePlatform, m *common.Macro) bool {
78 dw0 := p.GetRegisterDW0()
79 if dw0.GetGPIOInputRouteIOxAPIC() == 0 {
80 return false
81 }
82
83 m.Add("_APIC")
84 if dw0.GetRXLevelEdgeConfiguration() == bits.TrigLEVEL {
85 if dw0.GetRxInvert() != 0 {
86 // PAD_CFG_GPI_APIC_LOW(pad, pull, rst)
87 m.Add("_LOW")
88 } else {
89 // PAD_CFG_GPI_APIC_HIGH(pad, pull, rst)
90 m.Add("_HIGH")
91 }
92 m.Add("(").Id().Pull().Rstsrc().Add("),")
93 return true
94 }
95
96 // e.g. PAD_CFG_GPI_APIC_IOS(pad, pull, rst, trig, inv, iosstate, iosterm)
97 m.Add("_IOS(").Id().Pull().Rstsrc().Trig().Invert().Add(", TxLASTRxE, SAME),")
98 return true
99 }
100
101 // nmiRoute() generate macro to cause NMI when configured in GPIO input mode
102 func nmiRoute(p *BasePlatform, m *common.Macro) bool {
103 if p.GetRegisterDW0().GetGPIOInputRouteNMI() == 0 {
104 return false
105 }
106 // PAD_CFG_GPI_NMI(GPIO_24, UP_20K, DEEP, LEVEL, INVERT),
107 m.Add("_NMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),")
108 return true
109 }
110
111 // sciRoute() generate macro to cause SCI when configured in GPIO input mode
112 func sciRoute(p *BasePlatform, m *common.Macro) bool {
113 dw0 := p.GetRegisterDW0()
114 if dw0.GetGPIOInputRouteSCI() == 0 {
115 return false
116 }
117 // PAD_CFG_GPI_SCI(GPP_B18, UP_20K, PLTRST, LEVEL, INVERT),
118 m.Add("_SCI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),")
119 return true
120 }
121
122 // smiRoute() generates macro to cause SMI when configured in GPIO input mode
123 func smiRoute(p *BasePlatform, m *common.Macro) bool {
124 dw0 := p.GetRegisterDW0()
125 if dw0.GetGPIOInputRouteSMI() == 0 {
126 return false
127 }
128 // PAD_CFG_GPI_SMI(GPP_E7, NONE, DEEP, LEVEL, NONE),
129 m.Add("_SMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),")
130 return true
131 }
132
133 // AddGpiMacro() adds PAD_CFG_GPI macro with arguments
134 func (p *BasePlatform) AddGpiMacro(m *common.Macro) {
135 var ids []string
136 m.Set("PAD_CFG_GPI")
137 for routeid, isRoute := range map[string]func(*BasePlatform, *common.Macro) bool{
138 "IOAPIC": ioApicRoute,
139 "SCI": sciRoute,
140 "SMI": smiRoute,
141 "NMI": nmiRoute,
142 } {
143 if isRoute(p, m) {
144 ids = append(ids, routeid)
145 }
146 }
147
148 switch argc := len(ids); argc {
149 case 0:
150 // e.g. PAD_CFG_GPI_TRIG_OWN(pad, pull, rst, trig, own)
151 m.Add("_TRIG_OWN").Add("(").Id().Pull().Rstsrc().Trig().Own().Add("),")
152 case 1:
153 // GPI with IRQ route
154 if p2m.Config.IgnoredFields {
155 // Set Host Software Ownership to ACPI mode
156 m.SetOwnershipAcpi()
157 }
158
159 case 2:
160 // PAD_CFG_GPI_DUAL_ROUTE(pad, pull, rst, trig, inv, route1, route2)
161 m.Set("PAD_CFG_GPI_DUAL_ROUTE(").Id().Pull().Rstsrc().Trig().Invert()
162 m.Add(", " + ids[0] + ", " + ids[1] + "),")
163 if p2m.Config.IgnoredFields {
164 // Set Host Software Ownership to ACPI mode
165 m.SetOwnershipAcpi()
166 }
167 default:
168 // Clear the control mask so that the check fails and "Advanced" macro is
169 // generated
170 dw0 := p.GetRegisterDW0()
171 dw0.CntrMaskFieldsClear(bits.All32)
172 }
173 }
174
175 // AddGpoMacro() adds PAD_CFG_GPO macro with arguments
176 func (p *BasePlatform) AddGpoMacro(m *common.Macro) {
177 // #define PAD_CFG_GPO(pad, val, rst) \
178 // _PAD_CFG_STRUCT(pad, \
179 // PAD_FUNC(GPIO) | PAD_RESET(rst) | \
180 // PAD_TRIG(OFF) | PAD_BUF(RX_DISABLE) | !!val, \
181 // PAD_PULL(NONE) | PAD_IOSSTATE(TxLASTRxE))
182 if dw0 := p.GetRegisterDW0(); dw0.GetRXLevelEdgeConfiguration() != bits.TrigOFF {
183 mask := bits.DW0[bits.DW0RxLevelEdgeConfiguration]
184 dw0.CntrMaskFieldsClear(mask)
185 }
186 m.Set("PAD_CFG")
187 if m.IsOwnershipDriver() {
188 // PAD_CFG_GPO_GPIO_DRIVER(pad, val, rst, pull)
189 m.Add("_GPO_GPIO_DRIVER").Add("(").Id().Val().Rstsrc().Pull().Add("),")
190 return
191 }
192 dw1 := p.GetRegisterDW1()
193 term := dw1.GetTermination()
194 if term != 0 {
195 // e.g. PAD_CFG_TERM_GPO(GPP_B23, 1, DN_20K, DEEP),
196 m.Add("_TERM")
197 }
198 m.Add("_GPO").Add("(").Id().Val()
199 if term != 0 {
200 m.Pull()
201 }
202 m.Rstsrc().Add("),")
203 }
204
205 // AddNativeFunctionMacro() adds PAD_CFG_NF macro with arguments
206 func (p *BasePlatform) AddNativeFunctionMacro(m *common.Macro) {
207 // e.g. PAD_CFG_NF(GPP_D23, NONE, DEEP, NF1)
208 m.Set("PAD_CFG_NF")
209 if p.GetRegisterDW1().GetPadTol() != 0 {
210 m.Add("_1V8")
211 }
212 m.Add("(").Id().Pull().Rstsrc().Padfn().Add("),")
213 }
214
215 // AddNoConnMacro() adds PAD_NC macro
216 func (p *BasePlatform) AddNoConnMacro(m *common.Macro) {
217 // #define PAD_NC(pad, pull)
218 // _PAD_CFG_STRUCT(pad,
219 // PAD_FUNC(GPIO) | PAD_RESET(DEEP) | PAD_TRIG(OFF) | PAD_BUF(TX_RX_DISABLE),
220 // PAD_PULL(pull) | PAD_IOSSTATE(TxDRxE)),
221 dw0 := p.GetRegisterDW0()
222
223 // Some fields of the configuration registers are hidden inside the macros,
224 // we should check them to update the corresponding bits in the control mask.
225 if dw0.GetRXLevelEdgeConfiguration() != bits.TrigOFF {
226 mask := bits.DW0[bits.DW0RxLevelEdgeConfiguration]
227 dw0.CntrMaskFieldsClear(mask)
228 }
229 if dw0.GetResetConfig() != 1 { // 1 = RST_DEEP
230 mask := bits.DW0[bits.DW0PadRstCfg]
231 dw0.CntrMaskFieldsClear(mask)
232 }
233 m.Set("PAD_NC").Add("(").Id().Pull().Add("),")
234 }