x2apic_uv_x.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820
  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. * (C) Copyright 2020 Hewlett Packard Enterprise Development LP
  9. * Copyright (C) 2007-2014 Silicon Graphics, Inc. All rights reserved.
  10. */
  11. #include <linux/crash_dump.h>
  12. #include <linux/cpuhotplug.h>
  13. #include <linux/cpumask.h>
  14. #include <linux/proc_fs.h>
  15. #include <linux/memory.h>
  16. #include <linux/export.h>
  17. #include <linux/pci.h>
  18. #include <linux/acpi.h>
  19. #include <linux/efi.h>
  20. #include <asm/e820/api.h>
  21. #include <asm/uv/uv_mmrs.h>
  22. #include <asm/uv/uv_hub.h>
  23. #include <asm/uv/bios.h>
  24. #include <asm/uv/uv.h>
  25. #include <asm/apic.h>
  26. #include "local.h"
  27. static enum uv_system_type uv_system_type;
  28. static int uv_hubbed_system;
  29. static int uv_hubless_system;
  30. static u64 gru_start_paddr, gru_end_paddr;
  31. static union uvh_apicid uvh_apicid;
  32. static int uv_node_id;
  33. /* Unpack AT/OEM/TABLE ID's to be NULL terminated strings */
  34. static u8 uv_archtype[UV_AT_SIZE + 1];
  35. static u8 oem_id[ACPI_OEM_ID_SIZE + 1];
  36. static u8 oem_table_id[ACPI_OEM_TABLE_ID_SIZE + 1];
  37. /* Information derived from CPUID and some UV MMRs */
  38. static struct {
  39. unsigned int apicid_shift;
  40. unsigned int apicid_mask;
  41. unsigned int socketid_shift; /* aka pnode_shift for UV2/3 */
  42. unsigned int pnode_mask;
  43. unsigned int nasid_shift;
  44. unsigned int gpa_shift;
  45. unsigned int gnode_shift;
  46. unsigned int m_skt;
  47. unsigned int n_skt;
  48. } uv_cpuid;
  49. static int uv_min_hub_revision_id;
  50. static struct apic apic_x2apic_uv_x;
  51. static struct uv_hub_info_s uv_hub_info_node0;
  52. /* Set this to use hardware error handler instead of kernel panic: */
  53. static int disable_uv_undefined_panic = 1;
  54. unsigned long uv_undefined(char *str)
  55. {
  56. if (likely(!disable_uv_undefined_panic))
  57. panic("UV: error: undefined MMR: %s\n", str);
  58. else
  59. pr_crit("UV: error: undefined MMR: %s\n", str);
  60. /* Cause a machine fault: */
  61. return ~0ul;
  62. }
  63. EXPORT_SYMBOL(uv_undefined);
  64. static unsigned long __init uv_early_read_mmr(unsigned long addr)
  65. {
  66. unsigned long val, *mmr;
  67. mmr = early_ioremap(UV_LOCAL_MMR_BASE | addr, sizeof(*mmr));
  68. val = *mmr;
  69. early_iounmap(mmr, sizeof(*mmr));
  70. return val;
  71. }
  72. static inline bool is_GRU_range(u64 start, u64 end)
  73. {
  74. if (!gru_start_paddr)
  75. return false;
  76. return start >= gru_start_paddr && end <= gru_end_paddr;
  77. }
  78. static bool uv_is_untracked_pat_range(u64 start, u64 end)
  79. {
  80. return is_ISA_range(start, end) || is_GRU_range(start, end);
  81. }
  82. static void __init early_get_pnodeid(void)
  83. {
  84. int pnode;
  85. uv_cpuid.m_skt = 0;
  86. if (UVH_RH10_GAM_ADDR_MAP_CONFIG) {
  87. union uvh_rh10_gam_addr_map_config_u m_n_config;
  88. m_n_config.v = uv_early_read_mmr(UVH_RH10_GAM_ADDR_MAP_CONFIG);
  89. uv_cpuid.n_skt = m_n_config.s.n_skt;
  90. uv_cpuid.nasid_shift = 0;
  91. } else if (UVH_RH_GAM_ADDR_MAP_CONFIG) {
  92. union uvh_rh_gam_addr_map_config_u m_n_config;
  93. m_n_config.v = uv_early_read_mmr(UVH_RH_GAM_ADDR_MAP_CONFIG);
  94. uv_cpuid.n_skt = m_n_config.s.n_skt;
  95. if (is_uv(UV3))
  96. uv_cpuid.m_skt = m_n_config.s3.m_skt;
  97. if (is_uv(UV2))
  98. uv_cpuid.m_skt = m_n_config.s2.m_skt;
  99. uv_cpuid.nasid_shift = 1;
  100. } else {
  101. unsigned long GAM_ADDR_MAP_CONFIG = 0;
  102. WARN(GAM_ADDR_MAP_CONFIG == 0,
  103. "UV: WARN: GAM_ADDR_MAP_CONFIG is not available\n");
  104. uv_cpuid.n_skt = 0;
  105. uv_cpuid.nasid_shift = 0;
  106. }
  107. if (is_uv(UV4|UVY))
  108. uv_cpuid.gnode_shift = 2; /* min partition is 4 sockets */
  109. uv_cpuid.pnode_mask = (1 << uv_cpuid.n_skt) - 1;
  110. pnode = (uv_node_id >> uv_cpuid.nasid_shift) & uv_cpuid.pnode_mask;
  111. uv_cpuid.gpa_shift = 46; /* Default unless changed */
  112. pr_info("UV: n_skt:%d pnmsk:%x pn:%x\n",
  113. uv_cpuid.n_skt, uv_cpuid.pnode_mask, pnode);
  114. }
  115. /* Running on a UV Hubbed system, determine which UV Hub Type it is */
  116. static int __init early_set_hub_type(void)
  117. {
  118. union uvh_node_id_u node_id;
  119. /*
  120. * The NODE_ID MMR is always at offset 0.
  121. * Contains the chip part # + revision.
  122. * Node_id field started with 15 bits,
  123. * ... now 7 but upper 8 are masked to 0.
  124. * All blades/nodes have the same part # and hub revision.
  125. */
  126. node_id.v = uv_early_read_mmr(UVH_NODE_ID);
  127. uv_node_id = node_id.sx.node_id;
  128. switch (node_id.s.part_number) {
  129. case UV5_HUB_PART_NUMBER:
  130. uv_min_hub_revision_id = node_id.s.revision
  131. + UV5_HUB_REVISION_BASE;
  132. uv_hub_type_set(UV5);
  133. break;
  134. /* UV4/4A only have a revision difference */
  135. case UV4_HUB_PART_NUMBER:
  136. uv_min_hub_revision_id = node_id.s.revision
  137. + UV4_HUB_REVISION_BASE - 1;
  138. uv_hub_type_set(UV4);
  139. if (uv_min_hub_revision_id == UV4A_HUB_REVISION_BASE)
  140. uv_hub_type_set(UV4|UV4A);
  141. break;
  142. case UV3_HUB_PART_NUMBER:
  143. case UV3_HUB_PART_NUMBER_X:
  144. uv_min_hub_revision_id = node_id.s.revision
  145. + UV3_HUB_REVISION_BASE;
  146. uv_hub_type_set(UV3);
  147. break;
  148. case UV2_HUB_PART_NUMBER:
  149. case UV2_HUB_PART_NUMBER_X:
  150. uv_min_hub_revision_id = node_id.s.revision
  151. + UV2_HUB_REVISION_BASE - 1;
  152. uv_hub_type_set(UV2);
  153. break;
  154. default:
  155. return 0;
  156. }
  157. pr_info("UV: part#:%x rev:%d rev_id:%d UVtype:0x%x\n",
  158. node_id.s.part_number, node_id.s.revision,
  159. uv_min_hub_revision_id, is_uv(~0));
  160. return 1;
  161. }
  162. static void __init uv_tsc_check_sync(void)
  163. {
  164. u64 mmr;
  165. int sync_state;
  166. int mmr_shift;
  167. char *state;
  168. /* UV5 guarantees synced TSCs; do not zero TSC_ADJUST */
  169. if (!is_uv(UV2|UV3|UV4)) {
  170. mark_tsc_async_resets("UV5+");
  171. return;
  172. }
  173. /* UV2,3,4, UV BIOS TSC sync state available */
  174. mmr = uv_early_read_mmr(UVH_TSC_SYNC_MMR);
  175. mmr_shift =
  176. is_uv2_hub() ? UVH_TSC_SYNC_SHIFT_UV2K : UVH_TSC_SYNC_SHIFT;
  177. sync_state = (mmr >> mmr_shift) & UVH_TSC_SYNC_MASK;
  178. /* Check if TSC is valid for all sockets */
  179. switch (sync_state) {
  180. case UVH_TSC_SYNC_VALID:
  181. state = "in sync";
  182. mark_tsc_async_resets("UV BIOS");
  183. break;
  184. /* If BIOS state unknown, don't do anything */
  185. case UVH_TSC_SYNC_UNKNOWN:
  186. state = "unknown";
  187. break;
  188. /* Otherwise, BIOS indicates problem with TSC */
  189. default:
  190. state = "unstable";
  191. mark_tsc_unstable("UV BIOS");
  192. break;
  193. }
  194. pr_info("UV: TSC sync state from BIOS:0%d(%s)\n", sync_state, state);
  195. }
  196. /* Selector for (4|4A|5) structs */
  197. #define uvxy_field(sname, field, undef) ( \
  198. is_uv(UV4A) ? sname.s4a.field : \
  199. is_uv(UV4) ? sname.s4.field : \
  200. is_uv(UV3) ? sname.s3.field : \
  201. undef)
  202. static void __init early_get_apic_socketid_shift(void)
  203. {
  204. unsigned int sid_shift = topology_get_domain_shift(TOPO_PKG_DOMAIN);
  205. if (is_uv2_hub() || is_uv3_hub())
  206. uvh_apicid.v = uv_early_read_mmr(UVH_APICID);
  207. if (sid_shift) {
  208. uv_cpuid.apicid_shift = 0;
  209. uv_cpuid.apicid_mask = (~(-1 << sid_shift));
  210. uv_cpuid.socketid_shift = sid_shift;
  211. } else {
  212. pr_info("UV: CPU does not have valid CPUID.11\n");
  213. }
  214. pr_info("UV: apicid_shift:%d apicid_mask:0x%x\n", uv_cpuid.apicid_shift, uv_cpuid.apicid_mask);
  215. pr_info("UV: socketid_shift:%d pnode_mask:0x%x\n", uv_cpuid.socketid_shift, uv_cpuid.pnode_mask);
  216. }
  217. static void __init uv_stringify(int len, char *to, char *from)
  218. {
  219. strscpy(to, from, len);
  220. /* Trim trailing spaces */
  221. (void)strim(to);
  222. }
  223. /* Find UV arch type entry in UVsystab */
  224. static unsigned long __init early_find_archtype(struct uv_systab *st)
  225. {
  226. int i;
  227. for (i = 0; st->entry[i].type != UV_SYSTAB_TYPE_UNUSED; i++) {
  228. unsigned long ptr = st->entry[i].offset;
  229. if (!ptr)
  230. continue;
  231. ptr += (unsigned long)st;
  232. if (st->entry[i].type == UV_SYSTAB_TYPE_ARCH_TYPE)
  233. return ptr;
  234. }
  235. return 0;
  236. }
  237. /* Validate UV arch type field in UVsystab */
  238. static int __init decode_arch_type(unsigned long ptr)
  239. {
  240. struct uv_arch_type_entry *uv_ate = (struct uv_arch_type_entry *)ptr;
  241. int n = strlen(uv_ate->archtype);
  242. if (n > 0 && n < sizeof(uv_ate->archtype)) {
  243. pr_info("UV: UVarchtype received from BIOS\n");
  244. uv_stringify(sizeof(uv_archtype), uv_archtype, uv_ate->archtype);
  245. return 1;
  246. }
  247. return 0;
  248. }
  249. /* Determine if UV arch type entry might exist in UVsystab */
  250. static int __init early_get_arch_type(void)
  251. {
  252. unsigned long uvst_physaddr, uvst_size, ptr;
  253. struct uv_systab *st;
  254. u32 rev;
  255. int ret;
  256. uvst_physaddr = get_uv_systab_phys(0);
  257. if (!uvst_physaddr)
  258. return 0;
  259. st = early_memremap_ro(uvst_physaddr, sizeof(struct uv_systab));
  260. if (!st) {
  261. pr_err("UV: Cannot access UVsystab, remap failed\n");
  262. return 0;
  263. }
  264. rev = st->revision;
  265. if (rev < UV_SYSTAB_VERSION_UV5) {
  266. early_memunmap(st, sizeof(struct uv_systab));
  267. return 0;
  268. }
  269. uvst_size = st->size;
  270. early_memunmap(st, sizeof(struct uv_systab));
  271. st = early_memremap_ro(uvst_physaddr, uvst_size);
  272. if (!st) {
  273. pr_err("UV: Cannot access UVarchtype, remap failed\n");
  274. return 0;
  275. }
  276. ptr = early_find_archtype(st);
  277. if (!ptr) {
  278. early_memunmap(st, uvst_size);
  279. return 0;
  280. }
  281. ret = decode_arch_type(ptr);
  282. early_memunmap(st, uvst_size);
  283. return ret;
  284. }
  285. /* UV system found, check which APIC MODE BIOS already selected */
  286. static void __init early_set_apic_mode(void)
  287. {
  288. if (x2apic_enabled())
  289. uv_system_type = UV_X2APIC;
  290. else
  291. uv_system_type = UV_LEGACY_APIC;
  292. }
  293. static int __init uv_set_system_type(char *_oem_id, char *_oem_table_id)
  294. {
  295. /* Save OEM_ID passed from ACPI MADT */
  296. uv_stringify(sizeof(oem_id), oem_id, _oem_id);
  297. /* Check if BIOS sent us a UVarchtype */
  298. if (!early_get_arch_type())
  299. /* If not use OEM ID for UVarchtype */
  300. uv_stringify(sizeof(uv_archtype), uv_archtype, oem_id);
  301. /* Check if not hubbed */
  302. if (strncmp(uv_archtype, "SGI", 3) != 0) {
  303. /* (Not hubbed), check if not hubless */
  304. if (strncmp(uv_archtype, "NSGI", 4) != 0)
  305. /* (Not hubless), not a UV */
  306. return 0;
  307. /* Is UV hubless system */
  308. uv_hubless_system = 0x01;
  309. /* UV5 Hubless */
  310. if (strncmp(uv_archtype, "NSGI5", 5) == 0)
  311. uv_hubless_system |= 0x20;
  312. /* UV4 Hubless: CH */
  313. else if (strncmp(uv_archtype, "NSGI4", 5) == 0)
  314. uv_hubless_system |= 0x10;
  315. /* UV3 Hubless: UV300/MC990X w/o hub */
  316. else
  317. uv_hubless_system |= 0x8;
  318. /* Copy OEM Table ID */
  319. uv_stringify(sizeof(oem_table_id), oem_table_id, _oem_table_id);
  320. pr_info("UV: OEM IDs %s/%s, SystemType %d, HUBLESS ID %x\n",
  321. oem_id, oem_table_id, uv_system_type, uv_hubless_system);
  322. return 0;
  323. }
  324. if (numa_off) {
  325. pr_err("UV: NUMA is off, disabling UV support\n");
  326. return 0;
  327. }
  328. /* Set hubbed type if true */
  329. uv_hub_info->hub_revision =
  330. !strncmp(uv_archtype, "SGI5", 4) ? UV5_HUB_REVISION_BASE :
  331. !strncmp(uv_archtype, "SGI4", 4) ? UV4_HUB_REVISION_BASE :
  332. !strncmp(uv_archtype, "SGI3", 4) ? UV3_HUB_REVISION_BASE :
  333. !strcmp(uv_archtype, "SGI2") ? UV2_HUB_REVISION_BASE : 0;
  334. switch (uv_hub_info->hub_revision) {
  335. case UV5_HUB_REVISION_BASE:
  336. uv_hubbed_system = 0x21;
  337. uv_hub_type_set(UV5);
  338. break;
  339. case UV4_HUB_REVISION_BASE:
  340. uv_hubbed_system = 0x11;
  341. uv_hub_type_set(UV4);
  342. break;
  343. case UV3_HUB_REVISION_BASE:
  344. uv_hubbed_system = 0x9;
  345. uv_hub_type_set(UV3);
  346. break;
  347. case UV2_HUB_REVISION_BASE:
  348. uv_hubbed_system = 0x5;
  349. uv_hub_type_set(UV2);
  350. break;
  351. default:
  352. return 0;
  353. }
  354. /* Get UV hub chip part number & revision */
  355. early_set_hub_type();
  356. /* Other UV setup functions */
  357. early_set_apic_mode();
  358. early_get_pnodeid();
  359. early_get_apic_socketid_shift();
  360. x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
  361. x86_platform.nmi_init = uv_nmi_init;
  362. uv_tsc_check_sync();
  363. return 1;
  364. }
  365. /* Called early to probe for the correct APIC driver */
  366. static int __init uv_acpi_madt_oem_check(char *_oem_id, char *_oem_table_id)
  367. {
  368. /* Set up early hub info fields for Node 0 */
  369. uv_cpu_info->p_uv_hub_info = &uv_hub_info_node0;
  370. /* If not UV, return. */
  371. if (uv_set_system_type(_oem_id, _oem_table_id) == 0)
  372. return 0;
  373. /* Save for display of the OEM Table ID */
  374. uv_stringify(sizeof(oem_table_id), oem_table_id, _oem_table_id);
  375. pr_info("UV: OEM IDs %s/%s, System/UVType %d/0x%x, HUB RevID %d\n",
  376. oem_id, oem_table_id, uv_system_type, is_uv(UV_ANY),
  377. uv_min_hub_revision_id);
  378. return 0;
  379. }
  380. enum uv_system_type get_uv_system_type(void)
  381. {
  382. return uv_system_type;
  383. }
  384. int uv_get_hubless_system(void)
  385. {
  386. return uv_hubless_system;
  387. }
  388. EXPORT_SYMBOL_GPL(uv_get_hubless_system);
  389. ssize_t uv_get_archtype(char *buf, int len)
  390. {
  391. return scnprintf(buf, len, "%s/%s", uv_archtype, oem_table_id);
  392. }
  393. EXPORT_SYMBOL_GPL(uv_get_archtype);
  394. int is_uv_system(void)
  395. {
  396. return uv_system_type != UV_NONE;
  397. }
  398. EXPORT_SYMBOL_GPL(is_uv_system);
  399. int is_uv_hubbed(int uvtype)
  400. {
  401. return (uv_hubbed_system & uvtype);
  402. }
  403. EXPORT_SYMBOL_GPL(is_uv_hubbed);
  404. static int is_uv_hubless(int uvtype)
  405. {
  406. return (uv_hubless_system & uvtype);
  407. }
  408. void **__uv_hub_info_list;
  409. EXPORT_SYMBOL_GPL(__uv_hub_info_list);
  410. DEFINE_PER_CPU(struct uv_cpu_info_s, __uv_cpu_info);
  411. EXPORT_PER_CPU_SYMBOL_GPL(__uv_cpu_info);
  412. short uv_possible_blades;
  413. EXPORT_SYMBOL_GPL(uv_possible_blades);
  414. unsigned long sn_rtc_cycles_per_second;
  415. EXPORT_SYMBOL(sn_rtc_cycles_per_second);
  416. /* The following values are used for the per node hub info struct */
  417. static __initdata unsigned short _min_socket, _max_socket;
  418. static __initdata unsigned short _min_pnode, _max_pnode, _gr_table_len;
  419. static __initdata struct uv_gam_range_entry *uv_gre_table;
  420. static __initdata struct uv_gam_parameters *uv_gp_table;
  421. static __initdata unsigned short *_socket_to_node;
  422. static __initdata unsigned short *_socket_to_pnode;
  423. static __initdata unsigned short *_pnode_to_socket;
  424. static __initdata unsigned short *_node_to_socket;
  425. static __initdata struct uv_gam_range_s *_gr_table;
  426. #define SOCK_EMPTY ((unsigned short)~0)
  427. /* Default UV memory block size is 2GB */
  428. static unsigned long mem_block_size __initdata = (2UL << 30);
  429. /* Kernel parameter to specify UV mem block size */
  430. static int __init parse_mem_block_size(char *ptr)
  431. {
  432. unsigned long size = memparse(ptr, NULL);
  433. /* Size will be rounded down by set_block_size() below */
  434. mem_block_size = size;
  435. return 0;
  436. }
  437. early_param("uv_memblksize", parse_mem_block_size);
  438. static __init int adj_blksize(u32 lgre)
  439. {
  440. unsigned long base = (unsigned long)lgre << UV_GAM_RANGE_SHFT;
  441. unsigned long size;
  442. for (size = mem_block_size; size > MIN_MEMORY_BLOCK_SIZE; size >>= 1)
  443. if (IS_ALIGNED(base, size))
  444. break;
  445. if (size >= mem_block_size)
  446. return 0;
  447. mem_block_size = size;
  448. return 1;
  449. }
  450. static __init void set_block_size(void)
  451. {
  452. unsigned int order = ffs(mem_block_size);
  453. if (order) {
  454. /* adjust for ffs return of 1..64 */
  455. set_memory_block_size_order(order - 1);
  456. pr_info("UV: mem_block_size set to 0x%lx\n", mem_block_size);
  457. } else {
  458. /* bad or zero value, default to 1UL << 31 (2GB) */
  459. pr_err("UV: mem_block_size error with 0x%lx\n", mem_block_size);
  460. set_memory_block_size_order(31);
  461. }
  462. }
  463. /* Build GAM range lookup table: */
  464. static __init void build_uv_gr_table(void)
  465. {
  466. struct uv_gam_range_entry *gre = uv_gre_table;
  467. struct uv_gam_range_s *grt;
  468. unsigned long last_limit = 0, ram_limit = 0;
  469. int bytes, i, sid, lsid = -1, indx = 0, lindx = -1;
  470. if (!gre)
  471. return;
  472. bytes = _gr_table_len * sizeof(struct uv_gam_range_s);
  473. grt = kzalloc(bytes, GFP_KERNEL);
  474. if (WARN_ON_ONCE(!grt))
  475. return;
  476. _gr_table = grt;
  477. for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) {
  478. if (gre->type == UV_GAM_RANGE_TYPE_HOLE) {
  479. if (!ram_limit) {
  480. /* Mark hole between RAM/non-RAM: */
  481. ram_limit = last_limit;
  482. last_limit = gre->limit;
  483. lsid++;
  484. continue;
  485. }
  486. last_limit = gre->limit;
  487. pr_info("UV: extra hole in GAM RE table @%d\n", (int)(gre - uv_gre_table));
  488. continue;
  489. }
  490. if (_max_socket < gre->sockid) {
  491. pr_err("UV: GAM table sockid(%d) too large(>%d) @%d\n", gre->sockid, _max_socket, (int)(gre - uv_gre_table));
  492. continue;
  493. }
  494. sid = gre->sockid - _min_socket;
  495. if (lsid < sid) {
  496. /* New range: */
  497. grt = &_gr_table[indx];
  498. grt->base = lindx;
  499. grt->nasid = gre->nasid;
  500. grt->limit = last_limit = gre->limit;
  501. lsid = sid;
  502. lindx = indx++;
  503. continue;
  504. }
  505. /* Update range: */
  506. if (lsid == sid && !ram_limit) {
  507. /* .. if contiguous: */
  508. if (grt->limit == last_limit) {
  509. grt->limit = last_limit = gre->limit;
  510. continue;
  511. }
  512. }
  513. /* Non-contiguous RAM range: */
  514. if (!ram_limit) {
  515. grt++;
  516. grt->base = lindx;
  517. grt->nasid = gre->nasid;
  518. grt->limit = last_limit = gre->limit;
  519. continue;
  520. }
  521. /* Non-contiguous/non-RAM: */
  522. grt++;
  523. /* base is this entry */
  524. grt->base = grt - _gr_table;
  525. grt->nasid = gre->nasid;
  526. grt->limit = last_limit = gre->limit;
  527. lsid++;
  528. }
  529. /* Shorten table if possible */
  530. grt++;
  531. i = grt - _gr_table;
  532. if (i < _gr_table_len) {
  533. void *ret;
  534. bytes = i * sizeof(struct uv_gam_range_s);
  535. ret = krealloc(_gr_table, bytes, GFP_KERNEL);
  536. if (ret) {
  537. _gr_table = ret;
  538. _gr_table_len = i;
  539. }
  540. }
  541. /* Display resultant GAM range table: */
  542. for (i = 0, grt = _gr_table; i < _gr_table_len; i++, grt++) {
  543. unsigned long start, end;
  544. int gb = grt->base;
  545. start = gb < 0 ? 0 : (unsigned long)_gr_table[gb].limit << UV_GAM_RANGE_SHFT;
  546. end = (unsigned long)grt->limit << UV_GAM_RANGE_SHFT;
  547. pr_info("UV: GAM Range %2d %04x 0x%013lx-0x%013lx (%d)\n", i, grt->nasid, start, end, gb);
  548. }
  549. }
  550. static int uv_wakeup_secondary(u32 phys_apicid, unsigned long start_rip)
  551. {
  552. unsigned long val;
  553. int pnode;
  554. pnode = uv_apicid_to_pnode(phys_apicid);
  555. val = (1UL << UVH_IPI_INT_SEND_SHFT) |
  556. (phys_apicid << UVH_IPI_INT_APIC_ID_SHFT) |
  557. ((start_rip << UVH_IPI_INT_VECTOR_SHFT) >> 12) |
  558. APIC_DM_INIT;
  559. uv_write_global_mmr64(pnode, UVH_IPI_INT, val);
  560. val = (1UL << UVH_IPI_INT_SEND_SHFT) |
  561. (phys_apicid << UVH_IPI_INT_APIC_ID_SHFT) |
  562. ((start_rip << UVH_IPI_INT_VECTOR_SHFT) >> 12) |
  563. APIC_DM_STARTUP;
  564. uv_write_global_mmr64(pnode, UVH_IPI_INT, val);
  565. return 0;
  566. }
  567. static void uv_send_IPI_one(int cpu, int vector)
  568. {
  569. unsigned long apicid = per_cpu(x86_cpu_to_apicid, cpu);
  570. int pnode = uv_apicid_to_pnode(apicid);
  571. unsigned long dmode, val;
  572. if (vector == NMI_VECTOR)
  573. dmode = APIC_DELIVERY_MODE_NMI;
  574. else
  575. dmode = APIC_DELIVERY_MODE_FIXED;
  576. val = (1UL << UVH_IPI_INT_SEND_SHFT) |
  577. (apicid << UVH_IPI_INT_APIC_ID_SHFT) |
  578. (dmode << UVH_IPI_INT_DELIVERY_MODE_SHFT) |
  579. (vector << UVH_IPI_INT_VECTOR_SHFT);
  580. uv_write_global_mmr64(pnode, UVH_IPI_INT, val);
  581. }
  582. static void uv_send_IPI_mask(const struct cpumask *mask, int vector)
  583. {
  584. unsigned int cpu;
  585. for_each_cpu(cpu, mask)
  586. uv_send_IPI_one(cpu, vector);
  587. }
  588. static void uv_send_IPI_mask_allbutself(const struct cpumask *mask, int vector)
  589. {
  590. unsigned int this_cpu = smp_processor_id();
  591. unsigned int cpu;
  592. for_each_cpu(cpu, mask) {
  593. if (cpu != this_cpu)
  594. uv_send_IPI_one(cpu, vector);
  595. }
  596. }
  597. static void uv_send_IPI_allbutself(int vector)
  598. {
  599. unsigned int this_cpu = smp_processor_id();
  600. unsigned int cpu;
  601. for_each_online_cpu(cpu) {
  602. if (cpu != this_cpu)
  603. uv_send_IPI_one(cpu, vector);
  604. }
  605. }
  606. static void uv_send_IPI_all(int vector)
  607. {
  608. uv_send_IPI_mask(cpu_online_mask, vector);
  609. }
  610. static int uv_probe(void)
  611. {
  612. return apic == &apic_x2apic_uv_x;
  613. }
  614. static struct apic apic_x2apic_uv_x __ro_after_init = {
  615. .name = "UV large system",
  616. .probe = uv_probe,
  617. .acpi_madt_oem_check = uv_acpi_madt_oem_check,
  618. .dest_mode_logical = false,
  619. .disable_esr = 0,
  620. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  621. .max_apic_id = UINT_MAX,
  622. .get_apic_id = x2apic_get_apic_id,
  623. .calc_dest_apicid = apic_default_calc_apicid,
  624. .send_IPI = uv_send_IPI_one,
  625. .send_IPI_mask = uv_send_IPI_mask,
  626. .send_IPI_mask_allbutself = uv_send_IPI_mask_allbutself,
  627. .send_IPI_allbutself = uv_send_IPI_allbutself,
  628. .send_IPI_all = uv_send_IPI_all,
  629. .send_IPI_self = x2apic_send_IPI_self,
  630. .wakeup_secondary_cpu = uv_wakeup_secondary,
  631. .read = native_apic_msr_read,
  632. .write = native_apic_msr_write,
  633. .eoi = native_apic_msr_eoi,
  634. .icr_read = native_x2apic_icr_read,
  635. .icr_write = native_x2apic_icr_write,
  636. };
  637. #define UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_LENGTH 3
  638. #define DEST_SHIFT UVXH_RH_GAM_ALIAS_0_REDIRECT_CONFIG_DEST_BASE_SHFT
  639. static __init void get_lowmem_redirect(unsigned long *base, unsigned long *size)
  640. {
  641. union uvh_rh_gam_alias_2_overlay_config_u alias;
  642. union uvh_rh_gam_alias_2_redirect_config_u redirect;
  643. unsigned long m_redirect;
  644. unsigned long m_overlay;
  645. int i;
  646. for (i = 0; i < UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_LENGTH; i++) {
  647. switch (i) {
  648. case 0:
  649. m_redirect = UVH_RH_GAM_ALIAS_0_REDIRECT_CONFIG;
  650. m_overlay = UVH_RH_GAM_ALIAS_0_OVERLAY_CONFIG;
  651. break;
  652. case 1:
  653. m_redirect = UVH_RH_GAM_ALIAS_1_REDIRECT_CONFIG;
  654. m_overlay = UVH_RH_GAM_ALIAS_1_OVERLAY_CONFIG;
  655. break;
  656. case 2:
  657. m_redirect = UVH_RH_GAM_ALIAS_2_REDIRECT_CONFIG;
  658. m_overlay = UVH_RH_GAM_ALIAS_2_OVERLAY_CONFIG;
  659. break;
  660. }
  661. alias.v = uv_read_local_mmr(m_overlay);
  662. if (alias.s.enable && alias.s.base == 0) {
  663. *size = (1UL << alias.s.m_alias);
  664. redirect.v = uv_read_local_mmr(m_redirect);
  665. *base = (unsigned long)redirect.s.dest_base << DEST_SHIFT;
  666. return;
  667. }
  668. }
  669. *base = *size = 0;
  670. }
  671. enum map_type {map_wb, map_uc};
  672. static const char * const mt[] = { "WB", "UC" };
  673. static __init void map_high(char *id, unsigned long base, int pshift, int bshift, int max_pnode, enum map_type map_type)
  674. {
  675. unsigned long bytes, paddr;
  676. paddr = base << pshift;
  677. bytes = (1UL << bshift) * (max_pnode + 1);
  678. if (!paddr) {
  679. pr_info("UV: Map %s_HI base address NULL\n", id);
  680. return;
  681. }
  682. if (map_type == map_uc)
  683. init_extra_mapping_uc(paddr, bytes);
  684. else
  685. init_extra_mapping_wb(paddr, bytes);
  686. pr_info("UV: Map %s_HI 0x%lx - 0x%lx %s (%d segments)\n",
  687. id, paddr, paddr + bytes, mt[map_type], max_pnode + 1);
  688. }
  689. static __init void map_gru_high(int max_pnode)
  690. {
  691. union uvh_rh_gam_gru_overlay_config_u gru;
  692. unsigned long mask, base;
  693. int shift;
  694. if (UVH_RH_GAM_GRU_OVERLAY_CONFIG) {
  695. gru.v = uv_read_local_mmr(UVH_RH_GAM_GRU_OVERLAY_CONFIG);
  696. shift = UVH_RH_GAM_GRU_OVERLAY_CONFIG_BASE_SHFT;
  697. mask = UVH_RH_GAM_GRU_OVERLAY_CONFIG_BASE_MASK;
  698. } else if (UVH_RH10_GAM_GRU_OVERLAY_CONFIG) {
  699. gru.v = uv_read_local_mmr(UVH_RH10_GAM_GRU_OVERLAY_CONFIG);
  700. shift = UVH_RH10_GAM_GRU_OVERLAY_CONFIG_BASE_SHFT;
  701. mask = UVH_RH10_GAM_GRU_OVERLAY_CONFIG_BASE_MASK;
  702. } else {
  703. pr_err("UV: GRU unavailable (no MMR)\n");
  704. return;
  705. }
  706. if (!gru.s.enable) {
  707. pr_info("UV: GRU disabled (by BIOS)\n");
  708. return;
  709. }
  710. base = (gru.v & mask) >> shift;
  711. map_high("GRU", base, shift, shift, max_pnode, map_wb);
  712. gru_start_paddr = ((u64)base << shift);
  713. gru_end_paddr = gru_start_paddr + (1UL << shift) * (max_pnode + 1);
  714. }
  715. static __init void map_mmr_high(int max_pnode)
  716. {
  717. unsigned long base;
  718. int shift;
  719. bool enable;
  720. if (UVH_RH10_GAM_MMR_OVERLAY_CONFIG) {
  721. union uvh_rh10_gam_mmr_overlay_config_u mmr;
  722. mmr.v = uv_read_local_mmr(UVH_RH10_GAM_MMR_OVERLAY_CONFIG);
  723. enable = mmr.s.enable;
  724. base = mmr.s.base;
  725. shift = UVH_RH10_GAM_MMR_OVERLAY_CONFIG_BASE_SHFT;
  726. } else if (UVH_RH_GAM_MMR_OVERLAY_CONFIG) {
  727. union uvh_rh_gam_mmr_overlay_config_u mmr;
  728. mmr.v = uv_read_local_mmr(UVH_RH_GAM_MMR_OVERLAY_CONFIG);
  729. enable = mmr.s.enable;
  730. base = mmr.s.base;
  731. shift = UVH_RH_GAM_MMR_OVERLAY_CONFIG_BASE_SHFT;
  732. } else {
  733. pr_err("UV:%s:RH_GAM_MMR_OVERLAY_CONFIG MMR undefined?\n",
  734. __func__);
  735. return;
  736. }
  737. if (enable)
  738. map_high("MMR", base, shift, shift, max_pnode, map_uc);
  739. else
  740. pr_info("UV: MMR disabled\n");
  741. }
  742. /* Arch specific ENUM cases */
  743. enum mmioh_arch {
  744. UV2_MMIOH = -1,
  745. UVY_MMIOH0, UVY_MMIOH1,
  746. UVX_MMIOH0, UVX_MMIOH1,
  747. };
  748. /* Calculate and Map MMIOH Regions */
  749. static void __init calc_mmioh_map(enum mmioh_arch index,
  750. int min_pnode, int max_pnode,
  751. int shift, unsigned long base, int m_io, int n_io)
  752. {
  753. unsigned long mmr, nasid_mask;
  754. int nasid, min_nasid, max_nasid, lnasid, mapped;
  755. int i, fi, li, n, max_io;
  756. char id[8];
  757. /* One (UV2) mapping */
  758. if (index == UV2_MMIOH) {
  759. strscpy(id, "MMIOH", sizeof(id));
  760. max_io = max_pnode;
  761. mapped = 0;
  762. goto map_exit;
  763. }
  764. /* small and large MMIOH mappings */
  765. switch (index) {
  766. case UVY_MMIOH0:
  767. mmr = UVH_RH10_GAM_MMIOH_REDIRECT_CONFIG0;
  768. nasid_mask = UVYH_RH10_GAM_MMIOH_REDIRECT_CONFIG0_NASID_MASK;
  769. n = UVH_RH10_GAM_MMIOH_REDIRECT_CONFIG0_DEPTH;
  770. min_nasid = min_pnode;
  771. max_nasid = max_pnode;
  772. mapped = 1;
  773. break;
  774. case UVY_MMIOH1:
  775. mmr = UVH_RH10_GAM_MMIOH_REDIRECT_CONFIG1;
  776. nasid_mask = UVYH_RH10_GAM_MMIOH_REDIRECT_CONFIG1_NASID_MASK;
  777. n = UVH_RH10_GAM_MMIOH_REDIRECT_CONFIG1_DEPTH;
  778. min_nasid = min_pnode;
  779. max_nasid = max_pnode;
  780. mapped = 1;
  781. break;
  782. case UVX_MMIOH0:
  783. mmr = UVH_RH_GAM_MMIOH_REDIRECT_CONFIG0;
  784. nasid_mask = UVH_RH_GAM_MMIOH_REDIRECT_CONFIG0_NASID_MASK;
  785. n = UVH_RH_GAM_MMIOH_REDIRECT_CONFIG0_DEPTH;
  786. min_nasid = min_pnode * 2;
  787. max_nasid = max_pnode * 2;
  788. mapped = 1;
  789. break;
  790. case UVX_MMIOH1:
  791. mmr = UVH_RH_GAM_MMIOH_REDIRECT_CONFIG1;
  792. nasid_mask = UVH_RH_GAM_MMIOH_REDIRECT_CONFIG1_NASID_MASK;
  793. n = UVH_RH_GAM_MMIOH_REDIRECT_CONFIG1_DEPTH;
  794. min_nasid = min_pnode * 2;
  795. max_nasid = max_pnode * 2;
  796. mapped = 1;
  797. break;
  798. default:
  799. pr_err("UV:%s:Invalid mapping type:%d\n", __func__, index);
  800. return;
  801. }
  802. /* enum values chosen so (index mod 2) is MMIOH 0/1 (low/high) */
  803. snprintf(id, sizeof(id), "MMIOH%d", index%2);
  804. max_io = lnasid = fi = li = -1;
  805. for (i = 0; i < n; i++) {
  806. unsigned long m_redirect = mmr + i * 8;
  807. unsigned long redirect = uv_read_local_mmr(m_redirect);
  808. nasid = redirect & nasid_mask;
  809. if (i == 0)
  810. pr_info("UV: %s redirect base 0x%lx(@0x%lx) 0x%04x\n",
  811. id, redirect, m_redirect, nasid);
  812. /* Invalid NASID check */
  813. if (nasid < min_nasid || max_nasid < nasid) {
  814. /* Not an error: unused table entries get "poison" values */
  815. pr_debug("UV:%s:Invalid NASID(%x):%x (range:%x..%x)\n",
  816. __func__, index, nasid, min_nasid, max_nasid);
  817. nasid = -1;
  818. }
  819. if (nasid == lnasid) {
  820. li = i;
  821. /* Last entry check: */
  822. if (i != n-1)
  823. continue;
  824. }
  825. /* Check if we have a cached (or last) redirect to print: */
  826. if (lnasid != -1 || (i == n-1 && nasid != -1)) {
  827. unsigned long addr1, addr2;
  828. int f, l;
  829. if (lnasid == -1) {
  830. f = l = i;
  831. lnasid = nasid;
  832. } else {
  833. f = fi;
  834. l = li;
  835. }
  836. addr1 = (base << shift) + f * (1ULL << m_io);
  837. addr2 = (base << shift) + (l + 1) * (1ULL << m_io);
  838. pr_info("UV: %s[%03d..%03d] NASID 0x%04x ADDR 0x%016lx - 0x%016lx\n",
  839. id, fi, li, lnasid, addr1, addr2);
  840. if (max_io < l)
  841. max_io = l;
  842. }
  843. fi = li = i;
  844. lnasid = nasid;
  845. }
  846. map_exit:
  847. pr_info("UV: %s base:0x%lx shift:%d m_io:%d max_io:%d max_pnode:0x%x\n",
  848. id, base, shift, m_io, max_io, max_pnode);
  849. if (max_io >= 0 && !mapped)
  850. map_high(id, base, shift, m_io, max_io, map_uc);
  851. }
  852. static __init void map_mmioh_high(int min_pnode, int max_pnode)
  853. {
  854. /* UVY flavor */
  855. if (UVH_RH10_GAM_MMIOH_OVERLAY_CONFIG0) {
  856. union uvh_rh10_gam_mmioh_overlay_config0_u mmioh0;
  857. union uvh_rh10_gam_mmioh_overlay_config1_u mmioh1;
  858. mmioh0.v = uv_read_local_mmr(UVH_RH10_GAM_MMIOH_OVERLAY_CONFIG0);
  859. if (unlikely(mmioh0.s.enable == 0))
  860. pr_info("UV: MMIOH0 disabled\n");
  861. else
  862. calc_mmioh_map(UVY_MMIOH0, min_pnode, max_pnode,
  863. UVH_RH10_GAM_MMIOH_OVERLAY_CONFIG0_BASE_SHFT,
  864. mmioh0.s.base, mmioh0.s.m_io, mmioh0.s.n_io);
  865. mmioh1.v = uv_read_local_mmr(UVH_RH10_GAM_MMIOH_OVERLAY_CONFIG1);
  866. if (unlikely(mmioh1.s.enable == 0))
  867. pr_info("UV: MMIOH1 disabled\n");
  868. else
  869. calc_mmioh_map(UVY_MMIOH1, min_pnode, max_pnode,
  870. UVH_RH10_GAM_MMIOH_OVERLAY_CONFIG1_BASE_SHFT,
  871. mmioh1.s.base, mmioh1.s.m_io, mmioh1.s.n_io);
  872. return;
  873. }
  874. /* UVX flavor */
  875. if (UVH_RH_GAM_MMIOH_OVERLAY_CONFIG0) {
  876. union uvh_rh_gam_mmioh_overlay_config0_u mmioh0;
  877. union uvh_rh_gam_mmioh_overlay_config1_u mmioh1;
  878. mmioh0.v = uv_read_local_mmr(UVH_RH_GAM_MMIOH_OVERLAY_CONFIG0);
  879. if (unlikely(mmioh0.s.enable == 0))
  880. pr_info("UV: MMIOH0 disabled\n");
  881. else {
  882. unsigned long base = uvxy_field(mmioh0, base, 0);
  883. int m_io = uvxy_field(mmioh0, m_io, 0);
  884. int n_io = uvxy_field(mmioh0, n_io, 0);
  885. calc_mmioh_map(UVX_MMIOH0, min_pnode, max_pnode,
  886. UVH_RH_GAM_MMIOH_OVERLAY_CONFIG0_BASE_SHFT,
  887. base, m_io, n_io);
  888. }
  889. mmioh1.v = uv_read_local_mmr(UVH_RH_GAM_MMIOH_OVERLAY_CONFIG1);
  890. if (unlikely(mmioh1.s.enable == 0))
  891. pr_info("UV: MMIOH1 disabled\n");
  892. else {
  893. unsigned long base = uvxy_field(mmioh1, base, 0);
  894. int m_io = uvxy_field(mmioh1, m_io, 0);
  895. int n_io = uvxy_field(mmioh1, n_io, 0);
  896. calc_mmioh_map(UVX_MMIOH1, min_pnode, max_pnode,
  897. UVH_RH_GAM_MMIOH_OVERLAY_CONFIG1_BASE_SHFT,
  898. base, m_io, n_io);
  899. }
  900. return;
  901. }
  902. /* UV2 flavor */
  903. if (UVH_RH_GAM_MMIOH_OVERLAY_CONFIG) {
  904. union uvh_rh_gam_mmioh_overlay_config_u mmioh;
  905. mmioh.v = uv_read_local_mmr(UVH_RH_GAM_MMIOH_OVERLAY_CONFIG);
  906. if (unlikely(mmioh.s2.enable == 0))
  907. pr_info("UV: MMIOH disabled\n");
  908. else
  909. calc_mmioh_map(UV2_MMIOH, min_pnode, max_pnode,
  910. UV2H_RH_GAM_MMIOH_OVERLAY_CONFIG_BASE_SHFT,
  911. mmioh.s2.base, mmioh.s2.m_io, mmioh.s2.n_io);
  912. return;
  913. }
  914. }
  915. static __init void map_low_mmrs(void)
  916. {
  917. if (UV_GLOBAL_MMR32_BASE)
  918. init_extra_mapping_uc(UV_GLOBAL_MMR32_BASE, UV_GLOBAL_MMR32_SIZE);
  919. if (UV_LOCAL_MMR_BASE)
  920. init_extra_mapping_uc(UV_LOCAL_MMR_BASE, UV_LOCAL_MMR_SIZE);
  921. }
  922. static __init void uv_rtc_init(void)
  923. {
  924. long status;
  925. u64 ticks_per_sec;
  926. status = uv_bios_freq_base(BIOS_FREQ_BASE_REALTIME_CLOCK, &ticks_per_sec);
  927. if (status != BIOS_STATUS_SUCCESS || ticks_per_sec < 100000) {
  928. pr_warn("UV: unable to determine platform RTC clock frequency, guessing.\n");
  929. /* BIOS gives wrong value for clock frequency, so guess: */
  930. sn_rtc_cycles_per_second = 1000000000000UL / 30000UL;
  931. } else {
  932. sn_rtc_cycles_per_second = ticks_per_sec;
  933. }
  934. }
  935. /* Direct Legacy VGA I/O traffic to designated IOH */
  936. static int uv_set_vga_state(struct pci_dev *pdev, bool decode, unsigned int command_bits, u32 flags)
  937. {
  938. int domain, bus, rc;
  939. if (!(flags & PCI_VGA_STATE_CHANGE_BRIDGE))
  940. return 0;
  941. if ((command_bits & PCI_COMMAND_IO) == 0)
  942. return 0;
  943. domain = pci_domain_nr(pdev->bus);
  944. bus = pdev->bus->number;
  945. rc = uv_bios_set_legacy_vga_target(decode, domain, bus);
  946. return rc;
  947. }
  948. /*
  949. * Called on each CPU to initialize the per_cpu UV data area.
  950. * FIXME: hotplug not supported yet
  951. */
  952. void uv_cpu_init(void)
  953. {
  954. /* CPU 0 initialization will be done via uv_system_init. */
  955. if (smp_processor_id() == 0)
  956. return;
  957. uv_hub_info->nr_online_cpus++;
  958. }
  959. struct mn {
  960. unsigned char m_val;
  961. unsigned char n_val;
  962. unsigned char m_shift;
  963. unsigned char n_lshift;
  964. };
  965. /* Initialize caller's MN struct and fill in values */
  966. static void get_mn(struct mn *mnp)
  967. {
  968. memset(mnp, 0, sizeof(*mnp));
  969. mnp->n_val = uv_cpuid.n_skt;
  970. if (is_uv(UV4|UVY)) {
  971. mnp->m_val = 0;
  972. mnp->n_lshift = 0;
  973. } else if (is_uv3_hub()) {
  974. union uvyh_gr0_gam_gr_config_u m_gr_config;
  975. mnp->m_val = uv_cpuid.m_skt;
  976. m_gr_config.v = uv_read_local_mmr(UVH_GR0_GAM_GR_CONFIG);
  977. mnp->n_lshift = m_gr_config.s3.m_skt;
  978. } else if (is_uv2_hub()) {
  979. mnp->m_val = uv_cpuid.m_skt;
  980. mnp->n_lshift = mnp->m_val == 40 ? 40 : 39;
  981. }
  982. mnp->m_shift = mnp->m_val ? 64 - mnp->m_val : 0;
  983. }
  984. static void __init uv_init_hub_info(struct uv_hub_info_s *hi)
  985. {
  986. struct mn mn;
  987. get_mn(&mn);
  988. hi->gpa_mask = mn.m_val ?
  989. (1UL << (mn.m_val + mn.n_val)) - 1 :
  990. (1UL << uv_cpuid.gpa_shift) - 1;
  991. hi->m_val = mn.m_val;
  992. hi->n_val = mn.n_val;
  993. hi->m_shift = mn.m_shift;
  994. hi->n_lshift = mn.n_lshift ? mn.n_lshift : 0;
  995. hi->hub_revision = uv_hub_info->hub_revision;
  996. hi->hub_type = uv_hub_info->hub_type;
  997. hi->pnode_mask = uv_cpuid.pnode_mask;
  998. hi->nasid_shift = uv_cpuid.nasid_shift;
  999. hi->min_pnode = _min_pnode;
  1000. hi->min_socket = _min_socket;
  1001. hi->node_to_socket = _node_to_socket;
  1002. hi->pnode_to_socket = _pnode_to_socket;
  1003. hi->socket_to_node = _socket_to_node;
  1004. hi->socket_to_pnode = _socket_to_pnode;
  1005. hi->gr_table_len = _gr_table_len;
  1006. hi->gr_table = _gr_table;
  1007. uv_cpuid.gnode_shift = max_t(unsigned int, uv_cpuid.gnode_shift, mn.n_val);
  1008. hi->gnode_extra = (uv_node_id & ~((1 << uv_cpuid.gnode_shift) - 1)) >> 1;
  1009. if (mn.m_val)
  1010. hi->gnode_upper = (u64)hi->gnode_extra << mn.m_val;
  1011. if (uv_gp_table) {
  1012. hi->global_mmr_base = uv_gp_table->mmr_base;
  1013. hi->global_mmr_shift = uv_gp_table->mmr_shift;
  1014. hi->global_gru_base = uv_gp_table->gru_base;
  1015. hi->global_gru_shift = uv_gp_table->gru_shift;
  1016. hi->gpa_shift = uv_gp_table->gpa_shift;
  1017. hi->gpa_mask = (1UL << hi->gpa_shift) - 1;
  1018. } else {
  1019. hi->global_mmr_base =
  1020. uv_read_local_mmr(UVH_RH_GAM_MMR_OVERLAY_CONFIG) &
  1021. ~UV_MMR_ENABLE;
  1022. hi->global_mmr_shift = _UV_GLOBAL_MMR64_PNODE_SHIFT;
  1023. }
  1024. get_lowmem_redirect(&hi->lowmem_remap_base, &hi->lowmem_remap_top);
  1025. hi->apic_pnode_shift = uv_cpuid.socketid_shift;
  1026. /* Show system specific info: */
  1027. 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);
  1028. 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);
  1029. pr_info("UV: mmr_base/shift:0x%lx/%ld\n", hi->global_mmr_base, hi->global_mmr_shift);
  1030. if (hi->global_gru_base)
  1031. pr_info("UV: gru_base/shift:0x%lx/%ld\n",
  1032. hi->global_gru_base, hi->global_gru_shift);
  1033. pr_info("UV: gnode_upper:0x%lx gnode_extra:0x%x\n", hi->gnode_upper, hi->gnode_extra);
  1034. }
  1035. static void __init decode_gam_params(unsigned long ptr)
  1036. {
  1037. uv_gp_table = (struct uv_gam_parameters *)ptr;
  1038. pr_info("UV: GAM Params...\n");
  1039. pr_info("UV: mmr_base/shift:0x%llx/%d gru_base/shift:0x%llx/%d gpa_shift:%d\n",
  1040. uv_gp_table->mmr_base, uv_gp_table->mmr_shift,
  1041. uv_gp_table->gru_base, uv_gp_table->gru_shift,
  1042. uv_gp_table->gpa_shift);
  1043. }
  1044. static void __init decode_gam_rng_tbl(unsigned long ptr)
  1045. {
  1046. struct uv_gam_range_entry *gre = (struct uv_gam_range_entry *)ptr;
  1047. unsigned long lgre = 0, gend = 0;
  1048. int index = 0;
  1049. int sock_min = INT_MAX, pnode_min = INT_MAX;
  1050. int sock_max = -1, pnode_max = -1;
  1051. uv_gre_table = gre;
  1052. for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) {
  1053. unsigned long size = ((unsigned long)(gre->limit - lgre)
  1054. << UV_GAM_RANGE_SHFT);
  1055. int order = 0;
  1056. char suffix[] = " KMGTPE";
  1057. int flag = ' ';
  1058. while (size > 9999 && order < sizeof(suffix)) {
  1059. size /= 1024;
  1060. order++;
  1061. }
  1062. /* adjust max block size to current range start */
  1063. if (gre->type == 1 || gre->type == 2)
  1064. if (adj_blksize(lgre))
  1065. flag = '*';
  1066. if (!index) {
  1067. pr_info("UV: GAM Range Table...\n");
  1068. pr_info("UV: # %20s %14s %6s %4s %5s %3s %2s\n", "Range", "", "Size", "Type", "NASID", "SID", "PN");
  1069. }
  1070. pr_info("UV: %2d: 0x%014lx-0x%014lx%c %5lu%c %3d %04x %02x %02x\n",
  1071. index++,
  1072. (unsigned long)lgre << UV_GAM_RANGE_SHFT,
  1073. (unsigned long)gre->limit << UV_GAM_RANGE_SHFT,
  1074. flag, size, suffix[order],
  1075. gre->type, gre->nasid, gre->sockid, gre->pnode);
  1076. if (gre->type == UV_GAM_RANGE_TYPE_HOLE)
  1077. gend = (unsigned long)gre->limit << UV_GAM_RANGE_SHFT;
  1078. /* update to next range start */
  1079. lgre = gre->limit;
  1080. if (sock_min > gre->sockid)
  1081. sock_min = gre->sockid;
  1082. if (sock_max < gre->sockid)
  1083. sock_max = gre->sockid;
  1084. if (pnode_min > gre->pnode)
  1085. pnode_min = gre->pnode;
  1086. if (pnode_max < gre->pnode)
  1087. pnode_max = gre->pnode;
  1088. }
  1089. _min_socket = sock_min;
  1090. _max_socket = sock_max;
  1091. _min_pnode = pnode_min;
  1092. _max_pnode = pnode_max;
  1093. _gr_table_len = index;
  1094. pr_info("UV: GRT: %d entries, sockets(min:%x,max:%x), pnodes(min:%x,max:%x), gap_end(%d)\n",
  1095. index, _min_socket, _max_socket, _min_pnode, _max_pnode, fls64(gend));
  1096. }
  1097. /* Walk through UVsystab decoding the fields */
  1098. static int __init decode_uv_systab(void)
  1099. {
  1100. struct uv_systab *st;
  1101. int i;
  1102. /* Get mapped UVsystab pointer */
  1103. st = uv_systab;
  1104. /* If UVsystab is version 1, there is no extended UVsystab */
  1105. if (st && st->revision == UV_SYSTAB_VERSION_1)
  1106. return 0;
  1107. if ((!st) || (st->revision < UV_SYSTAB_VERSION_UV4_LATEST)) {
  1108. int rev = st ? st->revision : 0;
  1109. pr_err("UV: BIOS UVsystab mismatch, (%x < %x)\n",
  1110. rev, UV_SYSTAB_VERSION_UV4_LATEST);
  1111. pr_err("UV: Does not support UV, switch to non-UV x86_64\n");
  1112. uv_system_type = UV_NONE;
  1113. return -EINVAL;
  1114. }
  1115. for (i = 0; st->entry[i].type != UV_SYSTAB_TYPE_UNUSED; i++) {
  1116. unsigned long ptr = st->entry[i].offset;
  1117. if (!ptr)
  1118. continue;
  1119. /* point to payload */
  1120. ptr += (unsigned long)st;
  1121. switch (st->entry[i].type) {
  1122. case UV_SYSTAB_TYPE_GAM_PARAMS:
  1123. decode_gam_params(ptr);
  1124. break;
  1125. case UV_SYSTAB_TYPE_GAM_RNG_TBL:
  1126. decode_gam_rng_tbl(ptr);
  1127. break;
  1128. case UV_SYSTAB_TYPE_ARCH_TYPE:
  1129. /* already processed in early startup */
  1130. break;
  1131. default:
  1132. pr_err("UV:%s:Unrecognized UV_SYSTAB_TYPE:%d, skipped\n",
  1133. __func__, st->entry[i].type);
  1134. break;
  1135. }
  1136. }
  1137. return 0;
  1138. }
  1139. /*
  1140. * Given a bitmask 'bits' representing presnt blades, numbered
  1141. * starting at 'base', masking off unused high bits of blade number
  1142. * with 'mask', update the minimum and maximum blade numbers that we
  1143. * have found. (Masking with 'mask' necessary because of BIOS
  1144. * treatment of system partitioning when creating this table we are
  1145. * interpreting.)
  1146. */
  1147. static inline void blade_update_min_max(unsigned long bits, int base, int mask, int *min, int *max)
  1148. {
  1149. int first, last;
  1150. if (!bits)
  1151. return;
  1152. first = (base + __ffs(bits)) & mask;
  1153. last = (base + __fls(bits)) & mask;
  1154. if (*min > first)
  1155. *min = first;
  1156. if (*max < last)
  1157. *max = last;
  1158. }
  1159. /* Set up physical blade translations from UVH_NODE_PRESENT_TABLE */
  1160. static __init void boot_init_possible_blades(struct uv_hub_info_s *hub_info)
  1161. {
  1162. unsigned long np;
  1163. int i, uv_pb = 0;
  1164. int sock_min = INT_MAX, sock_max = -1, s_mask;
  1165. s_mask = (1 << uv_cpuid.n_skt) - 1;
  1166. if (UVH_NODE_PRESENT_TABLE) {
  1167. pr_info("UV: NODE_PRESENT_DEPTH = %d\n",
  1168. UVH_NODE_PRESENT_TABLE_DEPTH);
  1169. for (i = 0; i < UVH_NODE_PRESENT_TABLE_DEPTH; i++) {
  1170. np = uv_read_local_mmr(UVH_NODE_PRESENT_TABLE + i * 8);
  1171. pr_info("UV: NODE_PRESENT(%d) = 0x%016lx\n", i, np);
  1172. blade_update_min_max(np, i * 64, s_mask, &sock_min, &sock_max);
  1173. }
  1174. }
  1175. if (UVH_NODE_PRESENT_0) {
  1176. np = uv_read_local_mmr(UVH_NODE_PRESENT_0);
  1177. pr_info("UV: NODE_PRESENT_0 = 0x%016lx\n", np);
  1178. blade_update_min_max(np, 0, s_mask, &sock_min, &sock_max);
  1179. }
  1180. if (UVH_NODE_PRESENT_1) {
  1181. np = uv_read_local_mmr(UVH_NODE_PRESENT_1);
  1182. pr_info("UV: NODE_PRESENT_1 = 0x%016lx\n", np);
  1183. blade_update_min_max(np, 64, s_mask, &sock_min, &sock_max);
  1184. }
  1185. /* Only update if we actually found some bits indicating blades present */
  1186. if (sock_max >= sock_min) {
  1187. _min_socket = sock_min;
  1188. _max_socket = sock_max;
  1189. uv_pb = sock_max - sock_min + 1;
  1190. }
  1191. if (uv_possible_blades != uv_pb)
  1192. uv_possible_blades = uv_pb;
  1193. pr_info("UV: number nodes/possible blades %d (%d - %d)\n",
  1194. uv_pb, sock_min, sock_max);
  1195. }
  1196. static int __init alloc_conv_table(int num_elem, unsigned short **table)
  1197. {
  1198. int i;
  1199. size_t bytes;
  1200. bytes = num_elem * sizeof(*table[0]);
  1201. *table = kmalloc(bytes, GFP_KERNEL);
  1202. if (WARN_ON_ONCE(!*table))
  1203. return -ENOMEM;
  1204. for (i = 0; i < num_elem; i++)
  1205. ((unsigned short *)*table)[i] = SOCK_EMPTY;
  1206. return 0;
  1207. }
  1208. /* Remove conversion table if it's 1:1 */
  1209. #define FREE_1_TO_1_TABLE(tbl, min, max, max2) free_1_to_1_table(&tbl, #tbl, min, max, max2)
  1210. static void __init free_1_to_1_table(unsigned short **tp, char *tname, int min, int max, int max2)
  1211. {
  1212. int i;
  1213. unsigned short *table = *tp;
  1214. if (table == NULL)
  1215. return;
  1216. if (max != max2)
  1217. return;
  1218. for (i = 0; i < max; i++) {
  1219. if (i != table[i])
  1220. return;
  1221. }
  1222. kfree(table);
  1223. *tp = NULL;
  1224. pr_info("UV: %s is 1:1, conversion table removed\n", tname);
  1225. }
  1226. /*
  1227. * Build Socket Tables
  1228. * If the number of nodes is >1 per socket, socket to node table will
  1229. * contain lowest node number on that socket.
  1230. */
  1231. static void __init build_socket_tables(void)
  1232. {
  1233. struct uv_gam_range_entry *gre = uv_gre_table;
  1234. int nums, numn, nump;
  1235. int i, lnid, apicid;
  1236. int minsock = _min_socket;
  1237. int maxsock = _max_socket;
  1238. int minpnode = _min_pnode;
  1239. int maxpnode = _max_pnode;
  1240. if (!gre) {
  1241. if (is_uv2_hub() || is_uv3_hub()) {
  1242. pr_info("UV: No UVsystab socket table, ignoring\n");
  1243. return;
  1244. }
  1245. pr_err("UV: Error: UVsystab address translations not available!\n");
  1246. WARN_ON_ONCE(!gre);
  1247. return;
  1248. }
  1249. numn = num_possible_nodes();
  1250. nump = maxpnode - minpnode + 1;
  1251. nums = maxsock - minsock + 1;
  1252. /* Allocate and clear tables */
  1253. if ((alloc_conv_table(nump, &_pnode_to_socket) < 0)
  1254. || (alloc_conv_table(nums, &_socket_to_pnode) < 0)
  1255. || (alloc_conv_table(numn, &_node_to_socket) < 0)
  1256. || (alloc_conv_table(nums, &_socket_to_node) < 0)) {
  1257. kfree(_pnode_to_socket);
  1258. kfree(_socket_to_pnode);
  1259. kfree(_node_to_socket);
  1260. return;
  1261. }
  1262. /* Fill in pnode/node/addr conversion list values: */
  1263. for (; gre->type != UV_GAM_RANGE_TYPE_UNUSED; gre++) {
  1264. if (gre->type == UV_GAM_RANGE_TYPE_HOLE)
  1265. continue;
  1266. i = gre->sockid - minsock;
  1267. if (_socket_to_pnode[i] == SOCK_EMPTY)
  1268. _socket_to_pnode[i] = gre->pnode;
  1269. i = gre->pnode - minpnode;
  1270. if (_pnode_to_socket[i] == SOCK_EMPTY)
  1271. _pnode_to_socket[i] = gre->sockid;
  1272. pr_info("UV: sid:%02x type:%d nasid:%04x pn:%02x pn2s:%2x\n",
  1273. gre->sockid, gre->type, gre->nasid,
  1274. _socket_to_pnode[gre->sockid - minsock],
  1275. _pnode_to_socket[gre->pnode - minpnode]);
  1276. }
  1277. /* Set socket -> node values: */
  1278. lnid = NUMA_NO_NODE;
  1279. for (apicid = 0; apicid < ARRAY_SIZE(__apicid_to_node); apicid++) {
  1280. int nid = __apicid_to_node[apicid];
  1281. int sockid;
  1282. if ((nid == NUMA_NO_NODE) || (lnid == nid))
  1283. continue;
  1284. lnid = nid;
  1285. sockid = apicid >> uv_cpuid.socketid_shift;
  1286. if (_socket_to_node[sockid - minsock] == SOCK_EMPTY)
  1287. _socket_to_node[sockid - minsock] = nid;
  1288. if (_node_to_socket[nid] == SOCK_EMPTY)
  1289. _node_to_socket[nid] = sockid;
  1290. pr_info("UV: sid:%02x: apicid:%04x socket:%02d node:%03x s2n:%03x\n",
  1291. sockid,
  1292. apicid,
  1293. _node_to_socket[nid],
  1294. nid,
  1295. _socket_to_node[sockid - minsock]);
  1296. }
  1297. /*
  1298. * If e.g. socket id == pnode for all pnodes,
  1299. * system runs faster by removing corresponding conversion table.
  1300. */
  1301. FREE_1_TO_1_TABLE(_socket_to_node, _min_socket, nums, numn);
  1302. FREE_1_TO_1_TABLE(_node_to_socket, _min_socket, nums, numn);
  1303. FREE_1_TO_1_TABLE(_socket_to_pnode, _min_pnode, nums, nump);
  1304. FREE_1_TO_1_TABLE(_pnode_to_socket, _min_pnode, nums, nump);
  1305. }
  1306. /* Check which reboot to use */
  1307. static void check_efi_reboot(void)
  1308. {
  1309. /* If EFI reboot not available, use ACPI reboot */
  1310. if (!efi_enabled(EFI_BOOT))
  1311. reboot_type = BOOT_ACPI;
  1312. }
  1313. /*
  1314. * User proc fs file handling now deprecated.
  1315. * Recommend using /sys/firmware/sgi_uv/... instead.
  1316. */
  1317. static int __maybe_unused proc_hubbed_show(struct seq_file *file, void *data)
  1318. {
  1319. pr_notice_once("%s: using deprecated /proc/sgi_uv/hubbed, use /sys/firmware/sgi_uv/hub_type\n",
  1320. current->comm);
  1321. seq_printf(file, "0x%x\n", uv_hubbed_system);
  1322. return 0;
  1323. }
  1324. static int __maybe_unused proc_hubless_show(struct seq_file *file, void *data)
  1325. {
  1326. pr_notice_once("%s: using deprecated /proc/sgi_uv/hubless, use /sys/firmware/sgi_uv/hubless\n",
  1327. current->comm);
  1328. seq_printf(file, "0x%x\n", uv_hubless_system);
  1329. return 0;
  1330. }
  1331. static int __maybe_unused proc_archtype_show(struct seq_file *file, void *data)
  1332. {
  1333. pr_notice_once("%s: using deprecated /proc/sgi_uv/archtype, use /sys/firmware/sgi_uv/archtype\n",
  1334. current->comm);
  1335. seq_printf(file, "%s/%s\n", uv_archtype, oem_table_id);
  1336. return 0;
  1337. }
  1338. static __init void uv_setup_proc_files(int hubless)
  1339. {
  1340. struct proc_dir_entry *pde;
  1341. pde = proc_mkdir(UV_PROC_NODE, NULL);
  1342. proc_create_single("archtype", 0, pde, proc_archtype_show);
  1343. if (hubless)
  1344. proc_create_single("hubless", 0, pde, proc_hubless_show);
  1345. else
  1346. proc_create_single("hubbed", 0, pde, proc_hubbed_show);
  1347. }
  1348. /* Initialize UV hubless systems */
  1349. static __init int uv_system_init_hubless(void)
  1350. {
  1351. int rc;
  1352. /* Setup PCH NMI handler */
  1353. uv_nmi_setup_hubless();
  1354. /* Init kernel/BIOS interface */
  1355. rc = uv_bios_init();
  1356. if (rc < 0)
  1357. return rc;
  1358. /* Process UVsystab */
  1359. rc = decode_uv_systab();
  1360. if (rc < 0)
  1361. return rc;
  1362. /* Set section block size for current node memory */
  1363. set_block_size();
  1364. /* Create user access node */
  1365. if (rc >= 0)
  1366. uv_setup_proc_files(1);
  1367. check_efi_reboot();
  1368. return rc;
  1369. }
  1370. static void __init uv_system_init_hub(void)
  1371. {
  1372. struct uv_hub_info_s hub_info = {0};
  1373. int bytes, cpu, nodeid, bid;
  1374. unsigned short min_pnode = USHRT_MAX, max_pnode = 0;
  1375. char *hub = is_uv5_hub() ? "UV500" :
  1376. is_uv4_hub() ? "UV400" :
  1377. is_uv3_hub() ? "UV300" :
  1378. is_uv2_hub() ? "UV2000/3000" : NULL;
  1379. struct uv_hub_info_s **uv_hub_info_list_blade;
  1380. if (!hub) {
  1381. pr_err("UV: Unknown/unsupported UV hub\n");
  1382. return;
  1383. }
  1384. pr_info("UV: Found %s hub\n", hub);
  1385. map_low_mmrs();
  1386. /* Get uv_systab for decoding, setup UV BIOS calls */
  1387. uv_bios_init();
  1388. /* If there's an UVsystab problem then abort UV init: */
  1389. if (decode_uv_systab() < 0) {
  1390. pr_err("UV: Mangled UVsystab format\n");
  1391. return;
  1392. }
  1393. build_socket_tables();
  1394. build_uv_gr_table();
  1395. set_block_size();
  1396. uv_init_hub_info(&hub_info);
  1397. /* If UV2 or UV3 may need to get # blades from HW */
  1398. if (is_uv(UV2|UV3) && !uv_gre_table)
  1399. boot_init_possible_blades(&hub_info);
  1400. else
  1401. /* min/max sockets set in decode_gam_rng_tbl */
  1402. uv_possible_blades = (_max_socket - _min_socket) + 1;
  1403. /* uv_num_possible_blades() is really the hub count: */
  1404. pr_info("UV: Found %d hubs, %d nodes, %d CPUs\n", uv_num_possible_blades(), num_possible_nodes(), num_possible_cpus());
  1405. uv_bios_get_sn_info(0, &uv_type, &sn_partition_id, &sn_coherency_id, &sn_region_size, &system_serial_number);
  1406. hub_info.coherency_domain_number = sn_coherency_id;
  1407. uv_rtc_init();
  1408. /*
  1409. * __uv_hub_info_list[] is indexed by node, but there is only
  1410. * one hub_info structure per blade. First, allocate one
  1411. * structure per blade. Further down we create a per-node
  1412. * table (__uv_hub_info_list[]) pointing to hub_info
  1413. * structures for the correct blade.
  1414. */
  1415. bytes = sizeof(void *) * uv_num_possible_blades();
  1416. uv_hub_info_list_blade = kzalloc(bytes, GFP_KERNEL);
  1417. if (WARN_ON_ONCE(!uv_hub_info_list_blade))
  1418. return;
  1419. bytes = sizeof(struct uv_hub_info_s);
  1420. for_each_possible_blade(bid) {
  1421. struct uv_hub_info_s *new_hub;
  1422. /* Allocate & fill new per hub info list */
  1423. new_hub = (bid == 0) ? &uv_hub_info_node0
  1424. : kzalloc_node(bytes, GFP_KERNEL, uv_blade_to_node(bid));
  1425. if (WARN_ON_ONCE(!new_hub)) {
  1426. /* do not kfree() bid 0, which is statically allocated */
  1427. while (--bid > 0)
  1428. kfree(uv_hub_info_list_blade[bid]);
  1429. kfree(uv_hub_info_list_blade);
  1430. return;
  1431. }
  1432. uv_hub_info_list_blade[bid] = new_hub;
  1433. *new_hub = hub_info;
  1434. /* Use information from GAM table if available: */
  1435. if (uv_gre_table)
  1436. new_hub->pnode = uv_blade_to_pnode(bid);
  1437. else /* Or fill in during CPU loop: */
  1438. new_hub->pnode = 0xffff;
  1439. new_hub->numa_blade_id = bid;
  1440. new_hub->memory_nid = NUMA_NO_NODE;
  1441. new_hub->nr_possible_cpus = 0;
  1442. new_hub->nr_online_cpus = 0;
  1443. }
  1444. /*
  1445. * Now populate __uv_hub_info_list[] for each node with the
  1446. * pointer to the struct for the blade it resides on.
  1447. */
  1448. bytes = sizeof(void *) * num_possible_nodes();
  1449. __uv_hub_info_list = kzalloc(bytes, GFP_KERNEL);
  1450. if (WARN_ON_ONCE(!__uv_hub_info_list)) {
  1451. for_each_possible_blade(bid)
  1452. /* bid 0 is statically allocated */
  1453. if (bid != 0)
  1454. kfree(uv_hub_info_list_blade[bid]);
  1455. kfree(uv_hub_info_list_blade);
  1456. return;
  1457. }
  1458. for_each_node(nodeid)
  1459. __uv_hub_info_list[nodeid] = uv_hub_info_list_blade[uv_node_to_blade_id(nodeid)];
  1460. /* Initialize per CPU info: */
  1461. for_each_possible_cpu(cpu) {
  1462. int apicid = per_cpu(x86_cpu_to_apicid, cpu);
  1463. unsigned short bid;
  1464. unsigned short pnode;
  1465. pnode = uv_apicid_to_pnode(apicid);
  1466. bid = uv_pnode_to_socket(pnode) - _min_socket;
  1467. uv_cpu_info_per(cpu)->p_uv_hub_info = uv_hub_info_list_blade[bid];
  1468. uv_cpu_info_per(cpu)->blade_cpu_id = uv_cpu_hub_info(cpu)->nr_possible_cpus++;
  1469. if (uv_cpu_hub_info(cpu)->memory_nid == NUMA_NO_NODE)
  1470. uv_cpu_hub_info(cpu)->memory_nid = cpu_to_node(cpu);
  1471. if (uv_cpu_hub_info(cpu)->pnode == 0xffff)
  1472. uv_cpu_hub_info(cpu)->pnode = pnode;
  1473. }
  1474. for_each_possible_blade(bid) {
  1475. unsigned short pnode = uv_hub_info_list_blade[bid]->pnode;
  1476. if (pnode == 0xffff)
  1477. continue;
  1478. min_pnode = min(pnode, min_pnode);
  1479. max_pnode = max(pnode, max_pnode);
  1480. pr_info("UV: HUB:%2d pn:%02x nrcpus:%d\n",
  1481. bid,
  1482. uv_hub_info_list_blade[bid]->pnode,
  1483. uv_hub_info_list_blade[bid]->nr_possible_cpus);
  1484. }
  1485. pr_info("UV: min_pnode:%02x max_pnode:%02x\n", min_pnode, max_pnode);
  1486. map_gru_high(max_pnode);
  1487. map_mmr_high(max_pnode);
  1488. map_mmioh_high(min_pnode, max_pnode);
  1489. kfree(uv_hub_info_list_blade);
  1490. uv_hub_info_list_blade = NULL;
  1491. uv_nmi_setup();
  1492. uv_cpu_init();
  1493. uv_setup_proc_files(0);
  1494. /* Register Legacy VGA I/O redirection handler: */
  1495. pci_register_set_vga_state(uv_set_vga_state);
  1496. check_efi_reboot();
  1497. }
  1498. /*
  1499. * There is a different code path needed to initialize a UV system that does
  1500. * not have a "UV HUB" (referred to as "hubless").
  1501. */
  1502. void __init uv_system_init(void)
  1503. {
  1504. if (likely(!is_uv_system() && !is_uv_hubless(1)))
  1505. return;
  1506. if (is_uv_system())
  1507. uv_system_init_hub();
  1508. else
  1509. uv_system_init_hubless();
  1510. }
  1511. apic_driver(apic_x2apic_uv_x);