x2apic_uv_x.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * SGI UV APIC functions (note: not an Intel compatible APIC)
  7. *
  8. * Copyright (C) 2007-2014 Silicon Graphics, Inc. All rights reserved.
  9. */
  10. #include <linux/cpumask.h>
  11. #include <linux/hardirq.h>
  12. #include <linux/proc_fs.h>
  13. #include <linux/threads.h>
  14. #include <linux/kernel.h>
  15. #include <linux/export.h>
  16. #include <linux/string.h>
  17. #include <linux/ctype.h>
  18. #include <linux/sched.h>
  19. #include <linux/timer.h>
  20. #include <linux/slab.h>
  21. #include <linux/cpu.h>
  22. #include <linux/init.h>
  23. #include <linux/io.h>
  24. #include <linux/pci.h>
  25. #include <linux/kdebug.h>
  26. #include <linux/delay.h>
  27. #include <linux/crash_dump.h>
  28. #include <linux/reboot.h>
  29. #include <asm/uv/uv_mmrs.h>
  30. #include <asm/uv/uv_hub.h>
  31. #include <asm/current.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/uv/bios.h>
  34. #include <asm/uv/uv.h>
  35. #include <asm/apic.h>
  36. #include <asm/e820/api.h>
  37. #include <asm/ipi.h>
  38. #include <asm/smp.h>
  39. #include <asm/x86_init.h>
  40. #include <asm/nmi.h>
  41. DEFINE_PER_CPU(int, x2apic_extra_bits);
  42. static enum uv_system_type uv_system_type;
  43. static bool uv_hubless_system;
  44. static u64 gru_start_paddr, gru_end_paddr;
  45. static u64 gru_dist_base, gru_first_node_paddr = -1LL, gru_last_node_paddr;
  46. static u64 gru_dist_lmask, gru_dist_umask;
  47. static union uvh_apicid uvh_apicid;
  48. /* Information derived from CPUID: */
  49. static struct {
  50. unsigned int apicid_shift;
  51. unsigned int apicid_mask;
  52. unsigned int socketid_shift; /* aka pnode_shift for UV1/2/3 */
  53. unsigned int pnode_mask;
  54. unsigned int gpa_shift;
  55. unsigned int gnode_shift;
  56. } uv_cpuid;
  57. int uv_min_hub_revision_id;
  58. EXPORT_SYMBOL_GPL(uv_min_hub_revision_id);
  59. unsigned int uv_apicid_hibits;
  60. EXPORT_SYMBOL_GPL(uv_apicid_hibits);
  61. static struct apic apic_x2apic_uv_x;
  62. static struct uv_hub_info_s uv_hub_info_node0;
  63. /* Set this to use hardware error handler instead of kernel panic: */
  64. static int disable_uv_undefined_panic = 1;
  65. unsigned long uv_undefined(char *str)
  66. {
  67. if (likely(!disable_uv_undefined_panic))
  68. panic("UV: error: undefined MMR: %s\n", str);
  69. else
  70. pr_crit("UV: error: undefined MMR: %s\n", str);
  71. /* Cause a machine fault: */
  72. return ~0ul;
  73. }
  74. EXPORT_SYMBOL(uv_undefined);
  75. static unsigned long __init uv_early_read_mmr(unsigned long addr)
  76. {
  77. unsigned long val, *mmr;
  78. mmr = early_ioremap(UV_LOCAL_MMR_BASE | addr, sizeof(*mmr));
  79. val = *mmr;
  80. early_iounmap(mmr, sizeof(*mmr));
  81. return val;
  82. }
  83. static inline bool is_GRU_range(u64 start, u64 end)
  84. {
  85. if (gru_dist_base) {
  86. u64 su = start & gru_dist_umask; /* Upper (incl pnode) bits */
  87. u64 sl = start & gru_dist_lmask; /* Base offset bits */
  88. u64 eu = end & gru_dist_umask;
  89. u64 el = end & gru_dist_lmask;
  90. /* Must reside completely within a single GRU range: */
  91. return (sl == gru_dist_base && el == gru_dist_base &&
  92. su >= gru_first_node_paddr &&
  93. su <= gru_last_node_paddr &&
  94. eu == su);
  95. } else {
  96. return start >= gru_start_paddr && end <= gru_end_paddr;
  97. }
  98. }
  99. static bool uv_is_untracked_pat_range(u64 start, u64 end)
  100. {
  101. return is_ISA_range(start, end) || is_GRU_range(start, end);
  102. }
  103. static int __init early_get_pnodeid(void)
  104. {
  105. union uvh_node_id_u node_id;
  106. union uvh_rh_gam_config_mmr_u m_n_config;
  107. int pnode;
  108. /* Currently, all blades have same revision number */
  109. node_id.v = uv_early_read_mmr(UVH_NODE_ID);
  110. m_n_config.v = uv_early_read_mmr(UVH_RH_GAM_CONFIG_MMR);
  111. uv_min_hub_revision_id = node_id.s.revision;
  112. switch (node_id.s.part_number) {
  113. case UV2_HUB_PART_NUMBER:
  114. case UV2_HUB_PART_NUMBER_X:
  115. uv_min_hub_revision_id += UV2_HUB_REVISION_BASE - 1;
  116. break;
  117. case UV3_HUB_PART_NUMBER:
  118. case UV3_HUB_PART_NUMBER_X:
  119. uv_min_hub_revision_id += UV3_HUB_REVISION_BASE;
  120. break;
  121. case UV4_HUB_PART_NUMBER:
  122. uv_min_hub_revision_id += UV4_HUB_REVISION_BASE - 1;
  123. uv_cpuid.gnode_shift = 2; /* min partition is 4 sockets */
  124. break;
  125. }
  126. uv_hub_info->hub_revision = uv_min_hub_revision_id;
  127. uv_cpuid.pnode_mask = (1 << m_n_config.s.n_skt) - 1;
  128. pnode = (node_id.s.node_id >> 1) & uv_cpuid.pnode_mask;
  129. uv_cpuid.gpa_shift = 46; /* Default unless changed */
  130. pr_info("UV: rev:%d part#:%x nodeid:%04x n_skt:%d pnmsk:%x pn:%x\n",
  131. node_id.s.revision, node_id.s.part_number, node_id.s.node_id,
  132. m_n_config.s.n_skt, uv_cpuid.pnode_mask, pnode);
  133. return pnode;
  134. }
  135. /* [Copied from arch/x86/kernel/cpu/topology.c:detect_extended_topology()] */
  136. #define SMT_LEVEL 0 /* Leaf 0xb SMT level */
  137. #define INVALID_TYPE 0 /* Leaf 0xb sub-leaf types */
  138. #define SMT_TYPE 1
  139. #define CORE_TYPE 2
  140. #define LEAFB_SUBTYPE(ecx) (((ecx) >> 8) & 0xff)
  141. #define BITS_SHIFT_NEXT_LEVEL(eax) ((eax) & 0x1f)
  142. static void set_x2apic_bits(void)
  143. {
  144. unsigned int eax, ebx, ecx, edx, sub_index;
  145. unsigned int sid_shift;
  146. cpuid(0, &eax, &ebx, &ecx, &edx);
  147. if (eax < 0xb) {
  148. pr_info("UV: CPU does not have CPUID.11\n");
  149. return;
  150. }
  151. cpuid_count(0xb, SMT_LEVEL, &eax, &ebx, &ecx, &edx);
  152. if (ebx == 0 || (LEAFB_SUBTYPE(ecx) != SMT_TYPE)) {
  153. pr_info("UV: CPUID.11 not implemented\n");
  154. return;
  155. }
  156. sid_shift = BITS_SHIFT_NEXT_LEVEL(eax);
  157. sub_index = 1;
  158. do {
  159. cpuid_count(0xb, sub_index, &eax, &ebx, &ecx, &edx);
  160. if (LEAFB_SUBTYPE(ecx) == CORE_TYPE) {
  161. sid_shift = BITS_SHIFT_NEXT_LEVEL(eax);
  162. break;
  163. }
  164. sub_index++;
  165. } while (LEAFB_SUBTYPE(ecx) != INVALID_TYPE);
  166. uv_cpuid.apicid_shift = 0;
  167. uv_cpuid.apicid_mask = (~(-1 << sid_shift));
  168. uv_cpuid.socketid_shift = sid_shift;
  169. }
  170. static void __init early_get_apic_socketid_shift(void)
  171. {
  172. if (is_uv2_hub() || is_uv3_hub())
  173. uvh_apicid.v = uv_early_read_mmr(UVH_APICID);
  174. set_x2apic_bits();
  175. pr_info("UV: apicid_shift:%d apicid_mask:0x%x\n", uv_cpuid.apicid_shift, uv_cpuid.apicid_mask);
  176. pr_info("UV: socketid_shift:%d pnode_mask:0x%x\n", uv_cpuid.socketid_shift, uv_cpuid.pnode_mask);
  177. }
  178. /*
  179. * Add an extra bit as dictated by bios to the destination apicid of
  180. * interrupts potentially passing through the UV HUB. This prevents
  181. * a deadlock between interrupts and IO port operations.
  182. */
  183. static void __init uv_set_apicid_hibit(void)
  184. {
  185. union uv1h_lb_target_physical_apic_id_mask_u apicid_mask;
  186. if (is_uv1_hub()) {
  187. apicid_mask.v = uv_early_read_mmr(UV1H_LB_TARGET_PHYSICAL_APIC_ID_MASK);
  188. uv_apicid_hibits = apicid_mask.s1.bit_enables & UV_APICID_HIBIT_MASK;
  189. }
  190. }
  191. static int __init uv_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  192. {
  193. int pnodeid;
  194. int uv_apic;
  195. if (strncmp(oem_id, "SGI", 3) != 0) {
  196. if (strncmp(oem_id, "NSGI", 4) == 0) {
  197. uv_hubless_system = true;
  198. pr_info("UV: OEM IDs %s/%s, HUBLESS\n",
  199. oem_id, oem_table_id);
  200. }
  201. return 0;
  202. }
  203. if (numa_off) {
  204. pr_err("UV: NUMA is off, disabling UV support\n");
  205. return 0;
  206. }
  207. /* Set up early hub type field in uv_hub_info for Node 0 */
  208. uv_cpu_info->p_uv_hub_info = &uv_hub_info_node0;
  209. /*
  210. * Determine UV arch type.
  211. * SGI: UV100/1000
  212. * SGI2: UV2000/3000
  213. * SGI3: UV300 (truncated to 4 chars because of different varieties)
  214. * SGI4: UV400 (truncated to 4 chars because of different varieties)
  215. */
  216. uv_hub_info->hub_revision =
  217. !strncmp(oem_id, "SGI4", 4) ? UV4_HUB_REVISION_BASE :
  218. !strncmp(oem_id, "SGI3", 4) ? UV3_HUB_REVISION_BASE :
  219. !strcmp(oem_id, "SGI2") ? UV2_HUB_REVISION_BASE :
  220. !strcmp(oem_id, "SGI") ? UV1_HUB_REVISION_BASE : 0;
  221. if (uv_hub_info->hub_revision == 0)
  222. goto badbios;
  223. pnodeid = early_get_pnodeid();
  224. early_get_apic_socketid_shift();
  225. x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
  226. x86_platform.nmi_init = uv_nmi_init;
  227. if (!strcmp(oem_table_id, "UVX")) {
  228. /* This is the most common hardware variant: */
  229. uv_system_type = UV_X2APIC;
  230. uv_apic = 0;
  231. } else if (!strcmp(oem_table_id, "UVH")) {
  232. /* Only UV1 systems: */
  233. uv_system_type = UV_NON_UNIQUE_APIC;
  234. __this_cpu_write(x2apic_extra_bits, pnodeid << uvh_apicid.s.pnode_shift);
  235. uv_set_apicid_hibit();
  236. uv_apic = 1;
  237. } else if (!strcmp(oem_table_id, "UVL")) {
  238. /* Only used for very small systems: */
  239. uv_system_type = UV_LEGACY_APIC;
  240. uv_apic = 0;
  241. } else {
  242. goto badbios;
  243. }
  244. pr_info("UV: OEM IDs %s/%s, System/HUB Types %d/%d, uv_apic %d\n", oem_id, oem_table_id, uv_system_type, uv_min_hub_revision_id, uv_apic);
  245. return uv_apic;
  246. badbios:
  247. pr_err("UV: OEM_ID:%s OEM_TABLE_ID:%s\n", oem_id, oem_table_id);
  248. pr_err("Current BIOS not supported, update kernel and/or BIOS\n");
  249. BUG();
  250. }
  251. enum uv_system_type get_uv_system_type(void)
  252. {
  253. return uv_system_type;
  254. }
  255. int is_uv_system(void)
  256. {
  257. return uv_system_type != UV_NONE;
  258. }
  259. EXPORT_SYMBOL_GPL(is_uv_system);
  260. int is_uv_hubless(void)
  261. {
  262. return uv_hubless_system;
  263. }
  264. EXPORT_SYMBOL_GPL(is_uv_hubless);
  265. void **__uv_hub_info_list;
  266. EXPORT_SYMBOL_GPL(__uv_hub_info_list);
  267. DEFINE_PER_CPU(struct uv_cpu_info_s, __uv_cpu_info);
  268. EXPORT_PER_CPU_SYMBOL_GPL(__uv_cpu_info);
  269. short uv_possible_blades;
  270. EXPORT_SYMBOL_GPL(uv_possible_blades);
  271. unsigned long sn_rtc_cycles_per_second;
  272. EXPORT_SYMBOL(sn_rtc_cycles_per_second);
  273. /* The following values are used for the per node hub info struct */
  274. static __initdata unsigned short *_node_to_pnode;
  275. static __initdata unsigned short _min_socket, _max_socket;
  276. static __initdata unsigned short _min_pnode, _max_pnode, _gr_table_len;
  277. static __initdata struct uv_gam_range_entry *uv_gre_table;
  278. static __initdata struct uv_gam_parameters *uv_gp_table;
  279. static __initdata unsigned short *_socket_to_node;
  280. static __initdata unsigned short *_socket_to_pnode;
  281. static __initdata unsigned short *_pnode_to_socket;
  282. static __initdata struct uv_gam_range_s *_gr_table;
  283. #define SOCK_EMPTY ((unsigned short)~0)
  284. extern int uv_hub_info_version(void)
  285. {
  286. return UV_HUB_INFO_VERSION;
  287. }
  288. EXPORT_SYMBOL(uv_hub_info_version);
  289. /* Build GAM range lookup table: */
  290. static __init void build_uv_gr_table(void)
  291. {
  292. struct uv_gam_range_entry *gre = uv_gre_table;
  293. struct uv_gam_range_s *grt;
  294. unsigned long last_limit = 0, ram_limit = 0;
  295. int bytes, i, sid, lsid = -1, indx = 0, lindx = -1;
  296. if (!gre)
  297. return;
  298. bytes = _gr_table_len * sizeof(struct uv_gam_range_s);
  299. grt = kzalloc(bytes, GFP_KERNEL);
  300. BUG_ON(!grt);
  301. _gr_table = grt;
  302. for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) {
  303. if (gre->type == UV_GAM_RANGE_TYPE_HOLE) {
  304. if (!ram_limit) {
  305. /* Mark hole between RAM/non-RAM: */
  306. ram_limit = last_limit;
  307. last_limit = gre->limit;
  308. lsid++;
  309. continue;
  310. }
  311. last_limit = gre->limit;
  312. pr_info("UV: extra hole in GAM RE table @%d\n", (int)(gre - uv_gre_table));
  313. continue;
  314. }
  315. if (_max_socket < gre->sockid) {
  316. pr_err("UV: GAM table sockid(%d) too large(>%d) @%d\n", gre->sockid, _max_socket, (int)(gre - uv_gre_table));
  317. continue;
  318. }
  319. sid = gre->sockid - _min_socket;
  320. if (lsid < sid) {
  321. /* New range: */
  322. grt = &_gr_table[indx];
  323. grt->base = lindx;
  324. grt->nasid = gre->nasid;
  325. grt->limit = last_limit = gre->limit;
  326. lsid = sid;
  327. lindx = indx++;
  328. continue;
  329. }
  330. /* Update range: */
  331. if (lsid == sid && !ram_limit) {
  332. /* .. if contiguous: */
  333. if (grt->limit == last_limit) {
  334. grt->limit = last_limit = gre->limit;
  335. continue;
  336. }
  337. }
  338. /* Non-contiguous RAM range: */
  339. if (!ram_limit) {
  340. grt++;
  341. grt->base = lindx;
  342. grt->nasid = gre->nasid;
  343. grt->limit = last_limit = gre->limit;
  344. continue;
  345. }
  346. /* Non-contiguous/non-RAM: */
  347. grt++;
  348. /* base is this entry */
  349. grt->base = grt - _gr_table;
  350. grt->nasid = gre->nasid;
  351. grt->limit = last_limit = gre->limit;
  352. lsid++;
  353. }
  354. /* Shorten table if possible */
  355. grt++;
  356. i = grt - _gr_table;
  357. if (i < _gr_table_len) {
  358. void *ret;
  359. bytes = i * sizeof(struct uv_gam_range_s);
  360. ret = krealloc(_gr_table, bytes, GFP_KERNEL);
  361. if (ret) {
  362. _gr_table = ret;
  363. _gr_table_len = i;
  364. }
  365. }
  366. /* Display resultant GAM range table: */
  367. for (i = 0, grt = _gr_table; i < _gr_table_len; i++, grt++) {
  368. unsigned long start, end;
  369. int gb = grt->base;
  370. start = gb < 0 ? 0 : (unsigned long)_gr_table[gb].limit << UV_GAM_RANGE_SHFT;
  371. end = (unsigned long)grt->limit << UV_GAM_RANGE_SHFT;
  372. pr_info("UV: GAM Range %2d %04x 0x%013lx-0x%013lx (%d)\n", i, grt->nasid, start, end, gb);
  373. }
  374. }
  375. static int uv_wakeup_secondary(int phys_apicid, unsigned long start_rip)
  376. {
  377. unsigned long val;
  378. int pnode;
  379. pnode = uv_apicid_to_pnode(phys_apicid);
  380. phys_apicid |= uv_apicid_hibits;
  381. val = (1UL << UVH_IPI_INT_SEND_SHFT) |
  382. (phys_apicid << UVH_IPI_INT_APIC_ID_SHFT) |
  383. ((start_rip << UVH_IPI_INT_VECTOR_SHFT) >> 12) |
  384. APIC_DM_INIT;
  385. uv_write_global_mmr64(pnode, UVH_IPI_INT, val);
  386. val = (1UL << UVH_IPI_INT_SEND_SHFT) |
  387. (phys_apicid << UVH_IPI_INT_APIC_ID_SHFT) |
  388. ((start_rip << UVH_IPI_INT_VECTOR_SHFT) >> 12) |
  389. APIC_DM_STARTUP;
  390. uv_write_global_mmr64(pnode, UVH_IPI_INT, val);
  391. return 0;
  392. }
  393. static void uv_send_IPI_one(int cpu, int vector)
  394. {
  395. unsigned long apicid;
  396. int pnode;
  397. apicid = per_cpu(x86_cpu_to_apicid, cpu);
  398. pnode = uv_apicid_to_pnode(apicid);
  399. uv_hub_send_ipi(pnode, apicid, vector);
  400. }
  401. static void uv_send_IPI_mask(const struct cpumask *mask, int vector)
  402. {
  403. unsigned int cpu;
  404. for_each_cpu(cpu, mask)
  405. uv_send_IPI_one(cpu, vector);
  406. }
  407. static void uv_send_IPI_mask_allbutself(const struct cpumask *mask, int vector)
  408. {
  409. unsigned int this_cpu = smp_processor_id();
  410. unsigned int cpu;
  411. for_each_cpu(cpu, mask) {
  412. if (cpu != this_cpu)
  413. uv_send_IPI_one(cpu, vector);
  414. }
  415. }
  416. static void uv_send_IPI_allbutself(int vector)
  417. {
  418. unsigned int this_cpu = smp_processor_id();
  419. unsigned int cpu;
  420. for_each_online_cpu(cpu) {
  421. if (cpu != this_cpu)
  422. uv_send_IPI_one(cpu, vector);
  423. }
  424. }
  425. static void uv_send_IPI_all(int vector)
  426. {
  427. uv_send_IPI_mask(cpu_online_mask, vector);
  428. }
  429. static int uv_apic_id_valid(int apicid)
  430. {
  431. return 1;
  432. }
  433. static int uv_apic_id_registered(void)
  434. {
  435. return 1;
  436. }
  437. static void uv_init_apic_ldr(void)
  438. {
  439. }
  440. static int
  441. uv_cpu_mask_to_apicid(const struct cpumask *mask, struct irq_data *irqdata,
  442. unsigned int *apicid)
  443. {
  444. int ret = default_cpu_mask_to_apicid(mask, irqdata, apicid);
  445. if (!ret)
  446. *apicid |= uv_apicid_hibits;
  447. return ret;
  448. }
  449. static unsigned int x2apic_get_apic_id(unsigned long x)
  450. {
  451. unsigned int id;
  452. WARN_ON(preemptible() && num_online_cpus() > 1);
  453. id = x | __this_cpu_read(x2apic_extra_bits);
  454. return id;
  455. }
  456. static unsigned long set_apic_id(unsigned int id)
  457. {
  458. /* CHECKME: Do we need to mask out the xapic extra bits? */
  459. return id;
  460. }
  461. static unsigned int uv_read_apic_id(void)
  462. {
  463. return x2apic_get_apic_id(apic_read(APIC_ID));
  464. }
  465. static int uv_phys_pkg_id(int initial_apicid, int index_msb)
  466. {
  467. return uv_read_apic_id() >> index_msb;
  468. }
  469. static void uv_send_IPI_self(int vector)
  470. {
  471. apic_write(APIC_SELF_IPI, vector);
  472. }
  473. static int uv_probe(void)
  474. {
  475. return apic == &apic_x2apic_uv_x;
  476. }
  477. static struct apic apic_x2apic_uv_x __ro_after_init = {
  478. .name = "UV large system",
  479. .probe = uv_probe,
  480. .acpi_madt_oem_check = uv_acpi_madt_oem_check,
  481. .apic_id_valid = uv_apic_id_valid,
  482. .apic_id_registered = uv_apic_id_registered,
  483. .irq_delivery_mode = dest_Fixed,
  484. .irq_dest_mode = 0, /* Physical */
  485. .target_cpus = online_target_cpus,
  486. .disable_esr = 0,
  487. .dest_logical = APIC_DEST_LOGICAL,
  488. .check_apicid_used = NULL,
  489. .vector_allocation_domain = default_vector_allocation_domain,
  490. .init_apic_ldr = uv_init_apic_ldr,
  491. .ioapic_phys_id_map = NULL,
  492. .setup_apic_routing = NULL,
  493. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  494. .apicid_to_cpu_present = NULL,
  495. .check_phys_apicid_present = default_check_phys_apicid_present,
  496. .phys_pkg_id = uv_phys_pkg_id,
  497. .get_apic_id = x2apic_get_apic_id,
  498. .set_apic_id = set_apic_id,
  499. .cpu_mask_to_apicid = uv_cpu_mask_to_apicid,
  500. .send_IPI = uv_send_IPI_one,
  501. .send_IPI_mask = uv_send_IPI_mask,
  502. .send_IPI_mask_allbutself = uv_send_IPI_mask_allbutself,
  503. .send_IPI_allbutself = uv_send_IPI_allbutself,
  504. .send_IPI_all = uv_send_IPI_all,
  505. .send_IPI_self = uv_send_IPI_self,
  506. .wakeup_secondary_cpu = uv_wakeup_secondary,
  507. .inquire_remote_apic = NULL,
  508. .read = native_apic_msr_read,
  509. .write = native_apic_msr_write,
  510. .eoi_write = native_apic_msr_eoi_write,
  511. .icr_read = native_x2apic_icr_read,
  512. .icr_write = native_x2apic_icr_write,
  513. .wait_icr_idle = native_x2apic_wait_icr_idle,
  514. .safe_wait_icr_idle = native_safe_x2apic_wait_icr_idle,
  515. };
  516. static void set_x2apic_extra_bits(int pnode)
  517. {
  518. __this_cpu_write(x2apic_extra_bits, pnode << uvh_apicid.s.pnode_shift);
  519. }
  520. #define UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_LENGTH 3
  521. #define DEST_SHIFT UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR_DEST_BASE_SHFT
  522. static __init void get_lowmem_redirect(unsigned long *base, unsigned long *size)
  523. {
  524. union uvh_rh_gam_alias210_overlay_config_2_mmr_u alias;
  525. union uvh_rh_gam_alias210_redirect_config_2_mmr_u redirect;
  526. unsigned long m_redirect;
  527. unsigned long m_overlay;
  528. int i;
  529. for (i = 0; i < UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_LENGTH; i++) {
  530. switch (i) {
  531. case 0:
  532. m_redirect = UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR;
  533. m_overlay = UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_0_MMR;
  534. break;
  535. case 1:
  536. m_redirect = UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_1_MMR;
  537. m_overlay = UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_1_MMR;
  538. break;
  539. case 2:
  540. m_redirect = UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_2_MMR;
  541. m_overlay = UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_2_MMR;
  542. break;
  543. }
  544. alias.v = uv_read_local_mmr(m_overlay);
  545. if (alias.s.enable && alias.s.base == 0) {
  546. *size = (1UL << alias.s.m_alias);
  547. redirect.v = uv_read_local_mmr(m_redirect);
  548. *base = (unsigned long)redirect.s.dest_base << DEST_SHIFT;
  549. return;
  550. }
  551. }
  552. *base = *size = 0;
  553. }
  554. enum map_type {map_wb, map_uc};
  555. static __init void map_high(char *id, unsigned long base, int pshift, int bshift, int max_pnode, enum map_type map_type)
  556. {
  557. unsigned long bytes, paddr;
  558. paddr = base << pshift;
  559. bytes = (1UL << bshift) * (max_pnode + 1);
  560. if (!paddr) {
  561. pr_info("UV: Map %s_HI base address NULL\n", id);
  562. return;
  563. }
  564. pr_debug("UV: Map %s_HI 0x%lx - 0x%lx\n", id, paddr, paddr + bytes);
  565. if (map_type == map_uc)
  566. init_extra_mapping_uc(paddr, bytes);
  567. else
  568. init_extra_mapping_wb(paddr, bytes);
  569. }
  570. static __init void map_gru_distributed(unsigned long c)
  571. {
  572. union uvh_rh_gam_gru_overlay_config_mmr_u gru;
  573. u64 paddr;
  574. unsigned long bytes;
  575. int nid;
  576. gru.v = c;
  577. /* Only base bits 42:28 relevant in dist mode */
  578. gru_dist_base = gru.v & 0x000007fff0000000UL;
  579. if (!gru_dist_base) {
  580. pr_info("UV: Map GRU_DIST base address NULL\n");
  581. return;
  582. }
  583. bytes = 1UL << UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_BASE_SHFT;
  584. gru_dist_lmask = ((1UL << uv_hub_info->m_val) - 1) & ~(bytes - 1);
  585. gru_dist_umask = ~((1UL << uv_hub_info->m_val) - 1);
  586. gru_dist_base &= gru_dist_lmask; /* Clear bits above M */
  587. for_each_online_node(nid) {
  588. paddr = ((u64)uv_node_to_pnode(nid) << uv_hub_info->m_val) |
  589. gru_dist_base;
  590. init_extra_mapping_wb(paddr, bytes);
  591. gru_first_node_paddr = min(paddr, gru_first_node_paddr);
  592. gru_last_node_paddr = max(paddr, gru_last_node_paddr);
  593. }
  594. /* Save upper (63:M) bits of address only for is_GRU_range */
  595. gru_first_node_paddr &= gru_dist_umask;
  596. gru_last_node_paddr &= gru_dist_umask;
  597. pr_debug("UV: Map GRU_DIST base 0x%016llx 0x%016llx - 0x%016llx\n", gru_dist_base, gru_first_node_paddr, gru_last_node_paddr);
  598. }
  599. static __init void map_gru_high(int max_pnode)
  600. {
  601. union uvh_rh_gam_gru_overlay_config_mmr_u gru;
  602. int shift = UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_BASE_SHFT;
  603. unsigned long mask = UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_BASE_MASK;
  604. unsigned long base;
  605. gru.v = uv_read_local_mmr(UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR);
  606. if (!gru.s.enable) {
  607. pr_info("UV: GRU disabled\n");
  608. return;
  609. }
  610. if (is_uv3_hub() && gru.s3.mode) {
  611. map_gru_distributed(gru.v);
  612. return;
  613. }
  614. base = (gru.v & mask) >> shift;
  615. map_high("GRU", base, shift, shift, max_pnode, map_wb);
  616. gru_start_paddr = ((u64)base << shift);
  617. gru_end_paddr = gru_start_paddr + (1UL << shift) * (max_pnode + 1);
  618. }
  619. static __init void map_mmr_high(int max_pnode)
  620. {
  621. union uvh_rh_gam_mmr_overlay_config_mmr_u mmr;
  622. int shift = UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR_BASE_SHFT;
  623. mmr.v = uv_read_local_mmr(UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR);
  624. if (mmr.s.enable)
  625. map_high("MMR", mmr.s.base, shift, shift, max_pnode, map_uc);
  626. else
  627. pr_info("UV: MMR disabled\n");
  628. }
  629. /*
  630. * This commonality works because both 0 & 1 versions of the MMIOH OVERLAY
  631. * and REDIRECT MMR regs are exactly the same on UV3.
  632. */
  633. struct mmioh_config {
  634. unsigned long overlay;
  635. unsigned long redirect;
  636. char *id;
  637. };
  638. static __initdata struct mmioh_config mmiohs[] = {
  639. {
  640. UV3H_RH_GAM_MMIOH_OVERLAY_CONFIG0_MMR,
  641. UV3H_RH_GAM_MMIOH_REDIRECT_CONFIG0_MMR,
  642. "MMIOH0"
  643. },
  644. {
  645. UV3H_RH_GAM_MMIOH_OVERLAY_CONFIG1_MMR,
  646. UV3H_RH_GAM_MMIOH_REDIRECT_CONFIG1_MMR,
  647. "MMIOH1"
  648. },
  649. };
  650. /* UV3 & UV4 have identical MMIOH overlay configs */
  651. static __init void map_mmioh_high_uv3(int index, int min_pnode, int max_pnode)
  652. {
  653. union uv3h_rh_gam_mmioh_overlay_config0_mmr_u overlay;
  654. unsigned long mmr;
  655. unsigned long base;
  656. int i, n, shift, m_io, max_io;
  657. int nasid, lnasid, fi, li;
  658. char *id;
  659. id = mmiohs[index].id;
  660. overlay.v = uv_read_local_mmr(mmiohs[index].overlay);
  661. pr_info("UV: %s overlay 0x%lx base:0x%x m_io:%d\n", id, overlay.v, overlay.s3.base, overlay.s3.m_io);
  662. if (!overlay.s3.enable) {
  663. pr_info("UV: %s disabled\n", id);
  664. return;
  665. }
  666. shift = UV3H_RH_GAM_MMIOH_OVERLAY_CONFIG0_MMR_BASE_SHFT;
  667. base = (unsigned long)overlay.s3.base;
  668. m_io = overlay.s3.m_io;
  669. mmr = mmiohs[index].redirect;
  670. n = UV3H_RH_GAM_MMIOH_REDIRECT_CONFIG0_MMR_DEPTH;
  671. /* Convert to NASID: */
  672. min_pnode *= 2;
  673. max_pnode *= 2;
  674. max_io = lnasid = fi = li = -1;
  675. for (i = 0; i < n; i++) {
  676. union uv3h_rh_gam_mmioh_redirect_config0_mmr_u redirect;
  677. redirect.v = uv_read_local_mmr(mmr + i * 8);
  678. nasid = redirect.s3.nasid;
  679. /* Invalid NASID: */
  680. if (nasid < min_pnode || max_pnode < nasid)
  681. nasid = -1;
  682. if (nasid == lnasid) {
  683. li = i;
  684. /* Last entry check: */
  685. if (i != n-1)
  686. continue;
  687. }
  688. /* Check if we have a cached (or last) redirect to print: */
  689. if (lnasid != -1 || (i == n-1 && nasid != -1)) {
  690. unsigned long addr1, addr2;
  691. int f, l;
  692. if (lnasid == -1) {
  693. f = l = i;
  694. lnasid = nasid;
  695. } else {
  696. f = fi;
  697. l = li;
  698. }
  699. addr1 = (base << shift) + f * (1ULL << m_io);
  700. addr2 = (base << shift) + (l + 1) * (1ULL << m_io);
  701. pr_info("UV: %s[%03d..%03d] NASID 0x%04x ADDR 0x%016lx - 0x%016lx\n", id, fi, li, lnasid, addr1, addr2);
  702. if (max_io < l)
  703. max_io = l;
  704. }
  705. fi = li = i;
  706. lnasid = nasid;
  707. }
  708. pr_info("UV: %s base:0x%lx shift:%d M_IO:%d MAX_IO:%d\n", id, base, shift, m_io, max_io);
  709. if (max_io >= 0)
  710. map_high(id, base, shift, m_io, max_io, map_uc);
  711. }
  712. static __init void map_mmioh_high(int min_pnode, int max_pnode)
  713. {
  714. union uvh_rh_gam_mmioh_overlay_config_mmr_u mmioh;
  715. unsigned long mmr, base;
  716. int shift, enable, m_io, n_io;
  717. if (is_uv3_hub() || is_uv4_hub()) {
  718. /* Map both MMIOH regions: */
  719. map_mmioh_high_uv3(0, min_pnode, max_pnode);
  720. map_mmioh_high_uv3(1, min_pnode, max_pnode);
  721. return;
  722. }
  723. if (is_uv1_hub()) {
  724. mmr = UV1H_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR;
  725. shift = UV1H_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_BASE_SHFT;
  726. mmioh.v = uv_read_local_mmr(mmr);
  727. enable = !!mmioh.s1.enable;
  728. base = mmioh.s1.base;
  729. m_io = mmioh.s1.m_io;
  730. n_io = mmioh.s1.n_io;
  731. } else if (is_uv2_hub()) {
  732. mmr = UV2H_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR;
  733. shift = UV2H_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_BASE_SHFT;
  734. mmioh.v = uv_read_local_mmr(mmr);
  735. enable = !!mmioh.s2.enable;
  736. base = mmioh.s2.base;
  737. m_io = mmioh.s2.m_io;
  738. n_io = mmioh.s2.n_io;
  739. } else {
  740. return;
  741. }
  742. if (enable) {
  743. max_pnode &= (1 << n_io) - 1;
  744. pr_info("UV: base:0x%lx shift:%d N_IO:%d M_IO:%d max_pnode:0x%x\n", base, shift, m_io, n_io, max_pnode);
  745. map_high("MMIOH", base, shift, m_io, max_pnode, map_uc);
  746. } else {
  747. pr_info("UV: MMIOH disabled\n");
  748. }
  749. }
  750. static __init void map_low_mmrs(void)
  751. {
  752. init_extra_mapping_uc(UV_GLOBAL_MMR32_BASE, UV_GLOBAL_MMR32_SIZE);
  753. init_extra_mapping_uc(UV_LOCAL_MMR_BASE, UV_LOCAL_MMR_SIZE);
  754. }
  755. static __init void uv_rtc_init(void)
  756. {
  757. long status;
  758. u64 ticks_per_sec;
  759. status = uv_bios_freq_base(BIOS_FREQ_BASE_REALTIME_CLOCK, &ticks_per_sec);
  760. if (status != BIOS_STATUS_SUCCESS || ticks_per_sec < 100000) {
  761. pr_warn("UV: unable to determine platform RTC clock frequency, guessing.\n");
  762. /* BIOS gives wrong value for clock frequency, so guess: */
  763. sn_rtc_cycles_per_second = 1000000000000UL / 30000UL;
  764. } else {
  765. sn_rtc_cycles_per_second = ticks_per_sec;
  766. }
  767. }
  768. /*
  769. * percpu heartbeat timer
  770. */
  771. static void uv_heartbeat(unsigned long ignored)
  772. {
  773. struct timer_list *timer = &uv_scir_info->timer;
  774. unsigned char bits = uv_scir_info->state;
  775. /* Flip heartbeat bit: */
  776. bits ^= SCIR_CPU_HEARTBEAT;
  777. /* Is this CPU idle? */
  778. if (idle_cpu(raw_smp_processor_id()))
  779. bits &= ~SCIR_CPU_ACTIVITY;
  780. else
  781. bits |= SCIR_CPU_ACTIVITY;
  782. /* Update system controller interface reg: */
  783. uv_set_scir_bits(bits);
  784. /* Enable next timer period: */
  785. mod_timer(timer, jiffies + SCIR_CPU_HB_INTERVAL);
  786. }
  787. static int uv_heartbeat_enable(unsigned int cpu)
  788. {
  789. while (!uv_cpu_scir_info(cpu)->enabled) {
  790. struct timer_list *timer = &uv_cpu_scir_info(cpu)->timer;
  791. uv_set_cpu_scir_bits(cpu, SCIR_CPU_HEARTBEAT|SCIR_CPU_ACTIVITY);
  792. setup_pinned_timer(timer, uv_heartbeat, cpu);
  793. timer->expires = jiffies + SCIR_CPU_HB_INTERVAL;
  794. add_timer_on(timer, cpu);
  795. uv_cpu_scir_info(cpu)->enabled = 1;
  796. /* Also ensure that boot CPU is enabled: */
  797. cpu = 0;
  798. }
  799. return 0;
  800. }
  801. #ifdef CONFIG_HOTPLUG_CPU
  802. static int uv_heartbeat_disable(unsigned int cpu)
  803. {
  804. if (uv_cpu_scir_info(cpu)->enabled) {
  805. uv_cpu_scir_info(cpu)->enabled = 0;
  806. del_timer(&uv_cpu_scir_info(cpu)->timer);
  807. }
  808. uv_set_cpu_scir_bits(cpu, 0xff);
  809. return 0;
  810. }
  811. static __init void uv_scir_register_cpu_notifier(void)
  812. {
  813. cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "x86/x2apic-uvx:online",
  814. uv_heartbeat_enable, uv_heartbeat_disable);
  815. }
  816. #else /* !CONFIG_HOTPLUG_CPU */
  817. static __init void uv_scir_register_cpu_notifier(void)
  818. {
  819. }
  820. static __init int uv_init_heartbeat(void)
  821. {
  822. int cpu;
  823. if (is_uv_system()) {
  824. for_each_online_cpu(cpu)
  825. uv_heartbeat_enable(cpu);
  826. }
  827. return 0;
  828. }
  829. late_initcall(uv_init_heartbeat);
  830. #endif /* !CONFIG_HOTPLUG_CPU */
  831. /* Direct Legacy VGA I/O traffic to designated IOH */
  832. int uv_set_vga_state(struct pci_dev *pdev, bool decode, unsigned int command_bits, u32 flags)
  833. {
  834. int domain, bus, rc;
  835. if (!(flags & PCI_VGA_STATE_CHANGE_BRIDGE))
  836. return 0;
  837. if ((command_bits & PCI_COMMAND_IO) == 0)
  838. return 0;
  839. domain = pci_domain_nr(pdev->bus);
  840. bus = pdev->bus->number;
  841. rc = uv_bios_set_legacy_vga_target(decode, domain, bus);
  842. return rc;
  843. }
  844. /*
  845. * Called on each CPU to initialize the per_cpu UV data area.
  846. * FIXME: hotplug not supported yet
  847. */
  848. void uv_cpu_init(void)
  849. {
  850. /* CPU 0 initialization will be done via uv_system_init. */
  851. if (smp_processor_id() == 0)
  852. return;
  853. uv_hub_info->nr_online_cpus++;
  854. if (get_uv_system_type() == UV_NON_UNIQUE_APIC)
  855. set_x2apic_extra_bits(uv_hub_info->pnode);
  856. }
  857. struct mn {
  858. unsigned char m_val;
  859. unsigned char n_val;
  860. unsigned char m_shift;
  861. unsigned char n_lshift;
  862. };
  863. static void get_mn(struct mn *mnp)
  864. {
  865. union uvh_rh_gam_config_mmr_u m_n_config;
  866. union uv3h_gr0_gam_gr_config_u m_gr_config;
  867. /* Make sure the whole structure is well initialized: */
  868. memset(mnp, 0, sizeof(*mnp));
  869. m_n_config.v = uv_read_local_mmr(UVH_RH_GAM_CONFIG_MMR);
  870. mnp->n_val = m_n_config.s.n_skt;
  871. if (is_uv4_hub()) {
  872. mnp->m_val = 0;
  873. mnp->n_lshift = 0;
  874. } else if (is_uv3_hub()) {
  875. mnp->m_val = m_n_config.s3.m_skt;
  876. m_gr_config.v = uv_read_local_mmr(UV3H_GR0_GAM_GR_CONFIG);
  877. mnp->n_lshift = m_gr_config.s3.m_skt;
  878. } else if (is_uv2_hub()) {
  879. mnp->m_val = m_n_config.s2.m_skt;
  880. mnp->n_lshift = mnp->m_val == 40 ? 40 : 39;
  881. } else if (is_uv1_hub()) {
  882. mnp->m_val = m_n_config.s1.m_skt;
  883. mnp->n_lshift = mnp->m_val;
  884. }
  885. mnp->m_shift = mnp->m_val ? 64 - mnp->m_val : 0;
  886. }
  887. void __init uv_init_hub_info(struct uv_hub_info_s *hi)
  888. {
  889. union uvh_node_id_u node_id;
  890. struct mn mn;
  891. get_mn(&mn);
  892. hi->gpa_mask = mn.m_val ?
  893. (1UL << (mn.m_val + mn.n_val)) - 1 :
  894. (1UL << uv_cpuid.gpa_shift) - 1;
  895. hi->m_val = mn.m_val;
  896. hi->n_val = mn.n_val;
  897. hi->m_shift = mn.m_shift;
  898. hi->n_lshift = mn.n_lshift ? mn.n_lshift : 0;
  899. hi->hub_revision = uv_hub_info->hub_revision;
  900. hi->pnode_mask = uv_cpuid.pnode_mask;
  901. hi->min_pnode = _min_pnode;
  902. hi->min_socket = _min_socket;
  903. hi->pnode_to_socket = _pnode_to_socket;
  904. hi->socket_to_node = _socket_to_node;
  905. hi->socket_to_pnode = _socket_to_pnode;
  906. hi->gr_table_len = _gr_table_len;
  907. hi->gr_table = _gr_table;
  908. node_id.v = uv_read_local_mmr(UVH_NODE_ID);
  909. uv_cpuid.gnode_shift = max_t(unsigned int, uv_cpuid.gnode_shift, mn.n_val);
  910. hi->gnode_extra = (node_id.s.node_id & ~((1 << uv_cpuid.gnode_shift) - 1)) >> 1;
  911. if (mn.m_val)
  912. hi->gnode_upper = (u64)hi->gnode_extra << mn.m_val;
  913. if (uv_gp_table) {
  914. hi->global_mmr_base = uv_gp_table->mmr_base;
  915. hi->global_mmr_shift = uv_gp_table->mmr_shift;
  916. hi->global_gru_base = uv_gp_table->gru_base;
  917. hi->global_gru_shift = uv_gp_table->gru_shift;
  918. hi->gpa_shift = uv_gp_table->gpa_shift;
  919. hi->gpa_mask = (1UL << hi->gpa_shift) - 1;
  920. } else {
  921. hi->global_mmr_base = uv_read_local_mmr(UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR) & ~UV_MMR_ENABLE;
  922. hi->global_mmr_shift = _UV_GLOBAL_MMR64_PNODE_SHIFT;
  923. }
  924. get_lowmem_redirect(&hi->lowmem_remap_base, &hi->lowmem_remap_top);
  925. hi->apic_pnode_shift = uv_cpuid.socketid_shift;
  926. /* Show system specific info: */
  927. pr_info("UV: N:%d M:%d m_shift:%d n_lshift:%d\n", hi->n_val, hi->m_val, hi->m_shift, hi->n_lshift);
  928. pr_info("UV: gpa_mask/shift:0x%lx/%d pnode_mask:0x%x apic_pns:%d\n", hi->gpa_mask, hi->gpa_shift, hi->pnode_mask, hi->apic_pnode_shift);
  929. pr_info("UV: mmr_base/shift:0x%lx/%ld gru_base/shift:0x%lx/%ld\n", hi->global_mmr_base, hi->global_mmr_shift, hi->global_gru_base, hi->global_gru_shift);
  930. pr_info("UV: gnode_upper:0x%lx gnode_extra:0x%x\n", hi->gnode_upper, hi->gnode_extra);
  931. }
  932. static void __init decode_gam_params(unsigned long ptr)
  933. {
  934. uv_gp_table = (struct uv_gam_parameters *)ptr;
  935. pr_info("UV: GAM Params...\n");
  936. pr_info("UV: mmr_base/shift:0x%llx/%d gru_base/shift:0x%llx/%d gpa_shift:%d\n",
  937. uv_gp_table->mmr_base, uv_gp_table->mmr_shift,
  938. uv_gp_table->gru_base, uv_gp_table->gru_shift,
  939. uv_gp_table->gpa_shift);
  940. }
  941. static void __init decode_gam_rng_tbl(unsigned long ptr)
  942. {
  943. struct uv_gam_range_entry *gre = (struct uv_gam_range_entry *)ptr;
  944. unsigned long lgre = 0;
  945. int index = 0;
  946. int sock_min = 999999, pnode_min = 99999;
  947. int sock_max = -1, pnode_max = -1;
  948. uv_gre_table = gre;
  949. for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) {
  950. if (!index) {
  951. pr_info("UV: GAM Range Table...\n");
  952. pr_info("UV: # %20s %14s %5s %4s %5s %3s %2s\n", "Range", "", "Size", "Type", "NASID", "SID", "PN");
  953. }
  954. pr_info("UV: %2d: 0x%014lx-0x%014lx %5luG %3d %04x %02x %02x\n",
  955. index++,
  956. (unsigned long)lgre << UV_GAM_RANGE_SHFT,
  957. (unsigned long)gre->limit << UV_GAM_RANGE_SHFT,
  958. ((unsigned long)(gre->limit - lgre)) >>
  959. (30 - UV_GAM_RANGE_SHFT), /* 64M -> 1G */
  960. gre->type, gre->nasid, gre->sockid, gre->pnode);
  961. lgre = gre->limit;
  962. if (sock_min > gre->sockid)
  963. sock_min = gre->sockid;
  964. if (sock_max < gre->sockid)
  965. sock_max = gre->sockid;
  966. if (pnode_min > gre->pnode)
  967. pnode_min = gre->pnode;
  968. if (pnode_max < gre->pnode)
  969. pnode_max = gre->pnode;
  970. }
  971. _min_socket = sock_min;
  972. _max_socket = sock_max;
  973. _min_pnode = pnode_min;
  974. _max_pnode = pnode_max;
  975. _gr_table_len = index;
  976. pr_info("UV: GRT: %d entries, sockets(min:%x,max:%x) pnodes(min:%x,max:%x)\n", index, _min_socket, _max_socket, _min_pnode, _max_pnode);
  977. }
  978. static int __init decode_uv_systab(void)
  979. {
  980. struct uv_systab *st;
  981. int i;
  982. if (uv_hub_info->hub_revision < UV4_HUB_REVISION_BASE)
  983. return 0; /* No extended UVsystab required */
  984. st = uv_systab;
  985. if ((!st) || (st->revision < UV_SYSTAB_VERSION_UV4_LATEST)) {
  986. int rev = st ? st->revision : 0;
  987. pr_err("UV: BIOS UVsystab version(%x) mismatch, expecting(%x)\n", rev, UV_SYSTAB_VERSION_UV4_LATEST);
  988. pr_err("UV: Cannot support UV operations, switching to generic PC\n");
  989. uv_system_type = UV_NONE;
  990. return -EINVAL;
  991. }
  992. for (i = 0; st->entry[i].type != UV_SYSTAB_TYPE_UNUSED; i++) {
  993. unsigned long ptr = st->entry[i].offset;
  994. if (!ptr)
  995. continue;
  996. ptr = ptr + (unsigned long)st;
  997. switch (st->entry[i].type) {
  998. case UV_SYSTAB_TYPE_GAM_PARAMS:
  999. decode_gam_params(ptr);
  1000. break;
  1001. case UV_SYSTAB_TYPE_GAM_RNG_TBL:
  1002. decode_gam_rng_tbl(ptr);
  1003. break;
  1004. }
  1005. }
  1006. return 0;
  1007. }
  1008. /*
  1009. * Set up physical blade translations from UVH_NODE_PRESENT_TABLE
  1010. * .. NB: UVH_NODE_PRESENT_TABLE is going away,
  1011. * .. being replaced by GAM Range Table
  1012. */
  1013. static __init void boot_init_possible_blades(struct uv_hub_info_s *hub_info)
  1014. {
  1015. int i, uv_pb = 0;
  1016. pr_info("UV: NODE_PRESENT_DEPTH = %d\n", UVH_NODE_PRESENT_TABLE_DEPTH);
  1017. for (i = 0; i < UVH_NODE_PRESENT_TABLE_DEPTH; i++) {
  1018. unsigned long np;
  1019. np = uv_read_local_mmr(UVH_NODE_PRESENT_TABLE + i * 8);
  1020. if (np)
  1021. pr_info("UV: NODE_PRESENT(%d) = 0x%016lx\n", i, np);
  1022. uv_pb += hweight64(np);
  1023. }
  1024. if (uv_possible_blades != uv_pb)
  1025. uv_possible_blades = uv_pb;
  1026. }
  1027. static void __init build_socket_tables(void)
  1028. {
  1029. struct uv_gam_range_entry *gre = uv_gre_table;
  1030. int num, nump;
  1031. int cpu, i, lnid;
  1032. int minsock = _min_socket;
  1033. int maxsock = _max_socket;
  1034. int minpnode = _min_pnode;
  1035. int maxpnode = _max_pnode;
  1036. size_t bytes;
  1037. if (!gre) {
  1038. if (is_uv1_hub() || is_uv2_hub() || is_uv3_hub()) {
  1039. pr_info("UV: No UVsystab socket table, ignoring\n");
  1040. return;
  1041. }
  1042. pr_crit("UV: Error: UVsystab address translations not available!\n");
  1043. BUG();
  1044. }
  1045. /* Build socket id -> node id, pnode */
  1046. num = maxsock - minsock + 1;
  1047. bytes = num * sizeof(_socket_to_node[0]);
  1048. _socket_to_node = kmalloc(bytes, GFP_KERNEL);
  1049. _socket_to_pnode = kmalloc(bytes, GFP_KERNEL);
  1050. nump = maxpnode - minpnode + 1;
  1051. bytes = nump * sizeof(_pnode_to_socket[0]);
  1052. _pnode_to_socket = kmalloc(bytes, GFP_KERNEL);
  1053. BUG_ON(!_socket_to_node || !_socket_to_pnode || !_pnode_to_socket);
  1054. for (i = 0; i < num; i++)
  1055. _socket_to_node[i] = _socket_to_pnode[i] = SOCK_EMPTY;
  1056. for (i = 0; i < nump; i++)
  1057. _pnode_to_socket[i] = SOCK_EMPTY;
  1058. /* Fill in pnode/node/addr conversion list values: */
  1059. pr_info("UV: GAM Building socket/pnode conversion tables\n");
  1060. for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) {
  1061. if (gre->type == UV_GAM_RANGE_TYPE_HOLE)
  1062. continue;
  1063. i = gre->sockid - minsock;
  1064. /* Duplicate: */
  1065. if (_socket_to_pnode[i] != SOCK_EMPTY)
  1066. continue;
  1067. _socket_to_pnode[i] = gre->pnode;
  1068. i = gre->pnode - minpnode;
  1069. _pnode_to_socket[i] = gre->sockid;
  1070. pr_info("UV: sid:%02x type:%d nasid:%04x pn:%02x pn2s:%2x\n",
  1071. gre->sockid, gre->type, gre->nasid,
  1072. _socket_to_pnode[gre->sockid - minsock],
  1073. _pnode_to_socket[gre->pnode - minpnode]);
  1074. }
  1075. /* Set socket -> node values: */
  1076. lnid = -1;
  1077. for_each_present_cpu(cpu) {
  1078. int nid = cpu_to_node(cpu);
  1079. int apicid, sockid;
  1080. if (lnid == nid)
  1081. continue;
  1082. lnid = nid;
  1083. apicid = per_cpu(x86_cpu_to_apicid, cpu);
  1084. sockid = apicid >> uv_cpuid.socketid_shift;
  1085. _socket_to_node[sockid - minsock] = nid;
  1086. pr_info("UV: sid:%02x: apicid:%04x node:%2d\n",
  1087. sockid, apicid, nid);
  1088. }
  1089. /* Set up physical blade to pnode translation from GAM Range Table: */
  1090. bytes = num_possible_nodes() * sizeof(_node_to_pnode[0]);
  1091. _node_to_pnode = kmalloc(bytes, GFP_KERNEL);
  1092. BUG_ON(!_node_to_pnode);
  1093. for (lnid = 0; lnid < num_possible_nodes(); lnid++) {
  1094. unsigned short sockid;
  1095. for (sockid = minsock; sockid <= maxsock; sockid++) {
  1096. if (lnid == _socket_to_node[sockid - minsock]) {
  1097. _node_to_pnode[lnid] = _socket_to_pnode[sockid - minsock];
  1098. break;
  1099. }
  1100. }
  1101. if (sockid > maxsock) {
  1102. pr_err("UV: socket for node %d not found!\n", lnid);
  1103. BUG();
  1104. }
  1105. }
  1106. /*
  1107. * If socket id == pnode or socket id == node for all nodes,
  1108. * system runs faster by removing corresponding conversion table.
  1109. */
  1110. pr_info("UV: Checking socket->node/pnode for identity maps\n");
  1111. if (minsock == 0) {
  1112. for (i = 0; i < num; i++)
  1113. if (_socket_to_node[i] == SOCK_EMPTY || i != _socket_to_node[i])
  1114. break;
  1115. if (i >= num) {
  1116. kfree(_socket_to_node);
  1117. _socket_to_node = NULL;
  1118. pr_info("UV: 1:1 socket_to_node table removed\n");
  1119. }
  1120. }
  1121. if (minsock == minpnode) {
  1122. for (i = 0; i < num; i++)
  1123. if (_socket_to_pnode[i] != SOCK_EMPTY &&
  1124. _socket_to_pnode[i] != i + minpnode)
  1125. break;
  1126. if (i >= num) {
  1127. kfree(_socket_to_pnode);
  1128. _socket_to_pnode = NULL;
  1129. pr_info("UV: 1:1 socket_to_pnode table removed\n");
  1130. }
  1131. }
  1132. }
  1133. static void __init uv_system_init_hub(void)
  1134. {
  1135. struct uv_hub_info_s hub_info = {0};
  1136. int bytes, cpu, nodeid;
  1137. unsigned short min_pnode = 9999, max_pnode = 0;
  1138. char *hub = is_uv4_hub() ? "UV400" :
  1139. is_uv3_hub() ? "UV300" :
  1140. is_uv2_hub() ? "UV2000/3000" :
  1141. is_uv1_hub() ? "UV100/1000" : NULL;
  1142. if (!hub) {
  1143. pr_err("UV: Unknown/unsupported UV hub\n");
  1144. return;
  1145. }
  1146. pr_info("UV: Found %s hub\n", hub);
  1147. map_low_mmrs();
  1148. /* Get uv_systab for decoding: */
  1149. uv_bios_init();
  1150. /* If there's an UVsystab problem then abort UV init: */
  1151. if (decode_uv_systab() < 0)
  1152. return;
  1153. build_socket_tables();
  1154. build_uv_gr_table();
  1155. uv_init_hub_info(&hub_info);
  1156. uv_possible_blades = num_possible_nodes();
  1157. if (!_node_to_pnode)
  1158. boot_init_possible_blades(&hub_info);
  1159. /* uv_num_possible_blades() is really the hub count: */
  1160. pr_info("UV: Found %d hubs, %d nodes, %d CPUs\n", uv_num_possible_blades(), num_possible_nodes(), num_possible_cpus());
  1161. uv_bios_get_sn_info(0, &uv_type, &sn_partition_id, &sn_coherency_id, &sn_region_size, &system_serial_number);
  1162. hub_info.coherency_domain_number = sn_coherency_id;
  1163. uv_rtc_init();
  1164. bytes = sizeof(void *) * uv_num_possible_blades();
  1165. __uv_hub_info_list = kzalloc(bytes, GFP_KERNEL);
  1166. BUG_ON(!__uv_hub_info_list);
  1167. bytes = sizeof(struct uv_hub_info_s);
  1168. for_each_node(nodeid) {
  1169. struct uv_hub_info_s *new_hub;
  1170. if (__uv_hub_info_list[nodeid]) {
  1171. pr_err("UV: Node %d UV HUB already initialized!?\n", nodeid);
  1172. BUG();
  1173. }
  1174. /* Allocate new per hub info list */
  1175. new_hub = (nodeid == 0) ? &uv_hub_info_node0 : kzalloc_node(bytes, GFP_KERNEL, nodeid);
  1176. BUG_ON(!new_hub);
  1177. __uv_hub_info_list[nodeid] = new_hub;
  1178. new_hub = uv_hub_info_list(nodeid);
  1179. BUG_ON(!new_hub);
  1180. *new_hub = hub_info;
  1181. /* Use information from GAM table if available: */
  1182. if (_node_to_pnode)
  1183. new_hub->pnode = _node_to_pnode[nodeid];
  1184. else /* Or fill in during CPU loop: */
  1185. new_hub->pnode = 0xffff;
  1186. new_hub->numa_blade_id = uv_node_to_blade_id(nodeid);
  1187. new_hub->memory_nid = -1;
  1188. new_hub->nr_possible_cpus = 0;
  1189. new_hub->nr_online_cpus = 0;
  1190. }
  1191. /* Initialize per CPU info: */
  1192. for_each_possible_cpu(cpu) {
  1193. int apicid = per_cpu(x86_cpu_to_apicid, cpu);
  1194. int numa_node_id;
  1195. unsigned short pnode;
  1196. nodeid = cpu_to_node(cpu);
  1197. numa_node_id = numa_cpu_node(cpu);
  1198. pnode = uv_apicid_to_pnode(apicid);
  1199. uv_cpu_info_per(cpu)->p_uv_hub_info = uv_hub_info_list(nodeid);
  1200. uv_cpu_info_per(cpu)->blade_cpu_id = uv_cpu_hub_info(cpu)->nr_possible_cpus++;
  1201. if (uv_cpu_hub_info(cpu)->memory_nid == -1)
  1202. uv_cpu_hub_info(cpu)->memory_nid = cpu_to_node(cpu);
  1203. /* Init memoryless node: */
  1204. if (nodeid != numa_node_id &&
  1205. uv_hub_info_list(numa_node_id)->pnode == 0xffff)
  1206. uv_hub_info_list(numa_node_id)->pnode = pnode;
  1207. else if (uv_cpu_hub_info(cpu)->pnode == 0xffff)
  1208. uv_cpu_hub_info(cpu)->pnode = pnode;
  1209. uv_cpu_scir_info(cpu)->offset = uv_scir_offset(apicid);
  1210. }
  1211. for_each_node(nodeid) {
  1212. unsigned short pnode = uv_hub_info_list(nodeid)->pnode;
  1213. /* Add pnode info for pre-GAM list nodes without CPUs: */
  1214. if (pnode == 0xffff) {
  1215. unsigned long paddr;
  1216. paddr = node_start_pfn(nodeid) << PAGE_SHIFT;
  1217. pnode = uv_gpa_to_pnode(uv_soc_phys_ram_to_gpa(paddr));
  1218. uv_hub_info_list(nodeid)->pnode = pnode;
  1219. }
  1220. min_pnode = min(pnode, min_pnode);
  1221. max_pnode = max(pnode, max_pnode);
  1222. pr_info("UV: UVHUB node:%2d pn:%02x nrcpus:%d\n",
  1223. nodeid,
  1224. uv_hub_info_list(nodeid)->pnode,
  1225. uv_hub_info_list(nodeid)->nr_possible_cpus);
  1226. }
  1227. pr_info("UV: min_pnode:%02x max_pnode:%02x\n", min_pnode, max_pnode);
  1228. map_gru_high(max_pnode);
  1229. map_mmr_high(max_pnode);
  1230. map_mmioh_high(min_pnode, max_pnode);
  1231. uv_nmi_setup();
  1232. uv_cpu_init();
  1233. uv_scir_register_cpu_notifier();
  1234. proc_mkdir("sgi_uv", NULL);
  1235. /* Register Legacy VGA I/O redirection handler: */
  1236. pci_register_set_vga_state(uv_set_vga_state);
  1237. /*
  1238. * For a kdump kernel the reset must be BOOT_ACPI, not BOOT_EFI, as
  1239. * EFI is not enabled in the kdump kernel:
  1240. */
  1241. if (is_kdump_kernel())
  1242. reboot_type = BOOT_ACPI;
  1243. }
  1244. /*
  1245. * There is a small amount of UV specific code needed to initialize a
  1246. * UV system that does not have a "UV HUB" (referred to as "hubless").
  1247. */
  1248. void __init uv_system_init(void)
  1249. {
  1250. if (likely(!is_uv_system() && !is_uv_hubless()))
  1251. return;
  1252. if (is_uv_system())
  1253. uv_system_init_hub();
  1254. else
  1255. uv_nmi_setup_hubless();
  1256. }
  1257. apic_driver(apic_x2apic_uv_x);