ip27-klnuma.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 ([email protected])
  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/mapped_kernel.h>
  19. #include "ip27-common.h"
  20. static nodemask_t ktext_repmask;
  21. /*
  22. * XXX - This needs to be much smarter about where it puts copies of the
  23. * kernel. For example, we should never put a copy on a headless node,
  24. * and we should respect the topology of the machine.
  25. */
  26. void __init setup_replication_mask(void)
  27. {
  28. /* Set only the master cnode's bit. The master cnode is always 0. */
  29. nodes_clear(ktext_repmask);
  30. node_set(0, ktext_repmask);
  31. #ifdef CONFIG_REPLICATE_KTEXT
  32. #ifndef CONFIG_MAPPED_KERNEL
  33. #error Kernel replication works with mapped kernel support. No calias support.
  34. #endif
  35. {
  36. nasid_t nasid;
  37. for_each_online_node(nasid) {
  38. if (nasid == 0)
  39. continue;
  40. /* Advertise that we have a copy of the kernel */
  41. node_set(nasid, ktext_repmask);
  42. }
  43. }
  44. #endif
  45. /* Set up a GDA pointer to the replication mask. */
  46. GDA->g_ktext_repmask = &ktext_repmask;
  47. }
  48. static __init void set_ktext_source(nasid_t client_nasid, nasid_t server_nasid)
  49. {
  50. kern_vars_t *kvp;
  51. kvp = &hub_data(client_nasid)->kern_vars;
  52. KERN_VARS_ADDR(client_nasid) = (unsigned long)kvp;
  53. kvp->kv_magic = KV_MAGIC;
  54. kvp->kv_ro_nasid = server_nasid;
  55. kvp->kv_rw_nasid = master_nasid;
  56. kvp->kv_ro_baseaddr = NODE_CAC_BASE(server_nasid);
  57. kvp->kv_rw_baseaddr = NODE_CAC_BASE(master_nasid);
  58. printk("REPLICATION: ON nasid %d, ktext from nasid %d, kdata from nasid %d\n", client_nasid, server_nasid, master_nasid);
  59. }
  60. /* XXX - When the BTE works, we should use it instead of this. */
  61. static __init void copy_kernel(nasid_t dest_nasid)
  62. {
  63. unsigned long dest_kern_start, source_start, source_end, kern_size;
  64. source_start = (unsigned long) _stext;
  65. source_end = (unsigned long) _etext;
  66. kern_size = source_end - source_start;
  67. dest_kern_start = CHANGE_ADDR_NASID(MAPPED_KERN_RO_TO_K0(source_start),
  68. dest_nasid);
  69. memcpy((void *)dest_kern_start, (void *)source_start, kern_size);
  70. }
  71. void __init replicate_kernel_text(void)
  72. {
  73. nasid_t client_nasid;
  74. nasid_t server_nasid;
  75. server_nasid = master_nasid;
  76. /* Record where the master node should get its kernel text */
  77. set_ktext_source(master_nasid, master_nasid);
  78. for_each_online_node(client_nasid) {
  79. if (client_nasid == 0)
  80. continue;
  81. /* Check if this node should get a copy of the kernel */
  82. if (node_isset(client_nasid, ktext_repmask)) {
  83. server_nasid = client_nasid;
  84. copy_kernel(server_nasid);
  85. }
  86. /* Record where this node should get its kernel text */
  87. set_ktext_source(client_nasid, server_nasid);
  88. }
  89. }
  90. /*
  91. * Return pfn of first free page of memory on a node. PROM may allocate
  92. * data structures on the first couple of pages of the first slot of each
  93. * node. If this is the case, getfirstfree(node) > getslotstart(node, 0).
  94. */
  95. unsigned long node_getfirstfree(nasid_t nasid)
  96. {
  97. unsigned long loadbase = REP_BASE;
  98. unsigned long offset;
  99. #ifdef CONFIG_MAPPED_KERNEL
  100. loadbase += 16777216;
  101. #endif
  102. offset = PAGE_ALIGN((unsigned long)(&_end)) - loadbase;
  103. if ((nasid == 0) || (node_isset(nasid, ktext_repmask)))
  104. return TO_NODE(nasid, offset) >> PAGE_SHIFT;
  105. else
  106. return KDM_TO_PHYS(PAGE_ALIGN(SYMMON_STK_ADDR(nasid, 0))) >> PAGE_SHIFT;
  107. }