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/config.h>
27 #include <linux/types.h>
28 #include <linux/pci.h>
29 #include <linux/kernel.h>
30 #include <linux/slab.h>
31 #include <linux/version.h>
35 #include <linux/init.h>
36 #include <asm/titan_dep.h>
38 #ifdef CONFIG_HYPERTRANSPORT
42 * This function check if the Hypertransport Link Initialization completed. If
43 * it did, then proceed further with scanning bus #2
45 static __inline__ int check_titan_htlink(void)
49 val = *(volatile uint32_t *)(RM9000x2_HTLINK_REG);
51 /* HT Link Initialization completed */
57 static int titan_ht_config_read_dword(struct pci_dev *device,
61 uint32_t address_reg, data_reg;
64 bus = device->bus->number;
65 dev = PCI_SLOT(device->devfn);
66 func = PCI_FUNC(device->devfn);
68 /* XXX Need to change the Bus # */
70 address = (bus << 16) | (dev << 11) | (func << 8) | (offset & 0xfc) |
73 address = (dev << 11) | (func << 8) | (offset & 0xfc) | 0x80000000;
75 address_reg = RM9000x2_OCD_HTCFGA;
76 data_reg = RM9000x2_OCD_HTCFGD;
78 RM9K_WRITE(address_reg, address);
79 RM9K_READ(data_reg, val);
81 return PCIBIOS_SUCCESSFUL;
85 static int titan_ht_config_read_word(struct pci_dev *device,
89 uint32_t address_reg, data_reg;
92 bus = device->bus->number;
93 dev = PCI_SLOT(device->devfn);
94 func = PCI_FUNC(device->devfn);
96 /* XXX Need to change the Bus # */
98 address = (bus << 16) | (dev << 11) | (func << 8) | (offset & 0xfc) |
101 address = (dev << 11) | (func << 8) | (offset & 0xfc) | 0x80000000;
103 address_reg = RM9000x2_OCD_HTCFGA;
104 data_reg = RM9000x2_OCD_HTCFGD;
106 if ((offset & 0x3) == 0)
111 RM9K_WRITE(address_reg, address);
112 RM9K_READ_16(data_reg + offset, val);
114 return PCIBIOS_SUCCESSFUL;
118 u32 longswap(unsigned long l)
120 unsigned char b1,b2,b3,b4;
127 return ((b1<<24) + (b2<<16) + (b3<<8) + b4);
131 static int titan_ht_config_read_byte(struct pci_dev *device,
135 uint32_t address_reg, data_reg;
139 bus = device->bus->number;
140 dev = PCI_SLOT(device->devfn);
141 func = PCI_FUNC(device->devfn);
143 /* XXX Need to change the Bus # */
145 address = (bus << 16) | (dev << 11) | (func << 8) | (offset & 0xfc) |
148 address = (dev << 11) | (func << 8) | (offset & 0xfc) | 0x80000000;
150 address_reg = RM9000x2_OCD_HTCFGA;
151 data_reg = RM9000x2_OCD_HTCFGD;
153 RM9K_WRITE(address_reg, address);
155 if ((offset & 0x3) == 0) {
158 if ((offset & 0x3) == 1) {
161 if ((offset & 0x3) == 2) {
164 if ((offset & 0x3) == 3) {
167 RM9K_READ_8(data_reg + offset1, val);
169 return PCIBIOS_SUCCESSFUL;
173 static int titan_ht_config_write_dword(struct pci_dev *device,
177 uint32_t address_reg, data_reg;
180 bus = device->bus->number;
181 dev = PCI_SLOT(device->devfn);
182 func = PCI_FUNC(device->devfn);
184 /* XXX Need to change the Bus # */
186 address = (bus << 16) | (dev << 11) | (func << 8) | (offset & 0xfc) |
189 address = (dev << 11) | (func << 8) | (offset & 0xfc) | 0x80000000;
191 address_reg = RM9000x2_OCD_HTCFGA;
192 data_reg = RM9000x2_OCD_HTCFGD;
194 RM9K_WRITE(address_reg, address);
195 RM9K_WRITE(data_reg, val);
197 return PCIBIOS_SUCCESSFUL;
200 static int titan_ht_config_write_word(struct pci_dev *device,
204 uint32_t address_reg, data_reg;
207 bus = device->bus->number;
208 dev = PCI_SLOT(device->devfn);
209 func = PCI_FUNC(device->devfn);
211 /* XXX Need to change the Bus # */
213 address = (bus << 16) | (dev << 11) | (func << 8) | (offset & 0xfc) |
216 address = (dev << 11) | (func << 8) | (offset & 0xfc) | 0x80000000;
218 address_reg = RM9000x2_OCD_HTCFGA;
219 data_reg = RM9000x2_OCD_HTCFGD;
221 if ((offset & 0x3) == 0)
226 RM9K_WRITE(address_reg, address);
227 RM9K_WRITE_16(data_reg + offset, val);
229 return PCIBIOS_SUCCESSFUL;
232 static int titan_ht_config_write_byte(struct pci_dev *device,
236 uint32_t address_reg, data_reg;
240 bus = device->bus->number;
241 dev = PCI_SLOT(device->devfn);
242 func = PCI_FUNC(device->devfn);
244 /* XXX Need to change the Bus # */
246 address = (bus << 16) | (dev << 11) | (func << 8) | (offset & 0xfc) |
249 address = (dev << 11) | (func << 8) | (offset & 0xfc) | 0x80000000;
251 address_reg = RM9000x2_OCD_HTCFGA;
252 data_reg = RM9000x2_OCD_HTCFGD;
254 RM9K_WRITE(address_reg, address);
256 if ((offset & 0x3) == 0) {
259 if ((offset & 0x3) == 1) {
262 if ((offset & 0x3) == 2) {
265 if ((offset & 0x3) == 3) {
269 RM9K_WRITE_8(data_reg + offset1, val);
270 return PCIBIOS_SUCCESSFUL;
274 static void titan_pcibios_set_master(struct pci_dev *dev)
277 int bus = dev->bus->number;
279 if (check_titan_htlink())
280 titan_ht_config_read_word(dev, PCI_COMMAND, &cmd);
282 cmd |= PCI_COMMAND_MASTER;
284 if (check_titan_htlink())
285 titan_ht_config_write_word(dev, PCI_COMMAND, cmd);
289 int pcibios_enable_resources(struct pci_dev *dev)
295 int bus = dev->bus->number;
297 if (check_titan_htlink())
298 titan_ht_config_read_word(dev, PCI_COMMAND, &cmd);
301 for (idx = 0; idx < 6; idx++) {
302 r = &dev->resource[idx];
303 if (!r->start && r->end) {
305 "PCI: Device %s not available because of "
306 "resource collisions\n", pci_name(dev));
309 if (r->flags & IORESOURCE_IO)
310 cmd |= PCI_COMMAND_IO;
311 if (r->flags & IORESOURCE_MEM)
312 cmd |= PCI_COMMAND_MEMORY;
314 if (cmd != old_cmd) {
315 if (check_titan_htlink())
316 titan_ht_config_write_word(dev, PCI_COMMAND, cmd);
319 if (check_titan_htlink())
320 titan_ht_config_read_byte(dev, PCI_CACHE_LINE_SIZE, &tmp1);
323 printk(KERN_WARNING "PCI setting cache line size to 8 from "
327 if (check_titan_htlink())
328 titan_ht_config_write_byte(dev, PCI_CACHE_LINE_SIZE, 8);
330 if (check_titan_htlink())
331 titan_ht_config_read_byte(dev, PCI_LATENCY_TIMER, &tmp1);
333 if (tmp1 < 32 || tmp1 == 0xff) {
334 printk(KERN_WARNING "PCI setting latency timer to 32 from %d\n",
338 if (check_titan_htlink())
339 titan_ht_config_write_byte(dev, PCI_LATENCY_TIMER, 32);
345 int pcibios_enable_device(struct pci_dev *dev, int mask)
347 return pcibios_enable_resources(dev);
352 void pcibios_update_resource(struct pci_dev *dev, struct resource *root,
353 struct resource *res, int resource)
360 new = res->start | (res->flags & PCI_REGION_FLAG_MASK);
362 reg = PCI_BASE_ADDRESS_0 + 4 * resource;
363 } else if (resource == PCI_ROM_RESOURCE) {
364 res->flags |= IORESOURCE_ROM_ENABLE;
365 reg = dev->rom_base_reg;
368 * Somebody might have asked allocation of a non-standard
374 pci_write_config_dword(dev, reg, new);
375 pci_read_config_dword(dev, reg, &check);
377 ((new & PCI_BASE_ADDRESS_SPACE_IO) ? PCI_BASE_ADDRESS_IO_MASK :
378 PCI_BASE_ADDRESS_MEM_MASK)) {
379 printk(KERN_ERR "PCI: Error while updating region "
380 "%s/%d (%08x != %08x)\n", pci_name(dev), resource,
386 void pcibios_align_resource(void *data, struct resource *res,
387 unsigned long size, unsigned long align)
389 struct pci_dev *dev = data;
391 if (res->flags & IORESOURCE_IO) {
392 unsigned long start = res->start;
394 /* We need to avoid collisions with `mirrored' VGA ports
395 and other strange ISA hardware, so we always want the
396 addresses kilobyte aligned. */
398 printk(KERN_ERR "PCI: I/O Region %s/%d too large"
399 " (%ld bytes)\n", pci_name(dev),
400 dev->resource - res, size);
403 start = (start + 1024 - 1) & ~(1024 - 1);
408 struct pci_ops titan_pci_ops = {
409 titan_ht_config_read_byte,
410 titan_ht_config_read_word,
411 titan_ht_config_read_dword,
412 titan_ht_config_write_byte,
413 titan_ht_config_write_word,
414 titan_ht_config_write_dword
417 void __init pcibios_fixup_bus(struct pci_bus *c)
419 titan_ht_pcibios_fixup_bus(c);
422 void __init pcibios_init(void)
425 /* Reset PCI I/O and PCI MEM values */
426 /* XXX Need to add the proper values here */
427 ioport_resource.start = 0xe0000000;
428 ioport_resource.end = 0xe0000000 + 0x20000000 - 1;
429 iomem_resource.start = 0xc0000000;
430 iomem_resource.end = 0xc0000000 + 0x20000000 - 1;
432 /* XXX Need to add bus values */
433 pci_scan_bus(2, &titan_pci_ops, NULL);
434 pci_scan_bus(3, &titan_pci_ops, NULL);
438 * for parsing "pci=" kernel boot arguments.
440 char *pcibios_setup(char *str)
442 printk(KERN_INFO "rr: pcibios_setup\n");
443 /* Nothing to do for now. */
448 unsigned __init int pcibios_assign_all_busses(void)
450 /* We want to use the PCI bus detection done by PMON */
454 #endif /* CONFIG_HYPERTRANSPORT */