main.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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/module.h>
  27. #include <linux/init.h>
  28. #include <linux/pci.h>
  29. #include <linux/smp.h>
  30. #include <linux/cpu.h>
  31. #include <linux/mutex.h>
  32. #include <asm/mtrr.h>
  33. #include <asm/uaccess.h>
  34. #include <asm/processor.h>
  35. #include <asm/msr.h>
  36. #include "mtrr.h"
  37. u32 num_var_ranges = 0;
  38. unsigned int *usage_table;
  39. static DEFINE_MUTEX(mtrr_mutex);
  40. u32 size_or_mask, size_and_mask;
  41. static struct mtrr_ops * mtrr_ops[X86_VENDOR_NUM] = {};
  42. struct mtrr_ops * mtrr_if = NULL;
  43. static void set_mtrr(unsigned int reg, unsigned long base,
  44. unsigned long size, mtrr_type type);
  45. extern int arr3_protected;
  46. void set_mtrr_ops(struct mtrr_ops * ops)
  47. {
  48. if (ops->vendor && ops->vendor < X86_VENDOR_NUM)
  49. mtrr_ops[ops->vendor] = ops;
  50. }
  51. /* Returns non-zero if we have the write-combining memory type */
  52. static int have_wrcomb(void)
  53. {
  54. struct pci_dev *dev;
  55. u8 rev;
  56. if ((dev = pci_get_class(PCI_CLASS_BRIDGE_HOST << 8, NULL)) != NULL) {
  57. /* ServerWorks LE chipsets < rev 6 have problems with write-combining
  58. Don't allow it and leave room for other chipsets to be tagged */
  59. if (dev->vendor == PCI_VENDOR_ID_SERVERWORKS &&
  60. dev->device == PCI_DEVICE_ID_SERVERWORKS_LE) {
  61. pci_read_config_byte(dev, PCI_CLASS_REVISION, &rev);
  62. if (rev <= 5) {
  63. printk(KERN_INFO "mtrr: Serverworks LE rev < 6 detected. Write-combining disabled.\n");
  64. pci_dev_put(dev);
  65. return 0;
  66. }
  67. }
  68. /* Intel 450NX errata # 23. Non ascending cacheline evictions to
  69. write combining memory may resulting in data corruption */
  70. if (dev->vendor == PCI_VENDOR_ID_INTEL &&
  71. dev->device == PCI_DEVICE_ID_INTEL_82451NX) {
  72. printk(KERN_INFO "mtrr: Intel 450NX MMC detected. Write-combining disabled.\n");
  73. pci_dev_put(dev);
  74. return 0;
  75. }
  76. pci_dev_put(dev);
  77. }
  78. return (mtrr_if->have_wrcomb ? mtrr_if->have_wrcomb() : 0);
  79. }
  80. /* This function returns the number of variable MTRRs */
  81. static void __init set_num_var_ranges(void)
  82. {
  83. unsigned long config = 0, dummy;
  84. if (use_intel()) {
  85. rdmsr(MTRRcap_MSR, config, dummy);
  86. } else if (is_cpu(AMD))
  87. config = 2;
  88. else if (is_cpu(CYRIX) || is_cpu(CENTAUR))
  89. config = 8;
  90. num_var_ranges = config & 0xff;
  91. }
  92. static void __init init_table(void)
  93. {
  94. int i, max;
  95. max = num_var_ranges;
  96. if ((usage_table = kmalloc(max * sizeof *usage_table, GFP_KERNEL))
  97. == NULL) {
  98. printk(KERN_ERR "mtrr: could not allocate\n");
  99. return;
  100. }
  101. for (i = 0; i < max; i++)
  102. usage_table[i] = 1;
  103. }
  104. struct set_mtrr_data {
  105. atomic_t count;
  106. atomic_t gate;
  107. unsigned long smp_base;
  108. unsigned long smp_size;
  109. unsigned int smp_reg;
  110. mtrr_type smp_type;
  111. };
  112. #ifdef CONFIG_SMP
  113. static void ipi_handler(void *info)
  114. /* [SUMMARY] Synchronisation handler. Executed by "other" CPUs.
  115. [RETURNS] Nothing.
  116. */
  117. {
  118. struct set_mtrr_data *data = info;
  119. unsigned long flags;
  120. local_irq_save(flags);
  121. atomic_dec(&data->count);
  122. while(!atomic_read(&data->gate))
  123. cpu_relax();
  124. /* The master has cleared me to execute */
  125. if (data->smp_reg != ~0U)
  126. mtrr_if->set(data->smp_reg, data->smp_base,
  127. data->smp_size, data->smp_type);
  128. else
  129. mtrr_if->set_all();
  130. atomic_dec(&data->count);
  131. while(atomic_read(&data->gate))
  132. cpu_relax();
  133. atomic_dec(&data->count);
  134. local_irq_restore(flags);
  135. }
  136. #endif
  137. /**
  138. * set_mtrr - update mtrrs on all processors
  139. * @reg: mtrr in question
  140. * @base: mtrr base
  141. * @size: mtrr size
  142. * @type: mtrr type
  143. *
  144. * This is kinda tricky, but fortunately, Intel spelled it out for us cleanly:
  145. *
  146. * 1. Send IPI to do the following:
  147. * 2. Disable Interrupts
  148. * 3. Wait for all procs to do so
  149. * 4. Enter no-fill cache mode
  150. * 5. Flush caches
  151. * 6. Clear PGE bit
  152. * 7. Flush all TLBs
  153. * 8. Disable all range registers
  154. * 9. Update the MTRRs
  155. * 10. Enable all range registers
  156. * 11. Flush all TLBs and caches again
  157. * 12. Enter normal cache mode and reenable caching
  158. * 13. Set PGE
  159. * 14. Wait for buddies to catch up
  160. * 15. Enable interrupts.
  161. *
  162. * What does that mean for us? Well, first we set data.count to the number
  163. * of CPUs. As each CPU disables interrupts, it'll decrement it once. We wait
  164. * until it hits 0 and proceed. We set the data.gate flag and reset data.count.
  165. * Meanwhile, they are waiting for that flag to be set. Once it's set, each
  166. * CPU goes through the transition of updating MTRRs. The CPU vendors may each do it
  167. * differently, so we call mtrr_if->set() callback and let them take care of it.
  168. * When they're done, they again decrement data->count and wait for data.gate to
  169. * be reset.
  170. * When we finish, we wait for data.count to hit 0 and toggle the data.gate flag.
  171. * Everyone then enables interrupts and we all continue on.
  172. *
  173. * Note that the mechanism is the same for UP systems, too; all the SMP stuff
  174. * becomes nops.
  175. */
  176. static void set_mtrr(unsigned int reg, unsigned long base,
  177. unsigned long size, mtrr_type type)
  178. {
  179. struct set_mtrr_data data;
  180. unsigned long flags;
  181. data.smp_reg = reg;
  182. data.smp_base = base;
  183. data.smp_size = size;
  184. data.smp_type = type;
  185. atomic_set(&data.count, num_booting_cpus() - 1);
  186. atomic_set(&data.gate,0);
  187. /* Start the ball rolling on other CPUs */
  188. if (smp_call_function(ipi_handler, &data, 1, 0) != 0)
  189. panic("mtrr: timed out waiting for other CPUs\n");
  190. local_irq_save(flags);
  191. while(atomic_read(&data.count))
  192. cpu_relax();
  193. /* ok, reset count and toggle gate */
  194. atomic_set(&data.count, num_booting_cpus() - 1);
  195. atomic_set(&data.gate,1);
  196. /* do our MTRR business */
  197. /* HACK!
  198. * We use this same function to initialize the mtrrs on boot.
  199. * The state of the boot cpu's mtrrs has been saved, and we want
  200. * to replicate across all the APs.
  201. * If we're doing that @reg is set to something special...
  202. */
  203. if (reg != ~0U)
  204. mtrr_if->set(reg,base,size,type);
  205. /* wait for the others */
  206. while(atomic_read(&data.count))
  207. cpu_relax();
  208. atomic_set(&data.count, num_booting_cpus() - 1);
  209. atomic_set(&data.gate,0);
  210. /*
  211. * Wait here for everyone to have seen the gate change
  212. * So we're the last ones to touch 'data'
  213. */
  214. while(atomic_read(&data.count))
  215. cpu_relax();
  216. local_irq_restore(flags);
  217. }
  218. /**
  219. * mtrr_add_page - Add a memory type region
  220. * @base: Physical base address of region in pages (4 KB)
  221. * @size: Physical size of region in pages (4 KB)
  222. * @type: Type of MTRR desired
  223. * @increment: If this is true do usage counting on the region
  224. *
  225. * Memory type region registers control the caching on newer Intel and
  226. * non Intel processors. This function allows drivers to request an
  227. * MTRR is added. The details and hardware specifics of each processor's
  228. * implementation are hidden from the caller, but nevertheless the
  229. * caller should expect to need to provide a power of two size on an
  230. * equivalent power of two boundary.
  231. *
  232. * If the region cannot be added either because all regions are in use
  233. * or the CPU cannot support it a negative value is returned. On success
  234. * the register number for this entry is returned, but should be treated
  235. * as a cookie only.
  236. *
  237. * On a multiprocessor machine the changes are made to all processors.
  238. * This is required on x86 by the Intel processors.
  239. *
  240. * The available types are
  241. *
  242. * %MTRR_TYPE_UNCACHABLE - No caching
  243. *
  244. * %MTRR_TYPE_WRBACK - Write data back in bursts whenever
  245. *
  246. * %MTRR_TYPE_WRCOMB - Write data back soon but allow bursts
  247. *
  248. * %MTRR_TYPE_WRTHROUGH - Cache reads but not writes
  249. *
  250. * BUGS: Needs a quiet flag for the cases where drivers do not mind
  251. * failures and do not wish system log messages to be sent.
  252. */
  253. int mtrr_add_page(unsigned long base, unsigned long size,
  254. unsigned int type, char increment)
  255. {
  256. int i;
  257. mtrr_type ltype;
  258. unsigned long lbase;
  259. unsigned int lsize;
  260. int error;
  261. if (!mtrr_if)
  262. return -ENXIO;
  263. if ((error = mtrr_if->validate_add_page(base,size,type)))
  264. return error;
  265. if (type >= MTRR_NUM_TYPES) {
  266. printk(KERN_WARNING "mtrr: type: %u invalid\n", type);
  267. return -EINVAL;
  268. }
  269. /* If the type is WC, check that this processor supports it */
  270. if ((type == MTRR_TYPE_WRCOMB) && !have_wrcomb()) {
  271. printk(KERN_WARNING
  272. "mtrr: your processor doesn't support write-combining\n");
  273. return -ENOSYS;
  274. }
  275. if (base & size_or_mask || size & size_or_mask) {
  276. printk(KERN_WARNING "mtrr: base or size exceeds the MTRR width\n");
  277. return -EINVAL;
  278. }
  279. error = -EINVAL;
  280. /* No CPU hotplug when we change MTRR entries */
  281. lock_cpu_hotplug();
  282. /* Search for existing MTRR */
  283. mutex_lock(&mtrr_mutex);
  284. for (i = 0; i < num_var_ranges; ++i) {
  285. mtrr_if->get(i, &lbase, &lsize, &ltype);
  286. if (base >= lbase + lsize)
  287. continue;
  288. if ((base < lbase) && (base + size <= lbase))
  289. continue;
  290. /* At this point we know there is some kind of overlap/enclosure */
  291. if ((base < lbase) || (base + size > lbase + lsize)) {
  292. printk(KERN_WARNING
  293. "mtrr: 0x%lx000,0x%lx000 overlaps existing"
  294. " 0x%lx000,0x%x000\n", base, size, lbase,
  295. lsize);
  296. goto out;
  297. }
  298. /* New region is enclosed by an existing region */
  299. if (ltype != type) {
  300. if (type == MTRR_TYPE_UNCACHABLE)
  301. continue;
  302. printk (KERN_WARNING "mtrr: type mismatch for %lx000,%lx000 old: %s new: %s\n",
  303. base, size, mtrr_attrib_to_str(ltype),
  304. mtrr_attrib_to_str(type));
  305. goto out;
  306. }
  307. if (increment)
  308. ++usage_table[i];
  309. error = i;
  310. goto out;
  311. }
  312. /* Search for an empty MTRR */
  313. i = mtrr_if->get_free_region(base, size);
  314. if (i >= 0) {
  315. set_mtrr(i, base, size, type);
  316. usage_table[i] = 1;
  317. } else
  318. printk(KERN_INFO "mtrr: no more MTRRs available\n");
  319. error = i;
  320. out:
  321. mutex_unlock(&mtrr_mutex);
  322. unlock_cpu_hotplug();
  323. return error;
  324. }
  325. static int mtrr_check(unsigned long base, unsigned long size)
  326. {
  327. if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1))) {
  328. printk(KERN_WARNING
  329. "mtrr: size and base must be multiples of 4 kiB\n");
  330. printk(KERN_DEBUG
  331. "mtrr: size: 0x%lx base: 0x%lx\n", size, base);
  332. dump_stack();
  333. return -1;
  334. }
  335. return 0;
  336. }
  337. /**
  338. * mtrr_add - Add a memory type region
  339. * @base: Physical base address of region
  340. * @size: Physical size of region
  341. * @type: Type of MTRR desired
  342. * @increment: If this is true do usage counting on the region
  343. *
  344. * Memory type region registers control the caching on newer Intel and
  345. * non Intel processors. This function allows drivers to request an
  346. * MTRR is added. The details and hardware specifics of each processor's
  347. * implementation are hidden from the caller, but nevertheless the
  348. * caller should expect to need to provide a power of two size on an
  349. * equivalent power of two boundary.
  350. *
  351. * If the region cannot be added either because all regions are in use
  352. * or the CPU cannot support it a negative value is returned. On success
  353. * the register number for this entry is returned, but should be treated
  354. * as a cookie only.
  355. *
  356. * On a multiprocessor machine the changes are made to all processors.
  357. * This is required on x86 by the Intel processors.
  358. *
  359. * The available types are
  360. *
  361. * %MTRR_TYPE_UNCACHABLE - No caching
  362. *
  363. * %MTRR_TYPE_WRBACK - Write data back in bursts whenever
  364. *
  365. * %MTRR_TYPE_WRCOMB - Write data back soon but allow bursts
  366. *
  367. * %MTRR_TYPE_WRTHROUGH - Cache reads but not writes
  368. *
  369. * BUGS: Needs a quiet flag for the cases where drivers do not mind
  370. * failures and do not wish system log messages to be sent.
  371. */
  372. int
  373. mtrr_add(unsigned long base, unsigned long size, unsigned int type,
  374. char increment)
  375. {
  376. if (mtrr_check(base, size))
  377. return -EINVAL;
  378. return mtrr_add_page(base >> PAGE_SHIFT, size >> PAGE_SHIFT, type,
  379. increment);
  380. }
  381. /**
  382. * mtrr_del_page - delete a memory type region
  383. * @reg: Register returned by mtrr_add
  384. * @base: Physical base address
  385. * @size: Size of region
  386. *
  387. * If register is supplied then base and size are ignored. This is
  388. * how drivers should call it.
  389. *
  390. * Releases an MTRR region. If the usage count drops to zero the
  391. * register is freed and the region returns to default state.
  392. * On success the register is returned, on failure a negative error
  393. * code.
  394. */
  395. int mtrr_del_page(int reg, unsigned long base, unsigned long size)
  396. {
  397. int i, max;
  398. mtrr_type ltype;
  399. unsigned long lbase;
  400. unsigned int lsize;
  401. int error = -EINVAL;
  402. if (!mtrr_if)
  403. return -ENXIO;
  404. max = num_var_ranges;
  405. /* No CPU hotplug when we change MTRR entries */
  406. lock_cpu_hotplug();
  407. mutex_lock(&mtrr_mutex);
  408. if (reg < 0) {
  409. /* Search for existing MTRR */
  410. for (i = 0; i < max; ++i) {
  411. mtrr_if->get(i, &lbase, &lsize, &ltype);
  412. if (lbase == base && lsize == size) {
  413. reg = i;
  414. break;
  415. }
  416. }
  417. if (reg < 0) {
  418. printk(KERN_DEBUG "mtrr: no MTRR for %lx000,%lx000 found\n", base,
  419. size);
  420. goto out;
  421. }
  422. }
  423. if (reg >= max) {
  424. printk(KERN_WARNING "mtrr: register: %d too big\n", reg);
  425. goto out;
  426. }
  427. if (is_cpu(CYRIX) && !use_intel()) {
  428. if ((reg == 3) && arr3_protected) {
  429. printk(KERN_WARNING "mtrr: ARR3 cannot be changed\n");
  430. goto out;
  431. }
  432. }
  433. mtrr_if->get(reg, &lbase, &lsize, &ltype);
  434. if (lsize < 1) {
  435. printk(KERN_WARNING "mtrr: MTRR %d not used\n", reg);
  436. goto out;
  437. }
  438. if (usage_table[reg] < 1) {
  439. printk(KERN_WARNING "mtrr: reg: %d has count=0\n", reg);
  440. goto out;
  441. }
  442. if (--usage_table[reg] < 1)
  443. set_mtrr(reg, 0, 0, 0);
  444. error = reg;
  445. out:
  446. mutex_unlock(&mtrr_mutex);
  447. unlock_cpu_hotplug();
  448. return error;
  449. }
  450. /**
  451. * mtrr_del - delete a memory type region
  452. * @reg: Register returned by mtrr_add
  453. * @base: Physical base address
  454. * @size: Size of region
  455. *
  456. * If register is supplied then base and size are ignored. This is
  457. * how drivers should call it.
  458. *
  459. * Releases an MTRR region. If the usage count drops to zero the
  460. * register is freed and the region returns to default state.
  461. * On success the register is returned, on failure a negative error
  462. * code.
  463. */
  464. int
  465. mtrr_del(int reg, unsigned long base, unsigned long size)
  466. {
  467. if (mtrr_check(base, size))
  468. return -EINVAL;
  469. return mtrr_del_page(reg, base >> PAGE_SHIFT, size >> PAGE_SHIFT);
  470. }
  471. EXPORT_SYMBOL(mtrr_add);
  472. EXPORT_SYMBOL(mtrr_del);
  473. /* HACK ALERT!
  474. * These should be called implicitly, but we can't yet until all the initcall
  475. * stuff is done...
  476. */
  477. extern void amd_init_mtrr(void);
  478. extern void cyrix_init_mtrr(void);
  479. extern void centaur_init_mtrr(void);
  480. static void __init init_ifs(void)
  481. {
  482. amd_init_mtrr();
  483. cyrix_init_mtrr();
  484. centaur_init_mtrr();
  485. }
  486. /* The suspend/resume methods are only for CPU without MTRR. CPU using generic
  487. * MTRR driver doesn't require this
  488. */
  489. struct mtrr_value {
  490. mtrr_type ltype;
  491. unsigned long lbase;
  492. unsigned int lsize;
  493. };
  494. static struct mtrr_value * mtrr_state;
  495. static int mtrr_save(struct sys_device * sysdev, pm_message_t state)
  496. {
  497. int i;
  498. int size = num_var_ranges * sizeof(struct mtrr_value);
  499. mtrr_state = kmalloc(size,GFP_ATOMIC);
  500. if (mtrr_state)
  501. memset(mtrr_state,0,size);
  502. else
  503. return -ENOMEM;
  504. for (i = 0; i < num_var_ranges; i++) {
  505. mtrr_if->get(i,
  506. &mtrr_state[i].lbase,
  507. &mtrr_state[i].lsize,
  508. &mtrr_state[i].ltype);
  509. }
  510. return 0;
  511. }
  512. static int mtrr_restore(struct sys_device * sysdev)
  513. {
  514. int i;
  515. for (i = 0; i < num_var_ranges; i++) {
  516. if (mtrr_state[i].lsize)
  517. set_mtrr(i,
  518. mtrr_state[i].lbase,
  519. mtrr_state[i].lsize,
  520. mtrr_state[i].ltype);
  521. }
  522. kfree(mtrr_state);
  523. return 0;
  524. }
  525. static struct sysdev_driver mtrr_sysdev_driver = {
  526. .suspend = mtrr_save,
  527. .resume = mtrr_restore,
  528. };
  529. /**
  530. * mtrr_bp_init - initialize mtrrs on the boot CPU
  531. *
  532. * This needs to be called early; before any of the other CPUs are
  533. * initialized (i.e. before smp_init()).
  534. *
  535. */
  536. void __init mtrr_bp_init(void)
  537. {
  538. init_ifs();
  539. if (cpu_has_mtrr) {
  540. mtrr_if = &generic_mtrr_ops;
  541. size_or_mask = 0xff000000; /* 36 bits */
  542. size_and_mask = 0x00f00000;
  543. /* This is an AMD specific MSR, but we assume(hope?) that
  544. Intel will implement it to when they extend the address
  545. bus of the Xeon. */
  546. if (cpuid_eax(0x80000000) >= 0x80000008) {
  547. u32 phys_addr;
  548. phys_addr = cpuid_eax(0x80000008) & 0xff;
  549. /* CPUID workaround for Intel 0F33/0F34 CPU */
  550. if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
  551. boot_cpu_data.x86 == 0xF &&
  552. boot_cpu_data.x86_model == 0x3 &&
  553. (boot_cpu_data.x86_mask == 0x3 ||
  554. boot_cpu_data.x86_mask == 0x4))
  555. phys_addr = 36;
  556. size_or_mask = ~((1 << (phys_addr - PAGE_SHIFT)) - 1);
  557. size_and_mask = ~size_or_mask & 0xfff00000;
  558. } else if (boot_cpu_data.x86_vendor == X86_VENDOR_CENTAUR &&
  559. boot_cpu_data.x86 == 6) {
  560. /* VIA C* family have Intel style MTRRs, but
  561. don't support PAE */
  562. size_or_mask = 0xfff00000; /* 32 bits */
  563. size_and_mask = 0;
  564. }
  565. } else {
  566. switch (boot_cpu_data.x86_vendor) {
  567. case X86_VENDOR_AMD:
  568. if (cpu_has_k6_mtrr) {
  569. /* Pre-Athlon (K6) AMD CPU MTRRs */
  570. mtrr_if = mtrr_ops[X86_VENDOR_AMD];
  571. size_or_mask = 0xfff00000; /* 32 bits */
  572. size_and_mask = 0;
  573. }
  574. break;
  575. case X86_VENDOR_CENTAUR:
  576. if (cpu_has_centaur_mcr) {
  577. mtrr_if = mtrr_ops[X86_VENDOR_CENTAUR];
  578. size_or_mask = 0xfff00000; /* 32 bits */
  579. size_and_mask = 0;
  580. }
  581. break;
  582. case X86_VENDOR_CYRIX:
  583. if (cpu_has_cyrix_arr) {
  584. mtrr_if = mtrr_ops[X86_VENDOR_CYRIX];
  585. size_or_mask = 0xfff00000; /* 32 bits */
  586. size_and_mask = 0;
  587. }
  588. break;
  589. default:
  590. break;
  591. }
  592. }
  593. if (mtrr_if) {
  594. set_num_var_ranges();
  595. init_table();
  596. if (use_intel())
  597. get_mtrr_state();
  598. }
  599. }
  600. void mtrr_ap_init(void)
  601. {
  602. unsigned long flags;
  603. if (!mtrr_if || !use_intel())
  604. return;
  605. /*
  606. * Ideally we should hold mtrr_mutex here to avoid mtrr entries changed,
  607. * but this routine will be called in cpu boot time, holding the lock
  608. * breaks it. This routine is called in two cases: 1.very earily time
  609. * of software resume, when there absolutely isn't mtrr entry changes;
  610. * 2.cpu hotadd time. We let mtrr_add/del_page hold cpuhotplug lock to
  611. * prevent mtrr entry changes
  612. */
  613. local_irq_save(flags);
  614. mtrr_if->set_all();
  615. local_irq_restore(flags);
  616. }
  617. static int __init mtrr_init_finialize(void)
  618. {
  619. if (!mtrr_if)
  620. return 0;
  621. if (use_intel())
  622. mtrr_state_warn();
  623. else {
  624. /* The CPUs haven't MTRR and seemes not support SMP. They have
  625. * specific drivers, we use a tricky method to support
  626. * suspend/resume for them.
  627. * TBD: is there any system with such CPU which supports
  628. * suspend/resume? if no, we should remove the code.
  629. */
  630. sysdev_driver_register(&cpu_sysdev_class,
  631. &mtrr_sysdev_driver);
  632. }
  633. return 0;
  634. }
  635. subsys_initcall(mtrr_init_finialize);