x2apic_uv_x.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523
  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_and(const struct cpumask *cpumask,
  442. const struct cpumask *andmask,
  443. unsigned int *apicid)
  444. {
  445. int unsigned cpu;
  446. /*
  447. * We're using fixed IRQ delivery, can only return one phys APIC ID.
  448. * May as well be the first.
  449. */
  450. for_each_cpu_and(cpu, cpumask, andmask) {
  451. if (cpumask_test_cpu(cpu, cpu_online_mask))
  452. break;
  453. }
  454. if (likely(cpu < nr_cpu_ids)) {
  455. *apicid = per_cpu(x86_cpu_to_apicid, cpu) | uv_apicid_hibits;
  456. return 0;
  457. }
  458. return -EINVAL;
  459. }
  460. static unsigned int x2apic_get_apic_id(unsigned long x)
  461. {
  462. unsigned int id;
  463. WARN_ON(preemptible() && num_online_cpus() > 1);
  464. id = x | __this_cpu_read(x2apic_extra_bits);
  465. return id;
  466. }
  467. static unsigned long set_apic_id(unsigned int id)
  468. {
  469. /* CHECKME: Do we need to mask out the xapic extra bits? */
  470. return id;
  471. }
  472. static unsigned int uv_read_apic_id(void)
  473. {
  474. return x2apic_get_apic_id(apic_read(APIC_ID));
  475. }
  476. static int uv_phys_pkg_id(int initial_apicid, int index_msb)
  477. {
  478. return uv_read_apic_id() >> index_msb;
  479. }
  480. static void uv_send_IPI_self(int vector)
  481. {
  482. apic_write(APIC_SELF_IPI, vector);
  483. }
  484. static int uv_probe(void)
  485. {
  486. return apic == &apic_x2apic_uv_x;
  487. }
  488. static struct apic apic_x2apic_uv_x __ro_after_init = {
  489. .name = "UV large system",
  490. .probe = uv_probe,
  491. .acpi_madt_oem_check = uv_acpi_madt_oem_check,
  492. .apic_id_valid = uv_apic_id_valid,
  493. .apic_id_registered = uv_apic_id_registered,
  494. .irq_delivery_mode = dest_Fixed,
  495. .irq_dest_mode = 0, /* Physical */
  496. .target_cpus = online_target_cpus,
  497. .disable_esr = 0,
  498. .dest_logical = APIC_DEST_LOGICAL,
  499. .check_apicid_used = NULL,
  500. .vector_allocation_domain = default_vector_allocation_domain,
  501. .init_apic_ldr = uv_init_apic_ldr,
  502. .ioapic_phys_id_map = NULL,
  503. .setup_apic_routing = NULL,
  504. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  505. .apicid_to_cpu_present = NULL,
  506. .check_phys_apicid_present = default_check_phys_apicid_present,
  507. .phys_pkg_id = uv_phys_pkg_id,
  508. .get_apic_id = x2apic_get_apic_id,
  509. .set_apic_id = set_apic_id,
  510. .cpu_mask_to_apicid_and = uv_cpu_mask_to_apicid_and,
  511. .send_IPI = uv_send_IPI_one,
  512. .send_IPI_mask = uv_send_IPI_mask,
  513. .send_IPI_mask_allbutself = uv_send_IPI_mask_allbutself,
  514. .send_IPI_allbutself = uv_send_IPI_allbutself,
  515. .send_IPI_all = uv_send_IPI_all,
  516. .send_IPI_self = uv_send_IPI_self,
  517. .wakeup_secondary_cpu = uv_wakeup_secondary,
  518. .inquire_remote_apic = NULL,
  519. .read = native_apic_msr_read,
  520. .write = native_apic_msr_write,
  521. .eoi_write = native_apic_msr_eoi_write,
  522. .icr_read = native_x2apic_icr_read,
  523. .icr_write = native_x2apic_icr_write,
  524. .wait_icr_idle = native_x2apic_wait_icr_idle,
  525. .safe_wait_icr_idle = native_safe_x2apic_wait_icr_idle,
  526. };
  527. static void set_x2apic_extra_bits(int pnode)
  528. {
  529. __this_cpu_write(x2apic_extra_bits, pnode << uvh_apicid.s.pnode_shift);
  530. }
  531. #define UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_LENGTH 3
  532. #define DEST_SHIFT UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR_DEST_BASE_SHFT
  533. static __init void get_lowmem_redirect(unsigned long *base, unsigned long *size)
  534. {
  535. union uvh_rh_gam_alias210_overlay_config_2_mmr_u alias;
  536. union uvh_rh_gam_alias210_redirect_config_2_mmr_u redirect;
  537. unsigned long m_redirect;
  538. unsigned long m_overlay;
  539. int i;
  540. for (i = 0; i < UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_LENGTH; i++) {
  541. switch (i) {
  542. case 0:
  543. m_redirect = UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR;
  544. m_overlay = UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_0_MMR;
  545. break;
  546. case 1:
  547. m_redirect = UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_1_MMR;
  548. m_overlay = UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_1_MMR;
  549. break;
  550. case 2:
  551. m_redirect = UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_2_MMR;
  552. m_overlay = UVH_RH_GAM_ALIAS210_OVERLAY_CONFIG_2_MMR;
  553. break;
  554. }
  555. alias.v = uv_read_local_mmr(m_overlay);
  556. if (alias.s.enable && alias.s.base == 0) {
  557. *size = (1UL << alias.s.m_alias);
  558. redirect.v = uv_read_local_mmr(m_redirect);
  559. *base = (unsigned long)redirect.s.dest_base << DEST_SHIFT;
  560. return;
  561. }
  562. }
  563. *base = *size = 0;
  564. }
  565. enum map_type {map_wb, map_uc};
  566. static __init void map_high(char *id, unsigned long base, int pshift, int bshift, int max_pnode, enum map_type map_type)
  567. {
  568. unsigned long bytes, paddr;
  569. paddr = base << pshift;
  570. bytes = (1UL << bshift) * (max_pnode + 1);
  571. if (!paddr) {
  572. pr_info("UV: Map %s_HI base address NULL\n", id);
  573. return;
  574. }
  575. pr_debug("UV: Map %s_HI 0x%lx - 0x%lx\n", id, paddr, paddr + bytes);
  576. if (map_type == map_uc)
  577. init_extra_mapping_uc(paddr, bytes);
  578. else
  579. init_extra_mapping_wb(paddr, bytes);
  580. }
  581. static __init void map_gru_distributed(unsigned long c)
  582. {
  583. union uvh_rh_gam_gru_overlay_config_mmr_u gru;
  584. u64 paddr;
  585. unsigned long bytes;
  586. int nid;
  587. gru.v = c;
  588. /* Only base bits 42:28 relevant in dist mode */
  589. gru_dist_base = gru.v & 0x000007fff0000000UL;
  590. if (!gru_dist_base) {
  591. pr_info("UV: Map GRU_DIST base address NULL\n");
  592. return;
  593. }
  594. bytes = 1UL << UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_BASE_SHFT;
  595. gru_dist_lmask = ((1UL << uv_hub_info->m_val) - 1) & ~(bytes - 1);
  596. gru_dist_umask = ~((1UL << uv_hub_info->m_val) - 1);
  597. gru_dist_base &= gru_dist_lmask; /* Clear bits above M */
  598. for_each_online_node(nid) {
  599. paddr = ((u64)uv_node_to_pnode(nid) << uv_hub_info->m_val) |
  600. gru_dist_base;
  601. init_extra_mapping_wb(paddr, bytes);
  602. gru_first_node_paddr = min(paddr, gru_first_node_paddr);
  603. gru_last_node_paddr = max(paddr, gru_last_node_paddr);
  604. }
  605. /* Save upper (63:M) bits of address only for is_GRU_range */
  606. gru_first_node_paddr &= gru_dist_umask;
  607. gru_last_node_paddr &= gru_dist_umask;
  608. 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);
  609. }
  610. static __init void map_gru_high(int max_pnode)
  611. {
  612. union uvh_rh_gam_gru_overlay_config_mmr_u gru;
  613. int shift = UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_BASE_SHFT;
  614. unsigned long mask = UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_BASE_MASK;
  615. unsigned long base;
  616. gru.v = uv_read_local_mmr(UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR);
  617. if (!gru.s.enable) {
  618. pr_info("UV: GRU disabled\n");
  619. return;
  620. }
  621. if (is_uv3_hub() && gru.s3.mode) {
  622. map_gru_distributed(gru.v);
  623. return;
  624. }
  625. base = (gru.v & mask) >> shift;
  626. map_high("GRU", base, shift, shift, max_pnode, map_wb);
  627. gru_start_paddr = ((u64)base << shift);
  628. gru_end_paddr = gru_start_paddr + (1UL << shift) * (max_pnode + 1);
  629. }
  630. static __init void map_mmr_high(int max_pnode)
  631. {
  632. union uvh_rh_gam_mmr_overlay_config_mmr_u mmr;
  633. int shift = UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR_BASE_SHFT;
  634. mmr.v = uv_read_local_mmr(UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR);
  635. if (mmr.s.enable)
  636. map_high("MMR", mmr.s.base, shift, shift, max_pnode, map_uc);
  637. else
  638. pr_info("UV: MMR disabled\n");
  639. }
  640. /*
  641. * This commonality works because both 0 & 1 versions of the MMIOH OVERLAY
  642. * and REDIRECT MMR regs are exactly the same on UV3.
  643. */
  644. struct mmioh_config {
  645. unsigned long overlay;
  646. unsigned long redirect;
  647. char *id;
  648. };
  649. static __initdata struct mmioh_config mmiohs[] = {
  650. {
  651. UV3H_RH_GAM_MMIOH_OVERLAY_CONFIG0_MMR,
  652. UV3H_RH_GAM_MMIOH_REDIRECT_CONFIG0_MMR,
  653. "MMIOH0"
  654. },
  655. {
  656. UV3H_RH_GAM_MMIOH_OVERLAY_CONFIG1_MMR,
  657. UV3H_RH_GAM_MMIOH_REDIRECT_CONFIG1_MMR,
  658. "MMIOH1"
  659. },
  660. };
  661. /* UV3 & UV4 have identical MMIOH overlay configs */
  662. static __init void map_mmioh_high_uv3(int index, int min_pnode, int max_pnode)
  663. {
  664. union uv3h_rh_gam_mmioh_overlay_config0_mmr_u overlay;
  665. unsigned long mmr;
  666. unsigned long base;
  667. int i, n, shift, m_io, max_io;
  668. int nasid, lnasid, fi, li;
  669. char *id;
  670. id = mmiohs[index].id;
  671. overlay.v = uv_read_local_mmr(mmiohs[index].overlay);
  672. pr_info("UV: %s overlay 0x%lx base:0x%x m_io:%d\n", id, overlay.v, overlay.s3.base, overlay.s3.m_io);
  673. if (!overlay.s3.enable) {
  674. pr_info("UV: %s disabled\n", id);
  675. return;
  676. }
  677. shift = UV3H_RH_GAM_MMIOH_OVERLAY_CONFIG0_MMR_BASE_SHFT;
  678. base = (unsigned long)overlay.s3.base;
  679. m_io = overlay.s3.m_io;
  680. mmr = mmiohs[index].redirect;
  681. n = UV3H_RH_GAM_MMIOH_REDIRECT_CONFIG0_MMR_DEPTH;
  682. /* Convert to NASID: */
  683. min_pnode *= 2;
  684. max_pnode *= 2;
  685. max_io = lnasid = fi = li = -1;
  686. for (i = 0; i < n; i++) {
  687. union uv3h_rh_gam_mmioh_redirect_config0_mmr_u redirect;
  688. redirect.v = uv_read_local_mmr(mmr + i * 8);
  689. nasid = redirect.s3.nasid;
  690. /* Invalid NASID: */
  691. if (nasid < min_pnode || max_pnode < nasid)
  692. nasid = -1;
  693. if (nasid == lnasid) {
  694. li = i;
  695. /* Last entry check: */
  696. if (i != n-1)
  697. continue;
  698. }
  699. /* Check if we have a cached (or last) redirect to print: */
  700. if (lnasid != -1 || (i == n-1 && nasid != -1)) {
  701. unsigned long addr1, addr2;
  702. int f, l;
  703. if (lnasid == -1) {
  704. f = l = i;
  705. lnasid = nasid;
  706. } else {
  707. f = fi;
  708. l = li;
  709. }
  710. addr1 = (base << shift) + f * (1ULL << m_io);
  711. addr2 = (base << shift) + (l + 1) * (1ULL << m_io);
  712. pr_info("UV: %s[%03d..%03d] NASID 0x%04x ADDR 0x%016lx - 0x%016lx\n", id, fi, li, lnasid, addr1, addr2);
  713. if (max_io < l)
  714. max_io = l;
  715. }
  716. fi = li = i;
  717. lnasid = nasid;
  718. }
  719. pr_info("UV: %s base:0x%lx shift:%d M_IO:%d MAX_IO:%d\n", id, base, shift, m_io, max_io);
  720. if (max_io >= 0)
  721. map_high(id, base, shift, m_io, max_io, map_uc);
  722. }
  723. static __init void map_mmioh_high(int min_pnode, int max_pnode)
  724. {
  725. union uvh_rh_gam_mmioh_overlay_config_mmr_u mmioh;
  726. unsigned long mmr, base;
  727. int shift, enable, m_io, n_io;
  728. if (is_uv3_hub() || is_uv4_hub()) {
  729. /* Map both MMIOH regions: */
  730. map_mmioh_high_uv3(0, min_pnode, max_pnode);
  731. map_mmioh_high_uv3(1, min_pnode, max_pnode);
  732. return;
  733. }
  734. if (is_uv1_hub()) {
  735. mmr = UV1H_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR;
  736. shift = UV1H_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_BASE_SHFT;
  737. mmioh.v = uv_read_local_mmr(mmr);
  738. enable = !!mmioh.s1.enable;
  739. base = mmioh.s1.base;
  740. m_io = mmioh.s1.m_io;
  741. n_io = mmioh.s1.n_io;
  742. } else if (is_uv2_hub()) {
  743. mmr = UV2H_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR;
  744. shift = UV2H_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_BASE_SHFT;
  745. mmioh.v = uv_read_local_mmr(mmr);
  746. enable = !!mmioh.s2.enable;
  747. base = mmioh.s2.base;
  748. m_io = mmioh.s2.m_io;
  749. n_io = mmioh.s2.n_io;
  750. } else {
  751. return;
  752. }
  753. if (enable) {
  754. max_pnode &= (1 << n_io) - 1;
  755. 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);
  756. map_high("MMIOH", base, shift, m_io, max_pnode, map_uc);
  757. } else {
  758. pr_info("UV: MMIOH disabled\n");
  759. }
  760. }
  761. static __init void map_low_mmrs(void)
  762. {
  763. init_extra_mapping_uc(UV_GLOBAL_MMR32_BASE, UV_GLOBAL_MMR32_SIZE);
  764. init_extra_mapping_uc(UV_LOCAL_MMR_BASE, UV_LOCAL_MMR_SIZE);
  765. }
  766. static __init void uv_rtc_init(void)
  767. {
  768. long status;
  769. u64 ticks_per_sec;
  770. status = uv_bios_freq_base(BIOS_FREQ_BASE_REALTIME_CLOCK, &ticks_per_sec);
  771. if (status != BIOS_STATUS_SUCCESS || ticks_per_sec < 100000) {
  772. pr_warn("UV: unable to determine platform RTC clock frequency, guessing.\n");
  773. /* BIOS gives wrong value for clock frequency, so guess: */
  774. sn_rtc_cycles_per_second = 1000000000000UL / 30000UL;
  775. } else {
  776. sn_rtc_cycles_per_second = ticks_per_sec;
  777. }
  778. }
  779. /*
  780. * percpu heartbeat timer
  781. */
  782. static void uv_heartbeat(unsigned long ignored)
  783. {
  784. struct timer_list *timer = &uv_scir_info->timer;
  785. unsigned char bits = uv_scir_info->state;
  786. /* Flip heartbeat bit: */
  787. bits ^= SCIR_CPU_HEARTBEAT;
  788. /* Is this CPU idle? */
  789. if (idle_cpu(raw_smp_processor_id()))
  790. bits &= ~SCIR_CPU_ACTIVITY;
  791. else
  792. bits |= SCIR_CPU_ACTIVITY;
  793. /* Update system controller interface reg: */
  794. uv_set_scir_bits(bits);
  795. /* Enable next timer period: */
  796. mod_timer(timer, jiffies + SCIR_CPU_HB_INTERVAL);
  797. }
  798. static int uv_heartbeat_enable(unsigned int cpu)
  799. {
  800. while (!uv_cpu_scir_info(cpu)->enabled) {
  801. struct timer_list *timer = &uv_cpu_scir_info(cpu)->timer;
  802. uv_set_cpu_scir_bits(cpu, SCIR_CPU_HEARTBEAT|SCIR_CPU_ACTIVITY);
  803. setup_pinned_timer(timer, uv_heartbeat, cpu);
  804. timer->expires = jiffies + SCIR_CPU_HB_INTERVAL;
  805. add_timer_on(timer, cpu);
  806. uv_cpu_scir_info(cpu)->enabled = 1;
  807. /* Also ensure that boot CPU is enabled: */
  808. cpu = 0;
  809. }
  810. return 0;
  811. }
  812. #ifdef CONFIG_HOTPLUG_CPU
  813. static int uv_heartbeat_disable(unsigned int cpu)
  814. {
  815. if (uv_cpu_scir_info(cpu)->enabled) {
  816. uv_cpu_scir_info(cpu)->enabled = 0;
  817. del_timer(&uv_cpu_scir_info(cpu)->timer);
  818. }
  819. uv_set_cpu_scir_bits(cpu, 0xff);
  820. return 0;
  821. }
  822. static __init void uv_scir_register_cpu_notifier(void)
  823. {
  824. cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "x86/x2apic-uvx:online",
  825. uv_heartbeat_enable, uv_heartbeat_disable);
  826. }
  827. #else /* !CONFIG_HOTPLUG_CPU */
  828. static __init void uv_scir_register_cpu_notifier(void)
  829. {
  830. }
  831. static __init int uv_init_heartbeat(void)
  832. {
  833. int cpu;
  834. if (is_uv_system()) {
  835. for_each_online_cpu(cpu)
  836. uv_heartbeat_enable(cpu);
  837. }
  838. return 0;
  839. }
  840. late_initcall(uv_init_heartbeat);
  841. #endif /* !CONFIG_HOTPLUG_CPU */
  842. /* Direct Legacy VGA I/O traffic to designated IOH */
  843. int uv_set_vga_state(struct pci_dev *pdev, bool decode, unsigned int command_bits, u32 flags)
  844. {
  845. int domain, bus, rc;
  846. if (!(flags & PCI_VGA_STATE_CHANGE_BRIDGE))
  847. return 0;
  848. if ((command_bits & PCI_COMMAND_IO) == 0)
  849. return 0;
  850. domain = pci_domain_nr(pdev->bus);
  851. bus = pdev->bus->number;
  852. rc = uv_bios_set_legacy_vga_target(decode, domain, bus);
  853. return rc;
  854. }
  855. /*
  856. * Called on each CPU to initialize the per_cpu UV data area.
  857. * FIXME: hotplug not supported yet
  858. */
  859. void uv_cpu_init(void)
  860. {
  861. /* CPU 0 initialization will be done via uv_system_init. */
  862. if (smp_processor_id() == 0)
  863. return;
  864. uv_hub_info->nr_online_cpus++;
  865. if (get_uv_system_type() == UV_NON_UNIQUE_APIC)
  866. set_x2apic_extra_bits(uv_hub_info->pnode);
  867. }
  868. struct mn {
  869. unsigned char m_val;
  870. unsigned char n_val;
  871. unsigned char m_shift;
  872. unsigned char n_lshift;
  873. };
  874. static void get_mn(struct mn *mnp)
  875. {
  876. union uvh_rh_gam_config_mmr_u m_n_config;
  877. union uv3h_gr0_gam_gr_config_u m_gr_config;
  878. /* Make sure the whole structure is well initialized: */
  879. memset(mnp, 0, sizeof(*mnp));
  880. m_n_config.v = uv_read_local_mmr(UVH_RH_GAM_CONFIG_MMR);
  881. mnp->n_val = m_n_config.s.n_skt;
  882. if (is_uv4_hub()) {
  883. mnp->m_val = 0;
  884. mnp->n_lshift = 0;
  885. } else if (is_uv3_hub()) {
  886. mnp->m_val = m_n_config.s3.m_skt;
  887. m_gr_config.v = uv_read_local_mmr(UV3H_GR0_GAM_GR_CONFIG);
  888. mnp->n_lshift = m_gr_config.s3.m_skt;
  889. } else if (is_uv2_hub()) {
  890. mnp->m_val = m_n_config.s2.m_skt;
  891. mnp->n_lshift = mnp->m_val == 40 ? 40 : 39;
  892. } else if (is_uv1_hub()) {
  893. mnp->m_val = m_n_config.s1.m_skt;
  894. mnp->n_lshift = mnp->m_val;
  895. }
  896. mnp->m_shift = mnp->m_val ? 64 - mnp->m_val : 0;
  897. }
  898. void __init uv_init_hub_info(struct uv_hub_info_s *hi)
  899. {
  900. union uvh_node_id_u node_id;
  901. struct mn mn;
  902. get_mn(&mn);
  903. hi->gpa_mask = mn.m_val ?
  904. (1UL << (mn.m_val + mn.n_val)) - 1 :
  905. (1UL << uv_cpuid.gpa_shift) - 1;
  906. hi->m_val = mn.m_val;
  907. hi->n_val = mn.n_val;
  908. hi->m_shift = mn.m_shift;
  909. hi->n_lshift = mn.n_lshift ? mn.n_lshift : 0;
  910. hi->hub_revision = uv_hub_info->hub_revision;
  911. hi->pnode_mask = uv_cpuid.pnode_mask;
  912. hi->min_pnode = _min_pnode;
  913. hi->min_socket = _min_socket;
  914. hi->pnode_to_socket = _pnode_to_socket;
  915. hi->socket_to_node = _socket_to_node;
  916. hi->socket_to_pnode = _socket_to_pnode;
  917. hi->gr_table_len = _gr_table_len;
  918. hi->gr_table = _gr_table;
  919. node_id.v = uv_read_local_mmr(UVH_NODE_ID);
  920. uv_cpuid.gnode_shift = max_t(unsigned int, uv_cpuid.gnode_shift, mn.n_val);
  921. hi->gnode_extra = (node_id.s.node_id & ~((1 << uv_cpuid.gnode_shift) - 1)) >> 1;
  922. if (mn.m_val)
  923. hi->gnode_upper = (u64)hi->gnode_extra << mn.m_val;
  924. if (uv_gp_table) {
  925. hi->global_mmr_base = uv_gp_table->mmr_base;
  926. hi->global_mmr_shift = uv_gp_table->mmr_shift;
  927. hi->global_gru_base = uv_gp_table->gru_base;
  928. hi->global_gru_shift = uv_gp_table->gru_shift;
  929. hi->gpa_shift = uv_gp_table->gpa_shift;
  930. hi->gpa_mask = (1UL << hi->gpa_shift) - 1;
  931. } else {
  932. hi->global_mmr_base = uv_read_local_mmr(UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR) & ~UV_MMR_ENABLE;
  933. hi->global_mmr_shift = _UV_GLOBAL_MMR64_PNODE_SHIFT;
  934. }
  935. get_lowmem_redirect(&hi->lowmem_remap_base, &hi->lowmem_remap_top);
  936. hi->apic_pnode_shift = uv_cpuid.socketid_shift;
  937. /* Show system specific info: */
  938. 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);
  939. 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);
  940. 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);
  941. pr_info("UV: gnode_upper:0x%lx gnode_extra:0x%x\n", hi->gnode_upper, hi->gnode_extra);
  942. }
  943. static void __init decode_gam_params(unsigned long ptr)
  944. {
  945. uv_gp_table = (struct uv_gam_parameters *)ptr;
  946. pr_info("UV: GAM Params...\n");
  947. pr_info("UV: mmr_base/shift:0x%llx/%d gru_base/shift:0x%llx/%d gpa_shift:%d\n",
  948. uv_gp_table->mmr_base, uv_gp_table->mmr_shift,
  949. uv_gp_table->gru_base, uv_gp_table->gru_shift,
  950. uv_gp_table->gpa_shift);
  951. }
  952. static void __init decode_gam_rng_tbl(unsigned long ptr)
  953. {
  954. struct uv_gam_range_entry *gre = (struct uv_gam_range_entry *)ptr;
  955. unsigned long lgre = 0;
  956. int index = 0;
  957. int sock_min = 999999, pnode_min = 99999;
  958. int sock_max = -1, pnode_max = -1;
  959. uv_gre_table = gre;
  960. for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) {
  961. if (!index) {
  962. pr_info("UV: GAM Range Table...\n");
  963. pr_info("UV: # %20s %14s %5s %4s %5s %3s %2s\n", "Range", "", "Size", "Type", "NASID", "SID", "PN");
  964. }
  965. pr_info("UV: %2d: 0x%014lx-0x%014lx %5luG %3d %04x %02x %02x\n",
  966. index++,
  967. (unsigned long)lgre << UV_GAM_RANGE_SHFT,
  968. (unsigned long)gre->limit << UV_GAM_RANGE_SHFT,
  969. ((unsigned long)(gre->limit - lgre)) >>
  970. (30 - UV_GAM_RANGE_SHFT), /* 64M -> 1G */
  971. gre->type, gre->nasid, gre->sockid, gre->pnode);
  972. lgre = gre->limit;
  973. if (sock_min > gre->sockid)
  974. sock_min = gre->sockid;
  975. if (sock_max < gre->sockid)
  976. sock_max = gre->sockid;
  977. if (pnode_min > gre->pnode)
  978. pnode_min = gre->pnode;
  979. if (pnode_max < gre->pnode)
  980. pnode_max = gre->pnode;
  981. }
  982. _min_socket = sock_min;
  983. _max_socket = sock_max;
  984. _min_pnode = pnode_min;
  985. _max_pnode = pnode_max;
  986. _gr_table_len = index;
  987. 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);
  988. }
  989. static int __init decode_uv_systab(void)
  990. {
  991. struct uv_systab *st;
  992. int i;
  993. if (uv_hub_info->hub_revision < UV4_HUB_REVISION_BASE)
  994. return 0; /* No extended UVsystab required */
  995. st = uv_systab;
  996. if ((!st) || (st->revision < UV_SYSTAB_VERSION_UV4_LATEST)) {
  997. int rev = st ? st->revision : 0;
  998. pr_err("UV: BIOS UVsystab version(%x) mismatch, expecting(%x)\n", rev, UV_SYSTAB_VERSION_UV4_LATEST);
  999. pr_err("UV: Cannot support UV operations, switching to generic PC\n");
  1000. uv_system_type = UV_NONE;
  1001. return -EINVAL;
  1002. }
  1003. for (i = 0; st->entry[i].type != UV_SYSTAB_TYPE_UNUSED; i++) {
  1004. unsigned long ptr = st->entry[i].offset;
  1005. if (!ptr)
  1006. continue;
  1007. ptr = ptr + (unsigned long)st;
  1008. switch (st->entry[i].type) {
  1009. case UV_SYSTAB_TYPE_GAM_PARAMS:
  1010. decode_gam_params(ptr);
  1011. break;
  1012. case UV_SYSTAB_TYPE_GAM_RNG_TBL:
  1013. decode_gam_rng_tbl(ptr);
  1014. break;
  1015. }
  1016. }
  1017. return 0;
  1018. }
  1019. /*
  1020. * Set up physical blade translations from UVH_NODE_PRESENT_TABLE
  1021. * .. NB: UVH_NODE_PRESENT_TABLE is going away,
  1022. * .. being replaced by GAM Range Table
  1023. */
  1024. static __init void boot_init_possible_blades(struct uv_hub_info_s *hub_info)
  1025. {
  1026. int i, uv_pb = 0;
  1027. pr_info("UV: NODE_PRESENT_DEPTH = %d\n", UVH_NODE_PRESENT_TABLE_DEPTH);
  1028. for (i = 0; i < UVH_NODE_PRESENT_TABLE_DEPTH; i++) {
  1029. unsigned long np;
  1030. np = uv_read_local_mmr(UVH_NODE_PRESENT_TABLE + i * 8);
  1031. if (np)
  1032. pr_info("UV: NODE_PRESENT(%d) = 0x%016lx\n", i, np);
  1033. uv_pb += hweight64(np);
  1034. }
  1035. if (uv_possible_blades != uv_pb)
  1036. uv_possible_blades = uv_pb;
  1037. }
  1038. static void __init build_socket_tables(void)
  1039. {
  1040. struct uv_gam_range_entry *gre = uv_gre_table;
  1041. int num, nump;
  1042. int cpu, i, lnid;
  1043. int minsock = _min_socket;
  1044. int maxsock = _max_socket;
  1045. int minpnode = _min_pnode;
  1046. int maxpnode = _max_pnode;
  1047. size_t bytes;
  1048. if (!gre) {
  1049. if (is_uv1_hub() || is_uv2_hub() || is_uv3_hub()) {
  1050. pr_info("UV: No UVsystab socket table, ignoring\n");
  1051. return;
  1052. }
  1053. pr_crit("UV: Error: UVsystab address translations not available!\n");
  1054. BUG();
  1055. }
  1056. /* Build socket id -> node id, pnode */
  1057. num = maxsock - minsock + 1;
  1058. bytes = num * sizeof(_socket_to_node[0]);
  1059. _socket_to_node = kmalloc(bytes, GFP_KERNEL);
  1060. _socket_to_pnode = kmalloc(bytes, GFP_KERNEL);
  1061. nump = maxpnode - minpnode + 1;
  1062. bytes = nump * sizeof(_pnode_to_socket[0]);
  1063. _pnode_to_socket = kmalloc(bytes, GFP_KERNEL);
  1064. BUG_ON(!_socket_to_node || !_socket_to_pnode || !_pnode_to_socket);
  1065. for (i = 0; i < num; i++)
  1066. _socket_to_node[i] = _socket_to_pnode[i] = SOCK_EMPTY;
  1067. for (i = 0; i < nump; i++)
  1068. _pnode_to_socket[i] = SOCK_EMPTY;
  1069. /* Fill in pnode/node/addr conversion list values: */
  1070. pr_info("UV: GAM Building socket/pnode conversion tables\n");
  1071. for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) {
  1072. if (gre->type == UV_GAM_RANGE_TYPE_HOLE)
  1073. continue;
  1074. i = gre->sockid - minsock;
  1075. /* Duplicate: */
  1076. if (_socket_to_pnode[i] != SOCK_EMPTY)
  1077. continue;
  1078. _socket_to_pnode[i] = gre->pnode;
  1079. i = gre->pnode - minpnode;
  1080. _pnode_to_socket[i] = gre->sockid;
  1081. pr_info("UV: sid:%02x type:%d nasid:%04x pn:%02x pn2s:%2x\n",
  1082. gre->sockid, gre->type, gre->nasid,
  1083. _socket_to_pnode[gre->sockid - minsock],
  1084. _pnode_to_socket[gre->pnode - minpnode]);
  1085. }
  1086. /* Set socket -> node values: */
  1087. lnid = -1;
  1088. for_each_present_cpu(cpu) {
  1089. int nid = cpu_to_node(cpu);
  1090. int apicid, sockid;
  1091. if (lnid == nid)
  1092. continue;
  1093. lnid = nid;
  1094. apicid = per_cpu(x86_cpu_to_apicid, cpu);
  1095. sockid = apicid >> uv_cpuid.socketid_shift;
  1096. _socket_to_node[sockid - minsock] = nid;
  1097. pr_info("UV: sid:%02x: apicid:%04x node:%2d\n",
  1098. sockid, apicid, nid);
  1099. }
  1100. /* Set up physical blade to pnode translation from GAM Range Table: */
  1101. bytes = num_possible_nodes() * sizeof(_node_to_pnode[0]);
  1102. _node_to_pnode = kmalloc(bytes, GFP_KERNEL);
  1103. BUG_ON(!_node_to_pnode);
  1104. for (lnid = 0; lnid < num_possible_nodes(); lnid++) {
  1105. unsigned short sockid;
  1106. for (sockid = minsock; sockid <= maxsock; sockid++) {
  1107. if (lnid == _socket_to_node[sockid - minsock]) {
  1108. _node_to_pnode[lnid] = _socket_to_pnode[sockid - minsock];
  1109. break;
  1110. }
  1111. }
  1112. if (sockid > maxsock) {
  1113. pr_err("UV: socket for node %d not found!\n", lnid);
  1114. BUG();
  1115. }
  1116. }
  1117. /*
  1118. * If socket id == pnode or socket id == node for all nodes,
  1119. * system runs faster by removing corresponding conversion table.
  1120. */
  1121. pr_info("UV: Checking socket->node/pnode for identity maps\n");
  1122. if (minsock == 0) {
  1123. for (i = 0; i < num; i++)
  1124. if (_socket_to_node[i] == SOCK_EMPTY || i != _socket_to_node[i])
  1125. break;
  1126. if (i >= num) {
  1127. kfree(_socket_to_node);
  1128. _socket_to_node = NULL;
  1129. pr_info("UV: 1:1 socket_to_node table removed\n");
  1130. }
  1131. }
  1132. if (minsock == minpnode) {
  1133. for (i = 0; i < num; i++)
  1134. if (_socket_to_pnode[i] != SOCK_EMPTY &&
  1135. _socket_to_pnode[i] != i + minpnode)
  1136. break;
  1137. if (i >= num) {
  1138. kfree(_socket_to_pnode);
  1139. _socket_to_pnode = NULL;
  1140. pr_info("UV: 1:1 socket_to_pnode table removed\n");
  1141. }
  1142. }
  1143. }
  1144. static void __init uv_system_init_hub(void)
  1145. {
  1146. struct uv_hub_info_s hub_info = {0};
  1147. int bytes, cpu, nodeid;
  1148. unsigned short min_pnode = 9999, max_pnode = 0;
  1149. char *hub = is_uv4_hub() ? "UV400" :
  1150. is_uv3_hub() ? "UV300" :
  1151. is_uv2_hub() ? "UV2000/3000" :
  1152. is_uv1_hub() ? "UV100/1000" : NULL;
  1153. if (!hub) {
  1154. pr_err("UV: Unknown/unsupported UV hub\n");
  1155. return;
  1156. }
  1157. pr_info("UV: Found %s hub\n", hub);
  1158. map_low_mmrs();
  1159. /* Get uv_systab for decoding: */
  1160. uv_bios_init();
  1161. /* If there's an UVsystab problem then abort UV init: */
  1162. if (decode_uv_systab() < 0)
  1163. return;
  1164. build_socket_tables();
  1165. build_uv_gr_table();
  1166. uv_init_hub_info(&hub_info);
  1167. uv_possible_blades = num_possible_nodes();
  1168. if (!_node_to_pnode)
  1169. boot_init_possible_blades(&hub_info);
  1170. /* uv_num_possible_blades() is really the hub count: */
  1171. pr_info("UV: Found %d hubs, %d nodes, %d CPUs\n", uv_num_possible_blades(), num_possible_nodes(), num_possible_cpus());
  1172. uv_bios_get_sn_info(0, &uv_type, &sn_partition_id, &sn_coherency_id, &sn_region_size, &system_serial_number);
  1173. hub_info.coherency_domain_number = sn_coherency_id;
  1174. uv_rtc_init();
  1175. bytes = sizeof(void *) * uv_num_possible_blades();
  1176. __uv_hub_info_list = kzalloc(bytes, GFP_KERNEL);
  1177. BUG_ON(!__uv_hub_info_list);
  1178. bytes = sizeof(struct uv_hub_info_s);
  1179. for_each_node(nodeid) {
  1180. struct uv_hub_info_s *new_hub;
  1181. if (__uv_hub_info_list[nodeid]) {
  1182. pr_err("UV: Node %d UV HUB already initialized!?\n", nodeid);
  1183. BUG();
  1184. }
  1185. /* Allocate new per hub info list */
  1186. new_hub = (nodeid == 0) ? &uv_hub_info_node0 : kzalloc_node(bytes, GFP_KERNEL, nodeid);
  1187. BUG_ON(!new_hub);
  1188. __uv_hub_info_list[nodeid] = new_hub;
  1189. new_hub = uv_hub_info_list(nodeid);
  1190. BUG_ON(!new_hub);
  1191. *new_hub = hub_info;
  1192. /* Use information from GAM table if available: */
  1193. if (_node_to_pnode)
  1194. new_hub->pnode = _node_to_pnode[nodeid];
  1195. else /* Or fill in during CPU loop: */
  1196. new_hub->pnode = 0xffff;
  1197. new_hub->numa_blade_id = uv_node_to_blade_id(nodeid);
  1198. new_hub->memory_nid = -1;
  1199. new_hub->nr_possible_cpus = 0;
  1200. new_hub->nr_online_cpus = 0;
  1201. }
  1202. /* Initialize per CPU info: */
  1203. for_each_possible_cpu(cpu) {
  1204. int apicid = per_cpu(x86_cpu_to_apicid, cpu);
  1205. int numa_node_id;
  1206. unsigned short pnode;
  1207. nodeid = cpu_to_node(cpu);
  1208. numa_node_id = numa_cpu_node(cpu);
  1209. pnode = uv_apicid_to_pnode(apicid);
  1210. uv_cpu_info_per(cpu)->p_uv_hub_info = uv_hub_info_list(nodeid);
  1211. uv_cpu_info_per(cpu)->blade_cpu_id = uv_cpu_hub_info(cpu)->nr_possible_cpus++;
  1212. if (uv_cpu_hub_info(cpu)->memory_nid == -1)
  1213. uv_cpu_hub_info(cpu)->memory_nid = cpu_to_node(cpu);
  1214. /* Init memoryless node: */
  1215. if (nodeid != numa_node_id &&
  1216. uv_hub_info_list(numa_node_id)->pnode == 0xffff)
  1217. uv_hub_info_list(numa_node_id)->pnode = pnode;
  1218. else if (uv_cpu_hub_info(cpu)->pnode == 0xffff)
  1219. uv_cpu_hub_info(cpu)->pnode = pnode;
  1220. uv_cpu_scir_info(cpu)->offset = uv_scir_offset(apicid);
  1221. }
  1222. for_each_node(nodeid) {
  1223. unsigned short pnode = uv_hub_info_list(nodeid)->pnode;
  1224. /* Add pnode info for pre-GAM list nodes without CPUs: */
  1225. if (pnode == 0xffff) {
  1226. unsigned long paddr;
  1227. paddr = node_start_pfn(nodeid) << PAGE_SHIFT;
  1228. pnode = uv_gpa_to_pnode(uv_soc_phys_ram_to_gpa(paddr));
  1229. uv_hub_info_list(nodeid)->pnode = pnode;
  1230. }
  1231. min_pnode = min(pnode, min_pnode);
  1232. max_pnode = max(pnode, max_pnode);
  1233. pr_info("UV: UVHUB node:%2d pn:%02x nrcpus:%d\n",
  1234. nodeid,
  1235. uv_hub_info_list(nodeid)->pnode,
  1236. uv_hub_info_list(nodeid)->nr_possible_cpus);
  1237. }
  1238. pr_info("UV: min_pnode:%02x max_pnode:%02x\n", min_pnode, max_pnode);
  1239. map_gru_high(max_pnode);
  1240. map_mmr_high(max_pnode);
  1241. map_mmioh_high(min_pnode, max_pnode);
  1242. uv_nmi_setup();
  1243. uv_cpu_init();
  1244. uv_scir_register_cpu_notifier();
  1245. proc_mkdir("sgi_uv", NULL);
  1246. /* Register Legacy VGA I/O redirection handler: */
  1247. pci_register_set_vga_state(uv_set_vga_state);
  1248. /*
  1249. * For a kdump kernel the reset must be BOOT_ACPI, not BOOT_EFI, as
  1250. * EFI is not enabled in the kdump kernel:
  1251. */
  1252. if (is_kdump_kernel())
  1253. reboot_type = BOOT_ACPI;
  1254. }
  1255. /*
  1256. * There is a small amount of UV specific code needed to initialize a
  1257. * UV system that does not have a "UV HUB" (referred to as "hubless").
  1258. */
  1259. void __init uv_system_init(void)
  1260. {
  1261. if (likely(!is_uv_system() && !is_uv_hubless()))
  1262. return;
  1263. if (is_uv_system())
  1264. uv_system_init_hub();
  1265. else
  1266. uv_nmi_setup_hubless();
  1267. }
  1268. apic_driver(apic_x2apic_uv_x);