It adds support for automatic PSS object generation for AMD pre fam Fh CPU. Those...
[coreboot.git] / src / southbridge / amd / sb700 / early_setup.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2010 Advanced Micro Devices, Inc.
5  *
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.
9  *
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.
14  *
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
18  */
19
20 #ifndef _SB700_EARLY_SETUP_C_
21 #define _SB700_EARLY_SETUP_C_
22
23 #include <reset.h>
24 #include <arch/cpu.h>
25 #include <cbmem.h>
26 #include "sb700.h"
27 #include "smbus.c"
28
29 #define SMBUS_IO_BASE 0x6000    /* Is it a temporary SMBus I/O base address? */
30          /*SIZE 0x40 */
31
32 static void pmio_write(u8 reg, u8 value)
33 {
34         outb(reg, PM_INDEX);
35         outb(value, PM_INDEX + 1);
36 }
37
38 static u8 pmio_read(u8 reg)
39 {
40         outb(reg, PM_INDEX);
41         return inb(PM_INDEX + 1);
42 }
43
44 static void sb700_acpi_init(void)
45 {
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);
54
55         /* CpuControl is in \_PR.CPU0, 6 bytes */
56         pmio_write(0x26, ACPI_CPU_CONTROL & 0xFF);
57         pmio_write(0x27, ACPI_CPU_CONTROL >> 8);
58
59         pmio_write(0x2A, 0);    /* AcpiSmiCmdLo */
60         pmio_write(0x2B, 0);    /* AcpiSmiCmdHi */
61
62         pmio_write(0x2C, ACPI_PMA_CNT_BLK & 0xFF);
63         pmio_write(0x2D, ACPI_PMA_CNT_BLK >> 8);
64
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 */
70 }
71
72 /* RPR 2.28: Get SB ASIC Revision. */
73 static u8 set_sb700_revision(void)
74 {
75         device_t dev;
76         u8 rev_id, enable_14Mhz, byte;
77         u8 rev = 0;
78
79         /* if (rev != 0) return rev; */
80
81         dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
82
83         if (dev == PCI_DEV_INVALID) {
84                 die("SMBUS controller not found\n");
85                 /* NOT REACHED */
86         }
87         rev_id =  pci_read_config8(dev, 0x08);
88
89         if (rev_id == 0x39) {
90                 enable_14Mhz = (pmio_read(0x53) >> 6) & 1;
91                 if (enable_14Mhz == 0x0)
92                         rev = 0x11;     /* A11 */
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. */
97                         rev = 0x12;
98                         byte = pci_read_config8(dev, 0x40);
99                         byte |= 1 << 0;
100                         pci_write_config8(dev, 0x40, byte);
101
102                         pci_write_config8(dev, 0x08, 0x3A); /* Change 0x39 to 0x3A. */
103
104                         byte &= ~(1 << 0);
105                         pci_write_config8(dev, 0x40, byte);
106                 }
107         } else if (rev_id == 0x3A) { /* A12 will be 0x3A after BIOS is initialized */
108                 rev = 0x12;
109         } else if (rev_id == 0x3C) {
110                 rev = 0x14;
111         } else if (rev_id == 0x3D) {
112                 rev = 0x15;
113         } else
114                 die("It is not SB700 or SB710\n");
115
116         return rev;
117 }
118
119 /***************************************
120 * Legacy devices are mapped to LPC space.
121 *       Serial port 0
122 *       KBC Port
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)
129 {
130         u8 reg8;
131         u32 reg32;
132         device_t dev;
133
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);
140         reg32 |= 1 << 31;
141         pci_write_config32(dev, 0x4C, reg32);
142
143         /* Enable lpc controller */
144         reg32 = pci_read_config32(dev, 0x64);
145         reg32 |= 1 << 20;
146         pci_write_config32(dev, 0x64, reg32);
147
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);
152         reg8 |= 1 << 6;
153         pci_write_config8(dev, 0x44, reg8);
154
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);
159
160         /* Enable PrefetchEnSPIFromHost to speed up SPI flash read (does not affect LPC) */
161         reg8 = pci_read_config8(dev, 0xbb);
162         reg8 |= 1 << 0;
163         pci_write_config8(dev, 0xbb, reg8);
164
165         /* Super I/O, RTC */
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) */
170         reg8 |= (1 << 6);
171         pci_write_config8(dev, 0x48, reg8);
172 }
173
174 /* what is its usage? */
175 static u32 get_sbdn(u32 bus)
176 {
177         device_t dev;
178
179         /* Find the device. */
180         dev = pci_locate_device_on_bus(PCI_ID(0x1002, 0x4385), bus);
181         return (dev >> 15) & 0x1f;
182 }
183
184 static u8 dual_core(void)
185 {
186         return (pci_read_config32(PCI_DEV(0, 0x18, 3), 0xE8) & (0x3<<12)) != 0;
187 }
188
189 /*
190  * RPR 2.4 C-state and VID/FID change for the K8 platform.
191  */
192 static void enable_fid_change_on_sb(u32 sbbusn, u32 sbdn)
193 {
194         u8 byte;
195         byte = pmio_read(0x9a);
196         byte &= ~0x34;
197         if (dual_core())
198                 byte |= 0x34;
199         else
200                 byte |= 0x04;
201         pmio_write(0x9a, byte);
202
203         byte = pmio_read(0x8f);
204         byte &= ~0x30;
205         byte |= 0x20;
206         pmio_write(0x8f, byte);
207
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);
210
211         pmio_write(0x88, 0x10);
212
213         byte = pmio_read(0x7c);
214         byte |= 0x03;
215         pmio_write(0x7c, byte);
216
217         /* Must be 0 for K8 platform. */
218         byte = pmio_read(0x68);
219         byte &= ~0x01;
220         pmio_write(0x68, byte);
221         /* Must be 0 for K8 platform. */
222         byte = pmio_read(0x8d);
223         byte &= ~(1<<6);
224         pmio_write(0x8d, byte);
225
226         byte = pmio_read(0x61);
227         byte &= ~0x04;
228         pmio_write(0x61, byte);
229
230         byte = pmio_read(0x42);
231         byte &= ~0x04;
232         pmio_write(0x42, byte);
233
234         pmio_write(0x89, 0x10);
235
236         /* Toggle the LDT_STOP# during FID/VID Change, this bit is documented
237            only in SB600!
238            While here, enable C states too
239         */
240         pmio_write(0x67, 0x6);
241 }
242
243 void hard_reset(void)
244 {
245         set_bios_reset();
246
247         /* full reset */
248         outb(0x0a, 0x0cf9);
249         outb(0x0e, 0x0cf9);
250 }
251
252 void soft_reset(void)
253 {
254         set_bios_reset();
255         /* link reset */
256         outb(0x06, 0x0cf9);
257 }
258
259 void sb700_pci_port80(void)
260 {
261         u8 byte;
262         device_t dev;
263
264         /* P2P Bridge */
265         dev = pci_locate_device(PCI_ID(0x1002, 0x4384), 0);
266
267         /* Chip Control: Enable subtractive decoding */
268         byte = pci_read_config8(dev, 0x40);
269         byte |= 1 << 5;
270         pci_write_config8(dev, 0x40, byte);
271
272         /* Misc Control: Enable subtractive decoding if 0x40 bit 5 is set */
273         byte = pci_read_config8(dev, 0x4B);
274         byte |= 1 << 7;
275         pci_write_config8(dev, 0x4B, byte);
276
277         /* The same IO Base and IO Limit here is meaningful because we set the
278          * bridge to be subtractive. During early setup stage, we have to make
279          * sure that data can go through port 0x80.
280          */
281         /* IO Base: 0xf000 */
282         byte = pci_read_config8(dev, 0x1C);
283         byte |= 0xF << 4;
284         pci_write_config8(dev, 0x1C, byte);
285
286         /* IO Limit: 0xf000 */
287         byte = pci_read_config8(dev, 0x1D);
288         byte |= 0xF << 4;
289         pci_write_config8(dev, 0x1D, byte);
290
291         /* PCI Command: Enable IO response */
292         byte = pci_read_config8(dev, 0x04);
293         byte |= 1 << 0;
294         pci_write_config8(dev, 0x04, byte);
295
296         /* LPC controller */
297         dev = pci_locate_device(PCI_ID(0x1002, 0x439D), 0);
298
299         byte = pci_read_config8(dev, 0x4A);
300         byte &= ~(1 << 5);      /* disable lpc port 80 */
301         pci_write_config8(dev, 0x4A, byte);
302 }
303
304 void sb700_lpc_port80(void)
305 {
306         u8 byte;
307         device_t dev;
308         u32 reg32;
309
310         /* Enable LPC controller */
311         dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
312         reg32 = pci_read_config32(dev, 0x64);
313         reg32 |= 0x00100000;    /* lpcEnable */
314         pci_write_config32(dev, 0x64, reg32);
315
316         /* Enable port 80 LPC decode in pci function 3 configuration space. */
317         dev = pci_locate_device(PCI_ID(0x1002, 0x439d), 0);
318         byte = pci_read_config8(dev, 0x4a);
319         byte |= 1 << 5;         /* enable port 80 */
320         pci_write_config8(dev, 0x4a, byte);
321 }
322
323 /* sbDevicesPorInitTable */
324 static void sb700_devices_por_init(void)
325 {
326         device_t dev;
327         u8 byte;
328
329         printk(BIOS_INFO, "sb700_devices_por_init()\n");
330         /* SMBus Device, BDF:0-20-0 */
331         printk(BIOS_INFO, "sb700_devices_por_init(): SMBus Device, BDF:0-20-0\n");
332         dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
333
334         if (dev == PCI_DEV_INVALID) {
335                 die("SMBUS controller not found\n");
336                 /* NOT REACHED */
337         }
338         printk(BIOS_INFO, "SMBus controller enabled, sb revision is A%x\n",
339                     set_sb700_revision());
340
341         /* sbPorAtStartOfTblCfg */
342         /* Set A-Link bridge access address. This address is set at device 14h, function 0, register 0xf0.
343          * This is an I/O address. The I/O address must be on 16-byte boundry.  */
344         pci_write_config32(dev, 0xf0, AB_INDX);
345
346         /* To enable AB/BIF DMA access, a specific register inside the BIF register space needs to be configured first. */
347         /* 4.3:Enables the SB700 to send transactions upstream over A-Link Express interface. */
348         axcfg_reg(0x04, 1 << 2, 1 << 2);
349         axindxc_reg(0x21, 0xff, 0);
350
351         /* 2.5:Enabling Non-Posted Memory Write for the K8 Platform */
352         axindxc_reg(0x10, 1 << 9, 1 << 9);
353         /* END of sbPorAtStartOfTblCfg */
354
355         /* sbDevicesPorInitTables */
356         /* set smbus iobase */
357         pci_write_config32(dev, 0x90, SMBUS_IO_BASE | 1);
358
359         /* enable smbus controller interface */
360         byte = pci_read_config8(dev, 0xd2);
361         byte |= (1 << 0);
362         pci_write_config8(dev, 0xd2, byte);
363
364         /* KB2RstEnable */
365         pci_write_config8(dev, 0x40, 0x44);
366
367         /* Enable ISA Address 0-960K decoding */
368         pci_write_config8(dev, 0x48, 0x0f);
369
370         /* Enable ISA  Address 0xC0000-0xDFFFF decode */
371         pci_write_config8(dev, 0x49, 0xff);
372
373         /* Enable decode cycles to IO C50, C51, C52 GPM controls. */
374         byte = pci_read_config8(dev, 0x41);
375         byte &= 0x80;
376         byte |= 0x33;
377         pci_write_config8(dev, 0x41, byte);
378
379         /* Legacy DMA Prefetch Enhancement, CIM masked it. */
380         /* pci_write_config8(dev, 0x43, 0x1); */
381
382         /* Disabling Legacy USB Fast SMI# */
383         byte = pci_read_config8(dev, 0x62);
384         byte |= 0x24;
385         pci_write_config8(dev, 0x62, byte);
386
387         /* Features Enable */
388         pci_write_config32(dev, 0x64, 0x829E79BF); /* bit10: Enables the HPET interrupt. */
389
390         /* SerialIrq Control */
391         pci_write_config8(dev, 0x69, 0x90);
392
393         /* Test Mode, PCIB_SReset_En Mask is set. */
394         pci_write_config8(dev, 0x6c, 0x20);
395
396         /* IO Address Enable, CIM set 0x78 only and masked 0x79. */
397         /*pci_write_config8(dev, 0x79, 0x4F); */
398         pci_write_config8(dev, 0x78, 0xFF);
399
400         /* Set smbus iospace enable, I don't know why write 0x04 into reg5 that is reserved */
401         pci_write_config16(dev, 0x4, 0x0407);
402
403         /* clear any lingering errors, so the transaction will run */
404         outb(inb(SMBUS_IO_BASE + SMBHSTSTAT), SMBUS_IO_BASE + SMBHSTSTAT);
405
406         /* IDE Device, BDF:0-20-1 */
407         printk(BIOS_INFO, "sb700_devices_por_init(): IDE Device, BDF:0-20-1\n");
408         dev = pci_locate_device(PCI_ID(0x1002, 0x439C), 0);
409         /* Disable prefetch */
410         byte = pci_read_config8(dev, 0x63);
411         byte |= 0x1;
412         pci_write_config8(dev, 0x63, byte);
413
414         /* LPC Device, BDF:0-20-3 */
415         printk(BIOS_INFO, "sb700_devices_por_init(): LPC Device, BDF:0-20-3\n");
416         dev = pci_locate_device(PCI_ID(0x1002, 0x439D), 0);
417         /* DMA enable */
418         pci_write_config8(dev, 0x40, 0x04);
419
420         /* LPC Sync Timeout */
421         pci_write_config8(dev, 0x49, 0xFF);
422
423         /* Enable Tpm12_en and Tpm_legacy. I don't know what is its usage and copied from CIM. */
424         pci_write_config8(dev, 0x7C, 0x05);
425
426         /* P2P Bridge, BDF:0-20-4, the configuration of the registers in this dev are copied from CIM,
427          */
428         printk(BIOS_INFO, "sb700_devices_por_init(): P2P Bridge, BDF:0-20-4\n");
429         dev = pci_locate_device(PCI_ID(0x1002, 0x4384), 0);
430
431         /* Arbiter enable. */
432         pci_write_config8(dev, 0x43, 0xff);
433
434         /* Set PCDMA request into hight priority list. */
435         /* pci_write_config8(dev, 0x49, 0x1) */ ;
436
437         pci_write_config8(dev, 0x40, 0x26);
438
439         pci_write_config8(dev, 0x0d, 0x40);
440         pci_write_config8(dev, 0x1b, 0x40);
441         /* Enable PCIB_DUAL_EN_UP will fix potential problem with PCI cards. */
442         pci_write_config8(dev, 0x50, 0x01);
443
444         /* SATA Device, BDF:0-17-0, Non-Raid-5 SATA controller */
445         printk(BIOS_INFO, "sb700_devices_por_init(): SATA Device, BDF:0-18-0\n");
446         dev = pci_locate_device(PCI_ID(0x1002, 0x4390), 0);
447
448         /*PHY Global Control*/
449         pci_write_config16(dev, 0x86, 0x2C00);
450 }
451
452 /* sbPmioPorInitTable, Pre-initializing PMIO register space
453 * The power management (PM) block is resident in the PCI/LPC/ISA bridge.
454 * The PM regs are accessed via IO mapped regs 0xcd6 and 0xcd7.
455 * The index address is first programmed into IO reg 0xcd6.
456 * Read or write values are accessed through IO reg 0xcd7.
457 */
458 static void sb700_pmio_por_init(void)
459 {
460         u8 byte;
461
462         printk(BIOS_INFO, "sb700_pmio_por_init()\n");
463         /* K8KbRstEn, KB_RST# control for K8 system. */
464         byte = pmio_read(0x66);
465         byte |= 0x20;
466         pmio_write(0x66, byte);
467
468         /* RPR2.31 PM_TURN_OFF_MSG during ASF Shutdown. */
469         if (get_sb700_revision(pci_locate_device(PCI_ID(0x1002, 0x4385), 0)) <= 0x12) {
470                 byte = pmio_read(0x65);
471                 byte &= ~(1 << 7);
472                 pmio_write(0x65, byte);
473
474                 byte = pmio_read(0x75);
475                 byte &= 0xc0;
476                 byte |= 0x05;
477                 pmio_write(0x75, byte);
478
479                 byte = pmio_read(0x52);
480                 byte &= 0xc0;
481                 byte |= 0x08;
482                 pmio_write(0x52, byte);
483         } else {
484                 byte = pmio_read(0xD7);
485                 byte |= 1 << 0;
486                 pmio_write(0xD7, byte);
487
488                 byte = pmio_read(0x65);
489                 byte |= 1 << 7;
490                 pmio_write(0x65, byte);
491
492                 byte = pmio_read(0x75);
493                 byte &= 0xc0;
494                 byte |= 0x01;
495                 pmio_write(0x75, byte);
496
497                 byte = pmio_read(0x52);
498                 byte &= 0xc0;
499                 byte |= 0x02;
500                 pmio_write(0x52, byte);
501
502         }
503
504         /* Watch Dog Timer Control
505          * Set watchdog time base to 0xfec000f0 to avoid SCSI card boot failure.
506          * But I don't find WDT is enabled in SMBUS 0x41 bit3 in CIM.
507          */
508         pmio_write(0x6c, 0xf0);
509         pmio_write(0x6d, 0x00);
510         pmio_write(0x6e, 0xc0);
511         pmio_write(0x6f, 0xfe);
512
513         /* rpr2.15: Enabling Spread Spectrum */
514         byte = pmio_read(0x42);
515         byte |= 1 << 7;
516         pmio_write(0x42, byte);
517         /* TODO: Check if it is necessary. IDE reset */
518         byte = pmio_read(0xB2);
519         byte |= 1 << 0;
520         pmio_write(0xB2, byte);
521 }
522
523 /*
524 * Add any south bridge setting.
525 */
526 static void sb700_pci_cfg(void)
527 {
528         device_t dev;
529         u8 byte;
530
531         /* SMBus Device, BDF:0-20-0 */
532         dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
533         /* Enable watchdog decode timer */
534         byte = pci_read_config8(dev, 0x41);
535         byte |= (1 << 3);
536         pci_write_config8(dev, 0x41, byte);
537
538         /* Set to 1 to reset USB on the software (such as IO-64 or IO-CF9 cycles)
539          * generated PCIRST#. */
540         byte = pmio_read(0x65);
541         byte |= (1 << 4);
542         pmio_write(0x65, byte);
543
544         /* IDE Device, BDF:0-20-1 */
545         dev = pci_locate_device(PCI_ID(0x1002, 0x439C), 0);
546         /* Enable IDE Explicit prefetch, 0x63[0] clear */
547         byte = pci_read_config8(dev, 0x63);
548         byte &= 0xfe;
549         pci_write_config8(dev, 0x63, byte);
550
551         /* LPC Device, BDF:0-20-3 */
552         /* The code below is ported from old chipset. It is not
553          * mentioned in RPR. But I keep them. The registers and the
554          * comments are compatible. */
555         dev = pci_locate_device(PCI_ID(0x1002, 0x439D), 0);
556         /* Enabling LPC DMA function. */
557         byte = pci_read_config8(dev, 0x40);
558         byte |= (1 << 2);
559         pci_write_config8(dev, 0x40, byte);
560         /* Disabling LPC TimeOut. 0x48[7] clear. */
561         byte = pci_read_config8(dev, 0x48);
562         byte &= 0x7f;
563         pci_write_config8(dev, 0x48, byte);
564         /* Disabling LPC MSI Capability, 0x78[1] clear. */
565         byte = pci_read_config8(dev, 0x78);
566         byte &= 0xfd;
567         pci_write_config8(dev, 0x78, byte);
568
569         /* SATA Device, BDF:0-17-0, Non-Raid-5 SATA controller */
570         dev = pci_locate_device(PCI_ID(0x1002, 0x4390), 0);
571         /* rpr7.12 SATA MSI and D3 Power State Capability. */
572         byte = pci_read_config8(dev, 0x40);
573         byte |= 1 << 0;
574         pci_write_config8(dev, 0x40, byte);
575         if (get_sb700_revision(pci_locate_device(PCI_ID(0x1002, 0x4385), 0)) <= 0x12)
576                 pci_write_config8(dev, 0x34, 0x70); /* set 0x61 to 0x70 if S1 is not supported. */
577         else
578                 pci_write_config8(dev, 0x34, 0x50); /* set 0x61 to 0x50 if S1 is not supported. */
579         byte &= ~(1 << 0);
580         pci_write_config8(dev, 0x40, byte);
581 }
582
583 /*
584 */
585 static void sb700_por_init(void)
586 {
587         /* sbDevicesPorInitTable + sbK8PorInitTable */
588         sb700_devices_por_init();
589
590         /* sbPmioPorInitTable + sbK8PmioPorInitTable */
591         sb700_pmio_por_init();
592 }
593
594 /*
595 * It should be called during early POST after memory detection and BIOS shadowing but before PCI bus enumeration.
596 */
597 static void sb700_before_pci_init(void)
598 {
599         sb700_pci_cfg();
600 }
601
602 /*
603 * This function should be called after enable_sb700_smbus().
604 */
605 static void sb700_early_setup(void)
606 {
607         printk(BIOS_INFO, "sb700_early_setup()\n");
608         sb700_por_init();
609         sb700_acpi_init();
610 }
611
612 static int smbus_read_byte(u32 device, u32 address)
613 {
614         return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
615 }
616
617 int s3_save_nvram_early(u32 dword, int size, int  nvram_pos)
618 {
619         int i;
620         printk(BIOS_DEBUG, "Writing %x of size %d to nvram pos: %d\n", dword, size, nvram_pos);
621
622         for (i = 0; i<size; i++) {
623                 outb(nvram_pos, BIOSRAM_INDEX);
624                 outb((dword >>(8 * i)) & 0xff , BIOSRAM_DATA);
625                 nvram_pos++;
626         }
627
628         return nvram_pos;
629 }
630
631 int s3_load_nvram_early(int size, u32 *old_dword, int nvram_pos)
632 {
633         u32 data = *old_dword;
634         int i;
635         for (i = 0; i<size; i++) {
636                 outb(nvram_pos, BIOSRAM_INDEX);
637                 data &= ~(0xff << (i * 8));
638                 data |= inb(BIOSRAM_DATA) << (i *8);
639                 nvram_pos++;
640         }
641         *old_dword = data;
642         printk(BIOS_DEBUG, "Loading %x of size %d to nvram pos:%d\n", *old_dword, size,
643                 nvram_pos-size);
644         return nvram_pos;
645 }
646
647 #if CONFIG_HAVE_ACPI_RESUME == 1
648 static int acpi_is_wakeup_early(void)
649 {
650         u16 tmp;
651         tmp = inw(ACPI_PM1_CNT_BLK);
652         printk(BIOS_DEBUG, "IN TEST WAKEUP %x\n", tmp);
653         return (((tmp & (7 << 10)) >> 10) == 3);
654 }
655 #endif
656
657 struct cbmem_entry *get_cbmem_toc(void)
658 {
659         uint32_t xdata = 0;
660         int xnvram_pos = 0xfc, xi;
661         for (xi = 0; xi<4; xi++) {
662                 outb(xnvram_pos, BIOSRAM_INDEX);
663                 xdata &= ~(0xff << (xi * 8));
664                 xdata |= inb(BIOSRAM_DATA) << (xi *8);
665                 xnvram_pos++;
666         }
667         return (struct cbmem_entry *) xdata;
668 }
669
670 #endif