7 "review.coreboot.org/coreboot.git/util/intelp2m/config"
10 type Fields
interface {
56 // PlatformSpecific - platform-specific interface
57 type PlatformSpecific
interface {
62 NativeFunctionMacroAdd()
66 // Macro - contains macro information and methods
67 // Platform : platform-specific interface
68 // padID : pad ID string
69 // str : macro string entirely
70 // Reg : structure of configuration register values and their masks
72 Platform PlatformSpecific
73 Reg
[MAX_DW_NUM
]Register
80 var instanceMacro
*Macro
83 // GetInstance returns singleton
84 func GetInstanceMacro(p PlatformSpecific
, f Fields
) *Macro
{
86 instanceMacro
= &Macro
{ Platform
: p
, Fields
: f
}
91 func GetMacro() *Macro
{
92 return GetInstanceMacro(nil, nil)
95 func (macro
*Macro
) PadIdGet() string {
99 func (macro
*Macro
) PadIdSet(padid
string) *Macro
{
104 func (macro
*Macro
) SetPadOwnership(own
uint8) *Macro
{
105 macro
.ownership
= own
109 func (macro
*Macro
) IsOwnershipDriver() bool {
110 return macro
.ownership
== PAD_OWN_DRIVER
113 // returns <Register> data configuration structure
114 // number : register number
115 func (macro
*Macro
) Register(number
uint8) *Register
{
116 return ¯o
.Reg
[number
]
119 // add a string to macro
120 func (macro
*Macro
) Add(str
string) *Macro
{
125 // set a string in a macro instead of its previous contents
126 func (macro
*Macro
) Set(str
string) *Macro
{
132 func (macro
*Macro
) Get() string {
136 // set a string in a macro instead of its previous contents
137 func (macro
*Macro
) Clear() *Macro
{
142 // Adds PAD Id to the macro as a new argument
144 func (macro
*Macro
) Id() *Macro
{
145 return macro
.Add(macro
.padID
)
148 // Add Separator to macro if needed
149 func (macro
*Macro
) Separator() *Macro
{
152 if c
!= '(' && c
!= '_' {
158 // Adds the PADRSTCFG parameter from DW0 to the macro as a new argument
160 func (macro
*Macro
) Rstsrc() *Macro
{
161 dw0
:= macro
.Register(PAD_CFG_DW0
)
162 var resetsrc
= map[uint8]string {
168 return macro
.Separator().Add(resetsrc
[dw0
.GetResetConfig()])
171 // Adds The Pad Termination (TERM) parameter from DW1 to the macro as a new argument
173 func (macro
*Macro
) Pull() *Macro
{
174 macro
.Platform
.Pull()
178 // Adds Pad GPO value to macro string as a new argument
180 func (macro
*Macro
) Val() *Macro
{
181 dw0
:= macro
.Register(PAD_CFG_DW0
)
182 return macro
.Separator().Add(strconv
.Itoa(int(dw0
.GetGPIOTXState())))
185 // Adds Pad GPO value to macro string as a new argument
187 func (macro
*Macro
) Trig() *Macro
{
188 dw0
:= macro
.Register(PAD_CFG_DW0
)
189 var trig
= map[uint8]string{
195 return macro
.Separator().Add(trig
[dw0
.GetRXLevelEdgeConfiguration()])
198 // Adds Pad Polarity Inversion Stage (RXINV) to macro string as a new argument
200 func (macro
*Macro
) Invert() *Macro
{
202 if macro
.Register(PAD_CFG_DW0
).GetRxInvert() !=0 {
203 return macro
.Add("INVERT")
205 return macro
.Add("NONE")
208 // Adds input/output buffer state
210 func (macro
*Macro
) Bufdis() *Macro
{
211 var buffDisStat
= map[uint8]string{
212 0x0: "NO_DISABLE", // both buffers are enabled
213 0x1: "TX_DISABLE", // output buffer is disabled
214 0x2: "RX_DISABLE", // input buffer is disabled
215 0x3: "TX_RX_DISABLE", // both buffers are disabled
217 state
:= macro
.Register(PAD_CFG_DW0
).GetGPIORxTxDisableStatus()
218 return macro
.Separator().Add(buffDisStat
[state
])
221 // Adds macro to set the host software ownership
223 func (macro
*Macro
) Own() *Macro
{
224 if macro
.IsOwnershipDriver() {
225 return macro
.Separator().Add("DRIVER")
227 return macro
.Separator().Add("ACPI")
230 //Adds pad native function (PMODE) as a new argument
232 func (macro
*Macro
) Padfn() *Macro
{
233 dw0
:= macro
.Register(PAD_CFG_DW0
)
234 nfnum
:= int(dw0
.GetPadMode())
236 return macro
.Separator().Add("NF" + strconv
.Itoa(nfnum
))
238 // GPIO used only for PAD_FUNC(x) macro
239 return macro
.Add("GPIO")
242 // Add a line to the macro that defines IO Standby State
244 func (macro
*Macro
) IOSstate() *Macro
{
245 var stateMacro
= map[uint8]string{
246 TxLASTRxE
: "TxLASTRxE",
247 Tx0RxDCRx0
: "Tx0RxDCRx0",
248 Tx0RxDCRx1
: "Tx0RxDCRx1",
249 Tx1RxDCRx0
: "Tx1RxDCRx0",
250 Tx1RxDCRx1
: "Tx1RxDCRx1",
256 StandbyIgnore
: "IGNORE",
258 dw1
:= macro
.Register(PAD_CFG_DW1
)
259 str
, valid
:= stateMacro
[dw1
.GetIOStandbyState()]
261 // ignore setting for incorrect value
264 return macro
.Separator().Add(str
)
267 // Add a line to the macro that defines IO Standby Termination
269 func (macro
*Macro
) IOTerm() *Macro
{
270 var ioTermMacro
= map[uint8]string{
271 IOSTERM_SAME
: "SAME",
272 IOSTERM_DISPUPD
: "DISPUPD",
273 IOSTERM_ENPD
: "ENPD",
274 IOSTERM_ENPU
: "ENPU",
276 dw1
:= macro
.Register(PAD_CFG_DW1
)
277 return macro
.Separator().Add(ioTermMacro
[dw1
.GetIOStandbyTermination()])
280 // Check created macro
281 func (macro
*Macro
) check() *Macro
{
282 if !macro
.Register(PAD_CFG_DW0
).MaskCheck() {
283 return macro
.GenerateFields()
288 // or - Set " | " if its needed
289 func (macro
*Macro
) Or() *Macro
{
291 if str
:= macro
.Get(); str
[len(str
) - 1] == ')' {
297 // DecodeIgnored - Add info about ignored field mask
298 // reg : PAD_CFG_DW0 or PAD_CFG_DW1 register
299 func (macro
*Macro
) DecodeIgnored(reg
uint8) *Macro
{
300 var decode
= map[uint8]func() {
301 PAD_CFG_DW0
: macro
.Fields
.DecodeDW0
,
302 PAD_CFG_DW1
: macro
.Fields
.DecodeDW1
,
304 decodefn
, valid
:= decode
[reg
]
305 if !valid || config
.IsFspStyleMacro() {
308 dw
:= macro
.Register(reg
)
309 ignored
:= dw
.IgnoredFieldsGet()
311 temp
:= dw
.ValueGet()
313 regnum
:= strconv
.Itoa(int(reg
))
314 macro
.Add("/* DW" + regnum
+ ": ")
316 macro
.Add(" - IGNORED */\n\t")
322 // GenerateFields - generate bitfield macros
323 func (macro
*Macro
) GenerateFields() *Macro
{
324 dw0
:= macro
.Register(PAD_CFG_DW0
)
325 dw1
:= macro
.Register(PAD_CFG_DW1
)
327 // Get mask of ignored bit fields.
328 dw0Ignored
:= dw0
.IgnoredFieldsGet()
329 dw1Ignored
:= dw1
.IgnoredFieldsGet()
331 if config
.InfoLevelGet() != 4 {
334 if config
.InfoLevelGet() >= 3 {
335 // Add string of reference macro as a comment
336 reference
:= macro
.Get()
338 /* DW0 : PAD_TRIG(OFF) | PAD_BUF(RX_DISABLE) | 1 - IGNORED */
339 macro
.DecodeIgnored(PAD_CFG_DW0
).DecodeIgnored(PAD_CFG_DW1
)
340 if config
.InfoLevelGet() >= 4 {
341 /* PAD_CFG_NF(GPP_B23, 20K_PD, PLTRST, NF2), */
342 macro
.Add("/* ").Add(reference
).Add(" */\n\t")
345 if config
.AreFieldsIgnored() {
346 // Consider bit fields that should be ignored when regenerating
348 var tempVal
uint32 = dw0
.ValueGet() & ^dw0Ignored
349 dw0
.ValueSet(tempVal
)
351 tempVal
= dw1
.ValueGet() & ^dw1Ignored
352 dw1
.ValueSet(tempVal
)
355 macro
.Fields
.GenerateString()
359 // Generate macro for bi-directional GPIO port
360 func (macro
*Macro
) Bidirection() {
361 dw1
:= macro
.Register(PAD_CFG_DW1
)
362 ios
:= dw1
.GetIOStandbyState() != 0 || dw1
.GetIOStandbyTermination() != 0
363 macro
.Set("PAD_CFG_GPIO_BIDIRECT")
367 // PAD_CFG_GPIO_BIDIRECT(pad, val, pull, rst, trig, own)
368 macro
.Add("(").Id().Val().Pull().Rstsrc().Trig()
370 // PAD_CFG_GPIO_BIDIRECT_IOS(pad, val, pull, rst, trig, iosstate, iosterm, own)
371 macro
.IOSstate().IOTerm()
373 macro
.Own().Add("),")
377 rxDisable
uint8 = 0x2
378 txDisable
uint8 = 0x1
381 // Gets base string of current macro
382 // return: string of macro
383 func (macro
*Macro
) Generate() string {
384 dw0
:= macro
.Register(PAD_CFG_DW0
)
386 macro
.Platform
.RemmapRstSrc()
388 if dw0
.GetPadMode() == 0 {
390 switch dw0
.GetGPIORxTxDisableStatus() {
392 macro
.Platform
.GpiMacroAdd() // GPI
395 macro
.Platform
.GpoMacroAdd() // GPO
397 case rxDisable | txDisable
:
398 macro
.Platform
.NoConnMacroAdd() // NC
404 macro
.Platform
.NativeFunctionMacroAdd()
407 if config
.IsFieldsMacroUsed() {
408 // Clear control mask to generate advanced macro only
409 return macro
.GenerateFields().Get()
412 if config
.IsNonCheckingFlagUsed() {
414 if config
.InfoLevelGet() >= 3 {
415 macro
.Clear().DecodeIgnored(PAD_CFG_DW0
).DecodeIgnored(PAD_CFG_DW1
)
416 comment
:= macro
.Get()
417 if config
.InfoLevelGet() >= 4 {
418 macro
.Clear().Add("/* ")
419 macro
.Fields
.GenerateString()
421 comment
+= macro
.Get()
423 return comment
+ body
428 return macro
.check().Get()