init_64.c 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016
  1. /*
  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/extable.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/initrd.h>
  16. #include <linux/swap.h>
  17. #include <linux/pagemap.h>
  18. #include <linux/poison.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 <linux/ioport.h>
  25. #include <linux/percpu.h>
  26. #include <linux/memblock.h>
  27. #include <linux/mmzone.h>
  28. #include <linux/gfp.h>
  29. #include <asm/head.h>
  30. #include <asm/page.h>
  31. #include <asm/pgalloc.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/oplib.h>
  34. #include <asm/iommu.h>
  35. #include <asm/io.h>
  36. #include <asm/uaccess.h>
  37. #include <asm/mmu_context.h>
  38. #include <asm/tlbflush.h>
  39. #include <asm/dma.h>
  40. #include <asm/starfire.h>
  41. #include <asm/tlb.h>
  42. #include <asm/spitfire.h>
  43. #include <asm/sections.h>
  44. #include <asm/tsb.h>
  45. #include <asm/hypervisor.h>
  46. #include <asm/prom.h>
  47. #include <asm/mdesc.h>
  48. #include <asm/cpudata.h>
  49. #include <asm/setup.h>
  50. #include <asm/irq.h>
  51. #include "init_64.h"
  52. unsigned long kern_linear_pte_xor[4] __read_mostly;
  53. static unsigned long page_cache4v_flag;
  54. /* A bitmap, two bits for every 256MB of physical memory. These two
  55. * bits determine what page size we use for kernel linear
  56. * translations. They form an index into kern_linear_pte_xor[]. The
  57. * value in the indexed slot is XOR'd with the TLB miss virtual
  58. * address to form the resulting TTE. The mapping is:
  59. *
  60. * 0 ==> 4MB
  61. * 1 ==> 256MB
  62. * 2 ==> 2GB
  63. * 3 ==> 16GB
  64. *
  65. * All sun4v chips support 256MB pages. Only SPARC-T4 and later
  66. * support 2GB pages, and hopefully future cpus will support the 16GB
  67. * pages as well. For slots 2 and 3, we encode a 256MB TTE xor there
  68. * if these larger page sizes are not supported by the cpu.
  69. *
  70. * It would be nice to determine this from the machine description
  71. * 'cpu' properties, but we need to have this table setup before the
  72. * MDESC is initialized.
  73. */
  74. #ifndef CONFIG_DEBUG_PAGEALLOC
  75. /* A special kernel TSB for 4MB, 256MB, 2GB and 16GB linear mappings.
  76. * Space is allocated for this right after the trap table in
  77. * arch/sparc64/kernel/head.S
  78. */
  79. extern struct tsb swapper_4m_tsb[KERNEL_TSB4M_NENTRIES];
  80. #endif
  81. extern struct tsb swapper_tsb[KERNEL_TSB_NENTRIES];
  82. static unsigned long cpu_pgsz_mask;
  83. #define MAX_BANKS 1024
  84. static struct linux_prom64_registers pavail[MAX_BANKS];
  85. static int pavail_ents;
  86. u64 numa_latency[MAX_NUMNODES][MAX_NUMNODES];
  87. static int cmp_p64(const void *a, const void *b)
  88. {
  89. const struct linux_prom64_registers *x = a, *y = b;
  90. if (x->phys_addr > y->phys_addr)
  91. return 1;
  92. if (x->phys_addr < y->phys_addr)
  93. return -1;
  94. return 0;
  95. }
  96. static void __init read_obp_memory(const char *property,
  97. struct linux_prom64_registers *regs,
  98. int *num_ents)
  99. {
  100. phandle node = prom_finddevice("/memory");
  101. int prop_size = prom_getproplen(node, property);
  102. int ents, ret, i;
  103. ents = prop_size / sizeof(struct linux_prom64_registers);
  104. if (ents > MAX_BANKS) {
  105. prom_printf("The machine has more %s property entries than "
  106. "this kernel can support (%d).\n",
  107. property, MAX_BANKS);
  108. prom_halt();
  109. }
  110. ret = prom_getproperty(node, property, (char *) regs, prop_size);
  111. if (ret == -1) {
  112. prom_printf("Couldn't get %s property from /memory.\n",
  113. property);
  114. prom_halt();
  115. }
  116. /* Sanitize what we got from the firmware, by page aligning
  117. * everything.
  118. */
  119. for (i = 0; i < ents; i++) {
  120. unsigned long base, size;
  121. base = regs[i].phys_addr;
  122. size = regs[i].reg_size;
  123. size &= PAGE_MASK;
  124. if (base & ~PAGE_MASK) {
  125. unsigned long new_base = PAGE_ALIGN(base);
  126. size -= new_base - base;
  127. if ((long) size < 0L)
  128. size = 0UL;
  129. base = new_base;
  130. }
  131. if (size == 0UL) {
  132. /* If it is empty, simply get rid of it.
  133. * This simplifies the logic of the other
  134. * functions that process these arrays.
  135. */
  136. memmove(&regs[i], &regs[i + 1],
  137. (ents - i - 1) * sizeof(regs[0]));
  138. i--;
  139. ents--;
  140. continue;
  141. }
  142. regs[i].phys_addr = base;
  143. regs[i].reg_size = size;
  144. }
  145. *num_ents = ents;
  146. sort(regs, ents, sizeof(struct linux_prom64_registers),
  147. cmp_p64, NULL);
  148. }
  149. /* Kernel physical address base and size in bytes. */
  150. unsigned long kern_base __read_mostly;
  151. unsigned long kern_size __read_mostly;
  152. /* Initial ramdisk setup */
  153. extern unsigned long sparc_ramdisk_image64;
  154. extern unsigned int sparc_ramdisk_image;
  155. extern unsigned int sparc_ramdisk_size;
  156. struct page *mem_map_zero __read_mostly;
  157. EXPORT_SYMBOL(mem_map_zero);
  158. unsigned int sparc64_highest_unlocked_tlb_ent __read_mostly;
  159. unsigned long sparc64_kern_pri_context __read_mostly;
  160. unsigned long sparc64_kern_pri_nuc_bits __read_mostly;
  161. unsigned long sparc64_kern_sec_context __read_mostly;
  162. int num_kernel_image_mappings;
  163. #ifdef CONFIG_DEBUG_DCFLUSH
  164. atomic_t dcpage_flushes = ATOMIC_INIT(0);
  165. #ifdef CONFIG_SMP
  166. atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
  167. #endif
  168. #endif
  169. inline void flush_dcache_page_impl(struct page *page)
  170. {
  171. BUG_ON(tlb_type == hypervisor);
  172. #ifdef CONFIG_DEBUG_DCFLUSH
  173. atomic_inc(&dcpage_flushes);
  174. #endif
  175. #ifdef DCACHE_ALIASING_POSSIBLE
  176. __flush_dcache_page(page_address(page),
  177. ((tlb_type == spitfire) &&
  178. page_mapping(page) != NULL));
  179. #else
  180. if (page_mapping(page) != NULL &&
  181. tlb_type == spitfire)
  182. __flush_icache_page(__pa(page_address(page)));
  183. #endif
  184. }
  185. #define PG_dcache_dirty PG_arch_1
  186. #define PG_dcache_cpu_shift 32UL
  187. #define PG_dcache_cpu_mask \
  188. ((1UL<<ilog2(roundup_pow_of_two(NR_CPUS)))-1UL)
  189. #define dcache_dirty_cpu(page) \
  190. (((page)->flags >> PG_dcache_cpu_shift) & PG_dcache_cpu_mask)
  191. static inline void set_dcache_dirty(struct page *page, int this_cpu)
  192. {
  193. unsigned long mask = this_cpu;
  194. unsigned long non_cpu_bits;
  195. non_cpu_bits = ~(PG_dcache_cpu_mask << PG_dcache_cpu_shift);
  196. mask = (mask << PG_dcache_cpu_shift) | (1UL << PG_dcache_dirty);
  197. __asm__ __volatile__("1:\n\t"
  198. "ldx [%2], %%g7\n\t"
  199. "and %%g7, %1, %%g1\n\t"
  200. "or %%g1, %0, %%g1\n\t"
  201. "casx [%2], %%g7, %%g1\n\t"
  202. "cmp %%g7, %%g1\n\t"
  203. "bne,pn %%xcc, 1b\n\t"
  204. " nop"
  205. : /* no outputs */
  206. : "r" (mask), "r" (non_cpu_bits), "r" (&page->flags)
  207. : "g1", "g7");
  208. }
  209. static inline void clear_dcache_dirty_cpu(struct page *page, unsigned long cpu)
  210. {
  211. unsigned long mask = (1UL << PG_dcache_dirty);
  212. __asm__ __volatile__("! test_and_clear_dcache_dirty\n"
  213. "1:\n\t"
  214. "ldx [%2], %%g7\n\t"
  215. "srlx %%g7, %4, %%g1\n\t"
  216. "and %%g1, %3, %%g1\n\t"
  217. "cmp %%g1, %0\n\t"
  218. "bne,pn %%icc, 2f\n\t"
  219. " andn %%g7, %1, %%g1\n\t"
  220. "casx [%2], %%g7, %%g1\n\t"
  221. "cmp %%g7, %%g1\n\t"
  222. "bne,pn %%xcc, 1b\n\t"
  223. " nop\n"
  224. "2:"
  225. : /* no outputs */
  226. : "r" (cpu), "r" (mask), "r" (&page->flags),
  227. "i" (PG_dcache_cpu_mask),
  228. "i" (PG_dcache_cpu_shift)
  229. : "g1", "g7");
  230. }
  231. static inline void tsb_insert(struct tsb *ent, unsigned long tag, unsigned long pte)
  232. {
  233. unsigned long tsb_addr = (unsigned long) ent;
  234. if (tlb_type == cheetah_plus || tlb_type == hypervisor)
  235. tsb_addr = __pa(tsb_addr);
  236. __tsb_insert(tsb_addr, tag, pte);
  237. }
  238. unsigned long _PAGE_ALL_SZ_BITS __read_mostly;
  239. static void flush_dcache(unsigned long pfn)
  240. {
  241. struct page *page;
  242. page = pfn_to_page(pfn);
  243. if (page) {
  244. unsigned long pg_flags;
  245. pg_flags = page->flags;
  246. if (pg_flags & (1UL << PG_dcache_dirty)) {
  247. int cpu = ((pg_flags >> PG_dcache_cpu_shift) &
  248. PG_dcache_cpu_mask);
  249. int this_cpu = get_cpu();
  250. /* This is just to optimize away some function calls
  251. * in the SMP case.
  252. */
  253. if (cpu == this_cpu)
  254. flush_dcache_page_impl(page);
  255. else
  256. smp_flush_dcache_page_impl(page, cpu);
  257. clear_dcache_dirty_cpu(page, cpu);
  258. put_cpu();
  259. }
  260. }
  261. }
  262. /* mm->context.lock must be held */
  263. static void __update_mmu_tsb_insert(struct mm_struct *mm, unsigned long tsb_index,
  264. unsigned long tsb_hash_shift, unsigned long address,
  265. unsigned long tte)
  266. {
  267. struct tsb *tsb = mm->context.tsb_block[tsb_index].tsb;
  268. unsigned long tag;
  269. if (unlikely(!tsb))
  270. return;
  271. tsb += ((address >> tsb_hash_shift) &
  272. (mm->context.tsb_block[tsb_index].tsb_nentries - 1UL));
  273. tag = (address >> 22UL);
  274. tsb_insert(tsb, tag, tte);
  275. }
  276. void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep)
  277. {
  278. struct mm_struct *mm;
  279. unsigned long flags;
  280. pte_t pte = *ptep;
  281. if (tlb_type != hypervisor) {
  282. unsigned long pfn = pte_pfn(pte);
  283. if (pfn_valid(pfn))
  284. flush_dcache(pfn);
  285. }
  286. mm = vma->vm_mm;
  287. /* Don't insert a non-valid PTE into the TSB, we'll deadlock. */
  288. if (!pte_accessible(mm, pte))
  289. return;
  290. spin_lock_irqsave(&mm->context.lock, flags);
  291. #if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE)
  292. if ((mm->context.hugetlb_pte_count || mm->context.thp_pte_count) &&
  293. is_hugetlb_pte(pte)) {
  294. /* We are fabricating 8MB pages using 4MB real hw pages. */
  295. pte_val(pte) |= (address & (1UL << REAL_HPAGE_SHIFT));
  296. __update_mmu_tsb_insert(mm, MM_TSB_HUGE, REAL_HPAGE_SHIFT,
  297. address, pte_val(pte));
  298. } else
  299. #endif
  300. __update_mmu_tsb_insert(mm, MM_TSB_BASE, PAGE_SHIFT,
  301. address, pte_val(pte));
  302. spin_unlock_irqrestore(&mm->context.lock, flags);
  303. }
  304. void flush_dcache_page(struct page *page)
  305. {
  306. struct address_space *mapping;
  307. int this_cpu;
  308. if (tlb_type == hypervisor)
  309. return;
  310. /* Do not bother with the expensive D-cache flush if it
  311. * is merely the zero page. The 'bigcore' testcase in GDB
  312. * causes this case to run millions of times.
  313. */
  314. if (page == ZERO_PAGE(0))
  315. return;
  316. this_cpu = get_cpu();
  317. mapping = page_mapping(page);
  318. if (mapping && !mapping_mapped(mapping)) {
  319. int dirty = test_bit(PG_dcache_dirty, &page->flags);
  320. if (dirty) {
  321. int dirty_cpu = dcache_dirty_cpu(page);
  322. if (dirty_cpu == this_cpu)
  323. goto out;
  324. smp_flush_dcache_page_impl(page, dirty_cpu);
  325. }
  326. set_dcache_dirty(page, this_cpu);
  327. } else {
  328. /* We could delay the flush for the !page_mapping
  329. * case too. But that case is for exec env/arg
  330. * pages and those are %99 certainly going to get
  331. * faulted into the tlb (and thus flushed) anyways.
  332. */
  333. flush_dcache_page_impl(page);
  334. }
  335. out:
  336. put_cpu();
  337. }
  338. EXPORT_SYMBOL(flush_dcache_page);
  339. void __kprobes flush_icache_range(unsigned long start, unsigned long end)
  340. {
  341. /* Cheetah and Hypervisor platform cpus have coherent I-cache. */
  342. if (tlb_type == spitfire) {
  343. unsigned long kaddr;
  344. /* This code only runs on Spitfire cpus so this is
  345. * why we can assume _PAGE_PADDR_4U.
  346. */
  347. for (kaddr = start; kaddr < end; kaddr += PAGE_SIZE) {
  348. unsigned long paddr, mask = _PAGE_PADDR_4U;
  349. if (kaddr >= PAGE_OFFSET)
  350. paddr = kaddr & mask;
  351. else {
  352. pgd_t *pgdp = pgd_offset_k(kaddr);
  353. pud_t *pudp = pud_offset(pgdp, kaddr);
  354. pmd_t *pmdp = pmd_offset(pudp, kaddr);
  355. pte_t *ptep = pte_offset_kernel(pmdp, kaddr);
  356. paddr = pte_val(*ptep) & mask;
  357. }
  358. __flush_icache_page(paddr);
  359. }
  360. }
  361. }
  362. EXPORT_SYMBOL(flush_icache_range);
  363. void mmu_info(struct seq_file *m)
  364. {
  365. static const char *pgsz_strings[] = {
  366. "8K", "64K", "512K", "4MB", "32MB",
  367. "256MB", "2GB", "16GB",
  368. };
  369. int i, printed;
  370. if (tlb_type == cheetah)
  371. seq_printf(m, "MMU Type\t: Cheetah\n");
  372. else if (tlb_type == cheetah_plus)
  373. seq_printf(m, "MMU Type\t: Cheetah+\n");
  374. else if (tlb_type == spitfire)
  375. seq_printf(m, "MMU Type\t: Spitfire\n");
  376. else if (tlb_type == hypervisor)
  377. seq_printf(m, "MMU Type\t: Hypervisor (sun4v)\n");
  378. else
  379. seq_printf(m, "MMU Type\t: ???\n");
  380. seq_printf(m, "MMU PGSZs\t: ");
  381. printed = 0;
  382. for (i = 0; i < ARRAY_SIZE(pgsz_strings); i++) {
  383. if (cpu_pgsz_mask & (1UL << i)) {
  384. seq_printf(m, "%s%s",
  385. printed ? "," : "", pgsz_strings[i]);
  386. printed++;
  387. }
  388. }
  389. seq_putc(m, '\n');
  390. #ifdef CONFIG_DEBUG_DCFLUSH
  391. seq_printf(m, "DCPageFlushes\t: %d\n",
  392. atomic_read(&dcpage_flushes));
  393. #ifdef CONFIG_SMP
  394. seq_printf(m, "DCPageFlushesXC\t: %d\n",
  395. atomic_read(&dcpage_flushes_xcall));
  396. #endif /* CONFIG_SMP */
  397. #endif /* CONFIG_DEBUG_DCFLUSH */
  398. }
  399. struct linux_prom_translation prom_trans[512] __read_mostly;
  400. unsigned int prom_trans_ents __read_mostly;
  401. unsigned long kern_locked_tte_data;
  402. /* The obp translations are saved based on 8k pagesize, since obp can
  403. * use a mixture of pagesizes. Misses to the LOW_OBP_ADDRESS ->
  404. * HI_OBP_ADDRESS range are handled in ktlb.S.
  405. */
  406. static inline int in_obp_range(unsigned long vaddr)
  407. {
  408. return (vaddr >= LOW_OBP_ADDRESS &&
  409. vaddr < HI_OBP_ADDRESS);
  410. }
  411. static int cmp_ptrans(const void *a, const void *b)
  412. {
  413. const struct linux_prom_translation *x = a, *y = b;
  414. if (x->virt > y->virt)
  415. return 1;
  416. if (x->virt < y->virt)
  417. return -1;
  418. return 0;
  419. }
  420. /* Read OBP translations property into 'prom_trans[]'. */
  421. static void __init read_obp_translations(void)
  422. {
  423. int n, node, ents, first, last, i;
  424. node = prom_finddevice("/virtual-memory");
  425. n = prom_getproplen(node, "translations");
  426. if (unlikely(n == 0 || n == -1)) {
  427. prom_printf("prom_mappings: Couldn't get size.\n");
  428. prom_halt();
  429. }
  430. if (unlikely(n > sizeof(prom_trans))) {
  431. prom_printf("prom_mappings: Size %d is too big.\n", n);
  432. prom_halt();
  433. }
  434. if ((n = prom_getproperty(node, "translations",
  435. (char *)&prom_trans[0],
  436. sizeof(prom_trans))) == -1) {
  437. prom_printf("prom_mappings: Couldn't get property.\n");
  438. prom_halt();
  439. }
  440. n = n / sizeof(struct linux_prom_translation);
  441. ents = n;
  442. sort(prom_trans, ents, sizeof(struct linux_prom_translation),
  443. cmp_ptrans, NULL);
  444. /* Now kick out all the non-OBP entries. */
  445. for (i = 0; i < ents; i++) {
  446. if (in_obp_range(prom_trans[i].virt))
  447. break;
  448. }
  449. first = i;
  450. for (; i < ents; i++) {
  451. if (!in_obp_range(prom_trans[i].virt))
  452. break;
  453. }
  454. last = i;
  455. for (i = 0; i < (last - first); i++) {
  456. struct linux_prom_translation *src = &prom_trans[i + first];
  457. struct linux_prom_translation *dest = &prom_trans[i];
  458. *dest = *src;
  459. }
  460. for (; i < ents; i++) {
  461. struct linux_prom_translation *dest = &prom_trans[i];
  462. dest->virt = dest->size = dest->data = 0x0UL;
  463. }
  464. prom_trans_ents = last - first;
  465. if (tlb_type == spitfire) {
  466. /* Clear diag TTE bits. */
  467. for (i = 0; i < prom_trans_ents; i++)
  468. prom_trans[i].data &= ~0x0003fe0000000000UL;
  469. }
  470. /* Force execute bit on. */
  471. for (i = 0; i < prom_trans_ents; i++)
  472. prom_trans[i].data |= (tlb_type == hypervisor ?
  473. _PAGE_EXEC_4V : _PAGE_EXEC_4U);
  474. }
  475. static void __init hypervisor_tlb_lock(unsigned long vaddr,
  476. unsigned long pte,
  477. unsigned long mmu)
  478. {
  479. unsigned long ret = sun4v_mmu_map_perm_addr(vaddr, 0, pte, mmu);
  480. if (ret != 0) {
  481. prom_printf("hypervisor_tlb_lock[%lx:%x:%lx:%lx]: "
  482. "errors with %lx\n", vaddr, 0, pte, mmu, ret);
  483. prom_halt();
  484. }
  485. }
  486. static unsigned long kern_large_tte(unsigned long paddr);
  487. static void __init remap_kernel(void)
  488. {
  489. unsigned long phys_page, tte_vaddr, tte_data;
  490. int i, tlb_ent = sparc64_highest_locked_tlbent();
  491. tte_vaddr = (unsigned long) KERNBASE;
  492. phys_page = (prom_boot_mapping_phys_low >> ILOG2_4MB) << ILOG2_4MB;
  493. tte_data = kern_large_tte(phys_page);
  494. kern_locked_tte_data = tte_data;
  495. /* Now lock us into the TLBs via Hypervisor or OBP. */
  496. if (tlb_type == hypervisor) {
  497. for (i = 0; i < num_kernel_image_mappings; i++) {
  498. hypervisor_tlb_lock(tte_vaddr, tte_data, HV_MMU_DMMU);
  499. hypervisor_tlb_lock(tte_vaddr, tte_data, HV_MMU_IMMU);
  500. tte_vaddr += 0x400000;
  501. tte_data += 0x400000;
  502. }
  503. } else {
  504. for (i = 0; i < num_kernel_image_mappings; i++) {
  505. prom_dtlb_load(tlb_ent - i, tte_data, tte_vaddr);
  506. prom_itlb_load(tlb_ent - i, tte_data, tte_vaddr);
  507. tte_vaddr += 0x400000;
  508. tte_data += 0x400000;
  509. }
  510. sparc64_highest_unlocked_tlb_ent = tlb_ent - i;
  511. }
  512. if (tlb_type == cheetah_plus) {
  513. sparc64_kern_pri_context = (CTX_CHEETAH_PLUS_CTX0 |
  514. CTX_CHEETAH_PLUS_NUC);
  515. sparc64_kern_pri_nuc_bits = CTX_CHEETAH_PLUS_NUC;
  516. sparc64_kern_sec_context = CTX_CHEETAH_PLUS_CTX0;
  517. }
  518. }
  519. static void __init inherit_prom_mappings(void)
  520. {
  521. /* Now fixup OBP's idea about where we really are mapped. */
  522. printk("Remapping the kernel... ");
  523. remap_kernel();
  524. printk("done.\n");
  525. }
  526. void prom_world(int enter)
  527. {
  528. if (!enter)
  529. set_fs(get_fs());
  530. __asm__ __volatile__("flushw");
  531. }
  532. void __flush_dcache_range(unsigned long start, unsigned long end)
  533. {
  534. unsigned long va;
  535. if (tlb_type == spitfire) {
  536. int n = 0;
  537. for (va = start; va < end; va += 32) {
  538. spitfire_put_dcache_tag(va & 0x3fe0, 0x0);
  539. if (++n >= 512)
  540. break;
  541. }
  542. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  543. start = __pa(start);
  544. end = __pa(end);
  545. for (va = start; va < end; va += 32)
  546. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  547. "membar #Sync"
  548. : /* no outputs */
  549. : "r" (va),
  550. "i" (ASI_DCACHE_INVALIDATE));
  551. }
  552. }
  553. EXPORT_SYMBOL(__flush_dcache_range);
  554. /* get_new_mmu_context() uses "cache + 1". */
  555. DEFINE_SPINLOCK(ctx_alloc_lock);
  556. unsigned long tlb_context_cache = CTX_FIRST_VERSION;
  557. #define MAX_CTX_NR (1UL << CTX_NR_BITS)
  558. #define CTX_BMAP_SLOTS BITS_TO_LONGS(MAX_CTX_NR)
  559. DECLARE_BITMAP(mmu_context_bmap, MAX_CTX_NR);
  560. DEFINE_PER_CPU(struct mm_struct *, per_cpu_secondary_mm) = {0};
  561. static void mmu_context_wrap(void)
  562. {
  563. unsigned long old_ver = tlb_context_cache & CTX_VERSION_MASK;
  564. unsigned long new_ver, new_ctx, old_ctx;
  565. struct mm_struct *mm;
  566. int cpu;
  567. bitmap_zero(mmu_context_bmap, 1 << CTX_NR_BITS);
  568. /* Reserve kernel context */
  569. set_bit(0, mmu_context_bmap);
  570. new_ver = (tlb_context_cache & CTX_VERSION_MASK) + CTX_FIRST_VERSION;
  571. if (unlikely(new_ver == 0))
  572. new_ver = CTX_FIRST_VERSION;
  573. tlb_context_cache = new_ver;
  574. /*
  575. * Make sure that any new mm that are added into per_cpu_secondary_mm,
  576. * are going to go through get_new_mmu_context() path.
  577. */
  578. mb();
  579. /*
  580. * Updated versions to current on those CPUs that had valid secondary
  581. * contexts
  582. */
  583. for_each_online_cpu(cpu) {
  584. /*
  585. * If a new mm is stored after we took this mm from the array,
  586. * it will go into get_new_mmu_context() path, because we
  587. * already bumped the version in tlb_context_cache.
  588. */
  589. mm = per_cpu(per_cpu_secondary_mm, cpu);
  590. if (unlikely(!mm || mm == &init_mm))
  591. continue;
  592. old_ctx = mm->context.sparc64_ctx_val;
  593. if (likely((old_ctx & CTX_VERSION_MASK) == old_ver)) {
  594. new_ctx = (old_ctx & ~CTX_VERSION_MASK) | new_ver;
  595. set_bit(new_ctx & CTX_NR_MASK, mmu_context_bmap);
  596. mm->context.sparc64_ctx_val = new_ctx;
  597. }
  598. }
  599. }
  600. /* Caller does TLB context flushing on local CPU if necessary.
  601. * The caller also ensures that CTX_VALID(mm->context) is false.
  602. *
  603. * We must be careful about boundary cases so that we never
  604. * let the user have CTX 0 (nucleus) or we ever use a CTX
  605. * version of zero (and thus NO_CONTEXT would not be caught
  606. * by version mis-match tests in mmu_context.h).
  607. *
  608. * Always invoked with interrupts disabled.
  609. */
  610. void get_new_mmu_context(struct mm_struct *mm)
  611. {
  612. unsigned long ctx, new_ctx;
  613. unsigned long orig_pgsz_bits;
  614. spin_lock(&ctx_alloc_lock);
  615. retry:
  616. /* wrap might have happened, test again if our context became valid */
  617. if (unlikely(CTX_VALID(mm->context)))
  618. goto out;
  619. orig_pgsz_bits = (mm->context.sparc64_ctx_val & CTX_PGSZ_MASK);
  620. ctx = (tlb_context_cache + 1) & CTX_NR_MASK;
  621. new_ctx = find_next_zero_bit(mmu_context_bmap, 1 << CTX_NR_BITS, ctx);
  622. if (new_ctx >= (1 << CTX_NR_BITS)) {
  623. new_ctx = find_next_zero_bit(mmu_context_bmap, ctx, 1);
  624. if (new_ctx >= ctx) {
  625. mmu_context_wrap();
  626. goto retry;
  627. }
  628. }
  629. if (mm->context.sparc64_ctx_val)
  630. cpumask_clear(mm_cpumask(mm));
  631. mmu_context_bmap[new_ctx>>6] |= (1UL << (new_ctx & 63));
  632. new_ctx |= (tlb_context_cache & CTX_VERSION_MASK);
  633. tlb_context_cache = new_ctx;
  634. mm->context.sparc64_ctx_val = new_ctx | orig_pgsz_bits;
  635. out:
  636. spin_unlock(&ctx_alloc_lock);
  637. }
  638. static int numa_enabled = 1;
  639. static int numa_debug;
  640. static int __init early_numa(char *p)
  641. {
  642. if (!p)
  643. return 0;
  644. if (strstr(p, "off"))
  645. numa_enabled = 0;
  646. if (strstr(p, "debug"))
  647. numa_debug = 1;
  648. return 0;
  649. }
  650. early_param("numa", early_numa);
  651. #define numadbg(f, a...) \
  652. do { if (numa_debug) \
  653. printk(KERN_INFO f, ## a); \
  654. } while (0)
  655. static void __init find_ramdisk(unsigned long phys_base)
  656. {
  657. #ifdef CONFIG_BLK_DEV_INITRD
  658. if (sparc_ramdisk_image || sparc_ramdisk_image64) {
  659. unsigned long ramdisk_image;
  660. /* Older versions of the bootloader only supported a
  661. * 32-bit physical address for the ramdisk image
  662. * location, stored at sparc_ramdisk_image. Newer
  663. * SILO versions set sparc_ramdisk_image to zero and
  664. * provide a full 64-bit physical address at
  665. * sparc_ramdisk_image64.
  666. */
  667. ramdisk_image = sparc_ramdisk_image;
  668. if (!ramdisk_image)
  669. ramdisk_image = sparc_ramdisk_image64;
  670. /* Another bootloader quirk. The bootloader normalizes
  671. * the physical address to KERNBASE, so we have to
  672. * factor that back out and add in the lowest valid
  673. * physical page address to get the true physical address.
  674. */
  675. ramdisk_image -= KERNBASE;
  676. ramdisk_image += phys_base;
  677. numadbg("Found ramdisk at physical address 0x%lx, size %u\n",
  678. ramdisk_image, sparc_ramdisk_size);
  679. initrd_start = ramdisk_image;
  680. initrd_end = ramdisk_image + sparc_ramdisk_size;
  681. memblock_reserve(initrd_start, sparc_ramdisk_size);
  682. initrd_start += PAGE_OFFSET;
  683. initrd_end += PAGE_OFFSET;
  684. }
  685. #endif
  686. }
  687. struct node_mem_mask {
  688. unsigned long mask;
  689. unsigned long val;
  690. };
  691. static struct node_mem_mask node_masks[MAX_NUMNODES];
  692. static int num_node_masks;
  693. #ifdef CONFIG_NEED_MULTIPLE_NODES
  694. int numa_cpu_lookup_table[NR_CPUS];
  695. cpumask_t numa_cpumask_lookup_table[MAX_NUMNODES];
  696. struct mdesc_mblock {
  697. u64 base;
  698. u64 size;
  699. u64 offset; /* RA-to-PA */
  700. };
  701. static struct mdesc_mblock *mblocks;
  702. static int num_mblocks;
  703. static int find_numa_node_for_addr(unsigned long pa,
  704. struct node_mem_mask *pnode_mask);
  705. static unsigned long __init ra_to_pa(unsigned long addr)
  706. {
  707. int i;
  708. for (i = 0; i < num_mblocks; i++) {
  709. struct mdesc_mblock *m = &mblocks[i];
  710. if (addr >= m->base &&
  711. addr < (m->base + m->size)) {
  712. addr += m->offset;
  713. break;
  714. }
  715. }
  716. return addr;
  717. }
  718. static int __init find_node(unsigned long addr)
  719. {
  720. static bool search_mdesc = true;
  721. static struct node_mem_mask last_mem_mask = { ~0UL, ~0UL };
  722. static int last_index;
  723. int i;
  724. addr = ra_to_pa(addr);
  725. for (i = 0; i < num_node_masks; i++) {
  726. struct node_mem_mask *p = &node_masks[i];
  727. if ((addr & p->mask) == p->val)
  728. return i;
  729. }
  730. /* The following condition has been observed on LDOM guests because
  731. * node_masks only contains the best latency mask and value.
  732. * LDOM guest's mdesc can contain a single latency group to
  733. * cover multiple address range. Print warning message only if the
  734. * address cannot be found in node_masks nor mdesc.
  735. */
  736. if ((search_mdesc) &&
  737. ((addr & last_mem_mask.mask) != last_mem_mask.val)) {
  738. /* find the available node in the mdesc */
  739. last_index = find_numa_node_for_addr(addr, &last_mem_mask);
  740. numadbg("find_node: latency group for address 0x%lx is %d\n",
  741. addr, last_index);
  742. if ((last_index < 0) || (last_index >= num_node_masks)) {
  743. /* WARN_ONCE() and use default group 0 */
  744. WARN_ONCE(1, "find_node: A physical address doesn't match a NUMA node rule. Some physical memory will be owned by node 0.");
  745. search_mdesc = false;
  746. last_index = 0;
  747. }
  748. }
  749. return last_index;
  750. }
  751. static u64 __init memblock_nid_range(u64 start, u64 end, int *nid)
  752. {
  753. *nid = find_node(start);
  754. start += PAGE_SIZE;
  755. while (start < end) {
  756. int n = find_node(start);
  757. if (n != *nid)
  758. break;
  759. start += PAGE_SIZE;
  760. }
  761. if (start > end)
  762. start = end;
  763. return start;
  764. }
  765. #endif
  766. /* This must be invoked after performing all of the necessary
  767. * memblock_set_node() calls for 'nid'. We need to be able to get
  768. * correct data from get_pfn_range_for_nid().
  769. */
  770. static void __init allocate_node_data(int nid)
  771. {
  772. struct pglist_data *p;
  773. unsigned long start_pfn, end_pfn;
  774. #ifdef CONFIG_NEED_MULTIPLE_NODES
  775. unsigned long paddr;
  776. paddr = memblock_alloc_try_nid(sizeof(struct pglist_data), SMP_CACHE_BYTES, nid);
  777. if (!paddr) {
  778. prom_printf("Cannot allocate pglist_data for nid[%d]\n", nid);
  779. prom_halt();
  780. }
  781. NODE_DATA(nid) = __va(paddr);
  782. memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
  783. NODE_DATA(nid)->node_id = nid;
  784. #endif
  785. p = NODE_DATA(nid);
  786. get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
  787. p->node_start_pfn = start_pfn;
  788. p->node_spanned_pages = end_pfn - start_pfn;
  789. }
  790. static void init_node_masks_nonnuma(void)
  791. {
  792. #ifdef CONFIG_NEED_MULTIPLE_NODES
  793. int i;
  794. #endif
  795. numadbg("Initializing tables for non-numa.\n");
  796. node_masks[0].mask = node_masks[0].val = 0;
  797. num_node_masks = 1;
  798. #ifdef CONFIG_NEED_MULTIPLE_NODES
  799. for (i = 0; i < NR_CPUS; i++)
  800. numa_cpu_lookup_table[i] = 0;
  801. cpumask_setall(&numa_cpumask_lookup_table[0]);
  802. #endif
  803. }
  804. #ifdef CONFIG_NEED_MULTIPLE_NODES
  805. struct pglist_data *node_data[MAX_NUMNODES];
  806. EXPORT_SYMBOL(numa_cpu_lookup_table);
  807. EXPORT_SYMBOL(numa_cpumask_lookup_table);
  808. EXPORT_SYMBOL(node_data);
  809. struct mdesc_mlgroup {
  810. u64 node;
  811. u64 latency;
  812. u64 match;
  813. u64 mask;
  814. };
  815. static struct mdesc_mlgroup *mlgroups;
  816. static int num_mlgroups;
  817. static int scan_pio_for_cfg_handle(struct mdesc_handle *md, u64 pio,
  818. u32 cfg_handle)
  819. {
  820. u64 arc;
  821. mdesc_for_each_arc(arc, md, pio, MDESC_ARC_TYPE_FWD) {
  822. u64 target = mdesc_arc_target(md, arc);
  823. const u64 *val;
  824. val = mdesc_get_property(md, target,
  825. "cfg-handle", NULL);
  826. if (val && *val == cfg_handle)
  827. return 0;
  828. }
  829. return -ENODEV;
  830. }
  831. static int scan_arcs_for_cfg_handle(struct mdesc_handle *md, u64 grp,
  832. u32 cfg_handle)
  833. {
  834. u64 arc, candidate, best_latency = ~(u64)0;
  835. candidate = MDESC_NODE_NULL;
  836. mdesc_for_each_arc(arc, md, grp, MDESC_ARC_TYPE_FWD) {
  837. u64 target = mdesc_arc_target(md, arc);
  838. const char *name = mdesc_node_name(md, target);
  839. const u64 *val;
  840. if (strcmp(name, "pio-latency-group"))
  841. continue;
  842. val = mdesc_get_property(md, target, "latency", NULL);
  843. if (!val)
  844. continue;
  845. if (*val < best_latency) {
  846. candidate = target;
  847. best_latency = *val;
  848. }
  849. }
  850. if (candidate == MDESC_NODE_NULL)
  851. return -ENODEV;
  852. return scan_pio_for_cfg_handle(md, candidate, cfg_handle);
  853. }
  854. int of_node_to_nid(struct device_node *dp)
  855. {
  856. const struct linux_prom64_registers *regs;
  857. struct mdesc_handle *md;
  858. u32 cfg_handle;
  859. int count, nid;
  860. u64 grp;
  861. /* This is the right thing to do on currently supported
  862. * SUN4U NUMA platforms as well, as the PCI controller does
  863. * not sit behind any particular memory controller.
  864. */
  865. if (!mlgroups)
  866. return -1;
  867. regs = of_get_property(dp, "reg", NULL);
  868. if (!regs)
  869. return -1;
  870. cfg_handle = (regs->phys_addr >> 32UL) & 0x0fffffff;
  871. md = mdesc_grab();
  872. count = 0;
  873. nid = -1;
  874. mdesc_for_each_node_by_name(md, grp, "group") {
  875. if (!scan_arcs_for_cfg_handle(md, grp, cfg_handle)) {
  876. nid = count;
  877. break;
  878. }
  879. count++;
  880. }
  881. mdesc_release(md);
  882. return nid;
  883. }
  884. static void __init add_node_ranges(void)
  885. {
  886. struct memblock_region *reg;
  887. for_each_memblock(memory, reg) {
  888. unsigned long size = reg->size;
  889. unsigned long start, end;
  890. start = reg->base;
  891. end = start + size;
  892. while (start < end) {
  893. unsigned long this_end;
  894. int nid;
  895. this_end = memblock_nid_range(start, end, &nid);
  896. numadbg("Setting memblock NUMA node nid[%d] "
  897. "start[%lx] end[%lx]\n",
  898. nid, start, this_end);
  899. memblock_set_node(start, this_end - start,
  900. &memblock.memory, nid);
  901. start = this_end;
  902. }
  903. }
  904. }
  905. static int __init grab_mlgroups(struct mdesc_handle *md)
  906. {
  907. unsigned long paddr;
  908. int count = 0;
  909. u64 node;
  910. mdesc_for_each_node_by_name(md, node, "memory-latency-group")
  911. count++;
  912. if (!count)
  913. return -ENOENT;
  914. paddr = memblock_alloc(count * sizeof(struct mdesc_mlgroup),
  915. SMP_CACHE_BYTES);
  916. if (!paddr)
  917. return -ENOMEM;
  918. mlgroups = __va(paddr);
  919. num_mlgroups = count;
  920. count = 0;
  921. mdesc_for_each_node_by_name(md, node, "memory-latency-group") {
  922. struct mdesc_mlgroup *m = &mlgroups[count++];
  923. const u64 *val;
  924. m->node = node;
  925. val = mdesc_get_property(md, node, "latency", NULL);
  926. m->latency = *val;
  927. val = mdesc_get_property(md, node, "address-match", NULL);
  928. m->match = *val;
  929. val = mdesc_get_property(md, node, "address-mask", NULL);
  930. m->mask = *val;
  931. numadbg("MLGROUP[%d]: node[%llx] latency[%llx] "
  932. "match[%llx] mask[%llx]\n",
  933. count - 1, m->node, m->latency, m->match, m->mask);
  934. }
  935. return 0;
  936. }
  937. static int __init grab_mblocks(struct mdesc_handle *md)
  938. {
  939. unsigned long paddr;
  940. int count = 0;
  941. u64 node;
  942. mdesc_for_each_node_by_name(md, node, "mblock")
  943. count++;
  944. if (!count)
  945. return -ENOENT;
  946. paddr = memblock_alloc(count * sizeof(struct mdesc_mblock),
  947. SMP_CACHE_BYTES);
  948. if (!paddr)
  949. return -ENOMEM;
  950. mblocks = __va(paddr);
  951. num_mblocks = count;
  952. count = 0;
  953. mdesc_for_each_node_by_name(md, node, "mblock") {
  954. struct mdesc_mblock *m = &mblocks[count++];
  955. const u64 *val;
  956. val = mdesc_get_property(md, node, "base", NULL);
  957. m->base = *val;
  958. val = mdesc_get_property(md, node, "size", NULL);
  959. m->size = *val;
  960. val = mdesc_get_property(md, node,
  961. "address-congruence-offset", NULL);
  962. /* The address-congruence-offset property is optional.
  963. * Explicity zero it be identifty this.
  964. */
  965. if (val)
  966. m->offset = *val;
  967. else
  968. m->offset = 0UL;
  969. numadbg("MBLOCK[%d]: base[%llx] size[%llx] offset[%llx]\n",
  970. count - 1, m->base, m->size, m->offset);
  971. }
  972. return 0;
  973. }
  974. static void __init numa_parse_mdesc_group_cpus(struct mdesc_handle *md,
  975. u64 grp, cpumask_t *mask)
  976. {
  977. u64 arc;
  978. cpumask_clear(mask);
  979. mdesc_for_each_arc(arc, md, grp, MDESC_ARC_TYPE_BACK) {
  980. u64 target = mdesc_arc_target(md, arc);
  981. const char *name = mdesc_node_name(md, target);
  982. const u64 *id;
  983. if (strcmp(name, "cpu"))
  984. continue;
  985. id = mdesc_get_property(md, target, "id", NULL);
  986. if (*id < nr_cpu_ids)
  987. cpumask_set_cpu(*id, mask);
  988. }
  989. }
  990. static struct mdesc_mlgroup * __init find_mlgroup(u64 node)
  991. {
  992. int i;
  993. for (i = 0; i < num_mlgroups; i++) {
  994. struct mdesc_mlgroup *m = &mlgroups[i];
  995. if (m->node == node)
  996. return m;
  997. }
  998. return NULL;
  999. }
  1000. int __node_distance(int from, int to)
  1001. {
  1002. if ((from >= MAX_NUMNODES) || (to >= MAX_NUMNODES)) {
  1003. pr_warn("Returning default NUMA distance value for %d->%d\n",
  1004. from, to);
  1005. return (from == to) ? LOCAL_DISTANCE : REMOTE_DISTANCE;
  1006. }
  1007. return numa_latency[from][to];
  1008. }
  1009. static int find_numa_node_for_addr(unsigned long pa,
  1010. struct node_mem_mask *pnode_mask)
  1011. {
  1012. struct mdesc_handle *md = mdesc_grab();
  1013. u64 node, arc;
  1014. int i = 0;
  1015. node = mdesc_node_by_name(md, MDESC_NODE_NULL, "latency-groups");
  1016. if (node == MDESC_NODE_NULL)
  1017. goto out;
  1018. mdesc_for_each_node_by_name(md, node, "group") {
  1019. mdesc_for_each_arc(arc, md, node, MDESC_ARC_TYPE_FWD) {
  1020. u64 target = mdesc_arc_target(md, arc);
  1021. struct mdesc_mlgroup *m = find_mlgroup(target);
  1022. if (!m)
  1023. continue;
  1024. if ((pa & m->mask) == m->match) {
  1025. if (pnode_mask) {
  1026. pnode_mask->mask = m->mask;
  1027. pnode_mask->val = m->match;
  1028. }
  1029. mdesc_release(md);
  1030. return i;
  1031. }
  1032. }
  1033. i++;
  1034. }
  1035. out:
  1036. mdesc_release(md);
  1037. return -1;
  1038. }
  1039. static int __init find_best_numa_node_for_mlgroup(struct mdesc_mlgroup *grp)
  1040. {
  1041. int i;
  1042. for (i = 0; i < MAX_NUMNODES; i++) {
  1043. struct node_mem_mask *n = &node_masks[i];
  1044. if ((grp->mask == n->mask) && (grp->match == n->val))
  1045. break;
  1046. }
  1047. return i;
  1048. }
  1049. static void __init find_numa_latencies_for_group(struct mdesc_handle *md,
  1050. u64 grp, int index)
  1051. {
  1052. u64 arc;
  1053. mdesc_for_each_arc(arc, md, grp, MDESC_ARC_TYPE_FWD) {
  1054. int tnode;
  1055. u64 target = mdesc_arc_target(md, arc);
  1056. struct mdesc_mlgroup *m = find_mlgroup(target);
  1057. if (!m)
  1058. continue;
  1059. tnode = find_best_numa_node_for_mlgroup(m);
  1060. if (tnode == MAX_NUMNODES)
  1061. continue;
  1062. numa_latency[index][tnode] = m->latency;
  1063. }
  1064. }
  1065. static int __init numa_attach_mlgroup(struct mdesc_handle *md, u64 grp,
  1066. int index)
  1067. {
  1068. struct mdesc_mlgroup *candidate = NULL;
  1069. u64 arc, best_latency = ~(u64)0;
  1070. struct node_mem_mask *n;
  1071. mdesc_for_each_arc(arc, md, grp, MDESC_ARC_TYPE_FWD) {
  1072. u64 target = mdesc_arc_target(md, arc);
  1073. struct mdesc_mlgroup *m = find_mlgroup(target);
  1074. if (!m)
  1075. continue;
  1076. if (m->latency < best_latency) {
  1077. candidate = m;
  1078. best_latency = m->latency;
  1079. }
  1080. }
  1081. if (!candidate)
  1082. return -ENOENT;
  1083. if (num_node_masks != index) {
  1084. printk(KERN_ERR "Inconsistent NUMA state, "
  1085. "index[%d] != num_node_masks[%d]\n",
  1086. index, num_node_masks);
  1087. return -EINVAL;
  1088. }
  1089. n = &node_masks[num_node_masks++];
  1090. n->mask = candidate->mask;
  1091. n->val = candidate->match;
  1092. numadbg("NUMA NODE[%d]: mask[%lx] val[%lx] (latency[%llx])\n",
  1093. index, n->mask, n->val, candidate->latency);
  1094. return 0;
  1095. }
  1096. static int __init numa_parse_mdesc_group(struct mdesc_handle *md, u64 grp,
  1097. int index)
  1098. {
  1099. cpumask_t mask;
  1100. int cpu;
  1101. numa_parse_mdesc_group_cpus(md, grp, &mask);
  1102. for_each_cpu(cpu, &mask)
  1103. numa_cpu_lookup_table[cpu] = index;
  1104. cpumask_copy(&numa_cpumask_lookup_table[index], &mask);
  1105. if (numa_debug) {
  1106. printk(KERN_INFO "NUMA GROUP[%d]: cpus [ ", index);
  1107. for_each_cpu(cpu, &mask)
  1108. printk("%d ", cpu);
  1109. printk("]\n");
  1110. }
  1111. return numa_attach_mlgroup(md, grp, index);
  1112. }
  1113. static int __init numa_parse_mdesc(void)
  1114. {
  1115. struct mdesc_handle *md = mdesc_grab();
  1116. int i, j, err, count;
  1117. u64 node;
  1118. node = mdesc_node_by_name(md, MDESC_NODE_NULL, "latency-groups");
  1119. if (node == MDESC_NODE_NULL) {
  1120. mdesc_release(md);
  1121. return -ENOENT;
  1122. }
  1123. err = grab_mblocks(md);
  1124. if (err < 0)
  1125. goto out;
  1126. err = grab_mlgroups(md);
  1127. if (err < 0)
  1128. goto out;
  1129. count = 0;
  1130. mdesc_for_each_node_by_name(md, node, "group") {
  1131. err = numa_parse_mdesc_group(md, node, count);
  1132. if (err < 0)
  1133. break;
  1134. count++;
  1135. }
  1136. count = 0;
  1137. mdesc_for_each_node_by_name(md, node, "group") {
  1138. find_numa_latencies_for_group(md, node, count);
  1139. count++;
  1140. }
  1141. /* Normalize numa latency matrix according to ACPI SLIT spec. */
  1142. for (i = 0; i < MAX_NUMNODES; i++) {
  1143. u64 self_latency = numa_latency[i][i];
  1144. for (j = 0; j < MAX_NUMNODES; j++) {
  1145. numa_latency[i][j] =
  1146. (numa_latency[i][j] * LOCAL_DISTANCE) /
  1147. self_latency;
  1148. }
  1149. }
  1150. add_node_ranges();
  1151. for (i = 0; i < num_node_masks; i++) {
  1152. allocate_node_data(i);
  1153. node_set_online(i);
  1154. }
  1155. err = 0;
  1156. out:
  1157. mdesc_release(md);
  1158. return err;
  1159. }
  1160. static int __init numa_parse_jbus(void)
  1161. {
  1162. unsigned long cpu, index;
  1163. /* NUMA node id is encoded in bits 36 and higher, and there is
  1164. * a 1-to-1 mapping from CPU ID to NUMA node ID.
  1165. */
  1166. index = 0;
  1167. for_each_present_cpu(cpu) {
  1168. numa_cpu_lookup_table[cpu] = index;
  1169. cpumask_copy(&numa_cpumask_lookup_table[index], cpumask_of(cpu));
  1170. node_masks[index].mask = ~((1UL << 36UL) - 1UL);
  1171. node_masks[index].val = cpu << 36UL;
  1172. index++;
  1173. }
  1174. num_node_masks = index;
  1175. add_node_ranges();
  1176. for (index = 0; index < num_node_masks; index++) {
  1177. allocate_node_data(index);
  1178. node_set_online(index);
  1179. }
  1180. return 0;
  1181. }
  1182. static int __init numa_parse_sun4u(void)
  1183. {
  1184. if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  1185. unsigned long ver;
  1186. __asm__ ("rdpr %%ver, %0" : "=r" (ver));
  1187. if ((ver >> 32UL) == __JALAPENO_ID ||
  1188. (ver >> 32UL) == __SERRANO_ID)
  1189. return numa_parse_jbus();
  1190. }
  1191. return -1;
  1192. }
  1193. static int __init bootmem_init_numa(void)
  1194. {
  1195. int i, j;
  1196. int err = -1;
  1197. numadbg("bootmem_init_numa()\n");
  1198. /* Some sane defaults for numa latency values */
  1199. for (i = 0; i < MAX_NUMNODES; i++) {
  1200. for (j = 0; j < MAX_NUMNODES; j++)
  1201. numa_latency[i][j] = (i == j) ?
  1202. LOCAL_DISTANCE : REMOTE_DISTANCE;
  1203. }
  1204. if (numa_enabled) {
  1205. if (tlb_type == hypervisor)
  1206. err = numa_parse_mdesc();
  1207. else
  1208. err = numa_parse_sun4u();
  1209. }
  1210. return err;
  1211. }
  1212. #else
  1213. static int bootmem_init_numa(void)
  1214. {
  1215. return -1;
  1216. }
  1217. #endif
  1218. static void __init bootmem_init_nonnuma(void)
  1219. {
  1220. unsigned long top_of_ram = memblock_end_of_DRAM();
  1221. unsigned long total_ram = memblock_phys_mem_size();
  1222. numadbg("bootmem_init_nonnuma()\n");
  1223. printk(KERN_INFO "Top of RAM: 0x%lx, Total RAM: 0x%lx\n",
  1224. top_of_ram, total_ram);
  1225. printk(KERN_INFO "Memory hole size: %ldMB\n",
  1226. (top_of_ram - total_ram) >> 20);
  1227. init_node_masks_nonnuma();
  1228. memblock_set_node(0, (phys_addr_t)ULLONG_MAX, &memblock.memory, 0);
  1229. allocate_node_data(0);
  1230. node_set_online(0);
  1231. }
  1232. static unsigned long __init bootmem_init(unsigned long phys_base)
  1233. {
  1234. unsigned long end_pfn;
  1235. end_pfn = memblock_end_of_DRAM() >> PAGE_SHIFT;
  1236. max_pfn = max_low_pfn = end_pfn;
  1237. min_low_pfn = (phys_base >> PAGE_SHIFT);
  1238. if (bootmem_init_numa() < 0)
  1239. bootmem_init_nonnuma();
  1240. /* Dump memblock with node info. */
  1241. memblock_dump_all();
  1242. /* XXX cpu notifier XXX */
  1243. sparse_memory_present_with_active_regions(MAX_NUMNODES);
  1244. sparse_init();
  1245. return end_pfn;
  1246. }
  1247. static struct linux_prom64_registers pall[MAX_BANKS] __initdata;
  1248. static int pall_ents __initdata;
  1249. static unsigned long max_phys_bits = 40;
  1250. bool kern_addr_valid(unsigned long addr)
  1251. {
  1252. pgd_t *pgd;
  1253. pud_t *pud;
  1254. pmd_t *pmd;
  1255. pte_t *pte;
  1256. if ((long)addr < 0L) {
  1257. unsigned long pa = __pa(addr);
  1258. if ((pa >> max_phys_bits) != 0UL)
  1259. return false;
  1260. return pfn_valid(pa >> PAGE_SHIFT);
  1261. }
  1262. if (addr >= (unsigned long) KERNBASE &&
  1263. addr < (unsigned long)&_end)
  1264. return true;
  1265. pgd = pgd_offset_k(addr);
  1266. if (pgd_none(*pgd))
  1267. return 0;
  1268. pud = pud_offset(pgd, addr);
  1269. if (pud_none(*pud))
  1270. return 0;
  1271. if (pud_large(*pud))
  1272. return pfn_valid(pud_pfn(*pud));
  1273. pmd = pmd_offset(pud, addr);
  1274. if (pmd_none(*pmd))
  1275. return 0;
  1276. if (pmd_large(*pmd))
  1277. return pfn_valid(pmd_pfn(*pmd));
  1278. pte = pte_offset_kernel(pmd, addr);
  1279. if (pte_none(*pte))
  1280. return 0;
  1281. return pfn_valid(pte_pfn(*pte));
  1282. }
  1283. EXPORT_SYMBOL(kern_addr_valid);
  1284. static unsigned long __ref kernel_map_hugepud(unsigned long vstart,
  1285. unsigned long vend,
  1286. pud_t *pud)
  1287. {
  1288. const unsigned long mask16gb = (1UL << 34) - 1UL;
  1289. u64 pte_val = vstart;
  1290. /* Each PUD is 8GB */
  1291. if ((vstart & mask16gb) ||
  1292. (vend - vstart <= mask16gb)) {
  1293. pte_val ^= kern_linear_pte_xor[2];
  1294. pud_val(*pud) = pte_val | _PAGE_PUD_HUGE;
  1295. return vstart + PUD_SIZE;
  1296. }
  1297. pte_val ^= kern_linear_pte_xor[3];
  1298. pte_val |= _PAGE_PUD_HUGE;
  1299. vend = vstart + mask16gb + 1UL;
  1300. while (vstart < vend) {
  1301. pud_val(*pud) = pte_val;
  1302. pte_val += PUD_SIZE;
  1303. vstart += PUD_SIZE;
  1304. pud++;
  1305. }
  1306. return vstart;
  1307. }
  1308. static bool kernel_can_map_hugepud(unsigned long vstart, unsigned long vend,
  1309. bool guard)
  1310. {
  1311. if (guard && !(vstart & ~PUD_MASK) && (vend - vstart) >= PUD_SIZE)
  1312. return true;
  1313. return false;
  1314. }
  1315. static unsigned long __ref kernel_map_hugepmd(unsigned long vstart,
  1316. unsigned long vend,
  1317. pmd_t *pmd)
  1318. {
  1319. const unsigned long mask256mb = (1UL << 28) - 1UL;
  1320. const unsigned long mask2gb = (1UL << 31) - 1UL;
  1321. u64 pte_val = vstart;
  1322. /* Each PMD is 8MB */
  1323. if ((vstart & mask256mb) ||
  1324. (vend - vstart <= mask256mb)) {
  1325. pte_val ^= kern_linear_pte_xor[0];
  1326. pmd_val(*pmd) = pte_val | _PAGE_PMD_HUGE;
  1327. return vstart + PMD_SIZE;
  1328. }
  1329. if ((vstart & mask2gb) ||
  1330. (vend - vstart <= mask2gb)) {
  1331. pte_val ^= kern_linear_pte_xor[1];
  1332. pte_val |= _PAGE_PMD_HUGE;
  1333. vend = vstart + mask256mb + 1UL;
  1334. } else {
  1335. pte_val ^= kern_linear_pte_xor[2];
  1336. pte_val |= _PAGE_PMD_HUGE;
  1337. vend = vstart + mask2gb + 1UL;
  1338. }
  1339. while (vstart < vend) {
  1340. pmd_val(*pmd) = pte_val;
  1341. pte_val += PMD_SIZE;
  1342. vstart += PMD_SIZE;
  1343. pmd++;
  1344. }
  1345. return vstart;
  1346. }
  1347. static bool kernel_can_map_hugepmd(unsigned long vstart, unsigned long vend,
  1348. bool guard)
  1349. {
  1350. if (guard && !(vstart & ~PMD_MASK) && (vend - vstart) >= PMD_SIZE)
  1351. return true;
  1352. return false;
  1353. }
  1354. static unsigned long __ref kernel_map_range(unsigned long pstart,
  1355. unsigned long pend, pgprot_t prot,
  1356. bool use_huge)
  1357. {
  1358. unsigned long vstart = PAGE_OFFSET + pstart;
  1359. unsigned long vend = PAGE_OFFSET + pend;
  1360. unsigned long alloc_bytes = 0UL;
  1361. if ((vstart & ~PAGE_MASK) || (vend & ~PAGE_MASK)) {
  1362. prom_printf("kernel_map: Unaligned physmem[%lx:%lx]\n",
  1363. vstart, vend);
  1364. prom_halt();
  1365. }
  1366. while (vstart < vend) {
  1367. unsigned long this_end, paddr = __pa(vstart);
  1368. pgd_t *pgd = pgd_offset_k(vstart);
  1369. pud_t *pud;
  1370. pmd_t *pmd;
  1371. pte_t *pte;
  1372. if (pgd_none(*pgd)) {
  1373. pud_t *new;
  1374. new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
  1375. alloc_bytes += PAGE_SIZE;
  1376. pgd_populate(&init_mm, pgd, new);
  1377. }
  1378. pud = pud_offset(pgd, vstart);
  1379. if (pud_none(*pud)) {
  1380. pmd_t *new;
  1381. if (kernel_can_map_hugepud(vstart, vend, use_huge)) {
  1382. vstart = kernel_map_hugepud(vstart, vend, pud);
  1383. continue;
  1384. }
  1385. new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
  1386. alloc_bytes += PAGE_SIZE;
  1387. pud_populate(&init_mm, pud, new);
  1388. }
  1389. pmd = pmd_offset(pud, vstart);
  1390. if (pmd_none(*pmd)) {
  1391. pte_t *new;
  1392. if (kernel_can_map_hugepmd(vstart, vend, use_huge)) {
  1393. vstart = kernel_map_hugepmd(vstart, vend, pmd);
  1394. continue;
  1395. }
  1396. new = __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, PAGE_SIZE);
  1397. alloc_bytes += PAGE_SIZE;
  1398. pmd_populate_kernel(&init_mm, pmd, new);
  1399. }
  1400. pte = pte_offset_kernel(pmd, vstart);
  1401. this_end = (vstart + PMD_SIZE) & PMD_MASK;
  1402. if (this_end > vend)
  1403. this_end = vend;
  1404. while (vstart < this_end) {
  1405. pte_val(*pte) = (paddr | pgprot_val(prot));
  1406. vstart += PAGE_SIZE;
  1407. paddr += PAGE_SIZE;
  1408. pte++;
  1409. }
  1410. }
  1411. return alloc_bytes;
  1412. }
  1413. static void __init flush_all_kernel_tsbs(void)
  1414. {
  1415. int i;
  1416. for (i = 0; i < KERNEL_TSB_NENTRIES; i++) {
  1417. struct tsb *ent = &swapper_tsb[i];
  1418. ent->tag = (1UL << TSB_TAG_INVALID_BIT);
  1419. }
  1420. #ifndef CONFIG_DEBUG_PAGEALLOC
  1421. for (i = 0; i < KERNEL_TSB4M_NENTRIES; i++) {
  1422. struct tsb *ent = &swapper_4m_tsb[i];
  1423. ent->tag = (1UL << TSB_TAG_INVALID_BIT);
  1424. }
  1425. #endif
  1426. }
  1427. extern unsigned int kvmap_linear_patch[1];
  1428. static void __init kernel_physical_mapping_init(void)
  1429. {
  1430. unsigned long i, mem_alloced = 0UL;
  1431. bool use_huge = true;
  1432. #ifdef CONFIG_DEBUG_PAGEALLOC
  1433. use_huge = false;
  1434. #endif
  1435. for (i = 0; i < pall_ents; i++) {
  1436. unsigned long phys_start, phys_end;
  1437. phys_start = pall[i].phys_addr;
  1438. phys_end = phys_start + pall[i].reg_size;
  1439. mem_alloced += kernel_map_range(phys_start, phys_end,
  1440. PAGE_KERNEL, use_huge);
  1441. }
  1442. printk("Allocated %ld bytes for kernel page tables.\n",
  1443. mem_alloced);
  1444. kvmap_linear_patch[0] = 0x01000000; /* nop */
  1445. flushi(&kvmap_linear_patch[0]);
  1446. flush_all_kernel_tsbs();
  1447. __flush_tlb_all();
  1448. }
  1449. #ifdef CONFIG_DEBUG_PAGEALLOC
  1450. void __kernel_map_pages(struct page *page, int numpages, int enable)
  1451. {
  1452. unsigned long phys_start = page_to_pfn(page) << PAGE_SHIFT;
  1453. unsigned long phys_end = phys_start + (numpages * PAGE_SIZE);
  1454. kernel_map_range(phys_start, phys_end,
  1455. (enable ? PAGE_KERNEL : __pgprot(0)), false);
  1456. flush_tsb_kernel_range(PAGE_OFFSET + phys_start,
  1457. PAGE_OFFSET + phys_end);
  1458. /* we should perform an IPI and flush all tlbs,
  1459. * but that can deadlock->flush only current cpu.
  1460. */
  1461. __flush_tlb_kernel_range(PAGE_OFFSET + phys_start,
  1462. PAGE_OFFSET + phys_end);
  1463. }
  1464. #endif
  1465. unsigned long __init find_ecache_flush_span(unsigned long size)
  1466. {
  1467. int i;
  1468. for (i = 0; i < pavail_ents; i++) {
  1469. if (pavail[i].reg_size >= size)
  1470. return pavail[i].phys_addr;
  1471. }
  1472. return ~0UL;
  1473. }
  1474. unsigned long PAGE_OFFSET;
  1475. EXPORT_SYMBOL(PAGE_OFFSET);
  1476. unsigned long VMALLOC_END = 0x0000010000000000UL;
  1477. EXPORT_SYMBOL(VMALLOC_END);
  1478. unsigned long sparc64_va_hole_top = 0xfffff80000000000UL;
  1479. unsigned long sparc64_va_hole_bottom = 0x0000080000000000UL;
  1480. static void __init setup_page_offset(void)
  1481. {
  1482. if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  1483. /* Cheetah/Panther support a full 64-bit virtual
  1484. * address, so we can use all that our page tables
  1485. * support.
  1486. */
  1487. sparc64_va_hole_top = 0xfff0000000000000UL;
  1488. sparc64_va_hole_bottom = 0x0010000000000000UL;
  1489. max_phys_bits = 42;
  1490. } else if (tlb_type == hypervisor) {
  1491. switch (sun4v_chip_type) {
  1492. case SUN4V_CHIP_NIAGARA1:
  1493. case SUN4V_CHIP_NIAGARA2:
  1494. /* T1 and T2 support 48-bit virtual addresses. */
  1495. sparc64_va_hole_top = 0xffff800000000000UL;
  1496. sparc64_va_hole_bottom = 0x0000800000000000UL;
  1497. max_phys_bits = 39;
  1498. break;
  1499. case SUN4V_CHIP_NIAGARA3:
  1500. /* T3 supports 48-bit virtual addresses. */
  1501. sparc64_va_hole_top = 0xffff800000000000UL;
  1502. sparc64_va_hole_bottom = 0x0000800000000000UL;
  1503. max_phys_bits = 43;
  1504. break;
  1505. case SUN4V_CHIP_NIAGARA4:
  1506. case SUN4V_CHIP_NIAGARA5:
  1507. case SUN4V_CHIP_SPARC64X:
  1508. case SUN4V_CHIP_SPARC_M6:
  1509. /* T4 and later support 52-bit virtual addresses. */
  1510. sparc64_va_hole_top = 0xfff8000000000000UL;
  1511. sparc64_va_hole_bottom = 0x0008000000000000UL;
  1512. max_phys_bits = 47;
  1513. break;
  1514. case SUN4V_CHIP_SPARC_M7:
  1515. case SUN4V_CHIP_SPARC_SN:
  1516. default:
  1517. /* M7 and later support 52-bit virtual addresses. */
  1518. sparc64_va_hole_top = 0xfff8000000000000UL;
  1519. sparc64_va_hole_bottom = 0x0008000000000000UL;
  1520. max_phys_bits = 49;
  1521. break;
  1522. }
  1523. }
  1524. if (max_phys_bits > MAX_PHYS_ADDRESS_BITS) {
  1525. prom_printf("MAX_PHYS_ADDRESS_BITS is too small, need %lu\n",
  1526. max_phys_bits);
  1527. prom_halt();
  1528. }
  1529. PAGE_OFFSET = sparc64_va_hole_top;
  1530. VMALLOC_END = ((sparc64_va_hole_bottom >> 1) +
  1531. (sparc64_va_hole_bottom >> 2));
  1532. pr_info("MM: PAGE_OFFSET is 0x%016lx (max_phys_bits == %lu)\n",
  1533. PAGE_OFFSET, max_phys_bits);
  1534. pr_info("MM: VMALLOC [0x%016lx --> 0x%016lx]\n",
  1535. VMALLOC_START, VMALLOC_END);
  1536. pr_info("MM: VMEMMAP [0x%016lx --> 0x%016lx]\n",
  1537. VMEMMAP_BASE, VMEMMAP_BASE << 1);
  1538. }
  1539. static void __init tsb_phys_patch(void)
  1540. {
  1541. struct tsb_ldquad_phys_patch_entry *pquad;
  1542. struct tsb_phys_patch_entry *p;
  1543. pquad = &__tsb_ldquad_phys_patch;
  1544. while (pquad < &__tsb_ldquad_phys_patch_end) {
  1545. unsigned long addr = pquad->addr;
  1546. if (tlb_type == hypervisor)
  1547. *(unsigned int *) addr = pquad->sun4v_insn;
  1548. else
  1549. *(unsigned int *) addr = pquad->sun4u_insn;
  1550. wmb();
  1551. __asm__ __volatile__("flush %0"
  1552. : /* no outputs */
  1553. : "r" (addr));
  1554. pquad++;
  1555. }
  1556. p = &__tsb_phys_patch;
  1557. while (p < &__tsb_phys_patch_end) {
  1558. unsigned long addr = p->addr;
  1559. *(unsigned int *) addr = p->insn;
  1560. wmb();
  1561. __asm__ __volatile__("flush %0"
  1562. : /* no outputs */
  1563. : "r" (addr));
  1564. p++;
  1565. }
  1566. }
  1567. /* Don't mark as init, we give this to the Hypervisor. */
  1568. #ifndef CONFIG_DEBUG_PAGEALLOC
  1569. #define NUM_KTSB_DESCR 2
  1570. #else
  1571. #define NUM_KTSB_DESCR 1
  1572. #endif
  1573. static struct hv_tsb_descr ktsb_descr[NUM_KTSB_DESCR];
  1574. /* The swapper TSBs are loaded with a base sequence of:
  1575. *
  1576. * sethi %uhi(SYMBOL), REG1
  1577. * sethi %hi(SYMBOL), REG2
  1578. * or REG1, %ulo(SYMBOL), REG1
  1579. * or REG2, %lo(SYMBOL), REG2
  1580. * sllx REG1, 32, REG1
  1581. * or REG1, REG2, REG1
  1582. *
  1583. * When we use physical addressing for the TSB accesses, we patch the
  1584. * first four instructions in the above sequence.
  1585. */
  1586. static void patch_one_ktsb_phys(unsigned int *start, unsigned int *end, unsigned long pa)
  1587. {
  1588. unsigned long high_bits, low_bits;
  1589. high_bits = (pa >> 32) & 0xffffffff;
  1590. low_bits = (pa >> 0) & 0xffffffff;
  1591. while (start < end) {
  1592. unsigned int *ia = (unsigned int *)(unsigned long)*start;
  1593. ia[0] = (ia[0] & ~0x3fffff) | (high_bits >> 10);
  1594. __asm__ __volatile__("flush %0" : : "r" (ia));
  1595. ia[1] = (ia[1] & ~0x3fffff) | (low_bits >> 10);
  1596. __asm__ __volatile__("flush %0" : : "r" (ia + 1));
  1597. ia[2] = (ia[2] & ~0x1fff) | (high_bits & 0x3ff);
  1598. __asm__ __volatile__("flush %0" : : "r" (ia + 2));
  1599. ia[3] = (ia[3] & ~0x1fff) | (low_bits & 0x3ff);
  1600. __asm__ __volatile__("flush %0" : : "r" (ia + 3));
  1601. start++;
  1602. }
  1603. }
  1604. static void ktsb_phys_patch(void)
  1605. {
  1606. extern unsigned int __swapper_tsb_phys_patch;
  1607. extern unsigned int __swapper_tsb_phys_patch_end;
  1608. unsigned long ktsb_pa;
  1609. ktsb_pa = kern_base + ((unsigned long)&swapper_tsb[0] - KERNBASE);
  1610. patch_one_ktsb_phys(&__swapper_tsb_phys_patch,
  1611. &__swapper_tsb_phys_patch_end, ktsb_pa);
  1612. #ifndef CONFIG_DEBUG_PAGEALLOC
  1613. {
  1614. extern unsigned int __swapper_4m_tsb_phys_patch;
  1615. extern unsigned int __swapper_4m_tsb_phys_patch_end;
  1616. ktsb_pa = (kern_base +
  1617. ((unsigned long)&swapper_4m_tsb[0] - KERNBASE));
  1618. patch_one_ktsb_phys(&__swapper_4m_tsb_phys_patch,
  1619. &__swapper_4m_tsb_phys_patch_end, ktsb_pa);
  1620. }
  1621. #endif
  1622. }
  1623. static void __init sun4v_ktsb_init(void)
  1624. {
  1625. unsigned long ktsb_pa;
  1626. /* First KTSB for PAGE_SIZE mappings. */
  1627. ktsb_pa = kern_base + ((unsigned long)&swapper_tsb[0] - KERNBASE);
  1628. switch (PAGE_SIZE) {
  1629. case 8 * 1024:
  1630. default:
  1631. ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_8K;
  1632. ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_8K;
  1633. break;
  1634. case 64 * 1024:
  1635. ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_64K;
  1636. ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_64K;
  1637. break;
  1638. case 512 * 1024:
  1639. ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_512K;
  1640. ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_512K;
  1641. break;
  1642. case 4 * 1024 * 1024:
  1643. ktsb_descr[0].pgsz_idx = HV_PGSZ_IDX_4MB;
  1644. ktsb_descr[0].pgsz_mask = HV_PGSZ_MASK_4MB;
  1645. break;
  1646. }
  1647. ktsb_descr[0].assoc = 1;
  1648. ktsb_descr[0].num_ttes = KERNEL_TSB_NENTRIES;
  1649. ktsb_descr[0].ctx_idx = 0;
  1650. ktsb_descr[0].tsb_base = ktsb_pa;
  1651. ktsb_descr[0].resv = 0;
  1652. #ifndef CONFIG_DEBUG_PAGEALLOC
  1653. /* Second KTSB for 4MB/256MB/2GB/16GB mappings. */
  1654. ktsb_pa = (kern_base +
  1655. ((unsigned long)&swapper_4m_tsb[0] - KERNBASE));
  1656. ktsb_descr[1].pgsz_idx = HV_PGSZ_IDX_4MB;
  1657. ktsb_descr[1].pgsz_mask = ((HV_PGSZ_MASK_4MB |
  1658. HV_PGSZ_MASK_256MB |
  1659. HV_PGSZ_MASK_2GB |
  1660. HV_PGSZ_MASK_16GB) &
  1661. cpu_pgsz_mask);
  1662. ktsb_descr[1].assoc = 1;
  1663. ktsb_descr[1].num_ttes = KERNEL_TSB4M_NENTRIES;
  1664. ktsb_descr[1].ctx_idx = 0;
  1665. ktsb_descr[1].tsb_base = ktsb_pa;
  1666. ktsb_descr[1].resv = 0;
  1667. #endif
  1668. }
  1669. void sun4v_ktsb_register(void)
  1670. {
  1671. unsigned long pa, ret;
  1672. pa = kern_base + ((unsigned long)&ktsb_descr[0] - KERNBASE);
  1673. ret = sun4v_mmu_tsb_ctx0(NUM_KTSB_DESCR, pa);
  1674. if (ret != 0) {
  1675. prom_printf("hypervisor_mmu_tsb_ctx0[%lx]: "
  1676. "errors with %lx\n", pa, ret);
  1677. prom_halt();
  1678. }
  1679. }
  1680. static void __init sun4u_linear_pte_xor_finalize(void)
  1681. {
  1682. #ifndef CONFIG_DEBUG_PAGEALLOC
  1683. /* This is where we would add Panther support for
  1684. * 32MB and 256MB pages.
  1685. */
  1686. #endif
  1687. }
  1688. static void __init sun4v_linear_pte_xor_finalize(void)
  1689. {
  1690. unsigned long pagecv_flag;
  1691. /* Bit 9 of TTE is no longer CV bit on M7 processor and it instead
  1692. * enables MCD error. Do not set bit 9 on M7 processor.
  1693. */
  1694. switch (sun4v_chip_type) {
  1695. case SUN4V_CHIP_SPARC_M7:
  1696. case SUN4V_CHIP_SPARC_SN:
  1697. pagecv_flag = 0x00;
  1698. break;
  1699. default:
  1700. pagecv_flag = _PAGE_CV_4V;
  1701. break;
  1702. }
  1703. #ifndef CONFIG_DEBUG_PAGEALLOC
  1704. if (cpu_pgsz_mask & HV_PGSZ_MASK_256MB) {
  1705. kern_linear_pte_xor[1] = (_PAGE_VALID | _PAGE_SZ256MB_4V) ^
  1706. PAGE_OFFSET;
  1707. kern_linear_pte_xor[1] |= (_PAGE_CP_4V | pagecv_flag |
  1708. _PAGE_P_4V | _PAGE_W_4V);
  1709. } else {
  1710. kern_linear_pte_xor[1] = kern_linear_pte_xor[0];
  1711. }
  1712. if (cpu_pgsz_mask & HV_PGSZ_MASK_2GB) {
  1713. kern_linear_pte_xor[2] = (_PAGE_VALID | _PAGE_SZ2GB_4V) ^
  1714. PAGE_OFFSET;
  1715. kern_linear_pte_xor[2] |= (_PAGE_CP_4V | pagecv_flag |
  1716. _PAGE_P_4V | _PAGE_W_4V);
  1717. } else {
  1718. kern_linear_pte_xor[2] = kern_linear_pte_xor[1];
  1719. }
  1720. if (cpu_pgsz_mask & HV_PGSZ_MASK_16GB) {
  1721. kern_linear_pte_xor[3] = (_PAGE_VALID | _PAGE_SZ16GB_4V) ^
  1722. PAGE_OFFSET;
  1723. kern_linear_pte_xor[3] |= (_PAGE_CP_4V | pagecv_flag |
  1724. _PAGE_P_4V | _PAGE_W_4V);
  1725. } else {
  1726. kern_linear_pte_xor[3] = kern_linear_pte_xor[2];
  1727. }
  1728. #endif
  1729. }
  1730. /* paging_init() sets up the page tables */
  1731. static unsigned long last_valid_pfn;
  1732. static void sun4u_pgprot_init(void);
  1733. static void sun4v_pgprot_init(void);
  1734. static phys_addr_t __init available_memory(void)
  1735. {
  1736. phys_addr_t available = 0ULL;
  1737. phys_addr_t pa_start, pa_end;
  1738. u64 i;
  1739. for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, &pa_start,
  1740. &pa_end, NULL)
  1741. available = available + (pa_end - pa_start);
  1742. return available;
  1743. }
  1744. #define _PAGE_CACHE_4U (_PAGE_CP_4U | _PAGE_CV_4U)
  1745. #define _PAGE_CACHE_4V (_PAGE_CP_4V | _PAGE_CV_4V)
  1746. #define __DIRTY_BITS_4U (_PAGE_MODIFIED_4U | _PAGE_WRITE_4U | _PAGE_W_4U)
  1747. #define __DIRTY_BITS_4V (_PAGE_MODIFIED_4V | _PAGE_WRITE_4V | _PAGE_W_4V)
  1748. #define __ACCESS_BITS_4U (_PAGE_ACCESSED_4U | _PAGE_READ_4U | _PAGE_R)
  1749. #define __ACCESS_BITS_4V (_PAGE_ACCESSED_4V | _PAGE_READ_4V | _PAGE_R)
  1750. /* We need to exclude reserved regions. This exclusion will include
  1751. * vmlinux and initrd. To be more precise the initrd size could be used to
  1752. * compute a new lower limit because it is freed later during initialization.
  1753. */
  1754. static void __init reduce_memory(phys_addr_t limit_ram)
  1755. {
  1756. phys_addr_t avail_ram = available_memory();
  1757. phys_addr_t pa_start, pa_end;
  1758. u64 i;
  1759. if (limit_ram >= avail_ram)
  1760. return;
  1761. for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, &pa_start,
  1762. &pa_end, NULL) {
  1763. phys_addr_t region_size = pa_end - pa_start;
  1764. phys_addr_t clip_start = pa_start;
  1765. avail_ram = avail_ram - region_size;
  1766. /* Are we consuming too much? */
  1767. if (avail_ram < limit_ram) {
  1768. phys_addr_t give_back = limit_ram - avail_ram;
  1769. region_size = region_size - give_back;
  1770. clip_start = clip_start + give_back;
  1771. }
  1772. memblock_remove(clip_start, region_size);
  1773. if (avail_ram <= limit_ram)
  1774. break;
  1775. i = 0UL;
  1776. }
  1777. }
  1778. void __init paging_init(void)
  1779. {
  1780. unsigned long end_pfn, shift, phys_base;
  1781. unsigned long real_end, i;
  1782. setup_page_offset();
  1783. /* These build time checkes make sure that the dcache_dirty_cpu()
  1784. * page->flags usage will work.
  1785. *
  1786. * When a page gets marked as dcache-dirty, we store the
  1787. * cpu number starting at bit 32 in the page->flags. Also,
  1788. * functions like clear_dcache_dirty_cpu use the cpu mask
  1789. * in 13-bit signed-immediate instruction fields.
  1790. */
  1791. /*
  1792. * Page flags must not reach into upper 32 bits that are used
  1793. * for the cpu number
  1794. */
  1795. BUILD_BUG_ON(NR_PAGEFLAGS > 32);
  1796. /*
  1797. * The bit fields placed in the high range must not reach below
  1798. * the 32 bit boundary. Otherwise we cannot place the cpu field
  1799. * at the 32 bit boundary.
  1800. */
  1801. BUILD_BUG_ON(SECTIONS_WIDTH + NODES_WIDTH + ZONES_WIDTH +
  1802. ilog2(roundup_pow_of_two(NR_CPUS)) > 32);
  1803. BUILD_BUG_ON(NR_CPUS > 4096);
  1804. kern_base = (prom_boot_mapping_phys_low >> ILOG2_4MB) << ILOG2_4MB;
  1805. kern_size = (unsigned long)&_end - (unsigned long)KERNBASE;
  1806. /* Invalidate both kernel TSBs. */
  1807. memset(swapper_tsb, 0x40, sizeof(swapper_tsb));
  1808. #ifndef CONFIG_DEBUG_PAGEALLOC
  1809. memset(swapper_4m_tsb, 0x40, sizeof(swapper_4m_tsb));
  1810. #endif
  1811. /* TTE.cv bit on sparc v9 occupies the same position as TTE.mcde
  1812. * bit on M7 processor. This is a conflicting usage of the same
  1813. * bit. Enabling TTE.cv on M7 would turn on Memory Corruption
  1814. * Detection error on all pages and this will lead to problems
  1815. * later. Kernel does not run with MCD enabled and hence rest
  1816. * of the required steps to fully configure memory corruption
  1817. * detection are not taken. We need to ensure TTE.mcde is not
  1818. * set on M7 processor. Compute the value of cacheability
  1819. * flag for use later taking this into consideration.
  1820. */
  1821. switch (sun4v_chip_type) {
  1822. case SUN4V_CHIP_SPARC_M7:
  1823. case SUN4V_CHIP_SPARC_SN:
  1824. page_cache4v_flag = _PAGE_CP_4V;
  1825. break;
  1826. default:
  1827. page_cache4v_flag = _PAGE_CACHE_4V;
  1828. break;
  1829. }
  1830. if (tlb_type == hypervisor)
  1831. sun4v_pgprot_init();
  1832. else
  1833. sun4u_pgprot_init();
  1834. if (tlb_type == cheetah_plus ||
  1835. tlb_type == hypervisor) {
  1836. tsb_phys_patch();
  1837. ktsb_phys_patch();
  1838. }
  1839. if (tlb_type == hypervisor)
  1840. sun4v_patch_tlb_handlers();
  1841. /* Find available physical memory...
  1842. *
  1843. * Read it twice in order to work around a bug in openfirmware.
  1844. * The call to grab this table itself can cause openfirmware to
  1845. * allocate memory, which in turn can take away some space from
  1846. * the list of available memory. Reading it twice makes sure
  1847. * we really do get the final value.
  1848. */
  1849. read_obp_translations();
  1850. read_obp_memory("reg", &pall[0], &pall_ents);
  1851. read_obp_memory("available", &pavail[0], &pavail_ents);
  1852. read_obp_memory("available", &pavail[0], &pavail_ents);
  1853. phys_base = 0xffffffffffffffffUL;
  1854. for (i = 0; i < pavail_ents; i++) {
  1855. phys_base = min(phys_base, pavail[i].phys_addr);
  1856. memblock_add(pavail[i].phys_addr, pavail[i].reg_size);
  1857. }
  1858. memblock_reserve(kern_base, kern_size);
  1859. find_ramdisk(phys_base);
  1860. if (cmdline_memory_size)
  1861. reduce_memory(cmdline_memory_size);
  1862. memblock_allow_resize();
  1863. memblock_dump_all();
  1864. set_bit(0, mmu_context_bmap);
  1865. shift = kern_base + PAGE_OFFSET - ((unsigned long)KERNBASE);
  1866. real_end = (unsigned long)_end;
  1867. num_kernel_image_mappings = DIV_ROUND_UP(real_end - KERNBASE, 1 << ILOG2_4MB);
  1868. printk("Kernel: Using %d locked TLB entries for main kernel image.\n",
  1869. num_kernel_image_mappings);
  1870. /* Set kernel pgd to upper alias so physical page computations
  1871. * work.
  1872. */
  1873. init_mm.pgd += ((shift) / (sizeof(pgd_t)));
  1874. memset(swapper_pg_dir, 0, sizeof(swapper_pg_dir));
  1875. inherit_prom_mappings();
  1876. /* Ok, we can use our TLB miss and window trap handlers safely. */
  1877. setup_tba();
  1878. __flush_tlb_all();
  1879. prom_build_devicetree();
  1880. of_populate_present_mask();
  1881. #ifndef CONFIG_SMP
  1882. of_fill_in_cpu_data();
  1883. #endif
  1884. if (tlb_type == hypervisor) {
  1885. sun4v_mdesc_init();
  1886. mdesc_populate_present_mask(cpu_all_mask);
  1887. #ifndef CONFIG_SMP
  1888. mdesc_fill_in_cpu_data(cpu_all_mask);
  1889. #endif
  1890. mdesc_get_page_sizes(cpu_all_mask, &cpu_pgsz_mask);
  1891. sun4v_linear_pte_xor_finalize();
  1892. sun4v_ktsb_init();
  1893. sun4v_ktsb_register();
  1894. } else {
  1895. unsigned long impl, ver;
  1896. cpu_pgsz_mask = (HV_PGSZ_MASK_8K | HV_PGSZ_MASK_64K |
  1897. HV_PGSZ_MASK_512K | HV_PGSZ_MASK_4MB);
  1898. __asm__ __volatile__("rdpr %%ver, %0" : "=r" (ver));
  1899. impl = ((ver >> 32) & 0xffff);
  1900. if (impl == PANTHER_IMPL)
  1901. cpu_pgsz_mask |= (HV_PGSZ_MASK_32MB |
  1902. HV_PGSZ_MASK_256MB);
  1903. sun4u_linear_pte_xor_finalize();
  1904. }
  1905. /* Flush the TLBs and the 4M TSB so that the updated linear
  1906. * pte XOR settings are realized for all mappings.
  1907. */
  1908. __flush_tlb_all();
  1909. #ifndef CONFIG_DEBUG_PAGEALLOC
  1910. memset(swapper_4m_tsb, 0x40, sizeof(swapper_4m_tsb));
  1911. #endif
  1912. __flush_tlb_all();
  1913. /* Setup bootmem... */
  1914. last_valid_pfn = end_pfn = bootmem_init(phys_base);
  1915. kernel_physical_mapping_init();
  1916. {
  1917. unsigned long max_zone_pfns[MAX_NR_ZONES];
  1918. memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
  1919. max_zone_pfns[ZONE_NORMAL] = end_pfn;
  1920. free_area_init_nodes(max_zone_pfns);
  1921. }
  1922. printk("Booting Linux...\n");
  1923. }
  1924. int page_in_phys_avail(unsigned long paddr)
  1925. {
  1926. int i;
  1927. paddr &= PAGE_MASK;
  1928. for (i = 0; i < pavail_ents; i++) {
  1929. unsigned long start, end;
  1930. start = pavail[i].phys_addr;
  1931. end = start + pavail[i].reg_size;
  1932. if (paddr >= start && paddr < end)
  1933. return 1;
  1934. }
  1935. if (paddr >= kern_base && paddr < (kern_base + kern_size))
  1936. return 1;
  1937. #ifdef CONFIG_BLK_DEV_INITRD
  1938. if (paddr >= __pa(initrd_start) &&
  1939. paddr < __pa(PAGE_ALIGN(initrd_end)))
  1940. return 1;
  1941. #endif
  1942. return 0;
  1943. }
  1944. static void __init register_page_bootmem_info(void)
  1945. {
  1946. #ifdef CONFIG_NEED_MULTIPLE_NODES
  1947. int i;
  1948. for_each_online_node(i)
  1949. if (NODE_DATA(i)->node_spanned_pages)
  1950. register_page_bootmem_info_node(NODE_DATA(i));
  1951. #endif
  1952. }
  1953. void __init mem_init(void)
  1954. {
  1955. high_memory = __va(last_valid_pfn << PAGE_SHIFT);
  1956. register_page_bootmem_info();
  1957. free_all_bootmem();
  1958. /*
  1959. * Set up the zero page, mark it reserved, so that page count
  1960. * is not manipulated when freeing the page from user ptes.
  1961. */
  1962. mem_map_zero = alloc_pages(GFP_KERNEL|__GFP_ZERO, 0);
  1963. if (mem_map_zero == NULL) {
  1964. prom_printf("paging_init: Cannot alloc zero page.\n");
  1965. prom_halt();
  1966. }
  1967. mark_page_reserved(mem_map_zero);
  1968. mem_init_print_info(NULL);
  1969. if (tlb_type == cheetah || tlb_type == cheetah_plus)
  1970. cheetah_ecache_flush_init();
  1971. }
  1972. void free_initmem(void)
  1973. {
  1974. unsigned long addr, initend;
  1975. int do_free = 1;
  1976. /* If the physical memory maps were trimmed by kernel command
  1977. * line options, don't even try freeing this initmem stuff up.
  1978. * The kernel image could have been in the trimmed out region
  1979. * and if so the freeing below will free invalid page structs.
  1980. */
  1981. if (cmdline_memory_size)
  1982. do_free = 0;
  1983. /*
  1984. * The init section is aligned to 8k in vmlinux.lds. Page align for >8k pagesizes.
  1985. */
  1986. addr = PAGE_ALIGN((unsigned long)(__init_begin));
  1987. initend = (unsigned long)(__init_end) & PAGE_MASK;
  1988. for (; addr < initend; addr += PAGE_SIZE) {
  1989. unsigned long page;
  1990. page = (addr +
  1991. ((unsigned long) __va(kern_base)) -
  1992. ((unsigned long) KERNBASE));
  1993. memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
  1994. if (do_free)
  1995. free_reserved_page(virt_to_page(page));
  1996. }
  1997. }
  1998. #ifdef CONFIG_BLK_DEV_INITRD
  1999. void free_initrd_mem(unsigned long start, unsigned long end)
  2000. {
  2001. free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM,
  2002. "initrd");
  2003. }
  2004. #endif
  2005. pgprot_t PAGE_KERNEL __read_mostly;
  2006. EXPORT_SYMBOL(PAGE_KERNEL);
  2007. pgprot_t PAGE_KERNEL_LOCKED __read_mostly;
  2008. pgprot_t PAGE_COPY __read_mostly;
  2009. pgprot_t PAGE_SHARED __read_mostly;
  2010. EXPORT_SYMBOL(PAGE_SHARED);
  2011. unsigned long pg_iobits __read_mostly;
  2012. unsigned long _PAGE_IE __read_mostly;
  2013. EXPORT_SYMBOL(_PAGE_IE);
  2014. unsigned long _PAGE_E __read_mostly;
  2015. EXPORT_SYMBOL(_PAGE_E);
  2016. unsigned long _PAGE_CACHE __read_mostly;
  2017. EXPORT_SYMBOL(_PAGE_CACHE);
  2018. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  2019. int __meminit vmemmap_populate(unsigned long vstart, unsigned long vend,
  2020. int node)
  2021. {
  2022. unsigned long pte_base;
  2023. pte_base = (_PAGE_VALID | _PAGE_SZ4MB_4U |
  2024. _PAGE_CP_4U | _PAGE_CV_4U |
  2025. _PAGE_P_4U | _PAGE_W_4U);
  2026. if (tlb_type == hypervisor)
  2027. pte_base = (_PAGE_VALID | _PAGE_SZ4MB_4V |
  2028. page_cache4v_flag | _PAGE_P_4V | _PAGE_W_4V);
  2029. pte_base |= _PAGE_PMD_HUGE;
  2030. vstart = vstart & PMD_MASK;
  2031. vend = ALIGN(vend, PMD_SIZE);
  2032. for (; vstart < vend; vstart += PMD_SIZE) {
  2033. pgd_t *pgd = pgd_offset_k(vstart);
  2034. unsigned long pte;
  2035. pud_t *pud;
  2036. pmd_t *pmd;
  2037. if (pgd_none(*pgd)) {
  2038. pud_t *new = vmemmap_alloc_block(PAGE_SIZE, node);
  2039. if (!new)
  2040. return -ENOMEM;
  2041. pgd_populate(&init_mm, pgd, new);
  2042. }
  2043. pud = pud_offset(pgd, vstart);
  2044. if (pud_none(*pud)) {
  2045. pmd_t *new = vmemmap_alloc_block(PAGE_SIZE, node);
  2046. if (!new)
  2047. return -ENOMEM;
  2048. pud_populate(&init_mm, pud, new);
  2049. }
  2050. pmd = pmd_offset(pud, vstart);
  2051. pte = pmd_val(*pmd);
  2052. if (!(pte & _PAGE_VALID)) {
  2053. void *block = vmemmap_alloc_block(PMD_SIZE, node);
  2054. if (!block)
  2055. return -ENOMEM;
  2056. pmd_val(*pmd) = pte_base | __pa(block);
  2057. }
  2058. }
  2059. return 0;
  2060. }
  2061. void vmemmap_free(unsigned long start, unsigned long end)
  2062. {
  2063. }
  2064. #endif /* CONFIG_SPARSEMEM_VMEMMAP */
  2065. static void prot_init_common(unsigned long page_none,
  2066. unsigned long page_shared,
  2067. unsigned long page_copy,
  2068. unsigned long page_readonly,
  2069. unsigned long page_exec_bit)
  2070. {
  2071. PAGE_COPY = __pgprot(page_copy);
  2072. PAGE_SHARED = __pgprot(page_shared);
  2073. protection_map[0x0] = __pgprot(page_none);
  2074. protection_map[0x1] = __pgprot(page_readonly & ~page_exec_bit);
  2075. protection_map[0x2] = __pgprot(page_copy & ~page_exec_bit);
  2076. protection_map[0x3] = __pgprot(page_copy & ~page_exec_bit);
  2077. protection_map[0x4] = __pgprot(page_readonly);
  2078. protection_map[0x5] = __pgprot(page_readonly);
  2079. protection_map[0x6] = __pgprot(page_copy);
  2080. protection_map[0x7] = __pgprot(page_copy);
  2081. protection_map[0x8] = __pgprot(page_none);
  2082. protection_map[0x9] = __pgprot(page_readonly & ~page_exec_bit);
  2083. protection_map[0xa] = __pgprot(page_shared & ~page_exec_bit);
  2084. protection_map[0xb] = __pgprot(page_shared & ~page_exec_bit);
  2085. protection_map[0xc] = __pgprot(page_readonly);
  2086. protection_map[0xd] = __pgprot(page_readonly);
  2087. protection_map[0xe] = __pgprot(page_shared);
  2088. protection_map[0xf] = __pgprot(page_shared);
  2089. }
  2090. static void __init sun4u_pgprot_init(void)
  2091. {
  2092. unsigned long page_none, page_shared, page_copy, page_readonly;
  2093. unsigned long page_exec_bit;
  2094. int i;
  2095. PAGE_KERNEL = __pgprot (_PAGE_PRESENT_4U | _PAGE_VALID |
  2096. _PAGE_CACHE_4U | _PAGE_P_4U |
  2097. __ACCESS_BITS_4U | __DIRTY_BITS_4U |
  2098. _PAGE_EXEC_4U);
  2099. PAGE_KERNEL_LOCKED = __pgprot (_PAGE_PRESENT_4U | _PAGE_VALID |
  2100. _PAGE_CACHE_4U | _PAGE_P_4U |
  2101. __ACCESS_BITS_4U | __DIRTY_BITS_4U |
  2102. _PAGE_EXEC_4U | _PAGE_L_4U);
  2103. _PAGE_IE = _PAGE_IE_4U;
  2104. _PAGE_E = _PAGE_E_4U;
  2105. _PAGE_CACHE = _PAGE_CACHE_4U;
  2106. pg_iobits = (_PAGE_VALID | _PAGE_PRESENT_4U | __DIRTY_BITS_4U |
  2107. __ACCESS_BITS_4U | _PAGE_E_4U);
  2108. #ifdef CONFIG_DEBUG_PAGEALLOC
  2109. kern_linear_pte_xor[0] = _PAGE_VALID ^ PAGE_OFFSET;
  2110. #else
  2111. kern_linear_pte_xor[0] = (_PAGE_VALID | _PAGE_SZ4MB_4U) ^
  2112. PAGE_OFFSET;
  2113. #endif
  2114. kern_linear_pte_xor[0] |= (_PAGE_CP_4U | _PAGE_CV_4U |
  2115. _PAGE_P_4U | _PAGE_W_4U);
  2116. for (i = 1; i < 4; i++)
  2117. kern_linear_pte_xor[i] = kern_linear_pte_xor[0];
  2118. _PAGE_ALL_SZ_BITS = (_PAGE_SZ4MB_4U | _PAGE_SZ512K_4U |
  2119. _PAGE_SZ64K_4U | _PAGE_SZ8K_4U |
  2120. _PAGE_SZ32MB_4U | _PAGE_SZ256MB_4U);
  2121. page_none = _PAGE_PRESENT_4U | _PAGE_ACCESSED_4U | _PAGE_CACHE_4U;
  2122. page_shared = (_PAGE_VALID | _PAGE_PRESENT_4U | _PAGE_CACHE_4U |
  2123. __ACCESS_BITS_4U | _PAGE_WRITE_4U | _PAGE_EXEC_4U);
  2124. page_copy = (_PAGE_VALID | _PAGE_PRESENT_4U | _PAGE_CACHE_4U |
  2125. __ACCESS_BITS_4U | _PAGE_EXEC_4U);
  2126. page_readonly = (_PAGE_VALID | _PAGE_PRESENT_4U | _PAGE_CACHE_4U |
  2127. __ACCESS_BITS_4U | _PAGE_EXEC_4U);
  2128. page_exec_bit = _PAGE_EXEC_4U;
  2129. prot_init_common(page_none, page_shared, page_copy, page_readonly,
  2130. page_exec_bit);
  2131. }
  2132. static void __init sun4v_pgprot_init(void)
  2133. {
  2134. unsigned long page_none, page_shared, page_copy, page_readonly;
  2135. unsigned long page_exec_bit;
  2136. int i;
  2137. PAGE_KERNEL = __pgprot (_PAGE_PRESENT_4V | _PAGE_VALID |
  2138. page_cache4v_flag | _PAGE_P_4V |
  2139. __ACCESS_BITS_4V | __DIRTY_BITS_4V |
  2140. _PAGE_EXEC_4V);
  2141. PAGE_KERNEL_LOCKED = PAGE_KERNEL;
  2142. _PAGE_IE = _PAGE_IE_4V;
  2143. _PAGE_E = _PAGE_E_4V;
  2144. _PAGE_CACHE = page_cache4v_flag;
  2145. #ifdef CONFIG_DEBUG_PAGEALLOC
  2146. kern_linear_pte_xor[0] = _PAGE_VALID ^ PAGE_OFFSET;
  2147. #else
  2148. kern_linear_pte_xor[0] = (_PAGE_VALID | _PAGE_SZ4MB_4V) ^
  2149. PAGE_OFFSET;
  2150. #endif
  2151. kern_linear_pte_xor[0] |= (page_cache4v_flag | _PAGE_P_4V |
  2152. _PAGE_W_4V);
  2153. for (i = 1; i < 4; i++)
  2154. kern_linear_pte_xor[i] = kern_linear_pte_xor[0];
  2155. pg_iobits = (_PAGE_VALID | _PAGE_PRESENT_4V | __DIRTY_BITS_4V |
  2156. __ACCESS_BITS_4V | _PAGE_E_4V);
  2157. _PAGE_ALL_SZ_BITS = (_PAGE_SZ16GB_4V | _PAGE_SZ2GB_4V |
  2158. _PAGE_SZ256MB_4V | _PAGE_SZ32MB_4V |
  2159. _PAGE_SZ4MB_4V | _PAGE_SZ512K_4V |
  2160. _PAGE_SZ64K_4V | _PAGE_SZ8K_4V);
  2161. page_none = _PAGE_PRESENT_4V | _PAGE_ACCESSED_4V | page_cache4v_flag;
  2162. page_shared = (_PAGE_VALID | _PAGE_PRESENT_4V | page_cache4v_flag |
  2163. __ACCESS_BITS_4V | _PAGE_WRITE_4V | _PAGE_EXEC_4V);
  2164. page_copy = (_PAGE_VALID | _PAGE_PRESENT_4V | page_cache4v_flag |
  2165. __ACCESS_BITS_4V | _PAGE_EXEC_4V);
  2166. page_readonly = (_PAGE_VALID | _PAGE_PRESENT_4V | page_cache4v_flag |
  2167. __ACCESS_BITS_4V | _PAGE_EXEC_4V);
  2168. page_exec_bit = _PAGE_EXEC_4V;
  2169. prot_init_common(page_none, page_shared, page_copy, page_readonly,
  2170. page_exec_bit);
  2171. }
  2172. unsigned long pte_sz_bits(unsigned long sz)
  2173. {
  2174. if (tlb_type == hypervisor) {
  2175. switch (sz) {
  2176. case 8 * 1024:
  2177. default:
  2178. return _PAGE_SZ8K_4V;
  2179. case 64 * 1024:
  2180. return _PAGE_SZ64K_4V;
  2181. case 512 * 1024:
  2182. return _PAGE_SZ512K_4V;
  2183. case 4 * 1024 * 1024:
  2184. return _PAGE_SZ4MB_4V;
  2185. }
  2186. } else {
  2187. switch (sz) {
  2188. case 8 * 1024:
  2189. default:
  2190. return _PAGE_SZ8K_4U;
  2191. case 64 * 1024:
  2192. return _PAGE_SZ64K_4U;
  2193. case 512 * 1024:
  2194. return _PAGE_SZ512K_4U;
  2195. case 4 * 1024 * 1024:
  2196. return _PAGE_SZ4MB_4U;
  2197. }
  2198. }
  2199. }
  2200. pte_t mk_pte_io(unsigned long page, pgprot_t prot, int space, unsigned long page_size)
  2201. {
  2202. pte_t pte;
  2203. pte_val(pte) = page | pgprot_val(pgprot_noncached(prot));
  2204. pte_val(pte) |= (((unsigned long)space) << 32);
  2205. pte_val(pte) |= pte_sz_bits(page_size);
  2206. return pte;
  2207. }
  2208. static unsigned long kern_large_tte(unsigned long paddr)
  2209. {
  2210. unsigned long val;
  2211. val = (_PAGE_VALID | _PAGE_SZ4MB_4U |
  2212. _PAGE_CP_4U | _PAGE_CV_4U | _PAGE_P_4U |
  2213. _PAGE_EXEC_4U | _PAGE_L_4U | _PAGE_W_4U);
  2214. if (tlb_type == hypervisor)
  2215. val = (_PAGE_VALID | _PAGE_SZ4MB_4V |
  2216. page_cache4v_flag | _PAGE_P_4V |
  2217. _PAGE_EXEC_4V | _PAGE_W_4V);
  2218. return val | paddr;
  2219. }
  2220. /* If not locked, zap it. */
  2221. void __flush_tlb_all(void)
  2222. {
  2223. unsigned long pstate;
  2224. int i;
  2225. __asm__ __volatile__("flushw\n\t"
  2226. "rdpr %%pstate, %0\n\t"
  2227. "wrpr %0, %1, %%pstate"
  2228. : "=r" (pstate)
  2229. : "i" (PSTATE_IE));
  2230. if (tlb_type == hypervisor) {
  2231. sun4v_mmu_demap_all();
  2232. } else if (tlb_type == spitfire) {
  2233. for (i = 0; i < 64; i++) {
  2234. /* Spitfire Errata #32 workaround */
  2235. /* NOTE: Always runs on spitfire, so no
  2236. * cheetah+ page size encodings.
  2237. */
  2238. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  2239. "flush %%g6"
  2240. : /* No outputs */
  2241. : "r" (0),
  2242. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  2243. if (!(spitfire_get_dtlb_data(i) & _PAGE_L_4U)) {
  2244. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  2245. "membar #Sync"
  2246. : /* no outputs */
  2247. : "r" (TLB_TAG_ACCESS), "i" (ASI_DMMU));
  2248. spitfire_put_dtlb_data(i, 0x0UL);
  2249. }
  2250. /* Spitfire Errata #32 workaround */
  2251. /* NOTE: Always runs on spitfire, so no
  2252. * cheetah+ page size encodings.
  2253. */
  2254. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  2255. "flush %%g6"
  2256. : /* No outputs */
  2257. : "r" (0),
  2258. "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
  2259. if (!(spitfire_get_itlb_data(i) & _PAGE_L_4U)) {
  2260. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  2261. "membar #Sync"
  2262. : /* no outputs */
  2263. : "r" (TLB_TAG_ACCESS), "i" (ASI_IMMU));
  2264. spitfire_put_itlb_data(i, 0x0UL);
  2265. }
  2266. }
  2267. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  2268. cheetah_flush_dtlb_all();
  2269. cheetah_flush_itlb_all();
  2270. }
  2271. __asm__ __volatile__("wrpr %0, 0, %%pstate"
  2272. : : "r" (pstate));
  2273. }
  2274. pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  2275. unsigned long address)
  2276. {
  2277. struct page *page = alloc_page(GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO);
  2278. pte_t *pte = NULL;
  2279. if (page)
  2280. pte = (pte_t *) page_address(page);
  2281. return pte;
  2282. }
  2283. pgtable_t pte_alloc_one(struct mm_struct *mm,
  2284. unsigned long address)
  2285. {
  2286. struct page *page = alloc_page(GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO);
  2287. if (!page)
  2288. return NULL;
  2289. if (!pgtable_page_ctor(page)) {
  2290. free_hot_cold_page(page, 0);
  2291. return NULL;
  2292. }
  2293. return (pte_t *) page_address(page);
  2294. }
  2295. void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  2296. {
  2297. free_page((unsigned long)pte);
  2298. }
  2299. static void __pte_free(pgtable_t pte)
  2300. {
  2301. struct page *page = virt_to_page(pte);
  2302. pgtable_page_dtor(page);
  2303. __free_page(page);
  2304. }
  2305. void pte_free(struct mm_struct *mm, pgtable_t pte)
  2306. {
  2307. __pte_free(pte);
  2308. }
  2309. void pgtable_free(void *table, bool is_page)
  2310. {
  2311. if (is_page)
  2312. __pte_free(table);
  2313. else
  2314. kmem_cache_free(pgtable_cache, table);
  2315. }
  2316. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  2317. void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr,
  2318. pmd_t *pmd)
  2319. {
  2320. unsigned long pte, flags;
  2321. struct mm_struct *mm;
  2322. pmd_t entry = *pmd;
  2323. if (!pmd_large(entry) || !pmd_young(entry))
  2324. return;
  2325. pte = pmd_val(entry);
  2326. /* Don't insert a non-valid PMD into the TSB, we'll deadlock. */
  2327. if (!(pte & _PAGE_VALID))
  2328. return;
  2329. /* We are fabricating 8MB pages using 4MB real hw pages. */
  2330. pte |= (addr & (1UL << REAL_HPAGE_SHIFT));
  2331. mm = vma->vm_mm;
  2332. spin_lock_irqsave(&mm->context.lock, flags);
  2333. if (mm->context.tsb_block[MM_TSB_HUGE].tsb != NULL)
  2334. __update_mmu_tsb_insert(mm, MM_TSB_HUGE, REAL_HPAGE_SHIFT,
  2335. addr, pte);
  2336. spin_unlock_irqrestore(&mm->context.lock, flags);
  2337. }
  2338. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  2339. #if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE)
  2340. static void context_reload(void *__data)
  2341. {
  2342. struct mm_struct *mm = __data;
  2343. if (mm == current->mm)
  2344. load_secondary_context(mm);
  2345. }
  2346. void hugetlb_setup(struct pt_regs *regs)
  2347. {
  2348. struct mm_struct *mm = current->mm;
  2349. struct tsb_config *tp;
  2350. if (faulthandler_disabled() || !mm) {
  2351. const struct exception_table_entry *entry;
  2352. entry = search_exception_tables(regs->tpc);
  2353. if (entry) {
  2354. regs->tpc = entry->fixup;
  2355. regs->tnpc = regs->tpc + 4;
  2356. return;
  2357. }
  2358. pr_alert("Unexpected HugeTLB setup in atomic context.\n");
  2359. die_if_kernel("HugeTSB in atomic", regs);
  2360. }
  2361. tp = &mm->context.tsb_block[MM_TSB_HUGE];
  2362. if (likely(tp->tsb == NULL))
  2363. tsb_grow(mm, MM_TSB_HUGE, 0);
  2364. tsb_context_switch(mm);
  2365. smp_tsb_sync(mm);
  2366. /* On UltraSPARC-III+ and later, configure the second half of
  2367. * the Data-TLB for huge pages.
  2368. */
  2369. if (tlb_type == cheetah_plus) {
  2370. bool need_context_reload = false;
  2371. unsigned long ctx;
  2372. spin_lock_irq(&ctx_alloc_lock);
  2373. ctx = mm->context.sparc64_ctx_val;
  2374. ctx &= ~CTX_PGSZ_MASK;
  2375. ctx |= CTX_PGSZ_BASE << CTX_PGSZ0_SHIFT;
  2376. ctx |= CTX_PGSZ_HUGE << CTX_PGSZ1_SHIFT;
  2377. if (ctx != mm->context.sparc64_ctx_val) {
  2378. /* When changing the page size fields, we
  2379. * must perform a context flush so that no
  2380. * stale entries match. This flush must
  2381. * occur with the original context register
  2382. * settings.
  2383. */
  2384. do_flush_tlb_mm(mm);
  2385. /* Reload the context register of all processors
  2386. * also executing in this address space.
  2387. */
  2388. mm->context.sparc64_ctx_val = ctx;
  2389. need_context_reload = true;
  2390. }
  2391. spin_unlock_irq(&ctx_alloc_lock);
  2392. if (need_context_reload)
  2393. on_each_cpu(context_reload, mm, 0);
  2394. }
  2395. }
  2396. #endif
  2397. static struct resource code_resource = {
  2398. .name = "Kernel code",
  2399. .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM
  2400. };
  2401. static struct resource data_resource = {
  2402. .name = "Kernel data",
  2403. .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM
  2404. };
  2405. static struct resource bss_resource = {
  2406. .name = "Kernel bss",
  2407. .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM
  2408. };
  2409. static inline resource_size_t compute_kern_paddr(void *addr)
  2410. {
  2411. return (resource_size_t) (addr - KERNBASE + kern_base);
  2412. }
  2413. static void __init kernel_lds_init(void)
  2414. {
  2415. code_resource.start = compute_kern_paddr(_text);
  2416. code_resource.end = compute_kern_paddr(_etext - 1);
  2417. data_resource.start = compute_kern_paddr(_etext);
  2418. data_resource.end = compute_kern_paddr(_edata - 1);
  2419. bss_resource.start = compute_kern_paddr(__bss_start);
  2420. bss_resource.end = compute_kern_paddr(_end - 1);
  2421. }
  2422. static int __init report_memory(void)
  2423. {
  2424. int i;
  2425. struct resource *res;
  2426. kernel_lds_init();
  2427. for (i = 0; i < pavail_ents; i++) {
  2428. res = kzalloc(sizeof(struct resource), GFP_KERNEL);
  2429. if (!res) {
  2430. pr_warn("Failed to allocate source.\n");
  2431. break;
  2432. }
  2433. res->name = "System RAM";
  2434. res->start = pavail[i].phys_addr;
  2435. res->end = pavail[i].phys_addr + pavail[i].reg_size - 1;
  2436. res->flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM;
  2437. if (insert_resource(&iomem_resource, res) < 0) {
  2438. pr_warn("Resource insertion failed.\n");
  2439. break;
  2440. }
  2441. insert_resource(res, &code_resource);
  2442. insert_resource(res, &data_resource);
  2443. insert_resource(res, &bss_resource);
  2444. }
  2445. return 0;
  2446. }
  2447. arch_initcall(report_memory);
  2448. #ifdef CONFIG_SMP
  2449. #define do_flush_tlb_kernel_range smp_flush_tlb_kernel_range
  2450. #else
  2451. #define do_flush_tlb_kernel_range __flush_tlb_kernel_range
  2452. #endif
  2453. void flush_tlb_kernel_range(unsigned long start, unsigned long end)
  2454. {
  2455. if (start < HI_OBP_ADDRESS && end > LOW_OBP_ADDRESS) {
  2456. if (start < LOW_OBP_ADDRESS) {
  2457. flush_tsb_kernel_range(start, LOW_OBP_ADDRESS);
  2458. do_flush_tlb_kernel_range(start, LOW_OBP_ADDRESS);
  2459. }
  2460. if (end > HI_OBP_ADDRESS) {
  2461. flush_tsb_kernel_range(HI_OBP_ADDRESS, end);
  2462. do_flush_tlb_kernel_range(HI_OBP_ADDRESS, end);
  2463. }
  2464. } else {
  2465. flush_tsb_kernel_range(start, end);
  2466. do_flush_tlb_kernel_range(start, end);
  2467. }
  2468. }