blob: 6d2732128599503488e5aced413f9f2f93094de6 [file] [log] [blame]
Zheng Bao98fcc092011-03-27 16:39:58 +00001/*
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#include <console/console.h>
21#include <device/device.h>
22#include <device/pci.h>
23#include <device/pci_ids.h>
24#include <device/pci_ops.h>
25#include <arch/ioapic.h>
26#include "sr5650.h"
27
28/* Table 6-6 Recommended Interrupt Routing Configuration */
29typedef struct _apic_device_info {
30 u8 group;
31 u8 swizzle;
32 u8 pin;
33} apic_device_info;
34
35#define ABCD 0
36#define BCDA 1
37#define CDAB 2
38#define DABC 3
39
40static const apic_device_info default_apic_device_info_t [] = {
41 /* Group Swizzling Port Int Pin */
42 [0] = {0, 0, 31}, /* HT */
43 [1] = {0, 0, 31}, /* IOMMU */
44 [2] = {0, ABCD, 28}, /* Dev2 Grp0 [Int - 0..3] */
45 [3] = {1, ABCD, 28}, /* Dev3 Grp1 [Int - 4..7] */
46 [4] = {5, ABCD, 28}, /* Dev4 Grp5 [Int - 20..23] */
47 [5] = {5, CDAB, 28}, /* Dev5 Grp5 [Int - 20..23] */
48 [6] = {6, BCDA, 29}, /* Dev6 Grp6 [Int - 24..27] */
49 [7] = {6, CDAB, 29}, /* Dev7 Grp6 [Int - 24..27] */
50 [8] = {0, 0, 0 }, /* Reserved */
51 [9] = {6, ABCD, 29}, /* Dev9 Grp6 [Int - 24..27] */
52 [10] = {5, BCDA, 30}, /* Dev10 Grp5 [Int - 20..23] */
53 [11] = {2, ABCD, 30}, /* Dev11 Grp2 [Int - 8..11] */
54 [12] = {3, ABCD, 30}, /* Dev12 Grp3 [Int - 12..15] */
55 [13] = {4, ABCD, 30} /* Dev13 Grp4 [Int - 16..19] */
56};
57
58/* Their name are quite regular. So I undefine them. */
59#undef ABCD
60#undef BCDA
61#undef CDAB
62#undef DABC
63
64/* Init APIC of sr5690 */
65static void sr5690_apic_init(struct device *dev)
66{
67 u32 dword;
68 const apic_device_info *entry = default_apic_device_info_t;
69
70 /* rpr6.2.(2). Write to the IOAPIC Features Enable register */
71 pci_write_config32(dev, 0xF8, 0x0);
72 pci_write_config32(dev, 0xFC, 0x1F);
73 /* rpr6.2.(3). Write to the remaining interrupt routing registers */
74
75 /* IOAPICCMISCIND:0x3, group & swizzle of Dev 2,3,4,5 */
76 dword = (entry[2].group | entry[2].swizzle << 4) << 0 |
77 (entry[3].group | entry[3].swizzle << 4) << 8 |
78 (entry[4].group | entry[4].swizzle << 4) << 16 |
79 (entry[5].group | entry[5].swizzle << 4) << 24;
80 pci_write_config32(dev, 0xF8, 0x3);
81 pci_write_config32(dev, 0xFC, dword);
82
83 /* IOAPICCMISCIND:0x4, group & swizzle of Dev 6,7,9,10 */
84 dword = (entry[6].group | entry[6].swizzle << 4) << 0 |
85 (entry[7].group | entry[7].swizzle << 4) << 8 |
86 (entry[9].group | entry[9].swizzle << 4) << 16 |
87 (entry[10].group | entry[10].swizzle << 4) << 24;
88 pci_write_config32(dev, 0xF8, 0x4);
89 pci_write_config32(dev, 0xFC, dword);
90
91 /* IOAPICCMISCIND:0x5, group & swizzle of Dev 11,12,13 */
92 dword = (entry[11].group | entry[11].swizzle << 4) << 0 |
93 (entry[12].group | entry[12].swizzle << 4) << 8 |
94 (entry[13].group | entry[13].swizzle << 4) << 16;
95 pci_write_config32(dev, 0xF8, 0x5);
96 pci_write_config32(dev, 0xFC, dword);
97
98 /* IOAPICCMISCIND:0x6, pin map of dev 2,3,4,5 */
99 dword = entry[2].pin |
100 entry[3].pin << 8 |
101 entry[4].pin << 16|
102 entry[5].pin << 24;
103 pci_write_config32(dev, 0xF8, 0x6);
104 pci_write_config32(dev, 0xFC, dword);
105
106 /* IOAPICCMISCIND:0x7, pin map of dev 6,7,8,9 */
107 dword = entry[6].pin |
108 entry[7].pin << 8 |
109 entry[8].pin << 16|
110 entry[9].pin << 24;
111 pci_write_config32(dev, 0xF8, 0x7);
112 pci_write_config32(dev, 0xFC, dword);
113
114 /* IOAPICCMISCIND:0x8, pin map of dev 10,11,12,13 */
115 dword = entry[10].pin |
116 entry[11].pin << 8 |
117 entry[12].pin << 16|
118 entry[13].pin << 24;
119 pci_write_config32(dev, 0xF8, 0x8);
120 pci_write_config32(dev, 0xFC, dword);
121
122 /* IOAPICCMISCIND:0x9, pin map of ht, iommu */
123 dword = entry[0].pin | entry[1].pin << 8;
124 pci_write_config32(dev, 0xF8, 0x9);
125 pci_write_config32(dev, 0xFC, dword);
126
127 pci_write_config32(dev, 0xF8, 0x1);
128 dword = pci_read_config32(dev, 0xFC) & 0xfffffff0;
129 /* TODO: On SR56x0/SP5100 board, the IOAPIC on SR56x0 is the
130 * 2nd one. We need to check if it also is on your board. */
131 setup_ioapic(dword, 1);
132}
133
134static void pcie_init(struct device *dev)
135{
136 /* Enable pci error detecting */
137 u32 dword;
138
139 printk(BIOS_INFO, "pcie_init in sr5650_ht.c\n");
140
141 /* System error enable */
142 dword = pci_read_config32(dev, 0x04);
143 dword |= (1 << 8); /* System error enable */
144 dword |= (1 << 30); /* Clear possible errors */
145 pci_write_config32(dev, 0x04, dword);
146
147 /*
148 * 1 is APIC enable
149 * 18 is enable nb to accept A4 interrupt request from SB.
150 */
151 dword = pci_read_config32(dev, 0x4C);
152 dword |= 1 << 1 | 1 << 18; /* Clear possible errors */
153 pci_write_config32(dev, 0x4C, dword);
154
155 sr5690_apic_init(dev);
156}
157
158static void sr5690_read_resource(struct device *dev)
159{
160 pci_dev_read_resources(dev);
161
162 /* rpr6.2.(1). Write the Base Address Register (BAR) */
163 pci_write_config32(dev, 0xF8, 0x1); /* set IOAPIC's index as 1 and make sure no one changes it. */
164 pci_get_resource(dev, 0xFC); /* APIC located in sr5690 */
165
166 compact_resources(dev);
167}
168
169/* If IOAPIC's index changes, we should replace the pci_dev_set_resource(). */
170static void sr5690_set_resources(struct device *dev)
171{
172 pci_write_config32(dev, 0xF8, 0x1); /* set IOAPIC's index as 1 and make sure no one changes it. */
173 pci_dev_set_resources(dev);
174}
175
176static struct pci_operations lops_pci = {
177 .set_subsystem = pci_dev_set_subsystem,
178};
179
180static struct device_operations ht_ops = {
181 .read_resources = sr5690_read_resource,
182 .set_resources = sr5690_set_resources,
183 .enable_resources = pci_dev_enable_resources,
184 .init = pcie_init,
185 .scan_bus = 0,
186 .ops_pci = &lops_pci,
187};
188
189static const struct pci_driver ht_driver_sr5690 __pci_driver = {
190 .ops = &ht_ops,
191 .vendor = PCI_VENDOR_ID_ATI,
192 .device = PCI_DEVICE_ID_AMD_SR5690_HT,
193};
194
195static const struct pci_driver ht_driver_sr5670 __pci_driver = {
196 .ops = &ht_ops,
197 .vendor = PCI_VENDOR_ID_ATI,
198 .device = PCI_DEVICE_ID_AMD_SR5670_HT,
199};
200
201static const struct pci_driver ht_driver_sr5650 __pci_driver = {
202 .ops = &ht_ops,
203 .vendor = PCI_VENDOR_ID_ATI,
204 .device = PCI_DEVICE_ID_AMD_SR5650_HT,
205};