init.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717
  1. /* $Id: init.c,v 1.209 2002/02/09 19:49:31 davem Exp $
  2. * arch/sparc64/mm/init.c
  3. *
  4. * Copyright (C) 1996-1999 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1997-1999 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  6. */
  7. #include <linux/config.h>
  8. #include <linux/kernel.h>
  9. #include <linux/sched.h>
  10. #include <linux/string.h>
  11. #include <linux/init.h>
  12. #include <linux/bootmem.h>
  13. #include <linux/mm.h>
  14. #include <linux/hugetlb.h>
  15. #include <linux/slab.h>
  16. #include <linux/initrd.h>
  17. #include <linux/swap.h>
  18. #include <linux/pagemap.h>
  19. #include <linux/fs.h>
  20. #include <linux/seq_file.h>
  21. #include <linux/kprobes.h>
  22. #include <linux/cache.h>
  23. #include <linux/sort.h>
  24. #include <asm/head.h>
  25. #include <asm/system.h>
  26. #include <asm/page.h>
  27. #include <asm/pgalloc.h>
  28. #include <asm/pgtable.h>
  29. #include <asm/oplib.h>
  30. #include <asm/iommu.h>
  31. #include <asm/io.h>
  32. #include <asm/uaccess.h>
  33. #include <asm/mmu_context.h>
  34. #include <asm/tlbflush.h>
  35. #include <asm/dma.h>
  36. #include <asm/starfire.h>
  37. #include <asm/tlb.h>
  38. #include <asm/spitfire.h>
  39. #include <asm/sections.h>
  40. extern void device_scan(void);
  41. #define MAX_BANKS 32
  42. static struct linux_prom64_registers pavail[MAX_BANKS] __initdata;
  43. static struct linux_prom64_registers pavail_rescan[MAX_BANKS] __initdata;
  44. static int pavail_ents __initdata;
  45. static int pavail_rescan_ents __initdata;
  46. static int cmp_p64(const void *a, const void *b)
  47. {
  48. const struct linux_prom64_registers *x = a, *y = b;
  49. if (x->phys_addr > y->phys_addr)
  50. return 1;
  51. if (x->phys_addr < y->phys_addr)
  52. return -1;
  53. return 0;
  54. }
  55. static void __init read_obp_memory(const char *property,
  56. struct linux_prom64_registers *regs,
  57. int *num_ents)
  58. {
  59. int node = prom_finddevice("/memory");
  60. int prop_size = prom_getproplen(node, property);
  61. int ents, ret, i;
  62. ents = prop_size / sizeof(struct linux_prom64_registers);
  63. if (ents > MAX_BANKS) {
  64. prom_printf("The machine has more %s property entries than "
  65. "this kernel can support (%d).\n",
  66. property, MAX_BANKS);
  67. prom_halt();
  68. }
  69. ret = prom_getproperty(node, property, (char *) regs, prop_size);
  70. if (ret == -1) {
  71. prom_printf("Couldn't get %s property from /memory.\n");
  72. prom_halt();
  73. }
  74. *num_ents = ents;
  75. /* Sanitize what we got from the firmware, by page aligning
  76. * everything.
  77. */
  78. for (i = 0; i < ents; i++) {
  79. unsigned long base, size;
  80. base = regs[i].phys_addr;
  81. size = regs[i].reg_size;
  82. size &= PAGE_MASK;
  83. if (base & ~PAGE_MASK) {
  84. unsigned long new_base = PAGE_ALIGN(base);
  85. size -= new_base - base;
  86. if ((long) size < 0L)
  87. size = 0UL;
  88. base = new_base;
  89. }
  90. regs[i].phys_addr = base;
  91. regs[i].reg_size = size;
  92. }
  93. sort(regs, ents, sizeof(struct linux_prom64_registers),
  94. cmp_p64, NULL);
  95. }
  96. unsigned long *sparc64_valid_addr_bitmap __read_mostly;
  97. /* Ugly, but necessary... -DaveM */
  98. unsigned long phys_base __read_mostly;
  99. unsigned long kern_base __read_mostly;
  100. unsigned long kern_size __read_mostly;
  101. unsigned long pfn_base __read_mostly;
  102. /* get_new_mmu_context() uses "cache + 1". */
  103. DEFINE_SPINLOCK(ctx_alloc_lock);
  104. unsigned long tlb_context_cache = CTX_FIRST_VERSION - 1;
  105. #define CTX_BMAP_SLOTS (1UL << (CTX_NR_BITS - 6))
  106. unsigned long mmu_context_bmap[CTX_BMAP_SLOTS];
  107. /* References to special section boundaries */
  108. extern char _start[], _end[];
  109. /* Initial ramdisk setup */
  110. extern unsigned long sparc_ramdisk_image64;
  111. extern unsigned int sparc_ramdisk_image;
  112. extern unsigned int sparc_ramdisk_size;
  113. struct page *mem_map_zero __read_mostly;
  114. unsigned int sparc64_highest_unlocked_tlb_ent __read_mostly;
  115. unsigned long sparc64_kern_pri_context __read_mostly;
  116. unsigned long sparc64_kern_pri_nuc_bits __read_mostly;
  117. unsigned long sparc64_kern_sec_context __read_mostly;
  118. int bigkernel = 0;
  119. /* XXX Tune this... */
  120. #define PGT_CACHE_LOW 25
  121. #define PGT_CACHE_HIGH 50
  122. void check_pgt_cache(void)
  123. {
  124. preempt_disable();
  125. if (pgtable_cache_size > PGT_CACHE_HIGH) {
  126. do {
  127. if (pgd_quicklist)
  128. free_pgd_slow(get_pgd_fast());
  129. if (pte_quicklist[0])
  130. free_pte_slow(pte_alloc_one_fast(NULL, 0));
  131. if (pte_quicklist[1])
  132. free_pte_slow(pte_alloc_one_fast(NULL, 1 << (PAGE_SHIFT + 10)));
  133. } while (pgtable_cache_size > PGT_CACHE_LOW);
  134. }
  135. preempt_enable();
  136. }
  137. #ifdef CONFIG_DEBUG_DCFLUSH
  138. atomic_t dcpage_flushes = ATOMIC_INIT(0);
  139. #ifdef CONFIG_SMP
  140. atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
  141. #endif
  142. #endif
  143. __inline__ void flush_dcache_page_impl(struct page *page)
  144. {
  145. #ifdef CONFIG_DEBUG_DCFLUSH
  146. atomic_inc(&dcpage_flushes);
  147. #endif
  148. #ifdef DCACHE_ALIASING_POSSIBLE
  149. __flush_dcache_page(page_address(page),
  150. ((tlb_type == spitfire) &&
  151. page_mapping(page) != NULL));
  152. #else
  153. if (page_mapping(page) != NULL &&
  154. tlb_type == spitfire)
  155. __flush_icache_page(__pa(page_address(page)));
  156. #endif
  157. }
  158. #define PG_dcache_dirty PG_arch_1
  159. #define PG_dcache_cpu_shift 24
  160. #define PG_dcache_cpu_mask (256 - 1)
  161. #if NR_CPUS > 256
  162. #error D-cache dirty tracking and thread_info->cpu need fixing for > 256 cpus
  163. #endif
  164. #define dcache_dirty_cpu(page) \
  165. (((page)->flags >> PG_dcache_cpu_shift) & PG_dcache_cpu_mask)
  166. static __inline__ void set_dcache_dirty(struct page *page, int this_cpu)
  167. {
  168. unsigned long mask = this_cpu;
  169. unsigned long non_cpu_bits;
  170. non_cpu_bits = ~(PG_dcache_cpu_mask << PG_dcache_cpu_shift);
  171. mask = (mask << PG_dcache_cpu_shift) | (1UL << PG_dcache_dirty);
  172. __asm__ __volatile__("1:\n\t"
  173. "ldx [%2], %%g7\n\t"
  174. "and %%g7, %1, %%g1\n\t"
  175. "or %%g1, %0, %%g1\n\t"
  176. "casx [%2], %%g7, %%g1\n\t"
  177. "cmp %%g7, %%g1\n\t"
  178. "membar #StoreLoad | #StoreStore\n\t"
  179. "bne,pn %%xcc, 1b\n\t"
  180. " nop"
  181. : /* no outputs */
  182. : "r" (mask), "r" (non_cpu_bits), "r" (&page->flags)
  183. : "g1", "g7");
  184. }
  185. static __inline__ void clear_dcache_dirty_cpu(struct page *page, unsigned long cpu)
  186. {
  187. unsigned long mask = (1UL << PG_dcache_dirty);
  188. __asm__ __volatile__("! test_and_clear_dcache_dirty\n"
  189. "1:\n\t"
  190. "ldx [%2], %%g7\n\t"
  191. "srlx %%g7, %4, %%g1\n\t"
  192. "and %%g1, %3, %%g1\n\t"
  193. "cmp %%g1, %0\n\t"
  194. "bne,pn %%icc, 2f\n\t"
  195. " andn %%g7, %1, %%g1\n\t"
  196. "casx [%2], %%g7, %%g1\n\t"
  197. "cmp %%g7, %%g1\n\t"
  198. "membar #StoreLoad | #StoreStore\n\t"
  199. "bne,pn %%xcc, 1b\n\t"
  200. " nop\n"
  201. "2:"
  202. : /* no outputs */
  203. : "r" (cpu), "r" (mask), "r" (&page->flags),
  204. "i" (PG_dcache_cpu_mask),
  205. "i" (PG_dcache_cpu_shift)
  206. : "g1", "g7");
  207. }
  208. void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t pte)
  209. {
  210. struct page *page;
  211. unsigned long pfn;
  212. unsigned long pg_flags;
  213. pfn = pte_pfn(pte);
  214. if (pfn_valid(pfn) &&
  215. (page = pfn_to_page(pfn), page_mapping(page)) &&
  216. ((pg_flags = page->flags) & (1UL << PG_dcache_dirty))) {
  217. int cpu = ((pg_flags >> PG_dcache_cpu_shift) &
  218. PG_dcache_cpu_mask);
  219. int this_cpu = get_cpu();
  220. /* This is just to optimize away some function calls
  221. * in the SMP case.
  222. */
  223. if (cpu == this_cpu)
  224. flush_dcache_page_impl(page);
  225. else
  226. smp_flush_dcache_page_impl(page, cpu);
  227. clear_dcache_dirty_cpu(page, cpu);
  228. put_cpu();
  229. }
  230. }
  231. void flush_dcache_page(struct page *page)
  232. {
  233. struct address_space *mapping;
  234. int this_cpu;
  235. /* Do not bother with the expensive D-cache flush if it
  236. * is merely the zero page. The 'bigcore' testcase in GDB
  237. * causes this case to run millions of times.
  238. */
  239. if (page == ZERO_PAGE(0))
  240. return;
  241. this_cpu = get_cpu();
  242. mapping = page_mapping(page);
  243. if (mapping && !mapping_mapped(mapping)) {
  244. int dirty = test_bit(PG_dcache_dirty, &page->flags);
  245. if (dirty) {
  246. int dirty_cpu = dcache_dirty_cpu(page);
  247. if (dirty_cpu == this_cpu)
  248. goto out;
  249. smp_flush_dcache_page_impl(page, dirty_cpu);
  250. }
  251. set_dcache_dirty(page, this_cpu);
  252. } else {
  253. /* We could delay the flush for the !page_mapping
  254. * case too. But that case is for exec env/arg
  255. * pages and those are %99 certainly going to get
  256. * faulted into the tlb (and thus flushed) anyways.
  257. */
  258. flush_dcache_page_impl(page);
  259. }
  260. out:
  261. put_cpu();
  262. }
  263. void __kprobes flush_icache_range(unsigned long start, unsigned long end)
  264. {
  265. /* Cheetah has coherent I-cache. */
  266. if (tlb_type == spitfire) {
  267. unsigned long kaddr;
  268. for (kaddr = start; kaddr < end; kaddr += PAGE_SIZE)
  269. __flush_icache_page(__get_phys(kaddr));
  270. }
  271. }
  272. unsigned long page_to_pfn(struct page *page)
  273. {
  274. return (unsigned long) ((page - mem_map) + pfn_base);
  275. }
  276. struct page *pfn_to_page(unsigned long pfn)
  277. {
  278. return (mem_map + (pfn - pfn_base));
  279. }
  280. void show_mem(void)
  281. {
  282. printk("Mem-info:\n");
  283. show_free_areas();
  284. printk("Free swap: %6ldkB\n",
  285. nr_swap_pages << (PAGE_SHIFT-10));
  286. printk("%ld pages of RAM\n", num_physpages);
  287. printk("%d free pages\n", nr_free_pages());
  288. printk("%d pages in page table cache\n",pgtable_cache_size);
  289. }
  290. void mmu_info(struct seq_file *m)
  291. {
  292. if (tlb_type == cheetah)
  293. seq_printf(m, "MMU Type\t: Cheetah\n");
  294. else if (tlb_type == cheetah_plus)
  295. seq_printf(m, "MMU Type\t: Cheetah+\n");
  296. else if (tlb_type == spitfire)
  297. seq_printf(m, "MMU Type\t: Spitfire\n");
  298. else
  299. seq_printf(m, "MMU Type\t: ???\n");
  300. #ifdef CONFIG_DEBUG_DCFLUSH
  301. seq_printf(m, "DCPageFlushes\t: %d\n",
  302. atomic_read(&dcpage_flushes));
  303. #ifdef CONFIG_SMP
  304. seq_printf(m, "DCPageFlushesXC\t: %d\n",
  305. atomic_read(&dcpage_flushes_xcall));
  306. #endif /* CONFIG_SMP */
  307. #endif /* CONFIG_DEBUG_DCFLUSH */
  308. }
  309. struct linux_prom_translation {
  310. unsigned long virt;
  311. unsigned long size;
  312. unsigned long data;
  313. };
  314. static struct linux_prom_translation prom_trans[512] __initdata;
  315. static unsigned int prom_trans_ents __initdata;
  316. extern unsigned long prom_boot_page;
  317. extern void prom_remap(unsigned long physpage, unsigned long virtpage, int mmu_ihandle);
  318. extern int prom_get_mmu_ihandle(void);
  319. extern void register_prom_callbacks(void);
  320. /* Exported for SMP bootup purposes. */
  321. unsigned long kern_locked_tte_data;
  322. /* Exported for kernel TLB miss handling in ktlb.S */
  323. unsigned long prom_pmd_phys __read_mostly;
  324. unsigned int swapper_pgd_zero __read_mostly;
  325. static pmd_t *prompmd __read_mostly;
  326. #define BASE_PAGE_SIZE 8192
  327. /*
  328. * Translate PROM's mapping we capture at boot time into physical address.
  329. * The second parameter is only set from prom_callback() invocations.
  330. */
  331. unsigned long prom_virt_to_phys(unsigned long promva, int *error)
  332. {
  333. pmd_t *pmdp = prompmd + ((promva >> 23) & 0x7ff);
  334. pte_t *ptep;
  335. unsigned long base;
  336. if (pmd_none(*pmdp)) {
  337. if (error)
  338. *error = 1;
  339. return 0;
  340. }
  341. ptep = (pte_t *)__pmd_page(*pmdp) + ((promva >> 13) & 0x3ff);
  342. if (!pte_present(*ptep)) {
  343. if (error)
  344. *error = 1;
  345. return 0;
  346. }
  347. if (error) {
  348. *error = 0;
  349. return pte_val(*ptep);
  350. }
  351. base = pte_val(*ptep) & _PAGE_PADDR;
  352. return base + (promva & (BASE_PAGE_SIZE - 1));
  353. }
  354. /* The obp translations are saved based on 8k pagesize, since obp can
  355. * use a mixture of pagesizes. Misses to the LOW_OBP_ADDRESS ->
  356. * HI_OBP_ADDRESS range are handled in entry.S and do not use the vpte
  357. * scheme (also, see rant in inherit_locked_prom_mappings()).
  358. */
  359. static void __init build_obp_range(unsigned long start, unsigned long end, unsigned long data)
  360. {
  361. unsigned long vaddr;
  362. for (vaddr = start; vaddr < end; vaddr += BASE_PAGE_SIZE) {
  363. unsigned long val;
  364. pmd_t *pmd;
  365. pte_t *pte;
  366. pmd = prompmd + ((vaddr >> 23) & 0x7ff);
  367. if (pmd_none(*pmd)) {
  368. pte = __alloc_bootmem(BASE_PAGE_SIZE, BASE_PAGE_SIZE,
  369. PAGE_SIZE);
  370. if (!pte)
  371. prom_halt();
  372. memset(pte, 0, BASE_PAGE_SIZE);
  373. pmd_set(pmd, pte);
  374. }
  375. pte = (pte_t *) __pmd_page(*pmd) + ((vaddr >> 13) & 0x3ff);
  376. val = data;
  377. /* Clear diag TTE bits. */
  378. if (tlb_type == spitfire)
  379. val &= ~0x0003fe0000000000UL;
  380. set_pte_at(&init_mm, vaddr, pte,
  381. __pte(val | _PAGE_MODIFIED));
  382. data += BASE_PAGE_SIZE;
  383. }
  384. }
  385. static inline int in_obp_range(unsigned long vaddr)
  386. {
  387. return (vaddr >= LOW_OBP_ADDRESS &&
  388. vaddr < HI_OBP_ADDRESS);
  389. }
  390. #define OBP_PMD_SIZE 2048
  391. static void __init build_obp_pgtable(void)
  392. {
  393. unsigned long i;
  394. prompmd = __alloc_bootmem(OBP_PMD_SIZE, OBP_PMD_SIZE, PAGE_SIZE);
  395. if (!prompmd)
  396. prom_halt();
  397. memset(prompmd, 0, OBP_PMD_SIZE);
  398. prom_pmd_phys = __pa(prompmd);
  399. for (i = 0; i < prom_trans_ents; i++) {
  400. unsigned long start, end;
  401. if (!in_obp_range(prom_trans[i].virt))
  402. continue;
  403. start = prom_trans[i].virt;
  404. end = start + prom_trans[i].size;
  405. if (end > HI_OBP_ADDRESS)
  406. end = HI_OBP_ADDRESS;
  407. build_obp_range(start, end, prom_trans[i].data);
  408. }
  409. }
  410. /* Read OBP translations property into 'prom_trans[]'.
  411. * Return the number of entries.
  412. */
  413. static void __init read_obp_translations(void)
  414. {
  415. int n, node;
  416. node = prom_finddevice("/virtual-memory");
  417. n = prom_getproplen(node, "translations");
  418. if (unlikely(n == 0 || n == -1)) {
  419. prom_printf("prom_mappings: Couldn't get size.\n");
  420. prom_halt();
  421. }
  422. if (unlikely(n > sizeof(prom_trans))) {
  423. prom_printf("prom_mappings: Size %Zd is too big.\n", n);
  424. prom_halt();
  425. }
  426. if ((n = prom_getproperty(node, "translations",
  427. (char *)&prom_trans[0],
  428. sizeof(prom_trans))) == -1) {
  429. prom_printf("prom_mappings: Couldn't get property.\n");
  430. prom_halt();
  431. }
  432. n = n / sizeof(struct linux_prom_translation);
  433. prom_trans_ents = n;
  434. }
  435. static void __init remap_kernel(void)
  436. {
  437. unsigned long phys_page, tte_vaddr, tte_data;
  438. int tlb_ent = sparc64_highest_locked_tlbent();
  439. tte_vaddr = (unsigned long) KERNBASE;
  440. phys_page = (prom_boot_mapping_phys_low >> 22UL) << 22UL;
  441. tte_data = (phys_page | (_PAGE_VALID | _PAGE_SZ4MB |
  442. _PAGE_CP | _PAGE_CV | _PAGE_P |
  443. _PAGE_L | _PAGE_W));
  444. kern_locked_tte_data = tte_data;
  445. /* Now lock us into the TLBs via OBP. */
  446. prom_dtlb_load(tlb_ent, tte_data, tte_vaddr);
  447. prom_itlb_load(tlb_ent, tte_data, tte_vaddr);
  448. if (bigkernel) {
  449. tlb_ent -= 1;
  450. prom_dtlb_load(tlb_ent,
  451. tte_data + 0x400000,
  452. tte_vaddr + 0x400000);
  453. prom_itlb_load(tlb_ent,
  454. tte_data + 0x400000,
  455. tte_vaddr + 0x400000);
  456. }
  457. sparc64_highest_unlocked_tlb_ent = tlb_ent - 1;
  458. if (tlb_type == cheetah_plus) {
  459. sparc64_kern_pri_context = (CTX_CHEETAH_PLUS_CTX0 |
  460. CTX_CHEETAH_PLUS_NUC);
  461. sparc64_kern_pri_nuc_bits = CTX_CHEETAH_PLUS_NUC;
  462. sparc64_kern_sec_context = CTX_CHEETAH_PLUS_CTX0;
  463. }
  464. }
  465. static void __init inherit_prom_mappings_pre(void)
  466. {
  467. read_obp_translations();
  468. /* Now fixup OBP's idea about where we really are mapped. */
  469. prom_printf("Remapping the kernel... ");
  470. remap_kernel();
  471. prom_printf("done.\n");
  472. }
  473. static void __init inherit_prom_mappings_post(void)
  474. {
  475. build_obp_pgtable();
  476. register_prom_callbacks();
  477. }
  478. /* The OBP specifications for sun4u mark 0xfffffffc00000000 and
  479. * upwards as reserved for use by the firmware (I wonder if this
  480. * will be the same on Cheetah...). We use this virtual address
  481. * range for the VPTE table mappings of the nucleus so we need
  482. * to zap them when we enter the PROM. -DaveM
  483. */
  484. static void __flush_nucleus_vptes(void)
  485. {
  486. unsigned long prom_reserved_base = 0xfffffffc00000000UL;
  487. int i;
  488. /* Only DTLB must be checked for VPTE entries. */
  489. if (tlb_type == spitfire) {
  490. for (i = 0; i < 63; i++) {
  491. unsigned long tag;
  492. /* Spitfire Errata #32 workaround */
  493. /* NOTE: Always runs on spitfire, so no cheetah+
  494. * page size encodings.
  495. */
  496. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  497. "flush %%g6"
  498. : /* No outputs */
  499. : "r" (0),
  500. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  501. tag = spitfire_get_dtlb_tag(i);
  502. if (((tag & ~(PAGE_MASK)) == 0) &&
  503. ((tag & (PAGE_MASK)) >= prom_reserved_base)) {
  504. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  505. "membar #Sync"
  506. : /* no outputs */
  507. : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU));
  508. spitfire_put_dtlb_data(i, 0x0UL);
  509. }
  510. }
  511. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  512. for (i = 0; i < 512; i++) {
  513. unsigned long tag = cheetah_get_dtlb_tag(i, 2);
  514. if ((tag & ~PAGE_MASK) == 0 &&
  515. (tag & PAGE_MASK) >= prom_reserved_base) {
  516. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  517. "membar #Sync"
  518. : /* no outputs */
  519. : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU));
  520. cheetah_put_dtlb_data(i, 0x0UL, 2);
  521. }
  522. if (tlb_type != cheetah_plus)
  523. continue;
  524. tag = cheetah_get_dtlb_tag(i, 3);
  525. if ((tag & ~PAGE_MASK) == 0 &&
  526. (tag & PAGE_MASK) >= prom_reserved_base) {
  527. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  528. "membar #Sync"
  529. : /* no outputs */
  530. : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU));
  531. cheetah_put_dtlb_data(i, 0x0UL, 3);
  532. }
  533. }
  534. } else {
  535. /* Implement me :-) */
  536. BUG();
  537. }
  538. }
  539. static int prom_ditlb_set;
  540. struct prom_tlb_entry {
  541. int tlb_ent;
  542. unsigned long tlb_tag;
  543. unsigned long tlb_data;
  544. };
  545. struct prom_tlb_entry prom_itlb[16], prom_dtlb[16];
  546. void prom_world(int enter)
  547. {
  548. unsigned long pstate;
  549. int i;
  550. if (!enter)
  551. set_fs((mm_segment_t) { get_thread_current_ds() });
  552. if (!prom_ditlb_set)
  553. return;
  554. /* Make sure the following runs atomically. */
  555. __asm__ __volatile__("flushw\n\t"
  556. "rdpr %%pstate, %0\n\t"
  557. "wrpr %0, %1, %%pstate"
  558. : "=r" (pstate)
  559. : "i" (PSTATE_IE));
  560. if (enter) {
  561. /* Kick out nucleus VPTEs. */
  562. __flush_nucleus_vptes();
  563. /* Install PROM world. */
  564. for (i = 0; i < 16; i++) {
  565. if (prom_dtlb[i].tlb_ent != -1) {
  566. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  567. "membar #Sync"
  568. : : "r" (prom_dtlb[i].tlb_tag), "r" (TLB_TAG_ACCESS),
  569. "i" (ASI_DMMU));
  570. if (tlb_type == spitfire)
  571. spitfire_put_dtlb_data(prom_dtlb[i].tlb_ent,
  572. prom_dtlb[i].tlb_data);
  573. else if (tlb_type == cheetah || tlb_type == cheetah_plus)
  574. cheetah_put_ldtlb_data(prom_dtlb[i].tlb_ent,
  575. prom_dtlb[i].tlb_data);
  576. }
  577. if (prom_itlb[i].tlb_ent != -1) {
  578. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  579. "membar #Sync"
  580. : : "r" (prom_itlb[i].tlb_tag),
  581. "r" (TLB_TAG_ACCESS),
  582. "i" (ASI_IMMU));
  583. if (tlb_type == spitfire)
  584. spitfire_put_itlb_data(prom_itlb[i].tlb_ent,
  585. prom_itlb[i].tlb_data);
  586. else if (tlb_type == cheetah || tlb_type == cheetah_plus)
  587. cheetah_put_litlb_data(prom_itlb[i].tlb_ent,
  588. prom_itlb[i].tlb_data);
  589. }
  590. }
  591. } else {
  592. for (i = 0; i < 16; i++) {
  593. if (prom_dtlb[i].tlb_ent != -1) {
  594. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  595. "membar #Sync"
  596. : : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU));
  597. if (tlb_type == spitfire)
  598. spitfire_put_dtlb_data(prom_dtlb[i].tlb_ent, 0x0UL);
  599. else
  600. cheetah_put_ldtlb_data(prom_dtlb[i].tlb_ent, 0x0UL);
  601. }
  602. if (prom_itlb[i].tlb_ent != -1) {
  603. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  604. "membar #Sync"
  605. : : "r" (TLB_TAG_ACCESS),
  606. "i" (ASI_IMMU));
  607. if (tlb_type == spitfire)
  608. spitfire_put_itlb_data(prom_itlb[i].tlb_ent, 0x0UL);
  609. else
  610. cheetah_put_litlb_data(prom_itlb[i].tlb_ent, 0x0UL);
  611. }
  612. }
  613. }
  614. __asm__ __volatile__("wrpr %0, 0, %%pstate"
  615. : : "r" (pstate));
  616. }
  617. void inherit_locked_prom_mappings(int save_p)
  618. {
  619. int i;
  620. int dtlb_seen = 0;
  621. int itlb_seen = 0;
  622. /* Fucking losing PROM has more mappings in the TLB, but
  623. * it (conveniently) fails to mention any of these in the
  624. * translations property. The only ones that matter are
  625. * the locked PROM tlb entries, so we impose the following
  626. * irrecovable rule on the PROM, it is allowed 8 locked
  627. * entries in the ITLB and 8 in the DTLB.
  628. *
  629. * Supposedly the upper 16GB of the address space is
  630. * reserved for OBP, BUT I WISH THIS WAS DOCUMENTED
  631. * SOMEWHERE!!!!!!!!!!!!!!!!! Furthermore the entire interface
  632. * used between the client program and the firmware on sun5
  633. * systems to coordinate mmu mappings is also COMPLETELY
  634. * UNDOCUMENTED!!!!!! Thanks S(t)un!
  635. */
  636. if (save_p) {
  637. for (i = 0; i < 16; i++) {
  638. prom_itlb[i].tlb_ent = -1;
  639. prom_dtlb[i].tlb_ent = -1;
  640. }
  641. }
  642. if (tlb_type == spitfire) {
  643. int high = sparc64_highest_unlocked_tlb_ent;
  644. for (i = 0; i <= high; i++) {
  645. unsigned long data;
  646. /* Spitfire Errata #32 workaround */
  647. /* NOTE: Always runs on spitfire, so no cheetah+
  648. * page size encodings.
  649. */
  650. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  651. "flush %%g6"
  652. : /* No outputs */
  653. : "r" (0),
  654. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  655. data = spitfire_get_dtlb_data(i);
  656. if ((data & (_PAGE_L|_PAGE_VALID)) == (_PAGE_L|_PAGE_VALID)) {
  657. unsigned long tag;
  658. /* Spitfire Errata #32 workaround */
  659. /* NOTE: Always runs on spitfire, so no
  660. * cheetah+ page size encodings.
  661. */
  662. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  663. "flush %%g6"
  664. : /* No outputs */
  665. : "r" (0),
  666. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  667. tag = spitfire_get_dtlb_tag(i);
  668. if (save_p) {
  669. prom_dtlb[dtlb_seen].tlb_ent = i;
  670. prom_dtlb[dtlb_seen].tlb_tag = tag;
  671. prom_dtlb[dtlb_seen].tlb_data = data;
  672. }
  673. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  674. "membar #Sync"
  675. : : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU));
  676. spitfire_put_dtlb_data(i, 0x0UL);
  677. dtlb_seen++;
  678. if (dtlb_seen > 15)
  679. break;
  680. }
  681. }
  682. for (i = 0; i < high; i++) {
  683. unsigned long data;
  684. /* Spitfire Errata #32 workaround */
  685. /* NOTE: Always runs on spitfire, so no
  686. * cheetah+ page size encodings.
  687. */
  688. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  689. "flush %%g6"
  690. : /* No outputs */
  691. : "r" (0),
  692. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  693. data = spitfire_get_itlb_data(i);
  694. if ((data & (_PAGE_L|_PAGE_VALID)) == (_PAGE_L|_PAGE_VALID)) {
  695. unsigned long tag;
  696. /* Spitfire Errata #32 workaround */
  697. /* NOTE: Always runs on spitfire, so no
  698. * cheetah+ page size encodings.
  699. */
  700. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  701. "flush %%g6"
  702. : /* No outputs */
  703. : "r" (0),
  704. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  705. tag = spitfire_get_itlb_tag(i);
  706. if (save_p) {
  707. prom_itlb[itlb_seen].tlb_ent = i;
  708. prom_itlb[itlb_seen].tlb_tag = tag;
  709. prom_itlb[itlb_seen].tlb_data = data;
  710. }
  711. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  712. "membar #Sync"
  713. : : "r" (TLB_TAG_ACCESS), "i" (ASI_IMMU));
  714. spitfire_put_itlb_data(i, 0x0UL);
  715. itlb_seen++;
  716. if (itlb_seen > 15)
  717. break;
  718. }
  719. }
  720. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  721. int high = sparc64_highest_unlocked_tlb_ent;
  722. for (i = 0; i <= high; i++) {
  723. unsigned long data;
  724. data = cheetah_get_ldtlb_data(i);
  725. if ((data & (_PAGE_L|_PAGE_VALID)) == (_PAGE_L|_PAGE_VALID)) {
  726. unsigned long tag;
  727. tag = cheetah_get_ldtlb_tag(i);
  728. if (save_p) {
  729. prom_dtlb[dtlb_seen].tlb_ent = i;
  730. prom_dtlb[dtlb_seen].tlb_tag = tag;
  731. prom_dtlb[dtlb_seen].tlb_data = data;
  732. }
  733. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  734. "membar #Sync"
  735. : : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU));
  736. cheetah_put_ldtlb_data(i, 0x0UL);
  737. dtlb_seen++;
  738. if (dtlb_seen > 15)
  739. break;
  740. }
  741. }
  742. for (i = 0; i < high; i++) {
  743. unsigned long data;
  744. data = cheetah_get_litlb_data(i);
  745. if ((data & (_PAGE_L|_PAGE_VALID)) == (_PAGE_L|_PAGE_VALID)) {
  746. unsigned long tag;
  747. tag = cheetah_get_litlb_tag(i);
  748. if (save_p) {
  749. prom_itlb[itlb_seen].tlb_ent = i;
  750. prom_itlb[itlb_seen].tlb_tag = tag;
  751. prom_itlb[itlb_seen].tlb_data = data;
  752. }
  753. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  754. "membar #Sync"
  755. : : "r" (TLB_TAG_ACCESS), "i" (ASI_IMMU));
  756. cheetah_put_litlb_data(i, 0x0UL);
  757. itlb_seen++;
  758. if (itlb_seen > 15)
  759. break;
  760. }
  761. }
  762. } else {
  763. /* Implement me :-) */
  764. BUG();
  765. }
  766. if (save_p)
  767. prom_ditlb_set = 1;
  768. }
  769. /* Give PROM back his world, done during reboots... */
  770. void prom_reload_locked(void)
  771. {
  772. int i;
  773. for (i = 0; i < 16; i++) {
  774. if (prom_dtlb[i].tlb_ent != -1) {
  775. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  776. "membar #Sync"
  777. : : "r" (prom_dtlb[i].tlb_tag), "r" (TLB_TAG_ACCESS),
  778. "i" (ASI_DMMU));
  779. if (tlb_type == spitfire)
  780. spitfire_put_dtlb_data(prom_dtlb[i].tlb_ent,
  781. prom_dtlb[i].tlb_data);
  782. else if (tlb_type == cheetah || tlb_type == cheetah_plus)
  783. cheetah_put_ldtlb_data(prom_dtlb[i].tlb_ent,
  784. prom_dtlb[i].tlb_data);
  785. }
  786. if (prom_itlb[i].tlb_ent != -1) {
  787. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  788. "membar #Sync"
  789. : : "r" (prom_itlb[i].tlb_tag),
  790. "r" (TLB_TAG_ACCESS),
  791. "i" (ASI_IMMU));
  792. if (tlb_type == spitfire)
  793. spitfire_put_itlb_data(prom_itlb[i].tlb_ent,
  794. prom_itlb[i].tlb_data);
  795. else
  796. cheetah_put_litlb_data(prom_itlb[i].tlb_ent,
  797. prom_itlb[i].tlb_data);
  798. }
  799. }
  800. }
  801. #ifdef DCACHE_ALIASING_POSSIBLE
  802. void __flush_dcache_range(unsigned long start, unsigned long end)
  803. {
  804. unsigned long va;
  805. if (tlb_type == spitfire) {
  806. int n = 0;
  807. for (va = start; va < end; va += 32) {
  808. spitfire_put_dcache_tag(va & 0x3fe0, 0x0);
  809. if (++n >= 512)
  810. break;
  811. }
  812. } else {
  813. start = __pa(start);
  814. end = __pa(end);
  815. for (va = start; va < end; va += 32)
  816. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  817. "membar #Sync"
  818. : /* no outputs */
  819. : "r" (va),
  820. "i" (ASI_DCACHE_INVALIDATE));
  821. }
  822. }
  823. #endif /* DCACHE_ALIASING_POSSIBLE */
  824. /* If not locked, zap it. */
  825. void __flush_tlb_all(void)
  826. {
  827. unsigned long pstate;
  828. int i;
  829. __asm__ __volatile__("flushw\n\t"
  830. "rdpr %%pstate, %0\n\t"
  831. "wrpr %0, %1, %%pstate"
  832. : "=r" (pstate)
  833. : "i" (PSTATE_IE));
  834. if (tlb_type == spitfire) {
  835. for (i = 0; i < 64; i++) {
  836. /* Spitfire Errata #32 workaround */
  837. /* NOTE: Always runs on spitfire, so no
  838. * cheetah+ page size encodings.
  839. */
  840. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  841. "flush %%g6"
  842. : /* No outputs */
  843. : "r" (0),
  844. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  845. if (!(spitfire_get_dtlb_data(i) & _PAGE_L)) {
  846. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  847. "membar #Sync"
  848. : /* no outputs */
  849. : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU));
  850. spitfire_put_dtlb_data(i, 0x0UL);
  851. }
  852. /* Spitfire Errata #32 workaround */
  853. /* NOTE: Always runs on spitfire, so no
  854. * cheetah+ page size encodings.
  855. */
  856. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  857. "flush %%g6"
  858. : /* No outputs */
  859. : "r" (0),
  860. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  861. if (!(spitfire_get_itlb_data(i) & _PAGE_L)) {
  862. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  863. "membar #Sync"
  864. : /* no outputs */
  865. : "r" (TLB_TAG_ACCESS), "i" (ASI_IMMU));
  866. spitfire_put_itlb_data(i, 0x0UL);
  867. }
  868. }
  869. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  870. cheetah_flush_dtlb_all();
  871. cheetah_flush_itlb_all();
  872. }
  873. __asm__ __volatile__("wrpr %0, 0, %%pstate"
  874. : : "r" (pstate));
  875. }
  876. /* Caller does TLB context flushing on local CPU if necessary.
  877. * The caller also ensures that CTX_VALID(mm->context) is false.
  878. *
  879. * We must be careful about boundary cases so that we never
  880. * let the user have CTX 0 (nucleus) or we ever use a CTX
  881. * version of zero (and thus NO_CONTEXT would not be caught
  882. * by version mis-match tests in mmu_context.h).
  883. */
  884. void get_new_mmu_context(struct mm_struct *mm)
  885. {
  886. unsigned long ctx, new_ctx;
  887. unsigned long orig_pgsz_bits;
  888. spin_lock(&ctx_alloc_lock);
  889. orig_pgsz_bits = (mm->context.sparc64_ctx_val & CTX_PGSZ_MASK);
  890. ctx = (tlb_context_cache + 1) & CTX_NR_MASK;
  891. new_ctx = find_next_zero_bit(mmu_context_bmap, 1 << CTX_NR_BITS, ctx);
  892. if (new_ctx >= (1 << CTX_NR_BITS)) {
  893. new_ctx = find_next_zero_bit(mmu_context_bmap, ctx, 1);
  894. if (new_ctx >= ctx) {
  895. int i;
  896. new_ctx = (tlb_context_cache & CTX_VERSION_MASK) +
  897. CTX_FIRST_VERSION;
  898. if (new_ctx == 1)
  899. new_ctx = CTX_FIRST_VERSION;
  900. /* Don't call memset, for 16 entries that's just
  901. * plain silly...
  902. */
  903. mmu_context_bmap[0] = 3;
  904. mmu_context_bmap[1] = 0;
  905. mmu_context_bmap[2] = 0;
  906. mmu_context_bmap[3] = 0;
  907. for (i = 4; i < CTX_BMAP_SLOTS; i += 4) {
  908. mmu_context_bmap[i + 0] = 0;
  909. mmu_context_bmap[i + 1] = 0;
  910. mmu_context_bmap[i + 2] = 0;
  911. mmu_context_bmap[i + 3] = 0;
  912. }
  913. goto out;
  914. }
  915. }
  916. mmu_context_bmap[new_ctx>>6] |= (1UL << (new_ctx & 63));
  917. new_ctx |= (tlb_context_cache & CTX_VERSION_MASK);
  918. out:
  919. tlb_context_cache = new_ctx;
  920. mm->context.sparc64_ctx_val = new_ctx | orig_pgsz_bits;
  921. spin_unlock(&ctx_alloc_lock);
  922. }
  923. #ifndef CONFIG_SMP
  924. struct pgtable_cache_struct pgt_quicklists;
  925. #endif
  926. /* OK, we have to color these pages. The page tables are accessed
  927. * by non-Dcache enabled mapping in the VPTE area by the dtlb_backend.S
  928. * code, as well as by PAGE_OFFSET range direct-mapped addresses by
  929. * other parts of the kernel. By coloring, we make sure that the tlbmiss
  930. * fast handlers do not get data from old/garbage dcache lines that
  931. * correspond to an old/stale virtual address (user/kernel) that
  932. * previously mapped the pagetable page while accessing vpte range
  933. * addresses. The idea is that if the vpte color and PAGE_OFFSET range
  934. * color is the same, then when the kernel initializes the pagetable
  935. * using the later address range, accesses with the first address
  936. * range will see the newly initialized data rather than the garbage.
  937. */
  938. #ifdef DCACHE_ALIASING_POSSIBLE
  939. #define DC_ALIAS_SHIFT 1
  940. #else
  941. #define DC_ALIAS_SHIFT 0
  942. #endif
  943. pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
  944. {
  945. struct page *page;
  946. unsigned long color;
  947. {
  948. pte_t *ptep = pte_alloc_one_fast(mm, address);
  949. if (ptep)
  950. return ptep;
  951. }
  952. color = VPTE_COLOR(address);
  953. page = alloc_pages(GFP_KERNEL|__GFP_REPEAT, DC_ALIAS_SHIFT);
  954. if (page) {
  955. unsigned long *to_free;
  956. unsigned long paddr;
  957. pte_t *pte;
  958. #ifdef DCACHE_ALIASING_POSSIBLE
  959. set_page_count(page, 1);
  960. ClearPageCompound(page);
  961. set_page_count((page + 1), 1);
  962. ClearPageCompound(page + 1);
  963. #endif
  964. paddr = (unsigned long) page_address(page);
  965. memset((char *)paddr, 0, (PAGE_SIZE << DC_ALIAS_SHIFT));
  966. if (!color) {
  967. pte = (pte_t *) paddr;
  968. to_free = (unsigned long *) (paddr + PAGE_SIZE);
  969. } else {
  970. pte = (pte_t *) (paddr + PAGE_SIZE);
  971. to_free = (unsigned long *) paddr;
  972. }
  973. #ifdef DCACHE_ALIASING_POSSIBLE
  974. /* Now free the other one up, adjust cache size. */
  975. preempt_disable();
  976. *to_free = (unsigned long) pte_quicklist[color ^ 0x1];
  977. pte_quicklist[color ^ 0x1] = to_free;
  978. pgtable_cache_size++;
  979. preempt_enable();
  980. #endif
  981. return pte;
  982. }
  983. return NULL;
  984. }
  985. void sparc_ultra_dump_itlb(void)
  986. {
  987. int slot;
  988. if (tlb_type == spitfire) {
  989. printk ("Contents of itlb: ");
  990. for (slot = 0; slot < 14; slot++) printk (" ");
  991. printk ("%2x:%016lx,%016lx\n",
  992. 0,
  993. spitfire_get_itlb_tag(0), spitfire_get_itlb_data(0));
  994. for (slot = 1; slot < 64; slot+=3) {
  995. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  996. slot,
  997. spitfire_get_itlb_tag(slot), spitfire_get_itlb_data(slot),
  998. slot+1,
  999. spitfire_get_itlb_tag(slot+1), spitfire_get_itlb_data(slot+1),
  1000. slot+2,
  1001. spitfire_get_itlb_tag(slot+2), spitfire_get_itlb_data(slot+2));
  1002. }
  1003. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  1004. printk ("Contents of itlb0:\n");
  1005. for (slot = 0; slot < 16; slot+=2) {
  1006. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  1007. slot,
  1008. cheetah_get_litlb_tag(slot), cheetah_get_litlb_data(slot),
  1009. slot+1,
  1010. cheetah_get_litlb_tag(slot+1), cheetah_get_litlb_data(slot+1));
  1011. }
  1012. printk ("Contents of itlb2:\n");
  1013. for (slot = 0; slot < 128; slot+=2) {
  1014. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  1015. slot,
  1016. cheetah_get_itlb_tag(slot), cheetah_get_itlb_data(slot),
  1017. slot+1,
  1018. cheetah_get_itlb_tag(slot+1), cheetah_get_itlb_data(slot+1));
  1019. }
  1020. }
  1021. }
  1022. void sparc_ultra_dump_dtlb(void)
  1023. {
  1024. int slot;
  1025. if (tlb_type == spitfire) {
  1026. printk ("Contents of dtlb: ");
  1027. for (slot = 0; slot < 14; slot++) printk (" ");
  1028. printk ("%2x:%016lx,%016lx\n", 0,
  1029. spitfire_get_dtlb_tag(0), spitfire_get_dtlb_data(0));
  1030. for (slot = 1; slot < 64; slot+=3) {
  1031. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  1032. slot,
  1033. spitfire_get_dtlb_tag(slot), spitfire_get_dtlb_data(slot),
  1034. slot+1,
  1035. spitfire_get_dtlb_tag(slot+1), spitfire_get_dtlb_data(slot+1),
  1036. slot+2,
  1037. spitfire_get_dtlb_tag(slot+2), spitfire_get_dtlb_data(slot+2));
  1038. }
  1039. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  1040. printk ("Contents of dtlb0:\n");
  1041. for (slot = 0; slot < 16; slot+=2) {
  1042. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  1043. slot,
  1044. cheetah_get_ldtlb_tag(slot), cheetah_get_ldtlb_data(slot),
  1045. slot+1,
  1046. cheetah_get_ldtlb_tag(slot+1), cheetah_get_ldtlb_data(slot+1));
  1047. }
  1048. printk ("Contents of dtlb2:\n");
  1049. for (slot = 0; slot < 512; slot+=2) {
  1050. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  1051. slot,
  1052. cheetah_get_dtlb_tag(slot, 2), cheetah_get_dtlb_data(slot, 2),
  1053. slot+1,
  1054. cheetah_get_dtlb_tag(slot+1, 2), cheetah_get_dtlb_data(slot+1, 2));
  1055. }
  1056. if (tlb_type == cheetah_plus) {
  1057. printk ("Contents of dtlb3:\n");
  1058. for (slot = 0; slot < 512; slot+=2) {
  1059. printk ("%2x:%016lx,%016lx %2x:%016lx,%016lx\n",
  1060. slot,
  1061. cheetah_get_dtlb_tag(slot, 3), cheetah_get_dtlb_data(slot, 3),
  1062. slot+1,
  1063. cheetah_get_dtlb_tag(slot+1, 3), cheetah_get_dtlb_data(slot+1, 3));
  1064. }
  1065. }
  1066. }
  1067. }
  1068. extern unsigned long cmdline_memory_size;
  1069. unsigned long __init bootmem_init(unsigned long *pages_avail)
  1070. {
  1071. unsigned long bootmap_size, start_pfn, end_pfn;
  1072. unsigned long end_of_phys_memory = 0UL;
  1073. unsigned long bootmap_pfn, bytes_avail, size;
  1074. int i;
  1075. #ifdef CONFIG_DEBUG_BOOTMEM
  1076. prom_printf("bootmem_init: Scan pavail, ");
  1077. #endif
  1078. bytes_avail = 0UL;
  1079. for (i = 0; i < pavail_ents; i++) {
  1080. end_of_phys_memory = pavail[i].phys_addr +
  1081. pavail[i].reg_size;
  1082. bytes_avail += pavail[i].reg_size;
  1083. if (cmdline_memory_size) {
  1084. if (bytes_avail > cmdline_memory_size) {
  1085. unsigned long slack = bytes_avail - cmdline_memory_size;
  1086. bytes_avail -= slack;
  1087. end_of_phys_memory -= slack;
  1088. pavail[i].reg_size -= slack;
  1089. if ((long)pavail[i].reg_size <= 0L) {
  1090. pavail[i].phys_addr = 0xdeadbeefUL;
  1091. pavail[i].reg_size = 0UL;
  1092. pavail_ents = i;
  1093. } else {
  1094. pavail[i+1].reg_size = 0Ul;
  1095. pavail[i+1].phys_addr = 0xdeadbeefUL;
  1096. pavail_ents = i + 1;
  1097. }
  1098. break;
  1099. }
  1100. }
  1101. }
  1102. *pages_avail = bytes_avail >> PAGE_SHIFT;
  1103. /* Start with page aligned address of last symbol in kernel
  1104. * image. The kernel is hard mapped below PAGE_OFFSET in a
  1105. * 4MB locked TLB translation.
  1106. */
  1107. start_pfn = PAGE_ALIGN(kern_base + kern_size) >> PAGE_SHIFT;
  1108. bootmap_pfn = start_pfn;
  1109. end_pfn = end_of_phys_memory >> PAGE_SHIFT;
  1110. #ifdef CONFIG_BLK_DEV_INITRD
  1111. /* Now have to check initial ramdisk, so that bootmap does not overwrite it */
  1112. if (sparc_ramdisk_image || sparc_ramdisk_image64) {
  1113. unsigned long ramdisk_image = sparc_ramdisk_image ?
  1114. sparc_ramdisk_image : sparc_ramdisk_image64;
  1115. if (ramdisk_image >= (unsigned long)_end - 2 * PAGE_SIZE)
  1116. ramdisk_image -= KERNBASE;
  1117. initrd_start = ramdisk_image + phys_base;
  1118. initrd_end = initrd_start + sparc_ramdisk_size;
  1119. if (initrd_end > end_of_phys_memory) {
  1120. printk(KERN_CRIT "initrd extends beyond end of memory "
  1121. "(0x%016lx > 0x%016lx)\ndisabling initrd\n",
  1122. initrd_end, end_of_phys_memory);
  1123. initrd_start = 0;
  1124. }
  1125. if (initrd_start) {
  1126. if (initrd_start >= (start_pfn << PAGE_SHIFT) &&
  1127. initrd_start < (start_pfn << PAGE_SHIFT) + 2 * PAGE_SIZE)
  1128. bootmap_pfn = PAGE_ALIGN (initrd_end) >> PAGE_SHIFT;
  1129. }
  1130. }
  1131. #endif
  1132. /* Initialize the boot-time allocator. */
  1133. max_pfn = max_low_pfn = end_pfn;
  1134. min_low_pfn = pfn_base;
  1135. #ifdef CONFIG_DEBUG_BOOTMEM
  1136. prom_printf("init_bootmem(min[%lx], bootmap[%lx], max[%lx])\n",
  1137. min_low_pfn, bootmap_pfn, max_low_pfn);
  1138. #endif
  1139. bootmap_size = init_bootmem_node(NODE_DATA(0), bootmap_pfn, pfn_base, end_pfn);
  1140. /* Now register the available physical memory with the
  1141. * allocator.
  1142. */
  1143. for (i = 0; i < pavail_ents; i++) {
  1144. #ifdef CONFIG_DEBUG_BOOTMEM
  1145. prom_printf("free_bootmem(pavail:%d): base[%lx] size[%lx]\n",
  1146. i, pavail[i].phys_addr, pavail[i].reg_size);
  1147. #endif
  1148. free_bootmem(pavail[i].phys_addr, pavail[i].reg_size);
  1149. }
  1150. #ifdef CONFIG_BLK_DEV_INITRD
  1151. if (initrd_start) {
  1152. size = initrd_end - initrd_start;
  1153. /* Resert the initrd image area. */
  1154. #ifdef CONFIG_DEBUG_BOOTMEM
  1155. prom_printf("reserve_bootmem(initrd): base[%llx] size[%lx]\n",
  1156. initrd_start, initrd_end);
  1157. #endif
  1158. reserve_bootmem(initrd_start, size);
  1159. *pages_avail -= PAGE_ALIGN(size) >> PAGE_SHIFT;
  1160. initrd_start += PAGE_OFFSET;
  1161. initrd_end += PAGE_OFFSET;
  1162. }
  1163. #endif
  1164. /* Reserve the kernel text/data/bss. */
  1165. #ifdef CONFIG_DEBUG_BOOTMEM
  1166. prom_printf("reserve_bootmem(kernel): base[%lx] size[%lx]\n", kern_base, kern_size);
  1167. #endif
  1168. reserve_bootmem(kern_base, kern_size);
  1169. *pages_avail -= PAGE_ALIGN(kern_size) >> PAGE_SHIFT;
  1170. /* Reserve the bootmem map. We do not account for it
  1171. * in pages_avail because we will release that memory
  1172. * in free_all_bootmem.
  1173. */
  1174. size = bootmap_size;
  1175. #ifdef CONFIG_DEBUG_BOOTMEM
  1176. prom_printf("reserve_bootmem(bootmap): base[%lx] size[%lx]\n",
  1177. (bootmap_pfn << PAGE_SHIFT), size);
  1178. #endif
  1179. reserve_bootmem((bootmap_pfn << PAGE_SHIFT), size);
  1180. *pages_avail -= PAGE_ALIGN(size) >> PAGE_SHIFT;
  1181. return end_pfn;
  1182. }
  1183. #ifdef CONFIG_DEBUG_PAGEALLOC
  1184. static unsigned long kernel_map_range(unsigned long pstart, unsigned long pend, pgprot_t prot)
  1185. {
  1186. unsigned long vstart = PAGE_OFFSET + pstart;
  1187. unsigned long vend = PAGE_OFFSET + pend;
  1188. unsigned long alloc_bytes = 0UL;
  1189. if ((vstart & ~PAGE_MASK) || (vend & ~PAGE_MASK)) {
  1190. prom_printf("kernel_map: Unaligned physmem[%lx:%lx]\n",
  1191. vstart, vend);
  1192. prom_halt();
  1193. }
  1194. while (vstart < vend) {
  1195. unsigned long this_end, paddr = __pa(vstart);
  1196. pgd_t *pgd = pgd_offset_k(vstart);
  1197. pud_t *pud;
  1198. pmd_t *pmd;
  1199. pte_t *pte;
  1200. pud = pud_offset(pgd, vstart);
  1201. if (pud_none(*pud)) {
  1202. pmd_t *new;
  1203. new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
  1204. alloc_bytes += PAGE_SIZE;
  1205. pud_populate(&init_mm, pud, new);
  1206. }
  1207. pmd = pmd_offset(pud, vstart);
  1208. if (!pmd_present(*pmd)) {
  1209. pte_t *new;
  1210. new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
  1211. alloc_bytes += PAGE_SIZE;
  1212. pmd_populate_kernel(&init_mm, pmd, new);
  1213. }
  1214. pte = pte_offset_kernel(pmd, vstart);
  1215. this_end = (vstart + PMD_SIZE) & PMD_MASK;
  1216. if (this_end > vend)
  1217. this_end = vend;
  1218. while (vstart < this_end) {
  1219. pte_val(*pte) = (paddr | pgprot_val(prot));
  1220. vstart += PAGE_SIZE;
  1221. paddr += PAGE_SIZE;
  1222. pte++;
  1223. }
  1224. }
  1225. return alloc_bytes;
  1226. }
  1227. static struct linux_prom64_registers pall[MAX_BANKS] __initdata;
  1228. static int pall_ents __initdata;
  1229. extern unsigned int kvmap_linear_patch[1];
  1230. static void __init kernel_physical_mapping_init(void)
  1231. {
  1232. unsigned long i, mem_alloced = 0UL;
  1233. read_obp_memory("reg", &pall[0], &pall_ents);
  1234. for (i = 0; i < pall_ents; i++) {
  1235. unsigned long phys_start, phys_end;
  1236. phys_start = pall[i].phys_addr;
  1237. phys_end = phys_start + pall[i].reg_size;
  1238. mem_alloced += kernel_map_range(phys_start, phys_end,
  1239. PAGE_KERNEL);
  1240. }
  1241. printk("Allocated %ld bytes for kernel page tables.\n",
  1242. mem_alloced);
  1243. kvmap_linear_patch[0] = 0x01000000; /* nop */
  1244. flushi(&kvmap_linear_patch[0]);
  1245. __flush_tlb_all();
  1246. }
  1247. void kernel_map_pages(struct page *page, int numpages, int enable)
  1248. {
  1249. unsigned long phys_start = page_to_pfn(page) << PAGE_SHIFT;
  1250. unsigned long phys_end = phys_start + (numpages * PAGE_SIZE);
  1251. kernel_map_range(phys_start, phys_end,
  1252. (enable ? PAGE_KERNEL : __pgprot(0)));
  1253. /* we should perform an IPI and flush all tlbs,
  1254. * but that can deadlock->flush only current cpu.
  1255. */
  1256. __flush_tlb_kernel_range(PAGE_OFFSET + phys_start,
  1257. PAGE_OFFSET + phys_end);
  1258. }
  1259. #endif
  1260. unsigned long __init find_ecache_flush_span(unsigned long size)
  1261. {
  1262. int i;
  1263. for (i = 0; i < pavail_ents; i++) {
  1264. if (pavail[i].reg_size >= size)
  1265. return pavail[i].phys_addr;
  1266. }
  1267. return ~0UL;
  1268. }
  1269. /* paging_init() sets up the page tables */
  1270. extern void cheetah_ecache_flush_init(void);
  1271. static unsigned long last_valid_pfn;
  1272. pgd_t swapper_pg_dir[2048];
  1273. void __init paging_init(void)
  1274. {
  1275. unsigned long end_pfn, pages_avail, shift;
  1276. unsigned long real_end, i;
  1277. /* Find available physical memory... */
  1278. read_obp_memory("available", &pavail[0], &pavail_ents);
  1279. phys_base = 0xffffffffffffffffUL;
  1280. for (i = 0; i < pavail_ents; i++)
  1281. phys_base = min(phys_base, pavail[i].phys_addr);
  1282. pfn_base = phys_base >> PAGE_SHIFT;
  1283. kern_base = (prom_boot_mapping_phys_low >> 22UL) << 22UL;
  1284. kern_size = (unsigned long)&_end - (unsigned long)KERNBASE;
  1285. set_bit(0, mmu_context_bmap);
  1286. shift = kern_base + PAGE_OFFSET - ((unsigned long)KERNBASE);
  1287. real_end = (unsigned long)_end;
  1288. if ((real_end > ((unsigned long)KERNBASE + 0x400000)))
  1289. bigkernel = 1;
  1290. if ((real_end > ((unsigned long)KERNBASE + 0x800000))) {
  1291. prom_printf("paging_init: Kernel > 8MB, too large.\n");
  1292. prom_halt();
  1293. }
  1294. /* Set kernel pgd to upper alias so physical page computations
  1295. * work.
  1296. */
  1297. init_mm.pgd += ((shift) / (sizeof(pgd_t)));
  1298. memset(swapper_low_pmd_dir, 0, sizeof(swapper_low_pmd_dir));
  1299. /* Now can init the kernel/bad page tables. */
  1300. pud_set(pud_offset(&swapper_pg_dir[0], 0),
  1301. swapper_low_pmd_dir + (shift / sizeof(pgd_t)));
  1302. swapper_pgd_zero = pgd_val(swapper_pg_dir[0]);
  1303. inherit_prom_mappings_pre();
  1304. /* Ok, we can use our TLB miss and window trap handlers safely.
  1305. * We need to do a quick peek here to see if we are on StarFire
  1306. * or not, so setup_tba can setup the IRQ globals correctly (it
  1307. * needs to get the hard smp processor id correctly).
  1308. */
  1309. {
  1310. extern void setup_tba(int);
  1311. setup_tba(this_is_starfire);
  1312. }
  1313. __flush_tlb_all();
  1314. /* Everything from this point forward, until we are done with
  1315. * inherit_prom_mappings_post(), must complete successfully
  1316. * without calling into the firmware. The firwmare page tables
  1317. * have not been built, but we are running on the Linux kernel's
  1318. * trap table.
  1319. */
  1320. /* Setup bootmem... */
  1321. pages_avail = 0;
  1322. last_valid_pfn = end_pfn = bootmem_init(&pages_avail);
  1323. inherit_prom_mappings_post();
  1324. inherit_locked_prom_mappings(1);
  1325. #ifdef CONFIG_DEBUG_PAGEALLOC
  1326. kernel_physical_mapping_init();
  1327. #endif
  1328. {
  1329. unsigned long zones_size[MAX_NR_ZONES];
  1330. unsigned long zholes_size[MAX_NR_ZONES];
  1331. unsigned long npages;
  1332. int znum;
  1333. for (znum = 0; znum < MAX_NR_ZONES; znum++)
  1334. zones_size[znum] = zholes_size[znum] = 0;
  1335. npages = end_pfn - pfn_base;
  1336. zones_size[ZONE_DMA] = npages;
  1337. zholes_size[ZONE_DMA] = npages - pages_avail;
  1338. free_area_init_node(0, &contig_page_data, zones_size,
  1339. phys_base >> PAGE_SHIFT, zholes_size);
  1340. }
  1341. device_scan();
  1342. }
  1343. static void __init taint_real_pages(void)
  1344. {
  1345. int i;
  1346. read_obp_memory("available", &pavail_rescan[0], &pavail_rescan_ents);
  1347. /* Find changes discovered in the physmem available rescan and
  1348. * reserve the lost portions in the bootmem maps.
  1349. */
  1350. for (i = 0; i < pavail_ents; i++) {
  1351. unsigned long old_start, old_end;
  1352. old_start = pavail[i].phys_addr;
  1353. old_end = old_start +
  1354. pavail[i].reg_size;
  1355. while (old_start < old_end) {
  1356. int n;
  1357. for (n = 0; pavail_rescan_ents; n++) {
  1358. unsigned long new_start, new_end;
  1359. new_start = pavail_rescan[n].phys_addr;
  1360. new_end = new_start +
  1361. pavail_rescan[n].reg_size;
  1362. if (new_start <= old_start &&
  1363. new_end >= (old_start + PAGE_SIZE)) {
  1364. set_bit(old_start >> 22,
  1365. sparc64_valid_addr_bitmap);
  1366. goto do_next_page;
  1367. }
  1368. }
  1369. reserve_bootmem(old_start, PAGE_SIZE);
  1370. do_next_page:
  1371. old_start += PAGE_SIZE;
  1372. }
  1373. }
  1374. }
  1375. void __init mem_init(void)
  1376. {
  1377. unsigned long codepages, datapages, initpages;
  1378. unsigned long addr, last;
  1379. int i;
  1380. i = last_valid_pfn >> ((22 - PAGE_SHIFT) + 6);
  1381. i += 1;
  1382. sparc64_valid_addr_bitmap = (unsigned long *) alloc_bootmem(i << 3);
  1383. if (sparc64_valid_addr_bitmap == NULL) {
  1384. prom_printf("mem_init: Cannot alloc valid_addr_bitmap.\n");
  1385. prom_halt();
  1386. }
  1387. memset(sparc64_valid_addr_bitmap, 0, i << 3);
  1388. addr = PAGE_OFFSET + kern_base;
  1389. last = PAGE_ALIGN(kern_size) + addr;
  1390. while (addr < last) {
  1391. set_bit(__pa(addr) >> 22, sparc64_valid_addr_bitmap);
  1392. addr += PAGE_SIZE;
  1393. }
  1394. taint_real_pages();
  1395. max_mapnr = last_valid_pfn - pfn_base;
  1396. high_memory = __va(last_valid_pfn << PAGE_SHIFT);
  1397. #ifdef CONFIG_DEBUG_BOOTMEM
  1398. prom_printf("mem_init: Calling free_all_bootmem().\n");
  1399. #endif
  1400. totalram_pages = num_physpages = free_all_bootmem() - 1;
  1401. /*
  1402. * Set up the zero page, mark it reserved, so that page count
  1403. * is not manipulated when freeing the page from user ptes.
  1404. */
  1405. mem_map_zero = alloc_pages(GFP_KERNEL|__GFP_ZERO, 0);
  1406. if (mem_map_zero == NULL) {
  1407. prom_printf("paging_init: Cannot alloc zero page.\n");
  1408. prom_halt();
  1409. }
  1410. SetPageReserved(mem_map_zero);
  1411. codepages = (((unsigned long) _etext) - ((unsigned long) _start));
  1412. codepages = PAGE_ALIGN(codepages) >> PAGE_SHIFT;
  1413. datapages = (((unsigned long) _edata) - ((unsigned long) _etext));
  1414. datapages = PAGE_ALIGN(datapages) >> PAGE_SHIFT;
  1415. initpages = (((unsigned long) __init_end) - ((unsigned long) __init_begin));
  1416. initpages = PAGE_ALIGN(initpages) >> PAGE_SHIFT;
  1417. printk("Memory: %uk available (%ldk kernel code, %ldk data, %ldk init) [%016lx,%016lx]\n",
  1418. nr_free_pages() << (PAGE_SHIFT-10),
  1419. codepages << (PAGE_SHIFT-10),
  1420. datapages << (PAGE_SHIFT-10),
  1421. initpages << (PAGE_SHIFT-10),
  1422. PAGE_OFFSET, (last_valid_pfn << PAGE_SHIFT));
  1423. if (tlb_type == cheetah || tlb_type == cheetah_plus)
  1424. cheetah_ecache_flush_init();
  1425. }
  1426. void free_initmem(void)
  1427. {
  1428. unsigned long addr, initend;
  1429. /*
  1430. * The init section is aligned to 8k in vmlinux.lds. Page align for >8k pagesizes.
  1431. */
  1432. addr = PAGE_ALIGN((unsigned long)(__init_begin));
  1433. initend = (unsigned long)(__init_end) & PAGE_MASK;
  1434. for (; addr < initend; addr += PAGE_SIZE) {
  1435. unsigned long page;
  1436. struct page *p;
  1437. page = (addr +
  1438. ((unsigned long) __va(kern_base)) -
  1439. ((unsigned long) KERNBASE));
  1440. memset((void *)addr, 0xcc, PAGE_SIZE);
  1441. p = virt_to_page(page);
  1442. ClearPageReserved(p);
  1443. set_page_count(p, 1);
  1444. __free_page(p);
  1445. num_physpages++;
  1446. totalram_pages++;
  1447. }
  1448. }
  1449. #ifdef CONFIG_BLK_DEV_INITRD
  1450. void free_initrd_mem(unsigned long start, unsigned long end)
  1451. {
  1452. if (start < end)
  1453. printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
  1454. for (; start < end; start += PAGE_SIZE) {
  1455. struct page *p = virt_to_page(start);
  1456. ClearPageReserved(p);
  1457. set_page_count(p, 1);
  1458. __free_page(p);
  1459. num_physpages++;
  1460. totalram_pages++;
  1461. }
  1462. }
  1463. #endif