2 * This file is part of the coreboot project.
4 * Copyright (C) 2010 Advanced Micro Devices, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef _SB700_EARLY_SETUP_C_
21 #define _SB700_EARLY_SETUP_C_
29 #define SMBUS_IO_BASE 0x6000 /* Is it a temporary SMBus I/O base address? */
32 static void pmio_write(u8 reg, u8 value)
35 outb(value, PM_INDEX + 1);
38 static u8 pmio_read(u8 reg)
41 return inb(PM_INDEX + 1);
44 static void sb700_acpi_init(void)
46 pmio_write(0x20, ACPI_PM_EVT_BLK & 0xFF);
47 pmio_write(0x21, ACPI_PM_EVT_BLK >> 8);
48 pmio_write(0x22, ACPI_PM1_CNT_BLK & 0xFF);
49 pmio_write(0x23, ACPI_PM1_CNT_BLK >> 8);
50 pmio_write(0x24, ACPI_PM_TMR_BLK & 0xFF);
51 pmio_write(0x25, ACPI_PM_TMR_BLK >> 8);
52 pmio_write(0x28, ACPI_GPE0_BLK & 0xFF);
53 pmio_write(0x29, ACPI_GPE0_BLK >> 8);
55 /* CpuControl is in \_PR.CPU0, 6 bytes */
56 pmio_write(0x26, ACPI_CPU_CONTROL & 0xFF);
57 pmio_write(0x27, ACPI_CPU_CONTROL >> 8);
59 pmio_write(0x2A, 0); /* AcpiSmiCmdLo */
60 pmio_write(0x2B, 0); /* AcpiSmiCmdHi */
62 pmio_write(0x2C, ACPI_PMA_CNT_BLK & 0xFF);
63 pmio_write(0x2D, ACPI_PMA_CNT_BLK >> 8);
65 pmio_write(0x0E, 1<<3 | 0<<2); /* AcpiDecodeEnable, When set, SB uses
66 * the contents of the PM registers at
67 * index 20-2B to decode ACPI I/O address.
68 * AcpiSmiEn & SmiCmdEn*/
69 pmio_write(0x10, 1<<1 | 1<<3| 1<<5); /* RTC_En_En, TMR_En_En, GBL_EN_EN */
72 /* RPR 2.28: Get SB ASIC Revision. */
73 static u8 set_sb700_revision(void)
76 u8 rev_id, enable_14Mhz, byte;
79 /* if (rev != 0) return rev; */
81 dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
83 if (dev == PCI_DEV_INVALID) {
84 die("SMBUS controller not found\n");
87 rev_id = pci_read_config8(dev, 0x08);
90 enable_14Mhz = (pmio_read(0x53) >> 6) & 1;
91 if (enable_14Mhz == 0x0)
93 else if (enable_14Mhz == 0x1) {
94 /* This happens, if does, only once. So later if we need to get
95 * the revision ID, we don't have to make such a big function.
96 * We just get reg 0x8 in smbus dev. 0x39 is A11, 0x3A is A12. */
98 byte = pci_read_config8(dev, 0x40);
100 pci_write_config8(dev, 0x40, byte);
102 pci_write_config8(dev, 0x08, 0x3A); /* Change 0x39 to 0x3A. */
105 pci_write_config8(dev, 0x40, byte);
107 } else if (rev_id == 0x3A) { /* A12 will be 0x3A after BIOS is initialized */
109 } else if (rev_id == 0x3C) {
111 } else if (rev_id == 0x3D) {
114 die("It is not SB700 or SB710\n");
119 /***************************************
120 * Legacy devices are mapped to LPC space.
123 * ACPI Micro-controller port
124 * This function does not change port 0x80 decoding.
125 * Console output through any port besides 0x3f8 is unsupported.
126 * If you use FWH ROMs, you have to setup IDSEL.
127 ***************************************/
128 static void sb700_lpc_init(void)
134 dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0); /* SMBUS controller */
135 /* NOTE: Set BootTimerDisable, otherwise it would keep rebooting!!
136 * This bit has no meaning if debug strap is not enabled. So if the
137 * board keeps rebooting and the code fails to reach here, we could
138 * disable the debug strap first. */
139 reg32 = pci_read_config32(dev, 0x4C);
141 pci_write_config32(dev, 0x4C, reg32);
143 /* Enable lpc controller */
144 reg32 = pci_read_config32(dev, 0x64);
146 pci_write_config32(dev, 0x64, reg32);
148 dev = pci_locate_device(PCI_ID(0x1002, 0x439d), 0); /* LPC Controller */
149 /* Decode port 0x3f8-0x3ff (Serial 0) */
150 // XXX Serial port decode on LPC is hardcoded to 0x3f8
151 reg8 = pci_read_config8(dev, 0x44);
153 pci_write_config8(dev, 0x44, reg8);
155 /* Decode port 0x60 & 0x64 (PS/2 keyboard) and port 0x62 & 0x66 (ACPI)*/
156 reg8 = pci_read_config8(dev, 0x47);
157 reg8 |= (1 << 5) | (1 << 6);
158 pci_write_config8(dev, 0x47, reg8);
160 /* Enable PrefetchEnSPIFromHost to speed up SPI flash read (does not affect LPC) */
161 reg8 = pci_read_config8(dev, 0xbb);
163 pci_write_config8(dev, 0xbb, reg8);
166 reg8 = pci_read_config8(dev, 0x48);
167 /* Decode ports 0x2e-0x2f, 0x4e-0x4f (SuperI/O configuration) */
168 reg8 |= (1 << 1) | (1 << 0);
169 /* Decode port 0x70-0x73 (RTC) */
171 pci_write_config8(dev, 0x48, reg8);
174 /* what is its usage? */
175 static u32 get_sbdn(u32 bus)
179 /* Find the device. */
180 dev = pci_locate_device_on_bus(PCI_ID(0x1002, 0x4385), bus);
181 return (dev >> 15) & 0x1f;
184 static u8 dual_core(void)
186 return (pci_read_config32(PCI_DEV(0, 0x18, 3), 0xE8) & (0x3<<12)) != 0;
190 * RPR 2.4 C-state and VID/FID change for the K8 platform.
192 static void enable_fid_change_on_sb(u32 sbbusn, u32 sbdn)
195 byte = pmio_read(0x9a);
201 pmio_write(0x9a, byte);
203 byte = pmio_read(0x8f);
206 pmio_write(0x8f, byte);
208 pmio_write(0x8b, 0x01); /* TODO: if the HT Link is 200 MHz, it is 0x0A. It doesnt often happen. */
209 pmio_write(0x8a, 0x90);
211 pmio_write(0x88, 0x10);
213 byte = pmio_read(0x7c);
215 pmio_write(0x7c, byte);
217 /* Must be 0 for K8 platform. */
218 byte = pmio_read(0x68);
220 pmio_write(0x68, byte);
221 /* Must be 0 for K8 platform. */
222 byte = pmio_read(0x8d);
224 pmio_write(0x8d, byte);
226 byte = pmio_read(0x61);
228 pmio_write(0x61, byte);
230 byte = pmio_read(0x42);
232 pmio_write(0x42, byte);
234 pmio_write(0x89, 0x10);
237 void hard_reset(void)
246 void soft_reset(void)
253 void sb700_pci_port80(void)
259 dev = pci_locate_device(PCI_ID(0x1002, 0x4384), 0);
261 /* Chip Control: Enable subtractive decoding */
262 byte = pci_read_config8(dev, 0x40);
264 pci_write_config8(dev, 0x40, byte);
266 /* Misc Control: Enable subtractive decoding if 0x40 bit 5 is set */
267 byte = pci_read_config8(dev, 0x4B);
269 pci_write_config8(dev, 0x4B, byte);
271 /* The same IO Base and IO Limit here is meaningful because we set the
272 * bridge to be subtractive. During early setup stage, we have to make
273 * sure that data can go through port 0x80.
275 /* IO Base: 0xf000 */
276 byte = pci_read_config8(dev, 0x1C);
278 pci_write_config8(dev, 0x1C, byte);
280 /* IO Limit: 0xf000 */
281 byte = pci_read_config8(dev, 0x1D);
283 pci_write_config8(dev, 0x1D, byte);
285 /* PCI Command: Enable IO response */
286 byte = pci_read_config8(dev, 0x04);
288 pci_write_config8(dev, 0x04, byte);
291 dev = pci_locate_device(PCI_ID(0x1002, 0x439D), 0);
293 byte = pci_read_config8(dev, 0x4A);
294 byte &= ~(1 << 5); /* disable lpc port 80 */
295 pci_write_config8(dev, 0x4A, byte);
298 void sb700_lpc_port80(void)
304 /* Enable LPC controller */
305 dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
306 reg32 = pci_read_config32(dev, 0x64);
307 reg32 |= 0x00100000; /* lpcEnable */
308 pci_write_config32(dev, 0x64, reg32);
310 /* Enable port 80 LPC decode in pci function 3 configuration space. */
311 dev = pci_locate_device(PCI_ID(0x1002, 0x439d), 0);
312 byte = pci_read_config8(dev, 0x4a);
313 byte |= 1 << 5; /* enable port 80 */
314 pci_write_config8(dev, 0x4a, byte);
317 /* sbDevicesPorInitTable */
318 static void sb700_devices_por_init(void)
323 printk(BIOS_INFO, "sb700_devices_por_init()\n");
324 /* SMBus Device, BDF:0-20-0 */
325 printk(BIOS_INFO, "sb700_devices_por_init(): SMBus Device, BDF:0-20-0\n");
326 dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
328 if (dev == PCI_DEV_INVALID) {
329 die("SMBUS controller not found\n");
332 printk(BIOS_INFO, "SMBus controller enabled, sb revision is A%x\n",
333 set_sb700_revision());
335 /* sbPorAtStartOfTblCfg */
336 /* Set A-Link bridge access address. This address is set at device 14h, function 0, register 0xf0.
337 * This is an I/O address. The I/O address must be on 16-byte boundry. */
338 pci_write_config32(dev, 0xf0, AB_INDX);
340 /* To enable AB/BIF DMA access, a specific register inside the BIF register space needs to be configured first. */
341 /* 4.3:Enables the SB700 to send transactions upstream over A-Link Express interface. */
342 axcfg_reg(0x04, 1 << 2, 1 << 2);
343 axindxc_reg(0x21, 0xff, 0);
345 /* 2.5:Enabling Non-Posted Memory Write for the K8 Platform */
346 axindxc_reg(0x10, 1 << 9, 1 << 9);
347 /* END of sbPorAtStartOfTblCfg */
349 /* sbDevicesPorInitTables */
350 /* set smbus iobase */
351 pci_write_config32(dev, 0x90, SMBUS_IO_BASE | 1);
353 /* enable smbus controller interface */
354 byte = pci_read_config8(dev, 0xd2);
356 pci_write_config8(dev, 0xd2, byte);
359 pci_write_config8(dev, 0x40, 0x44);
361 /* Enable ISA Address 0-960K decoding */
362 pci_write_config8(dev, 0x48, 0x0f);
364 /* Enable ISA Address 0xC0000-0xDFFFF decode */
365 pci_write_config8(dev, 0x49, 0xff);
367 /* Enable decode cycles to IO C50, C51, C52 GPM controls. */
368 byte = pci_read_config8(dev, 0x41);
371 pci_write_config8(dev, 0x41, byte);
373 /* Legacy DMA Prefetch Enhancement, CIM masked it. */
374 /* pci_write_config8(dev, 0x43, 0x1); */
376 /* Disabling Legacy USB Fast SMI# */
377 byte = pci_read_config8(dev, 0x62);
379 pci_write_config8(dev, 0x62, byte);
381 /* Features Enable */
382 pci_write_config32(dev, 0x64, 0x829E79BF); /* bit10: Enables the HPET interrupt. */
384 /* SerialIrq Control */
385 pci_write_config8(dev, 0x69, 0x90);
387 /* Test Mode, PCIB_SReset_En Mask is set. */
388 pci_write_config8(dev, 0x6c, 0x20);
390 /* IO Address Enable, CIM set 0x78 only and masked 0x79. */
391 /*pci_write_config8(dev, 0x79, 0x4F); */
392 pci_write_config8(dev, 0x78, 0xFF);
394 /* Set smbus iospace enable, I don't know why write 0x04 into reg5 that is reserved */
395 pci_write_config16(dev, 0x4, 0x0407);
397 /* clear any lingering errors, so the transaction will run */
398 outb(inb(SMBUS_IO_BASE + SMBHSTSTAT), SMBUS_IO_BASE + SMBHSTSTAT);
400 /* IDE Device, BDF:0-20-1 */
401 printk(BIOS_INFO, "sb700_devices_por_init(): IDE Device, BDF:0-20-1\n");
402 dev = pci_locate_device(PCI_ID(0x1002, 0x439C), 0);
403 /* Disable prefetch */
404 byte = pci_read_config8(dev, 0x63);
406 pci_write_config8(dev, 0x63, byte);
408 /* LPC Device, BDF:0-20-3 */
409 printk(BIOS_INFO, "sb700_devices_por_init(): LPC Device, BDF:0-20-3\n");
410 dev = pci_locate_device(PCI_ID(0x1002, 0x439D), 0);
412 pci_write_config8(dev, 0x40, 0x04);
414 /* IO Port Decode Enable */
415 pci_write_config8(dev, 0x44, 0xFF);
416 pci_write_config8(dev, 0x45, 0xFF);
417 pci_write_config8(dev, 0x46, 0xC3);
418 pci_write_config8(dev, 0x47, 0xFF);
420 // TODO: This has already been done(?)
421 /* IO/Mem Port Decode Enable, I don't know why CIM disable some ports.
422 * Disable LPC TimeOut counter, enable SuperIO Configuration Port (2e/2f),
423 * Alternate Super I/O Configuration Port (4e/4f), Wide Generic IO Port (64/65). */
424 byte = pci_read_config8(dev, 0x48);
425 byte |= (1 << 1) | (1 << 0); /* enable Super IO config port 2e-2h, 4e-4f */
426 byte |= 1 << 6; /* enable for RTC I/O range */
427 pci_write_config8(dev, 0x48, byte);
428 pci_write_config8(dev, 0x49, 0xFF);
429 /* Enable 0x480-0x4bf, 0x4700-0x470B */
430 byte = pci_read_config8(dev, 0x4A);
431 byte |= ((1 << 1) + (1 << 6)); /*0x42, save the configuraion for port 0x80. */
432 pci_write_config8(dev, 0x4A, byte);
434 /* Enable Tpm12_en and Tpm_legacy. I don't know what is its usage and copied from CIM. */
435 pci_write_config8(dev, 0x7C, 0x05);
437 /* P2P Bridge, BDF:0-20-4, the configuration of the registers in this dev are copied from CIM,
439 printk(BIOS_INFO, "sb700_devices_por_init(): P2P Bridge, BDF:0-20-4\n");
440 dev = pci_locate_device(PCI_ID(0x1002, 0x4384), 0);
442 /* Arbiter enable. */
443 pci_write_config8(dev, 0x43, 0xff);
445 /* Set PCDMA request into hight priority list. */
446 /* pci_write_config8(dev, 0x49, 0x1) */ ;
448 pci_write_config8(dev, 0x40, 0x26);
450 pci_write_config8(dev, 0x0d, 0x40);
451 pci_write_config8(dev, 0x1b, 0x40);
452 /* Enable PCIB_DUAL_EN_UP will fix potential problem with PCI cards. */
453 pci_write_config8(dev, 0x50, 0x01);
455 /* SATA Device, BDF:0-17-0, Non-Raid-5 SATA controller */
456 printk(BIOS_INFO, "sb700_devices_por_init(): SATA Device, BDF:0-18-0\n");
457 dev = pci_locate_device(PCI_ID(0x1002, 0x4390), 0);
459 /*PHY Global Control*/
460 pci_write_config16(dev, 0x86, 0x2C00);
463 /* sbPmioPorInitTable, Pre-initializing PMIO register space
464 * The power management (PM) block is resident in the PCI/LPC/ISA bridge.
465 * The PM regs are accessed via IO mapped regs 0xcd6 and 0xcd7.
466 * The index address is first programmed into IO reg 0xcd6.
467 * Read or write values are accessed through IO reg 0xcd7.
469 static void sb700_pmio_por_init(void)
473 printk(BIOS_INFO, "sb700_pmio_por_init()\n");
474 /* K8KbRstEn, KB_RST# control for K8 system. */
475 byte = pmio_read(0x66);
477 pmio_write(0x66, byte);
479 /* RPR2.31 PM_TURN_OFF_MSG during ASF Shutdown. */
480 if (get_sb700_revision(pci_locate_device(PCI_ID(0x1002, 0x4385), 0)) <= 0x12) {
481 byte = pmio_read(0x65);
483 pmio_write(0x65, byte);
485 byte = pmio_read(0x75);
488 pmio_write(0x75, byte);
490 byte = pmio_read(0x52);
493 pmio_write(0x52, byte);
495 byte = pmio_read(0xD7);
497 pmio_write(0xD7, byte);
499 byte = pmio_read(0x65);
501 pmio_write(0x65, byte);
503 byte = pmio_read(0x75);
506 pmio_write(0x75, byte);
508 byte = pmio_read(0x52);
511 pmio_write(0x52, byte);
515 /* Watch Dog Timer Control
516 * Set watchdog time base to 0xfec000f0 to avoid SCSI card boot failure.
517 * But I don't find WDT is enabled in SMBUS 0x41 bit3 in CIM.
519 pmio_write(0x6c, 0xf0);
520 pmio_write(0x6d, 0x00);
521 pmio_write(0x6e, 0xc0);
522 pmio_write(0x6f, 0xfe);
524 /* rpr2.15: Enabling Spread Spectrum */
525 byte = pmio_read(0x42);
527 pmio_write(0x42, byte);
528 /* TODO: Check if it is necessary. IDE reset */
529 byte = pmio_read(0xB2);
531 pmio_write(0xB2, byte);
535 * Add any south bridge setting.
537 static void sb700_pci_cfg(void)
542 /* SMBus Device, BDF:0-20-0 */
543 dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
544 /* Enable watchdog decode timer */
545 byte = pci_read_config8(dev, 0x41);
547 pci_write_config8(dev, 0x41, byte);
549 /* Set to 1 to reset USB on the software (such as IO-64 or IO-CF9 cycles)
550 * generated PCIRST#. */
551 byte = pmio_read(0x65);
553 pmio_write(0x65, byte);
555 /* IDE Device, BDF:0-20-1 */
556 dev = pci_locate_device(PCI_ID(0x1002, 0x439C), 0);
557 /* Enable IDE Explicit prefetch, 0x63[0] clear */
558 byte = pci_read_config8(dev, 0x63);
560 pci_write_config8(dev, 0x63, byte);
562 /* LPC Device, BDF:0-20-3 */
563 /* The code below is ported from old chipset. It is not
564 * mentioned in RPR. But I keep them. The registers and the
565 * comments are compatible. */
566 dev = pci_locate_device(PCI_ID(0x1002, 0x439D), 0);
567 /* Enabling LPC DMA function. */
568 byte = pci_read_config8(dev, 0x40);
570 pci_write_config8(dev, 0x40, byte);
571 /* Disabling LPC TimeOut. 0x48[7] clear. */
572 byte = pci_read_config8(dev, 0x48);
574 pci_write_config8(dev, 0x48, byte);
575 /* Disabling LPC MSI Capability, 0x78[1] clear. */
576 byte = pci_read_config8(dev, 0x78);
578 pci_write_config8(dev, 0x78, byte);
580 /* SATA Device, BDF:0-17-0, Non-Raid-5 SATA controller */
581 dev = pci_locate_device(PCI_ID(0x1002, 0x4390), 0);
582 /* rpr7.12 SATA MSI and D3 Power State Capability. */
583 byte = pci_read_config8(dev, 0x40);
585 pci_write_config8(dev, 0x40, byte);
586 if (get_sb700_revision(pci_locate_device(PCI_ID(0x1002, 0x4385), 0)) <= 0x12)
587 pci_write_config8(dev, 0x34, 0x70); /* set 0x61 to 0x70 if S1 is not supported. */
589 pci_write_config8(dev, 0x34, 0x50); /* set 0x61 to 0x50 if S1 is not supported. */
591 pci_write_config8(dev, 0x40, byte);
596 static void sb700_por_init(void)
598 /* sbDevicesPorInitTable + sbK8PorInitTable */
599 sb700_devices_por_init();
601 /* sbPmioPorInitTable + sbK8PmioPorInitTable */
602 sb700_pmio_por_init();
606 * It should be called during early POST after memory detection and BIOS shadowing but before PCI bus enumeration.
608 static void sb700_before_pci_init(void)
614 * This function should be called after enable_sb700_smbus().
616 static void sb700_early_setup(void)
618 printk(BIOS_INFO, "sb700_early_setup()\n");
623 static int smbus_read_byte(u32 device, u32 address)
625 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
628 int s3_save_nvram_early(u32 dword, int size, int nvram_pos)
631 printk(BIOS_DEBUG, "Writing %x of size %d to nvram pos: %d\n", dword, size, nvram_pos);
633 for (i = 0; i<size; i++) {
634 outb(nvram_pos, BIOSRAM_INDEX);
635 outb((dword >>(8 * i)) & 0xff , BIOSRAM_DATA);
642 int s3_load_nvram_early(int size, u32 *old_dword, int nvram_pos)
644 u32 data = *old_dword;
646 for (i = 0; i<size; i++) {
647 outb(nvram_pos, BIOSRAM_INDEX);
648 data &= ~(0xff << (i * 8));
649 data |= inb(BIOSRAM_DATA) << (i *8);
653 printk(BIOS_DEBUG, "Loading %x of size %d to nvram pos:%d\n", *old_dword, size,
658 #if CONFIG_HAVE_ACPI_RESUME == 1
659 static int acpi_is_wakeup_early(void)
662 tmp = inw(ACPI_PM1_CNT_BLK);
663 printk(BIOS_DEBUG, "IN TEST WAKEUP %x\n", tmp);
664 return (((tmp & (7 << 10)) >> 10) == 3);
668 struct cbmem_entry *get_cbmem_toc(void)
671 int xnvram_pos = 0xfc, xi;
672 for (xi = 0; xi<4; xi++) {
673 outb(xnvram_pos, BIOSRAM_INDEX);
674 xdata &= ~(0xff << (xi * 8));
675 xdata |= inb(BIOSRAM_DATA) << (xi *8);
678 return (struct cbmem_entry *) xdata;