x2apic_uv_x.c 40 KB

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