2 static void setup_coherent_ht_domain(void)
4 static const unsigned int register_values[] = {
5 /* Routing Table Node i
14 * [ 0: 3] Request Route
15 * [0] Route to this node
19 * [11: 8] Response Route
20 * [0] Route to this node
24 * [19:16] Broadcast route
25 * [0] Route to this node
30 PCI_ADDR(0, 0x18, 0, 0x40), 0xfff0f0f0, 0x00010101,
31 PCI_ADDR(0, 0x18, 0, 0x44), 0xfff0f0f0, 0x00010101,
32 PCI_ADDR(0, 0x18, 0, 0x48), 0xfff0f0f0, 0x00010101,
33 PCI_ADDR(0, 0x18, 0, 0x4c), 0xfff0f0f0, 0x00010101,
34 PCI_ADDR(0, 0x18, 0, 0x50), 0xfff0f0f0, 0x00010101,
35 PCI_ADDR(0, 0x18, 0, 0x54), 0xfff0f0f0, 0x00010101,
36 PCI_ADDR(0, 0x18, 0, 0x58), 0xfff0f0f0, 0x00010101,
37 PCI_ADDR(0, 0x18, 0, 0x5c), 0xfff0f0f0, 0x00010101,
39 /* Hypetransport Transaction Control Register
41 * [ 0: 0] Disable read byte probe
43 * 1 = Probes not issued
44 * [ 1: 1] Disable Read Doubleword probe
46 * 1 = Probes not issued
47 * [ 2: 2] Disable write byte probes
49 * 1 = Probes not issued
50 * [ 3: 3] Disable Write Doubleword Probes
52 * 1 = Probes not issued.
53 * [ 4: 4] Disable Memroy Controller Target Start
54 * 0 = TgtStart packets are generated
55 * 1 = TgtStart packets are not generated.
57 * 0 = Second CPU disabled or not present
58 * 1 = Second CPU enabled.
59 * [ 6: 6] CPU Request PassPW
60 * 0 = CPU requests do not pass posted writes
61 * 1 = CPU requests pass posted writes.
62 * [ 7: 7] CPU read Respons PassPW
63 * 0 = CPU Responses do not pass posted writes
64 * 1 = CPU responses pass posted writes.
65 * [ 8: 8] Disable Probe Memory Cancel
66 * 0 = Probes may generate MemCancels
67 * 1 = Probes may not generate MemCancels
68 * [ 9: 9] Disable Remote Probe Memory Cancel.
69 * 0 = Probes hitting dirty blocks generate memory cancel packets
70 * 1 = Only probed caches on the same node as the memory controller
71 * generate cancel packets.
72 * [10:10] Disable Fill Probe
73 * 0 = Probes issued for cache fills
74 * 1 = Probes not issued for cache fills.
75 * [11:11] Response PassPw
76 * 0 = Downstream response PassPW based on original request
77 * 1 = Downstream response PassPW set to 1
78 * [12:12] Change ISOC to Ordered
79 * 0 = Bit 1 of coherent HT RdSz/WrSz command used for iosynchronous prioritization
80 * 1 = Bit 1 of coherent HT RdSz/WrSz command used for ordering.
81 * [14:13] Buffer Release Priority select
86 * [15:15] Limit Coherent HT Configuration Space Range
87 * 0 = No coherent HT configuration space restrictions
88 * 1 = Limit coherent HT configuration space based on node count
89 * [16:16] Local Interrupt Conversion Enable.
90 * 0 = ExtInt/NMI interrups unaffected.
91 * 1 = ExtInt/NMI broadcat interrupts converted to LINT0/1
92 * [17:17] APIC Extended Broadcast Enable.
93 * 0 = APIC broadcast is 0F
94 * 1 = APIC broadcast is FF
95 * [18:18] APIC Extended ID Enable
96 * 0 = APIC ID is 4 bits.
97 * 1 = APIC ID is 8 bits.
98 * [19:19] APIC Extended Spurious Vector Enable
99 * 0 = Lower 4 bits of spurious vector are read-only 1111
100 * 1 = Lower 4 bits of spurious vecotr are writeable.
101 * [20:20] Sequence ID Source Node Enable
102 * 0 = Normal operation
103 * 1 = Keep SeqID on routed packets for debugging.
104 * [22:21] Downstream non-posted request limit
110 * [25:24] Medium-Priority Bypass Count
111 * - Maximum # of times a medium priority access can pass a low
112 * priority access before Medium-Priority mode is disabled for one access.
113 * [27:26] High-Priority Bypass Count
114 * - Maximum # of times a high prioirty access can pass a medium or low
115 * priority access before High-prioirty mode is disabled for one access.
116 * [28:28] Enable High Priority CPU Reads
117 * 0 = Cpu reads are medium prioirty
118 * 1 = Cpu reads are high prioirty
119 * [29:29] Disable Low Priority Writes
120 * 0 = Non-isochronous writes are low priority
121 * 1 = Non-isochronous writes are medium prioirty
122 * [30:30] Disable High Priority Isochronous writes
123 * 0 = Isochronous writes are high priority
124 * 1 = Isochronous writes are medium priority
125 * [31:31] Disable Medium Priority Isochronous writes
126 * 0 = Isochronous writes are medium are high
127 * 1 = With bit 30 set makes Isochrouns writes low priority.
129 PCI_ADDR(0, 0x18, 0, 0x68), 0x00800000, 0x0f00840f,
130 /* HT Initialization Control Register
132 * [ 0: 0] Routing Table Disable
133 * 0 = Packets are routed according to routing tables
134 * 1 = Packets are routed according to the default link field
135 * [ 1: 1] Request Disable (BSP should clear this)
136 * 0 = Request packets may be generated
137 * 1 = Request packets may not be generated.
138 * [ 3: 2] Default Link (Read-only)
142 * 11 = CPU on same node
144 * - Scratch bit cleared by a cold reset
145 * [ 5: 5] BIOS Reset Detect
146 * - Scratch bit cleared by a cold reset
147 * [ 6: 6] INIT Detect
148 * - Scratch bit cleared by a warm or cold reset not by an INIT
151 PCI_ADDR(0, 0x18, 0, 0x6C), 0xffffff8c, 0x00000000 | (1 << 6) |(1 << 5)| (1 << 4),
152 /* LDTi Capabilities Registers
157 /* LDTi Link Control Registrs
161 * [ 1: 1] CRC Flood Enable
162 * 0 = Do not generate sync packets on CRC error
163 * 1 = Generate sync packets on CRC error
164 * [ 2: 2] CRC Start Test (Read-Only)
165 * [ 3: 3] CRC Force Frame Error
166 * 0 = Do not generate bad CRC
167 * 1 = Generate bad CRC
168 * [ 4: 4] Link Failure
169 * 0 = No link failure detected
170 * 1 = Link failure detected
171 * [ 5: 5] Initialization Complete
172 * 0 = Initialization not complete
173 * 1 = Initialization complete
174 * [ 6: 6] Receiver off
177 * [ 7: 7] Transmitter Off
179 * 1 = Transmitter off
182 * [0] = 1 Error on byte lane 0
183 * [1] = 1 Error on byte lane 1
184 * [12:12] Isochrnous Enable (Read-Only)
185 * [13:13] HT Stop Tristate Enable
186 * 0 = Driven during an LDTSTOP_L
187 * 1 = Tristated during and LDTSTOP_L
188 * [14:14] Extended CTL Time
189 * 0 = CTL is asserted for 16 bit times during link initialization
190 * 1 = CTL is asserted for 50us during link initialization
191 * [18:16] Max Link Width In (Read-Only?)
194 * [19:19] Doubleword Flow Control in (Read-Only)
195 * 0 = This link does not support doubleword flow control
196 * 1 = This link supports doubleword flow control
197 * [22:20] Max Link Width Out (Read-Only?)
200 * [23:23] Doubleworld Flow Control out (Read-Only)
201 * 0 = This link does not support doubleword flow control
202 * 1 = This link supports doubleworkd flow control
203 * [26:24] Link Width In
211 * 111 = Link physically not connected
212 * [27:27] Doubleword Flow Control In Enable
213 * 0 = Doubleword flow control disabled
214 * 1 = Doubleword flow control enabled (Not currently supported)
215 * [30:28] Link Width Out
223 * 111 = Link physically not connected
224 * [31:31] Doubleworld Flow Control Out Enable
225 * 0 = Doubleworld flow control disabled
226 * 1 = Doubleword flow control enabled (Not currently supported)
228 PCI_ADDR(0, 0x18, 0, 0x84), 0x00009c05, 0x11110020,
229 /* LDTi Frequency/Revision Registers
233 * [ 4: 0] Minor Revision
234 * Contains the HT Minor revision
235 * [ 7: 5] Major Revision
236 * Contains the HT Major revision
237 * [11: 8] Link Frequency (Takes effect the next time the link is reconnected)
254 * [15:12] Error (Not currently Implemented)
255 * [31:16] Indicates the frequency capabilities of the link
256 * [16] = 1 encoding 0000 of freq supported
257 * [17] = 1 encoding 0001 of freq supported
258 * [18] = 1 encoding 0010 of freq supported
259 * [19] = 1 encoding 0011 of freq supported
260 * [20] = 1 encoding 0100 of freq supported
261 * [21] = 1 encoding 0101 of freq supported
262 * [22] = 1 encoding 0110 of freq supported
263 * [23] = 1 encoding 0111 of freq supported
264 * [24] = 1 encoding 1000 of freq supported
265 * [25] = 1 encoding 1001 of freq supported
266 * [26] = 1 encoding 1010 of freq supported
267 * [27] = 1 encoding 1011 of freq supported
268 * [28] = 1 encoding 1100 of freq supported
269 * [29] = 1 encoding 1101 of freq supported
270 * [30] = 1 encoding 1110 of freq supported
271 * [31] = 1 encoding 1111 of freq supported
273 PCI_ADDR(0, 0x18, 0, 0x88), 0xfffff0ff, 0x00000200,
274 /* LDTi Feature Capability
279 /* LDTi Buffer Count Registers
284 /* LDTi Bus Number Registers
288 * For NonCoherent HT specifies the bus number downstream (behind the host bridge)
289 * [ 0: 7] Primary Bus Number
290 * [15: 8] Secondary Bus Number
291 * [23:15] Subordiante Bus Number
294 PCI_ADDR(0, 0x18, 0, 0x94), 0xff000000, 0x00ff0000,
295 /* LDTi Type Registers
303 print_debug("setting up coherent ht domain....\r\n");
304 max = sizeof(register_values)/sizeof(register_values[0]);
305 for(i = 0; i < max; i += 3) {
310 print_debug_hex32(register_values[i]);
312 print_debug_hex32(register_values[i+2]);
315 dev = register_values[i] & ~0xff;
316 where = register_values[i] & 0xff;
317 reg = pci_read_config32(dev, where);
318 reg &= register_values[i+1];
319 reg |= register_values[i+2];
320 pci_write_config32(dev, where, reg);
322 reg = pci_read_config32(register_values[i]);
323 reg &= register_values[i+1];
324 reg |= register_values[i+2] & ~register_values[i+1];
325 pci_write_config32(register_values[i], reg);
328 print_debug("done.\r\n");
331 /* coherent hypertransport initialization for AMD64
332 * written by Stefan Reinauer <stepan@openbios.info>
333 * (c) 2003 by SuSE Linux AG
335 * This code is licensed under GPL.
339 * This algorithm assumes a grid configuration as follows:
342 * org. : 1x1 2x1 2x2 2x3 2x4
350 #include <device/pci_def.h>
351 #include "arch/romcc_io.h"
354 /* when generating a temporary row configuration we
355 * don't want broadcast to be enabled for that node.
358 #define generate_temp_row(x...) ((generate_row(x)&(~0x0f0000))|0x010000)
359 #define clear_temp_row(x) fill_row(x,7,DEFAULT)
360 #define enable_bsp_routing() enable_routing(0)
362 #define NODE_HT(x) PCI_DEV(0,24+x,0)
363 #define NODE_MP(x) PCI_DEV(0,24+x,1)
364 #define NODE_MC(x) PCI_DEV(0,24+x,3)
366 #define DEFAULT 0x00010101 /* default row entry */
369 typedef uint32_t u32;
375 static void disable_probes(void)
377 /* disable read/write/fill probes for uniprocessor setup
378 * they don't make sense if only one cpu is available
381 /* Hypetransport Transaction Control Register
383 * [ 0: 0] Disable read byte probe
385 * 1 = Probes not issued
386 * [ 1: 1] Disable Read Doubleword probe
388 * 1 = Probes not issued
389 * [ 2: 2] Disable write byte probes
391 * 1 = Probes not issued
392 * [ 3: 3] Disable Write Doubleword Probes
394 * 1 = Probes not issued.
395 * [10:10] Disable Fill Probe
396 * 0 = Probes issued for cache fills
397 * 1 = Probes not issued for cache fills.
402 print_debug("Disabling read/write/fill probes for UP... ");
404 val=pci_read_config32(NODE_HT(0), 0x68);
406 pci_write_config32(NODE_HT(0), 0x68, val);
408 print_debug("done.\r\n");
412 static void enable_routing(u8 node)
416 /* HT Initialization Control Register
418 * [ 0: 0] Routing Table Disable
419 * 0 = Packets are routed according to routing tables
420 * 1 = Packets are routed according to the default link field
421 * [ 1: 1] Request Disable (BSP should clear this)
422 * 0 = Request packets may be generated
423 * 1 = Request packets may not be generated.
424 * [ 3: 2] Default Link (Read-only)
428 * 11 = CPU on same node
430 * - Scratch bit cleared by a cold reset
431 * [ 5: 5] BIOS Reset Detect
432 * - Scratch bit cleared by a cold reset
433 * [ 6: 6] INIT Detect
434 * - Scratch bit cleared by a warm or cold reset not by an INIT
438 /* Enable routing table for BSP */
439 print_debug("Enabling routing table for node ");
440 print_debug_hex32(node);
442 val=pci_read_config32(NODE_HT(node), 0x6c);
443 val |= (1 << 6) | (1 << 5) | (1 << 4);
445 val &= ~((1<<1)|(1<<0));
447 /* Don't enable requests here as the indicated processor starts booting */
450 pci_write_config32(NODE_HT(node), 0x6c, val);
452 print_debug(" done.\r\n");
457 static void rename_temp_node(u8 node)
461 print_debug("Renaming current temp node to ");
462 print_debug_hex32(node);
464 val=pci_read_config32(NODE_HT(7), 0x60);
465 val &= (~7); /* clear low bits. */
466 val |= node; /* new node */
467 pci_write_config32(NODE_HT(7), 0x60, val);
469 print_debug(" done.\r\n");
474 static bool check_connection(u8 src, u8 dest, u8 link)
476 /* this function does 2 things:
477 * 1) detect whether the coherent HT link is connected.
478 * After this step follows a small idle loop.
479 * 2) verify that the coherent hypertransport link
480 * is established and actually working by reading the
481 * remote node's vendor/device id
491 val=pci_read_config32(NODE_HT(src), 0x98+link);
492 if ( (val&0x17) != 0x03)
495 /* idle loop to make sure the link is established */
496 for (val=0;val<16;val++);
499 val=pci_read_config32(NODE_HT(dest),0);
500 if(val != 0x11001022)
506 static unsigned int generate_row(u8 node, u8 row, u8 maxnodes)
508 /* Routing Table Node i
510 * F0: 0x40, 0x44, 0x48, 0x4c, 0x50, 0x54, 0x58, 0x5c
511 * i: 0, 1, 2, 3, 4, 5, 6, 7
513 * [ 0: 3] Request Route
514 * [0] Route to this node
515 * [1] Route to Link 0
516 * [2] Route to Link 1
517 * [3] Route to Link 2
518 * [11: 8] Response Route
519 * [0] Route to this node
520 * [1] Route to Link 0
521 * [2] Route to Link 1
522 * [3] Route to Link 2
523 * [19:16] Broadcast route
524 * [0] Route to this node
525 * [1] Route to Link 0
526 * [2] Route to Link 1
527 * [3] Route to Link 2
532 static const unsigned int rows_2p[2][2] = {
533 { 0x00030101, 0x00010404 },
534 { 0x00010404, 0x00030101 }
537 static const unsigned int rows_4p[4][4] = {
538 { 0x00070101, 0x00010404, 0x00050202, 0x00010402 },
539 { 0x00010808, 0x000b0101, 0x00010802, 0x00090202 },
540 { 0x00090202, 0x00010802, 0x000b0101, 0x00010808 },
541 { 0x00010402, 0x00050202, 0x00010404, 0x00070101 }
544 if (!(node>=maxnodes || row>=maxnodes)) {
546 ret=rows_2p[node][row];
548 ret=rows_4p[node][row];
552 printk_spew("generating entry n=%d, r=%d, max=%d - row=%x\n",
553 node,row,maxnodes,ret);
559 static void fill_row(u8 node, u8 row, u32 value)
562 print_debug("fill_row: pci_write_config32(");
563 print_debug_hex32(NODE_HT(node));
564 print_debug_char(',');
565 print_debug_hex32(0x40 + (row << 2));
566 print_debug_char(',');
567 print_debug_hex32(value);
568 print_debug(")\r\n");
570 pci_write_config32(NODE_HT(node), 0x40+(row<<2), value);
573 static void setup_row(u8 source, u8 dest, u8 cpus)
576 printk_spew("setting up link from node %d to %d (%d cpus)\r\n",
580 fill_row(source,dest,generate_row(source,dest,cpus));
583 static void setup_temp_row(u8 source, u8 dest, u8 cpus)
586 printk_spew("setting up temp. link from node %d to %d (%d cpus)\r\n",
590 fill_row(source,7,generate_temp_row(source,dest,cpus));
593 static void setup_node(u8 node, u8 cpus)
596 for(row=0; row<cpus; row++)
597 setup_row(node, row, cpus);
600 static void setup_remote_row(u8 source, u8 dest, u8 cpus)
602 fill_row(7, dest, generate_row(source, dest, cpus));
605 static void setup_remote_node(u8 node, u8 cpus)
607 static const uint8_t pci_reg[] = {
608 0x44, 0x4c, 0x54, 0x5c, 0x64, 0x6c, 0x74, 0x7c,
609 0x40, 0x48, 0x50, 0x58, 0x60, 0x68, 0x70, 0x78,
610 0x84, 0x8c, 0x94, 0x9c, 0xa4, 0xac, 0xb4, 0xbc,
611 0x80, 0x88, 0x90, 0x98, 0xa0, 0xa8, 0xb0, 0xb8,
612 0xc4, 0xcc, 0xd4, 0xdc,
613 0xc0, 0xc8, 0xd0, 0xd8,
614 0xe0, 0xe4, 0xe8, 0xec,
619 print_debug("setup_remote_node\r\n");
621 for(row=0; row<cpus; row++)
622 setup_remote_row(node, row, cpus);
624 /* copy the default resource map from node 0 */
625 for(i = 0; i < sizeof(pci_reg)/sizeof(pci_reg[0]); i++) {
629 print_debug("copying reg: ");
630 print_debug_hex8(reg);
632 value = pci_read_config32(NODE_MP(0), reg);
633 pci_write_config32(NODE_MP(7), reg, value);
637 print_debug("setup_remote_done\r\n");
644 static void setup_temp_node(u8 node, u8 cpus)
647 for(row=0; row<cpus; row++)
648 fill_row(7,row,generate_row(node,row,cpus));
652 static u8 setup_uniprocessor(void)
654 print_debug("Enabling UP settings\r\n");
660 static u8 setup_smp(void)
664 print_debug("Enabling SMP settings\r\n");
667 /* Setup and check a temporary connection to node 1 */
668 setup_temp_row(0,1,cpus);
670 if (!check_connection(0, 7, ACROSS)) { // Link: ACROSS
671 print_debug("No connection to Node 1.\r\n");
672 clear_temp_row(0); /* delete temp connection */
673 setup_uniprocessor(); /* and get up working */
677 /* We found 2 nodes so far */
678 setup_node(0, cpus); /* Node 1 is there. Setup Node 0 correctly */
679 setup_remote_node(1, cpus); /* Setup the routes on the remote node */
680 enable_routing(7); /* Enable routing on Node 1 */
681 rename_temp_node(1); /* Rename Node 7 to Node 1 */
683 clear_temp_row(0); /* delete temporary connection */
688 /* Setup and check temporary connection from Node 0 to Node 2 */
689 setup_temp_row(0,2,cpus);
691 if (!check_connection(0, 7, UP)) { // Link: UP
692 print_debug("No connection to Node 2.\r\n");
693 clear_temp_row(0); /* delete temp connection */
697 /* We found 3 nodes so far. Now setup a temporary
698 * connection from node 0 to node 3 via node 1
701 setup_temp_row(0,1,cpus); /* temp. link between nodes 0 and 1 */
702 setup_temp_row(1,3,cpus); /* temp. link between nodes 1 and 3 */
704 if (!check_connection(1, 7, UP)) { // Link: UP
705 print_debug("No connection to Node 3.\r\n");
706 clear_temp_row(0); /* delete temp connection */
707 clear_temp_row(1); /* delete temp connection */
711 /* We found 4 nodes so far. Now setup all nodes for 4p */
713 setup_node(0, cpus); /* The first 2 nodes are configured */
714 setup_node(1, cpus); /* already. Just configure them for 4p */
716 setup_temp_row(0,2,cpus);
717 setup_temp_node(2,cpus);
721 setup_temp_row(0,1,cpus);
722 setup_temp_row(1,3,cpus);
723 setup_temp_node(3,cpus);
724 enable_routing(7); /* enable routing on node 3 (temp.) */
733 print_debug_hex32(cpus);
734 print_debug(" nodes initialized.\r\n");
740 static unsigned detect_mp_capabilities(unsigned cpus)
742 unsigned node, row, mask;
746 print_debug("detect_mp_capabilities: ");
747 print_debug_hex32(cpus);
751 mask=0x06; /* BigMPCap */
753 mask=0x02; /* MPCap */
755 for (node=0; node<cpus; node++) {
756 if ((pci_read_config32(NODE_MC(node), 0xe8) & mask)!=mask)
763 /* one of our cpus is not mp capable */
765 print_debug("One of the CPUs is not MP capable. Going back to UP\r\n");
767 for (node=cpus; node>0; node--)
768 for (row=cpus; row>0; row--)
769 fill_row(NODE_HT(node-1), row-1, DEFAULT);
771 return setup_uniprocessor();
776 /* this is a shrunken cpuid. */
778 static unsigned int cpuid(unsigned int op)
782 asm volatile ( "cpuid" : "=a" (ret) : "a" (op));
787 static void coherent_ht_finalize(unsigned cpus)
792 /* set up cpu count and node count and enable Limit
793 * Config Space Range for all available CPUs.
794 * Also clear non coherent hypertransport bus range
795 * registers on Hammer A0 revision.
799 print_debug("coherent_ht_finalize\r\n");
801 rev_a0=((cpuid(1)&0xffff)==0x0f10);
803 for (node=0; node<cpus; node++) {
805 val=pci_read_config32(NODE_HT(node), 0x60);
806 val &= (~0x000F0070);
807 val |= ((cpus-1)<<16)|((cpus-1)<<4);
808 pci_write_config32(NODE_HT(node),0x60,val);
810 val=pci_read_config32(NODE_HT(node), 0x68);
812 pci_write_config32(NODE_HT(node),0x68,val);
815 pci_write_config32(NODE_HT(node),0x94,0);
816 pci_write_config32(NODE_HT(node),0xb4,0);
817 pci_write_config32(NODE_HT(node),0xd4,0);
822 print_debug("done\n");
826 static void setup_coherent_ht_domain(void)
830 enable_bsp_routing();
833 cpus=setup_uniprocessor();
836 cpus=detect_mp_capabilities(cpus);
838 coherent_ht_finalize(cpus);