coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
l2_cache.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /*
4  * Intel Pentium L2 Cache initialization.
5  * This code was developed by reverse engineering
6  * the BIOS. Where the code accesses documented
7  * registers I have added comments as best I can.
8  * Some undocumented registers on the Pentium II are
9  * used so some of the documentation is incomplete.
10  *
11  * References:
12  * Intel Architecture Software Developer's Manual
13  * Volume 3B: System Programming Guide, Part 2 (#253669)
14  * Appendix B.9
15  */
16 
17 /* This code is ported from coreboot v1.
18  * The L2 cache initialization sequence here only apply to SECC/SECC2 P6 family
19  * CPUs with Klamath (63x), Deschutes (65x) and Katmai (67x) cores.
20  * It is not required for Coppermine (68x) and Tualatin (6bx) cores.
21  * It is currently not known if Celerons with Mendocino (66x) core require the
22  * special initialization.
23  * Covington-core Celerons do not have L2 cache.
24  */
25 
26 #include <stdint.h>
27 #include <arch/cpu.h>
28 #include <console/console.h>
29 #include <cpu/intel/l2_cache.h>
30 #include <cpu/x86/cache.h>
31 #include <cpu/x86/msr.h>
32 
33 /* Latency Tables */
34 struct latency_entry {
37 };
38 /*
39 Latency maps for Deschutes and Katmai.
40 No such mapping is available for Klamath.
41 
42 Cache latency to
43 be written to L2 -----++++
44 control register ||||
45 0000 xx 00 -----> 000 cccc 0
46 |||| 00 66MHz
47 |||| 10 100MHz
48 |||| 01 133MHz (Katmai "B" only)
49 ++++------ CPU frequency multiplier
50 
51 0000 2x
52 0001 3x
53 0010 4x
54 0011 5x
55 0100 2.5x
56 0101 3.5x
57 0110 4.5x
58 0111 5.5x
59 1000 6x
60 1001 7x
61 1010 8x
62 1011 Reserved
63 1100 6.5x
64 1101 7.5x
65 1110 1.5x
66 1111 2x
67 
68 */
69 static const struct latency_entry latency_650_t0[] = {
70  {0x10, 0x02}, {0x50, 0x02}, {0x20, 0x04}, {0x60, 0x06},
71  {0x00, 0x08}, {0x40, 0x0C}, {0x12, 0x06}, {0x52, 0x0A},
72  {0x22, 0x0E}, {0x62, 0x10}, {0x02, 0x10}, {0xFF, 0x00}
73 };
74 
75 static const struct latency_entry latency_650_t1[] = {
76  {0x12, 0x14}, {0x52, 0x16}, {0x22, 0x16}, {0x62, 0x16},
77  {0xFF, 0x00}
78 };
79 
80 static const struct latency_entry latency_670_t0[] = {
81  {0x60, 0x06}, {0x00, 0x08}, {0x12, 0x06}, {0x52, 0x0A},
82  {0x22, 0x0E}, {0x62, 0x10}, {0x02, 0x10}, {0x42, 0x02},
83  {0x11, 0x0E}, {0x51, 0x0C}, {0x21, 0x02}, {0x61, 0x10},
84  {0x01, 0x10}, {0x41, 0x02}, {0xFF, 0x00}
85 };
86 
87 static const struct latency_entry latency_670_t1[] = {
88  {0x22, 0x18}, {0x62, 0x18}, {0x02, 0x1A}, {0x11, 0x18},
89  {0xFF, 0x00}
90 };
91 
92 static const struct latency_entry latency_670_t2[] = {
93  {0x22, 0x12}, {0x62, 0x14}, {0x02, 0x16}, {0x42, 0x1E},
94  {0x11, 0x12}, {0x51, 0x16}, {0x21, 0x1E}, {0x61, 0x14},
95  {0x01, 0x16}, {0x41, 0x1E}, {0xFF, 0x00}
96 };
97 
98 /* Latency tables for 650 model/type */
99 static const struct latency_entry *latency_650[] = {
101 };
102 
103 /* Latency tables for 670 model/type */
104 static const struct latency_entry *latency_670[] = {
106 };
107 
109 {
110  u32 eax, l, signature;
111  const struct latency_entry *latency_table, *le;
112  msr_t msr;
113 
114  /* First, attempt to get cache latency value from
115  IA32_PLATFORM_ID[56:53]. (L2 Cache Latency Read)
116  */
117  msr = rdmsr(IA32_PLATFORM_ID);
118 
119  printk(BIOS_DEBUG, "rdmsr(IA32_PLATFORM_ID) = %x:%x\n", msr.hi, msr.lo);
120 
121  l = (msr.hi >> 20) & 0x1e;
122 
123  if (l == 0) {
124  /* If latency value isn't available from
125  IA32_PLATFORM_ID[56:53], read it from
126  L2 control register 0 for lookup from
127  tables. */
128  int t, a;
129 
130  /* The raw code is read from L2 register 0, bits [7:4]. */
131  a = read_l2(0);
132  if (a < 0)
133  return -1;
134 
135  a &= 0xf0;
136 
137  if ((a & 0x20) == 0)
138  t = 0;
139  else if (a == 0x20)
140  t = 1;
141  else if (a == 0x30)
142  t = 2;
143  else
144  return -1;
145 
146  printk(BIOS_DEBUG, "L2 latency type = %x\n", t);
147 
148  /* Get CPUID family/model */
149  signature = cpuid_eax(1) & 0xfff0;
150 
151  /* Read EBL_CR_POWERON */
152  msr = rdmsr(EBL_CR_POWERON);
153  /* Get clock multiplier and FSB frequency.
154  * Multiplier is in [25:22].
155  * FSB is in [19:18] in Katmai, [19] in Deschutes ([18] is zero
156  * for them).
157  */
158  eax = msr.lo >> 18;
159  if (signature == 0x650) {
160  eax &= ~0xf2;
161  latency_table = latency_650[t];
162  } else if (signature == 0x670) {
163  eax &= ~0xf3;
164  latency_table = latency_670[t];
165  } else
166  return -1;
167 
168  /* Search table for matching entry */
169  for (le = latency_table; le->key != eax; le++) {
170  /* Fail if we get to the end of the table */
171  if (le->key == 0xff) {
173  "Could not find key %02x in latency table\n",
174  eax);
175  return -1;
176  }
177  }
178 
179  l = le->value;
180  }
181 
182  printk(BIOS_DEBUG, "L2 Cache latency is %d\n", l / 2);
183 
184  /* Writes the calculated latency in BBL_CR_CTL3[4:1]. */
185  msr = rdmsr(BBL_CR_CTL3);
186  msr.lo &= 0xffffffe1;
187  msr.lo |= l;
188  wrmsr(BBL_CR_CTL3, msr);
189 
190  return 0;
191 }
192 
193 /* Setup address, data_high:data_low into the L2
194  * control registers and then issue command with correct cache way
195  */
196 int signal_l2(u32 address, u32 data_high, u32 data_low, int way, u8 command)
197 {
198  int i;
199  msr_t msr;
200 
201  /* Write L2 Address to BBL_CR_ADDR */
202  msr.lo = address;
203  msr.hi = 0;
204  wrmsr(BBL_CR_ADDR, msr);
205 
206  /* Write data to BBL_CR_D{0..3} */
207  msr.lo = data_low;
208  msr.hi = data_high;
209  for (i = BBL_CR_D0; i <= BBL_CR_D3; i++)
210  wrmsr(i, msr);
211 
212  /* Put the command and way into BBL_CR_CTL */
213  msr = rdmsr(BBL_CR_CTL);
214  msr.lo = (msr.lo & 0xfffffce0) | command | (way << 8);
215  wrmsr(BBL_CR_CTL, msr);
216 
217  /* Trigger L2 controller */
218  msr.lo = 0;
219  msr.hi = 0;
220  wrmsr(BBL_CR_TRIG, msr);
221 
222  /* Poll the controller to see when done */
223  for (i = 0; i < 0x100; i++) {
224  /* Read BBL_CR_BUSY */
225  msr = rdmsr(BBL_CR_BUSY);
226  /* If not busy then return */
227  if ((msr.lo & 1) == 0)
228  return 0;
229  }
230 
231  /* Return timeout code */
232  return -1;
233 }
234 
235 /* Read the L2 Cache controller register at given address */
237 {
238  msr_t msr;
239 
240  /* Send a L2 Control Register Read to L2 controller */
241  if (signal_l2(address << 5, 0, 0, 0, L2CMD_CR) != 0)
242  return -1;
243 
244  /* If OK then get the result from BBL_CR_ADDR */
245  msr = rdmsr(BBL_CR_ADDR);
246  return (msr.lo >> 0x15);
247 
248 }
249 
250 /* Write data into the L2 controller register at address */
252 {
253  int v1, v2, i;
254 
255  v1 = read_l2(0);
256  if (v1 < 0)
257  return -1;
258 
259  v2 = read_l2(2);
260  if (v2 < 0)
261  return -1;
262 
263  if ((v1 & 0x20) == 0) {
264  v2 &= 0x3;
265  v2++;
266  } else
267  v2 &= 0x7;
268 
269  /* This write has to be replicated to a number of places. Not sure what.
270  */
271 
272  for (i = 0; i < v2; i++) {
273 
274  u32 data1, data2;
275  // Bits legend
276  // data1 = ffffffff
277  // data2 = 000000dc
278  // address = 00aaaaaa
279  // Final address signaled:
280  // 000fffff fff000c0 000dcaaa aaa00000
281  data1 = data & 0xff;
282  data1 = data1 << 21;
283  data2 = (i << 11) & 0x1800;
284  data1 |= data2;
285  data2 <<= 6;
286  data2 &= 0x20000;
287  data1 |= data2;
288 
289  /* Signal L2 controller */
290  if (signal_l2((address << 5) | data1, 0, 0, 0, 3))
291  return -1;
292  }
293  return 0;
294 }
295 
296 /* Write data_high:data_low into the cache at address1. Test address2
297  * to see if the same data is returned. Return 0 if the data matches.
298  * return lower 16 bits if mismatched data if mismatch. Return -1
299  * on error
300  */
301 int test_l2_address_alias(u32 address1, u32 address2,
302  u32 data_high, u32 data_low)
303 {
304  int d;
305  msr_t msr;
306 
307  /* Tag Write with Data Write for L2 */
308  if (signal_l2(address1, data_high, data_low, 0, L2CMD_TWW))
309  return -1;
310 
311  /* Tag Read with Data Read for L2 */
312  if (signal_l2(address2, 0, 0, 0, L2CMD_TRR))
313  return -1;
314 
315  /* Read data from BBL_CR_D[0-3] */
316  for (d = BBL_CR_D0; d <= BBL_CR_D3; d++) {
317  msr = rdmsr(d);
318  if (msr.lo != data_low || msr.hi != data_high)
319  return (msr.lo & 0xffff);
320  }
321 
322  return 0;
323 }
324 
325 /* Calculates the L2 cache size.
326  *
327  * Reference: Intel(R) 64 and IA-32 Architectures Software Developer's Manual
328  * Volume 3B: System Programming Guide, Part 2, Intel pub. 253669,
329  * pg. B-172.
330  *
331  */
333 {
334  int v;
335  msr_t msr;
336  u32 cache_setting;
337  u32 address, size, eax, bblcr3;
338 
339  v = read_l2(0);
340  if (v < 0)
341  return -1;
342  if ((v & 0x20) == 0) {
343  msr = rdmsr(BBL_CR_CTL3);
344  bblcr3 = msr.lo & ~BBLCR3_L2_SIZE;
345  /*
346  * Successively write in all the possible cache size per bank
347  * into BBL_CR_CTL3[17:13], starting from 256KB (00001) to 4MB
348  * (10000), and read the last value written and accepted by the
349  * cache.
350  *
351  * No idea why these bits are writable at all.
352  */
353  for (cache_setting = BBLCR3_L2_SIZE_256K;
354  cache_setting <= BBLCR3_L2_SIZE_4M; cache_setting <<= 1) {
355 
356  eax = bblcr3 | cache_setting;
357  msr.lo = eax;
358  wrmsr(BBL_CR_CTL3, msr);
359  msr = rdmsr(BBL_CR_CTL3);
360 
361  /* Value not accepted */
362  if (msr.lo != eax)
363  break;
364  }
365 
366  /* Backtrack to the last value that worked... */
367  cache_setting >>= 1;
368 
369  /* and write it into BBL_CR_CTL3 */
370  msr.lo &= ~BBLCR3_L2_SIZE;
371  msr.lo |= (cache_setting & BBLCR3_L2_SIZE);
372 
373  wrmsr(BBL_CR_CTL3, msr);
374 
375  printk(BIOS_DEBUG, "Maximum cache mask is %x\n", cache_setting);
376 
377  /* For now, BBL_CR_CTL3 has the highest cache "size" that
378  * register will accept. Now we'll ping the cache and see where
379  * it wraps.
380  */
381 
382  /* Write aaaaaaaa:aaaaaaaa to address 0 in the l2 cache.
383  * If this "alias test" returns an "address", it means the
384  * cache cannot be written to properly, and we have a problem.
385  */
386  v = test_l2_address_alias(0, 0, 0xaaaaaaaa, 0xaaaaaaaa);
387  if (v != 0)
388  return -1;
389 
390  /* Start with 32K wrap point (256KB actually) */
391  size = 1;
392  address = 0x8000;
393 
394  while (1) {
395  v = test_l2_address_alias(address, 0, 0x55555555,
396  0x55555555);
397  // Write failed.
398  if (v < 0)
399  return -1;
400  // It wraps here.
401  else if (v == 0)
402  break;
403 
404  size <<= 1;
405  address <<= 1;
406 
407  if (address > 0x200000)
408  return -1;
409  }
410 
411  /* Mask size */
412  size &= 0x3e;
413 
414  /* Shift to [17:13] */
415  size <<= 12;
416 
417  /* Set this into BBL_CR_CTL3 */
418  msr = rdmsr(BBL_CR_CTL3);
419  msr.lo &= ~BBLCR3_L2_SIZE;
420  msr.lo |= size;
421  wrmsr(BBL_CR_CTL3, msr);
422 
423  printk(BIOS_DEBUG, "L2 Cache Mask is %x\n", size);
424 
425  /* Shift to [6:2] */
426  size >>= 11;
427 
428  v = read_l2(2);
429 
430  if (v < 0)
431  return -1;
432 
433  printk(BIOS_DEBUG, "L2(2): %x ", v);
434 
435  v &= 0x3;
436 
437  /* Shift size right by v */
438  size >>= v;
439 
440  /* Or in this size */
441  v |= size;
442 
443  printk(BIOS_DEBUG, "-> %x\n", v);
444 
445  if (write_l2(2, v) != 0)
446  return -1;
447  } else {
448  // Some cache size information is available from L2 registers.
449  // Work from there.
450  int b, c;
451 
452  v = read_l2(2);
453 
454  printk(BIOS_DEBUG, "L2(2) = %x\n", v);
455 
456  if (v < 0)
457  return -1;
458 
459  // L2 register 2 bitmap: cc---bbb
460  b = v & 0x7;
461  c = v >> 6;
462 
463  v = 1 << c * b;
464 
465  v &= 0xf;
466 
467  printk(BIOS_DEBUG, "Calculated a = %x\n", v);
468 
469  if (v == 0)
470  return -1;
471 
472  /* Shift to 17:14 */
473  v <<= 14;
474 
475  /* Write this size into BBL_CR_CTL3 */
476  msr = rdmsr(BBL_CR_CTL3);
477  msr.lo &= ~BBLCR3_L2_SIZE;
478  msr.lo |= v;
479  wrmsr(BBL_CR_CTL3, msr);
480  }
481 
482  return 0;
483 }
484 
485 // L2 physical address range can be found from L2 control register 3,
486 // bits [2:0].
488 {
489  int r0, r3;
490  msr_t msr;
491 
492  r3 = read_l2(3);
493  if (r3 < 0)
494  return -1;
495 
496  r0 = read_l2(0);
497  if (r0 < 0)
498  return -1;
499 
500  if (r0 & 0x20)
501  r3 = 0x7;
502  else
503  r3 &= 0x7;
504 
505  printk(BIOS_DEBUG, "L2 Physical Address Range is %dM\n",
506  (1 << r3) * 512);
507 
508  /* Shift into [22:20] to be saved into BBL_CR_CTL3. */
509  r3 = r3 << 20;
510 
511  msr = rdmsr(BBL_CR_CTL3);
513  msr.lo |= r3;
514  wrmsr(BBL_CR_CTL3, msr);
515 
516  return 0;
517 }
518 
519 int set_l2_ecc(void)
520 {
521  u32 eax;
522  const u32 data1 = 0xaa55aa55;
523  const u32 data2 = 0xaaaaaaaa;
524  msr_t msr;
525 
526  /* Set User Supplied ECC in BBL_CR_CTL */
527  msr = rdmsr(BBL_CR_CTL);
528  msr.lo |= BBLCR3_L2_SUPPLIED_ECC;
529  wrmsr(BBL_CR_CTL, msr);
530 
531  /* Write a value into the L2 Data ECC register BBL_CR_DECC */
532  msr.lo = data1;
533  msr.hi = 0;
534  wrmsr(BBL_CR_DECC, msr);
535 
536  if (test_l2_address_alias(0, 0, data2, data2) < 0)
537  return -1;
538 
539  /* Read back ECC from BBL_CR_DECC */
540  msr = rdmsr(BBL_CR_DECC);
541  eax = msr.lo;
542 
543  if (eax == data1) {
544  printk(BIOS_DEBUG, "L2 ECC Checking is enabled\n");
545 
546  /* Set ECC Check Enable in BBL_CR_CTL3 */
547  msr = rdmsr(BBL_CR_CTL3);
549  wrmsr(BBL_CR_CTL3, msr);
550  }
551 
552  /* Clear User Supplied ECC in BBL_CR_CTL */
553  msr = rdmsr(BBL_CR_CTL);
554  msr.lo &= ~BBLCR3_L2_SUPPLIED_ECC;
555  wrmsr(BBL_CR_CTL, msr);
556 
557  return 0;
558 }
559 
560 /*
561  * This is the function called from CPU initialization
562  * driver to set up P6 family L2 cache.
563  */
564 
566 {
567  msr_t msr, bblctl3;
568  unsigned int eax;
569  u16 signature;
570  int cache_size, bank;
571  int result, calc_eax;
572  int v, a;
573 
574  int badclk1, badclk2, clkratio;
575  int crctl3_or;
576 
577  printk(BIOS_INFO, "Configuring L2 cache... ");
578 
579  /* Read BBL_CR_CTL3 */
580  bblctl3 = rdmsr(BBL_CR_CTL3);
581  /* If bit 23 (L2 Hardware disable) is set then done */
582  /* These would be Covington core Celerons with no L2 cache */
583  if (bblctl3.lo & BBLCR3_L2_NOT_PRESENT) {
584  printk(BIOS_INFO, "hardware disabled\n");
585  return 0;
586  }
587 
588  signature = cpuid_eax(1) & 0xfff0;
589 
590  /* Klamath-specific bit settings for certain
591  preliminary checks.
592  */
593  if (signature == 0x630) {
594  clkratio = 0x1c00000;
595  badclk2 = 0x1000000;
596  crctl3_or = 0x44000;
597  } else {
598  clkratio = 0x3c00000;
599  badclk2 = 0x3000000;
600  crctl3_or = 0x40000;
601  }
602  badclk1 = 0xc00000;
603 
604  /* Read EBL_CR_POWERON */
605  msr = rdmsr(EBL_CR_POWERON);
606  eax = msr.lo;
607  /* Mask out [22-25] Clock frequency ratio */
608  eax &= clkratio;
609  if (eax == badclk1 || eax == badclk2) {
610  printk(BIOS_ERR, "Incorrect clock frequency ratio %x\n", eax);
611  return -1;
612  }
613 
614  disable_cache();
615 
616  /* Mask out from BBL_CR_CTL3:
617  * [0] L2 Configured
618  * [5] ECC Check Enable
619  * [6] Address Parity Check Enable
620  * [7] CRTN Parity Check Enable
621  * [8] L2 Enabled
622  * [12:11] Number of L2 banks
623  * [17:13] Cache size per bank
624  * [18] (Set below)
625  * [22:20] L2 Physical Address Range Support
626  */
627  bblctl3.lo &= 0xff88061e;
628  /* Set:
629  * [17:13] = 00010 = 512Kbyte Cache size per bank (63x)
630  * [17:13] = 00000 = 128Kbyte Cache size per bank (all others)
631  * [18] Cache state error checking enable
632  */
633  bblctl3.lo |= crctl3_or;
634 
635  /* Write BBL_CR_CTL3 */
636  wrmsr(BBL_CR_CTL3, bblctl3);
637 
638  if (signature != 0x630) {
639  eax = bblctl3.lo;
640 
641  /* Set the l2 latency in BBL_CR_CTL3 */
642  if (calculate_l2_latency() != 0)
643  goto bad;
644 
645  /* Read the new latency values back */
646  bblctl3 = rdmsr(BBL_CR_CTL3);
647  calc_eax = bblctl3.lo;
648 
649  /* Write back the original default value */
650  bblctl3.lo = eax;
651  wrmsr(BBL_CR_CTL3, bblctl3);
652 
653  /* Write BBL_CR_CTL3[27:26] (reserved??) to bits [1:0] of L2
654  * register 4. Apparently all other bits must be preserved,
655  * hence these code.
656  */
657 
658  v = (calc_eax >> 26) & 0x3;
659 
660  printk(BIOS_DEBUG, "write_l2(4, %x)\n", v);
661 
662  a = read_l2(4);
663  if (a >= 0) {
664  a &= 0xfffc;
665  a |= v;
666  a = write_l2(4, a);
667  /* a now contains result code from write_l2() */
668  }
669  if (a != 0)
670  goto bad;
671 
672  /* Restore the correct latency value into BBL_CR_CTL3 */
673  bblctl3.lo = calc_eax;
674  wrmsr(BBL_CR_CTL3, bblctl3);
675  } /* ! 63x CPU */
676 
677  /* Read L2 register 0 */
678  v = read_l2(0);
679 
680  /* If L2(0)[5] set (and can be read properly), enable CRTN and address
681  * parity
682  */
683  if (v >= 0 && (v & 0x20)) {
684  bblctl3 = rdmsr(BBL_CR_CTL3);
685  bblctl3.lo |= (BBLCR3_L2_ADDR_PARITY_ENABLE |
687  wrmsr(BBL_CR_CTL3, bblctl3);
688  }
689 
690  /* If something goes wrong at L2 ECC setup, cache ECC
691  * will just remain disabled.
692  */
693  set_l2_ecc();
694 
697  "Failed to calculate L2 physical address range");
698  goto bad;
699  }
700 
701  if (calculate_l2_cache_size() != 0) {
702  printk(BIOS_ERR, "Failed to calculate L2 cache size");
703  goto bad;
704  }
705 
706  /* Turn on cache. Only L1 is active at this time. */
707  enable_cache();
708 
709  /* Get the calculated cache size from BBL_CR_CTL3[17:13] */
710  bblctl3 = rdmsr(BBL_CR_CTL3);
711  cache_size = (bblctl3.lo & BBLCR3_L2_SIZE);
712  if (cache_size == 0)
713  cache_size = 0x1000;
714  cache_size = cache_size << 3;
715 
716  /* TODO: Cache size above is per bank. We're supposed to get
717  * the number of banks from BBL_CR_CTL3[12:11].
718  * Confirm that this still provides the correct answer.
719  */
720  bank = (bblctl3.lo >> 11) & 0x3;
721  if (bank == 0)
722  bank = 1;
723 
724  printk(BIOS_INFO, "size %dK... ", cache_size * bank * 4 / 1024);
725 
726  /* Write to all cache lines to initialize */
727 
728  while (cache_size > 0) {
729 
730  /* Each cache line is 32 bytes. */
731  cache_size -= 32;
732 
733  /* Update each way */
734 
735  /* We're supposed to get L2 associativity from
736  * BBL_CR_CTL3[10:9]. But this code only applies to certain
737  * members of the P6 processor family and since all P6
738  * processors have 4-way L2 cache, we can safely assume
739  * 4 way for all cache operations.
740  */
741 
742  for (v = 0; v < 4; v++) {
743  /* Send Tag Write w/Data Write (TWW) to L2 controller
744  * MESI = Invalid
745  */
746  if (signal_l2(cache_size, 0, 0, v, L2CMD_TWW
747  | L2CMD_MESI_I) != 0) {
749  "Failed on signal_l2(%x, %x)\n",
750  cache_size, v);
751  goto bad;
752  }
753  }
754  }
755  printk(BIOS_DEBUG, "L2 Cache lines initialized\n");
756 
757  /* Disable cache */
758  disable_cache();
759 
760  /* Set L2 cache configured in BBL_CR_CTL3 */
761  bblctl3 = rdmsr(BBL_CR_CTL3);
762  bblctl3.lo |= BBLCR3_L2_CONFIGURED;
763  wrmsr(BBL_CR_CTL3, bblctl3);
764 
765  /* Invalidate cache and discard unsaved writes */
766  asm volatile ("invd");
767 
768  /* Write 0 to L2 control register 5 */
769  if (write_l2(5, 0) != 0) {
770  printk(BIOS_ERR, "write_l2(5, 0) failed\n");
771  goto done;
772  }
773 
774  bblctl3 = rdmsr(BBL_CR_CTL3);
775  if (signature == 0x650) {
776  /* Change the L2 latency to 0101 then back to
777  * original value. I don't know why this is needed - dpd
778  */
779  eax = bblctl3.lo;
780  bblctl3.lo &= ~BBLCR3_L2_LATENCY;
781  bblctl3.lo |= 0x0a;
782  wrmsr(BBL_CR_CTL3, bblctl3);
783  bblctl3.lo = eax;
784  wrmsr(BBL_CR_CTL3, bblctl3);
785  }
786 
787  /* Enable L2 in BBL_CR_CTL3 */
788  bblctl3.lo |= BBLCR3_L2_ENABLED;
789  wrmsr(BBL_CR_CTL3, bblctl3);
790 
791  /* Turn on cache. Both L1 and L2 are now active. Wahoo! */
792 done:
793  result = 0;
794  goto out;
795 bad:
796  result = -1;
797 out:
798  printk(BIOS_INFO, "done.\n");
799  return result;
800 }
static unsigned int cpuid_eax(unsigned int op)
Definition: cpu.h:79
#define printk(level,...)
Definition: stdlib.h:16
uint64_t address
Definition: fw_cfg_if.h:0
static __always_inline void enable_cache(void)
Definition: cache.h:40
static __always_inline void disable_cache(void)
Definition: cache.h:48
static __always_inline msr_t rdmsr(unsigned int index)
Definition: msr.h:146
static __always_inline void wrmsr(unsigned int index, msr_t msr)
Definition: msr.h:157
#define IA32_PLATFORM_ID
Definition: msr.h:18
static const struct latency_entry * latency_650[]
Definition: l2_cache.c:99
static const struct latency_entry latency_650_t1[]
Definition: l2_cache.c:75
int calculate_l2_latency(void)
Definition: l2_cache.c:108
static const struct latency_entry latency_670_t2[]
Definition: l2_cache.c:92
int calculate_l2_physical_address_range(void)
Definition: l2_cache.c:487
int signal_l2(u32 address, u32 data_high, u32 data_low, int way, u8 command)
Definition: l2_cache.c:196
int p6_configure_l2_cache(void)
Definition: l2_cache.c:565
static const struct latency_entry latency_670_t1[]
Definition: l2_cache.c:87
int set_l2_ecc(void)
Definition: l2_cache.c:519
int read_l2(u32 address)
Definition: l2_cache.c:236
int write_l2(u32 address, u32 data)
Definition: l2_cache.c:251
static const struct latency_entry * latency_670[]
Definition: l2_cache.c:104
int calculate_l2_cache_size(void)
Definition: l2_cache.c:332
static const struct latency_entry latency_650_t0[]
Definition: l2_cache.c:69
int test_l2_address_alias(u32 address1, u32 address2, u32 data_high, u32 data_low)
Definition: l2_cache.c:301
static const struct latency_entry latency_670_t0[]
Definition: l2_cache.c:80
#define L2CMD_TRR
Definition: l2_cache.h:59
#define BBLCR3_L2_ENABLED
Definition: l2_cache.h:38
#define L2CMD_TWW
Definition: l2_cache.h:64
#define BBL_CR_D0
Definition: l2_cache.h:20
#define BBL_CR_TRIG
Definition: l2_cache.h:28
#define EBL_CR_POWERON
Definition: l2_cache.h:18
#define BBLCR3_L2_SIZE
Definition: l2_cache.h:40
#define BBL_CR_D3
Definition: l2_cache.h:23
#define BBLCR3_L2_SIZE_4M
Definition: l2_cache.h:45
#define BBL_CR_DECC
Definition: l2_cache.h:26
#define BBLCR3_L2_CRTN_PARITY_ENABLE
Definition: l2_cache.h:37
#define BBLCR3_L2_CONFIGURED
Definition: l2_cache.h:32
#define BBLCR3_L2_SUPPLIED_ECC
Definition: l2_cache.h:51
#define BBLCR3_L2_PHYSICAL_RANGE
Definition: l2_cache.h:47
#define BBLCR3_L2_ECC_CHECK_ENABLE
Definition: l2_cache.h:35
#define BBL_CR_ADDR
Definition: l2_cache.h:25
#define BBLCR3_L2_NOT_PRESENT
Definition: l2_cache.h:55
#define BBL_CR_CTL
Definition: l2_cache.h:27
#define BBL_CR_CTL3
Definition: l2_cache.h:30
#define BBL_CR_BUSY
Definition: l2_cache.h:29
#define L2CMD_CR
Definition: l2_cache.h:61
#define BBLCR3_L2_ADDR_PARITY_ENABLE
Definition: l2_cache.h:36
#define BBLCR3_L2_SIZE_256K
Definition: l2_cache.h:41
#define BBLCR3_L2_LATENCY
Definition: l2_cache.h:34
#define L2CMD_MESI_I
Definition: l2_cache.h:70
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
result
Definition: mrc_cache.c:35
uint32_t u32
Definition: stdint.h:51
uint16_t u16
Definition: stdint.h:48
uint8_t u8
Definition: stdint.h:45
Definition: l2_cache.c:34
u8 value
Definition: l2_cache.c:36
u8 key
Definition: l2_cache.c:35
unsigned int hi
Definition: msr.h:112
unsigned int lo
Definition: msr.h:111
#define c(value, pmcreg, dst_bits)