| 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 |
|
| 18 |
|
| 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 |
|
| 41 |
func (p *BasePlatform) RemapResetSource(m *common.Macro) { |
| 42 |
if strings.Contains(m.GetPadId(), "GPD") { |
| 43 |
|
| 44 |
|
| 45 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 87 |
m.Add("_LOW") |
| 88 |
} else { |
| 89 |
|
| 90 |
m.Add("_HIGH") |
| 91 |
} |
| 92 |
m.Add("(").Id().Pull().Rstsrc().Add("),") |
| 93 |
return true |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
m.Add("_IOS(").Id().Pull().Rstsrc().Trig().Invert().Add(", TxLASTRxE, SAME),") |
| 98 |
return true |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
func nmiRoute(p *BasePlatform, m *common.Macro) bool { |
| 103 |
if p.GetRegisterDW0().GetGPIOInputRouteNMI() == 0 { |
| 104 |
return false |
| 105 |
} |
| 106 |
|
| 107 |
m.Add("_NMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") |
| 108 |
return true |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
func sciRoute(p *BasePlatform, m *common.Macro) bool { |
| 113 |
dw0 := p.GetRegisterDW0() |
| 114 |
if dw0.GetGPIOInputRouteSCI() == 0 { |
| 115 |
return false |
| 116 |
} |
| 117 |
|
| 118 |
m.Add("_SCI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") |
| 119 |
return true |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
func smiRoute(p *BasePlatform, m *common.Macro) bool { |
| 124 |
dw0 := p.GetRegisterDW0() |
| 125 |
if dw0.GetGPIOInputRouteSMI() == 0 { |
| 126 |
return false |
| 127 |
} |
| 128 |
|
| 129 |
m.Add("_SMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),") |
| 130 |
return true |
| 131 |
} |
| 132 |
|
| 133 |
|
| 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 |
|
| 151 |
m.Add("_TRIG_OWN").Add("(").Id().Pull().Rstsrc().Trig().Own().Add("),") |
| 152 |
case 1: |
| 153 |
|
| 154 |
if p2m.Config.IgnoredFields { |
| 155 |
|
| 156 |
m.SetOwnershipAcpi() |
| 157 |
} |
| 158 |
|
| 159 |
case 2: |
| 160 |
|
| 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 |
|
| 165 |
m.SetOwnershipAcpi() |
| 166 |
} |
| 167 |
default: |
| 168 |
|
| 169 |
|
| 170 |
dw0 := p.GetRegisterDW0() |
| 171 |
dw0.CntrMaskFieldsClear(bits.All32) |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
func (p *BasePlatform) AddGpoMacro(m *common.Macro) { |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 206 |
func (p *BasePlatform) AddNativeFunctionMacro(m *common.Macro) { |
| 207 |
|
| 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 |
|
| 216 |
func (p *BasePlatform) AddNoConnMacro(m *common.Macro) { |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
dw0 := p.GetRegisterDW0() |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
if dw0.GetRXLevelEdgeConfiguration() != bits.TrigOFF { |
| 226 |
mask := bits.DW0[bits.DW0RxLevelEdgeConfiguration] |
| 227 |
dw0.CntrMaskFieldsClear(mask) |
| 228 |
} |
| 229 |
if dw0.GetResetConfig() != 1 { |
| 230 |
mask := bits.DW0[bits.DW0PadRstCfg] |
| 231 |
dw0.CntrMaskFieldsClear(mask) |
| 232 |
} |
| 233 |
m.Set("PAD_NC").Add("(").Id().Pull().Add("),") |
| 234 |
} |