blob: 9812c30cc6eb38590e974813c32f73f8b7858222 [file] [log] [blame]
Songmao Tian42d226c2007-06-06 14:52:38 +08001/*
Songmao Tian42d226c2007-06-06 14:52:38 +08002 * Copyright (C) 2007 Lemote, Inc. & Institute of Computing Technology
3 * Author: Fuxin Zhang, zhangfx@lemote.com
4 *
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.
Songmao Tian42d226c2007-06-06 14:52:38 +08009 */
Songmao Tian42d226c2007-06-06 14:52:38 +080010#include <linux/pci.h>
Songmao Tian42d226c2007-06-06 14:52:38 +080011
Wu Zhangjin5e983ff2009-07-02 23:23:03 +080012#include <pci.h>
13#include <loongson.h>
Songmao Tian42d226c2007-06-06 14:52:38 +080014
15static struct resource loongson2e_pci_mem_resource = {
16 .name = "LOONGSON2E PCI MEM",
Zhang Le3a639132008-10-27 23:33:24 +000017 .start = LOONGSON2E_PCI_MEM_START,
18 .end = LOONGSON2E_PCI_MEM_END,
Songmao Tian42d226c2007-06-06 14:52:38 +080019 .flags = IORESOURCE_MEM,
20};
21
22static struct resource loongson2e_pci_io_resource = {
23 .name = "LOONGSON2E PCI IO MEM",
Zhang Le3a639132008-10-27 23:33:24 +000024 .start = LOONGSON2E_PCI_IO_START,
Songmao Tian42d226c2007-06-06 14:52:38 +080025 .end = IO_SPACE_LIMIT,
26 .flags = IORESOURCE_IO,
27};
28
29static struct pci_controller loongson2e_pci_controller = {
30 .pci_ops = &bonito64_pci_ops,
31 .io_resource = &loongson2e_pci_io_resource,
32 .mem_resource = &loongson2e_pci_mem_resource,
33 .mem_offset = 0x00000000UL,
34 .io_offset = 0x00000000UL,
35};
36
Wu Zhangjinf7face02009-07-02 23:23:30 +080037static void __init setup_pcimap(void)
Songmao Tian42d226c2007-06-06 14:52:38 +080038{
39 /*
Wu Zhangjinf7face02009-07-02 23:23:30 +080040 * local to PCI mapping for CPU accessing PCI space
Songmao Tian42d226c2007-06-06 14:52:38 +080041 * CPU address space [256M,448M] is window for accessing pci space
Wu Zhangjinf7face02009-07-02 23:23:30 +080042 * we set pcimap_lo[0,1,2] to map it to pci space[0M,64M], [320M,448M]
43 *
44 * pcimap: PCI_MAP2 PCI_Mem_Lo2 PCI_Mem_Lo1 PCI_Mem_Lo0
45 * [<2G] [384M,448M] [320M,384M] [0M,64M]
Songmao Tian42d226c2007-06-06 14:52:38 +080046 */
Wu Zhangjinf7face02009-07-02 23:23:30 +080047 BONITO_PCIMAP = BONITO_PCIMAP_PCIMAP_2 |
48 BONITO_PCIMAP_WIN(2, BONITO_PCILO2_BASE) |
49 BONITO_PCIMAP_WIN(1, BONITO_PCILO1_BASE) |
50 BONITO_PCIMAP_WIN(0, 0);
Songmao Tian42d226c2007-06-06 14:52:38 +080051
52 /*
Wu Zhangjinf7face02009-07-02 23:23:30 +080053 * PCI-DMA to local mapping: [2G,2G+256M] -> [0M,256M]
Songmao Tian42d226c2007-06-06 14:52:38 +080054 */
Wu Zhangjinf7face02009-07-02 23:23:30 +080055 BONITO_PCIBASE0 = 0x80000000ul; /* base: 2G -> mmap: 0M */
56 /* size: 256M, burst transmission, pre-fetch enable, 64bit */
57 LOONGSON_PCI_HIT0_SEL_L = 0xc000000cul;
58 LOONGSON_PCI_HIT0_SEL_H = 0xfffffffful;
59 LOONGSON_PCI_HIT1_SEL_L = 0x00000006ul; /* set this BAR as invalid */
60 LOONGSON_PCI_HIT1_SEL_H = 0x00000000ul;
61 LOONGSON_PCI_HIT2_SEL_L = 0x00000006ul; /* set this BAR as invalid */
62 LOONGSON_PCI_HIT2_SEL_H = 0x00000000ul;
Songmao Tian42d226c2007-06-06 14:52:38 +080063
Wu Zhangjinf7face02009-07-02 23:23:30 +080064 /* avoid deadlock of PCI reading/writing lock operation */
65 LOONGSON_PCI_ISR4C = 0xd2000001ul;
66
67 /* can not change gnt to break pci transfer when device's gnt not
68 deassert for some broken device */
69 LOONGSON_PXARB_CFG = 0x00fe0105ul;
Songmao Tian42d226c2007-06-06 14:52:38 +080070}
71
72static int __init pcibios_init(void)
73{
Wu Zhangjinf7face02009-07-02 23:23:30 +080074 setup_pcimap();
Zhang Le3a639132008-10-27 23:33:24 +000075
Wu Zhangjinf54a40e2009-07-02 23:22:11 +080076 loongson2e_pci_controller.io_map_base = mips_io_port_base;
Zhang Le3a639132008-10-27 23:33:24 +000077
Songmao Tian42d226c2007-06-06 14:52:38 +080078 register_pci_controller(&loongson2e_pci_controller);
79
80 return 0;
81}
82
83arch_initcall(pcibios_init);