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);
405 val |= (1<<10)|(1<<9)|(1<<8)|(1<<4)|(1<<3)|(1<<2)|(1<<1)|(1 << 0);
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 * 2) verify that the coherent hypertransport link
479 * is established and actually working by reading the
480 * remote node's vendor/device id
490 val=pci_read_config32(NODE_HT(src), 0x98+link);
491 if ( (val&0x17) != 0x03)
495 val=pci_read_config32(NODE_HT(dest),0);
496 if(val != 0x11001022)
502 static unsigned int generate_row(u8 node, u8 row, u8 maxnodes)
504 /* Routing Table Node i
506 * F0: 0x40, 0x44, 0x48, 0x4c, 0x50, 0x54, 0x58, 0x5c
507 * i: 0, 1, 2, 3, 4, 5, 6, 7
509 * [ 0: 3] Request Route
510 * [0] Route to this node
511 * [1] Route to Link 0
512 * [2] Route to Link 1
513 * [3] Route to Link 2
514 * [11: 8] Response Route
515 * [0] Route to this node
516 * [1] Route to Link 0
517 * [2] Route to Link 1
518 * [3] Route to Link 2
519 * [19:16] Broadcast route
520 * [0] Route to this node
521 * [1] Route to Link 0
522 * [2] Route to Link 1
523 * [3] Route to Link 2
528 static const unsigned int rows_2p[2][2] = {
529 { 0x00030101, 0x00010404 },
530 { 0x00010404, 0x00030101 }
533 static const unsigned int rows_4p[4][4] = {
534 { 0x00070101, 0x00010404, 0x00050202, 0x00010402 },
535 { 0x00010808, 0x000b0101, 0x00010802, 0x00090202 },
536 { 0x00090202, 0x00010802, 0x000b0101, 0x00010808 },
537 { 0x00010402, 0x00050202, 0x00010404, 0x00070101 }
540 if (!(node>=maxnodes || row>=maxnodes)) {
542 ret=rows_2p[node][row];
544 ret=rows_4p[node][row];
548 printk_spew("generating entry n=%d, r=%d, max=%d - row=%x\n",
549 node,row,maxnodes,ret);
555 static void fill_row(u8 node, u8 row, u32 value)
558 print_debug("fill_row: pci_write_config32(");
559 print_debug_hex32(NODE_HT(node));
560 print_debug_char(',');
561 print_debug_hex32(0x40 + (row << 2));
562 print_debug_char(',');
563 print_debug_hex32(value);
564 print_debug(")\r\n");
566 pci_write_config32(NODE_HT(node), 0x40+(row<<2), value);
569 static void setup_row(u8 source, u8 dest, u8 cpus)
572 printk_spew("setting up link from node %d to %d (%d cpus)\r\n",
576 fill_row(source,dest,generate_row(source,dest,cpus));
579 static void setup_temp_row(u8 source, u8 dest, u8 cpus)
582 printk_spew("setting up temp. link from node %d to %d (%d cpus)\r\n",
586 fill_row(source,7,generate_temp_row(source,dest,cpus));
589 static void setup_node(u8 node, u8 cpus)
592 for(row=0; row<cpus; row++)
593 setup_row(node, row, cpus);
596 static void setup_remote_row(u8 source, u8 dest, u8 cpus)
598 fill_row(7, dest, generate_row(source, dest, cpus));
601 static void setup_remote_node(u8 node, u8 cpus)
603 static const uint8_t pci_reg[] = {
604 0x44, 0x4c, 0x54, 0x5c, 0x64, 0x6c, 0x74, 0x7c,
605 0x40, 0x48, 0x50, 0x58, 0x60, 0x68, 0x70, 0x78,
606 0x84, 0x8c, 0x94, 0x9c, 0xa4, 0xac, 0xb4, 0xbc,
607 0x80, 0x88, 0x90, 0x98, 0xa0, 0xa8, 0xb0, 0xb8,
608 0xc4, 0xcc, 0xd4, 0xdc,
609 0xc0, 0xc8, 0xd0, 0xd8,
610 0xe0, 0xe4, 0xe8, 0xec,
615 print_debug("setup_remote_node\r\n");
617 for(row=0; row<cpus; row++)
618 setup_remote_row(node, row, cpus);
620 /* copy the default resource map from node 0 */
621 for(i = 0; i < sizeof(pci_reg)/sizeof(pci_reg[0]); i++) {
625 print_debug("copying reg: ");
626 print_debug_hex8(reg);
628 value = pci_read_config32(NODE_MP(0), reg);
629 pci_write_config32(NODE_MP(7), reg, value);
633 print_debug("setup_remote_done\r\n");
640 static void setup_temp_node(u8 node, u8 cpus)
643 for(row=0; row<cpus; row++)
644 fill_row(7,row,generate_row(node,row,cpus));
648 static u8 setup_uniprocessor(void)
650 print_debug("Enabling UP settings\r\n");
656 static u8 setup_smp(void)
660 print_debug("Enabling SMP settings\r\n");
663 /* Setup and check a temporary connection to node 1 */
664 setup_temp_row(0,1,cpus);
666 if (!check_connection(0, 7, ACROSS)) { // Link: ACROSS
667 print_debug("No connection to Node 1.\r\n");
668 clear_temp_row(0); /* delete temp connection */
669 setup_uniprocessor(); /* and get up working */
673 /* We found 2 nodes so far */
674 setup_node(0, cpus); /* Node 1 is there. Setup Node 0 correctly */
675 setup_remote_node(1, cpus); /* Setup the routes on the remote node */
676 enable_routing(7); /* Enable routing on Node 1 */
677 rename_temp_node(1); /* Rename Node 7 to Node 1 */
679 clear_temp_row(0); /* delete temporary connection */
684 /* Setup and check temporary connection from Node 0 to Node 2 */
685 setup_temp_row(0,2,cpus);
687 if (!check_connection(0, 7, UP)) { // Link: UP
688 print_debug("No connection to Node 2.\r\n");
689 clear_temp_row(0); /* delete temp connection */
693 /* We found 3 nodes so far. Now setup a temporary
694 * connection from node 0 to node 3 via node 1
697 setup_temp_row(0,1,cpus); /* temp. link between nodes 0 and 1 */
698 setup_temp_row(1,3,cpus); /* temp. link between nodes 1 and 3 */
700 if (!check_connection(1, 7, UP)) { // Link: UP
701 print_debug("No connection to Node 3.\r\n");
702 clear_temp_row(0); /* delete temp connection */
703 clear_temp_row(1); /* delete temp connection */
707 /* We found 4 nodes so far. Now setup all nodes for 4p */
709 setup_node(0, cpus); /* The first 2 nodes are configured */
710 setup_node(1, cpus); /* already. Just configure them for 4p */
712 setup_temp_row(0,2,cpus);
713 setup_temp_node(2,cpus);
717 setup_temp_row(0,1,cpus);
718 setup_temp_row(1,3,cpus);
719 setup_temp_node(3,cpus);
720 enable_routing(7); /* enable routing on node 3 (temp.) */
729 print_debug_hex32(cpus);
730 print_debug(" nodes initialized.\r\n");
736 static unsigned detect_mp_capabilities(unsigned cpus)
738 unsigned node, row, mask;
742 print_debug("detect_mp_capabilities: ");
743 print_debug_hex32(cpus);
747 mask=0x06; /* BigMPCap */
749 mask=0x02; /* MPCap */
751 for (node=0; node<cpus; node++) {
752 if ((pci_read_config32(NODE_MC(node), 0xe8) & mask)!=mask)
759 /* one of our cpus is not mp capable */
761 print_debug("One of the CPUs is not MP capable. Going back to UP\r\n");
763 for (node=cpus; node>0; node--)
764 for (row=cpus; row>0; row--)
765 fill_row(NODE_HT(node-1), row-1, DEFAULT);
767 return setup_uniprocessor();
772 /* this is a shrunken cpuid. */
774 static unsigned int cpuid(unsigned int op)
778 asm volatile ( "cpuid" : "=a" (ret) : "a" (op));
783 static void coherent_ht_finalize(unsigned cpus)
788 /* set up cpu count and node count and enable Limit
789 * Config Space Range for all available CPUs.
790 * Also clear non coherent hypertransport bus range
791 * registers on Hammer A0 revision.
795 print_debug("coherent_ht_finalize\r\n");
797 rev_a0=((cpuid(1)&0xffff)==0x0f10);
799 for (node=0; node<cpus; node++) {
801 val=pci_read_config32(NODE_HT(node), 0x60);
802 val &= (~0x000F0070);
803 val |= ((cpus-1)<<16)|((cpus-1)<<4);
804 pci_write_config32(NODE_HT(node),0x60,val);
806 val=pci_read_config32(NODE_HT(node), 0x68);
808 pci_write_config32(NODE_HT(node),0x68,val);
811 pci_write_config32(NODE_HT(node),0x94,0);
812 pci_write_config32(NODE_HT(node),0xb4,0);
813 pci_write_config32(NODE_HT(node),0xd4,0);
818 print_debug("done\n");
822 static void setup_coherent_ht_domain(void)
826 enable_bsp_routing();
829 cpus=setup_uniprocessor();
832 cpus=detect_mp_capabilities(cpus);
834 coherent_ht_finalize(cpus);