+ print_spew("Enabling UP settings\n");
+#if CONFIG_LOGICAL_CPUS==1
+ unsigned tmp = (pci_read_config32(NODE_MC(0), 0xe8) >> 12) & 3;
+ if (tmp>0) return;
+#endif
+ disable_probes();
+}
+
+#if CONFIG_MAX_PHYSICAL_CPUS > 2
+static int optimize_connection_group(const u8 *opt_conn, int num)
+{
+ int needs_reset = 0;
+ int i;
+ for(i=0; i<num; i+=2) {
+ needs_reset = optimize_connection(
+ NODE_HT(opt_conn[i]), 0x80 + link_to_register(link_connection(opt_conn[i],opt_conn[i+1])),
+ NODE_HT(opt_conn[i+1]), 0x80 + link_to_register(link_connection(opt_conn[i+1],opt_conn[i])) );
+ }
+ return needs_reset;
+}
+#endif
+
+#if CONFIG_MAX_PHYSICAL_CPUS > 1
+static unsigned setup_smp2(void)
+{
+ unsigned nodes;
+ u8 byte;
+ uint32_t val;
+ nodes = 2;
+
+ setup_row_local(0, 0); /* it will update the broadcast RT*/
+
+ val = get_row(0,0);
+ byte = (val>>16) & 0xfe;
+ if(byte<0x2) { /* no coherent connection so get out.*/
+ nodes = 1;
+ return nodes;
+ }
+
+ /* Setup and check a temporary connection to node 1 */
+#if TRY_HIGH_FIRST == 1
+ byte = get_linkn_last(byte); /* Max Link to node1 */
+#else
+ byte = get_linkn_first(byte); /*Min Link to node1 --- according to AMD*/
+#endif
+ print_linkn("(0,1) link=", byte);
+ setup_row_direct(0,1, byte);
+ setup_temp_row(0, 1);
+
+ verify_connection(7);
+
+ /* We found 2 nodes so far */
+ val = pci_read_config32(NODE_HT(7), 0x6c);
+ byte = (val>>2) & 0x3; /*get default link on node7 to node0*/
+ print_linkn("(1,0) link=", byte);
+ setup_row_local(7,1);
+ setup_remote_row_direct(1, 0, byte);
+
+#if (CONFIG_MAX_PHYSICAL_CPUS > 4) || (CONFIG_MAX_PHYSICAL_CPUS_4_BUT_MORE_INSTALLED == 1)
+ val = get_row(7,1);
+ byte = (val>>16) & 0xfe;
+ byte = get_linkn_last_count(byte);
+ if((byte>>2)==3) { /* Oh! we need to treat it as node2. So use another link*/
+ val = get_row(0,0);
+ byte = (val>>16) & 0xfe;
+#if TRY_HIGH_FIRST == 1
+ byte = get_linkn_first(byte); /* Min link to Node1 */
+#else
+ byte = get_linkn_last(byte); /* Max link to Node1*/
+#endif
+ print_linkn("\t-->(0,1) link=", byte);
+ setup_row_direct(0,1, byte);
+ setup_temp_row(0, 1);
+
+ verify_connection(7);
+
+ /* We found 2 nodes so far */
+ val = pci_read_config32(NODE_HT(7), 0x6c);
+ byte = (val>>2) & 0x3; /* get default link on node7 to node0*/
+ print_linkn("\t-->(1,0) link=", byte);
+ setup_row_local(7,1);
+ setup_remote_row_direct(1, 0, byte);
+ }
+#endif
+
+ setup_remote_node(1); /* Setup the regs on the remote node */
+ rename_temp_node(1); /* Rename Node 7 to Node 1 */
+ enable_routing(1); /* Enable routing on Node 1 */
+#if 0
+ /*don't need and it is done by clear_dead_links */
+ clear_temp_row(0);
+#endif
+
+ return nodes;
+}
+#endif /*CONFIG_MAX_PHYSICAL_CPUS > 1 */
+
+#if CONFIG_MAX_PHYSICAL_CPUS > 2
+
+static unsigned setup_smp4(void)
+{
+ unsigned nodes;
+ u8 byte;
+ uint32_t val;
+
+ nodes=4;
+
+ /* Setup and check temporary connection from Node 0 to Node 2 */
+ val = get_row(0,0);
+ byte = ((val>>16) & 0xfe) - link_connection(0,1);
+ byte = get_linkn_last_count(byte);
+
+ if((byte>>2)==0) { /* We should have two coherent for 4p and above*/
+ nodes = 2;
+ return nodes;
+ }
+
+ byte &= 3; /* bit [3,2] is count-1*/
+ print_linkn("(0,2) link=", byte);
+ setup_row_direct(0, 2, byte); /*(0,2) direct link done*/
+
+ /* We found 3 nodes so far. Now setup a temporary
+ * connection from node 0 to node 3 via node 1
+ */
+ setup_temp_row(0,1); /* temp. link between nodes 0 and 1 */
+ /* here should setup_row_direct(1,3) at first, before that we should find the link in node 1 to 3*/
+ val = get_row(1,1);
+ byte = ((val>>16) & 0xfe) - link_connection(1,0);
+ byte = get_linkn_first(byte);
+ print_linkn("(1,3) link=", byte);
+ setup_row_direct(1,3,byte); /* (1, 3) direct link done*/
+
+ /* We found 4 nodes so far. Now setup all nodes for 4p */
+ // We need to make sure 0,2 and 1,3 link is set already
+#if !CROSS_BAR_47_56
+ static const u8 conn4_1[] = {
+ 0,3,
+ 1,2,
+ };
+#else
+ static const u8 conn4_1[] = {
+ 0,3,2,1,
+ 1,2,3,1,
+ };
+#endif
+
+ setup_row_indirect_group(conn4_1, ARRAY_SIZE(conn4_1));
+
+ setup_temp_row(0,2);
+ verify_connection(7);
+ val = pci_read_config32(NODE_HT(7), 0x6c);
+ byte = (val>>2) & 0x3; /* get default link on 7 to 0*/
+ print_linkn("(2,0) link=", byte);
+
+ setup_row_local(7,2);
+ setup_remote_row_direct(2, 0, byte); /* node 2 to node 0 direct link done */
+ setup_remote_node(2); /* Setup the regs on the remote node */
+
+ rename_temp_node(2); /* Rename Node 7 to Node 2 */
+ enable_routing(2); /* Enable routing on Node 2 */
+
+ setup_temp_row(0,1);
+ setup_temp_row(1,3);
+ verify_connection(7);
+
+ val = pci_read_config32(NODE_HT(7), 0x6c);
+ byte = (val>>2) & 0x3; /* get default link on 7 to 1*/
+ print_linkn("(3,1) link=", byte);
+
+ setup_row_local(7,3);
+ setup_remote_row_direct(3, 1, byte); /* node 3 to node 1 direct link done */
+ setup_remote_node(3); /* Setup the regs on the remote node */
+
+ /* We need to init link between 2, and 3 direct link */
+ val = get_row(2,2);
+ byte = ((val>>16) & 0xfe) - link_connection(2,0);
+ byte = get_linkn_last_count(byte);
+ print_linkn("(2,3) link=", byte & 3);
+
+ setup_row_direct(2,3, byte & 0x3);
+ setup_temp_row(0,2);
+ setup_temp_row(2,3);
+ verify_connection(7); /* to 3*/
+
+#if (CONFIG_MAX_PHYSICAL_CPUS > 4) || (CONFIG_MAX_PHYSICAL_CPUS_4_BUT_MORE_INSTALLED == 1)
+ /* We need to find out which link is to node3 */
+ if((byte>>2)==2) { /* one to node3, one to node0, one to node4*/
+ val = get_row(7,3);
+ if((val>>16) == 1) { /* that link is to node4, because via node1 it has been set, recompute it*/
+ val = get_row(2,2);
+ byte = ((val>>16) & 0xfe) - link_connection(2,0);
+ byte = get_linkn_first(byte);
+ print_linkn("\t-->(2,3) link=", byte);
+ setup_row_direct(2,3,byte);
+ setup_temp_row(2,3);
+ verify_connection(7); /* to 3*/
+ }
+ }
+#endif
+
+ val = pci_read_config32(NODE_HT(7), 0x6c);
+ byte = (val>>2) & 0x3; /* get default link on 7 to 2*/
+ print_linkn("(3,2) link=", byte);
+ setup_remote_row_direct(3,2, byte);
+
+#if (CONFIG_MAX_PHYSICAL_CPUS > 4) || (CONFIG_MAX_PHYSICAL_CPUS_4_BUT_MORE_INSTALLED == 1)
+ /* set link from 3 to 5 before enable it*/
+ val = get_row(7,3);
+ byte = ((val>>16) & 0xfe) - link_connection(7,2) - link_connection(7,1);
+ byte = get_linkn_last_count(byte);
+ if((byte>>2)==1) { /* We should have three coherent links on node 3 for 6p and above*/
+ byte &= 3; /*bit [3,2] is count-2*/
+ print_linkn("(3,5) link=", byte);
+ setup_remote_row_direct(3, 5, byte);
+ }
+
+ val = get_row(2,2);
+ byte = ((val>>16) & 0xfe) - link_connection(2,3) - link_connection(2,0);
+ byte = get_linkn_last_count(byte);
+
+ if((byte>>2)==1) { /* We should have three coherent link on node 2 for 6p and above*/
+ byte &= 3; /* bit [3,2] is count-2*/
+ print_linkn("(2,4) link=", byte);
+ setup_row_direct(2, 4, byte);
+ }
+#endif
+
+ //Beside 3, 1 is set, We need to make sure 3, 5 is set already in case has three link in 3
+#if !CROSS_BAR_47_56
+ static const u8 conn4_3[] = {
+ 3,0,
+ };
+#else
+ static const u8 conn4_3[] = {
+ 3,0,1,1,
+ };
+#endif
+ setup_remote_row_indirect_group(conn4_3, ARRAY_SIZE(conn4_3));
+
+/* ready to enable RT for Node 3 */
+ rename_temp_node(3);
+ enable_routing(3); /* enable routing on node 3 (temp.) */
+
+ // beside 2, 0 is set, We need to make sure 2, 4 link is set already in case has three link in 2
+#if !CROSS_BAR_47_56
+ static const u8 conn4_2[] = {
+ 2,1,
+ };
+#else
+ static const u8 conn4_2[] = {
+ 2,1,0,1,
+ };
+#endif
+ setup_row_indirect_group(conn4_2, ARRAY_SIZE(conn4_2));
+
+#if 0
+ /*We need to do sth to reverse work for setup_temp_row (0,1) (1,3) */
+ /* it will be done by clear_dead_links */
+ clear_temp_row(0);
+ clear_temp_row(1);
+#endif
+
+ return nodes;
+
+}
+
+#endif /* CONFIG_MAX_PHYSICAL_CPUS > 2 */
+
+#if CONFIG_MAX_PHYSICAL_CPUS > 4
+
+static unsigned setup_smp6(void)
+{
+ unsigned nodes;
+ u8 byte;
+ uint32_t val;
+
+ nodes=6;
+
+ /* Setup and check temporary connection from Node 0 to Node 4 through 2*/
+ val = get_row(2,2);
+ byte = ((val>>16) & 0xfe) - link_connection(2,3) - link_connection(2,0);
+ byte = get_linkn_last_count(byte);
+
+ if((byte>>2)==0) { /* We should have three coherent link on node 2 for 6p and above*/
+ nodes = 4;
+ return nodes;
+ }
+
+ /* Setup and check temporary connection from Node 0 to Node 5 through 1, 3*/
+ /* set link from 3 to 5 before enable it*/
+ val = get_row(3,3);
+ byte = ((val>>16) & 0xfe) - link_connection(3,2) - link_connection(3,1);
+ byte = get_linkn_last_count(byte);
+ if((byte>>2)==0) { /* We should have three coherent links on node 3 for 6p and above*/
+ nodes = 4;
+ return nodes;
+ }
+
+ /* We found 6 nodes so far. Now setup all nodes for 6p */
+#warning "FIXME we need to find out the correct gateway for 6p"
+ static const u8 conn6_1[] = {
+#if !CROSS_BAR_47_56
+ 0, 4,
+ 0, 5,
+ 1, 4,
+ 1, 5,
+ 2, 5,
+ 3, 4,
+#else
+ 0, 4, 2, 0,
+ 0, 5, 2, 1,
+ 1, 4, 3, 1,
+ 1, 5, 3, 0,
+ 2, 5, 3, 0,
+ 3, 4, 2, 0,
+#endif
+ };
+
+ setup_row_indirect_group(conn6_1, ARRAY_SIZE(conn6_1));
+
+ for(byte=0; byte<4; byte+=2) {
+ setup_temp_row(byte,byte+2);
+ }
+ verify_connection(7);
+ val = pci_read_config32(NODE_HT(7), 0x6c);
+ byte = (val>>2) & 0x3; /*get default link on 7 to 2*/
+ print_linkn("(4,2) link=", byte);
+
+ setup_row_local(7,4);
+ setup_remote_row_direct(4, 2, byte);
+ setup_remote_node(4); /* Setup the regs on the remote node */
+
+ /* Set indirect connection to 0, to 3 */
+ //we only need to set 4,0 here
+ static const u8 conn6_2[] = {
+#if !CROSS_BAR_47_56
+ 4, 0,
+#else
+ 4, 0, 2, 0,
+#endif
+ };
+
+ setup_remote_row_indirect_group(conn6_2, ARRAY_SIZE(conn6_2));
+
+ rename_temp_node(4);
+ enable_routing(4);
+
+ setup_temp_row(0,1);
+ for(byte=0; byte<4; byte+=2) {
+ setup_temp_row(byte+1,byte+3);
+ }
+ verify_connection(7);
+
+ val = pci_read_config32(NODE_HT(7), 0x6c);
+ byte = (val>>2) & 0x3; /* get default link on 7 to 3*/
+ print_linkn("(5,3) link=", byte);
+ setup_row_local(7,5);
+ setup_remote_row_direct(5, 3, byte);
+ setup_remote_node(5); /* Setup the regs on the remote node */
+
+#if !CROSS_BAR_47_56
+ /* We need to init link between 4, and 5 direct link */
+ val = get_row(4,4);
+ byte = ((val>>16) & 0xfe) - link_connection(4,2);
+ byte = get_linkn_last_count(byte);
+ print_linkn("(4,5) link=", byte & 3);
+
+ setup_row_direct(4,5, byte & 0x3);
+ setup_temp_row(0,2);
+ setup_temp_row(2,4);
+ setup_temp_row(4,5);
+ verify_connection(7); /* to 5*/
+
+#if CONFIG_MAX_PHYSICAL_CPUS > 6
+ /* We need to find out which link is to node5 */
+
+ if((byte>>2)==2) { /* one to node5, one to node2, one to node6*/
+ val = get_row(7,5);
+ if((val>>16) == 1) { /* that link is to node6, because via node 3 node 5 has been set*/
+ val = get_row(4,4);
+ byte = ((val>>16) & 0xfe) - link_connection(4,2);
+ byte = get_linkn_first(byte);
+ print_linkn("\t-->(4,5) link=", byte);
+ setup_row_direct(4,5,byte);
+ setup_temp_row(4,5);
+ verify_connection(7); /* to 5*/
+ }
+ }
+#endif
+
+ val = pci_read_config32(NODE_HT(7), 0x6c);
+ byte = (val>>2) & 0x3; /* get default link on 7 to 4*/
+ print_linkn("(5,4) link=", byte);
+ setup_remote_row_direct(5,4, byte);
+
+ //init 5, 7 here
+ val = get_row(7,5);
+ byte = ((val>>16) & 0xfe) - link_connection(7,4) - link_connection(7,3);
+ byte = get_linkn_last_count(byte);
+ if((byte>>2)==1) { /* We should have three coherent links on node 5 for 6p and above*/
+ byte &= 3; /*bit [3,2] is count-2*/
+ print_linkn("(5,7) link=", byte);
+ setup_remote_row_direct(5, 7, byte);
+ }
+
+ //init 4,6 here
+ val = get_row(4,4);
+ byte = ((val>>16) & 0xfe) - link_connection(4,5) - link_connection(4,2);
+ byte = get_linkn_last_count(byte);
+
+ if((byte>>2)==1) { /* We should have three coherent link on node 4 for 6p and above*/
+ byte &= 3; /* bit [3,2] is count-2*/
+ print_linkn("(4,6) link=", byte);
+ setup_row_direct(4, 6, byte);
+ }
+
+#endif
+
+ //We need to set 5,0 here only, We need to set up 5, 7 to make 5,0
+ /* Set indirect connection to 0, to 3 for indirect we will use clockwise routing */
+ static const u8 conn6_3[] = {
+#if !CROSS_BAR_47_56
+ 5, 0,
+#else
+ 5, 0, 3, 0,
+#endif
+ };
+
+ setup_remote_row_indirect_group(conn6_3, ARRAY_SIZE(conn6_3));
+
+/* ready to enable RT for 5 */
+ rename_temp_node(5);
+ enable_routing(5); /* enable routing on node 5 (temp.) */
+
+ static const u8 conn6_4[] = {
+#if !CROSS_BAR_47_56
+ 4, 1,
+ 4, 3,
+
+ 5, 2,
+ 5, 1,
+
+#else
+ 4, 1, 2, 0,
+ 4, 3, 2, 0,
+ 4, 5, 2, 0,
+
+ 5, 2, 3, 0,
+ 5, 1, 3, 0,
+ 5, 4, 3, 0,
+
+#endif
+ };
+
+ setup_row_indirect_group(conn6_4, ARRAY_SIZE(conn6_4));
+
+#if 0
+ /* We need to do sth about reverse about setup_temp_row (0,1), (2,4), (1, 3), (3,5)
+ * It will be done by clear_dead_links
+ */
+ for(byte=0; byte<4; byte++) {
+ clear_temp_row(byte);
+ }
+#endif
+
+ return nodes;
+
+}
+
+#endif /* CONFIG_MAX_PHYSICAL_CPUS > 4 */
+
+#if CONFIG_MAX_PHYSICAL_CPUS > 6
+
+static unsigned setup_smp8(void)
+{
+ unsigned nodes;
+ u8 byte;
+ uint32_t val;
+
+ nodes=8;
+
+ /* Setup and check temporary connection from Node 0 to Node 6 via 2 and 4 to 7 */
+ val = get_row(4,4);
+#if CROSS_BAR_47_56
+ byte = ((val>>16) & 0xfe) - link_connection(4,2);
+#else
+ byte = ((val>>16) & 0xfe) - link_connection(4,5) - link_connection(4,2);
+ byte = get_linkn_last_count(byte); /* Max link to 6*/
+ if((byte>>2)==0) { /* We should have two or three coherent links on node 4 for 8p*/
+ nodes = 6;
+ return nodes;
+ }
+#endif
+
+#if CROSS_BAR_47_56
+ byte = get_linkn_last_count(byte); /* Max link to 6*/
+ if((byte>>2)<2) { /* We should have two or three coherent links on node 4 for 8p*/
+ nodes = 6;
+ return nodes;
+ }
+#if TRY_HIGH_FIRST == 1
+ byte = ((val>>16) & 0xfe) - link_connection(4,2);
+ byte = get_linkn_first(byte); /*Min link to 6*/
+#else
+ byte &= 3; /* bit [3,2] is count-1 or 2*/
+#endif
+ print_linkn("(4,6) link=", byte);
+ setup_row_direct(4, 6, byte);
+#endif
+
+#if !CROSS_BAR_47_56
+ /* Setup and check temporary connection from Node 0 to Node 7 through 1, 3, 5*/
+ val = get_row(5,5);
+ byte = ((val>>16) & 0xfe) - link_connection(5,4) - link_connection(5,3);
+ byte = get_linkn_last_count(byte);
+ if((byte>>2)==0) { /* We should have three coherent links on node 5 for 6p and above*/
+ nodes = 6;
+ return nodes;
+ }
+#endif
+
+ /* We found 8 nodes so far. Now setup all nodes for 8p */
+ static const u8 conn8_1[] = {
+#if !CROSS_BAR_47_56
+ 0, 6,
+ /*0, 7,*/
+ 1, 6,
+ /*1, 7,*/
+ 2, 6,
+ /*2, 7,*/
+ 3, 6,
+ /*3, 7,*/
+ /*4, 7,*/
+ 5, 6,
+#else
+ 0, 6, 2, 0,
+ /*0, 7, 2, 0,*/
+ 1, 6, 3, 0,
+ /*1, 7, 3, 0,*/
+ 2, 6, 4, 0,
+ /*2, 7, 4, 0,*/
+ 3, 6, 5, 1,
+ /*3, 7, 5, 0,*/
+#endif
+ };
+
+ setup_row_indirect_group(conn8_1,ARRAY_SIZE(conn8_1));
+
+ for(byte=0; byte<6; byte+=2) {
+ setup_temp_row(byte,byte+2);
+ }
+ verify_connection(7);
+ val = pci_read_config32(NODE_HT(7), 0x6c);
+ byte = (val>>2) & 0x3; /* get default link on 7 to 4*/
+ print_linkn("(6,4) link=", byte);
+
+ setup_row_local(7,6);
+ setup_remote_row_direct(6, 4, byte);
+ setup_remote_node(6); /* Setup the regs on the remote node */
+ /* Set indirect connection to 0, to 3 */
+#warning "FIXME we need to find out the correct gateway for 8p"
+ static const u8 conn8_2[] = {
+#if !CROSS_BAR_47_56
+ 6, 0,
+#else
+ 6, 0, 4, 0,
+#endif
+ };
+
+ setup_remote_row_indirect_group(conn8_2, ARRAY_SIZE(conn8_2));
+
+#if CROSS_BAR_47_56
+ //init 5, 6 here
+ /* here init 5, 6 */
+ /* Setup and check temporary connection from Node 0 to Node 5 through 1, 3, 5*/
+ val = get_row(5,5);
+ byte = ((val>>16) & 0xfe) - link_connection(5,3);
+#if TRY_HIGH_FIRST == 1
+ byte = get_linkn_first(byte);
+#else
+ byte = get_linkn_last(byte);
+#endif
+ print_linkn("(5,6) link=", byte);
+ setup_row_direct(5, 6, byte);
+
+ setup_temp_row(0,1); /* temp. link between nodes 0 and 1 */
+ for(byte=0; byte<4; byte+=2) {
+ setup_temp_row(byte+1,byte+3);
+ }
+ setup_temp_row(5,6);
+
+ verify_connection(7);
+
+ val = get_row(7,6); // to chect it if it is node6 before renaming
+ if( (val>>16) == 1) { // it is real node 7 so swap it
+ /* We need to recompute link to 6 */
+ val = get_row(5,5);
+ byte = ((val>>16) & 0xfe) - link_connection(5,3);
+#if TRY_HIGH_FIRST == 1
+ byte = get_linkn_first(byte);
+#else
+ byte = get_linkn_last(byte);
+#endif
+ print_linkn("\t-->(5,6) link=", byte);
+ setup_row_direct(5, 6, byte);
+#if 0
+ setup_temp_row(0,1); /* temp. link between nodes 0 and 1 */
+ for(byte=0; byte<4; byte+=2) {
+ setup_temp_row(byte+1,byte+3);
+ }
+#endif
+ setup_temp_row(5,6);
+
+ verify_connection(7);
+ }
+ val = pci_read_config32(NODE_HT(7), 0x6c);
+ byte = (val>>2) & 0x3; /* get default link on 7 to 5*/
+ print_linkn("(6,5) link=", byte);
+ setup_remote_row_direct(6, 5, byte);
+ /*Till now 56, 65 done */
+#endif
+
+ rename_temp_node(6);
+ enable_routing(6);
+
+#if !CROSS_BAR_47_56
+ setup_temp_row(0,1);
+ for(byte=0; byte<6; byte+=2) {
+ setup_temp_row(byte+1,byte+3);
+ }
+
+ verify_connection(7);
+
+ val = pci_read_config32(NODE_HT(7), 0x6c);
+ byte = (val>>2) & 0x3; /* get default link on 7 to 5*/
+ print_linkn("(7,5) link=", byte);
+ setup_row_local(7,7);
+ setup_remote_row_direct(7, 5, byte);
+
+#else
+ val = get_row(4,4);
+ byte = ((val>>16) & 0xfe) - link_connection(4,2) - link_connection(4,6);
+ byte = get_linkn_first(byte);
+ print_linkn("(4,7) link=", byte);
+ setup_row_direct(4, 7, byte);
+
+ /* Setup and check temporary connection from Node 0 to Node 7 through 2, and 4*/
+ for(byte=0; byte<4; byte+=2) {
+ setup_temp_row(byte,byte+2);
+ }
+
+ verify_connection(7);
+
+ val = pci_read_config32(NODE_HT(7), 0x6c);
+ byte = (val>>2) & 0x3; /* get default link on 7 to 4*/
+ print_linkn("(7,4) link=", byte);
+ setup_row_local(7,7);
+ setup_remote_row_direct(7, 4, byte);
+ /* till now 4-7, 7-4 done. */
+#endif
+ setup_remote_node(7); /* Setup the regs on the remote node */
+
+#if CROSS_BAR_47_56
+ /* here init 5, 7 */
+ /* Setup and check temporary connection from Node 0 to Node 5 through 1, 3, 5*/
+ val = get_row(5,5);
+ byte = ((val>>16) & 0xfe) - link_connection(5,3) - link_connection(5,6);
+ byte = get_linkn_first(byte);
+ print_linkn("(5,7) link=", byte);
+ setup_row_direct(5, 7, byte);
+
+ setup_temp_row(0,1); /* temp. link between nodes 0 and 1 */
+ for(byte=0; byte<4; byte+=2) {
+ setup_temp_row(byte+1,byte+3);
+ }
+
+ verify_connection(7);
+
+ val = pci_read_config32(NODE_HT(7), 0x6c);
+ byte = (val>>2) & 0x3; /* get default link on 7 to 5*/
+ print_linkn("(7,5) link=", byte);
+ setup_remote_row_direct(7, 5, byte);
+ /*Till now 57, 75 done */
+
+#endif
+
+ /* We need to init link between 6, and 7 direct link */
+ val = get_row(6,6);
+#if !CROSS_BAR_47_56
+ byte = ((val>>16) & 0xfe) - link_connection(6,4);
+#else
+ byte = ((val>>16) & 0xfe) - link_connection(6,4) - link_connection(6,5);
+#endif
+ byte = get_linkn_first(byte);
+ print_linkn("(6,7) link=", byte);
+ setup_row_direct(6,7, byte);
+
+ val = get_row(7,7);
+#if !CROSS_BAR_47_56
+ byte = ((val>>16) & 0xfe) - link_connection(7,5);
+#else
+ byte = ((val>>16) & 0xfe) - link_connection(7,5) - link_connection(7,4);
+#endif
+ byte = get_linkn_first(byte);
+ print_linkn("(7,6) link=", byte);
+ setup_row_direct(7,6, byte);
+
+ /* Set indirect connection to 0, to 3 for indirect we will use clockwise routing */
+ static const u8 conn8_3[] = {
+#if !CROSS_BAR_47_56
+ 0, 7, /* restore it*/
+ 1, 7,
+ 2, 7,
+ 3, 7,
+ 4, 7,
+
+ 6, 1,
+ 6, 2,
+ 6, 3,
+ 6, 5,
+
+ 7, 0,
+ 7, 1,
+ 7, 2,
+ 7, 3,
+ 7, 4,
+#else
+
+
+ 4, 5, 6, 1,
+ 5, 4, 7, 1,
+
+ 6, 1, 5, 0, // or 4, 1
+ 6, 2, 4, 0,
+ 6, 3, 5, 0, // or 4, 1
+
+ 7, 0, 4, 0, // or 5, 1
+ 7, 1, 5, 0,
+ 7, 2, 4, 0, // or 5, 1
+ 7, 3, 5, 0,
+
+ 0, 7, 2, 0, /* restore it*/
+ 1, 7, 3, 0,
+ 2, 7, 4, 1,
+ 3, 7, 5, 0,
+
+ 2, 5, 4, 1, /* reset it */
+ 3, 4, 5, 1,
+
+ 4, 1, 2, 1, /* reset it */
+ 4, 3, 2, 1,
+
+ 5, 2, 3, 1, /* reset it */
+ 5, 0, 3, 1,
+
+#endif
+ };
+
+ setup_row_indirect_group(conn8_3, ARRAY_SIZE(conn8_3));
+
+#if CROSS_BAR_47_56
+ /* for 47, 56, 57, 75, 46, 64 we need to substract another link to
+ 6, 7, 6, 6, 7, 7 */
+ static const u8 conn8_4[] = {
+//direct
+ 4, 7, 6,
+ 5, 6, 7,
+ 5, 7, 6,
+ 7, 5, 6,
+ 4, 6, 7,
+ 6, 4, 7,
+
+//in direct
+ 0, 6, 1,
+ 0, 7, 1,
+
+ 1, 6, 0,
+ 1, 7, 0,
+
+ 2, 6, 3,
+// 2, 7, 3, +
+
+// 3, 6, 1, +
+ 3, 7, 2,
+
+ 6, 0, 7,
+ 6, 1, 7, // needed for via 5
+ 6, 1, 4, // ???
+ 6, 2, 7,
+ 6, 3, 7, // needed for via 5
+ 6, 3, 4, //???
+ 7, 0, 6, // needed for via 4
+ 7, 0, 5, //???
+ 7, 1, 6,
+ 7, 2, 6, // needed for via 4
+ 7, 2, 5, //???
+ 7, 3, 6,
+ };
+
+ opt_broadcast_rt_group(conn8_4, ARRAY_SIZE(conn8_4));
+
+ static const u8 conn8_5[] = {
+ 2, 7, 0,
+
+ 3, 6, 1,
+ };
+
+ opt_broadcast_rt_plus_group(conn8_5, ARRAY_SIZE(conn8_5));
+#endif
+
+
+
+/* ready to enable RT for Node 7 */
+ enable_routing(7); /* enable routing on node 7 (temp.) */
+
+ return nodes;
+}
+
+#endif /* CONFIG_MAX_PHYSICAL_CPUS > 6 */
+
+
+#if CONFIG_MAX_PHYSICAL_CPUS > 1
+
+static unsigned setup_smp(void)
+{
+ unsigned nodes;
+
+ print_spew("Enabling SMP settings\n");
+
+ nodes = setup_smp2();
+#if CONFIG_MAX_PHYSICAL_CPUS > 2
+ if(nodes == 2)
+ nodes = setup_smp4();
+#endif
+
+#if CONFIG_MAX_PHYSICAL_CPUS > 4
+ if(nodes == 4)
+ nodes = setup_smp6();
+#endif
+
+#if CONFIG_MAX_PHYSICAL_CPUS > 6
+ if(nodes == 6)
+ nodes = setup_smp8();
+#endif
+
+ printk(BIOS_DEBUG, "%02x nodes initialized.\n", nodes);
+
+ return nodes;
+}
+
+static unsigned verify_mp_capabilities(unsigned nodes)
+{
+ unsigned node, mask;
+
+ mask = 0x06; /* BigMPCap */
+
+ for (node=0; node<nodes; node++) {
+ mask &= pci_read_config32(NODE_MC(node), 0xe8);
+ }
+
+ switch(mask) {
+#if CONFIG_MAX_PHYSICAL_CPUS > 2
+ case 0x02: /* MPCap */
+ if(nodes > 2) {
+ print_err("Going back to DP\n");
+ return 2;
+ }
+ break;
+#endif
+ case 0x00: /* Non SMP */
+ if(nodes >1 ) {
+ print_err("Going back to UP\n");
+ return 1;
+ }
+ break;
+ }
+
+ return nodes;
+
+}
+
+
+static void clear_dead_routes(unsigned nodes)
+{
+ int last_row;
+ int node, row;
+#if CONFIG_MAX_PHYSICAL_CPUS == 8
+ if(nodes==8) return;/* don't touch (7,7)*/
+#endif
+ last_row = nodes;
+ if (nodes == 1) {
+ last_row = 0;
+ }
+ for(node = 7; node >= 0; node--) {
+ for(row = 7; row >= last_row; row--) {
+ fill_row(node, row, DEFAULT);
+ }
+ }
+
+ /* Update the local row */
+ for( node=0; node<nodes; node++) {
+ uint32_t val = 0;
+ for(row =0; row<nodes; row++) {
+ val |= get_row(node, row);
+ }
+ fill_row(node, node, (((val & 0xff) | ((val >> 8) & 0xff)) << 16) | 0x0101);
+ }
+}
+#endif /* CONFIG_MAX_PHYSICAL_CPUS > 1 */
+
+#if CONFIG_LOGICAL_CPUS==1
+static unsigned verify_dualcore(unsigned nodes)
+{
+ unsigned node, totalcpus, tmp;
+
+ totalcpus = 0;
+ for (node=0; node<nodes; node++) {
+ tmp = (pci_read_config32(NODE_MC(node), 0xe8) >> 12) & 3 ;
+ totalcpus += (tmp + 1);
+ }
+
+ return totalcpus;
+
+}
+#endif
+
+static void coherent_ht_finalize(unsigned nodes)
+{
+ unsigned node;
+#if CONFIG_K8_REV_F_SUPPORT == 0
+ int rev_a0;
+#endif
+#if CONFIG_LOGICAL_CPUS==1
+ unsigned total_cpus;
+
+ if (read_option(multi_core, 0) == 0) { /* multi_core */
+ total_cpus = verify_dualcore(nodes);
+ }
+ else {
+ total_cpus = nodes;
+ }
+#endif
+