1 /*
2 * pci.c
3 *
4 * Copyright (C) 2007 Lemote, Inc. & Institute of Computing Technology
5 * Author: Fuxin Zhang, zhangfx@lemote.com
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
13 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
15 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
16 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
18 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 */
28 #include <linux/types.h>
29 #include <linux/pci.h>
30 #include <linux/kernel.h>
31 #include <linux/init.h>
32 #include <asm/mips-boards/bonito64.h>
33 #include <asm/mach-lemote/pci.h>
34
35 extern struct pci_ops bonito64_pci_ops;
36
37 static struct resource loongson2e_pci_mem_resource = {
38 .name = "LOONGSON2E PCI MEM",
39 .start = LOONGSON2E_PCI_MEM_START,
40 .end = LOONGSON2E_PCI_MEM_END,
41 .flags = IORESOURCE_MEM,
42 };
43
44 static struct resource loongson2e_pci_io_resource = {
45 .name = "LOONGSON2E PCI IO MEM",
46 .start = LOONGSON2E_PCI_IO_START,
47 .end = IO_SPACE_LIMIT,
48 .flags = IORESOURCE_IO,
49 };
50
51 static struct pci_controller loongson2e_pci_controller = {
52 .pci_ops = &bonito64_pci_ops,
53 .io_resource = &loongson2e_pci_io_resource,
54 .mem_resource = &loongson2e_pci_mem_resource,
55 .mem_offset = 0x00000000UL,
56 .io_offset = 0x00000000UL,
57 };
58
ict_pcimap(void)59 static void __init ict_pcimap(void)
60 {
61 /*
62 * local to PCI mapping: [256M,512M] -> [256M,512M]; differ from PMON
63 *
64 * CPU address space [256M,448M] is window for accessing pci space
65 * we set pcimap_lo[0,1,2] to map it to pci space [256M,448M]
66 * pcimap: bit18,pcimap_2; bit[17-12],lo2;bit[11-6],lo1;bit[5-0],lo0
67 */
68 /* 1,00 0110 ,0001 01,00 0000 */
69 BONITO_PCIMAP = 0x46140;
70
71 /* 1, 00 0010, 0000,01, 00 0000 */
72 /* BONITO_PCIMAP = 0x42040; */
73
74 /*
75 * PCI to local mapping: [2G,2G+256M] -> [0,256M]
76 */
77 BONITO_PCIBASE0 = 0x80000000;
78 BONITO_PCIBASE1 = 0x00800000;
79 BONITO_PCIBASE2 = 0x90000000;
80
81 }
82
pcibios_init(void)83 static int __init pcibios_init(void)
84 {
85 ict_pcimap();
86
87 loongson2e_pci_controller.io_map_base =
88 (unsigned long) ioremap(LOONGSON2E_IO_PORT_BASE,
89 loongson2e_pci_io_resource.end -
90 loongson2e_pci_io_resource.start + 1);
91
92 register_pci_controller(&loongson2e_pci_controller);
93
94 return 0;
95 }
96
97 arch_initcall(pcibios_init);
98