• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1package cnl
2
3import (
4	"strings"
5	"fmt"
6
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"
11)
12
13const (
14	PAD_CFG_DW0_RO_FIELDS = (0x1 << 27) | (0x1 << 24) | (0x3 << 21) | (0xf << 16) | 0xfc
15	PAD_CFG_DW1_RO_FIELDS = 0xfdffc3ff
16)
17
18const (
19	PAD_CFG_DW0 = common.PAD_CFG_DW0
20	PAD_CFG_DW1 = common.PAD_CFG_DW1
21	MAX_DW_NUM  = common.MAX_DW_NUM
22)
23
24type InheritanceMacro interface {
25	GpoMacroAdd()
26	NativeFunctionMacroAdd()
27	NoConnMacroAdd()
28}
29
30type PlatformSpecific struct {
31	InheritanceMacro
32	InheritanceTemplate
33}
34
35// RemmapRstSrc - remmap Pad Reset Source Config
36func (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
41	}
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
49	}
50
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,
56	}
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())
64	}
65	dw0.CntrMaskFieldsClear(common.PadRstCfgMask)
66}
67
68// Adds The Pad Termination (TERM) parameter from PAD_CFG_DW1 to the macro
69// as a new argument
70func (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",
83	}
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()))
91	}
92	macro.Separator().Add(str)
93}
94
95// Generate macro to cause peripheral IRQ when configured in GPIO input mode
96func ioApicRoute() bool {
97	macro := common.GetMacro()
98	dw0 := macro.Register(PAD_CFG_DW0)
99	if dw0.GetGPIOInputRouteIOxAPIC() == 0 {
100		return false
101	}
102
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
107}
108
109// Generate macro to cause NMI when configured in GPIO input mode
110func nmiRoute() bool {
111	macro := common.GetMacro()
112	if macro.Register(PAD_CFG_DW0).GetGPIOInputRouteNMI() == 0 {
113		return false
114	}
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
118}
119
120// Generate macro to cause SCI when configured in GPIO input mode
121func sciRoute() bool {
122	macro := common.GetMacro()
123	dw0 := macro.Register(PAD_CFG_DW0)
124	if dw0.GetGPIOInputRouteSCI() == 0 {
125		return false
126	}
127	// PAD_CFG_GPI_SCI(pad, pull, rst, trig, inv)
128	macro.Add("_SCI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),")
129	return true
130}
131
132// Generate macro to cause SMI when configured in GPIO input mode
133func smiRoute() bool {
134	macro := common.GetMacro()
135	dw0 := macro.Register(PAD_CFG_DW0)
136	if dw0.GetGPIOInputRouteSMI() == 0 {
137		return false
138	}
139	// PAD_CFG_GPI_SMI(pad, pull, rst, trig, inv)
140	macro.Add("_SMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),")
141	return true
142}
143
144// Adds PAD_CFG_GPI macro with arguments
145func (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,
154	} {
155		if isRoute() {
156			ids = append(ids, routeid)
157		}
158	}
159
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)
169		}
170
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)
178		}
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)
183	}
184}
185
186// Adds PAD_CFG_GPO macro with arguments
187func (platform PlatformSpecific) GpoMacroAdd() {
188	platform.InheritanceMacro.GpoMacroAdd()
189}
190
191// Adds PAD_CFG_NF macro with arguments
192func (platform PlatformSpecific) NativeFunctionMacroAdd() {
193	platform.InheritanceMacro.NativeFunctionMacroAdd()
194}
195
196// Adds PAD_NC macro
197func (platform PlatformSpecific) NoConnMacroAdd() {
198	platform.InheritanceMacro.NoConnMacroAdd()
199}
200
201// GenMacro - generate pad macro
202// dw0 : DW0 config register value
203// dw1 : DW1 config register value
204// return: string of macro
205//         error
206func (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()
216}
217