ip27-klnuma.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. 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()
  72. {
  73. cnodeid_t cnode;
  74. nasid_t client_nasid;
  75. nasid_t server_nasid;
  76. server_nasid = master_nasid;
  77. /* Record where the master node should get its kernel text */
  78. set_ktext_source(master_nasid, master_nasid);
  79. for_each_online_node(cnode) {
  80. if (cnode == 0)
  81. continue;
  82. client_nasid = COMPACT_TO_NASID_NODEID(cnode);
  83. /* Check if this node should get a copy of the kernel */
  84. if (cpu_isset(cnode, ktext_repmask)) {
  85. server_nasid = client_nasid;
  86. copy_kernel(server_nasid);
  87. }
  88. /* Record where this node should get its kernel text */
  89. set_ktext_source(client_nasid, server_nasid);
  90. }
  91. }
  92. /*
  93. * Return pfn of first free page of memory on a node. PROM may allocate
  94. * data structures on the first couple of pages of the first slot of each
  95. * node. If this is the case, getfirstfree(node) > getslotstart(node, 0).
  96. */
  97. pfn_t node_getfirstfree(cnodeid_t cnode)
  98. {
  99. unsigned long loadbase = REP_BASE;
  100. nasid_t nasid = COMPACT_TO_NASID_NODEID(cnode);
  101. unsigned long offset;
  102. #ifdef CONFIG_MAPPED_KERNEL
  103. loadbase += 16777216;
  104. #endif
  105. offset = PAGE_ALIGN((unsigned long)(&_end)) - loadbase;
  106. if ((cnode == 0) || (cpu_isset(cnode, ktext_repmask)))
  107. return (TO_NODE(nasid, offset) >> PAGE_SHIFT);
  108. else
  109. return (KDM_TO_PHYS(PAGE_ALIGN(SYMMON_STK_ADDR(nasid, 0))) >>
  110. PAGE_SHIFT);
  111. }