1package fsp 2 3import "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" 4 5type FieldMacros struct {} 6 7// field - data structure for creating a new bitfield macro object 8// configmap : map to select the current configuration 9// value : the key value in the configmap 10// override : overrides the function to generate the current bitfield macro 11type field struct { 12 configmap map[uint8]string 13 value uint8 14 override func(configuration map[uint8]string, value uint8) 15} 16 17// generate - wrapper for generating bitfield macros string 18// fields : field structure 19func generate(fields ...*field) { 20 macro := common.GetMacro() 21 for _, field := range fields { 22 if field.override != nil { 23 // override if necessary 24 field.override(field.configmap, field.value) 25 continue 26 } 27 28 fieldmacro, valid := field.configmap[field.value] 29 if valid { 30 macro.Add(fieldmacro).Add(", ") 31 } else { 32 macro.Add("INVALID, ") 33 } 34 } 35} 36 37// DecodeDW0 - decode value of DW0 register 38func (FieldMacros) DecodeDW0() { 39 macro := common.GetMacro() 40 dw0 := macro.Register(common.PAD_CFG_DW0) 41 42 ownershipStatus := func() uint8 { 43 if macro.IsOwnershipDriver() { return 1 } 44 return 0 45 } 46 47 generate( 48 &field { 49 configmap : map[uint8]string{ 50 0: "GpioPadModeGpio", 51 1: "GpioPadModeNative1", 52 2: "GpioPadModeNative2", 53 3: "GpioPadModeNative3", 54 4: "GpioPadModeNative4", 55 5: "GpioPadModeNative5", 56 }, 57 value : dw0.GetPadMode(), 58 }, 59 60 &field { 61 configmap : map[uint8]string { 62 0: "GpioHostOwnAcpi", 63 1: "GpioHostOwnGpio", 64 }, 65 value : ownershipStatus(), 66 }, 67 68 &field { 69 configmap : map[uint8]string { 70 0: "GpioDirInOut", 71 1: "GpioDirIn", 72 2: "GpioDirOut", 73 3: "GpioDirNone", 74 1 << 4 | 0: "GpioDirInInvOut", 75 1 << 4 | 1: "GpioDirInInv", 76 }, 77 value : dw0.GetRxInvert() << 4 | dw0.GetGPIORxTxDisableStatus(), 78 }, 79 80 &field { 81 configmap : map[uint8]string { 82 0: "GpioOutLow", 83 1: "GpioOutHigh", 84 }, 85 value : dw0.GetGPIOTXState(), 86 }, 87 88 &field { 89 configmap : map[uint8]string { 90 1 << 0: "GpioIntNmi", 91 1 << 1: "GpioIntSmi", 92 1 << 2: "GpioIntSci", 93 1 << 3: "GpioIntApic", 94 }, 95 override : func(configmap map[uint8]string, value uint8) { 96 mask := dw0.GetGPIOInputRouteIOxAPIC() << 3 | 97 dw0.GetGPIOInputRouteSCI() << 2 | 98 dw0.GetGPIOInputRouteSMI() << 1 | 99 dw0.GetGPIOInputRouteNMI() 100 if mask == 0 { 101 macro.Add("GpioIntDis | ") 102 return 103 } 104 for bit, fieldmacro := range configmap { 105 if mask & bit != 0 { 106 macro.Add(fieldmacro).Add(" | ") 107 } 108 } 109 }, 110 }, 111 112 &field { 113 configmap : map[uint8]string { 114 0: "GpioIntLevel", 115 1: "GpioIntEdge", 116 2: "GpioIntLvlEdgDis", 117 3: "GpioIntBothEdge", 118 }, 119 value : dw0.GetRXLevelEdgeConfiguration(), 120 }, 121 122 &field { 123 configmap : map[uint8]string { 124 0: "GpioResetPwrGood", // TODO: Has multiple values (to GPP and GPD) 125 1: "GpioHostDeepReset", 126 2: "GpioPlatformReset", 127 3: "GpioResumeReset", 128 }, 129 value : dw0.GetResetConfig(), 130 }, 131 ) 132} 133 134// DecodeDW1 - decode value of DW1 register 135func (FieldMacros) DecodeDW1() { 136 macro := common.GetMacro() 137 dw1 := macro.Register(common.PAD_CFG_DW1) 138 generate( 139 &field { 140 override : func(configmap map[uint8]string, value uint8) { 141 if dw1.GetPadTol() != 0 { 142 macro.Add("GpioTolerance1v8 | ") 143 } 144 }, 145 }, 146 147 &field { 148 configmap : map[uint8]string { 149 0x0: "GpioTermNone", 150 0x2: "GpioTermWpd5K", 151 0x4: "GpioTermWpd20K", 152 0x9: "GpioTermWpu1K", 153 0xa: "GpioTermWpu5K", 154 0xb: "GpioTermWpu2K", 155 0xc: "GpioTermWpu20K", 156 0xd: "GpioTermWpu1K2K", 157 0xf: "GpioTermNative", 158 }, 159 value : dw1.GetTermination(), 160 }, 161 ) 162} 163 164// GenerateString - generates the entire string of bitfield macros. 165func (bitfields FieldMacros) GenerateString() { 166 macro := common.GetMacro() 167 macro.Add("{ GPIO_SKL_H_").Id().Add(", { ") 168 bitfields.DecodeDW0() 169 bitfields.DecodeDW1() 170 macro.Add(" GpioPadConfigLock } },") // TODO: configure GpioPadConfigLock 171} 172