Debian Codegraph @

util/intelp2m/platforms/cnl/cnl.go

raw symbols SCIP
1 package cnl
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 "review.coreboot.org/coreboot.git/util/intelp2m/platforms/snr"
11 )
12
13 const (
14 DW0Mask uint32 = (0b1 << 27) | (0b1 << 24) | (0b11 << 21) | (0b1111 << 16) | 0b11111100
15 DW1Mask uint32 = 0b11111101111111111100001111111111
16 )
17
18 var GPPGroups = []string{
19 "GPP_", "GPD", // "GPP_A", "GPP_B", "GPP_G", "GPP_D", "GPP_F", "GPP_H", "GPP_C", "GPP_E"
20 "I2S1_TXD", "CNV_BTEN", "CNV_GNEN", "CNV_WFEN", "CNV_WCEN", "vCNV_GNSS_HOST_WAKE_B",
21 "vSD3_CD_B", "CNV_BT_HOST_WAKE_B", "CNV_BT_IF_SELECT", "vCNV_BT_UART_TXD",
22 "vCNV_BT_UART_RXD", "vCNV_BT_UART_CTS_B", "vCNV_BT_UART_RTS_B", "vCNV_MFUART1_TXD",
23 "vCNV_MFUART1_RXD", "vCNV_MFUART1_CTS_B", "vCNV_MFUART1_RTS_B", "vCNV_GNSS_UART_TXD",
24 "vCNV_GNSS_UART_RXD", "vCNV_GNSS_UART_CTS_B", "vCNV_GNSS_UART_RTS_B", "vUART0_TXD",
25 "vUART0_RXD", "vUART0_CTS_B", "vUART0_RTS_B", "vISH_UART0_TXD", "vISH_UART0_RXD",
26 "vISH_UART0_CTS_B", "vISH_UART0_RTS_B", "vISH_UART1_TXD", "vISH_UART1_RXD",
27 "vISH_UART1_CTS_B", "vISH_UART1_RTS_B", "vCNV_BT_I2S_BCLK", "vCNV_BT_I2S_WS_SYNC",
28 "vCNV_BT_I2S_SDO", "vCNV_BT_I2S_SDI", "vSSP2_SCLK", "vSSP2_SFRM", "vSSP2_TXD",
29 "vSSP2_RXD", "SLP_LAN_B", "SLP_SUS_B", "WAKE_B", "DRAM_RESET_B", "SPI0_IO_2",
30 "SPI0_IO_3", "SPI0_MISO", "SPI0_MOSI", "SPI0_CS2_B", "SPI0_CS0_B", "SPI0_CS1_B",
31 "SPI0_CLK", "SPI0_CLK_LOOPBK", "HDACPU_SDI", "HDACPU_SDO", "HDACPU_SCLK", "PM_SYNC",
32 "PECI", "CPUPWRGD", "THRMTRIP_B", "PLTRST_CPU_B", "PM_DOWN", "TRIGGER_IN",
33 "TRIGGER_OUT", "PCH_TDO", "PCH_JTAGX", "PROC_PRDY_B", "PROC_PREQ_B", "CPU_TRST_B",
34 "PCH_TDI", "PCH_TMS", "PCH_TCK", "ITP_PMODE", "SYS_PWROK", "SYS_RESET_B", "CL_RST_B",
35 "HDA_BCLK", "HDA_RST_B", "HDA_SYNC", "HDA_SDO", "HDA_SDI0", "HDA_SDI1", "I2S1_SFRM",
36 }
37
38 var remapping = common.ResetSources{
39 0b00: bits.RstCfgRSMRST << bits.DW0PadRstCfg,
40 0b01: bits.RstCfgDEEP << bits.DW0PadRstCfg,
41 0b10: bits.RstCfgPLTRST << bits.DW0PadRstCfg,
42 }
43
44 type BasePlatform struct {
45 // based on the Sunrise platform
46 snr.BasePlatform
47 }
48
49 func InitBasePlatform(dw0, dw0mask uint32, dw1, dw1mask uint32) BasePlatform {
50 return BasePlatform{snr.InitBasePlatform(dw0, dw0mask, dw1, dw1mask)}
51 }
52
53 func GetPlatform(dw0, dw1 uint32) common.PlatformIf {
54 p := InitBasePlatform(dw0, DW0Mask, dw1, DW1Mask)
55 return &p
56 }
57
58 // Override BasePlatform.RemapResetSource()
59 func (p *BasePlatform) RemapResetSource(m *common.Macro) {
60 if strings.Contains(m.GetPadId(), "GPP_A") ||
61 strings.Contains(m.GetPadId(), "GPP_B") ||
62 strings.Contains(m.GetPadId(), "GPP_G") {
63 // See reset map for the Cannonlake Groups the Community 0:
64 // https://github.com/coreboot/coreboot/blob/master/src/soc/intel/cannonlake/gpio.c#L14
65 // remmap is not required because it is the same as common.
66 return
67 }
68 if err := p.UpdateResetSource(remapping); err != nil {
69 logs.Errorf("remap reset source for %s: %v", m.GetPadId(), err)
70 }
71 }
72
73 // Override BasePlatform.Pull()
74 func (p *BasePlatform) Pull(m *common.Macro) {
75 dw1 := p.GetRegisterDW1()
76 var pull = map[uint32]string{
77 0b0000: "NONE",
78 0b0010: "DN_5K",
79 0b0100: "DN_20K",
80 0b1001: "UP_1K",
81 0b1010: "UP_5K",
82 0b1011: "UP_2K",
83 0b1100: "UP_20K",
84 0b1101: "UP_667",
85 0b1111: "NATIVE",
86 }
87 term, valid := pull[dw1.GetTermination()]
88 if !valid {
89 term = "INVALID"
90 logs.Errorf("%s: DW1 %s: invalid termination value 0b%b",
91 dw1, m.GetPadId(), dw1.GetTermination())
92 }
93 m.Separator().Add(term)
94 }
95
96 // ioApicRoute() generate macro to cause peripheral IRQ when configured in GPIO input mode
97 func ioApicRoute(p *BasePlatform, m *common.Macro) bool {
98 dw0 := p.GetRegisterDW0()
99 if dw0.GetGPIOInputRouteIOxAPIC() == 0 {
100 return false
101 }
102
103 m.Add("_APIC")
104 // PAD_CFG_GPI_APIC(pad, pull, rst, trig, inv)
105 m.Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),")
106 return true
107 }
108
109 // nmiRoute() generate macro to cause NMI when configured in GPIO input mode
110 func nmiRoute(p *BasePlatform, m *common.Macro) bool {
111 if dw0 := p.GetRegisterDW0(); dw0.GetGPIOInputRouteNMI() == 0 {
112 return false
113 }
114 // PAD_CFG_GPI_NMI(GPIO_24, UP_20K, DEEP, LEVEL, INVERT),
115 m.Add("_NMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),")
116 return true
117 }
118
119 // sciRoute() generate macro to cause SCI when configured in GPIO input mode
120 func sciRoute(p *BasePlatform, m *common.Macro) bool {
121 if dw0 := p.GetRegisterDW0(); dw0.GetGPIOInputRouteSCI() == 0 {
122 return false
123 }
124 // PAD_CFG_GPI_SCI(pad, pull, rst, trig, inv)
125 m.Add("_SCI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),")
126 return true
127 }
128
129 // smiRoute() generates macro to cause SMI when configured in GPIO input mode
130 func smiRoute(p *BasePlatform, m *common.Macro) bool {
131 if dw0 := p.GetRegisterDW0(); dw0.GetGPIOInputRouteSMI() == 0 {
132 return false
133 }
134 // PAD_CFG_GPI_SMI(pad, pull, rst, trig, inv)
135 m.Add("_SMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),")
136 return true
137 }
138
139 // Override BasePlatform.AddGpiMacro()
140 func (p *BasePlatform) AddGpiMacro(m *common.Macro) {
141 var ids []string
142 m.Set("PAD_CFG_GPI")
143 for routeid, isRoute := range map[string]func(*BasePlatform, *common.Macro) bool{
144 "IOAPIC": ioApicRoute,
145 "SCI": sciRoute,
146 "SMI": smiRoute,
147 "NMI": nmiRoute,
148 } {
149 if isRoute(p, m) {
150 ids = append(ids, routeid)
151 }
152 }
153
154 switch argc := len(ids); argc {
155 case 0:
156 // e.g. PAD_CFG_GPI_TRIG_OWN(pad, pull, rst, trig, own)
157 m.Add("_TRIG_OWN").Add("(").Id().Pull().Rstsrc().Trig().Own().Add("),")
158 case 1:
159 // GPI with IRQ route
160 if p2m.Config.IgnoredFields {
161 // Set Host Software Ownership to ACPI mode
162 m.SetOwnershipAcpi()
163 }
164
165 case 2:
166 // PAD_CFG_GPI_DUAL_ROUTE(pad, pull, rst, trig, inv, route1, route2)
167 m.Set("PAD_CFG_GPI_DUAL_ROUTE(").Id().Pull().Rstsrc().Trig().Invert()
168 m.Add(", " + ids[0] + ", " + ids[1] + "),")
169 if p2m.Config.IgnoredFields {
170 // Set Host Software Ownership to ACPI mode
171 m.SetOwnershipAcpi()
172 }
173 default:
174 // Clear the control mask so that the check fails and "Advanced" macro is
175 // generated
176 dw0 := p.GetRegisterDW0()
177 dw0.CntrMaskFieldsClear(bits.All32)
178 }
179 }