2 * Copyright 2003 PMC-Sierra
3 * Author: Manish Lachwani (lachwani@pmc-sierra.com)
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
11 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
13 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
14 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
15 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
16 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
17 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
18 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
19 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <linux/types.h>
27 #include <linux/pci.h>
28 #include <linux/kernel.h>
32 #include <linux/init.h>
33 #include <asm/titan_dep.h>
35 #ifdef CONFIG_HYPERTRANSPORT
39 * This function check if the Hypertransport Link Initialization completed. If
40 * it did, then proceed further with scanning bus #2
42 static __inline__
int check_titan_htlink(void)
46 val
= *(volatile uint32_t *)(RM9000x2_HTLINK_REG
);
48 /* HT Link Initialization completed */
54 static int titan_ht_config_read_dword(struct pci_dev
*device
,
58 uint32_t address_reg
, data_reg
;
61 bus
= device
->bus
->number
;
62 dev
= PCI_SLOT(device
->devfn
);
63 func
= PCI_FUNC(device
->devfn
);
66 address
= (bus
<< 16) | (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) |
69 address
= (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) | 0x80000000;
71 address_reg
= RM9000x2_OCD_HTCFGA
;
72 data_reg
= RM9000x2_OCD_HTCFGD
;
74 RM9K_WRITE(address_reg
, address
);
75 RM9K_READ(data_reg
, val
);
77 return PCIBIOS_SUCCESSFUL
;
81 static int titan_ht_config_read_word(struct pci_dev
*device
,
85 uint32_t address_reg
, data_reg
;
88 bus
= device
->bus
->number
;
89 dev
= PCI_SLOT(device
->devfn
);
90 func
= PCI_FUNC(device
->devfn
);
93 address
= (bus
<< 16) | (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) |
96 address
= (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) | 0x80000000;
98 address_reg
= RM9000x2_OCD_HTCFGA
;
99 data_reg
= RM9000x2_OCD_HTCFGD
;
101 if ((offset
& 0x3) == 0)
106 RM9K_WRITE(address_reg
, address
);
107 RM9K_READ_16(data_reg
+ offset
, val
);
109 return PCIBIOS_SUCCESSFUL
;
113 u32
longswap(unsigned long l
)
115 unsigned char b1
, b2
, b3
, b4
;
122 return ((b1
<<24) + (b2
<<16) + (b3
<<8) + b4
);
126 static int titan_ht_config_read_byte(struct pci_dev
*device
,
130 uint32_t address_reg
, data_reg
;
134 bus
= device
->bus
->number
;
135 dev
= PCI_SLOT(device
->devfn
);
136 func
= PCI_FUNC(device
->devfn
);
139 address
= (bus
<< 16) | (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) |
142 address
= (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) | 0x80000000;
144 address_reg
= RM9000x2_OCD_HTCFGA
;
145 data_reg
= RM9000x2_OCD_HTCFGD
;
147 RM9K_WRITE(address_reg
, address
);
149 if ((offset
& 0x3) == 0) {
152 if ((offset
& 0x3) == 1) {
155 if ((offset
& 0x3) == 2) {
158 if ((offset
& 0x3) == 3) {
161 RM9K_READ_8(data_reg
+ offset1
, val
);
163 return PCIBIOS_SUCCESSFUL
;
167 static int titan_ht_config_write_dword(struct pci_dev
*device
,
171 uint32_t address_reg
, data_reg
;
174 bus
= device
->bus
->number
;
175 dev
= PCI_SLOT(device
->devfn
);
176 func
= PCI_FUNC(device
->devfn
);
179 address
= (bus
<< 16) | (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) |
182 address
= (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) | 0x80000000;
184 address_reg
= RM9000x2_OCD_HTCFGA
;
185 data_reg
= RM9000x2_OCD_HTCFGD
;
187 RM9K_WRITE(address_reg
, address
);
188 RM9K_WRITE(data_reg
, val
);
190 return PCIBIOS_SUCCESSFUL
;
193 static int titan_ht_config_write_word(struct pci_dev
*device
,
197 uint32_t address_reg
, data_reg
;
200 bus
= device
->bus
->number
;
201 dev
= PCI_SLOT(device
->devfn
);
202 func
= PCI_FUNC(device
->devfn
);
205 address
= (bus
<< 16) | (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) |
208 address
= (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) | 0x80000000;
210 address_reg
= RM9000x2_OCD_HTCFGA
;
211 data_reg
= RM9000x2_OCD_HTCFGD
;
213 if ((offset
& 0x3) == 0)
218 RM9K_WRITE(address_reg
, address
);
219 RM9K_WRITE_16(data_reg
+ offset
, val
);
221 return PCIBIOS_SUCCESSFUL
;
224 static int titan_ht_config_write_byte(struct pci_dev
*device
,
228 uint32_t address_reg
, data_reg
;
232 bus
= device
->bus
->number
;
233 dev
= PCI_SLOT(device
->devfn
);
234 func
= PCI_FUNC(device
->devfn
);
237 address
= (bus
<< 16) | (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) |
240 address
= (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) | 0x80000000;
242 address_reg
= RM9000x2_OCD_HTCFGA
;
243 data_reg
= RM9000x2_OCD_HTCFGD
;
245 RM9K_WRITE(address_reg
, address
);
247 if ((offset
& 0x3) == 0) {
250 if ((offset
& 0x3) == 1) {
253 if ((offset
& 0x3) == 2) {
256 if ((offset
& 0x3) == 3) {
260 RM9K_WRITE_8(data_reg
+ offset1
, val
);
261 return PCIBIOS_SUCCESSFUL
;
265 static void titan_pcibios_set_master(struct pci_dev
*dev
)
268 int bus
= dev
->bus
->number
;
270 if (check_titan_htlink())
271 titan_ht_config_read_word(dev
, PCI_COMMAND
, &cmd
);
273 cmd
|= PCI_COMMAND_MASTER
;
275 if (check_titan_htlink())
276 titan_ht_config_write_word(dev
, PCI_COMMAND
, cmd
);
280 int pcibios_enable_resources(struct pci_dev
*dev
)
286 int bus
= dev
->bus
->number
;
288 if (check_titan_htlink())
289 titan_ht_config_read_word(dev
, PCI_COMMAND
, &cmd
);
292 for (idx
= 0; idx
< 6; idx
++) {
293 r
= &dev
->resource
[idx
];
294 if (!r
->start
&& r
->end
) {
296 "PCI: Device %s not available because of "
297 "resource collisions\n", pci_name(dev
));
300 if (r
->flags
& IORESOURCE_IO
)
301 cmd
|= PCI_COMMAND_IO
;
302 if (r
->flags
& IORESOURCE_MEM
)
303 cmd
|= PCI_COMMAND_MEMORY
;
305 if (cmd
!= old_cmd
) {
306 if (check_titan_htlink())
307 titan_ht_config_write_word(dev
, PCI_COMMAND
, cmd
);
310 if (check_titan_htlink())
311 titan_ht_config_read_byte(dev
, PCI_CACHE_LINE_SIZE
, &tmp1
);
314 printk(KERN_WARNING
"PCI setting cache line size to 8 from "
318 if (check_titan_htlink())
319 titan_ht_config_write_byte(dev
, PCI_CACHE_LINE_SIZE
, 8);
321 if (check_titan_htlink())
322 titan_ht_config_read_byte(dev
, PCI_LATENCY_TIMER
, &tmp1
);
324 if (tmp1
< 32 || tmp1
== 0xff) {
325 printk(KERN_WARNING
"PCI setting latency timer to 32 from %d\n",
329 if (check_titan_htlink())
330 titan_ht_config_write_byte(dev
, PCI_LATENCY_TIMER
, 32);
336 int pcibios_enable_device(struct pci_dev
*dev
, int mask
)
338 return pcibios_enable_resources(dev
);
341 resource_size_t
pcibios_align_resource(void *data
, const struct resource
*res
,
342 resource_size_t size
, resource_size_t align
)
344 struct pci_dev
*dev
= data
;
345 resource_size_t start
= res
->start
;
347 if (res
->flags
& IORESOURCE_IO
) {
348 /* We need to avoid collisions with `mirrored' VGA ports
349 and other strange ISA hardware, so we always want the
350 addresses kilobyte aligned. */
352 printk(KERN_ERR
"PCI: I/O Region %s/%d too large"
353 " (%ld bytes)\n", pci_name(dev
),
354 dev
->resource
- res
, size
);
357 start
= (start
+ 1024 - 1) & ~(1024 - 1);
363 struct pci_ops titan_pci_ops
= {
364 titan_ht_config_read_byte
,
365 titan_ht_config_read_word
,
366 titan_ht_config_read_dword
,
367 titan_ht_config_write_byte
,
368 titan_ht_config_write_word
,
369 titan_ht_config_write_dword
372 void __init
pcibios_fixup_bus(struct pci_bus
*c
)
374 titan_ht_pcibios_fixup_bus(c
);
377 void __init
pcibios_init(void)
380 /* Reset PCI I/O and PCI MEM values */
381 ioport_resource
.start
= 0xe0000000;
382 ioport_resource
.end
= 0xe0000000 + 0x20000000 - 1;
383 iomem_resource
.start
= 0xc0000000;
384 iomem_resource
.end
= 0xc0000000 + 0x20000000 - 1;
386 pci_scan_bus(2, &titan_pci_ops
, NULL
);
387 pci_scan_bus(3, &titan_pci_ops
, NULL
);
391 * for parsing "pci=" kernel boot arguments.
393 char *pcibios_setup(char *str
)
395 printk(KERN_INFO
"rr: pcibios_setup\n");
396 /* Nothing to do for now. */
401 unsigned __init
int pcibios_assign_all_busses(void)
403 /* We want to use the PCI bus detection done by PMON */
407 #endif /* CONFIG_HYPERTRANSPORT */