drivers/amd/opensil/mpio: Factor out common MPIO symbols from vendorcode
[coreboot.git] / util / intelp2m / platforms / cnl / macro.go
blobae568d5096226f00997252f5c06bc96227f8d457
1 package cnl
3 import (
4 "strings"
5 "fmt"
7 "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common"
8 "review.coreboot.org/coreboot.git/util/intelp2m/config"
9 "review.coreboot.org/coreboot.git/util/intelp2m/fields"
10 "review.coreboot.org/coreboot.git/util/intelp2m/platforms/snr"
13 const (
14 PAD_CFG_DW0_RO_FIELDS = (0x1 << 27) | (0x1 << 24) | (0x3 << 21) | (0xf << 16) | 0xfc
15 PAD_CFG_DW1_RO_FIELDS = 0xfdffc3ff
18 const (
19 PAD_CFG_DW0 = common.PAD_CFG_DW0
20 PAD_CFG_DW1 = common.PAD_CFG_DW1
21 MAX_DW_NUM = common.MAX_DW_NUM
24 type InheritanceMacro interface {
25 GpoMacroAdd()
26 NativeFunctionMacroAdd()
27 NoConnMacroAdd()
30 type PlatformSpecific struct {
31 InheritanceMacro
32 InheritanceTemplate
35 // RemmapRstSrc - remmap Pad Reset Source Config
36 func (PlatformSpecific) RemmapRstSrc() {
37 macro := common.GetMacro()
38 if config.TemplateGet() != config.TempInteltool {
39 // Use reset source remapping only if the input file is inteltool.log dump
40 return
42 if strings.Contains(macro.PadIdGet(), "GPP_A") ||
43 strings.Contains(macro.PadIdGet(), "GPP_B") ||
44 strings.Contains(macro.PadIdGet(), "GPP_G") {
45 // See reset map for the Cannonlake Groups the Community 0:
46 // https://github.com/coreboot/coreboot/blob/master/src/soc/intel/cannonlake/gpio.c#L14
47 // remmap is not required because it is the same as common.
48 return
51 dw0 := macro.Register(PAD_CFG_DW0)
52 var remapping = map[uint8]uint32{
53 0: common.RST_RSMRST << common.PadRstCfgShift,
54 1: common.RST_DEEP << common.PadRstCfgShift,
55 2: common.RST_PLTRST << common.PadRstCfgShift,
57 resetsrc, valid := remapping[dw0.GetResetConfig()]
58 if valid {
59 // dw0.SetResetConfig(resetsrc)
60 ResetConfigFieldVal := (dw0.ValueGet() & 0x3fffffff) | remapping[dw0.GetResetConfig()]
61 dw0.ValueSet(ResetConfigFieldVal)
62 } else {
63 fmt.Println("Invalid Pad Reset Config [ 0x", resetsrc ," ] for ", macro.PadIdGet())
65 dw0.CntrMaskFieldsClear(common.PadRstCfgMask)
68 // Adds The Pad Termination (TERM) parameter from PAD_CFG_DW1 to the macro
69 // as a new argument
70 func (PlatformSpecific) Pull() {
71 macro := common.GetMacro()
72 dw1 := macro.Register(PAD_CFG_DW1)
73 var pull = map[uint8]string{
74 0x0: "NONE",
75 0x2: "DN_5K",
76 0x4: "DN_20K",
77 0x9: "UP_1K",
78 0xa: "UP_5K",
79 0xb: "UP_2K",
80 0xc: "UP_20K",
81 0xd: "UP_667",
82 0xf: "NATIVE",
84 str, valid := pull[dw1.GetTermination()]
85 if !valid {
86 str = "INVALID"
87 fmt.Println("Error",
88 macro.PadIdGet(),
89 " invalid TERM value = ",
90 int(dw1.GetTermination()))
92 macro.Separator().Add(str)
95 // Generate macro to cause peripheral IRQ when configured in GPIO input mode
96 func ioApicRoute() bool {
97 macro := common.GetMacro()
98 dw0 := macro.Register(PAD_CFG_DW0)
99 if dw0.GetGPIOInputRouteIOxAPIC() == 0 {
100 return false
103 macro.Add("_APIC")
104 // PAD_CFG_GPI_APIC(pad, pull, rst, trig, inv)
105 macro.Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),")
106 return true
109 // Generate macro to cause NMI when configured in GPIO input mode
110 func nmiRoute() bool {
111 macro := common.GetMacro()
112 if macro.Register(PAD_CFG_DW0).GetGPIOInputRouteNMI() == 0 {
113 return false
115 // PAD_CFG_GPI_NMI(GPIO_24, UP_20K, DEEP, LEVEL, INVERT),
116 macro.Add("_NMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),")
117 return true
120 // Generate macro to cause SCI when configured in GPIO input mode
121 func sciRoute() bool {
122 macro := common.GetMacro()
123 dw0 := macro.Register(PAD_CFG_DW0)
124 if dw0.GetGPIOInputRouteSCI() == 0 {
125 return false
127 // PAD_CFG_GPI_SCI(pad, pull, rst, trig, inv)
128 macro.Add("_SCI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),")
129 return true
132 // Generate macro to cause SMI when configured in GPIO input mode
133 func smiRoute() bool {
134 macro := common.GetMacro()
135 dw0 := macro.Register(PAD_CFG_DW0)
136 if dw0.GetGPIOInputRouteSMI() == 0 {
137 return false
139 // PAD_CFG_GPI_SMI(pad, pull, rst, trig, inv)
140 macro.Add("_SMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),")
141 return true
144 // Adds PAD_CFG_GPI macro with arguments
145 func (PlatformSpecific) GpiMacroAdd() {
146 macro := common.GetMacro()
147 var ids []string
148 macro.Set("PAD_CFG_GPI")
149 for routeid, isRoute := range map[string]func() (bool) {
150 "IOAPIC": ioApicRoute,
151 "SCI": sciRoute,
152 "SMI": smiRoute,
153 "NMI": nmiRoute,
155 if isRoute() {
156 ids = append(ids, routeid)
160 switch argc := len(ids); argc {
161 case 0:
162 // e.g. PAD_CFG_GPI_TRIG_OWN(pad, pull, rst, trig, own)
163 macro.Add("_TRIG_OWN").Add("(").Id().Pull().Rstsrc().Trig().Own().Add("),")
164 case 1:
165 // GPI with IRQ route
166 if config.AreFieldsIgnored() {
167 // Set Host Software Ownership to ACPI mode
168 macro.SetPadOwnership(common.PAD_OWN_ACPI)
171 case 2:
172 // PAD_CFG_GPI_DUAL_ROUTE(pad, pull, rst, trig, inv, route1, route2)
173 macro.Set("PAD_CFG_GPI_DUAL_ROUTE(").Id().Pull().Rstsrc().Trig().Invert()
174 macro.Add(", " + ids[0] + ", " + ids[1] + "),")
175 if config.AreFieldsIgnored() {
176 // Set Host Software Ownership to ACPI mode
177 macro.SetPadOwnership(common.PAD_OWN_ACPI)
179 default:
180 // Clear the control mask so that the check fails and "Advanced" macro is
181 // generated
182 macro.Register(PAD_CFG_DW0).CntrMaskFieldsClear(common.AllFields)
186 // Adds PAD_CFG_GPO macro with arguments
187 func (platform PlatformSpecific) GpoMacroAdd() {
188 platform.InheritanceMacro.GpoMacroAdd()
191 // Adds PAD_CFG_NF macro with arguments
192 func (platform PlatformSpecific) NativeFunctionMacroAdd() {
193 platform.InheritanceMacro.NativeFunctionMacroAdd()
196 // Adds PAD_NC macro
197 func (platform PlatformSpecific) NoConnMacroAdd() {
198 platform.InheritanceMacro.NoConnMacroAdd()
201 // GenMacro - generate pad macro
202 // dw0 : DW0 config register value
203 // dw1 : DW1 config register value
204 // return: string of macro
205 // error
206 func (PlatformSpecific) GenMacro(id string, dw0 uint32, dw1 uint32, ownership uint8) string {
207 macro := common.GetInstanceMacro(PlatformSpecific{InheritanceMacro : snr.PlatformSpecific{}},
208 fields.InterfaceGet())
209 macro.Clear()
210 macro.Register(PAD_CFG_DW0).CntrMaskFieldsClear(common.AllFields)
211 macro.Register(PAD_CFG_DW1).CntrMaskFieldsClear(common.AllFields)
212 macro.PadIdSet(id).SetPadOwnership(ownership)
213 macro.Register(PAD_CFG_DW0).ValueSet(dw0).ReadOnlyFieldsSet(PAD_CFG_DW0_RO_FIELDS)
214 macro.Register(PAD_CFG_DW1).ValueSet(dw1).ReadOnlyFieldsSet(PAD_CFG_DW1_RO_FIELDS)
215 return macro.Generate()