1 /*============================================================================
2 Copyright 2005 ADVANCED MICRO DEVICES, INC. All Rights Reserved.
3 This software and any related documentation (the "Materials") are the
4 confidential proprietary information of AMD. Unless otherwise provided in a
5 software agreement specifically licensing the Materials, the Materials are
6 provided in confidence and may not be distributed, modified, or reproduced in
7 whole or in part by any means.
8 LIMITATION OF LIABILITY: THE MATERIALS ARE PROVIDED "AS IS" WITHOUT ANY
9 EXPRESS OR IMPLIED WARRANTY OF ANY KIND, INCLUDING BUT NOT LIMITED TO
10 WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, TITLE, FITNESS FOR ANY
11 PARTICULAR PURPOSE, OR WARRANTIES ARISING FROM CONDUCT, COURSE OF DEALING, OR
12 USAGE OF TRADE. IN NO EVENT SHALL AMD OR ITS LICENSORS BE LIABLE FOR ANY
13 DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS,
14 BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OF OR
15 INABILITY TO USE THE MATERIALS, EVEN IF AMD HAS BEEN ADVISED OF THE
16 POSSIBILITY OF SUCH DAMAGES. BECAUSE SOME JURISDICTIONS PROHIBIT THE EXCLUSION
17 OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, THE ABOVE
18 LIMITATION MAY NOT APPLY TO YOU.
19 AMD does not assume any responsibility for any errors which may appear in the
20 Materials nor any responsibility to support or update the Materials. AMD
21 retains the right to modify the Materials at any time, without notice, and is
22 not obligated to provide such modified Materials to you.
23 NO SUPPORT OBLIGATION: AMD is not obligated to furnish, support, or make any
24 further information, software, technical information, know-how, or show-how
26 U.S. GOVERNMENT RESTRICTED RIGHTS: The Materials are provided with "RESTRICTED
27 RIGHTS." Use, duplication, or disclosure by the Government is subject to the
28 restrictions as set forth in FAR 52.227-14 and DFAR 252.227-7013, et seq., or
29 its successor. Use of the Materials by the Government constitutes
30 acknowledgement of AMD's proprietary rights in them.
31 ============================================================================*/
33 // in amd8132_bridge.c
37 // Description: amd 8132 support
40 //============================================================================
42 #include <console/console.h>
43 #include <device/device.h>
44 #include <device/pci.h>
45 #include <device/pci_ids.h>
46 #include <device/pci_ops.h>
47 #include <pc80/mc146818rtc.h>
48 #include <device/pci_def.h>
49 #include <device/pcix.h>
53 #define NPUML 0xD9 /* Non prefetchable upper memory limit */
54 #define NPUMB 0xD8 /* Non prefetchable upper memory base */
56 static void amd8132_walk_children(struct bus *bus,
57 void (*visit)(device_t dev, void *ptr), void *ptr)
60 for(child = bus->children; child; child = child->sibling)
62 if (child->path.type != DEVICE_PATH_PCI) {
65 if (child->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
66 amd8132_walk_children(&child->link[0], visit, ptr);
72 struct amd8132_bus_info {
79 static void amd8132_count_dev(device_t dev, void *ptr)
81 struct amd8132_bus_info *info = ptr;
82 /* Don't count pci bridges */
83 if (dev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
84 info->master_devices++;
86 if (PCI_FUNC(dev->path.pci.devfn) > info->max_func) {
87 info->max_func = PCI_FUNC(dev->path.pci.devfn);
92 static void amd8132_pcix_tune_dev(device_t dev, void *ptr)
94 struct amd8132_bus_info *info = ptr;
96 unsigned status, cmd, orig_cmd;
97 unsigned max_read, max_tran;
100 if (dev->hdr_type != PCI_HEADER_TYPE_NORMAL) {
103 cap = pci_find_capability(dev, PCI_CAP_ID_PCIX);
107 /* How many siblings does this device have? */
108 sibs = info->master_devices - 1;
110 printk(BIOS_DEBUG, "%s AMD8132 PCI-X tuning\n", dev_path(dev));
111 status = pci_read_config32(dev, cap + PCI_X_STATUS);
112 orig_cmd = cmd = pci_read_config16(dev,cap + PCI_X_CMD);
114 max_read = (status & PCI_X_STATUS_MAX_READ) >> 21;
115 max_tran = (status & PCI_X_STATUS_MAX_SPLIT) >> 23;
117 if (info->rev == 0x01) { // only a1 need it
118 /* Errata #53 Limit the number of split transactions to avoid starvation */
120 /* At most 2 outstanding split transactions when we have
121 * 3 or more bus master devices on the bus.
127 else if (sibs == 1) {
128 /* At most 4 outstanding split transactions when we have
129 * 2 bus master devices on the bus.
136 /* At most 8 outstanding split transactions when we have
137 * only one bus master device on the bus.
145 if (max_read != ((cmd & PCI_X_CMD_MAX_READ) >> 2)) {
146 cmd &= ~PCI_X_CMD_MAX_READ;
147 cmd |= max_read << 2;
149 if (max_tran != ((cmd & PCI_X_CMD_MAX_SPLIT) >> 4)) {
150 cmd &= ~PCI_X_CMD_MAX_SPLIT;
151 cmd |= max_tran << 4;
154 /* Don't attempt to handle PCI-X errors */
155 cmd &= ~PCI_X_CMD_DPERR_E;
156 if (orig_cmd != cmd) {
157 pci_write_config16(dev, cap + PCI_X_CMD, cmd);
162 static unsigned int amd8132_scan_bus(struct bus *bus,
163 unsigned min_devfn, unsigned max_devfn, unsigned int max)
165 struct amd8132_bus_info info;
169 /* Find the children on the bus */
170 max = pci_scan_bus(bus, min_devfn, max_devfn, max);
172 /* Find the revision of the 8132 */
173 info.rev = pci_read_config8(bus->dev, PCI_CLASS_REVISION);
175 /* Find the pcix capability and get the secondary bus status */
176 pos = pci_find_capability(bus->dev, PCI_CAP_ID_PCIX);
177 info.sstatus = pci_read_config16(bus->dev, pos + PCI_X_SEC_STATUS);
179 /* Print the PCI-X bus speed */
180 printk(BIOS_DEBUG, "PCI: %02x: %s sstatus=%04x rev=%02x \n", bus->secondary, pcix_speed(info.sstatus), info.sstatus, info.rev);
183 /* Examine the bus and find out how loaded it is */
185 info.master_devices = 0;
186 amd8132_walk_children(bus, amd8132_count_dev, &info);
189 /* Disable the bus if there are no devices on it
194 /* Disable all of my children */
195 disable_children(bus);
197 /* Remember the device is disabled */
198 bus->dev->enabled = 0;
200 /* Disable the PCI-X clocks */
201 pcix_misc = pci_read_config32(bus->dev, 0x40);
202 pcix_misc &= ~(0x1f << 16);
203 pci_write_config32(bus->dev, 0x40, pcix_misc);
209 /* If we are in conventional PCI mode nothing more is necessary.
211 if (PCI_X_SSTATUS_MFREQ(info.sstatus) == PCI_X_SSTATUS_CONVENTIONAL_PCI) {
215 /* Tune the devices on the bus */
216 amd8132_walk_children(bus, amd8132_pcix_tune_dev, &info);
221 static unsigned int amd8132_scan_bridge(device_t dev, unsigned int max)
223 return do_pci_scan_bridge(dev, max, amd8132_scan_bus);
227 static void amd8132_pcix_init(device_t dev)
233 /* Find the revision of the 8132 */
234 chip_rev = pci_read_config8(dev, PCI_CLASS_REVISION);
236 /* Enable memory write and invalidate ??? */
237 dword = pci_read_config32(dev, 0x04);
239 dword &= ~(1<<6); // PERSP Parity Error Response
240 pci_write_config32(dev, 0x04, dword);
242 if (chip_rev == 0x01) {
244 byte = pci_read_config8(dev, 0x0c);
246 pci_write_config8(dev, 0x0c, 0x10);
250 dword = pci_read_config32(dev, 0x40);
252 pci_write_config32(dev, 0x40, dword);
257 /* Set up error reporting, enable all */
258 /* system error enable */
259 dword = pci_read_config32(dev, 0x04);
261 pci_write_config32(dev, 0x04, dword);
263 /* system and error parity enable */
264 dword = pci_read_config32(dev, 0x3c);
266 pci_write_config32(dev, 0x3c, dword);
268 dword = pci_read_config32(dev, 0x40);
269 // dword &= ~(1<<31); /* WriteChainEnable */
271 dword |= (1<<7);// must set to 1
272 dword |= (3<<21); //PCIErrorSerrDisable
273 pci_write_config32(dev, 0x40, dword);
275 /* EXTARB = 1, COMPAT = 0 */
276 dword = pci_read_config32(dev, 0x48);
279 dword |= (1<<15); //CLEARPCILOG_L
280 dword |= (1<<19); //PERR FATAL Enable
281 dword |= (1<<22); // SERR FATAL Enable
282 dword |= (1<<23); // LPMARBENABLE
283 dword |= (0x61<<24); //LPMARBCOUNT
284 pci_write_config32(dev, 0x48, dword);
286 dword = pci_read_config32(dev, 0x4c);
287 dword |= (1<<6); //intial prefetch for memory read line request
288 dword |= (1<<9); //continuous prefetch Enable for memory read line request
289 pci_write_config32(dev, 0x4c, dword);
292 /* Disable Single-Bit-Error Correction [30] = 0 */
293 dword = pci_read_config32(dev, 0x70);
295 pci_write_config32(dev, 0x70, dword);
298 dword = pci_read_config32(dev, 0xd4);
300 pci_write_config32(dev, 0xd4, dword);
302 /* TxSlack0 [16:17] = 0, RxHwLookahdEn0 [18] = 1, TxSlack1 [24:25] = 0, RxHwLookahdEn1 [26] = 1 */
303 dword = pci_read_config32(dev, 0xdc);
304 dword |= (1<<1) | (1<<4); // stream disable 1 to 0 , DBLINSRATE
305 dword |= (1<<18)|(1<<26);
306 dword &= ~((3<<16)|(3<<24));
307 pci_write_config32(dev, 0xdc, dword);
309 /* Set up CRC flood enable */
310 dword = pci_read_config32(dev, 0xc0);
311 if(dword) { /* do device A only */
313 dword = pci_read_config32(dev, 0xc4);
315 pci_write_config32(dev, 0xc4, dword);
316 dword = pci_read_config32(dev, 0xc8);
318 pci_write_config32(dev, 0xc8, dword);
321 if (chip_rev == 0x11) {
322 /* [18] Clock Gate Enable = 1 */
323 dword = pci_read_config32(dev, 0xf0);
325 pci_write_config32(dev, 0xf0, dword);
332 #define BRIDGE_40_BIT_SUPPORT 0
333 #if BRIDGE_40_BIT_SUPPORT
334 static void bridge_read_resources(struct device *dev)
336 struct resource *res;
337 pci_bus_read_resources(dev);
338 res = find_resource(dev, PCI_MEMORY_BASE);
340 res->limit = 0xffffffffffULL;
344 static void bridge_set_resources(struct device *dev)
346 struct resource *res;
347 res = find_resource(dev, PCI_MEMORY_BASE);
349 resource_t base, end;
350 /* set the memory range */
351 dev->command |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
352 res->flags |= IORESOURCE_STORED;
354 end = resource_end(res);
355 pci_write_config16(dev, PCI_MEMORY_BASE, base >> 16);
356 pci_write_config8(dev, NPUML, (base >> 32) & 0xff);
357 pci_write_config16(dev, PCI_MEMORY_LIMIT, end >> 16);
358 pci_write_config8(dev, NPUMB, (end >> 32) & 0xff);
360 report_resource_stored(dev, res, "");
362 pci_dev_set_resources(dev);
364 #endif /* BRIDGE_40_BIT_SUPPORT */
366 static struct device_operations pcix_ops = {
367 #if BRIDGE_40_BIT_SUPPORT
368 .read_resources = bridge_read_resources,
369 .set_resources = bridge_set_resources,
371 .read_resources = pci_bus_read_resources,
372 .set_resources = pci_dev_set_resources,
374 .enable_resources = pci_bus_enable_resources,
375 .init = amd8132_pcix_init,
376 .scan_bus = amd8132_scan_bridge,
377 .reset_bus = pci_bus_reset,
380 static const struct pci_driver pcix_driver __pci_driver = {
382 .vendor = PCI_VENDOR_ID_AMD,
386 static void ioapic_enable(device_t dev)
390 value = pci_read_config32(dev, 0x44);
392 value |= ((1 << 1) | (1 << 0));
394 value &= ~((1 << 1) | (1 << 0));
396 pci_write_config32(dev, 0x44, value);
398 static void amd8132_ioapic_init(device_t dev)
403 /* Find the revision of the 8132 */
404 chip_rev = pci_read_config8(dev, PCI_CLASS_REVISION);
406 if (chip_rev == 0x01) {
409 dword = pci_read_config32(dev, 0xc8);
411 pci_write_config32(dev, 0xc8, dword);
417 if( (chip_rev == 0x11) ||(chip_rev == 0x12) ) {
420 dword = pci_read_config32(dev, 0x80);
422 pci_write_config32(dev, 0x80, dword);
423 dword = pci_read_config32(dev, 0x88);
425 pci_write_config32(dev, 0x88, dword);
428 dword = pci_read_config32(dev, 0x7c);
431 pci_write_config32(dev, 0x7c, dword);
436 static struct pci_operations pci_ops_pci_dev = {
437 .set_subsystem = pci_dev_set_subsystem,
439 static struct device_operations ioapic_ops = {
440 .read_resources = pci_dev_read_resources,
441 .set_resources = pci_dev_set_resources,
442 .enable_resources = pci_dev_enable_resources,
443 .init = amd8132_ioapic_init,
445 .enable = ioapic_enable,
446 .ops_pci = &pci_ops_pci_dev,
449 static const struct pci_driver ioapic_driver __pci_driver = {
451 .vendor = PCI_VENDOR_ID_AMD,