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