| 1 | Intel Pad to Macro (intelp2m) converter |
| 2 | ======================================= |
| 3 | |
| 4 | The utility generates `output/gpio.h` with the GPIO configuration for SoC or PCH from intel. |
| 5 | Use it to create coreboot port for your motherboard in the `src/mainboard/your-motherboard` |
| 6 | directory. Depending on the settings, you can create several configuration formats: |
| 7 | - [coreboot macros](../../getting_started/gpio.md); |
| 8 | - [Intel FSP macros](../../soc/intel/fsp/index.md). |
| 9 | |
| 10 | Installing the latest version: |
| 11 | |
| 12 | ```bash |
| 13 | go install review.coreboot.org/coreboot.git/util/intelp2m@master |
| 14 | ``` |
| 15 | |
| 16 | Including in the project as an external library: |
| 17 | |
| 18 | ```bash |
| 19 | go get review.coreboot.org/coreboot.git/util/intelp2m@master |
| 20 | ``` |
| 21 | |
| 22 | ## Build |
| 23 | |
| 24 | Since the utility is written in Go, you need to install the official |
| 25 | [go-compiler and go-tools](https://go.dev/dl/) to build the executive |
| 26 | image. |
| 27 | |
| 28 | ```bash |
| 29 | cd util/intelp2m |
| 30 | make |
| 31 | ``` |
| 32 | |
| 33 | Set automatic argument completion: |
| 34 | |
| 35 | ```bash |
| 36 | complete -C `pwd`/intelp2m ./intelp2m |
| 37 | ``` |
| 38 | |
| 39 | ## Demo |
| 40 | |
| 41 | ```bash |
| 42 | ./intelp2m -platform snr -file parser/testlog/inteltool_test.log |
| 43 | ``` |
| 44 | |
| 45 | ## Input data |
| 46 | |
| 47 | The chipset register dump obtained using [inteltool](../../util.md) is used as input data. |
| 48 | |
| 49 | ```bash |
| 50 | cd util/inteltool |
| 51 | make |
| 52 | sudo ./inteltool -G > inteltool.log |
| 53 | ``` |
| 54 | |
| 55 | After this step, you can generate `gpio.h`: |
| 56 | |
| 57 | ```bash |
| 58 | ./intelp2m -file ../inteltool/inteltool.log |
| 59 | ``` |
| 60 | |
| 61 | More details in the help: |
| 62 | |
| 63 | ```bash |
| 64 | ./intelp2m -h |
| 65 | ``` |
| 66 | |
| 67 | ## Platforms |
| 68 | |
| 69 | The utility supports the following chipsets from Intel: |
| 70 | |
| 71 | * `adl` - Alder Lake PCH |
| 72 | * `apl` - Apollo Lake SoC |
| 73 | * `cnl` - CannonLake-LP or Whiskeylake/Coffeelake/Cometlake-U SoC |
| 74 | * `ebg` - Emmitsburg PCH with Xeon SP |
| 75 | * `ehl` - Elkhart Lake SoC |
| 76 | * `jsl` - Jasper Lake SoC |
| 77 | * `lbg` - Lewisburg PCH with Xeon SP |
| 78 | * `mtl` - MeteorLake SoC |
| 79 | * `snr` - Sunrise PCH or Skylake/Kaby Lake SoC |
| 80 | * `tgl` - TigerLake-H SoC |
| 81 | |
| 82 | The `-platform` option allows you to identify one of the above platforms: |
| 83 | |
| 84 | ```bash |
| 85 | ./intelp2m -platform <platform> -file path/to/inteltool.log |
| 86 | ``` |
| 87 | |
| 88 | Show more details: |
| 89 | |
| 90 | ```bash |
| 91 | ./intelp2m -platform ? |
| 92 | ``` |
| 93 | |
| 94 | ## Auto-check macro |
| 95 | |
| 96 | The utility automatically checks the bit fields of the GPIO registers before generating the macro. |
| 97 | If the bit is set to 1 in a register but isn't used in the "short" macro, the "long" macro is |
| 98 | generated. This avoids data loss in the configuration. |
| 99 | |
| 100 | ```c |
| 101 | // the "short" macro: |
| 102 | PAD_CFG_NF_IOSSTATE_IOSTERM(GPIO_39, UP_20K, DEEP, NF1, TxLASTRxE, DISPUPD), |
| 103 | |
| 104 | // the "long" macro: |
| 105 | _PAD_CFG_STRUCT(GPIO_39, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_PULL(UP_20K) | PAD_IOSTERM(DISPUPD)), |
| 106 | |
| 107 | // [*] PAD_TRIG(OFF) isn't used in the "short" macro. |
| 108 | ``` |
| 109 | |
| 110 | The option `-u`, `-unchecked` is used to disable automatic verification. |
| 111 | In this case, all macros in `gpio.h` are generated in the "short" format: |
| 112 | |
| 113 | ```c |
| 114 | ... |
| 115 | PAD_NC(GPP_F18, NONE), |
| 116 | PAD_CFG_NF(GPP_F19, NONE, PLTRST, NF1), |
| 117 | ... |
| 118 | ``` |
| 119 | |
| 120 | ```bash |
| 121 | ./intelp2m -unchecked -platform apl -file path/to/inteltool.log |
| 122 | ``` |
| 123 | |
| 124 | ## Excluding fields from the macro |
| 125 | |
| 126 | The utility can generate "long" macros without fields that aren't used in "short" ones. |
| 127 | The `-e`, `-exclude` option is used to exclude these fields from the generated macros in |
| 128 | `gpio.h`: |
| 129 | |
| 130 | ```bash |
| 131 | ./intelp2m -exclude -platform apl -file path/to/inteltool.log |
| 132 | ``` |
| 133 | |
| 134 | ```c |
| 135 | _PAD_CFG_STRUCT(GPIO_39, PAD_FUNC(NF1) | PAD_RESET(DEEP), PAD_PULL(UP_20K) | PAD_IOSTERM(DISPUPD)), |
| 136 | |
| 137 | // [*] PAD_TRIG(OFF) field was excluded from the "long" macro. |
| 138 | ``` |
| 139 | |
| 140 | ## Packages |
| 141 | |
| 142 | ```text |
| 143 | +-------------------------------------------------------------------+ |
| 144 | | main | |
| 145 | +-------------------------------------------------------------------+ |
| 146 | | | | |
| 147 | V V V |
| 148 | +------------+ +--------------+ +-------------+ +-------------+ |
| 149 | | template |<--| parser | | generator | | printer | |
| 150 | +------------+ +--------------+ +-------------+ +-------------+ |
| 151 | | |
| 152 | V |
| 153 | +-------------------------------------------------------------------+ |
| 154 | | platforms | |
| 155 | +-------------------------------------------------------------------+ |
| 156 | | | | | | | |
| 157 | V V V V V V |
| 158 | +-------+ +-------+ +-------+ +-------+ +-------+ +-------+ |
| 159 | | adl | | apl | | cnl | | lbg | | snr | * * * | other | |
| 160 | +-------+ +-------+ +-------+ +-------+ +-------+ +-------+ |
| 161 | | | | | | | |
| 162 | V V V V V V |
| 163 | +-------------------------------------------------------------------+ |
| 164 | | common | |
| 165 | +-------------------------------------------------------------------+ |
| 166 | | | | |
| 167 | V | | |
| 168 | +------------------------------------+ | | |
| 169 | | fields | | | |
| 170 | +------------------------------------+ | | |
| 171 | | | | | | |
| 172 | V V V V V |
| 173 | +--------+ +---------+ +---------+ +-----------+ +------------+ |
| 174 | | cb | | raw | | fsp | | macro | | register | |
| 175 | +--------+ +---------+ +---------+ +-----------+ +------------+ |
| 176 | ``` |
| 177 | |
| 178 | ## Format |
| 179 | |
| 180 | Depending on the options -i, -ii, -iii, -iiiii (information level), |
| 181 | the utility can generate the configuration in different formats: |
| 182 | |
| 183 | ```bash |
| 184 | ./intelp2m [-i | -ii | -iii | -iiii] -platform apl -file path/to/inteltool.log |
| 185 | ``` |
| 186 | |
| 187 | * i adding a function name: |
| 188 | |
| 189 | ```c |
| 190 | _PAD_CFG_STRUCT(GPIO_39, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_PULL(UP_20K) | PAD_IOSTERM(DISPUPD)), /* LPSS_UART0_TXD */ |
| 191 | ``` |
| 192 | |
| 193 | * ii adds configuration register values: |
| 194 | |
| 195 | ```c |
| 196 | /* GPIO_39 - LPSS_UART0_TXD */ |
| 197 | /* DW0: 0x44000400, DW1: 0x00003100 */ |
| 198 | _PAD_CFG_STRUCT(GPIO_39, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_PULL(UP_20K) | PAD_IOSTERM(DISPUPD)), |
| 199 | ``` |
| 200 | |
| 201 | * iii adds information about ignored fields: |
| 202 | |
| 203 | ```c |
| 204 | /* GPIO_39 - LPSS_UART0_TXD */ |
| 205 | /* DW0: 0x44000400, DW1: 0x00003100 */ |
| 206 | /* DW0 : PAD_TRIG(OFF) - IGNORED */ |
| 207 | _PAD_CFG_STRUCT(GPIO_39, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_PULL(UP_20K) | PAD_IOSTERM(DISPUPD)), |
| 208 | ``` |
| 209 | |
| 210 | * iiii adds the "short" macro corresponding to the current one (possibly after excluding unused fields): |
| 211 | |
| 212 | ```c |
| 213 | /* GPIO_39 - LPSS_UART0_TXD */ |
| 214 | /* DW0: 0x44000400, DW1: 0x00003100 */ |
| 215 | /* DW0: PAD_TRIG(OFF) - IGNORED */ |
| 216 | /* PAD_CFG_NF_IOSSTATE_IOSTERM(GPIO_39, UP_20K, DEEP, NF1, TxLASTRxE, DISPUPD), */ |
| 217 | _PAD_CFG_STRUCT(GPIO_39, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_PULL(UP_20K) | PAD_IOSTERM(DISPUPD)), |
| 218 | ``` |
| 219 | |
| 220 | The same without automatic check: |
| 221 | |
| 222 | ```c |
| 223 | /* GPIO_39 - LPSS_UART0_TXD */ |
| 224 | /* DW0: 0x44000400, DW1: 0x00003100 */ |
| 225 | /* DW0: PAD_TRIG(OFF) - IGNORED */ |
| 226 | /* _PAD_CFG_STRUCT(GPIO_39, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_PULL(UP_20K) | PAD_IOSTERM(DISPUPD)), */ |
| 227 | PAD_CFG_NF_IOSSTATE_IOSTERM(GPIO_39, UP_20K, DEEP, NF1, TxLASTRxE, DISPUPD), |
| 228 | ``` |
| 229 | |
| 230 | iiii generates an original macro in the comments. |
| 231 | |
| 232 | ## Long macros with fields collection |
| 233 | |
| 234 | Depending on the value of the option -fields, the utility can generate |
| 235 | long macros with different styles of the field collection: |
| 236 | |
| 237 | ```bash |
| 238 | ./intelp2m -fields [fsp | cb | raw] -platform apl -file ../apollo-inteltool.log |
| 239 | ``` |
| 240 | |
| 241 | * fsp |
| 242 | |
| 243 | ```c |
| 244 | { GPIO_SKL_H_GPP_A12, { GpioPadModeGpio, GpioHostOwnAcpi, GpioDirInInvOut, GpioOutLow, GpioIntSci | GpioIntLvlEdgDis, GpioResetNormal GpioTermNone, GpioPadConfigLock }, |
| 245 | ``` |
| 246 | |
| 247 | * cb |
| 248 | |
| 249 | ```c |
| 250 | _PAD_CFG_STRUCT(GPIO_39, PAD_FUNC(NF1) | PAD_RESET(DEEP) | PAD_TRIG(OFF), PAD_PULL(UP_20K) | PAD_IOSTERM(DISPUPD)), |
| 251 | ``` |
| 252 | |
| 253 | * raw |
| 254 | |
| 255 | ```c |
| 256 | _PAD_CFG_STRUCT(GPP_A10, 0x44000500, 0x00000000), |
| 257 | ``` |
| 258 | |
| 259 | Show more details: |
| 260 | |
| 261 | ```bash |
| 262 | ./intelp2m -fields ? |
| 263 | ``` |
| 264 | |
| 265 | ## For developers |
| 266 | |
| 267 | ### Version |
| 268 | |
| 269 | ```bash |
| 270 | ./intelp2m -version |
| 271 | ``` |
| 272 | |
| 273 | The version string includes several parts: |
| 274 | |
| 275 | ```text |
| 276 | {major}.{minor}-{last commit in the intelp2m directory}-{?dirty} |
| 277 | ``` |
| 278 | |
| 279 | `major` - incompatible API changes (e.g. remove or update a command line option); |
| 280 | `minor` - new platform, new feature or adding a new command line option. |
| 281 | |
| 282 | The version is added to the generated `gpio.h` file and it is necessary to support the project. |
| 283 | |
| 284 | ```c |
| 285 | /* Pad configuration was generated automatically using intelp2m 2.5-870c694 */ |
| 286 | static const struct pad_config gpio_table[] = { |
| 287 | ... |
| 288 | ``` |
| 289 | |
| 290 | Please do not remove this information, as it makes support easier! |
| 291 | |
| 292 | ### Adding support for new platforms |
| 293 | |
| 294 | The platform-dependent code is located in `./platforms/`. Each PCH and SoC is in a separate |
| 295 | package with a name corresponding to this platform (adl, apl, snr, ...). The macro generation |
| 296 | code for all platforms is in the `common` directory. |
| 297 | |
| 298 | The package file must contain the structure `BasePlatform struct{}` with methods for the |
| 299 | `PlatformIf interface{}` from the `common` package: |
| 300 | |
| 301 | ```Go |
| 302 | type PlatformIf interface { |
| 303 | RemapResetSource(*Macro) |
| 304 | Pull(*Macro) |
| 305 | AddGpiMacro(*Macro) |
| 306 | AddGpoMacro(*Macro) |
| 307 | AddNativeFunctionMacro(*Macro) |
| 308 | AddNoConnMacro(*Macro) |
| 309 | GetRegisterDW0() *register.DW0 |
| 310 | GetRegisterDW1() *register.DW1 |
| 311 | } |
| 312 | ``` |
| 313 | |
| 314 | Some methods (for example, register access methods: `GetRegisterDW0()` and `GetRegisterDW1()`) |
| 315 | are already defined in the base platform from `common`. Therefore, embedding should be used in |
| 316 | the basic platform structure to avoid code duplication: |
| 317 | |
| 318 | ```Go |
| 319 | type BasePlatform struct { |
| 320 | common.BasePlatform |
| 321 | } |
| 322 | ``` |
| 323 | |
| 324 | Since GPIO controllers are similar across intel platforms, the macro generation code can also be |
| 325 | reused. You can use any platform instead of `common.BasePlatform` from the catalog to reuse its |
| 326 | methods and redefine those that differ in logic. |
| 327 | |
| 328 | The platform file should also contain the slice `GPPGroups[]` with templates for pad names from |
| 329 | `inteltool.log`, register masks `DW0` and `DW1` (the analysis will be only for the bits in these |
| 330 | masks), the base platform constructor - `InitBasePlatform()`, and `GetPlatform()` that provides |
| 331 | the platform interface. |
| 332 | |
| 333 | ```Go |
| 334 | const ( |
| 335 | DW0Mask = (0b1 << 27) | (0b1 << 18) | (0b00111111 << 11) | (0b00111111 << 2) | (0b1 << 1) |
| 336 | DW1Mask = 0b11111101111111111100001111111111 |
| 337 | ) |
| 338 | |
| 339 | // "GPP_A", "GPP_B", "GPP_C", "GPP_D", "GPP_E", "GPP_F", "GPP_G", "GPP_H", "GPP_R", "GPP_S", |
| 340 | // "GPP_T", "GPD", "HVMOS", "VGPIO5" |
| 341 | var GPPGroups = []string{"GPP_", "GPD", "VGPIO"} |
| 342 | |
| 343 | type BasePlatform struct { |
| 344 | // based on the Cannon Lake platform |
| 345 | cnl.BasePlatform |
| 346 | } |
| 347 | |
| 348 | func InitBasePlatform(dw0, dw0mask uint32, dw1, dw1mask uint32) BasePlatform { |
| 349 | return BasePlatform{cnl.InitBasePlatform(dw0, dw0mask, dw1, dw1mask)} |
| 350 | } |
| 351 | |
| 352 | func GetPlatform(dw0, dw1 uint32) common.PlatformIf { |
| 353 | p := InitBasePlatform(dw0, DW0Mask, dw1, DW1Mask) |
| 354 | return &p |
| 355 | } |
| 356 | |
| 357 | // Override BasePlatform.RemapResetSource() |
| 358 | func (p *BasePlatform) RemapResetSource(m *common.Macro) { |
| 359 | // Some code is here |
| 360 | } |
| 361 | ``` |
| 362 | |
| 363 | - Use `GetPlatform()` and `GPPGroups[]` in the file `./platform/platform.go` to define the |
| 364 | resources for the parser. |
| 365 | - Add the platform argument for the options `-p` (`-platform`) to `cli/options.go`. |
| 366 | - Update the documentation in `Documentation/util/intelp2m/index.md`. |
| 367 | - Add unit tests. |
| 368 | |
| 369 | [Here](https://review.coreboot.org/c/coreboot/+/84191) is an example of porting the Intel |
| 370 | Jasper lake platform. |
| 371 | |
| 372 | ### Unit testing |
| 373 | |
| 374 | Please run the tests before creating a new commit: |
| 375 | |
| 376 | ```bash |
| 377 | make test |
| 378 | ``` |
| 379 | |
| 380 | If successful, all tests contain the PASS prefix. |