Lee Leahy | 4dd34ee | 2016-05-02 14:31:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2016 Intel Corp. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied wacbmem_entryanty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #define __SIMPLE_DEVICE__ |
| 17 | |
Lee Leahy | 14d0926 | 2016-07-21 09:17:10 -0700 | [diff] [blame] | 18 | #include <assert.h> |
Lee Leahy | ae738ac | 2016-07-24 08:03:37 -0700 | [diff] [blame] | 19 | #include <cpu/x86/mtrr.h> |
Lee Leahy | 4dd34ee | 2016-05-02 14:31:02 -0700 | [diff] [blame] | 20 | #include <console/console.h> |
| 21 | #include <soc/pci_devs.h> |
Lee Leahy | 5ef051a | 2016-04-29 15:16:54 -0700 | [diff] [blame] | 22 | #include <soc/ramstage.h> |
Lee Leahy | 4dd34ee | 2016-05-02 14:31:02 -0700 | [diff] [blame] | 23 | |
Lee Leahy | 7f4b053 | 2016-05-22 11:52:28 -0700 | [diff] [blame] | 24 | static uint16_t get_gpe0_address(uint32_t reg_address) |
| 25 | { |
| 26 | uint32_t gpe0_base_address; |
| 27 | |
| 28 | /* Get the GPE0 base address */ |
| 29 | gpe0_base_address = pci_read_config32(LPC_BDF, R_QNC_LPC_GPE0BLK); |
| 30 | ASSERT (gpe0_base_address >= 0x80000000); |
| 31 | gpe0_base_address &= B_QNC_LPC_GPE0BLK_MASK; |
| 32 | |
| 33 | /* Return the GPE0 register address */ |
| 34 | return (uint16_t)(gpe0_base_address + reg_address); |
| 35 | } |
| 36 | |
Lee Leahy | ac690b1 | 2016-05-15 15:12:56 -0700 | [diff] [blame] | 37 | static uint32_t *get_gpio_address(uint32_t reg_address) |
| 38 | { |
| 39 | uint32_t gpio_base_address; |
| 40 | |
| 41 | /* Get the GPIO base address */ |
| 42 | gpio_base_address = pci_read_config32(I2CGPIO_BDF, PCI_BASE_ADDRESS_1); |
| 43 | gpio_base_address &= ~PCI_BASE_ADDRESS_MEM_ATTR_MASK; |
| 44 | ASSERT (gpio_base_address != 0x00000000); |
| 45 | |
| 46 | /* Return the GPIO register address */ |
| 47 | return (uint32_t *)(gpio_base_address + reg_address); |
| 48 | } |
| 49 | |
| 50 | void *get_i2c_address(void) |
| 51 | { |
| 52 | uint32_t gpio_base_address; |
| 53 | |
| 54 | /* Get the GPIO base address */ |
| 55 | gpio_base_address = pci_read_config32(I2CGPIO_BDF, PCI_BASE_ADDRESS_0); |
| 56 | gpio_base_address &= ~PCI_BASE_ADDRESS_MEM_ATTR_MASK; |
| 57 | ASSERT (gpio_base_address != 0x00000000); |
| 58 | |
| 59 | /* Return the GPIO register address */ |
| 60 | return (void *)gpio_base_address; |
| 61 | } |
| 62 | |
| 63 | static uint16_t get_legacy_gpio_address(uint32_t reg_address) |
| 64 | { |
| 65 | uint32_t gpio_base_address; |
| 66 | |
| 67 | /* Get the GPIO base address */ |
| 68 | gpio_base_address = pci_read_config32(LPC_BDF, R_QNC_LPC_GBA_BASE); |
| 69 | ASSERT (gpio_base_address >= 0x80000000); |
| 70 | gpio_base_address &= B_QNC_LPC_GPA_BASE_MASK; |
| 71 | |
| 72 | /* Return the GPIO register address */ |
| 73 | return (uint16_t)(gpio_base_address + reg_address); |
| 74 | } |
| 75 | |
Lee Leahy | ae738ac | 2016-07-24 08:03:37 -0700 | [diff] [blame] | 76 | static uint32_t mtrr_index_to_host_bridge_register_offset(unsigned long index) |
| 77 | { |
| 78 | uint32_t offset; |
| 79 | |
| 80 | /* Convert from MTRR index to host brigde offset (Datasheet 12.7.2) */ |
| 81 | if (index == MTRR_CAP_MSR) |
| 82 | offset = QUARK_NC_HOST_BRIDGE_IA32_MTRR_CAP; |
| 83 | else if (index == MTRR_DEF_TYPE_MSR) |
| 84 | offset = QUARK_NC_HOST_BRIDGE_IA32_MTRR_DEF_TYPE; |
| 85 | else if (index == MTRR_FIX_64K_00000) |
| 86 | offset = QUARK_NC_HOST_BRIDGE_MTRR_FIX64K_00000; |
| 87 | else if ((index >= MTRR_FIX_16K_80000) && (index <= MTRR_FIX_16K_A0000)) |
| 88 | offset = ((index - MTRR_FIX_16K_80000) << 1) |
| 89 | + QUARK_NC_HOST_BRIDGE_MTRR_FIX16K_80000; |
| 90 | else if ((index >= MTRR_FIX_4K_C0000) && (index <= MTRR_FIX_4K_F8000)) |
| 91 | offset = ((index - MTRR_FIX_4K_C0000) << 1) |
| 92 | + QUARK_NC_HOST_BRIDGE_IA32_MTRR_PHYSBASE0; |
| 93 | else if ((index >= MTRR_PHYS_BASE(0)) && (index <= MTRR_PHYS_MASK(7))) |
| 94 | offset = (index - MTRR_PHYS_BASE(0)) |
| 95 | + QUARK_NC_HOST_BRIDGE_IA32_MTRR_PHYSBASE0; |
| 96 | else { |
| 97 | printk(BIOS_DEBUG, "index: 0x%08lx\n", index); |
| 98 | die("Invalid MTRR index specified!\n"); |
| 99 | } |
| 100 | return offset; |
| 101 | } |
| 102 | |
Lee Leahy | 4dd34ee | 2016-05-02 14:31:02 -0700 | [diff] [blame] | 103 | void mcr_write(uint8_t opcode, uint8_t port, uint32_t reg_address) |
| 104 | { |
| 105 | pci_write_config32(MC_BDF, QNC_ACCESS_PORT_MCR, |
| 106 | (opcode << QNC_MCR_OP_OFFSET) |
| 107 | | ((uint32_t)port << QNC_MCR_PORT_OFFSET) |
| 108 | | ((reg_address & QNC_MCR_MASK) << QNC_MCR_REG_OFFSET) |
| 109 | | QNC_MCR_BYTE_ENABLES); |
| 110 | } |
| 111 | |
| 112 | uint32_t mdr_read(void) |
| 113 | { |
| 114 | return pci_read_config32(MC_BDF, QNC_ACCESS_PORT_MDR); |
| 115 | } |
| 116 | |
| 117 | void mdr_write(uint32_t value) |
| 118 | { |
| 119 | pci_write_config32(MC_BDF, QNC_ACCESS_PORT_MDR, value); |
| 120 | } |
| 121 | |
| 122 | void mea_write(uint32_t reg_address) |
| 123 | { |
| 124 | pci_write_config32(MC_BDF, QNC_ACCESS_PORT_MEA, reg_address |
| 125 | & QNC_MEA_MASK); |
| 126 | } |
| 127 | |
Lee Leahy | ae738ac | 2016-07-24 08:03:37 -0700 | [diff] [blame] | 128 | uint32_t port_reg_read(uint8_t port, uint32_t offset) |
| 129 | { |
| 130 | /* Read the port register */ |
| 131 | mea_write(offset); |
| 132 | mcr_write(QUARK_OPCODE_READ, port, offset); |
| 133 | return mdr_read(); |
| 134 | } |
| 135 | |
| 136 | void port_reg_write(uint8_t port, uint32_t offset, uint32_t value) |
| 137 | { |
| 138 | /* Write the port register */ |
| 139 | mea_write(offset); |
| 140 | mdr_write(value); |
| 141 | mcr_write(QUARK_OPCODE_WRITE, port, offset); |
| 142 | } |
| 143 | |
Lee Leahy | 5fafc6a | 2016-07-30 18:21:53 -0700 | [diff] [blame] | 144 | static CRx_TYPE reg_cpu_cr_read(uint32_t reg_address) |
| 145 | { |
| 146 | /* Read the CPU CRx register */ |
| 147 | switch(reg_address) { |
| 148 | case 0: |
| 149 | return read_cr0(); |
| 150 | |
| 151 | case 4: |
| 152 | return read_cr4(); |
| 153 | } |
| 154 | die("ERROR - Unsupported CPU register!\n"); |
| 155 | } |
| 156 | |
| 157 | static void reg_cpu_cr_write(uint32_t reg_address, CRx_TYPE value) |
| 158 | { |
| 159 | /* Write the CPU CRx register */ |
| 160 | switch(reg_address) { |
| 161 | default: |
| 162 | die("ERROR - Unsupported CPU register!\n"); |
| 163 | |
| 164 | case 0: |
| 165 | write_cr0(value); |
| 166 | |
| 167 | case 4: |
| 168 | write_cr4(value); |
| 169 | } |
| 170 | } |
| 171 | |
Lee Leahy | 7f4b053 | 2016-05-22 11:52:28 -0700 | [diff] [blame] | 172 | static uint32_t reg_gpe0_read(uint32_t reg_address) |
| 173 | { |
| 174 | /* Read the GPE0 register */ |
| 175 | return inl(get_gpe0_address(reg_address)); |
| 176 | } |
| 177 | |
| 178 | static void reg_gpe0_write(uint32_t reg_address, uint32_t value) |
| 179 | { |
| 180 | /* Write the GPE0 register */ |
| 181 | outl(get_gpe0_address(reg_address), value); |
| 182 | } |
| 183 | |
Lee Leahy | 083da16 | 2016-05-15 13:32:24 -0700 | [diff] [blame] | 184 | static uint32_t reg_gpio_read(uint32_t reg_address) |
| 185 | { |
| 186 | /* Read the GPIO register */ |
| 187 | return *get_gpio_address(reg_address); |
| 188 | } |
| 189 | |
| 190 | static void reg_gpio_write(uint32_t reg_address, uint32_t value) |
| 191 | { |
| 192 | /* Write the GPIO register */ |
| 193 | *get_gpio_address(reg_address) = value; |
| 194 | } |
| 195 | |
Lee Leahy | 660c67a | 2016-07-10 17:09:24 -0700 | [diff] [blame] | 196 | uint32_t reg_host_bridge_unit_read(uint32_t reg_address) |
| 197 | { |
| 198 | /* Read the host bridge register */ |
| 199 | mea_write(reg_address); |
| 200 | mcr_write(QUARK_OPCODE_READ, QUARK_NC_HOST_BRIDGE_SB_PORT_ID, |
| 201 | reg_address); |
| 202 | return mdr_read(); |
| 203 | } |
| 204 | |
| 205 | static void reg_host_bridge_unit_write(uint32_t reg_address, uint32_t value) |
| 206 | { |
| 207 | /* Write the host bridge register */ |
| 208 | mea_write(reg_address); |
| 209 | mdr_write(value); |
| 210 | mcr_write(QUARK_OPCODE_WRITE, QUARK_NC_HOST_BRIDGE_SB_PORT_ID, |
| 211 | reg_address); |
| 212 | } |
| 213 | |
Lee Leahy | 083da16 | 2016-05-15 13:32:24 -0700 | [diff] [blame] | 214 | uint32_t reg_legacy_gpio_read(uint32_t reg_address) |
| 215 | { |
| 216 | /* Read the legacy GPIO register */ |
| 217 | return inl(get_legacy_gpio_address(reg_address)); |
| 218 | } |
| 219 | |
| 220 | void reg_legacy_gpio_write(uint32_t reg_address, uint32_t value) |
| 221 | { |
| 222 | /* Write the legacy GPIO register */ |
| 223 | outl(value, get_legacy_gpio_address(reg_address)); |
| 224 | } |
| 225 | |
Lee Leahy | 5ef051a | 2016-04-29 15:16:54 -0700 | [diff] [blame] | 226 | static uint32_t reg_pcie_afe_read(uint32_t reg_address) |
| 227 | { |
| 228 | /* Read the PCIE AFE register */ |
| 229 | mea_write(reg_address); |
| 230 | mcr_write(QUARK_OPCODE_IO_READ, QUARK_SC_PCIE_AFE_SB_PORT_ID, |
| 231 | reg_address); |
| 232 | return mdr_read(); |
| 233 | } |
| 234 | |
| 235 | static void reg_pcie_afe_write(uint32_t reg_address, uint32_t value) |
| 236 | { |
| 237 | /* Write the PCIE AFE register */ |
| 238 | mea_write(reg_address); |
| 239 | mdr_write(value); |
| 240 | mcr_write(QUARK_OPCODE_IO_WRITE, QUARK_SC_PCIE_AFE_SB_PORT_ID, |
| 241 | reg_address); |
| 242 | } |
| 243 | |
Lee Leahy | 63e3dff | 2016-04-30 08:48:52 -0700 | [diff] [blame] | 244 | uint32_t reg_rmu_temp_read(uint32_t reg_address) |
| 245 | { |
| 246 | /* Read the RMU temperature register */ |
| 247 | mea_write(reg_address); |
| 248 | mcr_write(QUARK_OPCODE_READ, QUARK_NC_RMU_SB_PORT_ID, reg_address); |
| 249 | return mdr_read(); |
| 250 | } |
| 251 | |
| 252 | static void reg_rmu_temp_write(uint32_t reg_address, uint32_t value) |
| 253 | { |
| 254 | /* Write the RMU temperature register */ |
| 255 | mea_write(reg_address); |
| 256 | mdr_write(value); |
| 257 | mcr_write(QUARK_OPCODE_WRITE, QUARK_NC_RMU_SB_PORT_ID, reg_address); |
| 258 | } |
| 259 | |
| 260 | static uint32_t reg_soc_unit_read(uint32_t reg_address) |
| 261 | { |
| 262 | /* Read the temperature sensor register */ |
| 263 | mea_write(reg_address); |
| 264 | mcr_write(QUARK_ALT_OPCODE_READ, QUARK_SCSS_SOC_UNIT_SB_PORT_ID, |
| 265 | reg_address); |
| 266 | return mdr_read(); |
| 267 | } |
| 268 | |
| 269 | static void reg_soc_unit_write(uint32_t reg_address, uint32_t value) |
| 270 | { |
| 271 | /* Write the temperature sensor register */ |
| 272 | mea_write(reg_address); |
| 273 | mdr_write(value); |
| 274 | mcr_write(QUARK_ALT_OPCODE_WRITE, QUARK_SCSS_SOC_UNIT_SB_PORT_ID, |
| 275 | reg_address); |
| 276 | } |
| 277 | |
Lee Leahy | 4dd34ee | 2016-05-02 14:31:02 -0700 | [diff] [blame] | 278 | static uint32_t reg_usb_read(uint32_t reg_address) |
| 279 | { |
| 280 | /* Read the USB register */ |
| 281 | mea_write(reg_address); |
| 282 | mcr_write(QUARK_ALT_OPCODE_READ, QUARK_SC_USB_AFE_SB_PORT_ID, |
| 283 | reg_address); |
| 284 | return mdr_read(); |
| 285 | } |
| 286 | |
| 287 | static void reg_usb_write(uint32_t reg_address, uint32_t value) |
| 288 | { |
| 289 | /* Write the USB register */ |
| 290 | mea_write(reg_address); |
| 291 | mdr_write(value); |
| 292 | mcr_write(QUARK_ALT_OPCODE_WRITE, QUARK_SC_USB_AFE_SB_PORT_ID, |
| 293 | reg_address); |
| 294 | } |
| 295 | |
| 296 | static uint64_t reg_read(struct reg_script_context *ctx) |
| 297 | { |
| 298 | const struct reg_script *step = ctx->step; |
| 299 | uint64_t value = 0; |
| 300 | |
| 301 | switch (step->id) { |
| 302 | default: |
| 303 | printk(BIOS_ERR, |
| 304 | "ERROR - Unknown register set (0x%08x)!\n", |
| 305 | step->id); |
| 306 | ctx->display_features = REG_SCRIPT_DISPLAY_NOTHING; |
| 307 | return 0; |
| 308 | |
Lee Leahy | 5fafc6a | 2016-07-30 18:21:53 -0700 | [diff] [blame] | 309 | case CPU_CR: |
| 310 | ctx->display_prefix = "CPU CR"; |
| 311 | value = reg_cpu_cr_read(step->reg); |
| 312 | break; |
| 313 | |
Lee Leahy | 7f4b053 | 2016-05-22 11:52:28 -0700 | [diff] [blame] | 314 | case GPE0_REGS: |
Lee Leahy | 6b24dfc | 2016-05-22 16:24:36 -0700 | [diff] [blame] | 315 | ctx->display_prefix = "GPE0"; |
Lee Leahy | 7f4b053 | 2016-05-22 11:52:28 -0700 | [diff] [blame] | 316 | value = reg_gpe0_read(step->reg); |
| 317 | break; |
| 318 | |
Lee Leahy | 083da16 | 2016-05-15 13:32:24 -0700 | [diff] [blame] | 319 | case GPIO_REGS: |
Lee Leahy | 6b24dfc | 2016-05-22 16:24:36 -0700 | [diff] [blame] | 320 | ctx->display_prefix = "GPIO"; |
Lee Leahy | 083da16 | 2016-05-15 13:32:24 -0700 | [diff] [blame] | 321 | value = reg_gpio_read(step->reg); |
| 322 | break; |
| 323 | |
Lee Leahy | 660c67a | 2016-07-10 17:09:24 -0700 | [diff] [blame] | 324 | case HOST_BRIDGE: |
| 325 | ctx->display_prefix = "Host Bridge"; |
| 326 | value = reg_host_bridge_unit_read(step->reg); |
| 327 | break; |
| 328 | |
Lee Leahy | 083da16 | 2016-05-15 13:32:24 -0700 | [diff] [blame] | 329 | case LEG_GPIO_REGS: |
Lee Leahy | 6b24dfc | 2016-05-22 16:24:36 -0700 | [diff] [blame] | 330 | ctx->display_prefix = "Legacy GPIO"; |
Lee Leahy | 083da16 | 2016-05-15 13:32:24 -0700 | [diff] [blame] | 331 | value = reg_legacy_gpio_read(step->reg); |
Lee Leahy | b0672402 | 2016-07-18 10:39:55 -0700 | [diff] [blame] | 332 | break; |
Lee Leahy | 5ef051a | 2016-04-29 15:16:54 -0700 | [diff] [blame] | 333 | |
| 334 | case PCIE_AFE_REGS: |
Lee Leahy | 6b24dfc | 2016-05-22 16:24:36 -0700 | [diff] [blame] | 335 | ctx->display_prefix = "PCIe AFE"; |
Lee Leahy | 5ef051a | 2016-04-29 15:16:54 -0700 | [diff] [blame] | 336 | value = reg_pcie_afe_read(step->reg); |
Lee Leahy | 083da16 | 2016-05-15 13:32:24 -0700 | [diff] [blame] | 337 | break; |
| 338 | |
Lee Leahy | 63e3dff | 2016-04-30 08:48:52 -0700 | [diff] [blame] | 339 | case RMU_TEMP_REGS: |
| 340 | ctx->display_prefix = "RMU TEMP"; |
| 341 | value = reg_rmu_temp_read(step->reg); |
| 342 | break; |
| 343 | |
| 344 | case SOC_UNIT_REGS: |
| 345 | ctx->display_prefix = "SOC Unit"; |
| 346 | value = reg_soc_unit_read(step->reg); |
| 347 | break; |
| 348 | |
Lee Leahy | 4dd34ee | 2016-05-02 14:31:02 -0700 | [diff] [blame] | 349 | case USB_PHY_REGS: |
| 350 | ctx->display_prefix = "USB PHY"; |
| 351 | value = reg_usb_read(step->reg); |
| 352 | break; |
| 353 | } |
| 354 | return value; |
| 355 | } |
| 356 | |
| 357 | static void reg_write(struct reg_script_context *ctx) |
| 358 | { |
| 359 | const struct reg_script *step = ctx->step; |
| 360 | |
| 361 | switch (step->id) { |
| 362 | default: |
| 363 | printk(BIOS_ERR, |
| 364 | "ERROR - Unknown register set (0x%08x)!\n", |
| 365 | step->id); |
| 366 | ctx->display_features = REG_SCRIPT_DISPLAY_NOTHING; |
| 367 | return; |
| 368 | |
Lee Leahy | 5fafc6a | 2016-07-30 18:21:53 -0700 | [diff] [blame] | 369 | case CPU_CR: |
| 370 | ctx->display_prefix = "CPU CR"; |
| 371 | reg_cpu_cr_write(step->reg, step->value); |
| 372 | break; |
| 373 | |
Lee Leahy | 7f4b053 | 2016-05-22 11:52:28 -0700 | [diff] [blame] | 374 | case GPE0_REGS: |
Lee Leahy | 6b24dfc | 2016-05-22 16:24:36 -0700 | [diff] [blame] | 375 | ctx->display_prefix = "GPE0"; |
Lee Leahy | 7f4b053 | 2016-05-22 11:52:28 -0700 | [diff] [blame] | 376 | reg_gpe0_write(step->reg, (uint32_t)step->value); |
| 377 | break; |
| 378 | |
Lee Leahy | 083da16 | 2016-05-15 13:32:24 -0700 | [diff] [blame] | 379 | case GPIO_REGS: |
Lee Leahy | 6b24dfc | 2016-05-22 16:24:36 -0700 | [diff] [blame] | 380 | ctx->display_prefix = "GPIO"; |
Lee Leahy | 083da16 | 2016-05-15 13:32:24 -0700 | [diff] [blame] | 381 | reg_gpio_write(step->reg, (uint32_t)step->value); |
| 382 | break; |
| 383 | |
Lee Leahy | 660c67a | 2016-07-10 17:09:24 -0700 | [diff] [blame] | 384 | case HOST_BRIDGE: |
| 385 | ctx->display_prefix = "Host Bridge"; |
| 386 | reg_host_bridge_unit_write(step->reg, (uint32_t)step->value); |
| 387 | break; |
| 388 | |
Lee Leahy | 083da16 | 2016-05-15 13:32:24 -0700 | [diff] [blame] | 389 | case LEG_GPIO_REGS: |
Lee Leahy | 6b24dfc | 2016-05-22 16:24:36 -0700 | [diff] [blame] | 390 | ctx->display_prefix = "Legacy GPIO"; |
Lee Leahy | 083da16 | 2016-05-15 13:32:24 -0700 | [diff] [blame] | 391 | reg_legacy_gpio_write(step->reg, (uint32_t)step->value); |
| 392 | break; |
| 393 | |
Lee Leahy | 5ef051a | 2016-04-29 15:16:54 -0700 | [diff] [blame] | 394 | case PCIE_AFE_REGS: |
Lee Leahy | 6b24dfc | 2016-05-22 16:24:36 -0700 | [diff] [blame] | 395 | ctx->display_prefix = "PCIe AFE"; |
Lee Leahy | 5ef051a | 2016-04-29 15:16:54 -0700 | [diff] [blame] | 396 | reg_pcie_afe_write(step->reg, (uint32_t)step->value); |
| 397 | break; |
| 398 | |
| 399 | case PCIE_RESET: |
| 400 | if (ctx->display_features) { |
Lee Leahy | 6b24dfc | 2016-05-22 16:24:36 -0700 | [diff] [blame] | 401 | ctx->display_prefix = "PCIe reset"; |
Lee Leahy | 5ef051a | 2016-04-29 15:16:54 -0700 | [diff] [blame] | 402 | ctx->display_features &= ~REG_SCRIPT_DISPLAY_REGISTER; |
| 403 | } |
| 404 | mainboard_gpio_pcie_reset(step->value); |
| 405 | break; |
| 406 | |
Lee Leahy | 63e3dff | 2016-04-30 08:48:52 -0700 | [diff] [blame] | 407 | case RMU_TEMP_REGS: |
| 408 | ctx->display_prefix = "RMU TEMP"; |
| 409 | reg_rmu_temp_write(step->reg, (uint32_t)step->value); |
| 410 | break; |
| 411 | |
| 412 | case SOC_UNIT_REGS: |
| 413 | ctx->display_prefix = "SOC Unit"; |
| 414 | reg_soc_unit_write(step->reg, (uint32_t)step->value); |
| 415 | break; |
| 416 | |
Lee Leahy | 4c3f5dc | 2016-04-29 16:36:02 -0700 | [diff] [blame] | 417 | case MICROSECOND_DELAY: |
| 418 | /* The actual delay is >= the requested delay */ |
| 419 | if (ctx->display_features) { |
| 420 | /* Higher baud-rates will reduce the impact of displaying this message */ |
| 421 | printk(BIOS_INFO, "Delay %lld uSec\n", step->value); |
| 422 | ctx->display_features = REG_SCRIPT_DISPLAY_NOTHING; |
| 423 | } |
| 424 | udelay(step->value); |
| 425 | break; |
| 426 | |
Lee Leahy | 4dd34ee | 2016-05-02 14:31:02 -0700 | [diff] [blame] | 427 | case USB_PHY_REGS: |
| 428 | ctx->display_prefix = "USB PHY"; |
| 429 | reg_usb_write(step->reg, (uint32_t)step->value); |
| 430 | break; |
| 431 | } |
| 432 | } |
| 433 | |
Lee Leahy | ae738ac | 2016-07-24 08:03:37 -0700 | [diff] [blame] | 434 | msr_t soc_msr_read(unsigned index) |
| 435 | { |
| 436 | uint32_t offset; |
| 437 | union { |
| 438 | uint64_t u64; |
| 439 | msr_t msr; |
| 440 | } value; |
| 441 | |
| 442 | /* Read the low 32-bits of the register */ |
| 443 | offset = mtrr_index_to_host_bridge_register_offset(index); |
| 444 | value.u64 = port_reg_read(QUARK_NC_HOST_BRIDGE_SB_PORT_ID, offset); |
| 445 | |
| 446 | /* For 64-bit registers, read the upper 32-bits */ |
| 447 | if ((offset >= QUARK_NC_HOST_BRIDGE_MTRR_FIX64K_00000) |
| 448 | && (offset <= QUARK_NC_HOST_BRIDGE_MTRR_FIX4K_F8000)) { |
| 449 | offset += 1; |
| 450 | value.u64 |= port_reg_read(QUARK_NC_HOST_BRIDGE_SB_PORT_ID, |
| 451 | offset); |
| 452 | } |
| 453 | return value.msr; |
| 454 | } |
| 455 | |
| 456 | void soc_msr_write(unsigned index, msr_t msr) |
| 457 | { |
| 458 | uint32_t offset; |
| 459 | union { |
| 460 | uint32_t u32[2]; |
| 461 | msr_t msr; |
| 462 | } value; |
| 463 | |
| 464 | /* Write the low 32-bits of the register */ |
| 465 | value.msr = msr; |
| 466 | offset = mtrr_index_to_host_bridge_register_offset(index); |
| 467 | port_reg_write(QUARK_NC_HOST_BRIDGE_SB_PORT_ID, offset, value.u32[0]); |
| 468 | |
| 469 | /* For 64-bit registers, write the upper 32-bits */ |
| 470 | if ((offset >= QUARK_NC_HOST_BRIDGE_MTRR_FIX64K_00000) |
| 471 | && (offset <= QUARK_NC_HOST_BRIDGE_MTRR_FIX4K_F8000)) { |
| 472 | offset += 1; |
| 473 | port_reg_write(QUARK_NC_HOST_BRIDGE_SB_PORT_ID, offset, |
| 474 | value.u32[1]); |
| 475 | } |
| 476 | } |
| 477 | |
Lee Leahy | 4dd34ee | 2016-05-02 14:31:02 -0700 | [diff] [blame] | 478 | const struct reg_script_bus_entry soc_reg_script_bus_table = { |
| 479 | SOC_TYPE, reg_read, reg_write |
| 480 | }; |
| 481 | |
| 482 | REG_SCRIPT_BUS_ENTRY(soc_reg_script_bus_table); |