ip27-klnuma.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Ported from IRIX to Linux by Kanoj Sarcar, 06/08/00.
  3. * Copyright 2000 - 2001 Silicon Graphics, Inc.
  4. * Copyright 2000 - 2001 Kanoj Sarcar (kanoj@sgi.com)
  5. */
  6. #include <linux/init.h>
  7. #include <linux/mm.h>
  8. #include <linux/mmzone.h>
  9. #include <linux/kernel.h>
  10. #include <linux/nodemask.h>
  11. #include <linux/string.h>
  12. #include <asm/page.h>
  13. #include <asm/sections.h>
  14. #include <asm/sn/types.h>
  15. #include <asm/sn/arch.h>
  16. #include <asm/sn/gda.h>
  17. #include <asm/sn/hub.h>
  18. #include <asm/sn/mapped_kernel.h>
  19. #include <asm/sn/sn_private.h>
  20. static cpumask_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. cpus_clear(ktext_repmask);
  30. cpu_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. cnodeid_t cnode;
  37. for_each_online_node(cnode) {
  38. if (cnode == 0)
  39. continue;
  40. /* Advertise that we have a copy of the kernel */
  41. cpu_set(cnode, 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. cnodeid_t client_cnode;
  51. kern_vars_t *kvp;
  52. client_cnode = NASID_TO_COMPACT_NODEID(client_nasid);
  53. kvp = &hub_data(client_nasid)->kern_vars;
  54. KERN_VARS_ADDR(client_nasid) = (unsigned long)kvp;
  55. kvp->kv_magic = KV_MAGIC;
  56. kvp->kv_ro_nasid = server_nasid;
  57. kvp->kv_rw_nasid = master_nasid;
  58. kvp->kv_ro_baseaddr = NODE_CAC_BASE(server_nasid);
  59. kvp->kv_rw_baseaddr = NODE_CAC_BASE(master_nasid);
  60. printk("REPLICATION: ON nasid %d, ktext from nasid %d, kdata from nasid %d\n", client_nasid, server_nasid, master_nasid);
  61. }
  62. /* XXX - When the BTE works, we should use it instead of this. */
  63. static __init void copy_kernel(nasid_t dest_nasid)
  64. {
  65. unsigned long dest_kern_start, source_start, source_end, kern_size;
  66. source_start = (unsigned long) _stext;
  67. source_end = (unsigned long) _etext;
  68. kern_size = source_end - source_start;
  69. dest_kern_start = CHANGE_ADDR_NASID(MAPPED_KERN_RO_TO_K0(source_start),
  70. dest_nasid);
  71. memcpy((void *)dest_kern_start, (void *)source_start, kern_size);
  72. }
  73. void __init replicate_kernel_text()
  74. {
  75. cnodeid_t cnode;
  76. nasid_t client_nasid;
  77. nasid_t server_nasid;
  78. server_nasid = master_nasid;
  79. /* Record where the master node should get its kernel text */
  80. set_ktext_source(master_nasid, master_nasid);
  81. for_each_online_node(cnode) {
  82. if (cnode == 0)
  83. continue;
  84. client_nasid = COMPACT_TO_NASID_NODEID(cnode);
  85. /* Check if this node should get a copy of the kernel */
  86. if (cpu_isset(cnode, ktext_repmask)) {
  87. server_nasid = client_nasid;
  88. copy_kernel(server_nasid);
  89. }
  90. /* Record where this node should get its kernel text */
  91. set_ktext_source(client_nasid, server_nasid);
  92. }
  93. }
  94. /*
  95. * Return pfn of first free page of memory on a node. PROM may allocate
  96. * data structures on the first couple of pages of the first slot of each
  97. * node. If this is the case, getfirstfree(node) > getslotstart(node, 0).
  98. */
  99. pfn_t node_getfirstfree(cnodeid_t cnode)
  100. {
  101. unsigned long loadbase = REP_BASE;
  102. nasid_t nasid = COMPACT_TO_NASID_NODEID(cnode);
  103. unsigned long offset;
  104. #ifdef CONFIG_MAPPED_KERNEL
  105. loadbase += 16777216;
  106. #endif
  107. offset = PAGE_ALIGN((unsigned long)(&_end)) - loadbase;
  108. if ((cnode == 0) || (cpu_isset(cnode, ktext_repmask)))
  109. return (TO_NODE(nasid, offset) >> PAGE_SHIFT);
  110. else
  111. return (KDM_TO_PHYS(PAGE_ALIGN(SYMMON_STK_ADDR(nasid, 0))) >>
  112. PAGE_SHIFT);
  113. }