m5a99x-evo: sup @ ramstage :-)
[coreboot.git] / src / southbridge / amd / cimx / sb900 / early.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2011 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
21 //#include <config.h>
22 #include <stdint.h>
23 #include <device/pci_ids.h>
24 #include <arch/io.h>            /* inl, outl */
25 #include <arch/romcc_io.h>      /* device_t */
26 #include "SbPlatform.h"
27 #include "SbEarly.h"
28 #include <console/console.h>
29 #include <console/loglevel.h>
30 #include "smbus.h"
31
32
33 /**
34  * @brief Get SouthBridge device number
35  * @param[in] bus target bus number
36  * @return southbridge device number
37  */
38 u32 get_sbdn(u32 bus)
39 {
40         device_t dev;
41
42     printk(BIOS_INFO, "SB900 - Early.c - get_sbdn - Start.\n");
43         dev = PCI_DEV(bus, 0x14, 0);
44 #if 0
45         dev = pci_locate_device_on_bus(
46                         PCI_ID(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_ATI_SB900_SM),
47                         bus);
48 #endif
49
50     printk(BIOS_INFO, "SB900 - Early.c - get_sbdn - End.\n");
51         return (dev >> 15) & 0x1f;
52 }
53
54
55 /**
56  * @brief South Bridge CIMx romstage entry,
57  *        wrapper of sbPowerOnInit entry point.
58  */
59 void sb_poweron_init(void)
60 {
61         AMDSBCFG sb_early_cfg;
62         u8 data;
63
64     printk(BIOS_INFO, "SB900 - Early.c - sb_poweron_init - Start.\n");
65
66         //Enable/Disable PCI Bridge Device 14 Function 4.
67         outb(0xEA, 0xCD6);
68         data = inb(0xCD7);
69         data &= !BIT0;
70         if(!CONFIG_PCIB_ENABLE) {
71                 data |= BIT0;
72         }
73         outb(data, 0xCD7);
74
75         SbPowerOnInit_Config(&sb_early_cfg);
76         //sb_early_cfg.StdHeader.Func = SB_POWERON_INIT;
77         //AmdSbDispatcher(&sb_early_cfg);
78         //TODO
79         //AMD_IMAGE_HEADER was missing, when using AmdSbDispatcher,
80         // VerifyImage() will fail, LocateImage() take minitues to find the image.
81         sbPowerOnInit(&sb_early_cfg);
82     printk(BIOS_INFO, "SB900 - Early.c - sb_poweron_init - End.\n");
83 }
84
85 /**
86  * @brief South Bridge CIMx romstage entry,
87  *        wrapper of sbPowerOnInit entry point.
88  */
89 void sb_before_pci_init(void)
90 {
91         AMDSBCFG sb_early_cfg;
92
93     printk(BIOS_INFO, "SB900 - Early.c - sb_before_pci_init - Start.\n");
94         sb900_cimx_config(&sb_early_cfg);
95         //sb_early_cfg.StdHeader.Func = SB_POWERON_INIT;
96         //AmdSbDispatcher(&sb_early_cfg);
97         //TODO
98         //AMD_IMAGE_HEADER was missing, when using AmdSbDispatcher,
99         // VerifyImage() will fail, LocateImage() take minitues to find the image.
100         sbBeforePciInit(&sb_early_cfg);
101     printk(BIOS_INFO, "SB900 - Early.c - sb_before_pci_init - End.\n");
102 }
103
104 void sb_After_Pci_Init(void)
105 {
106         AMDSBCFG sb_early_cfg;
107
108     printk(BIOS_INFO, "SB900 - Early.c - sb_After_Pci_Init - Start.\n");
109         sb900_cimx_config(&sb_early_cfg);
110         //sb_early_cfg.StdHeader.Func = SB_POWERON_INIT;
111         //AmdSbDispatcher(&sb_early_cfg);
112         //TODO
113         //AMD_IMAGE_HEADER was missing, when using AmdSbDispatcher,
114         // VerifyImage() will fail, LocateImage() take minitues to find the image.
115         sbAfterPciInit(&sb_early_cfg);
116     printk(BIOS_INFO, "SB900 - Early.c - sb_After_Pci_Init - End.\n");
117 }
118
119 void sb_Mid_Post_Init(void)
120 {
121         AMDSBCFG sb_early_cfg;
122
123     printk(BIOS_INFO, "SB900 - Early.c - sb_Mid_Post_Init - Start.\n");
124         sb900_cimx_config(&sb_early_cfg);
125         //sb_early_cfg.StdHeader.Func = SB_POWERON_INIT;
126         //AmdSbDispatcher(&sb_early_cfg);
127         //TODO
128         //AMD_IMAGE_HEADER was missing, when using AmdSbDispatcher,
129         // VerifyImage() will fail, LocateImage() take minitues to find the image.
130         sbMidPostInit(&sb_early_cfg);
131     printk(BIOS_INFO, "SB900 - Early.c - sb_Mid_Post_Init - End.\n");
132 }
133
134 void sb_Late_Post(void)
135 {
136         AMDSBCFG sb_early_cfg;
137         u8 data;
138
139     printk(BIOS_INFO, "SB900 - Early.c - sb_Late_Post - Start.\n");
140         sb900_cimx_config(&sb_early_cfg);
141         //sb_early_cfg.StdHeader.Func = SB_POWERON_INIT;
142         //AmdSbDispatcher(&sb_early_cfg);
143         //TODO
144         //AMD_IMAGE_HEADER was missing, when using AmdSbDispatcher,
145         // VerifyImage() will fail, LocateImage() take minitues to find the image.
146         sbLatePost(&sb_early_cfg);
147
148         //Set ACPI SCI IRQ to 0x9.
149         data = CONFIG_ACPI_SCI_IRQ;
150         outb(0x10, 0xC00);
151         outb(data, 0xC01);
152         outb(0x90, 0xC00);
153         outb(data, 0xC01);
154
155         if (data > 0x7) {
156                 data = inb(0x4D1);
157                 data |= (1 << (CONFIG_ACPI_SCI_IRQ - 8));
158                 outb(data, 0x4D1);
159         } else {
160                 data = inb(0x4D0);
161                 data |= (1 << (CONFIG_ACPI_SCI_IRQ));
162                 outb(data, 0x4D0);
163         }
164
165     printk(BIOS_INFO, "SB900 - Early.c - sb_Late_Post - End.\n");
166 }
167
168