b9e993cbb41212691aa027f58b40d13f38379204
[coreboot.git] / src / southbridge / amd / sb600 / pci.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008 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 "sb600.h"
26
27 static void pci_init(struct device *dev)
28 {
29         u32 dword;
30         u16 word;
31         u8 byte;
32
33         /* RPR 4.1 Enables the PCI-bridge subtractive decode */
34         /* This setting is strongly recommended since it supports some legacy PCI add-on cards,such as BIOS debug cards */
35         byte = pci_read_config8(dev, 0x4B);
36         byte |= 1 << 7;
37         pci_write_config8(dev, 0x4B, byte);
38         byte = pci_read_config8(dev, 0x40);
39         byte |= 1 << 5;
40         pci_write_config8(dev, 0x40, byte);
41
42         /* RPR4.2 PCI-bridge upstream dual address window */
43         /* this setting is applicable if the system memory is more than 4GB,and the PCI device can support dual address access */
44         byte = pci_read_config8(dev, 0x50);
45         byte |= 1 << 0;
46         pci_write_config8(dev, 0x50, byte);
47
48         /* RPR 4.3 PCI bus 64-byte DMA read access */
49         /* Enhance the PCI bus DMA performance */
50         byte = pci_read_config8(dev, 0x4B);
51         byte |= 1 << 4;
52         pci_write_config8(dev, 0x4B, byte);
53
54         /* RPR 4.4 Enables the PCIB writes to be cacheline aligned. */
55         /* The size of the writes will be set in the Cacheline Register */
56         byte = pci_read_config8(dev, 0x40);
57         byte |= 1 << 1;
58         pci_write_config8(dev, 0x40, byte);
59
60         /* RPR 4.5 Enables the PCIB to retain ownership of the bus on the Primary side and on the Secondary side when GNT# is deasserted */
61         pci_write_config8(dev, 0x0D, 0x40);
62         pci_write_config8(dev, 0x1B, 0x40);
63
64         /* RPR 4.6 Enable the command matching checking function on "Memory Read" & "Memory Read Line" commands */
65         byte = pci_read_config8(dev, 0x4B);
66         byte |= 1 << 6;
67         pci_write_config8(dev, 0x4B, byte);
68
69         /* RPR 4.7 When enabled, the PCI arbiter checks for the Bus Idle before asserting GNT# */
70         byte = pci_read_config8(dev, 0x4B);
71         byte |= 1 << 0;
72         pci_write_config8(dev, 0x4B, byte);
73
74         /* RPR 4.8 Adjusts the GNT# de-assertion time */
75         word = pci_read_config16(dev, 0x64);
76         word |= 1 << 12;
77         pci_write_config16(dev, 0x64, word);
78
79         /* RPR 4.9 Fast Back to Back transactions support */
80         byte = pci_read_config8(dev, 0x48);
81         byte |= 1 << 2;
82         pci_write_config8(dev, 0x48, byte);
83
84         /* RPR 4.10 Enable Lock Operation */
85         byte = pci_read_config8(dev, 0x48);
86         byte |= 1 << 3;
87         pci_write_config8(dev, 0x48, byte);
88         byte = pci_read_config8(dev, 0x40);
89         byte |= (1 << 2);
90         pci_write_config8(dev, 0x40, byte);
91
92         /* RPR 4.11 Enable additional optional PCI clock */
93         word = pci_read_config16(dev, 0x64);
94         word |= 1 << 8;
95         pci_write_config16(dev, 0x64, word);
96
97         /* rpr4.12 Disable Fewer-Retry Mode for A11-A13 only. 0x64[5:4] clear */
98         byte = pci_read_config8(dev, 0x64);
99         byte &= 0xcf;
100         pci_write_config8(dev, 0x64, byte);
101
102         /* rpr4.14 Disabling Downstream Flush, for A12 only, 0x64[18]. */
103         dword = pci_read_config32(dev, 0x64);
104         dword |= (1 << 18);
105         pci_write_config32(dev, 0x64, dword);
106
107         /* RPR 4.13 Enable One-Prefetch-Channel Mode */
108         dword = pci_read_config32(dev, 0x64);
109         dword |= 1 << 20;
110         pci_write_config32(dev, 0x64, dword);
111
112         /* RPR 4.15 Disable PCIB MSI Capability */
113         byte = pci_read_config8(dev, 0x40);
114         byte &= ~(1 << 3);
115         pci_write_config8(dev, 0x40, byte);
116
117         /* rpr4.16 Adjusting CLKRUN# */
118         dword = pci_read_config32(dev, 0x64);
119         dword |= (1 << 15);
120         pci_write_config32(dev, 0x64, dword);
121 }
122
123 struct device_operations amd8111_pci = {
124         .id = {.type = DEVICE_ID_PCI,
125                 {.pci = {.vendor = PCI_VENDOR_ID_ATI,
126                               .device = PCI_DEVICE_ID_ATI_SB600_PCI}}},
127         .constructor             = default_device_constructor,
128         .phase3_scan             = pci_scan_bridge,
129         .phase4_enable_disable           = amd8111_enable,
130         .phase4_read_resources   = pci_bus_read_resources,
131         .phase4_set_resources    = pci_dev_set_resources,
132         .phase5_enable_resources = pci_bus_enable_resources,
133         .phase6_init             = pci_init,
134         .reset_bus = pci_bus_reset,
135 };