blob: 02f4f7ff198e9c705a39aaa6ff3a83b867219bb5 [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.
Timothy Pearsonc3fcdcc2015-09-05 17:46:38 -05005 * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering
Zheng Bao98fcc092011-03-27 16:39:58 +00006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010018 * Foundation, Inc.
Zheng Bao98fcc092011-03-27 16:39:58 +000019 */
20
21#include <console/console.h>
22#include <device/device.h>
23#include <device/pci.h>
24#include <device/pci_ids.h>
25#include <device/pci_ops.h>
26#include <arch/ioapic.h>
27#include "sr5650.h"
28
29/* Table 6-6 Recommended Interrupt Routing Configuration */
30typedef struct _apic_device_info {
31 u8 group;
32 u8 swizzle;
33 u8 pin;
34} apic_device_info;
35
36#define ABCD 0
37#define BCDA 1
38#define CDAB 2
39#define DABC 3
40
41static const apic_device_info default_apic_device_info_t [] = {
42 /* Group Swizzling Port Int Pin */
43 [0] = {0, 0, 31}, /* HT */
44 [1] = {0, 0, 31}, /* IOMMU */
45 [2] = {0, ABCD, 28}, /* Dev2 Grp0 [Int - 0..3] */
46 [3] = {1, ABCD, 28}, /* Dev3 Grp1 [Int - 4..7] */
47 [4] = {5, ABCD, 28}, /* Dev4 Grp5 [Int - 20..23] */
48 [5] = {5, CDAB, 28}, /* Dev5 Grp5 [Int - 20..23] */
49 [6] = {6, BCDA, 29}, /* Dev6 Grp6 [Int - 24..27] */
50 [7] = {6, CDAB, 29}, /* Dev7 Grp6 [Int - 24..27] */
51 [8] = {0, 0, 0 }, /* Reserved */
52 [9] = {6, ABCD, 29}, /* Dev9 Grp6 [Int - 24..27] */
53 [10] = {5, BCDA, 30}, /* Dev10 Grp5 [Int - 20..23] */
54 [11] = {2, ABCD, 30}, /* Dev11 Grp2 [Int - 8..11] */
55 [12] = {3, ABCD, 30}, /* Dev12 Grp3 [Int - 12..15] */
56 [13] = {4, ABCD, 30} /* Dev13 Grp4 [Int - 16..19] */
57};
58
Timothy Pearsonc3fcdcc2015-09-05 17:46:38 -050059/* These define names are common, so undefine them to avoid potential issues in other code */
Zheng Bao98fcc092011-03-27 16:39:58 +000060#undef ABCD
61#undef BCDA
62#undef CDAB
63#undef DABC
64
65/* Init APIC of sr5690 */
66static void sr5690_apic_init(struct device *dev)
67{
68 u32 dword;
69 const apic_device_info *entry = default_apic_device_info_t;
70
71 /* rpr6.2.(2). Write to the IOAPIC Features Enable register */
72 pci_write_config32(dev, 0xF8, 0x0);
73 pci_write_config32(dev, 0xFC, 0x1F);
74 /* rpr6.2.(3). Write to the remaining interrupt routing registers */
75
76 /* IOAPICCMISCIND:0x3, group & swizzle of Dev 2,3,4,5 */
77 dword = (entry[2].group | entry[2].swizzle << 4) << 0 |
78 (entry[3].group | entry[3].swizzle << 4) << 8 |
79 (entry[4].group | entry[4].swizzle << 4) << 16 |
80 (entry[5].group | entry[5].swizzle << 4) << 24;
81 pci_write_config32(dev, 0xF8, 0x3);
82 pci_write_config32(dev, 0xFC, dword);
83
84 /* IOAPICCMISCIND:0x4, group & swizzle of Dev 6,7,9,10 */
85 dword = (entry[6].group | entry[6].swizzle << 4) << 0 |
86 (entry[7].group | entry[7].swizzle << 4) << 8 |
87 (entry[9].group | entry[9].swizzle << 4) << 16 |
88 (entry[10].group | entry[10].swizzle << 4) << 24;
89 pci_write_config32(dev, 0xF8, 0x4);
90 pci_write_config32(dev, 0xFC, dword);
91
92 /* IOAPICCMISCIND:0x5, group & swizzle of Dev 11,12,13 */
93 dword = (entry[11].group | entry[11].swizzle << 4) << 0 |
94 (entry[12].group | entry[12].swizzle << 4) << 8 |
95 (entry[13].group | entry[13].swizzle << 4) << 16;
96 pci_write_config32(dev, 0xF8, 0x5);
97 pci_write_config32(dev, 0xFC, dword);
98
99 /* IOAPICCMISCIND:0x6, pin map of dev 2,3,4,5 */
100 dword = entry[2].pin |
101 entry[3].pin << 8 |
102 entry[4].pin << 16|
103 entry[5].pin << 24;
104 pci_write_config32(dev, 0xF8, 0x6);
105 pci_write_config32(dev, 0xFC, dword);
106
107 /* IOAPICCMISCIND:0x7, pin map of dev 6,7,8,9 */
108 dword = entry[6].pin |
109 entry[7].pin << 8 |
110 entry[8].pin << 16|
111 entry[9].pin << 24;
112 pci_write_config32(dev, 0xF8, 0x7);
113 pci_write_config32(dev, 0xFC, dword);
114
115 /* IOAPICCMISCIND:0x8, pin map of dev 10,11,12,13 */
116 dword = entry[10].pin |
117 entry[11].pin << 8 |
118 entry[12].pin << 16|
119 entry[13].pin << 24;
120 pci_write_config32(dev, 0xF8, 0x8);
121 pci_write_config32(dev, 0xFC, dword);
122
123 /* IOAPICCMISCIND:0x9, pin map of ht, iommu */
124 dword = entry[0].pin | entry[1].pin << 8;
125 pci_write_config32(dev, 0xF8, 0x9);
126 pci_write_config32(dev, 0xFC, dword);
127
128 pci_write_config32(dev, 0xF8, 0x1);
129 dword = pci_read_config32(dev, 0xFC) & 0xfffffff0;
130 /* TODO: On SR56x0/SP5100 board, the IOAPIC on SR56x0 is the
131 * 2nd one. We need to check if it also is on your board. */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800132 setup_ioapic((void *)dword, 1);
Zheng Bao98fcc092011-03-27 16:39:58 +0000133}
134
135static void pcie_init(struct device *dev)
136{
137 /* Enable pci error detecting */
138 u32 dword;
139
140 printk(BIOS_INFO, "pcie_init in sr5650_ht.c\n");
141
142 /* System error enable */
143 dword = pci_read_config32(dev, 0x04);
144 dword |= (1 << 8); /* System error enable */
145 dword |= (1 << 30); /* Clear possible errors */
146 pci_write_config32(dev, 0x04, dword);
147
148 /*
149 * 1 is APIC enable
150 * 18 is enable nb to accept A4 interrupt request from SB.
151 */
152 dword = pci_read_config32(dev, 0x4C);
153 dword |= 1 << 1 | 1 << 18; /* Clear possible errors */
154 pci_write_config32(dev, 0x4C, dword);
155
156 sr5690_apic_init(dev);
157}
158
159static void sr5690_read_resource(struct device *dev)
160{
161 pci_dev_read_resources(dev);
162
163 /* rpr6.2.(1). Write the Base Address Register (BAR) */
164 pci_write_config32(dev, 0xF8, 0x1); /* set IOAPIC's index as 1 and make sure no one changes it. */
165 pci_get_resource(dev, 0xFC); /* APIC located in sr5690 */
166
167 compact_resources(dev);
168}
169
170/* If IOAPIC's index changes, we should replace the pci_dev_set_resource(). */
171static void sr5690_set_resources(struct device *dev)
172{
173 pci_write_config32(dev, 0xF8, 0x1); /* set IOAPIC's index as 1 and make sure no one changes it. */
174 pci_dev_set_resources(dev);
175}
176
177static struct pci_operations lops_pci = {
178 .set_subsystem = pci_dev_set_subsystem,
179};
180
181static struct device_operations ht_ops = {
182 .read_resources = sr5690_read_resource,
183 .set_resources = sr5690_set_resources,
184 .enable_resources = pci_dev_enable_resources,
185 .init = pcie_init,
186 .scan_bus = 0,
187 .ops_pci = &lops_pci,
188};
189
190static const struct pci_driver ht_driver_sr5690 __pci_driver = {
191 .ops = &ht_ops,
192 .vendor = PCI_VENDOR_ID_ATI,
193 .device = PCI_DEVICE_ID_AMD_SR5690_HT,
194};
195
196static const struct pci_driver ht_driver_sr5670 __pci_driver = {
197 .ops = &ht_ops,
198 .vendor = PCI_VENDOR_ID_ATI,
199 .device = PCI_DEVICE_ID_AMD_SR5670_HT,
200};
201
202static const struct pci_driver ht_driver_sr5650 __pci_driver = {
203 .ops = &ht_ops,
204 .vendor = PCI_VENDOR_ID_ATI,
205 .device = PCI_DEVICE_ID_AMD_SR5650_HT,
206};