ip27-klnuma.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Ported from IRIX to Linux by Kanoj Sarcar, 06/08/00.
  4. * Copyright 2000 - 2001 Silicon Graphics, Inc.
  5. * Copyright 2000 - 2001 Kanoj Sarcar (kanoj@sgi.com)
  6. */
  7. #include <linux/init.h>
  8. #include <linux/mm.h>
  9. #include <linux/mmzone.h>
  10. #include <linux/kernel.h>
  11. #include <linux/nodemask.h>
  12. #include <linux/string.h>
  13. #include <asm/page.h>
  14. #include <asm/sections.h>
  15. #include <asm/sn/types.h>
  16. #include <asm/sn/arch.h>
  17. #include <asm/sn/gda.h>
  18. #include <asm/sn/hub.h>
  19. #include <asm/sn/mapped_kernel.h>
  20. #include <asm/sn/sn_private.h>
  21. static cpumask_t ktext_repmask;
  22. /*
  23. * XXX - This needs to be much smarter about where it puts copies of the
  24. * kernel. For example, we should never put a copy on a headless node,
  25. * and we should respect the topology of the machine.
  26. */
  27. void __init setup_replication_mask(void)
  28. {
  29. /* Set only the master cnode's bit. The master cnode is always 0. */
  30. cpumask_clear(&ktext_repmask);
  31. cpumask_set_cpu(0, &ktext_repmask);
  32. #ifdef CONFIG_REPLICATE_KTEXT
  33. #ifndef CONFIG_MAPPED_KERNEL
  34. #error Kernel replication works with mapped kernel support. No calias support.
  35. #endif
  36. {
  37. cnodeid_t cnode;
  38. for_each_online_node(cnode) {
  39. if (cnode == 0)
  40. continue;
  41. /* Advertise that we have a copy of the kernel */
  42. cpumask_set_cpu(cnode, &ktext_repmask);
  43. }
  44. }
  45. #endif
  46. /* Set up a GDA pointer to the replication mask. */
  47. GDA->g_ktext_repmask = &ktext_repmask;
  48. }
  49. static __init void set_ktext_source(nasid_t client_nasid, nasid_t server_nasid)
  50. {
  51. kern_vars_t *kvp;
  52. kvp = &hub_data(client_nasid)->kern_vars;
  53. KERN_VARS_ADDR(client_nasid) = (unsigned long)kvp;
  54. kvp->kv_magic = KV_MAGIC;
  55. kvp->kv_ro_nasid = server_nasid;
  56. kvp->kv_rw_nasid = master_nasid;
  57. kvp->kv_ro_baseaddr = NODE_CAC_BASE(server_nasid);
  58. kvp->kv_rw_baseaddr = NODE_CAC_BASE(master_nasid);
  59. printk("REPLICATION: ON nasid %d, ktext from nasid %d, kdata from nasid %d\n", client_nasid, server_nasid, master_nasid);
  60. }
  61. /* XXX - When the BTE works, we should use it instead of this. */
  62. static __init void copy_kernel(nasid_t dest_nasid)
  63. {
  64. unsigned long dest_kern_start, source_start, source_end, kern_size;
  65. source_start = (unsigned long) _stext;
  66. source_end = (unsigned long) _etext;
  67. kern_size = source_end - source_start;
  68. dest_kern_start = CHANGE_ADDR_NASID(MAPPED_KERN_RO_TO_K0(source_start),
  69. dest_nasid);
  70. memcpy((void *)dest_kern_start, (void *)source_start, kern_size);
  71. }
  72. void __init replicate_kernel_text(void)
  73. {
  74. cnodeid_t cnode;
  75. nasid_t client_nasid;
  76. nasid_t server_nasid;
  77. server_nasid = master_nasid;
  78. /* Record where the master node should get its kernel text */
  79. set_ktext_source(master_nasid, master_nasid);
  80. for_each_online_node(cnode) {
  81. if (cnode == 0)
  82. continue;
  83. client_nasid = COMPACT_TO_NASID_NODEID(cnode);
  84. /* Check if this node should get a copy of the kernel */
  85. if (cpumask_test_cpu(cnode, &ktext_repmask)) {
  86. server_nasid = client_nasid;
  87. copy_kernel(server_nasid);
  88. }
  89. /* Record where this node should get its kernel text */
  90. set_ktext_source(client_nasid, server_nasid);
  91. }
  92. }
  93. /*
  94. * Return pfn of first free page of memory on a node. PROM may allocate
  95. * data structures on the first couple of pages of the first slot of each
  96. * node. If this is the case, getfirstfree(node) > getslotstart(node, 0).
  97. */
  98. unsigned long node_getfirstfree(cnodeid_t cnode)
  99. {
  100. unsigned long loadbase = REP_BASE;
  101. nasid_t nasid = COMPACT_TO_NASID_NODEID(cnode);
  102. unsigned long offset;
  103. #ifdef CONFIG_MAPPED_KERNEL
  104. loadbase += 16777216;
  105. #endif
  106. offset = PAGE_ALIGN((unsigned long)(&_end)) - loadbase;
  107. if ((cnode == 0) || (cpumask_test_cpu(cnode, &ktext_repmask)))
  108. return TO_NODE(nasid, offset) >> PAGE_SHIFT;
  109. else
  110. return KDM_TO_PHYS(PAGE_ALIGN(SYMMON_STK_ADDR(nasid, 0))) >> PAGE_SHIFT;
  111. }