blob: c413ec158ff5a6587e7c611659f817dc33d9c7e4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Copyright (C) 2001 Dave Engebretsen, IBM Corporation
3 * Copyright (C) 2003 Anton Blanchard <anton@au.ibm.com>, IBM
4 *
5 * pSeries specific routines for PCI.
6 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * 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; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
Arnd Bergmannc5a3c2e2005-06-23 09:43:23 +100022#include <linux/init.h>
23#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/pci.h>
26#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Olaf Heringc3b9d9a2007-03-22 23:14:07 +010028#include <asm/eeh.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <asm/pci-bridge.h>
Arnd Bergmannc5a3c2e2005-06-23 09:43:23 +100030#include <asm/prom.h>
Stephen Rothwelld3878992005-09-28 02:50:25 +100031#include <asm/ppc-pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#if 0
34void pcibios_name_device(struct pci_dev *dev)
35{
36 struct device_node *dn;
37
38 /*
39 * Add IBM loc code (slot) as a prefix to the device names for service
40 */
41 dn = pci_device_to_OF_node(dev);
42 if (dn) {
Tushar Behera724c6abf2012-11-19 18:31:52 +000043 const char *loc_code = of_get_property(dn, "ibm,loc-code",
44 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 if (loc_code) {
46 int loc_len = strlen(loc_code);
47 if (loc_len < sizeof(dev->dev.name)) {
48 memmove(dev->dev.name+loc_len+1, dev->dev.name,
49 sizeof(dev->dev.name)-loc_len-1);
50 memcpy(dev->dev.name, loc_code, loc_len);
51 dev->dev.name[loc_len] = ' ';
52 dev->dev.name[sizeof(dev->dev.name)-1] = '\0';
53 }
54 }
55 }
56}
57DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pcibios_name_device);
58#endif
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060static void __init pSeries_request_regions(void)
61{
62 if (!isa_io_base)
63 return;
64
65 request_region(0x20,0x20,"pic1");
66 request_region(0xa0,0x20,"pic2");
67 request_region(0x00,0x20,"dma1");
68 request_region(0x40,0x20,"timer");
69 request_region(0x80,0x10,"dma page reg");
70 request_region(0xc0,0x20,"dma2");
71}
72
73void __init pSeries_final_fixup(void)
74{
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 pSeries_request_regions();
76
Gavin Shan3ab96a02012-09-07 22:44:23 +000077 eeh_addr_cache_build();
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
79
80/*
81 * Assume the winbond 82c105 is the IDE controller on a
Olaf Hering0bcace32007-01-04 18:31:55 +010082 * p610/p615/p630. We should probably be more careful in case
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 * someone tries to plug in a similar adapter.
84 */
85static void fixup_winbond_82c105(struct pci_dev* dev)
86{
87 int i;
88 unsigned int reg;
89
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +110090 if (!machine_is(pseries))
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 return;
92
93 printk("Using INTC for W82c105 IDE controller.\n");
94 pci_read_config_dword(dev, 0x40, &reg);
95 /* Enable LEGIRQ to use INTC instead of ISA interrupts */
96 pci_write_config_dword(dev, 0x40, reg | (1<<11));
97
98 for (i = 0; i < DEVICE_COUNT_RESOURCE; ++i) {
99 /* zap the 2nd function of the winbond chip */
100 if (dev->resource[i].flags & IORESOURCE_IO
101 && dev->bus->number == 0 && dev->devfn == 0x81)
102 dev->resource[i].flags &= ~IORESOURCE_IO;
Olaf Hering2d99c412007-02-10 21:38:37 +0100103 if (dev->resource[i].start == 0 && dev->resource[i].end) {
104 dev->resource[i].flags = 0;
105 dev->resource[i].end = 0;
106 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 }
108}
109DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_WINBOND, PCI_DEVICE_ID_WINBOND_82C105,
110 fixup_winbond_82c105);
Kleber Sacilotto de Souzad82fb312013-05-03 12:43:12 +0000111
112int pseries_root_bridge_prepare(struct pci_host_bridge *bridge)
113{
114 struct device_node *dn, *pdn;
115 struct pci_bus *bus;
Kleber Sacilotto de Souzab020cc62014-01-17 11:56:51 -0200116 u32 pcie_link_speed_stats[2];
117 int rc;
Kleber Sacilotto de Souzad82fb312013-05-03 12:43:12 +0000118
119 bus = bridge->bus;
120
121 dn = pcibios_get_phb_of_node(bus);
122 if (!dn)
123 return 0;
124
125 for (pdn = dn; pdn != NULL; pdn = of_get_next_parent(pdn)) {
Kleber Sacilotto de Souzab020cc62014-01-17 11:56:51 -0200126 rc = of_property_read_u32_array(pdn,
127 "ibm,pcie-link-speed-stats",
128 &pcie_link_speed_stats[0], 2);
129 if (!rc)
Kleber Sacilotto de Souzad82fb312013-05-03 12:43:12 +0000130 break;
131 }
132
133 of_node_put(pdn);
134
Kleber Sacilotto de Souzab020cc62014-01-17 11:56:51 -0200135 if (rc) {
Kleber Sacilotto de Souzad82fb312013-05-03 12:43:12 +0000136 pr_err("no ibm,pcie-link-speed-stats property\n");
137 return 0;
138 }
139
Kleber Sacilotto de Souzab020cc62014-01-17 11:56:51 -0200140 switch (pcie_link_speed_stats[0]) {
Kleber Sacilotto de Souzad82fb312013-05-03 12:43:12 +0000141 case 0x01:
142 bus->max_bus_speed = PCIE_SPEED_2_5GT;
143 break;
144 case 0x02:
145 bus->max_bus_speed = PCIE_SPEED_5_0GT;
146 break;
Kleber Sacilotto de Souza49d96842014-01-17 11:56:52 -0200147 case 0x04:
148 bus->max_bus_speed = PCIE_SPEED_8_0GT;
149 break;
Kleber Sacilotto de Souzad82fb312013-05-03 12:43:12 +0000150 default:
151 bus->max_bus_speed = PCI_SPEED_UNKNOWN;
152 break;
153 }
154
Kleber Sacilotto de Souzab020cc62014-01-17 11:56:51 -0200155 switch (pcie_link_speed_stats[1]) {
Kleber Sacilotto de Souzad82fb312013-05-03 12:43:12 +0000156 case 0x01:
157 bus->cur_bus_speed = PCIE_SPEED_2_5GT;
158 break;
159 case 0x02:
160 bus->cur_bus_speed = PCIE_SPEED_5_0GT;
161 break;
Kleber Sacilotto de Souza49d96842014-01-17 11:56:52 -0200162 case 0x04:
163 bus->cur_bus_speed = PCIE_SPEED_8_0GT;
164 break;
Kleber Sacilotto de Souzad82fb312013-05-03 12:43:12 +0000165 default:
166 bus->cur_bus_speed = PCI_SPEED_UNKNOWN;
167 break;
168 }
169
170 return 0;
171}