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
);
65 /* XXX Need to change the Bus # */
67 address
= (bus
<< 16) | (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) |
70 address
= (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) | 0x80000000;
72 address_reg
= RM9000x2_OCD_HTCFGA
;
73 data_reg
= RM9000x2_OCD_HTCFGD
;
75 RM9K_WRITE(address_reg
, address
);
76 RM9K_READ(data_reg
, val
);
78 return PCIBIOS_SUCCESSFUL
;
82 static int titan_ht_config_read_word(struct pci_dev
*device
,
86 uint32_t address_reg
, data_reg
;
89 bus
= device
->bus
->number
;
90 dev
= PCI_SLOT(device
->devfn
);
91 func
= PCI_FUNC(device
->devfn
);
93 /* XXX Need to change the Bus # */
95 address
= (bus
<< 16) | (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) |
98 address
= (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) | 0x80000000;
100 address_reg
= RM9000x2_OCD_HTCFGA
;
101 data_reg
= RM9000x2_OCD_HTCFGD
;
103 if ((offset
& 0x3) == 0)
108 RM9K_WRITE(address_reg
, address
);
109 RM9K_READ_16(data_reg
+ offset
, val
);
111 return PCIBIOS_SUCCESSFUL
;
115 u32
longswap(unsigned long l
)
117 unsigned char b1
, b2
, b3
, b4
;
124 return ((b1
<<24) + (b2
<<16) + (b3
<<8) + b4
);
128 static int titan_ht_config_read_byte(struct pci_dev
*device
,
132 uint32_t address_reg
, data_reg
;
136 bus
= device
->bus
->number
;
137 dev
= PCI_SLOT(device
->devfn
);
138 func
= PCI_FUNC(device
->devfn
);
140 /* XXX Need to change the Bus # */
142 address
= (bus
<< 16) | (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) |
145 address
= (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) | 0x80000000;
147 address_reg
= RM9000x2_OCD_HTCFGA
;
148 data_reg
= RM9000x2_OCD_HTCFGD
;
150 RM9K_WRITE(address_reg
, address
);
152 if ((offset
& 0x3) == 0) {
155 if ((offset
& 0x3) == 1) {
158 if ((offset
& 0x3) == 2) {
161 if ((offset
& 0x3) == 3) {
164 RM9K_READ_8(data_reg
+ offset1
, val
);
166 return PCIBIOS_SUCCESSFUL
;
170 static int titan_ht_config_write_dword(struct pci_dev
*device
,
174 uint32_t address_reg
, data_reg
;
177 bus
= device
->bus
->number
;
178 dev
= PCI_SLOT(device
->devfn
);
179 func
= PCI_FUNC(device
->devfn
);
181 /* XXX Need to change the Bus # */
183 address
= (bus
<< 16) | (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) |
186 address
= (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) | 0x80000000;
188 address_reg
= RM9000x2_OCD_HTCFGA
;
189 data_reg
= RM9000x2_OCD_HTCFGD
;
191 RM9K_WRITE(address_reg
, address
);
192 RM9K_WRITE(data_reg
, val
);
194 return PCIBIOS_SUCCESSFUL
;
197 static int titan_ht_config_write_word(struct pci_dev
*device
,
201 uint32_t address_reg
, data_reg
;
204 bus
= device
->bus
->number
;
205 dev
= PCI_SLOT(device
->devfn
);
206 func
= PCI_FUNC(device
->devfn
);
208 /* XXX Need to change the Bus # */
210 address
= (bus
<< 16) | (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) |
213 address
= (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) | 0x80000000;
215 address_reg
= RM9000x2_OCD_HTCFGA
;
216 data_reg
= RM9000x2_OCD_HTCFGD
;
218 if ((offset
& 0x3) == 0)
223 RM9K_WRITE(address_reg
, address
);
224 RM9K_WRITE_16(data_reg
+ offset
, val
);
226 return PCIBIOS_SUCCESSFUL
;
229 static int titan_ht_config_write_byte(struct pci_dev
*device
,
233 uint32_t address_reg
, data_reg
;
237 bus
= device
->bus
->number
;
238 dev
= PCI_SLOT(device
->devfn
);
239 func
= PCI_FUNC(device
->devfn
);
241 /* XXX Need to change the Bus # */
243 address
= (bus
<< 16) | (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) |
246 address
= (dev
<< 11) | (func
<< 8) | (offset
& 0xfc) | 0x80000000;
248 address_reg
= RM9000x2_OCD_HTCFGA
;
249 data_reg
= RM9000x2_OCD_HTCFGD
;
251 RM9K_WRITE(address_reg
, address
);
253 if ((offset
& 0x3) == 0) {
256 if ((offset
& 0x3) == 1) {
259 if ((offset
& 0x3) == 2) {
262 if ((offset
& 0x3) == 3) {
266 RM9K_WRITE_8(data_reg
+ offset1
, val
);
267 return PCIBIOS_SUCCESSFUL
;
271 static void titan_pcibios_set_master(struct pci_dev
*dev
)
274 int bus
= dev
->bus
->number
;
276 if (check_titan_htlink())
277 titan_ht_config_read_word(dev
, PCI_COMMAND
, &cmd
);
279 cmd
|= PCI_COMMAND_MASTER
;
281 if (check_titan_htlink())
282 titan_ht_config_write_word(dev
, PCI_COMMAND
, cmd
);
286 int pcibios_enable_resources(struct pci_dev
*dev
)
292 int bus
= dev
->bus
->number
;
294 if (check_titan_htlink())
295 titan_ht_config_read_word(dev
, PCI_COMMAND
, &cmd
);
298 for (idx
= 0; idx
< 6; idx
++) {
299 r
= &dev
->resource
[idx
];
300 if (!r
->start
&& r
->end
) {
302 "PCI: Device %s not available because of "
303 "resource collisions\n", pci_name(dev
));
306 if (r
->flags
& IORESOURCE_IO
)
307 cmd
|= PCI_COMMAND_IO
;
308 if (r
->flags
& IORESOURCE_MEM
)
309 cmd
|= PCI_COMMAND_MEMORY
;
311 if (cmd
!= old_cmd
) {
312 if (check_titan_htlink())
313 titan_ht_config_write_word(dev
, PCI_COMMAND
, cmd
);
316 if (check_titan_htlink())
317 titan_ht_config_read_byte(dev
, PCI_CACHE_LINE_SIZE
, &tmp1
);
320 printk(KERN_WARNING
"PCI setting cache line size to 8 from "
324 if (check_titan_htlink())
325 titan_ht_config_write_byte(dev
, PCI_CACHE_LINE_SIZE
, 8);
327 if (check_titan_htlink())
328 titan_ht_config_read_byte(dev
, PCI_LATENCY_TIMER
, &tmp1
);
330 if (tmp1
< 32 || tmp1
== 0xff) {
331 printk(KERN_WARNING
"PCI setting latency timer to 32 from %d\n",
335 if (check_titan_htlink())
336 titan_ht_config_write_byte(dev
, PCI_LATENCY_TIMER
, 32);
342 int pcibios_enable_device(struct pci_dev
*dev
, int mask
)
344 return pcibios_enable_resources(dev
);
347 resource_size_t
pcibios_align_resource(void *data
, const struct resource
*res
,
348 resource_size_t size
, resource_size_t align
)
350 struct pci_dev
*dev
= data
;
351 resource_size_t start
= res
->start
;
353 if (res
->flags
& IORESOURCE_IO
) {
354 /* We need to avoid collisions with `mirrored' VGA ports
355 and other strange ISA hardware, so we always want the
356 addresses kilobyte aligned. */
358 printk(KERN_ERR
"PCI: I/O Region %s/%d too large"
359 " (%ld bytes)\n", pci_name(dev
),
360 dev
->resource
- res
, size
);
363 start
= (start
+ 1024 - 1) & ~(1024 - 1);
369 struct pci_ops titan_pci_ops
= {
370 titan_ht_config_read_byte
,
371 titan_ht_config_read_word
,
372 titan_ht_config_read_dword
,
373 titan_ht_config_write_byte
,
374 titan_ht_config_write_word
,
375 titan_ht_config_write_dword
378 void __init
pcibios_fixup_bus(struct pci_bus
*c
)
380 titan_ht_pcibios_fixup_bus(c
);
383 void __init
pcibios_init(void)
386 /* Reset PCI I/O and PCI MEM values */
387 /* XXX Need to add the proper values here */
388 ioport_resource
.start
= 0xe0000000;
389 ioport_resource
.end
= 0xe0000000 + 0x20000000 - 1;
390 iomem_resource
.start
= 0xc0000000;
391 iomem_resource
.end
= 0xc0000000 + 0x20000000 - 1;
393 /* XXX Need to add bus values */
394 pci_scan_bus(2, &titan_pci_ops
, NULL
);
395 pci_scan_bus(3, &titan_pci_ops
, NULL
);
399 * for parsing "pci=" kernel boot arguments.
401 char *pcibios_setup(char *str
)
403 printk(KERN_INFO
"rr: pcibios_setup\n");
404 /* Nothing to do for now. */
409 unsigned __init
int pcibios_assign_all_busses(void)
411 /* We want to use the PCI bus detection done by PMON */
415 #endif /* CONFIG_HYPERTRANSPORT */