| Songmao Tian | 42d226c | 2007-06-06 14:52:38 +0800 | [diff] [blame] | 1 | /* | 
| Songmao Tian | 42d226c | 2007-06-06 14:52:38 +0800 | [diff] [blame] | 2 | * 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 Tian | 42d226c | 2007-06-06 14:52:38 +0800 | [diff] [blame] | 9 | */ | 
| Songmao Tian | 42d226c | 2007-06-06 14:52:38 +0800 | [diff] [blame] | 10 | #include <linux/pci.h> | 
| Songmao Tian | 42d226c | 2007-06-06 14:52:38 +0800 | [diff] [blame] | 11 |  | 
| Wu Zhangjin | 5e983ff | 2009-07-02 23:23:03 +0800 | [diff] [blame] | 12 | #include <pci.h> | 
|  | 13 | #include <loongson.h> | 
| Songmao Tian | 42d226c | 2007-06-06 14:52:38 +0800 | [diff] [blame] | 14 |  | 
| Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 15 | static struct resource loongson_pci_mem_resource = { | 
|  | 16 | .name   = "pci memory space", | 
|  | 17 | .start  = LOONGSON_PCI_MEM_START, | 
|  | 18 | .end    = LOONGSON_PCI_MEM_END, | 
| Songmao Tian | 42d226c | 2007-06-06 14:52:38 +0800 | [diff] [blame] | 19 | .flags  = IORESOURCE_MEM, | 
|  | 20 | }; | 
|  | 21 |  | 
| Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 22 | static struct resource loongson_pci_io_resource = { | 
|  | 23 | .name   = "pci io space", | 
|  | 24 | .start  = LOONGSON_PCI_IO_START, | 
| Songmao Tian | 42d226c | 2007-06-06 14:52:38 +0800 | [diff] [blame] | 25 | .end    = IO_SPACE_LIMIT, | 
|  | 26 | .flags  = IORESOURCE_IO, | 
|  | 27 | }; | 
|  | 28 |  | 
| Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 29 | static struct pci_controller  loongson_pci_controller = { | 
| Wu Zhangjin | e2fee57 | 2009-10-16 14:17:19 +0800 | [diff] [blame] | 30 | .pci_ops        = &loongson_pci_ops, | 
| Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 31 | .io_resource    = &loongson_pci_io_resource, | 
|  | 32 | .mem_resource   = &loongson_pci_mem_resource, | 
| Songmao Tian | 42d226c | 2007-06-06 14:52:38 +0800 | [diff] [blame] | 33 | .mem_offset     = 0x00000000UL, | 
|  | 34 | .io_offset      = 0x00000000UL, | 
|  | 35 | }; | 
|  | 36 |  | 
| Wu Zhangjin | f7face0 | 2009-07-02 23:23:30 +0800 | [diff] [blame] | 37 | static void __init setup_pcimap(void) | 
| Songmao Tian | 42d226c | 2007-06-06 14:52:38 +0800 | [diff] [blame] | 38 | { | 
|  | 39 | /* | 
| Wu Zhangjin | f7face0 | 2009-07-02 23:23:30 +0800 | [diff] [blame] | 40 | * local to PCI mapping for CPU accessing PCI space | 
| Songmao Tian | 42d226c | 2007-06-06 14:52:38 +0800 | [diff] [blame] | 41 | * CPU address space [256M,448M] is window for accessing pci space | 
| Wu Zhangjin | f7face0 | 2009-07-02 23:23:30 +0800 | [diff] [blame] | 42 | * 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 Tian | 42d226c | 2007-06-06 14:52:38 +0800 | [diff] [blame] | 46 | */ | 
| Wu Zhangjin | e2fee57 | 2009-10-16 14:17:19 +0800 | [diff] [blame] | 47 | LOONGSON_PCIMAP = LOONGSON_PCIMAP_PCIMAP_2 | | 
|  | 48 | LOONGSON_PCIMAP_WIN(2, LOONGSON_PCILO2_BASE) | | 
|  | 49 | LOONGSON_PCIMAP_WIN(1, LOONGSON_PCILO1_BASE) | | 
|  | 50 | LOONGSON_PCIMAP_WIN(0, 0); | 
| Songmao Tian | 42d226c | 2007-06-06 14:52:38 +0800 | [diff] [blame] | 51 |  | 
|  | 52 | /* | 
| Wu Zhangjin | f7face0 | 2009-07-02 23:23:30 +0800 | [diff] [blame] | 53 | * PCI-DMA to local mapping: [2G,2G+256M] -> [0M,256M] | 
| Songmao Tian | 42d226c | 2007-06-06 14:52:38 +0800 | [diff] [blame] | 54 | */ | 
| Wu Zhangjin | e2fee57 | 2009-10-16 14:17:19 +0800 | [diff] [blame] | 55 | LOONGSON_PCIBASE0 = 0x80000000ul;   /* base: 2G -> mmap: 0M */ | 
| Wu Zhangjin | f7face0 | 2009-07-02 23:23:30 +0800 | [diff] [blame] | 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 Tian | 42d226c | 2007-06-06 14:52:38 +0800 | [diff] [blame] | 63 |  | 
| Wu Zhangjin | f7face0 | 2009-07-02 23:23:30 +0800 | [diff] [blame] | 64 | /* 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; | 
| Wu Zhangjin | 6f7a251 | 2009-11-06 18:45:05 +0800 | [diff] [blame] | 70 |  | 
| Wu Zhangjin | 55045ff | 2009-11-11 13:39:12 +0800 | [diff] [blame] | 71 | #ifdef CONFIG_CPU_SUPPORTS_ADDRWINCFG | 
| Wu Zhangjin | 6f7a251 | 2009-11-06 18:45:05 +0800 | [diff] [blame] | 72 | /* | 
|  | 73 | * set cpu addr window2 to map CPU address space to PCI address space | 
|  | 74 | */ | 
|  | 75 | LOONGSON_ADDRWIN_CPUTOPCI(ADDRWIN_WIN2, LOONGSON_CPU_MEM_SRC, | 
|  | 76 | LOONGSON_PCI_MEM_DST, MMAP_CPUTOPCI_SIZE); | 
|  | 77 | #endif | 
| Songmao Tian | 42d226c | 2007-06-06 14:52:38 +0800 | [diff] [blame] | 78 | } | 
|  | 79 |  | 
|  | 80 | static int __init pcibios_init(void) | 
|  | 81 | { | 
| Wu Zhangjin | f7face0 | 2009-07-02 23:23:30 +0800 | [diff] [blame] | 82 | setup_pcimap(); | 
| Zhang Le | 3a63913 | 2008-10-27 23:33:24 +0000 | [diff] [blame] | 83 |  | 
| Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 84 | loongson_pci_controller.io_map_base = mips_io_port_base; | 
| Zhang Le | 3a63913 | 2008-10-27 23:33:24 +0000 | [diff] [blame] | 85 |  | 
| Wu Zhangjin | 85749d2 | 2009-07-02 23:26:45 +0800 | [diff] [blame] | 86 | register_pci_controller(&loongson_pci_controller); | 
| Songmao Tian | 42d226c | 2007-06-06 14:52:38 +0800 | [diff] [blame] | 87 |  | 
|  | 88 | return 0; | 
|  | 89 | } | 
|  | 90 |  | 
|  | 91 | arch_initcall(pcibios_init); |