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