x2apic_uv_x.c 40 KB

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