blob: 4e2575643781b1dc2ee7a36a6abaa770d44b2ce4 [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 *
Ralf Baechle70342282013-01-22 12:59:30 +01005 * 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
Songmao Tian42d226c2007-06-06 14:52:38 +08008 * 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>
Huacai Chen1a08f152014-03-21 18:44:02 +080014#include <boot_param.h>
Songmao Tian42d226c2007-06-06 14:52:38 +080015
Wu Zhangjin85749d22009-07-02 23:26:45 +080016static struct resource loongson_pci_mem_resource = {
Ralf Baechle70342282013-01-22 12:59:30 +010017 .name = "pci memory space",
18 .start = LOONGSON_PCI_MEM_START,
19 .end = LOONGSON_PCI_MEM_END,
20 .flags = IORESOURCE_MEM,
Songmao Tian42d226c2007-06-06 14:52:38 +080021};
22
Wu Zhangjin85749d22009-07-02 23:26:45 +080023static struct resource loongson_pci_io_resource = {
Ralf Baechle70342282013-01-22 12:59:30 +010024 .name = "pci io space",
25 .start = LOONGSON_PCI_IO_START,
26 .end = IO_SPACE_LIMIT,
27 .flags = IORESOURCE_IO,
Songmao Tian42d226c2007-06-06 14:52:38 +080028};
29
Wu Zhangjin85749d22009-07-02 23:26:45 +080030static struct pci_controller loongson_pci_controller = {
Ralf Baechle70342282013-01-22 12:59:30 +010031 .pci_ops = &loongson_pci_ops,
32 .io_resource = &loongson_pci_io_resource,
33 .mem_resource = &loongson_pci_mem_resource,
34 .mem_offset = 0x00000000UL,
35 .io_offset = 0x00000000UL,
Songmao Tian42d226c2007-06-06 14:52:38 +080036};
37
Wu Zhangjinf7face02009-07-02 23:23:30 +080038static void __init setup_pcimap(void)
Songmao Tian42d226c2007-06-06 14:52:38 +080039{
40 /*
Wu Zhangjinf7face02009-07-02 23:23:30 +080041 * local to PCI mapping for CPU accessing PCI space
Songmao Tian42d226c2007-06-06 14:52:38 +080042 * CPU address space [256M,448M] is window for accessing pci space
Wu Zhangjinf7face02009-07-02 23:23:30 +080043 * we set pcimap_lo[0,1,2] to map it to pci space[0M,64M], [320M,448M]
44 *
45 * pcimap: PCI_MAP2 PCI_Mem_Lo2 PCI_Mem_Lo1 PCI_Mem_Lo0
Ralf Baechle70342282013-01-22 12:59:30 +010046 * [<2G] [384M,448M] [320M,384M] [0M,64M]
Songmao Tian42d226c2007-06-06 14:52:38 +080047 */
Wu Zhangjine2fee572009-10-16 14:17:19 +080048 LOONGSON_PCIMAP = LOONGSON_PCIMAP_PCIMAP_2 |
49 LOONGSON_PCIMAP_WIN(2, LOONGSON_PCILO2_BASE) |
50 LOONGSON_PCIMAP_WIN(1, LOONGSON_PCILO1_BASE) |
51 LOONGSON_PCIMAP_WIN(0, 0);
Songmao Tian42d226c2007-06-06 14:52:38 +080052
53 /*
Wu Zhangjinf7face02009-07-02 23:23:30 +080054 * PCI-DMA to local mapping: [2G,2G+256M] -> [0M,256M]
Songmao Tian42d226c2007-06-06 14:52:38 +080055 */
Wu Zhangjine2fee572009-10-16 14:17:19 +080056 LOONGSON_PCIBASE0 = 0x80000000ul; /* base: 2G -> mmap: 0M */
Wu Zhangjinf7face02009-07-02 23:23:30 +080057 /* size: 256M, burst transmission, pre-fetch enable, 64bit */
58 LOONGSON_PCI_HIT0_SEL_L = 0xc000000cul;
59 LOONGSON_PCI_HIT0_SEL_H = 0xfffffffful;
60 LOONGSON_PCI_HIT1_SEL_L = 0x00000006ul; /* set this BAR as invalid */
61 LOONGSON_PCI_HIT1_SEL_H = 0x00000000ul;
62 LOONGSON_PCI_HIT2_SEL_L = 0x00000006ul; /* set this BAR as invalid */
63 LOONGSON_PCI_HIT2_SEL_H = 0x00000000ul;
Songmao Tian42d226c2007-06-06 14:52:38 +080064
Wu Zhangjinf7face02009-07-02 23:23:30 +080065 /* avoid deadlock of PCI reading/writing lock operation */
66 LOONGSON_PCI_ISR4C = 0xd2000001ul;
67
68 /* can not change gnt to break pci transfer when device's gnt not
69 deassert for some broken device */
70 LOONGSON_PXARB_CFG = 0x00fe0105ul;
Wu Zhangjin6f7a2512009-11-06 18:45:05 +080071
Wu Zhangjin55045ff2009-11-11 13:39:12 +080072#ifdef CONFIG_CPU_SUPPORTS_ADDRWINCFG
Wu Zhangjin6f7a2512009-11-06 18:45:05 +080073 /*
74 * set cpu addr window2 to map CPU address space to PCI address space
75 */
76 LOONGSON_ADDRWIN_CPUTOPCI(ADDRWIN_WIN2, LOONGSON_CPU_MEM_SRC,
77 LOONGSON_PCI_MEM_DST, MMAP_CPUTOPCI_SIZE);
78#endif
Songmao Tian42d226c2007-06-06 14:52:38 +080079}
80
Huacai Chen9c057b32015-03-29 10:54:10 +080081extern int sbx00_acpi_init(void);
82
Songmao Tian42d226c2007-06-06 14:52:38 +080083static int __init pcibios_init(void)
84{
Wu Zhangjinf7face02009-07-02 23:23:30 +080085 setup_pcimap();
Zhang Le3a639132008-10-27 23:33:24 +000086
Wu Zhangjin85749d22009-07-02 23:26:45 +080087 loongson_pci_controller.io_map_base = mips_io_port_base;
Huacai Chen1a08f152014-03-21 18:44:02 +080088#ifdef CONFIG_LEFI_FIRMWARE_INTERFACE
89 loongson_pci_mem_resource.start = loongson_sysconf.pci_mem_start_addr;
90 loongson_pci_mem_resource.end = loongson_sysconf.pci_mem_end_addr;
91#endif
Wu Zhangjin85749d22009-07-02 23:26:45 +080092 register_pci_controller(&loongson_pci_controller);
Songmao Tian42d226c2007-06-06 14:52:38 +080093
Huacai Chen9c057b32015-03-29 10:54:10 +080094#ifdef CONFIG_CPU_LOONGSON3
95 sbx00_acpi_init();
96#endif
97
Songmao Tian42d226c2007-06-06 14:52:38 +080098 return 0;
99}
100
101arch_initcall(pcibios_init);