2 This should be done by Eric
3 2004.12 yhlu add multi ht chain dynamically support
4 2005.11 yhlu add let real sb to use small unitid
6 #include <device/pci_def.h>
7 #include <device/pci_ids.h>
8 #include <device/hypertransport_def.h>
10 #ifndef CONFIG_K8_HT_FREQ_1G_SUPPORT
11 #define CONFIG_K8_HT_FREQ_1G_SUPPORT 0
14 #ifndef RAMINIT_SYSINFO
15 #define RAMINIT_SYSINFO 0
18 #ifndef K8_ALLOCATE_IO_RANGE
19 #define K8_ALLOCATE_IO_RANGE 0
22 // Do we need allocate MMIO? Current We direct last 64M to sblink only, We can not lose access to last 4M range to ROM
23 #ifndef K8_ALLOCATE_MMIO_RANGE
24 #define K8_ALLOCATE_MMIO_RANGE 0
27 static inline void print_linkn_in (const char *strval, uint8_t byteval)
29 printk(BIOS_DEBUG, "%s%02x\n", strval, byteval);
32 static uint8_t ht_lookup_capability(device_t dev, uint16_t val)
37 hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE);
41 if ((hdr_type == PCI_HEADER_TYPE_NORMAL) ||
42 (hdr_type == PCI_HEADER_TYPE_BRIDGE)) {
43 pos = PCI_CAPABILITY_LIST;
45 if (pos > PCI_CAP_LIST_NEXT) {
46 pos = pci_read_config8(dev, pos);
48 while(pos != 0) { /* loop through the linked list */
50 cap = pci_read_config8(dev, pos + PCI_CAP_LIST_ID);
51 if (cap == PCI_CAP_ID_HT) {
54 flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS);
55 if ((flags >> 13) == val) {
56 /* Entry is a slave or host , success... */
60 pos = pci_read_config8(dev, pos + PCI_CAP_LIST_NEXT);
65 static uint8_t ht_lookup_slave_capability(device_t dev)
67 return ht_lookup_capability(dev, 0); // Slave/Primary Interface Block Format
71 static uint8_t ht_lookup_host_capability(device_t dev)
73 return ht_lookup_capability(dev, 1); // Host/Secondary Interface Block Format
77 static void ht_collapse_previous_enumeration(uint8_t bus, unsigned offset_unitid)
81 //actually, only for one HT device HT chain, and unitid is 0
82 #if CONFIG_HT_CHAIN_UNITID_BASE == 0
88 /* Check if is already collapsed */
89 if((!offset_unitid) || (offset_unitid && (!((CONFIG_HT_CHAIN_END_UNITID_BASE == 0) && (CONFIG_HT_CHAIN_END_UNITID_BASE <CONFIG_HT_CHAIN_UNITID_BASE))))) {
91 dev = PCI_DEV(bus, 0, 0);
92 id = pci_read_config32(dev, PCI_VENDOR_ID);
93 if (!((id == 0xffffffff) || (id == 0x00000000) ||
94 (id == 0x0000ffff) || (id == 0xffff0000))) {
99 /* Spin through the devices and collapse any previous
100 * hypertransport enumeration.
102 for(dev = PCI_DEV(bus, 1, 0); dev <= PCI_DEV(bus, 0x1f, 0x7); dev += PCI_DEV(0, 1, 0)) {
107 id = pci_read_config32(dev, PCI_VENDOR_ID);
108 if ((id == 0xffffffff) || (id == 0x00000000) ||
109 (id == 0x0000ffff) || (id == 0xffff0000)) {
113 pos = ht_lookup_slave_capability(dev);
118 /* Clear the unitid */
119 flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS);
121 pci_write_config16(dev, pos + PCI_CAP_FLAGS, flags);
125 static uint16_t ht_read_freq_cap(device_t dev, uint8_t pos)
127 /* Handle bugs in valid hypertransport frequency reporting */
131 freq_cap = pci_read_config16(dev, pos);
132 printk(BIOS_SPEW, "pos=0x%x, unfiltered freq_cap=0x%x\n", pos, freq_cap);
133 freq_cap &= ~(1 << HT_FREQ_VENDOR); /* Ignore Vendor HT frequencies */
135 id = pci_read_config32(dev, 0);
137 /* AMD 8131 Errata 48 */
138 if (id == (PCI_VENDOR_ID_AMD | (PCI_DEVICE_ID_AMD_8131_PCIX << 16))) {
139 freq_cap &= ~(1 << HT_FREQ_800Mhz);
143 /* AMD 8151 Errata 23 */
144 if (id == (PCI_VENDOR_ID_AMD | (PCI_DEVICE_ID_AMD_8151_SYSCTRL << 16))) {
145 freq_cap &= ~(1 << HT_FREQ_800Mhz);
149 /* AMD K8 Unsupported 1Ghz? */
150 if (id == (PCI_VENDOR_ID_AMD | (0x1100 << 16))) {
151 #if CONFIG_K8_HT_FREQ_1G_SUPPORT == 1
152 #if CONFIG_K8_REV_F_SUPPORT == 0
153 if (is_cpu_pre_e0()) { // only E0 later support 1GHz
154 freq_cap &= ~(1 << HT_FREQ_1000Mhz);
158 freq_cap &= ~(1 << HT_FREQ_1000Mhz);
162 printk(BIOS_SPEW, "pos=0x%x, filtered freq_cap=0x%x\n", pos, freq_cap);
163 //printk(BIOS_SPEW, "capping to 800/600/400/200 MHz\n");
168 static uint8_t ht_read_width_cap(device_t dev, uint8_t pos)
170 uint8_t width_cap = pci_read_config8(dev, pos);
174 id = pci_read_config32(dev, 0);
176 /* netlogic micro cap doesn't support 16 bit yet */
177 if (id == (0x184e | (0x0001 << 16))) {
178 if((width_cap & 0x77) == 0x11) {
187 #define LINK_OFFS(CTRL, WIDTH,FREQ,FREQ_CAP) \
188 (((CTRL & 0xff) << 24) | ((WIDTH & 0xff) << 16) | ((FREQ & 0xff) << 8) | (FREQ_CAP & 0xFF))
190 #define LINK_CTRL(OFFS) ((OFFS >> 24) & 0xFF)
191 #define LINK_WIDTH(OFFS) ((OFFS >> 16) & 0xFF)
192 #define LINK_FREQ(OFFS) ((OFFS >> 8) & 0xFF)
193 #define LINK_FREQ_CAP(OFFS) ((OFFS) & 0xFF)
195 #define PCI_HT_HOST_OFFS LINK_OFFS( \
196 PCI_HT_CAP_HOST_CTRL, \
197 PCI_HT_CAP_HOST_WIDTH, \
198 PCI_HT_CAP_HOST_FREQ, \
199 PCI_HT_CAP_HOST_FREQ_CAP)
201 #define PCI_HT_SLAVE0_OFFS LINK_OFFS( \
202 PCI_HT_CAP_SLAVE_CTRL0, \
203 PCI_HT_CAP_SLAVE_WIDTH0, \
204 PCI_HT_CAP_SLAVE_FREQ0, \
205 PCI_HT_CAP_SLAVE_FREQ_CAP0)
207 #define PCI_HT_SLAVE1_OFFS LINK_OFFS( \
208 PCI_HT_CAP_SLAVE_CTRL1, \
209 PCI_HT_CAP_SLAVE_WIDTH1, \
210 PCI_HT_CAP_SLAVE_FREQ1, \
211 PCI_HT_CAP_SLAVE_FREQ_CAP1)
213 static int ht_optimize_link(
214 device_t dev1, uint8_t pos1, unsigned offs1,
215 device_t dev2, uint8_t pos2, unsigned offs2)
217 static const uint8_t link_width_to_pow2[]= { 3, 4, 0, 5, 1, 2, 0, 0 };
218 static const uint8_t pow2_to_link_width[] = { 0x7, 4, 5, 0, 1, 3 };
219 uint16_t freq_cap1, freq_cap2;
220 uint8_t width_cap1, width_cap2, width, old_width, ln_width1, ln_width2;
221 uint8_t freq, old_freq;
223 /* Set link width and frequency */
225 printk(BIOS_SPEW, "entering ht_optimize_link\n");
226 /* Initially assume everything is already optimized and I don't need a reset */
229 /* Get the frequency capabilities */
230 freq_cap1 = ht_read_freq_cap(dev1, pos1 + LINK_FREQ_CAP(offs1));
231 freq_cap2 = ht_read_freq_cap(dev2, pos2 + LINK_FREQ_CAP(offs2));
232 printk(BIOS_SPEW, "freq_cap1=0x%x, freq_cap2=0x%x\n", freq_cap1, freq_cap2);
234 /* Calculate the highest possible frequency */
235 freq = log2(freq_cap1 & freq_cap2);
237 /* See if I am changing the link freqency */
238 old_freq = pci_read_config8(dev1, pos1 + LINK_FREQ(offs1));
240 needs_reset |= old_freq != freq;
241 printk(BIOS_SPEW, "dev1 old_freq=0x%x, freq=0x%x, needs_reset=0x%0x\n", old_freq, freq, needs_reset);
242 old_freq = pci_read_config8(dev2, pos2 + LINK_FREQ(offs2));
244 needs_reset |= old_freq != freq;
245 printk(BIOS_SPEW, "dev2 old_freq=0x%x, freq=0x%x, needs_reset=0x%0x\n", old_freq, freq, needs_reset);
247 /* Set the Calculated link frequency */
248 pci_write_config8(dev1, pos1 + LINK_FREQ(offs1), freq);
249 pci_write_config8(dev2, pos2 + LINK_FREQ(offs2), freq);
251 /* Get the width capabilities */
252 width_cap1 = ht_read_width_cap(dev1, pos1 + LINK_WIDTH(offs1));
253 width_cap2 = ht_read_width_cap(dev2, pos2 + LINK_WIDTH(offs2));
254 printk(BIOS_SPEW, "width_cap1=0x%x, width_cap2=0x%x\n", width_cap1, width_cap2);
256 /* Calculate dev1's input width */
257 ln_width1 = link_width_to_pow2[width_cap1 & 7];
258 ln_width2 = link_width_to_pow2[(width_cap2 >> 4) & 7];
259 printk(BIOS_SPEW, "dev1 input ln_width1=0x%x, ln_width2=0x%x\n", ln_width1, ln_width2);
260 if (ln_width1 > ln_width2) {
261 ln_width1 = ln_width2;
263 width = pow2_to_link_width[ln_width1];
264 printk(BIOS_SPEW, "dev1 input width=0x%x\n", width);
265 /* Calculate dev1's output width */
266 ln_width1 = link_width_to_pow2[(width_cap1 >> 4) & 7];
267 ln_width2 = link_width_to_pow2[width_cap2 & 7];
268 printk(BIOS_SPEW, "dev1 output ln_width1=0x%x, ln_width2=0x%x\n", ln_width1, ln_width2);
269 if (ln_width1 > ln_width2) {
270 ln_width1 = ln_width2;
272 width |= pow2_to_link_width[ln_width1] << 4;
273 printk(BIOS_SPEW, "dev1 input|output width=0x%x\n", width);
275 /* See if I am changing dev1's width */
276 old_width = pci_read_config8(dev1, pos1 + LINK_WIDTH(offs1) + 1);
278 needs_reset |= old_width != width;
279 printk(BIOS_SPEW, "old dev1 input|output width=0x%x\n", width);
281 /* Set dev1's widths */
282 pci_write_config8(dev1, pos1 + LINK_WIDTH(offs1) + 1, width);
284 /* Calculate dev2's width */
285 width = ((width & 0x70) >> 4) | ((width & 0x7) << 4);
286 printk(BIOS_SPEW, "dev2 input|output width=0x%x\n", width);
288 /* See if I am changing dev2's width */
289 old_width = pci_read_config8(dev2, pos2 + LINK_WIDTH(offs2) + 1);
291 needs_reset |= old_width != width;
292 printk(BIOS_SPEW, "old dev2 input|output width=0x%x\n", width);
294 /* Set dev2's widths */
295 pci_write_config8(dev2, pos2 + LINK_WIDTH(offs2) + 1, width);
300 #if RAMINIT_SYSINFO == 1
301 static void ht_setup_chainx(device_t udev, uint8_t upos, uint8_t bus, unsigned offset_unitid, struct sys_info *sysinfo)
303 static int ht_setup_chainx(device_t udev, uint8_t upos, uint8_t bus, unsigned offset_unitid)
306 //even CONFIG_HT_CHAIN_UNITID_BASE == 0, we still can go through this function, because of end_of_chain check, also We need it to optimize link
308 uint8_t next_unitid, last_unitid;
311 #if RAMINIT_SYSINFO == 0
312 int reset_needed = 0;
315 #if CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20
316 //let't record the device of last ht device, So we can set the Unitid to CONFIG_HT_CHAIN_END_UNITID_BASE
317 unsigned real_last_unitid;
318 uint8_t real_last_pos;
320 uint8_t end_used = 0;
323 uoffs = PCI_HT_HOST_OFFS;
324 next_unitid = (offset_unitid) ? CONFIG_HT_CHAIN_UNITID_BASE:1;
329 uint16_t flags, ctrl;
333 /* Wait until the link initialization is complete */
335 ctrl = pci_read_config16(udev, upos + LINK_CTRL(uoffs));
336 /* Is this the end of the hypertransport chain? */
337 if (ctrl & (1 << 6)) {
341 if (ctrl & ((1 << 4) | (1 << 8))) {
343 * Either the link has failed, or we have
345 * Sometimes this can happen due to link
346 * retrain, so lets knock it down and see
349 ctrl |= ((1 << 4) | (1 <<8)); // Link fail + Crc
350 pci_write_config16(udev, upos + LINK_CTRL(uoffs), ctrl);
351 ctrl = pci_read_config16(udev, upos + LINK_CTRL(uoffs));
352 if (ctrl & ((1 << 4) | (1 << 8))) {
353 print_err("Detected error on Hypertransport Link\n");
357 } while((ctrl & (1 << 5)) == 0);
359 device_t dev = PCI_DEV(bus, 0, 0);
360 last_unitid = next_unitid;
362 id = pci_read_config32(dev, PCI_VENDOR_ID);
364 /* If the chain is enumerated quit */
365 if ((id == 0xffffffff) || (id == 0x00000000) ||
366 (id == 0x0000ffff) || (id == 0xffff0000))
371 pos = ht_lookup_slave_capability(dev);
373 print_err("udev="); print_err_hex32(udev);
374 print_err("\tupos="); print_err_hex32(upos);
375 print_err("\tuoffs="); print_err_hex32(uoffs);
376 print_err("\tHT link capability not found\n");
381 #if CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20
383 if(next_unitid>= (bus ? 0x20:0x18) ) {
385 next_unitid = CONFIG_HT_CHAIN_END_UNITID_BASE;
393 real_last_unitid = next_unitid;
397 /* Update the Unitid of the current device */
398 flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS);
399 flags &= ~0x1f; /* mask out the base Unit ID */
400 flags |= next_unitid & 0x1f;
401 pci_write_config16(dev, pos + PCI_CAP_FLAGS, flags);
403 /* Compute the number of unitids consumed */
404 count = (flags >> 5) & 0x1f;
406 /* Note the change in device number */
407 dev = PCI_DEV(bus, next_unitid, 0);
409 next_unitid += count;
411 /* Find which side of the ht link we are on,
412 * by reading which direction our last write to PCI_CAP_FLAGS
415 flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS);
416 offs = ((flags>>10) & 1) ? PCI_HT_SLAVE1_OFFS : PCI_HT_SLAVE0_OFFS;
418 #if RAMINIT_SYSINFO == 1
419 /* store the link pair here and we will Setup the Hypertransport link later, after we get final FID/VID */
421 struct link_pair_st *link_pair = &sysinfo->link_pair[sysinfo->link_pair_num];
422 link_pair->udev = udev;
423 link_pair->upos = upos;
424 link_pair->uoffs = uoffs;
425 link_pair->dev = dev;
426 link_pair->pos = pos;
427 link_pair->offs = offs;
428 sysinfo->link_pair_num++;
431 reset_needed |= ht_optimize_link(udev, upos, uoffs, dev, pos, offs);
434 /* Remeber the location of the last device */
437 uoffs = ( offs != PCI_HT_SLAVE0_OFFS ) ? PCI_HT_SLAVE0_OFFS : PCI_HT_SLAVE1_OFFS;
439 } while (last_unitid != next_unitid );
441 #if CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20
446 #if CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20
447 if(offset_unitid && (ht_dev_num>1) && (real_last_unitid != CONFIG_HT_CHAIN_END_UNITID_BASE) && !end_used ) {
449 flags = pci_read_config16(PCI_DEV(bus,real_last_unitid,0), real_last_pos + PCI_CAP_FLAGS);
451 flags |= CONFIG_HT_CHAIN_END_UNITID_BASE & 0x1f;
452 pci_write_config16(PCI_DEV(bus, real_last_unitid, 0), real_last_pos + PCI_CAP_FLAGS, flags);
454 #if RAMINIT_SYSINFO == 1
455 // Here need to change the dev in the array
457 for(i=0;i<sysinfo->link_pair_num;i++)
459 struct link_pair_st *link_pair = &sysinfo->link_pair[i];
460 if(link_pair->udev == PCI_DEV(bus, real_last_unitid, 0)) {
461 link_pair->udev = PCI_DEV(bus, CONFIG_HT_CHAIN_END_UNITID_BASE, 0);
464 if(link_pair->dev == PCI_DEV(bus, real_last_unitid, 0)) {
465 link_pair->dev = PCI_DEV(bus, CONFIG_HT_CHAIN_END_UNITID_BASE, 0);
473 #if RAMINIT_SYSINFO == 0
480 #if RAMINIT_SYSINFO == 1
481 static void ht_setup_chain(device_t udev, unsigned upos, struct sys_info *sysinfo)
483 static int ht_setup_chain(device_t udev, unsigned upos)
486 unsigned offset_unitid = 0;
487 #if ((CONFIG_HT_CHAIN_UNITID_BASE != 1) || (CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20))
491 /* Assumption the HT chain that is bus 0 has the HT I/O Hub on it.
492 * On most boards this just happens. If a cpu has multiple
493 * non Coherent links the appropriate bus registers for the
494 * links needs to be programed to point at bus 0.
497 /* Make certain the HT bus is not enumerated */
498 ht_collapse_previous_enumeration(0, 0);
500 #if ((CONFIG_HT_CHAIN_UNITID_BASE != 1) || (CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20))
504 #if RAMINIT_SYSINFO == 1
505 ht_setup_chainx(udev, upos, 0, offset_unitid, sysinfo);
507 return ht_setup_chainx(udev, upos, 0, offset_unitid);
512 static int optimize_link_read_pointer(uint8_t node, uint8_t linkn, uint8_t linkt, uint8_t val)
514 uint32_t dword, dword_old;
517 /* This works on an Athlon64 because unimplemented links return 0 */
518 dword = pci_read_config32(PCI_DEV(0,0x18+node,0), 0x98 + (linkn * 0x20));
519 link_type = dword & 0xff;
522 if ( (link_type & 7) == linkt ) { /* Coherent Link only linkt = 3, ncoherent = 7*/
523 dword_old = dword = pci_read_config32(PCI_DEV(0,0x18+node,3), 0xdc);
524 dword &= ~( 0xff<<(linkn *8) );
525 dword |= val << (linkn *8);
527 if (dword != dword_old) {
528 pci_write_config32(PCI_DEV(0,0x18+node,3), 0xdc, dword);
536 static int optimize_link_read_pointers_chain(uint8_t ht_c_num)
543 for (i = 0; i < ht_c_num; i++) {
545 uint8_t nodeid, linkn;
550 #if ((CONFIG_HT_CHAIN_UNITID_BASE != 1) || (CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20))
551 #if CONFIG_SB_HT_CHAIN_UNITID_OFFSET_ONLY == 1
552 if(i==0) // to check if it is sb ht chain
554 devn = CONFIG_HT_CHAIN_UNITID_BASE;
557 reg = pci_read_config32(PCI_DEV(0,0x18,1), 0xe0 + i * 4);
559 nodeid = ((reg & 0xf0)>>4); // nodeid
560 linkn = ((reg & 0xf00)>>8); // link n
561 busn = (reg & 0xff0000)>>16; //busn
563 reg = pci_read_config32( PCI_DEV(busn, devn, 0), PCI_VENDOR_ID); // ? the chain dev maybe offseted
564 if ( (reg & 0xffff) == PCI_VENDOR_ID_AMD) {
566 } else if ( (reg & 0xffff) == PCI_VENDOR_ID_NVIDIA ) {
572 reset_needed |= optimize_link_read_pointer(nodeid, linkn, 0x07, val);
579 #if defined(CONFIG_SOUTHBRIDGE_NVIDIA_CK804) // || defined(CONFIG_SOUTHBRIDGE_NVIDIA_MCP55)
580 static int set_ht_link_buffer_count(uint8_t node, uint8_t linkn, uint8_t linkt, unsigned val)
587 /* This works on an Athlon64 because unimplemented links return 0 */
588 regpos = 0x98 + (linkn * 0x20);
589 dev = PCI_DEV(0,0x18+node,0);
590 dword = pci_read_config32(dev, regpos);
591 link_type = dword & 0xff;
593 if ( (link_type & 0x7) == linkt ) { /* Coherent Link only linkt = 3, ncoherent = 7*/
594 regpos = 0x90 + (linkn * 0x20);
595 dword = pci_read_config32(dev, regpos );
598 pci_write_config32(dev, regpos, val);
606 static int set_ht_link_buffer_counts_chain(uint8_t ht_c_num, unsigned vendorid, unsigned val)
613 for (i = 0; i < ht_c_num; i++) {
615 uint8_t nodeid, linkn;
619 reg = pci_read_config32(PCI_DEV(0,0x18,1), 0xe0 + i * 4);
620 if((reg & 3) != 3) continue; // not enabled
622 nodeid = ((reg & 0xf0)>>4); // nodeid
623 linkn = ((reg & 0xf00)>>8); // link n
624 busn = (reg & 0xff0000)>>16; //busn
626 for(devn = 0; devn < 0x20; devn++) {
627 reg = pci_read_config32( PCI_DEV(busn, devn, 0), PCI_VENDOR_ID); //1?
628 if ( (reg & 0xffff) == vendorid ) {
629 reset_needed |= set_ht_link_buffer_count(nodeid, linkn, 0x07,val);
639 #if RAMINIT_SYSINFO == 1
640 static void ht_setup_chains(uint8_t ht_c_num, struct sys_info *sysinfo)
642 static int ht_setup_chains(uint8_t ht_c_num)
645 /* Assumption the HT chain that is bus 0 has the HT I/O Hub on it.
646 * On most boards this just happens. If a cpu has multiple
647 * non Coherent links the appropriate bus registers for the
648 * links needs to be programed to point at bus 0.
654 #if RAMINIT_SYSINFO == 0
655 int reset_needed = 0;
657 sysinfo->link_pair_num = 0;
660 // first one is SB Chain
661 for (i = 0; i < ht_c_num; i++) {
667 unsigned offset_unitid = 0;
669 reg = pci_read_config32(PCI_DEV(0,0x18,1), 0xe0 + i * 4);
671 //We need setup 0x94, 0xb4, and 0xd4 according to the reg
672 devpos = ((reg & 0xf0)>>4)+0x18; // nodeid; it will decide 0x18 or 0x19
673 regpos = ((reg & 0xf00)>>8) * 0x20 + 0x94; // link n; it will decide 0x94 or 0xb4, 0x0xd4;
674 busn = (reg & 0xff0000)>>16;
676 dword = pci_read_config32( PCI_DEV(0, devpos, 0), regpos) ;
677 dword &= ~(0xffff<<8);
678 dword |= (reg & 0xffff0000)>>8;
679 pci_write_config32( PCI_DEV(0, devpos,0), regpos , dword);
682 #if ((CONFIG_HT_CHAIN_UNITID_BASE != 1) || (CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20))
683 #if CONFIG_SB_HT_CHAIN_UNITID_OFFSET_ONLY == 1
684 if(i==0) // to check if it is sb ht chain
689 /* Make certain the HT bus is not enumerated */
690 ht_collapse_previous_enumeration(busn, offset_unitid);
692 upos = ((reg & 0xf00)>>8) * 0x20 + 0x80;
693 udev = PCI_DEV(0, devpos, 0);
695 #if RAMINIT_SYSINFO == 1
696 ht_setup_chainx(udev,upos,busn, offset_unitid, sysinfo); // all not
698 reset_needed |= ht_setup_chainx(udev,upos,busn, offset_unitid); //all not
703 #if RAMINIT_SYSINFO == 0
704 reset_needed |= optimize_link_read_pointers_chain(ht_c_num);
711 #if defined (__GNUC__)
712 static inline unsigned get_nodes(void);
715 #if RAMINIT_SYSINFO == 1
716 static void ht_setup_chains_x(struct sys_info *sysinfo)
718 static int ht_setup_chains_x(void)
727 #if K8_ALLOCATE_IO_RANGE == 1
728 unsigned next_io_base;
733 /* read PCI_DEV(0,0x18,0) 0x64 bit [8:9] to find out SbLink m */
734 reg = pci_read_config32(PCI_DEV(0, 0x18, 0), 0x64);
735 /* update PCI_DEV(0, 0x18, 1) 0xe0 to 0x05000m03, and next_busn=0x3f+1 */
736 print_linkn_in("SBLink=", ((reg>>8) & 3) );
737 #if RAMINIT_SYSINFO == 1
738 sysinfo->sblk = (reg>>8) & 3;
740 sysinfo->nodes = nodes;
742 tempreg = 3 | ( 0<<4) | (((reg>>8) & 3)<<8) | (0<<16)| (0x3f<<24);
743 pci_write_config32(PCI_DEV(0, 0x18, 1), 0xe0, tempreg);
745 next_busn=0x3f+1; /* 0 will be used ht chain with SB we need to keep SB in bus0 in auto stage*/
747 #if K8_ALLOCATE_IO_RANGE == 1
748 /* io range allocation */
749 tempreg = 0 | (((reg>>8) & 0x3) << 4 )| (0x3<<12); //limit
750 pci_write_config32(PCI_DEV(0, 0x18, 1), 0xC4, tempreg);
751 tempreg = 3 | ( 3<<4) | (0<<12); //base
752 pci_write_config32(PCI_DEV(0, 0x18, 1), 0xC0, tempreg);
753 next_io_base = 0x3+0x1;
757 for(ht_c_num=1;ht_c_num<4; ht_c_num++) {
758 pci_write_config32(PCI_DEV(0, 0x18, 1), 0xe0 + ht_c_num * 4, 0);
760 #if K8_ALLOCATE_IO_RANGE == 1
761 /* io range allocation */
762 pci_write_config32(PCI_DEV(0, 0x18, 1), 0xc4 + ht_c_num * 8, 0);
763 pci_write_config32(PCI_DEV(0, 0x18, 1), 0xc0 + ht_c_num * 8, 0);
767 for(nodeid=0; nodeid<nodes; nodeid++) {
770 dev = PCI_DEV(0, 0x18+nodeid,0);
771 for(linkn = 0; linkn<3; linkn++) {
773 regpos = 0x98 + 0x20 * linkn;
774 reg = pci_read_config32(dev, regpos);
775 if ((reg & 0x17) != 7) continue; /* it is not non conherent or not connected*/
776 print_linkn_in("NC node|link=", ((nodeid & 0xf)<<4)|(linkn & 0xf));
777 tempreg = 3 | (nodeid <<4) | (linkn<<8);
778 /*compare (temp & 0xffff), with (PCI(0, 0x18, 1) 0xe0 to 0xec & 0xfffff) */
779 for(ht_c_num=0;ht_c_num<4; ht_c_num++) {
780 reg = pci_read_config32(PCI_DEV(0, 0x18, 1), 0xe0 + ht_c_num * 4);
781 if(((reg & 0xffff) == (tempreg & 0xffff)) || ((reg & 0xffff) == 0x0000)) { /*we got it*/
785 if(ht_c_num == 4) break; /*used up only 4 non conherent allowed*/
786 /*update to 0xe0...*/
787 if((reg & 0xf) == 3) continue; /*SbLink so don't touch it */
788 print_linkn_in("\tbusn=", next_busn);
789 tempreg |= (next_busn<<16)|((next_busn+0x3f)<<24);
790 pci_write_config32(PCI_DEV(0, 0x18, 1), 0xe0 + ht_c_num * 4, tempreg);
793 #if K8_ALLOCATE_IO_RANGE == 1
794 /* io range allocation */
795 tempreg = nodeid | (linkn<<4) | ((next_io_base+0x3)<<12); //limit
796 pci_write_config32(PCI_DEV(0, 0x18, 1), 0xC4 + ht_c_num * 8, tempreg);
797 tempreg = 3 /*| ( 3<<4)*/ | (next_io_base<<12); //base :ISA and VGA ?
798 pci_write_config32(PCI_DEV(0, 0x18, 1), 0xC0 + ht_c_num * 8, tempreg);
799 next_io_base += 0x3+0x1;
804 /*update 0xe0, 0xe4, 0xe8, 0xec from PCI_DEV(0, 0x18,1) to PCI_DEV(0, 0x19,1) to PCI_DEV(0, 0x1f,1);*/
806 for(nodeid = 1; nodeid<nodes; nodeid++) {
809 dev = PCI_DEV(0, 0x18+nodeid,1);
810 for(i = 0; i< 4; i++) {
812 regpos = 0xe0 + i * 4;
813 reg = pci_read_config32(PCI_DEV(0, 0x18, 1), regpos);
814 pci_write_config32(dev, regpos, reg);
817 #if K8_ALLOCATE_IO_RANGE == 1
818 /* io range allocation */
819 for(i = 0; i< 4; i++) {
821 regpos = 0xc4 + i * 8;
822 reg = pci_read_config32(PCI_DEV(0, 0x18, 1), regpos);
823 pci_write_config32(dev, regpos, reg);
825 for(i = 0; i< 4; i++) {
827 regpos = 0xc0 + i * 8;
828 reg = pci_read_config32(PCI_DEV(0, 0x18, 1), regpos);
829 pci_write_config32(dev, regpos, reg);
834 /* recount ht_c_num*/
836 for(ht_c_num=0;ht_c_num<4; ht_c_num++) {
837 reg = pci_read_config32(PCI_DEV(0, 0x18, 1), 0xe0 + ht_c_num * 4);
838 if(((reg & 0xf) != 0x0)) {
843 #if RAMINIT_SYSINFO == 1
844 sysinfo->ht_c_num = i;
845 ht_setup_chains(i, sysinfo);
846 sysinfo->sbdn = get_sbdn(sysinfo->sbbusn);
848 return ht_setup_chains(i);
853 #if RAMINIT_SYSINFO == 1
854 static int optimize_link_incoherent_ht(struct sys_info *sysinfo)
856 // We need to use recorded link pair info to optimize the link
858 int reset_needed = 0;
860 unsigned link_pair_num = sysinfo->link_pair_num;
862 printk(BIOS_SPEW, "entering optimize_link_incoherent_ht\n");
863 printk(BIOS_SPEW, "sysinfo->link_pair_num=0x%x\n", link_pair_num);
864 for(i=0; i< link_pair_num; i++) {
865 struct link_pair_st *link_pair= &sysinfo->link_pair[i];
866 reset_needed |= ht_optimize_link(link_pair->udev, link_pair->upos, link_pair->uoffs, link_pair->dev, link_pair->pos, link_pair->offs);
867 printk(BIOS_SPEW, "after ht_optimize_link for link pair %d, reset_needed=0x%x\n", i, reset_needed);
870 reset_needed |= optimize_link_read_pointers_chain(sysinfo->ht_c_num);
871 printk(BIOS_SPEW, "after optimize_link_read_pointers_chain, reset_needed=0x%x\n", reset_needed);