0003-haswell-lynxpoint-Add-native-DMI-init.patch 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. From 6ec71c6df97eded010e96c4ea2bd37cc6a13849d Mon Sep 17 00:00:00 2001
  2. From: Angel Pons <th3fanbus@gmail.com>
  3. Date: Fri, 6 May 2022 21:56:48 +0200
  4. Subject: [PATCH 03/26] haswell/lynxpoint: Add native DMI init
  5. Implement native DMI init for Haswell and Lynx Point. This is only
  6. needed on non-ULT platforms, and only when MRC.bin is not used.
  7. TEST=Verify DMI initialises correctly on Asrock B85M Pro4.
  8. Change-Id: I5fb1a2adc4ffbf0ebbf0d2d3a444055c53765faa
  9. Signed-off-by: Angel Pons <th3fanbus@gmail.com>
  10. ---
  11. src/northbridge/intel/haswell/Makefile.inc | 1 +
  12. src/northbridge/intel/haswell/early_dmi.c | 96 ++++++++++++
  13. src/northbridge/intel/haswell/early_pcie.c | 121 ++++++++++++++
  14. src/northbridge/intel/haswell/haswell.h | 3 +
  15. .../haswell/native_raminit/raminit_native.c | 15 ++
  16. src/northbridge/intel/haswell/vcu_mailbox.c | 147 ++++++++++++++++++
  17. src/northbridge/intel/haswell/vcu_mailbox.h | 16 ++
  18. src/southbridge/intel/lynxpoint/Makefile.inc | 2 +
  19. .../intel/lynxpoint/early_pch_native.c | 52 +++++++
  20. src/southbridge/intel/lynxpoint/pch.h | 20 ++-
  21. 10 files changed, 472 insertions(+), 1 deletion(-)
  22. create mode 100644 src/northbridge/intel/haswell/early_dmi.c
  23. create mode 100644 src/northbridge/intel/haswell/early_pcie.c
  24. create mode 100644 src/northbridge/intel/haswell/vcu_mailbox.c
  25. create mode 100644 src/northbridge/intel/haswell/vcu_mailbox.h
  26. create mode 100644 src/southbridge/intel/lynxpoint/early_pch_native.c
  27. diff --git a/src/northbridge/intel/haswell/Makefile.inc b/src/northbridge/intel/haswell/Makefile.inc
  28. index 329f1f7ffe..df0b097296 100644
  29. --- a/src/northbridge/intel/haswell/Makefile.inc
  30. +++ b/src/northbridge/intel/haswell/Makefile.inc
  31. @@ -20,6 +20,7 @@ romstage-y += report_platform.c
  32. postcar-y += memmap.c
  33. ifeq ($(CONFIG_USE_NATIVE_RAMINIT),y)
  34. +romstage-y += early_dmi.c early_pcie.c vcu_mailbox.c
  35. subdirs-y += native_raminit
  36. else
  37. diff --git a/src/northbridge/intel/haswell/early_dmi.c b/src/northbridge/intel/haswell/early_dmi.c
  38. new file mode 100644
  39. index 0000000000..9941242fd5
  40. --- /dev/null
  41. +++ b/src/northbridge/intel/haswell/early_dmi.c
  42. @@ -0,0 +1,96 @@
  43. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  44. +
  45. +#include <console/console.h>
  46. +#include <northbridge/intel/haswell/haswell.h>
  47. +#include <southbridge/intel/lynxpoint/pch.h>
  48. +#include <types.h>
  49. +
  50. +static void dmi_print_link_status(int loglevel)
  51. +{
  52. + const uint16_t dmilsts = dmibar_read16(DMILSTS);
  53. + printk(loglevel, "DMI: Running at Gen%u x%u\n", dmilsts & 0xf, dmilsts >> 4 & 0x1f);
  54. +}
  55. +
  56. +#define RETRAIN (1 << 5)
  57. +
  58. +#define LTRN (1 << 11)
  59. +
  60. +static void dmi_setup_physical_layer(void)
  61. +{
  62. + /* Program DMI AFE settings, which are needed for DMI to work */
  63. + peg_dmi_recipe(false, 0);
  64. +
  65. + /* Additional DMI programming steps */
  66. + dmibar_setbits32(0x258, 1 << 29);
  67. + dmibar_clrsetbits32(0x208, 0x7ff, 0x6b5);
  68. + dmibar_clrsetbits32(0x22c, 0xffff, 0x2020);
  69. +
  70. + /* Write SA reference code version */
  71. + dmibar_write32(0x71c, 0x0000000f);
  72. + dmibar_write32(0x720, 0x01060200);
  73. +
  74. + /* We also have to bring up the PCH side of the DMI link */
  75. + pch_dmi_setup_physical_layer();
  76. +
  77. + /* Write-once settings */
  78. + dmibar_clrsetbits32(DMILCAP, 0x3f00f, 2 << 0);
  79. +
  80. + printk(BIOS_DEBUG, "Retraining DMI at Gen2 speeds...\n");
  81. + dmi_print_link_status(BIOS_DEBUG);
  82. +
  83. + /* Retrain link */
  84. + dmibar_setbits16(DMILCTL, RETRAIN);
  85. + do {} while (dmibar_read16(DMILSTS) & LTRN);
  86. + dmi_print_link_status(BIOS_DEBUG);
  87. +
  88. + /* Retrain link again for DMI Gen2 speeds */
  89. + dmibar_setbits16(DMILCTL, RETRAIN);
  90. + do {} while (dmibar_read16(DMILSTS) & LTRN);
  91. + dmi_print_link_status(BIOS_INFO);
  92. +}
  93. +
  94. +#define VC_ACTIVE (1U << 31)
  95. +
  96. +#define VCNEGPND (1 << 1)
  97. +
  98. +#define DMI_VC_CFG(vcid, tcmap) (VC_ACTIVE | ((vcid) << 24) | (tcmap))
  99. +
  100. +static void dmi_tc_vc_mapping(void)
  101. +{
  102. + printk(BIOS_DEBUG, "Programming SA DMI VC/TC mappings...\n");
  103. +
  104. + if (CONFIG(INTEL_LYNXPOINT_LP))
  105. + dmibar_setbits8(0xa78, 1 << 1);
  106. +
  107. + /* Each TC is mapped to one and only one VC */
  108. + const u32 vc0 = DMI_VC_CFG(0, (1 << 6) | (1 << 5) | (1 << 4) | (1 << 3) | (1 << 0));
  109. + const u32 vc1 = DMI_VC_CFG(1, (1 << 1));
  110. + const u32 vcp = DMI_VC_CFG(2, (1 << 2));
  111. + const u32 vcm = DMI_VC_CFG(7, (1 << 7));
  112. + dmibar_write32(DMIVC0RCTL, vc0);
  113. + dmibar_write32(DMIVC1RCTL, vc1);
  114. + dmibar_write32(DMIVCPRCTL, vcp);
  115. + dmibar_write32(DMIVCMRCTL, vcm);
  116. +
  117. + /* Set Extended VC Count (EVCC) to 1 if VC1 is active */
  118. + dmibar_clrsetbits8(DMIPVCCAP1, 7, !!(vc1 & VC_ACTIVE));
  119. +
  120. + /*
  121. + * We also have to program the PCH side of the DMI link. Since both ends
  122. + * must use the same Virtual Channel settings, we pass them as arguments.
  123. + */
  124. + pch_dmi_tc_vc_mapping(vc0, vc1, vcp, vcm);
  125. +
  126. + printk(BIOS_DEBUG, "Waiting for SA DMI VC negotiation... ");
  127. + do {} while (dmibar_read16(DMIVC0RSTS) & VCNEGPND);
  128. + do {} while (dmibar_read16(DMIVC1RSTS) & VCNEGPND);
  129. + do {} while (dmibar_read16(DMIVCPRSTS) & VCNEGPND);
  130. + do {} while (dmibar_read16(DMIVCMRSTS) & VCNEGPND);
  131. + printk(BIOS_DEBUG, "done!\n");
  132. +}
  133. +
  134. +void dmi_early_init(void)
  135. +{
  136. + dmi_setup_physical_layer();
  137. + dmi_tc_vc_mapping();
  138. +}
  139. diff --git a/src/northbridge/intel/haswell/early_pcie.c b/src/northbridge/intel/haswell/early_pcie.c
  140. new file mode 100644
  141. index 0000000000..d3940e3fac
  142. --- /dev/null
  143. +++ b/src/northbridge/intel/haswell/early_pcie.c
  144. @@ -0,0 +1,121 @@
  145. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  146. +
  147. +#include <console/console.h>
  148. +#include <device/pci_def.h>
  149. +#include <device/pci_mmio_cfg.h>
  150. +#include <device/pci_ops.h>
  151. +#include <northbridge/intel/haswell/haswell.h>
  152. +#include <northbridge/intel/haswell/vcu_mailbox.h>
  153. +#include <types.h>
  154. +
  155. +#define PEG_DEV(func) PCI_DEV(0, 1, func)
  156. +
  157. +#define MAX_PEG_FUNC 3
  158. +
  159. +static void peg_dmi_unset_and_set_mask_pcicfg(
  160. + volatile union pci_bank *const bank,
  161. + const uint32_t offset,
  162. + const uint32_t unset_mask,
  163. + const uint32_t set_mask,
  164. + const uint32_t shift,
  165. + const bool valid)
  166. +{
  167. + if (!valid)
  168. + return;
  169. +
  170. + volatile uint32_t *const addr = &bank->reg32[offset / sizeof(uint32_t)];
  171. + clrsetbits32(addr, unset_mask << shift, set_mask << shift);
  172. +}
  173. +
  174. +static void peg_dmi_unset_and_set_mask_common(
  175. + const bool is_peg,
  176. + const uint32_t offset,
  177. + const uint32_t unset,
  178. + const uint32_t set,
  179. + const uint32_t shift,
  180. + const bool valid)
  181. +{
  182. + const uint32_t unset_mask = unset << shift;
  183. + const uint32_t set_mask = set << shift;
  184. + if (is_peg) {
  185. + for (uint8_t i = 0; i < MAX_PEG_FUNC; i++)
  186. + pci_update_config32(PEG_DEV(i), offset, ~unset_mask, set_mask);
  187. + } else {
  188. + dmibar_clrsetbits32(offset, unset_mask, set_mask);
  189. + }
  190. +}
  191. +
  192. +static void peg_dmi_unset_and_set_mask_vcu_mmio(
  193. + const uint32_t addr,
  194. + const uint32_t unset_mask,
  195. + const uint32_t set_mask,
  196. + const uint32_t shift,
  197. + const bool valid)
  198. +{
  199. + if (!valid)
  200. + return;
  201. +
  202. + vcu_update_mmio(addr, ~(unset_mask << shift), set_mask << shift);
  203. +}
  204. +
  205. +#define BUNDLE_STEP 0x20
  206. +
  207. +static void *const dmibar = (void *)(uintptr_t)CONFIG_FIXED_DMIBAR_MMIO_BASE;
  208. +
  209. +void peg_dmi_recipe(const bool is_peg, const pci_devfn_t dev)
  210. +{
  211. + const bool always = true;
  212. + const bool is_dmi = !is_peg;
  213. +
  214. + /* Treat DMIBAR and PEG devices the same way */
  215. + volatile union pci_bank *const bank = is_peg ? pci_map_bus(dev) : dmibar;
  216. +
  217. + const size_t bundles = (is_peg ? 8 : 2) * BUNDLE_STEP;
  218. +
  219. + for (size_t i = 0; i < bundles; i += BUNDLE_STEP) {
  220. + /* These are actually per-lane */
  221. + peg_dmi_unset_and_set_mask_pcicfg(bank, 0xa00 + i, 0x1f, 0x0c, 0, always);
  222. + peg_dmi_unset_and_set_mask_pcicfg(bank, 0xa10 + i, 0x1f, 0x0c, 0, always);
  223. + }
  224. +
  225. + for (size_t i = 0; i < bundles; i += BUNDLE_STEP)
  226. + peg_dmi_unset_and_set_mask_pcicfg(bank, 0x904 + i, 0x1f, 0x02, 0, is_peg);
  227. +
  228. + for (size_t i = 0; i < bundles; i += BUNDLE_STEP)
  229. + peg_dmi_unset_and_set_mask_pcicfg(bank, 0x904 + i, 0x1f, 0x03, 5, is_peg);
  230. +
  231. + for (size_t i = 0; i < bundles; i += BUNDLE_STEP)
  232. + peg_dmi_unset_and_set_mask_pcicfg(bank, 0x90c + i, 0x3f, 0x09, 5, always);
  233. +
  234. + for (size_t i = 0; i < bundles; i += BUNDLE_STEP)
  235. + peg_dmi_unset_and_set_mask_pcicfg(bank, 0x90c + i, 0x0f, 0x05, 21, is_peg);
  236. +
  237. + for (size_t i = 0; i < bundles; i += BUNDLE_STEP)
  238. + peg_dmi_unset_and_set_mask_pcicfg(bank, 0x910 + i, 0x0f, 0x08, 6, is_peg);
  239. +
  240. + for (size_t i = 0; i < bundles; i += BUNDLE_STEP)
  241. + peg_dmi_unset_and_set_mask_pcicfg(bank, 0x910 + i, 0x0f, 0x00, 10, always);
  242. +
  243. + for (size_t i = 0; i < bundles; i += BUNDLE_STEP)
  244. + peg_dmi_unset_and_set_mask_pcicfg(bank, 0x910 + i, 0x07, 0x00, 18, always);
  245. +
  246. + peg_dmi_unset_and_set_mask_vcu_mmio(0x0c008001, 0x1f, 0x03, 25, is_peg);
  247. + peg_dmi_unset_and_set_mask_vcu_mmio(0x0c0c8001, 0x3f, 0x00, 23, is_dmi);
  248. +
  249. + peg_dmi_unset_and_set_mask_pcicfg(bank, 0xc28, 0x1f, 0x13, 18, always);
  250. +
  251. + peg_dmi_unset_and_set_mask_common(is_peg, 0xc38, 0x01, 0x00, 6, always);
  252. + peg_dmi_unset_and_set_mask_common(is_peg, 0x260, 0x03, 0x02, 0, always);
  253. +
  254. + for (size_t i = 0; i < bundles; i += BUNDLE_STEP)
  255. + peg_dmi_unset_and_set_mask_pcicfg(bank, 0x900 + i, 0x03, 0x00, 26, always);
  256. +
  257. + for (size_t i = 0; i < bundles; i += BUNDLE_STEP)
  258. + peg_dmi_unset_and_set_mask_pcicfg(bank, 0x904 + i, 0x03, 0x03, 10, always);
  259. +
  260. + for (size_t i = 0; i < bundles; i += BUNDLE_STEP)
  261. + peg_dmi_unset_and_set_mask_pcicfg(bank, 0x90c + i, 0x1f, 0x07, 25, is_peg);
  262. +
  263. + for (size_t i = 0; i < bundles; i += BUNDLE_STEP)
  264. + peg_dmi_unset_and_set_mask_pcicfg(bank, 0x91c + i, 0x07, 0x05, 27, is_peg);
  265. +}
  266. diff --git a/src/northbridge/intel/haswell/haswell.h b/src/northbridge/intel/haswell/haswell.h
  267. index 1b29f6baf0..30b4abd0a7 100644
  268. --- a/src/northbridge/intel/haswell/haswell.h
  269. +++ b/src/northbridge/intel/haswell/haswell.h
  270. @@ -34,6 +34,9 @@ void haswell_early_initialization(void);
  271. void haswell_late_initialization(void);
  272. void haswell_unhide_peg(void);
  273. +void dmi_early_init(void);
  274. +void peg_dmi_recipe(const bool is_peg, const pci_devfn_t dev);
  275. +
  276. void report_platform_info(void);
  277. struct acpi_rsdp;
  278. diff --git a/src/northbridge/intel/haswell/native_raminit/raminit_native.c b/src/northbridge/intel/haswell/native_raminit/raminit_native.c
  279. index 1aafdf8659..0938e026e3 100644
  280. --- a/src/northbridge/intel/haswell/native_raminit/raminit_native.c
  281. +++ b/src/northbridge/intel/haswell/native_raminit/raminit_native.c
  282. @@ -1,7 +1,19 @@
  283. /* SPDX-License-Identifier: GPL-2.0-or-later */
  284. #include <console/console.h>
  285. +#include <northbridge/intel/haswell/haswell.h>
  286. #include <northbridge/intel/haswell/raminit.h>
  287. +#include <types.h>
  288. +
  289. +static bool early_init_native(int s3resume)
  290. +{
  291. + printk(BIOS_DEBUG, "Starting native platform initialisation\n");
  292. +
  293. + if (!CONFIG(INTEL_LYNXPOINT_LP))
  294. + dmi_early_init();
  295. +
  296. + return false;
  297. +}
  298. void perform_raminit(const int s3resume)
  299. {
  300. @@ -9,6 +21,9 @@ void perform_raminit(const int s3resume)
  301. * See, this function's name is a lie. There are more things to
  302. * do that memory initialisation, but they are relatively easy.
  303. */
  304. + const bool cpu_replaced = early_init_native(s3resume);
  305. +
  306. + (void)cpu_replaced;
  307. /** TODO: Implement the required magic **/
  308. die("NATIVE RAMINIT: More Magic (tm) required.\n");
  309. diff --git a/src/northbridge/intel/haswell/vcu_mailbox.c b/src/northbridge/intel/haswell/vcu_mailbox.c
  310. new file mode 100644
  311. index 0000000000..aead144023
  312. --- /dev/null
  313. +++ b/src/northbridge/intel/haswell/vcu_mailbox.c
  314. @@ -0,0 +1,147 @@
  315. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  316. +
  317. +#include <assert.h>
  318. +#include <console/console.h>
  319. +#include <delay.h>
  320. +#include <northbridge/intel/haswell/haswell.h>
  321. +#include <northbridge/intel/haswell/vcu_mailbox.h>
  322. +#include <stdint.h>
  323. +
  324. +/*
  325. + * This is a library for the VCU (Validation Control Unit) mailbox. This
  326. + * mailbox is primarily used to adjust some magic PCIe tuning parameters.
  327. + *
  328. + * There are two revisions of the VCU mailbox. Rev1 is specific to Haswell
  329. + * stepping A0, and all other steppings use Rev2. Haswell stepping A0 CPUs
  330. + * are early Engineering Samples with undocumented errata, and most likely
  331. + * need special microcode updates to boot. Thus, the code does not support
  332. + * VCU mailbox Rev1, because no one should need it anymore.
  333. + */
  334. +
  335. +#define VCU_MAILBOX_INTERFACE 0x6c00
  336. +#define VCU_MAILBOX_DATA 0x6c04
  337. +
  338. +#define VCU_RUN_BUSY (1 << 31)
  339. +
  340. +enum vcu_opcode {
  341. + VCU_OPCODE_READ_VCU_API_VER_ID = 0x01,
  342. + VCU_OPCODE_OPEN_SEQ = 0x02,
  343. + VCU_OPCODE_CLOSE_SEQ = 0x03,
  344. + VCU_OPCODE_READ_DATA = 0x07,
  345. + VCU_OPCODE_WRITE_DATA = 0x08,
  346. + VCU_OPCODE_READ_CSR = 0x13,
  347. + VCU_OPCODE_WRITE_CSR = 0x14,
  348. + VCU_OPCODE_READ_MMIO = 0x15,
  349. + VCU_OPCODE_WRITE_MMIO = 0x16,
  350. +};
  351. +
  352. +enum vcu_sequence {
  353. + SEQ_ID_READ_CSR = 0x1,
  354. + SEQ_ID_WRITE_CSR = 0x2,
  355. + SEQ_ID_READ_MMIO = 0x3,
  356. + SEQ_ID_WRITE_MMIO = 0x4,
  357. +};
  358. +
  359. +#define VCU_RESPONSE_MASK 0xffff
  360. +#define VCU_RESPONSE_SUCCESS 0x40
  361. +#define VCU_RESPONSE_BUSY 0x80
  362. +#define VCU_RESPONSE_THREAD_UNAVAILABLE 0x82
  363. +#define VCU_RESPONSE_ILLEGAL 0x90
  364. +
  365. +/* FIXME: Use timer API */
  366. +static void send_vcu_command(const enum vcu_opcode opcode, const uint32_t data)
  367. +{
  368. + for (unsigned int i = 0; i < 10; i++) {
  369. + mchbar_write32(VCU_MAILBOX_DATA, data);
  370. + mchbar_write32(VCU_MAILBOX_INTERFACE, opcode | VCU_RUN_BUSY);
  371. + uint32_t vcu_interface;
  372. + for (unsigned int j = 0; j < 100; j++) {
  373. + vcu_interface = mchbar_read32(VCU_MAILBOX_INTERFACE);
  374. + if (!(vcu_interface & VCU_RUN_BUSY))
  375. + break;
  376. +
  377. + udelay(10);
  378. + }
  379. + if (vcu_interface & VCU_RUN_BUSY)
  380. + continue;
  381. +
  382. + if ((vcu_interface & VCU_RESPONSE_MASK) == VCU_RESPONSE_SUCCESS)
  383. + return;
  384. + }
  385. + printk(BIOS_ERR, "VCU: Failed to send command\n");
  386. +}
  387. +
  388. +static enum vcu_opcode get_register_opcode(enum vcu_sequence seq)
  389. +{
  390. + switch (seq) {
  391. + case SEQ_ID_READ_CSR:
  392. + return VCU_OPCODE_READ_CSR;
  393. + case SEQ_ID_WRITE_CSR:
  394. + return VCU_OPCODE_WRITE_CSR;
  395. + case SEQ_ID_READ_MMIO:
  396. + return VCU_OPCODE_READ_MMIO;
  397. + case SEQ_ID_WRITE_MMIO:
  398. + return VCU_OPCODE_WRITE_MMIO;
  399. + default:
  400. + return dead_code_t(enum vcu_opcode);
  401. + }
  402. +}
  403. +
  404. +static enum vcu_opcode get_data_opcode(enum vcu_sequence seq)
  405. +{
  406. + switch (seq) {
  407. + case SEQ_ID_READ_CSR:
  408. + case SEQ_ID_READ_MMIO:
  409. + return VCU_OPCODE_READ_DATA;
  410. + case SEQ_ID_WRITE_CSR:
  411. + case SEQ_ID_WRITE_MMIO:
  412. + return VCU_OPCODE_WRITE_DATA;
  413. + default:
  414. + return dead_code_t(enum vcu_opcode);
  415. + }
  416. +}
  417. +
  418. +static uint32_t send_vcu_sequence(uint32_t addr, enum vcu_sequence seq, uint32_t wr_data)
  419. +{
  420. + send_vcu_command(VCU_OPCODE_OPEN_SEQ, seq);
  421. +
  422. + send_vcu_command(get_register_opcode(seq), addr);
  423. +
  424. + send_vcu_command(get_data_opcode(seq), wr_data);
  425. +
  426. + const uint32_t rd_data = mchbar_read32(VCU_MAILBOX_DATA);
  427. +
  428. + send_vcu_command(VCU_OPCODE_CLOSE_SEQ, seq);
  429. +
  430. + return rd_data;
  431. +}
  432. +
  433. +uint32_t vcu_read_csr(uint32_t addr)
  434. +{
  435. + return send_vcu_sequence(addr, SEQ_ID_READ_CSR, 0);
  436. +}
  437. +
  438. +void vcu_write_csr(uint32_t addr, uint32_t data)
  439. +{
  440. + send_vcu_sequence(addr, SEQ_ID_WRITE_CSR, data);
  441. +}
  442. +
  443. +void vcu_update_csr(uint32_t addr, uint32_t andvalue, uint32_t orvalue)
  444. +{
  445. + vcu_write_csr(addr, (vcu_read_csr(addr) & andvalue) | orvalue);
  446. +}
  447. +
  448. +uint32_t vcu_read_mmio(uint32_t addr)
  449. +{
  450. + return send_vcu_sequence(addr, SEQ_ID_READ_MMIO, 0);
  451. +}
  452. +
  453. +void vcu_write_mmio(uint32_t addr, uint32_t data)
  454. +{
  455. + send_vcu_sequence(addr, SEQ_ID_WRITE_MMIO, data);
  456. +}
  457. +
  458. +void vcu_update_mmio(uint32_t addr, uint32_t andvalue, uint32_t orvalue)
  459. +{
  460. + vcu_write_mmio(addr, (vcu_read_mmio(addr) & andvalue) | orvalue);
  461. +}
  462. diff --git a/src/northbridge/intel/haswell/vcu_mailbox.h b/src/northbridge/intel/haswell/vcu_mailbox.h
  463. new file mode 100644
  464. index 0000000000..ba0a62e486
  465. --- /dev/null
  466. +++ b/src/northbridge/intel/haswell/vcu_mailbox.h
  467. @@ -0,0 +1,16 @@
  468. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  469. +
  470. +#ifndef HASWELL_VCU_MAILBOX_H
  471. +#define HASWELL_VCU_MAILBOX_H
  472. +
  473. +#include <stdint.h>
  474. +
  475. +uint32_t vcu_read_csr(uint32_t addr);
  476. +void vcu_write_csr(uint32_t addr, uint32_t data);
  477. +void vcu_update_csr(uint32_t addr, uint32_t andvalue, uint32_t orvalue);
  478. +
  479. +uint32_t vcu_read_mmio(uint32_t addr);
  480. +void vcu_write_mmio(uint32_t addr, uint32_t data);
  481. +void vcu_update_mmio(uint32_t addr, uint32_t andvalue, uint32_t orvalue);
  482. +
  483. +#endif /* HASWELL_VCU_MAILBOX_H */
  484. diff --git a/src/southbridge/intel/lynxpoint/Makefile.inc b/src/southbridge/intel/lynxpoint/Makefile.inc
  485. index 02022d348d..b8503ac8bc 100644
  486. --- a/src/southbridge/intel/lynxpoint/Makefile.inc
  487. +++ b/src/southbridge/intel/lynxpoint/Makefile.inc
  488. @@ -37,6 +37,8 @@ bootblock-y += early_pch.c
  489. romstage-y += early_usb.c early_me.c me_status.c early_pch.c
  490. romstage-y += pmutil.c
  491. +romstage-$(CONFIG_USE_NATIVE_RAMINIT) += early_pch_native.c
  492. +
  493. ifeq ($(CONFIG_INTEL_LYNXPOINT_LP),y)
  494. romstage-y += lp_gpio.c
  495. ramstage-y += lp_gpio.c
  496. diff --git a/src/southbridge/intel/lynxpoint/early_pch_native.c b/src/southbridge/intel/lynxpoint/early_pch_native.c
  497. new file mode 100644
  498. index 0000000000..c28ddfcf5d
  499. --- /dev/null
  500. +++ b/src/southbridge/intel/lynxpoint/early_pch_native.c
  501. @@ -0,0 +1,52 @@
  502. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  503. +
  504. +#include <console/console.h>
  505. +#include <device/pci_ops.h>
  506. +#include <southbridge/intel/lynxpoint/pch.h>
  507. +#include <types.h>
  508. +
  509. +void pch_dmi_setup_physical_layer(void)
  510. +{
  511. + /* FIXME: We need to make sure the SA supports Gen2 as well */
  512. + if ((RCBA32(0x21a4) & 0x0f) == 0x02) {
  513. + /* Set Gen 2 Common Clock N_FTS */
  514. + RCBA32_AND_OR(0x2340, ~0x00ff0000, 0x3a << 16);
  515. +
  516. + /* Set Target Link Speed to DMI Gen2 */
  517. + RCBA8_AND_OR(DLCTL2, ~0x07, 0x02);
  518. + }
  519. +}
  520. +
  521. +#define VC_ACTIVE (1U << 31)
  522. +
  523. +#define VCNEGPND (1 << 1)
  524. +
  525. +void pch_dmi_tc_vc_mapping(const u32 vc0, const u32 vc1, const u32 vcp, const u32 vcm)
  526. +{
  527. + printk(BIOS_DEBUG, "Programming PCH DMI VC/TC mappings...\n");
  528. +
  529. + RCBA32_AND_OR(CIR0050, ~(0xf << 20), 2 << 20);
  530. + if (vcp & VC_ACTIVE)
  531. + RCBA32_OR(CIR0050, 1 << 19 | 1 << 17);
  532. +
  533. + RCBA32(CIR0050); /* Posted Write */
  534. +
  535. + /* Use the same virtual channel mapping on both ends of the DMI link */
  536. + RCBA32(V0CTL) = vc0;
  537. + RCBA32(V1CTL) = vc1;
  538. + RCBA32(V1CTL); /* Posted Write */
  539. + RCBA32(VPCTL) = vcp;
  540. + RCBA32(VPCTL); /* Posted Write */
  541. + RCBA32(VMCTL) = vcm;
  542. +
  543. + /* Lock the registers */
  544. + RCBA32_OR(CIR0050, 1U << 31);
  545. + RCBA32(CIR0050); /* Posted Write */
  546. +
  547. + printk(BIOS_DEBUG, "Waiting for PCH DMI VC negotiation... ");
  548. + do {} while (RCBA16(V0STS) & VCNEGPND);
  549. + do {} while (RCBA16(V1STS) & VCNEGPND);
  550. + do {} while (RCBA16(VPSTS) & VCNEGPND);
  551. + do {} while (RCBA16(VMSTS) & VCNEGPND);
  552. + printk(BIOS_DEBUG, "done!\n");
  553. +}
  554. diff --git a/src/southbridge/intel/lynxpoint/pch.h b/src/southbridge/intel/lynxpoint/pch.h
  555. index 7d9fc6d6af..b5e0c2a830 100644
  556. --- a/src/southbridge/intel/lynxpoint/pch.h
  557. +++ b/src/southbridge/intel/lynxpoint/pch.h
  558. @@ -113,6 +113,9 @@ enum pch_platform_type {
  559. PCH_TYPE_ULT = 5,
  560. };
  561. +void pch_dmi_setup_physical_layer(void);
  562. +void pch_dmi_tc_vc_mapping(u32 vc0, u32 vc1, u32 vcp, u32 vcm);
  563. +
  564. void usb_ehci_sleep_prepare(pci_devfn_t dev, u8 slp_typ);
  565. void usb_ehci_disable(pci_devfn_t dev);
  566. void usb_xhci_sleep_prepare(pci_devfn_t dev, u8 slp_typ);
  567. @@ -406,9 +409,10 @@ void mainboard_config_rcba(void);
  568. /* Southbridge IO BARs */
  569. +#define PMBASE 0x40
  570. #define GPIOBASE 0x48
  571. -#define PMBASE 0x40
  572. +#define CIR0050 0x0050 /* 32bit */
  573. #define RPC 0x0400 /* 32bit */
  574. #define RPFN 0x0404 /* 32bit */
  575. @@ -431,6 +435,20 @@ void mainboard_config_rcba(void);
  576. #define IOTR2 0x1e90 /* 64bit */
  577. #define IOTR3 0x1e98 /* 64bit */
  578. +#define V0CTL 0x2014 /* 32bit */
  579. +#define V0STS 0x201a /* 16bit */
  580. +
  581. +#define V1CTL 0x2020 /* 32bit */
  582. +#define V1STS 0x2026 /* 16bit */
  583. +
  584. +#define VPCTL 0x2030 /* 32bit */
  585. +#define VPSTS 0x2038 /* 16bit */
  586. +
  587. +#define VMCTL 0x2040 /* 32bit */
  588. +#define VMSTS 0x2048 /* 16bit */
  589. +
  590. +#define DLCTL2 0x21b0
  591. +
  592. #define TCTL 0x3000 /* 8bit */
  593. #define NOINT 0
  594. --
  595. 2.39.2