mtrr.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /* Generic MTRR (Memory Type Range Register) driver.
  2. Copyright (C) 1997-2000 Richard Gooch
  3. Copyright (c) 2002 Patrick Mochel
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with this library; if not, write to the Free
  14. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. Richard Gooch may be reached by email at rgooch@atnf.csiro.au
  16. The postal address is:
  17. Richard Gooch, c/o ATNF, P. O. Box 76, Epping, N.S.W., 2121, Australia.
  18. Source: "Pentium Pro Family Developer's Manual, Volume 3:
  19. Operating System Writer's Guide" (Intel document number 242692),
  20. section 11.11.7
  21. This was cleaned and made readable by Patrick Mochel <mochel@osdl.org>
  22. on 6-7 March 2002.
  23. Source: Intel Architecture Software Developers Manual, Volume 3:
  24. System Programming Guide; Section 9.11. (1997 edition - PPro).
  25. */
  26. #include <linux/types.h> /* FIXME: kvm_para.h needs this */
  27. #include <linux/stop_machine.h>
  28. #include <linux/kvm_para.h>
  29. #include <linux/uaccess.h>
  30. #include <linux/export.h>
  31. #include <linux/mutex.h>
  32. #include <linux/init.h>
  33. #include <linux/sort.h>
  34. #include <linux/cpu.h>
  35. #include <linux/pci.h>
  36. #include <linux/smp.h>
  37. #include <linux/syscore_ops.h>
  38. #include <linux/rcupdate.h>
  39. #include <asm/cacheinfo.h>
  40. #include <asm/cpufeature.h>
  41. #include <asm/e820/api.h>
  42. #include <asm/mtrr.h>
  43. #include <asm/msr.h>
  44. #include <asm/memtype.h>
  45. #include "mtrr.h"
  46. static_assert(X86_MEMTYPE_UC == MTRR_TYPE_UNCACHABLE);
  47. static_assert(X86_MEMTYPE_WC == MTRR_TYPE_WRCOMB);
  48. static_assert(X86_MEMTYPE_WT == MTRR_TYPE_WRTHROUGH);
  49. static_assert(X86_MEMTYPE_WP == MTRR_TYPE_WRPROT);
  50. static_assert(X86_MEMTYPE_WB == MTRR_TYPE_WRBACK);
  51. /* arch_phys_wc_add returns an MTRR register index plus this offset. */
  52. #define MTRR_TO_PHYS_WC_OFFSET 1000
  53. u32 num_var_ranges;
  54. unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES];
  55. DEFINE_MUTEX(mtrr_mutex);
  56. const struct mtrr_ops *mtrr_if;
  57. /* Returns non-zero if we have the write-combining memory type */
  58. static int have_wrcomb(void)
  59. {
  60. struct pci_dev *dev;
  61. dev = pci_get_class(PCI_CLASS_BRIDGE_HOST << 8, NULL);
  62. if (dev != NULL) {
  63. /*
  64. * ServerWorks LE chipsets < rev 6 have problems with
  65. * write-combining. Don't allow it and leave room for other
  66. * chipsets to be tagged
  67. */
  68. if (dev->vendor == PCI_VENDOR_ID_SERVERWORKS &&
  69. dev->device == PCI_DEVICE_ID_SERVERWORKS_LE &&
  70. dev->revision <= 5) {
  71. pr_info("Serverworks LE rev < 6 detected. Write-combining disabled.\n");
  72. pci_dev_put(dev);
  73. return 0;
  74. }
  75. /*
  76. * Intel 450NX errata # 23. Non ascending cacheline evictions to
  77. * write combining memory may resulting in data corruption
  78. */
  79. if (dev->vendor == PCI_VENDOR_ID_INTEL &&
  80. dev->device == PCI_DEVICE_ID_INTEL_82451NX) {
  81. pr_info("Intel 450NX MMC detected. Write-combining disabled.\n");
  82. pci_dev_put(dev);
  83. return 0;
  84. }
  85. pci_dev_put(dev);
  86. }
  87. return mtrr_if->have_wrcomb ? mtrr_if->have_wrcomb() : 0;
  88. }
  89. static void __init init_table(void)
  90. {
  91. int i, max;
  92. max = num_var_ranges;
  93. for (i = 0; i < max; i++)
  94. mtrr_usage_table[i] = 1;
  95. }
  96. struct set_mtrr_data {
  97. unsigned long smp_base;
  98. unsigned long smp_size;
  99. unsigned int smp_reg;
  100. mtrr_type smp_type;
  101. };
  102. /**
  103. * mtrr_rendezvous_handler - Work done in the synchronization handler. Executed
  104. * by all the CPUs.
  105. * @info: pointer to mtrr configuration data
  106. *
  107. * Returns nothing.
  108. */
  109. static int mtrr_rendezvous_handler(void *info)
  110. {
  111. struct set_mtrr_data *data = info;
  112. mtrr_if->set(data->smp_reg, data->smp_base,
  113. data->smp_size, data->smp_type);
  114. return 0;
  115. }
  116. static inline int types_compatible(mtrr_type type1, mtrr_type type2)
  117. {
  118. return type1 == MTRR_TYPE_UNCACHABLE ||
  119. type2 == MTRR_TYPE_UNCACHABLE ||
  120. (type1 == MTRR_TYPE_WRTHROUGH && type2 == MTRR_TYPE_WRBACK) ||
  121. (type1 == MTRR_TYPE_WRBACK && type2 == MTRR_TYPE_WRTHROUGH);
  122. }
  123. /**
  124. * set_mtrr - update mtrrs on all processors
  125. * @reg: mtrr in question
  126. * @base: mtrr base
  127. * @size: mtrr size
  128. * @type: mtrr type
  129. *
  130. * This is kinda tricky, but fortunately, Intel spelled it out for us cleanly:
  131. *
  132. * 1. Queue work to do the following on all processors:
  133. * 2. Disable Interrupts
  134. * 3. Wait for all procs to do so
  135. * 4. Enter no-fill cache mode
  136. * 5. Flush caches
  137. * 6. Clear PGE bit
  138. * 7. Flush all TLBs
  139. * 8. Disable all range registers
  140. * 9. Update the MTRRs
  141. * 10. Enable all range registers
  142. * 11. Flush all TLBs and caches again
  143. * 12. Enter normal cache mode and reenable caching
  144. * 13. Set PGE
  145. * 14. Wait for buddies to catch up
  146. * 15. Enable interrupts.
  147. *
  148. * What does that mean for us? Well, stop_machine() will ensure that
  149. * the rendezvous handler is started on each CPU. And in lockstep they
  150. * do the state transition of disabling interrupts, updating MTRR's
  151. * (the CPU vendors may each do it differently, so we call mtrr_if->set()
  152. * callback and let them take care of it.) and enabling interrupts.
  153. *
  154. * Note that the mechanism is the same for UP systems, too; all the SMP stuff
  155. * becomes nops.
  156. */
  157. static void set_mtrr(unsigned int reg, unsigned long base, unsigned long size,
  158. mtrr_type type)
  159. {
  160. struct set_mtrr_data data = { .smp_reg = reg,
  161. .smp_base = base,
  162. .smp_size = size,
  163. .smp_type = type
  164. };
  165. stop_machine_cpuslocked(mtrr_rendezvous_handler, &data, cpu_online_mask);
  166. generic_rebuild_map();
  167. }
  168. /**
  169. * mtrr_add_page - Add a memory type region
  170. * @base: Physical base address of region in pages (in units of 4 kB!)
  171. * @size: Physical size of region in pages (4 kB)
  172. * @type: Type of MTRR desired
  173. * @increment: If this is true do usage counting on the region
  174. *
  175. * Memory type region registers control the caching on newer Intel and
  176. * non Intel processors. This function allows drivers to request an
  177. * MTRR is added. The details and hardware specifics of each processor's
  178. * implementation are hidden from the caller, but nevertheless the
  179. * caller should expect to need to provide a power of two size on an
  180. * equivalent power of two boundary.
  181. *
  182. * If the region cannot be added either because all regions are in use
  183. * or the CPU cannot support it a negative value is returned. On success
  184. * the register number for this entry is returned, but should be treated
  185. * as a cookie only.
  186. *
  187. * On a multiprocessor machine the changes are made to all processors.
  188. * This is required on x86 by the Intel processors.
  189. *
  190. * The available types are
  191. *
  192. * %MTRR_TYPE_UNCACHABLE - No caching
  193. *
  194. * %MTRR_TYPE_WRBACK - Write data back in bursts whenever
  195. *
  196. * %MTRR_TYPE_WRCOMB - Write data back soon but allow bursts
  197. *
  198. * %MTRR_TYPE_WRTHROUGH - Cache reads but not writes
  199. *
  200. * BUGS: Needs a quiet flag for the cases where drivers do not mind
  201. * failures and do not wish system log messages to be sent.
  202. */
  203. int mtrr_add_page(unsigned long base, unsigned long size,
  204. unsigned int type, bool increment)
  205. {
  206. unsigned long lbase, lsize;
  207. int i, replace, error;
  208. mtrr_type ltype;
  209. if (!mtrr_enabled())
  210. return -ENXIO;
  211. error = mtrr_if->validate_add_page(base, size, type);
  212. if (error)
  213. return error;
  214. if (type >= MTRR_NUM_TYPES) {
  215. pr_warn("type: %u invalid\n", type);
  216. return -EINVAL;
  217. }
  218. /* If the type is WC, check that this processor supports it */
  219. if ((type == MTRR_TYPE_WRCOMB) && !have_wrcomb()) {
  220. pr_warn("your processor doesn't support write-combining\n");
  221. return -ENOSYS;
  222. }
  223. if (!size) {
  224. pr_warn("zero sized request\n");
  225. return -EINVAL;
  226. }
  227. if ((base | (base + size - 1)) >>
  228. (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) {
  229. pr_warn("base or size exceeds the MTRR width\n");
  230. return -EINVAL;
  231. }
  232. error = -EINVAL;
  233. replace = -1;
  234. /* No CPU hotplug when we change MTRR entries */
  235. cpus_read_lock();
  236. /* Search for existing MTRR */
  237. mutex_lock(&mtrr_mutex);
  238. for (i = 0; i < num_var_ranges; ++i) {
  239. mtrr_if->get(i, &lbase, &lsize, &ltype);
  240. if (!lsize || base > lbase + lsize - 1 ||
  241. base + size - 1 < lbase)
  242. continue;
  243. /*
  244. * At this point we know there is some kind of
  245. * overlap/enclosure
  246. */
  247. if (base < lbase || base + size - 1 > lbase + lsize - 1) {
  248. if (base <= lbase &&
  249. base + size - 1 >= lbase + lsize - 1) {
  250. /* New region encloses an existing region */
  251. if (type == ltype) {
  252. replace = replace == -1 ? i : -2;
  253. continue;
  254. } else if (types_compatible(type, ltype))
  255. continue;
  256. }
  257. pr_warn("0x%lx000,0x%lx000 overlaps existing 0x%lx000,0x%lx000\n", base, size, lbase,
  258. lsize);
  259. goto out;
  260. }
  261. /* New region is enclosed by an existing region */
  262. if (ltype != type) {
  263. if (types_compatible(type, ltype))
  264. continue;
  265. pr_warn("type mismatch for %lx000,%lx000 old: %s new: %s\n",
  266. base, size, mtrr_attrib_to_str(ltype),
  267. mtrr_attrib_to_str(type));
  268. goto out;
  269. }
  270. if (increment)
  271. ++mtrr_usage_table[i];
  272. error = i;
  273. goto out;
  274. }
  275. /* Search for an empty MTRR */
  276. i = mtrr_if->get_free_region(base, size, replace);
  277. if (i >= 0) {
  278. set_mtrr(i, base, size, type);
  279. if (likely(replace < 0)) {
  280. mtrr_usage_table[i] = 1;
  281. } else {
  282. mtrr_usage_table[i] = mtrr_usage_table[replace];
  283. if (increment)
  284. mtrr_usage_table[i]++;
  285. if (unlikely(replace != i)) {
  286. set_mtrr(replace, 0, 0, 0);
  287. mtrr_usage_table[replace] = 0;
  288. }
  289. }
  290. } else {
  291. pr_info("no more MTRRs available\n");
  292. }
  293. error = i;
  294. out:
  295. mutex_unlock(&mtrr_mutex);
  296. cpus_read_unlock();
  297. return error;
  298. }
  299. static int mtrr_check(unsigned long base, unsigned long size)
  300. {
  301. if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1))) {
  302. pr_warn("size and base must be multiples of 4 kiB\n");
  303. Dprintk("size: 0x%lx base: 0x%lx\n", size, base);
  304. dump_stack();
  305. return -1;
  306. }
  307. return 0;
  308. }
  309. /**
  310. * mtrr_add - Add a memory type region
  311. * @base: Physical base address of region
  312. * @size: Physical size of region
  313. * @type: Type of MTRR desired
  314. * @increment: If this is true do usage counting on the region
  315. *
  316. * Memory type region registers control the caching on newer Intel and
  317. * non Intel processors. This function allows drivers to request an
  318. * MTRR is added. The details and hardware specifics of each processor's
  319. * implementation are hidden from the caller, but nevertheless the
  320. * caller should expect to need to provide a power of two size on an
  321. * equivalent power of two boundary.
  322. *
  323. * If the region cannot be added either because all regions are in use
  324. * or the CPU cannot support it a negative value is returned. On success
  325. * the register number for this entry is returned, but should be treated
  326. * as a cookie only.
  327. *
  328. * On a multiprocessor machine the changes are made to all processors.
  329. * This is required on x86 by the Intel processors.
  330. *
  331. * The available types are
  332. *
  333. * %MTRR_TYPE_UNCACHABLE - No caching
  334. *
  335. * %MTRR_TYPE_WRBACK - Write data back in bursts whenever
  336. *
  337. * %MTRR_TYPE_WRCOMB - Write data back soon but allow bursts
  338. *
  339. * %MTRR_TYPE_WRTHROUGH - Cache reads but not writes
  340. *
  341. * BUGS: Needs a quiet flag for the cases where drivers do not mind
  342. * failures and do not wish system log messages to be sent.
  343. */
  344. int mtrr_add(unsigned long base, unsigned long size, unsigned int type,
  345. bool increment)
  346. {
  347. if (!mtrr_enabled())
  348. return -ENODEV;
  349. if (mtrr_check(base, size))
  350. return -EINVAL;
  351. return mtrr_add_page(base >> PAGE_SHIFT, size >> PAGE_SHIFT, type,
  352. increment);
  353. }
  354. /**
  355. * mtrr_del_page - delete a memory type region
  356. * @reg: Register returned by mtrr_add
  357. * @base: Physical base address
  358. * @size: Size of region
  359. *
  360. * If register is supplied then base and size are ignored. This is
  361. * how drivers should call it.
  362. *
  363. * Releases an MTRR region. If the usage count drops to zero the
  364. * register is freed and the region returns to default state.
  365. * On success the register is returned, on failure a negative error
  366. * code.
  367. */
  368. int mtrr_del_page(int reg, unsigned long base, unsigned long size)
  369. {
  370. int i, max;
  371. mtrr_type ltype;
  372. unsigned long lbase, lsize;
  373. int error = -EINVAL;
  374. if (!mtrr_enabled())
  375. return -ENODEV;
  376. max = num_var_ranges;
  377. /* No CPU hotplug when we change MTRR entries */
  378. cpus_read_lock();
  379. mutex_lock(&mtrr_mutex);
  380. if (reg < 0) {
  381. /* Search for existing MTRR */
  382. for (i = 0; i < max; ++i) {
  383. mtrr_if->get(i, &lbase, &lsize, &ltype);
  384. if (lbase == base && lsize == size) {
  385. reg = i;
  386. break;
  387. }
  388. }
  389. if (reg < 0) {
  390. Dprintk("no MTRR for %lx000,%lx000 found\n", base, size);
  391. goto out;
  392. }
  393. }
  394. if (reg >= max) {
  395. pr_warn("register: %d too big\n", reg);
  396. goto out;
  397. }
  398. mtrr_if->get(reg, &lbase, &lsize, &ltype);
  399. if (lsize < 1) {
  400. pr_warn("MTRR %d not used\n", reg);
  401. goto out;
  402. }
  403. if (mtrr_usage_table[reg] < 1) {
  404. pr_warn("reg: %d has count=0\n", reg);
  405. goto out;
  406. }
  407. if (--mtrr_usage_table[reg] < 1)
  408. set_mtrr(reg, 0, 0, 0);
  409. error = reg;
  410. out:
  411. mutex_unlock(&mtrr_mutex);
  412. cpus_read_unlock();
  413. return error;
  414. }
  415. /**
  416. * mtrr_del - delete a memory type region
  417. * @reg: Register returned by mtrr_add
  418. * @base: Physical base address
  419. * @size: Size of region
  420. *
  421. * If register is supplied then base and size are ignored. This is
  422. * how drivers should call it.
  423. *
  424. * Releases an MTRR region. If the usage count drops to zero the
  425. * register is freed and the region returns to default state.
  426. * On success the register is returned, on failure a negative error
  427. * code.
  428. */
  429. int mtrr_del(int reg, unsigned long base, unsigned long size)
  430. {
  431. if (!mtrr_enabled())
  432. return -ENODEV;
  433. if (mtrr_check(base, size))
  434. return -EINVAL;
  435. return mtrr_del_page(reg, base >> PAGE_SHIFT, size >> PAGE_SHIFT);
  436. }
  437. /**
  438. * arch_phys_wc_add - add a WC MTRR and handle errors if PAT is unavailable
  439. * @base: Physical base address
  440. * @size: Size of region
  441. *
  442. * If PAT is available, this does nothing. If PAT is unavailable, it
  443. * attempts to add a WC MTRR covering size bytes starting at base and
  444. * logs an error if this fails.
  445. *
  446. * The called should provide a power of two size on an equivalent
  447. * power of two boundary.
  448. *
  449. * Drivers must store the return value to pass to mtrr_del_wc_if_needed,
  450. * but drivers should not try to interpret that return value.
  451. */
  452. int arch_phys_wc_add(unsigned long base, unsigned long size)
  453. {
  454. int ret;
  455. if (pat_enabled() || !mtrr_enabled())
  456. return 0; /* Success! (We don't need to do anything.) */
  457. ret = mtrr_add(base, size, MTRR_TYPE_WRCOMB, true);
  458. if (ret < 0) {
  459. pr_warn("Failed to add WC MTRR for [%p-%p]; performance may suffer.",
  460. (void *)base, (void *)(base + size - 1));
  461. return ret;
  462. }
  463. return ret + MTRR_TO_PHYS_WC_OFFSET;
  464. }
  465. EXPORT_SYMBOL(arch_phys_wc_add);
  466. /*
  467. * arch_phys_wc_del - undoes arch_phys_wc_add
  468. * @handle: Return value from arch_phys_wc_add
  469. *
  470. * This cleans up after mtrr_add_wc_if_needed.
  471. *
  472. * The API guarantees that mtrr_del_wc_if_needed(error code) and
  473. * mtrr_del_wc_if_needed(0) do nothing.
  474. */
  475. void arch_phys_wc_del(int handle)
  476. {
  477. if (handle >= 1) {
  478. WARN_ON(handle < MTRR_TO_PHYS_WC_OFFSET);
  479. mtrr_del(handle - MTRR_TO_PHYS_WC_OFFSET, 0, 0);
  480. }
  481. }
  482. EXPORT_SYMBOL(arch_phys_wc_del);
  483. /*
  484. * arch_phys_wc_index - translates arch_phys_wc_add's return value
  485. * @handle: Return value from arch_phys_wc_add
  486. *
  487. * This will turn the return value from arch_phys_wc_add into an mtrr
  488. * index suitable for debugging.
  489. *
  490. * Note: There is no legitimate use for this function, except possibly
  491. * in printk line. Alas there is an illegitimate use in some ancient
  492. * drm ioctls.
  493. */
  494. int arch_phys_wc_index(int handle)
  495. {
  496. if (handle < MTRR_TO_PHYS_WC_OFFSET)
  497. return -1;
  498. else
  499. return handle - MTRR_TO_PHYS_WC_OFFSET;
  500. }
  501. EXPORT_SYMBOL_GPL(arch_phys_wc_index);
  502. int __initdata changed_by_mtrr_cleanup;
  503. /**
  504. * mtrr_bp_init - initialize MTRRs on the boot CPU
  505. *
  506. * This needs to be called early; before any of the other CPUs are
  507. * initialized (i.e. before smp_init()).
  508. */
  509. void __init mtrr_bp_init(void)
  510. {
  511. bool generic_mtrrs = cpu_feature_enabled(X86_FEATURE_MTRR);
  512. const char *why = "(not available)";
  513. unsigned long config, dummy;
  514. phys_hi_rsvd = GENMASK(31, boot_cpu_data.x86_phys_bits - 32);
  515. if (!generic_mtrrs && mtrr_state.enabled) {
  516. /*
  517. * Software overwrite of MTRR state, only for generic case.
  518. * Note that X86_FEATURE_MTRR has been reset in this case.
  519. */
  520. init_table();
  521. mtrr_build_map();
  522. pr_info("MTRRs set to read-only\n");
  523. return;
  524. }
  525. if (generic_mtrrs)
  526. mtrr_if = &generic_mtrr_ops;
  527. else
  528. mtrr_set_if();
  529. if (mtrr_enabled()) {
  530. /* Get the number of variable MTRR ranges. */
  531. if (mtrr_if == &generic_mtrr_ops)
  532. rdmsr(MSR_MTRRcap, config, dummy);
  533. else
  534. config = mtrr_if->var_regs;
  535. num_var_ranges = config & MTRR_CAP_VCNT;
  536. init_table();
  537. if (mtrr_if == &generic_mtrr_ops) {
  538. /* BIOS may override */
  539. if (get_mtrr_state()) {
  540. memory_caching_control |= CACHE_MTRR;
  541. changed_by_mtrr_cleanup = mtrr_cleanup();
  542. mtrr_build_map();
  543. } else {
  544. mtrr_if = NULL;
  545. why = "by BIOS";
  546. }
  547. }
  548. }
  549. if (!mtrr_enabled())
  550. pr_info("MTRRs disabled %s\n", why);
  551. }
  552. /**
  553. * mtrr_save_state - Save current fixed-range MTRR state of the first
  554. * cpu in cpu_online_mask.
  555. */
  556. void mtrr_save_state(void)
  557. {
  558. int first_cpu;
  559. if (!mtrr_enabled() || !mtrr_state.have_fixed)
  560. return;
  561. first_cpu = cpumask_first(cpu_online_mask);
  562. smp_call_function_single(first_cpu, mtrr_save_fixed_ranges, NULL, 1);
  563. }
  564. static int __init mtrr_init_finalize(void)
  565. {
  566. /*
  567. * Map might exist if guest_force_mtrr_state() has been called or if
  568. * mtrr_enabled() returns true.
  569. */
  570. mtrr_copy_map();
  571. if (!mtrr_enabled())
  572. return 0;
  573. if (memory_caching_control & CACHE_MTRR) {
  574. if (!changed_by_mtrr_cleanup)
  575. mtrr_state_warn();
  576. return 0;
  577. }
  578. mtrr_register_syscore();
  579. return 0;
  580. }
  581. subsys_initcall(mtrr_init_finalize);